blob: befc0671f95dab0162ec67c5e7ed60ea7f0c0b53 [file] [log] [blame]
Jiri Olsad3b59a32012-11-10 01:46:42 +01001#include "thread_map.h"
2#include "evsel.h"
3#include "debug.h"
4#include "tests.h"
5
6int test__open_syscall_event(void)
7{
8 int err = -1, fd;
Jiri Olsad3b59a32012-11-10 01:46:42 +01009 struct perf_evsel *evsel;
Jiri Olsad3b59a32012-11-10 01:46:42 +010010 unsigned int nr_open_calls = 111, i;
Arnaldo Carvalho de Meloa60d7952012-12-10 15:11:43 -030011 struct thread_map *threads = thread_map__new(-1, getpid(), UINT_MAX);
Jiri Olsad3b59a32012-11-10 01:46:42 +010012
Jiri Olsad3b59a32012-11-10 01:46:42 +010013 if (threads == NULL) {
14 pr_debug("thread_map__new\n");
15 return -1;
16 }
17
Arnaldo Carvalho de Meloa60d7952012-12-10 15:11:43 -030018 evsel = perf_evsel__newtp("syscalls", "sys_enter_open", 0);
Jiri Olsad3b59a32012-11-10 01:46:42 +010019 if (evsel == NULL) {
Arnaldo Carvalho de Meloa60d7952012-12-10 15:11:43 -030020 pr_debug("is debugfs mounted on /sys/kernel/debug?\n");
Jiri Olsad3b59a32012-11-10 01:46:42 +010021 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;
48out_close_fd:
49 perf_evsel__close_fd(evsel, 1, threads->nr);
50out_evsel_delete:
51 perf_evsel__delete(evsel);
52out_thread_map_delete:
53 thread_map__delete(threads);
54 return err;
55}