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

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. 



Reviewers: mclow.lists, jroelofs, danalbert

Reviewed By: danalbert

Differential Revision: http://reviews.llvm.org/D8716

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@233669 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Eric Fiselier
2015-03-31 04:15:45 +00:00
parent f68d637860
commit bf9653d85f
6 changed files with 73 additions and 0 deletions

View File

@@ -47,6 +47,8 @@ if (LIT_EXECUTABLE)
pythonize_bool(LIBCXX_ENABLE_STDOUT)
pythonize_bool(LIBCXX_ENABLE_THREADS)
pythonize_bool(LIBCXX_ENABLE_MONOTONIC_CLOCK)
pythonize_bool(LIBCXX_GENERATE_COVERAGE)
# The tests shouldn't link to any ABI library when it has been linked into
# libc++ statically.
if (LIBCXX_ENABLE_STATIC_ABI_LIBRARY)
@@ -71,6 +73,14 @@ if (LIT_EXECUTABLE)
DEPENDS cxx
COMMENT "Running libcxx tests"
${cmake_3_2_USES_TERMINAL})
if (LIBCXX_GENERATE_COVERAGE)
include(CodeCoverage)
set(output_dir "${CMAKE_CURRENT_BINARY_DIR}/coverage")
set(capture_dirs "${LIBCXX_LIB_CMAKEFILES_DIR}/cxx.dir/;${CMAKE_CURRENT_BINARY_DIR}")
set(extract_dirs "${LIBCXX_SOURCE_DIR}/include;${LIBCXX_SOURCE_DIR}/src")
setup_lcov_test_target_coverage("cxx" "${output_dir}" "${capture_dirs}" "${extract_dirs}")
endif()
else()
message(WARNING
"LIT_EXECUTABLE not set, no check-libcxx target will be available!")

View File

@@ -98,6 +98,7 @@ class Configuration(object):
self.configure_debug_mode()
self.configure_warnings()
self.configure_sanitizer()
self.configure_coverage()
self.configure_substitutions()
self.configure_features()
@@ -594,6 +595,12 @@ class Configuration(object):
self.lit_config.fatal('unsupported value for '
'use_sanitizer: {0}'.format(san))
def configure_coverage(self):
self.generate_coverage = self.get_lit_bool('generate_coverage', False)
if self.generate_coverage:
self.cxx.flags += ['-g', '--coverage']
self.cxx.compile_flags += ['-O0']
def configure_substitutions(self):
sub = self.config.substitutions
# Configure compiler substitions

View File

@@ -20,6 +20,7 @@ config.configuration_variant = "@LIBCXX_LIT_VARIANT@"
config.target_triple = "@LIBCXX_TARGET_TRIPLE@"
config.sysroot = "@LIBCXX_SYSROOT@"
config.gcc_toolchain = "@LIBCXX_GCC_TOOLCHAIN@"
config.generate_coverage = "@LIBCXX_GENERATE_COVERAGE@"
config.target_info = "@LIBCXX_TARGET_INFO@"
config.executor = "@LIBCXX_EXECUTOR@"