3 # Test capturing and applying a WIM image in the normal (non-NTFS) capture mode
5 # Add in some tests with WIM splitting, joining, and exporting as well.
7 # Test all three compression modes (None, XPRESS, and LZX).
9 # Also, test if the capture configuration file works correctly.
13 srcdir="${srcdir:-.}/.."
14 srcdir="$(cd $srcdir; pwd)"
15 . "$srcdir/tests/tests-common.sh"
17 TEST_SUBDIR=tmpdir_test-imagex-capture_and_apply
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'
33 for ctype in None XPRESS LZX; do
35 # Can we capture the WIM, apply it, and get the same result?
39 if [ -x /usr/bin/tree -a "$ctype" = "None" ]; then
40 tree in.dir --inodes -F -s --noreport
42 if ! imagex capture in.dir test.wim --compress=$ctype --norpfix; then
43 error "Failed to capture directory tree into a WIM"
45 if ! imagex apply test.wim 1 out.dir; then
46 error "Failed to apply WIM to directory"
48 if [ `wim_ctype test.wim` != $ctype ]; then
49 error "'imagex info' didn't report the compression type on the captured WIM correctly"
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?
57 # LC_ALL=C avoids locale-dependent floating point number
59 if ! LC_ALL=C imagex split test.wim test.swm 0.01; then
60 error "Failed to split WIM"
62 if ! imagex apply test.swm 1 out.dir --ref "test*.swm" ; then
63 error "Failed to apply split WIM"
66 rm -rf out.dir/* test.wim
67 if ! imagex join test.wim test*.swm; then
68 error "Failed to join split WIM"
70 if ! imagex apply test.wim out.dir; then
71 error "Failed to apply joined WIM"
76 # Can we export the image to another WIM, apply it, and get the
78 (( image_name++ )) || true
79 if ! imagex export test.wim 1 test2.wim "$image_name"; then
80 error "Failed to export WIM image"
83 if ! imagex apply test2.wim "$image_name" out.dir; then
84 error "Failed to apply exported WIM image"
88 rm -rf out.dir/* in.dir/* test.wim test*.swm
94 echo "--------------------------------------------------------------------"
96 echo "--------------------------------------------------------------------"
100 __msg "Testing image capture and application of directory containing $1"
108 . $srcdir/tests/common_tests.sh
110 # Make sure exclusion list works
111 __msg "Testing default capture configuration file"
112 touch in.dir/hiberfil.sys
113 mkdir -p "in.dir/System Volume Information/subdir"
114 imagex capture in.dir test.wim
115 imagex apply test.wim out.dir
116 if [ -e out.dir/hiberfil.sys -o -e "out.dir/System Volume Information" ]; then
117 error "Files were not excluded from capture as expected"
120 # Make sure reparse point fixups are working as expected
121 __msg "Testing --rpfix"
124 ln -s $PWD/in.dir in.dir/absrootlink
125 ln -s $PWD/in.dir//// in.dir/absrootlinkslashes
126 ln -s /___NONEXISTENT___ in.dir/absnonexistent
127 ln -s /usr/bin/env in.dir/absoutoftree
128 ln -s file in.dir/relalink
129 ln -s $PWD/in.dir/file in.dir/abslink
130 ln -s $PWD/in.dir/file/// in.dir/abslinkslashes
131 imagex capture --rpfix in.dir test.wim
132 imagex apply --norpfix test.wim out.dir
133 if [[ `readlink out.dir/absrootlink` != "/" ]] ||
134 [[ `readlink out.dir/absrootlinkslashes` != "////" ]]; then
135 error "imagex capture --rpfix failed to fix absolute link to capture root"
138 if [[ -e out.dir/absnonexistent ]] ||
139 [[ -e out.dir/absoutoftree ]]; then
140 error "imagex capture --rpfix failed to exclude out of tree absolute links"
142 if [[ `readlink out.dir/relalink` != "file" ]]; then
143 error "imagex capture --rpfix failed to capture relative symlink"
145 if [[ `readlink out.dir/abslink` != "/file" ]] ||
146 [[ `readlink out.dir/abslinkslashes` != "/file///" ]]; then
147 error "imagex capture --rpfix did fix absolute link properly"
151 imagex apply test.wim out.dir
152 if [[ $(get_inode_number $(readlink out.dir/absrootlink)) != \
153 $(get_inode_number out.dir) ]];
155 error "imagex apply failed to apply fixed absolute symlinks"
158 # Make sure source list mode is working as expected
159 __msg "Testing source list capture mode"
160 rm -rf in.dir out.dir
163 ln in.dir/1 in.dir/1link
166 cp $srcdir/src/add_image.c otherdir
172 imagex capture srclist --source-list test.wim
173 imagex apply test.wim out.dir
174 if [[ ! -f out.dir/5 || ! -f out.dir/1 || ! -f out.dir/1link || \
175 ! -d out.dir/otherdir ]]; then
176 error "source list capture failed to work as expected"
179 # Still testing source list capture: add quoted name, and try overlay
185 "overlay dir 1" 'otherdir'
186 "overlay dir 2" 'otherdir'
188 mkdir "overlay dir 1"
189 mkdir "overlay dir 2"
190 echo A > "overlay dir 1"/A
191 echo B > "overlay dir 2"/B
192 imagex capture srclist --source-list test.wim
193 imagex apply test.wim out.dir
194 if [[ ! -f out.dir/5 || ! -f out.dir/1 || ! -f out.dir/1link || \
195 ! -f out.dir/otherdir/A || ! -f out.dir/otherdir/B ]]; then
196 error "source list capture (with quoted names and basic overlay) failed to work as expected"
200 rm -rf in.dir out.dir "overlay dir 1" "overlay dir 2"
201 mkdir -p in.dir.1/subdir/subdir2 in.dir.2/subdir/subdir2
206 echo 1 > in.dir.1/subdir/1
207 echo 2 > in.dir.2/subdir/2
208 echo 3 > in.dir.1/subdir/subdir2/3
209 echo 4 > in.dir.2/subdir/subdir2/4
210 imagex capture srclist --source-list test.wim
211 imagex apply test.wim out.dir
212 if [[ ! -f out.dir/subdir/1 || ! -f out.dir/subdir/2 || \
213 ! -f out.dir/subdir/subdir2/3 || ! -f out.dir/subdir/subdir2/4 ]]; then
214 error "source list capture (with deep overlay) failed to work as expected"
218 __msg "Testing bad overlay (errors expected)"
226 if imagex capture srclist --source-list test.wim; then
227 error "unexpected success in bad overlay with --source-list!"
230 echo "**********************************************************"
231 echo " imagex capture/apply tests passed "
232 echo "**********************************************************"