xref: /linux/tools/testing/selftests/powerpc/pmu/ebb/event_attributes_test.c (revision 3932b9ca55b0be314a36d3e84faff3e823c081f5)
1 /*
2  * Copyright 2014, Michael Ellerman, IBM Corp.
3  * Licensed under GPLv2.
4  */
5 
6 #include <stdio.h>
7 #include <stdlib.h>
8 
9 #include "ebb.h"
10 
11 
12 /*
13  * Test various attributes of the EBB event are enforced.
14  */
15 int event_attributes(void)
16 {
17 	struct event event, leader;
18 
19 	event_init(&event, 0x1001e);
20 	event_leader_ebb_init(&event);
21 	/* Expected to succeed */
22 	FAIL_IF(event_open(&event));
23 	event_close(&event);
24 
25 
26 	event_init(&event, 0x001e); /* CYCLES - no PMC specified */
27 	event_leader_ebb_init(&event);
28 	/* Expected to fail, no PMC specified */
29 	FAIL_IF(event_open(&event) == 0);
30 
31 
32 	event_init(&event, 0x2001e);
33 	event_leader_ebb_init(&event);
34 	event.attr.exclusive = 0;
35 	/* Expected to fail, not exclusive */
36 	FAIL_IF(event_open(&event) == 0);
37 
38 
39 	event_init(&event, 0x3001e);
40 	event_leader_ebb_init(&event);
41 	event.attr.freq = 1;
42 	/* Expected to fail, sets freq */
43 	FAIL_IF(event_open(&event) == 0);
44 
45 
46 	event_init(&event, 0x4001e);
47 	event_leader_ebb_init(&event);
48 	event.attr.sample_period = 1;
49 	/* Expected to fail, sets sample_period */
50 	FAIL_IF(event_open(&event) == 0);
51 
52 
53 	event_init(&event, 0x1001e);
54 	event_leader_ebb_init(&event);
55 	event.attr.enable_on_exec = 1;
56 	/* Expected to fail, sets enable_on_exec */
57 	FAIL_IF(event_open(&event) == 0);
58 
59 
60 	event_init(&event, 0x1001e);
61 	event_leader_ebb_init(&event);
62 	event.attr.inherit = 1;
63 	/* Expected to fail, sets inherit */
64 	FAIL_IF(event_open(&event) == 0);
65 
66 
67 	event_init(&leader, 0x1001e);
68 	event_leader_ebb_init(&leader);
69 	FAIL_IF(event_open(&leader));
70 
71 	event_init(&event, 0x20002);
72 	event_ebb_init(&event);
73 
74 	/* Expected to succeed */
75 	FAIL_IF(event_open_with_group(&event, leader.fd));
76 	event_close(&leader);
77 	event_close(&event);
78 
79 
80 	event_init(&leader, 0x1001e);
81 	event_leader_ebb_init(&leader);
82 	FAIL_IF(event_open(&leader));
83 
84 	event_init(&event, 0x20002);
85 
86 	/* Expected to fail, event doesn't request EBB, leader does */
87 	FAIL_IF(event_open_with_group(&event, leader.fd) == 0);
88 	event_close(&leader);
89 
90 
91 	event_init(&leader, 0x1001e);
92 	event_leader_ebb_init(&leader);
93 	/* Clear the EBB flag */
94 	leader.attr.config &= ~(1ull << 63);
95 
96 	FAIL_IF(event_open(&leader));
97 
98 	event_init(&event, 0x20002);
99 	event_ebb_init(&event);
100 
101 	/* Expected to fail, leader doesn't request EBB */
102 	FAIL_IF(event_open_with_group(&event, leader.fd) == 0);
103 	event_close(&leader);
104 
105 
106 	event_init(&leader, 0x1001e);
107 	event_leader_ebb_init(&leader);
108 	leader.attr.exclusive = 0;
109 	/* Expected to fail, leader isn't exclusive */
110 	FAIL_IF(event_open(&leader) == 0);
111 
112 
113 	event_init(&leader, 0x1001e);
114 	event_leader_ebb_init(&leader);
115 	leader.attr.pinned = 0;
116 	/* Expected to fail, leader isn't pinned */
117 	FAIL_IF(event_open(&leader) == 0);
118 
119 	event_init(&event, 0x1001e);
120 	event_leader_ebb_init(&event);
121 	/* Expected to fail, not a task event */
122 	SKIP_IF(require_paranoia_below(1));
123 	FAIL_IF(event_open_with_cpu(&event, 0) == 0);
124 
125 	return 0;
126 }
127 
128 int main(void)
129 {
130 	return test_harness(event_attributes, "event_attributes");
131 }
132