1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Copyright 2022, Athira Rajeev, IBM Corp.
4  */
5 
6 #include <stdio.h>
7 #include "../event.h"
8 #include <sys/prctl.h>
9 #include <limits.h>
10 #include "../sampling_tests/misc.h"
11 
12 /*
13  * Testcase for group constraint check for
14  * Performance Monitor Counter 5 (PMC5) and also
15  * Performance Monitor Counter 6 (PMC6).
16  * Test that pmc5/6 is excluded from constraint
17  * check when scheduled along with group of events.
18  */
19 
20 static int group_pmc56_exclude_constraints(void)
21 {
22 	struct event *e, events[3];
23 	int i;
24 
25 	/* Check for platform support for the test */
26 	SKIP_IF(platform_check_for_tests());
27 
28 	/*
29 	 * PMC5/6 is excluded from constraint bit
30 	 * check along with group of events. Use
31 	 * group of events with PMC5, PMC6 and also
32 	 * event with cache bit (dc_ic) set. Test expects
33 	 * this set of events to go in as a group.
34 	 */
35 	e = &events[0];
36 	event_init(e, 0x500fa);
37 
38 	e = &events[1];
39 	event_init(e, 0x600f4);
40 
41 	e = &events[2];
42 	event_init(e, 0x22C040);
43 
44 	FAIL_IF(event_open(&events[0]));
45 
46 	/*
47 	 * The event_open will fail if constraint check fails.
48 	 * Since we are asking for events in a group and since
49 	 * PMC5/PMC6 is excluded from group constraints, even_open
50 	 * should pass.
51 	 */
52 	for (i = 1; i < 3; i++)
53 		FAIL_IF(event_open_with_group(&events[i], events[0].fd));
54 
55 	for (i = 0; i < 3; i++)
56 		event_close(&events[i]);
57 
58 	return 0;
59 }
60 
61 int main(void)
62 {
63 	return test_harness(group_pmc56_exclude_constraints, "group_pmc56_exclude_constraints");
64 }
65