Martyn Capewell | ae5957c | 2021-03-31 11:44:16 +0100 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # Copyright 2021, VIXL authors |
| 4 | # All rights reserved. |
| 5 | # |
| 6 | # Redistribution and use in source and binary forms, with or without |
| 7 | # modification, are permitted provided that the following conditions are met: |
| 8 | # |
| 9 | # * Redistributions of source code must retain the above copyright notice, |
| 10 | # this list of conditions and the following disclaimer. |
| 11 | # * Redistributions in binary form must reproduce the above copyright notice, |
| 12 | # this list of conditions and the following disclaimer in the documentation |
| 13 | # and/or other materials provided with the distribution. |
| 14 | # * Neither the name of ARM Limited nor the names of its contributors may be |
| 15 | # used to endorse or promote products derived from this software without |
| 16 | # specific prior written permission. |
| 17 | # |
| 18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS CONTRIBUTORS "AS IS" AND |
| 19 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 20 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 21 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE |
| 22 | # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 23 | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 24 | # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 25 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 26 | # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 27 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | |
| 29 | # This code coverage script assumes a Linux-like environment, and has been |
| 30 | # tested on Ubuntu 18.04. |
| 31 | |
| 32 | if ! hash pv 2>/dev/null ; then |
| 33 | echo "This script requires 'pv'" |
| 34 | echo "On Ubuntu, install it with 'sudo apt-get install pv'" |
| 35 | exit 1; |
| 36 | fi |
| 37 | |
| 38 | export CXX=clang++ |
| 39 | export LLVM_PROFILE_FILE=$(mktemp) |
| 40 | PROFDATA=$(mktemp) |
Chris Jones | 7a2a472 | 2023-12-08 17:18:49 +0000 | [diff] [blame^] | 41 | BUILDDIR="obj/target_a64/mode_debug/symbols_on/compiler_clang++/std_c++17/simulator_aarch64/negative_testing_off/code_buffer_allocator_mmap" |
Martyn Capewell | ae5957c | 2021-03-31 11:44:16 +0100 | [diff] [blame] | 42 | RUNNER="$BUILDDIR/test/test-runner" |
| 43 | |
| 44 | # Build with code coverage instrumentation enabled. |
| 45 | scons mode=debug coverage=on target=a64 all -j8 |
| 46 | |
| 47 | if [ ! -f "$RUNNER" ]; then |
| 48 | echo "$RUNNER not found." |
| 49 | echo "No test-runner for profiling." |
| 50 | exit 1; |
| 51 | fi |
| 52 | |
| 53 | # Count the number of tests. |
| 54 | tests=`$RUNNER --list | wc -l` |
| 55 | |
| 56 | # Generate a raw profile for a run using all tests. |
| 57 | echo "Running $tests tests. This may take a while..." |
| 58 | $RUNNER --run-all 2>&1 | grep -P "^Running [A-Z0-9]{3,}_" | pv -lbp -w 40 -s $tests >/dev/null |
| 59 | |
| 60 | # Process the raw profile data for reporting. |
| 61 | llvm-profdata merge -sparse $LLVM_PROFILE_FILE -o $PROFDATA |
| 62 | |
| 63 | # Print a coverage report for the source files in src/ |
Martyn Capewell | ad16ac6 | 2021-06-30 15:10:02 +0100 | [diff] [blame] | 64 | REPORT="llvm-cov report $RUNNER -instr-profile=$PROFDATA $BUILDDIR/src/" |
| 65 | eval $REPORT |
| 66 | |
| 67 | # Log the report summary line. |
| 68 | eval $REPORT | tail -n1 | tr -s " " | cut -d" " -f4,7,10 | xargs -i printf "%s %s\n" `date +%s` {} >>tools/code_coverage.log |
Martyn Capewell | ae5957c | 2021-03-31 11:44:16 +0100 | [diff] [blame] | 69 | |
| 70 | # Clean up. |
| 71 | rm -f $LLVM_PROFILE_FILE |
| 72 | rm -f $PROFDATA |