If the transport driver returns an error, we should ensure we actually
get the error, not a success value.

Signed-off-by: Benjamin Tissoires <[email protected]>
---
 tools/testing/selftests/hid/hid_bpf.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/tools/testing/selftests/hid/hid_bpf.c 
b/tools/testing/selftests/hid/hid_bpf.c
index 32d81ba15a25..8c41ebfb85e4 100644
--- a/tools/testing/selftests/hid/hid_bpf.c
+++ b/tools/testing/selftests/hid/hid_bpf.c
@@ -546,6 +546,37 @@ TEST_F(hid_bpf, test_hid_user_raw_request_call)
        ASSERT_EQ(args.data[1], 2);
 }
 
+/*
+ * Call hid_hw_raw_request against the given uhid device,
+ * check that the program is called and does the expected.
+ */
+TEST_F(hid_bpf, test_hid_user_raw_request_call_eio)
+{
+       struct hid_hw_request_syscall_args args = {
+               .retval = -1,
+               .type = HID_FEATURE_REPORT,
+               .request_type = HID_REQ_GET_PROTOCOL,
+               .size = MAX_BUF_SIZE,
+       };
+       DECLARE_LIBBPF_OPTS(bpf_test_run_opts, tattrs,
+                           .ctx_in = &args,
+                           .ctx_size_in = sizeof(args),
+       );
+       int err, prog_fd;
+
+       LOAD_BPF;
+
+       args.hid = self->hid.hid_id;
+       args.data[0] = 1; /* report ID */
+
+       prog_fd = bpf_program__fd(self->skel->progs.hid_user_raw_request);
+
+       err = bpf_prog_test_run_opts(prog_fd, &tattrs);
+       ASSERT_OK(err) TH_LOG("error while calling bpf_prog_test_run_opts");
+
+       ASSERT_EQ(args.retval, -EIO);
+}
+
 /*
  * Call hid_hw_raw_request against the given uhid device,
  * check that the program is called and prevents the

-- 
2.55.0


Reply via email to