selftests/powerpc/pmu: Add selftest to check PMC5/6 is excluded from some constraint...
authorAthira Rajeev <atrajeev@linux.vnet.ibm.com>
Fri, 10 Jun 2022 13:40:55 +0000 (19:10 +0530)
committerMichael Ellerman <mpe@ellerman.id.au>
Tue, 28 Jun 2022 22:57:43 +0000 (08:57 +1000)
Events using Performance Monitor Counter 5 (PMC5) and Performance
Monitor Counter 6 (PMC6) should be excluded from constraint check when
scheduled along with group of events. Example, combination of PMC5,
PMC6, and an event with cache bit will succeed to schedule though first
two events doesn't have cache bit set. Testcase use three events, ie,
600f4(cycles), 500fa(instructions), 22C040 with cache bit (dc_ic) set to
test this constraint check.

Signed-off-by: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20220610134113.62991-18-atrajeev@linux.vnet.ibm.com
tools/testing/selftests/powerpc/pmu/event_code_tests/Makefile
tools/testing/selftests/powerpc/pmu/event_code_tests/group_pmc56_exclude_constraints_test.c [new file with mode: 0644]

index eb00172..c0eb289 100644 (file)
@@ -1,7 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0
 CFLAGS += -m64
 
-TEST_GEN_PROGS := group_constraint_pmc56_test
+TEST_GEN_PROGS := group_constraint_pmc56_test group_pmc56_exclude_constraints_test
 
 top_srcdir = ../../../../../..
 include ../../../lib.mk
diff --git a/tools/testing/selftests/powerpc/pmu/event_code_tests/group_pmc56_exclude_constraints_test.c b/tools/testing/selftests/powerpc/pmu/event_code_tests/group_pmc56_exclude_constraints_test.c
new file mode 100644 (file)
index 0000000..cff9ac1
--- /dev/null
@@ -0,0 +1,64 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright 2022, Athira Rajeev, IBM Corp.
+ */
+
+#include <stdio.h>
+#include "../event.h"
+#include <sys/prctl.h>
+#include <limits.h>
+#include "../sampling_tests/misc.h"
+
+/*
+ * Testcase for group constraint check for
+ * Performance Monitor Counter 5 (PMC5) and also
+ * Performance Monitor Counter 6 (PMC6).
+ * Test that pmc5/6 is excluded from constraint
+ * check when scheduled along with group of events.
+ */
+
+static int group_pmc56_exclude_constraints(void)
+{
+       struct event *e, events[3];
+       int i;
+
+       /* Check for platform support for the test */
+       SKIP_IF(platform_check_for_tests());
+
+       /*
+        * PMC5/6 is excluded from constraint bit
+        * check along with group of events. Use
+        * group of events with PMC5, PMC6 and also
+        * event with cache bit (dc_ic) set. Test expects
+        * this set of events to go in as a group.
+        */
+       e = &events[0];
+       event_init(e, 0x500fa);
+
+       e = &events[1];
+       event_init(e, 0x600f4);
+
+       e = &events[2];
+       event_init(e, 0x22C040);
+
+       FAIL_IF(event_open(&events[0]));
+
+       /*
+        * The event_open will fail if constraint check fails.
+        * Since we are asking for events in a group and since
+        * PMC5/PMC6 is excluded from group constraints, even_open
+        * should pass.
+        */
+       for (i = 1; i < 3; i++)
+               FAIL_IF(event_open_with_group(&events[i], events[0].fd));
+
+       for (i = 0; i < 3; i++)
+               event_close(&events[i]);
+
+       return 0;
+}
+
+int main(void)
+{
+       return test_harness(group_pmc56_exclude_constraints, "group_pmc56_exclude_constraints");
+}