7 srcdir="${srcdir:-.}/.."
8 srcdir="$(cd $srcdir; pwd)"
9 . "$srcdir/tests/tests-common.sh"
11 TEST_SUBDIR=tmpdir_test-imagex-mount
20 # Give the --lazy flag to work around a problem testing on Ubuntu and
21 # other OS's running Gnome, as they have a daemon
22 # "gvfs-gdu-volume-monitor" that apparently likes to randomly read
23 # filesystems that get mounted, thereby stopping them from being
25 imagex unmount "$@" --lazy
29 fusermount -u $TEST_SUBDIR/tmp &> /dev/null || true
30 fusermount -u $TEST_SUBDIR/tmp.mnt &> /dev/null || true
36 cp $srcdir/src/*.c dir
38 echo 'hello' > dir/subdir/hello
39 echo 'hello' > dir/subdir/hello2
40 ln dir/subdir/hello dir/subdir/hellolink
41 echo -n > dir/subdir/empty_file
42 ln -s hello dir/subdir/rel_symlink
45 echo 'testing' > dir2/file
46 dd if=/dev/zero of=dir2/zeroes bs=4096 count=5
47 mkdir tmp.empty tmp.mnt tmp.apply tmp.orig
48 imagex capture tmp.empty empty.wim --norpfix
51 if [ ! -r /dev/fuse ] || [ ! -w /dev/fuse ]; then
52 echo "WARNING: /dev/fuse is not readable and writable."
53 echo "Skipping WIM mounting checks"
64 for flag in "--compress=none" "--compress=maximum" "--compress=fast"; do
65 echo "Using flag $flag"
66 echo "Testing mounting WIM read-only"
67 if ! imagex capture dir dir.wim $flag; then
68 error "Failed to capture WIM"
71 if ! imagex mount dir.wim dir tmp; then
72 error "Failed to mount test WIM read-only. " \
73 "Please read any error messages above before reporting this test failure. "\
74 "Perhaps you don't have FUSE installed, or the FUSE kernel module isn't" \
75 "loaded, or you aren't a member of the FUSE group?"
77 echo "Testing extracting file from mounted read-only WIM"
78 if ! cp tmp/write.c write.c; then
79 error "Failed to extract file from read-only mounted WIM"
81 if ! diff -q dir/write.c write.c; then
82 error "Extracted file does not match copy in mounted WIM"
84 if ! diff -q tmp/write.c dir/write.c; then
85 error "Extractef file does not match original"
88 echo "Testing modifying mounted read-only WIM (should fail)"
89 if rm tmp/write.c; then
90 error "Removing file from read-only mounted WIM didn't fail"
92 if touch tmp/newfile; then
93 error "Creating file on read-only mounted WIM didn't fail"
95 if echo 3 > tmp/write.c; then
96 error "Writing to file on read-only mounted WIM didn't fail"
98 echo "Testing diff of mounted read-only WIM with original directory"
99 if ! diff -q -r tmp dir; then
100 error "Recursive diff of read-only mounted WIM with original directory failed"
102 echo "Testing unmount of read-only filesystem"
103 if ! imagex_unmount tmp; then
104 error "Unmounting read-only WIM failed"
106 echo "Testing unmount of read-only filesystem with --commit given"
107 if ! imagex mount dir.wim dir tmp; then
108 error "Failed to re-mount WIM read-only"
110 if ! imagex_unmount tmp --commit; then
111 error "Failed to unmount read-only WIM with --commit flag (should be ignored)"
117 echo "Testing mounting WIM read-write"
118 if ! imagex capture dir dir.wim; then
119 error "Failed to capture WIM"
122 if ! imagex mountrw dir.wim dir tmp; then
123 error "Failed to mount test WIM read-write"
125 echo "Testing unmounting WIM unmodified"
126 if ! imagex_unmount tmp; then
127 error "Failed to unmount test WIM unmodified"
129 echo "Testing unmounting WIM unmodified with --commit and --check"
130 if ! imagex mountrw dir.wim dir tmp; then
131 error "Failed to re-mount test WIM read-write"
133 if ! imagex_unmount tmp --commit --check; then
134 error "Failed to unmount read-write mounted WIM with changes commited (no changes made)"
136 echo "Testing removing file from mounted WIM"
137 if ! imagex mountrw dir.wim dir tmp; then
138 error "Failed to re-mount test WIM read-write"
140 if ! rm tmp/write.c; then
141 error "Failed to remove file from read-write mounted WIM"
143 if test -f tmp/write.c; then
144 error "Removing file from read-write mounted WIM failed"
146 echo "Testing making directory in mounted WIM"
147 if ! mkdir tmp/newdir; then
148 error "Failed to make directory in read-write mounted WIM"
150 if ! test -d tmp/newdir; then
151 error "Making directory in read-write mounted WIM failed"
153 echo "Testing making new empty file in mounted WIM"
154 if ! touch tmp/newdir/empty_file; then
155 error "Could not create new empty file in read-write mounted WIM"
157 if ! test -f tmp/newdir/empty_file; then
158 error "New empty file not created correctly in read-write mounted WIM"
160 if ! test "`get_file_size tmp/newdir/empty_file`" = 0; then
161 error "New empty file in read-write mounted WIM is not empty"
163 echo "Testing making new non-empty file in mounted WIM"
164 if ! dd if=/dev/zero of=tmp/newdir/zeroes1 bs=1 count=4096; then
165 error "Failed to make new non-empty file in mounted WIM"
167 if ! dd if=/dev/zero of=tmp/newdir/zeroes2 bs=4096 count=1; then
168 error "Failed to make new non-empty file in mounted WIM"
170 if ! diff -q tmp/newdir/zeroes1 tmp/newdir/zeroes2; then
171 error "New files in mounted WIM not made correctly"
173 echo "Unmounting WIM with changes committed and --check"
174 if ! imagex_unmount tmp --commit --check; then
175 error "Failed to unmount read-write mounted WIM"
177 if test "`imagex info dir.wim | grep Integrity | awk '{print $3}'`" != "yes"; then
178 error "Integrity information was not included"
181 if ! imagex apply dir.wim tmp; then
182 error "Failed to apply WIM we had previously mounted read-write"
184 if ! diff -q tmp/newdir/zeroes1 tmp/newdir/zeroes2; then
185 error "The new non-empty files we made in the read-write mounted WIM were not extracted correctly"
187 if test `get_file_size tmp/newdir/empty_file` != 0; then
188 error "The new empty file we made in the read-write mounted WIM was not extracted correctly"
190 if test `get_file_size tmp/newdir/zeroes1` != 4096; then
191 error "The new non-empty files we made in the read-write mounted WIM were not extracted correctly"
194 # Now do some tests using tar.
196 if ! ../tree-cmp $1 $2; then
197 if [ -x /usr/bin/tree ]; then
198 echo "Dumping tree of applied image"
199 tree $2 --inodes -F -s --noreport
200 error 'Information was lost or corrupted while capturing
201 and then applying a directory tree'
207 echo "--------------------------------------------------------------------"
208 echo "Testing making $1 on read-write mounted WIM"
209 echo "--------------------------------------------------------------------"
214 # Create tree, tar it up, and untar it on an empty WIM image mounted
217 cp empty.wim test.wim
221 if [ -x /usr/bin/tree ]; then
222 tree . --inodes -F -s --noreport
227 if ! imagex mountrw test.wim tmp.mnt --unix-data; then
228 error "Failed to mount WIM read-write"
232 if ! tar xf ../test.tar; then
233 error "Failed to untar archive on read-write mounted WIM"
237 # Diff the original tree with the mounted WIM
238 do_tree_cmp tmp.orig tmp.mnt
240 # Clear the mounted WIM and do it again! (We need to test deleting
241 # stuff as well as creating stuff.)
242 if ! rm -rf tmp.mnt/*; then
243 error "Failed to clear mounted WIM"
247 if ! tar xf ../test.tar; then
248 error "Failed to untar archive on read-write mounted WIM"
252 # Diff the original tree with the mounted WIM
253 do_tree_cmp tmp.orig tmp.mnt
255 # Unmount the WIM, apply it, and diff the original tree with the applied
257 if ! imagex_unmount tmp.mnt --commit; then
258 error "Failed to unmount WIM mounted read-write"
260 if ! imagex apply test.wim tmp.apply; then
261 error "Failed to apply WIM we previously had mounted read-write"
263 do_tree_cmp tmp.orig tmp.apply
264 rm -rf tmp.orig/* tmp.apply/*
267 . $srcdir/tests/common_tests.sh
270 echo "**********************************************************"
271 echo " WIM mount tests passed "
272 echo "**********************************************************"