blob: 7b1db8306098b40b97aa9053960ba0b160509318 [file] [log] [blame]
Jiri Olsafbf99622015-09-02 09:56:45 +02001#include <api/fs/tracing_path.h>
Jiri Olsa8dd2a132015-09-07 10:38:06 +02002#include <linux/err.h>
Jiri Olsad3b59a32012-11-10 01:46:42 +01003#include "thread_map.h"
4#include "evsel.h"
5#include "debug.h"
6#include "tests.h"
7
Riku Voipio43f322b2015-04-16 16:52:53 +03008int test__openat_syscall_event(void)
Jiri Olsad3b59a32012-11-10 01:46:42 +01009{
10 int err = -1, fd;
Jiri Olsad3b59a32012-11-10 01:46:42 +010011 struct perf_evsel *evsel;
Riku Voipio43f322b2015-04-16 16:52:53 +030012 unsigned int nr_openat_calls = 111, i;
Arnaldo Carvalho de Meloa60d7952012-12-10 15:11:43 -030013 struct thread_map *threads = thread_map__new(-1, getpid(), UINT_MAX);
Masami Hiramatsuba3dfff2014-08-14 02:22:45 +000014 char sbuf[STRERR_BUFSIZE];
Jiri Olsafbf99622015-09-02 09:56:45 +020015 char errbuf[BUFSIZ];
Jiri Olsad3b59a32012-11-10 01:46:42 +010016
Jiri Olsad3b59a32012-11-10 01:46:42 +010017 if (threads == NULL) {
18 pr_debug("thread_map__new\n");
19 return -1;
20 }
21
Riku Voipio43f322b2015-04-16 16:52:53 +030022 evsel = perf_evsel__newtp("syscalls", "sys_enter_openat");
Jiri Olsa8dd2a132015-09-07 10:38:06 +020023 if (IS_ERR(evsel)) {
Jiri Olsafbf99622015-09-02 09:56:45 +020024 tracing_path__strerror_open_tp(errno, errbuf, sizeof(errbuf), "syscalls", "sys_enter_openat");
25 pr_err("%s\n", errbuf);
Jiri Olsad3b59a32012-11-10 01:46:42 +010026 goto out_thread_map_delete;
27 }
28
29 if (perf_evsel__open_per_thread(evsel, threads) < 0) {
30 pr_debug("failed to open counter: %s, "
31 "tweak /proc/sys/kernel/perf_event_paranoid?\n",
Masami Hiramatsuba3dfff2014-08-14 02:22:45 +000032 strerror_r(errno, sbuf, sizeof(sbuf)));
Jiri Olsad3b59a32012-11-10 01:46:42 +010033 goto out_evsel_delete;
34 }
35
Riku Voipio43f322b2015-04-16 16:52:53 +030036 for (i = 0; i < nr_openat_calls; ++i) {
37 fd = openat(0, "/etc/passwd", O_RDONLY);
Jiri Olsad3b59a32012-11-10 01:46:42 +010038 close(fd);
39 }
40
41 if (perf_evsel__read_on_cpu(evsel, 0, 0) < 0) {
42 pr_debug("perf_evsel__read_on_cpu\n");
43 goto out_close_fd;
44 }
45
Jiri Olsaa6fa0032015-06-26 11:29:11 +020046 if (perf_counts(evsel->counts, 0, 0)->val != nr_openat_calls) {
Jiri Olsad3b59a32012-11-10 01:46:42 +010047 pr_debug("perf_evsel__read_on_cpu: expected to intercept %d calls, got %" PRIu64 "\n",
Jiri Olsaa6fa0032015-06-26 11:29:11 +020048 nr_openat_calls, perf_counts(evsel->counts, 0, 0)->val);
Jiri Olsad3b59a32012-11-10 01:46:42 +010049 goto out_close_fd;
50 }
51
52 err = 0;
53out_close_fd:
54 perf_evsel__close_fd(evsel, 1, threads->nr);
55out_evsel_delete:
56 perf_evsel__delete(evsel);
57out_thread_map_delete:
Jiri Olsa186fbb72015-06-23 00:36:05 +020058 thread_map__put(threads);
Jiri Olsad3b59a32012-11-10 01:46:42 +010059 return err;
60}