Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Jiri Olsa | a6e5281 | 2015-10-25 15:51:37 +0100 | [diff] [blame] | 2 | #include <linux/compiler.h> |
Jiri Olsa | 9c3516d | 2019-07-21 13:24:30 +0200 | [diff] [blame] | 3 | #include <perf/cpumap.h> |
Arnaldo Carvalho de Melo | f2a39fe | 2019-08-30 14:45:20 -0300 | [diff] [blame] | 4 | #include <string.h> |
Arnaldo Carvalho de Melo | 87ffb6c | 2019-09-10 16:29:02 +0100 | [diff] [blame] | 5 | #include "cpumap.h" |
Jiri Olsa | a6e5281 | 2015-10-25 15:51:37 +0100 | [diff] [blame] | 6 | #include "evlist.h" |
| 7 | #include "evsel.h" |
Arnaldo Carvalho de Melo | f2a39fe | 2019-08-30 14:45:20 -0300 | [diff] [blame] | 8 | #include "header.h" |
Jiri Olsa | a6e5281 | 2015-10-25 15:51:37 +0100 | [diff] [blame] | 9 | #include "machine.h" |
Arnaldo Carvalho de Melo | ea49e01 | 2019-09-18 11:36:13 -0300 | [diff] [blame] | 10 | #include "util/synthetic-events.h" |
Arnaldo Carvalho de Melo | 4a3cec8 | 2019-08-30 11:11:01 -0300 | [diff] [blame] | 11 | #include "tool.h" |
Jiri Olsa | a6e5281 | 2015-10-25 15:51:37 +0100 | [diff] [blame] | 12 | #include "tests.h" |
| 13 | #include "debug.h" |
| 14 | |
| 15 | static int process_event_unit(struct perf_tool *tool __maybe_unused, |
| 16 | union perf_event *event, |
| 17 | struct perf_sample *sample __maybe_unused, |
| 18 | struct machine *machine __maybe_unused) |
| 19 | { |
Jiri Olsa | 7293237 | 2019-08-28 15:57:16 +0200 | [diff] [blame] | 20 | struct perf_record_event_update *ev = (struct perf_record_event_update *)event; |
Jiri Olsa | a6e5281 | 2015-10-25 15:51:37 +0100 | [diff] [blame] | 21 | |
| 22 | TEST_ASSERT_VAL("wrong id", ev->id == 123); |
| 23 | TEST_ASSERT_VAL("wrong id", ev->type == PERF_EVENT_UPDATE__UNIT); |
| 24 | TEST_ASSERT_VAL("wrong unit", !strcmp(ev->data, "KRAVA")); |
| 25 | return 0; |
| 26 | } |
| 27 | |
Jiri Olsa | daeecbc | 2015-10-25 15:51:38 +0100 | [diff] [blame] | 28 | static int process_event_scale(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 | { |
Jiri Olsa | 7293237 | 2019-08-28 15:57:16 +0200 | [diff] [blame] | 33 | struct perf_record_event_update *ev = (struct perf_record_event_update *)event; |
| 34 | struct perf_record_event_update_scale *ev_data; |
Jiri Olsa | daeecbc | 2015-10-25 15:51:38 +0100 | [diff] [blame] | 35 | |
Jiri Olsa | 7293237 | 2019-08-28 15:57:16 +0200 | [diff] [blame] | 36 | ev_data = (struct perf_record_event_update_scale *)ev->data; |
Jiri Olsa | daeecbc | 2015-10-25 15:51:38 +0100 | [diff] [blame] | 37 | |
| 38 | TEST_ASSERT_VAL("wrong id", ev->id == 123); |
| 39 | TEST_ASSERT_VAL("wrong id", ev->type == PERF_EVENT_UPDATE__SCALE); |
Colin Ian King | 8daef50 | 2016-04-23 14:45:54 +0100 | [diff] [blame] | 40 | TEST_ASSERT_VAL("wrong scale", ev_data->scale == 0.123); |
Jiri Olsa | daeecbc | 2015-10-25 15:51:38 +0100 | [diff] [blame] | 41 | return 0; |
| 42 | } |
| 43 | |
Jiri Olsa | 802c904 | 2015-10-25 15:51:39 +0100 | [diff] [blame] | 44 | struct event_name { |
| 45 | struct perf_tool tool; |
| 46 | const char *name; |
| 47 | }; |
| 48 | |
| 49 | static int process_event_name(struct perf_tool *tool, |
| 50 | union perf_event *event, |
| 51 | struct perf_sample *sample __maybe_unused, |
| 52 | struct machine *machine __maybe_unused) |
| 53 | { |
| 54 | struct event_name *tmp = container_of(tool, struct event_name, tool); |
Jiri Olsa | 7293237 | 2019-08-28 15:57:16 +0200 | [diff] [blame] | 55 | struct perf_record_event_update *ev = (struct perf_record_event_update *)event; |
Jiri Olsa | 802c904 | 2015-10-25 15:51:39 +0100 | [diff] [blame] | 56 | |
| 57 | TEST_ASSERT_VAL("wrong id", ev->id == 123); |
| 58 | TEST_ASSERT_VAL("wrong id", ev->type == PERF_EVENT_UPDATE__NAME); |
| 59 | TEST_ASSERT_VAL("wrong name", !strcmp(ev->data, tmp->name)); |
| 60 | return 0; |
| 61 | } |
| 62 | |
Jiri Olsa | 86ebb09 | 2015-10-25 15:51:40 +0100 | [diff] [blame] | 63 | static int process_event_cpus(struct perf_tool *tool __maybe_unused, |
| 64 | union perf_event *event, |
| 65 | struct perf_sample *sample __maybe_unused, |
| 66 | struct machine *machine __maybe_unused) |
| 67 | { |
Jiri Olsa | 7293237 | 2019-08-28 15:57:16 +0200 | [diff] [blame] | 68 | struct perf_record_event_update *ev = (struct perf_record_event_update *)event; |
| 69 | struct perf_record_event_update_cpus *ev_data; |
Jiri Olsa | f854839 | 2019-07-21 13:23:49 +0200 | [diff] [blame] | 70 | struct perf_cpu_map *map; |
Jiri Olsa | 86ebb09 | 2015-10-25 15:51:40 +0100 | [diff] [blame] | 71 | |
Jiri Olsa | 7293237 | 2019-08-28 15:57:16 +0200 | [diff] [blame] | 72 | ev_data = (struct perf_record_event_update_cpus *) ev->data; |
Jiri Olsa | 86ebb09 | 2015-10-25 15:51:40 +0100 | [diff] [blame] | 73 | |
| 74 | map = cpu_map__new_data(&ev_data->cpus); |
| 75 | |
| 76 | TEST_ASSERT_VAL("wrong id", ev->id == 123); |
| 77 | TEST_ASSERT_VAL("wrong type", ev->type == PERF_EVENT_UPDATE__CPUS); |
| 78 | TEST_ASSERT_VAL("wrong cpus", map->nr == 3); |
| 79 | TEST_ASSERT_VAL("wrong cpus", map->map[0] == 1); |
| 80 | TEST_ASSERT_VAL("wrong cpus", map->map[1] == 2); |
| 81 | TEST_ASSERT_VAL("wrong cpus", map->map[2] == 3); |
Jiri Olsa | 38f01d8 | 2019-07-21 13:24:17 +0200 | [diff] [blame] | 82 | perf_cpu_map__put(map); |
Jiri Olsa | 86ebb09 | 2015-10-25 15:51:40 +0100 | [diff] [blame] | 83 | return 0; |
| 84 | } |
| 85 | |
Arnaldo Carvalho de Melo | 81f17c9 | 2017-08-03 15:16:31 -0300 | [diff] [blame] | 86 | int test__event_update(struct test *test __maybe_unused, int subtest __maybe_unused) |
Jiri Olsa | a6e5281 | 2015-10-25 15:51:37 +0100 | [diff] [blame] | 87 | { |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 88 | struct evsel *evsel; |
Jiri Olsa | 802c904 | 2015-10-25 15:51:39 +0100 | [diff] [blame] | 89 | struct event_name tmp; |
Arnaldo Carvalho de Melo | 606e2c2 | 2020-11-30 15:04:05 -0300 | [diff] [blame] | 90 | struct evlist *evlist = evlist__new_default(); |
Riccardo Mancini | dccfca9 | 2021-07-15 18:07:10 +0200 | [diff] [blame] | 91 | char *unit = strdup("KRAVA"); |
Jiri Olsa | a6e5281 | 2015-10-25 15:51:37 +0100 | [diff] [blame] | 92 | |
Jiri Olsa | a6e5281 | 2015-10-25 15:51:37 +0100 | [diff] [blame] | 93 | TEST_ASSERT_VAL("failed to get evlist", evlist); |
| 94 | |
Jiri Olsa | 515dbe4 | 2019-09-03 10:39:52 +0200 | [diff] [blame] | 95 | evsel = evlist__first(evlist); |
Jiri Olsa | a6e5281 | 2015-10-25 15:51:37 +0100 | [diff] [blame] | 96 | |
Colin Ian King | ce095c9 | 2019-09-11 16:21:48 +0100 | [diff] [blame] | 97 | TEST_ASSERT_VAL("failed to allocate ids", |
Jiri Olsa | 70c2036 | 2019-09-03 10:34:29 +0200 | [diff] [blame] | 98 | !perf_evsel__alloc_id(&evsel->core, 1, 1)); |
Jiri Olsa | a6e5281 | 2015-10-25 15:51:37 +0100 | [diff] [blame] | 99 | |
Jiri Olsa | b0031c2 | 2019-09-03 11:01:04 +0200 | [diff] [blame] | 100 | perf_evlist__id_add(&evlist->core, &evsel->core, 0, 0, 123); |
Jiri Olsa | a6e5281 | 2015-10-25 15:51:37 +0100 | [diff] [blame] | 101 | |
Riccardo Mancini | dccfca9 | 2021-07-15 18:07:10 +0200 | [diff] [blame] | 102 | evsel->unit = unit; |
Jiri Olsa | a6e5281 | 2015-10-25 15:51:37 +0100 | [diff] [blame] | 103 | |
| 104 | TEST_ASSERT_VAL("failed to synthesize attr update unit", |
| 105 | !perf_event__synthesize_event_update_unit(NULL, evsel, process_event_unit)); |
| 106 | |
Jiri Olsa | daeecbc | 2015-10-25 15:51:38 +0100 | [diff] [blame] | 107 | evsel->scale = 0.123; |
| 108 | |
| 109 | TEST_ASSERT_VAL("failed to synthesize attr update scale", |
| 110 | !perf_event__synthesize_event_update_scale(NULL, evsel, process_event_scale)); |
| 111 | |
Arnaldo Carvalho de Melo | 8ab2e96 | 2020-04-29 16:07:09 -0300 | [diff] [blame] | 112 | tmp.name = evsel__name(evsel); |
Jiri Olsa | 802c904 | 2015-10-25 15:51:39 +0100 | [diff] [blame] | 113 | |
| 114 | TEST_ASSERT_VAL("failed to synthesize attr update name", |
| 115 | !perf_event__synthesize_event_update_name(&tmp.tool, evsel, process_event_name)); |
| 116 | |
Jiri Olsa | fe1f61b | 2019-07-21 13:24:38 +0200 | [diff] [blame] | 117 | evsel->core.own_cpus = perf_cpu_map__new("1,2,3"); |
Jiri Olsa | 86ebb09 | 2015-10-25 15:51:40 +0100 | [diff] [blame] | 118 | |
| 119 | TEST_ASSERT_VAL("failed to synthesize attr update cpus", |
| 120 | !perf_event__synthesize_event_update_cpus(&tmp.tool, evsel, process_event_cpus)); |
| 121 | |
Riccardo Mancini | dccfca9 | 2021-07-15 18:07:10 +0200 | [diff] [blame] | 122 | free(unit); |
Riccardo Mancini | fc56f54 | 2021-07-15 18:07:09 +0200 | [diff] [blame] | 123 | evlist__delete(evlist); |
Jiri Olsa | a6e5281 | 2015-10-25 15:51:37 +0100 | [diff] [blame] | 124 | return 0; |
| 125 | } |