public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] selftests: x86: skip the tests if prerequisites aren't fulfilled
@ 2024-03-07 18:37 Muhammad Usama Anjum
  2024-03-09  1:06 ` Chang S. Bae
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Muhammad Usama Anjum @ 2024-03-07 18:37 UTC (permalink / raw)
  To: Shuah Khan, Muhammad Usama Anjum, Chang S. Bae, Dave Hansen,
	Kirill A. Shutemov, Peter Zijlstra (Intel), Weihong Zhang,
	Binbin Wu, angquan yu
  Cc: kernel, linux-kselftest, linux-kernel

Skip instead of failing when prerequisite conditions aren't fulfilled,
such as invalid xstate values etc. This patch would make the tests show
as skip when run by:
  make -C tools/testing/selftest/ TARGETS=x86 run_tests

  ...
  # timeout set to 45
  # selftests: x86: amx_64
  # # xstate cpuid: invalid tile data size/offset: 0/0
  ok 42 selftests: x86: amx_64 # SKIP
  # timeout set to 45
  # selftests: x86: lam_64
  # # Unsupported LAM feature!
  ok 43 selftests: x86: lam_64 # SKIP
  ...

Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
---
I'm not sure if xstate values should be correct on all the x86
processors. If the xstate is invalid on a CPU, the test should be
skipped instead of failing.
---
 tools/testing/selftests/x86/amx.c | 33 ++++++++++++++++++++-----------
 tools/testing/selftests/x86/lam.c |  2 +-
 2 files changed, 23 insertions(+), 12 deletions(-)

diff --git a/tools/testing/selftests/x86/amx.c b/tools/testing/selftests/x86/amx.c
index d884fd69dd510..5d1ca0bbaaae7 100644
--- a/tools/testing/selftests/x86/amx.c
+++ b/tools/testing/selftests/x86/amx.c
@@ -103,9 +103,10 @@ static void clearhandler(int sig)
 
 #define CPUID_LEAF1_ECX_XSAVE_MASK	(1 << 26)
 #define CPUID_LEAF1_ECX_OSXSAVE_MASK	(1 << 27)
-static inline void check_cpuid_xsave(void)
+static inline int check_cpuid_xsave(void)
 {
 	uint32_t eax, ebx, ecx, edx;
+	int ret = 0;
 
 	/*
 	 * CPUID.1:ECX.XSAVE[bit 26] enumerates general
@@ -113,10 +114,16 @@ static inline void check_cpuid_xsave(void)
 	 * XGETBV.
 	 */
 	__cpuid_count(1, 0, eax, ebx, ecx, edx);
-	if (!(ecx & CPUID_LEAF1_ECX_XSAVE_MASK))
-		fatal_error("cpuid: no CPU xsave support");
-	if (!(ecx & CPUID_LEAF1_ECX_OSXSAVE_MASK))
-		fatal_error("cpuid: no OS xsave support");
+	if (!(ecx & CPUID_LEAF1_ECX_XSAVE_MASK)) {
+		ksft_print_msg("cpuid: no CPU xsave support\n");
+		ret = -1;
+	}
+	if (!(ecx & CPUID_LEAF1_ECX_OSXSAVE_MASK)) {
+		ksft_print_msg("cpuid: no OS xsave support\n");
+		ret = -1;
+	}
+
+	return ret;
 }
 
 static uint32_t xbuf_size;
@@ -131,7 +138,7 @@ static struct {
 #define TILE_CPUID			0x1d
 #define TILE_PALETTE_ID			0x1
 
-static void check_cpuid_xtiledata(void)
+static int check_cpuid_xtiledata(void)
 {
 	uint32_t eax, ebx, ecx, edx;
 
@@ -153,12 +160,16 @@ static void check_cpuid_xtiledata(void)
 	 * eax: XTILEDATA state component size
 	 * ebx: XTILEDATA state component offset in user buffer
 	 */
-	if (!eax || !ebx)
-		fatal_error("xstate cpuid: invalid tile data size/offset: %d/%d",
-				eax, ebx);
+	if (!eax || !ebx) {
+		ksft_print_msg("xstate cpuid: invalid tile data size/offset: %d/%d\n",
+			       eax, ebx);
+		return -1;
+	}
 
 	xtiledata.size	      = eax;
 	xtiledata.xbuf_offset = ebx;
+
+	return 0;
 }
 
 /* The helpers for managing XSAVE buffer and tile states: */
@@ -929,8 +940,8 @@ static void test_ptrace(void)
 int main(void)
 {
 	/* Check hardware availability at first */
-	check_cpuid_xsave();
-	check_cpuid_xtiledata();
+	if (check_cpuid_xsave() || check_cpuid_xtiledata())
+		return KSFT_SKIP;
 
 	init_stashed_xsave();
 	sethandler(SIGILL, handle_noperm, 0);
diff --git a/tools/testing/selftests/x86/lam.c b/tools/testing/selftests/x86/lam.c
index 215b8150b7cca..c0f016f45ee17 100644
--- a/tools/testing/selftests/x86/lam.c
+++ b/tools/testing/selftests/x86/lam.c
@@ -1183,7 +1183,7 @@ int main(int argc, char **argv)
 
 	if (!cpu_has_lam()) {
 		ksft_print_msg("Unsupported LAM feature!\n");
-		return -1;
+		return KSFT_SKIP;
 	}
 
 	while ((c = getopt(argc, argv, "ht:")) != -1) {
-- 
2.39.2


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

end of thread, other threads:[~2024-03-12 17:28 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-07 18:37 [PATCH] selftests: x86: skip the tests if prerequisites aren't fulfilled Muhammad Usama Anjum
2024-03-09  1:06 ` Chang S. Bae
2024-03-11 17:02   ` Muhammad Usama Anjum
2024-03-11 17:39     ` Chang S. Bae
2024-03-12  9:26       ` Muhammad Usama Anjum
2024-03-12 16:07         ` Chang S. Bae
2024-03-12 17:28           ` Muhammad Usama Anjum
2024-03-11 12:39 ` Kirill A. Shutemov
2024-03-12  0:10 ` Binbin Wu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox