3 # This script does some sanity testing of the 'imagex' program. It by no means
4 # tests every aspect of wimlib comprehensively.
7 srcdir=`realpath $srcdir`
16 if [ -d tmp ] && mountpoint tmp > /dev/null; then
17 fusermount -u tmp > /dev/null;
19 rm -rf dir* tmp* *.wim *.swm
22 fusermount -u tmp || true
27 cp $srcdir/src/*.c $srcdir/src/*.h dir
29 echo 'hello' > dir/subdir/hello
30 echo 'hello' > dir/subdir/hello2
31 ln dir/subdir/hello dir/subdir/hellolink
32 echo -n > dir/subdir/empty_file
33 ln -s hello dir/subdir/rel_symlink
36 echo 'testing' > dir2/file
37 dd if=/dev/zero of=dir2/zeroes bs=4096 count=5
40 echo "**********************************************"
43 echo "**********************************************"
47 # Capturing and applying WIM with None, LZX, and XPRESS compression
49 for comp_type in None LZX XPRESS; do
50 echo "Testing capture and application of $comp_type-compressed WIM"
51 if ! imagex capture dir dir.wim --compress=$comp_type; then
52 error "'imagex capture' failed"
54 if ! imagex apply dir.wim tmp; then
55 error "'imagex apply' failed"
57 if ! test "`imagex info dir.wim | grep Compression | awk '{print $2}'`" = "$comp_type"; then
58 error "'imagex info' didn't report the compression type correctly"
60 if ! diff -q -r dir tmp; then
61 error "Recursive diff of extracted directory with original failed"
63 if ! test `stat -c %h tmp/subdir/hello` = 2; then
64 error "Incorrect number of hard links in extracted file"
66 if ! test `stat -c %i tmp/subdir/hello` != `stat -c %i tmp/subdir/hello2`; then
67 error "Expected different inode numbers in files not hard-linked"
69 if ! test "`stat -c %i tmp/subdir/hello`" = "`stat -c %i tmp/subdir/hellolink`"; then
70 error "Expected same inode numbers in hard-linked files"
72 if ! test -L tmp/subdir/rel_symlink; then
73 error "Symlink not extracted correctly"
75 if ! test "`readlink tmp/subdir/rel_symlink`" = "hello"; then
76 error "Symlink target not correct"
82 # Capturing and modifying name, description, and bootable flag
84 echo "Testing capture of WIM with default name and description"
85 imagex capture dir dir.wim
86 if ! test "`imagex info dir.wim | grep Name | awk '{print $2}'`" = "dir"; then
87 error "WIM name not set correctly"
89 if ! test "`imagex info dir.wim | grep Description | awk '{print $2}'`" = ""; then
90 error "WIM description not set correctly"
93 echo "Testing capture of WIM with default boot flag"
94 imagex capture dir dir.wim
95 if ! test "`imagex info dir.wim | grep Boot | awk '{print $3}'`" = "0"; then
96 error "WIM boot flag not set correctly"
99 echo "Testing changing image bootable flag"
100 if ! imagex info dir.wim 1 --boot; then
101 error "Failed to change bootable image"
103 if ! test "`imagex info dir.wim | grep Boot | awk '{print $3}'`" = "1"; then
104 error "Bootable image not changed correctly"
106 echo "Testing changing image bootable flag"
107 if ! imagex info dir.wim 0 --boot; then
108 error "Failed to reset bootable image"
110 if ! test "`imagex info dir.wim | grep Boot | awk '{print $3}'`" = "0"; then
111 error "Bootable image not reset correctly"
113 echo "Testing changing image bootable flag to invalid image (this should generate errors)"
114 if imagex info dir.wim 2 --boot; then
115 error "Succeeded in changing bootable image to invalid number"
117 if ! test "`imagex info dir.wim | grep Boot | awk '{print $3}'`" = "0"; then
118 error "Boot flag was changed even though the change command was supposed to fail"
122 echo "Testing capture of WIM with name and description"
123 if ! imagex capture dir dir.wim "myname" "mydesc"; then
124 error "Failed to capture WIM with specified name and description"
126 if ! test "`imagex info dir.wim | grep Name | awk '{print $2}'`" = "myname"; then
127 error "WIM name not set correctly"
129 if ! test "`imagex info dir.wim | grep Description | awk '{print $2}'`" = "mydesc"; then
130 error "WIM name not set correctly"
132 echo "Testing printing WIM lookup table"
133 if ! imagex info --lookup-table dir.wim > /dev/null; then
134 error "Failed to print WIM lookup table"
136 echo "Testing printing WIM header"
137 if ! imagex info --header dir.wim > /dev/null; then
138 error "Failed to print WIM header"
140 echo "Testing printing WIM XML info"
141 if ! imagex info --xml dir.wim > /dev/null; then
142 error "Failed to print WIM XML data"
144 echo "Testing extracting WIM XML info"
145 if ! imagex info --extract-xml=dir.xml dir.wim; then
146 error "Failed to extract WIM XML data"
148 echo "Testing printing WIM metadata"
149 if ! imagex info --metadata dir.wim > /dev/null; then
150 error "Failed to print WIM metadata"
152 rm -rf dir.wim tmp dir.xml
154 echo "Testing capture of bootable WIM"
155 if ! imagex capture dir dir.wim --boot; then
156 error "Failed to capture bootable WIM"
158 if ! test "`imagex info dir.wim | grep Boot | awk '{print $3}'`" = "1"; then
159 error "Boot flag on bootable WIM not set correctly"
165 echo "Testing capture of WIM with integrity table"
166 if ! imagex capture dir dir.wim --check; then
167 error "Failed to capture WIM with integrity table"
169 if ! test "`imagex info dir.wim | grep Integrity | awk '{print $3}'`" = "yes"; then
170 error "Integrity table on WIM not made"
172 if ! imagex apply --check dir.wim tmp; then
173 error "Integrity table on WIM not made correctly"
175 if ! diff -q -r dir tmp; then
176 error "Recursive diff of applied WIM with original directory failed"
180 # Appending and deleting images
182 echo "Testing appending WIM image"
183 imagex capture dir dir.wim
184 if ! imagex append dir2 dir.wim; then
185 error "Appending WIM image failed"
187 if ! test "`imagex info dir.wim | grep 'Image Count' | awk '{print $3}'`" = 2; then
188 error "WIM image count not correct"
191 echo "Testing appending WIM image with existing name (this should generate errors)"
192 if imagex append dir2 dir.wim; then
193 error "Adding duplicate image name didn't fail"
195 echo "Testing appending WIM image with new name"
196 if ! imagex append dir2 dir.wim "newname"; then
197 error "Appending WIM image failed"
199 echo "Testing appending WIM image with integrity check"
200 if ! imagex append dir2 dir.wim "newname2" --check; then
201 error "Appending WIM image failed"
203 if ! test "`imagex info dir.wim | grep Integrity | awk '{print $3}'`" = "yes"; then
204 error "Integrity table not set correctly on image append"
206 echo "Testing appending WIM image with no integrity check"
207 if ! imagex append dir2 dir.wim "newname3"; then
208 error "Appending WIM image failed"
210 if ! test "`imagex info dir.wim | grep Integrity | awk '{print $3}'`" = "no"; then
211 error "WIM integrity table not removed"
213 # 5 images at this point
214 if ! test "`imagex info dir.wim | grep 'Image Count' | awk '{print $3}'`" = 5; then
215 error "WIM does not contain the expected 5 images"
217 echo "Testing deleting first WIM image"
218 if ! imagex delete dir.wim 1; then
219 error "Failed to delete WIM image"
221 if ! test "`imagex info dir.wim | grep 'Image Count' | awk '{print $3}'`" = 4; then
222 error "WIM image not deleted correctly"
224 echo "Testing deleting last WIM image"
225 if ! imagex delete dir.wim 4; then
226 error "Failed to delete WIM image"
228 if ! test "`imagex info dir.wim | grep 'Image Count' | awk '{print $3}'`" = 3; then
229 error "WIM image not deleted correctly"
231 echo "Testing deleting invalid WIM image (this should generate errors)"
232 if imagex delete dir.wim 4; then
233 error "Expected to fail to delete non-existent WIM image"
235 if ! test "`imagex info dir.wim | grep 'Image Count' | awk '{print $3}'`" = 3; then
236 error "Image count changed even though we intentionally failed to delete an image"
238 echo "Testing deleting all WIM images"
239 if ! imagex delete dir.wim all; then
240 error "Failed to delete all images from WIM"
242 if ! test "`imagex info dir.wim | grep 'Image Count' | awk '{print $3}'`" = 0; then
243 error "Couldn't delete all WIM images correctly"
245 echo "Testing appending directory to empty WIM and making it bootable"
246 if ! imagex append dir dir.wim "myname" "mydesc" --check --boot; then
247 error "Couldn't append named, described, bootable image to empty WIM with integrity check"
249 if ! test "`imagex info dir.wim | grep Integrity | awk '{print $3}'`" = "yes"; then
250 error "Integrity check not found"
252 if ! test "`imagex info dir.wim | grep Boot | awk '{print $3}'`" = "1"; then
253 error "Bootable image not set correctly"
255 echo "Testing appending non-directory (should generate errors)"
256 if imagex append dir.wim dir.wim; then
257 error "Incorrectly succeeded to append non-directory to WIM"
259 echo "Testing appending non-existent file (should generate errors)"
260 if imagex append SOME_NONEXISTENT_FILE dir.wim; then
261 error "Incorrectly succeeded to append non-existent file to WIM"
263 if [ `id -u` != 0 ]; then
264 echo "Testing appending directory containing unreadable file (should generate errors)"
268 if imagex append dir3 dir.wim; then
269 error "Incorrectly succeeded in capturing directory with unreadable file"
274 # Applying multiple images, applying with hardlinks/symlinks
276 echo "Testing application of multiple images"
277 if ! imagex capture dir dir.wim; then
278 error "Failed to prepare test WIM"
280 if ! imagex append dir dir.wim "myname"; then
281 error "Failed to append image to test WIM"
283 if ! imagex apply dir.wim all tmp; then
284 error "Applying multiple images failed"
286 if ! diff -q -r tmp/dir tmp/myname || ! diff -q -r dir tmp/dir; then
287 error "Recursive diff of applied WIM with original directory failed"
289 if test "`stat -c %h tmp/dir/lz.c`" != 1; then
290 error "Incorrect link count on extracted file"
292 if test "`stat -c %h tmp/myname/lz.c`" != 1; then
293 error "Incorrect link count on extracted file"
295 if test "`stat -c %i tmp/myname/lz.c`" = "`stat -c %i tmp/dir/lz.c`"; then
296 error "Incorrect inode number"
299 echo "Testing application of multiple images with hardlinks"
300 if ! imagex apply dir.wim all tmp --hardlink; then
301 error "Failed to apply multiple images with cross-image hardlinks"
303 if ! diff -q -r tmp/dir tmp/myname || ! diff -q -r dir tmp/dir; then
304 error "Recursive diff of applied WIM with original directory failed"
306 if test "`stat -c %h tmp/dir/lz.c`" != 2; then
307 error "Incorrect link count on extracted file"
309 if test "`stat -c %h tmp/myname/lz.c`" != 2; then
310 error "Incorrect link count on extracted file"
312 if test "`stat -c %i tmp/myname/lz.c`" != "`stat -c %i tmp/dir/lz.c`"; then
313 error "Incorrect inode number"
317 echo "Testing application of single image containing identical files"
318 if ! imagex apply dir.wim 1 tmp; then
319 error "Failed to apply WIM"
321 if test "`stat -c %h tmp/subdir/hello`" != 2; then
322 error "Incorrect link count on extracted file"
324 if test "`stat -c %h tmp/subdir/hello2`" != 1; then
325 error "Incorrect link count on extracted file"
327 if test "`stat -c %i tmp/subdir/hello`" = "`stat -c %i tmp/subdir/hello2`"; then
328 error "Inode numbers on non-hard-linked files are the same"
330 if test "`stat -c %i tmp/subdir/hello`" != "`stat -c %i tmp/subdir/hellolink`"; then
331 error "Inode numbers on hard-linked files are different"
335 echo "Testing application of single image containing identical files with hardlinks"
336 if ! imagex apply dir.wim 1 tmp --hardlink; then
337 error "Failed to apply WIM"
339 if test "`stat -c %h tmp/subdir/hello`" != 3; then
340 error "Incorrect link count on extracted file"
342 if test "`stat -c %h tmp/subdir/hello2`" != 3; then
343 error "Incorrect link count on extracted file"
345 if test "`stat -c %i tmp/subdir/hello`" != "`stat -c %i tmp/subdir/hello2`"; then
346 error "Hard link set does not share inode number"
348 if test "`stat -c %i tmp/subdir/hello`" != "`stat -c %i tmp/subdir/hellolink`"; then
349 error "Hard link set does not share inode number"
353 echo "Testing application of single image containing identical files with symlinks"
354 if ! imagex apply dir.wim 1 tmp --symlink; then
355 error "Failed to apply WIM"
357 if test "`stat -c %h tmp/subdir/hello`" != 1; then
358 error "Incorrect link count on extracted file"
360 if test "`stat -c %h tmp/subdir/hello2`" != 1; then
361 error "Incorrect link count on extracted file"
363 if test "`stat -c %i tmp/subdir/hello`" = "`stat -c %i tmp/subdir/hello2`"; then
364 error "Incorrect inode number"
366 if ! test -L tmp/subdir/hello -o -L tmp/subdir/hello2 -o -L tmp/subdir/hellolink; then
367 error "Expected symlinks, but found non-symlinks"
373 for flag in "--compress=none" "--compress=maximum" "--compress=fast"; do
374 echo "Using flag $flag"
375 echo "Testing mounting WIM read-only"
376 if ! imagex capture dir dir.wim $flag; then
377 error "Failed to capture WIM"
380 if ! imagex mount dir.wim dir tmp; then
381 error "Failde to mount test WIM read-only"
383 echo "Testing extracting file from mounted read-only WIM"
384 if ! cp tmp/lz.c lz.c; then
385 error "Failed to extract file from read-only mounted WIM"
387 if ! diff -q dir/lz.c lz.c; then
388 error "Extracted file does not match copy in mounted WIM"
390 if ! diff -q tmp/lz.c dir/lz.c; then
391 error "Extractef file does not match original"
394 echo "Testing modifying mounted read-only WIM (should fail)"
396 error "Removing file from read-only mounted WIM didn't fail"
398 if touch tmp/newfile; then
399 error "Creating file on read-only mounted WIM didn't fail"
401 if echo 3 > tmp/lz.c; then
402 error "Writing to file on read-only mounted WIM didn't fail"
404 echo "Testing diff of mounted read-only WIM with original directory"
405 if ! diff -q -r tmp dir; then
406 error "Recursive diff of read-only mounted WIM with original directory failed"
408 echo "Testing unmount of read-only filesystem"
409 if ! imagex unmount tmp; then
410 error "Unmounting read-only WIM failed"
412 echo "Testing unmount of read-only filesystem with --commit given"
413 if ! imagex mount dir.wim dir tmp; then
414 error "Failed to re-mount WIM read-only"
416 if ! imagex unmount tmp --commit; then
417 error "Failed to unmount read-only WIM with --commit flag (should be ignored)"
423 echo "Testing mounting WIM read-write"
424 if ! imagex capture dir dir.wim; then
425 error "Failed to capture WIM"
428 if ! imagex mountrw dir.wim dir tmp; then
429 error "Failed to mount test WIM read-write"
431 echo "Testing unmounting WIM unmodified"
432 if ! imagex unmount tmp; then
433 error "Failed to unmount test WIM unmodified"
435 echo "Testing unmounting WIM unmodified with --commit and --check"
436 if ! imagex mountrw dir.wim dir tmp; then
437 error "Failed to re-mount test WIM read-write"
439 if ! imagex unmount tmp --commit --check; then
440 error "Failed to unmount read-write mounted WIM with changes commited (no changes made)"
442 echo "Testing removing file from mounted WIM"
443 if ! imagex mountrw dir.wim dir tmp; then
444 error "Failed to re-mount test WIM read-write"
446 if ! rm tmp/lz.c; then
447 error "Failed to remove file from read-write mounted WIM"
449 if test -f tmp/lz.c; then
450 error "Removing file from read-write mounted WIM failed"
452 echo "Testing making directory in mounted WIM"
453 if ! mkdir tmp/newdir; then
454 error "Failed to make directory in read-write mounted WIM"
456 if ! test -d tmp/newdir; then
457 error "Making directory in read-write mounted WIM failed"
459 echo "Testing making new empty file in mounted WIM"
460 if ! touch tmp/newdir/empty_file; then
461 error "Could not create new empty file in read-write mounted WIM"
463 if ! test -f tmp/newdir/empty_file; then
464 error "New empty file not created correctly in read-write mounted WIM"
466 if ! test "`stat -c %s tmp/newdir/empty_file`" = 0; then
467 error "New empty file in read-write mounted WIM is not empty"
469 echo "Testing making new non-empty file in mounted WIM"
470 if ! dd if=/dev/zero of=tmp/newdir/zeroes1 bs=1 count=4096; then
471 error "Failed to make new non-empty file in mounted WIM"
473 if ! dd if=/dev/zero of=tmp/newdir/zeroes2 bs=4096 count=1; then
474 error "Failed to make new non-empty file in mounted WIM"
476 if ! diff -q tmp/newdir/zeroes1 tmp/newdir/zeroes2; then
477 error "New files in mounted WIM not made correctly"
479 echo "Unmounting WIM with changes committed and --check"
480 if ! imagex unmount tmp --commit --check; then
481 error "Failed to unmount read-write mounted WIM"
483 if test "`imagex info dir.wim | grep Integrity | awk '{print $3}'`" != "yes"; then
484 error "Integrity information was not included"
487 if ! imagex apply dir.wim tmp; then
488 error "Failed to apply WIM we had previously mounted read-write"
490 if ! diff -q tmp/newdir/zeroes1 tmp/newdir/zeroes2; then
491 error "The new non-empty files we made in the read-write mounted WIM were not extracted correctly"
493 if test `stat -c %s tmp/newdir/empty_file` != 0; then
494 error "The new empty file we made in the read-write mounted WIM was not extracted correctly"
496 if test `stat -c %s tmp/newdir/zeroes1` != 4096; then
497 error "The new non-empty files we made in the read-write mounted WIM were not extracted correctly"
501 # imagex split, imagex join
503 echo "Creating random files to test WIM splitting on"
505 for i in `seq 1 100`; do
506 dd if=/dev/urandom of=tmp/file$i bs=4096 count=10 &> /dev/null
508 for flag in "--compress=none" "--compress=maximum" "--compress=fast"; do
509 echo "Using flag $flag"
510 if ! imagex capture tmp tmp.wim $flag; then
511 error "Failed to capture test WIM"
513 echo "Splitting WIM into 1 MiB chunks"
514 if ! imagex split tmp.wim tmp.swm 1; then
515 error "Failed to split WIM"
517 echo "Verifying the split WIMs (some errors expected)"
518 if test "`imagex info tmp.swm | grep 'Part Number' | awk '{print $3}'`" != "1/4"; then
519 error "Part number of split WIM not correct"
521 if ! imagex dir tmp.swm > /dev/null; then
522 error "Failed to list files in split WIM"
524 if ! test -e tmp2.swm; then
525 error "Could not find split-WIM part 2"
527 if imagex dir tmp2.swm > /dev/null; then
528 error "Listed files in part 2 of split WIM (this should have failed)"
531 # Unsupported, should fail
532 if imagex info tmp.swm --boot 0; then
533 error "Should not have been able to change boot index of split WIM"
535 echo "Joining the split WIMs and applying the result"
536 if ! imagex join tmp2.wim tmp*.wim; then
537 error "Failed to join split WIMs"
539 if ! imagex apply tmp2.wim tmp2; then
540 error "Failed to apply joined split WIM"
542 if ! imagex apply tmp.wim tmp3; then
543 error "Failed to apply test WIM"
545 if ! diff -q -r tmp tmp2 || ! diff -q -r tmp tmp3; then
546 error "Recursive diff of applied joined split WIM with original directory failed"
554 echo "Testing export of single image to new WIM"
555 if ! imagex capture dir dir.wim; then
556 error "Failed to capture test WIM"
558 if ! imagex append dir2 dir.wim; then
559 error "Failed to append image to test WIM"
561 if ! imagex export dir.wim dir new.wim; then
562 error "Failed to export single image to new WIM"
564 if test "`imagex info new.wim | grep 'Image Count' | awk '{print $3}'`" != 1; then
565 error "Exporting single image to new WIM wasn't done correctly"
567 echo "Testing export of single image to existing WIM"
568 if ! imagex export dir.wim dir2 new.wim; then
569 error "Failed to export single image to existing WIM"
571 if test "`imagex info new.wim | grep 'Image Count' | awk '{print $3}'`" != 2; then
572 error "Exporting single image to existing WIM wasn't done correctly"
574 echo "Testing export of single image to existing WIM using wrong compression type"
575 if imagex export dir.wim dir2 new.wim newname --compress=maximum; then
576 error "Successfully exported image using wrong compression type"
579 echo "Testing export of multiple images to new WIM"
580 if ! imagex export dir.wim all new.wim; then
581 error "Failed to export multiple images to new WIM"
583 if test "`imagex info new.wim | grep 'Image Count' | awk '{print $3}'`" != 2; then
584 error "Exporting multiple images to new WIM wasn't done correctly"
586 if ! imagex capture dir2 new.wim newname; then
587 error "Failed to capture test WIM"
589 echo "Testing export of multiple images to existing WIM"
590 if ! imagex export dir.wim all new.wim; then
591 error "Failed to export multiple images to existing WIM"
593 echo "Testing export of multiple images to existing WIM with --boot"
594 if ! imagex capture dir2 new.wim newname; then
595 error "Failed to capture test WIM"
597 if ! imagex info dir.wim --boot 1; then
598 error "Failed to set boot index on test WIM"
600 if ! imagex export dir.wim all new.wim --boot; then
601 error "Failed to export multiple images to existing WIM with bootable image"
603 echo "Testing export of multiple images to existing WIM with --boot, but no bootable image (errors expected)"
604 if ! imagex capture dir2 new.wim newname; then
605 error "Failed to capture test WIM"
607 if ! imagex info dir.wim --boot 0; then
608 error "Failed to clear boot index on test WIM"
610 if imagex export dir.wim all new.wim --boot; then
611 error "Successfully exported multiple images with --boot but with no bootable images"
614 echo "**********************************************************"
615 echo " Basic imagex tests passed "
616 echo "**********************************************************"