summaryrefslogtreecommitdiffstats
path: root/xlate-test.py
Commit message (Collapse)AuthorAgeFilesLines
* xlate-test: Fix for empty source line on failurePhil Sutter2022-03-311-1/+2
| | | | | | | | The code overwrites 'line' before checking expected output. Save it in a temporary variable. Fixes: 62828a6aff231 ("tests: xlate-test: support multiline expectation") Signed-off-by: Phil Sutter <phil@nwl.cc>
* xlate-test: Print full path if testing all filesPhil Sutter2021-11-081-9/+9
| | | | | | | | Lines won't become too long and it's more clear to users where test input comes from this way. Signed-off-by: Phil Sutter <phil@nwl.cc> Tested-by: Pablo Neira Ayuso <pablo@netfilter.org>
* tests: xlate-test: Exit non-zero on errorPhil Sutter2021-09-131-10/+16
| | | | | | | | | If a test fails, return a non-zero exit code. To do so, propagate the pass/fail statistics up to main() for evaluation. While being at it, move the statistics printing into there as well and get rid of that redundant assignment to 'test_passed'. Signed-off-by: Phil Sutter <phil@nwl.cc>
* tests: xlate-test: Print errors to stderrPhil Sutter2021-09-131-2/+2
| | | | | | | Return code is always zero, so grepping for output on stderr is a simple way to detect testsuite failures. Signed-off-by: Phil Sutter <phil@nwl.cc>
* tests: xlate-test: Don't skip any input after the first empty linePhil Sutter2021-09-131-2/+2
| | | | | | | | | | | | | | | | | | | | | In conditionals, testing the empty string evaluates to false. This is dumb but seems intentional, as readline() method returns an empty string at EOF. This is distinct from reading an empty line as the latter contains the newline character - unless it is stripped in between readline() and conditional. The fixed commit introduced just that by accident, effectively reducing any test file to the first contained test: | $ ./xlate-test.py | [...] | 81 test files, 84 tests, 84 tests passed, 0 tests failed, 0 errors With this change in place, the summary looks much better: | 81 test files, 368 tests, 368 tests passed, 0 tests failed, 0 errors Fixes: 62828a6aff231 ("tests: xlate-test: support multiline expectation") Signed-off-by: Phil Sutter <phil@nwl.cc>
* tests: xlate-test: support multiline expectationPablo Neira Ayuso2021-06-071-2/+12
| | | | | | | | | | Extend translation test to deal with multiline translation, e.g. iptables-translate -A INPUT -m connlimit --connlimit-above 2 nft add set ip filter connlimit0 { type ipv4_addr; flags dynamic; } nft add rule ip filter INPUT add @connlimit0 { ip saddr ct count over 2 } counter Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* xlate-test: Support testing host binariesPhil Sutter2019-02-221-3/+11
| | | | | | | | | | | Introduce --host parameter to run the testsuite against host's binaries instead of built ones. Apparently, extending PATH variable in main() was redundant with explicit full path call in run_test() so drop the former. Signed-off-by: Phil Sutter <phil@nwl.cc> Signed-off-by: Florian Westphal <fw@strlen.de>
* xlate-test: Fix for calling wrong command namePhil Sutter2018-08-241-1/+1
| | | | | | | | | Aparently, this is a leftover from the compat->nft naming change in created binary (symlinks). Fixes: be70918eab26e ("xtables: rename xt-multi binaries to -nft, -legacy") Signed-off-by: Phil Sutter <phil@nwl.cc> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* xlate-test: use locally installed xlate toolsFlorian Westphal2018-05-041-1/+3
| | | | | | | same as iptables-test: use the translate tools in the current working directory, not the system-wide ones. Signed-off-by: Florian Westphal <fw@strlen.de>
* ebtables-translate: add initial test casesFlorian Westphal2018-04-131-1/+1
| | | | Signed-off-by: Florian Westphal <fw@strlen.de>
* tests: xlate-test: no need to require superuser privilegesFlorian Westphal2018-01-311-3/+1
| | | | | Signed-off-by: Florian Westphal <fw@strlen.de> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* tests: xlate: print output in same way as nft-test.pyHarsha Sharma2017-10-241-13/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Print errors and total no. of tests, tests passed, failed and errors for testfile argument Remove option "--all" Print file names for which all tests are passed with OK For e.g - sudo ./xlate-test.py generic.txlate: OK libip6t_DNAT.txlate: OK ... libxt_TCPMSS.txlate: Fail src: iptables-translate -A FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu exp: nft add rule ip filter FORWARD tcp flags & (syn|rst) == syn counter tcp option maxseg size set rt mtu res: nft # -A FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu ... libxt_connlabel.txlate: Error: iptables-translate failure iptables-translate v1.6.1: Couldn't load match `connlabel':No such file or directory ... 64 test files, 246 tests, 242 tests passed, 2 tests failed, 2 errors sudo ./xlate-test.py extensions/libxt_iprange.txlate 1 test file, 5 tests, 5 tests passed, 0 tests failed, 0 errors sudo ./xlate-test.py extensions/libxt_connlabel.txlate extensions/libxt_connlabel.txlate: Error: iptables-translate failure iptables-translate v1.6.1: Couldn't load match `connlabel':No such file or directory ... 1 test file, 2 tests, 0 tests passed, 0 tests failed, 2 errors Signed-off-by: Harsha Sharma <harshasharmaiitr@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* tests: xlate: check if it is being run as rootPablo M. Bermudo Garay2017-04-251-1/+3
| | | | | Signed-off-by: Pablo M. Bermudo Garay <pablombg@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* tests: xlate: remove python 3.5 dependencyPablo M. Bermudo Garay2017-04-251-13/+19
| | | | | | | | | | | This commit replaces subprocess.run (introduced in python 3.5) with subprocess.Popen (supported since the first version of python 3). Furthermore, the output has been improved when ip[6]tables-translate exits with non-zero return code. Signed-off-by: Pablo M. Bermudo Garay <pablombg@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* tests: add regression tests for xtables-translatePablo M. Bermudo Garay2017-04-071-0/+85
This test suite is intended to detect regressions in the translation infrastructure. The script checks if ip[6]tables-translate produces the expected output, otherwise it prints the wrong translation and the expected one. ** Arguments --all # Show also passed tests [test] # Run only the specified test file ** Test files structure Test files are located under extensions directory. Every file contains tests about specific extension translations. A test file name must end with ".txlate". Inside the files, every single test is defined by two consecutive lines: ip[6]tables-translate command and expected result. One blank line is left between tests by convention. e.g. $ cat extensions/libxt_cpu.txlate iptables-translate -A INPUT -p tcp --dport 80 -m cpu --cpu 0 -j ACCEPT nft add rule ip filter INPUT tcp dport 80 cpu 0 counter accept iptables-translate -A INPUT -p tcp --dport 80 -m cpu ! --cpu 1 -j ACCEPT nft add rule ip filter INPUT tcp dport 80 cpu != 1 counter accept Signed-off-by: Pablo M. Bermudo Garay <pablombg@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>