]> wimlib.net Git - wimlib/blob - tests/test-imagex-ntfs
eb061b1a49ea892badf73694c877081f3f46a22d
[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
85         __do_mount out.ntfs out.mnt
86         ./ntfs-cmp in.mnt out.mnt
87         rm -rf out.mnt/* in.mnt/*
88         __do_unmount out.mnt
89 }
90 msg() {
91         echo "Testing image capture and application of $1"
92 }
93
94 cleanup
95 init
96
97 msg "Empty NTFS volume"
98 do_test ""
99
100 msg "NTFS volume containing a single file"
101 do_test "echo 1 > file"
102
103 msg "NTFS volume containing a single directory"
104 do_test "mkdir dir"
105
106 msg "NTFS volume containing subdirectory with file"
107 do_test "mkdir dir; echo 1 > dir/file"
108
109 msg "NTFS volume containing empty file"
110 do_test "echo -n > empty_file"
111
112 msg "NTFS volume containing two empty files"
113 do_test "echo -n > empty_file_1; echo -n > empty_file_2"
114
115 msg "NTFS volume containing hard link in same directory"
116 do_test "echo 1 > file; ln file link"
117
118 msg "NTFS volume containing hard link between empty files"
119 do_test "echo -n > empty_file; ln empty_file link"
120
121 msg "NTFS volume containing relative symbolic link"
122 do_test "echo 1 > file; ln -s file symlink"
123
124 msg "NTFS volume containing absolute symbolic link"
125 do_test "echo 1 > file; ln -s /some/absolute/target symlink"
126
127 msg "NTFS volume containing large file"
128 do_test "dd if=/dev/zero of=file bs=4096 count=10 &> /dev/null"
129
130 msg "NTFS volume containing file with DOS name"
131 do_test "echo 1 > file; setfattr -v file -n system.ntfs_dos_name file"
132
133 msg "NTFS volume containing file with DOS name with alphabetically smaller hardlink in same directory"
134 do_test "echo 1 > file; setfattr -v file -n system.ntfs_dos_name file; ln file aaa_link"
135
136 msg "NTFS volume containing file with DOS name with alphabetically larger hardlink in same directory"
137 do_test "echo 1 > file; setfattr -v file -n system.ntfs_dos_name file; ln file zzz_link"
138
139 msg "NTFS volume containing file with long name and with DOS name with alphabetically smaller hardlink in same directory"
140 do_test 'echo 1 > file_with_a_long_name;
141          setfattr -v "file~1" -n system.ntfs_dos_name file_with_a_long_name;
142          ln file_with_a_long_name aaa_link'
143
144 msg "NTFS volume containing many nested directories"
145 do_test 'mkdir dir; mkdir dir/subdir; mkdir dir/subdir/subdir2; mkdir dir/subdir/subdir3'
146
147 msg "NTFS volume containing identical files and symlinks in subdirectory"
148 do_test 'mkdir dir;
149          echo 888 > dir/file;
150          echo 888 > dir/idfile2;
151          ln -s dir dir/circle; ln -s file dir/filelink'
152
153 msg "NTFS volume containing hard link group and identical files not hard linked"
154 do_test 'echo 888 > file;
155          echo 888 > file2;
156          ln file link;
157          ln file link2;
158          echo 888 > file3'
159
160 msg "NTFS volume containing file with named data stream"
161 do_test 'echo 1 > file;
162          setfattr -n user.ads -v 2 file'
163
164         
165