Commit 791cad02 authored by Lorenzo Bianconi's avatar Lorenzo Bianconi Committed by Andrii Nakryiko

bpf: selftests: Get rid of CHECK macro in xdp_adjust_tail.c

Rely on ASSERT* macros and get rid of deprecated CHECK ones in
xdp_adjust_tail bpf selftest.
Signed-off-by: default avatarLorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/c0ab002ffa647a20ec9e584214bf0d4373142b54.1642679130.git.lorenzo@kernel.org
parent 4e950747
...@@ -11,22 +11,21 @@ static void test_xdp_adjust_tail_shrink(void) ...@@ -11,22 +11,21 @@ static void test_xdp_adjust_tail_shrink(void)
char buf[128]; char buf[128];
err = bpf_prog_test_load(file, BPF_PROG_TYPE_XDP, &obj, &prog_fd); err = bpf_prog_test_load(file, BPF_PROG_TYPE_XDP, &obj, &prog_fd);
if (CHECK_FAIL(err)) if (ASSERT_OK(err, "test_xdp_adjust_tail_shrink"))
return; return;
err = bpf_prog_test_run(prog_fd, 1, &pkt_v4, sizeof(pkt_v4), err = bpf_prog_test_run(prog_fd, 1, &pkt_v4, sizeof(pkt_v4),
buf, &size, &retval, &duration); buf, &size, &retval, &duration);
ASSERT_OK(err, "ipv4");
CHECK(err || retval != XDP_DROP, ASSERT_EQ(retval, XDP_DROP, "ipv4 retval");
"ipv4", "err %d errno %d retval %d size %d\n",
err, errno, retval, size);
expect_sz = sizeof(pkt_v6) - 20; /* Test shrink with 20 bytes */ expect_sz = sizeof(pkt_v6) - 20; /* Test shrink with 20 bytes */
err = bpf_prog_test_run(prog_fd, 1, &pkt_v6, sizeof(pkt_v6), err = bpf_prog_test_run(prog_fd, 1, &pkt_v6, sizeof(pkt_v6),
buf, &size, &retval, &duration); buf, &size, &retval, &duration);
CHECK(err || retval != XDP_TX || size != expect_sz, ASSERT_OK(err, "ipv6");
"ipv6", "err %d errno %d retval %d size %d expect-size %d\n", ASSERT_EQ(retval, XDP_TX, "ipv6 retval");
err, errno, retval, size, expect_sz); ASSERT_EQ(size, expect_sz, "ipv6 size");
bpf_object__close(obj); bpf_object__close(obj);
} }
...@@ -39,21 +38,20 @@ static void test_xdp_adjust_tail_grow(void) ...@@ -39,21 +38,20 @@ static void test_xdp_adjust_tail_grow(void)
int err, prog_fd; int err, prog_fd;
err = bpf_prog_test_load(file, BPF_PROG_TYPE_XDP, &obj, &prog_fd); err = bpf_prog_test_load(file, BPF_PROG_TYPE_XDP, &obj, &prog_fd);
if (CHECK_FAIL(err)) if (ASSERT_OK(err, "test_xdp_adjust_tail_grow"))
return; return;
err = bpf_prog_test_run(prog_fd, 1, &pkt_v4, sizeof(pkt_v4), err = bpf_prog_test_run(prog_fd, 1, &pkt_v4, sizeof(pkt_v4),
buf, &size, &retval, &duration); buf, &size, &retval, &duration);
CHECK(err || retval != XDP_DROP, ASSERT_OK(err, "ipv4");
"ipv4", "err %d errno %d retval %d size %d\n", ASSERT_EQ(retval, XDP_DROP, "ipv4 retval");
err, errno, retval, size);
expect_sz = sizeof(pkt_v6) + 40; /* Test grow with 40 bytes */ expect_sz = sizeof(pkt_v6) + 40; /* Test grow with 40 bytes */
err = bpf_prog_test_run(prog_fd, 1, &pkt_v6, sizeof(pkt_v6) /* 74 */, err = bpf_prog_test_run(prog_fd, 1, &pkt_v6, sizeof(pkt_v6) /* 74 */,
buf, &size, &retval, &duration); buf, &size, &retval, &duration);
CHECK(err || retval != XDP_TX || size != expect_sz, ASSERT_OK(err, "ipv6");
"ipv6", "err %d errno %d retval %d size %d expect-size %d\n", ASSERT_EQ(retval, XDP_TX, "ipv6 retval");
err, errno, retval, size, expect_sz); ASSERT_EQ(size, expect_sz, "ipv6 size");
bpf_object__close(obj); bpf_object__close(obj);
} }
...@@ -76,7 +74,7 @@ static void test_xdp_adjust_tail_grow2(void) ...@@ -76,7 +74,7 @@ static void test_xdp_adjust_tail_grow2(void)
}; };
err = bpf_prog_test_load(file, BPF_PROG_TYPE_XDP, &obj, &tattr.prog_fd); err = bpf_prog_test_load(file, BPF_PROG_TYPE_XDP, &obj, &tattr.prog_fd);
if (CHECK_ATTR(err, "load", "err %d errno %d\n", err, errno)) if (ASSERT_OK(err, "test_xdp_adjust_tail_grow"))
return; return;
/* Test case-64 */ /* Test case-64 */
...@@ -86,21 +84,17 @@ static void test_xdp_adjust_tail_grow2(void) ...@@ -86,21 +84,17 @@ static void test_xdp_adjust_tail_grow2(void)
/* Kernel side alloc packet memory area that is zero init */ /* Kernel side alloc packet memory area that is zero init */
err = bpf_prog_test_run_xattr(&tattr); err = bpf_prog_test_run_xattr(&tattr);
CHECK_ATTR(errno != ENOSPC /* Due limit copy_size in bpf_test_finish */ ASSERT_EQ(errno, ENOSPC, "case-64 errno"); /* Due limit copy_size in bpf_test_finish */
|| tattr.retval != XDP_TX ASSERT_EQ(tattr.retval, XDP_TX, "case-64 retval");
|| tattr.data_size_out != 192, /* Expected grow size */ ASSERT_EQ(tattr.data_size_out, 192, "case-64 data_size_out"); /* Expected grow size */
"case-64",
"err %d errno %d retval %d size %d\n",
err, errno, tattr.retval, tattr.data_size_out);
/* Extra checks for data contents */ /* Extra checks for data contents */
CHECK_ATTR(tattr.data_size_out != 192 ASSERT_EQ(buf[0], 1, "case-64-data buf[0]"); /* 0-63 memset to 1 */
|| buf[0] != 1 || buf[63] != 1 /* 0-63 memset to 1 */ ASSERT_EQ(buf[63], 1, "case-64-data buf[63]");
|| buf[64] != 0 || buf[127] != 0 /* 64-127 memset to 0 */ ASSERT_EQ(buf[64], 0, "case-64-data buf[64]"); /* 64-127 memset to 0 */
|| buf[128] != 1 || buf[191] != 1, /*128-191 memset to 1 */ ASSERT_EQ(buf[127], 0, "case-64-data buf[127]");
"case-64-data", ASSERT_EQ(buf[128], 1, "case-64-data buf[128]"); /* 128-191 memset to 1 */
"err %d errno %d retval %d size %d\n", ASSERT_EQ(buf[191], 1, "case-64-data buf[191]");
err, errno, tattr.retval, tattr.data_size_out);
/* Test case-128 */ /* Test case-128 */
memset(buf, 2, sizeof(buf)); memset(buf, 2, sizeof(buf));
...@@ -109,23 +103,17 @@ static void test_xdp_adjust_tail_grow2(void) ...@@ -109,23 +103,17 @@ static void test_xdp_adjust_tail_grow2(void)
err = bpf_prog_test_run_xattr(&tattr); err = bpf_prog_test_run_xattr(&tattr);
max_grow = 4096 - XDP_PACKET_HEADROOM - tailroom; /* 3520 */ max_grow = 4096 - XDP_PACKET_HEADROOM - tailroom; /* 3520 */
CHECK_ATTR(err ASSERT_OK(err, "case-128");
|| tattr.retval != XDP_TX ASSERT_EQ(tattr.retval, XDP_TX, "case-128 retval");
|| tattr.data_size_out != max_grow,/* Expect max grow size */ ASSERT_EQ(tattr.data_size_out, max_grow, "case-128 data_size_out"); /* Expect max grow */
"case-128",
"err %d errno %d retval %d size %d expect-size %d\n",
err, errno, tattr.retval, tattr.data_size_out, max_grow);
/* Extra checks for data content: Count grow size, will contain zeros */ /* Extra checks for data content: Count grow size, will contain zeros */
for (i = 0, cnt = 0; i < sizeof(buf); i++) { for (i = 0, cnt = 0; i < sizeof(buf); i++) {
if (buf[i] == 0) if (buf[i] == 0)
cnt++; cnt++;
} }
CHECK_ATTR((cnt != (max_grow - tattr.data_size_in)) /* Grow increase */ ASSERT_EQ(cnt, max_grow - tattr.data_size_in, "case-128-data cnt"); /* Grow increase */
|| tattr.data_size_out != max_grow, /* Total grow size */ ASSERT_EQ(tattr.data_size_out, max_grow, "case-128-data data_size_out"); /* Total grow */
"case-128-data",
"err %d errno %d retval %d size %d grow-size %d\n",
err, errno, tattr.retval, tattr.data_size_out, cnt);
bpf_object__close(obj); bpf_object__close(obj);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment