Skip to content

Commit 290fa68

Browse files
Chengdong Liacmel
authored andcommitted
perf test tsc: Fix error message when not supported
By default `perf test tsc` does not return the error message when the child process detected kernel does not support it. Instead, the child process prints an error message to stderr, unfortunately stderr is redirected to /dev/null when verbose <= 0. This patch does: - return TEST_SKIP to the parent process instead of TEST_OK when perf_read_tsc_conversion() is not supported. - Add a new subtest of testing if TSC is supported on current architecture by moving exist code to a separate function. It avoids two places in test__perf_time_to_tsc() that return TEST_SKIP by doing this. - Extend the test suite definition to contain above two subtests. Current test_suite and test_case structs do not support printing skip reason when the number of subtest less than 1. To print skip reason, it is necessary to extend current test suite definition. Reviewed-by: Adrian Hunter <adrian.hunter@intel.com> Signed-off-by: Chengdong Li <chengdongli@tencent.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: likexu@tencent.com Link: https://lore.kernel.org/r/20220408084748.43707-1-chengdongli@tencent.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 3a8a047 commit 290fa68

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

tools/perf/tests/perf-time-to-tsc.c

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,17 @@
4747
} \
4848
}
4949

50+
static int test__tsc_is_supported(struct test_suite *test __maybe_unused,
51+
int subtest __maybe_unused)
52+
{
53+
if (!TSC_IS_SUPPORTED) {
54+
pr_debug("Test not supported on this architecture\n");
55+
return TEST_SKIP;
56+
}
57+
58+
return TEST_OK;
59+
}
60+
5061
/**
5162
* test__perf_time_to_tsc - test converting perf time to TSC.
5263
*
@@ -70,7 +81,7 @@ static int test__perf_time_to_tsc(struct test_suite *test __maybe_unused, int su
7081
struct perf_cpu_map *cpus = NULL;
7182
struct evlist *evlist = NULL;
7283
struct evsel *evsel = NULL;
73-
int err = -1, ret, i;
84+
int err = TEST_FAIL, ret, i;
7485
const char *comm1, *comm2;
7586
struct perf_tsc_conversion tc;
7687
struct perf_event_mmap_page *pc;
@@ -79,10 +90,6 @@ static int test__perf_time_to_tsc(struct test_suite *test __maybe_unused, int su
7990
u64 test_time, comm1_time = 0, comm2_time = 0;
8091
struct mmap *md;
8192

82-
if (!TSC_IS_SUPPORTED) {
83-
pr_debug("Test not supported on this architecture");
84-
return TEST_SKIP;
85-
}
8693

8794
threads = thread_map__new(-1, getpid(), UINT_MAX);
8895
CHECK_NOT_NULL__(threads);
@@ -124,8 +131,8 @@ static int test__perf_time_to_tsc(struct test_suite *test __maybe_unused, int su
124131
ret = perf_read_tsc_conversion(pc, &tc);
125132
if (ret) {
126133
if (ret == -EOPNOTSUPP) {
127-
fprintf(stderr, " (not supported)");
128-
return 0;
134+
pr_debug("perf_read_tsc_conversion is not supported in current kernel\n");
135+
err = TEST_SKIP;
129136
}
130137
goto out_err;
131138
}
@@ -191,7 +198,7 @@ static int test__perf_time_to_tsc(struct test_suite *test __maybe_unused, int su
191198
test_tsc >= comm2_tsc)
192199
goto out_err;
193200

194-
err = 0;
201+
err = TEST_OK;
195202

196203
out_err:
197204
evlist__delete(evlist);
@@ -200,4 +207,15 @@ static int test__perf_time_to_tsc(struct test_suite *test __maybe_unused, int su
200207
return err;
201208
}
202209

203-
DEFINE_SUITE("Convert perf time to TSC", perf_time_to_tsc);
210+
static struct test_case time_to_tsc_tests[] = {
211+
TEST_CASE_REASON("TSC support", tsc_is_supported,
212+
"This architecture does not support"),
213+
TEST_CASE_REASON("Perf time to TSC", perf_time_to_tsc,
214+
"perf_read_tsc_conversion is not supported"),
215+
{ .name = NULL, }
216+
};
217+
218+
struct test_suite suite__perf_time_to_tsc = {
219+
.desc = "Convert perf time to TSC",
220+
.test_cases = time_to_tsc_tests,
221+
};

0 commit comments

Comments
 (0)