linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] perf test tsc: Fix error message report when not supported.
@ 2022-04-02 11:42 Chengdong Li
  2022-04-04  4:41 ` Adrian Hunter
  0 siblings, 1 reply; 2+ messages in thread
From: Chengdong Li @ 2022-04-02 11:42 UTC (permalink / raw)
  To: adrian.hunter, linux-kernel, linux-perf-users, peterz, mingo,
	acme, mark.rutland, alexander.shishkin, jolsa, namhyung
  Cc: ak, likexu, chengdongli

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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-04-04  4:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-04-02 11:42 [PATCH] perf test tsc: Fix error message report when not supported Chengdong Li
2022-04-04  4:41 ` Adrian Hunter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).