Linux 5.6.12
[linux/fpc-iii.git] / tools / bootconfig / test-bootconfig.sh
blob1411f4c3454fbdb55cb1e290f71fc9849fa931ce
1 #!/bin/sh
2 # SPDX-License-Identifier: GPL-2.0-only
4 echo "Boot config test script"
6 BOOTCONF=./bootconfig
7 INITRD=`mktemp initrd-XXXX`
8 TEMPCONF=`mktemp temp-XXXX.bconf`
9 NG=0
11 cleanup() {
12 rm -f $INITRD $TEMPCONF $OUTFILE
13 exit $NG
16 trap cleanup EXIT TERM
18 NO=1
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))
25 NO=$((NO + 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))
33 NO=$((NO + 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 + 12)
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 "No error messge while applying"
68 OUTFILE=`mktemp tempout-XXXX`
69 dd if=/dev/zero of=$INITRD bs=4096 count=1
70 printf " \0\0\0 \0\0\0" >> $INITRD
71 $BOOTCONF -a $TEMPCONF $INITRD > $OUTFILE 2>&1
72 xfail grep -i "failed" $OUTFILE
73 xfail grep -i "error" $OUTFILE
75 echo "Max node number check"
77 echo -n > $TEMPCONF
78 for i in `seq 1 1024` ; do
79 echo "node$i" >> $TEMPCONF
80 done
81 xpass $BOOTCONF -a $TEMPCONF $INITRD
83 echo "badnode" >> $TEMPCONF
84 xfail $BOOTCONF -a $TEMPCONF $INITRD
86 echo "Max filesize check"
88 # Max size is 32767 (including terminal byte)
89 echo -n "data = \"" > $TEMPCONF
90 dd if=/dev/urandom bs=768 count=32 | base64 -w0 >> $TEMPCONF
91 echo "\"" >> $TEMPCONF
92 xfail $BOOTCONF -a $TEMPCONF $INITRD
94 truncate -s 32764 $TEMPCONF
95 echo "\"" >> $TEMPCONF # add 2 bytes + terminal ('\"\n\0')
96 xpass $BOOTCONF -a $TEMPCONF $INITRD
98 echo "Adding same-key values"
99 cat > $TEMPCONF << EOF
100 key = bar, baz
101 key += qux
103 echo > $INITRD
105 xpass $BOOTCONF -a $TEMPCONF $INITRD
106 $BOOTCONF $INITRD > $OUTFILE
107 xpass grep -q "bar" $OUTFILE
108 xpass grep -q "baz" $OUTFILE
109 xpass grep -q "qux" $OUTFILE
111 echo "=== expected failure cases ==="
112 for i in samples/bad-* ; do
113 xfail $BOOTCONF -a $i $INITRD
114 done
116 echo "=== expected success cases ==="
117 for i in samples/good-* ; do
118 xpass $BOOTCONF -a $i $INITRD
119 done
121 echo
122 if [ $NG -eq 0 ]; then
123 echo "All tests passed"
124 else
125 echo "$NG tests failed"