Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tools: bootconfig: Add bootconfig test script

Add a bootconfig test script to ensure the tool and
boot config parser are working correctly.

Link: http://lkml.kernel.org/r/157867224728.17873.18114241801246589416.stgit@devnote2

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>

authored by

Masami Hiramatsu and committed by
Steven Rostedt (VMware)
081c6536 950313eb

+176
+3
tools/bootconfig/Makefile
··· 16 16 install: $(PROGS) 17 17 install bootconfig $(DESTDIR)$(bindir) 18 18 19 + test: bootconfig 20 + ./test-bootconfig.sh 21 + 19 22 clean: 20 23 $(RM) -f *.o bootconfig
+5
tools/bootconfig/samples/bad-array-space-comment.bconf
··· 1 + key = # comment 2 + "value1", # comment1 3 + "value2" # comment2 4 + , 5 + "value3"
+2
tools/bootconfig/samples/bad-array.bconf
··· 1 + # Array must be comma separated. 2 + key = "value1" "value2"
+4
tools/bootconfig/samples/bad-dotword.bconf
··· 1 + # do not start keyword with . 2 + key { 3 + .word = 1 4 + }
+1
tools/bootconfig/samples/bad-empty.bconf
··· 1 + # Wrong boot config: comment only
+2
tools/bootconfig/samples/bad-keyerror.bconf
··· 1 + # key word can not contain "," 2 + key,word
+1
tools/bootconfig/samples/bad-longkey.bconf
··· 1 + key_word_is_too_long01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345
+1
tools/bootconfig/samples/bad-manywords.bconf
··· 1 + key1.is2.too3.long4.5.6.7.8.9.10.11.12.13.14.15.16.17
+2
tools/bootconfig/samples/bad-no-keyword.bconf
··· 1 + # No keyword 2 + {}
+2
tools/bootconfig/samples/bad-nonprintable.bconf
··· 1 + # Non printable 2 + key = ""
+2
tools/bootconfig/samples/bad-spaceword.bconf
··· 1 + # No space between words 2 + key . word
+5
tools/bootconfig/samples/bad-tree.bconf
··· 1 + # brace is not closing 2 + tree { 3 + node { 4 + value = 1 5 + }
+3
tools/bootconfig/samples/bad-value.bconf
··· 1 + # Quotes error 2 + value = "data 3 +
+3
tools/bootconfig/samples/escaped.bconf
··· 1 + key1 = "A\B\C" 2 + key2 = '\'\'' 3 + key3 = "\\"
+4
tools/bootconfig/samples/good-array-space-comment.bconf
··· 1 + key = # comment 2 + "value1", # comment1 3 + "value2" , # comment2 4 + "value3"
+1
tools/bootconfig/samples/good-comment-after-value.bconf
··· 1 + key = "value" # comment
+2
tools/bootconfig/samples/good-printables.bconf
··· 1 + key = " 2 + !#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
+11
tools/bootconfig/samples/good-simple.bconf
··· 1 + # A good simple bootconfig 2 + 3 + key.word1 = 1 4 + key.word2=2 5 + key.word3 = 3; 6 + 7 + key { 8 + word4 = 4 } 9 + 10 + key { word5 = 5; word6 = 6 } 11 +
+4
tools/bootconfig/samples/good-single.bconf
··· 1 + # single key style 2 + key = 1 3 + key2 = 2 4 + key3 = "alpha", "beta"
+1
tools/bootconfig/samples/good-space-after-value.bconf
··· 1 + key = "value"
+12
tools/bootconfig/samples/good-tree.bconf
··· 1 + key { 2 + word { 3 + tree { 4 + value = "0"} 5 + } 6 + word2 { 7 + tree { 8 + value = 1,2 } 9 + } 10 + } 11 + other.tree { 12 + value = 2; value2 = 3;}
+105
tools/bootconfig/test-bootconfig.sh
··· 1 + #!/bin/sh 2 + # SPDX-License-Identifier: GPL-2.0-only 3 + 4 + echo "Boot config test script" 5 + 6 + BOOTCONF=./bootconfig 7 + INITRD=`mktemp initrd-XXXX` 8 + TEMPCONF=`mktemp temp-XXXX.bconf` 9 + NG=0 10 + 11 + cleanup() { 12 + rm -f $INITRD $TEMPCONF 13 + exit $NG 14 + } 15 + 16 + trap cleanup EXIT TERM 17 + 18 + NO=1 19 + 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)) 24 + fi 25 + NO=$((NO + 1)) 26 + } 27 + 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)) 32 + fi 33 + NO=$((NO + 1)) 34 + } 35 + 36 + echo "Basic command test" 37 + xpass $BOOTCONF $INITRD 38 + 39 + echo "Delete command should success without bootconfig" 40 + xpass $BOOTCONF -d $INITRD 41 + 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) 46 + 47 + echo "Apply command test" 48 + xpass $BOOTCONF -a $TEMPCONF $INITRD 49 + new_size=$(stat -c %s $INITRD) 50 + 51 + echo "File size check" 52 + xpass test $new_size -eq $(expr $bconf_size + $initrd_size + 9) 53 + 54 + echo "Apply command repeat test" 55 + xpass $BOOTCONF -a $TEMPCONF $INITRD 56 + 57 + echo "File size check" 58 + xpass test $new_size -eq $(stat -c %s $INITRD) 59 + 60 + echo "Delete command check" 61 + xpass $BOOTCONF -d $INITRD 62 + 63 + echo "File size check" 64 + new_size=$(stat -c %s $INITRD) 65 + xpass test $new_size -eq $initrd_size 66 + 67 + echo "Max node number check" 68 + 69 + echo -n > $TEMPCONF 70 + for i in `seq 1 1024` ; do 71 + echo "node$i" >> $TEMPCONF 72 + done 73 + xpass $BOOTCONF -a $TEMPCONF $INITRD 74 + 75 + echo "badnode" >> $TEMPCONF 76 + xfail $BOOTCONF -a $TEMPCONF $INITRD 77 + 78 + echo "Max filesize check" 79 + 80 + # Max size is 32767 (including terminal byte) 81 + echo -n "data = \"" > $TEMPCONF 82 + dd if=/dev/urandom bs=768 count=32 | base64 -w0 >> $TEMPCONF 83 + echo "\"" >> $TEMPCONF 84 + xfail $BOOTCONF -a $TEMPCONF $INITRD 85 + 86 + truncate -s 32764 $TEMPCONF 87 + echo "\"" >> $TEMPCONF # add 2 bytes + terminal ('\"\n\0') 88 + xpass $BOOTCONF -a $TEMPCONF $INITRD 89 + 90 + echo "=== expected failure cases ===" 91 + for i in samples/bad-* ; do 92 + xfail $BOOTCONF -a $i $INITRD 93 + done 94 + 95 + echo "=== expected success cases ===" 96 + for i in samples/good-* ; do 97 + xpass $BOOTCONF -a $i $INITRD 98 + done 99 + 100 + echo 101 + if [ $NG -eq 0 ]; then 102 + echo "All tests passed" 103 + else 104 + echo "$NG tests failed" 105 + fi