^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) #include <linux/compiler.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) #include <perf/cpumap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) #include <string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #include "cpumap.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include "evlist.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include "evsel.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include "header.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include "machine.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include "util/synthetic-events.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include "tool.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include "tests.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include "debug.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) static int process_event_unit(struct perf_tool *tool __maybe_unused,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) union perf_event *event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) struct perf_sample *sample __maybe_unused,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) struct machine *machine __maybe_unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) struct perf_record_event_update *ev = (struct perf_record_event_update *)event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) TEST_ASSERT_VAL("wrong id", ev->id == 123);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) TEST_ASSERT_VAL("wrong id", ev->type == PERF_EVENT_UPDATE__UNIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) TEST_ASSERT_VAL("wrong unit", !strcmp(ev->data, "KRAVA"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) static int process_event_scale(struct perf_tool *tool __maybe_unused,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) union perf_event *event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) struct perf_sample *sample __maybe_unused,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) struct machine *machine __maybe_unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) struct perf_record_event_update *ev = (struct perf_record_event_update *)event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) struct perf_record_event_update_scale *ev_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) ev_data = (struct perf_record_event_update_scale *)ev->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) TEST_ASSERT_VAL("wrong id", ev->id == 123);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) TEST_ASSERT_VAL("wrong id", ev->type == PERF_EVENT_UPDATE__SCALE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) TEST_ASSERT_VAL("wrong scale", ev_data->scale == 0.123);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) struct event_name {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) struct perf_tool tool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) static int process_event_name(struct perf_tool *tool,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) union perf_event *event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) struct perf_sample *sample __maybe_unused,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) struct machine *machine __maybe_unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) struct event_name *tmp = container_of(tool, struct event_name, tool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) struct perf_record_event_update *ev = (struct perf_record_event_update *)event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) TEST_ASSERT_VAL("wrong id", ev->id == 123);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) TEST_ASSERT_VAL("wrong id", ev->type == PERF_EVENT_UPDATE__NAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) TEST_ASSERT_VAL("wrong name", !strcmp(ev->data, tmp->name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) static int process_event_cpus(struct perf_tool *tool __maybe_unused,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) union perf_event *event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) struct perf_sample *sample __maybe_unused,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) struct machine *machine __maybe_unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) struct perf_record_event_update *ev = (struct perf_record_event_update *)event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) struct perf_record_event_update_cpus *ev_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) struct perf_cpu_map *map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) ev_data = (struct perf_record_event_update_cpus *) ev->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) map = cpu_map__new_data(&ev_data->cpus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) TEST_ASSERT_VAL("wrong id", ev->id == 123);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) TEST_ASSERT_VAL("wrong type", ev->type == PERF_EVENT_UPDATE__CPUS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) TEST_ASSERT_VAL("wrong cpus", map->nr == 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) TEST_ASSERT_VAL("wrong cpus", map->map[0] == 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) TEST_ASSERT_VAL("wrong cpus", map->map[1] == 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) TEST_ASSERT_VAL("wrong cpus", map->map[2] == 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) perf_cpu_map__put(map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) int test__event_update(struct test *test __maybe_unused, int subtest __maybe_unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) struct evlist *evlist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) struct evsel *evsel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) struct event_name tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) evlist = perf_evlist__new_default();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) TEST_ASSERT_VAL("failed to get evlist", evlist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) evsel = evlist__first(evlist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) TEST_ASSERT_VAL("failed to allocate ids",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) !perf_evsel__alloc_id(&evsel->core, 1, 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) perf_evlist__id_add(&evlist->core, &evsel->core, 0, 0, 123);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) evsel->unit = strdup("KRAVA");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) TEST_ASSERT_VAL("failed to synthesize attr update unit",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) !perf_event__synthesize_event_update_unit(NULL, evsel, process_event_unit));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) evsel->scale = 0.123;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) TEST_ASSERT_VAL("failed to synthesize attr update scale",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) !perf_event__synthesize_event_update_scale(NULL, evsel, process_event_scale));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) tmp.name = evsel__name(evsel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) TEST_ASSERT_VAL("failed to synthesize attr update name",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) !perf_event__synthesize_event_update_name(&tmp.tool, evsel, process_event_name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) evsel->core.own_cpus = perf_cpu_map__new("1,2,3");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) TEST_ASSERT_VAL("failed to synthesize attr update cpus",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) !perf_event__synthesize_event_update_cpus(&tmp.tool, evsel, process_event_cpus));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) evlist__delete(evlist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) }