Tomás González | 010b637 | 2025-04-29 17:13:47 +0100 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | # |
| 3 | # Copyright (c) 2025 Arm Limited. All rights reserved. |
| 4 | # |
| 5 | # SPDX-License-Identifier: BSD-3-Clause |
| 6 | # |
| 7 | |
Tomás González | 3286e4b | 2025-06-05 18:25:09 +0100 | [diff] [blame^] | 8 | set -ex |
| 9 | |
Tomás González | 010b637 | 2025-04-29 17:13:47 +0100 | [diff] [blame] | 10 | echo '----------------------------------------------' |
| 11 | echo '-- Running Cargo tests --' |
| 12 | echo '----------------------------------------------' |
| 13 | |
| 14 | export LOG_TEST_FILENAME=$(pwd)/next-generic-checks.log |
| 15 | export RUSTUP_HOME=/usr/local/rustup |
| 16 | |
Tomás González | 3286e4b | 2025-06-05 18:25:09 +0100 | [diff] [blame^] | 17 | REPO_SPACE=$1 |
| 18 | REPO_NAME=$2 |
Tomás González | 010b637 | 2025-04-29 17:13:47 +0100 | [diff] [blame] | 19 | # For local runs, we require GERRIT_BRANCH to be set to get the merge-base/diff |
| 20 | # between the checked out commit and the tip of $GERRIT_BRANCH - for running |
| 21 | # next tests, usually this will be tfa-next |
| 22 | export GERRIT_BRANCH=${GERRIT_BRANCH:="tfa-next"} |
| 23 | |
Tomás González | 3286e4b | 2025-06-05 18:25:09 +0100 | [diff] [blame^] | 24 | # git operations e.g. ${get_merge_base} rely on access to tfa-next branch, |
| 25 | # we need to access via SSH for that to work currently |
| 26 | SSH_PARAMS="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o PubkeyAcceptedKeyTypes=+ssh-rsa -p 29418 -i ${CI_BOT_KEY}" |
| 27 | REPO_SSH_URL="ssh://${CI_BOT_USERNAME}@review.trustedfirmware.org:29418/${REPO_SPACE}/${REPO_NAME}" |
| 28 | export GIT_SSH_COMMAND="ssh ${SSH_PARAMS}" |
| 29 | |
| 30 | cd "${REPO_NAME}" |
| 31 | |
| 32 | if [ "$REPO_NAME" == "trusted-firmware-a" ] && ["$IS_CONTINUOUS_INTEGRATION" == 1 ]; then |
Tomás González | 010b637 | 2025-04-29 17:13:47 +0100 | [diff] [blame] | 33 | git remote set-url origin ${REPO_SSH_URL} |
| 34 | git fetch origin |
| 35 | fi |
| 36 | |
| 37 | TEST_CASE="cargo test checks" |
| 38 | |
| 39 | echo "# ${TEST_CASE}" |
| 40 | echo >> "$LOG_TEST_FILENAME" |
| 41 | echo "****** $TEST_CASE ******" >> "$LOG_TEST_FILENAME" |
| 42 | echo >> "$LOG_TEST_FILENAME" |
| 43 | |
Tomás González | 010b637 | 2025-04-29 17:13:47 +0100 | [diff] [blame] | 44 | ERROR_COUNT=0 |
| 45 | |
| 46 | # Run cargo test |
| 47 | |
Tomás González | 3286e4b | 2025-06-05 18:25:09 +0100 | [diff] [blame^] | 48 | if [ "$REPO_NAME" == "trusted-firmware-a" ]; then |
| 49 | cd rust |
| 50 | declare -a all_features=($(make PLAT=${platform} --silent list_features)) |
| 51 | else |
| 52 | declare -a all_features=($TEST_FEATURES) |
| 53 | fi |
| 54 | |
Tomás González | 010b637 | 2025-04-29 17:13:47 +0100 | [diff] [blame] | 55 | # append empty features by default |
| 56 | all_features+=("") |
| 57 | |
| 58 | for features in "${all_features[@]}"; do |
| 59 | echo "cargo test features: '$features'" >> "$LOG_TEST_FILENAME" 2>&1 |
| 60 | cargo test --features=$features >> "$LOG_TEST_FILENAME" 2>&1 |
| 61 | |
| 62 | if [ "$?" != 0 ]; then |
| 63 | echo "cargo test --features='$features': FAILURE" |
| 64 | ((ERROR_COUNT++)) |
| 65 | else |
| 66 | echo "cargo test --features='$features': PASS" |
| 67 | fi |
| 68 | |
| 69 | echo "-------------------------------------" >> "$LOG_TEST_FILENAME" 2>&1 |
| 70 | done |
| 71 | |
| 72 | echo |
| 73 | |
| 74 | cd - |
| 75 | if [ "$ERROR_COUNT" != 0 ]; then |
| 76 | echo "Some cargo tests checks have failed." |
| 77 | exit 1 |
| 78 | fi |
| 79 | |
| 80 | exit 0 |