selftests: netfilter: nft_concat_range.sh: prefer per element counters for testing
authorFlorian Westphal <fw@strlen.de>
Fri, 23 May 2025 12:20:45 +0000 (14:20 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Thu, 5 Jun 2025 08:50:04 +0000 (10:50 +0200)
commitfebe7eda74d105437c7532b4a76ff14eb6007828
treef335cd20f5accefe576e66f5f313bc8fd96059e4
parentea77c397bff8b6d59f6d83dae1425b08f465e8b5
selftests: netfilter: nft_concat_range.sh: prefer per element counters for testing

The selftest uses following rule:
  ... @test counter name "test"

Then sends a packet, then checks if the named counter did increment or
not.

This is fine for the 'no-match' test case: If anything matches the
counter increments and the test fails as expected.

But for the 'should match' test cases this isn't optimal.
Consider buggy matching, where the packet matches entry x, but it
should have matched entry y.

In that case the test would erronously pass.

Rework the selftest to use per-element counters to avoid this.

After sending packet that should have matched entry x, query the
relevant element via 'nft reset element' and check that its counter
had incremented.

The 'nomatch' case isn't altered, no entry should match so the named
counter must be 0, changing it to the per-element counter would then
pass if another entry matches.

The downside of this change is a slight increase in test run-time by
a few seconds.

Signed-off-by: Florian Westphal <fw@strlen.de>
Reviewed-by: Stefano Brivio <sbrivio@redhat.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
tools/testing/selftests/net/netfilter/nft_concat_range.sh