[PATCH] kselftest/riscv: Improve building under native riscv64 environment

Hui Wang hui.wang at canonical.com
Mon Jul 13 21:31:08 PDT 2026


When we build the kselftest natively, we usually don't pass an ARCH=
parameter. In this case if I build kselftest/riscv under a riscv64
environment, the testcase will not be built at all because 'uname -m'
returns riscv64 instead of riscv.

    make -C tools/testing/selftests TARGETS=riscv
    make: Entering directory 'linux/tools/testing/selftests'
    make[1]: Entering directory 'linux/tools/testing/selftests/riscv'
    make[1]: Leaving directory 'linux/tools/testing/selftests/riscv'
    make: Leaving directory 'linux/tools/testing/selftests'

This issue can be fixed by getting ARCH from scripts/subarch.include,
whose SUBARCH normalizes 'riscv64' to 'riscv'. This also aligns with
how other selftests (e.g. arm64, x86) already resolve ARCH.

Signed-off-by: Hui Wang <hui.wang at canonical.com>
---
 tools/testing/selftests/riscv/Makefile | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/tools/testing/selftests/riscv/Makefile b/tools/testing/selftests/riscv/Makefile
index 5671b4405a12..43eddb919705 100644
--- a/tools/testing/selftests/riscv/Makefile
+++ b/tools/testing/selftests/riscv/Makefile
@@ -1,8 +1,12 @@
 # SPDX-License-Identifier: GPL-2.0
 # Originally tools/testing/arm64/Makefile
 
+# A proper top_srcdir is needed by KSFT(lib.mk)
+top_srcdir = $(realpath ../../../../)
+
 # When ARCH not overridden for crosscompiling, lookup machine
-ARCH ?= $(shell uname -m 2>/dev/null || echo not)
+include $(top_srcdir)/scripts/subarch.include
+ARCH ?= $(SUBARCH)
 
 ifneq (,$(filter $(ARCH),riscv))
 RISCV_SUBTARGETS ?= abi hwprobe mm sigreturn vector cfi
@@ -12,9 +16,6 @@ endif
 
 CFLAGS := -Wall -O2 -g
 
-# A proper top_srcdir is needed by KSFT(lib.mk)
-top_srcdir = $(realpath ../../../../)
-
 # Additional include paths needed by kselftest.h and local headers
 CFLAGS += -I$(top_srcdir)/tools/testing/selftests/
 
-- 
2.43.0




More information about the linux-riscv mailing list