1 // SPDX-License-Identifier: GPL-2.0
4 #include "thread_map.h"
14 static void sig_handler(int sig __maybe_unused)
20 * perf_evlist__prepare_workload will send a SIGUSR1 if the fork fails, since
21 * we asked by setting its exec_error to this handler.
23 static void workload_exec_failed_signal(int signo __maybe_unused,
24 siginfo_t *info __maybe_unused,
25 void *ucontext __maybe_unused)
32 * This test will start a workload that does nothing then it checks
33 * if the number of exit event reported by the kernel is 1 or not
34 * in order to check the kernel returns correct number of event.
36 int test__task_exit(struct test *test __maybe_unused, int subtest __maybe_unused)
39 union perf_event *event;
40 struct perf_evsel *evsel;
41 struct perf_evlist *evlist;
42 struct target target = {
46 const char *argv[] = { "true", NULL };
47 char sbuf[STRERR_BUFSIZE];
49 struct thread_map *threads;
52 signal(SIGCHLD, sig_handler);
54 evlist = perf_evlist__new_default();
56 pr_debug("perf_evlist__new_default\n");
61 * Create maps of threads and cpus to monitor. In this case
62 * we start with all threads and cpus (-1, -1) but then in
63 * perf_evlist__prepare_workload we'll fill in the only thread
64 * we're monitoring, the one forked there.
66 cpus = cpu_map__dummy_new();
67 threads = thread_map__new_by_tid(-1);
68 if (!cpus || !threads) {
70 pr_debug("Not enough memory to create thread/cpu maps\n");
74 perf_evlist__set_maps(evlist, cpus, threads);
79 err = perf_evlist__prepare_workload(evlist, &target, argv, false,
80 workload_exec_failed_signal);
82 pr_debug("Couldn't run the workload!\n");
83 goto out_delete_evlist;
86 evsel = perf_evlist__first(evlist);
89 evsel->attr.sample_freq = 1000000;
91 evsel->attr.sample_freq = 1;
93 evsel->attr.inherit = 0;
94 evsel->attr.watermark = 0;
95 evsel->attr.wakeup_events = 1;
96 evsel->attr.exclude_kernel = 1;
98 err = perf_evlist__open(evlist);
100 pr_debug("Couldn't open the evlist: %s\n",
101 str_error_r(-err, sbuf, sizeof(sbuf)));
102 goto out_delete_evlist;
105 if (perf_evlist__mmap(evlist, 128) < 0) {
106 pr_debug("failed to mmap events: %d (%s)\n", errno,
107 str_error_r(errno, sbuf, sizeof(sbuf)));
109 goto out_delete_evlist;
112 perf_evlist__start_workload(evlist);
115 md = &evlist->mmap[0];
116 if (perf_mmap__read_init(md) < 0)
119 while ((event = perf_mmap__read_event(md)) != NULL) {
120 if (event->header.type == PERF_RECORD_EXIT)
123 perf_mmap__consume(md);
125 perf_mmap__read_done(md);
128 if (!exited || !nr_exit) {
129 perf_evlist__poll(evlist, -1);
134 pr_debug("received %d EXIT records\n", nr_exit);
140 thread_map__put(threads);
142 perf_evlist__delete(evlist);