~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/perf/tests/event_update.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

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

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php