Skip to content

Commit

Permalink
selftests/hid: add test for attaching multiple time the same struct_ops
Browse files Browse the repository at this point in the history
Turns out that we would en up in a bad state if we attempt to attach
twice the same HID-BPF struct_ops, so have a test for it.

Link: https://patch.msgid.link/[email protected]
Signed-off-by: Benjamin Tissoires <[email protected]>
  • Loading branch information
Benjamin Tissoires committed Jul 24, 2024
1 parent acd34cf commit facdbdf
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tools/testing/selftests/hid/hid_bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,24 @@ TEST_F(hid_bpf, subprog_raw_event)
ASSERT_EQ(buf[2], 52);
}

/*
* Attach hid_first_event to the given uhid device,
* attempt at re-attaching it, we should not lock and
* return an invalid struct bpf_link
*/
TEST_F(hid_bpf, multiple_attach)
{
const struct test_program progs[] = {
{ .name = "hid_first_event" },
};
struct bpf_link *link;

LOAD_PROGRAMS(progs);

link = bpf_map__attach_struct_ops(self->skel->maps.first_event);
ASSERT_NULL(link) TH_LOG("unexpected return value when re-attaching the struct_ops");
}

/*
* Ensures that we can attach/detach programs
*/
Expand Down

0 comments on commit facdbdf

Please sign in to comment.