1 #include "thread_map.h"
2 #include "evsel.h"
3 #include "debug.h"
4 #include "tests.h"
5
test__open_syscall_event(void)6 int test__open_syscall_event(void)
7 {
8 int err = -1, fd;
9 struct perf_evsel *evsel;
10 unsigned int nr_open_calls = 111, i;
11 struct thread_map *threads = thread_map__new(-1, getpid(), UINT_MAX);
12
13 if (threads == NULL) {
14 pr_debug("thread_map__new\n");
15 return -1;
16 }
17
18 evsel = perf_evsel__newtp("syscalls", "sys_enter_open", 0);
19 if (evsel == NULL) {
20 pr_debug("is debugfs mounted on /sys/kernel/debug?\n");
21 goto out_thread_map_delete;
22 }
23
24 if (perf_evsel__open_per_thread(evsel, threads) < 0) {
25 pr_debug("failed to open counter: %s, "
26 "tweak /proc/sys/kernel/perf_event_paranoid?\n",
27 strerror(errno));
28 goto out_evsel_delete;
29 }
30
31 for (i = 0; i < nr_open_calls; ++i) {
32 fd = open("/etc/passwd", O_RDONLY);
33 close(fd);
34 }
35
36 if (perf_evsel__read_on_cpu(evsel, 0, 0) < 0) {
37 pr_debug("perf_evsel__read_on_cpu\n");
38 goto out_close_fd;
39 }
40
41 if (evsel->counts->cpu[0].val != nr_open_calls) {
42 pr_debug("perf_evsel__read_on_cpu: expected to intercept %d calls, got %" PRIu64 "\n",
43 nr_open_calls, evsel->counts->cpu[0].val);
44 goto out_close_fd;
45 }
46
47 err = 0;
48 out_close_fd:
49 perf_evsel__close_fd(evsel, 1, threads->nr);
50 out_evsel_delete:
51 perf_evsel__delete(evsel);
52 out_thread_map_delete:
53 thread_map__delete(threads);
54 return err;
55 }
56