2 # SPDX-License-Identifier: GPL-2.0-only
4 echo "Boot config test script"
7 INITRD
=`mktemp initrd-XXXX`
8 TEMPCONF
=`mktemp temp-XXXX.bconf`
12 rm -f $INITRD $TEMPCONF
16 trap cleanup EXIT TERM
20 xpass
() { # pass test command
21 echo "test case $NO ($3)... "
22 if ! ($@
&& echo "\t\t[OK]"); then
23 echo "\t\t[NG]"; NG
=$
((NG
+ 1))
28 xfail
() { # fail test command
29 echo "test case $NO ($3)... "
30 if ! (! $@
&& echo "\t\t[OK]"); then
31 echo "\t\t[NG]"; NG
=$
((NG
+ 1))
36 echo "Basic command test"
37 xpass
$BOOTCONF $INITRD
39 echo "Delete command should success without bootconfig"
40 xpass
$BOOTCONF -d $INITRD
42 dd if=/dev
/zero of
=$INITRD bs
=4096 count
=1
43 echo "key = value;" > $TEMPCONF
44 bconf_size
=$
(stat
-c %s
$TEMPCONF)
45 initrd_size
=$
(stat
-c %s
$INITRD)
47 echo "Apply command test"
48 xpass
$BOOTCONF -a $TEMPCONF $INITRD
49 new_size
=$
(stat
-c %s
$INITRD)
51 echo "File size check"
52 xpass
test $new_size -eq $
(expr $bconf_size + $initrd_size + 9)
54 echo "Apply command repeat test"
55 xpass
$BOOTCONF -a $TEMPCONF $INITRD
57 echo "File size check"
58 xpass
test $new_size -eq $
(stat
-c %s
$INITRD)
60 echo "Delete command check"
61 xpass
$BOOTCONF -d $INITRD
63 echo "File size check"
64 new_size
=$
(stat
-c %s
$INITRD)
65 xpass
test $new_size -eq $initrd_size
67 echo "Max node number check"
70 for i
in `seq 1 1024` ; do
71 echo "node$i" >> $TEMPCONF
73 xpass
$BOOTCONF -a $TEMPCONF $INITRD
75 echo "badnode" >> $TEMPCONF
76 xfail
$BOOTCONF -a $TEMPCONF $INITRD
78 echo "Max filesize check"
80 # Max size is 32767 (including terminal byte)
81 echo -n "data = \"" > $TEMPCONF
82 dd if=/dev
/urandom bs
=768 count
=32 | base64
-w0 >> $TEMPCONF
83 echo "\"" >> $TEMPCONF
84 xfail
$BOOTCONF -a $TEMPCONF $INITRD
86 truncate
-s 32764 $TEMPCONF
87 echo "\"" >> $TEMPCONF # add 2 bytes + terminal ('\"\n\0')
88 xpass
$BOOTCONF -a $TEMPCONF $INITRD
90 echo "=== expected failure cases ==="
91 for i
in samples
/bad-
* ; do
92 xfail
$BOOTCONF -a $i $INITRD
95 echo "=== expected success cases ==="
96 for i
in samples
/good-
* ; do
97 xpass
$BOOTCONF -a $i $INITRD
101 if [ $NG -eq 0 ]; then
102 echo "All tests passed"
104 echo "$NG tests failed"