From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 98BB93A4690; Tue, 1 Aug 2023 21:48:52 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 98BB93A4690 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1690915732; bh=lM88bV0o+QKj1UE2ZegiQi5vg995IpX+gArREstZ9RE=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=dQQviPgEOk3JmHKFd5rUuU6xZE/F+o0l6wMzuNvU1pMtJqJSKgYrDZVUCPymhDV4J 5hq3lSrcw/JTrmKjFQpi4J1Tr4H3yWhxXUEQGqBWaYRm9GJiOs2p7w6ucX7EITl9di 3O8NzhfLcUzak2WUY1ppSP7ThnzJpewjts8Pik7Q= Received: from mail-lj1-f180.google.com (mail-lj1-f180.google.com [209.85.208.180]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 1B6303A4690 for ; Tue, 1 Aug 2023 21:48:31 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 1B6303A4690 Received: by mail-lj1-f180.google.com with SMTP id 38308e7fff4ca-2b9338e4695so91080471fa.2 for ; Tue, 01 Aug 2023 11:48:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690915710; x=1691520510; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4oc+/aDa+nBT8fsJHZNc/QDszv4op0+5GJ7n5Mo2JWs=; b=cbFJV6bScALCfbkkDXNXryBqCji36Og7+ZkvT237k4ew0I0hLdGCBRgLEtlZvo7IrH 09aywwE4icz0xxzu2zAxSO4O1wPdJGhU3wRWt/fL6Fn2S0J6WEvFZ4CX3leC+axYL5bg 8/w3a+LOtvVqJTMtG2G+6tPaV11KSM2aCSz2aRGsVgWsDLrHtyMEIOY8BXTg9r2tFRb/ kxE0wUOKGa0hKP+pBWMQB9wU19q+hQG+ATdrONtnxDX8H6YHuvpv6K2F7e5aDEMPsmz4 +1rQ1tDLh0t9fCOCi9Pfu6AO9MQXZ/i0HUftgajMftUu7dxUOJxod25vFeX2VA08XdQJ Thfg== X-Gm-Message-State: ABy/qLagxVfchmAdlz5qNAKg361KNMNyeAlXI/BmQXiXmk40CWH+znvB quTSLAa9De+RYld7O4zVKlNZ7haAmn8= X-Google-Smtp-Source: APBJJlF4CTnCCY68Zf8uR0raaaCMtuHRJx0DcVlG+op63gmyuQIuJUJKZi+53snO8TRHhRxr3GrFRw== X-Received: by 2002:a2e:9884:0:b0:2b9:c5fd:d649 with SMTP id b4-20020a2e9884000000b002b9c5fdd649mr3125080ljj.24.1690915709985; Tue, 01 Aug 2023 11:48:29 -0700 (PDT) Received: from pony.bronevichok.ru ([79.164.223.111]) by smtp.gmail.com with ESMTPSA id t22-20020a2e9c56000000b002b9c0822951sm3188867ljj.119.2023.08.01.11.48.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Aug 2023 11:48:29 -0700 (PDT) To: tarantool-patches@dev.tarantool.org, Sergey Kaplun , max.kokryashkin@gmail.com Date: Tue, 1 Aug 2023 21:46:08 +0300 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH 1/2 v2] cmake: add code coverage support X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Sergey Bronnikov via Tarantool-patches Reply-To: Sergey Bronnikov Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" From: Sergey Bronnikov The patch adds building code coverage report using gcovr [1] and gcov. gcovr is a better version of lcov, see [2]. There were two new CMake targets added: LuaJIT-coverage proccess *.gcno and *.gcda files with gcov, builds a detailed HTML report and prints a summary, target coverage executes LuaJIT-tests and then runs LuaJIT-coverage. Target LuaJIT-coverage is useful for building code coverage report for a custom set of regression tests. ``` $ cmake -S . -B build -DENABLE_COVERAGE=ON $ cmake --build build --parallel --target coverage lines: 84.1% (26056 out of 30997) functions: 88.8% (2055 out of 2314) branches: 71.5% (14801 out of 20703) ``` 1. https://gcovr.com/ 2. https://gcovr.com/en/stable/faq.html#what-is-the-difference-between-lcov-and-gcovr --- CMakeLists.txt | 9 ++++++ cmake/CodeCoverage.cmake | 45 +++++++++++++++++++++++++++ test/CMakeLists.txt | 7 +++++ test/tarantool-c-tests/CMakeLists.txt | 6 +++- 4 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 cmake/CodeCoverage.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 6ef24bba..fe6582fa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -116,6 +116,15 @@ if(LUAJIT_ENABLE_WARNINGS) ) endif() +set(LUAJIT_ENABLE_COVERAGE_DEFAULT OFF) +option(LUAJIT_ENABLE_COVERAGE + "Enable integration with gcovr, a code coverage program" + ${LUAJIT_ENABLE_COVERAGE_DEFAULT}) +if (LUAJIT_ENABLE_COVERAGE) + AppendFlags(CMAKE_C_FLAGS --coverage) + include(CodeCoverage) +endif(LUAJIT_ENABLE_COVERAGE) + # Auxiliary flags for main targets (libraries, binaries). AppendFlags(TARGET_C_FLAGS -D_FILE_OFFSET_BITS=64 diff --git a/cmake/CodeCoverage.cmake b/cmake/CodeCoverage.cmake new file mode 100644 index 00000000..2be7d129 --- /dev/null +++ b/cmake/CodeCoverage.cmake @@ -0,0 +1,45 @@ +find_program(GCOVR gcovr) +find_program(GCOV gcov) + +set(COVERAGE_DIR "${PROJECT_BINARY_DIR}/coverage") +set(COVERAGE_HTML_REPORT "${COVERAGE_DIR}/luajit.html") +set(COVERAGE_XML_REPORT "${COVERAGE_DIR}/luajit.xml") + +if(NOT GCOVR OR NOT GCOV) + add_custom_target(${PROJECT_NAME}-coverage + COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --red "LuaJIT-coverage is a dummy target" + ) + message(WARNING "Either `gcovr' or `gcov` not found, \ +so ${PROJECT_NAME}-coverage target is dummy") + return() +endif() + +file(MAKE_DIRECTORY ${COVERAGE_DIR}) +add_custom_target(${PROJECT_NAME}-coverage) +add_custom_command(TARGET ${PROJECT_NAME}-coverage + COMMENT "Building coverage report" + COMMAND + ${GCOVR} + # See https://gcovr.com/en/stable/guide/configuration.html + --root ${PROJECT_SOURCE_DIR} + --object-directory ${PROJECT_BINARY_DIR} + --filter ${PROJECT_SOURCE_DIR}/src + # Exclude DynASM files, that contain a low-level VM code for CPUs. + --exclude ".*\.dasc" + # Exclude buildvm source code, it's the project's infrastructure. + --exclude ".*/host/" + --print-summary + --output ${COVERAGE_HTML_REPORT} + --cobertura ${COVERAGE_XML_REPORT} + --html + --html-title "Tarantool LuaJIT Code Coverage Report" + --html-details + --sort-percentage + --branches + --decisions + -j ${CMAKE_BUILD_PARALLEL_LEVEL} + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} +) + +message(STATUS "Code coverage HTML report: ${COVERAGE_HTML_REPORT}") +message(STATUS "Code coverage XML report: ${COVERAGE_XML_REPORT}") diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 47296a22..e23d6d45 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -76,4 +76,11 @@ if(LUAJIT_USE_TEST) ${PROJECT_NAME}-test ${PROJECT_NAME}-luacheck ) + + if (LUAJIT_ENABLE_COVERAGE) + add_custom_target(coverage DEPENDS + ${PROJECT_NAME}-test + ${PROJECT_NAME}-coverage + ) + endif (LUAJIT_ENABLE_COVERAGE) endif() diff --git a/test/tarantool-c-tests/CMakeLists.txt b/test/tarantool-c-tests/CMakeLists.txt index 17255345..d74e99fc 100644 --- a/test/tarantool-c-tests/CMakeLists.txt +++ b/test/tarantool-c-tests/CMakeLists.txt @@ -45,7 +45,11 @@ foreach(test_source ${tests}) OUTPUT_NAME "${exe}${C_TEST_SUFFIX}" RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" ) - target_link_libraries(${exe} libtest ${LUAJIT_LIBRARY}) + set(libtest-libs libtest ${LUAJIT_LIBRARY}) + if (LUAJIT_ENABLE_COVERAGE) + set(libtest-libs ${libtest-libs} --coverage) + endif (LUAJIT_ENABLE_COVERAGE) + target_link_libraries(${exe} ${libtest-libs}) LIST(APPEND TESTS_COMPILED ${exe}) endforeach() -- 2.34.1