~aleteoryx/muditaos

ref: 9ba4d8cea949692768b4cbb0042fad7999362faa muditaos/cmake/modules/PureCoverage.cmake -rw-r--r-- 2.8 KiB
9ba4d8ce — Lukasz Mastalerz [BH-1838] Relaxation plays in the background for certain song lengths 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
option(COVERAGE_ENABLE "Enable code coverage report generation")

if(COVERAGE_ENABLE)
    if(NOT (${PROJECT_TARGET_NAME} STREQUAL "linux" AND ${CMAKE_BUILD_TYPE} STREQUAL "Debug"))
        message(FATAL_ERROR "Coverage generation is supported for the Linux/Debug configuration only")
    endif()

    include(CodeCoverage)
    include(ProcessorCount)

    append_coverage_compiler_flags()

    ProcessorCount(N)
    if (NOT N EQUAL 0)
        set(COVERAGE_PARALLEL_JOBS -j ${N})
    endif()

    set(COVERAGE_EXCLUDES
        .*/test/.*
        .*/tests/.*
        .*/thirdparty/.*
        .*/third-party/.*
        board/linux/libiosyscalls/.*
        host-tools/.*
        module-audio/Audio/decoder/dr_flac.h
        module-bluetooth/Bluetooth/glucode/.*
        module-bluetooth/lib/.*
        module-db/Database/sqlite3.c
        module-lwip/lib/.*
        module-os/.*
        source/main.cpp
        test/.*
    )

    SET(GCOVR_ADDITIONAL_ARGS
        --exclude-throw-branches
        --print-summary
        ${COVERAGE_PARALLEL_JOBS}
    )

    # target to cleanup gcda's from the previous run
    add_custom_target(
        coverage-cleanup
        COMMAND find . -name "*.gcda" -delete
        WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
        COMMENT "Cleaning up coverage data files"
    )

    # full HTML report with a test run
    setup_target_for_coverage_gcovr_html(
        NAME coverage-all-html
        EXECUTABLE ${CMAKE_CTEST_COMMAND}
        DEPENDENCIES unittests coverage-cleanup
    )

    # html report without running any ctest command
    setup_target_for_coverage_gcovr_html(
        NAME coverage-html
        EXECUTABLE ;
        DEPENDENCIES ""
    )

    # cobertura report without running any ctest command
    setup_target_for_coverage_gcovr_xml(
        NAME coverage
        EXECUTABLE ;
        DEPENDENCIES ""
    )
endif()

function(enable_entity_coverage)
    if(COVERAGE_ENABLE)
        cmake_parse_arguments(
            _ARGS
            ""
            "NAME;COVERAGE_PATH"
            ""
            ${ARGN}
        )

        message("Enabling coverage reporting for test entity: ${_ARGS_NAME} (${PROJECT_NAME})")

        if(_ARGS_COVERAGE_PATH)
            set(GCOVR_ADDITIONAL_ARGS ${GCOVR_ADDITIONAL_ARGS} -f ${_ARGS_COVERAGE_PATH})
        endif()

        setup_target_for_coverage_gcovr_html(
            NAME coverage-${_ARGS_NAME}-html
            EXECUTABLE ;
            DEPENDENCIES ""
        )

        setup_target_for_coverage_gcovr_xml(
            NAME coverage-${_ARGS_NAME}
            EXECUTABLE ;
            DEPENDENCIES ""
        )

        add_dependencies(coverage-${_ARGS_NAME}-html check-${_ARGS_NAME})
        add_dependencies(coverage-${_ARGS_NAME} check-${_ARGS_NAME})
        add_dependencies(check-${_ARGS_NAME} coverage-cleanup)
    endif()
endfunction(enable_entity_coverage)