]> wimlib.net Git - wimlib/blob - tests/test-imagex-capture_and_apply
1dfc9431568662f92613753be8ba9e58b1bd30a4
[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
18 imagex() {
19         echo "imagex $@"
20         ../imagex "$@" > /dev/null
21 }
22
23 imagex_info() {
24         echo "imagex info $@"
25         ../imagex info "$@"
26 }
27
28 init() {
29         mkdir in.dir out.dir
30 }
31
32 cleanup() {
33         rm -rf in.dir out.dir test*.wim test*.swm
34 }
35
36 error() {
37         echo "****************************************************************"
38         echo "                         Test failure                           "
39         echo $*
40         echo "****************************************************************"
41         exit 1
42 }
43
44 wim_ctype() {
45         ../imagex info $1 | grep Compression | awk '{print $2}'
46 }
47
48 do_tree_cmp() {
49         if ! ./tree-cmp in.dir out.dir; then
50                 if [ -x /usr/bin/tree ]; then
51                         echo "Dumping tree of applied image"
52                         echo "(Note: compression type was $ctype)"
53                         tree out.dir --inodes -F -s --noreport
54                         error 'Information was lost or corrupted while capturing
55                                 and then applying a directory tree'
56                 fi
57         fi
58 }
59
60 image_name=0
61 do_test() {
62         for ctype in None LZX XPRESS; do
63
64                 # Can we capture the WIM, apply it, and get the same result?
65                 cd in.dir
66                 eval "$1"
67                 cd ..
68                 if [ -x /usr/bin/tree -a "$ctype" = "None" ]; then
69                         tree in.dir --inodes -F -s --noreport
70                 fi
71                 if ! imagex capture in.dir test.wim --compress=$ctype; then
72                         error "Failed to capture directory tree into a WIM"
73                 fi
74                 if ! imagex apply test.wim 1 out.dir; then
75                         error "Failed to apply WIM to directory"
76                 fi
77                 if [ `wim_ctype test.wim` != $ctype ]; then
78                         error "'imagex info' didn't report the compression type on the captured WIM correctly"
79                 fi
80                 do_tree_cmp
81                 rm -rf out.dir/*
82
83                 # Can we split the WIM, apply the split WIM, join the split WIM,
84                 # and apply the joined WIM, and get the same results every time?
85                 if ! imagex split test.wim test.swm 0.01; then
86                         error "Failed to split WIM"
87                 fi
88                 if ! imagex apply test.swm 1 out.dir --ref "test*.swm" ; then
89                         error "Failed to apply split WIM"
90                 fi
91                 do_tree_cmp
92                 rm -rf out.dir/* test.wim
93                 if ! imagex join test.wim test*.swm; then
94                         error "Failed to join split WIM"
95                 fi
96                 if ! imagex apply test.wim out.dir; then
97                         error "Failed to apply joined WIM"
98                 fi
99                 do_tree_cmp
100                 rm -rf out.dir/*
101
102                 # Can we export the image to another WIM, apply it, and get the
103                 # same results?
104                 (( image_name++ )) || true
105                 if ! imagex export test.wim 1 test2.wim "$image_name"; then
106                         error "Failed to export WIM image"
107                 fi
108
109                 if ! imagex apply test2.wim "$image_name" out.dir; then
110                         error "Failed to apply exported WIM image"
111                 fi
112                 do_tree_cmp
113
114                 rm -rf out.dir/* in.dir/* test.wim test*.swm
115
116         done
117 }
118
119 __msg() {
120         echo "--------------------------------------------------------------------"
121         echo $1
122         echo "--------------------------------------------------------------------"
123 }
124
125 msg() {
126         __msg "Testing image capture and application of directory containing $1"
127 }
128
129 cleanup
130 init
131
132 . $srcdir/tests/common_tests.sh
133
134 # Make sure exclusion list works
135 __msg "Testing default capture configuration file"
136 touch in.dir/hiberfil.sys
137 mkdir -p "in.dir/System Volume Information/subdir"
138 imagex capture in.dir test.wim
139 imagex apply test.wim out.dir
140 if [ -e out.dir/hiberfil.sys -o -e "out.dir/System Volume Information" ]; then
141         error "Files were not excluded from capture as expected"
142 fi
143 rm -rf out.dir/* in.dir/*
144
145 cleanup
146
147 echo "**********************************************************"
148 echo "          imagex capture/apply tests passed               "
149 echo "**********************************************************"