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 CEF7754C63C; Tue, 25 Jul 2023 16:53:22 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org CEF7754C63C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1690293202; bh=Zvr+n09dvuEGOxB9lgG7qG1oKvHxcQgp8hlVq79ND2c=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=CePE9YDChUnn3eo76EOfYyQYHMjZizyAH9rbfcn966c5TnbOab5pKjMJR48IyU1sc EwWonoxdqisrRt14vsc8aIbI0OeSiU9pajFoXFW8HZq8/JqYP/ggKxm/9xC0+qO/IN OFGOuAlUtszthl4uTn198hgcUX+IdwLGmraUD7pU= Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.51]) (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 62FA150D8D2 for ; Tue, 25 Jul 2023 16:53:21 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 62FA150D8D2 Received: by mail-lf1-f51.google.com with SMTP id 2adb3069b0e04-4f95bf5c493so8528655e87.3 for ; Tue, 25 Jul 2023 06:53:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690293200; x=1690898000; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=EUKVjR1g/wCTc6e91ZXSxynQSS7dULVjBKxspQqziJc=; b=jatMPypdV+mGc2PRS9Kum13J1mR3u1VISgvXlpysEkant2rbtNJkE/TaoD1BFxxF1n XUUBPXqlcofQKOm8RCN6rg/DBCCTIBQwh/5P3Ac2giaH6TPeAPaCgWGZ3Gt78cDu7WxY b1xOHr6ipn6X4icmKuFijWaDgsV7aqvknNMMXxDYz4wCCUWG6JuR69LeKbj91MspyXUw vXvWPTFhNioUWJ7upcB/0yEt8DE5dQ3XbDCZBHaKIuTa9i8YbTU5kGfMQ2NwGNMhiVkc a5Pr07xdk4B9AwZCe+1xMe49yIe5CpBxEGaCQxNq+a7f20o8yYbn8itPJQhvFDe3kW2z ouYg== X-Gm-Message-State: ABy/qLaeDToyEP2vM8qAcxDm8TDHIZcYnhIVqX19czJLEEUdLc42PzxU pfsyA0CLkA9JoObwNzbKmENsc5CEZi0= X-Google-Smtp-Source: APBJJlFbZt8CSTMDwnLQknTzV9ctQ3+30uJYsKsOrKYKGZMb+Ru9zJWFPlLn/vDv6DimFDOsi7q5CQ== X-Received: by 2002:ac2:5e24:0:b0:4fe:958:88ac with SMTP id o4-20020ac25e24000000b004fe095888acmr867176lfg.6.1690293200001; Tue, 25 Jul 2023 06:53:20 -0700 (PDT) Received: from pony.mail.msk ([2a00:1148:b0ba:16:37e9:bf80:d77e:ff11]) by smtp.gmail.com with ESMTPSA id d27-20020ac2545b000000b004fe08164362sm252401lfn.136.2023.07.25.06.53.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jul 2023 06:53:19 -0700 (PDT) To: tarantool-patches@dev.tarantool.org, Sergey Kaplun , max.kokryashkin@gmail.com Date: Tue, 25 Jul 2023 16:52:24 +0300 Message-Id: <4a26e6a1f06191178c385a1df62d61763a5743e3.1690293120.git.sergeyb@tarantool.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH] 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]. CMake target LuaJIT-coverage executes regression tests, proccess *.gcno and *.gcda files with gcov, builds detailed HTML report and prints summary about code coverage. ``` $ cmake -S . -B build -DENABLE_COVERAGE=ON $ cmake --build build --parallel $ cmake --build build --target LuaJIT-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 ++++++ test/CMakeLists.txt | 40 +++++++++++++++++++++++++++ test/tarantool-c-tests/CMakeLists.txt | 2 +- 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6ef24bba..8bc63b90 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -116,6 +116,15 @@ if(LUAJIT_ENABLE_WARNINGS) ) endif() +set(ENABLE_COVERAGE_DEFAULT OFF) +option(ENABLE_COVERAGE "Enable integration with gcovr, a code coverage program" ${ENABLE_COVERAGE_DEFAULT}) +if (ENABLE_COVERAGE) + AppendFlags(CMAKE_C_FLAGS + -fprofile-arcs + -ftest-coverage + ) +endif() + # Auxiliary flags for main targets (libraries, binaries). AppendFlags(TARGET_C_FLAGS -D_FILE_OFFSET_BITS=64 diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 47296a22..9b0f11d8 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -59,6 +59,44 @@ add_custom_target(${PROJECT_NAME}-test DEPENDS tarantool-tests ) +find_program(GCOVR gcovr) +find_program(GCOV gcov) +set(COVERAGE_HTML_REPORT "luajit-coverage.html") +set(COVERAGE_JSON_REPORT "luajit-coverage.json") +if(ENABLE_COVERAGE) + if(NOT GCOVR OR NOT GCOV) + add_custom_target(${PROJECT_NAME}-coverage) + add_custom_command(TARGET ${PROJECT_NAME}-coverage + COMMENT "Either `gcovr' or `gcov` not found, so ${PROJECT_NAME}-coverage target is dummy" + ) + return() + endif() + + 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} + --filter ${PROJECT_SOURCE_DIR}/src + --print-summary + --output ${COVERAGE_HTML_REPORT} + --coveralls ${COVERAGE_JSON_REPORT} + --html + --html-title "LuaJIT Code Coverage Report" + --html-details + --sort-percentage + --branches + --decisions + --verbose + -j ${CMAKE_BUILD_PARALLEL_LEVEL} + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} + ) + message(STATUS "Code coverage HTML report: ${COVERAGE_HTML_REPORT}") + message(STATUS "Code coverage JSON report: ${COVERAGE_JSON_REPORT}") +endif(ENABLE_COVERAGE) + if(LUAJIT_USE_TEST) if(POLICY CMP0037) if(CMAKE_VERSION VERSION_LESS 3.11) @@ -76,4 +114,6 @@ if(LUAJIT_USE_TEST) ${PROJECT_NAME}-test ${PROJECT_NAME}-luacheck ) + + add_dependencies(${PROJECT_NAME}-coverage ${PROJECT_NAME}-test) endif() diff --git a/test/tarantool-c-tests/CMakeLists.txt b/test/tarantool-c-tests/CMakeLists.txt index 17255345..8cd76b44 100644 --- a/test/tarantool-c-tests/CMakeLists.txt +++ b/test/tarantool-c-tests/CMakeLists.txt @@ -45,7 +45,7 @@ foreach(test_source ${tests}) OUTPUT_NAME "${exe}${C_TEST_SUFFIX}" RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" ) - target_link_libraries(${exe} libtest ${LUAJIT_LIBRARY}) + target_link_libraries(${exe} libtest ${LUAJIT_LIBRARY} --coverage) LIST(APPEND TESTS_COMPILED ${exe}) endforeach() -- 2.34.1