|
27 | 27 |
|
28 | 28 | #include "tests.h" |
29 | 29 |
|
30 | | -static int trace_event__id(const char *evname) |
31 | | -{ |
32 | | - char *filename; |
33 | | - int err = -1, fd; |
34 | | - |
35 | | - if (asprintf(&filename, |
36 | | - "%s/syscalls/%s/id", |
37 | | - tracing_events_path, evname) < 0) |
38 | | - return -1; |
39 | | - |
40 | | - fd = open(filename, O_RDONLY); |
41 | | - if (fd >= 0) { |
42 | | - char id[16]; |
43 | | - if (read(fd, id, sizeof(id)) > 0) |
44 | | - err = atoi(id); |
45 | | - close(fd); |
46 | | - } |
47 | | - |
48 | | - free(filename); |
49 | | - return err; |
50 | | -} |
51 | | - |
52 | | -static int test__open_syscall_event(void) |
53 | | -{ |
54 | | - int err = -1, fd; |
55 | | - struct thread_map *threads; |
56 | | - struct perf_evsel *evsel; |
57 | | - struct perf_event_attr attr; |
58 | | - unsigned int nr_open_calls = 111, i; |
59 | | - int id = trace_event__id("sys_enter_open"); |
60 | | - |
61 | | - if (id < 0) { |
62 | | - pr_debug("is debugfs mounted on /sys/kernel/debug?\n"); |
63 | | - return -1; |
64 | | - } |
65 | | - |
66 | | - threads = thread_map__new(-1, getpid(), UINT_MAX); |
67 | | - if (threads == NULL) { |
68 | | - pr_debug("thread_map__new\n"); |
69 | | - return -1; |
70 | | - } |
71 | | - |
72 | | - memset(&attr, 0, sizeof(attr)); |
73 | | - attr.type = PERF_TYPE_TRACEPOINT; |
74 | | - attr.config = id; |
75 | | - evsel = perf_evsel__new(&attr, 0); |
76 | | - if (evsel == NULL) { |
77 | | - pr_debug("perf_evsel__new\n"); |
78 | | - goto out_thread_map_delete; |
79 | | - } |
80 | | - |
81 | | - if (perf_evsel__open_per_thread(evsel, threads) < 0) { |
82 | | - pr_debug("failed to open counter: %s, " |
83 | | - "tweak /proc/sys/kernel/perf_event_paranoid?\n", |
84 | | - strerror(errno)); |
85 | | - goto out_evsel_delete; |
86 | | - } |
87 | | - |
88 | | - for (i = 0; i < nr_open_calls; ++i) { |
89 | | - fd = open("/etc/passwd", O_RDONLY); |
90 | | - close(fd); |
91 | | - } |
92 | | - |
93 | | - if (perf_evsel__read_on_cpu(evsel, 0, 0) < 0) { |
94 | | - pr_debug("perf_evsel__read_on_cpu\n"); |
95 | | - goto out_close_fd; |
96 | | - } |
97 | | - |
98 | | - if (evsel->counts->cpu[0].val != nr_open_calls) { |
99 | | - pr_debug("perf_evsel__read_on_cpu: expected to intercept %d calls, got %" PRIu64 "\n", |
100 | | - nr_open_calls, evsel->counts->cpu[0].val); |
101 | | - goto out_close_fd; |
102 | | - } |
103 | | - |
104 | | - err = 0; |
105 | | -out_close_fd: |
106 | | - perf_evsel__close_fd(evsel, 1, threads->nr); |
107 | | -out_evsel_delete: |
108 | | - perf_evsel__delete(evsel); |
109 | | -out_thread_map_delete: |
110 | | - thread_map__delete(threads); |
111 | | - return err; |
112 | | -} |
113 | | - |
114 | 30 | #include <sched.h> |
115 | 31 |
|
116 | 32 | static int test__open_syscall_event_on_all_cpus(void) |
|
0 commit comments