diff options
-rw-r--r-- | CMakeLists.txt | 6 | ||||
-rw-r--r-- | Makefile | 5 | ||||
-rwxr-xr-x | scripts/coverage.sh | 40 |
3 files changed, 50 insertions, 1 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index c74db485..5a61f10c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,6 +24,7 @@ option(USE_ASAN "Use address sanitizer" OFF) option(USE_MSAN "Use memory sanitizer" OFF) option(USE_LSAN "Use leak sanitizer" OFF) option(USE_UBSAN "Use undefined behavior sanitizer" OFF) +option(CODE_COVERAGE "Build with code coverage enabled" OFF) if ("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang") set(COMPILER_IS_CLANG 1) @@ -234,6 +235,11 @@ add_library(libwabt STATIC set_target_properties(libwabt PROPERTIES OUTPUT_NAME wabt) if (NOT EMSCRIPTEN) + if (CODE_COVERAGE) + add_definitions("-fprofile-arcs -ftest-coverage") + link_libraries(gcov) + endif () + # wast2wasm add_executable(wast2wasm src/tools/wast2wasm.c) add_dependencies(everything wast2wasm) @@ -31,7 +31,7 @@ DEFAULT_BUILD_TYPE = DEBUG COMPILERS := GCC GCC_I686 GCC_FUZZ CLANG EMSCRIPTEN BUILD_TYPES := DEBUG RELEASE SANITIZERS := ASAN MSAN LSAN UBSAN -CONFIGS := NORMAL $(SANITIZERS) NO_RE2C_BISON NO_TESTS +CONFIGS := NORMAL $(SANITIZERS) COV NO_RE2C_BISON NO_TESTS EXECUTABLES := wast2wasm wasm2wast wasm-interp wasmopcodecnt hexfloat_test \ wasmdump wast-desugar wasm-link @@ -49,6 +49,7 @@ MSAN_DIR := msan/ LSAN_DIR := lsan/ UBSAN_DIR := ubsan/ NO_RE2C_BISON_DIR := no-re2c-bison/ +COV_DIR := cov/ NO_TESTS_DIR := no-tests/ # CMake flags @@ -65,6 +66,7 @@ ASAN_FLAG := -DUSE_ASAN=ON MSAN_FLAG := -DUSE_MSAN=ON LSAN_FLAG := -DUSE_LSAN=ON UBSAN_FLAG := -DUSE_UBSAN=ON +COV_FLAG := -DCODE_COVERAGE=ON NO_RE2C_BISON_FLAG := -DRUN_BISON=OFF -DRUN_RE2C=OFF NO_TESTS_FLAG := -DBUILD_TESTS=OFF @@ -81,6 +83,7 @@ ASAN_PREFIX := -asan MSAN_PREFIX := -msan LSAN_PREFIX := -lsan UBSAN_PREFIX := -ubsan +COV_PREFIX := -cov NO_RE2C_BISON_PREFIX := -no-re2c-bison NO_TESTS_PREFIX := -no-tests diff --git a/scripts/coverage.sh b/scripts/coverage.sh new file mode 100755 index 00000000..f167af52 --- /dev/null +++ b/scripts/coverage.sh @@ -0,0 +1,40 @@ +#!/bin/bash +# +# Copyright 2017 WebAssembly Community Group participants +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +set -o nounset +set -o errexit + +COMPILER=${1:-gcc} +BUILD_TYPE=${2:-Debug} + +SCRIPT_DIR="$(cd "$(dirname "$0")"; pwd -P)" +ROOT_DIR=${SCRIPT_DIR}/.. +BIN_DIR=${ROOT_DIR}/out/${COMPILER}/${BUILD_TYPE}/cov +LCOVRC_FILE=${ROOT_DIR}/lcovrc +COV_FILE=${BIN_DIR}/lcov.info +COV_HTML_DIR=${ROOT_DIR}/out/lcov + +log_and_run() { + echo $* + (exec $*) +} + +log_and_run lcov --zerocounters -d ${BIN_DIR} --rc lcov_branch_coverage=1 +log_and_run python test/run-tests.py --bindir ${BIN_DIR} +log_and_run python test/run-tests.py --bindir ${BIN_DIR} -a=--use-libc-allocator +log_and_run lcov -c -d ${BIN_DIR} -o ${COV_FILE} --rc lcov_branch_coverage=1 +log_and_run genhtml --branch-coverage -o ${COV_HTML_DIR} ${COV_FILE} |