xref: /aosp_15_r20/external/ltp/testcases/kernel/syscalls/perf_event_open/perf_event_open.h (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  * Copyright (c) 2021 SUSE LLC <[email protected]>
4  *
5  * Common definitions for perf_event_open tests
6  */
7 
8 #ifndef PERF_EVENT_OPEN_H
9 #define PERF_EVENT_OPEN_H
10 
11 #include <linux/types.h>
12 #include <linux/perf_event.h>
13 #include <inttypes.h>
14 
perf_event_open(struct perf_event_attr * event,pid_t pid,int cpu,int group_fd,unsigned long flags)15 static int perf_event_open(struct perf_event_attr *event, pid_t pid,
16 	int cpu, int group_fd, unsigned long flags)
17 {
18 	int ret;
19 
20 	ret = tst_syscall(__NR_perf_event_open, event, pid, cpu,
21 		group_fd, flags);
22 
23 	if (ret != -1)
24 		return ret;
25 
26 	tst_res(TINFO, "%s event.type: %"PRIu32
27 		", event.config: %"PRIu64, __func__, (uint32_t)event->type,
28 		(uint64_t)event->config);
29 	if (errno == ENOENT || errno == ENODEV) {
30 		tst_brk(TCONF | TERRNO, "%s type/config not supported",
31 			__func__);
32 	}
33 	tst_brk(TBROK | TERRNO, "%s failed", __func__);
34 
35 	/* unreachable */
36 	return -1;
37 }
38 
39 #endif /* PERF_EVENT_OPEN_H */
40