This commit is contained in:
Wesley Moore 2025-03-09 20:15:33 +10:00
parent e256d2b1d1
commit cc1ae33f1c
No known key found for this signature in database
4 changed files with 59 additions and 4 deletions

View file

@ -1,7 +1,7 @@
CC=riscv64-unknown-elf-gcc
AS=riscv64-unknown-elf-as
ASFLAGS=-g -mabi=ilp32e -march=rv32ec
CFLAGS=$(ASFLAGS)
CFLAGS=$(ASFLAGS) -Os -Wall -std=c99
LD=riscv64-unknown-elf-ld
export JQ?=jaq
export QEMU?=qemu-riscv32
@ -57,7 +57,7 @@ tests/btohex.elf: mem.o hex.o debug.o tests/btohex.o
tests/tohex.elf: hex.o tests/tohex.o
$(LD) -m elf32lriscv -T link.ld $^ -o $@
tests/harness.elf: tests/harness.o
tests/harness.elf: tests/harness.o tests/charness.o
$(LD) -m elf32lriscv -T link.ld $^ -o $@
%.o : %.s

11
calc.h Normal file
View file

@ -0,0 +1,11 @@
#ifndef CALC_H
#define CALC_H
typedef unsigned char bool;
#define true 1;
#define false 0;
typedef unsigned char u8;
typedef unsigned int uint;
#endif

43
tests/charness.c Normal file
View file

@ -0,0 +1,43 @@
#include "../calc.h"
#define BUF_SIZE 80
#define make_str(s) { sizeof(s), (const u8 *)s }
#define make_test(name) { make_str(#name), name }
extern bool streq(const u8 *, uint, const u8 *, uint);
extern int read(u8 *, uint); // read from stdin
// Tests
extern void count_digits(void);
extern void fmt_decimal(void);
typedef struct {
u8 len;
const u8 *data;
} str;
typedef void (*testfn)(void);
typedef struct {
str name;
testfn fn;
} test;
static str tests[2] = {make_test(count_digits), make_test(fmt_decimal)};
void _start(void) {
u8 buf[BUF_SIZE];
int nread0 = read(buf, BUF_SIZE);
if (nread0 < 0) {
for(;;); // TODO: add abort function
}
uint nread = (uint)nread0;
for(uint i = 0; i < sizeof(tests); i++) {
const str s = tests[i];
if (streq(buf, nread, s.data, s.len)) {
}
}
}

View file

@ -3,7 +3,8 @@
.org 0
# Provide program starting address to linker
.global _start
.global read
.global streq
# .extern fmt_decimal
@ -25,7 +26,7 @@ inbuf: .skip 80
.text
_start:
_start2:
la a0, inbuf
li a1, 80
jal read