Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 #include <linux/compiler.h>
0003 #include <perf/cpumap.h>
0004 #include <string.h>
0005 #include "cpumap.h"
0006 #include "evlist.h"
0007 #include "evsel.h"
0008 #include "header.h"
0009 #include "machine.h"
0010 #include "util/synthetic-events.h"
0011 #include "tool.h"
0012 #include "tests.h"
0013 #include "debug.h"
0014 
0015 static int process_event_unit(struct perf_tool *tool __maybe_unused,
0016                   union perf_event *event,
0017                   struct perf_sample *sample __maybe_unused,
0018                   struct machine *machine __maybe_unused)
0019 {
0020     struct perf_record_event_update *ev = (struct perf_record_event_update *)event;
0021 
0022     TEST_ASSERT_VAL("wrong id", ev->id == 123);
0023     TEST_ASSERT_VAL("wrong id", ev->type == PERF_EVENT_UPDATE__UNIT);
0024     TEST_ASSERT_VAL("wrong unit", !strcmp(ev->data, "KRAVA"));
0025     return 0;
0026 }
0027 
0028 static int process_event_scale(struct perf_tool *tool __maybe_unused,
0029                    union perf_event *event,
0030                    struct perf_sample *sample __maybe_unused,
0031                    struct machine *machine __maybe_unused)
0032 {
0033     struct perf_record_event_update *ev = (struct perf_record_event_update *)event;
0034     struct perf_record_event_update_scale *ev_data;
0035 
0036     ev_data = (struct perf_record_event_update_scale *)ev->data;
0037 
0038     TEST_ASSERT_VAL("wrong id", ev->id == 123);
0039     TEST_ASSERT_VAL("wrong id", ev->type == PERF_EVENT_UPDATE__SCALE);
0040     TEST_ASSERT_VAL("wrong scale", ev_data->scale == 0.123);
0041     return 0;
0042 }
0043 
0044 struct event_name {
0045     struct perf_tool tool;
0046     const char *name;
0047 };
0048 
0049 static int process_event_name(struct perf_tool *tool,
0050                   union perf_event *event,
0051                   struct perf_sample *sample __maybe_unused,
0052                   struct machine *machine __maybe_unused)
0053 {
0054     struct event_name *tmp = container_of(tool, struct event_name, tool);
0055     struct perf_record_event_update *ev = (struct perf_record_event_update *)event;
0056 
0057     TEST_ASSERT_VAL("wrong id", ev->id == 123);
0058     TEST_ASSERT_VAL("wrong id", ev->type == PERF_EVENT_UPDATE__NAME);
0059     TEST_ASSERT_VAL("wrong name", !strcmp(ev->data, tmp->name));
0060     return 0;
0061 }
0062 
0063 static int process_event_cpus(struct perf_tool *tool __maybe_unused,
0064                   union perf_event *event,
0065                   struct perf_sample *sample __maybe_unused,
0066                   struct machine *machine __maybe_unused)
0067 {
0068     struct perf_record_event_update *ev = (struct perf_record_event_update *)event;
0069     struct perf_record_event_update_cpus *ev_data;
0070     struct perf_cpu_map *map;
0071 
0072     ev_data = (struct perf_record_event_update_cpus *) ev->data;
0073 
0074     map = cpu_map__new_data(&ev_data->cpus);
0075 
0076     TEST_ASSERT_VAL("wrong id", ev->id == 123);
0077     TEST_ASSERT_VAL("wrong type", ev->type == PERF_EVENT_UPDATE__CPUS);
0078     TEST_ASSERT_VAL("wrong cpus", perf_cpu_map__nr(map) == 3);
0079     TEST_ASSERT_VAL("wrong cpus", perf_cpu_map__cpu(map, 0).cpu == 1);
0080     TEST_ASSERT_VAL("wrong cpus", perf_cpu_map__cpu(map, 1).cpu == 2);
0081     TEST_ASSERT_VAL("wrong cpus", perf_cpu_map__cpu(map, 2).cpu == 3);
0082     perf_cpu_map__put(map);
0083     return 0;
0084 }
0085 
0086 static int test__event_update(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
0087 {
0088     struct evsel *evsel;
0089     struct event_name tmp;
0090     struct evlist *evlist = evlist__new_default();
0091 
0092     TEST_ASSERT_VAL("failed to get evlist", evlist);
0093 
0094     evsel = evlist__first(evlist);
0095 
0096     TEST_ASSERT_VAL("failed to allocate ids",
0097             !perf_evsel__alloc_id(&evsel->core, 1, 1));
0098 
0099     perf_evlist__id_add(&evlist->core, &evsel->core, 0, 0, 123);
0100 
0101     free((char *)evsel->unit);
0102     evsel->unit = strdup("KRAVA");
0103 
0104     TEST_ASSERT_VAL("failed to synthesize attr update unit",
0105             !perf_event__synthesize_event_update_unit(NULL, evsel, process_event_unit));
0106 
0107     evsel->scale = 0.123;
0108 
0109     TEST_ASSERT_VAL("failed to synthesize attr update scale",
0110             !perf_event__synthesize_event_update_scale(NULL, evsel, process_event_scale));
0111 
0112     tmp.name = evsel__name(evsel);
0113 
0114     TEST_ASSERT_VAL("failed to synthesize attr update name",
0115             !perf_event__synthesize_event_update_name(&tmp.tool, evsel, process_event_name));
0116 
0117     evsel->core.own_cpus = perf_cpu_map__new("1,2,3");
0118 
0119     TEST_ASSERT_VAL("failed to synthesize attr update cpus",
0120             !perf_event__synthesize_event_update_cpus(&tmp.tool, evsel, process_event_cpus));
0121 
0122     evlist__delete(evlist);
0123     return 0;
0124 }
0125 
0126 DEFINE_SUITE("Synthesize attr update", event_update);