3 # This script does some sanity testing of the 'imagex' program. It by no means
4 # tests every aspect of wimlib comprehensively.
8 srcdir="${srcdir:-.}/.."
9 srcdir="$(cd $srcdir; pwd)"
10 . "$srcdir/tests/tests-common.sh"
14 ../imagex "$@" > /dev/null
23 fusermount -u tmp &> /dev/null || true
24 rm -rf dir* tmp* *.wim *.swm &> /dev/null || true
30 cp $srcdir/src/*.c $srcdir/src/*.h dir
32 echo 'hello' > dir/subdir/hello
33 echo 'hello' > dir/subdir/hello2
34 ln dir/subdir/hello dir/subdir/hellolink
35 echo -n > dir/subdir/empty_file
36 ln -s hello dir/subdir/rel_symlink
39 echo 'testing' > dir2/file
40 dd if=/dev/zero of=dir2/zeroes bs=4096 count=5
43 echo "**********************************************"
46 echo "**********************************************"
50 # Capturing and applying WIM with None, LZX, and XPRESS compression
52 for comp_type in None LZX XPRESS; do
53 echo "Testing capture and application of $comp_type-compressed WIM"
54 if ! imagex capture dir dir.wim --compress=$comp_type; then
55 error "'imagex capture' failed"
57 if ! imagex apply dir.wim tmp; then
58 error "'imagex apply' failed"
60 if ! test "`imagex_info dir.wim | grep Compression | awk '{print $2}'`" = "$comp_type"; then
61 error "'imagex_info' didn't report the compression type correctly"
63 if ! diff -q -r dir tmp; then
64 error "Recursive diff of extracted directory with original failed"
66 if ! test `get_link_count tmp/subdir/hello` = 2; then
67 error "Incorrect number of hard links in extracted file"
69 if ! test `get_inode_number tmp/subdir/hello` != `get_inode_number tmp/subdir/hello2`; then
70 error "Expected different inode numbers in files not hard-linked"
72 if ! test "`get_inode_number tmp/subdir/hello`" = "`get_inode_number tmp/subdir/hellolink`"; then
73 error "Expected same inode numbers in hard-linked files"
75 if ! test -L tmp/subdir/rel_symlink; then
76 error "Symlink not extracted correctly"
78 if ! test "`readlink tmp/subdir/rel_symlink`" = "hello"; then
79 error "Symlink target not correct"
85 # Capturing and modifying name, description, and bootable flag
87 echo "Testing capture of WIM with default name and description"
88 imagex capture dir dir.wim
89 if ! test "`imagex_info dir.wim | grep Name | awk '{print $2}'`" = "dir"; then
90 error "WIM name not set correctly"
92 if ! test "`imagex_info dir.wim | grep Description | awk '{print $2}'`" = ""; then
93 error "WIM description not set correctly"
96 echo "Testing capture of WIM with default boot flag"
97 imagex capture dir dir.wim
98 if ! test "`imagex_info dir.wim | grep Boot | awk '{print $3}'`" = "0"; then
99 error "WIM boot flag not set correctly"
102 echo "Testing changing image bootable flag"
103 if ! imagex_info dir.wim 1 --boot; then
104 error "Failed to change bootable image"
106 if ! test "`imagex_info dir.wim | grep Boot | awk '{print $3}'`" = "1"; then
107 error "Bootable image not changed correctly"
109 echo "Testing changing image bootable flag"
110 if ! imagex_info dir.wim 0 --boot; then
111 error "Failed to reset bootable image"
113 if ! test "`imagex_info dir.wim | grep Boot | awk '{print $3}'`" = "0"; then
114 error "Bootable image not reset correctly"
116 echo "Testing changing image bootable flag to invalid image (this should generate errors)"
117 if imagex_info dir.wim 2 --boot; then
118 error "Succeeded in changing bootable image to invalid number"
120 if ! test "`imagex_info dir.wim | grep Boot | awk '{print $3}'`" = "0"; then
121 error "Boot flag was changed even though the change command was supposed to fail"
125 echo "Testing capture of WIM with name and description"
126 if ! imagex capture dir dir.wim "myname" "mydesc"; then
127 error "Failed to capture WIM with specified name and description"
129 if ! test "`imagex_info dir.wim | grep Name | awk '{print $2}'`" = "myname"; then
130 error "WIM name not set correctly"
132 if ! test "`imagex_info dir.wim | grep Description | awk '{print $2}'`" = "mydesc"; then
133 error "WIM name not set correctly"
135 echo "Testing printing WIM lookup table"
136 if ! imagex_info --lookup-table dir.wim > /dev/null; then
137 error "Failed to print WIM lookup table"
139 echo "Testing printing WIM header"
140 if ! imagex_info --header dir.wim > /dev/null; then
141 error "Failed to print WIM header"
143 echo "Testing printing WIM XML info"
144 if ! imagex_info --xml dir.wim > /dev/null; then
145 error "Failed to print WIM XML data"
147 echo "Testing extracting WIM XML info"
148 if ! imagex_info --extract-xml=dir.xml dir.wim; then
149 error "Failed to extract WIM XML data"
151 echo "Testing printing WIM metadata"
152 if ! imagex_info --metadata dir.wim > /dev/null; then
153 error "Failed to print WIM metadata"
155 rm -rf dir.wim tmp dir.xml
157 echo "Testing capture of bootable WIM"
158 if ! imagex capture dir dir.wim --boot; then
159 error "Failed to capture bootable WIM"
161 if ! test "`imagex_info dir.wim | grep Boot | awk '{print $3}'`" = "1"; then
162 error "Boot flag on bootable WIM not set correctly"
168 echo "Testing capture of WIM with integrity table"
169 if ! imagex capture dir dir.wim --check; then
170 error "Failed to capture WIM with integrity table"
172 if ! test "`imagex_info dir.wim | grep Integrity | awk '{print $3}'`" = "yes"; then
173 error "Integrity table on WIM not made"
175 if ! imagex apply --check dir.wim tmp; then
176 error "Integrity table on WIM not made correctly"
178 if ! diff -q -r dir tmp; then
179 error "Recursive diff of applied WIM with original directory failed"
183 # Appending and deleting images
185 echo "Testing appending WIM image"
186 imagex capture dir dir.wim
187 if ! imagex append dir2 dir.wim; then
188 error "Appending WIM image failed"
190 if ! test "`imagex_info dir.wim | grep 'Image Count' | awk '{print $3}'`" = 2; then
191 error "WIM image count not correct"
194 echo "Testing appending WIM image with existing name (this should generate errors)"
195 if imagex append dir2 dir.wim; then
196 error "Adding duplicate image name didn't fail"
198 echo "Testing appending WIM image with new name"
199 if ! imagex append dir2 dir.wim "newname"; then
200 error "Appending WIM image failed"
202 echo "Testing appending WIM image with integrity check"
203 if ! imagex append dir2 dir.wim "newname2" --check; then
204 error "Appending WIM image failed"
206 if ! test "`imagex_info dir.wim | grep Integrity | awk '{print $3}'`" = "yes"; then
207 error "Integrity table not set correctly on image append"
209 echo "Testing appending WIM image with no integrity check"
210 if ! imagex append dir2 dir.wim "newname3"; then
211 error "Appending WIM image failed"
213 if ! test "`imagex_info dir.wim | grep Integrity | awk '{print $3}'`" = "no"; then
214 error "WIM integrity table not removed"
216 # 5 images at this point
217 if ! test "`imagex_info dir.wim | grep 'Image Count' | awk '{print $3}'`" = 5; then
218 error "WIM does not contain the expected 5 images"
220 echo "Testing deleting first WIM image"
221 if ! imagex delete dir.wim 1; then
222 error "Failed to delete WIM image"
224 if ! test "`imagex_info dir.wim | grep 'Image Count' | awk '{print $3}'`" = 4; then
225 error "WIM image not deleted correctly"
227 echo "Testing deleting last WIM image"
228 if ! imagex delete dir.wim 4; then
229 error "Failed to delete WIM image"
231 if ! test "`imagex_info dir.wim | grep 'Image Count' | awk '{print $3}'`" = 3; then
232 error "WIM image not deleted correctly"
234 echo "Testing deleting invalid WIM image (this should generate errors)"
235 if imagex delete dir.wim 4; then
236 error "Expected to fail to delete non-existent WIM image"
238 if ! test "`imagex_info dir.wim | grep 'Image Count' | awk '{print $3}'`" = 3; then
239 error "Image count changed even though we intentionally failed to delete an image"
241 echo "Testing deleting all WIM images"
242 if ! imagex delete dir.wim all; then
243 error "Failed to delete all images from WIM"
245 if ! test "`imagex_info dir.wim | grep 'Image Count' | awk '{print $3}'`" = 0; then
246 error "Couldn't delete all WIM images correctly"
248 echo "Testing appending directory to empty WIM and making it bootable"
249 if ! imagex append dir dir.wim "myname" "mydesc" --check --boot; then
250 error "Couldn't append named, described, bootable image to empty WIM with integrity check"
252 if ! test "`imagex_info dir.wim | grep Integrity | awk '{print $3}'`" = "yes"; then
253 error "Integrity check not found"
255 if ! test "`imagex_info dir.wim | grep Boot | awk '{print $3}'`" = "1"; then
256 error "Bootable image not set correctly"
258 echo "Testing appending non-directory (should generate errors)"
259 if imagex append dir.wim dir.wim; then
260 error "Incorrectly succeeded to append non-directory to WIM"
262 echo "Testing appending non-existent file (should generate errors)"
263 if imagex append SOME_NONEXISTENT_FILE dir.wim; then
264 error "Incorrectly succeeded to append non-existent file to WIM"
266 if [ `id -u` != 0 ]; then
267 echo "Testing appending directory containing unreadable file (should generate errors)"
271 if imagex append dir3 dir.wim; then
272 error "Incorrectly succeeded in capturing directory with unreadable file"
277 # Applying multiple images, applying with hardlinks/symlinks
279 echo "Testing application of multiple images"
280 if ! imagex capture dir dir.wim; then
281 error "Failed to prepare test WIM"
283 if ! imagex append dir dir.wim "myname"; then
284 error "Failed to append image to test WIM"
286 if ! imagex apply dir.wim all tmp; then
287 error "Applying multiple images failed"
289 if ! diff -q -r tmp/dir tmp/myname || ! diff -q -r dir tmp/dir; then
290 error "Recursive diff of applied WIM with original directory failed"
292 if test "`get_link_count tmp/dir/lz77.c`" != 1; then
293 error "Incorrect link count on extracted file"
295 if test "`get_link_count tmp/myname/lz77.c`" != 1; then
296 error "Incorrect link count on extracted file"
298 if test "`get_inode_number tmp/myname/lz77.c`" = "`get_inode_number tmp/dir/lz77.c`"; then
299 error "Incorrect inode number"
302 echo "Testing application of multiple images with hardlinks"
303 if ! imagex apply dir.wim all tmp --hardlink; then
304 error "Failed to apply multiple images with cross-image hardlinks"
306 if ! diff -q -r tmp/dir tmp/myname || ! diff -q -r dir tmp/dir; then
307 error "Recursive diff of applied WIM with original directory failed"
309 if test "`get_link_count tmp/dir/lz77.c`" != 2; then
310 error "Incorrect link count on extracted file"
312 if test "`get_link_count tmp/myname/lz77.c`" != 2; then
313 error "Incorrect link count on extracted file"
315 if test "`get_inode_number tmp/myname/lz77.c`" != "`get_inode_number tmp/dir/lz77.c`"; then
316 error "Incorrect inode number"
320 echo "Testing application of single image containing identical files"
321 if ! imagex apply dir.wim 1 tmp; then
322 error "Failed to apply WIM"
324 if test "`get_link_count tmp/subdir/hello`" != 2; then
325 error "Incorrect link count on extracted file"
327 if test "`get_link_count tmp/subdir/hello2`" != 1; then
328 error "Incorrect link count on extracted file"
330 if test "`get_inode_number tmp/subdir/hello`" = "`get_inode_number tmp/subdir/hello2`"; then
331 error "Inode numbers on non-hard-linked files are the same"
333 if test "`get_inode_number tmp/subdir/hello`" != "`get_inode_number tmp/subdir/hellolink`"; then
334 error "Inode numbers on hard-linked files are different"
338 echo "Testing application of single image containing identical files with hardlinks"
339 if ! imagex apply dir.wim 1 tmp --hardlink; then
340 error "Failed to apply WIM"
342 if test "`get_link_count tmp/subdir/hello`" != 3; then
343 error "Incorrect link count on extracted file"
345 if test "`get_link_count tmp/subdir/hello2`" != 3; then
346 error "Incorrect link count on extracted file"
348 if test "`get_inode_number tmp/subdir/hello`" != "`get_inode_number tmp/subdir/hello2`"; then
349 error "Hard link set does not share inode number"
351 if test "`get_inode_number tmp/subdir/hello`" != "`get_inode_number tmp/subdir/hellolink`"; then
352 error "Hard link set does not share inode number"
356 echo "Testing application of single image containing identical files with symlinks"
357 if ! imagex apply dir.wim 1 tmp --symlink; then
358 error "Failed to apply WIM"
360 if test "`get_link_count tmp/subdir/hello`" != 1; then
361 error "Incorrect link count on extracted file"
363 if test "`get_link_count tmp/subdir/hello2`" != 1; then
364 error "Incorrect link count on extracted file"
366 if test "`get_inode_number tmp/subdir/hello`" = "`get_inode_number tmp/subdir/hello2`"; then
367 error "Incorrect inode number"
369 if ! test -L tmp/subdir/hello -o -L tmp/subdir/hello2 -o -L tmp/subdir/hellolink; then
370 error "Expected symlinks, but found non-symlinks"
375 # imagex split, imagex join
377 echo "Creating random files to test WIM splitting on"
379 for ((i = 0; i < 100; i++)); do
380 dd if=/dev/urandom of=tmp/file$i bs=4096 count=10 &> /dev/null
382 for flag in "--compress=none" "--compress=maximum" "--compress=fast"; do
383 echo "Using flag $flag"
384 if ! imagex capture tmp tmp.wim $flag; then
385 error "Failed to capture test WIM"
387 echo "Splitting WIM into 1 MiB chunks"
388 if ! imagex split tmp.wim tmp.swm 1; then
389 error "Failed to split WIM"
391 echo "Verifying the split WIMs (some errors expected)"
392 if test "`imagex_info tmp.swm | grep 'Part Number' | awk '{print $3}'`" != "1/4"; then
393 error "Part number of split WIM not correct"
395 if ! imagex dir tmp.swm > /dev/null; then
396 error "Failed to list files in split WIM"
398 if ! test -e tmp2.swm; then
399 error "Could not find split-WIM part 2"
401 if imagex dir tmp2.swm > /dev/null; then
402 error "Listed files in part 2 of split WIM (this should have failed)"
405 # Unsupported, should fail
406 if imagex_info tmp.swm --boot 0; then
407 error "Should not have been able to change boot index of split WIM"
409 echo "Joining the split WIMs and applying the result"
410 if ! imagex join tmp2.wim tmp*.wim; then
411 error "Failed to join split WIMs"
413 if ! imagex apply tmp2.wim tmp2; then
414 error "Failed to apply joined split WIM"
416 if ! imagex apply tmp.wim tmp3; then
417 error "Failed to apply test WIM"
419 if ! diff -q -r tmp tmp2 || ! diff -q -r tmp tmp3; then
420 error "Recursive diff of applied joined split WIM with original directory failed"
428 echo "Testing export of single image to new WIM"
429 if ! imagex capture dir dir.wim; then
430 error "Failed to capture test WIM"
432 if ! imagex append dir2 dir.wim; then
433 error "Failed to append image to test WIM"
435 if ! imagex export dir.wim dir new.wim; then
436 error "Failed to export single image to new WIM"
438 if test "`imagex_info new.wim | grep 'Image Count' | awk '{print $3}'`" != 1; then
439 error "Exporting single image to new WIM wasn't done correctly"
441 echo "Testing export of single image to existing WIM"
442 if ! imagex export dir.wim dir2 new.wim; then
443 error "Failed to export single image to existing WIM"
445 if test "`imagex_info new.wim | grep 'Image Count' | awk '{print $3}'`" != 2; then
446 error "Exporting single image to existing WIM wasn't done correctly"
448 echo "Testing export of single image to existing WIM using wrong compression type"
449 if imagex export dir.wim dir2 new.wim newname --compress=maximum; then
450 error "Successfully exported image using wrong compression type"
453 echo "Testing export of multiple images to new WIM"
454 if ! imagex export dir.wim all new.wim; then
455 error "Failed to export multiple images to new WIM"
457 if test "`imagex_info new.wim | grep 'Image Count' | awk '{print $3}'`" != 2; then
458 error "Exporting multiple images to new WIM wasn't done correctly"
460 if ! imagex capture dir2 new.wim newname; then
461 error "Failed to capture test WIM"
463 echo "Testing export of multiple images to existing WIM"
464 if ! imagex export dir.wim all new.wim; then
465 error "Failed to export multiple images to existing WIM"
467 echo "Testing export of multiple images to existing WIM with --boot"
468 if ! imagex capture dir2 new.wim newname; then
469 error "Failed to capture test WIM"
471 if ! imagex_info dir.wim --boot 1; then
472 error "Failed to set boot index on test WIM"
474 if ! imagex export dir.wim all new.wim --boot; then
475 error "Failed to export multiple images to existing WIM with bootable image"
477 echo "Testing export of multiple images to existing WIM with --boot, but no bootable image (errors expected)"
478 if ! imagex capture dir2 new.wim newname; then
479 error "Failed to capture test WIM"
481 if ! imagex_info dir.wim --boot 0; then
482 error "Failed to clear boot index on test WIM"
484 if imagex export dir.wim all new.wim --boot; then
485 error "Successfully exported multiple images with --boot but with no bootable images"
488 # Test exporting an image to another WIM, then applying it.
489 # We try with 5 different combinations of compression types to make sure we go
490 # through all paths in the resource-handling code.
491 for i in 1 2 3 4 5; do
494 cflag1="--compress=none";
495 cflag2="--compress=none";
498 cflag1="--compress=xpress";
499 cflag2="--compress=xpress";
502 cflag1="--compress=xpress"
503 cflag2="--compress=lzx"
506 cflag1="--compress=none"
507 cflag2="--compress=xpress"
510 cflag1="--compress=xpress"
511 cflag2="--compress=none"
514 echo "Testing exporting then applying an image (\"$cflag1\" => \"$cflag2\")"
515 rm -rf dir.wim new.wim tmp tmp2
516 imagex capture dir dir.wim $cflag1
517 imagex capture dir2 dir2.wim $cflag2
518 imagex export dir.wim dir dir2.wim
519 imagex apply dir.wim dir tmp
520 if ! imagex apply dir2.wim dir tmp2; then
521 error "Failed to apply image that was exported to a WIM"
523 if ! diff -r tmp tmp2; then
524 error "Image that was exported to a WIM was not applied correctly"
528 echo "**********************************************************"
529 echo " Basic imagex tests passed "
530 echo "**********************************************************"