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