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