diff --git a/.gitignore b/.gitignore index 8bec7c74d..dc7bc2589 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ *.o +* /lightning.info +/tests/test-addr +/tests/test-addi diff --git a/tests/Makefile b/tests/Makefile index ee41e5e8e..ead09bdab 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -1,10 +1,18 @@ -TESTS = addr +TESTS = addr addi CC = gcc CFLAGS = -Wall -O0 -g all: $(addprefix test-,$(TESTS)) +check: all + @echo "Running unit tests..." + @set -e; for test in $(TESTS); do \ + echo "Testing: $$test"; \ + ./test-$$test; \ + done + @echo "Success." + jit.o: ../jit.h ../jit/*.c $(CC) $(CFLAGS) $(CPPFLAGS) -flto -I.. -o jit.o -c ../jit/jit.c diff --git a/tests/test-addi.c b/tests/test-addi.c new file mode 100644 index 000000000..586dc1c18 --- /dev/null +++ b/tests/test-addi.c @@ -0,0 +1,26 @@ +#include "test.h" + +static void +run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size) +{ + jit_begin(j, arena_base, arena_size); + + jit_arg_abi_t abi[] = { JIT_ARG_ABI_INT32 }; + jit_arg_t args[1]; + jit_receive(j, 1, abi, args); + ASSERT(args[0].kind == JIT_ARG_LOC_GPR); + jit_addi(j, JIT_R0, args[0].loc.gpr, 69); + jit_retr(j, JIT_R0); + + size_t size = 0; + void* ret = jit_end(j, &size); + + int (*f)(int) = ret; + ASSERT(f(42) == 111); +} + +int +main (int argc, char *argv[]) +{ + return main_helper(argc, argv, run_test); +}