History

Add tcov support in Makefile

The following targets are added: testc / testc2.all / testc2.37 / testc2.37+ / testc2.37- testcpp.all / make testcpp.17 This allows to check that the testcase(s) test the code modified. See Makefile tests/pp/Makefile tests/tests2/Makefile lib/tcov.c: Fix while loops with fgets. tcc.h: Fix tcc_p compilation with latest gcc tests/tests2/22_floating_point.*: Better test floating point

herman ten brugge committed 3 years ago

Commit ff2a3721 parent b50a0bd8 files · +150 −48Browse files

Unified · Split

8 files
  1. .gitignore +3 −0
  2. Makefile +24 −3
  3. lib/tcov.c +6 −6
  4. tcc.h +1 −0
  5. tests/pp/Makefile +2 −2
  6. tests/tests2/22_floating_point.c +76 −22
  7. tests/tests2/22_floating_point.expect +34 −11
  8. tests/tests2/Makefile +4 −4
.gitignore+3−0
@@ -16,6 +16,8 @@ · 15 unmodified lines
16a.out16a.out
17tcc_g17tcc_g
18tcc18tcc
19tcc_c
20tcc_p
19*-tcc21*-tcc
20libtcc*.def22libtcc*.def
21 23
@@ -31,6 +33,7 @@ tcc.1 · 9 unmodified lines
31*.pod33*.pod
32tcc-doc.html34tcc-doc.html
33tcc-doc.info35tcc-doc.info
36tcc_c.tcov
34 37
35win32/doc38win32/doc
36win32/examples/libtcc_test.c39win32/examples/libtcc_test.c
Makefile+24−3
@@ -68,7 +68,11 @@ endif · 67 unmodified lines
68TCCFLAGS-unx = -B$(TOP) -I$(TOPSRC)/include -I$(TOPSRC) -I$(TOP)68TCCFLAGS-unx = -B$(TOP) -I$(TOPSRC)/include -I$(TOPSRC) -I$(TOP)
69TCCFLAGS-win = -B$(TOPSRC)/win32 -I$(TOPSRC)/include -I$(TOPSRC) -I$(TOP) -L$(TOP)69TCCFLAGS-win = -B$(TOPSRC)/win32 -I$(TOPSRC)/include -I$(TOPSRC) -I$(TOP) -L$(TOP)
70TCCFLAGS = $(TCCFLAGS$(CFG))70TCCFLAGS = $(TCCFLAGS$(CFG))
71ifdef USE_TCC_C
72TCC = $(TOP)/tcc_c$(EXESUF) $(TCCFLAGS)
73else
71TCC = $(TOP)/tcc$(EXESUF) $(TCCFLAGS)74TCC = $(TOP)/tcc$(EXESUF) $(TCCFLAGS)
75endif
72 76
73CFLAGS_P = $(CFLAGS) -pg -static -DCONFIG_TCC_STATIC -DTCC_PROFILE77CFLAGS_P = $(CFLAGS) -pg -static -DCONFIG_TCC_STATIC -DTCC_PROFILE
74LIBS_P = $(LIBS)78LIBS_P = $(LIBS)
@@ -459,8 +463,21 @@ tests2.%: · 384 unmodified lines
459testspp.%:463testspp.%:
460 @$(MAKE) -C tests/pp $@464 @$(MAKE) -C tests/pp $@
461 465
466# run all tests with code coverage
467tcc_c$(EXESUF): $($T_FILES)
468 @${TCC} -o $@ -ftest-coverage $< $(DEFINES) $(CFLAGS) $(LIBS) $(LDFLAGS)
469testc: tcc_c$(EXESUF)
470 @rm -f tcc_c.tcov
471 @USE_TCC_C=yes $(MAKE) -C tests
472testc2.%: tcc_c$(EXESUF)
473 @rm -f tcc_c.tcov
474 @USE_TCC_C=yes $(MAKE) -C tests/tests2 $@
475testcpp.%: tcc_c$(EXESUF)
476 @rm -f tcc_c.tcov
477 @USE_TCC_C=yes $(MAKE) -C tests/pp $@
478
462clean:479clean:
463 @rm -f tcc$(EXESUF) tcc_p$(EXESUF) *-tcc$(EXESUF) tags ETAGS *.pod480 @rm -f tcc$(EXESUF) tcc_c$(EXESUF) tcc_p$(EXESUF) *-tcc$(EXESUF) tags ETAGS *.pod
464 @rm -f *.o *.a *.so* *.out *.log lib*.def *.exe *.dll a.out *.dylib *_.h481 @rm -f *.o *.a *.so* *.out *.log lib*.def *.exe *.dll a.out *.dylib *_.h
465 @$(MAKE) -s -C lib $@482 @$(MAKE) -s -C lib $@
466 @$(MAKE) -s -C tests $@483 @$(MAKE) -s -C tests $@
@@ -489,12 +506,16 @@ help: · 22 unmodified lines
489 @echo "make test"506 @echo "make test"
490 @echo " run all tests"507 @echo " run all tests"
491 @echo ""508 @echo ""
492 @echo "make tests2.all / make tests2.37 / make tests2.37+"509 @echo "make tests2.all / make tests2.37 / make tests2.37+ / make tests2.37-"
493 @echo " run all/single test(s) from tests2, optionally update .expect"510 @echo " run all/single test(s) from tests2, optionally update .expect, display"
494 @echo ""511 @echo ""
495 @echo "make testspp.all / make testspp.17"512 @echo "make testspp.all / make testspp.17"
496 @echo " run all/single test(s) from tests/pp"513 @echo " run all/single test(s) from tests/pp"
497 @echo ""514 @echo ""
515 @echo "make testc / testc2.all / testc2.37 / testc2.37+ / testc2.37-"
516 @echo "make testcpp.all / make testcpp.17"
517 @echo " run tests with code coverage. After test(s) see tcc_c.tcov"
518 @echo ""
498 @echo "Other supported make targets:"519 @echo "Other supported make targets:"
499 @echo " install install-strip doc clean tags ETAGS tar distclean help"520 @echo " install install-strip doc clean tags ETAGS tar distclean help"
500 @echo ""521 @echo ""
lib/tcov.c+6−6
@@ -340,9 +340,9 @@ void __store_test_coverage (unsigned char * p) · 339 unmodified lines
340 for (i = 0; i < nfile->n_func; i++) {340 for (i = 0; i < nfile->n_func; i++) {
341 func = &nfile->func[i];341 func = &nfile->func[i];
342 342
343 while (curline < func->first_line)343 while (curline < func->first_line &&
344 if (fgets(str, sizeof(str), src))344 fgets(str, sizeof(str), src))
345 fprintf (fp, " -:%5u:%s", curline++, str);345 fprintf (fp, " -:%5u:%s", curline++, str);
346 blocks = 0;346 blocks = 0;
347 blocks_run = 0;347 blocks_run = 0;
348 for (j = 0; j < func->n_line; j++) {348 for (j = 0; j < func->n_line; j++) {
@@ -390,9 +390,9 @@ void __store_test_coverage (unsigned char * p) · 41 unmodified lines
390 if (same_line)390 if (same_line)
391 lline++;391 lline++;
392 392
393 while (curline < fline)393 while (curline < fline &&
394 if (fgets(str, sizeof(str), src))394 fgets(str, sizeof(str), src))
395 fprintf (fp, " -:%5u:%s", curline++, str);395 fprintf (fp, " -:%5u:%s", curline++, str);
396 while (curline < lline &&396 while (curline < lline &&
397 fgets(str, sizeof(str), src)) {397 fgets(str, sizeof(str), src)) {
398 if (count == 0)398 if (count == 0)
tcc.h+1−0
@@ -399,6 +399,7 @@ extern long double strtold (const char *__nptr, char **__endptr); · 398 unmodified lines
399 399
400#ifdef TCC_PROFILE /* profile all functions */400#ifdef TCC_PROFILE /* profile all functions */
401# define static401# define static
402# define inline
402#endif403#endif
403 404
404/* -------------------------------------------- */405/* -------------------------------------------- */
tests/pp/Makefile+2−2
@@ -10,7 +10,7 @@ VPATH = $(SRC) · 9 unmodified lines
10files = $(patsubst %.$1,%.test,$(notdir $(wildcard $(SRC)/*.$1)))10files = $(patsubst %.$1,%.test,$(notdir $(wildcard $(SRC)/*.$1)))
11TESTS = $(call files,c) $(call files,S)11TESTS = $(call files,c) $(call files,S)
12 12
13all test testspp.all: $(sort $(TESTS))13all test testspp.all testcpp.all: $(sort $(TESTS))
14 14
15DIFF_OPTS = -Nu -b15DIFF_OPTS = -Nu -b
16 16
@@ -29,7 +29,7 @@ FILTER = 2>&1 | sed 's,$(SRC)/,,g' · 12 unmodified lines
29 diff $(DIFF_OPTS) $(SRC)/$*.expect $*.output \29 diff $(DIFF_OPTS) $(SRC)/$*.expect $*.output \
30 && rm -f $*.output30 && rm -f $*.output
31 31
32testspp.%: %.test ;32testspp.% testcpp.%: %.test ;
33 33
34# automatically generate .expect files with gcc:34# automatically generate .expect files with gcc:
35%.expect: # %.c35%.expect: # %.c
tests/tests2/22_floating_point.c+76−22
@@ -14,6 +14,14 @@ test() · 13 unmodified lines
14 }14 }
15}15}
16 16
17float f1 = 12.34f, f2 = 56.78f;
18double d1 = 12.34, d2 = 56.78;
19long double ld1 = 12.34l, ld2 = 56.78l;
20
21float tf = 12.34f + 56.78f - 12.34f * 56.78f + 12.34f / 56.78f;
22double td = 12.34 + 56.78 - 12.34 * 56.78 + 12.34 / 56.78;
23long double tld = 12.34l + 56.78l - 12.34l * 56.78l + 12.34l / 56.78l;
24
17int main()25int main()
18{26{
19 static int e1 = -1.0 == 0.0;27 static int e1 = -1.0 == 0.0;
@@ -23,45 +31,91 @@ int main() · 3 unmodified lines
23 static int e5 = -1.0 <= 0.0;31 static int e5 = -1.0 <= 0.0;
24 static int e6 = -1.0 > 0.0;32 static int e6 = -1.0 > 0.0;
25 // variables33 // variables
26 float a = 12.34 + 56.78;34 float af = 12.34f + 56.78f;
27 printf("%f\n", a);35 double ad = 12.34 + 56.78;
36 long double ald = 12.34l + 56.78l;
37 printf("%f %f \n", af, tf);
38 printf("%g %g\n", ad, td);
39 printf("%Lf %Lf\n", ald, tld);
28 40
29 // infix operators41 // infix operators
30 printf("%f\n", 12.34 + 56.78);42 printf("%f %f %f %f\n", 12.34f + 56.78f, 12.34f - 56.78f, 12.34f * 56.78f, 12.34f / 56.78f);
31 printf("%f\n", 12.34 - 56.78);43 printf("%g %g %g %g\n", 12.34 + 56.78, 12.34 - 56.78, 12.34 * 56.78, 12.34 / 56.78);
32 printf("%f\n", 12.34 * 56.78);44 printf("%Lf %Lf %Lf %Lf\n", 12.34l + 56.78l, 12.34l - 56.78l, 12.34l * 56.78l, 12.34l / 56.78l);
33 printf("%f\n", 12.34 / 56.78);45#ifdef __i386__
46 // gcc/clang -m32 -mno-sse and tcc all fail for + and * but all have the same value
47 printf("%f %f %f %f\n", 12.34f + 56.78f, f1 - f2, 12.34f * 56.78f, f1 / f2);
48#else
49 printf("%f %f %f %f\n", f1 + f2, f1 - f2, f1 * f2, f1 / f2);
50#endif
51 printf("%g %g %g %g\n", d1 + d2, d1 - d2, d1 * d2, d1 / d2);
52 printf("%Lf %Lf %Lf %Lf\n", ld1 + ld2, ld1 - ld2, ld1 * ld2, ld1 / ld2);
34 53
35 // comparison operators54 // comparison operators
55 printf("%d %d %d %d %d %d\n", 12.34f < 56.78f, 12.34f <= 56.78f, 12.34f == 56.78f, 12.34f >= 56.78f, 12.34f > 56.78f, 12.34f != 56.78f);
56 printf("%d %d %d %d %d %d\n", 12.34f < 12.34f, 12.34f <= 12.34f, 12.34f == 12.34f, 12.34f >= 12.34f, 12.34f > 12.34f, 12.34f != 12.34f);
57 printf("%d %d %d %d %d %d\n", 56.78f < 12.34f, 56.78f <= 12.34f, 56.78f == 12.34f, 56.78f >= 12.34f, 56.78f > 12.34f, 56.78f != 12.34f);
36 printf("%d %d %d %d %d %d\n", 12.34 < 56.78, 12.34 <= 56.78, 12.34 == 56.78, 12.34 >= 56.78, 12.34 > 56.78, 12.34 != 56.78);58 printf("%d %d %d %d %d %d\n", 12.34 < 56.78, 12.34 <= 56.78, 12.34 == 56.78, 12.34 >= 56.78, 12.34 > 56.78, 12.34 != 56.78);
37 printf("%d %d %d %d %d %d\n", 12.34 < 12.34, 12.34 <= 12.34, 12.34 == 12.34, 12.34 >= 12.34, 12.34 > 12.34, 12.34 != 12.34);59 printf("%d %d %d %d %d %d\n", 12.34 < 12.34, 12.34 <= 12.34, 12.34 == 12.34, 12.34 >= 12.34, 12.34 > 12.34, 12.34 != 12.34);
38 printf("%d %d %d %d %d %d\n", 56.78 < 12.34, 56.78 <= 12.34, 56.78 == 12.34, 56.78 >= 12.34, 56.78 > 12.34, 56.78 != 12.34);60 printf("%d %d %d %d %d %d\n", 56.78 < 12.34, 56.78 <= 12.34, 56.78 == 12.34, 56.78 >= 12.34, 56.78 > 12.34, 56.78 != 12.34);
61 printf("%d %d %d %d %d %d\n", 12.34l < 56.78l, 12.34l <= 56.78l, 12.34l == 56.78l, 12.34l >= 56.78l, 12.34l > 56.78l, 12.34l != 56.78l);
62 printf("%d %d %d %d %d %d\n", 12.34l < 12.34l, 12.34l <= 12.34l, 12.34l == 12.34l, 12.34l >= 12.34l, 12.34l > 12.34l, 12.34l != 12.34l);
63 printf("%d %d %d %d %d %d\n", 56.78l < 12.34l, 56.78l <= 12.34l, 56.78l == 12.34l, 56.78l >= 12.34l, 56.78l > 12.34l, 56.78l != 12.34l);
64 printf("%d %d %d %d %d %d\n", f1 < f2, f1 <= f2, f1 == f2, f1 >= f2, f1 > f2, f1 != f2);
65 printf("%d %d %d %d %d %d\n", f1 < f1, f1 <= f1, f1 == f1, f1 >= f1, f1 > f1, f1 != f1);
66 printf("%d %d %d %d %d %d\n", f2 < f1, f2 <= f1, f2 == f1, f2 >= f1, f2 > f1, f2 != f1);
67 printf("%d %d %d %d %d %d\n", d1 < d2, d1 <= d2, d1 == d2, d1 >= d2, d1 > d2, d1 != d2);
68 printf("%d %d %d %d %d %d\n", d1 < d1, d1 <= d1, d1 == d1, d1 >= d1, d1 > d1, d1 != d1);
69 printf("%d %d %d %d %d %d\n", d2 < d1, d2 <= d1, d2 == d1, d2 >= d1, d2 > d1, d2 != d1);
70 printf("%d %d %d %d %d %d\n", ld1 < ld2, ld1 <= ld2, ld1 == ld2, ld1 >= ld2, ld1 > ld2, ld1 != ld2);
71 printf("%d %d %d %d %d %d\n", ld1 < ld1, ld1 <= ld1, ld1 == ld1, ld1 >= ld1, ld1 > ld1, ld1 != ld1);
72 printf("%d %d %d %d %d %d\n", ld2 < ld1, ld2 <= ld1, ld2 == ld1, ld2 >= ld1, ld2 > ld1, ld2 != ld1);
39 printf("%d %d %d %d %d %d\n", e1, e2, e3, e4, e5, e6);73 printf("%d %d %d %d %d %d\n", e1, e2, e3, e4, e5, e6);
40 74
41 // assignment operators75 // assignment operators
42 a = 12.34;76 af = 12.34f; ad = 12.34; ald = 12.34l;
43 a += 56.78;77 af += 56.78f; ad += 56.78; ald += 56.78l;
44 printf("%f\n", a);78 printf("%f %g %Lf\n", af, ad, ald);
79#ifdef __i386__
80 printf("%f %g %Lf\n", af, ad, ald);
81#else
82 af = f1; ad = d1; ald = ld1;
83 af += f2; ad += d2; ald += ld2;
84 printf("%f %g %Lf\n", af, ad, ald);
85#endif
45 86
46 a = 12.34;87 af = 12.34f; ad = 12.34; ald = 12.34l;
47 a -= 56.78;88 af -= 56.78f; ad -= 56.78; ald -= 56.78l;
48 printf("%f\n", a);89 printf("%f %g %Lf\n", af, ad, ald);
90 af = f1; ad = d1; ald = ld1;
91 af -= f2; ad -= d2; ald -= ld2;
92 printf("%f %g %Lf\n", af, ad, ald);
49 93
50 a = 12.34;94 af = 12.34f; ad = 12.34; ald = 12.34l;
51 a *= 56.78;95 af *= 56.78f; ad *= 56.78; ald *= 56.78l;
52 printf("%f\n", a);96 printf("%f %g %Lf\n", af, ad, ald);
97#ifdef __i386__
98 printf("%f %g %Lf\n", af, ad, ald);
99#else
100 af = f1; ad = d1; ald = ld1;
101 af *= f2; ad *= d2; ald *= ld2;
102 printf("%f %g %Lf\n", af, ad, ald);
103#endif
53 104
54 a = 12.34;105 af = 12.34f; ad = 12.34; ald = 12.34l;
55 a /= 56.78;106 af /= 56.78f; ad /= 56.78; ald /= 56.78l;
56 printf("%f\n", a);107 printf("%f %g %Lf\n", af, ad, ald);
108 af = f1; ad = d1; ald = ld1;
109 af /= f2; ad /= d2; ald /= ld2;
110 printf("%f %g %Lf\n", af, ad, ald);
57 111
58 // prefix operators112 // prefix operators
59 printf("%f\n", +12.34);113 printf("%f %g %Lf\n", +12.34f, +12.34, +12.34l);
60 printf("%f\n", -12.34);114 printf("%f %g %Lf\n", -12.34f, -12.34, -12.34l);
61 115
62 // type coercion116 // type coercion
63 a = 2;117 af = 2;
64 printf("%f\n", a);118 printf("%f\n", af);
65 printf("%f\n", sin(2));119 printf("%f\n", sin(2));
66 120
67 return 0;121 return 0;
tests/tests2/22_floating_point.expect+34−11
@@ -1,17 +1,40 @@
169.120003169.119995 -631.327881
269.120000269.12 -631.328
3-44.440000369.120000 -631.327870
4700.665200469.119995 -44.439999 700.665222 0.217330
50.217330569.12 -44.44 700.665 0.21733
669.120000 -44.440000 700.665200 0.217330
769.119995 -44.439999 700.665222 0.217330
869.12 -44.44 700.665 0.21733
969.120000 -44.440000 700.665200 0.217330
101 1 0 0 0 1
110 1 1 1 0 0
120 0 0 1 1 1
131 1 0 0 0 1
140 1 1 1 0 0
150 0 0 1 1 1
161 1 0 0 0 1
170 1 1 1 0 0
180 0 0 1 1 1
191 1 0 0 0 1
200 1 1 1 0 0
210 0 0 1 1 1
221 1 0 0 0 1
230 1 1 1 0 0
240 0 0 1 1 1
61 1 0 0 0 1251 1 0 0 0 1
70 1 1 1 0 0260 1 1 1 0 0
80 0 0 1 1 1270 0 0 1 1 1
90 1 1 0 1 0280 1 1 0 1 0
1069.1200032969.119995 69.12 69.120000
11-44.4399993069.119995 69.12 69.120000
12700.66522231-44.439999 -44.44 -44.440000
130.21733032-44.439999 -44.44 -44.440000
1412.34000033700.665222 700.665 700.665200
15-12.34000034700.665222 700.665 700.665200
350.217330 0.21733 0.217330
360.217330 0.21733 0.217330
3712.340000 12.34 12.340000
38-12.340000 -12.34 -12.340000
162.000000392.000000
170.909297400.909297
tests/tests2/Makefile+4−4
@@ -124,7 +124,7 @@ endif · 123 unmodified lines
124# Filter source directory in warnings/errors (out-of-tree builds)124# Filter source directory in warnings/errors (out-of-tree builds)
125FILTER = 2>&1 | sed -e 's,$(SRC)/,,g'125FILTER = 2>&1 | sed -e 's,$(SRC)/,,g'
126 126
127all test tests2.all: $(filter-out $(SKIP),$(TESTS))127all test tests2.all testc2.all: $(filter-out $(SKIP),$(TESTS))
128 @$(MAKE) clean --no-print-directory -s128 @$(MAKE) clean --no-print-directory -s
129 129
130%.test: %.c %.expect130%.test: %.c %.expect
@@ -138,15 +138,15 @@ T3 = $(FILTER) >$*.output 2>&1 || true \ · 7 unmodified lines
138 && rm -f $*.output $(filter $*.expect,$(GEN-ALWAYS))138 && rm -f $*.output $(filter $*.expect,$(GEN-ALWAYS))
139 139
140# run single test and update .expect file, e.g. "make tests2.37+"140# run single test and update .expect file, e.g. "make tests2.37+"
141tests2.%+:141tests2.%+ testc2.%+:
142 @$(MAKE) $(call F2,$(call F1,$*)) --no-print-directory142 @$(MAKE) $(call F2,$(call F1,$*)) --no-print-directory
143 143
144# just run tcc to see the output, e.g. "make tests2.37-"144# just run tcc to see the output, e.g. "make tests2.37-"
145tests2.%-:145tests2.%- testc2.%-:
146 @$(MAKE) $(call F1,$*) T3= --no-print-directory146 @$(MAKE) $(call F1,$*) T3= --no-print-directory
147 147
148# run single test, e.g. "make tests2.37"148# run single test, e.g. "make tests2.37"
149tests2.%:149tests2.% testc2.%:
150 @$(MAKE) $(call F1,$*) --no-print-directory150 @$(MAKE) $(call F1,$*) --no-print-directory
151 151
152F1 = $(or $(filter $1_%,$(TESTS)),$1_???.test)152F1 = $(or $(filter $1_%,$(TESTS)),$1_???.test)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t