@@ -18,5 +18,8 @@ bootconfig: ../../lib/bootconfig.c main.c $(HEADER)
install: $(PROGS)
install bootconfig $(DESTDIR)$(bindir)
+test: bootconfig
+ ./test-bootconfig.sh
+
clean:
$(RM) -f *.o bootconfig
new file mode 100644
@@ -0,0 +1,4 @@
+# do not start keyword with .
+key {
+ .word = 1
+}
new file mode 100644
@@ -0,0 +1 @@
+# Wrong boot config: comment only
new file mode 100644
@@ -0,0 +1,2 @@
+# key word can not contain ","
+key,word
new file mode 100644
@@ -0,0 +1 @@
+key_word_is_too_long01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345
new file mode 100644
@@ -0,0 +1 @@
+key1.is2.too3.long4.5.6.7.8.9.10.11.12.13.14.15.16.17
new file mode 100644
@@ -0,0 +1,2 @@
+# No keyword
+{}
new file mode 100644
@@ -0,0 +1,2 @@
+# No space between words
+key . word
new file mode 100644
@@ -0,0 +1,5 @@
+# brace is not closing
+tree {
+ node {
+ value = 1
+}
new file mode 100644
@@ -0,0 +1,3 @@
+# Quotes error
+value = "data
+
new file mode 100644
@@ -0,0 +1,11 @@
+# A good simple bootconfig
+
+key.word1 = 1
+key.word2=2
+key.word3 = 3;
+
+key {
+word4 = 4 }
+
+key { word5 = 5; word6 = 6 }
+
new file mode 100644
@@ -0,0 +1,4 @@
+# single key style
+key = 1
+key2 = 2
+key3 = "alpha", "beta"
new file mode 100644
@@ -0,0 +1,15 @@
+key {
+ word {
+ tree {
+ value = "0"
+ }
+ }
+ word2 {
+ tree {
+ value = 1
+ }
+ }
+}
+other.tree {
+ value = 2; value2 = 3;
+}
new file mode 100755
@@ -0,0 +1,80 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-only
+
+echo "Boot config test script"
+
+BOOTCONF=./bootconfig
+INITRD=`mktemp initrd-XXXX`
+TEMPCONF=`mktemp temp-XXXX.bconf`
+NG=0
+
+cleanup() {
+ rm -f $INITRD $TEMPCONF
+ exit $NG
+}
+
+trap cleanup EXIT TERM
+
+NO=1
+
+xpass() { # pass test command
+ echo "test case $NO ... "
+ if ! ($* && echo "\t\t[OK]"); then
+ echo "\t\t[NG]"; NG=$((NG + 1))
+ fi
+ NO=$((NO + 1))
+}
+
+xfail() { # fail test command
+ echo "test case $NO ... "
+ if ! (! $* && echo "\t\t[OK]"); then
+ echo "\t\t[NG]"; NG=$((NG + 1))
+ fi
+ NO=$((NO + 1))
+}
+
+echo "Basic command test"
+xpass $BOOTCONF $INITRD
+
+echo "Delete command should success without bootconfig"
+xpass $BOOTCONF -d $INITRD
+
+echo "Max node number check"
+
+echo -n > $TEMPCONF
+for i in `seq 1 1024` ; do
+ echo "node$i" >> $TEMPCONF
+done
+xpass $BOOTCONF -a $TEMPCONF $INITRD
+
+echo "badnode" >> $TEMPCONF
+xfail $BOOTCONF -a $TEMPCONF $INITRD
+
+echo "Max filesize check"
+
+# Max size is 32767 (including terminal byte)
+echo -n "data = \"" > $TEMPCONF
+dd if=/dev/urandom bs=768 count=32 | base64 -w0 >> $TEMPCONF
+echo "\"" >> $TEMPCONF
+xfail $BOOTCONF -a $TEMPCONF $INITRD
+
+truncate -s 32764 $TEMPCONF
+echo "\"" >> $TEMPCONF # add 2 bytes + terminal ('\"\n\0')
+xpass $BOOTCONF -a $TEMPCONF $INITRD
+
+echo "=== expected failure cases ==="
+for i in samples/bad-* ; do
+xfail $BOOTCONF -a $i $INITRD
+done
+
+echo "=== expected success cases ==="
+for i in samples/good-* ; do
+xpass $BOOTCONF -a $i $INITRD
+done
+
+echo
+if [ $NG -eq 0 ]; then
+ echo "All tests passed"
+else
+ echo "$NG tests failed"
+fi
Add a bootconfig test script to ensure the tool and boot config parser are working correctly. Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org> --- tools/bootconfig/Makefile | 3 + tools/bootconfig/samples/bad-dotword.bconf | 4 + tools/bootconfig/samples/bad-empty.bconf | 1 tools/bootconfig/samples/bad-keyerror.bconf | 2 + tools/bootconfig/samples/bad-longkey.bconf | 1 tools/bootconfig/samples/bad-manywords.bconf | 1 tools/bootconfig/samples/bad-no-keyword.bconf | 2 + tools/bootconfig/samples/bad-spaceword.bconf | 2 + tools/bootconfig/samples/bad-tree.bconf | 5 ++ tools/bootconfig/samples/bad-value.bconf | 3 + tools/bootconfig/samples/good-simple.bconf | 11 +++ tools/bootconfig/samples/good-single.bconf | 4 + tools/bootconfig/samples/good-tree.bconf | 15 +++++ tools/bootconfig/test-bootconfig.sh | 80 +++++++++++++++++++++++++ 14 files changed, 134 insertions(+) create mode 100644 tools/bootconfig/samples/bad-dotword.bconf create mode 100644 tools/bootconfig/samples/bad-empty.bconf create mode 100644 tools/bootconfig/samples/bad-keyerror.bconf create mode 100644 tools/bootconfig/samples/bad-longkey.bconf create mode 100644 tools/bootconfig/samples/bad-manywords.bconf create mode 100644 tools/bootconfig/samples/bad-no-keyword.bconf create mode 100644 tools/bootconfig/samples/bad-spaceword.bconf create mode 100644 tools/bootconfig/samples/bad-tree.bconf create mode 100644 tools/bootconfig/samples/bad-value.bconf create mode 100644 tools/bootconfig/samples/good-simple.bconf create mode 100644 tools/bootconfig/samples/good-single.bconf create mode 100644 tools/bootconfig/samples/good-tree.bconf create mode 100755 tools/bootconfig/test-bootconfig.sh