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
17 * Sampling criteria is Load or Store only sampling
18 */
19#define EventCode_1 0x35340401e0
20#define EventCode_2 0x35540101ec
21#define EventCode_3 0x35340101ec
22
23/*
24 * Testcase for group constraint check of thresh_sel bits which is
25 * used to program thresh select field in Monitor Mode Control Register A
26 * (MMCRA: 45-57).
27 * All events in the group should match thresh sel bits otherwise
28 * event_open for the group will fail.
29 */
30static int group_constraint_thresh_sel(void)
31{
32 struct event event, leader;
33
34 /* Check for platform support for the test */
35 SKIP_IF(platform_check_for_tests());
36
37 /* Init the events for the group contraint thresh select test */
38 event_init(e: &leader, EventCode_1);
39 FAIL_IF(event_open(e: &leader));
40
41 event_init(e: &event, EventCode_2);
42
43 /* Expected to fail as sibling and leader event request different thresh_sel bits */
44 FAIL_IF(!event_open_with_group(e: &event, group_fd: leader.fd));
45
46 event_close(e: &event);
47
48 /* Init the event for the group contraint thresh select test */
49 event_init(e: &event, EventCode_3);
50
51 /* Expected to succeed as sibling and leader event request same thresh_sel bits */
52 FAIL_IF(event_open_with_group(e: &event, group_fd: leader.fd));
53
54 event_close(e: &leader);
55 event_close(e: &event);
56
57 return 0;
58}
59
60int main(void)
61{
62 return test_harness(group_constraint_thresh_sel, "group_constraint_thresh_sel");
63}
64

source code of linux/tools/testing/selftests/powerpc/pmu/event_code_tests/group_constraint_thresh_sel_test.c