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