tests: - add "hello" to test first basic compilation to file/memory - add "more" test (tests2 suite) - remove some tests tests2: - move into tests dir - Convert some files from DOS to unix LF - remove 2>&1 redirection win32: - tccrun.c: modify exception filter to exit correctly (needed for btest) - tcctest.c: exclude weak_test() (feature does not exist on win32)
Unified · Split
| @@ -350,12 +350,10 @@ tcc-doc.info: tcc-doc.texi · 349 unmodified lines | |||
| 350 | export LIBTCC1 | 350 | export LIBTCC1 |
| 351 | 351 | ||
| 352 | %est: | 352 | %est: |
| 353 | $(MAKE) -C tests2 $@ | ||
| 354 | $(MAKE) -C tests $@ | 353 | $(MAKE) -C tests $@ |
| 355 | 354 | ||
| 356 | clean: | 355 | clean: |
| 357 | rm -vf $(PROGS) tcc_p$(EXESUF) tcc.pod *~ *.o *.a *.so* *.out *.exe libtcc_test$(EXESUF) | 356 | rm -vf $(PROGS) tcc_p$(EXESUF) tcc.pod *~ *.o *.a *.so* *.out *.exe libtcc_test$(EXESUF) |
| 358 | $(MAKE) -C tests2 $@ | ||
| 359 | $(MAKE) -C tests $@ | 357 | $(MAKE) -C tests $@ |
| 360 | ifneq ($(LIBTCC1),) | 358 | ifneq ($(LIBTCC1),) |
| 361 | $(MAKE) -C lib $@ | 359 | $(MAKE) -C lib $@ |
| @@ -500,7 +500,7 @@ echo "SRC_PATH=$source_path" >>config.mak · 499 unmodified lines | |||
| 500 | 500 | ||
| 501 | # build tree in object directory if source path is different from current one | 501 | # build tree in object directory if source path is different from current one |
| 502 | if test "$source_path_used" = "yes" ; then | 502 | if test "$source_path_used" = "yes" ; then |
| 503 | FILES="Makefile lib/Makefile tests/Makefile tests2/Makefile" | 503 | FILES="Makefile lib/Makefile tests/Makefile tests/tests2/Makefile" |
| 504 | for f in $FILES ; do | 504 | for f in $FILES ; do |
| 505 | dir=`fn_dirname "$f"` | 505 | dir=`fn_dirname "$f"` |
| 506 | test -d "$dir" || mkdir -p "$dir" | 506 | test -d "$dir" || mkdir -p "$dir" |
| @@ -615,8 +615,7 @@ static long __stdcall cpu_exception_handler(EXCEPTION_POINTERS *ex_info) · 614 unmodified lines | |||
| 615 | rt_error(uc, "exception caught"); | 615 | rt_error(uc, "exception caught"); |
| 616 | break; | 616 | break; |
| 617 | } | 617 | } |
| 618 | exit(-1); | 618 | return EXCEPTION_EXECUTE_HANDLER; |
| 619 | return EXCEPTION_CONTINUE_SEARCH; | ||
| 620 | } | 619 | } |
| 621 | 620 | ||
| 622 | /* Generate a stack backtrace when a CPU exception occurs. */ | 621 | /* Generate a stack backtrace when a CPU exception occurs. */ |
| @@ -7,73 +7,61 @@ include $(TOP)/Makefile · 6 unmodified lines | |||
| 7 | VPATH = $(top_srcdir)/tests | 7 | VPATH = $(top_srcdir)/tests |
| 8 | 8 | ||
| 9 | # what tests to run | 9 | # what tests to run |
| 10 | TESTS = libtest \ | 10 | TESTS = \ |
| 11 | test1 \ | 11 | hello \ |
| 12 | test2 \ | 12 | libtest \ |
| 13 | test3 \ | 13 | test3 \ |
| 14 | speedtest \ | 14 | moretests |
| 15 | btest \ | 15 | |
| 16 | test1b\ | 16 | # test4 -- problem with -static |
| 17 | test2b\ | 17 | # asmtest -- minor differences with gcc |
| 18 | test3b\ | 18 | # btest -- works on i386 (including win32) |
| 19 | weaktest | 19 | # test3 -- win32 does not know how to printf long doubles |
| 20 | |||
| 21 | # test4 # this test does not seem to work on any platform | ||
| 22 | # asmtest # this test does not seem to work on any platform | ||
| 23 | 20 | ||
| 24 | # bounds-checking is supported only on i386 | 21 | # bounds-checking is supported only on i386 |
| 25 | ifneq ($(ARCH),i386) | 22 | ifneq ($(ARCH),i386) |
| 26 | TESTS := $(filter-out btest,$(TESTS)) | 23 | TESTS := $(filter-out btest,$(TESTS)) |
| 27 | TESTS := $(filter-out test1b,$(TESTS)) | ||
| 28 | TESTS := $(filter-out test2b,$(TESTS)) | ||
| 29 | TESTS := $(filter-out test3b,$(TESTS)) | ||
| 30 | endif | 24 | endif |
| 31 | 25 | ifdef CONFIG_WIN32 | |
| 32 | # these should work too | 26 | TESTS := $(filter-out test3,$(TESTS)) |
| 33 | # TESTS += test1 test2 speedtest btest weaktest | ||
| 34 | |||
| 35 | # some tests do not pass on all platforms, remove them for now | ||
| 36 | ifeq ($(TARGETOS),Linux) | ||
| 37 | TESTS := $(filter-out weaktest,$(TESTS)) | ||
| 38 | endif | 27 | endif |
| 39 | ifeq ($(TARGETOS),Darwin) | 28 | ifeq ($(TARGETOS),Darwin) |
| 40 | TESTS := $(filter-out test1,$(TESTS)) | 29 | TESTS := $(filter-out test3 btest,$(TESTS)) |
| 41 | TESTS := $(filter-out test2,$(TESTS)) | ||
| 42 | TESTS := $(filter-out test3,$(TESTS)) | ||
| 43 | TESTS := $(filter-out btest,$(TESTS)) | ||
| 44 | TESTS := $(filter-out weaktest,$(TESTS)) | ||
| 45 | endif | 30 | endif |
| 46 | 31 | ||
| 47 | ifdef DISABLE_STATIC | 32 | ifdef DISABLE_STATIC |
| 48 | export LD_LIBRARY_PATH:=$(CURDIR)/.. | 33 | export LD_LIBRARY_PATH:=$(CURDIR)/.. |
| 49 | endif | 34 | endif |
| 50 | 35 | ||
| 51 | ifeq ($(TARGETOS),Darwin) | 36 | ifeq ($(TARGETOS),Darwin) |
| 52 | CFLAGS+=-Wl,-flat_namespace,-undefined,warning | 37 | CFLAGS+=-Wl,-flat_namespace,-undefined,warning |
| 53 | export MACOSX_DEPLOYMENT_TARGET:=10.2 | 38 | export MACOSX_DEPLOYMENT_TARGET:=10.2 |
| 54 | NATIVE_DEFINES+=-D_ANSI_SOURCE | 39 | NATIVE_DEFINES+=-D_ANSI_SOURCE |
| 55 | endif | 40 | endif |
| 56 | 41 | ||
| 57 | # run local version of tcc with local libraries and includes | 42 | # run local version of tcc with local libraries and includes |
| 58 | TCC = ../tcc -B.. $(NATIVE_DEFINES) | 43 | TCCFLAGS = -B$(TOP) |
| 59 | ifdef CONFIG_WIN32 | 44 | ifdef CONFIG_WIN32 |
| 60 | TCC := $(TCC) -I $(top_srcdir)/win32/include -L$(top_build) | 45 | TCCFLAGS = -B$(top_srcdir)/win32 -I$(top_srcdir)/include -L$(TOP) |
| 61 | endif | 46 | endif |
| 62 | RUN_TCC = $(NATIVE_DEFINES) -run -DONE_SOURCE ../tcc.c -B.. | ||
| 63 | DISAS=objdump -d | ||
| 64 | 47 | ||
| 65 | all test : $(TESTS) | 48 | TCC = $(TOP)/tcc $(TCCFLAGS) |
| 49 | RUN_TCC = $(NATIVE_DEFINES) -DONE_SOURCE -run $(TOP)/tcc.c $(TCCFLAGS) | ||
| 66 | 50 | ||
| 67 | # make sure that tcc exists | 51 | DISAS = objdump -d |
| 68 | test1 test2 test3 test4 btest speedtest asmtest weaktest : ../tcc | ||
| 69 | ../%: | ||
| 70 | $(MAKE) -C .. $* | ||
| 71 | 52 | ||
| 72 | # libtcc test | 53 | # libtcc test |
| 73 | ifdef LIBTCC1 | 54 | ifdef LIBTCC1 |
| 74 | LIBTCC1:=$(TOP)/$(LIBTCC1) | 55 | LIBTCC1:=$(TOP)/$(LIBTCC1) |
| 75 | endif | 56 | endif |
| 76 | 57 | ||
| 58 | all test : $(TESTS) | ||
| 59 | |||
| 60 | hello: ../examples/ex1.c | ||
| 61 | @echo ------------ $@ ------------ | ||
| 62 | $(TCC) $< -o $@$(EXESUF) && ./$@$(EXESUF) | ||
| 63 | $(TCC) -run $< | ||
| 64 | |||
| 77 | libtest: libtcc_test$(EXESUF) $(LIBTCC1) | 65 | libtest: libtcc_test$(EXESUF) $(LIBTCC1) |
| 78 | @echo ------------ $@ ------------ | 66 | @echo ------------ $@ ------------ |
| 79 | ./libtcc_test$(EXESUF) lib_path=.. | 67 | ./libtcc_test$(EXESUF) lib_path=.. |
| @@ -81,6 +69,10 @@ libtest: libtcc_test$(EXESUF) $(LIBTCC1) · 1 unmodified line | |||
| 81 | libtcc_test$(EXESUF): libtcc_test.c $(top_builddir)/$(LIBTCC) | 69 | libtcc_test$(EXESUF): libtcc_test.c $(top_builddir)/$(LIBTCC) |
| 82 | $(CC) -o $@ $^ $(CPPFLAGS) $(CFLAGS) $(NATIVE_DEFINES) $(LIBS) $(LINK_LIBTCC) $(LDFLAGS) | 70 | $(CC) -o $@ $^ $(CPPFLAGS) $(CFLAGS) $(NATIVE_DEFINES) $(LIBS) $(LINK_LIBTCC) $(LDFLAGS) |
| 83 | 71 | ||
| 72 | moretests: | ||
| 73 | @echo ------------ $@ ------------ | ||
| 74 | $(MAKE) -C tests2 | ||
| 75 | |||
| 84 | # test.ref - generate using gcc | 76 | # test.ref - generate using gcc |
| 85 | # copy only tcclib.h so GCC's stddef and stdarg will be used | 77 | # copy only tcclib.h so GCC's stddef and stdarg will be used |
| 86 | test.ref: tcctest.c | 78 | test.ref: tcctest.c |
| @@ -94,59 +86,44 @@ test1: test.ref · 7 unmodified lines | |||
| 94 | $(TCC) -run tcctest.c > test.out1 | 86 | $(TCC) -run tcctest.c > test.out1 |
| 95 | @if diff -u test.ref test.out1 ; then echo "Auto Test OK"; fi | 87 | @if diff -u test.ref test.out1 ; then echo "Auto Test OK"; fi |
| 96 | 88 | ||
| 97 | test1b: test.ref | ||
| 98 | @echo ------------ $@ ------------ | ||
| 99 | $(TCC) -b -run tcctest.c > test.out1b | ||
| 100 | @if diff -u test.ref test.out1b ; then echo "Auto Test OK"; fi | ||
| 101 | |||
| 102 | # iterated test2 (compile tcc then compile tcctest.c !) | 89 | # iterated test2 (compile tcc then compile tcctest.c !) |
| 103 | test2: test.ref | 90 | test2: test.ref |
| 104 | @echo ------------ $@ ------------ | 91 | @echo ------------ $@ ------------ |
| 105 | $(TCC) $(RUN_TCC) $(RUN_TCC) -run tcctest.c > test.out2 | 92 | $(TCC) $(RUN_TCC) $(RUN_TCC) -run tcctest.c > test.out2 |
| 106 | @if diff -u test.ref test.out2 ; then echo "Auto Test2 OK"; fi | 93 | @if diff -u test.ref test.out2 ; then echo "Auto Test2 OK"; fi |
| 107 | 94 | ||
| 108 | test2b: test.ref ../bcheck.o | ||
| 109 | @echo ------------ $@ ------------ | ||
| 110 | $(TCC) -b $(RUN_TCC) $(RUN_TCC) -run tcctest.c > test.out2b | ||
| 111 | @if diff -u test.ref test.out2b ; then echo "Auto Test2b OK"; fi | ||
| 112 | |||
| 113 | # iterated test3 (compile tcc then compile tcc then compile tcctest.c !) | 95 | # iterated test3 (compile tcc then compile tcc then compile tcctest.c !) |
| 114 | test3: test.ref | 96 | test3: test.ref |
| 115 | @echo ------------ $@ ------------ | 97 | @echo ------------ $@ ------------ |
| 116 | $(TCC) $(RUN_TCC) $(RUN_TCC) $(RUN_TCC) -run tcctest.c > test.out3 | 98 | $(TCC) $(RUN_TCC) $(RUN_TCC) $(RUN_TCC) -run tcctest.c > test.out3 |
| 117 | @if diff -u test.ref test.out3 ; then echo "Auto Test3 OK"; fi | 99 | @if diff -u test.ref test.out3 ; then echo "Auto Test3 OK"; fi |
| 118 | 100 | ||
| 119 | test3b: test.ref | ||
| 120 | @echo ------------ $@ ------------ | ||
| 121 | $(TCC) -b $(RUN_TCC) $(RUN_TCC) $(RUN_TCC) -run tcctest.c > test.out3b | ||
| 122 | @if diff -u test.ref test.out3b ; then echo "Auto Test3 OK"; fi | ||
| 123 | |||
| 124 | # binary output test | 101 | # binary output test |
| 125 | test4: test.ref | 102 | test4: test.ref |
| 126 | @echo ------------ $@ ------------ | 103 | @echo ------------ $@ ------------ |
| 127 | # dynamic output | ||
| 128 | $(TCC) -o tcctest1 tcctest.c | ||
| 129 | ./tcctest1 > test1.out | ||
| 130 | @if diff -u test.ref test1.out ; then echo "Dynamic Auto Test OK"; fi | ||
| 131 | # object + link output | 104 | # object + link output |
| 132 | $(TCC) -c -o tcctest3.o tcctest.c | 105 | $(TCC) -c -o tcctest3.o tcctest.c |
| 133 | $(TCC) -o tcctest3 tcctest3.o | 106 | $(TCC) -o tcctest3 tcctest3.o |
| 134 | ./tcctest3 > test3.out | 107 | ./tcctest3 > test3.out |
| 135 | @if diff -u test.ref test3.out ; then echo "Object Auto Test OK"; fi | 108 | @if diff -u test.ref test3.out ; then echo "Object Auto Test OK"; fi |
| 136 | # static output | 109 | # dynamic output |
| 137 | $(TCC) -static -o tcctest2 tcctest.c | 110 | $(TCC) -o tcctest1 tcctest.c |
| 138 | ./tcctest2 > test2.out | 111 | ./tcctest1 > test1.out |
| 139 | @if diff -u test.ref test2.out ; then echo "Static Auto Test OK"; fi | 112 | @if diff -u test.ref test1.out ; then echo "Dynamic Auto Test OK"; fi |
| 140 | # dynamic output + bound check | 113 | # dynamic output + bound check |
| 141 | $(TCC) -b -o tcctest4 tcctest.c | 114 | $(TCC) -b -o tcctest4 tcctest.c |
| 142 | ./tcctest4 > test4.out | 115 | ./tcctest4 > test4.out |
| 143 | @if diff -u test.ref test4.out ; then echo "BCheck Auto Test OK"; fi | 116 | @if diff -u test.ref test4.out ; then echo "BCheck Auto Test OK"; fi |
| 117 | # static output | ||
| 118 | $(TCC) -static -o tcctest2 tcctest.c | ||
| 119 | ./tcctest2 > test2.out | ||
| 120 | @if diff -u test.ref test2.out ; then echo "Static Auto Test OK"; fi | ||
| 144 | 121 | ||
| 145 | # memory and bound check auto test | 122 | # memory and bound check auto test |
| 146 | BOUNDS_OK = 1 4 8 10 14 | 123 | BOUNDS_OK = 1 4 8 10 14 |
| 147 | BOUNDS_FAIL= 2 5 7 9 11 12 13 15 | 124 | BOUNDS_FAIL= 2 5 7 9 11 12 13 15 |
| 148 | 125 | ||
| 149 | btest: boundtest.c ../bcheck.o | 126 | btest: boundtest.c |
| 150 | @echo ------------ $@ ------------ | 127 | @echo ------------ $@ ------------ |
| 151 | @for i in $(BOUNDS_OK); do \ | 128 | @for i in $(BOUNDS_OK); do \ |
| 152 | echo ; echo --- boundtest $$i ---; \ | 129 | echo ; echo --- boundtest $$i ---; \ |
| @@ -212,5 +189,6 @@ cache: tcc_g · 59 unmodified lines | |||
| 212 | 189 | ||
| 213 | # clean | 190 | # clean |
| 214 | clean: | 191 | clean: |
| 215 | rm -vf *~ *.o *.a *.bin *.i *.ref *.out *.out? *.out?b *.gcc \ | 192 | $(MAKE) -C tests2 $@ |
| 216 | tcctest[1234] ex? libtcc_test$(EXESUF) tcc_g tcclib.h | 193 | rm -vf *~ *.o *.a *.bin *.i *.ref *.out *.out? *.out?b *.gcc *.exe \ |
| 194 | hello libtcc_test tcctest[1234] ex? tcc_g tcclib.h | ||
| @@ -594,7 +594,9 @@ int main(int argc, char **argv) · 593 unmodified lines | |||
| 594 | local_label_test(); | 594 | local_label_test(); |
| 595 | asm_test(); | 595 | asm_test(); |
| 596 | builtin_test(); | 596 | builtin_test(); |
| 597 | #ifndef _WIN32 | ||
| 597 | weak_test(); | 598 | weak_test(); |
| 599 | #endif | ||
| 598 | global_data_test(); | 600 | global_data_test(); |
| 599 | cmp_comparison_test(); | 601 | cmp_comparison_test(); |
| 600 | math_cmp_test(); | 602 | math_cmp_test(); |
| @@ -2464,7 +2466,7 @@ void builtin_test(void) · 1863 unmodified lines | |||
| 2464 | printf("res = %d\n", __builtin_constant_p(constant_p_var)); | 2466 | printf("res = %d\n", __builtin_constant_p(constant_p_var)); |
| 2465 | } | 2467 | } |
| 2466 | 2468 | ||
| 2467 | 2469 | #ifndef _WIN32 | |
| 2468 | extern int __attribute__((weak)) weak_f1(void); | 2470 | extern int __attribute__((weak)) weak_f1(void); |
| 2469 | extern int __attribute__((weak)) weak_f2(void); | 2471 | extern int __attribute__((weak)) weak_f2(void); |
| 2470 | extern int weak_f3(void); | 2472 | extern int weak_f3(void); |
| @@ -2520,6 +2522,7 @@ int __attribute__((weak)) weak_f2() { return 222; } · 49 unmodified lines | |||
| 2520 | int __attribute__((weak)) weak_f3() { return 333; } | 2522 | int __attribute__((weak)) weak_f3() { return 333; } |
| 2521 | int __attribute__((weak)) weak_v2 = 222; | 2523 | int __attribute__((weak)) weak_v2 = 222; |
| 2522 | int __attribute__((weak)) weak_v3 = 333; | 2524 | int __attribute__((weak)) weak_v3 = 333; |
| 2525 | #endif | ||
| 2523 | 2526 | ||
| 2524 | void const_func(const int a) | 2527 | void const_func(const int a) |
| 2525 | { | 2528 | { |
| @@ -1,18 +1,18 @@ | |||
| 1 | 0 0 0 | 1 | 0 0 0 |
| 2 | 0 0 1 | 2 | 0 0 1 |
| 3 | 0 0 2 | 3 | 0 0 2 |
| 4 | 0 1 0 | 4 | 0 1 0 |
| 5 | 0 1 1 | 5 | 0 1 1 |
| 6 | 0 1 2 | 6 | 0 1 2 |
| 7 | 0 2 0 | 7 | 0 2 0 |
| 8 | 0 2 1 | 8 | 0 2 1 |
| 9 | 0 2 2 | 9 | 0 2 2 |
| 10 | 1 0 0 | 10 | 1 0 0 |
| 11 | 1 0 1 | 11 | 1 0 1 |
| 12 | 1 0 2 | 12 | 1 0 2 |
| 13 | 1 1 0 | 13 | 1 1 0 |
| 14 | 1 1 1 | 14 | 1 1 1 |
| 15 | 1 1 2 | 15 | 1 1 2 |
| 16 | 1 2 0 | 16 | 1 2 0 |
| 17 | 1 2 1 | 17 | 1 2 1 |
| 18 | 1 2 2 | 18 | 1 2 2 |
| @@ -1,3 +1,3 @@ | |||
| 1 | 0 1 2 3 54 73 74 75 | 1 | 0 1 2 3 54 73 74 75 |
| 2 | 12 | 2 | 12 |
| 3 | 54 | 3 | 54 |
| @@ -1,3 +1,3 @@ | |||
| 1 | including | 1 | including |
| 2 | included | 2 | included |
| 3 | done | 3 | done |
| @@ -1 +1 @@ | |||
| 1 | printf("included\n"); | 1 | printf("included\n"); |
| @@ -1,17 +1,17 @@ | |||
| 1 | #include <stdio.h> | 1 | #include <stdio.h> |
| 2 | 2 | ||
| 3 | int main() | 3 | int main() |
| 4 | { | 4 | { |
| 5 | int a; | 5 | int a; |
| 6 | 6 | ||
| 7 | for (a = 0; a < 2; a++) | 7 | for (a = 0; a < 2; a++) |
| 8 | { | 8 | { |
| 9 | int b = a; | 9 | int b = a; |
| 10 | } | 10 | } |
| 11 | 11 | ||
| 12 | printf("it's all good\n"); | 12 | printf("it's all good\n"); |
| 13 | 13 | ||
| 14 | return 0; | 14 | return 0; |
| 15 | } | 15 | } |
| 16 | 16 | ||
| 17 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ | 17 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ |
| @@ -1,18 +1,18 @@ | |||
| 1 | #include <stdio.h> | 1 | #include <stdio.h> |
| 2 | 2 | ||
| 3 | int main() | 3 | int main() |
| 4 | { | 4 | { |
| 5 | int Count = 0; | 5 | int Count = 0; |
| 6 | 6 | ||
| 7 | for (;;) | 7 | for (;;) |
| 8 | { | 8 | { |
| 9 | Count++; | 9 | Count++; |
| 10 | printf("%d\n", Count); | 10 | printf("%d\n", Count); |
| 11 | if (Count >= 10) | 11 | if (Count >= 10) |
| 12 | break; | 12 | break; |
| 13 | } | 13 | } |
| 14 | 14 | ||
| 15 | return 0; | 15 | return 0; |
| 16 | } | 16 | } |
| 17 | 17 | ||
| 18 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ | 18 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ |
| @@ -1,29 +1,29 @@ | |||
| 1 | #include <stdio.h> | 1 | #include <stdio.h> |
| 2 | 2 | ||
| 3 | int fred() | 3 | int fred() |
| 4 | { | 4 | { |
| 5 | printf("fred\n"); | 5 | printf("fred\n"); |
| 6 | return 0; | 6 | return 0; |
| 7 | } | 7 | } |
| 8 | 8 | ||
| 9 | int joe() | 9 | int joe() |
| 10 | { | 10 | { |
| 11 | printf("joe\n"); | 11 | printf("joe\n"); |
| 12 | return 1; | 12 | return 1; |
| 13 | } | 13 | } |
| 14 | 14 | ||
| 15 | int main() | 15 | int main() |
| 16 | { | 16 | { |
| 17 | printf("%d\n", fred() && joe()); | 17 | printf("%d\n", fred() && joe()); |
| 18 | printf("%d\n", fred() || joe()); | 18 | printf("%d\n", fred() || joe()); |
| 19 | printf("%d\n", joe() && fred()); | 19 | printf("%d\n", joe() && fred()); |
| 20 | printf("%d\n", joe() || fred()); | 20 | printf("%d\n", joe() || fred()); |
| 21 | printf("%d\n", fred() && (1 + joe())); | 21 | printf("%d\n", fred() && (1 + joe())); |
| 22 | printf("%d\n", fred() || (0 + joe())); | 22 | printf("%d\n", fred() || (0 + joe())); |
| 23 | printf("%d\n", joe() && (0 + fred())); | 23 | printf("%d\n", joe() && (0 + fred())); |
| 24 | printf("%d\n", joe() || (1 + fred())); | 24 | printf("%d\n", joe() || (1 + fred())); |
| 25 | 25 | ||
| 26 | return 0; | 26 | return 0; |
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ | 29 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ |
| @@ -1,56 +1,56 @@ | |||
| 1 | #include <stdio.h> | 1 | #include <stdio.h> |
| 2 | 2 | ||
| 3 | void fred() | 3 | void fred() |
| 4 | { | 4 | { |
| 5 | printf("In fred()\n"); | 5 | printf("In fred()\n"); |
| 6 | goto done; | 6 | goto done; |
| 7 | printf("In middle\n"); | 7 | printf("In middle\n"); |
| 8 | done: | 8 | done: |
| 9 | printf("At end\n"); | 9 | printf("At end\n"); |
| 10 | } | 10 | } |
| 11 | 11 | ||
| 12 | void joe() | 12 | void joe() |
| 13 | { | 13 | { |
| 14 | int b = 5678; | 14 | int b = 5678; |
| 15 | 15 | ||
| 16 | printf("In joe()\n"); | 16 | printf("In joe()\n"); |
| 17 | 17 | ||
| 18 | { | 18 | { |
| 19 | int c = 1234; | 19 | int c = 1234; |
| 20 | printf("c = %d\n", c); | 20 | printf("c = %d\n", c); |
| 21 | goto outer; | 21 | goto outer; |
| 22 | printf("uh-oh\n"); | 22 | printf("uh-oh\n"); |
| 23 | } | 23 | } |
| 24 | 24 | ||
| 25 | outer: | 25 | outer: |
| 26 | 26 | ||
| 27 | printf("done\n"); | 27 | printf("done\n"); |
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | void henry() | 30 | void henry() |
| 31 | { | 31 | { |
| 32 | int a; | 32 | int a; |
| 33 | 33 | ||
| 34 | printf("In henry()\n"); | 34 | printf("In henry()\n"); |
| 35 | goto inner; | 35 | goto inner; |
| 36 | 36 | ||
| 37 | { | 37 | { |
| 38 | int b; | 38 | int b; |
| 39 | inner: | 39 | inner: |
| 40 | b = 1234; | 40 | b = 1234; |
| 41 | printf("b = %d\n", b); | 41 | printf("b = %d\n", b); |
| 42 | } | 42 | } |
| 43 | 43 | ||
| 44 | printf("done\n"); | 44 | printf("done\n"); |
| 45 | } | 45 | } |
| 46 | 46 | ||
| 47 | int main() | 47 | int main() |
| 48 | { | 48 | { |
| 49 | fred(); | 49 | fred(); |
| 50 | joe(); | 50 | joe(); |
| 51 | henry(); | 51 | henry(); |
| 52 | 52 | ||
| 53 | return 0; | 53 | return 0; |
| 54 | } | 54 | } |
| 55 | 55 | ||
| 56 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ | 56 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ |
| @@ -1,103 +1,98 @@ | |||
| 1 | TOP = .. | 1 | TOP = ../.. |
| 2 | include $(TOP)/Makefile | 2 | include $(TOP)/Makefile |
| 3 | VPATH = $(top_srcdir)/tests2 | 3 | VPATH = $(top_srcdir)/tests/tests2 |
| 4 | 4 | ||
| 5 | ifeq ($(TARGETOS),Darwin) | 5 | TCCFLAGS = -B$(TOP) |
| 6 | CFLAGS+=-Wl,-flat_namespace,-undefined,warning | 6 | ifdef CONFIG_WIN32 |
| 7 | TCCFLAGS=-D_ANSI_SOURCE | 7 | TCCFLAGS = -B$(top_srcdir)/win32 -I$(top_srcdir)/include -L$(TOP) |
| 8 | export MACOSX_DEPLOYMENT_TARGET:=10.2 | ||
| 9 | endif | 8 | endif |
| 10 | 9 | ||
| 11 | ifdef CONFIG_WIN32 | 10 | ifeq ($(TARGETOS),Darwin) |
| 12 | TCCFLAGS=-I $(TOP)/win32/include -L$(TOP) | 11 | CFLAGS += -Wl,-flat_namespace,-undefined,warning |
| 12 | TCCFLAGS += -D_ANSI_SOURCE | ||
| 13 | export MACOSX_DEPLOYMENT_TARGET:=10.2 | ||
| 13 | endif | 14 | endif |
| 14 | 15 | ||
| 15 | TESTS= 00_assignment.test \ | 16 | TCC_RUN = $(TOP)/tcc $(TCCFLAGS) -run |
| 16 | 01_comment.test \ | ||
| 17 | 02_printf.test \ | ||
| 18 | 03_struct.test \ | ||
| 19 | 04_for.test \ | ||
| 20 | 05_array.test \ | ||
| 21 | 06_case.test \ | ||
| 22 | 07_function.test \ | ||
| 23 | 08_while.test \ | ||
| 24 | 09_do_while.test \ | ||
| 25 | 10_pointer.test \ | ||
| 26 | 11_precedence.test \ | ||
| 27 | 12_hashdefine.test \ | ||
| 28 | 13_integer_literals.test \ | ||
| 29 | 14_if.test \ | ||
| 30 | 15_recursion.test \ | ||
| 31 | 16_nesting.test \ | ||
| 32 | 17_enum.test \ | ||
| 33 | 18_include.test \ | ||
| 34 | 19_pointer_arithmetic.test \ | ||
| 35 | 20_pointer_comparison.test \ | ||
| 36 | 21_char_array.test \ | ||
| 37 | 22_floating_point.test \ | ||
| 38 | 23_type_coercion.test \ | ||
| 39 | 24_math_library.test \ | ||
| 40 | 25_quicksort.test \ | ||
| 41 | 26_character_constants.test \ | ||
| 42 | 27_sizeof.test \ | ||
| 43 | 28_strings.test \ | ||
| 44 | 29_array_address.test \ | ||
| 45 | 31_args.test \ | ||
| 46 | 32_led.test \ | ||
| 47 | 33_ternary_op.test \ | ||
| 48 | 35_sizeof.test \ | ||
| 49 | 36_array_initialisers.test \ | ||
| 50 | 37_sprintf.test \ | ||
| 51 | 38_multiple_array_index.test \ | ||
| 52 | 39_typedef.test \ | ||
| 53 | 40_stdio.test \ | ||
| 54 | 41_hashif.test \ | ||
| 55 | 42_function_pointer.test \ | ||
| 56 | 43_void_param.test \ | ||
| 57 | 44_scoped_declarations.test \ | ||
| 58 | 45_empty_for.test \ | ||
| 59 | 47_switch_return.test \ | ||
| 60 | 48_nested_break.test \ | ||
| 61 | 49_bracket_evaluation.test \ | ||
| 62 | 50_logical_second_arg.test \ | ||
| 63 | 51_static.test \ | ||
| 64 | 52_unnamed_enum.test \ | ||
| 65 | 54_goto.test \ | ||
| 66 | 55_lshift_type.test | ||
| 67 | 17 | ||
| 68 | # 30_hanoi.test \ # seg fault in the code, gcc as well | 18 | TESTS = \ |
| 69 | # 34_array_assignment.test \ # array assignment is not in C standard | 19 | 00_assignment.test \ |
| 70 | # 46_grep.test \ # does not compile even with gcc | 20 | 01_comment.test \ |
| 21 | 02_printf.test \ | ||
| 22 | 03_struct.test \ | ||
| 23 | 04_for.test \ | ||
| 24 | 05_array.test \ | ||
| 25 | 06_case.test \ | ||
| 26 | 07_function.test \ | ||
| 27 | 08_while.test \ | ||
| 28 | 09_do_while.test \ | ||
| 29 | 10_pointer.test \ | ||
| 30 | 11_precedence.test \ | ||
| 31 | 12_hashdefine.test \ | ||
| 32 | 13_integer_literals.test \ | ||
| 33 | 14_if.test \ | ||
| 34 | 15_recursion.test \ | ||
| 35 | 16_nesting.test \ | ||
| 36 | 17_enum.test \ | ||
| 37 | 18_include.test \ | ||
| 38 | 19_pointer_arithmetic.test \ | ||
| 39 | 20_pointer_comparison.test \ | ||
| 40 | 21_char_array.test \ | ||
| 41 | 22_floating_point.test \ | ||
| 42 | 23_type_coercion.test \ | ||
| 43 | 24_math_library.test \ | ||
| 44 | 25_quicksort.test \ | ||
| 45 | 26_character_constants.test \ | ||
| 46 | 27_sizeof.test \ | ||
| 47 | 28_strings.test \ | ||
| 48 | 29_array_address.test \ | ||
| 49 | 31_args.test \ | ||
| 50 | 32_led.test \ | ||
| 51 | 33_ternary_op.test \ | ||
| 52 | 35_sizeof.test \ | ||
| 53 | 36_array_initialisers.test \ | ||
| 54 | 37_sprintf.test \ | ||
| 55 | 38_multiple_array_index.test \ | ||
| 56 | 39_typedef.test \ | ||
| 57 | 40_stdio.test \ | ||
| 58 | 41_hashif.test \ | ||
| 59 | 42_function_pointer.test \ | ||
| 60 | 43_void_param.test \ | ||
| 61 | 44_scoped_declarations.test \ | ||
| 62 | 45_empty_for.test \ | ||
| 63 | 47_switch_return.test \ | ||
| 64 | 48_nested_break.test \ | ||
| 65 | 49_bracket_evaluation.test \ | ||
| 66 | 50_logical_second_arg.test \ | ||
| 67 | 51_static.test \ | ||
| 68 | 52_unnamed_enum.test \ | ||
| 69 | 54_goto.test \ | ||
| 70 | 55_lshift_type.test | ||
| 71 | |||
| 72 | # 30_hanoi.test -- seg fault in the code, gcc as well | ||
| 73 | # 34_array_assignment.test -- array assignment is not in C standard | ||
| 74 | # 46_grep.test -- does not compile even with gcc | ||
| 71 | 75 | ||
| 72 | # some tests do not pass on all platforms, remove them for now | 76 | # some tests do not pass on all platforms, remove them for now |
| 73 | ifeq ($(TARGETOS),Darwin) | 77 | ifeq ($(TARGETOS),Darwin) |
| 74 | TESTS := $(filter-out 40_stdio.test,$(TESTS)) | 78 | TESTS := $(filter-out 40_stdio.test,$(TESTS)) |
| 75 | endif | 79 | endif |
| 76 | ifdef CONFIG_WIN32 | 80 | ifdef CONFIG_WIN32 |
| 77 | TESTS := $(filter-out 24_math_library.test,$(TESTS)) | 81 | TESTS := $(filter-out 24_math_library.test 28_strings.test,$(TESTS)) |
| 78 | TESTS := $(filter-out 28_strings.test,$(TESTS)) | ||
| 79 | endif | 82 | endif |
| 80 | 83 | ||
| 81 | %.test: %.c %.expect | 84 | %.test: %.c %.expect |
| 82 | @echo Test: $*... | 85 | @echo Test: $*... |
| 83 | @if [ "x`echo $* | grep args`" != "x" ]; \ | 86 | @if [ "x`echo $* | grep args`" != "x" ]; \ |
| 84 | then \ | 87 | then $(TCC_RUN) $< - arg1 arg2 arg3 arg4 >$*.output; \ |
| 85 | ../tcc -B.. $(TCCFLAGS) -run $< - arg1 arg2 arg3 arg4 2>&1 >$*.output; \ | 88 | else $(TCC_RUN) $< >$*.output; \ |
| 86 | else \ | ||
| 87 | ../tcc -B.. $(TCCFLAGS) -run $< 2>&1 >$*.output; \ | ||
| 88 | fi | 89 | fi |
| 89 | @if diff -bu $(<:.c=.expect) $*.output ; \ | 90 | @if diff -bu $(<:.c=.expect) $*.output ; \ |
| 90 | then \ | 91 | then rm -f $*.output; \ |
| 91 | rm -f $*.output \ | 92 | else exit 1; \ |
| 92 | else \ | ||
| 93 | echo "ERROR: test $*"; \ | ||
| 94 | fi | 93 | fi |
| 95 | 94 | ||
| 96 | all: test | 95 | all test: $(TESTS) |
| 97 | |||
| 98 | test: $(TESTS) | ||
| 99 | |||
| 100 | # vim: set expandtab ts=4 sw=4 sts=4 tw=80 : | ||
| 101 | 96 | ||
| 102 | clean: | 97 | clean: |
| 103 | rm -vf fred.txt | 98 | rm -vf fred.txt *.output |