]> wimlib.net Git - wimlib/blob - tests/test-imagex-capture_and_apply
test-imagex-mount: Check for /dev/fuse both readable and writable
[wimlib] / tests / test-imagex-capture_and_apply
1 #!/usr/bin/env bash
2
3 # Test capturing and applying a WIM image in the normal (non-NTFS) capture mode
4 #
5 # Add in some tests with WIM splitting, joining, and exporting as well.
6 #
7 # Test all three compression modes (None, XPRESS, and LZX).
8 #
9 # Also, test if the capture configuration file works correctly.
10
11 set -e
12 cd tests
13 srcdir="${srcdir:-.}/.."
14 srcdir="$(cd $srcdir; pwd)"
15 . "$srcdir/tests/tests-common.sh"
16
17 TEST_SUBDIR=tmpdir_test-imagex-capture_and_apply
18
19 do_tree_cmp() {
20         if ! ../tree-cmp in.dir out.dir; then
21                 if [ -x /usr/bin/tree ]; then
22                         echo "Dumping tree of applied image"
23                         echo "(Note: compression type was $ctype)"
24                         tree out.dir --inodes -F -s --noreport
25                         error 'Information was lost or corrupted while capturing
26                                 and then applying a directory tree'
27                 fi
28         fi
29 }
30
31 image_name=0
32 do_test() {
33         for ctype in None XPRESS LZX; do
34
35                 # Can we capture the WIM, apply it, and get the same result?
36                 cd in.dir
37                 eval "$1"
38                 cd ..
39                 if [ -x /usr/bin/tree -a "$ctype" = "None" ]; then
40                         tree in.dir --inodes -F -s --noreport
41                 fi
42                 if ! imagex capture in.dir test.wim --compress=$ctype --norpfix; then
43                         error "Failed to capture directory tree into a WIM"
44                 fi
45                 if ! imagex apply test.wim 1 out.dir; then
46                         error "Failed to apply WIM to directory"
47                 fi
48                 if [ `wim_ctype test.wim` != $ctype ]; then
49                         error "'imagex info' didn't report the compression type on the captured WIM correctly"
50                 fi
51                 do_tree_cmp
52                 rm -rf out.dir/*
53
54                 # Can we split the WIM, apply the split WIM, join the split WIM,
55                 # and apply the joined WIM, and get the same results every time?
56                 if ! imagex split test.wim test.swm 0.01; then
57                         error "Failed to split WIM"
58                 fi
59                 if ! imagex apply test.swm 1 out.dir --ref "test*.swm" ; then
60                         error "Failed to apply split WIM"
61                 fi
62                 do_tree_cmp
63                 rm -rf out.dir/* test.wim
64                 if ! imagex join test.wim test*.swm; then
65                         error "Failed to join split WIM"
66                 fi
67                 if ! imagex apply test.wim out.dir; then
68                         error "Failed to apply joined WIM"
69                 fi
70                 do_tree_cmp
71                 rm -rf out.dir/*
72
73                 # Can we export the image to another WIM, apply it, and get the
74                 # same results?
75                 (( image_name++ )) || true
76                 if ! imagex export test.wim 1 test2.wim "$image_name"; then
77                         error "Failed to export WIM image"
78                 fi
79
80                 if ! imagex apply test2.wim "$image_name" out.dir; then
81                         error "Failed to apply exported WIM image"
82                 fi
83                 do_tree_cmp
84
85                 rm -rf out.dir/* in.dir/* test.wim test*.swm
86
87         done
88 }
89
90 __msg() {
91         echo "--------------------------------------------------------------------"
92         echo $1
93         echo "--------------------------------------------------------------------"
94 }
95
96 msg() {
97         __msg "Testing image capture and application of directory containing $1"
98 }
99
100 default_cleanup
101 mkdir $TEST_SUBDIR
102 cd $TEST_SUBDIR
103 mkdir in.dir out.dir
104
105 . $srcdir/tests/common_tests.sh
106
107 # Make sure exclusion list works
108 __msg "Testing default capture configuration file"
109 touch in.dir/hiberfil.sys
110 mkdir -p "in.dir/System Volume Information/subdir"
111 imagex capture in.dir test.wim
112 imagex apply test.wim out.dir
113 if [ -e out.dir/hiberfil.sys -o -e "out.dir/System Volume Information" ]; then
114         error "Files were not excluded from capture as expected"
115 fi
116
117 # Make sure reparse point fixups are working as expected
118 __msg "Testing --rpfix"
119 rm -r in.dir out.dir
120 mkdir in.dir
121 ln -s $PWD/in.dir          in.dir/absrootlink
122 ln -s $PWD/in.dir////      in.dir/absrootlinkslashes
123 ln -s /___NONEXISTENT___   in.dir/absnonexistent
124 ln -s /usr/bin/env         in.dir/absoutoftree
125 ln -s file                 in.dir/relalink
126 ln -s $PWD/in.dir/file     in.dir/abslink
127 ln -s $PWD/in.dir/file///  in.dir/abslinkslashes
128 imagex capture --rpfix in.dir test.wim
129 imagex apply --norpfix test.wim out.dir
130 if [[ `readlink out.dir/absrootlink` != "/" ]] ||
131    [[ `readlink out.dir/absrootlinkslashes` != "////" ]]; then
132         error "imagex capture --rpfix failed to fix absolute link to capture root"
133 fi
134
135 if [[ -e out.dir/absnonexistent ]] ||
136    [[ -e out.dir/absoutoftree ]]; then
137         error "imagex capture --rpfix failed to exclude out of tree absolute links"
138 fi
139 if [[ `readlink out.dir/relalink` != "file" ]]; then
140         error "imagex capture --rpfix failed to capture relative symlink"
141 fi
142 if [[ `readlink out.dir/abslink` != "/file" ]] ||
143    [[ `readlink out.dir/abslinkslashes` != "/file///" ]]; then
144         error "imagex capture --rpfix did fix absolute link properly"
145 fi
146 rm -rf out.dir
147
148 imagex apply test.wim out.dir
149 if [[ $(get_inode_number $(readlink out.dir/absrootlink)) != \
150         $(get_inode_number out.dir) ]];
151 then
152         error "imagex apply failed to apply fixed absolute symlinks"
153 fi
154
155 # Make sure source list mode is working as expected
156 __msg "Testing source list capture mode"
157 rm -rf in.dir out.dir
158 mkdir in.dir
159 echo 1 > in.dir/1
160 ln in.dir/1 in.dir/1link
161 echo 5 > 5
162 mkdir otherdir
163 cp $srcdir/src/add_image.c otherdir
164 cat > srclist << EOF
165 in.dir /
166 5      /5
167 otherdir /otherdir
168 EOF
169 imagex capture srclist --source-list test.wim
170 imagex apply test.wim out.dir
171 if [[ ! -f out.dir/5 || ! -f out.dir/1 || ! -f out.dir/1link || \
172       ! -d out.dir/otherdir ]]; then
173         error "source list capture failed to work as expected"
174 fi
175
176 # Still testing source list capture: add quoted name, and try overlay
177 rm -rf out.dir
178 cat > srclist << EOF
179 in.dir /
180 5      /5
181 otherdir /otherdir
182  "overlay dir 1"                'otherdir'      
183  "overlay dir 2"                'otherdir'  
184 EOF
185 mkdir "overlay dir 1"
186 mkdir "overlay dir 2"
187 echo A > "overlay dir 1"/A
188 echo B > "overlay dir 2"/B
189 imagex capture srclist --source-list test.wim
190 imagex apply test.wim out.dir
191 if [[ ! -f out.dir/5 || ! -f out.dir/1 || ! -f out.dir/1link || \
192       ! -f out.dir/otherdir/A || ! -f out.dir/otherdir/B ]]; then
193         error "source list capture (with quoted names and basic overlay) failed to work as expected"
194 fi
195
196 # Try deep overlay
197 rm -rf in.dir out.dir "overlay dir 1" "overlay dir 2"
198 mkdir -p in.dir.1/subdir/subdir2 in.dir.2/subdir/subdir2
199 cat > srclist << EOF
200 in.dir.1        /
201 in.dir.2        /
202 EOF
203 echo 1 > in.dir.1/subdir/1
204 echo 2 > in.dir.2/subdir/2
205 echo 3 > in.dir.1/subdir/subdir2/3
206 echo 4 > in.dir.2/subdir/subdir2/4
207 imagex capture srclist --source-list test.wim
208 imagex apply test.wim out.dir
209 if [[ ! -f out.dir/subdir/1 || ! -f out.dir/subdir/2 || \
210         ! -f out.dir/subdir/subdir2/3 || ! -f out.dir/subdir/subdir2/4 ]]; then
211         error "source list capture (with deep overlay) failed to work as expected"
212 fi
213
214 # Try bad overlay
215 __msg "Testing bad overlay (errors expected)"
216 rm -rf out.dir
217 echo 5 > 5
218 cat > srclist << EOF
219 in.dir.1        /
220 in.dir.2        /
221 5               /subdir
222 EOF
223 if imagex capture srclist --source-list test.wim; then
224         error "unexpected success in bad overlay with --source-list!"
225 fi
226
227 echo "**********************************************************"
228 echo "          imagex capture/apply tests passed               "
229 echo "**********************************************************"
230
231 cd ..
232 default_cleanup