path: root/tests/monitor/README
diff options
authorPhil Sutter <>2017-07-25 16:56:29 +0200
committerPablo Neira Ayuso <>2017-07-25 18:17:28 +0200
commit9c870174df2837131359f2876d4675d0f5ffe86a (patch)
tree116b754cbb6bc5e40fd7b3f6007d549384f51b7b /tests/monitor/README
parentf9158151f368b009bed2ef3da4ea252014ab11f1 (diff)
tests/monitor: Add a small README
Signed-off-by: Phil Sutter <> Signed-off-by: Pablo Neira Ayuso <>
Diffstat (limited to 'tests/monitor/README')
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/monitor/README b/tests/monitor/README
new file mode 100644
index 00000000..9c5e37f5
--- /dev/null
+++ b/tests/monitor/README
@@ -0,0 +1,48 @@
+Simple NFT MONITOR Testsuite
+The purpose of this suite of tests is to assert correct 'nft monitor' output for
+known input. The suite consists of the single shell script '' which
+performs the tests and a number of test definition files in 'testcases/'. The
+latter have to be suffixed '.t' in order to be recognized as such.
+Test Case Syntax
+Each testcase defines a number of commands to pass on to 'nft' binary and an
+associated 'nft monitor' output definition. Prerequisites for each command have
+to be established manually, i.e. in order to test monitor output when adding a
+chain, the table containing it has to be created first. In between each
+testcase, rule set is flushed completely.
+Input and output lines are prefixed by 'I' and 'O', respectively. The prefix has
+to be separated from the rest of the line by whitespace. Consecutive input lines
+are passed to 'nft' together, hence lead to a single transaction.
+Since in most cases output should be equal to input, there is a shortcut: If a
+line consists of 'O -' only, the test script uses all previous input lines as
+expected output directly.
+Empty lines and those starting with '#' are ignored.
+Test Script Semantics
+The script iterates over all test case files, reading them line by line. It
+assumes that sections of 'I' lines alternate with sections of 'O' lines. After
+stripping the prefix, each line is appended to a temporary file. There are
+separate files for input and output lines.
+If a set of input and output lines is complete (i.e. upon encountering either a
+new input line or end of file), a testrun is performed: 'nft monitor' is run in
+background, redirecting the output into a third file. The input file is passed
+to 'nft -f'. Finally 'nft monitor' is killed and it's output compared to the
+output file created earlier. If the files differ, a unified diff is printed and
+test execution aborts.
+After each testrun, input and output files are cleared.
+Note: Running 'nft monitor' in background is prone to race conditions. Hence
+an artificial delay is introduced before calling 'nft -f' to allow for 'nft
+monitor' to complete initialization and another one before comparing the output
+to allow for 'nft monitor' to process the netlink events.