forked from luck/tmp_suning_uos_patched
489338a717
Notice that the use of the bitwise OR operator '|' always leads to true
in this particular case, which seems a bit suspicious due to the context
in which this expression is being used.
Fix this by using bitwise AND operator '&' instead.
This bug was detected with the help of Coccinelle.
Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: stable@vger.kernel.org
Fixes: 6a6cd11d4e
("perf test: Add test for the sched tracepoint format fields")
Link: http://lkml.kernel.org/r/20190122233439.GA5868@embeddedor
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
90 lines
2.1 KiB
C
90 lines
2.1 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
#include <linux/err.h>
|
|
#include <traceevent/event-parse.h>
|
|
#include "evsel.h"
|
|
#include "tests.h"
|
|
#include "debug.h"
|
|
|
|
static int perf_evsel__test_field(struct perf_evsel *evsel, const char *name,
|
|
int size, bool should_be_signed)
|
|
{
|
|
struct tep_format_field *field = perf_evsel__field(evsel, name);
|
|
int is_signed;
|
|
int ret = 0;
|
|
|
|
if (field == NULL) {
|
|
pr_debug("%s: \"%s\" field not found!\n", evsel->name, name);
|
|
return -1;
|
|
}
|
|
|
|
is_signed = !!(field->flags & TEP_FIELD_IS_SIGNED);
|
|
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;
|
|
}
|
|
|
|
int test__perf_evsel__tp_sched_test(struct test *test __maybe_unused, int subtest __maybe_unused)
|
|
{
|
|
struct perf_evsel *evsel = perf_evsel__newtp("sched", "sched_switch");
|
|
int ret = 0;
|
|
|
|
if (IS_ERR(evsel)) {
|
|
pr_debug("perf_evsel__newtp failed with %ld\n", PTR_ERR(evsel));
|
|
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;
|
|
|
|
if (perf_evsel__test_field(evsel, "prev_state", sizeof(long), true))
|
|
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);
|
|
|
|
evsel = perf_evsel__newtp("sched", "sched_wakeup");
|
|
|
|
if (IS_ERR(evsel)) {
|
|
pr_debug("perf_evsel__newtp failed with %ld\n", PTR_ERR(evsel));
|
|
return -1;
|
|
}
|
|
|
|
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;
|
|
}
|