Skip to content

Commit

Permalink
Fix test failure due to incorrect link type
Browse files Browse the repository at this point in the history
  • Loading branch information
lmb committed Dec 16, 2024
1 parent b549a94 commit f6f7901
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions tests/unit/libbpf_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2222,8 +2222,8 @@ TEST_CASE("enumerate link IDs with bpf", "[libbpf]")
attr.info.info = (uintptr_t)&info;
attr.info.info_len = sizeof(info);
REQUIRE(bpf(BPF_OBJ_GET_INFO_BY_FD, &attr, sizeof(attr)) == 0);
REQUIRE(info.type == BPF_LINK_TYPE_PLAIN);
REQUIRE(info.id != 0);
REQUIRE(info.type == BPF_LINK_TYPE_UNSPEC);
REQUIRE(info.id == id1);
REQUIRE(info.prog_id != 0);

// Detach the first link.
Expand All @@ -2238,7 +2238,7 @@ TEST_CASE("enumerate link IDs with bpf", "[libbpf]")
attr.info.info_len = sizeof(info);
REQUIRE(bpf(BPF_OBJ_GET_INFO_BY_FD, &attr, sizeof(attr)) == 0);
REQUIRE(info.type == BPF_LINK_TYPE_PLAIN);
REQUIRE(info.id != 0);
REQUIRE(info.id == id1);
REQUIRE(info.prog_id == 0);

// Pin the detached link.
Expand All @@ -2262,6 +2262,17 @@ TEST_CASE("enumerate link IDs with bpf", "[libbpf]")
attr.info.info_len = sizeof(info);
REQUIRE(bpf(BPF_OBJ_GET_INFO_BY_FD, &attr, sizeof(attr)) == 0);
REQUIRE(info.id == id1);

// Get info on the second link.
memset(&attr, 0, sizeof(attr));
info = {};
attr.info.bpf_fd = fd2;
attr.info.info = (uintptr_t)&info;
attr.info.info_len = sizeof(info);
REQUIRE(bpf(BPF_OBJ_GET_INFO_BY_FD, &attr, sizeof(attr)) == 0);
REQUIRE(info.type == BPF_LINK_TYPE_PLAIN);
REQUIRE(info.id == id2);
REQUIRE(info.prog_id != 0);

// And for completeness, try an invalid bpf() call.
REQUIRE(bpf(-1, &attr, sizeof(attr)) == -EINVAL);
Expand Down

0 comments on commit f6f7901

Please sign in to comment.