Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Chengdong Li and committed by
Arnaldo Carvalho de Melo
290fa68b 3a8a0475

+27 -9
+27 -9
tools/perf/tests/perf-time-to-tsc.c
··· 47 47 } \ 48 48 } 49 49 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 + 50 61 /** 51 62 * test__perf_time_to_tsc - test converting perf time to TSC. 52 63 * ··· 81 70 struct perf_cpu_map *cpus = NULL; 82 71 struct evlist *evlist = NULL; 83 72 struct evsel *evsel = NULL; 84 - int err = -1, ret, i; 73 + int err = TEST_FAIL, ret, i; 85 74 const char *comm1, *comm2; 86 75 struct perf_tsc_conversion tc; 87 76 struct perf_event_mmap_page *pc; ··· 90 79 u64 test_time, comm1_time = 0, comm2_time = 0; 91 80 struct mmap *md; 92 81 93 - if (!TSC_IS_SUPPORTED) { 94 - pr_debug("Test not supported on this architecture"); 95 - return TEST_SKIP; 96 - } 97 82 98 83 threads = thread_map__new(-1, getpid(), UINT_MAX); 99 84 CHECK_NOT_NULL__(threads); ··· 131 124 ret = perf_read_tsc_conversion(pc, &tc); 132 125 if (ret) { 133 126 if (ret == -EOPNOTSUPP) { 134 - fprintf(stderr, " (not supported)"); 135 - return 0; 127 + pr_debug("perf_read_tsc_conversion is not supported in current kernel\n"); 128 + err = TEST_SKIP; 136 129 } 137 130 goto out_err; 138 131 } ··· 198 191 test_tsc >= comm2_tsc) 199 192 goto out_err; 200 193 201 - err = 0; 194 + err = TEST_OK; 202 195 203 196 out_err: 204 197 evlist__delete(evlist); ··· 207 200 return err; 208 201 } 209 202 210 - DEFINE_SUITE("Convert perf time to TSC", perf_time_to_tsc); 203 + static struct test_case time_to_tsc_tests[] = { 204 + TEST_CASE_REASON("TSC support", tsc_is_supported, 205 + "This architecture does not support"), 206 + TEST_CASE_REASON("Perf time to TSC", perf_time_to_tsc, 207 + "perf_read_tsc_conversion is not supported"), 208 + { .name = NULL, } 209 + }; 210 + 211 + struct test_suite suite__perf_time_to_tsc = { 212 + .desc = "Convert perf time to TSC", 213 + .test_cases = time_to_tsc_tests, 214 + };