1f50a7f3dSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
23752e453SMichael Ellerman /*
33752e453SMichael Ellerman  * Copyright 2014, Michael Ellerman, IBM Corp.
43752e453SMichael Ellerman  */
53752e453SMichael Ellerman 
63752e453SMichael Ellerman #include <stdio.h>
73752e453SMichael Ellerman #include <stdlib.h>
83752e453SMichael Ellerman #include <setjmp.h>
93752e453SMichael Ellerman #include <signal.h>
103752e453SMichael Ellerman 
113752e453SMichael Ellerman #include "ebb.h"
123752e453SMichael Ellerman 
133752e453SMichael Ellerman 
143752e453SMichael Ellerman /* Test that things work sanely if we have no handler */
153752e453SMichael Ellerman 
no_handler_test(void)163752e453SMichael Ellerman static int no_handler_test(void)
173752e453SMichael Ellerman {
183752e453SMichael Ellerman 	struct event event;
193752e453SMichael Ellerman 	u64 val;
203752e453SMichael Ellerman 	int i;
213752e453SMichael Ellerman 
2239fcfb91SDenis Kirjanov 	SKIP_IF(!ebb_is_supported());
2339fcfb91SDenis Kirjanov 
243752e453SMichael Ellerman 	event_init_named(&event, 0x1001e, "cycles");
253752e453SMichael Ellerman 	event_leader_ebb_init(&event);
263752e453SMichael Ellerman 
273752e453SMichael Ellerman 	event.attr.exclude_kernel = 1;
283752e453SMichael Ellerman 	event.attr.exclude_hv = 1;
293752e453SMichael Ellerman 	event.attr.exclude_idle = 1;
303752e453SMichael Ellerman 
313752e453SMichael Ellerman 	FAIL_IF(event_open(&event));
323752e453SMichael Ellerman 	FAIL_IF(ebb_event_enable(&event));
333752e453SMichael Ellerman 
343752e453SMichael Ellerman 	val = mfspr(SPRN_EBBHR);
353752e453SMichael Ellerman 	FAIL_IF(val != 0);
363752e453SMichael Ellerman 
373752e453SMichael Ellerman 	/* Make sure it overflows quickly */
383752e453SMichael Ellerman 	sample_period = 1000;
393752e453SMichael Ellerman 	mtspr(SPRN_PMC1, pmc_sample_period(sample_period));
403752e453SMichael Ellerman 
413752e453SMichael Ellerman 	/* Spin to make sure the event has time to overflow */
423752e453SMichael Ellerman 	for (i = 0; i < 1000; i++)
433752e453SMichael Ellerman 		mb();
443752e453SMichael Ellerman 
453752e453SMichael Ellerman 	dump_ebb_state();
463752e453SMichael Ellerman 
473752e453SMichael Ellerman 	/* We expect to see the PMU frozen & PMAO set */
483752e453SMichael Ellerman 	val = mfspr(SPRN_MMCR0);
493752e453SMichael Ellerman 	FAIL_IF(val != 0x0000000080000080);
503752e453SMichael Ellerman 
513752e453SMichael Ellerman 	event_close(&event);
523752e453SMichael Ellerman 
533752e453SMichael Ellerman 	/* The real test is that we never took an EBB at 0x0 */
543752e453SMichael Ellerman 
553752e453SMichael Ellerman 	return 0;
563752e453SMichael Ellerman }
573752e453SMichael Ellerman 
main(void)583752e453SMichael Ellerman int main(void)
593752e453SMichael Ellerman {
603752e453SMichael Ellerman 	return test_harness(no_handler_test,"no_handler_test");
613752e453SMichael Ellerman }
62