2022-04-05 02:00:10

by Chengdong Li

[permalink] [raw]
Subject: [PATCH] perf test tsc: Fix error message report when not supported.

By default `perf test tsc` does not return the error message
when child process detected kernel does not support. Instead, child
process print error message to stderr, unfortunately the stderr is
redirected to /dev/null when verbose <= 0.
This patch add a helper function test__perf_test_tsc_skip_reason() to
help parent process to get the appropriate error message and force child
process returns TEST_SKIP instead of TEST_OK.

Signed-off-by: Chengdong Li <[email protected]>
---
tools/perf/tests/builtin-test.c | 3 +++
tools/perf/tests/perf-time-to-tsc.c | 17 +++++++++++------
tools/perf/tests/tests.h | 1 +
3 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index da7dc5e45d0c..d3359ed2f3df 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -359,6 +359,9 @@ static struct test generic_tests[] = {
.desc = "Convert perf time to TSC",
.func = test__perf_time_to_tsc,
.is_supported = test__tsc_is_supported,
+ .subtest = {
+ .skip_reason = test__perf_time_to_tsc_skip_reason,
+ },
},
{
.desc = "dlfilter C API",
diff --git a/tools/perf/tests/perf-time-to-tsc.c b/tools/perf/tests/perf-time-to-tsc.c
index 7c56bc1f4cff..4e7da132ca47 100644
--- a/tools/perf/tests/perf-time-to-tsc.c
+++ b/tools/perf/tests/perf-time-to-tsc.c
@@ -37,6 +37,13 @@
} \
}

+static const char *notsupported = "not supported";
+
+const char *test__perf_time_to_tsc_skip_reason(int subtest __maybe_unused)
+{
+ return notsupported;
+}
+
/**
* test__perf_time_to_tsc - test converting perf time to TSC.
*
@@ -60,7 +67,7 @@ int test__perf_time_to_tsc(struct test *test __maybe_unused, int subtest __maybe
struct perf_cpu_map *cpus = NULL;
struct evlist *evlist = NULL;
struct evsel *evsel = NULL;
- int err = -1, ret, i;
+ int err = TEST_FAIL, ret, i;
const char *comm1, *comm2;
struct perf_tsc_conversion tc;
struct perf_event_mmap_page *pc;
@@ -108,10 +115,8 @@ int test__perf_time_to_tsc(struct test *test __maybe_unused, int subtest __maybe
pc = evlist->mmap[0].core.base;
ret = perf_read_tsc_conversion(pc, &tc);
if (ret) {
- if (ret == -EOPNOTSUPP) {
- fprintf(stderr, " (not supported)");
- return 0;
- }
+ if (ret == -EOPNOTSUPP)
+ err = TEST_SKIP;
goto out_err;
}

@@ -176,7 +181,7 @@ int test__perf_time_to_tsc(struct test *test __maybe_unused, int subtest __maybe
test_tsc >= comm2_tsc)
goto out_err;

- err = 0;
+ err = TEST_OK;

out_err:
evlist__delete(evlist);
diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h
index fe1306f58495..2ba0f260d3ea 100644
--- a/tools/perf/tests/tests.h
+++ b/tools/perf/tests/tests.h
@@ -127,6 +127,7 @@ int test__parse_metric(struct test *test, int subtest);
int test__pe_file_parsing(struct test *test, int subtest);
int test__expand_cgroup_events(struct test *test, int subtest);
int test__perf_time_to_tsc(struct test *test, int subtest);
+const char *test__perf_time_to_tsc_skip_reason(int subtest);
int test__dlfilter(struct test *test, int subtest);

bool test__bp_signal_is_supported(void);
--
2.27.0


2022-04-05 02:38:07

by Adrian Hunter

[permalink] [raw]
Subject: Re: [PATCH] perf test tsc: Fix error message report when not supported.

On 02/04/2022 14.42, Chengdong Li wrote:
> By default `perf test tsc` does not return the error message
> when child process detected kernel does not support. Instead, child
> process print error message to stderr, unfortunately the stderr is
> redirected to /dev/null when verbose <= 0.
> This patch add a helper function test__perf_test_tsc_skip_reason() to
> help parent process to get the appropriate error message and force child
> process returns TEST_SKIP instead of TEST_OK.
>
> Signed-off-by: Chengdong Li <[email protected]>
> ---
> tools/perf/tests/builtin-test.c | 3 +++
> tools/perf/tests/perf-time-to-tsc.c | 17 +++++++++++------
> tools/perf/tests/tests.h | 1 +
> 3 files changed, 15 insertions(+), 6 deletions(-)
>

Please base on current source, for example perf/core branch of:

git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git