Commit 6f856172 authored by Viktor Porvaznik's avatar Viktor Porvaznik Committed by Viktor Porvaznik

More work on coverage

parent 678e4f7c
......@@ -129,7 +129,42 @@ if(KF5DocTools_FOUND)
endif()
if(BUILD_TESTING AND NOT SAILFISHOS)
include(ECMCoverageOption)
set(BUILD_COVERAGE 1)
# Clean the coverage and generated HTML output
file(REMOVE_RECURSE ${CMAKE_BINARY_DIR}/tests/coverage)
file(REMOVE_RECURSE ${CMAKE_BINARY_DIR}/tests/html)
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/tests/coverage)
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/tests/html)
add_custom_target(coverage_wrappers
ALL)
add_subdirectory(tests)
# add_subdirectory(filesyncapp/daemon/tests/singleton_pool_test)e
set(generate_coverage_html_deps "" CACHE string "List of unit tests to generate coverage for" FORCE)
file(GLOB all_unit_tests */**/tests/*)
foreach(unit_test ${all_unit_tests})
message("Processing unit test ${unit_test}")
add_subdirectory(${unit_test})
endforeach()
message(" .......... ${generate_coverage_html_deps}")
file(GLOB coverage_info "${CMAKE_BINARY_DIR}/tests/coverage")
message(${coverage_info})
#${CMAKE_BINARY_DIR}/tests/coverage
#$\(ls .\)
add_custom_target(generate_coverage_html
ALL
DEPENDS coverage_wrappers
COMMAND lcov "${generate_coverage_html_deps}" --output-file "${CMAKE_BINARY_DIR}/tests/kdeconnect.info"
COMMAND genhtml --legend -s -o "${CMAKE_BINARY_DIR}/tests/html" "${CMAKE_BINARY_DIR}/tests/kdeconnect.info")
# add_dependencies(generate_coverage_html singleton_pool_test_coverage_wrapper index_test_coverage_wrapper)
endif()
feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES)
......@@ -6,3 +6,27 @@
function(kdeconnect_add_plugin)
kcoreaddons_add_plugin(${ARGN} INSTALL_NAMESPACE kdeconnect)
endfunction()
function(add_to_coverage test_name class_under_test)
set(class_to_extract "*\\/${class_under_test}.*")
add_custom_target(${test_name}_coverage_wrapper
DEPENDS ${test_name}
COMMAND echo "Running unit test ${test_name}"
COMMAND ${CMAKE_BINARY_DIR}/bin/${test_name}
COMMAND echo "Processing gcov data for the unit test ${test_name}"
COMMAND lcov --directory ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${test_name}.dir/ --capture --output-file ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${test_name}.dir/gcov.info
COMMAND lcov --extract ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${test_name}.dir/gcov.info ${class_to_extract} --output-file ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${test_name}.dir/${test_name}.info
COMMAND cp ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${test_name}.dir/${test_name}.info ${CMAKE_BINARY_DIR}/tests/coverage/
)
add_dependencies(coverage_wrappers "${test_name}_coverage_wrapper")
# add_custom_target(
# "coverage_for_${test_name}" ALL DEPENDS gen
# )
set(generate_coverage_html_deps "${generate_coverage_html_deps} --add-tracefile ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${test_name}.dir/${test_name}.info" CACHE string "List of unit tests to generate coverage for" FORCE)
# add_dependencies(generate_coverage_html "generate_coverage_for_${test_name}")
# message(" .......... ${generate_coverage_html_deps}")
endfunction()
......@@ -23,29 +23,3 @@ target_link_libraries(kdeconnect-filesync-daemon
)
install(TARGETS kdeconnect-filesync-daemon ${INSTALL_TARGETS_DEFAULT_ARGS})
# Add tests
include(ECMCoverageOption)
set(BUILD_COVERAGE 1)
file(REMOVE_RECURSE ${CMAKE_BINARY_DIR}/tests/coverage)
file(REMOVE_RECURSE ${CMAKE_BINARY_DIR}/tests/html)
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/tests/coverage)
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/tests/html)
function(prepare_to_extract_coverage_data test_name class_under_test)
set(class_to_extract *${class_under_test}.*)
find_program(test_target ${class_under_test})
add_custom_command(TARGET ${test_target}
POST_BUILD
COMMAND echo "Processing gcov data ..."
COMMAND lcov --directory ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${test_name}.dir/ --capture --output-file ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${test_name}.dir/gcov.info
COMMAND lcov --extract ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${test_name}.dir/gcov.info ${class_to_extract} --output-file ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${test_name}.dir/${test_name}.info
COMMAND lcov --add-tracefile ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${test_name}.dir/${test_name}.info --output-file ${CMAKE_BINARY_DIR}/tests/coverage/kdeconnect.info
COMMAND genhtml --legend -s -o ${CMAKE_BINARY_DIR}/tests/html/ ${CMAKE_BINARY_DIR}/tests/coverage/kdeconnect.info)
endfunction()
add_subdirectory(tests/singleton_pool_test)
add_subdirectory(tests/index_test)
\ No newline at end of file
......@@ -29,4 +29,4 @@ ecm_add_test(
../../index.cpp
index_test.cpp LINK_LIBRARIES ${kdeconnect_libraries} TEST_NAME index_test)
prepare_to_extract_coverage_data("index_test" "index")
\ No newline at end of file
add_to_coverage("index_test" "index")
\ No newline at end of file
......@@ -38,6 +38,12 @@ namespace FileSync
{
m_index = &Index::instance("testIndos");
// m_testDeviceId = "testDeviceId";
// QString testIndexPath = QDir::currentPath() +
// "/../sync_index_test/test_resources/sync_db.json";
......
......@@ -26,4 +26,4 @@ ecm_add_test(
../../index.cpp
singleton_pool_test.cpp LINK_LIBRARIES ${kdeconnect_libraries} TEST_NAME singleton_pool_test)
prepare_to_extract_coverage_data("singleton_pool_test" "singleton_pool")
add_to_coverage("singleton_pool_test" "singleton_pool")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment