diff options
-rw-r--r-- | tools/perf/builtin-test.c | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/tools/perf/builtin-test.c b/tools/perf/builtin-test.c index 4aed1553db56..32caf13cfe01 100644 --- a/tools/perf/builtin-test.c +++ b/tools/perf/builtin-test.c | |||
@@ -14,6 +14,7 @@ | |||
14 | #include "util/symbol.h" | 14 | #include "util/symbol.h" |
15 | #include "util/thread_map.h" | 15 | #include "util/thread_map.h" |
16 | #include "util/pmu.h" | 16 | #include "util/pmu.h" |
17 | #include "event-parse.h" | ||
17 | #include "../../include/linux/hw_breakpoint.h" | 18 | #include "../../include/linux/hw_breakpoint.h" |
18 | 19 | ||
19 | #include <sys/mman.h> | 20 | #include <sys/mman.h> |
@@ -1207,6 +1208,87 @@ static int perf_evsel__roundtrip_name_test(void) | |||
1207 | return ret; | 1208 | return ret; |
1208 | } | 1209 | } |
1209 | 1210 | ||
1211 | static int perf_evsel__test_field(struct perf_evsel *evsel, const char *name, | ||
1212 | int size, bool should_be_signed) | ||
1213 | { | ||
1214 | struct format_field *field = perf_evsel__field(evsel, name); | ||
1215 | int is_signed; | ||
1216 | int ret = 0; | ||
1217 | |||
1218 | if (field == NULL) { | ||
1219 | pr_debug("%s: \"%s\" field not found!\n", evsel->name, name); | ||
1220 | return -1; | ||
1221 | } | ||
1222 | |||
1223 | is_signed = !!(field->flags | FIELD_IS_SIGNED); | ||
1224 | if (should_be_signed && !is_signed) { | ||
1225 | pr_debug("%s: \"%s\" signedness(%d) is wrong, should be %d\n", | ||
1226 | evsel->name, name, is_signed, should_be_signed); | ||
1227 | ret = -1; | ||
1228 | } | ||
1229 | |||
1230 | if (field->size != size) { | ||
1231 | pr_debug("%s: \"%s\" size (%d) should be %d!\n", | ||
1232 | evsel->name, name, field->size, size); | ||
1233 | ret = -1; | ||
1234 | } | ||
1235 | |||
1236 | return 0; | ||
1237 | } | ||
1238 | |||
1239 | static int perf_evsel__tp_sched_test(void) | ||
1240 | { | ||
1241 | struct perf_evsel *evsel = perf_evsel__newtp("sched", "sched_switch", 0); | ||
1242 | int ret = 0; | ||
1243 | |||
1244 | if (evsel == NULL) { | ||
1245 | pr_debug("perf_evsel__new\n"); | ||
1246 | return -1; | ||
1247 | } | ||
1248 | |||
1249 | if (perf_evsel__test_field(evsel, "prev_comm", 16, true)) | ||
1250 | ret = -1; | ||
1251 | |||
1252 | if (perf_evsel__test_field(evsel, "prev_pid", 4, true)) | ||
1253 | ret = -1; | ||
1254 | |||
1255 | if (perf_evsel__test_field(evsel, "prev_prio", 4, true)) | ||
1256 | ret = -1; | ||
1257 | |||
1258 | if (perf_evsel__test_field(evsel, "prev_state", 8, true)) | ||
1259 | ret = -1; | ||
1260 | |||
1261 | if (perf_evsel__test_field(evsel, "next_comm", 16, true)) | ||
1262 | ret = -1; | ||
1263 | |||
1264 | if (perf_evsel__test_field(evsel, "next_pid", 4, true)) | ||
1265 | ret = -1; | ||
1266 | |||
1267 | if (perf_evsel__test_field(evsel, "next_prio", 4, true)) | ||
1268 | ret = -1; | ||
1269 | |||
1270 | perf_evsel__delete(evsel); | ||
1271 | |||
1272 | evsel = perf_evsel__newtp("sched", "sched_wakeup", 0); | ||
1273 | |||
1274 | if (perf_evsel__test_field(evsel, "comm", 16, true)) | ||
1275 | ret = -1; | ||
1276 | |||
1277 | if (perf_evsel__test_field(evsel, "pid", 4, true)) | ||
1278 | ret = -1; | ||
1279 | |||
1280 | if (perf_evsel__test_field(evsel, "prio", 4, true)) | ||
1281 | ret = -1; | ||
1282 | |||
1283 | if (perf_evsel__test_field(evsel, "success", 4, true)) | ||
1284 | ret = -1; | ||
1285 | |||
1286 | if (perf_evsel__test_field(evsel, "target_cpu", 4, true)) | ||
1287 | ret = -1; | ||
1288 | |||
1289 | return 0; | ||
1290 | } | ||
1291 | |||
1210 | static struct test { | 1292 | static struct test { |
1211 | const char *desc; | 1293 | const char *desc; |
1212 | int (*func)(void); | 1294 | int (*func)(void); |
@@ -1254,6 +1336,10 @@ static struct test { | |||
1254 | .func = perf_evsel__roundtrip_name_test, | 1336 | .func = perf_evsel__roundtrip_name_test, |
1255 | }, | 1337 | }, |
1256 | { | 1338 | { |
1339 | .desc = "Check parsing of sched tracepoints fields", | ||
1340 | .func = perf_evsel__tp_sched_test, | ||
1341 | }, | ||
1342 | { | ||
1257 | .func = NULL, | 1343 | .func = NULL, |
1258 | }, | 1344 | }, |
1259 | }; | 1345 | }; |