test-cpumap.c 795 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <stdarg.h>
  3. #include <stdio.h>
  4. #include <perf/cpumap.h>
  5. #include <internal/tests.h>
  6. #include "tests.h"
  7. static int libperf_print(enum libperf_print_level level,
  8. const char *fmt, va_list ap)
  9. {
  10. return vfprintf(stderr, fmt, ap);
  11. }
  12. int test_cpumap(int argc, char **argv)
  13. {
  14. struct perf_cpu_map *cpus;
  15. struct perf_cpu cpu;
  16. int idx;
  17. __T_START;
  18. libperf_init(libperf_print);
  19. cpus = perf_cpu_map__new_any_cpu();
  20. if (!cpus)
  21. return -1;
  22. perf_cpu_map__get(cpus);
  23. perf_cpu_map__put(cpus);
  24. perf_cpu_map__put(cpus);
  25. cpus = perf_cpu_map__new_online_cpus();
  26. if (!cpus)
  27. return -1;
  28. perf_cpu_map__for_each_cpu(cpu, idx, cpus)
  29. __T("wrong cpu number", cpu.cpu != -1);
  30. perf_cpu_map__put(cpus);
  31. __T_END;
  32. return tests_failed == 0 ? 0 : -1;
  33. }