Magellan Linux

Contents of /trunk/grubby/test-bls.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3141 - (show annotations) (download) (as text)
Tue Jul 7 11:15:03 2020 UTC (3 years, 9 months ago) by niro
File MIME type: application/x-sh
File size: 10070 byte(s)
Add grubby-bls script (#35)
1 #!/bin/bash
2 #
3 # test.sh -- grubby wrapper regression tests
4 #
5 # Copyright 2007-2018 Red Hat, Inc. All rights reserved.
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #
20
21 #----------------------------------------------------------------------
22 # Global vars
23 #----------------------------------------------------------------------
24
25 cmd=${0##*/}
26 opt_bootloader=*
27 opt_verbose=false
28 read -d '' usage <<EOT
29 usage: test.sh [ -hv ]
30
31 -b B --bootloader=B Test bootloader B instead of all
32 -h --help Show this help message
33 -v --verbose Verbose output
34 EOT
35 declare -i pass=0 fail=0
36 testing=
37
38 BLSDIR=$(mktemp -d)
39
40 #----------------------------------------------------------------------
41 # Functions
42 #----------------------------------------------------------------------
43
44 empty_blsdir() {
45 rm -rf $BLSDIR/*
46 }
47
48 oneTest() {
49 typeset mode=$1 correct=test/bls/results/$2
50 shift 2
51
52 local ENV_FILE=""
53 if [ "$mode" == "--grub2" ]; then
54 ENV_FILE="test/bls/grub2-support_files/env_temp"
55 if [ ! -f $ENV_FILE ]; then
56 cp "test/bls/grub2-support_files/grubenv" "$ENV_FILE"
57 fi
58 ENV_FILE="--env=$ENV_FILE"
59 fi
60
61 local CFG_FILE=""
62 if [ "$mode" == "--zipl" ]; then
63 CFG_FILE=$BLSDIR/cfg_temp
64 if [ ! -f $CFG_FILE ]; then
65 cp "test/bls/zipl-support_files/zipl.conf" "$CFG_FILE"
66 fi
67 CFG_FILE="--config-file=$CFG_FILE"
68 fi
69
70 echo "$testing ... $mode $correct"
71 runme=( ./grubby-bls "$mode" --bad-image-okay $ENV_FILE $CFG_FILE -b $BLSDIR "$@" )
72 runtest=( ./grubby-bls "$mode" --info=ALL $ENV_FILE $CFG_FILE -b $BLSDIR)
73 if "${runme[@]}" && "${runtest[@]}" | cmp "$correct" > /dev/null; then
74 (( pass++ ))
75 if $opt_verbose; then
76 echo -------------------------------------------------------------
77 echo -n "PASS: "
78 printf "%q " "${runme[@]}"; echo
79 "${runtest[@]}" | diff -U30 "$correct" -
80 echo
81 fi
82 else
83 (( fail++ ))
84 echo -------------------------------------------------------------
85 echo -n "FAIL: "
86 printf "%q " "${runme[@]}"; echo
87 "${runtest[@]}" | diff -U30 "$correct" -
88 echo
89 fi
90 }
91
92 # Test feature that display some information, checking that output instead of
93 # the generated configuration file
94 oneDisplayTest() {
95 typeset mode=$1 correct=test/bls/results/$2
96 shift 2
97
98 local ENV_FILE=""
99 if [ "$mode" == "--grub2" ]; then
100 ENV_FILE="test/bls/grub2-support_files/env_temp"
101 if [ ! -f $ENV_FILE ]; then
102 cp "test/bls/grub2-support_files/grubenv" "$ENV_FILE"
103 fi
104 ENV_FILE="--env=$ENV_FILE"
105 fi
106
107 local CFG_FILE=""
108 if [ "$mode" == "--zipl" ]; then
109 CFG_FILE=$BLSDIR/cfg_temp
110 if [ ! -f $CFG_FILE ]; then
111 cp "test/bls/zipl-support_files/zipl.conf" "$CFG_FILE"
112 fi
113 CFG_FILE="--config-file=$CFG_FILE"
114 fi
115
116 local BIO="--bad-image-okay"
117 if [ "$1" == "--bad-image-bad" ]; then
118 BIO=""
119 shift
120 fi
121
122 echo "$testing ... $mode $correct"
123 runme=( ./grubby-bls "$mode" $BIO $ENV_FILE $CFG_FILE -b $BLSDIR "$@" )
124 if "${runme[@]}" 2>&1 | cmp "$correct" > /dev/null; then
125 (( pass++ ))
126 if $opt_verbose; then
127 echo -------------------------------------------------------------
128 echo -n "PASS: "
129 printf "%q " "${runme[@]}"; echo
130 "${runme[@]}" 2>&1 | diff -U30 "$correct" -
131 echo
132 fi
133 else
134 (( fail++ ))
135 echo -------------------------------------------------------------
136 echo -n "FAIL: "
137 printf "%q " "${runme[@]}"; echo
138 "${runme[@]}" 2>&1 | diff -U30 "$correct" -
139 echo
140 fi
141 }
142
143 commandTest() {
144 description=$1
145 cmd0=$2
146 text1=$3
147 shift 3
148 echo "$description"
149 output0=$(mktemp)
150
151 $cmd0 > $output0
152
153 if echo $text1 | cmp $output0 - >/dev/null; then
154 (( pass++))
155 if $opt_verbose; then
156 echo -------------------------------------------------------------
157 echo -n "PASS: "
158 printf "%q " "\"$cmd0\""; echo
159 echo $text1 | diff -U30 $output0 -
160 echo
161 fi
162 else
163 (( fail++ ))
164 echo -------------------------------------------------------------
165 echo -n "FAIL: "
166 printf "%q " "\"$cmd0\""; echo
167 echo $text1 | diff -U30 $output0 -
168 echo
169 fi
170 }
171
172 # generate convenience functions
173 for b in $(./grubby-bls --help | \
174 sed -n 's/^.*--\([^ ]*\) *configure \1 bootloader.*/\1/p'); do
175 eval "${b}Test() { [[ \"$b\" == \$opt_bootloader ]] && oneTest --$b \"\$@\"; }"
176 eval "${b}DisplayTest() { [[ \"$b\" == \$opt_bootloader ]] && oneDisplayTest --$b \"\$@\"; }"
177 done
178
179 #----------------------------------------------------------------------
180 # Main
181 #----------------------------------------------------------------------
182
183 # Use /usr/bin/getopt which supports GNU-style long options
184 args=$(getopt -o b:hv --long bootloader,help,verbose -n "$cmd" -- "$@") || exit
185 eval set -- "$args"
186 while true; do
187 case $1 in
188 -b|--bootloader) opt_bootloader=$2; shift 2 ;;
189 -h|--help) echo "$usage"; exit 0 ;;
190 -v|--verbose) opt_verbose=true; shift ;;
191 --) shift; break ;;
192 *) echo "failed to process cmdline args" >&2; exit 1 ;;
193 esac
194 done
195
196 empty_blsdir
197
198 testing="Z/IPL default directive"
199 ziplTest add/z1.1 --add-kernel /boot/new-kernel0 --title "title 0"
200 ziplTest add/z1.2 --add-kernel /boot/new-kernel1 --title "title 1" --make-default
201
202 testing="Z/IPL display default index"
203 ziplDisplayTest default/index0 --default-index
204
205 testing="Z/IPL default index directive"
206 ziplTest default/z2 --set-default-index=1
207
208 testing="Z/IPL display default index"
209 ziplDisplayTest default/index1 --default-index
210
211 testing="Z/IPL display default title"
212 ziplDisplayTest default/title0 --default-title
213
214 testing="Z/IPL display default kernel"
215 ziplDisplayTest default/kernel0 --default-kernel
216
217 testing="Z/IPL display entry information"
218 ziplDisplayTest display/info0 --info=1
219
220 testing="Z/IPL remove kernel"
221 ziplTest remove/z3.1 --remove-kernel=/boot/new-kernel1
222 ziplTest remove/z3.2 --remove-kernel=DEFAULT
223
224 testing="Z/IPL add kernel"
225 ziplTest add/z4.1 --add-kernel=/boot/new-kernel0 --title test --args="foo=bar"
226 ziplTest add/z4.2 --add-kernel=/boot/new-kernel1 --title test --copy-default --args="x=y"
227
228 empty_blsdir
229
230 testing="GRUB2 add kernel with title"
231 grub2Test add/g1 --add-kernel=/boot/new-kernel0 --title='title 0' \
232 --initrd=/boot/new-initrd0.img
233
234 testing="GRUB2 add kernel with initrd"
235 grub2Test add/g2 --add-kernel=/boot/new-kernel1 --initrd=/boot/new-initrd1.img \
236 --title="title 1" --make-default
237
238 testing="GRUB2 add kernel"
239 grub2Test add/g3 --add-kernel=/boot/new-kernel2 --title "title 2"
240
241 testing="GRUB2 remove kernel"
242 grub2Test remove/g4 --remove-kernel=/boot/new-kernel2
243
244 testing="GRUB2 add kernel with copy default"
245 grub2Test add/g5 --add-kernel=/boot/new-kernel3.img --title='title 3' \
246 --initrd=/boot/new-initrd3.img --copy-default
247
248 testing="GRUB2 add kernel with args and ignore remove kernel"
249 grub2Test add/g6 --add-kernel=/boot/vmlinuz-0-rescue-5a94251776a14678911d4ae0949500f5 \
250 --initrd /boot/initramfs-0-rescue-5a94251776a14678911d4ae0949500f5.img \
251 --copy-default --title "Fedora 21 Rescue" --args=root=/fooooo \
252 --remove-kernel=wtf
253
254 testing="GRUB2 add initrd"
255 grub2Test add/g7 --update-kernel=/boot/new-kernel0 --initrd=/boot/new-initrd
256
257 testing="GRUB2 display default index"
258 grub2DisplayTest default/index1 --default-index
259
260 testing="GRUB2 display default title"
261 grub2DisplayTest default/title1 --default-title
262
263 testing="GRUB2 remove kernel via index"
264 grub2Test remove/g8 --remove-kernel=1
265
266 testing="GRUB2 remove kernel via title"
267 grub2Test remove/g9 --remove-kernel="TITLE=title 3"
268
269 testing="GRUB2 default index directive"
270 grub2Test default/g10.1 --set-default-index=0
271 grub2DisplayTest default/index0 --default-index
272 grub2Test default/g10.2 --set-default-index=1
273 grub2DisplayTest default/index1 --default-index
274 grub2Test default/g10.3 --set-default-index=9
275 grub2DisplayTest default/index1 --default-index
276
277 testing="GRUB2 add kernel with default=saved_entry"
278 grub2Test add/g11 --add-kernel=/boot/new-kernel.img \
279 --title='title' --initrd=/boot/new-initrd \
280 --copy-default
281 commandTest "saved_default output" \
282 "grub2-editenv test/bls/grub2-support_files/env_temp list" \
283 "saved_entry=Fedora 21 Rescue"
284
285 testing="GRUB2 add kernel with default=saved_entry and a terrible title"
286 grub2Test add/g12 --add-kernel=/boot/new-kernel.img \
287 --title='Fedora (3.10.3-300.fc19.x86_64) 19 (Schrödinger’s Cat)' \
288 --initrd=/boot/new-initrd --copy-default
289
290 testing="GRUB2 set default with default=saved_entry and a terrible name"
291 grub2Test add/g13 --set-default-index=1
292 commandTest "saved_default output" \
293 "grub2-editenv test/bls/grub2-support_files/env_temp list" \
294 'saved_entry=Fedora (3.10.3-300.fc19.x86_64) 19 (Schrödinger’s Cat)'
295
296 testing="GRUB2 set default with default=saved_entry"
297 grub2Test add/g14 --set-default-index=0
298 commandTest "saved_default output" \
299 "grub2-editenv test/bls/grub2-support_files/env_temp list" \
300 "saved_entry=title 0"
301
302 testing="GRUB2 --default-index with default=saved_entry"
303 grub2DisplayTest default/index0 --default-index
304
305 testing="GRUB2 --default-title with default=saved_entry"
306 grub2DisplayTest default/title0 --default-title
307
308 testing="GRUB2 --default-index with default=saved_entry and empty grubenv"
309 grub2DisplayTest default/index0 --env /dev/null --default-index
310
311 printf "\n%d (%d%%) tests passed, %d (%d%%) tests failed\n" \
312 $pass $(((100*pass)/(pass+fail))) \
313 $fail $(((100*fail)/(pass+fail)))
314
315 rm -rf $BLSDIR
316
317 exit $(( !!fail ))

Properties

Name Value
svn:executable *