1f38cb554SJohn Wren Kennedy#
2f38cb554SJohn Wren Kennedy# CDDL HEADER START
3f38cb554SJohn Wren Kennedy#
4f38cb554SJohn Wren Kennedy# The contents of this file are subject to the terms of the
5f38cb554SJohn Wren Kennedy# Common Development and Distribution License (the "License").
6f38cb554SJohn Wren Kennedy# You may not use this file except in compliance with the License.
7f38cb554SJohn Wren Kennedy#
8f38cb554SJohn Wren Kennedy# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9f38cb554SJohn Wren Kennedy# or http://www.opensolaris.org/os/licensing.
10f38cb554SJohn Wren Kennedy# See the License for the specific language governing permissions
11f38cb554SJohn Wren Kennedy# and limitations under the License.
12f38cb554SJohn Wren Kennedy#
13f38cb554SJohn Wren Kennedy# When distributing Covered Code, include this CDDL HEADER in each
14f38cb554SJohn Wren Kennedy# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15f38cb554SJohn Wren Kennedy# If applicable, add the following below this CDDL HEADER, with the
16f38cb554SJohn Wren Kennedy# fields enclosed by brackets "[]" replaced with your own identifying
17f38cb554SJohn Wren Kennedy# information: Portions Copyright [yyyy] [name of copyright owner]
18f38cb554SJohn Wren Kennedy#
19f38cb554SJohn Wren Kennedy# CDDL HEADER END
20f38cb554SJohn Wren Kennedy#
21f38cb554SJohn Wren Kennedy
22f38cb554SJohn Wren Kennedy#
23f38cb554SJohn Wren Kennedy# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
24f38cb554SJohn Wren Kennedy# Use is subject to license terms.
25f38cb554SJohn Wren Kennedy#
26f38cb554SJohn Wren Kennedy
27f38cb554SJohn Wren Kennedy#
28*1d32ba66SJohn Wren Kennedy# Copyright (c) 2013, 2016 by Delphix. All rights reserved.
29f38cb554SJohn Wren Kennedy#
30f38cb554SJohn Wren Kennedy
31f38cb554SJohn Wren Kennedy. $STF_SUITE/tests/functional/migration/migration.cfg
32f38cb554SJohn Wren Kennedy
33f38cb554SJohn Wren Kennedy#
34f38cb554SJohn Wren Kennedy# This function creates the test archive for migration.
35f38cb554SJohn Wren Kennedy#
36f38cb554SJohn Wren Kennedy# Usage:
37f38cb554SJohn Wren Kennedy# prepare srcdir cmd
38f38cb554SJohn Wren Kennedy#
39f38cb554SJohn Wren Kennedy# Return value: 0 on success
40f38cb554SJohn Wren Kennedy#		1 on failure
41f38cb554SJohn Wren Kennedy#
42f38cb554SJohn Wren Kennedy# Where:
43f38cb554SJohn Wren Kennedy#	srcdir: is the directory where the testfile is
44f38cb554SJohn Wren Kennedy#	cmd:	is the command to be executed.
45f38cb554SJohn Wren Kennedy#		E.g.
46*1d32ba66SJohn Wren Kennedy#		tar cf $TESTDIR/tar$$.tar
47f38cb554SJohn Wren Kennedy#
48f38cb554SJohn Wren Kennedyfunction prepare #srcdir cmd
49f38cb554SJohn Wren Kennedy{
50f38cb554SJohn Wren Kennedy	typeset srcdir=$1
51f38cb554SJohn Wren Kennedy	typeset cmd=$2
52f38cb554SJohn Wren Kennedy	typeset -i retval=0
53f38cb554SJohn Wren Kennedy
54f38cb554SJohn Wren Kennedy	cwd=$PWD
55f38cb554SJohn Wren Kennedy	cd $srcdir
56f38cb554SJohn Wren Kennedy	(( $? != 0 )) && return 1
57f38cb554SJohn Wren Kennedy
58f38cb554SJohn Wren Kennedy	$cmd
59f38cb554SJohn Wren Kennedy	(( $? != 0 )) && return 1
60f38cb554SJohn Wren Kennedy
61f38cb554SJohn Wren Kennedy	cd $cwd
62f38cb554SJohn Wren Kennedy	(( $? != 0 )) && return 1
63f38cb554SJohn Wren Kennedy
64f38cb554SJohn Wren Kennedy	return 0
65f38cb554SJohn Wren Kennedy}
66f38cb554SJohn Wren Kennedy
67f38cb554SJohn Wren Kennedy#
68f38cb554SJohn Wren Kennedy# This function executes a passed in command and then determines the chksum
69f38cb554SJohn Wren Kennedy# of the resulting file.  The chksum components are checked against the ones
70f38cb554SJohn Wren Kennedy# passed in to determine if they are equal.  If they are equal, 0 is returned
71f38cb554SJohn Wren Kennedy# otherwise 1 is returned.
72f38cb554SJohn Wren Kennedy#
73f38cb554SJohn Wren Kennedy# Usage:
74f38cb554SJohn Wren Kennedy# migrate destdir oldsuma oldsumb command_to_execute
75f38cb554SJohn Wren Kennedy#
76f38cb554SJohn Wren Kennedy# Return value: 0 on success
77f38cb554SJohn Wren Kennedy#		1 on failure
78f38cb554SJohn Wren Kennedy#
79f38cb554SJohn Wren Kennedy# Where:
80f38cb554SJohn Wren Kennedy#	destdir: is the directory where the command is to be executed on
81f38cb554SJohn Wren Kennedy#	oldsuma: is the first part of the values returned by sum
82f38cb554SJohn Wren Kennedy#	oldsumb: is the second part of the values returned by sum
83f38cb554SJohn Wren Kennedy#	cmd: is the command to be executed;
84f38cb554SJohn Wren Kennedy#		E.g.
85*1d32ba66SJohn Wren Kennedy#		"tar xf $TESTDIR/tar$$.tar"
86f38cb554SJohn Wren Kennedy#
87f38cb554SJohn Wren Kennedyfunction migrate #destdir oldsuma oldsumb cmd
88f38cb554SJohn Wren Kennedy{
89f38cb554SJohn Wren Kennedy	typeset destdir=$1
90f38cb554SJohn Wren Kennedy	typeset oldsuma=$2
91f38cb554SJohn Wren Kennedy	typeset oldsumb=$3
92f38cb554SJohn Wren Kennedy	typeset cmd=$4
93f38cb554SJohn Wren Kennedy	typeset -i retval=0
94f38cb554SJohn Wren Kennedy
95f38cb554SJohn Wren Kennedy	cwd=$PWD
96f38cb554SJohn Wren Kennedy	cd $destdir
97f38cb554SJohn Wren Kennedy	(( $? != 0 )) && return 1
98f38cb554SJohn Wren Kennedy
99f38cb554SJohn Wren Kennedy	$cmd
100f38cb554SJohn Wren Kennedy	(( $? != 0 )) && return 1
101f38cb554SJohn Wren Kennedy
102*1d32ba66SJohn Wren Kennedy	sumy=`sum ./$BNAME`
103*1d32ba66SJohn Wren Kennedy	suma=`echo $sumy | awk '{print $1}'`
104*1d32ba66SJohn Wren Kennedy	sumb=`echo $sumy | awk '{print $2}'`
105f38cb554SJohn Wren Kennedy
106f38cb554SJohn Wren Kennedy	if (( $oldsuma != $suma )); then
107*1d32ba66SJohn Wren Kennedy		log_note "sum values are not the same"
108f38cb554SJohn Wren Kennedy		retval=1
109f38cb554SJohn Wren Kennedy	fi
110f38cb554SJohn Wren Kennedy
111f38cb554SJohn Wren Kennedy	if (( $oldsumb != $sumb )); then
112*1d32ba66SJohn Wren Kennedy		log_note "sum values are not the same"
113f38cb554SJohn Wren Kennedy		retval=1
114f38cb554SJohn Wren Kennedy	fi
115f38cb554SJohn Wren Kennedy
116f38cb554SJohn Wren Kennedy	cd $cwd
117f38cb554SJohn Wren Kennedy	(( $? != 0 )) && return 1
118f38cb554SJohn Wren Kennedy	return $retval
119f38cb554SJohn Wren Kennedy}
120f38cb554SJohn Wren Kennedy
121f38cb554SJohn Wren Kennedyfunction migrate_cpio
122f38cb554SJohn Wren Kennedy{
123f38cb554SJohn Wren Kennedy	typeset destdir=$1
124f38cb554SJohn Wren Kennedy	typeset archive=$2
125f38cb554SJohn Wren Kennedy	typeset oldsuma=$3
126f38cb554SJohn Wren Kennedy	typeset oldsumb=$4
127f38cb554SJohn Wren Kennedy	typeset -i retval=0
128f38cb554SJohn Wren Kennedy
129f38cb554SJohn Wren Kennedy	cwd=$PWD
130f38cb554SJohn Wren Kennedy	cd $destdir
131f38cb554SJohn Wren Kennedy	(( $? != 0 )) && return 1
132f38cb554SJohn Wren Kennedy
133*1d32ba66SJohn Wren Kennedy	cpio -iv < $archive
134f38cb554SJohn Wren Kennedy	(( $? != 0 )) && return 1
135f38cb554SJohn Wren Kennedy
136*1d32ba66SJohn Wren Kennedy	sumy=`sum ./$BNAME`
137*1d32ba66SJohn Wren Kennedy	suma=`echo $sumy | awk '{print $1}'`
138*1d32ba66SJohn Wren Kennedy	sumb=`echo $sumy | awk '{print $2}'`
139f38cb554SJohn Wren Kennedy
140f38cb554SJohn Wren Kennedy	if (( $oldsuma != $suma )); then
141*1d32ba66SJohn Wren Kennedy		log_note "sum values are not the same"
142f38cb554SJohn Wren Kennedy		retval=1
143f38cb554SJohn Wren Kennedy	fi
144f38cb554SJohn Wren Kennedy
145f38cb554SJohn Wren Kennedy	if (( $oldsumb != $sumb )); then
146*1d32ba66SJohn Wren Kennedy		log_note "sum values are not the same"
147f38cb554SJohn Wren Kennedy		retval=1
148f38cb554SJohn Wren Kennedy	fi
149f38cb554SJohn Wren Kennedy
150f38cb554SJohn Wren Kennedy	cd $cwd
151f38cb554SJohn Wren Kennedy	(( $? != 0 )) && return 1
152f38cb554SJohn Wren Kennedy	return $retval
153f38cb554SJohn Wren Kennedy}
154