unit test introduced:

User should create <test-name>-test.c file in the following manner:
> cat codegen/function/sum-test.c
extern void *resolve_symbol(const char*);

int
run_test() {
  int (*sum)(int, int) = resolve_symbol("kfun:sum");

  if (sum(2, 3) != 5) return 1;

  return 0;
}
and add <test-name> to the TESTS variable in the Makefile
to run tests:
> make clean run
Note: failing tests should return no zero values.
This commit is contained in:
Vasily Levchenko
2016-10-09 20:59:58 +03:00
parent dbdbc9a844
commit 4c32689e1f
6 changed files with 72 additions and 0 deletions
+43
View File
@@ -0,0 +1,43 @@
TESTS := sum
BIN_TESTS=$(foreach t, ${TESTS},${t}_test)
VPATH=codegen/function
LLC=llc-mp-3.8
CC=clang-mp-3.8
JAVA=java
TOP=../..
RUNTIME=${TOP}/runtime
BACKEND=${TOP}/backend.native
BACKEND_CLASSES=${TOP}/backend.native/build/classes
KOTLIN_DIST=${BACKEND}/kotlin-ir/dist
KOTLIN_NATIVE_CLASSPATH=${BACKEND_CLASSES}/bc_frontend:${BACKEND_CLASSES}/cli_bc:${BACKEND_CLASSES}/compiler:${KOTLIN_DIST}/kotlinc/lib/kotlin-reflect.jar:${KOTLIN_DIST}kotlinc/lib/kotlin-stdlib.jar:${KOTLIN_DIST}/kotlinc/lib/kotlin-compiler.jar:${KOTLIN_DIST}/kotlinc/lib/kotlin-runtime.jar:${TOP}/Interop/Runtime/build/classes/main
define PROTO
$(1)_test: main.c $1-test.c $1.S
$(CC) -o $$@ $$^
${1}_run:${1}_test
./${1}_test
endef
$(foreach test,${TESTS},$(eval $(call PROTO,$(test))))
all:${BIN_TESTS}
run:$(foreach test,${TESTS},${test}_run)
clean:
${RM} *.o *.S *.BCkt ${BIN_TESTS}
%.S:%.BCkt
${LLC} -o $@ $<
%.BCkt:%.kt
${JAVA} -cp ${KOTLIN_NATIVE_CLASSPATH} -Djava.library.path=${BACKEND}/build/nativelibs org.jetbrains.kotlin.cli.bc.K2NativeKt -output $@ -runtime ${RUNTIME}/build/runtime.bc $<
@@ -0,0 +1,10 @@
extern void *resolve_symbol(const char*);
int
run_test() {
int (*sum)(int, int) = resolve_symbol("kfun:sum");
if (sum(2, 3) != 5) return 1;
return 0;
}
+19
View File
@@ -0,0 +1,19 @@
#include <dlfcn.h>
#include <stdio.h>
/**
* > llc-mp-3.8 b.out -o b.S
* > /opt/local/libexec/llvm-3.8/bin/clang main.c b.S -o sum-test
*/
extern int run_test();
void * resolve_symbol(char *name) {
/* here we can add here some magic to resolve symbols in kotlin native*/
return dlsym(RTLD_SELF, name);
}
int
main() {
return run_test();
}