Skip to content

Commit d92d97a

Browse files
committed
Add Scheme coverage collection with option GUILE_COVERAGE.
This can be used with or without COVERAGE, though if without the results will reflect only the Scheme code exercised by the tests.
1 parent 1e85d0b commit d92d97a

File tree

4 files changed

+48
-12
lines changed

4 files changed

+48
-12
lines changed

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ option (WITH_PYTHON "enable python plugin and bindings" OFF)
5555
option (ENABLE_BINRELOC "compile with binary relocation support" ON)
5656
option (DISABLE_NLS "do not use Native Language Support" OFF)
5757
option (COVERAGE "Instrument a Debug or Asan build for coverage reporting" OFF)
58+
option (GUILE_COVERAGE "Compute testing coverage of Scheme code. WARNING: 15X slowdown!" OFF)
5859
option (LEAKS "Report leaks for tests in a non-Apple Asan build." OFF)
5960
option (ODR "Report One Definition Rule violations in tests in a non-Apple Asan build." OFF)
6061
# ############################################################
@@ -627,7 +628,7 @@ elseif(UNIX)
627628
set(ASAN_DYNAMIC_LIB_ENV LD_PRELOAD=${PRELOADS})
628629
endif ()
629630
set(ASAN_LINK_OPTIONS -fsanitize=address -fsanitize=undefined)
630-
if (COVERAGE)
631+
if (COVERAGE OR GUILE_COVERAGE)
631632
include(GncCoverage)
632633
endif()
633634
if (COVERAGE)

bindings/guile/test/srfi64-extras.scm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,5 @@
4545
(lambda (runner)
4646
(format #t "Source:~a\npass = ~a, fail = ~a\n"
4747
(test-result-ref runner 'source-file) num-passed num-failed)
48-
(exit (zero? num-failed))))
48+
(zero? num-failed)))
4949
runner))

common/cmake_modules/GncAddTest.cmake

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ function(get_guile_env)
3434
set(guile_load_paths "")
3535
list(APPEND guile_load_paths "${CMAKE_BINARY_DIR}/${GUILE_REL_SITEDIR}")
3636
list(APPEND guile_load_paths "${CMAKE_BINARY_DIR}/${GUILE_REL_SITEDIR}/gnucash/deprecated") # Path to gnucash' deprecated modules
37+
if (GUILE_COVERAGE)
38+
list(APPEND guile_load_paths "${CMAKE_BINARY_DIR}/${GUILE_REL_SITEDIR}/gnucash")
39+
list(APPEND guile_load_paths "${CMAKE_BINARY_DIR}/${GUILE_REL_SITEDIR}/gnucash/report")
40+
list(APPEND guile_load_paths "${CMAKE_BINARY_DIR}/${GUILE_REL_SITEDIR}/gnucash/reports")
41+
list(APPEND guile_load_paths "${CMAKE_BINARY_DIR}/${GUILE_REL_SITEDIR}/gnucash/engine")
42+
list(APPEND guile_load_paths "${CMAKE_BINARY_DIR}/${GUILE_REL_SITEDIR}/gnucash/app-utils")
43+
list(APPEND guile_load_paths "${CMAKE_BINARY_DIR}/${GUILE_REL_SITEDIR}/gnucash/qif-import")
44+
45+
endif()
3746
set(guile_load_path "${guile_load_paths}")
3847

3948
set(guile_load_compiled_paths "")
@@ -103,20 +112,46 @@ function(gnc_add_test_with_guile _TARGET _SOURCE_FILES TEST_INCLUDE_VAR_NAME TES
103112
)
104113
endfunction()
105114

106-
107115
function(gnc_add_scheme_test _TARGET _SOURCE_FILE)
108-
add_test(NAME ${_TARGET} COMMAND ${GUILE_EXECUTABLE} --debug -c "
109-
(set! %load-hook
116+
if (GUILE_COVERAGE)
117+
add_test(NAME ${_TARGET} COMMAND ${GUILE_EXECUTABLE} --debug -c "
118+
(set! %load-hook
110119
(lambda (filename)
111-
(when (and filename
112-
(string-contains filename \"${GUILE_REL_SITEDIR}\")
113-
(not (string-prefix? \"${CMAKE_BINARY_DIR}\" filename)))
120+
(when (and filename
121+
(string-contains filename \"${GUILE_REL_SITEDIR}\")
122+
(not (string-prefix? \"${CMAKE_BINARY_DIR}\" filename)))
114123
(format #t \"%load-path = ~s~%\" %load-path)
115124
(format #t \"%load-compiled-path = ~s~%\" %load-compiled-path)
116125
(error \"Loading guile/site file from outside build tree!\" filename))))
117-
(load-from-path \"${_TARGET}\")
118-
(exit (run-test))"
119-
)
126+
(load-from-path \"${_TARGET}\")
127+
(use-modules (system vm coverage)
128+
(system vm vm))
129+
(call-with-values (lambda ()
130+
(with-code-coverage
131+
(lambda ()
132+
(run-test))))
133+
134+
(lambda (data result)
135+
(let ((port (open-output-file \"${coverage_dir}/${_TARGET}_results.info\")))
136+
(coverage-data->lcov data port)
137+
(close port))
138+
(exit result)))
139+
"
140+
)
141+
else()
142+
add_test(NAME ${_TARGET} COMMAND ${GUILE_EXECUTABLE} --debug -c "
143+
(set! %load-hook
144+
(lambda (filename)
145+
(when (and filename
146+
(string-contains filename \"${GUILE_REL_SITEDIR}\")
147+
(not (string-prefix? \"${CMAKE_BINARY_DIR}\" filename)))
148+
(format #t \"%load-path = ~s~%\" %load-path)
149+
(format #t \"%load-compiled-path = ~s~%\" %load-compiled-path)
150+
(error \"Loading guile/site file from outside build tree!\" filename))))
151+
(load-from-path \"${_TARGET}\")
152+
(exit (run-test))"
153+
)
154+
endif()
120155
get_guile_env()
121156
set_tests_properties(${_TARGET} PROPERTIES ENVIRONMENT "${GUILE_ENV}$<$<CONFIG:Asan>:;${ASAN_DYNAMIC_LIB_ENV};ASAN_OPTIONS=${ASAN_TEST_OPTIONS}>;${ARGN}>")
122157
endfunction()

common/cmake_modules/GncCoverage.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# --branch-coverage; to ensure branch info is saved
1515
# --demangle-cpp; requires c++filt
1616

17-
if (COVERAGE)
17+
if (COVERAGE OR GUILE_COVERAGE)
1818
find_program(LCOV lcov)
1919
find_program(GENINFO geninfo)
2020
find_program(GENHTML genhtml)

0 commit comments

Comments
 (0)