event_update.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #include <linux/compiler.h>
  2. #include "evlist.h"
  3. #include "evsel.h"
  4. #include "machine.h"
  5. #include "tests.h"
  6. #include "debug.h"
  7. static int process_event_unit(struct perf_tool *tool __maybe_unused,
  8. union perf_event *event,
  9. struct perf_sample *sample __maybe_unused,
  10. struct machine *machine __maybe_unused)
  11. {
  12. struct event_update_event *ev = (struct event_update_event *) event;
  13. TEST_ASSERT_VAL("wrong id", ev->id == 123);
  14. TEST_ASSERT_VAL("wrong id", ev->type == PERF_EVENT_UPDATE__UNIT);
  15. TEST_ASSERT_VAL("wrong unit", !strcmp(ev->data, "KRAVA"));
  16. return 0;
  17. }
  18. static int process_event_scale(struct perf_tool *tool __maybe_unused,
  19. union perf_event *event,
  20. struct perf_sample *sample __maybe_unused,
  21. struct machine *machine __maybe_unused)
  22. {
  23. struct event_update_event *ev = (struct event_update_event *) event;
  24. struct event_update_event_scale *ev_data;
  25. ev_data = (struct event_update_event_scale *) ev->data;
  26. TEST_ASSERT_VAL("wrong id", ev->id == 123);
  27. TEST_ASSERT_VAL("wrong id", ev->type == PERF_EVENT_UPDATE__SCALE);
  28. TEST_ASSERT_VAL("wrong scale", ev_data->scale == 0.123);
  29. return 0;
  30. }
  31. struct event_name {
  32. struct perf_tool tool;
  33. const char *name;
  34. };
  35. static int process_event_name(struct perf_tool *tool,
  36. union perf_event *event,
  37. struct perf_sample *sample __maybe_unused,
  38. struct machine *machine __maybe_unused)
  39. {
  40. struct event_name *tmp = container_of(tool, struct event_name, tool);
  41. struct event_update_event *ev = (struct event_update_event*) event;
  42. TEST_ASSERT_VAL("wrong id", ev->id == 123);
  43. TEST_ASSERT_VAL("wrong id", ev->type == PERF_EVENT_UPDATE__NAME);
  44. TEST_ASSERT_VAL("wrong name", !strcmp(ev->data, tmp->name));
  45. return 0;
  46. }
  47. static int process_event_cpus(struct perf_tool *tool __maybe_unused,
  48. union perf_event *event,
  49. struct perf_sample *sample __maybe_unused,
  50. struct machine *machine __maybe_unused)
  51. {
  52. struct event_update_event *ev = (struct event_update_event*) event;
  53. struct event_update_event_cpus *ev_data;
  54. struct cpu_map *map;
  55. ev_data = (struct event_update_event_cpus*) ev->data;
  56. map = cpu_map__new_data(&ev_data->cpus);
  57. TEST_ASSERT_VAL("wrong id", ev->id == 123);
  58. TEST_ASSERT_VAL("wrong type", ev->type == PERF_EVENT_UPDATE__CPUS);
  59. TEST_ASSERT_VAL("wrong cpus", map->nr == 3);
  60. TEST_ASSERT_VAL("wrong cpus", map->map[0] == 1);
  61. TEST_ASSERT_VAL("wrong cpus", map->map[1] == 2);
  62. TEST_ASSERT_VAL("wrong cpus", map->map[2] == 3);
  63. cpu_map__put(map);
  64. return 0;
  65. }
  66. int test__event_update(int subtest __maybe_unused)
  67. {
  68. struct perf_evlist *evlist;
  69. struct perf_evsel *evsel;
  70. struct event_name tmp;
  71. evlist = perf_evlist__new_default();
  72. TEST_ASSERT_VAL("failed to get evlist", evlist);
  73. evsel = perf_evlist__first(evlist);
  74. TEST_ASSERT_VAL("failed to allos ids",
  75. !perf_evsel__alloc_id(evsel, 1, 1));
  76. perf_evlist__id_add(evlist, evsel, 0, 0, 123);
  77. evsel->unit = strdup("KRAVA");
  78. TEST_ASSERT_VAL("failed to synthesize attr update unit",
  79. !perf_event__synthesize_event_update_unit(NULL, evsel, process_event_unit));
  80. evsel->scale = 0.123;
  81. TEST_ASSERT_VAL("failed to synthesize attr update scale",
  82. !perf_event__synthesize_event_update_scale(NULL, evsel, process_event_scale));
  83. tmp.name = perf_evsel__name(evsel);
  84. TEST_ASSERT_VAL("failed to synthesize attr update name",
  85. !perf_event__synthesize_event_update_name(&tmp.tool, evsel, process_event_name));
  86. evsel->own_cpus = cpu_map__new("1,2,3");
  87. TEST_ASSERT_VAL("failed to synthesize attr update cpus",
  88. !perf_event__synthesize_event_update_cpus(&tmp.tool, evsel, process_event_cpus));
  89. cpu_map__put(evsel->own_cpus);
  90. return 0;
  91. }