Skip to content

Commit 1d2684a

Browse files
etterlicolluca
andauthored
treewide: Add official riscv-tests ISA tests (#218)
--------- Co-authored-by: Luca Colagrande <luca.colagrande3@gmail.com>
1 parent c176a57 commit 1d2684a

File tree

7 files changed

+255
-0
lines changed

7 files changed

+255
-0
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ jobs:
150150
working-directory: target/snitch_cluster
151151
run: |
152152
./util/run.py sw/run.yaml --simulator verilator -j
153+
./util/run.py sw/riscv_tests_isa.yaml --simulator verilator -j
153154
- name: Annotate traces
154155
working-directory: target/snitch_cluster
155156
run: |

.gitlab-ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ snitch-cluster-vsim:
124124
- cd target/snitch_cluster
125125
- make bin/snitch_cluster.vsim
126126
- ./util/run.py sw/run.yaml --simulator vsim -j --run-dir runs/vsim
127+
- ./util/run.py sw/riscv_tests_isa.yaml --simulator vsim -j --run-dir runs/vsim
127128
# Test trace annotation
128129
- make SIM_DIR=./runs/vsim/simple annotate -j
129130
# Run additional, more extensive tests

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@
44
[submodule "sw/deps/printf"]
55
path = sw/deps/printf
66
url = https://github.com/mpaland/printf.git
7+
[submodule "sw/deps/riscv-tests"]
8+
path = sw/deps/riscv-tests
9+
url = git@github.com:riscv-software-src/riscv-tests.git

sw/deps/riscv-tests

Submodule riscv-tests added at 8d1e1ca

target/snitch_cluster/sw.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ clean-headers:
4545
include sw/toolchain.mk
4646
include sw/runtime/runtime.mk
4747
include sw/tests/tests.mk
48+
include sw/riscv-tests/riscv-tests.mk
4849

4950
APPS = sw/apps/nop
5051
APPS += sw/apps/blas/axpy
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
# Copyright 2025 ETH Zurich and University of Bologna.
2+
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
3+
# SPDX-License-Identifier: Apache-2.0
4+
#
5+
# Pascal Etterli <petterli@student.ethz.ch>
6+
#
7+
# This Makefile builds the ISA tests from the RISC-V Test repository.
8+
# It makes use of the ETHZ LLVM clang infrastructure instead of the provided
9+
# gcc build setup in the original repository.
10+
# See also: https://github.com/riscv-software-src/riscv-tests
11+
12+
##################
13+
# Test selection #
14+
##################
15+
# Sources & destination
16+
RVT_SCRDIR := $(ROOT)/sw/deps/riscv-tests/isa
17+
RVT_BUILDDIR := $(ROOT)/target/snitch_cluster/sw/riscv-tests/build/
18+
19+
# Select the desired test cases
20+
# We ignore the following tests as we cannot build them with the snitch
21+
# compiler toolchain.
22+
# - rv32mi: CSR tcontrol is not recognized
23+
#
24+
# We ignore the following test cases as we don't implement the extensions
25+
# - rv32uc
26+
# - rv32si
27+
# - rv32uzfh
28+
# - rv32uzba
29+
# - rv32uzbb
30+
# - rv32uzbc
31+
# - rv32uzbs
32+
33+
include $(RVT_SCRDIR)/rv32ui/Makefrag
34+
# include $(RVT_SCRDIR)/rv32uc/Makefrag
35+
include $(RVT_SCRDIR)/rv32um/Makefrag
36+
include $(RVT_SCRDIR)/rv32ua/Makefrag
37+
include $(RVT_SCRDIR)/rv32uf/Makefrag
38+
include $(RVT_SCRDIR)/rv32ud/Makefrag
39+
# include $(RVT_SCRDIR)/rv32uzfh/Makefrag
40+
# include $(RVT_SCRDIR)/rv32uzba/Makefrag
41+
# include $(RVT_SCRDIR)/rv32uzbb/Makefrag
42+
# include $(RVT_SCRDIR)/rv32uzbc/Makefrag
43+
# include $(RVT_SCRDIR)/rv32uzbs/Makefrag
44+
# include $(RVT_SCRDIR)/rv32si/Makefrag
45+
# include $(RVT_SCRDIR)/rv32mi/Makefrag
46+
47+
###################
48+
# Build variables #
49+
###################
50+
# Provided variables from toolchain.mk
51+
# - RISCV_CC
52+
# - RISCV_LD
53+
# - RISCV_OBJDUMP
54+
55+
RVT_RISCV_CFLAGS := $(RISCV_CFLAGS) $(RISCV_LDFLAGS)
56+
RVT_RISCV_CFLAGS += -mno-relax -fvisibility=hidden
57+
RVT_RISCV_OBJDUMP_FLAGS := $(RISCV_OBJDUMP_FLAGS)
58+
RVT_RISCV_OBJDUMP_FLAGS += --disassemble-zeroes --section=.text --section=.text.startup --section=.text.init --section=.data
59+
60+
#########
61+
# Rules #
62+
#########
63+
vpath %.S $(RVT_SCRDIR)
64+
65+
# Create the objdumps for each compiled program
66+
%.dump: %
67+
$(RISCV_OBJDUMP) $(RVT_RISCV_OBJDUMP_FLAGS) $(RVT_BUILDDIR)$<.elf > $(RVT_BUILDDIR)$@
68+
69+
# Macro to compile each program
70+
define compile_template
71+
72+
$$($(1)_p_tests): $(1)-p-%: $(1)/%.S | $(RVT_BUILDDIR)
73+
$$(RISCV_CC) $$(RVT_RISCV_CFLAGS) -I$(RVT_SCRDIR)/../env/p -I$(RVT_SCRDIR)/macros/scalar -T$(RVT_SCRDIR)/../env/p/link.ld $$< -o $(RVT_BUILDDIR)$$@.elf
74+
$(1)_tests += $$($(1)_p_tests)
75+
76+
$$($(1)_v_tests): $(1)-v-%: $(1)/%.S
77+
$$(RISCV_CC) $$(RVT_RISCV_CFLAGS) -DENTROPY=0x$$(shell echo \$$@ | md5sum | cut -c 1-7) -std=gnu99 -O2 -I$(RVT_SCRDIR)/../env/v -I$(RVT_SCRDIR)/macros/scalar -T$(RVT_SCRDIR)/../env/v/link.ld $(RVT_SCRDIR)/../env/v/entry.S $(RVT_SCRDIR)/../env/v/*.c $$< -o $(RVT_BUILDDIR)$$@.elf
78+
$(1)_tests += $$($(1)_v_tests)
79+
80+
$(1)_tests_dump = $$(addsuffix .dump, $$($(1)_tests))
81+
82+
$(1): $$($(1)_tests_dump)
83+
84+
.PHONY: $(1)
85+
86+
COMPILER_SUPPORTS_$(1) := $$(shell $(RISCV_CC) $(2) -c -x c /dev/null -o /dev/null 2> /dev/null; echo $$$$?)
87+
ifeq ($$(COMPILER_SUPPORTS_$(1)),0)
88+
tests += $$($(1)_tests)
89+
endif
90+
91+
tests += $$($(1)_tests)
92+
93+
endef
94+
95+
# auto generate all test cases. Generates empty ones if Makefrag is not included above
96+
$(eval $(call compile_template,rv32ui))
97+
$(eval $(call compile_template,rv32uc))
98+
$(eval $(call compile_template,rv32um))
99+
$(eval $(call compile_template,rv32ua))
100+
$(eval $(call compile_template,rv32uf))
101+
$(eval $(call compile_template,rv32ud))
102+
$(eval $(call compile_template,rv32uzfh))
103+
$(eval $(call compile_template,rv32uzba))
104+
$(eval $(call compile_template,rv32uzbb))
105+
$(eval $(call compile_template,rv32uzbc))
106+
$(eval $(call compile_template,rv32uzbs))
107+
$(eval $(call compile_template,rv32si))
108+
$(eval $(call compile_template,rv32mi))
109+
110+
tests_dump = $(addsuffix .dump, $(tests))
111+
112+
junk += $(addprefix $(RVT_BUILDDIR),$(addsuffix .elf,$(tests))) $(addprefix $(RVT_BUILDDIR),$(tests_dump))
113+
114+
$(RVT_BUILDDIR):
115+
mkdir -p $@
116+
117+
.PHONY: riscv-tests clean-riscv-tests
118+
119+
riscv-tests: $(tests_dump) | $(RVT_BUILDDIR)
120+
121+
clean-riscv-tests:
122+
rm -rf $(junk)
123+
124+
# Integrate into main Makefile flow
125+
sw: riscv-tests
126+
clean-sw: clean-riscv-tests
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# Copyright 2025 ETH Zurich and University of Bologna.
2+
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
# Runs riscv-tests ISA test cases for the p environment.
6+
# Make sure the test cases are compiled in the riscv-tests.mk.
7+
8+
runs:
9+
# Base set
10+
- elf: ./riscv-tests/build/rv32ui-p-simple.elf
11+
- elf: ./riscv-tests/build/rv32ui-p-sltu.elf
12+
- elf: ./riscv-tests/build/rv32ui-p-add.elf
13+
- elf: ./riscv-tests/build/rv32ui-p-addi.elf
14+
- elf: ./riscv-tests/build/rv32ui-p-xori.elf
15+
- elf: ./riscv-tests/build/rv32ui-p-and.elf
16+
- elf: ./riscv-tests/build/rv32ui-p-andi.elf
17+
- elf: ./riscv-tests/build/rv32ui-p-auipc.elf
18+
- elf: ./riscv-tests/build/rv32ui-p-beq.elf
19+
- elf: ./riscv-tests/build/rv32ui-p-bge.elf
20+
- elf: ./riscv-tests/build/rv32ui-p-bgeu.elf
21+
- elf: ./riscv-tests/build/rv32ui-p-blt.elf
22+
- elf: ./riscv-tests/build/rv32ui-p-bltu.elf
23+
- elf: ./riscv-tests/build/rv32ui-p-bne.elf
24+
- elf: ./riscv-tests/build/rv32ui-p-sltiu.elf
25+
- elf: ./riscv-tests/build/rv32ui-p-fence_i.elf
26+
- elf: ./riscv-tests/build/rv32ui-p-jal.elf
27+
- elf: ./riscv-tests/build/rv32ui-p-jalr.elf
28+
- elf: ./riscv-tests/build/rv32ui-p-lb.elf
29+
- elf: ./riscv-tests/build/rv32ui-p-lbu.elf
30+
- elf: ./riscv-tests/build/rv32ui-p-lh.elf
31+
- elf: ./riscv-tests/build/rv32ui-p-lhu.elf
32+
- elf: ./riscv-tests/build/rv32ui-p-lw.elf
33+
- elf: ./riscv-tests/build/rv32ui-p-ld_st.elf
34+
- elf: ./riscv-tests/build/rv32ui-p-lui.elf
35+
# Exclude the rv32ui-p-ma_data test as it is for user space EEI and assumes that we support
36+
# unaligned memory access in U mode. Snitch never supports unaligned accesses.
37+
# - elf: ./riscv-tests/build/rv32ui-p-ma_data.elf
38+
- elf: ./riscv-tests/build/rv32ui-p-or.elf
39+
- elf: ./riscv-tests/build/rv32ui-p-ori.elf
40+
- elf: ./riscv-tests/build/rv32ui-p-sb.elf
41+
- elf: ./riscv-tests/build/rv32ui-p-sh.elf
42+
- elf: ./riscv-tests/build/rv32ui-p-sw.elf
43+
- elf: ./riscv-tests/build/rv32ui-p-st_ld.elf
44+
- elf: ./riscv-tests/build/rv32ui-p-sll.elf
45+
- elf: ./riscv-tests/build/rv32ui-p-slli.elf
46+
- elf: ./riscv-tests/build/rv32ui-p-slt.elf
47+
- elf: ./riscv-tests/build/rv32ui-p-slti.elf
48+
- elf: ./riscv-tests/build/rv32ui-p-sra.elf
49+
- elf: ./riscv-tests/build/rv32ui-p-srai.elf
50+
- elf: ./riscv-tests/build/rv32ui-p-srl.elf
51+
- elf: ./riscv-tests/build/rv32ui-p-srli.elf
52+
- elf: ./riscv-tests/build/rv32ui-p-sub.elf
53+
- elf: ./riscv-tests/build/rv32ui-p-xor.elf
54+
# Multiplication
55+
- elf: ./riscv-tests/build/rv32um-p-div.elf
56+
- elf: ./riscv-tests/build/rv32um-p-divu.elf
57+
- elf: ./riscv-tests/build/rv32um-p-mul.elf
58+
- elf: ./riscv-tests/build/rv32um-p-mulh.elf
59+
- elf: ./riscv-tests/build/rv32um-p-mulhsu.elf
60+
- elf: ./riscv-tests/build/rv32um-p-mulhu.elf
61+
- elf: ./riscv-tests/build/rv32um-p-rem.elf
62+
- elf: ./riscv-tests/build/rv32um-p-remu.elf
63+
# Atomics
64+
- elf: ./riscv-tests/build/rv32ua-p-amomaxu_w.elf
65+
- elf: ./riscv-tests/build/rv32ua-p-amoor_w.elf
66+
- elf: ./riscv-tests/build/rv32ua-p-amoand_w.elf
67+
- elf: ./riscv-tests/build/rv32ua-p-amoadd_w.elf
68+
- elf: ./riscv-tests/build/rv32ua-p-amomin_w.elf
69+
- elf: ./riscv-tests/build/rv32ua-p-amomax_w.elf
70+
- elf: ./riscv-tests/build/rv32ua-p-amoswap_w.elf
71+
- elf: ./riscv-tests/build/rv32ua-p-amoxor_w.elf
72+
- elf: ./riscv-tests/build/rv32ua-p-amominu_w.elf
73+
- elf: ./riscv-tests/build/rv32ua-p-lrsc.elf
74+
# FLOATING POINT TESTS
75+
# Some tests could fail because there are additional bits in the fcsr register.
76+
#
77+
# The following tests fail because the fcsr read operations are not ordered in regards to the
78+
# FPU instructions:
79+
# - elf: ./riscv-tests/build/rv32uf-p-fadd.elf
80+
# - elf: ./riscv-tests/build/rv32uf-p-fcmp.elf
81+
# - elf: ./riscv-tests/build/rv32uf-p-fcvt_w.elf
82+
# - elf: ./riscv-tests/build/rv32uf-p-fmadd.elf
83+
# - elf: ./riscv-tests/build/rv32uf-p-fmin.elf
84+
#
85+
# The fdiv fails because it includes fdiv and fsqrt which both are not supported.
86+
# - elf: ./riscv-tests/build/rv32uf-p-fdiv.elf
87+
#
88+
# The move fails because Snitch has additional custom fcsr CSR bits.
89+
# - elf: ./riscv-tests/build/rv32uf-p-move.elf
90+
#
91+
# The following tests do not check the fcsr value
92+
- elf: ./riscv-tests/build/rv32uf-p-fclass.elf
93+
- elf: ./riscv-tests/build/rv32uf-p-fcvt.elf
94+
- elf: ./riscv-tests/build/rv32uf-p-ldst.elf
95+
- elf: ./riscv-tests/build/rv32uf-p-recoding.elf
96+
97+
# DOUBLE TESTS
98+
# Some tests could fail because there are additional bits in the fcsr register.
99+
#
100+
# The following tests fail because the fcsr read operations are not ordered in regards to the
101+
# FPU instructions:
102+
# - elf: ./riscv-tests/build/rv32ud-p-fcmp.elf
103+
# - elf: ./riscv-tests/build/rv32ud-p-fcvt_w.elf
104+
#
105+
# The following tests pass only because there are enough integer core instructions between the
106+
# relevant FPU instruction and its corresponding fcsr read:
107+
- elf: ./riscv-tests/build/rv32ud-p-fadd.elf
108+
- elf: ./riscv-tests/build/rv32ud-p-fcvt.elf
109+
- elf: ./riscv-tests/build/rv32ud-p-fmadd.elf
110+
- elf: ./riscv-tests/build/rv32ud-p-fmin.elf
111+
#
112+
# fdiv tests includes fdiv and fsqrt which both are not supported.
113+
# - elf: ./riscv-tests/build/rv32ud-p-fdiv.elf
114+
#
115+
# The move test is not yet enabled in riscv-tests repo for double. It would probably fail on the
116+
# additional bits in the fcsr.
117+
# - elf: no binary yet
118+
#
119+
# The following tests do not check the fcsr value
120+
- elf: ./riscv-tests/build/rv32ud-p-fclass.elf
121+
- elf: ./riscv-tests/build/rv32ud-p-ldst.elf
122+
- elf: ./riscv-tests/build/rv32ud-p-recoding.elf

0 commit comments

Comments
 (0)