🗒️
notes
  • Journal
  • URLs
  • Java Card
    • SCP02
    • Rapid Notes
    • _FIXVALS_
    • Mifare
    • Chain Of Trust
  • Encoding
    • CBEFF
    • Bytes
  • Snippets
    • JNI_OnLoad
  • float to byte[]
  • Protobuf
  • C/C++
    • Containers
    • Basics
    • JNI
    • gcov
    • Castings
  • chess
    • Untitled
  • Compression
    • Untitled
  • Snippets
    • Untitled
  • Build Systems
    • Maven
    • Windows
  • Gradle
  • CMake
  • Java
    • Untitled
    • Certificates
  • Android
    • Mifare
  • Python
    • ctypes
  • WebSub
    • References
  • Spring Boot
    • Form-based Authentication
    • Basic Access Authentication
    • JWT Authentication
  • QR Code
    • Denso QR Code
  • Philosophical Inquiry
    • First
  • XML
    • xmlstarlet
Powered by GitBook
On this page

Was this helpful?

  1. C/C++

gcov

code coverage

Make sure gcc --version matches compatible version against gcov --version .

Makefile

main: export GCOV_PREFIX=/tmp/cov
main: export GCOV_PREFIX_STRIP=4

main : main.cpp helper/helper.c Makefile
        #g++ -o main main.cpp -fprofile-arcs -ftest-coverage && ./main 123
        g++ -o main main.cpp helper/helper.c -g -O0 -coverage && ./main
        mv *.gcno $(GCOV_PREFIX)
        cp main.cpp $(GCOV_PREFIX)
        mkdir $(GCOV_PREFIX)/helper
        cp helper/helper.c $(GCOV_PREFIX)/helper
        lcov -c --directory $(GCOV_PREFIX) --output-file $(GCOV_PREFIX)/coverage.info
        genhtml $(GCOV_PREFIX)/coverage.info -o $(GCOV_PREFIX)/html/

clean:
        @rm -rf main *.o *.gcda *.gcno *.gcov /tmp/cov/* 2>/dev/null
        git clean -fdx

.PHONY: clean

I'm still uncomfortable that I need to cp main.cpp ... So the gcno and other stuff does not really have the source info. In a huge codebase with subdirs and inter linkage, the safest I see is to merely use the current directory as output dirs for gcov.

PreviousJNINextCastings

Last updated 4 years ago

Was this helpful?