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 Nov 12, 2024
1 parent bc1535f commit 105411a
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 105411a

Please sign in to comment.