1 // SPDX-License-Identifier: GPL-2.0
3 * Test backward bit in event attribute, read ring buffer from end to
16 static void testcase(void)
20 for (i
= 0; i
< NR_ITERS
; i
++) {
23 snprintf(proc_name
, sizeof(proc_name
), "p:%d\n", i
);
24 prctl(PR_SET_NAME
, proc_name
);
28 static int count_samples(struct perf_evlist
*evlist
, int *sample_count
,
33 for (i
= 0; i
< evlist
->nr_mmaps
; i
++) {
34 struct perf_mmap
*map
= &evlist
->overwrite_mmap
[i
];
35 union perf_event
*event
;
38 perf_mmap__read_init(map
, true, &start
, &end
);
39 while ((event
= perf_mmap__read_event(map
, true, &start
, end
)) != NULL
) {
40 const u32 type
= event
->header
.type
;
43 case PERF_RECORD_SAMPLE
:
46 case PERF_RECORD_COMM
:
50 pr_err("Unexpected record of type %d\n", type
);
54 perf_mmap__read_done(map
);
59 static int do_test(struct perf_evlist
*evlist
, int mmap_pages
,
60 int *sample_count
, int *comm_count
)
63 char sbuf
[STRERR_BUFSIZE
];
65 err
= perf_evlist__mmap(evlist
, mmap_pages
);
67 pr_debug("perf_evlist__mmap: %s\n",
68 str_error_r(errno
, sbuf
, sizeof(sbuf
)));
72 perf_evlist__enable(evlist
);
74 perf_evlist__disable(evlist
);
76 err
= count_samples(evlist
, sample_count
, comm_count
);
77 perf_evlist__munmap(evlist
);
82 int test__backward_ring_buffer(struct test
*test __maybe_unused
, int subtest __maybe_unused
)
84 int ret
= TEST_SKIP
, err
, sample_count
= 0, comm_count
= 0;
85 char pid
[16], sbuf
[STRERR_BUFSIZE
];
86 struct perf_evlist
*evlist
;
87 struct perf_evsel
*evsel __maybe_unused
;
88 struct parse_events_error parse_error
;
89 struct record_opts opts
= {
96 .default_interval
= 1,
99 snprintf(pid
, sizeof(pid
), "%d", getpid());
100 pid
[sizeof(pid
) - 1] = '\0';
101 opts
.target
.tid
= opts
.target
.pid
= pid
;
103 evlist
= perf_evlist__new();
105 pr_debug("Not enough memory to create evlist\n");
109 err
= perf_evlist__create_maps(evlist
, &opts
.target
);
111 pr_debug("Not enough memory to create thread/cpu maps\n");
112 goto out_delete_evlist
;
115 bzero(&parse_error
, sizeof(parse_error
));
117 * Set backward bit, ring buffer should be writing from end. Record
120 err
= parse_events(evlist
, "syscalls:sys_enter_prctl/overwrite/", &parse_error
);
122 pr_debug("Failed to parse tracepoint event, try use root\n");
124 goto out_delete_evlist
;
127 perf_evlist__config(evlist
, &opts
, NULL
);
129 err
= perf_evlist__open(evlist
);
131 pr_debug("perf_evlist__open: %s\n",
132 str_error_r(errno
, sbuf
, sizeof(sbuf
)));
133 goto out_delete_evlist
;
137 err
= do_test(evlist
, opts
.mmap_pages
, &sample_count
,
140 goto out_delete_evlist
;
142 if ((sample_count
!= NR_ITERS
) || (comm_count
!= NR_ITERS
)) {
143 pr_err("Unexpected counter: sample_count=%d, comm_count=%d\n",
144 sample_count
, comm_count
);
145 goto out_delete_evlist
;
148 err
= do_test(evlist
, 1, &sample_count
, &comm_count
);
150 goto out_delete_evlist
;
154 perf_evlist__delete(evlist
);