2 # SPDX-License-Identifier: GPL-2.0-only
4 echo "Boot config test script"
11 BOOTCONF
=${TESTDIR}/bootconfig
13 INITRD
=`mktemp ${TESTDIR}/initrd-XXXX`
14 TEMPCONF
=`mktemp ${TESTDIR}/temp-XXXX.bconf`
15 OUTFILE
=`mktemp ${TESTDIR}/tempout-XXXX`
19 rm -f $INITRD $TEMPCONF $OUTFILE
23 trap cleanup EXIT TERM
27 xpass
() { # pass test command
28 echo "test case $NO ($3)... "
29 if ! ($@
&& echo "\t\t[OK]"); then
30 echo "\t\t[NG]"; NG
=$
((NG
+ 1))
35 xfail
() { # fail test command
36 echo "test case $NO ($3)... "
37 if ! (! $@
&& echo "\t\t[OK]"); then
38 echo "\t\t[NG]"; NG
=$
((NG
+ 1))
43 echo "Basic command test"
44 xpass
$BOOTCONF $INITRD
46 echo "Delete command should success without bootconfig"
47 xpass
$BOOTCONF -d $INITRD
49 dd if=/dev
/zero of
=$INITRD bs
=4096 count
=1
50 echo "key = value;" > $TEMPCONF
51 bconf_size
=$
(stat
-c %s
$TEMPCONF)
52 initrd_size
=$
(stat
-c %s
$INITRD)
54 echo "Apply command test"
55 xpass
$BOOTCONF -a $TEMPCONF $INITRD
56 new_size
=$
(stat
-c %s
$INITRD)
58 echo "Show command test"
59 xpass
$BOOTCONF $INITRD
61 echo "File size check"
62 xpass
test $new_size -eq $
(expr $bconf_size + $initrd_size + 9 + 12)
64 echo "Apply command repeat test"
65 xpass
$BOOTCONF -a $TEMPCONF $INITRD
67 echo "File size check"
68 xpass
test $new_size -eq $
(stat
-c %s
$INITRD)
70 echo "Delete command check"
71 xpass
$BOOTCONF -d $INITRD
73 echo "File size check"
74 new_size
=$
(stat
-c %s
$INITRD)
75 xpass
test $new_size -eq $initrd_size
77 echo "No error messge while applying"
78 dd if=/dev
/zero of
=$INITRD bs
=4096 count
=1
79 printf " \0\0\0 \0\0\0" >> $INITRD
80 $BOOTCONF -a $TEMPCONF $INITRD > $OUTFILE 2>&1
81 xfail
grep -i "failed" $OUTFILE
82 xfail
grep -i "error" $OUTFILE
84 echo "Max node number check"
87 for i
in `seq 1 1024` ; do
88 echo "node$i" >> $TEMPCONF
90 xpass
$BOOTCONF -a $TEMPCONF $INITRD
92 echo "badnode" >> $TEMPCONF
93 xfail
$BOOTCONF -a $TEMPCONF $INITRD
95 echo "Max filesize check"
97 # Max size is 32767 (including terminal byte)
98 echo -n "data = \"" > $TEMPCONF
99 dd if=/dev
/urandom bs
=768 count
=32 | base64
-w0 >> $TEMPCONF
100 echo "\"" >> $TEMPCONF
101 xfail
$BOOTCONF -a $TEMPCONF $INITRD
103 truncate
-s 32764 $TEMPCONF
104 echo "\"" >> $TEMPCONF # add 2 bytes + terminal ('\"\n\0')
105 xpass
$BOOTCONF -a $TEMPCONF $INITRD
107 echo "Adding same-key values"
108 cat > $TEMPCONF << EOF
114 xpass
$BOOTCONF -a $TEMPCONF $INITRD
115 $BOOTCONF $INITRD > $OUTFILE
116 xpass
grep -q "bar" $OUTFILE
117 xpass
grep -q "baz" $OUTFILE
118 xpass
grep -q "qux" $OUTFILE
120 echo "Double/single quotes test"
121 echo "key = '\"string\"';" > $TEMPCONF
122 $BOOTCONF -a $TEMPCONF $INITRD
123 $BOOTCONF $INITRD > $TEMPCONF
125 xpass
grep \'\"string
\"\' $TEMPCONF
127 echo "=== expected failure cases ==="
128 for i
in samples
/bad-
* ; do
129 xfail
$BOOTCONF -a $i $INITRD
132 echo "=== expected success cases ==="
133 for i
in samples
/good-
* ; do
134 xpass
$BOOTCONF -a $i $INITRD
139 echo "=== Summary ==="
140 echo "# of Passed: $(expr $NO - $NG - 1)"
141 echo "# of Failed: $NG"
144 if [ $NG -eq 0 ]; then
145 echo "All tests passed"
147 echo "$NG tests failed"