Skip to content

Commit ac1975a

Browse files
Test metering, prove that system can resume after a hang error with a range of meter sizes
1 parent 9d9e754 commit ac1975a

File tree

14 files changed

+222
-53
lines changed

14 files changed

+222
-53
lines changed

host/host.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ int main(int argc, char *argv[]) {
171171
printf("UVM32_EVT_ERR '%s' (%d)\n", evt.data.err.errstr, (int)evt.data.err.errcode);
172172
if (evt.data.err.errcode == UVM32_ERR_HUNG) {
173173
printf("VM may have hung, increase max_instrs_per_run\n");
174+
uvm32_clearError(&vmst); // allow to continue
174175
} else {
175176
isrunning = false;
176177
}

test/Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
TESTS = example_1 stackoverflow custom_syscall
1+
TESTS = \
2+
basic_syscalls \
3+
stackoverflow \
4+
custom_syscall \
5+
syscall_args \
6+
meter
7+
28
RUNCMD = $(foreach TEST,${TESTS},make -C ${TEST} &&)
39
CLEANCMD = $(foreach TEST,${TESTS},make -C ${TEST} clean &&)
410

test/basic_syscalls/rom/rom.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include "uvm32_target.h"
2+
3+
void main(void) {
4+
println("Hello world");
5+
print("Hello world");
6+
printdec(42);
7+
printhex(0xDEADBEEF);
8+
putc('G');
9+
}
10+

test/basic_syscalls/test/tests.c

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#include <string.h>
2+
#include "unity.h"
3+
#include "uvm32.h"
4+
#include "../common/uvm32_common_custom.h"
5+
6+
#include "rom-header.h"
7+
8+
static uvm32_state_t vmst;
9+
static uvm32_evt_t evt;
10+
11+
void setUp(void) {
12+
// runs before each test
13+
uvm32_init(&vmst);
14+
uvm32_load(&vmst, rom_bin, rom_bin_len);
15+
}
16+
17+
void tearDown(void) {
18+
}
19+
20+
void test_syscalls(void) {
21+
// check for println syscall
22+
uvm32_run(&vmst, &evt, 1000);
23+
TEST_ASSERT_EQUAL(evt.typ, UVM32_EVT_SYSCALL);
24+
TEST_ASSERT_EQUAL(evt.data.syscall.code, UVM32_SYSCALL_PRINTLN);
25+
TEST_ASSERT_EQUAL(0, strcmp(uvm32_getcstr(&vmst, &evt, ARG0), "Hello world"));
26+
27+
// check for print syscall
28+
uvm32_run(&vmst, &evt, 1000);
29+
TEST_ASSERT_EQUAL(evt.typ, UVM32_EVT_SYSCALL);
30+
TEST_ASSERT_EQUAL(evt.data.syscall.code, UVM32_SYSCALL_PRINT);
31+
TEST_ASSERT_EQUAL(0, strcmp(uvm32_getcstr(&vmst, &evt, ARG0), "Hello world"));
32+
33+
// check for printdec syscall
34+
uvm32_run(&vmst, &evt, 1000);
35+
TEST_ASSERT_EQUAL(evt.typ, UVM32_EVT_SYSCALL);
36+
TEST_ASSERT_EQUAL(evt.data.syscall.code, UVM32_SYSCALL_PRINTDEC);
37+
TEST_ASSERT_EQUAL(42, uvm32_getval(&vmst, &evt, ARG0));
38+
39+
// check for printhex syscall
40+
uvm32_run(&vmst, &evt, 1000);
41+
TEST_ASSERT_EQUAL(evt.typ, UVM32_EVT_SYSCALL);
42+
TEST_ASSERT_EQUAL(evt.data.syscall.code, UVM32_SYSCALL_PRINTHEX);
43+
TEST_ASSERT_EQUAL(0xDEADBEEF, uvm32_getval(&vmst, &evt, ARG0));
44+
45+
// check for putc syscall
46+
uvm32_run(&vmst, &evt, 1000);
47+
TEST_ASSERT_EQUAL(evt.typ, UVM32_EVT_SYSCALL);
48+
TEST_ASSERT_EQUAL(evt.data.syscall.code, UVM32_SYSCALL_PUTC);
49+
TEST_ASSERT_EQUAL('G', uvm32_getval(&vmst, &evt, ARG0));
50+
51+
// run vm to completion
52+
uvm32_run(&vmst, &evt, 10000);
53+
TEST_ASSERT_EQUAL(evt.typ, UVM32_EVT_END);
54+
}
55+
56+

test/example_1/rom/rom.c

Lines changed: 0 additions & 6 deletions
This file was deleted.

test/example_1/test/tests.c

Lines changed: 0 additions & 33 deletions
This file was deleted.

test/meter/Makefile

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
C_COMPILER=gcc
2+
3+
UNITY_ROOT=../unity
4+
5+
CFLAGS=-std=c99
6+
CFLAGS += -Wall
7+
CFLAGS += -Werror
8+
CFLAGS += -DUVM32_MEMORY_SIZE=16384
9+
10+
SUITE_NAME=tests
11+
12+
TARGET_BASE1=test1
13+
TARGET1 = $(TARGET_BASE1)
14+
SRC_FILES1=$(UNITY_ROOT)/src/unity.c test/${SUITE_NAME}.c test/test_runners/${SUITE_NAME}_Runner.c ../../uvm32/uvm32.c
15+
INC_DIRS=-I$(UNITY_ROOT)/src -I../../uvm32/ -I../../common -Irom
16+
17+
.PHONY: rom
18+
19+
default: $(SRC_FILES1) rom
20+
@$(C_COMPILER) $(CFLAGS) $(INC_DIRS) $(SYMBOLS) $(SRC_FILES1) rom/rom-header.c -o $(TARGET1)
21+
@ ./$(TARGET1)
22+
23+
rom:
24+
@(cd rom && make)
25+
26+
test/test_runners/${SUITE_NAME}_Runner.c: test/${SUITE_NAME}.c
27+
@mkdir -p test/test_runners
28+
@ruby $(UNITY_ROOT)/auto/generate_test_runner.rb test/${SUITE_NAME}.c test/test_runners/${SUITE_NAME}_Runner.c
29+
30+
clean:
31+
rm -rf $(TARGET1) test/test_runners
32+
(cd rom && make clean)
33+

test/meter/rom/Makefile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
TOPDIR=../../../
2+
PROJECT:=$(shell basename ${PWD})
3+
SRCS=${PROJECT}.c ${TOPDIR}/apps/crt0.S
4+
OPT=-O0 # don't let optimiser remove stall loop
5+
all: all_common
6+
@# Convert ROM to C file and header
7+
@xxd -i ${PROJECT}.bin > ${PROJECT}-header.c
8+
@echo "extern unsigned char ${PROJECT}_bin[]; extern int ${PROJECT}_bin_len;" > ${PROJECT}-header.h
9+
10+
test: test_common
11+
clean: clean_common
12+
rm -f ${PROJECT}-header.h ${PROJECT}-header.c
13+
14+
include ${TOPDIR}/apps/makefile.common

0 commit comments

Comments
 (0)