new test suite
Pablo Neira Ayuso
maintainerQuoted 9 lines · Arturo Borrero Gonzalez
Hi,
I suggest a testsuite like this, which can test higher level operations, so more tests can be performed to the code apart of the regression tests:
* listings/filterings
* deletions/flushes
* monitor operations
* ruleset loadings with -f
* interactive interface with -i (perhaps)
I started something similar here locally.
We can probably rearrange the directory to something like:
tests
|
.--- py
.--- shell
.--- files
So under tests/py/ we get the python-based infrastructure, then shell includes shell scripts for your test cases. The files directory should contain files that we can load via 'nft -f'.
That should be pretty much covering all paths of the command line interface.
Quoted 3 lines
In patch 1/3 there is a description of this simple testbed.
If you like the idea I would be happy to add more tests cases.
I think it's good idea to enhance the test infrastructure to catch regressions on as many fronts as possible.
cover new test suite
Hi,
I suggest a testsuite like this, which can test higher level operations, so more tests can be performed to the code apart of the regression tests:
* listings/filterings
* deletions/flushes
* monitor operations
* ruleset loadings with -f
* interactive interface with -i (perhaps)
In patch 1/3 there is a description of this simple testbed.
If you like the idea I would be happy to add more tests cases.
---
Arturo Borrero Gonzalez (3):
tests: add operations test-suite tests/operations: add maps tests cases tests/operations: add tests for handles and comments
tests/operations/README | 23 ++++++ tests/operations/run-operations-tests.sh | 72 ++++++++++++++++++++ .../operations/testcases/maps/anonymous_snat_map_0 | 7 ++ tests/operations/testcases/maps/named_snat_map_0 | 9 +++ tests/operations/testcases/optionals/comments_0 | 9 +++ .../testcases/optionals/comments_handles_0 | 11 +++ .../testcases/optionals/comments_handles_monitor_0 | 21 ++++++ tests/operations/testcases/optionals/handles_0 | 9 +++ tests/operations/testcases/optionals/handles_1 | 9 +++ 9 files changed, 170 insertions(+) create mode 100644 tests/operations/README create mode 100755 tests/operations/run-operations-tests.sh create mode 100755 tests/operations/testcases/maps/anonymous_snat_map_0 create mode 100755 tests/operations/testcases/maps/named_snat_map_0 create mode 100755 tests/operations/testcases/optionals/comments_0 create mode 100755 tests/operations/testcases/optionals/comments_handles_0 create mode 100755 tests/operations/testcases/optionals/comments_handles_monitor_0 create mode 100755 tests/operations/testcases/optionals/handles_0 create mode 100755 tests/operations/testcases/optionals/handles_1
--
RFC PATCH 1/3 tests: add operations test-suite
This new test-suite is intended to perform tests of higher level than the other reggresion test-suite.
It can run arbitrary executables which can perform any test apart of testing the nft syntax or netlink code (which is what the regression tests does).
To run the test suite (as root):
% cd tests/operations
% ./run-operations-tests.sh
Test files are executables files with the pattern <<name_N>>, where N is the expected return code of the executable. Since they are located with `find', test-files can be spreaded in any sub-directories.
You can turn on a verbose execution by calling:
% ./run-operations-tests.sh -v
Before each call to the test-files, `nft flush ruleset' will be called. Also, test-files will receive the environment variable $NFT which contains the path to the nftables binary being tested.
You can pass an arbitrary $NFT value as well:
% NFT=../../src/nft ./run-operations-tests.sh
--- tests/operations/README | 23 ++++++++++ tests/operations/run-operations-tests.sh | 72 ++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 tests/operations/README create mode 100755 tests/operations/run-operations-tests.sh
tests/operations/README new file +23 -0
@@ -0,0 +1,23 @@ +This test-suite is intended to perform tests of higher level than +the other reggresion test-suite. + +It can run arbitrary executables which can perform any test apart of testing +the nft syntax or netlink code (which is what the regression tests does). + +To run the test suite (as root): + % cd tests/operations + % ./run-operations-tests.sh + +Test files are executables files with the pattern <<name_N>>, where N is the +expected return code of the executable. Since they are located with `find', +test-files can be spreaded in any sub-directories. + +You can turn on a verbose execution by calling: + % ./run-operations-tests.sh -v + +Before each call to the test-files, `nft flush ruleset' will be called. +Also, test-files will receive the environment variable $NFT which contains the +path to the nftables binary being tested. + +You can pass an arbitrary $NFT value as well: + % NFT=../../src/nft ./run-operations-tests.sh
tests/operations/run-operations-tests.sh new file +72 -0
72 lines not on this page · raw message
RFC PATCH 2/3 tests/operations: add maps tests cases
In reply to Arturo Borrero GonzalezLet's add some tests cases for maps.
--- .../operations/testcases/maps/anonymous_snat_map_0 | 7 +++++++ tests/operations/testcases/maps/named_snat_map_0 | 9 +++++++++ 2 files changed, 16 insertions(+) create mode 100755 tests/operations/testcases/maps/anonymous_snat_map_0 create mode 100755 tests/operations/testcases/maps/named_snat_map_0
tests/operations/testcases/maps/anonymous_snat_map_0 new file +7 -0
@@ -0,0 +1,7 @@ +#!/bin/bash + +# anonymous map can be added to a snat rule + +$NFT add table nat +$NFT add chain nat postrouting +$NFT add rule nat postrouting snat ip saddr map {1.1.1.1 : 2.2.2.2}
tests/operations/testcases/maps/named_snat_map_0 new file +9 -0
@@ -0,0 +1,9 @@ +#!/bin/bash + +# nameds map can be addedd to a snat rule + +$NFT add table nat +$NFT add chain nat postrouting +$NFT add map nat m { type ipv4_addr : ipv4_addr\; } +$NFT add element nat m {1.1.1.1: 2.2.2.2} +$NFT add rule nat postrouting snat ip saddr map @m
RFC PATCH 3/3 tests/operations: add tests for handles and comments
In reply to Arturo Borrero GonzalezHere some tests for optional things like rule handles and comments.
--- tests/operations/testcases/optionals/comments_0 | 9 +++++++++ .../testcases/optionals/comments_handles_0 | 11 ++++++++++ .../testcases/optionals/comments_handles_monitor_0 | 21 ++++++++++++++++++++ tests/operations/testcases/optionals/handles_0 | 9 +++++++++ tests/operations/testcases/optionals/handles_1 | 9 +++++++++ 5 files changed, 59 insertions(+) create mode 100755 tests/operations/testcases/optionals/comments_0 create mode 100755 tests/operations/testcases/optionals/comments_handles_0 create mode 100755 tests/operations/testcases/optionals/comments_handles_monitor_0 create mode 100755 tests/operations/testcases/optionals/handles_0 create mode 100755 tests/operations/testcases/optionals/handles_1
tests/operations/testcases/optionals/comments_0 new file +9 -0
@@ -0,0 +1,9 @@ +#!/bin/bash + +# comments are shown + +$NFT flush ruleset +$NFT add table test +$NFT add chain test test +$NFT add rule test test tcp dport 22 counter accept comment test_comment +$NFT list table test -a | grep 'accept comment \"test_comment\"' >/dev/null
tests/operations/testcases/optionals/comments_handles_0 new file +11 -0
@@ -0,0 +1,11 @@ +#!/bin/bash + +# handles and comments mix well + +$NFT flush ruleset +$NFT add table test +$NFT add chain test test +$NFT add rule test test tcp dport 22 counter accept comment test_comment +set -e +$NFT list table test -a | grep 'accept comment \"test_comment\" # handle '[[:digit:]]$ >/dev/null +$NFT list table test | grep 'accept comment \"test_comment\"' | grep -v '# handle '[[:digit:]]$ >/dev/null
tests/operations/testcases/optionals/comments_handles_monitor_0 new file +21 -0
@@ -0,0 +1,21 @@ +#!/bin/bash + +# handles and comments mix well in monitor + +MKTEMP=$(which mktemp) +[ ! -x $MKTEMP ] && exit 0 # :-( no mktemp + +tmpfile=$(${MKTEMP}) +trap "rm -rf $tmpfile" EXIT # cleanup if aborted + +$NFT flush ruleset +$NFT add table test +$NFT add chain test test + +$NFT monitor -a > $tmpfile & +$NFT add rule test test tcp dport 22 counter accept comment test_comment +kill $! +set -e +grep 'accept comment \"test_comment\" # handle '[[:digit:]]$ $tmpfile >/dev/null +set +e +rm -rf $tmpfile
tests/operations/testcases/optionals/handles_0 new file +9 -0
@@ -0,0 +1,9 @@ +#!/bin/bash + +# handles are shown last + +$NFT flush ruleset +$NFT add table test +$NFT add chain test test +$NFT add rule test test tcp dport 22 counter accept +$NFT list table test -a | grep 'accept # handle '[[:digit:]]$ >/dev/null
tests/operations/testcases/optionals/handles_1 new file +9 -0
@@ -0,0 +1,9 @@ +#!/bin/bash + +# handles are not shown if not asked for them + +$NFT flush ruleset +$NFT add table test +$NFT add chain test test +$NFT add rule test test tcp dport 22 counter accept +$NFT list table test | grep 'accept # handle '[[:digit:]]$ >/dev/null