Skip to content

Commit 192908c

Browse files
cphurley82@gmail.comeyck
authored andcommitted
test: add PMP CSR ctest and restructure CI
- ci.yml: split into two jobs. cpp-compliance (matrix C++17/20) handles pure build compliance and uploads the C++17 binary as an artifact. pmp-tests downloads that binary, compiles firmware with only gcc-riscv64-unknown-elf, and runs the test directly. Trigger paths extended to include **.S for firmware changes. - contrib/fw/pmp-csr-test/pmp_csr_test.S: firmware that writes 0xDEAD to pmpaddr0, reads it back, and exits 0 on match (j .) or non-zero via semihosting SYS_EXIT on mismatch.
1 parent 199a68a commit 192908c

3 files changed

Lines changed: 133 additions & 55 deletions

File tree

.github/workflows/ci-compile.yml

Lines changed: 0 additions & 55 deletions
This file was deleted.

.github/workflows/ci.yml

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
name: CI
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
paths:
7+
- '**.hpp'
8+
- '**.cpp'
9+
- '**.h'
10+
- '**.c'
11+
- '**.S'
12+
- '**CMakeLists.txt'
13+
- '.github/workflows/**'
14+
- 'conanfile.py'
15+
pull_request:
16+
paths:
17+
- '**.hpp'
18+
- '**.cpp'
19+
- '**.h'
20+
- '**.c'
21+
- '**.S'
22+
- '**CMakeLists.txt'
23+
- '.github/workflows/**'
24+
- 'conanfile.py'
25+
26+
jobs:
27+
cpp-compliance:
28+
name: C++ Std Compliance (C++${{ matrix.cpp_std }})
29+
runs-on: ubuntu-24.04
30+
strategy:
31+
matrix:
32+
cpp_std: [17, 20]
33+
steps:
34+
- uses: actions/checkout@v4
35+
36+
- name: Update submodules
37+
run: git submodule update --init --recursive
38+
39+
- name: Cache Conan
40+
uses: actions/cache@v4
41+
with:
42+
path: ~/.conan2
43+
key: conan-${{ runner.os }}-unit-cpp${{ matrix.cpp_std }}-${{ hashFiles('conanfile.py') }}
44+
45+
- name: Install dependencies
46+
run: |
47+
sudo apt-get install -y g++ python3-pip cmake llvm-19-dev
48+
pip3 install conan
49+
cmake --version
50+
51+
- name: Configure
52+
run: cmake --preset Release -B build -DCMAKE_CXX_STANDARD=${{ matrix.cpp_std }} -DWITH_LLVM=ON -DWITH_SYSTEM_LLVM=ON
53+
54+
- name: Build
55+
run: cmake --build build -j
56+
57+
- name: Smoke test
58+
run: ./build/riscv-sim -h
59+
60+
# NOTE: .so filename is tied to VERSION in top-level CMakeLists.txt - update both together
61+
- name: Upload binary
62+
if: matrix.cpp_std == 20
63+
uses: actions/upload-artifact@v4
64+
with:
65+
name: riscv-sim
66+
path: |
67+
build/riscv-sim
68+
build/libdbt-rise-riscv.so.2.1.0
69+
70+
pmp-tests:
71+
name: PMP Functional Tests
72+
runs-on: ubuntu-24.04
73+
needs: cpp-compliance
74+
steps:
75+
- uses: actions/checkout@v4
76+
77+
- name: Install RISC-V toolchain
78+
run: sudo apt-get install -y gcc-riscv64-unknown-elf
79+
80+
- name: Download riscv-sim binary
81+
uses: actions/download-artifact@v4
82+
with:
83+
name: riscv-sim
84+
85+
- name: Make binary executable
86+
run: chmod +x riscv-sim
87+
88+
- name: Build PMP CSR test firmware
89+
run: |
90+
riscv64-unknown-elf-gcc -nostdlib -march=rv64gc -mabi=lp64 \
91+
-Wl,-Ttext=0x10000,--no-dynamic-linker \
92+
-o pmp_csr_test \
93+
contrib/fw/pmp-csr-test/pmp_csr_test.S
94+
95+
- name: rv64gc_m CSR test - interp (no PMP, expect exit 2)
96+
run: |
97+
LD_LIBRARY_PATH=. ./riscv-sim -f pmp_csr_test --isa rv64gc_m --backend interp || rc=$?
98+
[ "${rc:-0}" -eq 2 ]
99+
100+
- name: rv64gc_mp CSR test - interp (with PMP)
101+
run: LD_LIBRARY_PATH=. ./riscv-sim -f pmp_csr_test --isa rv64gc_mp --backend interp
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Verify pmpaddr0 is accessible as a CSR (no illegal-instruction trap on read/write).
2+
// Pass: j . detected as JUMP_TO_SELF by ISS, exits 0.
3+
// Fail: semihosting SYS_EXIT sequence, ISS exits non-zero.
4+
5+
.section .text
6+
.globl _start
7+
_start:
8+
// Install fail handler: any unexpected trap before the ecall path means the CSR
9+
// is not available or behaves incorrectly
10+
la t0, fail
11+
csrw mtvec, t0
12+
13+
// Write a distinctive value to pmpaddr0 and verify the readback matches
14+
li t0, 0xDEAD
15+
csrw pmpaddr0, t0
16+
csrr t1, pmpaddr0
17+
bne t0, t1, fail
18+
19+
j . // pass: ISS detects j . and exits 0
20+
21+
fail:
22+
// Semihosting SYS_EXIT: the ISS checks for slli+ebreak+srai and intercepts
23+
// before dispatching to mtvec. Must use 4-byte ebreak (not c.ebreak) so the
24+
// check lands at the correct offsets (-4 and +4 from the ebreak address).
25+
li a0, 0x18 // SYS_EXIT
26+
.option push
27+
.option norvc // force 4-byte ebreak (0x00100073), not 2-byte c.ebreak
28+
slli zero, zero, 0x1f
29+
ebreak
30+
srai zero, zero, 7
31+
.option pop
32+
j . // fallback if semihosting is not configured

0 commit comments

Comments
 (0)