3 # This script does some sanity testing of the 'wimlib-imagex' program. It by no
4 # means tests every aspect of wimlib comprehensively.
8 srcdir="${srcdir:-.}/.."
9 srcdir="$(cd $srcdir; pwd)"
10 . "$srcdir/tests/test_utils.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 ! wimcapture dir dir.wim --compress=$comp_type; then
38 error "'wimcapture' failed"
40 if ! wimapply dir.wim tmp; then
41 error "'wimapply' failed"
43 if ! test `wim_ctype dir.wim` = "$comp_type"; then
44 error "'wiminfo' 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 # Test wimverify and the SHA-1 code
69 WIMLIB_DISABLE_CPU_FEATURES='*' wimcapture dir dir.wim --compress=none
71 for cpu_feature in '' sha1 bmi2 avx sse4.2 sse4.1 ssse3; do
72 [ -n "$disabled" ] && disabled+=','
73 disabled+="$cpu_feature"
74 if ! WIMLIB_DISABLE_CPU_FEATURES=$disabled wimverify dir.wim; then
75 error "wimverify failed (cpu_features_disabled=$disabled)"
79 # Test wimappend --create
81 if wimappend dir dir.wim; then
82 error "wimappend to nonexisting file unexpectedly succeeded"
84 if ! wimappend dir dir.wim --create; then
85 error "wimappend --create to nonexisting file failed"
87 if ! wimappend dir dir.wim --create; then
88 error "wimappend --create to existing file failed"
90 if ! test "`wiminfo dir.wim | grep 'Image Count' | awk '{print $3}'`" = 2; then
91 error "Incorrect WIM image count after wimappend --create"
94 # Capturing and modifying name, description, and bootable flag
96 echo "Testing capture of WIM with default name and description"
97 wimcapture dir dir.wim
98 if ! test "`wiminfo dir.wim | grep Name | awk '{print $2}'`" = "dir"; then
99 error "WIM name not set correctly"
101 if ! test "`wiminfo dir.wim | grep Description | awk '{print $2}'`" = ""; then
102 error "WIM description not set correctly"
105 echo "Testing capture of WIM with default boot flag"
106 wimcapture dir dir.wim
107 if ! test "`wiminfo dir.wim | grep '^Boot Index' | awk '{print $3}'`" = "0"; then
108 error "WIM boot flag not set correctly"
111 echo "Testing changing image bootable flag"
112 if ! wiminfo dir.wim 1 --boot; then
113 error "Failed to change bootable image"
115 if ! test "`wiminfo dir.wim | grep '^Boot Index' | awk '{print $3}'`" = "1"; then
116 error "Bootable image not changed correctly"
118 echo "Testing changing image bootable flag"
119 if ! wiminfo dir.wim 0 --boot; then
120 error "Failed to reset bootable image"
122 if ! test "`wiminfo dir.wim | grep '^Boot Index' | awk '{print $3}'`" = "0"; then
123 error "Bootable image not reset correctly"
125 echo "Testing changing image bootable flag to invalid image (this should generate errors)"
126 if wiminfo dir.wim 2 --boot; then
127 error "Succeeded in changing bootable image to invalid number"
129 if ! test "`wiminfo dir.wim | grep '^Boot Index' | awk '{print $3}'`" = "0"; then
130 error "Boot flag was changed even though the change command was supposed to fail"
134 echo "Testing capture of WIM with name and description"
135 if ! wimcapture dir dir.wim "myname" "mydesc"; then
136 error "Failed to capture WIM with specified name and description"
138 if ! test "`wiminfo dir.wim | grep Name | awk '{print $2}'`" = "myname"; then
139 error "WIM name not set correctly"
141 if ! test "`wiminfo dir.wim | grep Description | awk '{print $2}'`" = "mydesc"; then
142 error "WIM name not set correctly"
144 echo "Testing printing WIM lookup table"
145 if ! wiminfo --lookup-table dir.wim > /dev/null; then
146 error "Failed to print WIM lookup table"
148 echo "Testing printing WIM header"
149 if ! wiminfo --header dir.wim > /dev/null; then
150 error "Failed to print WIM header"
152 echo "Testing printing WIM XML info"
153 if ! wiminfo --xml dir.wim > /dev/null; then
154 error "Failed to print WIM XML data"
156 echo "Testing extracting WIM XML info"
157 if ! wiminfo --extract-xml=dir.xml dir.wim; then
158 error "Failed to extract WIM XML data"
160 echo "Testing printing WIM metadata"
161 if ! wimdir --detailed dir.wim > /dev/null; then
162 error "Failed to print WIM metadata"
164 rm -rf dir.wim tmp dir.xml
166 echo "Testing capture of bootable WIM"
167 if ! wimcapture dir dir.wim --boot; then
168 error "Failed to capture bootable WIM"
170 if ! test "`wiminfo dir.wim | grep '^Boot Index' | awk '{print $3}'`" = "1"; then
171 error "Boot flag on bootable WIM not set correctly"
177 echo "Testing capture of WIM with integrity table"
178 if ! wimcapture dir dir.wim --check; then
179 error "Failed to capture WIM with integrity table"
181 if ! wiminfo dir.wim | grep -q Integrity; then
182 error "Integrity table on WIM not made"
184 if ! wimapply --check dir.wim tmp; then
185 error "Integrity table on WIM not made correctly"
187 if ! diff -q -r dir tmp; then
188 error "Recursive diff of applied WIM with original directory failed"
192 # Appending and deleting images
194 echo "Testing appending WIM image"
195 wimcapture dir dir.wim
196 if ! wimappend dir2 dir.wim; then
197 error "Appending WIM image failed"
199 if ! test "`wiminfo dir.wim | grep 'Image Count' | awk '{print $3}'`" = 2; then
200 error "WIM image count not correct"
203 echo "Testing appending WIM image with existing name (this should generate errors)"
204 if wimappend dir2 dir.wim "dir"; then
205 error "Adding duplicate image name didn't fail"
207 echo "Testing appending WIM image with new name"
208 if ! wimappend dir2 dir.wim "newname"; then
209 error "Appending WIM image failed"
211 echo "Testing appending WIM image with integrity check"
212 if ! wimappend dir2 dir.wim "newname2" --check; then
213 error "Appending WIM image failed"
215 if ! wiminfo dir.wim | grep -q Integrity; then
216 error "Integrity table not set correctly on image append"
218 echo "Testing appending WIM image with no integrity check"
219 if ! wimappend dir2 dir.wim "newname3" --nocheck; then
220 error "Appending WIM image failed"
222 if wiminfo dir.wim | grep -q Integrity; then
223 error "WIM integrity table not removed"
225 # 5 images at this point
226 if ! test "`wiminfo dir.wim | grep 'Image Count' | awk '{print $3}'`" = 5; then
227 error "WIM does not contain the expected 5 images"
229 echo "Testing deleting first WIM image"
230 if ! wimdelete dir.wim 1; then
231 error "Failed to delete WIM image"
233 if ! test "`wiminfo dir.wim | grep 'Image Count' | awk '{print $3}'`" = 4; then
234 error "WIM image not deleted correctly"
236 echo "Testing deleting last WIM image"
237 if ! wimdelete dir.wim 4; then
238 error "Failed to delete WIM image"
240 if ! test "`wiminfo dir.wim | grep 'Image Count' | awk '{print $3}'`" = 3; then
241 error "WIM image not deleted correctly"
243 echo "Testing deleting invalid WIM image (this should generate errors)"
244 if wimdelete dir.wim 4; then
245 error "Expected to fail to delete non-existent WIM image"
247 if ! test "`wiminfo dir.wim | grep 'Image Count' | awk '{print $3}'`" = 3; then
248 error "Image count changed even though we intentionally failed to delete an image"
250 echo "Testing deleting all WIM images"
251 if ! wimdelete dir.wim all; then
252 error "Failed to delete all images from WIM"
254 if ! test "`wiminfo dir.wim | grep 'Image Count' | awk '{print $3}'`" = 0; then
255 error "Couldn't delete all WIM images correctly"
257 echo "Testing appending directory to empty WIM and making it bootable"
258 if ! wimappend dir dir.wim "myname" "mydesc" --check --boot; then
259 error "Couldn't append named, described, bootable image to empty WIM with integrity check"
261 if ! wiminfo dir.wim | grep -q Integrity; then
262 error "Integrity check not found"
264 if ! test "`wiminfo dir.wim | grep '^Boot Index' | awk '{print $3}'`" = "1"; then
265 error "Bootable image not set correctly"
267 echo "Testing appending non-directory (should generate errors)"
268 if wimappend dir.wim dir.wim; then
269 error "Incorrectly succeeded to append non-directory to WIM"
271 echo "Testing appending non-existent file (should generate errors)"
272 if wimappend SOME_NONEXISTENT_FILE dir.wim; then
273 error "Incorrectly succeeded to append non-existent file to WIM"
275 if [ `id -u` != 0 ]; then
276 echo "Testing appending directory containing unreadable file (should generate errors)"
280 if wimappend dir3 dir.wim; then
281 error "Incorrectly succeeded in capturing directory with unreadable file"
286 # Applying multiple images, applying with hardlinks/symlinks
288 echo "Testing application of multiple images"
289 if ! wimcapture dir dir.wim; then
290 error "Failed to prepare test WIM"
292 if ! wimappend dir dir.wim "myname"; then
293 error "Failed to append image to test WIM"
295 if ! wimapply dir.wim all tmp; then
296 error "Applying multiple images failed"
298 if ! diff -q -r tmp/dir tmp/myname || ! diff -q -r dir tmp/dir; then
299 error "Recursive diff of applied WIM with original directory failed"
301 if test "`get_link_count tmp/dir/write.c`" != 1; then
302 error "Incorrect link count on extracted file"
304 if test "`get_link_count tmp/myname/write.c`" != 1; then
305 error "Incorrect link count on extracted file"
307 if test "`get_inode_number tmp/myname/write.c`" = "`get_inode_number tmp/dir/write.c`"; then
308 error "Incorrect inode number"
312 echo "Testing application of single image containing identical files"
313 if ! wimapply dir.wim 1 tmp; then
314 error "Failed to apply WIM"
316 if test "`get_link_count tmp/subdir/hello`" != 2; then
317 error "Incorrect link count on extracted file"
319 if test "`get_link_count tmp/subdir/hello2`" != 1; then
320 error "Incorrect link count on extracted file"
322 if test "`get_inode_number tmp/subdir/hello`" = "`get_inode_number tmp/subdir/hello2`"; then
323 error "Inode numbers on non-hard-linked files are the same"
325 if test "`get_inode_number tmp/subdir/hello`" != "`get_inode_number tmp/subdir/hellolink`"; then
326 error "Inode numbers on hard-linked files are different"
332 echo "Creating random files to test WIM splitting on"
334 for ((i = 0; i < 100; i++)); do
335 dd if=/dev/urandom of=tmp/file$i bs=4096 count=10 &> /dev/null
337 for flag in "--compress=none" "--compress=maximum" "--compress=fast"; do
338 echo "Using flag $flag"
339 if ! wimcapture tmp tmp.wim $flag; then
340 error "Failed to capture test WIM"
342 echo "Splitting WIM into 1 MiB chunks"
343 if ! wimsplit tmp.wim tmp.swm 1; then
344 error "Failed to split WIM"
346 echo "Verifying the split WIMs (some errors expected)"
347 if test "`wiminfo tmp.swm | grep 'Part Number' | awk '{print $3}'`" != "1/4"; then
348 error "Part number of split WIM not correct"
350 if ! wimdir tmp.swm > /dev/null; then
351 error "Failed to list files in split WIM"
353 if ! test -e tmp2.swm; then
354 error "Could not find split-WIM part 2"
356 if wimdir tmp2.swm > /dev/null; then
357 error "Listed files in part 2 of split WIM (this should have failed)"
360 # Unsupported, should fail
361 if wiminfo tmp.swm --boot 1; then
362 error "Should not have been able to change boot index of split WIM"
364 echo "Joining the split WIMs and applying the result"
365 if ! wimjoin tmp2.wim tmp*.wim; then
366 error "Failed to join split WIMs"
368 if ! wimapply tmp2.wim tmp2; then
369 error "Failed to apply joined split WIM"
371 if ! wimapply tmp.wim tmp3; then
372 error "Failed to apply test WIM"
374 if ! diff -q -r tmp tmp2 || ! diff -q -r tmp tmp3; then
375 error "Recursive diff of applied joined split WIM with original directory failed"
383 echo "Testing export of single image to new WIM"
384 if ! wimcapture dir dir.wim; then
385 error "Failed to capture test WIM"
387 if ! wimappend dir2 dir.wim; then
388 error "Failed to append image to test WIM"
390 if ! wimexport dir.wim dir new.wim; then
391 error "Failed to export single image to new WIM"
393 if test "`wiminfo new.wim | grep 'Image Count' | awk '{print $3}'`" != 1; then
394 error "Exporting single image to new WIM wasn't done correctly"
396 echo "Testing export of single image to existing WIM"
397 if ! wimexport dir.wim dir2 new.wim; then
398 error "Failed to export single image to existing WIM"
400 if test "`wiminfo new.wim | grep 'Image Count' | awk '{print $3}'`" != 2; then
401 error "Exporting single image to existing WIM wasn't done correctly"
403 echo "Testing export of single image to existing WIM using wrong compression type"
404 if wimexport dir.wim dir2 new.wim newname --compress=xpress; then
405 error "Successfully exported image using wrong compression type"
408 echo "Testing export of multiple images to new WIM"
409 if ! wimexport dir.wim all new.wim; then
410 error "Failed to export multiple images to new WIM"
412 if test "`wiminfo new.wim | grep 'Image Count' | awk '{print $3}'`" != 2; then
413 error "Exporting multiple images to new WIM wasn't done correctly"
415 if ! wimcapture dir2 new.wim newname; then
416 error "Failed to capture test WIM"
418 echo "Testing export of multiple images to existing WIM"
419 if ! wimexport dir.wim all new.wim; then
420 error "Failed to export multiple images to existing WIM"
422 echo "Testing export of multiple images to existing WIM with --boot"
423 if ! wimcapture dir2 new.wim newname; then
424 error "Failed to capture test WIM"
426 if ! wiminfo dir.wim --boot 1; then
427 error "Failed to set boot index on test WIM"
429 if ! wimexport dir.wim all new.wim --boot; then
430 error "Failed to export multiple images to existing WIM with bootable image"
432 echo "Testing export of multiple images to existing WIM with --boot, but no bootable image (errors expected)"
433 if ! wimcapture dir2 new.wim newname; then
434 error "Failed to capture test WIM"
436 if ! wiminfo dir.wim --boot 0; then
437 error "Failed to clear boot index on test WIM"
439 if wimexport dir.wim all new.wim --boot; then
440 error "Successfully exported multiple images with --boot but with no bootable images"
443 # Test exporting an image to another WIM, then applying it.
444 # We try with 5 different combinations of compression types to make sure we go
445 # through all paths in the resource-handling code.
446 for i in 1 2 3 4 5; do
449 cflag1="--compress=none";
450 cflag2="--compress=none";
453 cflag1="--compress=xpress";
454 cflag2="--compress=xpress";
457 cflag1="--compress=xpress"
458 cflag2="--compress=lzx"
461 cflag1="--compress=none"
462 cflag2="--compress=xpress"
465 cflag1="--compress=xpress"
466 cflag2="--compress=none"
469 echo "Testing exporting then applying an image (\"$cflag1\" => \"$cflag2\")"
470 rm -rf dir.wim new.wim tmp tmp2
471 wimcapture dir dir.wim $cflag1
472 wimcapture dir2 dir2.wim $cflag2
473 wimexport dir.wim dir dir2.wim
474 wimapply dir.wim dir tmp
475 if ! wimapply dir2.wim dir tmp2; then
476 error "Failed to apply image that was exported to a WIM"
478 if ! diff -r tmp tmp2; then
479 error "Image that was exported to a WIM was not applied correctly"
483 echo "**********************************************************"
484 echo " Basic wimlib-imagex tests passed "
485 echo "**********************************************************"
487 # Leave test subdirectory and cleanup