Test for lb, lbu, lw, sb, sbu, sw explicitly

This commit is contained in:
Toby Jaffey 2025-12-14 00:58:35 +00:00
parent 2037f6e575
commit fe51154698
3 changed files with 114 additions and 1 deletions

View file

@ -77,7 +77,24 @@ void main(void) {
// pass a string beyond end of extram // pass a string beyond end of extram
println((uint32_t)UVM32_EXTRAM_BASE); // extram has been shrunk, this is now out of bounds, println((uint32_t)UVM32_EXTRAM_BASE); // extram has been shrunk, this is now out of bounds,
} break; } break;
case TEST15: {
int8_t *p = (int8_t *)UVM32_EXTRAM_BASE;
p[7] = -42; // single byte write
yield(0);
} break;
case TEST16: {
int8_t *p = (int8_t *)UVM32_EXTRAM_BASE;
printdec(p[7]); // single byte read
} break;
case TEST17: {
int16_t *p = (int16_t *)UVM32_EXTRAM_BASE;
p[7] = -1234; // short write
yield(0);
} break;
case TEST18: {
int16_t *p = (int16_t *)UVM32_EXTRAM_BASE;
printdec(p[7]); // short read
} break;
} }
} }

View file

@ -16,5 +16,9 @@ enum {
TEST12, TEST12,
TEST13, TEST13,
TEST14, TEST14,
TEST15,
TEST16,
TEST17,
TEST18,
}; };

View file

@ -401,3 +401,95 @@ void test_extram_buf_cstr_beyond_extram_end(void) {
} }
void test_extram_signed_byte_write(void) {
// run the vm
uvm32_run(&vmst, &evt, 100);
TEST_ASSERT_EQUAL(false, uvm32_extramDirty(&vmst));
// check for picktest syscall
TEST_ASSERT_EQUAL(evt.typ, UVM32_EVT_SYSCALL);
TEST_ASSERT_EQUAL(evt.data.syscall.code, SYSCALL_PICKTEST);
uvm32_arg_setval(&vmst, &evt, RET, TEST15);
uvm32_run(&vmst, &evt, 100);
TEST_ASSERT_EQUAL(true, uvm32_extramDirty(&vmst));
// check that byte 7 only of extram has changed
int8_t *p = (int8_t *)extram;
for (int i=0;i<sizeof(extram);i++) {
if (i == 7) {
TEST_ASSERT_EQUAL(-42, p[i]);
} else {
TEST_ASSERT_EQUAL(0x00, p[i]);
}
}
}
void test_extram_signed_byte_read(void) {
// run the vm
uvm32_run(&vmst, &evt, 100);
TEST_ASSERT_EQUAL(false, uvm32_extramDirty(&vmst));
// check for picktest syscall
TEST_ASSERT_EQUAL(evt.typ, UVM32_EVT_SYSCALL);
TEST_ASSERT_EQUAL(evt.data.syscall.code, SYSCALL_PICKTEST);
uvm32_arg_setval(&vmst, &evt, RET, TEST16);
// set only byte 7 in extram
int8_t *p = (int8_t *)extram;
p[7] = -69;
uvm32_run(&vmst, &evt, 100);
TEST_ASSERT_EQUAL(false, uvm32_extramDirty(&vmst));
// check for printdec of val
TEST_ASSERT_EQUAL(UVM32_EVT_SYSCALL, evt.typ);
TEST_ASSERT_EQUAL(evt.data.syscall.code, UVM32_SYSCALL_PRINTDEC);
TEST_ASSERT_EQUAL(-69, (int8_t)uvm32_arg_getval(&vmst, &evt, ARG0));
}
void test_extram_signed_short_write(void) {
// run the vm
uvm32_run(&vmst, &evt, 100);
TEST_ASSERT_EQUAL(false, uvm32_extramDirty(&vmst));
// check for picktest syscall
TEST_ASSERT_EQUAL(evt.typ, UVM32_EVT_SYSCALL);
TEST_ASSERT_EQUAL(evt.data.syscall.code, SYSCALL_PICKTEST);
uvm32_arg_setval(&vmst, &evt, RET, TEST17);
uvm32_run(&vmst, &evt, 100);
TEST_ASSERT_EQUAL(true, uvm32_extramDirty(&vmst));
// check that short 7 only of extram has changed
int16_t *p = (int16_t *)extram;
for (int i=0;i<sizeof(extram)/2;i++) {
if (i == 7) {
TEST_ASSERT_EQUAL(-1234, p[i]);
} else {
TEST_ASSERT_EQUAL(0x00, p[i]);
}
}
}
void test_extram_signed_short_read(void) {
// run the vm
uvm32_run(&vmst, &evt, 100);
TEST_ASSERT_EQUAL(false, uvm32_extramDirty(&vmst));
// check for picktest syscall
TEST_ASSERT_EQUAL(evt.typ, UVM32_EVT_SYSCALL);
TEST_ASSERT_EQUAL(evt.data.syscall.code, SYSCALL_PICKTEST);
uvm32_arg_setval(&vmst, &evt, RET, TEST18);
// set only short 7 in extram
int16_t *p = (int16_t *)extram;
p[7] = -4567;
uvm32_run(&vmst, &evt, 100);
TEST_ASSERT_EQUAL(false, uvm32_extramDirty(&vmst));
// check for printdec of val
TEST_ASSERT_EQUAL(UVM32_EVT_SYSCALL, evt.typ);
TEST_ASSERT_EQUAL(evt.data.syscall.code, UVM32_SYSCALL_PRINTDEC);
TEST_ASSERT_EQUAL(-4567, (int16_t)uvm32_arg_getval(&vmst, &evt, ARG0));
}