mirror of
https://github.com/ringtailsoftware/uvm32.git
synced 2026-06-05 22:43:39 +00:00
Test that repeatedly stopping and starting results in executing exactly the same number of VM instructions
This commit is contained in:
parent
da7f186ff7
commit
3f21335fc3
2 changed files with 14 additions and 4 deletions
|
|
@ -20,11 +20,12 @@ void tearDown(void) {
|
||||||
// run program until printdec() reaches 100
|
// run program until printdec() reaches 100
|
||||||
// every time it hangs, resume
|
// every time it hangs, resume
|
||||||
// run in batches of num_instr
|
// run in batches of num_instr
|
||||||
void metered_run(uint32_t num_instr) {
|
uint32_t metered_run(uint32_t num_instr) {
|
||||||
uint32_t expected = 0;
|
uint32_t expected = 0;
|
||||||
|
uint32_t total_instr = 0;
|
||||||
|
|
||||||
while(expected < 100) {
|
while(expected < 100) {
|
||||||
uvm32_run(&vmst, &evt, num_instr);
|
total_instr += uvm32_run(&vmst, &evt, num_instr);
|
||||||
switch(evt.typ) {
|
switch(evt.typ) {
|
||||||
case UVM32_EVT_SYSCALL: {
|
case UVM32_EVT_SYSCALL: {
|
||||||
TEST_ASSERT_EQUAL(UVM32_SYSCALL_PRINTDEC, evt.data.syscall.code);
|
TEST_ASSERT_EQUAL(UVM32_SYSCALL_PRINTDEC, evt.data.syscall.code);
|
||||||
|
|
@ -43,16 +44,24 @@ void metered_run(uint32_t num_instr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// run vm to completion
|
// run vm to completion
|
||||||
uvm32_run(&vmst, &evt, 10000);
|
total_instr += uvm32_run(&vmst, &evt, 10000);
|
||||||
TEST_ASSERT_EQUAL(evt.typ, UVM32_EVT_END);
|
TEST_ASSERT_EQUAL(evt.typ, UVM32_EVT_END);
|
||||||
|
return total_instr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_meter(void) {
|
void test_meter(void) {
|
||||||
// test many different meter values, including 0 (which should run 1 instruction, as 0 is going to hang)
|
// test many different meter values, including 0 (which should run 1 instruction, as 0 is going to hang)
|
||||||
|
uint32_t total_instr = 0;
|
||||||
|
|
||||||
for (uint32_t i=0;i<1000;i++) {
|
for (uint32_t i=0;i<1000;i++) {
|
||||||
uvm32_init(&vmst);
|
uvm32_init(&vmst);
|
||||||
uvm32_load(&vmst, rom_bin, rom_bin_len);
|
uvm32_load(&vmst, rom_bin, rom_bin_len);
|
||||||
metered_run(i);
|
uint32_t instrs = metered_run(i);
|
||||||
|
if (total_instr == 0) { // first run
|
||||||
|
total_instr = instrs;
|
||||||
|
} else {
|
||||||
|
TEST_ASSERT_EQUAL(total_instr, instrs); // check that every run takes the total number of instructions
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -149,6 +149,7 @@ uint32_t uvm32_run(uvm32_state_t *vmst, uvm32_evt_t *evt, uint32_t instr_meter)
|
||||||
|
|
||||||
if (instr_meter < min_instrs) {
|
if (instr_meter < min_instrs) {
|
||||||
instr_meter = min_instrs;
|
instr_meter = min_instrs;
|
||||||
|
orig_instr_meter = min_instrs;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vmst->stack_canary != UVM32_NULL && *vmst->stack_canary != STACK_CANARY_VALUE) {
|
if (vmst->stack_canary != UVM32_NULL && *vmst->stack_canary != STACK_CANARY_VALUE) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue