]> wimlib.net Git - wimlib/blob - tests/test-imagex-capture_and_apply
d4333486d13ad09f3d27b1d0984bb9becd3d18f5
[wimlib] / tests / test-imagex-capture_and_apply
1 #!/usr/bin/env bash
2
3 # Test capturing and applying a WIM image in the normal (non-NTFS) capture mode
4 #
5 # Add in some tests with WIM splitting, joining, and exporting as well.
6 #
7 # Test all three compression modes (None, XPRESS, and LZX).
8 #
9 # Also, test if the capture configuration file works correctly.
10
11 set -e
12 cd tests
13 srcdir="${srcdir:-.}/.."
14 srcdir="$(cd $srcdir; pwd)"
15 . "$srcdir/tests/tests-common.sh"
16
17 TEST_SUBDIR=tmpdir_test-imagex-capture_and_apply
18
19 do_tree_cmp() {
20         if ! ../tree-cmp in.dir out.dir; then
21                 if [ -x /usr/bin/tree ]; then
22                         echo "Dumping tree of applied image"
23                         echo "(Note: compression type was $ctype)"
24                         tree out.dir --inodes -F -s --noreport
25                         error 'Information was lost or corrupted while capturing
26                                 and then applying a directory tree'
27                 fi
28         fi
29 }
30
31 image_name=0
32 do_test() {
33         for ctype in None XPRESS LZX; do
34
35                 # Can we capture the WIM, apply it, and get the same result?
36                 cd in.dir
37                 eval "$1"
38                 cd ..
39                 if [ -x /usr/bin/tree -a "$ctype" = "None" ]; then
40                         tree in.dir --inodes -F -s --noreport
41                 fi
42                 if ! imagex capture in.dir test.wim --compress=$ctype --norpfix; then
43                         error "Failed to capture directory tree into a WIM"
44                 fi
45                 if ! imagex apply test.wim 1 out.dir; then
46                         error "Failed to apply WIM to directory"
47                 fi
48                 if [ `wim_ctype test.wim` != $ctype ]; then
49                         error "'imagex info' didn't report the compression type on the captured WIM correctly"
50                 fi
51                 do_tree_cmp
52                 rm -rf out.dir/*
53
54                 # Can we split the WIM, apply the split WIM, join the split WIM,
55                 # and apply the joined WIM, and get the same results every time?
56                 #
57                 # LC_ALL=C avoids locale-dependent floating point number
58                 # parsing.
59                 if ! LC_ALL=C imagex split test.wim test.swm 0.01; then
60                         error "Failed to split WIM"
61                 fi
62                 if ! imagex apply test.swm 1 out.dir --ref "test*.swm" ; then
63                         error "Failed to apply split WIM"
64                 fi
65                 do_tree_cmp
66                 rm -rf out.dir/* test.wim
67                 if ! imagex join test.wim test*.swm; then
68                         error "Failed to join split WIM"
69                 fi
70                 if ! imagex apply test.wim out.dir; then
71                         error "Failed to apply joined WIM"
72                 fi
73                 do_tree_cmp
74                 rm -rf out.dir/*
75
76                 # Can we export the image to another WIM, apply it, and get the
77                 # same results?
78                 (( image_name++ )) || true
79                 if ! imagex export test.wim 1 test2.wim "$image_name"; then
80                         error "Failed to export WIM image"
81                 fi
82
83                 if ! imagex apply test2.wim "$image_name" out.dir; then
84                         error "Failed to apply exported WIM image"
85                 fi
86                 do_tree_cmp
87
88                 rm -rf out.dir/* in.dir/* test.wim test*.swm
89
90         done
91 }
92
93 __msg() {
94         echo "--------------------------------------------------------------------"
95         echo $1
96         echo "--------------------------------------------------------------------"
97 }
98
99 msg() {
100         __msg "Testing image capture and application of directory containing $1"
101 }
102
103 default_cleanup
104 mkdir $TEST_SUBDIR
105 cd $TEST_SUBDIR
106 mkdir in.dir out.dir
107
108 . $srcdir/tests/common_tests.sh
109
110 # Make sure exclusion list works
111 __msg "Testing default capture configuration file"
112 touch in.dir/hiberfil.sys
113 mkdir -p "in.dir/System Volume Information/subdir"
114 imagex capture in.dir test.wim
115 imagex apply test.wim out.dir
116 if [ -e out.dir/hiberfil.sys -o -e "out.dir/System Volume Information" ]; then
117         error "Files were not excluded from capture as expected"
118 fi
119
120 # Make sure reparse point fixups are working as expected
121 __msg "Testing --rpfix"
122 rm -r in.dir out.dir
123 mkdir in.dir
124 ln -s $PWD/in.dir          in.dir/absrootlink
125 ln -s $PWD/in.dir////      in.dir/absrootlinkslashes
126 ln -s /___NONEXISTENT___   in.dir/absnonexistent
127 ln -s /usr/bin/env         in.dir/absoutoftree
128 ln -s file                 in.dir/relalink
129 ln -s $PWD/in.dir/file     in.dir/abslink
130 ln -s $PWD/in.dir/file///  in.dir/abslinkslashes
131 imagex capture --rpfix in.dir test.wim
132 imagex apply --norpfix test.wim out.dir
133 if [[ `readlink out.dir/absrootlink` != "/" ]] ||
134    [[ `readlink out.dir/absrootlinkslashes` != "////" ]]; then
135         error "imagex capture --rpfix failed to fix absolute link to capture root"
136 fi
137
138 if [[ -e out.dir/absnonexistent ]] ||
139    [[ -e out.dir/absoutoftree ]]; then
140         error "imagex capture --rpfix failed to exclude out of tree absolute links"
141 fi
142 if [[ `readlink out.dir/relalink` != "file" ]]; then
143         error "imagex capture --rpfix failed to capture relative symlink"
144 fi
145 if [[ `readlink out.dir/abslink` != "/file" ]] ||
146    [[ `readlink out.dir/abslinkslashes` != "/file///" ]]; then
147         error "imagex capture --rpfix did fix absolute link properly"
148 fi
149 rm -rf out.dir
150
151 imagex apply test.wim out.dir
152 if [[ $(get_inode_number $(readlink out.dir/absrootlink)) != \
153         $(get_inode_number out.dir) ]];
154 then
155         error "imagex apply failed to apply fixed absolute symlinks"
156 fi
157
158 # Make sure source list mode is working as expected
159 __msg "Testing source list capture mode"
160 rm -rf in.dir out.dir
161 mkdir in.dir
162 echo 1 > in.dir/1
163 ln in.dir/1 in.dir/1link
164 echo 5 > 5
165 mkdir otherdir
166 cp $srcdir/src/add_image.c otherdir
167 cat > srclist << EOF
168 in.dir /
169 5      /5
170 otherdir /otherdir
171 EOF
172 imagex capture srclist --source-list test.wim
173 imagex apply test.wim out.dir
174 if [[ ! -f out.dir/5 || ! -f out.dir/1 || ! -f out.dir/1link || \
175       ! -d out.dir/otherdir ]]; then
176         error "source list capture failed to work as expected"
177 fi
178
179 # Still testing source list capture: add quoted name, and try overlay
180 rm -rf out.dir
181 cat > srclist << EOF
182 in.dir /
183 5      /5
184 otherdir /otherdir
185  "overlay dir 1"                'otherdir'      
186  "overlay dir 2"                'otherdir'  
187 EOF
188 mkdir "overlay dir 1"
189 mkdir "overlay dir 2"
190 echo A > "overlay dir 1"/A
191 echo B > "overlay dir 2"/B
192 imagex capture srclist --source-list test.wim
193 imagex apply test.wim out.dir
194 if [[ ! -f out.dir/5 || ! -f out.dir/1 || ! -f out.dir/1link || \
195       ! -f out.dir/otherdir/A || ! -f out.dir/otherdir/B ]]; then
196         error "source list capture (with quoted names and basic overlay) failed to work as expected"
197 fi
198
199 # Try deep overlay
200 rm -rf in.dir out.dir "overlay dir 1" "overlay dir 2"
201 mkdir -p in.dir.1/subdir/subdir2 in.dir.2/subdir/subdir2
202 cat > srclist << EOF
203 in.dir.1        /
204 in.dir.2        /
205 EOF
206 echo 1 > in.dir.1/subdir/1
207 echo 2 > in.dir.2/subdir/2
208 echo 3 > in.dir.1/subdir/subdir2/3
209 echo 4 > in.dir.2/subdir/subdir2/4
210 imagex capture srclist --source-list test.wim
211 imagex apply test.wim out.dir
212 if [[ ! -f out.dir/subdir/1 || ! -f out.dir/subdir/2 || \
213         ! -f out.dir/subdir/subdir2/3 || ! -f out.dir/subdir/subdir2/4 ]]; then
214         error "source list capture (with deep overlay) failed to work as expected"
215 fi
216
217 # Try bad overlay
218 __msg "Testing bad overlay (errors expected)"
219 rm -rf out.dir
220 echo 5 > 5
221 cat > srclist << EOF
222 in.dir.1        /
223 in.dir.2        /
224 5               /subdir
225 EOF
226 if imagex capture srclist --source-list test.wim; then
227         error "unexpected success in bad overlay with --source-list!"
228 fi
229
230 echo "**********************************************************"
231 echo "          imagex capture/apply tests passed               "
232 echo "**********************************************************"
233
234 cd ..
235 default_cleanup