3 # This script does some sanity testing of the 'imagex' program. It by no means
4 # tests every aspect of wimlib comprehensively.
8 srcdir=`realpath $srcdir`
13 ../imagex "$@" > /dev/null
22 fusermount -u tmp &> /dev/null || true
23 rm -rf dir* tmp* *.wim *.swm
29 cp $srcdir/src/*.c $srcdir/src/*.h dir
31 echo 'hello' > dir/subdir/hello
32 echo 'hello' > dir/subdir/hello2
33 ln dir/subdir/hello dir/subdir/hellolink
34 echo -n > dir/subdir/empty_file
35 ln -s hello dir/subdir/rel_symlink
38 echo 'testing' > dir2/file
39 dd if=/dev/zero of=dir2/zeroes bs=4096 count=5
42 echo "**********************************************"
45 echo "**********************************************"
49 # Capturing and applying WIM with None, LZX, and XPRESS compression
51 for comp_type in None LZX XPRESS; do
52 echo "Testing capture and application of $comp_type-compressed WIM"
53 if ! imagex capture dir dir.wim --compress=$comp_type; then
54 error "'imagex capture' failed"
56 if ! imagex apply dir.wim tmp; then
57 error "'imagex apply' failed"
59 if ! test "`imagex_info dir.wim | grep Compression | awk '{print $2}'`" = "$comp_type"; then
60 error "'imagex_info' didn't report the compression type correctly"
62 if ! diff -q -r dir tmp; then
63 error "Recursive diff of extracted directory with original failed"
65 if ! test `stat -c %h tmp/subdir/hello` = 2; then
66 error "Incorrect number of hard links in extracted file"
68 if ! test `stat -c %i tmp/subdir/hello` != `stat -c %i tmp/subdir/hello2`; then
69 error "Expected different inode numbers in files not hard-linked"
71 if ! test "`stat -c %i tmp/subdir/hello`" = "`stat -c %i tmp/subdir/hellolink`"; then
72 error "Expected same inode numbers in hard-linked files"
74 if ! test -L tmp/subdir/rel_symlink; then
75 error "Symlink not extracted correctly"
77 if ! test "`readlink tmp/subdir/rel_symlink`" = "hello"; then
78 error "Symlink target not correct"
84 # Capturing and modifying name, description, and bootable flag
86 echo "Testing capture of WIM with default name and description"
87 imagex capture dir dir.wim
88 if ! test "`imagex_info dir.wim | grep Name | awk '{print $2}'`" = "dir"; then
89 error "WIM name not set correctly"
91 if ! test "`imagex_info dir.wim | grep Description | awk '{print $2}'`" = ""; then
92 error "WIM description not set correctly"
95 echo "Testing capture of WIM with default boot flag"
96 imagex capture dir dir.wim
97 if ! test "`imagex_info dir.wim | grep Boot | awk '{print $3}'`" = "0"; then
98 error "WIM boot flag not set correctly"
101 echo "Testing changing image bootable flag"
102 if ! imagex_info dir.wim 1 --boot; then
103 error "Failed to change bootable image"
105 if ! test "`imagex_info dir.wim | grep Boot | awk '{print $3}'`" = "1"; then
106 error "Bootable image not changed correctly"
108 echo "Testing changing image bootable flag"
109 if ! imagex_info dir.wim 0 --boot; then
110 error "Failed to reset bootable image"
112 if ! test "`imagex_info dir.wim | grep Boot | awk '{print $3}'`" = "0"; then
113 error "Bootable image not reset correctly"
115 echo "Testing changing image bootable flag to invalid image (this should generate errors)"
116 if imagex_info dir.wim 2 --boot; then
117 error "Succeeded in changing bootable image to invalid number"
119 if ! test "`imagex_info dir.wim | grep Boot | awk '{print $3}'`" = "0"; then
120 error "Boot flag was changed even though the change command was supposed to fail"
124 echo "Testing capture of WIM with name and description"
125 if ! imagex capture dir dir.wim "myname" "mydesc"; then
126 error "Failed to capture WIM with specified name and description"
128 if ! test "`imagex_info dir.wim | grep Name | awk '{print $2}'`" = "myname"; then
129 error "WIM name not set correctly"
131 if ! test "`imagex_info dir.wim | grep Description | awk '{print $2}'`" = "mydesc"; then
132 error "WIM name not set correctly"
134 echo "Testing printing WIM lookup table"
135 if ! imagex_info --lookup-table dir.wim > /dev/null; then
136 error "Failed to print WIM lookup table"
138 echo "Testing printing WIM header"
139 if ! imagex_info --header dir.wim > /dev/null; then
140 error "Failed to print WIM header"
142 echo "Testing printing WIM XML info"
143 if ! imagex_info --xml dir.wim > /dev/null; then
144 error "Failed to print WIM XML data"
146 echo "Testing extracting WIM XML info"
147 if ! imagex_info --extract-xml=dir.xml dir.wim; then
148 error "Failed to extract WIM XML data"
150 echo "Testing printing WIM metadata"
151 if ! imagex_info --metadata dir.wim > /dev/null; then
152 error "Failed to print WIM metadata"
154 rm -rf dir.wim tmp dir.xml
156 echo "Testing capture of bootable WIM"
157 if ! imagex capture dir dir.wim --boot; then
158 error "Failed to capture bootable WIM"
160 if ! test "`imagex_info dir.wim | grep Boot | awk '{print $3}'`" = "1"; then
161 error "Boot flag on bootable WIM not set correctly"
167 echo "Testing capture of WIM with integrity table"
168 if ! imagex capture dir dir.wim --check; then
169 error "Failed to capture WIM with integrity table"
171 if ! test "`imagex_info dir.wim | grep Integrity | awk '{print $3}'`" = "yes"; then
172 error "Integrity table on WIM not made"
174 if ! imagex apply --check dir.wim tmp; then
175 error "Integrity table on WIM not made correctly"
177 if ! diff -q -r dir tmp; then
178 error "Recursive diff of applied WIM with original directory failed"
182 # Appending and deleting images
184 echo "Testing appending WIM image"
185 imagex capture dir dir.wim
186 if ! imagex append dir2 dir.wim; then
187 error "Appending WIM image failed"
189 if ! test "`imagex_info dir.wim | grep 'Image Count' | awk '{print $3}'`" = 2; then
190 error "WIM image count not correct"
193 echo "Testing appending WIM image with existing name (this should generate errors)"
194 if imagex append dir2 dir.wim; then
195 error "Adding duplicate image name didn't fail"
197 echo "Testing appending WIM image with new name"
198 if ! imagex append dir2 dir.wim "newname"; then
199 error "Appending WIM image failed"
201 echo "Testing appending WIM image with integrity check"
202 if ! imagex append dir2 dir.wim "newname2" --check; then
203 error "Appending WIM image failed"
205 if ! test "`imagex_info dir.wim | grep Integrity | awk '{print $3}'`" = "yes"; then
206 error "Integrity table not set correctly on image append"
208 echo "Testing appending WIM image with no integrity check"
209 if ! imagex append dir2 dir.wim "newname3"; then
210 error "Appending WIM image failed"
212 if ! test "`imagex_info dir.wim | grep Integrity | awk '{print $3}'`" = "no"; then
213 error "WIM integrity table not removed"
215 # 5 images at this point
216 if ! test "`imagex_info dir.wim | grep 'Image Count' | awk '{print $3}'`" = 5; then
217 error "WIM does not contain the expected 5 images"
219 echo "Testing deleting first WIM image"
220 if ! imagex delete dir.wim 1; then
221 error "Failed to delete WIM image"
223 if ! test "`imagex_info dir.wim | grep 'Image Count' | awk '{print $3}'`" = 4; then
224 error "WIM image not deleted correctly"
226 echo "Testing deleting last WIM image"
227 if ! imagex delete dir.wim 4; then
228 error "Failed to delete WIM image"
230 if ! test "`imagex_info dir.wim | grep 'Image Count' | awk '{print $3}'`" = 3; then
231 error "WIM image not deleted correctly"
233 echo "Testing deleting invalid WIM image (this should generate errors)"
234 if imagex delete dir.wim 4; then
235 error "Expected to fail to delete non-existent WIM image"
237 if ! test "`imagex_info dir.wim | grep 'Image Count' | awk '{print $3}'`" = 3; then
238 error "Image count changed even though we intentionally failed to delete an image"
240 echo "Testing deleting all WIM images"
241 if ! imagex delete dir.wim all; then
242 error "Failed to delete all images from WIM"
244 if ! test "`imagex_info dir.wim | grep 'Image Count' | awk '{print $3}'`" = 0; then
245 error "Couldn't delete all WIM images correctly"
247 echo "Testing appending directory to empty WIM and making it bootable"
248 if ! imagex append dir dir.wim "myname" "mydesc" --check --boot; then
249 error "Couldn't append named, described, bootable image to empty WIM with integrity check"
251 if ! test "`imagex_info dir.wim | grep Integrity | awk '{print $3}'`" = "yes"; then
252 error "Integrity check not found"
254 if ! test "`imagex_info dir.wim | grep Boot | awk '{print $3}'`" = "1"; then
255 error "Bootable image not set correctly"
257 echo "Testing appending non-directory (should generate errors)"
258 if imagex append dir.wim dir.wim; then
259 error "Incorrectly succeeded to append non-directory to WIM"
261 echo "Testing appending non-existent file (should generate errors)"
262 if imagex append SOME_NONEXISTENT_FILE dir.wim; then
263 error "Incorrectly succeeded to append non-existent file to WIM"
265 if [ `id -u` != 0 ]; then
266 echo "Testing appending directory containing unreadable file (should generate errors)"
270 if imagex append dir3 dir.wim; then
271 error "Incorrectly succeeded in capturing directory with unreadable file"
276 # Applying multiple images, applying with hardlinks/symlinks
278 echo "Testing application of multiple images"
279 if ! imagex capture dir dir.wim; then
280 error "Failed to prepare test WIM"
282 if ! imagex append dir dir.wim "myname"; then
283 error "Failed to append image to test WIM"
285 if ! imagex apply dir.wim all tmp; then
286 error "Applying multiple images failed"
288 if ! diff -q -r tmp/dir tmp/myname || ! diff -q -r dir tmp/dir; then
289 error "Recursive diff of applied WIM with original directory failed"
291 if test "`stat -c %h tmp/dir/lz.c`" != 1; then
292 error "Incorrect link count on extracted file"
294 if test "`stat -c %h tmp/myname/lz.c`" != 1; then
295 error "Incorrect link count on extracted file"
297 if test "`stat -c %i tmp/myname/lz.c`" = "`stat -c %i tmp/dir/lz.c`"; then
298 error "Incorrect inode number"
301 echo "Testing application of multiple images with hardlinks"
302 if ! imagex apply dir.wim all tmp --hardlink; then
303 error "Failed to apply multiple images with cross-image hardlinks"
305 if ! diff -q -r tmp/dir tmp/myname || ! diff -q -r dir tmp/dir; then
306 error "Recursive diff of applied WIM with original directory failed"
308 if test "`stat -c %h tmp/dir/lz.c`" != 2; then
309 error "Incorrect link count on extracted file"
311 if test "`stat -c %h tmp/myname/lz.c`" != 2; then
312 error "Incorrect link count on extracted file"
314 if test "`stat -c %i tmp/myname/lz.c`" != "`stat -c %i tmp/dir/lz.c`"; then
315 error "Incorrect inode number"
319 echo "Testing application of single image containing identical files"
320 if ! imagex apply dir.wim 1 tmp; then
321 error "Failed to apply WIM"
323 if test "`stat -c %h tmp/subdir/hello`" != 2; then
324 error "Incorrect link count on extracted file"
326 if test "`stat -c %h tmp/subdir/hello2`" != 1; then
327 error "Incorrect link count on extracted file"
329 if test "`stat -c %i tmp/subdir/hello`" = "`stat -c %i tmp/subdir/hello2`"; then
330 error "Inode numbers on non-hard-linked files are the same"
332 if test "`stat -c %i tmp/subdir/hello`" != "`stat -c %i tmp/subdir/hellolink`"; then
333 error "Inode numbers on hard-linked files are different"
337 echo "Testing application of single image containing identical files with hardlinks"
338 if ! imagex apply dir.wim 1 tmp --hardlink; then
339 error "Failed to apply WIM"
341 if test "`stat -c %h tmp/subdir/hello`" != 3; then
342 error "Incorrect link count on extracted file"
344 if test "`stat -c %h tmp/subdir/hello2`" != 3; then
345 error "Incorrect link count on extracted file"
347 if test "`stat -c %i tmp/subdir/hello`" != "`stat -c %i tmp/subdir/hello2`"; then
348 error "Hard link set does not share inode number"
350 if test "`stat -c %i tmp/subdir/hello`" != "`stat -c %i tmp/subdir/hellolink`"; then
351 error "Hard link set does not share inode number"
355 echo "Testing application of single image containing identical files with symlinks"
356 if ! imagex apply dir.wim 1 tmp --symlink; then
357 error "Failed to apply WIM"
359 if test "`stat -c %h tmp/subdir/hello`" != 1; then
360 error "Incorrect link count on extracted file"
362 if test "`stat -c %h tmp/subdir/hello2`" != 1; then
363 error "Incorrect link count on extracted file"
365 if test "`stat -c %i tmp/subdir/hello`" = "`stat -c %i tmp/subdir/hello2`"; then
366 error "Incorrect inode number"
368 if ! test -L tmp/subdir/hello -o -L tmp/subdir/hello2 -o -L tmp/subdir/hellolink; then
369 error "Expected symlinks, but found non-symlinks"
374 # imagex split, imagex join
376 echo "Creating random files to test WIM splitting on"
378 for i in `seq 1 100`; do
379 dd if=/dev/urandom of=tmp/file$i bs=4096 count=10 &> /dev/null
381 for flag in "--compress=none" "--compress=maximum" "--compress=fast"; do
382 echo "Using flag $flag"
383 if ! imagex capture tmp tmp.wim $flag; then
384 error "Failed to capture test WIM"
386 echo "Splitting WIM into 1 MiB chunks"
387 if ! imagex split tmp.wim tmp.swm 1; then
388 error "Failed to split WIM"
390 echo "Verifying the split WIMs (some errors expected)"
391 if test "`imagex_info tmp.swm | grep 'Part Number' | awk '{print $3}'`" != "1/4"; then
392 error "Part number of split WIM not correct"
394 if ! imagex dir tmp.swm > /dev/null; then
395 error "Failed to list files in split WIM"
397 if ! test -e tmp2.swm; then
398 error "Could not find split-WIM part 2"
400 if imagex dir tmp2.swm > /dev/null; then
401 error "Listed files in part 2 of split WIM (this should have failed)"
404 # Unsupported, should fail
405 if imagex_info tmp.swm --boot 0; then
406 error "Should not have been able to change boot index of split WIM"
408 echo "Joining the split WIMs and applying the result"
409 if ! imagex join tmp2.wim tmp*.wim; then
410 error "Failed to join split WIMs"
412 if ! imagex apply tmp2.wim tmp2; then
413 error "Failed to apply joined split WIM"
415 if ! imagex apply tmp.wim tmp3; then
416 error "Failed to apply test WIM"
418 if ! diff -q -r tmp tmp2 || ! diff -q -r tmp tmp3; then
419 error "Recursive diff of applied joined split WIM with original directory failed"
427 echo "Testing export of single image to new WIM"
428 if ! imagex capture dir dir.wim; then
429 error "Failed to capture test WIM"
431 if ! imagex append dir2 dir.wim; then
432 error "Failed to append image to test WIM"
434 if ! imagex export dir.wim dir new.wim; then
435 error "Failed to export single image to new WIM"
437 if test "`imagex_info new.wim | grep 'Image Count' | awk '{print $3}'`" != 1; then
438 error "Exporting single image to new WIM wasn't done correctly"
440 echo "Testing export of single image to existing WIM"
441 if ! imagex export dir.wim dir2 new.wim; then
442 error "Failed to export single image to existing WIM"
444 if test "`imagex_info new.wim | grep 'Image Count' | awk '{print $3}'`" != 2; then
445 error "Exporting single image to existing WIM wasn't done correctly"
447 echo "Testing export of single image to existing WIM using wrong compression type"
448 if imagex export dir.wim dir2 new.wim newname --compress=maximum; then
449 error "Successfully exported image using wrong compression type"
452 echo "Testing export of multiple images to new WIM"
453 if ! imagex export dir.wim all new.wim; then
454 error "Failed to export multiple images to new WIM"
456 if test "`imagex_info new.wim | grep 'Image Count' | awk '{print $3}'`" != 2; then
457 error "Exporting multiple images to new WIM wasn't done correctly"
459 if ! imagex capture dir2 new.wim newname; then
460 error "Failed to capture test WIM"
462 echo "Testing export of multiple images to existing WIM"
463 if ! imagex export dir.wim all new.wim; then
464 error "Failed to export multiple images to existing WIM"
466 echo "Testing export of multiple images to existing WIM with --boot"
467 if ! imagex capture dir2 new.wim newname; then
468 error "Failed to capture test WIM"
470 if ! imagex_info dir.wim --boot 1; then
471 error "Failed to set boot index on test WIM"
473 if ! imagex export dir.wim all new.wim --boot; then
474 error "Failed to export multiple images to existing WIM with bootable image"
476 echo "Testing export of multiple images to existing WIM with --boot, but no bootable image (errors expected)"
477 if ! imagex capture dir2 new.wim newname; then
478 error "Failed to capture test WIM"
480 if ! imagex_info dir.wim --boot 0; then
481 error "Failed to clear boot index on test WIM"
483 if imagex export dir.wim all new.wim --boot; then
484 error "Successfully exported multiple images with --boot but with no bootable images"
487 # Test exporting an image to another WIM, then applying it.
488 # We try with 5 different combinations of compression types to make sure we go
489 # through all paths in the resource-handling code.
490 for i in `seq 1 3`; do
493 cflag1="--compress=none";
494 cflag2="--compress=none";
497 cflag1="--compress=xpress";
498 cflag2="--compress=xpress";
501 cflag1="--compress=xpress"
502 cflag2="--compress=lzx"
505 cflag1="--compress=none"
506 cflag2="--compress=xpress"
509 cflag1="--compress=xpress"
510 cflag2="--compress=none"
513 echo "Testing exporting then applying an image (\"$cflag1\" => \"$cflag2\")"
514 rm -rf dir.wim new.wim tmp tmp2
515 imagex capture dir dir.wim $cflag1
516 imagex capture dir2 dir2.wim $cflag2
517 imagex export dir.wim dir dir2.wim
518 imagex apply dir.wim dir tmp
519 if ! imagex apply dir2.wim dir tmp2; then
520 error "Failed to apply image that was exported to a WIM"
522 if ! diff -r tmp tmp2; then
523 error "Image that was exported to a WIM was not applied correctly"
527 echo "**********************************************************"
528 echo " Basic imagex tests passed "
529 echo "**********************************************************"