event_update.c 3.7 KB

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