Merge pull request #4544 from ethereum/code-coverage

Code coverage
This commit is contained in:
Alex Beregszaszi 2018-07-24 18:32:51 +01:00 committed by GitHub
commit fc68d22ba4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 17 deletions

View File

@ -14,7 +14,7 @@ defaults:
command: | command: |
mkdir -p build mkdir -p build
cd build cd build
cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo $CMAKE_OPTIONS
make -j4 make -j4
- run_tests: &run_tests - run_tests: &run_tests
name: Tests name: Tests
@ -122,6 +122,7 @@ jobs:
- image: buildpack-deps:artful - image: buildpack-deps:artful
environment: environment:
TERM: xterm TERM: xterm
CMAKE_OPTIONS: -DCOVERAGE=ON
steps: steps:
- checkout - checkout
- run: - run:
@ -133,7 +134,10 @@ jobs:
- run: *setup_prerelease_commit_hash - run: *setup_prerelease_commit_hash
- run: *run_build - run: *run_build
- store_artifacts: *solc_artifact - store_artifacts: *solc_artifact
- persist_to_workspace: *all_artifacts - persist_to_workspace:
root: build
paths:
- "*"
build_x86_mac: build_x86_mac:
macos: macos:
@ -188,9 +192,19 @@ jobs:
name: Install dependencies name: Install dependencies
command: | command: |
apt-get -qq update apt-get -qq update
apt-get -qy install libz3-dev libleveldb1v5 apt-get -qy install libz3-dev libleveldb1v5 python-pip
pip install codecov
- run: mkdir -p test_results - run: mkdir -p test_results
- run:
name: Test type checker
command: build/test/soltest -t 'syntaxTest*' -- --no-ipc --testpath test
- run:
name: Coverage of type checker
command: codecov --flags type_checker --gcov-root build
- run: *run_tests - run: *run_tests
- run:
name: Coverage of all
command: codecov --flags all --gcov-root build
- store_test_results: - store_test_results:
path: test_results/ path: test_results/

View File

@ -151,20 +151,22 @@ if (SANITIZE)
endif() endif()
endif() endif()
if (PROFILING AND (("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") OR ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang"))) # Code coverage support.
set(CMAKE_CXX_FLAGS "-g ${CMAKE_CXX_FLAGS}") # Copied from Cable:
set(CMAKE_C_FLAGS "-g ${CMAKE_C_FLAGS}") # https://github.com/ethereum/cable/blob/v0.2.4/CableCompilerSettings.cmake#L118-L132
add_definitions(-DETH_PROFILING_GPERF) option(COVERAGE "Build with code coverage support" OFF)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -lprofiler") if(COVERAGE)
# set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} -lprofiler") # Set the linker flags first, they are required to properly test the compiler flag.
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lprofiler") set(CMAKE_SHARED_LINKER_FLAGS "--coverage ${CMAKE_SHARED_LINKER_FLAGS}")
endif () set(CMAKE_EXE_LINKER_FLAGS "--coverage ${CMAKE_EXE_LINKER_FLAGS}")
if (PROFILING AND (("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU"))) set(CMAKE_REQUIRED_LIBRARIES "--coverage ${CMAKE_REQUIRED_LIBRARIES}")
set(CMAKE_CXX_FLAGS "-g --coverage ${CMAKE_CXX_FLAGS}") check_cxx_compiler_flag(--coverage have_coverage)
set(CMAKE_C_FLAGS "-g --coverage ${CMAKE_C_FLAGS}") string(REPLACE "--coverage " "" CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
set(CMAKE_SHARED_LINKER_FLAGS "--coverage ${CMAKE_SHARED_LINKER_FLAGS} -lprofiler") if(NOT have_coverage)
set(CMAKE_EXE_LINKER_FLAGS "--coverage ${CMAKE_EXE_LINKER_FLAGS} -lprofiler") message(FATAL_ERROR "Coverage not supported")
endif()
add_compile_options(-g --coverage)
endif() endif()
if (("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") OR ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")) if (("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") OR ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang"))