]> granicus.if.org Git - strace/commitdiff
tests: check decoding of ndtmsg netlink attributes
authorJingPiao Chen <chenjingpiao@gmail.com>
Wed, 30 Aug 2017 13:56:09 +0000 (21:56 +0800)
committerDmitry V. Levin <ldv@altlinux.org>
Fri, 1 Sep 2017 08:41:08 +0000 (08:41 +0000)
* 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

index b5b85deb7307a460059c754c584f0cfe37550027..d3f1bdb7e3824fdb2ebe0edabba745402f39b7b6 100644 (file)
@@ -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;
 }