提交 cea6c4d9 编写于 作者: B Benjamin Tissoires 提交者: Jiri Kosina

selftests: hid: attach/detach 2 bpf programs, not just one

Add a second BPF program to attach to the device, as the development of
this feature showed that we also need to ensure we can detach multiple
programs to a device (hid_bpf_link->hid_table_index was actually not set
initially, and this lead to any BPF program not being released except for
the first one).
Signed-off-by: NBenjamin Tissoires <benjamin.tissoires@redhat.com>
Signed-off-by: NJiri Kosina <jkosina@suse.cz>
上级 633ba3be
...@@ -616,6 +616,7 @@ TEST_F(hid_bpf, test_attach_detach) ...@@ -616,6 +616,7 @@ TEST_F(hid_bpf, test_attach_detach)
{ {
const struct test_program progs[] = { const struct test_program progs[] = {
{ .name = "hid_first_event" }, { .name = "hid_first_event" },
{ .name = "hid_second_event" },
}; };
__u8 buf[10] = {0}; __u8 buf[10] = {0};
int err; int err;
...@@ -634,7 +635,10 @@ TEST_F(hid_bpf, test_attach_detach) ...@@ -634,7 +635,10 @@ TEST_F(hid_bpf, test_attach_detach)
ASSERT_EQ(buf[0], 1); ASSERT_EQ(buf[0], 1);
ASSERT_EQ(buf[2], 47); ASSERT_EQ(buf[2], 47);
/* pin the program and immediately unpin it */ /* make sure both programs are run */
ASSERT_EQ(buf[3], 52);
/* pin the first program and immediately unpin it */
#define PIN_PATH "/sys/fs/bpf/hid_first_event" #define PIN_PATH "/sys/fs/bpf/hid_first_event"
bpf_program__pin(self->skel->progs.hid_first_event, PIN_PATH); bpf_program__pin(self->skel->progs.hid_first_event, PIN_PATH);
remove(PIN_PATH); remove(PIN_PATH);
...@@ -660,6 +664,7 @@ TEST_F(hid_bpf, test_attach_detach) ...@@ -660,6 +664,7 @@ TEST_F(hid_bpf, test_attach_detach)
ASSERT_EQ(buf[0], 1); ASSERT_EQ(buf[0], 1);
ASSERT_EQ(buf[1], 47); ASSERT_EQ(buf[1], 47);
ASSERT_EQ(buf[2], 0); ASSERT_EQ(buf[2], 0);
ASSERT_EQ(buf[3], 0);
/* re-attach our program */ /* re-attach our program */
...@@ -677,6 +682,7 @@ TEST_F(hid_bpf, test_attach_detach) ...@@ -677,6 +682,7 @@ TEST_F(hid_bpf, test_attach_detach)
ASSERT_EQ(err, 6) TH_LOG("read_hidraw"); ASSERT_EQ(err, 6) TH_LOG("read_hidraw");
ASSERT_EQ(buf[0], 1); ASSERT_EQ(buf[0], 1);
ASSERT_EQ(buf[2], 47); ASSERT_EQ(buf[2], 47);
ASSERT_EQ(buf[3], 52);
} }
/* /*
......
...@@ -32,6 +32,19 @@ int BPF_PROG(hid_first_event, struct hid_bpf_ctx *hid_ctx) ...@@ -32,6 +32,19 @@ int BPF_PROG(hid_first_event, struct hid_bpf_ctx *hid_ctx)
return hid_ctx->size; return hid_ctx->size;
} }
SEC("?fmod_ret/hid_bpf_device_event")
int BPF_PROG(hid_second_event, struct hid_bpf_ctx *hid_ctx)
{
__u8 *rw_data = hid_bpf_get_data(hid_ctx, 0 /* offset */, 4 /* size */);
if (!rw_data)
return 0; /* EPERM check */
rw_data[3] = rw_data[2] + 5;
return hid_ctx->size;
}
SEC("?fmod_ret/hid_bpf_device_event") SEC("?fmod_ret/hid_bpf_device_event")
int BPF_PROG(hid_change_report_id, struct hid_bpf_ctx *hid_ctx) int BPF_PROG(hid_change_report_id, struct hid_bpf_ctx *hid_ctx)
{ {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册