thread-map.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #include <sys/types.h>
  2. #include <unistd.h>
  3. #include "tests.h"
  4. #include "thread_map.h"
  5. #include "debug.h"
  6. int test__thread_map(void)
  7. {
  8. struct thread_map *map;
  9. /* test map on current pid */
  10. map = thread_map__new_by_pid(getpid());
  11. TEST_ASSERT_VAL("failed to alloc map", map);
  12. thread_map__read_comms(map);
  13. TEST_ASSERT_VAL("wrong nr", map->nr == 1);
  14. TEST_ASSERT_VAL("wrong pid",
  15. thread_map__pid(map, 0) == getpid());
  16. TEST_ASSERT_VAL("wrong comm",
  17. thread_map__comm(map, 0) &&
  18. !strcmp(thread_map__comm(map, 0), "perf"));
  19. TEST_ASSERT_VAL("wrong refcnt",
  20. atomic_read(&map->refcnt) == 1);
  21. thread_map__put(map);
  22. /* test dummy pid */
  23. map = thread_map__new_dummy();
  24. TEST_ASSERT_VAL("failed to alloc map", map);
  25. thread_map__read_comms(map);
  26. TEST_ASSERT_VAL("wrong nr", map->nr == 1);
  27. TEST_ASSERT_VAL("wrong pid", thread_map__pid(map, 0) == -1);
  28. TEST_ASSERT_VAL("wrong comm",
  29. thread_map__comm(map, 0) &&
  30. !strcmp(thread_map__comm(map, 0), "dummy"));
  31. TEST_ASSERT_VAL("wrong refcnt",
  32. atomic_read(&map->refcnt) == 1);
  33. thread_map__put(map);
  34. return 0;
  35. }