Compare commits

..

2 commits

Author SHA1 Message Date
cc1ae33f1c
WIP 2025-03-09 20:15:33 +10:00
e256d2b1d1
Include tests in make all 2025-03-08 11:21:47 +10:00
3 changed files with 41 additions and 6 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
@ -11,7 +11,7 @@ TEST_SRC := $(shell find tests -name '*.s')
# Replace .s with .elf
TESTS := $(patsubst %.s,%.elf,$(TEST_SRC))
all: calc.elf
all: calc.elf tests
check: tests
@tests/unittest

3
calc.h
View file

@ -2,6 +2,9 @@
#define CALC_H
typedef unsigned char bool;
#define true 1;
#define false 0;
typedef unsigned char u8;
typedef unsigned int uint;

View file

@ -1,11 +1,43 @@
#include "../calc.h"
// TODO: make these pascal strings
extern bool streq(u8 *, uint, u8 *, uint);
#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)) {
}
}
}