From 72f74c972d142f82fb806301fa79e614197008e4 Mon Sep 17 00:00:00 2001 From: Noratrieb <48135649+Noratrieb@users.noreply.github.com> Date: Sun, 9 Mar 2025 17:24:18 +0100 Subject: [PATCH] add more tests --- tests/check.rs | 4 +- tests/check/arith.s | 23 ----------- tests/check/branch.S | 6 +++ tests/check/int_comp.S | 90 ++++++++++++++++++++++++++++++++++++++++++ tests/check/smoke.S | 4 ++ tests/check/smoke.s | 6 --- tests/helper.S | 21 ++++++++++ 7 files changed, 123 insertions(+), 31 deletions(-) delete mode 100644 tests/check/arith.s create mode 100644 tests/check/branch.S create mode 100644 tests/check/int_comp.S create mode 100644 tests/check/smoke.S delete mode 100644 tests/check/smoke.s create mode 100644 tests/helper.S diff --git a/tests/check.rs b/tests/check.rs index fa3dbf4..305e74b 100644 --- a/tests/check.rs +++ b/tests/check.rs @@ -21,7 +21,7 @@ fn check() -> eyre::Result<()> { let name = file.file_name(); let name = name.to_str().unwrap(); - if !name.ends_with(".s") { + if !name.ends_with(".S") { continue; } @@ -34,7 +34,7 @@ fn check() -> eyre::Result<()> { let status = rustv32i::execute_linux_elf( &content, - matches!(std::env::var("EMULATOR_DEBUG").as_deref(), Ok(v) if v != "0"), + true, Box::new(|_, xreg| { if xreg[Reg::A7.0 as usize] == u32::MAX { if xreg[Reg::A0.0 as usize] == 1 { diff --git a/tests/check/arith.s b/tests/check/arith.s deleted file mode 100644 index 29abddb..0000000 --- a/tests/check/arith.s +++ /dev/null @@ -1,23 +0,0 @@ -.section .text -.globl _start -_start: - li t0, 10 - li t1, 20 - add t2, t0, t1 - li t3, 30 - bne t2, t3, fail - - li t0, 10 - li t1, -2 - add t2, t0, t1 - li t3, 8 - bne t2, t3, fail - - li a7, -1 - li a0, 1 - ecall - -fail: - li a7, -1 - li a0, 0 - ecall diff --git a/tests/check/branch.S b/tests/check/branch.S new file mode 100644 index 0000000..ce5497b --- /dev/null +++ b/tests/check/branch.S @@ -0,0 +1,6 @@ +# Control transfer instructions + +#include "../helper.S" + +START_TEST + PASS diff --git a/tests/check/int_comp.S b/tests/check/int_comp.S new file mode 100644 index 0000000..6842c52 --- /dev/null +++ b/tests/check/int_comp.S @@ -0,0 +1,90 @@ +# Integer computational register-register instruction. + +#include "../helper.S" + +.macro CASE_REG inst a b expected + li t0, \a + li t1, \b + \inst t2, t0, t1 + ASSERT_EQ t2, \expected +.endm + +.macro CASE_IMM inst a b expected + li t0, \a + \inst t2, t0, \b + ASSERT_EQ t2, \expected +.endm + +.macro CASE_BOTH inst insti a b expected + CASE_REG \inst, \a, \b, \expected + + CASE_IMM \insti, \a, \b, \expected +.endm + + +.macro CASE inst a b expected + CASE_BOTH \inst, \inst\()i, \a, \b, \expected +.endm + +START_TEST + CASE add 10, 20, 30 + CASE add 10, -2, 8 + CASE add 10, 0, 10 + CASE add 0, 0, 0 + + CASE slt 10 20 1 + CASE slt 20 10 0 + CASE slt, -1 0 1 + CASE slt 0, -1 0 + CASE slt, -1, -1, 0 + CASE slt, -100, -1, 1 + + CASE_BOTH sltu sltiu 10 20 1 + CASE_BOTH sltu sltiu 20 10 0 + CASE_BOTH sltu sltiu, -1, 0, 0 + CASE_BOTH sltu sltiu, -100, -1, 1 + CASE_BOTH sltu sltiu, 100, -1, 1 + + CASE and 0b11, 0b11, 0b11 + CASE and, -1, -1, -1 + CASE and, -1, 0, 0 + CASE and, -1, 40, 40 + CASE and, 0b101, 0b100, 0b100 + + CASE or, -1, 0, -1 + CASE or, -1, 40, -1 + CASE or, 0, 0, 0 + CASE or, 0b101, 0b110, 0b111 + + CASE xor, -1, 0, -1 + CASE xor, -1, -1, 0 + CASE xor 0b101, 0b100, 0b001 + + CASE sll, 2, 1, 4 + CASE sll, 0, 10, 0 + CASE sll, 10, 0, 10 + CASE sll, -1, 31, -2147483648 + CASE_REG sll, -1, 32, -1 # error for immediate + + CASE srl, 4, 1, 2 + CASE srl, 0, 10, 0 + CASE srl, 10, 0, 10 + CASE srl, -1, 1, 2147483647 + CASE srl, 0b111, 2, 0b001 + CASE_REG srl, -1, 32, -1 # error for immediate + + CASE_REG sub, 10, 5, 5 + CASE_REG sub, -1, 1, -2 + CASE_REG sub, 1, 2, -1 + CASE_REG sub, -1, -2, 1 + CASE_REG sub, 0, 4294967295, 1 + + CASE sra, 4, 1, 2 + CASE sra, 0, 10, 0 + CASE sra, 10, 0, 10 + CASE sra, -1, 1, -1 + CASE sra, -1, 31, -1 + CASE sra, 0b111, 2, 0b001 + CASE_REG sra, 10, 32, 10 # error for immediate + + PASS diff --git a/tests/check/smoke.S b/tests/check/smoke.S new file mode 100644 index 0000000..520f4de --- /dev/null +++ b/tests/check/smoke.S @@ -0,0 +1,4 @@ +#include "../helper.S" + +START_TEST + PASS diff --git a/tests/check/smoke.s b/tests/check/smoke.s deleted file mode 100644 index a033929..0000000 --- a/tests/check/smoke.s +++ /dev/null @@ -1,6 +0,0 @@ -.section .text -.globl _start -_start: - li a7, -1 - li a0, 1 - ecall diff --git a/tests/helper.S b/tests/helper.S new file mode 100644 index 0000000..e8fedbf --- /dev/null +++ b/tests/helper.S @@ -0,0 +1,21 @@ +.macro START_TEST + .section .text + .globl _start + _start: +.endm + +.macro ASSERT_EQ actual expected + li t6, \expected + bne \actual, t6, fail +.endm + +.macro PASS + li a7, -1 + li a0, 1 + ecall +.endm + +fail: + li a7, -1 + li a0, 0 + ecall