This is an archive of the discontinued LLVM Phabricator instance.

[libcxx] Add code coverage configuration to CMake and LIT.
ClosedPublic

Authored by EricWF on Mar 30 2015, 7:37 PM.

Details

Summary

This patch adds configuration to CMake and LIT for running the libc++ test-suite to generate code coverage.

To use code coverage use following instructions.

  • Find the clang resource dir using $CXX -print-search-dirs. Let <library-dir> be the first library search directory.
  • cmake <regular-options> -DLIBCXX_GENERATE_COVERAGE=ON -DLIBCXX_COVERAGE_LIBRARY=<library-dir>/lib/<platform>/libclang_rt.profile.a <source>
  • make cxx
  • make check-libcxx
  • make generate-libcxx-coverage

The reason I want this patch upstreamed is so I can setup a bot that generates code coverage and posts in online for every revision.

Diff Detail

Event Timeline

EricWF updated this revision to Diff 22924.Mar 30 2015, 7:37 PM
EricWF retitled this revision from to [libcxx] Add code coverage configuration to CMake and LIT..
EricWF updated this object.
EricWF edited the test plan for this revision. (Show Details)
EricWF added reviewers: mclow.lists, danalbert, jroelofs.
danalbert added inline comments.Mar 30 2015, 7:45 PM
CMakeLists.txt
69

Why is this needed? --coverage should handle this for us.

EricWF added inline comments.Mar 30 2015, 7:49 PM
CMakeLists.txt
69

--coverage doesn't link profileRT with -nodefaultlibs. Unfortunately this means we have to manually link it.

danalbert added inline comments.Mar 30 2015, 7:55 PM
CMakeLists.txt
69

That's disappointing, but makes sense.

We really need to add a -stdlib=none...

Couldn't cmake handle finding this directory by calling -print-search-dirs?

test/libcxx/test/config.py
601

But it doesn't need to be linked here?

I don't think we actually want --coverage for the tests.

EricWF added inline comments.Mar 30 2015, 8:09 PM
CMakeLists.txt
69

Couldn't cmake handle finding this directory by calling -print-search-dirs?

I had a CMake patch that did this, but it's ugly and tricky. There are a bunch of problems manually linking compiler-rt libraries. The format of the library path is <search-dir-output>/lib/<platform>/libclang_rt.profile-<arch>.a. So CMake would have to automagically figure out the platform name and the target arch. It's a lot easier for this one case to just make the user provide it manually.

test/libcxx/test/config.py
601

I haven't needed to manually link. It seems that profileRT is typically a static library so all the symbols get exposed via libc++.

I don't think we actually want --coverage for the tests.

Why not? we need to build the tests with code coverage so that header-only parts of libc++ get coverage stats. The coverage information for all files under libcxx/test are removed from the final output.

danalbert accepted this revision.Mar 30 2015, 8:58 PM
danalbert edited edge metadata.

LGTM.

CMakeLists.txt
69

Okay. If it gets to be enough of a PITA we'll fix it later, but this will do for now unless anyone else feels strongly about it.

test/libcxx/test/config.py
601

I haven't needed to manually link. It seems that profileRT is typically a static library so all the symbols get exposed via libc++.

That makes sense.

we need to build the tests with code coverage so that header-only parts of libc++ get coverage stats.

Right... was thinking of the more typical coverage case where most of the code isn't in headers.

This revision is now accepted and ready to land.Mar 30 2015, 8:58 PM
EricWF closed this revision.Mar 30 2015, 9:18 PM