Magellan Linux

Annotation of /trunk/grubby/test.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1332 - (hide annotations) (download) (as text)
Fri Jun 3 20:32:19 2011 UTC (13 years, 5 months ago) by niro
File MIME type: application/x-sh
File size: 16484 byte(s)
-forkin standalone grubby
1 niro 532 #!/bin/bash
2 niro 1308 #
3     # test.sh -- grubby regression tests
4     #
5     # Copyright 2007-2008 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 niro 532
21 niro 1308 if [ -n "$TOPDIR" ]; then
22     LD_LIBRARY_PATH="$TOPDIR/nash:$TOPDIR/bdevid:/usr/lib:/lib"
23     export LD_LIBRARY_PATH
24     fi
25 niro 532
26 niro 1308 #----------------------------------------------------------------------
27     # Global vars
28     #----------------------------------------------------------------------
29 niro 532
30 niro 1308 cmd=${0##*/}
31     opt_bootloader=*
32     opt_verbose=false
33     read -d '' usage <<EOT
34     usage: test.sh [ -hv ]
35 niro 532
36 niro 1308 -b B --bootloader=B Test bootloader B instead of all
37     -h --help Show this help message
38     -v --verbose Verbose output
39     EOT
40     declare -i pass=0 fail=0
41     testing=
42 niro 532
43 niro 1308 #----------------------------------------------------------------------
44     # Functions
45     #----------------------------------------------------------------------
46 niro 532
47 niro 1308 oneTest() {
48     typeset mode=$1 cfg=test/$2 correct=test/results/$3
49     shift 3
50 niro 532
51 niro 1308 echo "$testing ... $mode $cfg $correct"
52     runme=( ./grubby "$mode" --bad-image-okay -c "$cfg" -o - "$@" )
53     if "${runme[@]}" | cmp "$correct" > /dev/null; then
54     (( pass++ ))
55     if $opt_verbose; then
56     echo -------------------------------------------------------------
57     echo -n "PASS: "
58     printf "%q " "${runme[@]}"; echo
59     "${runme[@]}" | diff -U30 "$cfg" -
60     echo
61     fi
62     else
63     (( fail++ ))
64 niro 532 echo -------------------------------------------------------------
65 niro 1308 echo -n "FAIL: "
66     printf "%q " "${runme[@]}"; echo
67     "${runme[@]}" | diff -U30 "$correct" -
68     echo
69 niro 532 fi
70     }
71    
72 niro 1308 # generate convenience functions
73     for b in $(./grubby --help | \
74     sed -n 's/^.*--\([^ ]*\) *configure \1 bootloader$/\1/p'); do
75     eval "${b}Test() { [[ \"$b\" == \$opt_bootloader ]] && oneTest --$b \"\$@\"; }"
76     done
77 niro 532
78 niro 1308 #----------------------------------------------------------------------
79     # Main
80     #----------------------------------------------------------------------
81 niro 532
82 niro 1308 # Use /usr/bin/getopt which supports GNU-style long options
83     args=$(getopt -o b:hv --long bootloader,help,verbose -n "$cmd" -- "$@") || exit
84     eval set -- "$args"
85     while true; do
86     case $1 in
87     -b|--bootloader) opt_bootloader=$2; shift 2 ;;
88     -h|--help) echo "$usage"; exit 0 ;;
89     -v|--verbose) opt_verbose=true; shift ;;
90     --) shift; break ;;
91     *) echo "failed to process cmdline args" >&2; exit 1 ;;
92     esac
93     done
94 niro 532
95 niro 1308 export MALLOC_CHECK_=2
96 niro 532
97 niro 1308 testing="Parse/write comparison"
98     for n in test/*.[0-9]*; do
99     n=${n#*/} # remove test/
100     b=${n%.*} # remove suffix
101     [[ $b == $opt_bootloader ]] || continue
102     ${b}Test $n ../$n --remove-kernel 1234
103 niro 532 done
104    
105 niro 1308 testing="Permission preservation"
106     unset b
107     for n in test/*.[0-9]*; do
108     n=${n#*/} # remove test/
109     [[ ${n%.*} == "$b" ]] && continue
110     b=${n%.*} # remove suffix
111     [[ $b == $opt_bootloader ]] || continue
112    
113     echo "$testing ... --$b"
114    
115     cp test/$n ${b}-test
116     chmod 0614 ${b}-test
117     touch -t 200301010101.00 ${b}-test
118     time=$(ls -l ${b}-test | awk '{ print $6 " " $7 " "$8}')
119     perm=$(ls -l ${b}-test | awk '{print $1}')
120     ./grubby --${b} --add-kernel bar --title title -c ${b}-test
121     if [[ $? != 0 ]]; then
122     echo " FAIL (grubby returned non-zero)"
123     (( fail++ ))
124     elif newtime=$(ls -l ${b}-test | awk '{ print $6 " " $7 " "$8}') && \
125     newperm=$(ls -l ${b}-test | awk '{print $1}') && \
126     [[ $time == "$newtime" || $perm != "$newperm" ]]
127     then
128     echo " FAIL ($perm $newperm)";
129     (( fail++ ))
130     else
131     (( pass++ ))
132     fi
133     rm -f ${b}-test
134 niro 532 done
135    
136 niro 1308 testing="Following symlinks"
137     unset b
138     for n in test/*.[0-9]*; do
139     n=${n#*/} # remove test/
140     [[ ${n%.*} == "$b" ]] && continue
141     b=${n%.*} # remove suffix
142     [[ $b == $opt_bootloader ]] || continue
143 niro 532
144 niro 1308 echo "$testing ... --$b"
145 niro 532
146 niro 1308 cp test/${b}.1 ${b}-test
147     ln -s ./${b}-test mytest
148     ./grubby --${b} --add-kernel bar --title title -c mytest
149     if [[ $? != 0 ]]; then
150     echo " failed (grubby returned non-zero)"
151     (( fail++ ))
152     elif [[ ! -L mytest ]]; then
153     echo " failed (not a symlink)"
154     (( fail++ ))
155     elif target=$(readlink mytest) && [[ $target != "./${b}-test" ]]; then
156     echo " failed (wrong target)"
157     (( fail++ ))
158     else
159     (( pass++ ))
160     fi
161     rm -f ${b}-test mytest
162     done
163 niro 532
164 niro 1308 testing="GRUB default directive"
165 niro 532 grubTest grub.1 default/g1.1 --boot-filesystem=/boot --add-kernel /boot/new-kernel --title Some_Title
166     grubTest grub.1 default/g1.2 --boot-filesystem=/boot --add-kernel /boot/new-kernel --title Some_Title --make-default
167     grubTest grub.3 default/g3.1 --boot-filesystem=/boot --set-default=/boot/vmlinuz-2.4.7-2
168     grubTest grub.3 default/g3.2 --boot-filesystem=/boot --set-default=/boot/vmlinuz-2.4.7-2smp
169     grubTest grub.4 default/g4.1 --boot-filesystem=/ --set-default=/boot/vmlinuz-2.4.7-ac3 --remove-kernel /boot/vmlinuz-2.4.7-2.5
170     grubTest grub.4 default/g4.2 --boot-filesystem=/ --set-default=/boot/vmlinuz-2.4.7-ac3 --remove-kernel /boot/vmlinuz-2.4.7-2.5 --add-kernel=/boot/new-kernel --copy-default --title New_Title
171     grubTest grub.6 default/g6.1 --remove-kernel=/boot/vmlinuz-2.4.7-2.9 --boot-filesystem=/
172    
173 niro 1308 testing="LILO default directive"
174 niro 532 liloTest lilo.1 default/l1.1 --set-default=/boot/vmlinuz-2.4.18-4
175     liloTest lilo.1 default/l1.2 --remove-kernel=/boot/vmlinuz-2.4.18-4smp
176     liloTest lilo.1 default/l1.3 --add-kernel /boot/kernel --title label \
177     --copy-default
178     liloTest lilo.1 default/l1.4 --add-kernel /boot/kernel --title label \
179     --copy-default --make-default
180    
181 niro 1308 testing="Z/IPL default directive"
182 niro 532 ziplTest zipl.1 default/z1.1 --add-kernel /boot/new-kernel --title test
183     ziplTest zipl.1 default/z1.2 --add-kernel /boot/new-kernel --title test --make-default
184    
185 niro 1308 testing="GRUB fallback directive"
186 niro 532 grubTest grub.5 fallback/g5.1 --remove-kernel=/boot/vmlinuz-2.4.7-ac3 \
187     --boot-filesystem=/
188     grubTest grub.5 fallback/g5.2 --remove-kernel=/boot/vmlinuz-2.4.7-2.5 \
189     --boot-filesystem=/
190     grubTest grub.5 fallback/g5.3 --remove-kernel=/boot/vmlinuz-2.4.7-2.5 \
191     --boot-filesystem=/ --copy-default --add-kernel=/boot/new-kernel \
192     --title="Some_Title"
193    
194 niro 1308 testing="GRUB new kernel argument handling"
195 niro 532 grubTest grub.1 args/g1.1 --boot-filesystem=/boot \
196     --add-kernel=/boot/foo --title=some_title --args="1234" --copy-default
197     grubTest grub.1 args/g1.2 --boot-filesystem=/boot \
198     --add-kernel=/boot/foo --title=some_title --args="1234"
199    
200 niro 1308 testing="GRUB remove kernel"
201 niro 532 grubTest grub.7 remove/g7.1 --boot-filesystem=/ \
202     --remove-kernel=/boot/vmlinuz-2.4.7-2.5
203     grubTest grub.3 remove/g3.1 --boot-filesystem=/ \
204     --remove-kernel=DEFAULT
205     grubTest grub.9 remove/g9.1 --boot-filesystem=/boot \
206     --remove-kernel=/boot/vmlinuz-2.4.7-2
207    
208 niro 1308 testing="YABOOT remove kernel"
209 niro 532 yabootTest yaboot.1 remove/y1.1 --boot-filesystem=/ --remove-kernel=DEFAULT
210     yabootTest yaboot.1 remove/y1.2 --boot-filesystem=/ --remove-kernel=/boot/vmlinuz-2.5.50-eepro
211     yabootTest yaboot.2 remove/y2.1 --boot-filesystem=/ --remove-kernel=/boot/vmlinux-2.5.50
212    
213 niro 1308 testing="Z/IPL remove kernel"
214 niro 532 ziplTest zipl.1 remove/z1.1 --remove-kernel=/boot/vmlinuz-2.4.9-38
215     ziplTest zipl.1 remove/z1.2 --remove-kernel=DEFAULT
216    
217 niro 1308 testing="GRUB update kernel argument handling"
218 niro 532 grubTest grub.1 updargs/g1.1 --update-kernel=DEFAULT --args="root=/dev/hda1"
219     grubTest grub.1 updargs/g1.2 --update-kernel=DEFAULT \
220     --args="root=/dev/hda1 hda=ide-scsi root=/dev/hda2"
221     grubTest grub.3 updargs/g3.1 --update-kernel=DEFAULT --args "hdd=notide-scsi"
222     grubTest grub.3 updargs/g3.2 --update-kernel=DEFAULT \
223     --args "hdd=notide-scsi root=/dev/hdd1"
224     grubTest grub.3 updargs/g3.2 --update-kernel=DEFAULT \
225     --args "root=/dev/hdd1 hdd=notide-scsi"
226     grubTest grub.3 updargs/g3.4 --update-kernel=ALL --remove-args="hdd"
227     grubTest grub.3 updargs/g3.4 --update-kernel=ALL --remove-args="hdd=ide-scsi"
228     grubTest grub.3 updargs/g3.4 --update-kernel=ALL --remove-args="hdd=foobar"
229     grubTest grub.3 updargs/g3.7 --update-kernel=ALL \
230     --remove-args="hdd root ro"
231     grubTest grub.7 updargs/g7.2 --boot-filesystem=/ \
232     --update-kernel=ALL --args "hde=ide-scsi"
233     grubTest grub.7 updargs/g7.2 --boot-filesystem=/ \
234     --update-kernel=ALL --args "hde=ide-scsi"
235     grubTest grub.7 updargs/g7.3 --boot-filesystem=/ \
236     --update-kernel=DEFAULT --args "hde=ide-scsi"
237     grubTest grub.7 updargs/g7.4 --boot-filesystem=/ \
238     --update-kernel=/vmlinuz-2.4.7-2 \
239     --args "ro root=LABEL=/ console=tty0 console=ttyS1,9600n81 single"
240 niro 1308 grubTest grub.7 updargs/g7.5 --boot-filesystem=/ \
241     --update-kernel=ALL --args "root=/dev/hda2"
242 niro 532 grubTest grub.11 updargs/g11.1 --boot-filesystem=/ \
243     --update-kernel=/vmlinuz-2.4.7-2smp \
244     --args "ro root=LABEL=/ console=tty0 console=ttyS1,9600n81 single"
245     grubTest grub.11 updargs/g11.2 --boot-filesystem=/ \
246     --update-kernel=/vmlinuz-2.4.7-2smp \
247     --args "ro root=LABEL=/ single"
248    
249 niro 1308 testing="LILO update kernel argument handling"
250 niro 532 liloTest lilo.1 updargs/l1.1 --update-kernel=/boot/vmlinuz-2.4.18-4 \
251     --args="root=/dev/md1"
252     liloTest lilo.1 updargs/l1.2 --update-kernel=/boot/vmlinuz-2.4.18-4smp \
253     --args="root=LABEL=foo"
254     liloTest lilo.1 updargs/l1.3 --update-kernel=DEFAULT --args="foo"
255     liloTest lilo.1 updargs/l1.4 --update-kernel=ALL --args="foo bar root=/dev/md1"
256     liloTest lilo.1 updargs/l1.4 --update-kernel=ALL --args="foo root=/dev/md1 bar"
257     liloTest lilo.1 updargs/l1.6 --update-kernel=ALL --args="foo root=LABEL=/ bar"
258     liloTest lilo.3 updargs/l3.1 --update-kernel=/boot/vmlinuz-2.4.18-4 \
259     --remove-args="hda"
260     liloTest lilo.3 updargs/l3.2 --update-kernel=ALL \
261     --remove-args="single" --args "root=/dev/hda2"
262    
263 niro 1308 testing="LILO add kernel"
264 niro 532 liloTest lilo.4 add/l4.1 --add-kernel=/boot/new-kernel.img --title="title" \
265     --copy-default --boot-filesystem=/boot
266     liloTest lilo.4 add/l4.2 --add-kernel=/boot/new-kernel.img --title="linux" \
267     --copy-default --boot-filesystem=/boot --remove-kernel "TITLE=linux"
268     liloTest lilo.5 add/l5.1 --add-kernel=/boot/new-kernel.img --title="title" \
269     --copy-default --boot-filesystem=/boot
270     liloTest lilo.5 add/l5.2 --add-kernel=/boot/new-kernel.img --title="linux" \
271     --copy-default --boot-filesystem=/boot --remove-kernel "TITLE=linux"
272     liloTest lilo.6 add/l6.1 --add-kernel=/boot/new-kernel.img --title="title" \
273     --initrd=/boot/new-initrd --copy-default --boot-filesystem=/boot
274     liloTest lilo.6 add/l6.2 --add-kernel=/boot/new-kernel.img --title="linux" \
275     --initrd=/boot/new-initrd --copy-default --boot-filesystem=/boot --remove-kernel "TITLE=linux"
276    
277    
278 niro 1308 testing="GRUB add kernel"
279 niro 532 grubTest grub.1 add/g1.1 --add-kernel=/boot/new-kernel.img --title='title' \
280     --initrd=/boot/new-initrd --boot-filesystem=/
281     grubTest grub.1 add/g1.2 --add-kernel=/boot/new-kernel.img --title='title' \
282     --initrd=/boot/new-initrd --boot-filesystem=/boot
283     grubTest grub.1 add/g1.3 --add-kernel=/boot/new-kernel.img --title='title' \
284     --initrd=/boot/new-initrd --boot-filesystem=/ --copy-default
285     grubTest grub.1 add/g1.4 --add-kernel=/boot/new-kernel.img --title='title' \
286     --initrd=/boot/new-initrd --boot-filesystem=/boot --copy-default
287 niro 1308 grubTest grub.1 add/g1.5 --add-kernel=/boot/new-kernel.img --title='title' \
288     --initrd=/boot/new-initrd --extra-initrd=/boot/extra-initrd --boot-filesystem=/
289     grubTest grub.1 add/g1.6 --add-kernel=/boot/new-kernel.img --title='title' \
290     --initrd=/boot/new-initrd --extra-initrd=/boot/extra-initrd --boot-filesystem=/boot
291 niro 532 grubTest grub.2 add/g2.1 --add-kernel=/boot/vmlinuz-2.4.7-2 \
292     --initrd=/boot/initrd-2.4.7-new.img --boot-filesystem=/boot --copy-default \
293     --title="Red Hat Linux (2.4.7-2)" \
294     --remove-kernel="TITLE=Red Hat Linux (2.4.7-2)"
295     grubTest grub.8 add/g8.1 --add-kernel=/boot/new-kernel.img --title='title' \
296     --initrd=/boot/new-initrd --boot-filesystem=/boot --copy-default
297     grubTest grub.8 add/g8.2 --add-kernel=/boot/new-kernel.img --title='title' \
298     --initrd=/boot/new-initrd --boot-filesystem=/boot --copy-default \
299     --args='console=tty0 console=ttyS1,9600n81 single'
300     grubTest grub.11 add/g11.1 --add-kernel=/boot/new-kernel.img --title='title' \
301     --initrd=/boot/new-initrd --boot-filesystem=/boot --copy-default \
302     --args='console=tty0 console=ttyS1,9600n81 single'
303    
304 niro 1308 testing="YABOOT add kernel"
305 niro 532 yabootTest yaboot.1 add/y1.1 --copy-default --boot-filesystem=/ --add-kernel=/boot/new-kernel \
306     --title=newtitle
307     yabootTest yaboot.1 add/y1.2 --add-kernel=/boot/new-kernel --boot-filesystem=/ --title=newtitle
308    
309 niro 1308 testing="YABOOT empty label"
310 niro 532 yabootTest yaboot.3 add/y3.1 --add-kernel=/boot/new-kernel --boot-filesystem=/ --title=newtitle
311    
312 niro 1308 testing="Z/IPL add kernel"
313 niro 532 ziplTest zipl.1 add/z1.1 --add-kernel=/boot/new-kernel.img --title test
314     ziplTest zipl.1 add/z1.2 --add-kernel=/boot/new-kernel.img --title test --copy-default
315    
316 niro 1308 testing="LILO long titles"
317 niro 532 liloTest lilo.1 longtitle/l1.1 --add-kernel=/boot/new-kernel.img \
318     --title="linux-longtitle" --copy-default --boot-filesystem=/boot
319     liloTest lilo.1 longtitle/l1.2 --add-kernel=/boot/new-kernel.img \
320     --title="linux-toolongtitle" --copy-default --boot-filesystem=/boot
321     liloTest lilo.7 longtitle/l7.1 --add-kernel=/boot/new-kernel.img \
322     --title="linux-longtitle-fix" --copy-default --boot-filesystem=/boot
323    
324 niro 1308 testing="ELILO long titles"
325 niro 532 eliloTest lilo.7 longtitle/e7.1 --add-kernel=/boot/new-kernel.img \
326     --title="linux-longtitle-fix" --copy-default --boot-filesystem=/boot
327    
328 niro 1308 testing="GRUB add multiboot"
329 niro 532 grubTest grub.1 multiboot/g1.1 --add-multiboot=/boot/xen.gz \
330     --add-kernel=/boot/vmlinuz-2.6.10-1.1088_FC4 --boot-filesystem=/boot \
331     --initrd=/boot/initrd-2.6.10-1.1088_FC4.img --title foo \
332     --mbargs="dom0_mem=130000"
333     grubTest grub.1 multiboot/g1.2 --add-multiboot=/boot/xen.gz \
334     --add-kernel=/boot/vmlinuz-2.6.10-1.1088_FC4 --boot-filesystem=/boot \
335     --initrd=/boot/initrd-2.6.10-1.1088_FC4.img --title foo \
336     --mbargs="dom0_mem=130000" --copy-default
337     grubTest grub.10 multiboot/g10.1 --add-multiboot=/boot/xen.gz \
338     --add-kernel=/boot/vmlinuz-2.6.10-1.1088_FC4 --boot-filesystem=/boot \
339     --initrd=/boot/initrd-2.6.10-1.1088_FC4.img --title foo \
340     --mbargs="dom0_mem=130000"
341     grubTest grub.10 multiboot/g10.2 --add-multiboot=/boot/xen.gz \
342     --add-kernel=/boot/vmlinuz-2.6.10-1.1088_FC4 --boot-filesystem=/boot \
343     --initrd=/boot/initrd-2.6.10-1.1088_FC4.img --title foo \
344     --mbargs="dom0_mem=130000" --copy-default
345     grubTest grub.10 multiboot/g10.3 --add-kernel=/boot/vmlinuz-2.6.10-1.1088_FC4 \
346     --initrd=/boot/initrd-2.6.10-1.1088_FC4.img --title foo \
347     --copy-default --boot-filesystem=/boot
348     grubTest grub.10 multiboot/g10.4 --add-kernel=/boot/vmlinuz-2.6.10-1.1088_FC4 \
349     --initrd=/boot/initrd-2.6.10-1.1088_FC4.img --title foo \
350     --boot-filesystem=/boot
351    
352 niro 1308 testing="GRUB remove multiboot"
353 niro 532 grubTest grub.10 multiboot/g10.5 --boot-filesystem=/boot \
354     --remove-kernel=/boot/vmlinuz-2.6.10-1.1076_FC4
355     grubTest grub.10 multiboot/g10.6 --boot-filesystem=/boot \
356     --remove-kernel=/boot/vmlinuz-2.6.10-1.1082_FC4
357     grubTest grub.10 multiboot/g10.7 --boot-filesystem=/boot \
358     --remove-multiboot=/boot/xen.gz
359    
360 niro 1308 testing="ELILO add multiboot"
361     eliloTest elilo.1 multiboot/e1.1 --add-multiboot=/boot/xen.gz \
362     --add-kernel=/boot/vmlinuz-2.6.10-1.1088_FC4 --boot-filesystem=/boot \
363     --initrd=/boot/initrd-2.6.10-1.1088_FC4.img --title foo \
364     --mbargs="dom0_mem=130000"
365     eliloTest elilo.1 multiboot/e1.2 --add-multiboot=/boot/xen.gz \
366     --add-kernel=/boot/vmlinuz-2.6.10-1.1088_FC4 --boot-filesystem=/boot \
367     --initrd=/boot/initrd-2.6.10-1.1088_FC4.img --title foo \
368     --mbargs="dom0_mem=130000" --copy-default
369    
370     testing="ELILO remove multiboot"
371     eliloTest elilo.2 multiboot/e2.1 --boot-filesystem=/boot \
372     --remove-kernel=/boot/vmlinuz-2.6.10-1.1076_FC4
373     eliloTest elilo.2 multiboot/e2.2 --boot-filesystem=/boot \
374     --remove-kernel=/boot/vmlinuz-2.6.10-1.1082_FC4
375     eliloTest elilo.2 multiboot/e2.3 --boot-filesystem=/boot \
376     --remove-multiboot=/boot/xen.gz
377    
378     printf "\n%d (%d%%) tests passed, %d (%d%%) tests failed\n" \
379     $pass $(((100*pass)/(pass+fail))) \
380     $fail $(((100*fail)/(pass+fail)))
381    
382     exit $(( !!fail ))

Properties

Name Value
svn:executable *