tinycc/tests/Makefile

163 lines
4.5 KiB
Makefile
Raw Normal View History

2009-04-18 16:31:35 +04:00
#
# Tiny C Compiler Makefile - tests
#
# what tests to run
TESTS = libtest test3
# these should work too
# TESTS += test1 test2 speedtest btest weaktest
2009-04-18 16:31:35 +04:00
# these don't work as they should
2009-07-06 23:10:14 +04:00
# TESTS += test4 asmtest
2009-04-18 16:31:35 +04:00
TOP = ..
include $(TOP)/Makefile
ifdef DISABLE_STATIC
export LD_LIBRARY_PATH:=$(CURDIR)/..
endif
2009-04-18 16:31:35 +04:00
# run local version of tcc with local libraries and includes
TCC = ../tcc -B..
2011-07-22 13:12:49 +04:00
RUN_TCC = $(NATIVE_DEFINES) -run -DONE_SOURCE ../tcc.c -B..
2009-04-18 16:31:35 +04:00
DISAS=objdump -d
all test : $(TESTS)
# make sure that tcc exists
test1 test2 test3 test4 btest speedtest asmtest weaktest : ../tcc
../%:
$(MAKE) -C .. $*
2009-04-18 16:31:35 +04:00
# libtcc test
ifdef LIBTCC1
LIBTCC1:=$(TOP)/$(LIBTCC1)
endif
libtest: libtcc_test$(EXESUF) $(LIBTCC1)
2009-04-18 16:31:35 +04:00
@echo ------------ $@ ------------
./libtcc_test$(EXESUF) lib_path=..
2009-04-18 16:31:35 +04:00
libtcc_test$(EXESUF): libtcc_test.c ../$(LIBTCC)
$(CC) -o $@ $^ -I.. $(CFLAGS) $(LIBS) $(LINK_LIBTCC)
2009-04-18 16:31:35 +04:00
# test.ref - generate using gcc
# 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
cp -u ../include/tcclib.h .
2011-03-07 22:28:31 +03:00
$(CC) -o tcctest.gcc $< -I. -w $(CFLAGS) -std=gnu99
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 ------------ $@ ------------
$(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 ------------ $@ ------------
$(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 ------------ $@ ------------
# dynamic output
$(TCC) -o tcctest1 tcctest.c
./tcctest1 > test1.out
@if diff -u test.ref test1.out ; then echo "Dynamic Auto Test OK"; fi
# 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
# 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
# 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
# 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
btest: boundtest.c ../bcheck.o
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
speedtest: ex2 ex3
2009-04-18 16:31:35 +04:00
@echo ------------ $@ ------------
time ./ex2 1238 2 3 4 10 13 4
time $(TCC) -run ../examples/ex2.c 1238 2 3 4 10 13 4
time ./ex3 35
time $(TCC) -run ../examples/ex3.c 35
weaktest: test.ref
$(TCC) -c tcctest.c -o weaktest.tcc.o
$(CC) -c tcctest.c -o weaktest.gcc.o -I. -w $(CFLAGS)
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"
2009-04-18 16:31:35 +04:00
ex%: ../examples/ex%.c
$(CC) -o $@ $< $(CFLAGS)
# tiny assembler testing
asmtest.ref: asmtest.S
$(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
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:
rm -vf *~ *.o *.a *.bin *.i *.ref *.out *.out? *.gcc \
tcctest[1234] ex? libtcc_test$(EXESUF) tcc_g tcclib.h