]> wimlib.net Git - wimlib/blob - tests/test-imagex-ntfs
test-imagex-ntfs (IN PROGRESS)
[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 mountpoint $1 &> /dev/null; then
19                 if !  fusermount -u $1; then
20                         error "Failed to unmount \"$1\""
21                 fi
22         fi
23 }
24
25 do_mkntfs() {
26         if ! mkntfs --force $1 &> /dev/null; then
27                 error "Could not create NTFS volume on \"$1\".  Make sure ntfs-3g / ntfsprogs are installed"
28         fi
29 }
30
31 init() {
32         echo "Creating NTFS volumes and empty directories to use as mountpoints"
33         dd if=/dev/zero of=in.ntfs bs=4096 count=1000 &> /dev/null
34         dd if=/dev/zero of=out.ntfs bs=4096 count=1000 &> /dev/null
35         mkdir in.mnt out.mnt
36         do_mkntfs in.ntfs
37         do_mkntfs out.ntfs
38 }
39
40 cleanup() {
41         do_unmount in.mnt
42         do_unmount out.mnt
43         rm -rf in.ntfs out.ntfs in.mnt out.mnt in.xattr out.xattr
44 }
45 #trap cleanup exit
46
47
48 error() {
49         echo "****************************************************************"
50         echo "                         Test failure                           "
51         echo $*
52         echo "****************************************************************"
53         exit 1
54 }
55
56 do_capture() {
57         if ! imagex capture in.ntfs ntfs.wim; then
58                 error "Failed to capture NTFS volume into a WIM"
59         fi
60 }
61
62 do_apply() {
63         do_unmount out.ntfs
64         do_mkntfs out.ntfs
65         if ! imagex apply ntfs.wim 1 out.ntfs; then
66                 error "Failed to apply WIM to NTFS volume"
67         fi
68         echo "do_apply"
69 }
70
71 cmp_xattrs() {
72         infile=$1
73         outfile=$2
74         xattr=$3
75         #echo "Comparing xattr $xattr of $infile and $outfile"
76         if test "$xattr" = "system.ntfs_times"; then
77                 headnum=24
78         else
79                 headnum=1000000000
80         fi
81         if eval getfattr --only-values -d -n $xattr $infile 2>/dev/null\
82                                         | head -c $headnum > in.xattr; then
83                 if eval getfattr --only-values -d -n $xattr $outfile 2>/dev/null\
84                                         | head -c $headnum > out.xattr; then
85                         if ! cmp in.xattr out.xattr; then
86                                 error "Extended attribute $xattr of $infile and $outfile differs"
87                         fi
88                 else
89                         error "$infile has extended attribute $xattr, but $outfile doesn't"
90                 fi
91         else
92                 if eval getfattr --only-values -d -n $xattr $outfile 2>/dev/null\
93                                         | head -c $headnum > out.xattr; then
94                         error "$outfile has extended attribute $xattr, but $infile doesn't"
95                 fi
96         fi
97 }
98
99 do_capture_and_apply() {
100         do_unmount in.mnt
101         do_unmount out.mnt
102         do_capture
103         if ! ntfs-3g -o ro in.ntfs in.mnt || ! ntfs-3g -o ro out.ntfs out.mnt; then
104                 error "Could not mount NTFS volume.  Make sure ntfs-3g is installed"
105         fi
106         if ! diff -r in.mnt out.mnt; then
107                 error "Recursive diff of original NTFS volume with applied NTFS volume failed"
108         fi
109         for infile in `find in.mnt`; do
110                 outfile=out.mnt${infile##in.mnt}
111                 echo "Comparing xattrs of $infile and $outfile"
112                 cmp_xattrs $infile $outfile system.ntfs_attrib
113                 cmp_xattrs $infile $outfile system.ntfs_reparse_data
114                 cmp_xattrs $infile $outfile system.ntfs_acl
115                 cmp_xattrs $infile $outfile system.ntfs_dos_name
116                 cmp_xattrs $infile $outfile system.ntfs_times
117         done
118 }
119
120 cleanup
121 init
122
123 echo "Testing capture and apply of empty NTFS volume"
124 do_capture_and_apply
125
126