1b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0 2a6e52817SJiri Olsa #include <linux/compiler.h> 39c3516d1SJiri Olsa #include <perf/cpumap.h> 4f2a39fe8SArnaldo Carvalho de Melo #include <string.h> 587ffb6c6SArnaldo Carvalho de Melo #include "cpumap.h" 6a6e52817SJiri Olsa #include "evlist.h" 7a6e52817SJiri Olsa #include "evsel.h" 8f2a39fe8SArnaldo Carvalho de Melo #include "header.h" 9a6e52817SJiri Olsa #include "machine.h" 10ea49e01cSArnaldo Carvalho de Melo #include "util/synthetic-events.h" 114a3cec84SArnaldo Carvalho de Melo #include "tool.h" 12a6e52817SJiri Olsa #include "tests.h" 13a6e52817SJiri Olsa #include "debug.h" 14a6e52817SJiri Olsa 15*30f29baeSIan Rogers static int process_event_unit(const struct perf_tool *tool __maybe_unused, 16a6e52817SJiri Olsa union perf_event *event, 17a6e52817SJiri Olsa struct perf_sample *sample __maybe_unused, 18a6e52817SJiri Olsa struct machine *machine __maybe_unused) 19a6e52817SJiri Olsa { 2072932371SJiri Olsa struct perf_record_event_update *ev = (struct perf_record_event_update *)event; 21a6e52817SJiri Olsa 22a6e52817SJiri Olsa TEST_ASSERT_VAL("wrong id", ev->id == 123); 23a6e52817SJiri Olsa TEST_ASSERT_VAL("wrong id", ev->type == PERF_EVENT_UPDATE__UNIT); 24d773c999SIan Rogers TEST_ASSERT_VAL("wrong unit", !strcmp(ev->unit, "KRAVA")); 25a6e52817SJiri Olsa return 0; 26a6e52817SJiri Olsa } 27a6e52817SJiri Olsa 28*30f29baeSIan Rogers static int process_event_scale(const struct perf_tool *tool __maybe_unused, 29daeecbc0SJiri Olsa union perf_event *event, 30daeecbc0SJiri Olsa struct perf_sample *sample __maybe_unused, 31daeecbc0SJiri Olsa struct machine *machine __maybe_unused) 32daeecbc0SJiri Olsa { 3372932371SJiri Olsa struct perf_record_event_update *ev = (struct perf_record_event_update *)event; 34daeecbc0SJiri Olsa 35daeecbc0SJiri Olsa TEST_ASSERT_VAL("wrong id", ev->id == 123); 36daeecbc0SJiri Olsa TEST_ASSERT_VAL("wrong id", ev->type == PERF_EVENT_UPDATE__SCALE); 37d773c999SIan Rogers TEST_ASSERT_VAL("wrong scale", ev->scale.scale == 0.123); 38daeecbc0SJiri Olsa return 0; 39daeecbc0SJiri Olsa } 40daeecbc0SJiri Olsa 41802c9048SJiri Olsa struct event_name { 42802c9048SJiri Olsa struct perf_tool tool; 43802c9048SJiri Olsa const char *name; 44802c9048SJiri Olsa }; 45802c9048SJiri Olsa 46*30f29baeSIan Rogers static int process_event_name(const struct perf_tool *tool, 47802c9048SJiri Olsa union perf_event *event, 48802c9048SJiri Olsa struct perf_sample *sample __maybe_unused, 49802c9048SJiri Olsa struct machine *machine __maybe_unused) 50802c9048SJiri Olsa { 51802c9048SJiri Olsa struct event_name *tmp = container_of(tool, struct event_name, tool); 5272932371SJiri Olsa struct perf_record_event_update *ev = (struct perf_record_event_update *)event; 53802c9048SJiri Olsa 54802c9048SJiri Olsa TEST_ASSERT_VAL("wrong id", ev->id == 123); 55802c9048SJiri Olsa TEST_ASSERT_VAL("wrong id", ev->type == PERF_EVENT_UPDATE__NAME); 56d773c999SIan Rogers TEST_ASSERT_VAL("wrong name", !strcmp(ev->name, tmp->name)); 57802c9048SJiri Olsa return 0; 58802c9048SJiri Olsa } 59802c9048SJiri Olsa 60*30f29baeSIan Rogers static int process_event_cpus(const struct perf_tool *tool __maybe_unused, 6186ebb09fSJiri Olsa union perf_event *event, 6286ebb09fSJiri Olsa struct perf_sample *sample __maybe_unused, 6386ebb09fSJiri Olsa struct machine *machine __maybe_unused) 6486ebb09fSJiri Olsa { 6572932371SJiri Olsa struct perf_record_event_update *ev = (struct perf_record_event_update *)event; 66f854839bSJiri Olsa struct perf_cpu_map *map; 6786ebb09fSJiri Olsa 68d773c999SIan Rogers map = cpu_map__new_data(&ev->cpus.cpus); 6986ebb09fSJiri Olsa 7086ebb09fSJiri Olsa TEST_ASSERT_VAL("wrong id", ev->id == 123); 7186ebb09fSJiri Olsa TEST_ASSERT_VAL("wrong type", ev->type == PERF_EVENT_UPDATE__CPUS); 7244028699SIan Rogers TEST_ASSERT_VAL("wrong cpus", perf_cpu_map__nr(map) == 3); 7344028699SIan Rogers TEST_ASSERT_VAL("wrong cpus", perf_cpu_map__cpu(map, 0).cpu == 1); 7444028699SIan Rogers TEST_ASSERT_VAL("wrong cpus", perf_cpu_map__cpu(map, 1).cpu == 2); 7544028699SIan Rogers TEST_ASSERT_VAL("wrong cpus", perf_cpu_map__cpu(map, 2).cpu == 3); 7638f01d8dSJiri Olsa perf_cpu_map__put(map); 7786ebb09fSJiri Olsa return 0; 7886ebb09fSJiri Olsa } 7986ebb09fSJiri Olsa 8033f44bfdSIan Rogers static int test__event_update(struct test_suite *test __maybe_unused, int subtest __maybe_unused) 81a6e52817SJiri Olsa { 8232dcd021SJiri Olsa struct evsel *evsel; 83802c9048SJiri Olsa struct event_name tmp; 84606e2c29SArnaldo Carvalho de Melo struct evlist *evlist = evlist__new_default(); 85a6e52817SJiri Olsa 86a6e52817SJiri Olsa TEST_ASSERT_VAL("failed to get evlist", evlist); 87a6e52817SJiri Olsa 88515dbe48SJiri Olsa evsel = evlist__first(evlist); 89a6e52817SJiri Olsa 90ce095c9aSColin Ian King TEST_ASSERT_VAL("failed to allocate ids", 9170c20369SJiri Olsa !perf_evsel__alloc_id(&evsel->core, 1, 1)); 92a6e52817SJiri Olsa 93b0031c22SJiri Olsa perf_evlist__id_add(&evlist->core, &evsel->core, 0, 0, 123); 94a6e52817SJiri Olsa 95b194c9cdSIan Rogers free((char *)evsel->unit); 96b194c9cdSIan Rogers evsel->unit = strdup("KRAVA"); 97a6e52817SJiri Olsa 98a6e52817SJiri Olsa TEST_ASSERT_VAL("failed to synthesize attr update unit", 99a6e52817SJiri Olsa !perf_event__synthesize_event_update_unit(NULL, evsel, process_event_unit)); 100a6e52817SJiri Olsa 101daeecbc0SJiri Olsa evsel->scale = 0.123; 102daeecbc0SJiri Olsa 103daeecbc0SJiri Olsa TEST_ASSERT_VAL("failed to synthesize attr update scale", 104daeecbc0SJiri Olsa !perf_event__synthesize_event_update_scale(NULL, evsel, process_event_scale)); 105daeecbc0SJiri Olsa 1068ab2e96dSArnaldo Carvalho de Melo tmp.name = evsel__name(evsel); 107802c9048SJiri Olsa 108802c9048SJiri Olsa TEST_ASSERT_VAL("failed to synthesize attr update name", 109802c9048SJiri Olsa !perf_event__synthesize_event_update_name(&tmp.tool, evsel, process_event_name)); 110802c9048SJiri Olsa 111fe1f61b3SJiri Olsa evsel->core.own_cpus = perf_cpu_map__new("1,2,3"); 11286ebb09fSJiri Olsa 11386ebb09fSJiri Olsa TEST_ASSERT_VAL("failed to synthesize attr update cpus", 11486ebb09fSJiri Olsa !perf_event__synthesize_event_update_cpus(&tmp.tool, evsel, process_event_cpus)); 11586ebb09fSJiri Olsa 116fc56f54fSRiccardo Mancini evlist__delete(evlist); 117a6e52817SJiri Olsa return 0; 118a6e52817SJiri Olsa } 119d68f0365SIan Rogers 120d68f0365SIan Rogers DEFINE_SUITE("Synthesize attr update", event_update); 121