Jiri Olsa | fbf9962 | 2015-09-02 09:56:45 +0200 | [diff] [blame] | 1 | #include <api/fs/tracing_path.h> |
Jiri Olsa | 8dd2a13 | 2015-09-07 10:38:06 +0200 | [diff] [blame] | 2 | #include <linux/err.h> |
Jiri Olsa | d3b59a3 | 2012-11-10 01:46:42 +0100 | [diff] [blame] | 3 | #include "thread_map.h" |
| 4 | #include "evsel.h" |
| 5 | #include "debug.h" |
| 6 | #include "tests.h" |
| 7 | |
Arnaldo Carvalho de Melo | 721a1f5 | 2015-11-19 12:01:48 -0300 | [diff] [blame^] | 8 | int test__openat_syscall_event(int subtest __maybe_unused) |
Jiri Olsa | d3b59a3 | 2012-11-10 01:46:42 +0100 | [diff] [blame] | 9 | { |
| 10 | int err = -1, fd; |
Jiri Olsa | d3b59a3 | 2012-11-10 01:46:42 +0100 | [diff] [blame] | 11 | struct perf_evsel *evsel; |
Riku Voipio | 43f322b | 2015-04-16 16:52:53 +0300 | [diff] [blame] | 12 | unsigned int nr_openat_calls = 111, i; |
Arnaldo Carvalho de Melo | a60d795 | 2012-12-10 15:11:43 -0300 | [diff] [blame] | 13 | struct thread_map *threads = thread_map__new(-1, getpid(), UINT_MAX); |
Masami Hiramatsu | ba3dfff | 2014-08-14 02:22:45 +0000 | [diff] [blame] | 14 | char sbuf[STRERR_BUFSIZE]; |
Jiri Olsa | fbf9962 | 2015-09-02 09:56:45 +0200 | [diff] [blame] | 15 | char errbuf[BUFSIZ]; |
Jiri Olsa | d3b59a3 | 2012-11-10 01:46:42 +0100 | [diff] [blame] | 16 | |
Jiri Olsa | d3b59a3 | 2012-11-10 01:46:42 +0100 | [diff] [blame] | 17 | if (threads == NULL) { |
| 18 | pr_debug("thread_map__new\n"); |
| 19 | return -1; |
| 20 | } |
| 21 | |
Riku Voipio | 43f322b | 2015-04-16 16:52:53 +0300 | [diff] [blame] | 22 | evsel = perf_evsel__newtp("syscalls", "sys_enter_openat"); |
Jiri Olsa | 8dd2a13 | 2015-09-07 10:38:06 +0200 | [diff] [blame] | 23 | if (IS_ERR(evsel)) { |
Jiri Olsa | fbf9962 | 2015-09-02 09:56:45 +0200 | [diff] [blame] | 24 | tracing_path__strerror_open_tp(errno, errbuf, sizeof(errbuf), "syscalls", "sys_enter_openat"); |
Namhyung Kim | 8719138 | 2015-10-20 00:23:48 +0900 | [diff] [blame] | 25 | pr_debug("%s\n", errbuf); |
Jiri Olsa | d3b59a3 | 2012-11-10 01:46:42 +0100 | [diff] [blame] | 26 | 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 Hiramatsu | ba3dfff | 2014-08-14 02:22:45 +0000 | [diff] [blame] | 32 | strerror_r(errno, sbuf, sizeof(sbuf))); |
Jiri Olsa | d3b59a3 | 2012-11-10 01:46:42 +0100 | [diff] [blame] | 33 | goto out_evsel_delete; |
| 34 | } |
| 35 | |
Riku Voipio | 43f322b | 2015-04-16 16:52:53 +0300 | [diff] [blame] | 36 | for (i = 0; i < nr_openat_calls; ++i) { |
| 37 | fd = openat(0, "/etc/passwd", O_RDONLY); |
Jiri Olsa | d3b59a3 | 2012-11-10 01:46:42 +0100 | [diff] [blame] | 38 | 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 Olsa | a6fa003 | 2015-06-26 11:29:11 +0200 | [diff] [blame] | 46 | if (perf_counts(evsel->counts, 0, 0)->val != nr_openat_calls) { |
Jiri Olsa | d3b59a3 | 2012-11-10 01:46:42 +0100 | [diff] [blame] | 47 | pr_debug("perf_evsel__read_on_cpu: expected to intercept %d calls, got %" PRIu64 "\n", |
Jiri Olsa | a6fa003 | 2015-06-26 11:29:11 +0200 | [diff] [blame] | 48 | nr_openat_calls, perf_counts(evsel->counts, 0, 0)->val); |
Jiri Olsa | d3b59a3 | 2012-11-10 01:46:42 +0100 | [diff] [blame] | 49 | goto out_close_fd; |
| 50 | } |
| 51 | |
| 52 | err = 0; |
| 53 | out_close_fd: |
| 54 | perf_evsel__close_fd(evsel, 1, threads->nr); |
| 55 | out_evsel_delete: |
| 56 | perf_evsel__delete(evsel); |
| 57 | out_thread_map_delete: |
Jiri Olsa | 186fbb7 | 2015-06-23 00:36:05 +0200 | [diff] [blame] | 58 | thread_map__put(threads); |
Jiri Olsa | d3b59a3 | 2012-11-10 01:46:42 +0100 | [diff] [blame] | 59 | return err; |
| 60 | } |