summaryrefslogtreecommitdiffstats
path: root/libcxx
diff options
context:
space:
mode:
authorEric Fiselier <eric@efcs.ca>2015-03-31 04:15:45 +0000
committerEric Fiselier <eric@efcs.ca>2015-03-31 04:15:45 +0000
commit78fdf2d0f5274923fff06de4402d83bb9609d2b3 (patch)
tree137c6f95bcaac14f09cbbbe405594acbaade25cb /libcxx
parent77b5bb7ce22e826db5f7408c677115957c98614e (diff)
downloadbcm5719-llvm-78fdf2d0f5274923fff06de4402d83bb9609d2b3.tar.gz
bcm5719-llvm-78fdf2d0f5274923fff06de4402d83bb9609d2b3.zip
[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 llvm-svn: 233669
Diffstat (limited to 'libcxx')
-rw-r--r--libcxx/CMakeLists.txt13
-rw-r--r--libcxx/cmake/Modules/CodeCoverage.cmake36
-rw-r--r--libcxx/lib/CMakeLists.txt6
-rw-r--r--libcxx/test/CMakeLists.txt10
-rw-r--r--libcxx/test/libcxx/test/config.py7
-rw-r--r--libcxx/test/lit.site.cfg.in1
6 files changed, 73 insertions, 0 deletions
diff --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt
index 82a35e0c6b6..2e5db7757e2 100644
--- a/libcxx/CMakeLists.txt
+++ b/libcxx/CMakeLists.txt
@@ -64,6 +64,9 @@ option(LIBCXX_ENABLE_MONOTONIC_CLOCK
This option may only be used when LIBCXX_ENABLE_THREADS=OFF." ON)
option(LIBCXX_INSTALL_HEADERS "Install the libc++ headers." ON)
option(LIBCXX_INSTALL_SUPPORT_HEADERS "Install libc++ support headers." ON)
+option(LIBCXX_GENERATE_COVERAGE "Enable generating code coverage." OFF)
+set(LIBCXX_COVERAGE_LIBRARY "" CACHE STRING
+ "The Profile-rt library used to build with code coverage")
option(LIBCXX_ENABLE_STATIC_ABI_LIBRARY "Statically link the ABI library" OFF)
set(LIBCXX_SYSROOT "" CACHE STRING "Use alternate sysroot.")
set(LIBCXX_GCC_TOOLCHAIN "" CACHE STRING "Use alternate GCC toolchain.")
@@ -140,6 +143,11 @@ set(LIBCXX_LINK_FLAGS "")
include(config-ix)
# Configure ABI library
include(HandleLibCXXABI)
+# Configure coverage options.
+if (LIBCXX_GENERATE_COVERAGE)
+ include(CodeCoverage)
+ set(CMAKE_BUILD_TYPE "COVERAGE" CACHE STRING "" FORCE)
+endif()
#===============================================================================
# Setup Compiler Flags
@@ -318,10 +326,15 @@ endif()
append_if(LIBCXX_CXX_FLAGS LIBCXX_TARGET_TRIPLE
"-target ${LIBCXX_TARGET_TRIPLE}")
+
append_if(LIBCXX_CXX_FLAGS LIBCXX_SYSROOT "--sysroot ${LIBCXX_SYSROOT}")
append_if(LIBCXX_CXX_FLAGS LIBCXX_GCC_TOOLCHAIN
"-gcc-toolchain ${LIBCXX_GCC_TOOLCHAIN}")
+if (LLVM_USE_SANITIZER AND LIBCXX_GENERATE_COVERAGE)
+ message(FATAL_ERROR "LLVM_USE_SANITIZER cannot be used with LIBCXX_GENERATE_COVERAGE")
+endif()
+
string(REPLACE ";" " " LIBCXX_CXX_FLAGS "${LIBCXX_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LIBCXX_CXX_FLAGS}")
diff --git a/libcxx/cmake/Modules/CodeCoverage.cmake b/libcxx/cmake/Modules/CodeCoverage.cmake
new file mode 100644
index 00000000000..addd10abdfe
--- /dev/null
+++ b/libcxx/cmake/Modules/CodeCoverage.cmake
@@ -0,0 +1,36 @@
+find_program(CODE_COVERAGE_LCOV lcov)
+if (NOT CODE_COVERAGE_LCOV)
+ message(FATAL_ERROR "Cannot find lcov...")
+endif()
+
+find_program(CODE_COVERAGE_GENHTML genhtml)
+if (NOT CODE_COVERAGE_GENHTML)
+ message(FATAL_ERROR "Cannot find genhtml...")
+endif()
+
+set(CMAKE_CXX_FLAGS_COVERAGE "-g -O0 --coverage")
+
+function(setup_lcov_test_target_coverage target_name output_dir capture_dirs source_dirs)
+ file(MAKE_DIRECTORY ${output_dir})
+
+ set(CAPTURE_DIRS "")
+ foreach(cdir ${capture_dirs})
+ list(APPEND CAPTURE_DIRS "-d;${cdir}")
+ endforeach()
+
+ set(EXTRACT_DIRS "")
+ foreach(sdir ${source_dirs})
+ list(APPEND EXTRACT_DIRS "'${sdir}/*'")
+ endforeach()
+
+ message(STATUS "Capture Directories: ${CAPTURE_DIRS}")
+ message(STATUS "Extract Directories: ${EXTRACT_DIRS}")
+
+ add_custom_target(generate-lib${target_name}-coverage
+ COMMAND ${CODE_COVERAGE_LCOV} --capture ${CAPTURE_DIRS} -o test_coverage.info
+ COMMAND ${CODE_COVERAGE_LCOV} --extract test_coverage.info ${EXTRACT_DIRS} -o test_coverage.info
+ COMMAND ${CODE_COVERAGE_GENHTML} --demangle-cpp test_coverage.info -o test_coverage
+ COMMAND ${CMAKE_COMMAND} -E remove test_coverage.info
+ WORKING_DIRECTORY ${output_dir}
+ COMMENT "Generating coverage results")
+endfunction()
diff --git a/libcxx/lib/CMakeLists.txt b/libcxx/lib/CMakeLists.txt
index ee6cec493d8..d3d5f381d81 100644
--- a/libcxx/lib/CMakeLists.txt
+++ b/libcxx/lib/CMakeLists.txt
@@ -1,3 +1,5 @@
+set(LIBCXX_LIB_CMAKEFILES_DIR "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}" PARENT_SCOPE)
+
# Get sources
file(GLOB LIBCXX_SOURCES ../src/*.cpp)
if(WIN32)
@@ -61,8 +63,12 @@ append_if(libraries LIBCXX_HAS_M_LIB m)
append_if(libraries LIBCXX_HAS_RT_LIB rt)
append_if(libraries LIBCXX_HAS_GCC_S_LIB gcc_s)
+if (LIBCXX_COVERAGE_LIBRARY)
+ target_link_libraries(cxx ${LIBCXX_COVERAGE_LIBRARY})
+endif()
target_link_libraries(cxx ${libraries})
+
# Setup flags.
append_if(LIBCXX_COMPILE_FLAGS LIBCXX_HAS_FPIC_FLAG -fPIC)
append_if(LIBCXX_LINK_FLAGS LIBCXX_HAS_NODEFAULTLIBS_FLAG -nodefaultlibs)
diff --git a/libcxx/test/CMakeLists.txt b/libcxx/test/CMakeLists.txt
index 707acd1d479..bcab5c2ae6f 100644
--- a/libcxx/test/CMakeLists.txt
+++ b/libcxx/test/CMakeLists.txt
@@ -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!")
diff --git a/libcxx/test/libcxx/test/config.py b/libcxx/test/libcxx/test/config.py
index a23f46db250..c1f7489b5d7 100644
--- a/libcxx/test/libcxx/test/config.py
+++ b/libcxx/test/libcxx/test/config.py
@@ -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
diff --git a/libcxx/test/lit.site.cfg.in b/libcxx/test/lit.site.cfg.in
index 31eb73be0eb..9ed4adf8fa9 100644
--- a/libcxx/test/lit.site.cfg.in
+++ b/libcxx/test/lit.site.cfg.in
@@ -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@"
OpenPOWER on IntegriCloud