aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/tests/perf-hooks.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf/tests/perf-hooks.c')
-rw-r--r--tools/perf/tests/perf-hooks.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/tools/perf/tests/perf-hooks.c b/tools/perf/tests/perf-hooks.c
new file mode 100644
index 000000000000..9338cb2c25ab
--- /dev/null
+++ b/tools/perf/tests/perf-hooks.c
@@ -0,0 +1,44 @@
1#include <signal.h>
2#include <stdlib.h>
3
4#include "tests.h"
5#include "debug.h"
6#include "util.h"
7#include "perf-hooks.h"
8
9static void sigsegv_handler(int sig __maybe_unused)
10{
11 pr_debug("SIGSEGV is observed as expected, try to recover.\n");
12 perf_hooks__recover();
13 signal(SIGSEGV, SIG_DFL);
14 raise(SIGSEGV);
15 exit(-1);
16}
17
18static int hook_flags;
19
20static void the_hook(void)
21{
22 int *p = NULL;
23
24 hook_flags = 1234;
25
26 /* Generate a segfault, test perf_hooks__recover */
27 *p = 0;
28}
29
30int test__perf_hooks(int subtest __maybe_unused)
31{
32 signal(SIGSEGV, sigsegv_handler);
33 perf_hooks__set_hook("test", the_hook);
34 perf_hooks__invoke_test();
35
36 /* hook is triggered? */
37 if (hook_flags != 1234)
38 return TEST_FAIL;
39
40 /* the buggy hook is removed? */
41 if (perf_hooks__get_hook("test"))
42 return TEST_FAIL;
43 return TEST_OK;
44}