cpumap.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #include "tests.h"
  2. #include "cpumap.h"
  3. static int process_event_mask(struct perf_tool *tool __maybe_unused,
  4. union perf_event *event,
  5. struct perf_sample *sample __maybe_unused,
  6. struct machine *machine __maybe_unused)
  7. {
  8. struct cpu_map_event *map_event = &event->cpu_map;
  9. struct cpu_map_mask *mask;
  10. struct cpu_map_data *data;
  11. struct cpu_map *map;
  12. int i;
  13. data = &map_event->data;
  14. TEST_ASSERT_VAL("wrong type", data->type == PERF_CPU_MAP__MASK);
  15. mask = (struct cpu_map_mask *)data->data;
  16. TEST_ASSERT_VAL("wrong nr", mask->nr == 1);
  17. for (i = 0; i < 20; i++) {
  18. TEST_ASSERT_VAL("wrong cpu", test_bit(i, mask->mask));
  19. }
  20. map = cpu_map__new_data(data);
  21. TEST_ASSERT_VAL("wrong nr", map->nr == 20);
  22. for (i = 0; i < 20; i++) {
  23. TEST_ASSERT_VAL("wrong cpu", map->map[i] == i);
  24. }
  25. cpu_map__put(map);
  26. return 0;
  27. }
  28. static int process_event_cpus(struct perf_tool *tool __maybe_unused,
  29. union perf_event *event,
  30. struct perf_sample *sample __maybe_unused,
  31. struct machine *machine __maybe_unused)
  32. {
  33. struct cpu_map_event *map_event = &event->cpu_map;
  34. struct cpu_map_entries *cpus;
  35. struct cpu_map_data *data;
  36. struct cpu_map *map;
  37. data = &map_event->data;
  38. TEST_ASSERT_VAL("wrong type", data->type == PERF_CPU_MAP__CPUS);
  39. cpus = (struct cpu_map_entries *)data->data;
  40. TEST_ASSERT_VAL("wrong nr", cpus->nr == 2);
  41. TEST_ASSERT_VAL("wrong cpu", cpus->cpu[0] == 1);
  42. TEST_ASSERT_VAL("wrong cpu", cpus->cpu[1] == 256);
  43. map = cpu_map__new_data(data);
  44. TEST_ASSERT_VAL("wrong nr", map->nr == 2);
  45. TEST_ASSERT_VAL("wrong cpu", map->map[0] == 1);
  46. TEST_ASSERT_VAL("wrong cpu", map->map[1] == 256);
  47. TEST_ASSERT_VAL("wrong refcnt", atomic_read(&map->refcnt) == 1);
  48. cpu_map__put(map);
  49. return 0;
  50. }
  51. int test__cpu_map_synthesize(int subtest __maybe_unused)
  52. {
  53. struct cpu_map *cpus;
  54. /* This one is better stores in mask. */
  55. cpus = cpu_map__new("0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19");
  56. TEST_ASSERT_VAL("failed to synthesize map",
  57. !perf_event__synthesize_cpu_map(NULL, cpus, process_event_mask, NULL));
  58. cpu_map__put(cpus);
  59. /* This one is better stores in cpu values. */
  60. cpus = cpu_map__new("1,256");
  61. TEST_ASSERT_VAL("failed to synthesize map",
  62. !perf_event__synthesize_cpu_map(NULL, cpus, process_event_cpus, NULL));
  63. cpu_map__put(cpus);
  64. return 0;
  65. }