2009-04-18 16:31:35 +04:00
|
|
|
#
|
|
|
|
# Tiny C Compiler Makefile - tests
|
|
|
|
#
|
|
|
|
|
2012-06-27 21:04:27 +04:00
|
|
|
TOP = ..
|
|
|
|
include $(TOP)/Makefile
|
2012-12-14 20:18:03 +04:00
|
|
|
VPATH = $(top_srcdir)/tests
|
2012-06-27 21:04:27 +04:00
|
|
|
|
2009-04-18 16:31:35 +04:00
|
|
|
# what tests to run
|
2013-02-05 17:27:38 +04:00
|
|
|
TESTS = \
|
|
|
|
hello \
|
|
|
|
libtest \
|
|
|
|
test3 \
|
|
|
|
moretests
|
|
|
|
|
|
|
|
# test4 -- problem with -static
|
|
|
|
# asmtest -- minor differences with gcc
|
|
|
|
# btest -- works on i386 (including win32)
|
|
|
|
# test3 -- win32 does not know how to printf long doubles
|
2009-04-18 16:31:35 +04:00
|
|
|
|
2012-11-21 09:47:23 +04:00
|
|
|
# bounds-checking is supported only on i386
|
|
|
|
ifneq ($(ARCH),i386)
|
2013-02-05 17:27:38 +04:00
|
|
|
TESTS := $(filter-out btest,$(TESTS))
|
2012-11-21 09:47:23 +04:00
|
|
|
endif
|
2013-02-05 17:27:38 +04:00
|
|
|
ifdef CONFIG_WIN32
|
|
|
|
TESTS := $(filter-out test3,$(TESTS))
|
2012-06-27 21:04:27 +04:00
|
|
|
endif
|
|
|
|
ifeq ($(TARGETOS),Darwin)
|
2013-02-06 22:01:07 +04:00
|
|
|
TESTS := $(filter-out hello test3 btest,$(TESTS))
|
2012-06-27 21:04:27 +04:00
|
|
|
endif
|
2009-04-18 16:31:35 +04:00
|
|
|
|
2010-12-04 18:47:08 +03:00
|
|
|
ifdef DISABLE_STATIC
|
2013-02-05 17:27:38 +04:00
|
|
|
export LD_LIBRARY_PATH:=$(CURDIR)/..
|
2010-12-04 18:47:08 +03:00
|
|
|
endif
|
|
|
|
|
2012-03-06 22:26:36 +04:00
|
|
|
ifeq ($(TARGETOS),Darwin)
|
2013-02-05 17:27:38 +04:00
|
|
|
CFLAGS+=-Wl,-flat_namespace,-undefined,warning
|
|
|
|
export MACOSX_DEPLOYMENT_TARGET:=10.2
|
|
|
|
NATIVE_DEFINES+=-D_ANSI_SOURCE
|
2012-03-06 22:26:36 +04:00
|
|
|
endif
|
|
|
|
|
2009-04-18 16:31:35 +04:00
|
|
|
# run local version of tcc with local libraries and includes
|
2013-02-05 17:27:38 +04:00
|
|
|
TCCFLAGS = -B$(TOP)
|
2012-06-27 21:04:27 +04:00
|
|
|
ifdef CONFIG_WIN32
|
2013-02-05 17:27:38 +04:00
|
|
|
TCCFLAGS = -B$(top_srcdir)/win32 -I$(top_srcdir)/include -L$(TOP)
|
2012-06-27 21:04:27 +04:00
|
|
|
endif
|
2009-04-18 16:31:35 +04:00
|
|
|
|
2013-02-05 17:27:38 +04:00
|
|
|
TCC = $(TOP)/tcc $(TCCFLAGS)
|
|
|
|
RUN_TCC = $(NATIVE_DEFINES) -DONE_SOURCE -run $(TOP)/tcc.c $(TCCFLAGS)
|
2009-04-18 16:31:35 +04:00
|
|
|
|
2013-02-05 17:27:38 +04:00
|
|
|
DISAS = objdump -d
|
2009-04-18 16:31:35 +04:00
|
|
|
|
|
|
|
# libtcc test
|
2011-05-14 18:21:45 +04:00
|
|
|
ifdef LIBTCC1
|
2013-02-05 17:27:38 +04:00
|
|
|
LIBTCC1:=$(TOP)/$(LIBTCC1)
|
2011-05-14 18:21:45 +04:00
|
|
|
endif
|
|
|
|
|
2013-02-05 17:27:38 +04:00
|
|
|
all test : $(TESTS)
|
|
|
|
|
|
|
|
hello: ../examples/ex1.c
|
|
|
|
@echo ------------ $@ ------------
|
|
|
|
$(TCC) $< -o $@$(EXESUF) && ./$@$(EXESUF)
|
|
|
|
$(TCC) -run $<
|
|
|
|
|
2011-05-14 18:21:45 +04:00
|
|
|
libtest: libtcc_test$(EXESUF) $(LIBTCC1)
|
2009-04-18 16:31:35 +04:00
|
|
|
@echo ------------ $@ ------------
|
2010-12-04 18:47:08 +03:00
|
|
|
./libtcc_test$(EXESUF) lib_path=..
|
2009-04-18 16:31:35 +04:00
|
|
|
|
2012-12-14 20:18:03 +04:00
|
|
|
libtcc_test$(EXESUF): libtcc_test.c $(top_builddir)/$(LIBTCC)
|
|
|
|
$(CC) -o $@ $^ $(CPPFLAGS) $(CFLAGS) $(NATIVE_DEFINES) $(LIBS) $(LINK_LIBTCC) $(LDFLAGS)
|
2009-04-18 16:31:35 +04:00
|
|
|
|
2013-02-05 17:27:38 +04:00
|
|
|
moretests:
|
|
|
|
@echo ------------ $@ ------------
|
|
|
|
$(MAKE) -C tests2
|
|
|
|
|
2009-04-18 16:31:35 +04:00
|
|
|
# test.ref - generate using gcc
|
2010-12-06 21:01:14 +03:00
|
|
|
# copy only tcclib.h so GCC's stddef and stdarg will be used
|
2009-04-18 16:31:35 +04:00
|
|
|
test.ref: tcctest.c
|
2012-02-09 21:53:17 +04:00
|
|
|
cp ../include/tcclib.h .
|
2013-01-25 23:14:10 +04:00
|
|
|
gcc -o tcctest.gcc $< -I. $(CPPFLAGS) -w $(CFLAGS) $(NATIVE_DEFINES) -std=gnu99 -O0 -fno-omit-frame-pointer $(LDFLAGS)
|
2009-04-18 16:31:35 +04:00
|
|
|
./tcctest.gcc > $@
|
|
|
|
|
|
|
|
# auto test
|
|
|
|
test1: test.ref
|
|
|
|
@echo ------------ $@ ------------
|
|
|
|
$(TCC) -run tcctest.c > test.out1
|
|
|
|
@if diff -u test.ref test.out1 ; then echo "Auto Test OK"; fi
|
|
|
|
|
|
|
|
# iterated test2 (compile tcc then compile tcctest.c !)
|
|
|
|
test2: test.ref
|
|
|
|
@echo ------------ $@ ------------
|
2009-04-18 18:53:25 +04:00
|
|
|
$(TCC) $(RUN_TCC) $(RUN_TCC) -run tcctest.c > test.out2
|
2009-04-18 16:31:35 +04:00
|
|
|
@if diff -u test.ref test.out2 ; then echo "Auto Test2 OK"; fi
|
|
|
|
|
|
|
|
# iterated test3 (compile tcc then compile tcc then compile tcctest.c !)
|
|
|
|
test3: test.ref
|
|
|
|
@echo ------------ $@ ------------
|
2009-04-18 18:53:25 +04:00
|
|
|
$(TCC) $(RUN_TCC) $(RUN_TCC) $(RUN_TCC) -run tcctest.c > test.out3
|
2009-04-18 16:31:35 +04:00
|
|
|
@if diff -u test.ref test.out3 ; then echo "Auto Test3 OK"; fi
|
|
|
|
|
|
|
|
# binary output test
|
|
|
|
test4: test.ref
|
|
|
|
@echo ------------ $@ ------------
|
|
|
|
# object + link output
|
|
|
|
$(TCC) -c -o tcctest3.o tcctest.c
|
|
|
|
$(TCC) -o tcctest3 tcctest3.o
|
|
|
|
./tcctest3 > test3.out
|
|
|
|
@if diff -u test.ref test3.out ; then echo "Object Auto Test OK"; fi
|
2013-02-05 17:27:38 +04:00
|
|
|
# dynamic output
|
|
|
|
$(TCC) -o tcctest1 tcctest.c
|
|
|
|
./tcctest1 > test1.out
|
|
|
|
@if diff -u test.ref test1.out ; then echo "Dynamic Auto Test OK"; fi
|
2009-04-18 16:31:35 +04:00
|
|
|
# dynamic output + bound check
|
|
|
|
$(TCC) -b -o tcctest4 tcctest.c
|
|
|
|
./tcctest4 > test4.out
|
|
|
|
@if diff -u test.ref test4.out ; then echo "BCheck Auto Test OK"; fi
|
2013-02-05 17:27:38 +04:00
|
|
|
# static output
|
|
|
|
$(TCC) -static -o tcctest2 tcctest.c
|
|
|
|
./tcctest2 > test2.out
|
|
|
|
@if diff -u test.ref test2.out ; then echo "Static Auto Test OK"; fi
|
2009-04-18 16:31:35 +04:00
|
|
|
|
|
|
|
# memory and bound check auto test
|
2009-07-19 00:06:54 +04:00
|
|
|
BOUNDS_OK = 1 4 8 10 14
|
|
|
|
BOUNDS_FAIL= 2 5 7 9 11 12 13 15
|
2009-04-18 16:31:35 +04:00
|
|
|
|
2013-02-05 17:27:38 +04:00
|
|
|
btest: boundtest.c
|
2009-04-18 16:31:35 +04:00
|
|
|
@echo ------------ $@ ------------
|
|
|
|
@for i in $(BOUNDS_OK); do \
|
2009-07-06 23:10:14 +04:00
|
|
|
echo ; echo --- boundtest $$i ---; \
|
2009-04-18 16:31:35 +04:00
|
|
|
if $(TCC) -b -run boundtest.c $$i ; then \
|
2009-07-06 23:10:14 +04:00
|
|
|
echo succeded as expected; \
|
2009-04-18 16:31:35 +04:00
|
|
|
else\
|
|
|
|
echo Failed positive test $$i ; exit 1 ; \
|
|
|
|
fi ;\
|
|
|
|
done ;\
|
|
|
|
for i in $(BOUNDS_FAIL); do \
|
2009-07-06 23:10:14 +04:00
|
|
|
echo ; echo --- boundtest $$i ---; \
|
2009-04-18 16:31:35 +04:00
|
|
|
if $(TCC) -b -run boundtest.c $$i ; then \
|
|
|
|
echo Failed negative test $$i ; exit 1 ;\
|
|
|
|
else\
|
2009-07-06 23:10:14 +04:00
|
|
|
echo failed as expected; \
|
2009-04-18 16:31:35 +04:00
|
|
|
fi ;\
|
|
|
|
done ;\
|
2009-07-06 23:10:14 +04:00
|
|
|
echo; echo Bound test OK
|
2009-04-18 16:31:35 +04:00
|
|
|
|
|
|
|
# speed test
|
2009-07-06 23:11:19 +04:00
|
|
|
speedtest: ex2 ex3
|
2009-04-18 16:31:35 +04:00
|
|
|
@echo ------------ $@ ------------
|
|
|
|
time ./ex2 1238 2 3 4 10 13 4
|
2012-12-14 20:18:03 +04:00
|
|
|
time $(TCC) -run $(top_srcdir)/examples/ex2.c 1238 2 3 4 10 13 4
|
2009-04-18 16:31:35 +04:00
|
|
|
time ./ex3 35
|
2012-12-14 20:18:03 +04:00
|
|
|
time $(TCC) -run $(top_srcdir)/examples/ex3.c 35
|
2009-04-18 16:31:35 +04:00
|
|
|
|
2011-02-01 20:41:03 +03:00
|
|
|
weaktest: test.ref
|
2012-10-22 13:11:42 +04:00
|
|
|
$(TCC) -c tcctest.c -o weaktest.tcc.o $(CPPFLAGS) $(CFLAGS)
|
|
|
|
$(CC) -c tcctest.c -o weaktest.gcc.o -I. $(CPPFLAGS) -w $(CFLAGS)
|
2011-02-01 20:41:03 +03:00
|
|
|
objdump -t weaktest.tcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.tcc.o.txt
|
|
|
|
objdump -t weaktest.gcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.gcc.o.txt
|
|
|
|
diff weaktest.gcc.o.txt weaktest.tcc.o.txt && echo "Weak Auto Test OK"
|
|
|
|
|
2012-12-14 20:18:03 +04:00
|
|
|
ex%: $(top_srcdir)/examples/ex%.c
|
2012-10-22 13:11:42 +04:00
|
|
|
$(CC) -o $@ $< $(CPPFLAGS) $(CFLAGS) $(LDFLAGS)
|
2009-04-18 16:31:35 +04:00
|
|
|
|
|
|
|
# tiny assembler testing
|
|
|
|
asmtest.ref: asmtest.S
|
2009-07-06 23:11:19 +04:00
|
|
|
$(CC) -Wa,-W -o asmtest.ref.o -c asmtest.S
|
|
|
|
objdump -D asmtest.ref.o > asmtest.ref
|
2009-04-18 16:31:35 +04:00
|
|
|
|
|
|
|
asmtest: asmtest.ref
|
|
|
|
@echo ------------ $@ ------------
|
|
|
|
$(TCC) -c asmtest.S
|
2009-07-06 23:11:19 +04:00
|
|
|
objdump -D asmtest.o > asmtest.out
|
2009-04-18 16:31:35 +04:00
|
|
|
@if diff -u --ignore-matching-lines="file format" asmtest.ref asmtest.out ; then echo "ASM Auto Test OK"; fi
|
|
|
|
|
|
|
|
# targets for development
|
|
|
|
%.bin: %.c tcc
|
|
|
|
$(TCC) -g -o $@ $<
|
|
|
|
$(DISAS) $@
|
|
|
|
|
|
|
|
instr: instr.o
|
|
|
|
objdump -d instr.o
|
|
|
|
|
|
|
|
instr.o: instr.S
|
|
|
|
$(CC) -o $@ -c $< -O2 -Wall -g
|
|
|
|
|
|
|
|
cache: tcc_g
|
|
|
|
cachegrind ./tcc_g -o /tmp/linpack -lm bench/linpack.c
|
|
|
|
vg_annotate tcc.c > /tmp/linpack.cache.log
|
|
|
|
|
|
|
|
# clean
|
|
|
|
clean:
|
2013-02-05 17:27:38 +04:00
|
|
|
$(MAKE) -C tests2 $@
|
|
|
|
rm -vf *~ *.o *.a *.bin *.i *.ref *.out *.out? *.out?b *.gcc *.exe \
|
|
|
|
hello libtcc_test tcctest[1234] ex? tcc_g tcclib.h
|