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 # Capturing and modifying name, description, and bootable flag
70 echo "Testing capture of WIM with default name and description"
71 wimcapture dir dir.wim
72 if ! test "`wiminfo dir.wim | grep Name | awk '{print $2}'`" = "dir"; then
73 error "WIM name not set correctly"
75 if ! test "`wiminfo 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 wimcapture dir dir.wim
81 if ! test "`wiminfo dir.wim | grep '^Boot Index' | awk '{print $3}'`" = "0"; then
82 error "WIM boot flag not set correctly"
85 echo "Testing changing image bootable flag"
86 if ! wiminfo dir.wim 1 --boot; then
87 error "Failed to change bootable image"
89 if ! test "`wiminfo dir.wim | grep '^Boot Index' | awk '{print $3}'`" = "1"; then
90 error "Bootable image not changed correctly"
92 echo "Testing changing image bootable flag"
93 if ! wiminfo dir.wim 0 --boot; then
94 error "Failed to reset bootable image"
96 if ! test "`wiminfo dir.wim | grep '^Boot Index' | 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 wiminfo dir.wim 2 --boot; then
101 error "Succeeded in changing bootable image to invalid number"
103 if ! test "`wiminfo dir.wim | grep '^Boot Index' | 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 ! wimcapture dir dir.wim "myname" "mydesc"; then
110 error "Failed to capture WIM with specified name and description"
112 if ! test "`wiminfo dir.wim | grep Name | awk '{print $2}'`" = "myname"; then
113 error "WIM name not set correctly"
115 if ! test "`wiminfo 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 ! wiminfo --lookup-table dir.wim > /dev/null; then
120 error "Failed to print WIM lookup table"
122 echo "Testing printing WIM header"
123 if ! wiminfo --header dir.wim > /dev/null; then
124 error "Failed to print WIM header"
126 echo "Testing printing WIM XML info"
127 if ! wiminfo --xml dir.wim > /dev/null; then
128 error "Failed to print WIM XML data"
130 echo "Testing extracting WIM XML info"
131 if ! wiminfo --extract-xml=dir.xml dir.wim; then
132 error "Failed to extract WIM XML data"
134 echo "Testing printing WIM metadata"
135 if ! wimdir --detailed 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 ! wimcapture dir dir.wim --boot; then
142 error "Failed to capture bootable WIM"
144 if ! test "`wiminfo dir.wim | grep '^Boot Index' | 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 ! wimcapture dir dir.wim --check; then
153 error "Failed to capture WIM with integrity table"
155 if ! wiminfo dir.wim | grep -q Integrity; then
156 error "Integrity table on WIM not made"
158 if ! wimapply --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 wimcapture dir dir.wim
170 if ! wimappend dir2 dir.wim; then
171 error "Appending WIM image failed"
173 if ! test "`wiminfo 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 wimappend dir2 dir.wim "dir"; then
179 error "Adding duplicate image name didn't fail"
181 echo "Testing appending WIM image with new name"
182 if ! wimappend dir2 dir.wim "newname"; then
183 error "Appending WIM image failed"
185 echo "Testing appending WIM image with integrity check"
186 if ! wimappend dir2 dir.wim "newname2" --check; then
187 error "Appending WIM image failed"
189 if ! wiminfo dir.wim | grep -q Integrity; then
190 error "Integrity table not set correctly on image append"
192 echo "Testing appending WIM image with no integrity check"
193 if ! wimappend dir2 dir.wim "newname3" --nocheck; then
194 error "Appending WIM image failed"
196 if wiminfo dir.wim | grep -q Integrity; then
197 error "WIM integrity table not removed"
199 # 5 images at this point
200 if ! test "`wiminfo 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 ! wimdelete dir.wim 1; then
205 error "Failed to delete WIM image"
207 if ! test "`wiminfo 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 ! wimdelete dir.wim 4; then
212 error "Failed to delete WIM image"
214 if ! test "`wiminfo 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 wimdelete dir.wim 4; then
219 error "Expected to fail to delete non-existent WIM image"
221 if ! test "`wiminfo 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 ! wimdelete dir.wim all; then
226 error "Failed to delete all images from WIM"
228 if ! test "`wiminfo 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 ! wimappend 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 ! wiminfo dir.wim | grep -q Integrity; then
236 error "Integrity check not found"
238 if ! test "`wiminfo dir.wim | grep '^Boot Index' | awk '{print $3}'`" = "1"; then
239 error "Bootable image not set correctly"
241 echo "Testing appending non-directory (should generate errors)"
242 if wimappend 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 wimappend 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 wimappend 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 ! wimcapture dir dir.wim; then
264 error "Failed to prepare test WIM"
266 if ! wimappend dir dir.wim "myname"; then
267 error "Failed to append image to test WIM"
269 if ! wimapply 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/write.c`" != 1; then
276 error "Incorrect link count on extracted file"
278 if test "`get_link_count tmp/myname/write.c`" != 1; then
279 error "Incorrect link count on extracted file"
281 if test "`get_inode_number tmp/myname/write.c`" = "`get_inode_number tmp/dir/write.c`"; then
282 error "Incorrect inode number"
286 echo "Testing application of single image containing identical files"
287 if ! wimapply dir.wim 1 tmp; then
288 error "Failed to apply WIM"
290 if test "`get_link_count tmp/subdir/hello`" != 2; then
291 error "Incorrect link count on extracted file"
293 if test "`get_link_count tmp/subdir/hello2`" != 1; then
294 error "Incorrect link count on extracted file"
296 if test "`get_inode_number tmp/subdir/hello`" = "`get_inode_number tmp/subdir/hello2`"; then
297 error "Inode numbers on non-hard-linked files are the same"
299 if test "`get_inode_number tmp/subdir/hello`" != "`get_inode_number tmp/subdir/hellolink`"; then
300 error "Inode numbers on hard-linked files are different"
306 echo "Creating random files to test WIM splitting on"
308 for ((i = 0; i < 100; i++)); do
309 dd if=/dev/urandom of=tmp/file$i bs=4096 count=10 &> /dev/null
311 for flag in "--compress=none" "--compress=maximum" "--compress=fast"; do
312 echo "Using flag $flag"
313 if ! wimcapture tmp tmp.wim $flag; then
314 error "Failed to capture test WIM"
316 echo "Splitting WIM into 1 MiB chunks"
317 if ! wimsplit tmp.wim tmp.swm 1; then
318 error "Failed to split WIM"
320 echo "Verifying the split WIMs (some errors expected)"
321 if test "`wiminfo tmp.swm | grep 'Part Number' | awk '{print $3}'`" != "1/4"; then
322 error "Part number of split WIM not correct"
324 if ! wimdir tmp.swm > /dev/null; then
325 error "Failed to list files in split WIM"
327 if ! test -e tmp2.swm; then
328 error "Could not find split-WIM part 2"
330 if wimdir tmp2.swm > /dev/null; then
331 error "Listed files in part 2 of split WIM (this should have failed)"
334 # Unsupported, should fail
335 if wiminfo tmp.swm --boot 1; then
336 error "Should not have been able to change boot index of split WIM"
338 echo "Joining the split WIMs and applying the result"
339 if ! wimjoin tmp2.wim tmp*.wim; then
340 error "Failed to join split WIMs"
342 if ! wimapply tmp2.wim tmp2; then
343 error "Failed to apply joined split WIM"
345 if ! wimapply tmp.wim tmp3; then
346 error "Failed to apply test WIM"
348 if ! diff -q -r tmp tmp2 || ! diff -q -r tmp tmp3; then
349 error "Recursive diff of applied joined split WIM with original directory failed"
357 echo "Testing export of single image to new WIM"
358 if ! wimcapture dir dir.wim; then
359 error "Failed to capture test WIM"
361 if ! wimappend dir2 dir.wim; then
362 error "Failed to append image to test WIM"
364 if ! wimexport dir.wim dir new.wim; then
365 error "Failed to export single image to new WIM"
367 if test "`wiminfo new.wim | grep 'Image Count' | awk '{print $3}'`" != 1; then
368 error "Exporting single image to new WIM wasn't done correctly"
370 echo "Testing export of single image to existing WIM"
371 if ! wimexport dir.wim dir2 new.wim; then
372 error "Failed to export single image to existing WIM"
374 if test "`wiminfo new.wim | grep 'Image Count' | awk '{print $3}'`" != 2; then
375 error "Exporting single image to existing WIM wasn't done correctly"
377 echo "Testing export of single image to existing WIM using wrong compression type"
378 if wimexport dir.wim dir2 new.wim newname --compress=xpress; then
379 error "Successfully exported image using wrong compression type"
382 echo "Testing export of multiple images to new WIM"
383 if ! wimexport dir.wim all new.wim; then
384 error "Failed to export multiple images to new WIM"
386 if test "`wiminfo new.wim | grep 'Image Count' | awk '{print $3}'`" != 2; then
387 error "Exporting multiple images to new WIM wasn't done correctly"
389 if ! wimcapture dir2 new.wim newname; then
390 error "Failed to capture test WIM"
392 echo "Testing export of multiple images to existing WIM"
393 if ! wimexport dir.wim all new.wim; then
394 error "Failed to export multiple images to existing WIM"
396 echo "Testing export of multiple images to existing WIM with --boot"
397 if ! wimcapture dir2 new.wim newname; then
398 error "Failed to capture test WIM"
400 if ! wiminfo dir.wim --boot 1; then
401 error "Failed to set boot index on test WIM"
403 if ! wimexport dir.wim all new.wim --boot; then
404 error "Failed to export multiple images to existing WIM with bootable image"
406 echo "Testing export of multiple images to existing WIM with --boot, but no bootable image (errors expected)"
407 if ! wimcapture dir2 new.wim newname; then
408 error "Failed to capture test WIM"
410 if ! wiminfo dir.wim --boot 0; then
411 error "Failed to clear boot index on test WIM"
413 if wimexport dir.wim all new.wim --boot; then
414 error "Successfully exported multiple images with --boot but with no bootable images"
417 # Test exporting an image to another WIM, then applying it.
418 # We try with 5 different combinations of compression types to make sure we go
419 # through all paths in the resource-handling code.
420 for i in 1 2 3 4 5; do
423 cflag1="--compress=none";
424 cflag2="--compress=none";
427 cflag1="--compress=xpress";
428 cflag2="--compress=xpress";
431 cflag1="--compress=xpress"
432 cflag2="--compress=lzx"
435 cflag1="--compress=none"
436 cflag2="--compress=xpress"
439 cflag1="--compress=xpress"
440 cflag2="--compress=none"
443 echo "Testing exporting then applying an image (\"$cflag1\" => \"$cflag2\")"
444 rm -rf dir.wim new.wim tmp tmp2
445 wimcapture dir dir.wim $cflag1
446 wimcapture dir2 dir2.wim $cflag2
447 wimexport dir.wim dir dir2.wim
448 wimapply dir.wim dir tmp
449 if ! wimapply dir2.wim dir tmp2; then
450 error "Failed to apply image that was exported to a WIM"
452 if ! diff -r tmp tmp2; then
453 error "Image that was exported to a WIM was not applied correctly"
457 echo "**********************************************************"
458 echo " Basic wimlib-imagex tests passed "
459 echo "**********************************************************"
461 # Leave test subdirectory and cleanup