Linux Audio

Check our new training course

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