Messages in this thread Patch in this message |  | | From | Chengdong Li <> | Subject | [PATCH] perf test tsc: Fix error message report when not supported. | Date | Sat, 2 Apr 2022 19:42:18 +0800 |
| |
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 <chengdongli@tencent.com> --- 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
|  |