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 C9835559602; Wed, 2 Aug 2023 11:06:50 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org C9835559602 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1690963610; bh=FFAN8oGmGzspe3PSYhWykX3eMa8MveNnlacm0XfiuQ4=; h=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=s6mjpSk7We90rtdsaQ2Bhifvr3dqQshZQyyhPS1QL6PX8ZBbe2e36wij43mGTGua/ DIm8Ul2zEjw0TNlKuNAqOfvxbDr1aHWuUmkTXl2R6d/HSf3AkPv9qXZX2J1QX/iTxh IhhYkCMGiHtYrY/Jhnk1bmX+R5L+3ZUjMrBszrzk= Received: from smtp35.i.mail.ru (smtp35.i.mail.ru [95.163.41.76]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 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 DD84F520C42 for ; Wed, 2 Aug 2023 11:06:49 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org DD84F520C42 Received: by smtp35.i.mail.ru with esmtpa (envelope-from ) id 1qR6sa-008HjW-2n; Wed, 02 Aug 2023 11:06:49 +0300 Date: Wed, 2 Aug 2023 11:06:48 +0300 To: Sergey Bronnikov Message-ID: <27qwncp6oubrmexp6bwsur5nnm5xnlxaby3slxk4rrk2beyuin@5wtqxgcetnfk> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD93761F2630DFFAF41A06C3F00224CE1B2857C7744A811472E182A05F53808504010062CAEB4232E5BD20D439E7587CA7C6AA42B8531CE0554550F147DA54E8300 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE721D130CF676D2164EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006378D70459436292EC88638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8C8CC3DEB4B6934C1673667C0A3A643DA117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC3A703B70628EAD7BA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F4460429728776938767073520437C869540D2AB0F28451B159A507268D2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EEB28585415E75ADA91B780A39BCC1DD35D8FC6C240DEA76429C9F4D5AE37F343AA9539A8B242431040A6AB1C7CE11FEE3AD74539164518AE5302FCEF25BFAB345C4224003CC836476E2F48590F00D11D6E2021AF6380DFAD1A18204E546F3947CD2DCF9CF1F528DBC2E808ACE2090B5E1725E5C173C3A84C327ED053E960B195E089D37D7C0E48F6C8AA50765F7900637A7EFCB0EB5ACB161EFF80C71ABB335746BA297DBC24807EABDAD6C7F3747799A X-C1DE0DAB: 0D63561A33F958A5337ABF161BCCE0187BC8C81955F88BF1CC8C7CF9C121AC2DF87CCE6106E1FC07E67D4AC08A07B9B0AD74539164518AE5CB5012B2E24CD356 X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF3FED46C3ACD6F73ED3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CF79EC8DE2EA6FF5C49A861BDABC7E947816437AD2D39C0F4915026EE069F64F8F6238D603D2F19CCF8553022043D0BC9AFF449727C60930BAD6F6E5A1B938519AA74DFFEFA5DC0E7F02C26D483E81D6BE64ACE4A408B72B61B0CA6F94E606A667A52EF62A646584F811BD90D3D42C882D43082AE146A756F3 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojV0vAgLNnFufBRQFStol9vA== X-Mailru-Sender: 7940E2A4EB16C9974CFF14AB62FAC1503CD0CF97C825FECCDF39F2CCCEA87305E2527C969975515CFF9FCECFB8D89CB6C77752E0C033A69E235A20A81F3B0E39AB3C5F247CB2F7F93A5DB60FBEB33A8A0DA7A0AF5A3A8387 X-Mras: Ok Subject: Re: [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: Maxim Kokryashkin via Tarantool-patches Reply-To: Maxim Kokryashkin Cc: max.kokryashkin@gmail.com, tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Hi, Sergey! Thanks for the fixes! LGTM, except for a few comments below. Side note: I see that coverage job in CI is red. Why is that happening? On Tue, Aug 01, 2023 at 09:46:08PM +0300, Sergey Bronnikov via Tarantool-patches wrote: > 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 Typo: s/process/processes/ > 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") Nit: Something is wrong with alignment here. > + 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 >