2 # SPDX-License-Identifier: GPL-2.0-only
4 echo "Boot config test script"
11 BOOTCONF=${TESTDIR}/bootconfig
14 INITRD=`mktemp ${TESTDIR}/initrd-XXXX`
15 TEMPCONF=`mktemp ${TESTDIR}/temp-XXXX.bconf`
16 OUTFILE=`mktemp ${TESTDIR}/tempout-XXXX`
20 rm -f $INITRD $TEMPCONF $OUTFILE
24 trap cleanup EXIT TERM
28 xpass() { # pass test command
29 echo "test case $NO ($*)... "
30 if ! ($@ && echo "\t\t[OK]"); then
31 echo "\t\t[NG]"; NG=$((NG + 1))
36 xfail() { # fail test command
37 echo "test case $NO ($*)... "
38 if ! (! $@ && echo "\t\t[OK]"); then
39 echo "\t\t[NG]"; NG=$((NG + 1))
44 echo "Basic command test"
45 xpass $BOOTCONF $INITRD
47 echo "Delete command should success without bootconfig"
48 xpass $BOOTCONF -d $INITRD
50 dd if=/dev/zero of=$INITRD bs=4096 count=1
51 echo "key = value;" > $TEMPCONF
52 bconf_size=$(stat -c %s $TEMPCONF)
53 initrd_size=$(stat -c %s $INITRD)
55 echo "Apply command test"
56 xpass $BOOTCONF -a $TEMPCONF $INITRD
57 new_size=$(stat -c %s $INITRD)
59 echo "Show command test"
60 xpass $BOOTCONF $INITRD
62 echo "File size check"
63 total_size=$(expr $bconf_size + $initrd_size + 9 + 12 + $ALIGN - 1 )
64 total_size=$(expr $total_size / $ALIGN)
65 total_size=$(expr $total_size \* $ALIGN)
66 xpass test $new_size -eq $total_size
68 echo "Apply command repeat test"
69 xpass $BOOTCONF -a $TEMPCONF $INITRD
71 echo "File size check"
72 xpass test $new_size -eq $(stat -c %s $INITRD)
74 echo "Delete command check"
75 xpass $BOOTCONF -d $INITRD
77 echo "File size check"
78 new_size=$(stat -c %s $INITRD)
79 xpass test $new_size -eq $initrd_size
81 echo "No error messge while applying"
82 dd if=/dev/zero of=$INITRD bs=4096 count=1
83 printf " \0\0\0 \0\0\0" >> $INITRD
84 $BOOTCONF -a $TEMPCONF $INITRD > $OUTFILE 2>&1
85 xfail grep -i "failed" $OUTFILE
86 xfail grep -i "error" $OUTFILE
88 echo "Max node number check"
91 for i in `seq 1 1024` ; do
92 echo "node$i" >> $TEMPCONF
94 xpass $BOOTCONF -a $TEMPCONF $INITRD
96 echo "badnode" >> $TEMPCONF
97 xfail $BOOTCONF -a $TEMPCONF $INITRD
99 echo "Max filesize check"
101 # Max size is 32767 (including terminal byte)
102 echo -n "data = \"" > $TEMPCONF
103 dd if=/dev/urandom bs=768 count=32 | base64 -w0 >> $TEMPCONF
104 echo "\"" >> $TEMPCONF
105 xfail $BOOTCONF -a $TEMPCONF $INITRD
107 truncate -s 32764 $TEMPCONF
108 echo "\"" >> $TEMPCONF # add 2 bytes + terminal ('\"\n\0')
109 xpass $BOOTCONF -a $TEMPCONF $INITRD
111 echo "Adding same-key values"
112 cat > $TEMPCONF << EOF
118 xpass $BOOTCONF -a $TEMPCONF $INITRD
119 $BOOTCONF $INITRD > $OUTFILE
120 xpass grep -q "bar" $OUTFILE
121 xpass grep -q "baz" $OUTFILE
122 xpass grep -q "qux" $OUTFILE
124 echo "Override same-key values"
125 cat > $TEMPCONF << EOF
131 xpass $BOOTCONF -a $TEMPCONF $INITRD
132 $BOOTCONF $INITRD > $OUTFILE
133 xfail grep -q "bar" $OUTFILE
134 xfail grep -q "baz" $OUTFILE
135 xpass grep -q "qux" $OUTFILE
137 echo "Double/single quotes test"
138 echo "key = '\"string\"';" > $TEMPCONF
139 $BOOTCONF -a $TEMPCONF $INITRD
140 $BOOTCONF $INITRD > $TEMPCONF
142 xpass grep \'\"string\"\' $TEMPCONF
144 echo "Repeat same-key tree"
145 cat > $TEMPCONF << EOF
152 xpass $BOOTCONF -a $TEMPCONF $INITRD
153 $BOOTCONF $INITRD > $OUTFILE
154 xpass grep -q "bar" $OUTFILE
157 echo "Remove/keep tailing spaces"
158 cat > $TEMPCONF << EOF
160 bar = "val2 " # comment
164 xpass $BOOTCONF -a $TEMPCONF $INITRD
165 $BOOTCONF $INITRD > $OUTFILE
166 xfail grep -q val[[:space:]] $OUTFILE
167 xpass grep -q val2[[:space:]] $OUTFILE
169 echo "=== expected failure cases ==="
170 for i in samples/bad-* ; do
171 xfail $BOOTCONF -a $i $INITRD
174 echo "=== expected success cases ==="
175 for i in samples/good-* ; do
176 xpass $BOOTCONF -a $i $INITRD
181 echo "=== Summary ==="
182 echo "# of Passed: $(expr $NO - $NG - 1)"
183 echo "# of Failed: $NG"
186 if [ $NG -eq 0 ]; then
187 echo "All tests passed"
189 echo "$NG tests failed"