Skip to content

Commit 9c1db67

Browse files
committed
selftests/bpf: Add uprobe_multi path_fd fail tests
Adding tests to attach_api_fails suite to make sure we fail wrong setup for path_fd usage. Signed-off-by: Jiri Olsa <jolsa@kernel.org>
1 parent 363a5e4 commit 9c1db67

1 file changed

Lines changed: 31 additions & 1 deletion

File tree

tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,37 @@ static void test_attach_api_fails(void)
537537
link_fd = bpf_link_create(prog_fd, 0, BPF_TRACE_UPROBE_MULTI, &opts);
538538
if (!ASSERT_ERR(link_fd, "link_fd"))
539539
goto cleanup;
540-
ASSERT_EQ(link_fd, -EINVAL, "pid_is_wrong");
540+
if (!ASSERT_EQ(link_fd, -EINVAL, "pid_is_wrong"))
541+
goto cleanup;
542+
543+
/* wrong path_fd */
544+
LIBBPF_OPTS_RESET(opts,
545+
.uprobe_multi.path = NULL,
546+
.uprobe_multi.path_fd = -1,
547+
.uprobe_multi.flags = BPF_F_UPROBE_MULTI_PATH_FD,
548+
.uprobe_multi.offsets = (unsigned long *) &offset,
549+
.uprobe_multi.cnt = 1,
550+
);
551+
552+
link_fd = bpf_link_create(prog_fd, 0, BPF_TRACE_UPROBE_MULTI, &opts);
553+
if (!ASSERT_ERR(link_fd, "link_fd"))
554+
goto cleanup;
555+
if (!ASSERT_EQ(link_fd, -EBADF, "path_fd_is_wrong"))
556+
goto cleanup;
557+
558+
/* path and path_fd both set with BPF_F_UPROBE_MULTI_PATH_FD flag */
559+
LIBBPF_OPTS_RESET(opts,
560+
.uprobe_multi.path = path,
561+
.uprobe_multi.path_fd = 1,
562+
.uprobe_multi.flags = BPF_F_UPROBE_MULTI_PATH_FD,
563+
.uprobe_multi.offsets = (unsigned long *) &offset,
564+
.uprobe_multi.cnt = 1,
565+
);
566+
567+
link_fd = bpf_link_create(prog_fd, 0, BPF_TRACE_UPROBE_MULTI, &opts);
568+
if (!ASSERT_ERR(link_fd, "link_fd"))
569+
goto cleanup;
570+
ASSERT_EQ(link_fd, -EINVAL, "path_and_path_fd_together");
541571

542572
cleanup:
543573
if (link_fd >= 0)

0 commit comments

Comments
 (0)