1*11bbc524SAthira Rajeev // SPDX-License-Identifier: GPL-2.0-only 2*11bbc524SAthira Rajeev /* 3*11bbc524SAthira Rajeev * Copyright 2022, Athira Rajeev, IBM Corp. 4*11bbc524SAthira Rajeev */ 5*11bbc524SAthira Rajeev 6*11bbc524SAthira Rajeev #include <stdio.h> 7*11bbc524SAthira Rajeev #include <stdlib.h> 8*11bbc524SAthira Rajeev 9*11bbc524SAthira Rajeev #include "../event.h" 10*11bbc524SAthira Rajeev #include "misc.h" 11*11bbc524SAthira Rajeev #include "utils.h" 12*11bbc524SAthira Rajeev 13*11bbc524SAthira Rajeev /* 14*11bbc524SAthira Rajeev * A perf sampling test for making sure 15*11bbc524SAthira Rajeev * sampling with -intr-regs doesn't crash 16*11bbc524SAthira Rajeev * in any environment, say: 17*11bbc524SAthira Rajeev * - With generic compat PMU 18*11bbc524SAthira Rajeev * - without any PMU registered 19*11bbc524SAthira Rajeev * - With platform specific PMU. 20*11bbc524SAthira Rajeev * A fix for crash with intr_regs was 21*11bbc524SAthira Rajeev * addressed in commit: f75e7d73bdf7 in kernel. 22*11bbc524SAthira Rajeev * 23*11bbc524SAthira Rajeev * This testcase exercises this code path by doing 24*11bbc524SAthira Rajeev * intr_regs using software event. Software event is 25*11bbc524SAthira Rajeev * used since s/w event will work even in platform 26*11bbc524SAthira Rajeev * without PMU. 27*11bbc524SAthira Rajeev */ intr_regs_no_crash_wo_pmu_test(void)28*11bbc524SAthira Rajeevstatic int intr_regs_no_crash_wo_pmu_test(void) 29*11bbc524SAthira Rajeev { 30*11bbc524SAthira Rajeev struct event event; 31*11bbc524SAthira Rajeev 32*11bbc524SAthira Rajeev /* 33*11bbc524SAthira Rajeev * Init the event for the sampling test. 34*11bbc524SAthira Rajeev * This uses software event which works on 35*11bbc524SAthira Rajeev * any platform. 36*11bbc524SAthira Rajeev */ 37*11bbc524SAthira Rajeev event_init_opts(&event, 0, PERF_TYPE_SOFTWARE, "cycles"); 38*11bbc524SAthira Rajeev 39*11bbc524SAthira Rajeev event.attr.sample_period = 1000; 40*11bbc524SAthira Rajeev event.attr.sample_type = PERF_SAMPLE_REGS_INTR; 41*11bbc524SAthira Rajeev event.attr.disabled = 1; 42*11bbc524SAthira Rajeev 43*11bbc524SAthira Rajeev /* 44*11bbc524SAthira Rajeev * Return code of event_open is not considered 45*11bbc524SAthira Rajeev * since test just expects no crash from using 46*11bbc524SAthira Rajeev * PERF_SAMPLE_REGS_INTR. 47*11bbc524SAthira Rajeev */ 48*11bbc524SAthira Rajeev event_open(&event); 49*11bbc524SAthira Rajeev 50*11bbc524SAthira Rajeev event_close(&event); 51*11bbc524SAthira Rajeev return 0; 52*11bbc524SAthira Rajeev } 53*11bbc524SAthira Rajeev main(void)54*11bbc524SAthira Rajeevint main(void) 55*11bbc524SAthira Rajeev { 56*11bbc524SAthira Rajeev return test_harness(intr_regs_no_crash_wo_pmu_test, "intr_regs_no_crash_wo_pmu_test"); 57*11bbc524SAthira Rajeev } 58