]> wimlib.net Git - wimlib/blob - tests/test-imagex
Test suite
[wimlib] / tests / test-imagex
1 #!/bin/sh
2
3 # This script does some sanity testing of the 'imagex' program.  It by no means
4 # tests every aspect of wimlib comprehensively.
5
6 # Assume an in-tree build.
7 set -e
8 cd tests
9
10 imagex() {
11         echo "imagex $@"
12         ../imagex $@
13 }
14 #diff() {
15         #echo "diff $@"
16         #/usr/bin/env diff $@
17 #}
18
19 #dd() {
20         #echo "dd $@"
21         #/usr/bin/env dd $@
22 #}
23 #stat() {
24         #echo "stat $@" 1>&2
25         #/usr/bin/env stat $@
26 #}
27 #cmp() {
28         #echo "cmp $@"
29         #/usr/bin/env cmp $@
30 #}
31
32
33 cleanup() {
34         if [ -d tmp ] && mountpoint tmp; then
35                 fusermount -u tmp > /dev/null;
36         fi
37         rm -rf tmp* *.wim *.swm dir3
38 }
39 trap cleanup exit
40
41 # Capturing and applying WIM with None, LZX, and XPRESS compression
42
43 echo "Testing capture and application of uncompressed WIM"
44 imagex capture dir dir.wim
45 imagex apply dir.wim tmp
46 test "`imagex info dir.wim | grep Compression | awk '{print $2}'`" = "None";
47 diff -q -r dir tmp
48 rm -rf dir.wim tmp
49
50 echo "Testing capture and application of LZX-compressed WIM"
51 imagex capture dir dir.wim --compress=maximum
52 imagex apply dir.wim tmp
53 test "`imagex info dir.wim | grep Compression | awk '{print $2}'`" = "LZX";
54 diff -q -r dir tmp
55 rm -rf dir.wim tmp
56
57 echo "Testing capture and application of XPRESS-compressed WIM"
58 imagex capture dir dir.wim --compress=fast
59 imagex apply dir.wim tmp
60 test "`imagex info dir.wim | grep Compression | awk '{print $2}'`" = "XPRESS";
61 diff -q -r dir tmp
62 rm -rf dir.wim tmp
63
64 # Capturing and modifying name, description, and bootable flag
65
66 echo "Testing capture of WIM with default name and description"
67 imagex capture dir dir.wim
68 test "`imagex info dir.wim | grep Name | awk '{print $2}'`" = "dir";
69 test "`imagex info dir.wim | grep Description | awk '{print $2}'`" = "";
70 rm -rf dir.wim tmp
71
72 echo "Testing capture of WIM with default boot flag"
73 imagex capture dir dir.wim
74 test "`imagex info dir.wim | grep Boot | awk '{print $3}'`" = "0";
75 echo "Testing changing image bootable flag"
76 imagex info dir.wim 1 --boot
77 test "`imagex info dir.wim | grep Boot | awk '{print $3}'`" = "1";
78 echo "Testing changing image bootable flag"
79 imagex info dir.wim 0 --boot
80 test "`imagex info dir.wim | grep Boot | awk '{print $3}'`" = "0";
81 echo "Testing changing image bootable flag to invalid image (this should generate errors)"
82 ! imagex info dir.wim 2 --boot 
83 test "`imagex info dir.wim | grep Boot | awk '{print $3}'`" = "0";
84 rm -rf dir.wim tmp
85
86 echo "Testing capture of WIM with name and description"
87 imagex capture dir dir.wim "myname" "mydesc"
88 test "`imagex info dir.wim | grep Name | awk '{print $2}'`" = "myname";
89 test "`imagex info dir.wim | grep Description | awk '{print $2}'`" = "mydesc";
90 echo "Testing printing WIM lookup table"
91 imagex info --lookup-table dir.wim
92 echo "Testing printing WIM header"
93 imagex info --header dir.wim
94 echo "Testing printing WIM XML info"
95 imagex info --xml dir.wim
96 echo "Testing extracting WIM XML info"
97 imagex info --extract-xml=dir.xml dir.wim
98 echo "Testing printing WIM metadata"
99 imagex info --metadata dir.wim
100 rm -rf dir.wim tmp dir.xml
101
102 echo "Testing capture of bootable WIM"
103 imagex capture dir dir.wim --boot
104 test "`imagex info dir.wim | grep Boot | awk '{print $3}'`" = "1";
105 rm -rf dir.wim tmp
106
107 # Integrity table
108
109 echo "Testing capture of WIM with integrity table"
110 imagex capture dir dir.wim --check
111 test "`imagex info dir.wim | grep Integrity | awk '{print $3}'`" = "yes";
112 imagex apply --check dir.wim tmp
113 diff -q -r dir tmp
114 rm -rf dir.wim tmp
115
116 # Appending and deleting images
117
118 echo "Testing appending WIM image"
119 imagex capture dir dir.wim
120 imagex append dir2 dir.wim
121 test "`imagex info dir.wim | grep 'Image Count' | awk '{print $3}'`" = 2;
122 echo "Testing appending WIM image with existing name (this should generate errors)"
123 ! imagex append dir2 dir.wim
124 echo "Testing appending WIM image with new name"
125 imagex append dir2 dir.wim "newname"
126 echo "Testing appending WIM image with integrity check"
127 imagex append dir2 dir.wim "newname2" --check
128 test "`imagex info dir.wim | grep Integrity | awk '{print $3}'`" = "yes";
129 echo "Testing appending WIM image with no integrity check"
130 imagex append dir2 dir.wim "newname3"
131 test "`imagex info dir.wim | grep Integrity | awk '{print $3}'`" = "no";
132 test "`imagex info dir.wim | grep 'Image Count' | awk '{print $3}'`" = 5;
133 echo "Testing deleting first WIM image"
134 imagex delete dir.wim 1
135 test "`imagex info dir.wim | grep 'Image Count' | awk '{print $3}'`" = 4;
136 echo "Testing deleting last WIM image"
137 imagex delete dir.wim 4
138 test "`imagex info dir.wim | grep 'Image Count' | awk '{print $3}'`" = 3;
139 echo "Testing deleting invalid WIM image (this should generate errors)"
140 ! imagex delete dir.wim 4
141 test "`imagex info dir.wim | grep 'Image Count' | awk '{print $3}'`" = 3;
142 echo "Testing deleting all WIM images"
143 imagex delete dir.wim all
144 test "`imagex info dir.wim | grep 'Image Count' | awk '{print $3}'`" = 0;
145 echo "Testing appending directory to empty WIM and making it bootable"
146 imagex append dir dir.wim "myname" "mydesc" --check --boot
147 test "`imagex info dir.wim | grep Integrity | awk '{print $3}'`" = "yes";
148 test "`imagex info dir.wim | grep Boot | awk '{print $3}'`" = "1";
149 echo "Testing appending non-directory (should generate errors)"
150 ! imagex append dir.wim dir.wim
151 echo "Testing appending non-existent file (should generate errors)"
152 ! imagex append SOME_NONEXISTENT_FILE dir.wim
153 echo "Testing appending directory containing unreadable file (should generate errors)"
154 mkdir -p dir3
155 touch dir3/file
156 chmod -r dir3/file
157 ! imagex append dir3 dir.wim
158 rm -rf dir3 dir.wim
159
160 # Applying multiple images, applying with hardlinks/symlinks
161
162 imagex capture dir dir.wim
163 imagex append dir dir.wim "myname"
164 echo "Testing application of multiple images"
165 imagex apply dir.wim all tmp
166 diff -q -r tmp/dir tmp/myname
167 test `stat -c %h tmp/dir/lz.c` = 1;
168 test `stat -c %h tmp/myname/lz.c` = 1;
169 test `stat -c %i tmp/myname/lz.c` != `stat -c %i tmp/dir/lz.c`;
170 rm -rf tmp
171 echo "Testing application of multiple images with hardlinks"
172 imagex apply dir.wim all tmp --hardlink
173 diff -q -r tmp/dir tmp/myname
174 test `stat -c %h tmp/dir/lz.c` = 2;
175 test `stat -c %h tmp/myname/lz.c` = 2;
176 test `stat -c %i tmp/myname/lz.c` = `stat -c %i tmp/dir/lz.c`;
177 rm -rf tmp
178 echo "Testing application of single image containing identical files"
179 imagex apply dir.wim 1 tmp
180 test `stat -c %h tmp/subdir/identical_file1` = 1;
181 test `stat -c %h tmp/subdir/identical_file2` = 1;
182 test `stat -c %i tmp/subdir/identical_file1` != `stat -c %i tmp/subdir/identical_file2`;
183 ! readlink tmp/subdir/identical_file1 && ! readlink tmp/subdir/identical_file2
184 rm -rf tmp
185
186 echo "Testing application of single image containing identical files with hardlinks"
187 imagex apply dir.wim 1 tmp --hardlink
188 test `stat -c %h tmp/subdir/identical_file1` = 2;
189 test `stat -c %h tmp/subdir/identical_file2` = 2;
190 test `stat -c %i tmp/subdir/identical_file1` = `stat -c %i tmp/subdir/identical_file2`;
191 ! readlink tmp/subdir/identical_file1 && ! readlink tmp/subdir/identical_file2
192 rm -rf tmp
193
194 echo "Testing application of single image containing identical files with symlinks"
195 imagex apply dir.wim 1 tmp --symlink
196 test `stat -c %h tmp/subdir/identical_file1` = 1;
197 test `stat -c %h tmp/subdir/identical_file2` = 1;
198 test `stat -c %i tmp/subdir/identical_file1` != `stat -c %i tmp/subdir/identical_file2`;
199 readlink tmp/subdir/identical_file1 > /dev/null || \
200                 readlink tmp/subdir/identical_file2 > /dev/null
201 rm -rf dir.wim tmp
202
203 # imagex mount
204
205 for flag in "--compress=none" "--compress=maximum" "--compress=fast"; do
206         echo "Using flag $flag"
207         echo "Testing mounting WIM read-only"
208         imagex capture dir dir.wim $flag
209         mkdir tmp
210         imagex mount dir.wim dir tmp
211         echo "Testing extracting file from mounted read-only WIM"
212         cp tmp/lz.c lz.c
213         diff -q dir/lz.c lz.c
214         diff -q tmp/lz.c dir/lz.c
215         rm -f lz.c
216         echo "Testing modifying mounted read-only WIM (should fail)"
217         ! rm tmp/lz.c
218         ! touch tmp/newfile
219         ! echo 3 > tmp/newfile
220         echo "Testing diff of mounted read-only WIM with original directory"
221         diff -q -r tmp dir
222         echo "Testing unmount of read-only filesystem"
223         imagex unmount tmp
224         echo "Testing unmount of read-only filesystem with --commit given"
225         imagex mount dir.wim dir tmp
226         imagex unmount tmp --commit
227         rm -rf tmp dir.wim
228 done
229
230 # imagex mountrw
231 for flag in "--compress=none" "--compress=maximum" "--compress=fast"; do
232         echo "Using flag $flag"
233         echo "Testing mounting WIM read-write"
234         imagex capture dir dir.wim $flag
235         mkdir tmp
236         imagex mountrw dir.wim dir tmp
237         echo "Testing unmounting WIM unmodified"
238         imagex unmount tmp
239         echo "Testing unmounting WIM unmodified with --commit and --check"
240         imagex mountrw dir.wim dir tmp
241         imagex unmount tmp --commit --check
242         echo "Testing removing file from mounted WIM"
243         imagex mountrw dir.wim dir tmp
244         rm tmp/lz.c
245         test ! -e tmp/lz.c
246         echo "Testing making directory in mounted WIM"
247         mkdir tmp/newdir
248         test -d tmp/newdir
249         echo "Testing making new empty file in mounted WIM"
250         touch tmp/newdir/empty_file
251         test -e tmp/newdir/empty_file
252         test `stat -c %s tmp/newdir/empty_file` = 0;
253         echo "Testing making new non-empty file in mounted WIM"
254         dd if=/dev/zero of=tmp/newdir/zeroes1 bs=1 count=4096
255         dd if=/dev/zero of=tmp/newdir/zeroes2 bs=4096 count=1
256         cmp tmp/newdir/zeroes1 tmp/newdir/zeroes2
257         echo "Unmounting WIM with changes committed and --check"
258         imagex unmount tmp --commit --check
259         test "`imagex info dir.wim | grep Integrity | awk '{print $3}'`" = "yes";
260         rm -rf tmp
261         imagex apply dir.wim tmp
262         cmp tmp/newdir/zeroes1 tmp/newdir/zeroes2
263         test `stat -c %s tmp/newdir/empty_file` = 0;
264         test `stat -c %s tmp/newdir/zeroes1` = 4096;
265         rm -rf tmp dir.wim
266 done
267
268 # imagex split, imagex join
269
270 echo "Creating random files to test WIM splitting on"
271 mkdir tmp
272 for i in `seq 1 100`; do
273         dd if=/dev/urandom of=tmp/file$i bs=4096 count=10 &> /dev/null
274 done
275 for flag in "--compress=none" "--compress=maximum" "--compress=fast"; do
276         echo "Using flag $flag"
277         imagex capture tmp tmp.wim $flag
278         echo "Splitting WIM into 1 MiB chunks"
279         imagex split tmp.wim tmp.swm 1
280         echo "Verifying the split WIMs (some errors expected)"
281         test "`imagex info tmp.swm | grep 'Part Number' | awk '{print $3}'`" = "1/4"
282         imagex dir tmp.swm > /dev/null
283         test -e tmp2.swm && ! imagex dir tmp2.swm
284         ! imagex info tmp.swm --boot 0 # Unsupported, should fail
285         echo "Joining the split WIMs and applying the result"
286         imagex join tmp2.wim tmp*.wim
287         imagex apply tmp2.wim tmp2
288         imagex apply tmp.wim tmp3
289         diff -q -r tmp tmp2
290         diff -q -r tmp tmp3
291         rm -f *.wim *.swm
292         rm -rf tmp2 tmp3
293 done
294 rm -rf tmp
295
296 # imagex export
297 echo "Testing export of single image to new WIM"
298 imagex capture dir dir.wim
299 imagex append dir2 dir.wim
300 imagex export dir.wim dir new.wim
301 test "`imagex info new.wim | grep 'Image Count' | awk '{print $3}'`" = 1;
302 echo "Testing export of single image to existing WIM"
303 imagex export dir.wim dir2 new.wim
304 test "`imagex info new.wim | grep 'Image Count' | awk '{print $3}'`" = 2;
305 echo "Testing export of single image to existing WIM using wrong compression type"
306 ! imagex export dir.wim dir2 new.wim newname --compress=maximum
307 rm -f new.wim
308 echo "Testing export of multiple images to new WIM"
309 imagex export dir.wim all new.wim
310 test "`imagex info new.wim | grep 'Image Count' | awk '{print $3}'`" = 2;
311 imagex capture dir2 new.wim newname
312 echo "Testing export of multiple images to existing WIM"
313 imagex export dir.wim all new.wim
314 echo "Testing export of multiple images to existing WIM with --boot"
315 imagex capture dir2 new.wim newname
316 imagex info dir.wim --boot 1
317 imagex export dir.wim all new.wim --boot
318 echo "Testing export of multiple images to existing WIM with --boot, but no bootable image (errors expected)"
319 imagex capture dir2 new.wim newname
320 imagex info dir.wim --boot 0
321 ! imagex export dir.wim all new.wim --boot