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 wimappend --create
70 if wimappend dir dir.wim; then
71 error "wimappend to nonexisting file unexpectedly succeeded"
73 if ! wimappend dir dir.wim --create; then
74 error "wimappend --create to nonexisting file failed"
76 if ! wimappend dir dir.wim --create; then
77 error "wimappend --create to existing file failed"
79 if ! test "`wiminfo dir.wim | grep 'Image Count' | awk '{print $3}'`" = 2; then
80 error "Incorrect WIM image count after wimappend --create"
83 # Capturing and modifying name, description, and bootable flag
85 echo "Testing capture of WIM with default name and description"
86 wimcapture dir dir.wim
87 if ! test "`wiminfo dir.wim | grep Name | awk '{print $2}'`" = "dir"; then
88 error "WIM name not set correctly"
90 if ! test "`wiminfo 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 wimcapture dir dir.wim
96 if ! test "`wiminfo dir.wim | grep '^Boot Index' | awk '{print $3}'`" = "0"; then
97 error "WIM boot flag not set correctly"
100 echo "Testing changing image bootable flag"
101 if ! wiminfo dir.wim 1 --boot; then
102 error "Failed to change bootable image"
104 if ! test "`wiminfo dir.wim | grep '^Boot Index' | awk '{print $3}'`" = "1"; then
105 error "Bootable image not changed correctly"
107 echo "Testing changing image bootable flag"
108 if ! wiminfo dir.wim 0 --boot; then
109 error "Failed to reset bootable image"
111 if ! test "`wiminfo dir.wim | grep '^Boot Index' | 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 wiminfo dir.wim 2 --boot; then
116 error "Succeeded in changing bootable image to invalid number"
118 if ! test "`wiminfo dir.wim | grep '^Boot Index' | 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 ! wimcapture dir dir.wim "myname" "mydesc"; then
125 error "Failed to capture WIM with specified name and description"
127 if ! test "`wiminfo dir.wim | grep Name | awk '{print $2}'`" = "myname"; then
128 error "WIM name not set correctly"
130 if ! test "`wiminfo 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 ! wiminfo --lookup-table dir.wim > /dev/null; then
135 error "Failed to print WIM lookup table"
137 echo "Testing printing WIM header"
138 if ! wiminfo --header dir.wim > /dev/null; then
139 error "Failed to print WIM header"
141 echo "Testing printing WIM XML info"
142 if ! wiminfo --xml dir.wim > /dev/null; then
143 error "Failed to print WIM XML data"
145 echo "Testing extracting WIM XML info"
146 if ! wiminfo --extract-xml=dir.xml dir.wim; then
147 error "Failed to extract WIM XML data"
149 echo "Testing printing WIM metadata"
150 if ! wimdir --detailed 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 ! wimcapture dir dir.wim --boot; then
157 error "Failed to capture bootable WIM"
159 if ! test "`wiminfo dir.wim | grep '^Boot Index' | 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 ! wimcapture dir dir.wim --check; then
168 error "Failed to capture WIM with integrity table"
170 if ! wiminfo dir.wim | grep -q Integrity; then
171 error "Integrity table on WIM not made"
173 if ! wimapply --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 wimcapture dir dir.wim
185 if ! wimappend dir2 dir.wim; then
186 error "Appending WIM image failed"
188 if ! test "`wiminfo 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 wimappend dir2 dir.wim "dir"; then
194 error "Adding duplicate image name didn't fail"
196 echo "Testing appending WIM image with new name"
197 if ! wimappend dir2 dir.wim "newname"; then
198 error "Appending WIM image failed"
200 echo "Testing appending WIM image with integrity check"
201 if ! wimappend dir2 dir.wim "newname2" --check; then
202 error "Appending WIM image failed"
204 if ! wiminfo dir.wim | grep -q Integrity; then
205 error "Integrity table not set correctly on image append"
207 echo "Testing appending WIM image with no integrity check"
208 if ! wimappend dir2 dir.wim "newname3" --nocheck; then
209 error "Appending WIM image failed"
211 if wiminfo dir.wim | grep -q Integrity; then
212 error "WIM integrity table not removed"
214 # 5 images at this point
215 if ! test "`wiminfo 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 ! wimdelete dir.wim 1; then
220 error "Failed to delete WIM image"
222 if ! test "`wiminfo 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 ! wimdelete dir.wim 4; then
227 error "Failed to delete WIM image"
229 if ! test "`wiminfo 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 wimdelete dir.wim 4; then
234 error "Expected to fail to delete non-existent WIM image"
236 if ! test "`wiminfo 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 ! wimdelete dir.wim all; then
241 error "Failed to delete all images from WIM"
243 if ! test "`wiminfo 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 ! wimappend 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 ! wiminfo dir.wim | grep -q Integrity; then
251 error "Integrity check not found"
253 if ! test "`wiminfo dir.wim | grep '^Boot Index' | awk '{print $3}'`" = "1"; then
254 error "Bootable image not set correctly"
256 echo "Testing appending non-directory (should generate errors)"
257 if wimappend 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 wimappend 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 wimappend 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 ! wimcapture dir dir.wim; then
279 error "Failed to prepare test WIM"
281 if ! wimappend dir dir.wim "myname"; then
282 error "Failed to append image to test WIM"
284 if ! wimapply 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/write.c`" != 1; then
291 error "Incorrect link count on extracted file"
293 if test "`get_link_count tmp/myname/write.c`" != 1; then
294 error "Incorrect link count on extracted file"
296 if test "`get_inode_number tmp/myname/write.c`" = "`get_inode_number tmp/dir/write.c`"; then
297 error "Incorrect inode number"
301 echo "Testing application of single image containing identical files"
302 if ! wimapply dir.wim 1 tmp; then
303 error "Failed to apply WIM"
305 if test "`get_link_count tmp/subdir/hello`" != 2; then
306 error "Incorrect link count on extracted file"
308 if test "`get_link_count tmp/subdir/hello2`" != 1; then
309 error "Incorrect link count on extracted file"
311 if test "`get_inode_number tmp/subdir/hello`" = "`get_inode_number tmp/subdir/hello2`"; then
312 error "Inode numbers on non-hard-linked files are the same"
314 if test "`get_inode_number tmp/subdir/hello`" != "`get_inode_number tmp/subdir/hellolink`"; then
315 error "Inode numbers on hard-linked files are different"
321 echo "Creating random files to test WIM splitting on"
323 for ((i = 0; i < 100; i++)); do
324 dd if=/dev/urandom of=tmp/file$i bs=4096 count=10 &> /dev/null
326 for flag in "--compress=none" "--compress=maximum" "--compress=fast"; do
327 echo "Using flag $flag"
328 if ! wimcapture tmp tmp.wim $flag; then
329 error "Failed to capture test WIM"
331 echo "Splitting WIM into 1 MiB chunks"
332 if ! wimsplit tmp.wim tmp.swm 1; then
333 error "Failed to split WIM"
335 echo "Verifying the split WIMs (some errors expected)"
336 if test "`wiminfo tmp.swm | grep 'Part Number' | awk '{print $3}'`" != "1/4"; then
337 error "Part number of split WIM not correct"
339 if ! wimdir tmp.swm > /dev/null; then
340 error "Failed to list files in split WIM"
342 if ! test -e tmp2.swm; then
343 error "Could not find split-WIM part 2"
345 if wimdir tmp2.swm > /dev/null; then
346 error "Listed files in part 2 of split WIM (this should have failed)"
349 # Unsupported, should fail
350 if wiminfo tmp.swm --boot 1; then
351 error "Should not have been able to change boot index of split WIM"
353 echo "Joining the split WIMs and applying the result"
354 if ! wimjoin tmp2.wim tmp*.wim; then
355 error "Failed to join split WIMs"
357 if ! wimapply tmp2.wim tmp2; then
358 error "Failed to apply joined split WIM"
360 if ! wimapply tmp.wim tmp3; then
361 error "Failed to apply test WIM"
363 if ! diff -q -r tmp tmp2 || ! diff -q -r tmp tmp3; then
364 error "Recursive diff of applied joined split WIM with original directory failed"
372 echo "Testing export of single image to new WIM"
373 if ! wimcapture dir dir.wim; then
374 error "Failed to capture test WIM"
376 if ! wimappend dir2 dir.wim; then
377 error "Failed to append image to test WIM"
379 if ! wimexport dir.wim dir new.wim; then
380 error "Failed to export single image to new WIM"
382 if test "`wiminfo new.wim | grep 'Image Count' | awk '{print $3}'`" != 1; then
383 error "Exporting single image to new WIM wasn't done correctly"
385 echo "Testing export of single image to existing WIM"
386 if ! wimexport dir.wim dir2 new.wim; then
387 error "Failed to export single image to existing WIM"
389 if test "`wiminfo new.wim | grep 'Image Count' | awk '{print $3}'`" != 2; then
390 error "Exporting single image to existing WIM wasn't done correctly"
392 echo "Testing export of single image to existing WIM using wrong compression type"
393 if wimexport dir.wim dir2 new.wim newname --compress=xpress; then
394 error "Successfully exported image using wrong compression type"
397 echo "Testing export of multiple images to new WIM"
398 if ! wimexport dir.wim all new.wim; then
399 error "Failed to export multiple images to new WIM"
401 if test "`wiminfo new.wim | grep 'Image Count' | awk '{print $3}'`" != 2; then
402 error "Exporting multiple images to new WIM wasn't done correctly"
404 if ! wimcapture dir2 new.wim newname; then
405 error "Failed to capture test WIM"
407 echo "Testing export of multiple images to existing WIM"
408 if ! wimexport dir.wim all new.wim; then
409 error "Failed to export multiple images to existing WIM"
411 echo "Testing export of multiple images to existing WIM with --boot"
412 if ! wimcapture dir2 new.wim newname; then
413 error "Failed to capture test WIM"
415 if ! wiminfo dir.wim --boot 1; then
416 error "Failed to set boot index on test WIM"
418 if ! wimexport dir.wim all new.wim --boot; then
419 error "Failed to export multiple images to existing WIM with bootable image"
421 echo "Testing export of multiple images to existing WIM with --boot, but no bootable image (errors expected)"
422 if ! wimcapture dir2 new.wim newname; then
423 error "Failed to capture test WIM"
425 if ! wiminfo dir.wim --boot 0; then
426 error "Failed to clear boot index on test WIM"
428 if wimexport dir.wim all new.wim --boot; then
429 error "Successfully exported multiple images with --boot but with no bootable images"
432 # Test exporting an image to another WIM, then applying it.
433 # We try with 5 different combinations of compression types to make sure we go
434 # through all paths in the resource-handling code.
435 for i in 1 2 3 4 5; do
438 cflag1="--compress=none";
439 cflag2="--compress=none";
442 cflag1="--compress=xpress";
443 cflag2="--compress=xpress";
446 cflag1="--compress=xpress"
447 cflag2="--compress=lzx"
450 cflag1="--compress=none"
451 cflag2="--compress=xpress"
454 cflag1="--compress=xpress"
455 cflag2="--compress=none"
458 echo "Testing exporting then applying an image (\"$cflag1\" => \"$cflag2\")"
459 rm -rf dir.wim new.wim tmp tmp2
460 wimcapture dir dir.wim $cflag1
461 wimcapture dir2 dir2.wim $cflag2
462 wimexport dir.wim dir dir2.wim
463 wimapply dir.wim dir tmp
464 if ! wimapply dir2.wim dir tmp2; then
465 error "Failed to apply image that was exported to a WIM"
467 if ! diff -r tmp tmp2; then
468 error "Image that was exported to a WIM was not applied correctly"
472 echo "**********************************************************"
473 echo " Basic wimlib-imagex tests passed "
474 echo "**********************************************************"
476 # Leave test subdirectory and cleanup