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
1616 a.out
1717 tcc_g
1818 tcc
19+tcc_c
20+tcc_p
1921 *-tcc
2022 libtcc*.def
2123
@@ -31,6 +33,7 @@ tcc.1 · 9 unmodified lines
3133 *.pod
3234 tcc-doc.html
3335 tcc-doc.info
36+tcc_c.tcov
3437
3538 win32/doc
3639 win32/examples/libtcc_test.c
Makefile+24−3
@@ -68,7 +68,11 @@ endif · 67 unmodified lines
6868 TCCFLAGS-unx = -B$(TOP) -I$(TOPSRC)/include -I$(TOPSRC) -I$(TOP)
6969 TCCFLAGS-win = -B$(TOPSRC)/win32 -I$(TOPSRC)/include -I$(TOPSRC) -I$(TOP) -L$(TOP)
7070 TCCFLAGS = $(TCCFLAGS$(CFG))
71+ifdef USE_TCC_C
72+TCC = $(TOP)/tcc_c$(EXESUF) $(TCCFLAGS)
73+else
7174 TCC = $(TOP)/tcc$(EXESUF) $(TCCFLAGS)
75+endif
7276
7377 CFLAGS_P = $(CFLAGS) -pg -static -DCONFIG_TCC_STATIC -DTCC_PROFILE
7478 LIBS_P = $(LIBS)
@@ -459,8 +463,21 @@ tests2.%: · 384 unmodified lines
459463 testspp.%:
460464 @$(MAKE) -C tests/pp $@
461465
466+# run all tests with code coverage
467+tcc_c$(EXESUF): $($T_FILES)
468+ @${TCC} -o $@ -ftest-coverage $< $(DEFINES) $(CFLAGS) $(LIBS) $(LDFLAGS)
469+testc: tcc_c$(EXESUF)
470+ @rm -f tcc_c.tcov
471+ @USE_TCC_C=yes $(MAKE) -C tests
472+testc2.%: tcc_c$(EXESUF)
473+ @rm -f tcc_c.tcov
474+ @USE_TCC_C=yes $(MAKE) -C tests/tests2 $@
475+testcpp.%: tcc_c$(EXESUF)
476+ @rm -f tcc_c.tcov
477+ @USE_TCC_C=yes $(MAKE) -C tests/pp $@
478+
462479 clean:
463− @rm -f tcc$(EXESUF) tcc_p$(EXESUF) *-tcc$(EXESUF) tags ETAGS *.pod
480+ @rm -f tcc$(EXESUF) tcc_c$(EXESUF) tcc_p$(EXESUF) *-tcc$(EXESUF) tags ETAGS *.pod
464481 @rm -f *.o *.a *.so* *.out *.log lib*.def *.exe *.dll a.out *.dylib *_.h
465482 @$(MAKE) -s -C lib $@
466483 @$(MAKE) -s -C tests $@
@@ -489,12 +506,16 @@ help: · 22 unmodified lines
489506 @echo "make test"
490507 @echo " run all tests"
491508 @echo ""
492− @echo "make tests2.all / make tests2.37 / make tests2.37+"
493− @echo " run all/single test(s) from tests2, optionally update .expect"
509+ @echo "make tests2.all / make tests2.37 / make tests2.37+ / make tests2.37-"
510+ @echo " run all/single test(s) from tests2, optionally update .expect, display"
494511 @echo ""
495512 @echo "make testspp.all / make testspp.17"
496513 @echo " run all/single test(s) from tests/pp"
497514 @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 ""
498519 @echo "Other supported make targets:"
499520 @echo " install install-strip doc clean tags ETAGS tar distclean help"
500521 @echo ""
lib/tcov.c+6−6
@@ -340,9 +340,9 @@ void __store_test_coverage (unsigned char * p) · 339 unmodified lines
340340 for (i = 0; i < nfile->n_func; i++) {
341341 func = &nfile->func[i];
342342
343− while (curline < func->first_line)
344− if (fgets(str, sizeof(str), src))
345− fprintf (fp, " -:%5u:%s", curline++, str);
343+ while (curline < func->first_line &&
344+ fgets(str, sizeof(str), src))
345+ fprintf (fp, " -:%5u:%s", curline++, str);
346346 blocks = 0;
347347 blocks_run = 0;
348348 for (j = 0; j < func->n_line; j++) {
@@ -390,9 +390,9 @@ void __store_test_coverage (unsigned char * p) · 41 unmodified lines
390390 if (same_line)
391391 lline++;
392392
393− while (curline < fline)
394− if (fgets(str, sizeof(str), src))
395− fprintf (fp, " -:%5u:%s", curline++, str);
393+ while (curline < fline &&
394+ fgets(str, sizeof(str), src))
395+ fprintf (fp, " -:%5u:%s", curline++, str);
396396 while (curline < lline &&
397397 fgets(str, sizeof(str), src)) {
398398 if (count == 0)
tcc.h+1−0
@@ -399,6 +399,7 @@ extern long double strtold (const char *__nptr, char **__endptr); · 398 unmodified lines
399399
400400 #ifdef TCC_PROFILE /* profile all functions */
401401 # define static
402+# define inline
402403 #endif
403404
404405 /* -------------------------------------------- */
tests/pp/Makefile+2−2
@@ -10,7 +10,7 @@ VPATH = $(SRC) · 9 unmodified lines
1010 files = $(patsubst %.$1,%.test,$(notdir $(wildcard $(SRC)/*.$1)))
1111 TESTS = $(call files,c) $(call files,S)
1212
13−all test testspp.all: $(sort $(TESTS))
13+all test testspp.all testcpp.all: $(sort $(TESTS))
1414
1515 DIFF_OPTS = -Nu -b
1616
@@ -29,7 +29,7 @@ FILTER = 2>&1 | sed 's,$(SRC)/,,g' · 12 unmodified lines
2929 diff $(DIFF_OPTS) $(SRC)/$*.expect $*.output \
3030 && rm -f $*.output
3131
32−testspp.%: %.test ;
32+testspp.% testcpp.%: %.test ;
3333
3434 # automatically generate .expect files with gcc:
3535 %.expect: # %.c
tests/tests2/22_floating_point.c+76−22
@@ -14,6 +14,14 @@ test() · 13 unmodified lines
1414 }
1515 }
1616
17+float f1 = 12.34f, f2 = 56.78f;
18+double d1 = 12.34, d2 = 56.78;
19+long double ld1 = 12.34l, ld2 = 56.78l;
20+
21+float tf = 12.34f + 56.78f - 12.34f * 56.78f + 12.34f / 56.78f;
22+double td = 12.34 + 56.78 - 12.34 * 56.78 + 12.34 / 56.78;
23+long double tld = 12.34l + 56.78l - 12.34l * 56.78l + 12.34l / 56.78l;
24+
1725 int main()
1826 {
1927 static int e1 = -1.0 == 0.0;
@@ -23,45 +31,91 @@ int main() · 3 unmodified lines
2331 static int e5 = -1.0 <= 0.0;
2432 static int e6 = -1.0 > 0.0;
2533 // variables
26− float a = 12.34 + 56.78;
27− printf("%f\n", a);
34+ float af = 12.34f + 56.78f;
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);
2840
2941 // infix operators
30− printf("%f\n", 12.34 + 56.78);
31− printf("%f\n", 12.34 - 56.78);
32− printf("%f\n", 12.34 * 56.78);
33− 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);
43+ printf("%g %g %g %g\n", 12.34 + 56.78, 12.34 - 56.78, 12.34 * 56.78, 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);
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);
3453
3554 // 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);
3658 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);
3759 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);
3860 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);
3973 printf("%d %d %d %d %d %d\n", e1, e2, e3, e4, e5, e6);
4074
4175 // assignment operators
42− a = 12.34;
43− a += 56.78;
44− printf("%f\n", a);
76+ af = 12.34f; ad = 12.34; ald = 12.34l;
77+ af += 56.78f; ad += 56.78; ald += 56.78l;
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
4586
46− a = 12.34;
47− a -= 56.78;
48− printf("%f\n", a);
87+ af = 12.34f; ad = 12.34; ald = 12.34l;
88+ af -= 56.78f; ad -= 56.78; ald -= 56.78l;
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);
4993
50− a = 12.34;
51− a *= 56.78;
52− printf("%f\n", a);
94+ af = 12.34f; ad = 12.34; ald = 12.34l;
95+ af *= 56.78f; ad *= 56.78; ald *= 56.78l;
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
53104
54− a = 12.34;
55− a /= 56.78;
56− printf("%f\n", a);
105+ af = 12.34f; ad = 12.34; ald = 12.34l;
106+ af /= 56.78f; ad /= 56.78; ald /= 56.78l;
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);
57111
58112 // prefix operators
59− printf("%f\n", +12.34);
60− printf("%f\n", -12.34);
113+ printf("%f %g %Lf\n", +12.34f, +12.34, +12.34l);
114+ printf("%f %g %Lf\n", -12.34f, -12.34, -12.34l);
61115
62116 // type coercion
63− a = 2;
64− printf("%f\n", a);
117+ af = 2;
118+ printf("%f\n", af);
65119 printf("%f\n", sin(2));
66120
67121 return 0;
tests/tests2/22_floating_point.expect+34−11
@@ -1,17 +1,40 @@
1−69.120003
2−69.120000
3−-44.440000
4−700.665200
5−0.217330
1+69.119995 -631.327881
2+69.12 -631.328
3+69.120000 -631.327870
4+69.119995 -44.439999 700.665222 0.217330
5+69.12 -44.44 700.665 0.21733
6+69.120000 -44.440000 700.665200 0.217330
7+69.119995 -44.439999 700.665222 0.217330
8+69.12 -44.44 700.665 0.21733
9+69.120000 -44.440000 700.665200 0.217330
10+1 1 0 0 0 1
11+0 1 1 1 0 0
12+0 0 0 1 1 1
13+1 1 0 0 0 1
14+0 1 1 1 0 0
15+0 0 0 1 1 1
16+1 1 0 0 0 1
17+0 1 1 1 0 0
18+0 0 0 1 1 1
19+1 1 0 0 0 1
20+0 1 1 1 0 0
21+0 0 0 1 1 1
22+1 1 0 0 0 1
23+0 1 1 1 0 0
24+0 0 0 1 1 1
625 1 1 0 0 0 1
726 0 1 1 1 0 0
827 0 0 0 1 1 1
928 0 1 1 0 1 0
10−69.120003
11−-44.439999
12−700.665222
13−0.217330
14−12.340000
15−-12.340000
29+69.119995 69.12 69.120000
30+69.119995 69.12 69.120000
31+-44.439999 -44.44 -44.440000
32+-44.439999 -44.44 -44.440000
33+700.665222 700.665 700.665200
34+700.665222 700.665 700.665200
35+0.217330 0.21733 0.217330
36+0.217330 0.21733 0.217330
37+12.340000 12.34 12.340000
38+-12.340000 -12.34 -12.340000
1639 2.000000
1740 0.909297
tests/tests2/Makefile+4−4
@@ -124,7 +124,7 @@ endif · 123 unmodified lines
124124 # Filter source directory in warnings/errors (out-of-tree builds)
125125 FILTER = 2>&1 | sed -e 's,$(SRC)/,,g'
126126
127−all test tests2.all: $(filter-out $(SKIP),$(TESTS))
127+all test tests2.all testc2.all: $(filter-out $(SKIP),$(TESTS))
128128 @$(MAKE) clean --no-print-directory -s
129129
130130 %.test: %.c %.expect
@@ -138,15 +138,15 @@ T3 = $(FILTER) >$*.output 2>&1 || true \ · 7 unmodified lines
138138 && rm -f $*.output $(filter $*.expect,$(GEN-ALWAYS))
139139
140140 # run single test and update .expect file, e.g. "make tests2.37+"
141−tests2.%+:
141+tests2.%+ testc2.%+:
142142 @$(MAKE) $(call F2,$(call F1,$*)) --no-print-directory
143143
144144 # just run tcc to see the output, e.g. "make tests2.37-"
145−tests2.%-:
145+tests2.%- testc2.%-:
146146 @$(MAKE) $(call F1,$*) T3= --no-print-directory
147147
148148 # run single test, e.g. "make tests2.37"
149−tests2.%:
149+tests2.% testc2.%:
150150 @$(MAKE) $(call F1,$*) --no-print-directory
151151
152152 F1 = $(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