Add test for string reading off end of extram

This commit is contained in:
Toby Jaffey 2025-12-13 23:24:24 +00:00
parent 2039de73f2
commit 6429d2cdaf
3 changed files with 36 additions and 0 deletions

View file

@ -73,6 +73,10 @@ void main(void) {
// pass a slice beyond end of extram
printbuf((uint32_t)UVM32_EXTRAM_BASE + 32, 64); // extram has been shrunk, this is now out of bounds,
} break;
case TEST14: {
// pass a string beyond end of extram
println((uint32_t)UVM32_EXTRAM_BASE); // extram has been shrunk, this is now out of bounds,
} break;
}
}

View file

@ -15,5 +15,6 @@ enum {
TEST11,
TEST12,
TEST13,
TEST14,
};

View file

@ -369,4 +369,35 @@ void test_extram_buf_slice_beyond_extram_end(void) {
TEST_ASSERT_EQUAL(evt.data.err.errcode, UVM32_ERR_MEM_RD);
}
void test_extram_buf_cstr_beyond_extram_end(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, TEST14);
uvm32_run(&vmst, &evt, 100);
TEST_ASSERT_EQUAL(false, uvm32_extramDirty(&vmst));
// check for printbuf of val
TEST_ASSERT_EQUAL(UVM32_EVT_SYSCALL, evt.typ);
TEST_ASSERT_EQUAL(evt.data.syscall.code, UVM32_SYSCALL_PRINTLN);
// replace extram with a tiny one, so read is off the end
uint32_t r[3];
// non-zero so string never terminates
memset(r, 0xAA, sizeof(r));
uvm32_extram(&vmst, (uint8_t *)r, sizeof(r));
// string starts in valid extram, but no terminator will be found before hitting end of extram
// check that reading from non-existent extram gives empty string and puts into err state
const char *str = uvm32_arg_getcstr(&vmst, &evt, ARG0);
TEST_ASSERT_EQUAL(0, strlen(str));
uvm32_run(&vmst, &evt, 100);
TEST_ASSERT_EQUAL(evt.typ, UVM32_EVT_ERR);
TEST_ASSERT_EQUAL(evt.data.err.errcode, UVM32_ERR_MEM_RD);
}