|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +set -ex |
| 4 | + |
| 5 | +SRC_PATH=$1 |
| 6 | +COVERAGE_THRESHOLD=$2 |
| 7 | + |
| 8 | +if [ -z "$SRC_PATH" ]; then |
| 9 | + echo "SRC_PATH not defined!" |
| 10 | + exit 1 |
| 11 | +fi |
| 12 | + |
| 13 | +if [ -z "$COVERAGE_THRESHOLD" ]; then |
| 14 | + echo "COVERAGE_THRESHOLD not defined!" |
| 15 | + exit 1 |
| 16 | +fi |
| 17 | + |
| 18 | +pushd "$SRC_PATH" |
| 19 | + |
| 20 | +rm -fR build |
| 21 | +mkdir build |
| 22 | + |
| 23 | +# Run the tests in Release mode and check code coverage |
| 24 | +# and code style (the coverage target runs all unit tests) |
| 25 | +cmake -DBUILD_TESTS=ON -DCOVERAGE=ON -DDOCUMENTATION=ON -DBUILD_SAMPLES=ON -DCMAKE_BUILD_TYPE=Debug -B build/ |
| 26 | +cmake --build build/ -- -j6 |
| 27 | +cmake --build build/ --target coverage |
| 28 | +cmake --build build/ --target check_style |
| 29 | + |
| 30 | +# Make sure unit test coverage doesn't fall below the predefined threshold |
| 31 | +function_coverage=$(lcov --summary build/coverage/coverage.info | grep functions | cut -c 16-17) |
| 32 | +line_coverage=$(lcov --summary build/coverage/coverage.info | grep lines | cut -c 16-17) |
| 33 | +echo "The current function coverage is $(lcov --summary build/coverage/coverage.info | grep functions | cut -c 16-19)%" |
| 34 | +if [ "$function_coverage" -lt "$COVERAGE_THRESHOLD" ]; then |
| 35 | + echo "The current function coverage falls below the $COVERAGE_THRESHOLD% threshold." |
| 36 | + exit 1 |
| 37 | +fi |
| 38 | +echo "The current line coverage is $(lcov --summary build/coverage/coverage.info | grep lines | cut -c 16-19)%" |
| 39 | +if [ "$line_coverage" -lt "$COVERAGE_THRESHOLD" ]; then |
| 40 | + echo "The current line coverage falls below the $COVERAGE_THRESHOLD% threshold." |
| 41 | + exit 1 |
| 42 | +fi |
| 43 | + |
| 44 | +# Copy the coverage directory so we don't loose it |
| 45 | +rm -rf ./coverage |
| 46 | +cp -r build/coverage . |
| 47 | + |
| 48 | +# Running the various code sanitizers |
| 49 | +# ----------------------------------- |
| 50 | +clean_and_build() { |
| 51 | + rm -fR build |
| 52 | + mkdir build |
| 53 | + cmake -DBUILD_TESTS=ON -DDOCUMENTATION=OFF -DBUILD_SAMPLES=OFF -DCMAKE_BUILD_TYPE="$1" -B build/ |
| 54 | + cmake --build build/ -- -j6 |
| 55 | +} |
| 56 | + |
| 57 | +run_tests() { |
| 58 | + cmake --build build/ --target unit_test |
| 59 | +} |
| 60 | + |
| 61 | +echo -e "\nRunning the UndefinedBehaviorSanitizer...\n" |
| 62 | +clean_and_build ubsan |
| 63 | +run_tests |
| 64 | + |
| 65 | +echo -e "\nRunning the LeakSanitizer...\n" |
| 66 | +clean_and_build lsan |
| 67 | +run_tests |
| 68 | + |
| 69 | +echo -e "\nRunning the AddressSanitizer...\n" |
| 70 | +clean_and_build asan |
| 71 | +run_tests |
| 72 | + |
| 73 | +echo -e "\nRunning the ThreadSanitizer...\n" |
| 74 | +clean_and_build tsan |
| 75 | +run_tests |
| 76 | + |
| 77 | +popd |
0 commit comments