1fbf99625SJiri Olsa #include <api/fs/tracing_path.h> 28dd2a131SJiri Olsa #include <linux/err.h> 3fbb2df23SRiku Voipio #include "thread_map.h" 4fbb2df23SRiku Voipio #include "evsel.h" 5fbb2df23SRiku Voipio #include "debug.h" 6fbb2df23SRiku Voipio #include "tests.h" 7fbb2df23SRiku Voipio 8fbb2df23SRiku Voipio int test__openat_syscall_event(void) 9fbb2df23SRiku Voipio { 10fbb2df23SRiku Voipio int err = -1, fd; 11fbb2df23SRiku Voipio struct perf_evsel *evsel; 12fbb2df23SRiku Voipio unsigned int nr_openat_calls = 111, i; 13fbb2df23SRiku Voipio struct thread_map *threads = thread_map__new(-1, getpid(), UINT_MAX); 14fbb2df23SRiku Voipio char sbuf[STRERR_BUFSIZE]; 15fbf99625SJiri Olsa char errbuf[BUFSIZ]; 16fbb2df23SRiku Voipio 17fbb2df23SRiku Voipio if (threads == NULL) { 18fbb2df23SRiku Voipio pr_debug("thread_map__new\n"); 19fbb2df23SRiku Voipio return -1; 20fbb2df23SRiku Voipio } 21fbb2df23SRiku Voipio 22fbb2df23SRiku Voipio evsel = perf_evsel__newtp("syscalls", "sys_enter_openat"); 238dd2a131SJiri Olsa if (IS_ERR(evsel)) { 24fbf99625SJiri Olsa tracing_path__strerror_open_tp(errno, errbuf, sizeof(errbuf), "syscalls", "sys_enter_openat"); 25*87191383SNamhyung Kim pr_debug("%s\n", errbuf); 26fbb2df23SRiku Voipio goto out_thread_map_delete; 27fbb2df23SRiku Voipio } 28fbb2df23SRiku Voipio 29fbb2df23SRiku Voipio if (perf_evsel__open_per_thread(evsel, threads) < 0) { 30fbb2df23SRiku Voipio pr_debug("failed to open counter: %s, " 31fbb2df23SRiku Voipio "tweak /proc/sys/kernel/perf_event_paranoid?\n", 32fbb2df23SRiku Voipio strerror_r(errno, sbuf, sizeof(sbuf))); 33fbb2df23SRiku Voipio goto out_evsel_delete; 34fbb2df23SRiku Voipio } 35fbb2df23SRiku Voipio 36fbb2df23SRiku Voipio for (i = 0; i < nr_openat_calls; ++i) { 37fbb2df23SRiku Voipio fd = openat(0, "/etc/passwd", O_RDONLY); 38fbb2df23SRiku Voipio close(fd); 39fbb2df23SRiku Voipio } 40fbb2df23SRiku Voipio 41fbb2df23SRiku Voipio if (perf_evsel__read_on_cpu(evsel, 0, 0) < 0) { 42fbb2df23SRiku Voipio pr_debug("perf_evsel__read_on_cpu\n"); 43fbb2df23SRiku Voipio goto out_close_fd; 44fbb2df23SRiku Voipio } 45fbb2df23SRiku Voipio 46a6fa0038SJiri Olsa if (perf_counts(evsel->counts, 0, 0)->val != nr_openat_calls) { 47fbb2df23SRiku Voipio pr_debug("perf_evsel__read_on_cpu: expected to intercept %d calls, got %" PRIu64 "\n", 48a6fa0038SJiri Olsa nr_openat_calls, perf_counts(evsel->counts, 0, 0)->val); 49fbb2df23SRiku Voipio goto out_close_fd; 50fbb2df23SRiku Voipio } 51fbb2df23SRiku Voipio 52fbb2df23SRiku Voipio err = 0; 53fbb2df23SRiku Voipio out_close_fd: 54fbb2df23SRiku Voipio perf_evsel__close_fd(evsel, 1, threads->nr); 55fbb2df23SRiku Voipio out_evsel_delete: 56fbb2df23SRiku Voipio perf_evsel__delete(evsel); 57fbb2df23SRiku Voipio out_thread_map_delete: 58186fbb74SJiri Olsa thread_map__put(threads); 59fbb2df23SRiku Voipio return err; 60fbb2df23SRiku Voipio } 61