Add the start of a test harness binary
This commit is contained in:
parent
63e79b8bb6
commit
e8f2a96f97
2 changed files with 60 additions and 0 deletions
3
Makefile
3
Makefile
|
@ -57,6 +57,9 @@ tests/btohex.elf: mem.o hex.o debug.o tests/btohex.o
|
||||||
tests/tohex.elf: hex.o tests/tohex.o
|
tests/tohex.elf: hex.o tests/tohex.o
|
||||||
$(LD) -m elf32lriscv -T link.ld $^ -o $@
|
$(LD) -m elf32lriscv -T link.ld $^ -o $@
|
||||||
|
|
||||||
|
tests/harness.elf: tests/harness.o
|
||||||
|
$(LD) -m elf32lriscv -T link.ld $^ -o $@
|
||||||
|
|
||||||
%.o : %.s
|
%.o : %.s
|
||||||
$(AS) $(ASFLAGS) $< -o $@
|
$(AS) $(ASFLAGS) $< -o $@
|
||||||
|
|
||||||
|
|
57
tests/harness.s
Normal file
57
tests/harness.s
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
# Unit tests harness
|
||||||
|
# Read suite name from stdin, then run that suite
|
||||||
|
|
||||||
|
.org 0
|
||||||
|
# Provide program starting address to linker
|
||||||
|
.global _start
|
||||||
|
|
||||||
|
# .extern fmt_decimal
|
||||||
|
|
||||||
|
/* newlib system calls */
|
||||||
|
.set SYSEXIT, 93
|
||||||
|
.set SYSREAD, 63
|
||||||
|
.set SYSWRITE, 64
|
||||||
|
|
||||||
|
.section .rodata
|
||||||
|
|
||||||
|
inputs:
|
||||||
|
.word 0, 1, 2, 3, 9, 10, 100, 0x80000000
|
||||||
|
inputs_end:
|
||||||
|
|
||||||
|
.section .bss
|
||||||
|
|
||||||
|
buf: .skip 11
|
||||||
|
inbuf: .skip 80
|
||||||
|
|
||||||
|
.text
|
||||||
|
|
||||||
|
_start:
|
||||||
|
la a0, inbuf
|
||||||
|
li a1, 80
|
||||||
|
jal read
|
||||||
|
|
||||||
|
mv a2, a0 # move bytes read to a2
|
||||||
|
li t0, SYSWRITE # "write" syscall
|
||||||
|
li a0, 1 # 1 = standard output (stdout)
|
||||||
|
la a1, inbuf # load address of buffer
|
||||||
|
ecall # invoke syscall to print the string
|
||||||
|
|
||||||
|
li t0, SYSEXIT # "exit" syscall
|
||||||
|
la a0, 0 # Use 0 return code
|
||||||
|
ecall # invoke syscall to terminate the program
|
||||||
|
|
||||||
|
|
||||||
|
# Read from stdin
|
||||||
|
# arguments:
|
||||||
|
# a0: address of buffer to read into
|
||||||
|
# a1: number of bytes to read
|
||||||
|
# return:
|
||||||
|
# a0: count of bytes read, or error if < 0
|
||||||
|
|
||||||
|
read:
|
||||||
|
li t0, SYSREAD # "read" syscall
|
||||||
|
mv a2, a1 # bytes to read
|
||||||
|
mv a1, a0 # buffer address
|
||||||
|
li a0, 1 # 0 = standard input (stdin)
|
||||||
|
ecall # invoke syscall
|
||||||
|
ret
|
Loading…
Reference in a new issue