3 # This script does some sanity testing of the 'imagex' program. It by no means
4 # tests every aspect of wimlib comprehensively.
6 # Assume an in-tree build.
34 if [ -d tmp ] && mountpoint tmp > /dev/null; then
35 fusermount -u tmp > /dev/null;
37 rm -rf tmp* *.wim *.swm dir3
41 # Capturing and applying WIM with None, LZX, and XPRESS compression
43 echo "Testing capture and application of uncompressed WIM"
44 imagex capture dir dir.wim
45 imagex apply dir.wim tmp
46 test "`imagex info dir.wim | grep Compression | awk '{print $2}'`" = "None";
50 echo "Testing capture and application of LZX-compressed WIM"
51 imagex capture dir dir.wim --compress=maximum
52 imagex apply dir.wim tmp
53 test "`imagex info dir.wim | grep Compression | awk '{print $2}'`" = "LZX";
57 echo "Testing capture and application of XPRESS-compressed WIM"
58 imagex capture dir dir.wim --compress=fast
59 imagex apply dir.wim tmp
60 test "`imagex info dir.wim | grep Compression | awk '{print $2}'`" = "XPRESS";
64 # Capturing and modifying name, description, and bootable flag
66 echo "Testing capture of WIM with default name and description"
67 imagex capture dir dir.wim
68 test "`imagex info dir.wim | grep Name | awk '{print $2}'`" = "dir";
69 test "`imagex info dir.wim | grep Description | awk '{print $2}'`" = "";
72 echo "Testing capture of WIM with default boot flag"
73 imagex capture dir dir.wim
74 test "`imagex info dir.wim | grep Boot | awk '{print $3}'`" = "0";
75 echo "Testing changing image bootable flag"
76 imagex info dir.wim 1 --boot
77 test "`imagex info dir.wim | grep Boot | awk '{print $3}'`" = "1";
78 echo "Testing changing image bootable flag"
79 imagex info dir.wim 0 --boot
80 test "`imagex info dir.wim | grep Boot | awk '{print $3}'`" = "0";
81 echo "Testing changing image bootable flag to invalid image (this should generate errors)"
82 ! imagex info dir.wim 2 --boot
83 test "`imagex info dir.wim | grep Boot | awk '{print $3}'`" = "0";
86 echo "Testing capture of WIM with name and description"
87 imagex capture dir dir.wim "myname" "mydesc"
88 test "`imagex info dir.wim | grep Name | awk '{print $2}'`" = "myname";
89 test "`imagex info dir.wim | grep Description | awk '{print $2}'`" = "mydesc";
90 echo "Testing printing WIM lookup table"
91 imagex info --lookup-table dir.wim
92 echo "Testing printing WIM header"
93 imagex info --header dir.wim
94 echo "Testing printing WIM XML info"
95 imagex info --xml dir.wim
96 echo "Testing extracting WIM XML info"
97 imagex info --extract-xml=dir.xml dir.wim
98 echo "Testing printing WIM metadata"
99 imagex info --metadata dir.wim
100 rm -rf dir.wim tmp dir.xml
102 echo "Testing capture of bootable WIM"
103 imagex capture dir dir.wim --boot
104 test "`imagex info dir.wim | grep Boot | awk '{print $3}'`" = "1";
109 echo "Testing capture of WIM with integrity table"
110 imagex capture dir dir.wim --check
111 test "`imagex info dir.wim | grep Integrity | awk '{print $3}'`" = "yes";
112 imagex apply --check dir.wim tmp
116 # Appending and deleting images
118 echo "Testing appending WIM image"
119 imagex capture dir dir.wim
120 imagex append dir2 dir.wim
121 test "`imagex info dir.wim | grep 'Image Count' | awk '{print $3}'`" = 2;
122 echo "Testing appending WIM image with existing name (this should generate errors)"
123 ! imagex append dir2 dir.wim
124 echo "Testing appending WIM image with new name"
125 imagex append dir2 dir.wim "newname"
126 echo "Testing appending WIM image with integrity check"
127 imagex append dir2 dir.wim "newname2" --check
128 test "`imagex info dir.wim | grep Integrity | awk '{print $3}'`" = "yes";
129 echo "Testing appending WIM image with no integrity check"
130 imagex append dir2 dir.wim "newname3"
131 test "`imagex info dir.wim | grep Integrity | awk '{print $3}'`" = "no";
132 test "`imagex info dir.wim | grep 'Image Count' | awk '{print $3}'`" = 5;
133 echo "Testing deleting first WIM image"
134 imagex delete dir.wim 1
135 test "`imagex info dir.wim | grep 'Image Count' | awk '{print $3}'`" = 4;
136 echo "Testing deleting last WIM image"
137 imagex delete dir.wim 4
138 test "`imagex info dir.wim | grep 'Image Count' | awk '{print $3}'`" = 3;
139 echo "Testing deleting invalid WIM image (this should generate errors)"
140 ! imagex delete dir.wim 4
141 test "`imagex info dir.wim | grep 'Image Count' | awk '{print $3}'`" = 3;
142 echo "Testing deleting all WIM images"
143 imagex delete dir.wim all
144 test "`imagex info dir.wim | grep 'Image Count' | awk '{print $3}'`" = 0;
145 echo "Testing appending directory to empty WIM and making it bootable"
146 imagex append dir dir.wim "myname" "mydesc" --check --boot
147 test "`imagex info dir.wim | grep Integrity | awk '{print $3}'`" = "yes";
148 test "`imagex info dir.wim | grep Boot | awk '{print $3}'`" = "1";
149 echo "Testing appending non-directory (should generate errors)"
150 ! imagex append dir.wim dir.wim
151 echo "Testing appending non-existent file (should generate errors)"
152 ! imagex append SOME_NONEXISTENT_FILE dir.wim
153 echo "Testing appending directory containing unreadable file (should generate errors)"
157 ! imagex append dir3 dir.wim
160 # Applying multiple images, applying with hardlinks/symlinks
162 imagex capture dir dir.wim
163 imagex append dir dir.wim "myname"
164 echo "Testing application of multiple images"
165 imagex apply dir.wim all tmp
166 diff -q -r tmp/dir tmp/myname
167 test `stat -c %h tmp/dir/lz.c` = 1;
168 test `stat -c %h tmp/myname/lz.c` = 1;
169 test `stat -c %i tmp/myname/lz.c` != `stat -c %i tmp/dir/lz.c`;
171 echo "Testing application of multiple images with hardlinks"
172 imagex apply dir.wim all tmp --hardlink
173 diff -q -r tmp/dir tmp/myname
174 test `stat -c %h tmp/dir/lz.c` = 2;
175 test `stat -c %h tmp/myname/lz.c` = 2;
176 test `stat -c %i tmp/myname/lz.c` = `stat -c %i tmp/dir/lz.c`;
178 echo "Testing application of single image containing identical files"
179 imagex apply dir.wim 1 tmp
180 test `stat -c %h tmp/subdir/identical_file1` = 1;
181 test `stat -c %h tmp/subdir/identical_file2` = 1;
182 test `stat -c %i tmp/subdir/identical_file1` != `stat -c %i tmp/subdir/identical_file2`;
183 ! readlink tmp/subdir/identical_file1 && ! readlink tmp/subdir/identical_file2
186 echo "Testing application of single image containing identical files with hardlinks"
187 imagex apply dir.wim 1 tmp --hardlink
188 test `stat -c %h tmp/subdir/identical_file1` = 2;
189 test `stat -c %h tmp/subdir/identical_file2` = 2;
190 test `stat -c %i tmp/subdir/identical_file1` = `stat -c %i tmp/subdir/identical_file2`;
191 ! readlink tmp/subdir/identical_file1 && ! readlink tmp/subdir/identical_file2
194 echo "Testing application of single image containing identical files with symlinks"
195 imagex apply dir.wim 1 tmp --symlink
196 test `stat -c %h tmp/subdir/identical_file1` = 1;
197 test `stat -c %h tmp/subdir/identical_file2` = 1;
198 test `stat -c %i tmp/subdir/identical_file1` != `stat -c %i tmp/subdir/identical_file2`;
199 readlink tmp/subdir/identical_file1 > /dev/null || \
200 readlink tmp/subdir/identical_file2 > /dev/null
205 for flag in "--compress=none" "--compress=maximum" "--compress=fast"; do
206 echo "Using flag $flag"
207 echo "Testing mounting WIM read-only"
208 imagex capture dir dir.wim $flag
210 imagex mount dir.wim dir tmp
211 echo "Testing extracting file from mounted read-only WIM"
213 diff -q dir/lz.c lz.c
214 diff -q tmp/lz.c dir/lz.c
216 echo "Testing modifying mounted read-only WIM (should fail)"
219 ! echo 3 > tmp/newfile
220 echo "Testing diff of mounted read-only WIM with original directory"
222 echo "Testing unmount of read-only filesystem"
224 echo "Testing unmount of read-only filesystem with --commit given"
225 imagex mount dir.wim dir tmp
226 imagex unmount tmp --commit
231 for flag in "--compress=none" "--compress=maximum" "--compress=fast"; do
232 echo "Using flag $flag"
233 echo "Testing mounting WIM read-write"
234 imagex capture dir dir.wim $flag
236 imagex mountrw dir.wim dir tmp
237 echo "Testing unmounting WIM unmodified"
239 echo "Testing unmounting WIM unmodified with --commit and --check"
240 imagex mountrw dir.wim dir tmp
241 imagex unmount tmp --commit --check
242 echo "Testing removing file from mounted WIM"
243 imagex mountrw dir.wim dir tmp
246 echo "Testing making directory in mounted WIM"
249 echo "Testing making new empty file in mounted WIM"
250 touch tmp/newdir/empty_file
251 test -e tmp/newdir/empty_file
252 test `stat -c %s tmp/newdir/empty_file` = 0;
253 echo "Testing making new non-empty file in mounted WIM"
254 dd if=/dev/zero of=tmp/newdir/zeroes1 bs=1 count=4096
255 dd if=/dev/zero of=tmp/newdir/zeroes2 bs=4096 count=1
256 cmp tmp/newdir/zeroes1 tmp/newdir/zeroes2
257 echo "Unmounting WIM with changes committed and --check"
258 imagex unmount tmp --commit --check
259 test "`imagex info dir.wim | grep Integrity | awk '{print $3}'`" = "yes";
261 imagex apply dir.wim tmp
262 cmp tmp/newdir/zeroes1 tmp/newdir/zeroes2
263 test `stat -c %s tmp/newdir/empty_file` = 0;
264 test `stat -c %s tmp/newdir/zeroes1` = 4096;
268 # imagex split, imagex join
270 echo "Creating random files to test WIM splitting on"
272 for i in `seq 1 100`; do
273 dd if=/dev/urandom of=tmp/file$i bs=4096 count=10 &> /dev/null
275 for flag in "--compress=none" "--compress=maximum" "--compress=fast"; do
276 echo "Using flag $flag"
277 imagex capture tmp tmp.wim $flag
278 echo "Splitting WIM into 1 MiB chunks"
279 imagex split tmp.wim tmp.swm 1
280 echo "Verifying the split WIMs (some errors expected)"
281 test "`imagex info tmp.swm | grep 'Part Number' | awk '{print $3}'`" = "1/4"
282 imagex dir tmp.swm > /dev/null
283 test -e tmp2.swm && ! imagex dir tmp2.swm
284 ! imagex info tmp.swm --boot 0 # Unsupported, should fail
285 echo "Joining the split WIMs and applying the result"
286 imagex join tmp2.wim tmp*.wim
287 imagex apply tmp2.wim tmp2
288 imagex apply tmp.wim tmp3
297 echo "Testing export of single image to new WIM"
298 imagex capture dir dir.wim
299 imagex append dir2 dir.wim
300 imagex export dir.wim dir new.wim
301 test "`imagex info new.wim | grep 'Image Count' | awk '{print $3}'`" = 1;
302 echo "Testing export of single image to existing WIM"
303 imagex export dir.wim dir2 new.wim
304 test "`imagex info new.wim | grep 'Image Count' | awk '{print $3}'`" = 2;
305 echo "Testing export of single image to existing WIM using wrong compression type"
306 ! imagex export dir.wim dir2 new.wim newname --compress=maximum
308 echo "Testing export of multiple images to new WIM"
309 imagex export dir.wim all new.wim
310 test "`imagex info new.wim | grep 'Image Count' | awk '{print $3}'`" = 2;
311 imagex capture dir2 new.wim newname
312 echo "Testing export of multiple images to existing WIM"
313 imagex export dir.wim all new.wim
314 echo "Testing export of multiple images to existing WIM with --boot"
315 imagex capture dir2 new.wim newname
316 imagex info dir.wim --boot 1
317 imagex export dir.wim all new.wim --boot
318 echo "Testing export of multiple images to existing WIM with --boot, but no bootable image (errors expected)"
319 imagex capture dir2 new.wim newname
320 imagex info dir.wim --boot 0
321 ! imagex export dir.wim all new.wim --boot