Compare commits
2 commits
ddefa0cac0
...
cc1ae33f1c
Author | SHA1 | Date | |
---|---|---|---|
cc1ae33f1c | |||
e256d2b1d1 |
3 changed files with 41 additions and 6 deletions
4
Makefile
4
Makefile
|
@ -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
3
calc.h
|
@ -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;
|
||||
|
||||
|
|
|
@ -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)) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue