improved testing and added general Makefile

This commit is contained in:
Daniel Knüttel 2018-10-27 12:14:57 +02:00
parent 9b599b4ebb
commit 5dc1f88247
3 changed files with 27 additions and 1 deletions

16
Makefile Normal file
View File

@ -0,0 +1,16 @@
CC=gcc
objects= stack.o method_dispatcher/method_dispatcher.o interpreter/core_methods.o interpreter/interpreter.o
all: $(objects) test
CFLAG= -c -O -o
%.o: %.c
$(CC) $(CFLAG) $@ $<
.PHONY: test
test:
cd test && make
cd method_dispatcher/test && make
cd interpreter/test && make

View File

@ -1,5 +1,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <assert.h>
#include "../interpreter.h" #include "../interpreter.h"
#include "../core_methods.h" #include "../core_methods.h"
#include "../../method_dispatcher/method_dispatcher.h" #include "../../method_dispatcher/method_dispatcher.h"
@ -39,9 +40,13 @@ int main(void)
machine_state_t_exec_cycle(state); machine_state_t_exec_cycle(state);
machine_state_t_exec_cycle(state); machine_state_t_exec_cycle(state);
printf("data_reg[0]: %x\n", state->data_reg[0]); printf("data_reg[0]: %x\n", state->data_reg[0]);
assert(state->data_reg[0] == 0xfefe);
printf("data_reg[1]: %x\n", state->data_reg[1]); printf("data_reg[1]: %x\n", state->data_reg[1]);
assert(state->data_reg[1] == 5);
printf("data_reg[2]: %x\n", state->data_reg[2]); printf("data_reg[2]: %x\n", state->data_reg[2]);
assert(state->data_reg[2] == 3);
printf("program_counter: %d\n", state->program_counter); printf("program_counter: %d\n", state->program_counter);
assert(state->program_counter == 8);
dispatch_tree_autoinserter_t_del(inserter); dispatch_tree_autoinserter_t_del(inserter);
machine_state_t_del(state); machine_state_t_del(state);
free(program); free(program);

View File

@ -1,5 +1,6 @@
#include <stdio.h> #include <stdio.h>
#include "../stack.h" #include "../stack.h"
#include <assert.h>
int main(void) int main(void)
{ {
@ -13,10 +14,14 @@ int main(void)
{ {
bci_stack_t_push(&stack, (uint16_t) i); bci_stack_t_push(&stack, (uint16_t) i);
} }
--i;
while(!status) while(!status)
{ {
status = bci_stack_t_pop(&stack, &res); status = bci_stack_t_pop(&stack, &res);
printf("%d\n", res); if(!status)
{
assert(res == i--);
}
} }