Merge tag 'ntb-5.11' of git://github.com/jonmason/ntb
[linux/fpc-iii.git] / tools / bootconfig / test-bootconfig.sh
blobbaed891d0ba4969a9b13fbe335898fee8661a0c1
1 #!/bin/sh
2 # SPDX-License-Identifier: GPL-2.0-only
4 echo "Boot config test script"
6 if [ -d "$1" ]; then
7 TESTDIR=$1
8 else
9 TESTDIR=.
11 BOOTCONF=${TESTDIR}/bootconfig
12 ALIGN=4
14 INITRD=`mktemp ${TESTDIR}/initrd-XXXX`
15 TEMPCONF=`mktemp ${TESTDIR}/temp-XXXX.bconf`
16 OUTFILE=`mktemp ${TESTDIR}/tempout-XXXX`
17 NG=0
19 cleanup() {
20 rm -f $INITRD $TEMPCONF $OUTFILE
21 exit $NG
24 trap cleanup EXIT TERM
26 NO=1
28 xpass() { # pass test command
29 echo "test case $NO ($3)... "
30 if ! ($@ && echo "\t\t[OK]"); then
31 echo "\t\t[NG]"; NG=$((NG + 1))
33 NO=$((NO + 1))
36 xfail() { # fail test command
37 echo "test case $NO ($3)... "
38 if ! (! $@ && echo "\t\t[OK]"); then
39 echo "\t\t[NG]"; NG=$((NG + 1))
41 NO=$((NO + 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"
90 echo -n > $TEMPCONF
91 for i in `seq 1 1024` ; do
92 echo "node$i" >> $TEMPCONF
93 done
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
113 key = bar, baz
114 key += qux
116 echo > $INITRD
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
126 key = bar, baz
127 key := qux
129 echo > $INITRD
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
141 cat $TEMPCONF
142 xpass grep \'\"string\"\' $TEMPCONF
144 echo "Repeat same-key tree"
145 cat > $TEMPCONF << EOF
148 foo { buz }
150 echo > $INITRD
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
159 foo = val # comment
160 bar = "val2 " # comment
162 echo > $INITRD
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
172 done
174 echo "=== expected success cases ==="
175 for i in samples/good-* ; do
176 xpass $BOOTCONF -a $i $INITRD
177 done
180 echo
181 echo "=== Summary ==="
182 echo "# of Passed: $(expr $NO - $NG - 1)"
183 echo "# of Failed: $NG"
185 echo
186 if [ $NG -eq 0 ]; then
187 echo "All tests passed"
188 else
189 echo "$NG tests failed"
190 exit 1