3 # This script does some sanity testing of the 'imagex' program. It by no means
4 # tests every aspect of wimlib comprehensively.
12 ../imagex "$@" > /dev/null
21 fusermount -u tmp &> /dev/null || true
22 rm -rf dir* tmp* *.wim *.swm &> /dev/null || true
28 cp $srcdir/src/*.c $srcdir/src/*.h dir
30 echo 'hello' > dir/subdir/hello
31 echo 'hello' > dir/subdir/hello2
32 ln dir/subdir/hello dir/subdir/hellolink
33 echo -n > dir/subdir/empty_file
34 ln -s hello dir/subdir/rel_symlink
37 echo 'testing' > dir2/file
38 dd if=/dev/zero of=dir2/zeroes bs=4096 count=5
41 echo "**********************************************"
44 echo "**********************************************"
48 # Capturing and applying WIM with None, LZX, and XPRESS compression
50 for comp_type in None LZX XPRESS; do
51 echo "Testing capture and application of $comp_type-compressed WIM"
52 if ! imagex capture dir dir.wim --compress=$comp_type; then
53 error "'imagex capture' failed"
55 if ! imagex apply dir.wim tmp; then
56 error "'imagex apply' failed"
58 if ! test "`imagex_info dir.wim | grep Compression | awk '{print $2}'`" = "$comp_type"; then
59 error "'imagex_info' didn't report the compression type correctly"
61 if ! diff -q -r dir tmp; then
62 error "Recursive diff of extracted directory with original failed"
64 if ! test `get_link_count tmp/subdir/hello` = 2; then
65 error "Incorrect number of hard links in extracted file"
67 if ! test `get_inode_number tmp/subdir/hello` != `get_inode_number tmp/subdir/hello2`; then
68 error "Expected different inode numbers in files not hard-linked"
70 if ! test "`get_inode_number tmp/subdir/hello`" = "`get_inode_number tmp/subdir/hellolink`"; then
71 error "Expected same inode numbers in hard-linked files"
73 if ! test -L tmp/subdir/rel_symlink; then
74 error "Symlink not extracted correctly"
76 if ! test "`readlink tmp/subdir/rel_symlink`" = "hello"; then
77 error "Symlink target not correct"
83 # Capturing and modifying name, description, and bootable flag
85 echo "Testing capture of WIM with default name and description"
86 imagex capture dir dir.wim
87 if ! test "`imagex_info dir.wim | grep Name | awk '{print $2}'`" = "dir"; then
88 error "WIM name not set correctly"
90 if ! test "`imagex_info dir.wim | grep Description | awk '{print $2}'`" = ""; then
91 error "WIM description not set correctly"
94 echo "Testing capture of WIM with default boot flag"
95 imagex capture dir dir.wim
96 if ! test "`imagex_info dir.wim | grep Boot | awk '{print $3}'`" = "0"; then
97 error "WIM boot flag not set correctly"
100 echo "Testing changing image bootable flag"
101 if ! imagex_info dir.wim 1 --boot; then
102 error "Failed to change bootable image"
104 if ! test "`imagex_info dir.wim | grep Boot | awk '{print $3}'`" = "1"; then
105 error "Bootable image not changed correctly"
107 echo "Testing changing image bootable flag"
108 if ! imagex_info dir.wim 0 --boot; then
109 error "Failed to reset bootable image"
111 if ! test "`imagex_info dir.wim | grep Boot | awk '{print $3}'`" = "0"; then
112 error "Bootable image not reset correctly"
114 echo "Testing changing image bootable flag to invalid image (this should generate errors)"
115 if imagex_info dir.wim 2 --boot; then
116 error "Succeeded in changing bootable image to invalid number"
118 if ! test "`imagex_info dir.wim | grep Boot | awk '{print $3}'`" = "0"; then
119 error "Boot flag was changed even though the change command was supposed to fail"
123 echo "Testing capture of WIM with name and description"
124 if ! imagex capture dir dir.wim "myname" "mydesc"; then
125 error "Failed to capture WIM with specified name and description"
127 if ! test "`imagex_info dir.wim | grep Name | awk '{print $2}'`" = "myname"; then
128 error "WIM name not set correctly"
130 if ! test "`imagex_info dir.wim | grep Description | awk '{print $2}'`" = "mydesc"; then
131 error "WIM name not set correctly"
133 echo "Testing printing WIM lookup table"
134 if ! imagex_info --lookup-table dir.wim > /dev/null; then
135 error "Failed to print WIM lookup table"
137 echo "Testing printing WIM header"
138 if ! imagex_info --header dir.wim > /dev/null; then
139 error "Failed to print WIM header"
141 echo "Testing printing WIM XML info"
142 if ! imagex_info --xml dir.wim > /dev/null; then
143 error "Failed to print WIM XML data"
145 echo "Testing extracting WIM XML info"
146 if ! imagex_info --extract-xml=dir.xml dir.wim; then
147 error "Failed to extract WIM XML data"
149 echo "Testing printing WIM metadata"
150 if ! imagex_info --metadata dir.wim > /dev/null; then
151 error "Failed to print WIM metadata"
153 rm -rf dir.wim tmp dir.xml
155 echo "Testing capture of bootable WIM"
156 if ! imagex capture dir dir.wim --boot; then
157 error "Failed to capture bootable WIM"
159 if ! test "`imagex_info dir.wim | grep Boot | awk '{print $3}'`" = "1"; then
160 error "Boot flag on bootable WIM not set correctly"
166 echo "Testing capture of WIM with integrity table"
167 if ! imagex capture dir dir.wim --check; then
168 error "Failed to capture WIM with integrity table"
170 if ! test "`imagex_info dir.wim | grep Integrity | awk '{print $3}'`" = "yes"; then
171 error "Integrity table on WIM not made"
173 if ! imagex apply --check dir.wim tmp; then
174 error "Integrity table on WIM not made correctly"
176 if ! diff -q -r dir tmp; then
177 error "Recursive diff of applied WIM with original directory failed"
181 # Appending and deleting images
183 echo "Testing appending WIM image"
184 imagex capture dir dir.wim
185 if ! imagex append dir2 dir.wim; then
186 error "Appending WIM image failed"
188 if ! test "`imagex_info dir.wim | grep 'Image Count' | awk '{print $3}'`" = 2; then
189 error "WIM image count not correct"
192 echo "Testing appending WIM image with existing name (this should generate errors)"
193 if imagex append dir2 dir.wim; then
194 error "Adding duplicate image name didn't fail"
196 echo "Testing appending WIM image with new name"
197 if ! imagex append dir2 dir.wim "newname"; then
198 error "Appending WIM image failed"
200 echo "Testing appending WIM image with integrity check"
201 if ! imagex append dir2 dir.wim "newname2" --check; then
202 error "Appending WIM image failed"
204 if ! test "`imagex_info dir.wim | grep Integrity | awk '{print $3}'`" = "yes"; then
205 error "Integrity table not set correctly on image append"
207 echo "Testing appending WIM image with no integrity check"
208 if ! imagex append dir2 dir.wim "newname3"; then
209 error "Appending WIM image failed"
211 if ! test "`imagex_info dir.wim | grep Integrity | awk '{print $3}'`" = "no"; then
212 error "WIM integrity table not removed"
214 # 5 images at this point
215 if ! test "`imagex_info dir.wim | grep 'Image Count' | awk '{print $3}'`" = 5; then
216 error "WIM does not contain the expected 5 images"
218 echo "Testing deleting first WIM image"
219 if ! imagex delete dir.wim 1; then
220 error "Failed to delete WIM image"
222 if ! test "`imagex_info dir.wim | grep 'Image Count' | awk '{print $3}'`" = 4; then
223 error "WIM image not deleted correctly"
225 echo "Testing deleting last WIM image"
226 if ! imagex delete dir.wim 4; then
227 error "Failed to delete WIM image"
229 if ! test "`imagex_info dir.wim | grep 'Image Count' | awk '{print $3}'`" = 3; then
230 error "WIM image not deleted correctly"
232 echo "Testing deleting invalid WIM image (this should generate errors)"
233 if imagex delete dir.wim 4; then
234 error "Expected to fail to delete non-existent WIM image"
236 if ! test "`imagex_info dir.wim | grep 'Image Count' | awk '{print $3}'`" = 3; then
237 error "Image count changed even though we intentionally failed to delete an image"
239 echo "Testing deleting all WIM images"
240 if ! imagex delete dir.wim all; then
241 error "Failed to delete all images from WIM"
243 if ! test "`imagex_info dir.wim | grep 'Image Count' | awk '{print $3}'`" = 0; then
244 error "Couldn't delete all WIM images correctly"
246 echo "Testing appending directory to empty WIM and making it bootable"
247 if ! imagex append dir dir.wim "myname" "mydesc" --check --boot; then
248 error "Couldn't append named, described, bootable image to empty WIM with integrity check"
250 if ! test "`imagex_info dir.wim | grep Integrity | awk '{print $3}'`" = "yes"; then
251 error "Integrity check not found"
253 if ! test "`imagex_info dir.wim | grep Boot | awk '{print $3}'`" = "1"; then
254 error "Bootable image not set correctly"
256 echo "Testing appending non-directory (should generate errors)"
257 if imagex append dir.wim dir.wim; then
258 error "Incorrectly succeeded to append non-directory to WIM"
260 echo "Testing appending non-existent file (should generate errors)"
261 if imagex append SOME_NONEXISTENT_FILE dir.wim; then
262 error "Incorrectly succeeded to append non-existent file to WIM"
264 if [ `id -u` != 0 ]; then
265 echo "Testing appending directory containing unreadable file (should generate errors)"
269 if imagex append dir3 dir.wim; then
270 error "Incorrectly succeeded in capturing directory with unreadable file"
275 # Applying multiple images, applying with hardlinks/symlinks
277 echo "Testing application of multiple images"
278 if ! imagex capture dir dir.wim; then
279 error "Failed to prepare test WIM"
281 if ! imagex append dir dir.wim "myname"; then
282 error "Failed to append image to test WIM"
284 if ! imagex apply dir.wim all tmp; then
285 error "Applying multiple images failed"
287 if ! diff -q -r tmp/dir tmp/myname || ! diff -q -r dir tmp/dir; then
288 error "Recursive diff of applied WIM with original directory failed"
290 if test "`get_link_count tmp/dir/lz.c`" != 1; then
291 error "Incorrect link count on extracted file"
293 if test "`get_link_count tmp/myname/lz.c`" != 1; then
294 error "Incorrect link count on extracted file"
296 if test "`get_inode_number tmp/myname/lz.c`" = "`get_inode_number tmp/dir/lz.c`"; then
297 error "Incorrect inode number"
300 echo "Testing application of multiple images with hardlinks"
301 if ! imagex apply dir.wim all tmp --hardlink; then
302 error "Failed to apply multiple images with cross-image hardlinks"
304 if ! diff -q -r tmp/dir tmp/myname || ! diff -q -r dir tmp/dir; then
305 error "Recursive diff of applied WIM with original directory failed"
307 if test "`get_link_count tmp/dir/lz.c`" != 2; then
308 error "Incorrect link count on extracted file"
310 if test "`get_link_count tmp/myname/lz.c`" != 2; then
311 error "Incorrect link count on extracted file"
313 if test "`get_inode_number tmp/myname/lz.c`" != "`get_inode_number tmp/dir/lz.c`"; then
314 error "Incorrect inode number"
318 echo "Testing application of single image containing identical files"
319 if ! imagex apply dir.wim 1 tmp; then
320 error "Failed to apply WIM"
322 if test "`get_link_count tmp/subdir/hello`" != 2; then
323 error "Incorrect link count on extracted file"
325 if test "`get_link_count tmp/subdir/hello2`" != 1; then
326 error "Incorrect link count on extracted file"
328 if test "`get_inode_number tmp/subdir/hello`" = "`get_inode_number tmp/subdir/hello2`"; then
329 error "Inode numbers on non-hard-linked files are the same"
331 if test "`get_inode_number tmp/subdir/hello`" != "`get_inode_number tmp/subdir/hellolink`"; then
332 error "Inode numbers on hard-linked files are different"
336 echo "Testing application of single image containing identical files with hardlinks"
337 if ! imagex apply dir.wim 1 tmp --hardlink; then
338 error "Failed to apply WIM"
340 if test "`get_link_count tmp/subdir/hello`" != 3; then
341 error "Incorrect link count on extracted file"
343 if test "`get_link_count tmp/subdir/hello2`" != 3; then
344 error "Incorrect link count on extracted file"
346 if test "`get_inode_number tmp/subdir/hello`" != "`get_inode_number tmp/subdir/hello2`"; then
347 error "Hard link set does not share inode number"
349 if test "`get_inode_number tmp/subdir/hello`" != "`get_inode_number tmp/subdir/hellolink`"; then
350 error "Hard link set does not share inode number"
354 echo "Testing application of single image containing identical files with symlinks"
355 if ! imagex apply dir.wim 1 tmp --symlink; then
356 error "Failed to apply WIM"
358 if test "`get_link_count tmp/subdir/hello`" != 1; then
359 error "Incorrect link count on extracted file"
361 if test "`get_link_count tmp/subdir/hello2`" != 1; then
362 error "Incorrect link count on extracted file"
364 if test "`get_inode_number tmp/subdir/hello`" = "`get_inode_number tmp/subdir/hello2`"; then
365 error "Incorrect inode number"
367 if ! test -L tmp/subdir/hello -o -L tmp/subdir/hello2 -o -L tmp/subdir/hellolink; then
368 error "Expected symlinks, but found non-symlinks"
373 # imagex split, imagex join
375 echo "Creating random files to test WIM splitting on"
377 for ((i = 0; i < 100; i++)); do
378 dd if=/dev/urandom of=tmp/file$i bs=4096 count=10 &> /dev/null
380 for flag in "--compress=none" "--compress=maximum" "--compress=fast"; do
381 echo "Using flag $flag"
382 if ! imagex capture tmp tmp.wim $flag; then
383 error "Failed to capture test WIM"
385 echo "Splitting WIM into 1 MiB chunks"
386 if ! imagex split tmp.wim tmp.swm 1; then
387 error "Failed to split WIM"
389 echo "Verifying the split WIMs (some errors expected)"
390 if test "`imagex_info tmp.swm | grep 'Part Number' | awk '{print $3}'`" != "1/4"; then
391 error "Part number of split WIM not correct"
393 if ! imagex dir tmp.swm > /dev/null; then
394 error "Failed to list files in split WIM"
396 if ! test -e tmp2.swm; then
397 error "Could not find split-WIM part 2"
399 if imagex dir tmp2.swm > /dev/null; then
400 error "Listed files in part 2 of split WIM (this should have failed)"
403 # Unsupported, should fail
404 if imagex_info tmp.swm --boot 0; then
405 error "Should not have been able to change boot index of split WIM"
407 echo "Joining the split WIMs and applying the result"
408 if ! imagex join tmp2.wim tmp*.wim; then
409 error "Failed to join split WIMs"
411 if ! imagex apply tmp2.wim tmp2; then
412 error "Failed to apply joined split WIM"
414 if ! imagex apply tmp.wim tmp3; then
415 error "Failed to apply test WIM"
417 if ! diff -q -r tmp tmp2 || ! diff -q -r tmp tmp3; then
418 error "Recursive diff of applied joined split WIM with original directory failed"
426 echo "Testing export of single image to new WIM"
427 if ! imagex capture dir dir.wim; then
428 error "Failed to capture test WIM"
430 if ! imagex append dir2 dir.wim; then
431 error "Failed to append image to test WIM"
433 if ! imagex export dir.wim dir new.wim; then
434 error "Failed to export single image to new WIM"
436 if test "`imagex_info new.wim | grep 'Image Count' | awk '{print $3}'`" != 1; then
437 error "Exporting single image to new WIM wasn't done correctly"
439 echo "Testing export of single image to existing WIM"
440 if ! imagex export dir.wim dir2 new.wim; then
441 error "Failed to export single image to existing WIM"
443 if test "`imagex_info new.wim | grep 'Image Count' | awk '{print $3}'`" != 2; then
444 error "Exporting single image to existing WIM wasn't done correctly"
446 echo "Testing export of single image to existing WIM using wrong compression type"
447 if imagex export dir.wim dir2 new.wim newname --compress=maximum; then
448 error "Successfully exported image using wrong compression type"
451 echo "Testing export of multiple images to new WIM"
452 if ! imagex export dir.wim all new.wim; then
453 error "Failed to export multiple images to new WIM"
455 if test "`imagex_info new.wim | grep 'Image Count' | awk '{print $3}'`" != 2; then
456 error "Exporting multiple images to new WIM wasn't done correctly"
458 if ! imagex capture dir2 new.wim newname; then
459 error "Failed to capture test WIM"
461 echo "Testing export of multiple images to existing WIM"
462 if ! imagex export dir.wim all new.wim; then
463 error "Failed to export multiple images to existing WIM"
465 echo "Testing export of multiple images to existing WIM with --boot"
466 if ! imagex capture dir2 new.wim newname; then
467 error "Failed to capture test WIM"
469 if ! imagex_info dir.wim --boot 1; then
470 error "Failed to set boot index on test WIM"
472 if ! imagex export dir.wim all new.wim --boot; then
473 error "Failed to export multiple images to existing WIM with bootable image"
475 echo "Testing export of multiple images to existing WIM with --boot, but no bootable image (errors expected)"
476 if ! imagex capture dir2 new.wim newname; then
477 error "Failed to capture test WIM"
479 if ! imagex_info dir.wim --boot 0; then
480 error "Failed to clear boot index on test WIM"
482 if imagex export dir.wim all new.wim --boot; then
483 error "Successfully exported multiple images with --boot but with no bootable images"
486 # Test exporting an image to another WIM, then applying it.
487 # We try with 5 different combinations of compression types to make sure we go
488 # through all paths in the resource-handling code.
489 for i in `seq 1 3`; do
492 cflag1="--compress=none";
493 cflag2="--compress=none";
496 cflag1="--compress=xpress";
497 cflag2="--compress=xpress";
500 cflag1="--compress=xpress"
501 cflag2="--compress=lzx"
504 cflag1="--compress=none"
505 cflag2="--compress=xpress"
508 cflag1="--compress=xpress"
509 cflag2="--compress=none"
512 echo "Testing exporting then applying an image (\"$cflag1\" => \"$cflag2\")"
513 rm -rf dir.wim new.wim tmp tmp2
514 imagex capture dir dir.wim $cflag1
515 imagex capture dir2 dir2.wim $cflag2
516 imagex export dir.wim dir dir2.wim
517 imagex apply dir.wim dir tmp
518 if ! imagex apply dir2.wim dir tmp2; then
519 error "Failed to apply image that was exported to a WIM"
521 if ! diff -r tmp tmp2; then
522 error "Image that was exported to a WIM was not applied correctly"
526 echo "**********************************************************"
527 echo " Basic imagex tests passed "
528 echo "**********************************************************"