[PATCH v8 5/5] Add tests for PID namespace translation
Dmitry V. Levin
ldv at altlinux.org
Sat Aug 15 21:19:41 UTC 2020
On Sun, Aug 09, 2020 at 04:13:06PM +0200, Ákos Uzonyi wrote:
[...]
> * tests/kill--pidns-translation.c: New file.
Tests for tkill and tgkill syscalls were added recently,
could you extend them too, please?
[...]
> static void
> test_f_owner_ex(void)
> {
> - static const struct {
> + struct {
> int type;
> const char *type_name;
> - pid_t pid[2];
> + enum pid_type pid_type;
> + pid_t pid;
> } a[] = {
> - { ARG_STR(F_OWNER_TID), { 1234567890, 20 } },
> - { ARG_STR(F_OWNER_PID), { 1298126790, 30 } },
> - { ARG_STR(F_OWNER_PGRP), { 1294567890, 40 } }
> + { ARG_STR(F_OWNER_TID), PT_NONE, 1234567890 },
> + { ARG_STR(F_OWNER_PID), PT_NONE, 1234567890 },
> + { ARG_STR(F_OWNER_PGRP), PT_NONE, 1234567890 },
> + { ARG_STR(F_OWNER_TID), PT_TID, 0 },
> + { ARG_STR(F_OWNER_PID), PT_TGID, 0 },
> + { ARG_STR(F_OWNER_PGRP), PT_PGID, 0 },
> };
>
> - for (unsigned int i = 0; i < ARRAY_SIZE(a); i++) {
> - for (unsigned int j = 0; j < ARRAY_SIZE(a[0].pid); j++) {
> - test_f_owner_ex_umove_or_printaddr(a[i].type,
> - a[i].type_name,
> - a[i].pid[j]);
> - }
> - }
> + a[3].pid = syscall(__NR_gettid);
> + a[4].pid = getpid();
> + a[5].pid = getpgid(0);
> +
> + for (unsigned int i = 0; i < ARRAY_SIZE(a); i++)
> + test_f_owner_ex_umove_or_printaddr(a[i].type, a[i].type_name,
> + a[i].pid_type, a[i].pid);
> }
Let's initialize the array during the definition.
If it's no longer static, function calls are allowed in the definition.
[...]
> --- /dev/null
> +++ b/tests/ioctl_block--pidns-translation.test
> @@ -0,0 +1,24 @@
> +#!/bin/sh
> +#
> +# Check ioctl syscall decoding.
This is primarily not a generic check of ioctl syscall decoding.
[...]
> @@ -365,7 +393,8 @@ check_ax25(void)
> for (size_t i = 0; i < 3; i++) {
> size = sizeof(ax25) + sizeof(ax25_address) * (i / 2);
> rc = connect(-1, sax_void, size);
> - printf("connect(-1, {sa_family=AF_AX25"
> + pidns_print_leader();
> + printf("connect(-1, {sa_family=AF_AX25"
> ", fsa_ax25={sax25_call=VALID-13, sax25_ndigis=%d}"
> ", fsa_digipeater=[VALID2-7, OK-15, %s /* FINE-2 */"
> ", {ax25_call=\"\\xe6\\xda\\xc2\\xd8\\xd8\\xe6\\x12\""
Something went wrong with the indentation here,
> @@ -427,13 +456,15 @@ check_x25(void)
> long rc;
>
> rc = connect(-1, x25_void, sizeof(c_x25) - 1);
> + pidns_print_leader();
> printf("connect(-1, {sa_family=AF_X25"
> ", sa_data=\"0123456789abcde\"}, %zu) = %s\n",
> sizeof(c_x25) - 1, sprintrc(rc));
>
> for (size_t i = 0; i < 2; i++) {
> rc = connect(-1, x25_void, sizeof(c_x25) + i);
> - printf("connect(-1, {sa_family=AF_X25"
> + pidns_print_leader();
> + printf("connect(-1, {sa_family=AF_X25"
> ", sx25_addr={x25_addr=\"0123456789abcde\"...}"
> "}, %zu) = %s\n",
> sizeof(c_x25) + i, sprintrc(rc));
here,
> @@ -526,7 +563,8 @@ check_ll(void)
> ((struct sockaddr_ll *) ll)->sll_ifindex = ifindex_lo();
> if (((struct sockaddr_ll *) ll)->sll_ifindex) {
> ret = connect(-1, ll, len);
> - printf("connect(-1, {sa_family=AF_PACKET"
> + pidns_print_leader();
> + printf("connect(-1, {sa_family=AF_PACKET"
> ", sll_protocol=htons(ETH_P_ALL)"
> ", sll_ifindex=%s"
> ", sll_hatype=ARPHRD_ETHER"
and here.
[...]
> --- /dev/null
> +++ b/tests/netlink_audit--pidns-translation.test
> @@ -0,0 +1,13 @@
> +#!/bin/sh
> +#
> +# Check decoding of NETLINK_SOCK_DIAG protocol
This is primarily not a generic check of NETLINK_SOCK_DIAG protocol decoding.
--
ldv
More information about the Strace-devel
mailing list