Path: blob/master/tools/lib/perf/tests/test-threadmap.c
26288 views
// SPDX-License-Identifier: GPL-2.01#include <stdarg.h>2#include <stdio.h>3#include <perf/threadmap.h>4#include <internal/tests.h>5#include "tests.h"67static int libperf_print(enum libperf_print_level level,8const char *fmt, va_list ap)9{10return vfprintf(stderr, fmt, ap);11}1213static int test_threadmap_array(int nr, pid_t *array)14{15struct perf_thread_map *threads;16int i;1718threads = perf_thread_map__new_array(nr, array);19__T("Failed to allocate new thread map", threads);2021__T("Unexpected number of threads", perf_thread_map__nr(threads) == nr);2223for (i = 0; i < nr; i++) {24__T("Unexpected initial value of thread",25perf_thread_map__pid(threads, i) == (array ? array[i] : -1));26}2728for (i = 1; i < nr; i++)29perf_thread_map__set_pid(threads, i, i * 100);3031__T("Unexpected value of thread 0",32perf_thread_map__pid(threads, 0) == (array ? array[0] : -1));3334for (i = 1; i < nr; i++) {35__T("Unexpected thread value",36perf_thread_map__pid(threads, i) == i * 100);37}3839perf_thread_map__put(threads);4041return 0;42}4344#define THREADS_NR 1045int test_threadmap(int argc, char **argv)46{47struct perf_thread_map *threads;48pid_t thr_array[THREADS_NR];49int i;5051__T_START;5253libperf_init(libperf_print);5455threads = perf_thread_map__new_dummy();56if (!threads)57return -1;5859perf_thread_map__get(threads);60perf_thread_map__put(threads);61perf_thread_map__put(threads);6263test_threadmap_array(THREADS_NR, NULL);6465for (i = 0; i < THREADS_NR; i++)66thr_array[i] = i + 100;6768test_threadmap_array(THREADS_NR, thr_array);6970__T_END;71return tests_failed == 0 ? 0 : -1;72}737475