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