]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/zfs-tests/tests/functional/migration/migration.kshlib
Vendor import of openzfs master @ 184df27eef0abdc7ab2105b21257f753834b936b
[FreeBSD/FreeBSD.git] / tests / zfs-tests / tests / functional / migration / migration.kshlib
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 http://www.opensolaris.org/os/licensing.
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 #
48 function prepare #srcdir cmd
49 {
50         typeset srcdir=$1
51         typeset cmd=$2
52         typeset -i retval=0
53
54         cwd=$PWD
55         cd $srcdir
56         (( $? != 0 )) && return 1
57
58         $cmd
59         (( $? != 0 )) && return 1
60
61         cd $cwd
62         (( $? != 0 )) && return 1
63
64         return 0
65 }
66
67 #
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.
72 #
73 # Usage:
74 # migrate destdir oldsuma oldsumb command_to_execute
75 #
76 # Return value: 0 on success
77 #               1 on failure
78 #
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"
86 #
87 function migrate #destdir oldsuma oldsumb cmd
88 {
89         typeset destdir=$1
90         typeset oldsuma=$2
91         typeset oldsumb=$3
92         typeset cmd=$4
93         typeset -i retval=0
94
95         cwd=$PWD
96         cd $destdir
97         (( $? != 0 )) && return 1
98
99         $cmd
100         (( $? != 0 )) && return 1
101
102         sumy=`sum ./$BNAME`
103         suma=`echo $sumy | awk '{print $1}'`
104         sumb=`echo $sumy | awk '{print $2}'`
105
106         if (( $oldsuma != $suma )); then
107                 log_note "sum values are not the same"
108                 retval=1
109         fi
110
111         if (( $oldsumb != $sumb )); then
112                 log_note "sum values are not the same"
113                 retval=1
114         fi
115
116         cd $cwd
117         (( $? != 0 )) && return 1
118         return $retval
119 }
120
121 function migrate_cpio
122 {
123         typeset destdir=$1
124         typeset archive=$2
125         typeset oldsuma=$3
126         typeset oldsumb=$4
127         typeset -i retval=0
128
129         cwd=$PWD
130         cd $destdir
131         (( $? != 0 )) && return 1
132
133         cpio -iv < $archive
134         (( $? != 0 )) && return 1
135
136         sumy=`sum ./$BNAME`
137         suma=`echo $sumy | awk '{print $1}'`
138         sumb=`echo $sumy | awk '{print $2}'`
139
140         if (( $oldsuma != $suma )); then
141                 log_note "sum values are not the same"
142                 retval=1
143         fi
144
145         if (( $oldsumb != $sumb )); then
146                 log_note "sum values are not the same"
147                 retval=1
148         fi
149
150         cd $cwd
151         (( $? != 0 )) && return 1
152         return $retval
153 }