[PATCH 2/5] tests: check decoding of tcmsg netlink attributes

JingPiao Chen chenjingpiao at gmail.com
Tue Sep 5 13:16:29 UTC 2017


* 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 | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/tests/nlattr_tcmsg.c b/tests/nlattr_tcmsg.c
index 00b7ae4..32ce479 100644
--- a/tests/nlattr_tcmsg.c
+++ b/tests/nlattr_tcmsg.c
@@ -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;
 }
-- 
2.7.4





More information about the Strace-devel mailing list