[RFC PATCH v1 4/4] riscv: Add test for hwcaps-subdir
Yao Zihong
zihong.plct@isrc.iscas.ac.cn
Fri Sep 26 14:48:42 GMT 2025
Introduce basic tests for RISC-V glibc-hwcaps subdirs(rva20u64),
similar to existing powerpc/x86 coverage.
Signed-off-by: Yao Zihong <zihong.plct@isrc.iscas.ac.cn>
---
elf/Makefile | 2 +-
elf/tst-glibc-hwcaps-cache.script | 10 +++++
sysdeps/riscv/Makefile | 6 +++
sysdeps/riscv/tst-glibc-hwcaps.c | 64 +++++++++++++++++++++++++++++++
4 files changed, 81 insertions(+), 1 deletion(-)
create mode 100644 sysdeps/riscv/tst-glibc-hwcaps.c
diff --git a/elf/Makefile b/elf/Makefile
index 5a676f858d..54703e761a 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -2884,7 +2884,7 @@ $(objpfx)argv0test.out: tst-rtld-argv0.sh $(objpfx)ld.so \
# glibc-hwcaps mechanism for this architecture). Used to obtain test
# coverage for some glibc-hwcaps tests for the widest possible range
# of systems.
-glibc-hwcaps-first-subdirs-for-tests = power9 x86-64-v2 z13
+glibc-hwcaps-first-subdirs-for-tests = power9 x86-64-v2 z13 rva20u64
# The test modules are parameterized by preprocessor macros.
LDFLAGS-libmarkermod1-1.so += -Wl,-soname,libmarkermod1.so
diff --git a/elf/tst-glibc-hwcaps-cache.script b/elf/tst-glibc-hwcaps-cache.script
index af89e9c6f8..b85b8224bf 100644
--- a/elf/tst-glibc-hwcaps-cache.script
+++ b/elf/tst-glibc-hwcaps-cache.script
@@ -43,3 +43,13 @@ mkdirp 0770 $L/glibc-hwcaps/x86-64-v4
cp $B/elf/libmarkermod4-2.so $L/glibc-hwcaps/x86-64-v2/libmarkermod4.so
cp $B/elf/libmarkermod4-3.so $L/glibc-hwcaps/x86-64-v3/libmarkermod4.so
cp $B/elf/libmarkermod4-4.so $L/glibc-hwcaps/x86-64-v4/libmarkermod4.so
+
+mkdirp 0770 $L/glibc-hwcaps/rva20u64
+cp $B/elf/libmarkermod2-2.so $L/glibc-hwcaps/rva20u64/libmarkermod2.so
+mkdirp 0770 $L/glibc-hwcaps/rva22u64
+cp $B/elf/libmarkermod3-2.so $L/glibc-hwcaps/rva20u64/libmarkermod3.so
+cp $B/elf/libmarkermod3-3.so $L/glibc-hwcaps/rva22u64/libmarkermod3.so
+mkdirp 0770 $L/glibc-hwcaps/rva23u64
+cp $B/elf/libmarkermod4-2.so $L/glibc-hwcaps/rva20u64/libmarkermod4.so
+cp $B/elf/libmarkermod4-3.so $L/glibc-hwcaps/rva22u64/libmarkermod4.so
+cp $B/elf/libmarkermod4-4.so $L/glibc-hwcaps/rva23u64/libmarkermod4.so
diff --git a/sysdeps/riscv/Makefile b/sysdeps/riscv/Makefile
index 7d149d42e6..be49c6fcf5 100644
--- a/sysdeps/riscv/Makefile
+++ b/sysdeps/riscv/Makefile
@@ -37,6 +37,12 @@ $(objpfx)glibc-hwcaps/rva23u64/libmarkermod4.so: $(objpfx)libmarkermod4-4.so
$(make-target-directory)
cp $< $@
+ifeq (no,$(build-hardcoded-path-in-tests))
+# This is an ld.so.cache test, and RPATH/RUNPATH in the executable
+# interferes with its test objectives.
+tests-container += tst-glibc-hwcaps-cache
+endif
+
endif
# RISC-V's assembler also needs to know about PIC as it changes the definition
diff --git a/sysdeps/riscv/tst-glibc-hwcaps.c b/sysdeps/riscv/tst-glibc-hwcaps.c
new file mode 100644
index 0000000000..c1396cf39b
--- /dev/null
+++ b/sysdeps/riscv/tst-glibc-hwcaps.c
@@ -0,0 +1,64 @@
+/* glibc-hwcaps subdirectory test. RISC-V version.
+ Copyright (C) 2025 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#include <stdio.h>
+#include <support/check.h>
+#include <sys/param.h>
+#include <elf.h>
+#include <get-profile-level.h>
+
+extern int marker2 (void);
+extern int marker3 (void);
+extern int marker4 (void);
+
+/* Return the RISC-V profile level, 1 for the baseline. */
+static int
+compute_level (void)
+{
+ unsigned int profile_level = get_profile_level ();
+
+ if(profile_level < 20) {
+ return 1;
+ }
+
+ /* v2: RVA20U64 */
+ if(profile_level < 22) {
+ return 2;
+ }
+
+ /* v3: RVA22U64 */
+ if(profile_level < 23) {
+ return 3;
+ }
+
+ /* v4: RVA23U64 */
+ return 4;
+}
+
+static int
+do_test (void)
+{
+ int level = compute_level ();
+ printf ("info: detected RISC-V micro-architecture level: %d\n", level);
+ TEST_COMPARE (marker2 (), MIN (level, 2));
+ TEST_COMPARE (marker3 (), MIN (level, 3));
+ TEST_COMPARE (marker4 (), MIN (level, 4));
+ return 0;
+}
+
+#include <support/test-driver.c>
--
2.47.2
More information about the Libc-alpha
mailing list