Skip to content

Commit 2125b15

Browse files
committed
Added coverage command
1 parent 9dfce38 commit 2125b15

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

CMakeLists.txt

+10-2
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,26 @@ cmake_minimum_required (VERSION 2.8)
22
project(libcbor)
33
include(CTest)
44

5-
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0 -Wall -pedantic -g -ggdb --coverage -DDEBUG=true")
5+
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0 -Wall -pedantic -g -ggdb --coverage -fprofile-arcs -ftest-coverage -DDEBUG=true")
66
set(CMAKE_C_FLAGS_RELEASE "-O3 -Wall -pedantic -DNDEBUG")
77
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11")
88

99

10-
set(CMAKE_EXE_LINKER_FLAGS "-g --coverage")
10+
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "-g --coverage -fprofile-arcs -ftest-coverage")
1111

1212
enable_testing()
1313

1414
set(CTEST_MEMORYCHECK_COMMAND "/usr/bin/valgrind")
1515
set(MEMORYCHECK_COMMAND_OPTIONS "")
1616

17+
add_custom_target(coverage
18+
erb ${CMAKE_CURRENT_SOURCE_DIR}/test/stream_expectations.c.erb > ${CMAKE_CURRENT_SOURCE_DIR}/test/stream_expectations.c
19+
COMMAND ctest
20+
COMMAND lcov --capture --directory . --output-file coverage.info
21+
COMMAND genhtml coverage.info --output-directory coverage_html
22+
COMMAND ${CMAKE_COMMAND} -E remove ${CMAKE_CURRENT_SOURCE_DIR}/test/stream_expectations.c
23+
COMMAND echo "Coverage report ready: file://${CMAKE_CURRENT_BINARY_DIR}/coverage_html/index.html")
24+
1725
include_directories(src)
1826
subdirs(src)
1927
subdirs(demo)

doc/source/tests.rst

+7-1
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,14 @@ Every release is tested for memory correctness. You can run these tests by passi
1919
Code coverage
2020
-------------------
2121

22-
Every release is inspected using `GCOV/LCOV <http://ltp.sourceforge.net/coverage/lcov.php>`_. Platform-independent code should be fully covered by the test suite.
22+
Every release is inspected using `GCOV/LCOV <http://ltp.sourceforge.net/coverage/lcov.php>`_. Platform-independent code should be fully covered by the test suite. Simply run
2323

24+
.. code-block:: bash
25+
26+
make coverage
27+
28+
29+
or alternatively run ``lcov`` by hand using
2430

2531
.. code-block:: bash
2632

0 commit comments

Comments
 (0)