Wireshark-dev: Re: [Wireshark-dev] Code Coverage Measurement of Wireshark - Outdated Instructio
From: Graham Bloice <graham.bloice@xxxxxxxxxxxxx>
Date: Wed, 29 Jul 2020 09:15:19 +0100
There's some chatter on the CMake forums about a better story for code coverage support but it doesn't seem to have been made first class yet.

There's a S.O. question here where the top answer uses a 3rd party CMake module; https://stackoverflow.com/questions/13116488/detailed-guide-on-using-gcov-with-cmake-cdash and the module; https://github.com/bilke/cmake-modules/blob/master/CodeCoverage.cmake and an article that discusses the same with a CMake option; http://www.stablecoder.ca/2018/01/15/code-coverage.html.

Note I haven't tried any of these, just found them with a Google search.

On Tue, 28 Jul 2020 at 16:50, Jaap Keuter <jaap.keuter@xxxxxxxxx> wrote:
Sounds to me as something that could be made into a build option, but that’s just ’shooting from the hip’, I haven’t looked at the CMake files yet.

On 28 Jul 2020, at 11:11, Peimann, Jannis <jannis.peimann@xxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote:

Okay, I was able to find a workaround.
 
I changed the following inside the main CMakeLists.txt inside my Wireshark 3.2.4 root directory and rebuild Wireshark:
 
Line 500 (add code coverage compiler flags; changed extension from *.c.gcno to *.gcno):
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
set(CMAKE_C_OUTPUT_EXTENSION_REPLACE 1)
set(CMAKE_CXX_OUTPUT_EXTENSION_REPLACE 1)
 
Line 750 (Added -lgcov for GCOV and LCOV integration):
set(WIRESHARK_LD_FLAGS
                               # See also CheckCLinkerFlag.cmake
                               -Wl,--as-needed
                               # -flto
                               # -fwhopr
                               # -fwhole-program
                               -lgcov 
                )
 
 
*.gcda and *.gcno file location in Ubuntu:
/*/build-ninja/plugins/epan/dissector_name/CMakeFiles/dissector_name.dir/
 
 
Evaluation commands:
local@vxu-1804: ~/*/build-ninja
lcov -c -d . -o coverage.lcov
mkdir lcov-output
 
genhtml -o lcov-output/ coverage.lcov
or with source error ignoration:
genhtml –ignore-errors source -o lcov-output/ coverage.lcov
 
 
Maybe this helps someone else.
 
Is this a good way, or is there a better/preferred way to do it?
 
 
Von: Wireshark-dev <wireshark-dev-bounces@xxxxxxxxxxxxx> Im Auftrag von Peimann, Jannis
Gesendet: Montag, 27. Juli 2020 13:07
An: wireshark-dev@xxxxxxxxxxxxx
Betreff: [Wireshark-dev] Code Coverage Measurement of Wireshark - Outdated Instruction
 
Hello together,
 
I created a small Dissector that I want to test now.
Therefore I tried the Code Coverage Measurement from the Wireshark Wiki Page but ran into some issues.
 
At first I have seen, that this page was updated the last time in 2008. (wiki.wireshark.org/Development/CodeCoverage)
These steps are not valid anymore:
 
~/wireshark$ ./autogen.sh
~/wireshark$ ./configure CFLAGS=--coverage [options]
 
Starting with Wireshark 3.0.0, autotools is no longer supported, only cmake. – According to this thread: Missing autogen.sh in 3.0.0 (Ask Wireshark Thread)
 
Could someone please update that Wiki entry or/and explain to me how I can achieve this with CMake?
Unfortunately I am not able to create *.gcno files with CMake.
I guess some commands are different and I maybe have to change some CMake Configuration Files.
 
For your interest, I use Ubuntu.
GCC Version is 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)
 
I tried this already but no *.gcno files were created:
make clean && make CFLAGS=--coverage LDFLAGS=--coverage
 
 
Thanks in advance for your help.
 
 
Best regards,
 
Jannis Peimann


___________________________________________________________________________
Sent via:    Wireshark-dev mailing list <wireshark-dev@xxxxxxxxxxxxx>
Archives:    https://www.wireshark.org/lists/wireshark-dev
Unsubscribe: https://www.wireshark.org/mailman/options/wireshark-dev
             mailto:wireshark-dev-request@xxxxxxxxxxxxx?subject=unsubscribe


--
Graham Bloice
Software Developer
Trihedral UK Limited