1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-11-23 22:58:06 +11:00

test: begin adding common test harnessing code

This should make tests a bit more convenient to write and debug.

Moreover, begin de de-IX-ization of parseExpr. I have, in a local WIP, a
parseExpr implemented using a recursive descent algo, it passes all tests, but
it unfortunately assembles a faulty zasm. I have to find the expressions that
it doesn't parse properly.

But before I do that, I prefer to commit these significant improvements I've
been making to tests harness in parallel of this development.
This commit is contained in:
Virgil Dupras 2019-12-23 15:41:25 -05:00
parent 98ca338aba
commit a034f63e23
6 changed files with 85 additions and 116 deletions

View File

@ -26,6 +26,18 @@ parseExpr:
pop de pop de
ret ret
; Same as parseExpr, but preserves IX and puts result in DE. This is a
; transitionary routine and will replace parseExpr when everyone has jumped
; ship.
parseExprDE:
push ix
push hl
call _parseExpr
push ix \ pop de
pop hl
pop ix
ret
_parseExpr: _parseExpr:
ld de, exprTbl ld de, exprTbl
.loop: .loop:

View File

@ -6,9 +6,15 @@
* until it halts. The return code is the value of the register A at halt time. * until it halts. The return code is the value of the register A at halt time.
*/ */
static void iowr_stderr(uint8_t val)
{
fputc(val, stderr);
}
int main() int main()
{ {
Machine *m = emul_init(); Machine *m = emul_init();
m->iowr[0] = iowr_stderr;
// read stdin in mem // read stdin in mem
int i = 0; int i = 0;
int c = getchar(); int c = getchar();
@ -22,6 +28,7 @@ int main()
return 1; return 1;
} }
emul_loop(); emul_loop();
if (m->cpu.R1.wr.HL)
return m->cpu.R1.br.A; return m->cpu.R1.br.A;
} }

View File

@ -11,7 +11,7 @@ APPS="${BASE}/apps"
chk() { chk() {
echo "Running test $1" echo "Running test $1"
if ! ${ZASM} "${KERNEL}" "${APPS}" < $1 | ${RUNBIN}; then if ! ${ZASM} "${KERNEL}" "${APPS}" common.asm < $1 | ${RUNBIN}; then
echo "failed with code ${PIPESTATUS[1]}" echo "failed with code ${PIPESTATUS[1]}"
exit 1 exit 1
fi fi
@ -22,7 +22,7 @@ if [ ! -z $1 ]; then
exit 0 exit 0
fi fi
for fn in *.asm; do for fn in test_*.asm; do
chk "${fn}" chk "${fn}"
done done

View File

@ -1,5 +1,6 @@
jp test jp test
.inc "ascii.h"
.inc "core.asm" .inc "core.asm"
.inc "str.asm" .inc "str.asm"
.inc "lib/util.asm" .inc "lib/util.asm"
@ -8,6 +9,9 @@ jp test
.equ EXPR_PARSE parseLiteral .equ EXPR_PARSE parseLiteral
.inc "lib/expr.asm" .inc "lib/expr.asm"
.inc "basic/parse.asm" .inc "basic/parse.asm"
.inc "lib/fmt.asm"
.inc "stdio.asm"
.inc "common.asm"
test: test:
ld sp, 0xffff ld sp, 0xffff
@ -55,21 +59,21 @@ testParseThruth:
.true: .true:
call parseTruth call parseTruth
jp nz, fail call assertZ
or a or a
jp z, fail call assertNZ
jp nexttest jp nexttest
.false: .false:
call parseTruth call parseTruth
jp nz, fail call assertZ
or a or a
jp nz, fail call assertZ
jp nexttest jp nexttest
.error: .error:
call parseTruth call parseTruth
jp z, fail call assertNZ
jp nexttest jp nexttest
.t1: .db "42", 0 .t1: .db "42", 0
@ -88,17 +92,4 @@ testParseThruth:
.f6: .db "2<=1", 0 .f6: .db "2<=1", 0
.e1: .db "foo", 0 .e1: .db "foo", 0
testNum: .db 1 STDIO_RAMSTART:
nexttest:
ld a, (testNum)
inc a
ld (testNum), a
ret
fail:
ld a, (testNum)
halt
; used as RAM
sandbox:

View File

@ -5,8 +5,14 @@
jp test jp test
.inc "ascii.h"
.inc "core.asm"
.inc "lib/ari.asm"
.inc "lib/fmt.asm"
.inc "stdio.asm"
.inc "common.asm"
dummyLabel: dummyLabel:
testNum: .db 1
.equ dummyLabel 0x42 .equ dummyLabel 0x42
@ -37,37 +43,25 @@ test:
call nexttest call nexttest
; Test that .equ can override label ; Test that .equ can override label
ld a, 0x42 ld de, 0x42
ld hl, dummyLabel ld hl, dummyLabel
cp l call assertEQW
jp nz, fail
call nexttest call nexttest
; test that "@" is updated by a .org directive ; test that "@" is updated by a .org directive
ld hl, AFTER_ORG ld hl, AFTER_ORG
ld de, 0x1234 ld de, 0x1234
or a ; clear carry call assertEQW
sbc hl, de
jp nz, fail
call nexttest call nexttest
; test that AND affects the Z flag ; test that AND affects the Z flag
ld a, 0x69 ld a, 0x69
and 0x80 and 0x80
jp nz, fail call assertZ
call nexttest call nexttest
; success ; success
xor a xor a
halt halt
nexttest: STDIO_RAMSTART:
ld a, (testNum)
inc a
ld (testNum), a
ret
fail:
ld a, (testNum)
halt

View File

@ -9,10 +9,12 @@
jp test jp test
.inc "ascii.h"
.inc "core.asm" .inc "core.asm"
.inc "str.asm" .inc "str.asm"
.inc "lib/util.asm" .inc "lib/util.asm"
.inc "lib/ari.asm" .inc "lib/ari.asm"
.inc "lib/fmt.asm"
.inc "zasm/util.asm" .inc "zasm/util.asm"
.inc "zasm/const.asm" .inc "zasm/const.asm"
.inc "lib/parse.asm" .inc "lib/parse.asm"
@ -21,6 +23,9 @@ jp test
.inc "zasm/symbol.asm" .inc "zasm/symbol.asm"
.equ EXPR_PARSE parseNumberOrSymbol .equ EXPR_PARSE parseNumberOrSymbol
.inc "lib/expr.asm" .inc "lib/expr.asm"
.equ STDIO_RAMSTART SYM_RAMEND
.inc "stdio.asm"
.inc "common.asm"
; Pretend that we aren't in first pass ; Pretend that we aren't in first pass
zasmIsFirstPass: zasmIsFirstPass:
@ -29,8 +34,6 @@ zasmIsFirstPass:
zasmGetPC: zasmGetPC:
ret ret
testNum: .db 1
s1: .db "2+2", 0 s1: .db "2+2", 0
s2: .db "0x4001+0x22", 0 s2: .db "0x4001+0x22", 0
s3: .db "FOO+BAR", 0 s3: .db "FOO+BAR", 0
@ -44,29 +47,22 @@ sBAR: .db "BAR", 0
test: test:
ld sp, 0xffff ld sp, 0xffff
; New-style tests
;call testParseExpr
; Old-style tests, not touching them now. ; Old-style tests, not touching them now.
ld hl, s1 ld hl, s1
call parseExpr call parseExprDE
jp nz, fail call assertZ
push ix \ pop hl ld hl, 4
ld a, h call assertEQW
or a
jp nz, fail
ld a, l
cp 4
jp nz, fail
call nexttest call nexttest
ld hl, s2 ld hl, s2
call parseExpr call parseExprDE
jp nz, fail call assertZ
push ix \ pop hl ld hl, 0x4023
ld a, h call assertEQW
cp 0x40
jp nz, fail
ld a, l
cp 0x23
jp nz, fail
call nexttest call nexttest
; before the next test, let's set up FOO and BAR symbols ; before the next test, let's set up FOO and BAR symbols
@ -81,55 +77,33 @@ test:
jp nz, fail jp nz, fail
ld hl, s3 ld hl, s3
call parseExpr call parseExprDE
jp nz, fail call assertZ
push ix \ pop hl ld hl, 0x4020
ld a, h call assertEQW
cp 0x40
jp nz, fail
ld a, l
cp 0x20
jp nz, fail
call nexttest call nexttest
ld hl, s4 ld hl, s4
call parseExpr call parseExprDE
jp nz, fail call assertZ
push ix \ pop hl ld hl, 0x60
ld a, h call assertEQW
or a
jp nz, fail
ld a, l
cp 0x60
jp nz, fail
call nexttest call nexttest
ld hl, s5 ld hl, s5
call parseExpr call parseExprDE
jp nz, fail call assertZ
push ix \ pop hl ld hl, 0x3ffd
ld a, h call assertEQW
cp 0x3f
jp nz, fail
ld a, l
cp 0xfd
jp nz, fail
call nexttest call nexttest
ld hl, s6 ld hl, s6
call parseExpr call parseExprDE
jp nz, fail call assertZ
push ix \ pop hl ld hl, 0x4080
ld a, h call assertEQW
cp 0x40
jp nz, fail
ld a, l
cp 0x80
jp nz, fail
call nexttest call nexttest
; New-style tests
call testParseExpr
; success ; success
xor a xor a
halt halt
@ -151,20 +125,18 @@ testParseExpr:
call .testEQ call .testEQ
ld iy, .t8 ld iy, .t8
call .testEQ call .testEQ
ld iy, .t9
call .testEQ
ret ret
.testEQ: .testEQ:
push iy \ pop hl push iy \ pop hl
inc hl \ inc hl inc hl \ inc hl
call parseExpr call parseExprDE
jp nz, fail call assertZ
push ix \ pop de ld l, (iy)
ld a, e ld h, (iy+1)
cp (iy) call assertEQW
jp nz, fail
ld a, d
cp (iy+1)
jp nz, fail
jp nexttest jp nexttest
.t1: .t1:
@ -191,13 +163,6 @@ testParseExpr:
.t8: .t8:
.dw 0xffff .dw 0xffff
.db "-1", 0 .db "-1", 0
.t9:
nexttest: .dw 10
ld a, (testNum) .db "2*3+4", 0
inc a
ld (testNum), a
ret
fail:
ld a, (testNum)
halt