#risc-v #testing #rv32

ralte32

嵌入式RISC-V 32位算术库测试环境

4个版本

0.1.3 2023年9月13日
0.1.2 2023年9月13日
0.1.1 2023年9月13日
0.1.0 2023年9月13日

#641嵌入式开发

MIT/Apache

18KB
312

RALTE32

Crates.io | Docs.rs | 仓库

RALTE32是一个Rust算术库测试环境,用于嵌入式RISC-V 32位。此库允许使用QEMU模拟器测试为RISC-V 32位制作的Rust算术代码。这对于使用Rust riscv32内嵌函数进行开发特别有用。

此库主要是一个最小的修改,以实现测试环境并将riscv32嵌入式目标端口到Linux用户空间目标。

使用方法

首先,此项目使用QEMU用户空间模拟器来模拟目标代码。这可以在大多数操作系统上使用标准qemu-user包安装。

# Linux: Debian / Ubuntu
sudo apt-get install qemu-user

# Linux: ArchLinux
sudo pacman -S qemu-user

更多平台,请查看这里

然后,将ralte32添加为开发依赖项。

cargo add --dev ralte32

最后,创建并/或将一个简短的节添加到您的.cargo/config.toml中。

# ...

[target.riscv32imac-unknown-none-elf]
rustflags = ['-Ctarget-feature=+crt-static']
runner = "qemu-riscv32 -cpu rv32"

# NOTE: If you want to enable additional target features, add them here.
# 
# Example to enable the `zk` feature:
# rustflags = ['-Ctarget-feature=+crt-static,+zk']
# runner = "qemu-riscv32 -cpu rv32,zk=true"

然后,要实现一些测试,您可以在examples/中添加一个示例。

// examples/test-rv32.rs
#![no_std]
#![no_main]

use ralte32::define_tests;

fn test_multiplication() {
    assert_eq!(6 * 7, 42);
}

fn test_remainder() {
    assert_eq!(7 % 6, 1);
}

define_tests!{
    test_multiplication,
    test_remainder,
}

然后可以运行

cargo run --example test-rv32 --target riscv32imac-unknown-none-elf

这将给出

Running tests...

Running "test_multiplication"... SUCCESSFUL
Running "test_remainder"... SUCCESSFUL

限制

存在几个已知的限制。

  1. 第一个测试或断言失败,将停止测试环境。
  2. 这仅测试用户级代码。无法访问监督程序、机器或虚拟机指令和CSR。
  3. 打印支持非常有限。

许可证

此项目根据MITAPACHE-2.0许可证双授权。

无运行时依赖