mirror of https://gitee.com/openkylin/linux.git
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>
This commit is contained in:
parent
950313ebf7
commit
081c65360b
|
@ -16,5 +16,8 @@ bootconfig: ../../lib/bootconfig.c main.c $(HEADER)
|
|||
install: $(PROGS)
|
||||
install bootconfig $(DESTDIR)$(bindir)
|
||||
|
||||
test: bootconfig
|
||||
./test-bootconfig.sh
|
||||
|
||||
clean:
|
||||
$(RM) -f *.o bootconfig
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
key = # comment
|
||||
"value1", # comment1
|
||||
"value2" # comment2
|
||||
,
|
||||
"value3"
|
|
@ -0,0 +1,2 @@
|
|||
# Array must be comma separated.
|
||||
key = "value1" "value2"
|
|
@ -0,0 +1,4 @@
|
|||
# do not start keyword with .
|
||||
key {
|
||||
.word = 1
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
# Wrong boot config: comment only
|
|
@ -0,0 +1,2 @@
|
|||
# key word can not contain ","
|
||||
key,word
|
|
@ -0,0 +1 @@
|
|||
key_word_is_too_long01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345
|
|
@ -0,0 +1 @@
|
|||
key1.is2.too3.long4.5.6.7.8.9.10.11.12.13.14.15.16.17
|
|
@ -0,0 +1,2 @@
|
|||
# No keyword
|
||||
{}
|
|
@ -0,0 +1,2 @@
|
|||
# Non printable
|
||||
key = ""
|
|
@ -0,0 +1,2 @@
|
|||
# No space between words
|
||||
key . word
|
|
@ -0,0 +1,5 @@
|
|||
# brace is not closing
|
||||
tree {
|
||||
node {
|
||||
value = 1
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
# Quotes error
|
||||
value = "data
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
key1 = "A\B\C"
|
||||
key2 = '\'\''
|
||||
key3 = "\\"
|
|
@ -0,0 +1,4 @@
|
|||
key = # comment
|
||||
"value1", # comment1
|
||||
"value2" , # comment2
|
||||
"value3"
|
|
@ -0,0 +1 @@
|
|||
key = "value" # comment
|
|
@ -0,0 +1,2 @@
|
|||
key = "
|
||||
!#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
|
|
@ -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 }
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
# single key style
|
||||
key = 1
|
||||
key2 = 2
|
||||
key3 = "alpha", "beta"
|
|
@ -0,0 +1 @@
|
|||
key = "value"
|
|
@ -0,0 +1,12 @@
|
|||
key {
|
||||
word {
|
||||
tree {
|
||||
value = "0"}
|
||||
}
|
||||
word2 {
|
||||
tree {
|
||||
value = 1,2 }
|
||||
}
|
||||
}
|
||||
other.tree {
|
||||
value = 2; value2 = 3;}
|
|
@ -0,0 +1,105 @@
|
|||
#!/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 ($3)... "
|
||||
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 ($3)... "
|
||||
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
|
||||
|
||||
dd if=/dev/zero of=$INITRD bs=4096 count=1
|
||||
echo "key = value;" > $TEMPCONF
|
||||
bconf_size=$(stat -c %s $TEMPCONF)
|
||||
initrd_size=$(stat -c %s $INITRD)
|
||||
|
||||
echo "Apply command test"
|
||||
xpass $BOOTCONF -a $TEMPCONF $INITRD
|
||||
new_size=$(stat -c %s $INITRD)
|
||||
|
||||
echo "File size check"
|
||||
xpass test $new_size -eq $(expr $bconf_size + $initrd_size + 9)
|
||||
|
||||
echo "Apply command repeat test"
|
||||
xpass $BOOTCONF -a $TEMPCONF $INITRD
|
||||
|
||||
echo "File size check"
|
||||
xpass test $new_size -eq $(stat -c %s $INITRD)
|
||||
|
||||
echo "Delete command check"
|
||||
xpass $BOOTCONF -d $INITRD
|
||||
|
||||
echo "File size check"
|
||||
new_size=$(stat -c %s $INITRD)
|
||||
xpass test $new_size -eq $initrd_size
|
||||
|
||||
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
|
Loading…
Reference in New Issue