diff --git a/tests/unit/libbpf_test.cpp b/tests/unit/libbpf_test.cpp index 1647672e6c..1ee9d0bcc3 100644 --- a/tests/unit/libbpf_test.cpp +++ b/tests/unit/libbpf_test.cpp @@ -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. @@ -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. @@ -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);