Skip to content

Commit ecc1b6d

Browse files
committed
[#2389] test: cover D-width atomic gate
1 parent 38ee5e0 commit ecc1b6d

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

tests/unit/test_riscv.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,29 @@ static void test_riscv64_nop(void)
5555
OK(uc_close(uc));
5656
}
5757

58+
static void test_riscv64_dwidth_atomic_without_a(void)
59+
{
60+
uc_engine *uc;
61+
const char code[] = "\x2f\xb5\x05\x10"; // lr.d a0, (a1)
62+
uint64_t misa;
63+
uint64_t address = 0x2000;
64+
uint64_t value = 0;
65+
66+
OK(uc_open(UC_ARCH_RISCV, UC_MODE_RISCV64, &uc));
67+
OK(uc_mem_map(uc, code_start, code_len, UC_PROT_ALL));
68+
OK(uc_mem_write(uc, code_start, code, sizeof(code) - 1));
69+
OK(uc_mem_write(uc, address, &value, sizeof(value)));
70+
OK(uc_reg_read(uc, UC_RISCV_REG_MISA, &misa));
71+
misa &= ~1ULL;
72+
OK(uc_reg_write(uc, UC_RISCV_REG_MISA, &misa));
73+
OK(uc_reg_write(uc, UC_RISCV_REG_A1, &address));
74+
75+
uc_assert_err(UC_ERR_EXCEPTION,
76+
uc_emu_start(uc, code_start,
77+
code_start + sizeof(code) - 1, 0, 0));
78+
OK(uc_close(uc));
79+
}
80+
5881
static void test_riscv32_until_pc_update(void)
5982
{
6083
uc_engine *uc;
@@ -911,6 +934,8 @@ static void test_riscv_priv(void)
911934
TEST_LIST = {
912935
{"test_riscv32_nop", test_riscv32_nop},
913936
{"test_riscv64_nop", test_riscv64_nop},
937+
{"test_riscv64_dwidth_atomic_without_a",
938+
test_riscv64_dwidth_atomic_without_a},
914939
{"test_riscv32_3steps_pc_update", test_riscv32_3steps_pc_update},
915940
{"test_riscv64_3steps_pc_update", test_riscv64_3steps_pc_update},
916941
{"test_riscv64_until_at_page_end", test_riscv64_until_at_page_end},

0 commit comments

Comments
 (0)