Skip to content

Commit 7300b94

Browse files
mmurookak-okada
authored andcommitted
add defforeign test.
1 parent 21a5d86 commit 7300b94

File tree

7 files changed

+162
-0
lines changed

7 files changed

+162
-0
lines changed

.travis.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ if [ "$QEMU" != "" ]; then
8787
export EXIT_STATUS=0;
8888
set +e
8989
# run test in EusLisp/test
90+
make -C test
9091
for test_l in test/*.l; do
9192

9293
travis_time_start euslisp.${test_l##*/}.test
@@ -235,6 +236,7 @@ if [[ "`uname -m`" == "aarch"* ]]; then
235236
fi
236237

237238
# run test in EusLisp/test
239+
make -C $CI_SOURCE_PATH/test
238240
for test_l in $CI_SOURCE_PATH/test/*.l; do
239241

240242
travis_time_start euslisp.${test_l##*/}.test

test/Makefile

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
GCC_MACHINE=$(shell gcc -dumpmachine)
2+
$(info "-- GCC_MACHINE = ${GCC_MACHINE}")
3+
OS=$(shell uname -s | sed 's/[^A-Za-z1-9].*//')
4+
$(info "-- OS = ${OS}")
5+
ifeq ($(OS),Linux)
6+
export MAKEFILE=Makefile.Linux
7+
endif
8+
ifeq ($(OS),CYGWIN)
9+
export MAKEFILE=Makefile.Cygwin
10+
endif
11+
ifeq ($(OS),Darwin)
12+
export MAKEFILE=Makefile.Darwin
13+
endif
14+
15+
$(info "-- MAKEFILE = ${MAKEFILE}")
16+
17+
# set EUSDIR if not defined
18+
export EUSDIR?=$(CURDIR)/..
19+
$(info "-- EUSDIR = ${EUSDIR}")
20+
21+
include $(MAKEFILE)
22+
23+
SRC=testdefforeign.c
24+
OBJ=$(basename $(SRC)).o
25+
LIB=$(LPFX)$(basename $(SRC)).$(LSFX)
26+
27+
$(LIB): $(OBJ)
28+
$(LD) $(SOFLAGS) $(OUTOPT)$(LIB) $(OBJ) $(LDFLAGS)
29+
30+
$(OBJ): $(SRC)
31+
$(CC) $(CFLAGS) -DCOMPILE_LIB -c $(SRC) $(OBJOPT)$(OBJ)
32+
33+
clean:
34+
rm -f $(LIB) $(OBJ)

test/Makefile.Cygwin

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CC = c++
2+
CFLAGS = -O2 -falign-functions=4 -DCygwin -I$(EUSDIR)/include
3+
LDFLAGS =
4+
OBJOPT = -o
5+
OUTOPT = -o
6+
LD = c++ -shared -falign-functions=4
7+
EXELD = c++ -falign-functions=4
8+
SOFLAGS =
9+
EXESFX = .exe
10+
LSFX = dll
11+
LPFX = lib
12+
LIBS = -L$(ARCHDIR) -lRAPID

test/Makefile.Darwin

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CC = c++
2+
CFLAGS = -O2 -falign-functions=8 -fPIC -DDarwin -DGCC -I$(EUSDIR)/include
3+
LDFLAGS =
4+
OBJOPT = -o
5+
OUTOPT = -o
6+
LD = c++
7+
SOFLAGS = -dynamiclib -flat_namespace -undefined suppress
8+
EXELD = c++
9+
EXESFX =
10+
LSFX = so
11+
LPFX = lib
12+
LIBS = -L$(ARCHDIR) -lRAPID

test/Makefile.Linux

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
CC = c++
2+
CFLAGS = -O2 -DLinux -DGCC -I$(EUSDIR)/include
3+
LDFLAGS =
4+
OBJOPT = -o
5+
OUTOPT = -o
6+
LD = c++
7+
SOFLAGS = -shared
8+
EXELD = c++
9+
EXESFX =
10+
LSFX = so
11+
LPFX = lib
12+
13+
ifneq (,$(findstring 64,$(shell gcc -dumpmachine)))
14+
CFLAGS+=-falign-functions=8
15+
else
16+
CFLAGS+=-falign-functions=4
17+
endif
18+
19+
ifneq ($(shell gcc -dumpmachine | egrep "^(arm|aarch)"),)
20+
LDFLAGS+=-Wl,-z,execstack
21+
CFLAGS+=-DARM -fPIC
22+
endif
23+
ifneq ($(shell gcc -dumpmachine | grep "^x86_64"),)
24+
CFLAGS+=-fPIC
25+
endif
26+
27+
ifneq ($(shell gcc -dumpmachine | grep "i.*86-linux"),)
28+
CC += -m32
29+
LD += -m32
30+
EXELD += -m32
31+
endif
32+
33+

test/test-defforeign.l

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
(require :unittest "lib/llib/unittest.l")
2+
3+
(init-unit-test)
4+
5+
(deftest test-defforeign
6+
(defvar *testforeign-lib*
7+
(load-foreign (format nil "~a/test/libtestdefforeign.so" (unix:getenv "EUSDIR"))))
8+
9+
(defforeign test1
10+
*testforeign-lib*
11+
"test1"
12+
(:integer :float)
13+
:float
14+
)
15+
16+
(defforeign test2
17+
*testforeign-lib*
18+
"test2"
19+
(:string)
20+
:float
21+
)
22+
23+
(setq test1-result (test1 1 2.5))
24+
(format t "test1: ~a~%" test1-result)
25+
(assert (= test1-result 3.5))
26+
27+
(setq test2-result (test2 (float-vector 1.0 2.5)))
28+
(format t "test2: ~a~%" test2-result)
29+
(assert (= test2-result 3.5))
30+
)
31+
32+
(eval-when
33+
(load eval)
34+
(run-all-tests)
35+
(exit))

test/testdefforeign.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// for eus.h
2+
#include <stdio.h>
3+
#include <stdlib.h>
4+
#include <unistd.h>
5+
#include <string.h>
6+
#include <setjmp.h>
7+
#include <errno.h>
8+
#include <sstream>
9+
10+
#define class eus_class
11+
#define throw eus_throw
12+
#define export eus_export
13+
#define vector eus_vector
14+
#define string eus_string
15+
#include <eus.h> // include eus.h just for eusfloat_t ...
16+
#undef class
17+
#undef throw
18+
#undef export
19+
#undef vector
20+
#undef string
21+
22+
extern "C" {
23+
eusfloat_t test1(eusinteger_t v1, eusfloat_t v2) {
24+
printf("// v1: %d\n", (int)v1);
25+
printf("// v2: %f\n", v2);
26+
return v1 + v2;
27+
}
28+
29+
eusfloat_t test2(eusfloat_t *v) {
30+
printf("// v[0]: %f\n", v[0]);
31+
printf("// v[1]: %f\n", v[1]);
32+
return v[0] + v[1];
33+
}
34+
}

0 commit comments

Comments
 (0)