Blame tests/monitor/README

Packit c5a612
Simple NFT MONITOR Testsuite
Packit c5a612
============================
Packit c5a612
Packit c5a612
The purpose of this suite of tests is to assert correct 'nft monitor' output for
Packit c5a612
known input. The suite consists of the single shell script 'run-tests.sh' which
Packit c5a612
performs the tests and a number of test definition files in 'testcases/'. The
Packit c5a612
latter have to be suffixed '.t' in order to be recognized as such.
Packit c5a612
Packit c5a612
Test Case Syntax
Packit c5a612
----------------
Packit c5a612
Packit c5a612
Each testcase defines a number of commands to pass on to 'nft' binary and an
Packit c5a612
associated 'nft monitor' output definition. Prerequisites for each command have
Packit c5a612
to be established manually, i.e. in order to test monitor output when adding a
Packit c5a612
chain, the table containing it has to be created first. In between each
Packit c5a612
testcase, rule set is flushed completely.
Packit c5a612
Packit c5a612
Input lines are prefixed by 'I'. Multiple consecutive input lines are passed to
Packit c5a612
'nft' together, hence lead to a single transaction.
Packit c5a612
Packit c5a612
There are two types of output lines: Those for standard syntax, prefixed by 'O'
Packit c5a612
and those for JSON output, prefixed by 'J'. For standard syntax output lines,
Packit c5a612
there is a shortcut: If a line consists of 'O -' only, the test script uses all
Packit c5a612
previous input lines as expected output directly. Of course this is not
Packit c5a612
available for JSON output lines.
Packit c5a612
Packit c5a612
Empty lines and those starting with '#' are ignored.
Packit c5a612
Packit c5a612
Test Script Semantics
Packit c5a612
---------------------
Packit c5a612
Packit c5a612
The script iterates over all test case files, reading them line by line. It
Packit c5a612
assumes that sections of 'I' lines alternate with sections of 'O'/'J' lines.
Packit c5a612
After stripping the prefix, each line is appended to a temporary file. There are
Packit c5a612
separate files for input and output lines.
Packit c5a612
Packit c5a612
If a set of input and output lines is complete (i.e. upon encountering either a
Packit c5a612
new input line or end of file), a testrun is performed: 'nft monitor' is run in
Packit c5a612
background, redirecting the output into a third file. The input file is passed
Packit c5a612
to 'nft -f'. Finally 'nft monitor' is killed and it's output compared to the
Packit c5a612
output file created earlier. If the files differ, a unified diff is printed and
Packit c5a612
test execution aborts.
Packit c5a612
Packit c5a612
After each testrun, input and output files are cleared.
Packit c5a612
Packit c5a612
Note: Running 'nft monitor' in background is prone to race conditions. Hence
Packit c5a612
an artificial delay is introduced before calling 'nft -f' to allow for 'nft
Packit c5a612
monitor' to complete initialization and another one before comparing the output
Packit c5a612
to allow for 'nft monitor' to process the netlink events.
Packit c5a612
Packit c5a612
By default, only standard syntax is being tested for, i.e. 'J'-prefixed lines
Packit c5a612
are simply ignored. If JSON testing was requested (by passing '-j' flag to the
Packit c5a612
test script), 'O'-prefixed lines in turn are ignored.
Packit c5a612
Packit c5a612
There is one caveat with regards to JSON output: Since it always contains handle
Packit c5a612
properties (if the given object possesses such) which is supposed to be
Packit c5a612
arbitrary, there is a filter script which normalizes all handle values in
Packit c5a612
monitor output to zero before comparison. Therefore expected output must have
Packit c5a612
all handle properties present but with a value of zero.