summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tools/testing/selftests/hid/hid_bpf.c8
-rw-r--r--tools/testing/selftests/hid/progs/hid.c13
2 files changed, 20 insertions, 1 deletions
diff --git a/tools/testing/selftests/hid/hid_bpf.c b/tools/testing/selftests/hid/hid_bpf.c
index 6615c26fb5dd..d215bb492eb4 100644
--- a/tools/testing/selftests/hid/hid_bpf.c
+++ b/tools/testing/selftests/hid/hid_bpf.c
@@ -616,6 +616,7 @@ TEST_F(hid_bpf, test_attach_detach)
{
const struct test_program progs[] = {
{ .name = "hid_first_event" },
+ { .name = "hid_second_event" },
};
__u8 buf[10] = {0};
int err;
@@ -634,7 +635,10 @@ TEST_F(hid_bpf, test_attach_detach)
ASSERT_EQ(buf[0], 1);
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"
bpf_program__pin(self->skel->progs.hid_first_event, PIN_PATH);
remove(PIN_PATH);
@@ -660,6 +664,7 @@ TEST_F(hid_bpf, test_attach_detach)
ASSERT_EQ(buf[0], 1);
ASSERT_EQ(buf[1], 47);
ASSERT_EQ(buf[2], 0);
+ ASSERT_EQ(buf[3], 0);
/* re-attach our program */
@@ -677,6 +682,7 @@ TEST_F(hid_bpf, test_attach_detach)
ASSERT_EQ(err, 6) TH_LOG("read_hidraw");
ASSERT_EQ(buf[0], 1);
ASSERT_EQ(buf[2], 47);
+ ASSERT_EQ(buf[3], 52);
}
/*
diff --git a/tools/testing/selftests/hid/progs/hid.c b/tools/testing/selftests/hid/progs/hid.c
index 6a86af0aa545..88c593f753b5 100644
--- a/tools/testing/selftests/hid/progs/hid.c
+++ b/tools/testing/selftests/hid/progs/hid.c
@@ -33,6 +33,19 @@ int BPF_PROG(hid_first_event, struct hid_bpf_ctx *hid_ctx)
}
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")
int BPF_PROG(hid_change_report_id, struct hid_bpf_ctx *hid_ctx)
{
__u8 *rw_data = hid_bpf_get_data(hid_ctx, 0 /* offset */, 3 /* size */);