2020-01-11 00:04:07 +08:00
|
|
|
#!/bin/sh
|
|
|
|
# SPDX-License-Identifier: GPL-2.0-only
|
|
|
|
|
|
|
|
echo "Boot config test script"
|
|
|
|
|
2020-03-03 19:24:40 +08:00
|
|
|
if [ -d "$1" ]; then
|
|
|
|
TESTDIR=$1
|
|
|
|
else
|
|
|
|
TESTDIR=.
|
|
|
|
fi
|
|
|
|
BOOTCONF=${TESTDIR}/bootconfig
|
2020-11-19 13:53:40 +08:00
|
|
|
ALIGN=4
|
2020-03-03 19:24:40 +08:00
|
|
|
|
|
|
|
INITRD=`mktemp ${TESTDIR}/initrd-XXXX`
|
|
|
|
TEMPCONF=`mktemp ${TESTDIR}/temp-XXXX.bconf`
|
|
|
|
OUTFILE=`mktemp ${TESTDIR}/tempout-XXXX`
|
2020-01-11 00:04:07 +08:00
|
|
|
NG=0
|
|
|
|
|
|
|
|
cleanup() {
|
2020-02-21 16:13:52 +08:00
|
|
|
rm -f $INITRD $TEMPCONF $OUTFILE
|
2020-01-11 00:04:07 +08:00
|
|
|
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)
|
|
|
|
|
2020-06-16 18:14:34 +08:00
|
|
|
echo "Show command test"
|
|
|
|
xpass $BOOTCONF $INITRD
|
|
|
|
|
2020-01-11 00:04:07 +08:00
|
|
|
echo "File size check"
|
2020-11-19 13:53:40 +08:00
|
|
|
total_size=$(expr $bconf_size + $initrd_size + 9 + 12 + $ALIGN - 1 )
|
|
|
|
total_size=$(expr $total_size / $ALIGN)
|
|
|
|
total_size=$(expr $total_size \* $ALIGN)
|
|
|
|
xpass test $new_size -eq $total_size
|
2020-01-11 00:04:07 +08:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2020-02-09 21:05:13 +08:00
|
|
|
echo "No error messge while applying"
|
|
|
|
dd if=/dev/zero of=$INITRD bs=4096 count=1
|
|
|
|
printf " \0\0\0 \0\0\0" >> $INITRD
|
|
|
|
$BOOTCONF -a $TEMPCONF $INITRD > $OUTFILE 2>&1
|
|
|
|
xfail grep -i "failed" $OUTFILE
|
|
|
|
xfail grep -i "error" $OUTFILE
|
|
|
|
|
2020-01-11 00:04:07 +08:00
|
|
|
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
|
|
|
|
|
2020-02-21 16:13:52 +08:00
|
|
|
echo "Adding same-key values"
|
|
|
|
cat > $TEMPCONF << EOF
|
|
|
|
key = bar, baz
|
|
|
|
key += qux
|
|
|
|
EOF
|
|
|
|
echo > $INITRD
|
|
|
|
|
|
|
|
xpass $BOOTCONF -a $TEMPCONF $INITRD
|
|
|
|
$BOOTCONF $INITRD > $OUTFILE
|
|
|
|
xpass grep -q "bar" $OUTFILE
|
|
|
|
xpass grep -q "baz" $OUTFILE
|
|
|
|
xpass grep -q "qux" $OUTFILE
|
|
|
|
|
2020-07-16 00:00:38 +08:00
|
|
|
echo "Override same-key values"
|
|
|
|
cat > $TEMPCONF << EOF
|
|
|
|
key = bar, baz
|
|
|
|
key := qux
|
|
|
|
EOF
|
|
|
|
echo > $INITRD
|
|
|
|
|
|
|
|
xpass $BOOTCONF -a $TEMPCONF $INITRD
|
|
|
|
$BOOTCONF $INITRD > $OUTFILE
|
|
|
|
xfail grep -q "bar" $OUTFILE
|
|
|
|
xfail grep -q "baz" $OUTFILE
|
|
|
|
xpass grep -q "qux" $OUTFILE
|
|
|
|
|
2020-06-16 18:14:34 +08:00
|
|
|
echo "Double/single quotes test"
|
|
|
|
echo "key = '\"string\"';" > $TEMPCONF
|
|
|
|
$BOOTCONF -a $TEMPCONF $INITRD
|
|
|
|
$BOOTCONF $INITRD > $TEMPCONF
|
|
|
|
cat $TEMPCONF
|
|
|
|
xpass grep \'\"string\"\' $TEMPCONF
|
|
|
|
|
2020-09-21 17:45:02 +08:00
|
|
|
echo "Repeat same-key tree"
|
|
|
|
cat > $TEMPCONF << EOF
|
|
|
|
foo
|
|
|
|
bar
|
|
|
|
foo { buz }
|
|
|
|
EOF
|
|
|
|
echo > $INITRD
|
|
|
|
|
|
|
|
xpass $BOOTCONF -a $TEMPCONF $INITRD
|
|
|
|
$BOOTCONF $INITRD > $OUTFILE
|
|
|
|
xpass grep -q "bar" $OUTFILE
|
|
|
|
|
2020-09-21 17:45:11 +08:00
|
|
|
|
|
|
|
echo "Remove/keep tailing spaces"
|
|
|
|
cat > $TEMPCONF << EOF
|
|
|
|
foo = val # comment
|
|
|
|
bar = "val2 " # comment
|
|
|
|
EOF
|
|
|
|
echo > $INITRD
|
|
|
|
|
|
|
|
xpass $BOOTCONF -a $TEMPCONF $INITRD
|
|
|
|
$BOOTCONF $INITRD > $OUTFILE
|
|
|
|
xfail grep -q val[[:space:]] $OUTFILE
|
|
|
|
xpass grep -q val2[[:space:]] $OUTFILE
|
|
|
|
|
2020-01-11 00:04:07 +08:00
|
|
|
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
|
|
|
|
|
2020-05-09 08:58:25 +08:00
|
|
|
|
|
|
|
echo
|
|
|
|
echo "=== Summary ==="
|
|
|
|
echo "# of Passed: $(expr $NO - $NG - 1)"
|
|
|
|
echo "# of Failed: $NG"
|
|
|
|
|
2020-01-11 00:04:07 +08:00
|
|
|
echo
|
|
|
|
if [ $NG -eq 0 ]; then
|
|
|
|
echo "All tests passed"
|
|
|
|
else
|
|
|
|
echo "$NG tests failed"
|
2020-05-09 08:58:25 +08:00
|
|
|
exit 1
|
2020-01-11 00:04:07 +08:00
|
|
|
fi
|