Merge tag 'locks-v3.16-2' of git://git.samba.org/jlayton/linux
[linux/fpc-iii.git] / tools / perf / tests / open-syscall.c
blobc1dc7d25f38c6170847c74188ec5bac6d08e06f0
1 #include "thread_map.h"
2 #include "evsel.h"
3 #include "debug.h"
4 #include "tests.h"
6 int test__open_syscall_event(void)
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);
13 if (threads == NULL) {
14 pr_debug("thread_map__new\n");
15 return -1;
18 evsel = perf_evsel__newtp("syscalls", "sys_enter_open");
19 if (evsel == NULL) {
20 pr_debug("is debugfs mounted on /sys/kernel/debug?\n");
21 goto out_thread_map_delete;
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;
31 for (i = 0; i < nr_open_calls; ++i) {
32 fd = open("/etc/passwd", O_RDONLY);
33 close(fd);
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;
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;
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;