libnftnl/backport-tests-nft-rule-test-Add-test-cases-to-improve-code-c.patch
shixuantong 46249f8971 Do not leave free'd expr_list elements in place and add test cases
(cherry picked from commit 77e6e104fdf5e63c941d8c2bb9f5b94fec51a0c9)
2023-06-05 16:06:09 +08:00

41 lines
1.7 KiB
Diff

From 53ccf6e7a50d33ec6da5501bf75a1a621459f7aa Mon Sep 17 00:00:00 2001
From: shixuantong <tongxiaoge1001@126.com>
Date: Fri, 2 Jun 2023 00:05:37 +0800
Subject: [PATCH] tests: nft-rule-test: Add test cases to improve code coverage
Signed-off-by: shixuantong <tongxiaoge1001@126.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
tests/nft-rule-test.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/tests/nft-rule-test.c b/tests/nft-rule-test.c
index 3652bf6..3a92223 100644
--- a/tests/nft-rule-test.c
+++ b/tests/nft-rule-test.c
@@ -48,6 +48,12 @@ static void cmp_nftnl_rule(struct nftnl_rule *a, struct nftnl_rule *b)
if (nftnl_rule_get_u32(a, NFTNL_RULE_COMPAT_FLAGS) !=
nftnl_rule_get_u32(b, NFTNL_RULE_COMPAT_FLAGS))
print_err("Rule compat_flags mismatches");
+ if (nftnl_rule_get_u32(a, NFTNL_RULE_ID) !=
+ nftnl_rule_get_u32(b, NFTNL_RULE_ID))
+ print_err("Rule id mismatches");
+ if (nftnl_rule_get_u32(a, NFTNL_RULE_POSITION_ID) !=
+ nftnl_rule_get_u32(b, NFTNL_RULE_POSITION_ID))
+ print_err("Rule position_id mismatches");
if (nftnl_rule_get_u64(a, NFTNL_RULE_POSITION) !=
nftnl_rule_get_u64(b, NFTNL_RULE_POSITION))
print_err("Rule compat_position mismatches");
@@ -84,6 +90,8 @@ int main(int argc, char *argv[])
nftnl_rule_set_u64(a, NFTNL_RULE_HANDLE, 0x1234567812345678);
nftnl_rule_set_u32(a, NFTNL_RULE_COMPAT_PROTO, 0x12345678);
nftnl_rule_set_u32(a, NFTNL_RULE_COMPAT_FLAGS, 0x12345678);
+ nftnl_rule_set_u32(a, NFTNL_RULE_ID, 0x12345678);
+ nftnl_rule_set_u32(a, NFTNL_RULE_POSITION_ID, 0x12345678);
nftnl_rule_set_u64(a, NFTNL_RULE_POSITION, 0x1234567812345678);
nftnl_rule_set_data(a, NFTNL_RULE_USERDATA,
nftnl_udata_buf_data(udata),
--
2.27.0