1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Copyright 2022, Athira Rajeev, IBM Corp.
4  */
5 
6 #include <stdio.h>
7 #include <stdlib.h>
8 
9 #include "../event.h"
10 #include "misc.h"
11 #include "utils.h"
12 
13 /*
14  * A perf sampling test for making sure
15  * sampling with -intr-regs doesn't crash
16  * in any environment, say:
17  *  - With generic compat PMU
18  *  - without any PMU registered
19  *  - With platform specific PMU.
20  *  A fix for crash with intr_regs was
21  *  addressed in commit: f75e7d73bdf7 in kernel.
22  *
23  * This testcase exercises this code path by doing
24  * intr_regs using software event. Software event is
25  * used since s/w event will work even in platform
26  * without PMU.
27  */
28 static int intr_regs_no_crash_wo_pmu_test(void)
29 {
30 	struct event event;
31 
32 	/*
33 	 * Init the event for the sampling test.
34 	 * This uses software event which works on
35 	 * any platform.
36 	 */
37 	event_init_opts(&event, 0, PERF_TYPE_SOFTWARE, "cycles");
38 
39 	event.attr.sample_period = 1000;
40 	event.attr.sample_type = PERF_SAMPLE_REGS_INTR;
41 	event.attr.disabled = 1;
42 
43 	/*
44 	 * Return code of event_open is not considered
45 	 * since test just expects no crash from using
46 	 * PERF_SAMPLE_REGS_INTR.
47 	 */
48 	event_open(&event);
49 
50 	event_close(&event);
51 	return 0;
52 }
53 
54 int main(void)
55 {
56 	return test_harness(intr_regs_no_crash_wo_pmu_test, "intr_regs_no_crash_wo_pmu_test");
57 }
58