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"
92 for (i = 0; i < 26; i += 1)
93 printf("%c\n", 65 + i % 26)
94 for (i = 26; i < 8192; i += 1)
95 printf("%c%c%c\n", 65 + i % 26, 65 + (i / 26) % 26, 65 + (i / 26 / 26))
98 xpass $BOOTCONF -a $TEMPCONF $INITRD
100 echo "badnode" >> $TEMPCONF
101 xfail $BOOTCONF -a $TEMPCONF $INITRD
103 echo "Max filesize check"
105 # Max size is 32767 (including terminal byte)
106 echo -n "data = \"" > $TEMPCONF
107 dd if=/dev/urandom bs=768 count=32 | base64 -w0 >> $TEMPCONF
108 echo "\"" >> $TEMPCONF
109 xfail $BOOTCONF -a $TEMPCONF $INITRD
111 truncate -s 32764 $TEMPCONF
112 echo "\"" >> $TEMPCONF # add 2 bytes + terminal ('\"\n\0')
113 xpass $BOOTCONF -a $TEMPCONF $INITRD
115 echo "Adding same-key values"
116 cat > $TEMPCONF << EOF
122 xpass $BOOTCONF -a $TEMPCONF $INITRD
123 $BOOTCONF $INITRD > $OUTFILE
124 xpass grep -q "bar" $OUTFILE
125 xpass grep -q "baz" $OUTFILE
126 xpass grep -q "qux" $OUTFILE
128 echo "Override same-key values"
129 cat > $TEMPCONF << EOF
135 xpass $BOOTCONF -a $TEMPCONF $INITRD
136 $BOOTCONF $INITRD > $OUTFILE
137 xfail grep -q "bar" $OUTFILE
138 xfail grep -q "baz" $OUTFILE
139 xpass grep -q "qux" $OUTFILE
141 echo "Double/single quotes test"
142 echo "key = '\"string\"';" > $TEMPCONF
143 $BOOTCONF -a $TEMPCONF $INITRD
144 $BOOTCONF $INITRD > $TEMPCONF
146 xpass grep \'\"string\"\' $TEMPCONF
148 echo "Repeat same-key tree"
149 cat > $TEMPCONF << EOF
156 xpass $BOOTCONF -a $TEMPCONF $INITRD
157 $BOOTCONF $INITRD > $OUTFILE
158 xpass grep -q "bar" $OUTFILE
161 echo "Remove/keep tailing spaces"
162 cat > $TEMPCONF << EOF
164 bar = "val2 " # comment
168 xpass $BOOTCONF -a $TEMPCONF $INITRD
169 $BOOTCONF $INITRD > $OUTFILE
170 xfail grep -q val[[:space:]] $OUTFILE
171 xpass grep -q val2[[:space:]] $OUTFILE
173 echo "=== expected failure cases ==="
174 for i in samples/bad-* ; do
175 xfail $BOOTCONF -a $i $INITRD
178 echo "=== expected success cases ==="
179 for i in samples/good-* ; do
180 xpass $BOOTCONF -a $i $INITRD
185 echo "=== Summary ==="
186 echo "# of Passed: $(expr $NO - $NG - 1)"
187 echo "# of Failed: $NG"
190 if [ $NG -eq 0 ]; then
191 echo "All tests passed"
193 echo "$NG tests failed"