1 // SPDX-License-Identifier: GPL-2.0
2 #include <test_progs.h>
4 void test_task_fd_query_rawtp(void)
6 const char *file
= "./test_get_stack_rawtp.o";
7 __u64 probe_offset
, probe_addr
;
8 __u32 len
, prog_id
, fd_type
;
9 struct bpf_object
*obj
;
10 int efd
, err
, prog_fd
;
14 err
= bpf_prog_load(file
, BPF_PROG_TYPE_RAW_TRACEPOINT
, &obj
, &prog_fd
);
15 if (CHECK(err
, "prog_load raw tp", "err %d errno %d\n", err
, errno
))
18 efd
= bpf_raw_tracepoint_open("sys_enter", prog_fd
);
19 if (CHECK(efd
< 0, "raw_tp_open", "err %d errno %d\n", efd
, errno
))
22 /* query (getpid(), efd) */
24 err
= bpf_task_fd_query(getpid(), efd
, 0, buf
, &len
, &prog_id
,
25 &fd_type
, &probe_offset
, &probe_addr
);
26 if (CHECK(err
< 0, "bpf_task_fd_query", "err %d errno %d\n", err
,
30 err
= fd_type
== BPF_FD_TYPE_RAW_TRACEPOINT
&&
31 strcmp(buf
, "sys_enter") == 0;
32 if (CHECK(!err
, "check_results", "fd_type %d tp_name %s\n",
38 err
= bpf_task_fd_query(getpid(), efd
, 0, buf
, &len
, &prog_id
,
39 &fd_type
, &probe_offset
, &probe_addr
);
40 if (CHECK(err
< 0, "bpf_task_fd_query (len = 0)", "err %d errno %d\n",
43 err
= fd_type
== BPF_FD_TYPE_RAW_TRACEPOINT
&&
44 len
== strlen("sys_enter");
45 if (CHECK(!err
, "check_results", "fd_type %d len %u\n", fd_type
, len
))
48 /* test empty buffer */
50 err
= bpf_task_fd_query(getpid(), efd
, 0, 0, &len
, &prog_id
,
51 &fd_type
, &probe_offset
, &probe_addr
);
52 if (CHECK(err
< 0, "bpf_task_fd_query (buf = 0)", "err %d errno %d\n",
55 err
= fd_type
== BPF_FD_TYPE_RAW_TRACEPOINT
&&
56 len
== strlen("sys_enter");
57 if (CHECK(!err
, "check_results", "fd_type %d len %u\n", fd_type
, len
))
60 /* test smaller buffer */
62 err
= bpf_task_fd_query(getpid(), efd
, 0, buf
, &len
, &prog_id
,
63 &fd_type
, &probe_offset
, &probe_addr
);
64 if (CHECK(err
>= 0 || errno
!= ENOSPC
, "bpf_task_fd_query (len = 3)",
65 "err %d errno %d\n", err
, errno
))
67 err
= fd_type
== BPF_FD_TYPE_RAW_TRACEPOINT
&&
68 len
== strlen("sys_enter") &&
69 strcmp(buf
, "sy") == 0;
70 if (CHECK(!err
, "check_results", "fd_type %d len %u\n", fd_type
, len
))
73 goto close_prog_noerr
;
77 bpf_object__close(obj
);