]> wimlib.net Git - wimlib/blob - tests/test-imagex-ntfs
Fix tests (again)
[wimlib] / tests / test-imagex-ntfs
1 #!/bin/bash
2
3 # This script does some sanity testing of the 'imagex' program, specifically
4 # checking the NTFS capture and apply features.
5 #
6 # This test will fail if wimlib was compiled with --without-ntfs-3g.
7 #
8 # Please note that cleanup is not done if a test fails, and NTFS volumes may
9 # remain mounted.
10
11 set -e
12 srcdir=`pwd`
13 cd tests
14
15 imagex() {
16         ../imagex $@ > /dev/null
17 }
18
19 __do_unmount() {
20         if !  fusermount -u $1; then
21                 error "Failed to unmount \"$1\""
22         fi
23
24 }
25 do_unmount() {
26         if mountpoint $1 &> /dev/null; then
27                 __do_unmount $1
28         fi
29 }
30
31 __do_mount() {
32         options="$3"
33         if [ -z "$options" ]; then
34                 options="no_def_opts,silent"
35         else
36                 options="$options,no_def_opts,silent"
37         fi
38         if ! ntfs-3g -o $options $1 $2; then
39                 error "Could not mount NTFS volume \"$1\" on \"$2\"!  Make sure ntfs-3g is "\
40                       "installed, and that you are either running the tests as root or have ntfs-3g "\
41                       "installed setuid root, so that we can mount a NTFS volume."
42         fi
43 }
44
45 do_mount() {
46         do_unmount $2
47         __do_mount $1 $2 $3
48 }
49
50 do_mkntfs() {
51         if ! mkntfs --force --fast $1 &> /dev/null; then
52                 error "Could not create NTFS volume \"$1\"!  Make sure ntfsprogs are installed."
53         fi
54 }
55
56 init() {
57         echo "Creating NTFS volumes and empty directories to use as mountpoints"
58         dd if=/dev/zero of=in.ntfs bs=4096 count=500 &> /dev/null
59         dd if=/dev/zero of=out.ntfs bs=4096 count=500 &> /dev/null
60         mkdir in.mnt out.mnt
61         do_mkntfs in.ntfs
62         do_mkntfs out.ntfs
63         do_mount in.ntfs in.mnt
64 }
65
66 cleanup() {
67         do_unmount in.mnt
68         do_unmount out.mnt
69         rm -rf in.ntfs out.ntfs in.mnt out.mnt in.xattr out.xattr ntfs.wim
70 }
71 #trap cleanup exit
72
73
74 error() {
75         echo "****************************************************************"
76         echo "                         Test failure                           "
77         while [ $# -gt 0 ]; do
78                 echo $1
79                 shift
80         done
81         echo "****************************************************************"
82         exit 1
83 }
84
85 do_test() {
86         cd in.mnt
87         eval "$1"
88         cd ..
89         __do_unmount in.mnt
90         if ! imagex capture in.ntfs ntfs.wim; then
91                 error "Failed to capture NTFS volume into a WIM"
92         fi
93         if ! imagex apply ntfs.wim 1 out.ntfs; then
94                 error "Failed to apply WIM to NTFS volume"
95         fi
96         __do_mount in.ntfs in.mnt noatime
97         __do_mount out.ntfs out.mnt noatime
98         if [ -x /usr/bin/tree ]; then
99                 tree in.mnt --inodes -F -s --noreport
100         fi
101         if ! ./tree-cmp in.mnt out.mnt NTFS; then
102                 if [ -x /usr/bin/tree ]; then
103                         echo "Dumping tree of applied image"
104                         tree out.mnt --inodes -F -s --noreport
105                         error 'Information was lost or corrupted while capturing
106                                 and then applying a NTFS volume'
107                 fi
108         fi
109         rm -rf out.mnt/* in.mnt/*
110         __do_unmount out.mnt
111 }
112 msg() {
113         echo "--------------------------------------------------------------------"
114         echo "Testing image capture and application of NTFS volume containing $1"
115         echo "--------------------------------------------------------------------"
116 }
117
118 cleanup
119 init
120
121 msg "Empty NTFS volume"
122 do_test ""
123
124 msg "a single file"
125 do_test "echo 1 > file"
126
127 msg "a single directory"
128 do_test "mkdir dir"
129
130 msg "subdirectory with file"
131 do_test "mkdir dir; echo 1 > dir/file"
132
133 msg "empty file"
134 do_test "echo -n > empty_file"
135
136 msg "two empty files"
137 do_test "echo -n > empty_file_1; echo -n > empty_file_2"
138
139 msg "hard link in same directory"
140 do_test "echo 1 > file; ln file link"
141
142 msg "hard link between empty files"
143 do_test "echo -n > empty_file; ln empty_file link"
144
145 msg "relative symbolic link"
146 do_test "echo 1 > file; ln -s file symlink"
147
148 msg "absolute symbolic link"
149 do_test "echo 1 > file; ln -s /some/absolute/target symlink"
150
151 msg "large file"
152 do_test "dd if=/dev/zero of=file bs=4096 count=10 &> /dev/null"
153
154 msg "file with DOS name"
155 do_test "echo 1 > file; setfattr -v file -n system.ntfs_dos_name file"
156
157 msg "file with DOS name with alphabetically smaller hardlink in same directory"
158 do_test "echo 1 > file; setfattr -v file -n system.ntfs_dos_name file; ln file aaa_link"
159
160 msg "file with DOS name with alphabetically larger hardlink in same directory"
161 do_test "echo 1 > file; setfattr -v file -n system.ntfs_dos_name file; ln file zzz_link"
162
163 msg "file with long name and with DOS name with alphabetically smaller hardlink in same directory"
164 do_test 'echo 1 > file_with_a_long_name;
165          setfattr -v "file~1" -n system.ntfs_dos_name file_with_a_long_name;
166          ln file_with_a_long_name aaa_link'
167
168 msg "many nested directories"
169 do_test 'mkdir dir; mkdir dir/subdir; mkdir dir/subdir/subdir2; mkdir dir/subdir/subdir3'
170
171 msg "identical files and symlinks in subdirectory"
172 do_test 'mkdir dir;
173          echo 888 > dir/file;
174          echo 888 > dir/idfile2;
175          ln -s ../dir dir/circle; ln -s file dir/filelink'
176
177 msg "hard link group and identical files not hard linked"
178 do_test 'echo 888 > file;
179          echo 888 > file2;
180          ln file link;
181          ln file link2;
182          echo 888 > file3'
183
184 msg "file with named data stream"
185 do_test 'echo 1 > file;
186          setfattr -n user.ads -v 2 file'
187
188 msg "file with multiple named data streams"
189 do_test 'echo 1 > file;
190          setfattr -n user.a -v 1 file;
191          setfattr -n user.aa -v 11 file;
192          setfattr -n user.aaa -v 111 file;
193          setfattr -n user.aaaa -v 1111 file'
194
195 msg "file with multiple named data streams with same contents"
196 do_test 'echo 1 > file;
197          setfattr -n user.a -v 1111 file;
198          setfattr -n user.aa -v 1111 file;
199          setfattr -n user.aaa -v 1111 file;
200          setfattr -n user.aaaa -v 1111 file;'
201
202 msg "file with named data streams with same contents as other file"
203 do_test 'echo -n > file;
204          setfattr -n user.a -v 1111 file;
205          echo -n 1111 > otherfile;'
206
207 msg "file with empty named data stream and non-empty unnamed data stream"
208 do_test 'echo 1 > file;
209          setfattr -n user.ads -v "" file;'
210
211 msg "file with empty named data stream and empty unnamed data stream"
212 do_test 'echo -n > file;
213          setfattr -n user.ads -v "" file;'
214
215 msg "file with named data stream with hardlink"
216 do_test 'echo 999 > file;
217          setfattr -n user.ads -v "888" file;
218          ln file link;'
219
220 msg "file with named data stream with hardlink and DOS name"
221 do_test 'echo 999 > file;
222          setfattr -n user.ads -v "888" file;
223          ln file link;
224          setfattr -v DOSNAME -n system.ntfs_dos_name file;'
225
226 msg "C source code of wimlib"
227 do_test 'cp $srcdir/src/*.{c,h} .'
228
229 msg "file with security descriptor"
230 do_test 'touch file;
231          setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` file'
232
233 msg "files with different security descriptors"
234 do_test 'touch file;
235          touch file2;
236          setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` file
237          setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_2.base64` file'
238
239 msg "files with different security descriptors and some with the same security descriptor"
240 do_test 'touch file;
241          touch file2;
242          touch file3;
243          mkdir dir;
244          setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` file
245          setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_2.base64` file
246          setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` dir
247          setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` file3'
248
249 msg "tons of random stuff"
250 do_test 'echo -n 8 > file;
251          ln file hardlink;
252          ln -s hardlink symlink;
253          echo -n 8 > identical file;
254          dd if=/dev/urandom of=randomfile bs=4096 count=10 &>/dev/null;
255          mkdir dir;
256          setfattr -n system.ntfs_dos_name -v DOSNAME dir;
257          setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` dir
258          mkdir anotherdir;
259          cp file anotherdir;
260          ln file anotherdir/anotherhardlink;
261          ln -s .. anotherdir/anothersymlink;
262          ln -s anothersymlink anotherdir/symlinktosymlink;
263          echo -n 33 > anotherfile;
264          setfattr -n user.ads anotherfile -v 33;
265          setfattr -n user.ads2 anotherfile -v 8;
266          setfattr -n user.ads3 anotherfile -v 33;
267          echo -n > emptyfile;
268          setfattr -n user.ads emptyfile -v 8;
269          setfattr -n user.ads5 emptyfile -v"`cat $srcdir/src/hardlink.c`"
270          mkdir dir/subdir;
271          ln file dir/subdir/file;
272          echo -n 8 > dir/subdir/file2;
273          ln dir/subdir/file dir/subdir/link;
274          setfattr -n system.ntfs_dos_name -v 123 dir/subdir/link;
275          setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` dir/subdir/link;
276          setfattr -n user.yet_another_ads -v "" dir/subdir/link;
277          setfattr -n user.yet_another_ads2 -v "" dir/subdir/link;
278          setfattr -n user.yet_another_ads3 -v "abc" dir/subdir/link;
279          setfattr -n user.yet_another_ads4 -v "" dir/subdir/link;'
280
281 cleanup
282
283 echo "**********************************************************"
284 echo "           NTFS capture/apply tests passed                "
285 echo "**********************************************************"