Skip to content

Commit f7af382

Browse files
committed
[ISSUE-10]: support of making coverage report (see cov directory)
1 parent b3fd0b7 commit f7af382

4 files changed

Lines changed: 108 additions & 13 deletions

File tree

cov/coverage.mk

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
SELF_MKFILE := $(lastword $(MAKEFILE_LIST))
2+
3+
PROJ=esp32basic
4+
5+
##progs
6+
GCOV=gcov
7+
8+
## paths
9+
HTML=html/index.html
10+
SRCDIR=../src
11+
## we get direct information about modification time
12+
## note: I do not like wildcard, but could not find better solution
13+
SOURCES=$(wildcard $(SRCDIR)/*.c)
14+
HEADERS=$(wildcard $(SRCDIR)/*.h)
15+
OBJS=$(addprefix src/, $(notdir $(SOURCES:.c=.o)))
16+
GCDA=$(OBJS:.o=.gcda)
17+
GCNO=$(OBJS:.o=.gcno)
18+
GCDA_EXIST := $(foreach gcda,$(GCDA),$(wildcard $(gcda)))
19+
#$(info $$GCDA = $(GCDA))
20+
#$(info $$GCDA_EXIST = $(GCDA_EXIST))
21+
22+
all: $(HTML)
23+
24+
gcov: testrun
25+
$(MAKE) -f $(SELF_MKFILE) _gcov
26+
27+
_gcov: $(GCNO:%.gcno=%.c.gcov)
28+
29+
%.c.gcov: %.gcno
30+
cd src; $(GCOV) -wrabcfu -s ../.. -o $(notdir $<) $(notdir $(@:.gcov=))
31+
32+
#src/%.gcda: testrun
33+
34+
35+
$(HTML): $(PROJ).info
36+
genhtml -s --branch-coverage $(PROJ).info --output-directory $(dir $(HTML))
37+
38+
$(PROJ).info: $(PROJ).pre.info
39+
lcov --rc lcov_branch_coverage=1 -r $< "/usr*" -o $@
40+
41+
$(PROJ).pre.info: $(PROJ).base.info $(PROJ).test.info
42+
lcov --rc lcov_branch_coverage=1 -a $(PROJ).base.info -a $(PROJ).test.info -o $@
43+
44+
#$(PROJ).base.info: src/lib$(PROJ).a
45+
$(PROJ).base.info: testrun
46+
lcov -z -d src
47+
lcov --rc lcov_branch_coverage=1 -c -i -d src -o $@
48+
49+
$(PROJ).test.info: $(PROJ).base.info
50+
$(MAKE) -C tests check
51+
lcov --rc lcov_branch_coverage=1 -c -d src -o $@
52+
53+
54+
#source: Makefile FORCE
55+
# $(MAKE) -C src
56+
57+
#testrun: source FORCE
58+
testrun: tests/Makefile FORCE
59+
$(MAKE) -C tests check
60+
61+
tests/Makefile:
62+
mkdir -p tests
63+
(cd tests && ../../tests/configure CFLAGS="-fprofile-arcs -ftest-coverage" LDFLAGS="-fprofile-arcs -ftest-coverage")
64+
65+
FORCE:
66+
67+
clean:
68+
rm -f $(PROJ).info
69+
rm -f $(PROJ).pre.info
70+
rm -f $(PROJ).base.info
71+
rm -f $(PROJ).test.info
72+
rm -rf $(dir $(HTML))
73+
rm -f src/*.gcda
74+
rm -f tests/*.gcda
75+
$(MAKE) -C tests clean
76+
77+
distclean: clean
78+
$(MAKE) -C tests distclean
79+
rm -rf src
80+
rm -rf tests
81+
82+
.PHONY: clean distclean source testrun gcov _gcov
83+

tests/Makefile.am

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ check_PROGRAMS = $(TESTS)
77
AM_CPPFLAGS = -I${top_srcdir}/../src
88
LDADD = gentest_common.o
99

10-
bitgen_test_SOURCES = bitgen_test.c ${top_srcdir}/../src/utils/generators.c
11-
bytegen_test_SOURCES = bytegen_test.c ${top_srcdir}/../src/utils/generators.c
10+
bitgen_test_SOURCES = bitgen_test.c ../src/utils/generators.c
11+
bytegen_test_SOURCES = bytegen_test.c ../src/utils/generators.c

tests/bytegen_test.c

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,33 @@
77
#include "gentest_common.h"
88
#include "typeaux.h"
99

10-
const char gacInput0[] = "abc def";
10+
#define TEXTANDLEN(X) X, sizeof(X)-1
11+
12+
typedef struct {
13+
const char *sText;
14+
size_t zLen;
15+
} STextAndLen;
16+
17+
const STextAndLen gasInput[]={
18+
{TEXTANDLEN("abc def")},
19+
{TEXTANDLEN("")}
20+
};
1121

1222
uint8_t gau8Input1[] = {3, 5, 7, 9};
1323
uint8_t gau8Param1[] = {10, 0x80, 0x00};
1424
uint16_t gau16Expected1[] = {0x8003, 0x0007, 0x8005, 0x0005, 0x8007, 0x0003, 0x8009, 0x0001};
1525

16-
bool test_bytegen_iter(const char *str) {
17-
SByteGenState sGen = bytegen_init((uint8_t*) str, strlen(str));
18-
return gentest_check_seq8_equal(gsByteGenFunc, (void*) &sGen, (uint8_t*) gacInput0, strlen(gacInput0));
26+
bool test_bytegen_iter(const STextAndLen sParam) {
27+
SByteGenState sGen = bytegen_init((uint8_t*) sParam.sText, sParam.zLen);
28+
return gentest_check_seq8_equal(gsByteGenFunc, (void*) &sGen, (uint8_t*) sParam.sText, sParam.zLen);
1929
}
2030

21-
bool test_bytegen_reset(const char *str) {
31+
bool test_bytegen_reset(const STextAndLen sParam) {
2232
bool bRet = true;
23-
for (unsigned int i = 0; i < strlen(str); ++i) {
24-
SByteGenState sGen = bytegen_init((uint8_t*) str, strlen(str));
33+
for (unsigned int i = 0; i < sParam.zLen; ++i) {
34+
SByteGenState sGen = bytegen_init((uint8_t*) sParam.sText, sParam.zLen);
2535
gentest_reset_after_steps(&sGen, (FToByteNext) bytegen_next, (FToXReset) bytegen_reset, i);
26-
bRet &= gentest_check_seq8_equal(gsByteGenFunc, (void*) &sGen, (uint8_t*) gacInput0, strlen(gacInput0));
36+
bRet &= gentest_check_seq8_equal(gsByteGenFunc, (void*) &sGen, (uint8_t*) sParam.sText, sParam.zLen);
2737
}
2838
return bRet;
2939
}
@@ -51,8 +61,10 @@ int main(int argc, char **argv) {
5161
fprintf(stderr, "%s does not require command line arguments\n", argv[0]);
5262
}
5363

54-
assert(test_bytegen_iter(gacInput0));
55-
assert(test_bytegen_reset(gacInput0));
64+
assert(test_bytegen_iter(gasInput[0]));
65+
assert(test_bytegen_reset(gasInput[0]));
66+
assert(test_bytegen_iter(gasInput[1]));
67+
assert(test_bytegen_reset(gasInput[1]));
5668
assert(test_pwngen_iter(gau8Input1, ARRAY_SIZE(gau8Input1), gau16Expected1, gau8Param1[0], gau8Param1[1], gau8Param1[2]));
5769
assert(test_pwmgen_reset(gau8Input1, ARRAY_SIZE(gau8Input1), gau16Expected1, gau8Param1[0], gau8Param1[1], gau8Param1[2]));
5870
}

tests/configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
AC_PREREQ([2.69])
22
AC_INIT([esp32basic-test],[1.0.0])
3-
AM_INIT_AUTOMAKE
3+
AM_INIT_AUTOMAKE([subdir-objects])
44
: ${CFLAGS="-g -Wall"} ${LDFLAGS=""}
55
AC_PROG_CC
66
AC_PROG_CC_STDC

0 commit comments

Comments
 (0)