7290 ZFS test suite needs to control what utilities it can run
[unleashed.git] / usr / src / test / zfs-tests / tests / functional / migration / migration.kshlib
bloba2b4ed99b11e76ec2ccf5f320b7da0584cf2ac94
2 # CDDL HEADER START
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.
8 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 # or http://www.opensolaris.org/os/licensing.
10 # See the License for the specific language governing permissions
11 # and limitations under the License.
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]
19 # CDDL HEADER END
23 # Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
24 # Use is subject to license terms.
28 # Copyright (c) 2013, 2016 by Delphix. All rights reserved.
31 . $STF_SUITE/tests/functional/migration/migration.cfg
34 # This function creates the test archive for migration.
36 # Usage:
37 # prepare srcdir cmd
39 # Return value: 0 on success
40 #               1 on failure
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
48 function prepare #srcdir cmd
50         typeset srcdir=$1
51         typeset cmd=$2
52         typeset -i retval=0
54         cwd=$PWD
55         cd $srcdir
56         (( $? != 0 )) && return 1
58         $cmd
59         (( $? != 0 )) && return 1
61         cd $cwd
62         (( $? != 0 )) && return 1
64         return 0
68 # This function executes a passed in command and then determines the chksum
69 # of the resulting file.  The chksum components are checked against the ones
70 # passed in to determine if they are equal.  If they are equal, 0 is returned
71 # otherwise 1 is returned.
73 # Usage:
74 # migrate destdir oldsuma oldsumb command_to_execute
76 # Return value: 0 on success
77 #               1 on failure
79 # Where:
80 #       destdir: is the directory where the command is to be executed on
81 #       oldsuma: is the first part of the values returned by sum
82 #       oldsumb: is the second part of the values returned by sum
83 #       cmd: is the command to be executed;
84 #               E.g.
85 #               "tar xf $TESTDIR/tar$$.tar"
87 function migrate #destdir oldsuma oldsumb cmd
89         typeset destdir=$1
90         typeset oldsuma=$2
91         typeset oldsumb=$3
92         typeset cmd=$4
93         typeset -i retval=0
95         cwd=$PWD
96         cd $destdir
97         (( $? != 0 )) && return 1
99         $cmd
100         (( $? != 0 )) && return 1
102         sumy=`sum ./$BNAME`
103         suma=`echo $sumy | awk '{print $1}'`
104         sumb=`echo $sumy | awk '{print $2}'`
106         if (( $oldsuma != $suma )); then
107                 log_note "sum values are not the same"
108                 retval=1
109         fi
111         if (( $oldsumb != $sumb )); then
112                 log_note "sum values are not the same"
113                 retval=1
114         fi
116         cd $cwd
117         (( $? != 0 )) && return 1
118         return $retval
121 function migrate_cpio
123         typeset destdir=$1
124         typeset archive=$2
125         typeset oldsuma=$3
126         typeset oldsumb=$4
127         typeset -i retval=0
129         cwd=$PWD
130         cd $destdir
131         (( $? != 0 )) && return 1
133         cpio -iv < $archive
134         (( $? != 0 )) && return 1
136         sumy=`sum ./$BNAME`
137         suma=`echo $sumy | awk '{print $1}'`
138         sumb=`echo $sumy | awk '{print $2}'`
140         if (( $oldsuma != $suma )); then
141                 log_note "sum values are not the same"
142                 retval=1
143         fi
145         if (( $oldsumb != $sumb )); then
146                 log_note "sum values are not the same"
147                 retval=1
148         fi
150         cd $cwd
151         (( $? != 0 )) && return 1
152         return $retval