Skip to content

Commit 9c2a2a4

Browse files
mmhalAlexei Starovoitov
authored andcommitted
selftest/bpf: Add test for af_vsock poll()
Verify that vsock's poll() notices when sk_psock::ingress_msg isn't empty. Signed-off-by: Michal Luczaj <[email protected]> Acked-by: Stefano Garzarella <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]> Acked-by: John Fastabend <[email protected]>
1 parent 9f0fc98 commit 9c2a2a4

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

tools/testing/selftests/bpf/prog_tests/sockmap_basic.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -937,6 +937,50 @@ static void test_sockmap_same_sock(void)
937937
test_sockmap_pass_prog__destroy(skel);
938938
}
939939

940+
static void test_sockmap_skb_verdict_vsock_poll(void)
941+
{
942+
struct test_sockmap_pass_prog *skel;
943+
int err, map, conn, peer;
944+
struct bpf_program *prog;
945+
struct bpf_link *link;
946+
char buf = 'x';
947+
int zero = 0;
948+
949+
skel = test_sockmap_pass_prog__open_and_load();
950+
if (!ASSERT_OK_PTR(skel, "open_and_load"))
951+
return;
952+
953+
if (create_pair(AF_VSOCK, SOCK_STREAM, &conn, &peer))
954+
goto destroy;
955+
956+
prog = skel->progs.prog_skb_verdict;
957+
map = bpf_map__fd(skel->maps.sock_map_rx);
958+
link = bpf_program__attach_sockmap(prog, map);
959+
if (!ASSERT_OK_PTR(link, "bpf_program__attach_sockmap"))
960+
goto close;
961+
962+
err = bpf_map_update_elem(map, &zero, &conn, BPF_ANY);
963+
if (!ASSERT_OK(err, "bpf_map_update_elem"))
964+
goto detach;
965+
966+
if (xsend(peer, &buf, 1, 0) != 1)
967+
goto detach;
968+
969+
err = poll_read(conn, IO_TIMEOUT_SEC);
970+
if (!ASSERT_OK(err, "poll"))
971+
goto detach;
972+
973+
if (xrecv_nonblock(conn, &buf, 1, 0) != 1)
974+
FAIL("xrecv_nonblock");
975+
detach:
976+
bpf_link__detach(link);
977+
close:
978+
xclose(conn);
979+
xclose(peer);
980+
destroy:
981+
test_sockmap_pass_prog__destroy(skel);
982+
}
983+
940984
void test_sockmap_basic(void)
941985
{
942986
if (test__start_subtest("sockmap create_update_free"))
@@ -997,4 +1041,6 @@ void test_sockmap_basic(void)
9971041
test_skmsg_helpers_with_link(BPF_MAP_TYPE_SOCKMAP);
9981042
if (test__start_subtest("sockhash sk_msg attach sockhash helpers with link"))
9991043
test_skmsg_helpers_with_link(BPF_MAP_TYPE_SOCKHASH);
1044+
if (test__start_subtest("sockmap skb_verdict vsock poll"))
1045+
test_sockmap_skb_verdict_vsock_poll();
10001046
}

0 commit comments

Comments
 (0)