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.
33 if [ -d tmp ] && mountpoint tmp > /dev/null; then
34 fusermount -u tmp > /dev/null;
36 rm -rf dir* tmp* *.wim *.swm
42 cp ../src/*.c ../src/*.h dir
44 echo 'hello' > dir/subdir/hello
45 echo 'hello' > dir/subdir/hello2
46 ln dir/subdir/hello dir/subdir/hellolink
47 echo -n > dir/subdir/empty_file
48 ln -s hello dir/subdir/rel_symlink
51 echo 'testing' > dir2/file
52 dd if=/dev/zero of=dir2/zeroes bs=4096 count=5
55 echo "**********************************************"
58 echo "**********************************************"
62 # Capturing and applying WIM with None, LZX, and XPRESS compression
64 for comp_type in None LZX XPRESS; do
65 echo "Testing capture and application of $comp_type-compressed WIM"
66 if ! imagex capture dir dir.wim --compress=$comp_type; then
67 error "'imagex capture' failed"
69 if ! imagex apply dir.wim tmp; then
70 error "'imagex apply' failed"
72 if ! test "`imagex info dir.wim | grep Compression | awk '{print $2}'`" = "$comp_type"; then
73 error "'imagex info' didn't report the compression type correctly"
75 if ! diff -q -r dir tmp; then
76 error "Recursive diff of extracted directory with original failed"
78 if ! test `stat -c %h tmp/subdir/hello` = 2; then
79 error "Incorrect number of hard links in extracted file"
81 if ! test `stat -c %i tmp/subdir/hello` != `stat -c %i tmp/subdir/hello2`; then
82 error "Expected different inode numbers in files not hard-linked"
84 if ! test "`stat -c %i tmp/subdir/hello`" = "`stat -c %i tmp/subdir/hellolink`"; then
85 error "Expected same inode numbers in hard-linked files"
87 if ! test -L tmp/subdir/rel_symlink; then
88 error "Symlink not extracted correctly"
90 if ! test "`readlink tmp/subdir/rel_symlink`" = "hello"; then
91 error "Symlink target not correct"
97 # Capturing and modifying name, description, and bootable flag
99 echo "Testing capture of WIM with default name and description"
100 imagex capture dir dir.wim
101 if ! test "`imagex info dir.wim | grep Name | awk '{print $2}'`" = "dir"; then
102 error "WIM name not set correctly"
104 if ! test "`imagex info dir.wim | grep Description | awk '{print $2}'`" = ""; then
105 error "WIM description not set correctly"
108 echo "Testing capture of WIM with default boot flag"
109 imagex capture dir dir.wim
110 if ! test "`imagex info dir.wim | grep Boot | awk '{print $3}'`" = "0"; then
111 error "WIM boot flag not set correctly"
114 echo "Testing changing image bootable flag"
115 if ! imagex info dir.wim 1 --boot; then
116 error "Failed to change bootable image"
118 if ! test "`imagex info dir.wim | grep Boot | awk '{print $3}'`" = "1"; then
119 error "Bootable image not changed correctly"
121 echo "Testing changing image bootable flag"
122 if ! imagex info dir.wim 0 --boot; then
123 error "Failed to reset bootable image"
125 if ! test "`imagex info dir.wim | grep Boot | awk '{print $3}'`" = "0"; then
126 error "Bootable image not reset correctly"
128 echo "Testing changing image bootable flag to invalid image (this should generate errors)"
129 if imagex info dir.wim 2 --boot; then
130 error "Succeeded in changing bootable image to invalid number"
132 if ! test "`imagex info dir.wim | grep Boot | awk '{print $3}'`" = "0"; then
133 error "Boot flag was changed even though the change command was supposed to fail"
137 echo "Testing capture of WIM with name and description"
138 if ! imagex capture dir dir.wim "myname" "mydesc"; then
139 error "Failed to capture WIM with specified name and description"
141 if ! test "`imagex info dir.wim | grep Name | awk '{print $2}'`" = "myname"; then
142 error "WIM name not set correctly"
144 if ! test "`imagex info dir.wim | grep Description | awk '{print $2}'`" = "mydesc"; then
145 error "WIM name not set correctly"
147 echo "Testing printing WIM lookup table"
148 if ! imagex info --lookup-table dir.wim > /dev/null; then
149 error "Failed to print WIM lookup table"
151 echo "Testing printing WIM header"
152 if ! imagex info --header dir.wim > /dev/null; then
153 error "Failed to print WIM header"
155 echo "Testing printing WIM XML info"
156 if ! imagex info --xml dir.wim > /dev/null; then
157 error "Failed to print WIM XML data"
159 echo "Testing extracting WIM XML info"
160 if ! imagex info --extract-xml=dir.xml dir.wim; then
161 error "Failed to extract WIM XML data"
163 echo "Testing printing WIM metadata"
164 if ! imagex info --metadata dir.wim > /dev/null; then
165 error "Failed to print WIM metadata"
167 rm -rf dir.wim tmp dir.xml
169 echo "Testing capture of bootable WIM"
170 if ! imagex capture dir dir.wim --boot; then
171 error "Failed to capture bootable WIM"
173 if ! test "`imagex info dir.wim | grep Boot | awk '{print $3}'`" = "1"; then
174 error "Boot flag on bootable WIM not set correctly"
180 echo "Testing capture of WIM with integrity table"
181 if ! imagex capture dir dir.wim --check; then
182 error "Failed to capture WIM with integrity table"
184 if ! test "`imagex info dir.wim | grep Integrity | awk '{print $3}'`" = "yes"; then
185 error "Integrity table on WIM not made"
187 if ! imagex apply --check dir.wim tmp; then
188 error "Integrity table on WIM not made correctly"
190 if ! diff -q -r dir tmp; then
191 error "Recursive diff of applied WIM with original directory failed"
195 # Appending and deleting images
197 echo "Testing appending WIM image"
198 imagex capture dir dir.wim
199 if ! imagex append dir2 dir.wim; then
200 error "Appending WIM image failed"
202 if ! test "`imagex info dir.wim | grep 'Image Count' | awk '{print $3}'`" = 2; then
203 error "WIM image count not correct"
206 echo "Testing appending WIM image with existing name (this should generate errors)"
207 if imagex append dir2 dir.wim; then
208 error "Adding duplicate image name didn't fail"
210 echo "Testing appending WIM image with new name"
211 if ! imagex append dir2 dir.wim "newname"; then
212 error "Appending WIM image failed"
214 echo "Testing appending WIM image with integrity check"
215 if ! imagex append dir2 dir.wim "newname2" --check; then
216 error "Appending WIM image failed"
218 if ! test "`imagex info dir.wim | grep Integrity | awk '{print $3}'`" = "yes"; then
219 error "Integrity table not set correctly on image append"
221 echo "Testing appending WIM image with no integrity check"
222 if ! imagex append dir2 dir.wim "newname3"; then
223 error "Appending WIM image failed"
225 if ! test "`imagex info dir.wim | grep Integrity | awk '{print $3}'`" = "no"; then
226 error "WIM integrity table not removed"
228 # 5 images at this point
229 if ! test "`imagex info dir.wim | grep 'Image Count' | awk '{print $3}'`" = 5; then
230 error "WIM does not contain the expected 5 images"
232 echo "Testing deleting first WIM image"
233 if ! imagex delete dir.wim 1; then
234 error "Failed to delete WIM image"
236 if ! test "`imagex info dir.wim | grep 'Image Count' | awk '{print $3}'`" = 4; then
237 error "WIM image not deleted correctly"
239 echo "Testing deleting last WIM image"
240 if ! imagex delete dir.wim 4; then
241 error "Failed to delete WIM image"
243 if ! test "`imagex info dir.wim | grep 'Image Count' | awk '{print $3}'`" = 3; then
244 error "WIM image not deleted correctly"
246 echo "Testing deleting invalid WIM image (this should generate errors)"
247 if imagex delete dir.wim 4; then
248 error "Expected to fail to delete non-existent WIM image"
250 if ! test "`imagex info dir.wim | grep 'Image Count' | awk '{print $3}'`" = 3; then
251 error "Image count changed even though we intentionally failed to delete an image"
253 echo "Testing deleting all WIM images"
254 if ! imagex delete dir.wim all; then
255 error "Failed to delete all images from WIM"
257 if ! test "`imagex info dir.wim | grep 'Image Count' | awk '{print $3}'`" = 0; then
258 error "Couldn't delete all WIM images correctly"
260 echo "Testing appending directory to empty WIM and making it bootable"
261 if ! imagex append dir dir.wim "myname" "mydesc" --check --boot; then
262 error "Couldn't append named, described, bootable image to empty WIM with integrity check"
264 if ! test "`imagex info dir.wim | grep Integrity | awk '{print $3}'`" = "yes"; then
265 error "Integrity check not found"
267 if ! test "`imagex info dir.wim | grep Boot | awk '{print $3}'`" = "1"; then
268 error "Bootable image not set correctly"
270 echo "Testing appending non-directory (should generate errors)"
271 if imagex append dir.wim dir.wim; then
272 error "Incorrectly succeeded to append non-directory to WIM"
274 echo "Testing appending non-existent file (should generate errors)"
275 if imagex append SOME_NONEXISTENT_FILE dir.wim; then
276 error "Incorrectly succeeded to append non-existent file to WIM"
278 echo "Testing appending directory containing unreadable file (should generate errors)"
282 if imagex append dir3 dir.wim; then
283 error "Incorrectly succeeded in capturing directory with unreadable file"
287 # Applying multiple images, applying with hardlinks/symlinks
289 echo "Testing application of multiple images"
290 if ! imagex capture dir dir.wim; then
291 error "Failed to prepare test WIM"
293 if ! imagex append dir dir.wim "myname"; then
294 error "Failed to append image to test WIM"
296 if ! imagex apply dir.wim all tmp; then
297 error "Applying multiple images failed"
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`" != 1; then
303 error "Incorrect link count on extracted file"
305 if test "`stat -c %h tmp/myname/lz.c`" != 1; 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"
312 echo "Testing application of multiple images with hardlinks"
313 if ! imagex apply dir.wim all tmp --hardlink; then
314 error "Failed to apply multiple images with cross-image hardlinks"
316 if ! diff -q -r tmp/dir tmp/myname || ! diff -q -r dir tmp/dir; then
317 error "Recursive diff of applied WIM with original directory failed"
319 if test "`stat -c %h tmp/dir/lz.c`" != 2; then
320 error "Incorrect link count on extracted file"
322 if test "`stat -c %h tmp/myname/lz.c`" != 2; then
323 error "Incorrect link count on extracted file"
325 if test "`stat -c %i tmp/myname/lz.c`" != "`stat -c %i tmp/dir/lz.c`"; then
326 error "Incorrect inode number"
330 echo "Testing application of single image containing identical files"
331 if ! imagex apply dir.wim 1 tmp; then
332 error "Failed to apply WIM"
334 if test "`stat -c %h tmp/subdir/hello`" != 2; then
335 error "Incorrect link count on extracted file"
337 if test "`stat -c %h tmp/subdir/hello2`" != 1; then
338 error "Incorrect link count on extracted file"
340 if test "`stat -c %i tmp/subdir/hello`" = "`stat -c %i tmp/subdir/hello2`"; then
341 error "Inode numbers on non-hard-linked files are the same"
343 if test "`stat -c %i tmp/subdir/hello`" != "`stat -c %i tmp/subdir/hellolink`"; then
344 error "Inode numbers on hard-linked files are different"
348 echo "Testing application of single image containing identical files with hardlinks"
349 if ! imagex apply dir.wim 1 tmp --hardlink; then
350 error "Failed to apply WIM"
352 if test "`stat -c %h tmp/subdir/hello`" != 3; then
353 error "Incorrect link count on extracted file"
355 if test "`stat -c %h tmp/subdir/hello2`" != 3; then
356 error "Incorrect link count on extracted file"
358 if test "`stat -c %i tmp/subdir/hello`" != "`stat -c %i tmp/subdir/hello2`"; then
359 error "Hard link set does not share inode number"
361 if test "`stat -c %i tmp/subdir/hello`" != "`stat -c %i tmp/subdir/hellolink`"; then
362 error "Hard link set does not share inode number"
366 echo "Testing application of single image containing identical files with symlinks"
367 if ! imagex apply dir.wim 1 tmp --symlink; then
368 error "Failed to apply WIM"
370 if test "`stat -c %h tmp/subdir/hello`" != 1; then
371 error "Incorrect link count on extracted file"
373 if test "`stat -c %h tmp/subdir/hello2`" != 1; then
374 error "Incorrect link count on extracted file"
376 if test "`stat -c %i tmp/subdir/hello`" = "`stat -c %i tmp/subdir/hello2`"; then
377 error "Incorrect inode number"
379 if ! test -L tmp/subdir/hello || ! test -L tmp/subdir/hello2; then
380 error "Expected symlinks, but found non-symlinks"
386 for flag in "--compress=none" "--compress=maximum" "--compress=fast"; do
387 echo "Using flag $flag"
388 echo "Testing mounting WIM read-only"
389 if ! imagex capture dir dir.wim $flag; then
390 error "Failed to capture WIM"
393 if ! imagex mount dir.wim dir tmp; then
394 error "Failde to mount test WIM read-only"
396 echo "Testing extracting file from mounted read-only WIM"
397 if ! cp tmp/lz.c lz.c; then
398 error "Failed to extract file from read-only mounted WIM"
400 if ! diff -q dir/lz.c lz.c; then
401 error "Extracted file does not match copy in mounted WIM"
403 if ! diff -q tmp/lz.c dir/lz.c; then
404 error "Extractef file does not match original"
407 echo "Testing modifying mounted read-only WIM (should fail)"
409 error "Removing file from read-only mounted WIM didn't fail"
411 if touch tmp/newfile; then
412 error "Creating file on read-only mounted WIM didn't fail"
414 if echo 3 > tmp/lz.c; then
415 error "Writing to file on read-only mounted WIM didn't fail"
417 echo "Testing diff of mounted read-only WIM with original directory"
418 if ! diff -q -r tmp dir; then
419 error "Recursive diff of read-only mounted WIM with original directory failed"
421 echo "Testing unmount of read-only filesystem"
422 if ! imagex unmount tmp; then
423 error "Unmounting read-only WIM failed"
425 echo "Testing unmount of read-only filesystem with --commit given"
426 if ! imagex mount dir.wim dir tmp; then
427 error "Failed to re-mount WIM read-only"
429 if ! imagex unmount tmp --commit; then
430 error "Failed to unmount read-only WIM with --commit flag (should be ignored)"
436 echo "Testing mounting WIM read-write"
437 if ! imagex capture dir dir.wim; then
438 error "Failed to capture WIM"
441 if ! imagex mountrw dir.wim dir tmp; then
442 error "Failed to mount test WIM read-write"
444 echo "Testing unmounting WIM unmodified"
445 if ! imagex unmount tmp; then
446 error "Failed to unmount test WIM unmodified"
448 echo "Testing unmounting WIM unmodified with --commit and --check"
449 if ! imagex mountrw dir.wim dir tmp; then
450 error "Failed to re-mount test WIM read-write"
452 if ! imagex unmount tmp --commit --check; then
453 error "Failed to unmount read-write mounted WIM with changes commited (no changes made)"
455 echo "Testing removing file from mounted WIM"
456 if ! imagex mountrw dir.wim dir tmp; then
457 error "Failed to re-mount test WIM read-write"
459 if ! rm tmp/lz.c; then
460 error "Failed to remove file from read-write mounted WIM"
462 if test -f tmp/lz.c; then
463 error "Removing file from read-write mounted WIM failed"
465 echo "Testing making directory in mounted WIM"
466 if ! mkdir tmp/newdir; then
467 error "Failed to make directory in read-write mounted WIM"
469 if ! test -d tmp/newdir; then
470 error "Making directory in read-write mounted WIM failed"
472 echo "Testing making new empty file in mounted WIM"
473 if ! touch tmp/newdir/empty_file; then
474 error "Could not create new empty file in read-write mounted WIM"
476 if ! test -f tmp/newdir/empty_file; then
477 error "New empty file not created correctly in read-write mounted WIM"
479 if ! test "`stat -c %s tmp/newdir/empty_file`" = 0; then
480 error "New empty file in read-write mounted WIM is not empty"
482 echo "Testing making new non-empty file in mounted WIM"
483 if ! dd if=/dev/zero of=tmp/newdir/zeroes1 bs=1 count=4096; then
484 error "Failed to make new non-empty file in mounted WIM"
486 if ! dd if=/dev/zero of=tmp/newdir/zeroes2 bs=4096 count=1; then
487 error "Failed to make new non-empty file in mounted WIM"
489 if ! diff -q tmp/newdir/zeroes1 tmp/newdir/zeroes2; then
490 error "New files in mounted WIM not made correctly"
492 echo "Unmounting WIM with changes committed and --check"
493 if ! imagex unmount tmp --commit --check; then
494 error "Failed to unmount read-write mounted WIM"
496 if test "`imagex info dir.wim | grep Integrity | awk '{print $3}'`" != "yes"; then
497 error "Integrity information was not included"
500 if ! imagex apply dir.wim tmp; then
501 error "Failed to apply WIM we had previously mounted read-write"
503 if ! diff -q tmp/newdir/zeroes1 tmp/newdir/zeroes2; then
504 error "The new non-empty files we made in the read-write mounted WIM were not extracted correctly"
506 if test `stat -c %s tmp/newdir/empty_file` != 0; then
507 error "The new empty file we made in the read-write mounted WIM was not extracted correctly"
509 if test `stat -c %s tmp/newdir/zeroes1` != 4096; then
510 error "The new non-empty files we made in the read-write mounted WIM were not extracted correctly"
514 # imagex split, imagex join
516 echo "Creating random files to test WIM splitting on"
518 for i in `seq 1 100`; do
519 dd if=/dev/urandom of=tmp/file$i bs=4096 count=10 &> /dev/null
521 for flag in "--compress=none" "--compress=maximum" "--compress=fast"; do
522 echo "Using flag $flag"
523 if ! imagex capture tmp tmp.wim $flag; then
524 error "Failed to capture test WIM"
526 echo "Splitting WIM into 1 MiB chunks"
527 if ! imagex split tmp.wim tmp.swm 1; then
528 error "Failed to split WIM"
530 echo "Verifying the split WIMs (some errors expected)"
531 if test "`imagex info tmp.swm | grep 'Part Number' | awk '{print $3}'`" != "1/4"; then
532 error "Part number of split WIM not correct"
534 if ! imagex dir tmp.swm > /dev/null; then
535 error "Failed to list files in split WIM"
537 if ! test -e tmp2.swm; then
538 error "Could not find split-WIM part 2"
540 if imagex dir tmp2.swm > /dev/null; then
541 error "Listed files in part 2 of split WIM (this should have failed)"
544 # Unsupported, should fail
545 if imagex info tmp.swm --boot 0; then
546 error "Should not have been able to change boot index of split WIM"
548 echo "Joining the split WIMs and applying the result"
549 if ! imagex join tmp2.wim tmp*.wim; then
550 error "Failed to join split WIMs"
552 if ! imagex apply tmp2.wim tmp2; then
553 error "Failed to apply joined split WIM"
555 if ! imagex apply tmp.wim tmp3; then
556 error "Failed to apply test WIM"
558 if ! diff -q -r tmp tmp2 || ! diff -q -r tmp tmp3; then
559 error "Recursive diff of applied joined split WIM with original directory failed"
567 echo "Testing export of single image to new WIM"
568 imagex capture dir dir.wim
569 imagex append dir2 dir.wim
570 imagex export dir.wim dir new.wim
571 test "`imagex info new.wim | grep 'Image Count' | awk '{print $3}'`" = 1;
572 echo "Testing export of single image to existing WIM"
573 imagex export dir.wim dir2 new.wim
574 test "`imagex info new.wim | grep 'Image Count' | awk '{print $3}'`" = 2;
575 echo "Testing export of single image to existing WIM using wrong compression type"
576 ! imagex export dir.wim dir2 new.wim newname --compress=maximum
578 echo "Testing export of multiple images to new WIM"
579 imagex export dir.wim all new.wim
580 test "`imagex info new.wim | grep 'Image Count' | awk '{print $3}'`" = 2;
581 imagex capture dir2 new.wim newname
582 echo "Testing export of multiple images to existing WIM"
583 imagex export dir.wim all new.wim
584 echo "Testing export of multiple images to existing WIM with --boot"
585 imagex capture dir2 new.wim newname
586 imagex info dir.wim --boot 1
587 imagex export dir.wim all new.wim --boot
588 echo "Testing export of multiple images to existing WIM with --boot, but no bootable image (errors expected)"
589 imagex capture dir2 new.wim newname
590 imagex info dir.wim --boot 0
591 ! imagex export dir.wim all new.wim --boot