0001
0002 #include <signal.h>
0003 #include <stdlib.h>
0004
0005 #include "tests.h"
0006 #include "debug.h"
0007 #include "perf-hooks.h"
0008
0009 static void sigsegv_handler(int sig __maybe_unused)
0010 {
0011 pr_debug("SIGSEGV is observed as expected, try to recover.\n");
0012 perf_hooks__recover();
0013 signal(SIGSEGV, SIG_DFL);
0014 raise(SIGSEGV);
0015 exit(-1);
0016 }
0017
0018
0019 static void the_hook(void *_hook_flags)
0020 {
0021 int *hook_flags = _hook_flags;
0022
0023 *hook_flags = 1234;
0024
0025
0026 raise(SIGSEGV);
0027 }
0028
0029 static int test__perf_hooks(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
0030 {
0031 int hook_flags = 0;
0032
0033 signal(SIGSEGV, sigsegv_handler);
0034 perf_hooks__set_hook("test", the_hook, &hook_flags);
0035 perf_hooks__invoke_test();
0036
0037
0038 if (hook_flags != 1234) {
0039 pr_debug("Setting failed: %d (%p)\n", hook_flags, &hook_flags);
0040 return TEST_FAIL;
0041 }
0042
0043
0044 if (perf_hooks__get_hook("test"))
0045 return TEST_FAIL;
0046 return TEST_OK;
0047 }
0048
0049 DEFINE_SUITE("perf hooks", perf_hooks);