evsel-tp-sched.c 2.1 KB
Newer Older
1
// SPDX-License-Identifier: GPL-2.0
2
#include <linux/err.h>
3
#include <traceevent/event-parse.h>
4 5
#include "evsel.h"
#include "tests.h"
6
#include "debug.h"
7 8 9 10

static int perf_evsel__test_field(struct perf_evsel *evsel, const char *name,
				  int size, bool should_be_signed)
{
11
	struct tep_format_field *field = perf_evsel__field(evsel, name);
12 13 14 15 16 17 18 19
	int is_signed;
	int ret = 0;

	if (field == NULL) {
		pr_debug("%s: \"%s\" field not found!\n", evsel->name, name);
		return -1;
	}

20
	is_signed = !!(field->flags & TEP_FIELD_IS_SIGNED);
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
	if (should_be_signed && !is_signed) {
		pr_debug("%s: \"%s\" signedness(%d) is wrong, should be %d\n",
			 evsel->name, name, is_signed, should_be_signed);
		ret = -1;
	}

	if (field->size != size) {
		pr_debug("%s: \"%s\" size (%d) should be %d!\n",
			 evsel->name, name, field->size, size);
		ret = -1;
	}

	return ret;
}

36
int test__perf_evsel__tp_sched_test(struct test *test __maybe_unused, int subtest __maybe_unused)
37
{
38
	struct perf_evsel *evsel = perf_evsel__newtp("sched", "sched_switch");
39 40
	int ret = 0;

41 42
	if (IS_ERR(evsel)) {
		pr_debug("perf_evsel__newtp failed with %ld\n", PTR_ERR(evsel));
43 44 45 46 47 48 49 50 51 52 53 54
		return -1;
	}

	if (perf_evsel__test_field(evsel, "prev_comm", 16, true))
		ret = -1;

	if (perf_evsel__test_field(evsel, "prev_pid", 4, true))
		ret = -1;

	if (perf_evsel__test_field(evsel, "prev_prio", 4, true))
		ret = -1;

55
	if (perf_evsel__test_field(evsel, "prev_state", sizeof(long), true))
56 57 58 59 60 61 62 63 64 65 66 67 68
		ret = -1;

	if (perf_evsel__test_field(evsel, "next_comm", 16, true))
		ret = -1;

	if (perf_evsel__test_field(evsel, "next_pid", 4, true))
		ret = -1;

	if (perf_evsel__test_field(evsel, "next_prio", 4, true))
		ret = -1;

	perf_evsel__delete(evsel);

69
	evsel = perf_evsel__newtp("sched", "sched_wakeup");
70

71 72 73 74 75
	if (IS_ERR(evsel)) {
		pr_debug("perf_evsel__newtp failed with %ld\n", PTR_ERR(evsel));
		return -1;
	}

76 77 78 79 80 81 82 83 84 85 86 87 88 89
	if (perf_evsel__test_field(evsel, "comm", 16, true))
		ret = -1;

	if (perf_evsel__test_field(evsel, "pid", 4, true))
		ret = -1;

	if (perf_evsel__test_field(evsel, "prio", 4, true))
		ret = -1;

	if (perf_evsel__test_field(evsel, "target_cpu", 4, true))
		ret = -1;

	return ret;
}