3 # This script does some sanity testing of the 'imagex' program. It by no means
4 # tests every aspect of wimlib comprehensively.
6 # Assume an in-tree build.
16 if [ -d tmp ] && mountpoint tmp > /dev/null; then
17 fusermount -u tmp > /dev/null;
19 rm -rf dir* tmp* *.wim *.swm
25 cp ../src/*.c ../src/*.h dir
27 echo 'hello' > dir/subdir/hello
28 echo 'hello' > dir/subdir/hello2
29 ln dir/subdir/hello dir/subdir/hellolink
30 echo -n > dir/subdir/empty_file
31 ln -s hello dir/subdir/rel_symlink
34 echo 'testing' > dir2/file
35 dd if=/dev/zero of=dir2/zeroes bs=4096 count=5
38 echo "**********************************************"
41 echo "**********************************************"
45 # Capturing and applying WIM with None, LZX, and XPRESS compression
47 for comp_type in None LZX XPRESS; do
48 echo "Testing capture and application of $comp_type-compressed WIM"
49 if ! imagex capture dir dir.wim --compress=$comp_type; then
50 error "'imagex capture' failed"
52 if ! imagex apply dir.wim tmp; then
53 error "'imagex apply' failed"
55 if ! test "`imagex info dir.wim | grep Compression | awk '{print $2}'`" = "$comp_type"; then
56 error "'imagex info' didn't report the compression type correctly"
58 if ! diff -q -r dir tmp; then
59 error "Recursive diff of extracted directory with original failed"
61 if ! test `stat -c %h tmp/subdir/hello` = 2; then
62 error "Incorrect number of hard links in extracted file"
64 if ! test `stat -c %i tmp/subdir/hello` != `stat -c %i tmp/subdir/hello2`; then
65 error "Expected different inode numbers in files not hard-linked"
67 if ! test "`stat -c %i tmp/subdir/hello`" = "`stat -c %i tmp/subdir/hellolink`"; then
68 error "Expected same inode numbers in hard-linked files"
70 if ! test -L tmp/subdir/rel_symlink; then
71 error "Symlink not extracted correctly"
73 if ! test "`readlink tmp/subdir/rel_symlink`" = "hello"; then
74 error "Symlink target not correct"
80 # Capturing and modifying name, description, and bootable flag
82 echo "Testing capture of WIM with default name and description"
83 imagex capture dir dir.wim
84 if ! test "`imagex info dir.wim | grep Name | awk '{print $2}'`" = "dir"; then
85 error "WIM name not set correctly"
87 if ! test "`imagex info dir.wim | grep Description | awk '{print $2}'`" = ""; then
88 error "WIM description not set correctly"
91 echo "Testing capture of WIM with default boot flag"
92 imagex capture dir dir.wim
93 if ! test "`imagex info dir.wim | grep Boot | awk '{print $3}'`" = "0"; then
94 error "WIM boot flag not set correctly"
97 echo "Testing changing image bootable flag"
98 if ! imagex info dir.wim 1 --boot; then
99 error "Failed to change bootable image"
101 if ! test "`imagex info dir.wim | grep Boot | awk '{print $3}'`" = "1"; then
102 error "Bootable image not changed correctly"
104 echo "Testing changing image bootable flag"
105 if ! imagex info dir.wim 0 --boot; then
106 error "Failed to reset bootable image"
108 if ! test "`imagex info dir.wim | grep Boot | awk '{print $3}'`" = "0"; then
109 error "Bootable image not reset correctly"
111 echo "Testing changing image bootable flag to invalid image (this should generate errors)"
112 if imagex info dir.wim 2 --boot; then
113 error "Succeeded in changing bootable image to invalid number"
115 if ! test "`imagex info dir.wim | grep Boot | awk '{print $3}'`" = "0"; then
116 error "Boot flag was changed even though the change command was supposed to fail"
120 echo "Testing capture of WIM with name and description"
121 if ! imagex capture dir dir.wim "myname" "mydesc"; then
122 error "Failed to capture WIM with specified name and description"
124 if ! test "`imagex info dir.wim | grep Name | awk '{print $2}'`" = "myname"; then
125 error "WIM name not set correctly"
127 if ! test "`imagex info dir.wim | grep Description | awk '{print $2}'`" = "mydesc"; then
128 error "WIM name not set correctly"
130 echo "Testing printing WIM lookup table"
131 if ! imagex info --lookup-table dir.wim > /dev/null; then
132 error "Failed to print WIM lookup table"
134 echo "Testing printing WIM header"
135 if ! imagex info --header dir.wim > /dev/null; then
136 error "Failed to print WIM header"
138 echo "Testing printing WIM XML info"
139 if ! imagex info --xml dir.wim > /dev/null; then
140 error "Failed to print WIM XML data"
142 echo "Testing extracting WIM XML info"
143 if ! imagex info --extract-xml=dir.xml dir.wim; then
144 error "Failed to extract WIM XML data"
146 echo "Testing printing WIM metadata"
147 if ! imagex info --metadata dir.wim > /dev/null; then
148 error "Failed to print WIM metadata"
150 rm -rf dir.wim tmp dir.xml
152 echo "Testing capture of bootable WIM"
153 if ! imagex capture dir dir.wim --boot; then
154 error "Failed to capture bootable WIM"
156 if ! test "`imagex info dir.wim | grep Boot | awk '{print $3}'`" = "1"; then
157 error "Boot flag on bootable WIM not set correctly"
163 echo "Testing capture of WIM with integrity table"
164 if ! imagex capture dir dir.wim --check; then
165 error "Failed to capture WIM with integrity table"
167 if ! test "`imagex info dir.wim | grep Integrity | awk '{print $3}'`" = "yes"; then
168 error "Integrity table on WIM not made"
170 if ! imagex apply --check dir.wim tmp; then
171 error "Integrity table on WIM not made correctly"
173 if ! diff -q -r dir tmp; then
174 error "Recursive diff of applied WIM with original directory failed"
178 # Appending and deleting images
180 echo "Testing appending WIM image"
181 imagex capture dir dir.wim
182 if ! imagex append dir2 dir.wim; then
183 error "Appending WIM image failed"
185 if ! test "`imagex info dir.wim | grep 'Image Count' | awk '{print $3}'`" = 2; then
186 error "WIM image count not correct"
189 echo "Testing appending WIM image with existing name (this should generate errors)"
190 if imagex append dir2 dir.wim; then
191 error "Adding duplicate image name didn't fail"
193 echo "Testing appending WIM image with new name"
194 if ! imagex append dir2 dir.wim "newname"; then
195 error "Appending WIM image failed"
197 echo "Testing appending WIM image with integrity check"
198 if ! imagex append dir2 dir.wim "newname2" --check; then
199 error "Appending WIM image failed"
201 if ! test "`imagex info dir.wim | grep Integrity | awk '{print $3}'`" = "yes"; then
202 error "Integrity table not set correctly on image append"
204 echo "Testing appending WIM image with no integrity check"
205 if ! imagex append dir2 dir.wim "newname3"; then
206 error "Appending WIM image failed"
208 if ! test "`imagex info dir.wim | grep Integrity | awk '{print $3}'`" = "no"; then
209 error "WIM integrity table not removed"
211 # 5 images at this point
212 if ! test "`imagex info dir.wim | grep 'Image Count' | awk '{print $3}'`" = 5; then
213 error "WIM does not contain the expected 5 images"
215 echo "Testing deleting first WIM image"
216 if ! imagex delete dir.wim 1; then
217 error "Failed to delete WIM image"
219 if ! test "`imagex info dir.wim | grep 'Image Count' | awk '{print $3}'`" = 4; then
220 error "WIM image not deleted correctly"
222 echo "Testing deleting last WIM image"
223 if ! imagex delete dir.wim 4; then
224 error "Failed to delete WIM image"
226 if ! test "`imagex info dir.wim | grep 'Image Count' | awk '{print $3}'`" = 3; then
227 error "WIM image not deleted correctly"
229 echo "Testing deleting invalid WIM image (this should generate errors)"
230 if imagex delete dir.wim 4; then
231 error "Expected to fail to delete non-existent WIM image"
233 if ! test "`imagex info dir.wim | grep 'Image Count' | awk '{print $3}'`" = 3; then
234 error "Image count changed even though we intentionally failed to delete an image"
236 echo "Testing deleting all WIM images"
237 if ! imagex delete dir.wim all; then
238 error "Failed to delete all images from WIM"
240 if ! test "`imagex info dir.wim | grep 'Image Count' | awk '{print $3}'`" = 0; then
241 error "Couldn't delete all WIM images correctly"
243 echo "Testing appending directory to empty WIM and making it bootable"
244 if ! imagex append dir dir.wim "myname" "mydesc" --check --boot; then
245 error "Couldn't append named, described, bootable image to empty WIM with integrity check"
247 if ! test "`imagex info dir.wim | grep Integrity | awk '{print $3}'`" = "yes"; then
248 error "Integrity check not found"
250 if ! test "`imagex info dir.wim | grep Boot | awk '{print $3}'`" = "1"; then
251 error "Bootable image not set correctly"
253 echo "Testing appending non-directory (should generate errors)"
254 if imagex append dir.wim dir.wim; then
255 error "Incorrectly succeeded to append non-directory to WIM"
257 echo "Testing appending non-existent file (should generate errors)"
258 if imagex append SOME_NONEXISTENT_FILE dir.wim; then
259 error "Incorrectly succeeded to append non-existent file to WIM"
261 echo "Testing appending directory containing unreadable file (should generate errors)"
265 if imagex append dir3 dir.wim; then
266 error "Incorrectly succeeded in capturing directory with unreadable file"
270 # Applying multiple images, applying with hardlinks/symlinks
272 echo "Testing application of multiple images"
273 if ! imagex capture dir dir.wim; then
274 error "Failed to prepare test WIM"
276 if ! imagex append dir dir.wim "myname"; then
277 error "Failed to append image to test WIM"
279 if ! imagex apply dir.wim all tmp; then
280 error "Applying multiple images failed"
282 if ! diff -q -r tmp/dir tmp/myname || ! diff -q -r dir tmp/dir; then
283 error "Recursive diff of applied WIM with original directory failed"
285 if test "`stat -c %h tmp/dir/lz.c`" != 1; then
286 error "Incorrect link count on extracted file"
288 if test "`stat -c %h tmp/myname/lz.c`" != 1; then
289 error "Incorrect link count on extracted file"
291 if test "`stat -c %i tmp/myname/lz.c`" = "`stat -c %i tmp/dir/lz.c`"; then
292 error "Incorrect inode number"
295 echo "Testing application of multiple images with hardlinks"
296 if ! imagex apply dir.wim all tmp --hardlink; then
297 error "Failed to apply multiple images with cross-image hardlinks"
299 if ! diff -q -r tmp/dir tmp/myname || ! diff -q -r dir tmp/dir; then
300 error "Recursive diff of applied WIM with original directory failed"
302 if test "`stat -c %h tmp/dir/lz.c`" != 2; then
303 error "Incorrect link count on extracted file"
305 if test "`stat -c %h tmp/myname/lz.c`" != 2; then
306 error "Incorrect link count on extracted file"
308 if test "`stat -c %i tmp/myname/lz.c`" != "`stat -c %i tmp/dir/lz.c`"; then
309 error "Incorrect inode number"
313 echo "Testing application of single image containing identical files"
314 if ! imagex apply dir.wim 1 tmp; then
315 error "Failed to apply WIM"
317 if test "`stat -c %h tmp/subdir/hello`" != 2; then
318 error "Incorrect link count on extracted file"
320 if test "`stat -c %h tmp/subdir/hello2`" != 1; then
321 error "Incorrect link count on extracted file"
323 if test "`stat -c %i tmp/subdir/hello`" = "`stat -c %i tmp/subdir/hello2`"; then
324 error "Inode numbers on non-hard-linked files are the same"
326 if test "`stat -c %i tmp/subdir/hello`" != "`stat -c %i tmp/subdir/hellolink`"; then
327 error "Inode numbers on hard-linked files are different"
331 echo "Testing application of single image containing identical files with hardlinks"
332 if ! imagex apply dir.wim 1 tmp --hardlink; then
333 error "Failed to apply WIM"
335 if test "`stat -c %h tmp/subdir/hello`" != 3; then
336 error "Incorrect link count on extracted file"
338 if test "`stat -c %h tmp/subdir/hello2`" != 3; then
339 error "Incorrect link count on extracted file"
341 if test "`stat -c %i tmp/subdir/hello`" != "`stat -c %i tmp/subdir/hello2`"; then
342 error "Hard link set does not share inode number"
344 if test "`stat -c %i tmp/subdir/hello`" != "`stat -c %i tmp/subdir/hellolink`"; then
345 error "Hard link set does not share inode number"
349 echo "Testing application of single image containing identical files with symlinks"
350 if ! imagex apply dir.wim 1 tmp --symlink; then
351 error "Failed to apply WIM"
353 if test "`stat -c %h tmp/subdir/hello`" != 1; then
354 error "Incorrect link count on extracted file"
356 if test "`stat -c %h tmp/subdir/hello2`" != 1; then
357 error "Incorrect link count on extracted file"
359 if test "`stat -c %i tmp/subdir/hello`" = "`stat -c %i tmp/subdir/hello2`"; then
360 error "Incorrect inode number"
362 if ! test -L tmp/subdir/hello || ! test -L tmp/subdir/hello2; then
363 error "Expected symlinks, but found non-symlinks"
369 for flag in "--compress=none" "--compress=maximum" "--compress=fast"; do
370 echo "Using flag $flag"
371 echo "Testing mounting WIM read-only"
372 if ! imagex capture dir dir.wim $flag; then
373 error "Failed to capture WIM"
376 if ! imagex mount dir.wim dir tmp; then
377 error "Failde to mount test WIM read-only"
379 echo "Testing extracting file from mounted read-only WIM"
380 if ! cp tmp/lz.c lz.c; then
381 error "Failed to extract file from read-only mounted WIM"
383 if ! diff -q dir/lz.c lz.c; then
384 error "Extracted file does not match copy in mounted WIM"
386 if ! diff -q tmp/lz.c dir/lz.c; then
387 error "Extractef file does not match original"
390 echo "Testing modifying mounted read-only WIM (should fail)"
392 error "Removing file from read-only mounted WIM didn't fail"
394 if touch tmp/newfile; then
395 error "Creating file on read-only mounted WIM didn't fail"
397 if echo 3 > tmp/lz.c; then
398 error "Writing to file on read-only mounted WIM didn't fail"
400 echo "Testing diff of mounted read-only WIM with original directory"
401 if ! diff -q -r tmp dir; then
402 error "Recursive diff of read-only mounted WIM with original directory failed"
404 echo "Testing unmount of read-only filesystem"
405 if ! imagex unmount tmp; then
406 error "Unmounting read-only WIM failed"
408 echo "Testing unmount of read-only filesystem with --commit given"
409 if ! imagex mount dir.wim dir tmp; then
410 error "Failed to re-mount WIM read-only"
412 if ! imagex unmount tmp --commit; then
413 error "Failed to unmount read-only WIM with --commit flag (should be ignored)"
419 echo "Testing mounting WIM read-write"
420 if ! imagex capture dir dir.wim; then
421 error "Failed to capture WIM"
424 if ! imagex mountrw dir.wim dir tmp; then
425 error "Failed to mount test WIM read-write"
427 echo "Testing unmounting WIM unmodified"
428 if ! imagex unmount tmp; then
429 error "Failed to unmount test WIM unmodified"
431 echo "Testing unmounting WIM unmodified with --commit and --check"
432 if ! imagex mountrw dir.wim dir tmp; then
433 error "Failed to re-mount test WIM read-write"
435 if ! imagex unmount tmp --commit --check; then
436 error "Failed to unmount read-write mounted WIM with changes commited (no changes made)"
438 echo "Testing removing file from mounted WIM"
439 if ! imagex mountrw dir.wim dir tmp; then
440 error "Failed to re-mount test WIM read-write"
442 if ! rm tmp/lz.c; then
443 error "Failed to remove file from read-write mounted WIM"
445 if test -f tmp/lz.c; then
446 error "Removing file from read-write mounted WIM failed"
448 echo "Testing making directory in mounted WIM"
449 if ! mkdir tmp/newdir; then
450 error "Failed to make directory in read-write mounted WIM"
452 if ! test -d tmp/newdir; then
453 error "Making directory in read-write mounted WIM failed"
455 echo "Testing making new empty file in mounted WIM"
456 if ! touch tmp/newdir/empty_file; then
457 error "Could not create new empty file in read-write mounted WIM"
459 if ! test -f tmp/newdir/empty_file; then
460 error "New empty file not created correctly in read-write mounted WIM"
462 if ! test "`stat -c %s tmp/newdir/empty_file`" = 0; then
463 error "New empty file in read-write mounted WIM is not empty"
465 echo "Testing making new non-empty file in mounted WIM"
466 if ! dd if=/dev/zero of=tmp/newdir/zeroes1 bs=1 count=4096; then
467 error "Failed to make new non-empty file in mounted WIM"
469 if ! dd if=/dev/zero of=tmp/newdir/zeroes2 bs=4096 count=1; then
470 error "Failed to make new non-empty file in mounted WIM"
472 if ! diff -q tmp/newdir/zeroes1 tmp/newdir/zeroes2; then
473 error "New files in mounted WIM not made correctly"
475 echo "Unmounting WIM with changes committed and --check"
476 if ! imagex unmount tmp --commit --check; then
477 error "Failed to unmount read-write mounted WIM"
479 if test "`imagex info dir.wim | grep Integrity | awk '{print $3}'`" != "yes"; then
480 error "Integrity information was not included"
483 if ! imagex apply dir.wim tmp; then
484 error "Failed to apply WIM we had previously mounted read-write"
486 if ! diff -q tmp/newdir/zeroes1 tmp/newdir/zeroes2; then
487 error "The new non-empty files we made in the read-write mounted WIM were not extracted correctly"
489 if test `stat -c %s tmp/newdir/empty_file` != 0; then
490 error "The new empty file we made in the read-write mounted WIM was not extracted correctly"
492 if test `stat -c %s tmp/newdir/zeroes1` != 4096; then
493 error "The new non-empty files we made in the read-write mounted WIM were not extracted correctly"
497 # imagex split, imagex join
499 echo "Creating random files to test WIM splitting on"
501 for i in `seq 1 100`; do
502 dd if=/dev/urandom of=tmp/file$i bs=4096 count=10 &> /dev/null
504 for flag in "--compress=none" "--compress=maximum" "--compress=fast"; do
505 echo "Using flag $flag"
506 if ! imagex capture tmp tmp.wim $flag; then
507 error "Failed to capture test WIM"
509 echo "Splitting WIM into 1 MiB chunks"
510 if ! imagex split tmp.wim tmp.swm 1; then
511 error "Failed to split WIM"
513 echo "Verifying the split WIMs (some errors expected)"
514 if test "`imagex info tmp.swm | grep 'Part Number' | awk '{print $3}'`" != "1/4"; then
515 error "Part number of split WIM not correct"
517 if ! imagex dir tmp.swm > /dev/null; then
518 error "Failed to list files in split WIM"
520 if ! test -e tmp2.swm; then
521 error "Could not find split-WIM part 2"
523 if imagex dir tmp2.swm > /dev/null; then
524 error "Listed files in part 2 of split WIM (this should have failed)"
527 # Unsupported, should fail
528 if imagex info tmp.swm --boot 0; then
529 error "Should not have been able to change boot index of split WIM"
531 echo "Joining the split WIMs and applying the result"
532 if ! imagex join tmp2.wim tmp*.wim; then
533 error "Failed to join split WIMs"
535 if ! imagex apply tmp2.wim tmp2; then
536 error "Failed to apply joined split WIM"
538 if ! imagex apply tmp.wim tmp3; then
539 error "Failed to apply test WIM"
541 if ! diff -q -r tmp tmp2 || ! diff -q -r tmp tmp3; then
542 error "Recursive diff of applied joined split WIM with original directory failed"
550 echo "Testing export of single image to new WIM"
551 if ! imagex capture dir dir.wim; then
552 error "Failed to capture test WIM"
554 if ! imagex append dir2 dir.wim; then
555 error "Failed to append image to test WIM"
557 if ! imagex export dir.wim dir new.wim; then
558 error "Failed to export single image to new WIM"
560 if test "`imagex info new.wim | grep 'Image Count' | awk '{print $3}'`" != 1; then
561 error "Exporting single image to new WIM wasn't done correctly"
563 echo "Testing export of single image to existing WIM"
564 if ! imagex export dir.wim dir2 new.wim; then
565 error "Failed to export single image to existing WIM"
567 if test "`imagex info new.wim | grep 'Image Count' | awk '{print $3}'`" != 2; then
568 error "Exporting single image to existing WIM wasn't done correctly"
570 echo "Testing export of single image to existing WIM using wrong compression type"
571 if imagex export dir.wim dir2 new.wim newname --compress=maximum; then
572 error "Successfully exported image using wrong compression type"
575 echo "Testing export of multiple images to new WIM"
576 if ! imagex export dir.wim all new.wim; then
577 error "Failed to export multiple images to new WIM"
579 if test "`imagex info new.wim | grep 'Image Count' | awk '{print $3}'`" != 2; then
580 error "Exporting multiple images to new WIM wasn't done correctly"
582 if ! imagex capture dir2 new.wim newname; then
583 error "Failed to capture test WIM"
585 echo "Testing export of multiple images to existing WIM"
586 if ! imagex export dir.wim all new.wim; then
587 error "Failed to export multiple images to existing WIM"
589 echo "Testing export of multiple images to existing WIM with --boot"
590 if ! imagex capture dir2 new.wim newname; then
591 error "Failed to capture test WIM"
593 if ! imagex info dir.wim --boot 1; then
594 error "Failed to set boot index on test WIM"
596 if ! imagex export dir.wim all new.wim --boot; then
597 error "Failed to export multiple images to existing WIM with bootable image"
599 echo "Testing export of multiple images to existing WIM with --boot, but no bootable image (errors expected)"
600 if ! imagex capture dir2 new.wim newname; then
601 error "Failed to capture test WIM"
603 if ! imagex info dir.wim --boot 0; then
604 error "Failed to clear boot index on test WIM"
606 if imagex export dir.wim all new.wim --boot; then
607 error "Successfully exported multiple images with --boot but with no bootable images"
610 echo "**********************************************************"
611 echo " All tests passed "
612 echo "**********************************************************"