libnftnl/add-some-test-cases-to-improve-code-coverage.patch
shixuantong d5401bdc59 add some test cases to improve code coverage
(cherry picked from commit dd319e2c0d7455943477368ffc08b22e045a5890)
2023-07-11 10:44:20 +08:00

54 lines
1.9 KiB
Diff

From 0ddcddb289c6355d6f533aeceb6895a38fcf0a0f Mon Sep 17 00:00:00 2001
From: shixuantong <shixuantong1@huawei.com>
Date: Mon, 5 Jun 2023 16:31:58 +0800
Subject: [PATCH] add some test cases to improve code coverage
---
tests/nft-rule-test.c | 3 +++
tests/nft-table-test.c | 8 ++++++++
2 files changed, 11 insertions(+)
diff --git a/tests/nft-rule-test.c b/tests/nft-rule-test.c
index c48381e..8186752 100644
--- a/tests/nft-rule-test.c
+++ b/tests/nft-rule-test.c
@@ -106,6 +106,9 @@ int main(int argc, char *argv[])
cmp_nftnl_rule(a,b);
+ nftnl_rule_unset(a, NFTNL_RULE_TABLE);
+ nftnl_rule_unset(a, NFTNL_RULE_CHAIN);
+ nftnl_rule_unset(a, NFTNL_RULE_USERDATA);
nftnl_rule_free(a);
nftnl_rule_free(b);
if (!test_ok)
diff --git a/tests/nft-table-test.c b/tests/nft-table-test.c
index 1031ffe..ab111ba 100644
--- a/tests/nft-table-test.c
+++ b/tests/nft-table-test.c
@@ -35,6 +35,12 @@ static void cmp_nftnl_table(struct nftnl_table *a, struct nftnl_table *b)
if (nftnl_table_get_u32(a, NFTNL_TABLE_FAMILY) !=
nftnl_table_get_u32(b, NFTNL_TABLE_FAMILY))
print_err("tabke family mismatches");
+ if (nftnl_table_get_u64(a, NFTNL_TABLE_HANDLE) !=
+ nftnl_table_get_u64(b, NFTNL_TABLE_HANDLE))
+ print_err("tabke handle mismatches");
+ if (strcmp(nftnl_table_get_str(a, NFTNL_TABLE_USERDATA),
+ nftnl_table_get_str(b, NFTNL_TABLE_USERDATA)) != 0)
+ print_err("table userdata mismatches");
}
int main(int argc, char *argv[])
@@ -53,6 +59,8 @@ int main(int argc, char *argv[])
nftnl_table_set_str(a, NFTNL_TABLE_NAME, "test");
nftnl_table_set_u32(a, NFTNL_TABLE_FAMILY, AF_INET);
nftnl_table_set_u32(a, NFTNL_TABLE_FLAGS, 0);
+ nftnl_table_set_u64(a, NFTNL_TABLE_HANDLE, 0x12345678);
+ nftnl_table_set_str(a, NFTNL_TABLE_USERDATA, "test for userdata");
/* cmd extracted from include/linux/netfilter/nf_tables.h */
nlh = nftnl_table_nlmsg_build_hdr(buf, NFT_MSG_NEWTABLE, AF_INET, 0,
--
2.27.0