This post is in english / Dieser Artikel ist auf Englisch, da er sich an die internationale Entwicklergemeinschaft richtet.
While the i3 window manager has a lot of testcases, I never got around to actually doing code coverage tests. Now I took the time to get it to work and want to describe the process so that others don’t do the same mistakes I did.
Outline of the process
- Compile your source code with
-fprofile-arcs -ftest-coverage, link against
-lgcov. In addition to each
.ofile, you will have a
- Run your program and cleanly exit it! This will produce a
.gcdafile for each source file.
lcov --base-directory . --directory . --capture --output-file i3.infoto generate an info file.
genhtml -o /tmp/i3-coverage i3.infoto convert that info file to HTML.
1: Changing the compilation flags
This step should be really straight-forward. Make sure the
-fprofile-arcs -ftest-coverage and the
CFLAGS += -fprofile-arcs -ftest-coverage LDFLAGS += -lgcov
2: Run your program
Sounds easy, but be aware that you have to exit your program cleanly! Pressing
Ctrl-C to abort it lead to a situation where no
.gcda files were
generated for me.
3: Run lcov (from CVS)
This one was tricky. At the time of writing,
lcov’s most recent
release is version 1.9. This version has a bug (it uses Perl’s two-parameter
open) which leads to not opening the file
<built-in>.gcov correctly. Get the most recent version from
CVS, which includes a
fix for this.
Afterwards, run the following command:
lcov --base-directory . --directory src --capture --output-file i3.info
--base-directory parameter makes sure that relative filenames
src/render.c) will be found.
Should you do multiple runs of your program, just repeat this command. If you
are done and want to start over with fresh values, run
lcov --directory .
4: Run genhtml
The last step is to convert the
i3.info file to a nice HTML report
with the following command:
genhtml -o /tmp/i3-coverage/ i3.info