]> wimlib.net Git - wimlib/blob - tests/test-imagex-ntfs
a0c79fccf8ef5ed5ae88ae27cd248666b64d87f9
[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 # Assume an in-tree build.
9 set -e
10 cd tests
11
12 imagex() {
13         #echo "imagex $@"
14         ../imagex $@ > /dev/null
15 }
16
17 __do_unmount() {
18         if !  fusermount -u $1; then
19                 error "Failed to unmount \"$1\""
20         fi
21
22 }
23 do_unmount() {
24         if mountpoint $1 &> /dev/null; then
25                 __do_unmount $1
26         fi
27 }
28
29 __do_mount() {
30         options="$3"
31         if ! ntfs-3g ${options:+-o $options} $1 $2; then
32                 error "Could not mount NTFS volume \"$1\" on \"$2\".  Make sure ntfs-3g is installed."
33         fi
34 }
35
36 do_mount() {
37         do_unmount $2
38         __do_mount $1 $2 $3
39 }
40
41 do_mkntfs() {
42         if ! mkntfs --force --fast $1 &> /dev/null; then
43                 error "Could not create NTFS volume on \"$1\".  Make sure ntfs-3g / ntfsprogs are installed"
44         fi
45 }
46
47 init() {
48         echo "Creating NTFS volumes and empty directories to use as mountpoints"
49         dd if=/dev/zero of=in.ntfs bs=4096 count=260 &> /dev/null
50         dd if=/dev/zero of=out.ntfs bs=4096 count=260 &> /dev/null
51         mkdir in.mnt out.mnt
52         do_mkntfs in.ntfs
53         do_mkntfs out.ntfs
54         do_mount in.ntfs in.mnt
55 }
56
57 cleanup() {
58         do_unmount in.mnt
59         do_unmount out.mnt
60         rm -rf in.ntfs out.ntfs in.mnt out.mnt in.xattr out.xattr
61 }
62 #trap cleanup exit
63
64
65 error() {
66         echo "****************************************************************"
67         echo "                         Test failure                           "
68         echo $*
69         echo "****************************************************************"
70         exit 1
71 }
72
73 do_test() {
74         cd in.mnt
75         eval "$1"
76         cd ..
77         __do_unmount in.mnt
78         if ! imagex capture in.ntfs ntfs.wim; then
79                 error "Failed to capture NTFS volume into a WIM"
80         fi
81         if ! imagex apply ntfs.wim 1 out.ntfs; then
82                 error "Failed to apply WIM to NTFS volume"
83         fi
84         __do_mount in.ntfs in.mnt noatime
85         __do_mount out.ntfs out.mnt noatime
86         if [ -x /usr/bin/tree ]; then
87                 tree in.mnt --inodes -F -s --noreport
88         fi
89         if ! ./ntfs-cmp in.mnt out.mnt; then
90                 if [ -x /usr/bin/tree ]; then
91                         echo "Dumping tree of applied image"
92                         tree out.mnt --inodes -F -s --noreport
93                         error 'Information was lost or corrupted while capturing
94                                 and then applying a NTFS volume'
95                 fi
96         fi
97         rm -rf out.mnt/* in.mnt/*
98         __do_unmount out.mnt
99 }
100 msg() {
101         echo "Testing image capture and application of $1"
102 }
103
104 cleanup
105 init
106
107 msg "Empty NTFS volume"
108 do_test ""
109
110 msg "NTFS volume containing a single file"
111 do_test "echo 1 > file"
112
113 msg "NTFS volume containing a single directory"
114 do_test "mkdir dir"
115
116 msg "NTFS volume containing subdirectory with file"
117 do_test "mkdir dir; echo 1 > dir/file"
118
119 msg "NTFS volume containing empty file"
120 do_test "echo -n > empty_file"
121
122 msg "NTFS volume containing two empty files"
123 do_test "echo -n > empty_file_1; echo -n > empty_file_2"
124
125 msg "NTFS volume containing hard link in same directory"
126 do_test "echo 1 > file; ln file link"
127
128 msg "NTFS volume containing hard link between empty files"
129 do_test "echo -n > empty_file; ln empty_file link"
130
131 msg "NTFS volume containing relative symbolic link"
132 do_test "echo 1 > file; ln -s file symlink"
133
134 msg "NTFS volume containing absolute symbolic link"
135 do_test "echo 1 > file; ln -s /some/absolute/target symlink"
136
137 msg "NTFS volume containing large file"
138 do_test "dd if=/dev/zero of=file bs=4096 count=10 &> /dev/null"
139
140 msg "NTFS volume containing file with DOS name"
141 do_test "echo 1 > file; setfattr -v file -n system.ntfs_dos_name file"
142
143 msg "NTFS volume containing file with DOS name with alphabetically smaller hardlink in same directory"
144 do_test "echo 1 > file; setfattr -v file -n system.ntfs_dos_name file; ln file aaa_link"
145
146 msg "NTFS volume containing file with DOS name with alphabetically larger hardlink in same directory"
147 do_test "echo 1 > file; setfattr -v file -n system.ntfs_dos_name file; ln file zzz_link"
148
149 msg "NTFS volume containing file with long name and with DOS name with alphabetically smaller hardlink in same directory"
150 do_test 'echo 1 > file_with_a_long_name;
151          setfattr -v "file~1" -n system.ntfs_dos_name file_with_a_long_name;
152          ln file_with_a_long_name aaa_link'
153
154 msg "NTFS volume containing many nested directories"
155 do_test 'mkdir dir; mkdir dir/subdir; mkdir dir/subdir/subdir2; mkdir dir/subdir/subdir3'
156
157 msg "NTFS volume containing identical files and symlinks in subdirectory"
158 do_test 'mkdir dir;
159          echo 888 > dir/file;
160          echo 888 > dir/idfile2;
161          ln -s ../dir dir/circle; ln -s file dir/filelink'
162
163 msg "NTFS volume containing hard link group and identical files not hard linked"
164 do_test 'echo 888 > file;
165          echo 888 > file2;
166          ln file link;
167          ln file link2;
168          echo 888 > file3'
169
170 msg "NTFS volume containing file with named data stream"
171 do_test 'echo 1 > file;
172          setfattr -n user.ads -v 2 file'
173
174 msg "NTFS volume containing file with multiple named data streams"
175 do_test 'echo 1 > file;
176          setfattr -n user.a -v 1 file;
177          setfattr -n user.aa -v 11 file;
178          setfattr -n user.aaa -v 111 file;
179          setfattr -n user.aaaa -v 1111 file'
180
181 msg "NTFS volume containing file with multiple named data streams with same contents"
182 do_test 'echo 1 > file;
183          setfattr -n user.a -v 1111 file;
184          setfattr -n user.aa -v 1111 file;
185          setfattr -n user.aaa -v 1111 file;
186          setfattr -n user.aaaa -v 1111 file;'
187         
188 msg "NTFS volume containing file with named data streams with same contents as other file"
189 do_test 'echo -n > file;
190          setfattr -n user.a -v 1111 file;
191          echo -n 1111 > otherfile;'
192
193 msg "NTFS volume containing file with empty named data stream and non-empty unnamed data stream"
194 do_test 'echo 1 > file;
195          setfattr -n user.ads -v "" file;'
196
197 msg "NTFS volume containing file with empty named data stream and empty unnamed data stream"
198 do_test 'echo -n > file;
199          setfattr -n user.ads -v "" file;'
200
201 msg "NTFS volume containing file with named data stream with hardlink"
202 do_test 'echo 999 > file;
203          setfattr -n user.ads -v "888" file;
204          ln file link;'
205
206 msg "NTFS volume containing file with named data stream with hardlink and DOS name"
207 do_test 'echo 999 > file;
208          setfattr -n user.ads -v "888" file;
209          ln file link;
210          setfattr -v DOSNAME -n system.ntfs_dos_name file;'