Debian Codegraph @

example/Makefile

raw ◀ ▶
1 Debian patch touch this file
1 #
2 # Makefile for the LCOV example program.
3 #
4 # Make targets:
5 # - example: compile the example program
6 # - output: run test cases on example program and create HTML output
7 # - clean: clean up directory
8 #
9
10 CC := gcc
11 CFLAGS := -Wall -I. --coverage
12 LDFLAGS := --coverage
13
14 LCOV_FLAGS = --branch-coverage
15
16 ifneq ($(COVER_DB),)
17 export PERL_COVER_ARGS := -MDevel::Cover=-db,$(COVER_DB),-coverage,statement,branch,condition,subroutine,-silent,1
18 EXEC_COVER := perl ${PERL_COVER_ARGS}
19 endif
20
21 # MC/DC enabled in gcc/14 and above
22 ENABLE_MCDC=$(shell X=`$(CXX) -dumpversion` ; IFS='.' read -r -a VER <<< $$X ; if [ "$${VER[0]}" -ge 14 ] ; then echo 1 ; else echo 0 ; fi)
23
24 ifeq ($(ENABLE_MCDC), 1)
25 CFLAGS += -fcondition-coverage
26 LDFLAGS += -fcondition-coverage
27 LCOV_FLAGS += --mcdc-coverage
28 endif
29
30 # path differs depending on whether we are in the install dir or not
31 # run with "make LCOV_HOME=/path/to/my/release" if necessary
32
33 ifeq ($(LCOV_HOME),)
34 LCOV_HOME := $(shell if [ -d ../bin ] ; then echo `realpath ..` ; else echo `realpath ../../..` ; fi)
35 endif
36
37 EG_SRCDIR = $(shell if [ -d $(LCOV_HOME)/example ] ; then echo $(LCOV_HOME)/example ; else echo $(LCOV_HOME)/share/lcov/example ; fi)
38 # override this variable to write the differential testcase data someplace
39 # else
40 REPO = exampleRepo
•41 BINDIR = /usr/bin
42 SCRIPTS = /usr/libexec/lcov/scripts
43 LCOV := $(EXEC_COVER) $(BINDIR)/lcov $(LCOV_FLAGS)
44 GENHTML := $(EXEC_COVER) $(BINDIR)/genhtml $(LCOV_FLAGS)
45 GENDESC := $(EXEC_COVER) $(BINDIR)/gendesc
46 GENPNG := $(EXEC_COVER) $(BINDIR)/genpng
47 SCRIPTDIR = $(shell if [ -d ../scripts ] ; then echo $(SCRIPTS) ; else echo $(LCOV_HOME)/share/lcov/support-scripts ; fi)
48
49 # Depending on the presence of the GD.pm perl module, we can use the
50 # special option '--frames' for genhtml
51 USE_GENPNG := $(shell $(GENPNG) --help >/dev/null 2>/dev/null; echo $$?)
52
53 ifeq ($(USE_GENPNG),0)
54 FRAMES := --frames
55 else
56 FRAMES :=
57 endif
58
59 ifeq ("${V}","1")
60 echocmd=
61 else
62 echocmd=echo $1 ;
63 .SILENT: clean
64 endif
65
66
67 .PHONY: clean output test_noargs test_2_to_2000 test_overflow test_differential
68
69 all: output
70
71 example: example.o iterate.o gauss.o
72 $(CC) $^ -o $@ $(LDFLAGS)
73
74 example.o: example.c iterate.h gauss.h
75 $(CC) $(CFLAGS) -c example.c -o example.o
76
77 iterate.o: methods/iterate.c iterate.h
78 $(CC) $(CFLAGS) -c methods/iterate.c -o iterate.o
79
80 gauss.o: methods/gauss.c gauss.h
81 $(CC) $(CFLAGS) -c methods/gauss.c -o gauss.o
82
83 output: example descriptions test_noargs test_2_to_2000 test_overflow test_differential
84 @echo
85 @echo '*'
86 @echo '* Generating HTML output'
87 @echo '*'
88 @echo
89 $(GENHTML) trace_noargs.info trace_args.info trace_overflow.info \
90 --output-directory output --title "Basic example" \
91 --show-details --description-file descriptions $(FRAMES) \
92 --legend
93 @echo
94 @echo '*'
95 @echo '* See '`pwd`/output/index.html
96 @echo '*'
97 @echo
98 @echo "Generate HTML with hierarchical report and additional navigation features"
99 @echo '*'
100 $(GENHTML) trace_noargs.info trace_args.info trace_overflow.info \
101 --output-directory hierarchical \
102 --title "Basic example - hierarchical" \
103 --show-details --hierarchical --show-navigation \
104 --description-file descriptions $(FRAMES) \
105 --legend
106 @echo
107 @echo '* See '`pwd`/hierarchical/index.html
108
109 descriptions: descriptions.txt
110 $(GENDESC) descriptions.txt -o descriptions
111
112 all_tests: example test_noargs test_2_to_2000 test_overflow differential
113
114 test_noargs:
115 @echo
116 @echo '*'
117 @echo '* Test case 1: running ./example without parameters'
118 @echo '*'
119 @echo
120 $(LCOV) --zerocounters --directory .
121 ./example
122 $(LCOV) --capture --directory . --output-file trace_noargs.info --test-name test_noargs --no-external
123
124 test_2_to_2000:
125 @echo
126 @echo '*'
127 @echo '* Test case 2: running ./example 2 2000'
128 @echo '*'
129 @echo
130 $(LCOV) --zerocounters --directory .
131 ./example 2 2000
132 $(LCOV) --capture --directory . --output-file trace_args.info --test-name test_2_to_2000 --no-external
133
134 test_overflow:
135 @echo
136 @echo '*'
137 @echo '* Test case 3: running ./example 0 100000 (causes an overflow)'
138 @echo '*'
139 @echo
140 $(LCOV) --zerocounters --directory .
141 ./example 0 100000 || true
142 $(LCOV) --capture --directory . --output-file trace_overflow.info --test-name "test_overflow" --no-external
143
144 # This test pretends to write some code, run some tests, then modify
145 # code and rerun some tests.
146 # The differential coverage report is categorizes the code based on
147 # what changed in the source code and what changed in the tests.
148 # Note that we are suing perl module for callbacks here - but could use
149 # script or executable if desired.
150 # Could use --verbose and --quiet flags to make the execution less noisy -
151 # but verbosity can help to debug configuration issues.
152 # See the lcov README and man pages for more details.
153 test_differential:
154 @echo
155 @echo '*'
156 @echo '* Test case 4: differential coverage example'
157 @echo '*'
158 @echo
159 @echo "Step 1: Initialize GIT repo with example source"
160 @$(RM) -rf $(REPO)
161 @git init $(REPO) ;
162 @(cd $(REPO) ; \
163 cp -f $(EG_SRCDIR)/*.h $(EG_SRCDIR)/example.c . ; \
164 mkdir methods ; \
165 cp -f $(EG_SRCDIR)/methods/gauss.c methods ; \
166 cp -f $(EG_SRCDIR)/methods/iterate.c methods ; \
167 find . \( -name '*.h' -o -name '*.c' \) -exec git add {} \; ; \
168 git commit -m baseline ; git tag baseline )
169 @echo "Build example and run some tests"
170 (cd $(REPO) ; \
171 $(CC) -o example $(CFLAGS) -I. example.c methods/gauss.c methods/iterate.c ; \
172 ./example ; \
173 ./example 2 1000 ; \
174 ./example 2 100000 || true )
175
176 @echo "Step 2: Capture initial coverage"
177 (cd $(REPO) ; \
178 $(LCOV) --capture -o baseline.info -d . --version-script $(SCRIPTDIR)/gitversion.pm )
179
180 @echo "Step 3: Modify source code"
181 @(cd $(REPO) ; \
182 cp -f $(EG_SRCDIR)/example_mod.c example.c ; \
183 cp -f $(EG_SRCDIR)/methods/iterate_mod.c methods/iterate.c ; \
184 git add example.c methods/iterate.c ; \
185 git commit -m current ; \
186 git tag current )
187
188 @echo "Step 4: Rebuild and run tests (fewer tests this time)"
189 ( cd $(REPO) ; \
190 find . -name '*.gc*' -delete ; \
191 $(CC) -o example $(CFLAGS) -I. example.c methods/gauss.c methods/iterate.c ; \
192 ./example )
193
194 @echo "Step 5: Capture new coverage (after source changes)"
195 (cd $(REPO) ; \
196 $(LCOV) --capture -o current.info -d . --version-script $(SCRIPTDIR)/gitversion.pm )
197 @echo "Compute source diffs"
198 (cd $(REPO) ; \
199 $(SCRIPTDIR)/gitdiff -b . `git rev-list -n 1 baseline` \
200 `git rev-list -n 1 current` > udiff.txt )
201
202 @echo "Step 6: Generate differential coverage report"
203 @echo " (caching revision control data may result in improved runtime performance)"
204 (cd $(REPO) ; \
205 $(GENHTML) -o differential --baseline-file baseline.info \
206 --diff-file udiff.txt --show-owners \
207 --title "Differential coverage example" \
208 --annotate $(SCRIPTDIR)/gitblame.pm,--cache,./my_cache \
209 --version-script $(SCRIPTDIR)/gitversion.pm \
210 -- current.info )
211
212 @echo "point your browser to `realpath $(REPO)`/differential/index.html"
213
214 @echo "Step 7: Generate subset report for code review:"
215 @echo " (reuse revision control data cached in previous step)"
216 (cd $(REPO) ; \
217 $(GENHTML) -o review --baseline-file baseline.info \
218 --diff-file udiff.txt --show-owners \
219 --title "Differential report for code review" \
220 --annotate $(SCRIPTDIR)/gitblame.pm,--cache,./my_cache \
221 --version-script $(SCRIPTDIR)/gitversion.pm \
222 --select-script $(SCRIPTDIR)/select.pm \
223 --select-script --tla --select-script UNC,UIC,LBC \
224 -- current.info )
225
226 @echo "point your browser to `realpath $(REPO)`/review/index.html"
227
228
229 clean:
230 $(call echocmd," CLEAN lcov/example")
231 rm -rf *.o *.bb *.bbg *.da *.gcno *.gcda *.info output example descriptions \
232 $(REPO) hierarchical