1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * Copyright 2022, Kajol Jain, IBM Corp.
4 */
5
6#include <stdio.h>
7#include <stdlib.h>
8
9#include "../event.h"
10#include "utils.h"
11#include "../sampling_tests/misc.h"
12
13/*
14 * Primary PMU events used here are PM_MRK_INST_CMPL (0x401e0) and
15 * PM_THRESH_MET (0x101ec).
16 * Threshold event selection used is issue to complete and issue to
17 * finished for cycles
18 * Sampling criteria is Load or Store only sampling
19 */
20#define EventCode_1 0x35340401e0
21#define EventCode_2 0x34340101ec
22#define EventCode_3 0x35340101ec
23
24/*
25 * Testcase for group constraint check of thresh_ctl bits which is
26 * used to program thresh compare field in Monitor Mode Control Register A
27 * (MMCR0: 48-55).
28 * All events in the group should match thresh ctl bits otherwise
29 * event_open for the group will fail.
30 */
31static int group_constraint_thresh_ctl(void)
32{
33	struct event event, leader;
34
35	/* Check for platform support for the test */
36	SKIP_IF(platform_check_for_tests());
37
38	/* Init the events for the group contraint thresh control test */
39	event_init(&leader, EventCode_1);
40	FAIL_IF(event_open(&leader));
41
42	event_init(&event, EventCode_2);
43
44	/* Expected to fail as sibling and leader event request different thresh_ctl bits */
45	FAIL_IF(!event_open_with_group(&event, leader.fd));
46
47	event_close(&event);
48
49	/* Init the event for the group contraint thresh control test */
50	event_init(&event, EventCode_3);
51
52	 /* Expected to succeed as sibling and leader event request same thresh_ctl bits */
53	FAIL_IF(event_open_with_group(&event, leader.fd));
54
55	event_close(&leader);
56	event_close(&event);
57
58	return 0;
59}
60
61int main(void)
62{
63	return test_harness(group_constraint_thresh_ctl, "group_constraint_thresh_ctl");
64}
65