Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Jiri Olsa | 8dd2a13 | 2015-09-07 10:38:06 +0200 | [diff] [blame] | 2 | #include <linux/err.h> |
Robert Richter | 4e31902 | 2013-06-11 17:29:18 +0200 | [diff] [blame] | 3 | #include <traceevent/event-parse.h> |
Jiri Olsa | 5e24a09 | 2012-11-10 01:46:48 +0100 | [diff] [blame] | 4 | #include "evsel.h" |
| 5 | #include "tests.h" |
Jiri Olsa | 84f5d36 | 2014-07-14 23:46:48 +0200 | [diff] [blame] | 6 | #include "debug.h" |
Jiri Olsa | 5e24a09 | 2012-11-10 01:46:48 +0100 | [diff] [blame] | 7 | |
| 8 | static int perf_evsel__test_field(struct perf_evsel *evsel, const char *name, |
| 9 | int size, bool should_be_signed) |
| 10 | { |
| 11 | struct format_field *field = perf_evsel__field(evsel, name); |
| 12 | int is_signed; |
| 13 | int ret = 0; |
| 14 | |
| 15 | if (field == NULL) { |
| 16 | pr_debug("%s: \"%s\" field not found!\n", evsel->name, name); |
| 17 | return -1; |
| 18 | } |
| 19 | |
| 20 | is_signed = !!(field->flags | FIELD_IS_SIGNED); |
| 21 | if (should_be_signed && !is_signed) { |
| 22 | pr_debug("%s: \"%s\" signedness(%d) is wrong, should be %d\n", |
| 23 | evsel->name, name, is_signed, should_be_signed); |
| 24 | ret = -1; |
| 25 | } |
| 26 | |
| 27 | if (field->size != size) { |
| 28 | pr_debug("%s: \"%s\" size (%d) should be %d!\n", |
| 29 | evsel->name, name, field->size, size); |
| 30 | ret = -1; |
| 31 | } |
| 32 | |
| 33 | return ret; |
| 34 | } |
| 35 | |
Arnaldo Carvalho de Melo | 81f17c9 | 2017-08-03 15:16:31 -0300 | [diff] [blame] | 36 | int test__perf_evsel__tp_sched_test(struct test *test __maybe_unused, int subtest __maybe_unused) |
Jiri Olsa | 5e24a09 | 2012-11-10 01:46:48 +0100 | [diff] [blame] | 37 | { |
Arnaldo Carvalho de Melo | ef50383 | 2013-11-07 16:41:19 -0300 | [diff] [blame] | 38 | struct perf_evsel *evsel = perf_evsel__newtp("sched", "sched_switch"); |
Jiri Olsa | 5e24a09 | 2012-11-10 01:46:48 +0100 | [diff] [blame] | 39 | int ret = 0; |
| 40 | |
Jiri Olsa | 8dd2a13 | 2015-09-07 10:38:06 +0200 | [diff] [blame] | 41 | if (IS_ERR(evsel)) { |
| 42 | pr_debug("perf_evsel__newtp failed with %ld\n", PTR_ERR(evsel)); |
Jiri Olsa | 5e24a09 | 2012-11-10 01:46:48 +0100 | [diff] [blame] | 43 | return -1; |
| 44 | } |
| 45 | |
| 46 | if (perf_evsel__test_field(evsel, "prev_comm", 16, true)) |
| 47 | ret = -1; |
| 48 | |
| 49 | if (perf_evsel__test_field(evsel, "prev_pid", 4, true)) |
| 50 | ret = -1; |
| 51 | |
| 52 | if (perf_evsel__test_field(evsel, "prev_prio", 4, true)) |
| 53 | ret = -1; |
| 54 | |
Jiri Olsa | 8d76e18 | 2013-07-12 16:29:06 +0200 | [diff] [blame] | 55 | if (perf_evsel__test_field(evsel, "prev_state", sizeof(long), true)) |
Jiri Olsa | 5e24a09 | 2012-11-10 01:46:48 +0100 | [diff] [blame] | 56 | ret = -1; |
| 57 | |
| 58 | if (perf_evsel__test_field(evsel, "next_comm", 16, true)) |
| 59 | ret = -1; |
| 60 | |
| 61 | if (perf_evsel__test_field(evsel, "next_pid", 4, true)) |
| 62 | ret = -1; |
| 63 | |
| 64 | if (perf_evsel__test_field(evsel, "next_prio", 4, true)) |
| 65 | ret = -1; |
| 66 | |
| 67 | perf_evsel__delete(evsel); |
| 68 | |
Arnaldo Carvalho de Melo | ef50383 | 2013-11-07 16:41:19 -0300 | [diff] [blame] | 69 | evsel = perf_evsel__newtp("sched", "sched_wakeup"); |
Jiri Olsa | 5e24a09 | 2012-11-10 01:46:48 +0100 | [diff] [blame] | 70 | |
Jiri Olsa | 8dd2a13 | 2015-09-07 10:38:06 +0200 | [diff] [blame] | 71 | if (IS_ERR(evsel)) { |
| 72 | pr_debug("perf_evsel__newtp failed with %ld\n", PTR_ERR(evsel)); |
| 73 | return -1; |
| 74 | } |
| 75 | |
Jiri Olsa | 5e24a09 | 2012-11-10 01:46:48 +0100 | [diff] [blame] | 76 | if (perf_evsel__test_field(evsel, "comm", 16, true)) |
| 77 | ret = -1; |
| 78 | |
| 79 | if (perf_evsel__test_field(evsel, "pid", 4, true)) |
| 80 | ret = -1; |
| 81 | |
| 82 | if (perf_evsel__test_field(evsel, "prio", 4, true)) |
| 83 | ret = -1; |
| 84 | |
Jiri Olsa | 5e24a09 | 2012-11-10 01:46:48 +0100 | [diff] [blame] | 85 | if (perf_evsel__test_field(evsel, "target_cpu", 4, true)) |
| 86 | ret = -1; |
| 87 | |
| 88 | return ret; |
| 89 | } |