thread-map.c 943 B

1234567891011121314151617181920212223242526272829303132333435363738
  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. thread_map__put(map);
  20. /* test dummy pid */
  21. map = thread_map__new_dummy();
  22. TEST_ASSERT_VAL("failed to alloc map", map);
  23. thread_map__read_comms(map);
  24. TEST_ASSERT_VAL("wrong nr", map->nr == 1);
  25. TEST_ASSERT_VAL("wrong pid", thread_map__pid(map, 0) == -1);
  26. TEST_ASSERT_VAL("wrong comm",
  27. thread_map__comm(map, 0) &&
  28. !strcmp(thread_map__comm(map, 0), "dummy"));
  29. thread_map__put(map);
  30. return 0;
  31. }