Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame^] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright (c) 2019, Arm Limited. All rights reserved. |
| 4 | # |
| 5 | # SPDX-License-Identifier: BSD-3-Clause |
| 6 | # |
| 7 | |
| 8 | set -e |
| 9 | |
| 10 | ci_root="$(readlink -f "$(dirname "$0")/..")" |
| 11 | source "$ci_root/utils.sh" |
| 12 | |
| 13 | # Change directory to the TF-A checkout ready to build |
| 14 | cd "$TF_CHECKOUT_LOC" |
| 15 | |
| 16 | # Build TF-A to get blx.bin images and the tools (fiptool and cert_create) |
| 17 | # Debug build enabled so that valgrind has access to source file line numbers |
| 18 | if ! make CROSS_COMPILE="aarch64-linux-gnu-" all fiptool certtool DEBUG=1 V=1 \ |
| 19 | &>"$workspace/build.log"; then |
| 20 | echo "Error building tools; see archived build.log" |
| 21 | exit 1 |
| 22 | fi |
| 23 | |
| 24 | run_valgrind() { |
| 25 | valgrind --leak-check=full -v --log-file="$log_file" $* |
| 26 | echo |
| 27 | if ! grep -iq "All heap blocks were freed -- no leaks are possible" \ |
| 28 | "$log_file"; then |
| 29 | echo "Memory leak reported in $log_file" |
| 30 | return 1 |
| 31 | fi |
| 32 | return 0 |
| 33 | } |
| 34 | |
| 35 | has_leak=0 |
| 36 | |
| 37 | fiptool_cmd="./tools/fiptool/fiptool \ |
| 38 | create \ |
| 39 | --tb-fw build/fvp/debug/bl2.bin \ |
| 40 | --soc-fw build/fvp/debug/bl31.bin \ |
| 41 | fip.bin" |
| 42 | |
| 43 | # Build the FIP under Valgrind |
| 44 | if ! log_file="$workspace/fiptool.log" run_valgrind "$fiptool_cmd"; then |
| 45 | echo "fiptool has memory leaks." |
| 46 | has_leak=1 |
| 47 | else |
| 48 | echo "fiptool does not have memory leaks." |
| 49 | fi |
| 50 | |
| 51 | echo |
| 52 | |
| 53 | cert_create_cmd="./tools/cert_create/cert_create \ |
| 54 | -n \ |
| 55 | --tb-fw build/fvp/debug/bl2.bin" |
| 56 | |
| 57 | # Run cert_create under Valgrind |
| 58 | if ! log_file="$workspace/cert_create.log" run_valgrind "$cert_create_cmd"; then |
| 59 | echo "cert_create has memory leaks." |
| 60 | has_leak=1 |
| 61 | else |
| 62 | echo "cert_create does not have memory leaks." |
| 63 | fi |
| 64 | |
| 65 | echo |
| 66 | |
| 67 | exit "$has_leak" |