From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Subject: [PATCH iptables,v2 2/5] tests: xlate-test: support multiline expectation
Date: Fri, 4 Jun 2021 00:58:03 +0200 [thread overview]
Message-ID: <20210603225806.13625-3-pablo@netfilter.org> (raw)
In-Reply-To: <20210603225806.13625-1-pablo@netfilter.org>
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.py | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/xlate-test.py b/xlate-test.py
index 4c014f9bd269..cba98b6e8e49 100755
--- a/xlate-test.py
+++ b/xlate-test.py
@@ -39,14 +39,21 @@ def run_test(name, payload):
tests = passed = failed = errors = 0
result = []
- for line in payload:
+ line = payload.readline()
+ while line:
if line.startswith(keywords):
tests += 1
process = Popen([ xtables_nft_multi ] + shlex.split(line), stdout=PIPE, stderr=PIPE)
(output, error) = process.communicate()
if process.returncode == 0:
translation = output.decode("utf-8").rstrip(" \n")
- expected = next(payload).rstrip(" \n")
+ expected = payload.readline().rstrip(" \n")
+ next_expected = payload.readline().rstrip(" \n")
+ if next_expected.startswith("nft"):
+ expected += "\n" + next_expected
+ line = payload.readline()
+ else:
+ line = next_expected
if translation != expected:
test_passed = False
failed += 1
@@ -62,6 +69,9 @@ def run_test(name, payload):
errors += 1
result.append(name + ": " + red("Error: ") + "iptables-translate failure")
result.append(error.decode("utf-8"))
+ line = payload.readline()
+ else:
+ line = payload.readline()
if (passed == tests) and not args.test:
print(name + ": " + green("OK"))
if not test_passed:
--
2.20.1
next prev parent reply other threads:[~2021-06-03 22:58 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-03 22:58 [PATCH iptables,v2 0/5] iptables-translation enhancements Pablo Neira Ayuso
2021-06-03 22:58 ` [PATCH iptables,v2 1/5] libxtables: extend xlate infrastructure Pablo Neira Ayuso
2021-06-03 22:58 ` Pablo Neira Ayuso [this message]
2021-06-03 22:58 ` [PATCH iptables,v2 3/5] extensions: libxt_connlimit: add translation Pablo Neira Ayuso
2021-06-03 22:58 ` [PATCH iptables,v2 4/5] extensions: libxt_tcp: rework translation to use flags match representation Pablo Neira Ayuso
2021-06-03 22:58 ` [PATCH iptables,v2 5/5] extensions: libxt_conntrack: simplify translation using negation Pablo Neira Ayuso
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210603225806.13625-3-pablo@netfilter.org \
--to=pablo@netfilter.org \
--cc=netfilter-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).