Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. #
  2. # Tiny C Compiler Makefile - tests
  3. #
  4.  
  5. TOP = ..
  6. include $(TOP)/Makefile
  7. SRCDIR = $(top_srcdir)/tests
  8. VPATH = $(SRCDIR) $(top_srcdir)
  9.  
  10. # clear CFLAGS and LDFLAGS
  11. CFLAGS :=
  12. LDFLAGS :=
  13.  
  14. # what tests to run
  15. TESTS = \
  16.  hello-exe \
  17.  hello-run \
  18.  libtest \
  19.  test3 \
  20.  abitest \
  21.  vla_test-run \
  22.  tests2-dir pp-dir
  23.  
  24. BTESTS = test1b test3b btest
  25.  
  26. ifdef CONFIG_CROSS
  27.  TESTS += hello-cross
  28. endif
  29.  
  30. # test4 -- problem with -static
  31. # asmtest -- minor differences with gcc
  32. # btest -- works on i386 (including win32)
  33.  
  34. # bounds-checking is supported only on i386
  35. ifneq ($(ARCH),i386)
  36.  TESTS := $(filter-out $(BTESTS),$(TESTS))
  37. endif
  38. ifdef CONFIG_WIN32
  39.  TESTS := $(filter-out $(BTESTS),$(TESTS))
  40. endif
  41. ifeq ($(TARGETOS),Darwin)
  42.  TESTS := $(filter-out hello-exe test3 $(BTESTS),$(TESTS))
  43. endif
  44. ifeq (,$(filter arm64 i386 x86-64,$(ARCH)))
  45.  TESTS := $(filter-out vla_test-run,$(TESTS))
  46. endif
  47. ifeq ($(CONFIG_arm_eabi),yes)
  48.  TESTS := $(filter-out test3,$(TESTS))
  49. endif
  50.  
  51. ifdef DISABLE_STATIC
  52.  export LD_LIBRARY_PATH:=$(CURDIR)/..
  53. endif
  54.  
  55. ifeq ($(TARGETOS),Darwin)
  56.  CFLAGS+=-Wl,-flat_namespace,-undefined,warning
  57.  export MACOSX_DEPLOYMENT_TARGET:=10.2
  58.  NATIVE_DEFINES+=-D_ANSI_SOURCE
  59. endif
  60.  
  61. # run local version of tcc with local libraries and includes
  62. TCCFLAGS = -B$(TOP) -I$(TOP) -I$(top_srcdir) -I$(top_srcdir)/include -L$(TOP)
  63. ifdef CONFIG_WIN32
  64.  TCCFLAGS = -B$(top_srcdir)/win32 -I$(top_srcdir) -I$(top_srcdir)/include -L$(TOP)
  65. endif
  66. XTCCFLAGS = -B$(TOP) -B$(top_srcdir)/win32 -I$(TOP) -I$(top_srcdir) -I$(top_srcdir)/include
  67.  
  68. TCC = $(TOP)/tcc $(TCCFLAGS)
  69. RUN_TCC = $(NATIVE_DEFINES) -DONE_SOURCE -run $(top_srcdir)/tcc.c $(TCCFLAGS)
  70.  
  71. DISAS = objdump -d
  72.  
  73. # libtcc test
  74. ifdef LIBTCC1
  75.  ifdef CONFIG_WIN32
  76.     LIBTCC1:=$(TOP)/win32/libtcc/libtcc.a
  77.  else
  78.     LIBTCC1:=$(TOP)/$(LIBTCC1)
  79.  endif
  80. endif
  81.  
  82. all test : $(TESTS)
  83.  
  84. hello-exe: ../examples/ex1.c
  85.         @echo ------------ $@ ------------
  86.         $(TCC) $< -o hello$(EXESUF) || ($(TOP)/tcc -vv; exit 1) && ./hello$(EXESUF)
  87.  
  88. hello-cross: ../examples/ex1.c
  89.         @echo ------------ $@ ------------
  90.         for XTCC in $(PROGS_CROSS) ; \
  91.                 do echo -n "Test of $$XTCC...  "; \
  92.                 out=$$($(TOP)/$$XTCC $(XTCCFLAGS) -c $< 2>&1); \
  93.                 test $$? -ne 0 && { echo "Failed\n$$out\n" ; $(TOP)/$$XTCC -vv; exit 1; } ; \
  94.                 echo "Success"; \
  95.         done
  96.  
  97. hello-run: ../examples/ex1.c
  98.         @echo ------------ $@ ------------
  99.         $(TCC) -run $<
  100.  
  101. libtest: libtcc_test$(EXESUF) $(LIBTCC1)
  102.         @echo ------------ $@ ------------
  103.         ./libtcc_test$(EXESUF) $(TCCFLAGS)
  104.  
  105. libtcc_test$(EXESUF): libtcc_test.c $(top_builddir)/$(LIBTCC)
  106.         $(CC) -o $@ $^ $(CPPFLAGS) $(CFLAGS) $(NATIVE_DEFINES) $(LIBS) $(LINK_LIBTCC) $(LDFLAGS) -I$(top_srcdir)
  107.  
  108. %-dir:
  109.         @echo ------------ $@ ------------
  110.         $(MAKE) -k -C $*
  111.  
  112. # test.ref - generate using cc
  113. test.ref: tcctest.c
  114.         $(CC) -o tcctest.cc $< -I$(top_srcdir) $(CPPFLAGS) -w $(CFLAGS) $(NATIVE_DEFINES) -std=gnu99 -O0 -fno-omit-frame-pointer $(LDFLAGS)
  115.         ./tcctest.cc > $@
  116.  
  117. # auto test
  118. test1 test1b: tcctest.c test.ref
  119.         @echo ------------ $@ ------------
  120.         $(TCC) -run $< > test.out1
  121.         @diff -u test.ref test.out1 && echo "Auto Test OK"
  122.  
  123. # iterated test2 (compile tcc then compile tcctest.c !)
  124. test2 test2b: tcctest.c test.ref
  125.         @echo ------------ $@ ------------
  126.         $(TCC) $(RUN_TCC) $(RUN_TCC) -run $< > test.out2
  127.         @diff -u test.ref test.out2 && echo "Auto Test2 OK"
  128.  
  129. # iterated test3 (compile tcc then compile tcc then compile tcctest.c !)
  130. test3 test3b: tcctest.c test.ref
  131.         @echo ------------ $@ ------------
  132.         $(TCC) $(RUN_TCC) $(RUN_TCC) $(RUN_TCC) -run $< > test.out3
  133.         @diff -u test.ref test.out3 && echo "Auto Test3 OK"
  134.  
  135. test%b : TCCFLAGS += -b
  136.  
  137. # binary output test
  138. test4: tcctest.c test.ref
  139.         @echo ------------ $@ ------------
  140. # object + link output
  141.         $(TCC) -c -o tcctest3.o $<
  142.         $(TCC) -o tcctest3 tcctest3.o
  143.         ./tcctest3 > test3.out
  144.         @if diff -u test.ref test3.out ; then echo "Object Auto Test OK"; fi
  145. # dynamic output
  146.         $(TCC) -o tcctest1 $<
  147.         ./tcctest1 > test1.out
  148.         @if diff -u test.ref test1.out ; then echo "Dynamic Auto Test OK"; fi
  149. # dynamic output + bound check
  150.         $(TCC) -b -o tcctest4 $<
  151.         ./tcctest4 > test4.out
  152.         @if diff -u test.ref test4.out ; then echo "BCheck Auto Test OK"; fi
  153. # static output
  154.         $(TCC) -static -o tcctest2 $<
  155.         ./tcctest2 > test2.out
  156.         @if diff -u test.ref test2.out ; then echo "Static Auto Test OK"; fi
  157.  
  158. # memory and bound check auto test
  159. BOUNDS_OK  = 1 4 8 10 14
  160. BOUNDS_FAIL= 2 5 7 9 11 12 13 15
  161.  
  162. btest: boundtest.c
  163.         @echo ------------ $@ ------------
  164.         @for i in $(BOUNDS_OK); do \
  165.            echo ; echo --- boundtest $$i ---; \
  166.            if $(TCC) -b -run $< $$i ; then \
  167.                echo succeeded as expected; \
  168.            else\
  169.                echo Failed positive test $$i ; exit 1 ; \
  170.            fi ;\
  171.         done ;\
  172.         for i in $(BOUNDS_FAIL); do \
  173.            echo ; echo --- boundtest $$i ---; \
  174.            if $(TCC) -b -run $< $$i ; then \
  175.                echo Failed negative test $$i ; exit 1 ;\
  176.            else\
  177.                echo failed as expected; \
  178.            fi ;\
  179.         done ;\
  180.         echo; echo Bound test OK
  181.  
  182. # speed test
  183. speedtest: ex2 ex3
  184.         @echo ------------ $@ ------------
  185.         time ./ex2 1238 2 3 4 10 13 4
  186.         time $(TCC) -run $(top_srcdir)/examples/ex2.c 1238 2 3 4 10 13 4
  187.         time ./ex3 35
  188.         time $(TCC) -run $(top_srcdir)/examples/ex3.c 35
  189.  
  190. weaktest: tcctest.c test.ref
  191.         $(TCC) -c $< -o weaktest.tcc.o $(CPPFLAGS) $(CFLAGS)
  192.          $(CC) -c $< -o weaktest.cc.o -I. $(CPPFLAGS) -w $(CFLAGS)
  193.         objdump -t weaktest.tcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.tcc.o.txt
  194.         objdump -t weaktest.cc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.cc.o.txt
  195.         diff weaktest.cc.o.txt weaktest.tcc.o.txt && echo "Weak Auto Test OK"
  196.  
  197. ex%: $(top_srcdir)/examples/ex%.c
  198.         $(CC) -o $@ $< $(CPPFLAGS) $(CFLAGS) $(LDFLAGS)
  199.  
  200. # tiny assembler testing
  201. asmtest.ref: asmtest.S
  202.         $(CC) -m32 -Wa,-W -o asmtest.ref.o -c asmtest.S
  203.         objdump -D asmtest.ref.o > asmtest.ref
  204.  
  205. asmtest: asmtest.ref
  206.         @echo ------------ $@ ------------
  207.         $(TCC) -c asmtest.S
  208.         objdump -D asmtest.o > asmtest.out
  209.         @if diff -u --ignore-matching-lines="file format" asmtest.ref asmtest.out ; then echo "ASM Auto Test OK"; fi
  210.  
  211. # Check that code generated by libtcc is binary compatible with
  212. # that generated by CC
  213. abitest-cc$(EXESUF): abitest.c $(top_builddir)/$(LIBTCC)
  214.         $(CC) -o $@ $^ $(CPPFLAGS) $(CFLAGS) $(NATIVE_DEFINES) $(LIBS) $(LINK_LIBTCC) $(LDFLAGS) -I$(top_srcdir)
  215.  
  216. abitest-tcc$(EXESUF): abitest.c libtcc.c
  217.         $(TCC) -o $@ $^ $(CPPFLAGS) $(CFLAGS) $(NATIVE_DEFINES) -DONE_SOURCE $(LIBS) $(LDFLAGS) -I$(top_srcdir)
  218.  
  219. ABITESTS := abitest-cc$(EXESUF)
  220. ifneq ($(CONFIG_arm_eabi),yes) # not ARM soft-float
  221.         ABITESTS += abitest-tcc$(EXESUF)
  222. endif
  223.  
  224. abitest: $(ABITESTS)
  225.         @echo ------------ $@ ------------
  226.         ./abitest-cc$(EXESUF) $(TCCFLAGS)
  227.         if [ "$(CONFIG_arm_eabi)" != "yes" ]; then ./abitest-tcc$(EXESUF) $(TCCFLAGS); fi
  228.  
  229. vla_test$(EXESUF): vla_test.c
  230.         $(TCC) -o $@ $^ $(CPPFLAGS) $(CFLAGS)
  231. vla_test-run: vla_test$(EXESUF)
  232.         @echo ------------ $@ ------------
  233.         ./vla_test$(EXESUF)
  234.  
  235. # targets for development
  236. %.bin: %.c tcc
  237.         $(TCC) -g -o $@ $<
  238.         $(DISAS) $@
  239.  
  240. instr: instr.o
  241.         objdump -d instr.o
  242.  
  243. instr.o: instr.S
  244.         $(CC) -o $@ -c $< -O2 -Wall -g
  245.  
  246. cache: tcc_g
  247.         cachegrind ./tcc_g -o /tmp/linpack -lm bench/linpack.c
  248.         vg_annotate tcc.c > /tmp/linpack.cache.log
  249.  
  250. # clean
  251. clean:
  252.         $(MAKE) -C tests2 $@
  253.         rm -vf *~ *.o *.a *.bin *.i *.ref *.out *.out? *.out?b *.cc \
  254.                 *-cc *-tcc *.exe \
  255.                 hello libtcc_test vla_test tcctest[1234] ex? tcc_g
  256.