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"
12 TEST_SUBDIR=tmpdir_test-imagex
14 # Execute the tests in a subdirectory to avoid conflicts with concurrent tests
21 cp $srcdir/src/*.c dir
23 echo 'hello' > dir/subdir/hello
24 echo 'hello' > dir/subdir/hello2
25 ln dir/subdir/hello dir/subdir/hellolink
26 echo -n > dir/subdir/empty_file
27 ln -s hello dir/subdir/rel_symlink
30 echo 'testing' > dir2/file
31 dd if=/dev/zero of=dir2/zeroes bs=4096 count=5
33 # Capturing and applying WIM with None, LZX, and XPRESS compression
35 for comp_type in None LZX XPRESS; do
36 echo "Testing capture and application of $comp_type-compressed WIM"
37 if ! imagex capture dir dir.wim --compress=$comp_type; then
38 error "'imagex capture' failed"
40 if ! imagex apply dir.wim tmp; then
41 error "'imagex apply' failed"
43 if ! test `wim_ctype dir.wim` = "$comp_type"; then
44 error "'imagex info' didn't report the compression type correctly"
46 if ! diff -q -r dir tmp; then
47 error "Recursive diff of extracted directory with original failed"
49 if ! test `get_link_count tmp/subdir/hello` = 2; then
50 error "Incorrect number of hard links in extracted file"
52 if ! test `get_inode_number tmp/subdir/hello` != `get_inode_number tmp/subdir/hello2`; then
53 error "Expected different inode numbers in files not hard-linked"
55 if ! test "`get_inode_number tmp/subdir/hello`" = "`get_inode_number tmp/subdir/hellolink`"; then
56 error "Expected same inode numbers in hard-linked files"
58 if ! test -L tmp/subdir/rel_symlink; then
59 error "Symlink not extracted correctly"
61 if ! test "`readlink tmp/subdir/rel_symlink`" = "hello"; then
62 error "Symlink target not correct"
68 # Capturing and modifying name, description, and bootable flag
70 echo "Testing capture of WIM with default name and description"
71 imagex capture dir dir.wim
72 if ! test "`imagex info dir.wim | grep Name | awk '{print $2}'`" = "dir"; then
73 error "WIM name not set correctly"
75 if ! test "`imagex info dir.wim | grep Description | awk '{print $2}'`" = ""; then
76 error "WIM description not set correctly"
79 echo "Testing capture of WIM with default boot flag"
80 imagex capture dir dir.wim
81 if ! test "`imagex info dir.wim | grep Boot | awk '{print $3}'`" = "0"; then
82 error "WIM boot flag not set correctly"
85 echo "Testing changing image bootable flag"
86 if ! imagex info dir.wim 1 --boot; then
87 error "Failed to change bootable image"
89 if ! test "`imagex info dir.wim | grep Boot | awk '{print $3}'`" = "1"; then
90 error "Bootable image not changed correctly"
92 echo "Testing changing image bootable flag"
93 if ! imagex info dir.wim 0 --boot; then
94 error "Failed to reset bootable image"
96 if ! test "`imagex info dir.wim | grep Boot | awk '{print $3}'`" = "0"; then
97 error "Bootable image not reset correctly"
99 echo "Testing changing image bootable flag to invalid image (this should generate errors)"
100 if imagex info dir.wim 2 --boot; then
101 error "Succeeded in changing bootable image to invalid number"
103 if ! test "`imagex info dir.wim | grep Boot | awk '{print $3}'`" = "0"; then
104 error "Boot flag was changed even though the change command was supposed to fail"
108 echo "Testing capture of WIM with name and description"
109 if ! imagex capture dir dir.wim "myname" "mydesc"; then
110 error "Failed to capture WIM with specified name and description"
112 if ! test "`imagex info dir.wim | grep Name | awk '{print $2}'`" = "myname"; then
113 error "WIM name not set correctly"
115 if ! test "`imagex info dir.wim | grep Description | awk '{print $2}'`" = "mydesc"; then
116 error "WIM name not set correctly"
118 echo "Testing printing WIM lookup table"
119 if ! imagex info --lookup-table dir.wim > /dev/null; then
120 error "Failed to print WIM lookup table"
122 echo "Testing printing WIM header"
123 if ! imagex info --header dir.wim > /dev/null; then
124 error "Failed to print WIM header"
126 echo "Testing printing WIM XML info"
127 if ! imagex info --xml dir.wim > /dev/null; then
128 error "Failed to print WIM XML data"
130 echo "Testing extracting WIM XML info"
131 if ! imagex info --extract-xml=dir.xml dir.wim; then
132 error "Failed to extract WIM XML data"
134 echo "Testing printing WIM metadata"
135 if ! imagex info --metadata dir.wim > /dev/null; then
136 error "Failed to print WIM metadata"
138 rm -rf dir.wim tmp dir.xml
140 echo "Testing capture of bootable WIM"
141 if ! imagex capture dir dir.wim --boot; then
142 error "Failed to capture bootable WIM"
144 if ! test "`imagex info dir.wim | grep Boot | awk '{print $3}'`" = "1"; then
145 error "Boot flag on bootable WIM not set correctly"
151 echo "Testing capture of WIM with integrity table"
152 if ! imagex capture dir dir.wim --check; then
153 error "Failed to capture WIM with integrity table"
155 if ! test "`imagex info dir.wim | grep Integrity | awk '{print $3}'`" = "yes"; then
156 error "Integrity table on WIM not made"
158 if ! imagex apply --check dir.wim tmp; then
159 error "Integrity table on WIM not made correctly"
161 if ! diff -q -r dir tmp; then
162 error "Recursive diff of applied WIM with original directory failed"
166 # Appending and deleting images
168 echo "Testing appending WIM image"
169 imagex capture dir dir.wim
170 if ! imagex append dir2 dir.wim; then
171 error "Appending WIM image failed"
173 if ! test "`imagex info dir.wim | grep 'Image Count' | awk '{print $3}'`" = 2; then
174 error "WIM image count not correct"
177 echo "Testing appending WIM image with existing name (this should generate errors)"
178 if imagex append dir2 dir.wim; then
179 error "Adding duplicate image name didn't fail"
181 echo "Testing appending WIM image with new name"
182 if ! imagex append dir2 dir.wim "newname"; then
183 error "Appending WIM image failed"
185 echo "Testing appending WIM image with integrity check"
186 if ! imagex append dir2 dir.wim "newname2" --check; then
187 error "Appending WIM image failed"
189 if ! test "`imagex info dir.wim | grep Integrity | awk '{print $3}'`" = "yes"; then
190 error "Integrity table not set correctly on image append"
192 echo "Testing appending WIM image with no integrity check"
193 if ! imagex append dir2 dir.wim "newname3"; then
194 error "Appending WIM image failed"
196 if ! test "`imagex info dir.wim | grep Integrity | awk '{print $3}'`" = "no"; then
197 error "WIM integrity table not removed"
199 # 5 images at this point
200 if ! test "`imagex info dir.wim | grep 'Image Count' | awk '{print $3}'`" = 5; then
201 error "WIM does not contain the expected 5 images"
203 echo "Testing deleting first WIM image"
204 if ! imagex delete dir.wim 1; then
205 error "Failed to delete WIM image"
207 if ! test "`imagex info dir.wim | grep 'Image Count' | awk '{print $3}'`" = 4; then
208 error "WIM image not deleted correctly"
210 echo "Testing deleting last WIM image"
211 if ! imagex delete dir.wim 4; then
212 error "Failed to delete WIM image"
214 if ! test "`imagex info dir.wim | grep 'Image Count' | awk '{print $3}'`" = 3; then
215 error "WIM image not deleted correctly"
217 echo "Testing deleting invalid WIM image (this should generate errors)"
218 if imagex delete dir.wim 4; then
219 error "Expected to fail to delete non-existent WIM image"
221 if ! test "`imagex info dir.wim | grep 'Image Count' | awk '{print $3}'`" = 3; then
222 error "Image count changed even though we intentionally failed to delete an image"
224 echo "Testing deleting all WIM images"
225 if ! imagex delete dir.wim all; then
226 error "Failed to delete all images from WIM"
228 if ! test "`imagex info dir.wim | grep 'Image Count' | awk '{print $3}'`" = 0; then
229 error "Couldn't delete all WIM images correctly"
231 echo "Testing appending directory to empty WIM and making it bootable"
232 if ! imagex append dir dir.wim "myname" "mydesc" --check --boot; then
233 error "Couldn't append named, described, bootable image to empty WIM with integrity check"
235 if ! test "`imagex info dir.wim | grep Integrity | awk '{print $3}'`" = "yes"; then
236 error "Integrity check not found"
238 if ! test "`imagex info dir.wim | grep Boot | awk '{print $3}'`" = "1"; then
239 error "Bootable image not set correctly"
241 echo "Testing appending non-directory (should generate errors)"
242 if imagex append dir.wim dir.wim; then
243 error "Incorrectly succeeded to append non-directory to WIM"
245 echo "Testing appending non-existent file (should generate errors)"
246 if imagex append SOME_NONEXISTENT_FILE dir.wim; then
247 error "Incorrectly succeeded to append non-existent file to WIM"
249 if [ `id -u` != 0 ]; then
250 echo "Testing appending directory containing unreadable file (should generate errors)"
254 if imagex append dir3 dir.wim; then
255 error "Incorrectly succeeded in capturing directory with unreadable file"
260 # Applying multiple images, applying with hardlinks/symlinks
262 echo "Testing application of multiple images"
263 if ! imagex capture dir dir.wim; then
264 error "Failed to prepare test WIM"
266 if ! imagex append dir dir.wim "myname"; then
267 error "Failed to append image to test WIM"
269 if ! imagex apply dir.wim all tmp; then
270 error "Applying multiple images failed"
272 if ! diff -q -r tmp/dir tmp/myname || ! diff -q -r dir tmp/dir; then
273 error "Recursive diff of applied WIM with original directory failed"
275 if test "`get_link_count tmp/dir/lz77.c`" != 1; then
276 error "Incorrect link count on extracted file"
278 if test "`get_link_count tmp/myname/lz77.c`" != 1; then
279 error "Incorrect link count on extracted file"
281 if test "`get_inode_number tmp/myname/lz77.c`" = "`get_inode_number tmp/dir/lz77.c`"; then
282 error "Incorrect inode number"
285 echo "Testing application of multiple images with hardlinks"
286 if ! imagex apply dir.wim all tmp --hardlink; then
287 error "Failed to apply multiple images with cross-image hardlinks"
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`" != 2; then
293 error "Incorrect link count on extracted file"
295 if test "`get_link_count tmp/myname/lz77.c`" != 2; 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"
303 echo "Testing application of single image containing identical files"
304 if ! imagex apply dir.wim 1 tmp; then
305 error "Failed to apply WIM"
307 if test "`get_link_count tmp/subdir/hello`" != 2; then
308 error "Incorrect link count on extracted file"
310 if test "`get_link_count tmp/subdir/hello2`" != 1; then
311 error "Incorrect link count on extracted file"
313 if test "`get_inode_number tmp/subdir/hello`" = "`get_inode_number tmp/subdir/hello2`"; then
314 error "Inode numbers on non-hard-linked files are the same"
316 if test "`get_inode_number tmp/subdir/hello`" != "`get_inode_number tmp/subdir/hellolink`"; then
317 error "Inode numbers on hard-linked files are different"
321 echo "Testing application of single image containing identical files with hardlinks"
322 if ! imagex apply dir.wim 1 tmp --hardlink; then
323 error "Failed to apply WIM"
325 if test "`get_link_count tmp/subdir/hello`" != 3; then
326 error "Incorrect link count on extracted file"
328 if test "`get_link_count tmp/subdir/hello2`" != 3; then
329 error "Incorrect link count on extracted file"
331 if test "`get_inode_number tmp/subdir/hello`" != "`get_inode_number tmp/subdir/hello2`"; then
332 error "Hard link set does not share inode number"
334 if test "`get_inode_number tmp/subdir/hello`" != "`get_inode_number tmp/subdir/hellolink`"; then
335 error "Hard link set does not share inode number"
339 echo "Testing application of single image containing identical files with symlinks"
340 if ! imagex apply dir.wim 1 tmp --symlink; then
341 error "Failed to apply WIM"
343 if test "`get_link_count tmp/subdir/hello`" != 1; then
344 error "Incorrect link count on extracted file"
346 if test "`get_link_count tmp/subdir/hello2`" != 1; then
347 error "Incorrect link count on extracted file"
349 if test "`get_inode_number tmp/subdir/hello`" = "`get_inode_number tmp/subdir/hello2`"; then
350 error "Incorrect inode number"
352 if ! test -L tmp/subdir/hello -o -L tmp/subdir/hello2 -o -L tmp/subdir/hellolink; then
353 error "Expected symlinks, but found non-symlinks"
358 # imagex split, imagex join
360 echo "Creating random files to test WIM splitting on"
362 for ((i = 0; i < 100; i++)); do
363 dd if=/dev/urandom of=tmp/file$i bs=4096 count=10 &> /dev/null
365 for flag in "--compress=none" "--compress=maximum" "--compress=fast"; do
366 echo "Using flag $flag"
367 if ! imagex capture tmp tmp.wim $flag; then
368 error "Failed to capture test WIM"
370 echo "Splitting WIM into 1 MiB chunks"
371 if ! imagex split tmp.wim tmp.swm 1; then
372 error "Failed to split WIM"
374 echo "Verifying the split WIMs (some errors expected)"
375 if test "`imagex info tmp.swm | grep 'Part Number' | awk '{print $3}'`" != "1/4"; then
376 error "Part number of split WIM not correct"
378 if ! imagex dir tmp.swm > /dev/null; then
379 error "Failed to list files in split WIM"
381 if ! test -e tmp2.swm; then
382 error "Could not find split-WIM part 2"
384 if imagex dir tmp2.swm > /dev/null; then
385 error "Listed files in part 2 of split WIM (this should have failed)"
388 # Unsupported, should fail
389 if imagex info tmp.swm --boot 0; then
390 error "Should not have been able to change boot index of split WIM"
392 echo "Joining the split WIMs and applying the result"
393 if ! imagex join tmp2.wim tmp*.wim; then
394 error "Failed to join split WIMs"
396 if ! imagex apply tmp2.wim tmp2; then
397 error "Failed to apply joined split WIM"
399 if ! imagex apply tmp.wim tmp3; then
400 error "Failed to apply test WIM"
402 if ! diff -q -r tmp tmp2 || ! diff -q -r tmp tmp3; then
403 error "Recursive diff of applied joined split WIM with original directory failed"
411 echo "Testing export of single image to new WIM"
412 if ! imagex capture dir dir.wim; then
413 error "Failed to capture test WIM"
415 if ! imagex append dir2 dir.wim; then
416 error "Failed to append image to test WIM"
418 if ! imagex export dir.wim dir new.wim; then
419 error "Failed to export single image to new WIM"
421 if test "`imagex info new.wim | grep 'Image Count' | awk '{print $3}'`" != 1; then
422 error "Exporting single image to new WIM wasn't done correctly"
424 echo "Testing export of single image to existing WIM"
425 if ! imagex export dir.wim dir2 new.wim; then
426 error "Failed to export single image to existing WIM"
428 if test "`imagex info new.wim | grep 'Image Count' | awk '{print $3}'`" != 2; then
429 error "Exporting single image to existing WIM wasn't done correctly"
431 echo "Testing export of single image to existing WIM using wrong compression type"
432 if imagex export dir.wim dir2 new.wim newname --compress=maximum; then
433 error "Successfully exported image using wrong compression type"
436 echo "Testing export of multiple images to new WIM"
437 if ! imagex export dir.wim all new.wim; then
438 error "Failed to export multiple images to new WIM"
440 if test "`imagex info new.wim | grep 'Image Count' | awk '{print $3}'`" != 2; then
441 error "Exporting multiple images to new WIM wasn't done correctly"
443 if ! imagex capture dir2 new.wim newname; then
444 error "Failed to capture test WIM"
446 echo "Testing export of multiple images to existing WIM"
447 if ! imagex export dir.wim all new.wim; then
448 error "Failed to export multiple images to existing WIM"
450 echo "Testing export of multiple images to existing WIM with --boot"
451 if ! imagex capture dir2 new.wim newname; then
452 error "Failed to capture test WIM"
454 if ! imagex info dir.wim --boot 1; then
455 error "Failed to set boot index on test WIM"
457 if ! imagex export dir.wim all new.wim --boot; then
458 error "Failed to export multiple images to existing WIM with bootable image"
460 echo "Testing export of multiple images to existing WIM with --boot, but no bootable image (errors expected)"
461 if ! imagex capture dir2 new.wim newname; then
462 error "Failed to capture test WIM"
464 if ! imagex info dir.wim --boot 0; then
465 error "Failed to clear boot index on test WIM"
467 if imagex export dir.wim all new.wim --boot; then
468 error "Successfully exported multiple images with --boot but with no bootable images"
471 # Test exporting an image to another WIM, then applying it.
472 # We try with 5 different combinations of compression types to make sure we go
473 # through all paths in the resource-handling code.
474 for i in 1 2 3 4 5; do
477 cflag1="--compress=none";
478 cflag2="--compress=none";
481 cflag1="--compress=xpress";
482 cflag2="--compress=xpress";
485 cflag1="--compress=xpress"
486 cflag2="--compress=lzx"
489 cflag1="--compress=none"
490 cflag2="--compress=xpress"
493 cflag1="--compress=xpress"
494 cflag2="--compress=none"
497 echo "Testing exporting then applying an image (\"$cflag1\" => \"$cflag2\")"
498 rm -rf dir.wim new.wim tmp tmp2
499 imagex capture dir dir.wim $cflag1
500 imagex capture dir2 dir2.wim $cflag2
501 imagex export dir.wim dir dir2.wim
502 imagex apply dir.wim dir tmp
503 if ! imagex apply dir2.wim dir tmp2; then
504 error "Failed to apply image that was exported to a WIM"
506 if ! diff -r tmp tmp2; then
507 error "Image that was exported to a WIM was not applied correctly"
511 echo "**********************************************************"
512 echo " Basic imagex tests passed "
513 echo "**********************************************************"
515 # Leave test subdirectory and cleanup