xref: /linux/tools/perf/tests/evsel-tp-sched.c (revision ca55b2fef3a9373fcfc30f82fd26bc7fccbda732)
1 #include <traceevent/event-parse.h>
2 #include "evsel.h"
3 #include "tests.h"
4 #include "debug.h"
5 
6 static int perf_evsel__test_field(struct perf_evsel *evsel, const char *name,
7 				  int size, bool should_be_signed)
8 {
9 	struct format_field *field = perf_evsel__field(evsel, name);
10 	int is_signed;
11 	int ret = 0;
12 
13 	if (field == NULL) {
14 		pr_debug("%s: \"%s\" field not found!\n", evsel->name, name);
15 		return -1;
16 	}
17 
18 	is_signed = !!(field->flags | FIELD_IS_SIGNED);
19 	if (should_be_signed && !is_signed) {
20 		pr_debug("%s: \"%s\" signedness(%d) is wrong, should be %d\n",
21 			 evsel->name, name, is_signed, should_be_signed);
22 		ret = -1;
23 	}
24 
25 	if (field->size != size) {
26 		pr_debug("%s: \"%s\" size (%d) should be %d!\n",
27 			 evsel->name, name, field->size, size);
28 		ret = -1;
29 	}
30 
31 	return ret;
32 }
33 
34 int test__perf_evsel__tp_sched_test(void)
35 {
36 	struct perf_evsel *evsel = perf_evsel__newtp("sched", "sched_switch");
37 	int ret = 0;
38 
39 	if (evsel == NULL) {
40 		pr_debug("perf_evsel__new\n");
41 		return -1;
42 	}
43 
44 	if (perf_evsel__test_field(evsel, "prev_comm", 16, true))
45 		ret = -1;
46 
47 	if (perf_evsel__test_field(evsel, "prev_pid", 4, true))
48 		ret = -1;
49 
50 	if (perf_evsel__test_field(evsel, "prev_prio", 4, true))
51 		ret = -1;
52 
53 	if (perf_evsel__test_field(evsel, "prev_state", sizeof(long), true))
54 		ret = -1;
55 
56 	if (perf_evsel__test_field(evsel, "next_comm", 16, true))
57 		ret = -1;
58 
59 	if (perf_evsel__test_field(evsel, "next_pid", 4, true))
60 		ret = -1;
61 
62 	if (perf_evsel__test_field(evsel, "next_prio", 4, true))
63 		ret = -1;
64 
65 	perf_evsel__delete(evsel);
66 
67 	evsel = perf_evsel__newtp("sched", "sched_wakeup");
68 
69 	if (perf_evsel__test_field(evsel, "comm", 16, true))
70 		ret = -1;
71 
72 	if (perf_evsel__test_field(evsel, "pid", 4, true))
73 		ret = -1;
74 
75 	if (perf_evsel__test_field(evsel, "prio", 4, true))
76 		ret = -1;
77 
78 	if (perf_evsel__test_field(evsel, "target_cpu", 4, true))
79 		ret = -1;
80 
81 	return ret;
82 }
83