1*38b6da45SAthira Rajeev // SPDX-License-Identifier: GPL-2.0-only
2*38b6da45SAthira Rajeev /*
3*38b6da45SAthira Rajeev  * Copyright 2022, Athira Rajeev, IBM Corp.
4*38b6da45SAthira Rajeev  */
5*38b6da45SAthira Rajeev 
6*38b6da45SAthira Rajeev #include <stdio.h>
7*38b6da45SAthira Rajeev #include "../event.h"
8*38b6da45SAthira Rajeev #include "../sampling_tests/misc.h"
9*38b6da45SAthira Rajeev 
10*38b6da45SAthira Rajeev /* The processor's L1 data cache was reloaded */
11*38b6da45SAthira Rajeev #define EventCode1 0x21C040
12*38b6da45SAthira Rajeev #define EventCode2 0x22C040
13*38b6da45SAthira Rajeev 
14*38b6da45SAthira Rajeev /*
15*38b6da45SAthira Rajeev  * Testcase for group constraint check
16*38b6da45SAthira Rajeev  * when using events with same PMC.
17*38b6da45SAthira Rajeev  * Multiple events in a group shouldn't
18*38b6da45SAthira Rajeev  * ask for same PMC. If so it should fail.
19*38b6da45SAthira Rajeev  */
20*38b6da45SAthira Rajeev 
group_constraint_repeat(void)21*38b6da45SAthira Rajeev static int group_constraint_repeat(void)
22*38b6da45SAthira Rajeev {
23*38b6da45SAthira Rajeev 	struct event event, leader;
24*38b6da45SAthira Rajeev 
25*38b6da45SAthira Rajeev 	/* Check for platform support for the test */
26*38b6da45SAthira Rajeev 	SKIP_IF(platform_check_for_tests());
27*38b6da45SAthira Rajeev 
28*38b6da45SAthira Rajeev 	/*
29*38b6da45SAthira Rajeev 	 * Two events in a group using same PMC
30*38b6da45SAthira Rajeev 	 * should fail to get scheduled. Usei same PMC2
31*38b6da45SAthira Rajeev 	 * for leader and sibling event which is expected
32*38b6da45SAthira Rajeev 	 * to fail.
33*38b6da45SAthira Rajeev 	 */
34*38b6da45SAthira Rajeev 	event_init(&leader, EventCode1);
35*38b6da45SAthira Rajeev 	FAIL_IF(event_open(&leader));
36*38b6da45SAthira Rajeev 
37*38b6da45SAthira Rajeev 	event_init(&event, EventCode1);
38*38b6da45SAthira Rajeev 
39*38b6da45SAthira Rajeev 	/* Expected to fail since sibling event is requesting same PMC as leader */
40*38b6da45SAthira Rajeev 	FAIL_IF(!event_open_with_group(&event, leader.fd));
41*38b6da45SAthira Rajeev 
42*38b6da45SAthira Rajeev 	event_init(&event, EventCode2);
43*38b6da45SAthira Rajeev 
44*38b6da45SAthira Rajeev 	/* Expected to pass since sibling event is requesting different PMC */
45*38b6da45SAthira Rajeev 	FAIL_IF(event_open_with_group(&event, leader.fd));
46*38b6da45SAthira Rajeev 
47*38b6da45SAthira Rajeev 	event_close(&leader);
48*38b6da45SAthira Rajeev 	event_close(&event);
49*38b6da45SAthira Rajeev 
50*38b6da45SAthira Rajeev 	return 0;
51*38b6da45SAthira Rajeev }
52*38b6da45SAthira Rajeev 
main(void)53*38b6da45SAthira Rajeev int main(void)
54*38b6da45SAthira Rajeev {
55*38b6da45SAthira Rajeev 	return test_harness(group_constraint_repeat, "group_constraint_repeat");
56*38b6da45SAthira Rajeev }
57