tests: check decoding of several standard netlink attributes
authorDmitry V. Levin <ldv@altlinux.org>
Fri, 30 Jun 2017 21:38:49 +0000 (21:38 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Sat, 1 Jul 2017 00:05:39 +0000 (00:05 +0000)
* tests/nlattr_inet_diag_msg.c (main): Check decoding of uint32_t,
uint8_t, and zero-terminated string attributes.

Co-authored-by: JingPiao Chen <chenjingpiao@gmail.com>
tests/nlattr_inet_diag_msg.c

index 65ca667b5e08e453d04bfca4337f412130d05648..59c2e0d0ac4285b90a84f27f29ba266a014b116e 100644 (file)
@@ -162,6 +162,30 @@ main(void)
                          init_inet_diag_msg, print_inet_diag_msg,
                          INET_DIAG_SKMEMINFO, pattern, mem, print_uint);
 
+       static const uint32_t mark = 0xabdfadca;
+       TEST_NLATTR_OBJECT(fd, nlh0, hdrlen,
+                          init_inet_diag_msg, print_inet_diag_msg,
+                          INET_DIAG_MARK, pattern, mark,
+                          printf("%u", mark));
+
+       static const uint8_t shutdown = 0xcd;
+       TEST_NLATTR(fd, nlh0, hdrlen,
+                   init_inet_diag_msg, print_inet_diag_msg, INET_DIAG_SHUTDOWN,
+                   sizeof(shutdown), &shutdown, sizeof(shutdown),
+                   printf("%u", shutdown));
+
+       char *const str = tail_alloc(DEFAULT_STRLEN);
+       fill_memory_ex(str, DEFAULT_STRLEN, '0', 10);
+       TEST_NLATTR(fd, nlh0, hdrlen,
+                   init_inet_diag_msg, print_inet_diag_msg, INET_DIAG_CONG,
+                   DEFAULT_STRLEN, str, DEFAULT_STRLEN,
+                   printf("\"%.*s\"...", DEFAULT_STRLEN, str));
+       str[DEFAULT_STRLEN - 1] = '\0';
+       TEST_NLATTR(fd, nlh0, hdrlen,
+                   init_inet_diag_msg, print_inet_diag_msg, INET_DIAG_CONG,
+                   DEFAULT_STRLEN, str, DEFAULT_STRLEN,
+                   printf("\"%s\"", str));
+
        puts("+++ exited with 0 +++");
        return 0;
 }