From f6f790106654af150f09fca5013a4e9c2bab49a1 Mon Sep 17 00:00:00 2001 From: Lorenz Bauer Date: Tue, 12 Nov 2024 10:39:32 -0500 Subject: [PATCH] Fix test failure due to incorrect link type --- tests/unit/libbpf_test.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/tests/unit/libbpf_test.cpp b/tests/unit/libbpf_test.cpp index 840f432df1..6e202b9e10 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);