[PATCH 5/7] tests: check decoding of ndtmsg netlink attributes

JingPiao Chen chenjingpiao at gmail.com
Thu Aug 31 02:39:23 UTC 2017


* tests/nlattr_ndtmsg.c (NDTA_PARMS, NDTPA_IFINDEX): New macros.
(main): Check decoding of NDTA_CONFIG, NDTA_PARMS and NDTA_STATS.
---
 tests/nlattr_ndtmsg.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 75 insertions(+)

diff --git a/tests/nlattr_ndtmsg.c b/tests/nlattr_ndtmsg.c
index b5b85de..d3f1bdb 100644
--- a/tests/nlattr_ndtmsg.c
+++ b/tests/nlattr_ndtmsg.c
@@ -35,6 +35,9 @@
 #endif
 #include <linux/rtnetlink.h>
 
+#define NDTA_PARMS 6
+#define NDTPA_IFINDEX 1
+
 static void
 init_ndtmsg(struct nlmsghdr *const nlh, const unsigned int msg_len)
 {
@@ -79,6 +82,78 @@ main(void)
 		     4, pattern, 4,
 		     print_quoted_hex(pattern, 4));
 
+#ifdef HAVE_STRUCT_NDT_CONFIG
+	static const struct ndt_config ndtc = {
+		.ndtc_key_len = 0xabcd,
+		.ndtc_entry_size = 0xbcda,
+		.ndtc_entries = 0xcdabedad,
+		.ndtc_last_flush = 0xdebaedba,
+		.ndtc_last_rand = 0xedadedab,
+		.ndtc_hash_rnd = 0xfeadedaf,
+		.ndtc_hash_mask = 0xadbcdead,
+		.ndtc_hash_chain_gc = 0xbdaedacd,
+		.ndtc_proxy_qlen = 0xcdeaedab
+	};
+	TEST_NLATTR_OBJECT(fd, nlh0, hdrlen,
+			   init_ndtmsg, print_ndtmsg,
+			   NDTA_CONFIG, pattern, ndtc,
+			   PRINT_FIELD_U("{", ndtc, ndtc_key_len);
+			   PRINT_FIELD_U(", ", ndtc, ndtc_entry_size);
+			   PRINT_FIELD_U(", ", ndtc, ndtc_entries);
+			   PRINT_FIELD_U(", ", ndtc, ndtc_last_flush);
+			   PRINT_FIELD_U(", ", ndtc, ndtc_last_rand);
+			   PRINT_FIELD_U(", ", ndtc, ndtc_hash_rnd);
+			   PRINT_FIELD_0X(", ", ndtc, ndtc_hash_mask);
+			   PRINT_FIELD_U(", ", ndtc, ndtc_hash_chain_gc);
+			   PRINT_FIELD_U(", ", ndtc, ndtc_proxy_qlen);
+			   printf("}"));
+#endif /* HAVE_STRUCT_NDT_CONFIG */
+
+	static const struct nlattr nla = {
+		.nla_len = sizeof(nla),
+		.nla_type = NDTPA_IFINDEX
+	};
+	TEST_NLATTR_OBJECT(fd, nlh0, hdrlen,
+			   init_ndtmsg, print_ndtmsg,
+			   NDTA_PARMS, pattern, nla,
+			   PRINT_FIELD_U("{", nla, nla_len);
+			   printf(", nla_type=NDTPA_IFINDEX}"));
+
+#ifdef HAVE_STRUCT_NDT_STATS
+	static const struct ndt_stats ndtst = {
+		.ndts_allocs		= 0xabcdedabedadedfa,
+		.ndts_destroys		= 0xbcdefabefacdbaad,
+		.ndts_hash_grows	= 0xcdbadefacdcbaede,
+		.ndts_res_failed	= 0xdedbaecfdbcadcfe,
+		.ndts_lookups		= 0xedfafdedbdadedec,
+		.ndts_hits		= 0xfebdeadebcddeade,
+		.ndts_rcv_probes_mcast	= 0xadebfeadecddeafe,
+		.ndts_rcv_probes_ucast	= 0xbcdefeacdadecdfe,
+		.ndts_periodic_gc_runs	= 0xedffeadedeffbecc,
+		.ndts_forced_gc_runs	= 0xfeefefeabedeedcd,
+#ifdef HAVE_STRUCT_NDT_STATS_NDTS_TABLE_FULLS
+		.ndts_table_fulls	= 0xadebfefaecdfeade
+#endif /* HAVE_STRUCT_NDT_STATS_NDTS_TABLE_FULLS */
+	};
+	TEST_NLATTR_OBJECT(fd, nlh0, hdrlen,
+			   init_ndtmsg, print_ndtmsg,
+			   NDTA_STATS, pattern, ndtst,
+			   PRINT_FIELD_U("{", ndtst, ndts_allocs);
+			   PRINT_FIELD_U(", ", ndtst, ndts_destroys);
+			   PRINT_FIELD_U(", ", ndtst, ndts_hash_grows);
+			   PRINT_FIELD_U(", ", ndtst, ndts_res_failed);
+			   PRINT_FIELD_U(", ", ndtst, ndts_lookups);
+			   PRINT_FIELD_U(", ", ndtst, ndts_hits);
+			   PRINT_FIELD_U(", ", ndtst, ndts_rcv_probes_mcast);
+			   PRINT_FIELD_U(", ", ndtst, ndts_rcv_probes_ucast);
+			   PRINT_FIELD_U(", ", ndtst, ndts_periodic_gc_runs);
+			   PRINT_FIELD_U(", ", ndtst, ndts_forced_gc_runs);
+#ifdef HAVE_STRUCT_NDT_STATS_NDTS_TABLE_FULLS
+			   PRINT_FIELD_U(", ", ndtst, ndts_table_fulls);
+#endif /* HAVE_STRUCT_NDT_STATS_NDTS_TABLE_FULLS */
+			   printf("}"));
+#endif /* HAVE_STRUCT_NDT_STATS */
+
 	puts("+++ exited with 0 +++");
 	return 0;
 }
-- 
2.7.4





More information about the Strace-devel mailing list