]> granicus.if.org Git - strace/commitdiff
tests: check decoding of tcmsg netlink attributes
authorJingPiao Chen <chenjingpiao@gmail.com>
Mon, 4 Sep 2017 07:11:33 +0000 (15:11 +0800)
committerDmitry V. Levin <ldv@altlinux.org>
Thu, 7 Sep 2017 11:35:04 +0000 (11:35 +0000)
* tests/nlattr_tcmsg.c: Include <stddef.h> and <linux/pkt_sched.h>.
(main): Check decoding of TCA_STATS and TCA_RATE.

tests/nlattr_tcmsg.c

index 00b7ae461fd2037f31494ae781edb827def87377..32ce47905b8355ecbf42080a62942757aeff46e8 100644 (file)
@@ -29,7 +29,9 @@
 #include "tests.h"
 
 #include <stdio.h>
+#include <stddef.h>
 #include "test_nlattr.h"
+#include <linux/pkt_sched.h>
 #include <linux/rtnetlink.h>
 
 static void
@@ -80,6 +82,42 @@ main(void)
                     4, pattern, 4,
                     print_quoted_hex(pattern, 4));
 
+       static const struct tc_stats st = {
+               .bytes = 0xabcdcdbefeadefac,
+               .packets = 0xbcdeaefd,
+               .drops = 0xcdedafed,
+               .overlimits = 0xdcdbefad,
+               .bps = 0xefaebfad,
+               .pps = 0xfefbaedb,
+               .qlen = 0xabcdefab,
+               .backlog = 0xbdeabeab
+       };
+       char buf[offsetofend(struct tc_stats, backlog)];
+       memcpy(buf, &st, sizeof(buf));
+       TEST_NLATTR_OBJECT(fd, nlh0, hdrlen,
+                          init_tcmsg, print_tcmsg,
+                          TCA_STATS, pattern, buf,
+                          PRINT_FIELD_U("{", st, bytes);
+                          PRINT_FIELD_U(", ", st, packets);
+                          PRINT_FIELD_U(", ", st, drops);
+                          PRINT_FIELD_U(", ", st, overlimits);
+                          PRINT_FIELD_U(", ", st, bps);
+                          PRINT_FIELD_U(", ", st, pps);
+                          PRINT_FIELD_U(", ", st, qlen);
+                          PRINT_FIELD_U(", ", st, backlog);
+                          printf("}"));
+
+       static const struct tc_estimator est = {
+               .interval = 0xcd,
+               .ewma_log = 0xab
+       };
+       TEST_NLATTR_OBJECT(fd, nlh0, hdrlen,
+                          init_tcmsg, print_tcmsg,
+                          TCA_RATE, pattern, est,
+                          PRINT_FIELD_D("{", est, interval);
+                          PRINT_FIELD_U(", ", est, ewma_log);
+                          printf("}"));
+
        puts("+++ exited with 0 +++");
        return 0;
 }