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.
This commit is contained in:
John Ralls 2023-12-05 17:00:52 -08:00
parent 1e85d0b115
commit d92d97aef6
4 changed files with 48 additions and 12 deletions

View File

@ -55,6 +55,7 @@ option (WITH_PYTHON "enable python plugin and bindings" OFF)
option (ENABLE_BINRELOC "compile with binary relocation support" ON)
option (DISABLE_NLS "do not use Native Language Support" OFF)
option (COVERAGE "Instrument a Debug or Asan build for coverage reporting" OFF)
option (GUILE_COVERAGE "Compute testing coverage of Scheme code. WARNING: 15X slowdown!" OFF)
option (LEAKS "Report leaks for tests in a non-Apple Asan build." OFF)
option (ODR "Report One Definition Rule violations in tests in a non-Apple Asan build." OFF)
# ############################################################
@ -627,7 +628,7 @@ elseif(UNIX)
set(ASAN_DYNAMIC_LIB_ENV LD_PRELOAD=${PRELOADS})
endif ()
set(ASAN_LINK_OPTIONS -fsanitize=address -fsanitize=undefined)
if (COVERAGE)
if (COVERAGE OR GUILE_COVERAGE)
include(GncCoverage)
endif()
if (COVERAGE)

View File

@ -45,5 +45,5 @@
(lambda (runner)
(format #t "Source:~a\npass = ~a, fail = ~a\n"
(test-result-ref runner 'source-file) num-passed num-failed)
(exit (zero? num-failed))))
(zero? num-failed)))
runner))

View File

@ -34,6 +34,15 @@ function(get_guile_env)
set(guile_load_paths "")
list(APPEND guile_load_paths "${CMAKE_BINARY_DIR}/${GUILE_REL_SITEDIR}")
list(APPEND guile_load_paths "${CMAKE_BINARY_DIR}/${GUILE_REL_SITEDIR}/gnucash/deprecated") # Path to gnucash' deprecated modules
if (GUILE_COVERAGE)
list(APPEND guile_load_paths "${CMAKE_BINARY_DIR}/${GUILE_REL_SITEDIR}/gnucash")
list(APPEND guile_load_paths "${CMAKE_BINARY_DIR}/${GUILE_REL_SITEDIR}/gnucash/report")
list(APPEND guile_load_paths "${CMAKE_BINARY_DIR}/${GUILE_REL_SITEDIR}/gnucash/reports")
list(APPEND guile_load_paths "${CMAKE_BINARY_DIR}/${GUILE_REL_SITEDIR}/gnucash/engine")
list(APPEND guile_load_paths "${CMAKE_BINARY_DIR}/${GUILE_REL_SITEDIR}/gnucash/app-utils")
list(APPEND guile_load_paths "${CMAKE_BINARY_DIR}/${GUILE_REL_SITEDIR}/gnucash/qif-import")
endif()
set(guile_load_path "${guile_load_paths}")
set(guile_load_compiled_paths "")
@ -103,20 +112,46 @@ function(gnc_add_test_with_guile _TARGET _SOURCE_FILES TEST_INCLUDE_VAR_NAME TES
)
endfunction()
function(gnc_add_scheme_test _TARGET _SOURCE_FILE)
add_test(NAME ${_TARGET} COMMAND ${GUILE_EXECUTABLE} --debug -c "
(set! %load-hook
if (GUILE_COVERAGE)
add_test(NAME ${_TARGET} COMMAND ${GUILE_EXECUTABLE} --debug -c "
(set! %load-hook
(lambda (filename)
(when (and filename
(string-contains filename \"${GUILE_REL_SITEDIR}\")
(not (string-prefix? \"${CMAKE_BINARY_DIR}\" filename)))
(when (and filename
(string-contains filename \"${GUILE_REL_SITEDIR}\")
(not (string-prefix? \"${CMAKE_BINARY_DIR}\" filename)))
(format #t \"%load-path = ~s~%\" %load-path)
(format #t \"%load-compiled-path = ~s~%\" %load-compiled-path)
(error \"Loading guile/site file from outside build tree!\" filename))))
(load-from-path \"${_TARGET}\")
(exit (run-test))"
)
(load-from-path \"${_TARGET}\")
(use-modules (system vm coverage)
(system vm vm))
(call-with-values (lambda ()
(with-code-coverage
(lambda ()
(run-test))))
(lambda (data result)
(let ((port (open-output-file \"${coverage_dir}/${_TARGET}_results.info\")))
(coverage-data->lcov data port)
(close port))
(exit result)))
"
)
else()
add_test(NAME ${_TARGET} COMMAND ${GUILE_EXECUTABLE} --debug -c "
(set! %load-hook
(lambda (filename)
(when (and filename
(string-contains filename \"${GUILE_REL_SITEDIR}\")
(not (string-prefix? \"${CMAKE_BINARY_DIR}\" filename)))
(format #t \"%load-path = ~s~%\" %load-path)
(format #t \"%load-compiled-path = ~s~%\" %load-compiled-path)
(error \"Loading guile/site file from outside build tree!\" filename))))
(load-from-path \"${_TARGET}\")
(exit (run-test))"
)
endif()
get_guile_env()
set_tests_properties(${_TARGET} PROPERTIES ENVIRONMENT "${GUILE_ENV}$<$<CONFIG:Asan>:;${ASAN_DYNAMIC_LIB_ENV};ASAN_OPTIONS=${ASAN_TEST_OPTIONS}>;${ARGN}>")
endfunction()

View File

@ -14,7 +14,7 @@
# --branch-coverage; to ensure branch info is saved
# --demangle-cpp; requires c++filt
if (COVERAGE)
if (COVERAGE OR GUILE_COVERAGE)
find_program(LCOV lcov)
find_program(GENINFO geninfo)
find_program(GENHTML genhtml)