blob: 9cdf4c9349778565d9c752e4f2fc1d80b2ed9aa5 [file] [log] [blame]
Jiri Olsaa6e52812015-10-25 15:51:37 +01001#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
21int test__event_update(int subtest __maybe_unused)
22{
23 struct perf_evlist *evlist;
24 struct perf_evsel *evsel;
25
26 evlist = perf_evlist__new_default();
27 TEST_ASSERT_VAL("failed to get evlist", evlist);
28
29 evsel = perf_evlist__first(evlist);
30
31 TEST_ASSERT_VAL("failed to allos ids",
32 !perf_evsel__alloc_id(evsel, 1, 1));
33
34 perf_evlist__id_add(evlist, evsel, 0, 0, 123);
35
36 evsel->unit = strdup("KRAVA");
37
38 TEST_ASSERT_VAL("failed to synthesize attr update unit",
39 !perf_event__synthesize_event_update_unit(NULL, evsel, process_event_unit));
40
41 return 0;
42}