]> wimlib.net Git - wimlib/blob - tests/test-imagex-mount
dist files and test fixes
[wimlib] / tests / test-imagex-mount
1 #!/bin/sh
2
3 # Test WIM mounting
4
5 set -e
6 srcdir=${srcdir:-.}
7 srcdir=`realpath $srcdir`
8 cd tests
9
10 imagex() {
11         echo "imagex $@"
12         ../imagex $@  > /dev/null
13 }
14
15 imagex_info() {
16         echo "imagex info $@"
17         ../imagex info "$@"
18 }
19
20 imagex_mountrw() {
21         echo "imagex mountrw $@"
22         ../imagex mountrw --debug "$@" &> mount.log &
23         while ! mountpoint $2 >& /dev/null; do
24                 sleep 0.01;
25         done
26         return 0
27 }
28
29 cleanup() {
30         if mountpoint tmp &> /dev/null; then
31                 fusermount -u tmp > /dev/null;
32         fi
33         if mountpoint tmp.mnt &> /dev/null; then
34                 fusermount -u tmp.mnt > /dev/null;
35         fi
36         rm -rf dir* tmp* *.wim *.swm empty.wim tmp.orig tmp.mnt \
37                         tmp.apply mount.log test.tar wimlib-staging*
38 }
39 init() {
40         mkdir dir
41         cp $srcdir/src/*.c $srcdir/src/*.h dir
42         mkdir dir/subdir
43         echo 'hello' > dir/subdir/hello
44         echo 'hello' > dir/subdir/hello2
45         ln dir/subdir/hello dir/subdir/hellolink
46         echo -n > dir/subdir/empty_file
47         ln -s hello dir/subdir/rel_symlink
48
49         mkdir dir2
50         echo 'testing' > dir2/file
51         dd if=/dev/zero of=dir2/zeroes bs=4096 count=5
52         mkdir tmp.empty tmp.mnt tmp.apply tmp.orig
53         imagex capture tmp.empty empty.wim
54 }
55
56 error() {
57         echo "**********************************************"
58         echo "                  Test failure                "
59         echo $*
60         echo "**********************************************"
61         exit 1
62 }
63
64 cleanup
65 init
66
67 # imagex mount
68
69 for flag in "--compress=none" "--compress=maximum" "--compress=fast"; do
70         echo "Using flag $flag"
71         echo "Testing mounting WIM read-only"
72         if ! imagex capture dir dir.wim $flag; then
73                 error "Failed to capture WIM"
74         fi
75         mkdir tmp
76         if ! imagex mount dir.wim dir tmp; then
77                 error "Failde to mount test WIM read-only"
78         fi
79         echo "Testing extracting file from mounted read-only WIM"
80         if ! cp tmp/lz.c lz.c; then
81                 error "Failed to extract file from read-only mounted WIM"
82         fi
83         if ! diff -q dir/lz.c lz.c; then
84                 error "Extracted file does not match copy in mounted WIM"
85         fi
86         if ! diff -q tmp/lz.c dir/lz.c; then
87                 error "Extractef file does not match original"
88         fi
89         rm -f lz.c
90         echo "Testing modifying mounted read-only WIM (should fail)"
91         if rm tmp/lz.c; then
92                 error "Removing file from read-only mounted WIM didn't fail"
93         fi
94         if touch tmp/newfile; then
95                 error "Creating file on read-only mounted WIM didn't fail"
96         fi
97         if echo 3 > tmp/lz.c; then
98                 error "Writing to file on read-only mounted WIM didn't fail"
99         fi
100         echo "Testing diff of mounted read-only WIM with original directory"
101         if ! diff -q -r tmp dir; then
102                 error "Recursive diff of read-only mounted WIM with original directory failed"
103         fi
104         echo "Testing unmount of read-only filesystem"
105         if ! imagex unmount tmp; then
106                 error "Unmounting read-only WIM failed"
107         fi
108         echo "Testing unmount of read-only filesystem with --commit given"
109         if ! imagex mount dir.wim dir tmp; then
110                 error "Failed to re-mount WIM read-only"
111         fi
112         if ! imagex unmount tmp --commit; then
113                 error "Failed to unmount read-only WIM with --commit flag (should be ignored)"
114         fi
115         rm -rf tmp dir.wim
116 done
117
118 # imagex mountrw
119 echo "Testing mounting WIM read-write"
120 if ! imagex capture dir dir.wim; then
121         error "Failed to capture WIM"
122 fi
123 mkdir tmp
124 if ! imagex mountrw dir.wim dir tmp; then
125         error "Failed to mount test WIM read-write"
126 fi
127 echo "Testing unmounting WIM unmodified"
128 if ! imagex unmount tmp; then
129         error "Failed to unmount test WIM unmodified"
130 fi
131 echo "Testing unmounting WIM unmodified with --commit and --check"
132 if ! imagex mountrw dir.wim dir tmp; then
133         error "Failed to re-mount test WIM read-write"
134 fi
135 if ! imagex unmount tmp --commit --check; then
136         error "Failed to unmount read-write mounted WIM with changes commited (no changes made)"
137 fi
138 echo "Testing removing file from mounted WIM"
139 if ! imagex mountrw dir.wim dir tmp; then
140         error "Failed to re-mount test WIM read-write"
141 fi
142 if ! rm tmp/lz.c; then
143         error "Failed to remove file from read-write mounted WIM"
144 fi
145 if test -f tmp/lz.c; then
146         error "Removing file from read-write mounted WIM failed"
147 fi
148 echo "Testing making directory in mounted WIM"
149 if ! mkdir tmp/newdir; then
150         error "Failed to make directory in read-write mounted WIM"
151 fi
152 if ! test -d tmp/newdir; then
153         error "Making directory in read-write mounted WIM failed"
154 fi
155 echo "Testing making new empty file in mounted WIM"
156 if ! touch tmp/newdir/empty_file; then
157         error "Could not create new empty file in read-write mounted WIM"
158 fi
159 if ! test -f tmp/newdir/empty_file; then
160         error "New empty file not created correctly in read-write mounted WIM"
161 fi
162 if ! test "`stat -c %s tmp/newdir/empty_file`" = 0; then
163         error "New empty file in read-write mounted WIM is not empty"
164 fi
165 echo "Testing making new non-empty file in mounted WIM"
166 if ! dd if=/dev/zero of=tmp/newdir/zeroes1 bs=1 count=4096; then
167         error "Failed to make new non-empty file in mounted WIM"
168 fi
169 if ! dd if=/dev/zero of=tmp/newdir/zeroes2 bs=4096 count=1; then
170         error "Failed to make new non-empty file in mounted WIM"
171 fi
172 if ! diff -q tmp/newdir/zeroes1 tmp/newdir/zeroes2; then
173         error "New files in mounted WIM not made correctly"
174 fi
175 echo "Unmounting WIM with changes committed and --check"
176 if ! imagex unmount tmp --commit --check; then
177         error "Failed to unmount read-write mounted WIM"
178 fi
179 if test "`imagex_info dir.wim | grep Integrity | awk '{print $3}'`" != "yes"; then
180         error "Integrity information was not included"
181 fi
182 rm -rf tmp
183 if ! imagex apply dir.wim tmp; then
184         error "Failed to apply WIM we had previously mounted read-write"
185 fi
186 if ! diff -q tmp/newdir/zeroes1 tmp/newdir/zeroes2; then
187         error "The new non-empty files we made in the read-write mounted WIM were not extracted correctly"
188 fi
189 if test `stat -c %s tmp/newdir/empty_file` != 0; then
190         error "The new empty file we made in the read-write mounted WIM was not extracted correctly"
191 fi
192 if test `stat -c %s tmp/newdir/zeroes1` != 4096; then
193         error "The new non-empty files we made in the read-write mounted WIM were not extracted correctly"
194 fi
195
196 # Now do some tests using tar.
197 do_tree_cmp() {
198         if ! ./tree-cmp $1 $2; then
199                 if [ -x /usr/bin/tree ]; then
200                         echo "Dumping tree of applied image"
201                         tree $2 --inodes -F -s --noreport
202                         error 'Information was lost or corrupted while capturing
203                                 and then applying a directory tree'
204                 fi
205         fi
206 }
207
208 msg() {
209         echo "--------------------------------------------------------------------"
210         echo "Testing making $1 on read-write mounted WIM"
211         echo "--------------------------------------------------------------------"
212 }
213
214 do_test() {
215
216         # Create tree, tar it up, and untar it on an empty WIM image mounted
217         # read-write
218
219         cp empty.wim test.wim
220
221         cd tmp.orig
222         eval "$1"
223         if [ -x /usr/bin/tree ]; then
224                 tree . --inodes -F -s --noreport
225         fi
226         tar cf ../test.tar .
227         cd ..
228
229         if ! imagex_mountrw test.wim tmp.mnt; then
230                 error "Failed to mount WIM read-write"
231         fi
232
233         cd tmp.mnt
234         if ! tar xf ../test.tar; then
235                 error "Failed to untar archive on read-write mounted WIM"
236         fi
237         cd ..
238
239         # Diff the original tree with the mounted WIM
240         do_tree_cmp tmp.orig tmp.mnt
241
242         # Clear the mounted WIM and do it again!  (We need to test deleting
243         # stuff as well as creating stuff.)
244         if ! rm -rf tmp.mnt/*; then
245                 error "Failed to clear mounted WIM"
246         fi
247
248         cd tmp.mnt
249         if ! tar xf ../test.tar; then
250                 error "Failed to untar archive on read-write mounted WIM"
251         fi
252         cd ..
253
254         # Diff the original tree with the mounted WIM
255         do_tree_cmp tmp.orig tmp.mnt
256
257         # Unmount the WIM, apply it, and diff the original tree with the applied
258         # tree
259         if ! imagex unmount tmp.mnt --commit; then
260                 error "Failed to unmount WIM mounted read-write"
261         fi
262         if ! imagex apply test.wim tmp.apply; then
263                 error "Failed to apply WIM we previously had mounted read-write"
264         fi
265         do_tree_cmp tmp.orig tmp.apply
266         rm -rf tmp.orig/* tmp.apply/*
267 }
268
269 . $srcdir/tests/common_tests.sh
270
271 cleanup
272
273 echo "**********************************************************"
274 echo "                 WIM mount tests passed                   "
275 echo "**********************************************************"