summaryrefslogtreecommitdiffstats
path: root/tests/shell/run-tests.sh
diff options
context:
space:
mode:
authorLaura Garcia Liebana <nevola@gmail.com>2018-03-07 22:51:10 +0100
committerPablo Neira Ayuso <pablo@netfilter.org>2018-03-09 12:45:16 +0100
commit7d93e2c2fbc77f05fd7acb63a2acf9874c9ad58f (patch)
tree6773a61dcd261a25d525457bf8b6049787345424 /tests/shell/run-tests.sh
parent1870165e0241bd06f96da43edbee0e0e82bfa09d (diff)
tests: shell: autogenerate dump verification
Complete the automated shell tests with the verification of the test file dump, only for positive tests and if the test execution was successful. It's able to generate the dump file with the -g option. Example: # ./run-tests.sh -g testcases/chains/0001jumps_0 The dump files are generated in the same path in the folder named dumps/ with .nft extension. It has been avoided the dump verification code in every test file. Signed-off-by: Laura Garcia Liebana <nevola@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'tests/shell/run-tests.sh')
-rwxr-xr-xtests/shell/run-tests.sh46
1 files changed, 39 insertions, 7 deletions
diff --git a/tests/shell/run-tests.sh b/tests/shell/run-tests.sh
index 3eee99df..d2f3e96b 100755
--- a/tests/shell/run-tests.sh
+++ b/tests/shell/run-tests.sh
@@ -4,6 +4,8 @@
TESTDIR="./$(dirname $0)/"
RETURNCODE_SEPARATOR="_"
SRC_NFT="$(dirname $0)/../../src/nft"
+POSITIVE_RET=0
+DIFF=$(which diff)
msg_error() {
echo "E: $1 ..." >&2
@@ -43,6 +45,16 @@ if [ ! -x "$MODPROBE" ] ; then
msg_error "no modprobe binary found"
fi
+if [ "$1" == "-v" ] ; then
+ VERBOSE=y
+ shift
+fi
+
+if [ "$1" == "-g" ] ; then
+ DUMPGEN=y
+ shift
+fi
+
if [ -x "$1" ] ; then
if grep ^.*${RETURNCODE_SEPARATOR}[0-9]\\+$ <<< $1 >/dev/null ; then
SINGLE=$1
@@ -50,10 +62,6 @@ if [ -x "$1" ] ; then
fi
fi
-if [ "$1" == "-v" ] ; then
- VERBOSE=y
-fi
-
kernel_cleanup() {
$NFT flush ruleset
$MODPROBE -raq \
@@ -97,9 +105,33 @@ do
echo -en "\033[1A\033[K" # clean the [EXECUTING] foobar line
if [ "$rc_got" == "$rc_spec" ] ; then
- msg_info "[OK] $testfile"
- [ "$VERBOSE" == "y" ] && [ ! -z "$test_output" ] && echo "$test_output"
- ((ok++))
+ # check nft dump only for positive tests
+ rc_spec="${POSITIVE_RET}"
+ dumppath="$(dirname ${testfile})/dumps"
+ dumpfile="${dumppath}/$(basename ${testfile}).nft"
+ if [ "$rc_got" == "${POSITIVE_RET}" ] && [ -f ${dumpfile} ]; then
+ test_output=$(${DIFF} ${dumpfile} <(nft list ruleset) 2>&1)
+ rc_spec=$?
+ fi
+
+ if [ "$rc_spec" == "${POSITIVE_RET}" ]; then
+ msg_info "[OK] $testfile"
+ [ "$VERBOSE" == "y" ] && [ ! -z "$test_output" ] && echo "$test_output"
+ ((ok++))
+
+ if [ "$DUMPGEN" == "y" ] && [ "$rc_got" == "${POSITIVE_RET}" ] && [ ! -f "${dumpfile}" ]; then
+ mkdir -p "${dumppath}"
+ nft list ruleset > "${dumpfile}"
+ fi
+ else
+ ((failed++))
+ if [ "$VERBOSE" == "y" ] ; then
+ msg_warn "[DUMP FAIL] $testfile: dump diff detected"
+ [ ! -z "$test_output" ] && echo "$test_output"
+ else
+ msg_warn "[DUMP FAIL] $testfile"
+ fi
+ fi
else
((failed++))
if [ "$VERBOSE" == "y" ] ; then