1 // SPDX-License-Identifier: GPL-2.0
4 #include <perf/threadmap.h>
5 #include <internal/tests.h>
8 static int libperf_print(enum libperf_print_level level,
9 const char *fmt, va_list ap)
11 return vfprintf(stderr, fmt, ap);
14 static int test_threadmap_array(int nr, pid_t *array)
16 struct perf_thread_map *threads;
19 threads = perf_thread_map__new_array(nr, array);
20 __T("Failed to allocate new thread map", threads);
22 __T("Unexpected number of threads", perf_thread_map__nr(threads) == nr);
24 for (i = 0; i < nr; i++) {
25 __T("Unexpected initial value of thread",
26 perf_thread_map__pid(threads, i) == (array ? array[i] : -1));
29 for (i = 1; i < nr; i++)
30 perf_thread_map__set_pid(threads, i, i * 100);
32 __T("Unexpected value of thread 0",
33 perf_thread_map__pid(threads, 0) == (array ? array[0] : -1));
35 for (i = 1; i < nr; i++) {
36 __T("Unexpected thread value",
37 perf_thread_map__pid(threads, i) == i * 100);
40 perf_thread_map__put(threads);
46 int test_threadmap(int argc, char **argv)
48 struct perf_thread_map *threads;
49 pid_t thr_array[THREADS_NR];
54 libperf_init(libperf_print);
56 threads = perf_thread_map__new_dummy();
60 perf_thread_map__get(threads);
61 perf_thread_map__put(threads);
62 perf_thread_map__put(threads);
64 test_threadmap_array(THREADS_NR, NULL);
66 for (i = 0; i < THREADS_NR; i++)
67 thr_array[i] = i + 100;
69 test_threadmap_array(THREADS_NR, thr_array);
72 return tests_failed == 0 ? 0 : -1;