blob: 599ff29e68b447d144c5845ebbb966f78e3e0111 [file] [log] [blame]
Tomás González010b6372025-04-29 17:13:47 +01001#!/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ález3286e4b2025-06-05 18:25:09 +01008set -ex
9
Tomás González010b6372025-04-29 17:13:47 +010010echo '----------------------------------------------'
11echo '-- Running Cargo tests --'
12echo '----------------------------------------------'
13
14export LOG_TEST_FILENAME=$(pwd)/next-generic-checks.log
15export RUSTUP_HOME=/usr/local/rustup
16
Tomás González3286e4b2025-06-05 18:25:09 +010017REPO_SPACE=$1
18REPO_NAME=$2
Tomás González010b6372025-04-29 17:13:47 +010019# 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
22export GERRIT_BRANCH=${GERRIT_BRANCH:="tfa-next"}
23
Chris Kay10a38d52025-07-31 16:13:20 +010024# git operations rely on access to tfa-next branch, we need to access via SSH for that to work currently
Tomás González3286e4b2025-06-05 18:25:09 +010025SSH_PARAMS="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o PubkeyAcceptedKeyTypes=+ssh-rsa -p 29418 -i ${CI_BOT_KEY}"
26REPO_SSH_URL="ssh://${CI_BOT_USERNAME}@review.trustedfirmware.org:29418/${REPO_SPACE}/${REPO_NAME}"
27export GIT_SSH_COMMAND="ssh ${SSH_PARAMS}"
28
29cd "${REPO_NAME}"
30
Tomás Gonzálezeaa86c42025-07-28 12:19:15 +010031if [ "$REPO_NAME" == "rusted-firmware-a" ] && ["$IS_CONTINUOUS_INTEGRATION" == 1 ]; then
Tomás González010b6372025-04-29 17:13:47 +010032 git remote set-url origin ${REPO_SSH_URL}
33 git fetch origin
34fi
35
36TEST_CASE="cargo test checks"
37
38echo "# ${TEST_CASE}"
39echo >> "$LOG_TEST_FILENAME"
40echo "****** $TEST_CASE ******" >> "$LOG_TEST_FILENAME"
41echo >> "$LOG_TEST_FILENAME"
42
Tomás González010b6372025-04-29 17:13:47 +010043ERROR_COUNT=0
44
45# Run cargo test
46
Tomás Gonzálezeaa86c42025-07-28 12:19:15 +010047if [ "$REPO_NAME" == "rusted-firmware-a" ]; then
Tomás Gonzálezafd25082025-06-10 11:44:55 +010048 # These tests are platform independent. However, we are specifying a platform:
49 # The fvp platform is expected to cover all platform independent features that can be tested
50 # with cargo test.
51 IFS=" " read -a all_features <<< "$(make PLAT=fvp --silent list_features)"
Tomás González3286e4b2025-06-05 18:25:09 +010052else
Tomás Gonzálezeb05c392025-06-12 15:48:54 +010053 IFS=" " read -a all_features <<< ${TEST_FEATURES}
54 if [ ${#all_features[@]} = 0 ]; then
55 all_features+=("")
56 fi
Tomás González3286e4b2025-06-05 18:25:09 +010057fi
58
Tomás González010b6372025-04-29 17:13:47 +010059for features in "${all_features[@]}"; do
Tomás Gonzálezafd25082025-06-10 11:44:55 +010060 features=$(echo $features | sed "s/'//g")
Tomás González010b6372025-04-29 17:13:47 +010061 echo "cargo test features: '$features'" >> "$LOG_TEST_FILENAME" 2>&1
62 cargo test --features=$features >> "$LOG_TEST_FILENAME" 2>&1
63
64 if [ "$?" != 0 ]; then
65 echo "cargo test --features='$features': FAILURE"
66 ((ERROR_COUNT++))
67 else
68 echo "cargo test --features='$features': PASS"
69 fi
70
71 echo "-------------------------------------" >> "$LOG_TEST_FILENAME" 2>&1
72done
73
74echo
75
Tomás Gonzálezeb05c392025-06-12 15:48:54 +010076# Run cargo doc
77
Tomás Gonzálezeaa86c42025-07-28 12:19:15 +010078if [ "$REPO_NAME" != "rusted-firmware-a" ]; then
Tomás González2e7e1562025-06-18 14:34:34 +010079 echo "cargo doc --no-deps" >> "$LOG_TEST_FILENAME" 2>&1
Tomás Gonzálezeb05c392025-06-12 15:48:54 +010080
Tomás González2e7e1562025-06-18 14:34:34 +010081 RUSTDOCFLAGS="-D warnings" cargo doc --no-deps >> "$LOG_TEST_FILENAME" 2>&1
Tomás Gonzálezeb05c392025-06-12 15:48:54 +010082
Tomás González2e7e1562025-06-18 14:34:34 +010083 if [ "$?" != 0 ]; then
84 echo "cargo doc: FAILURE"
85 ((ERROR_COUNT++))
86 else
87 echo "cargo doc: PASS"
88 fi
89
90 echo "-------------------------------------" >> "$LOG_TEST_FILENAME" 2>&1
Tomás Gonzálezeb05c392025-06-12 15:48:54 +010091fi
92
Tomás González010b6372025-04-29 17:13:47 +010093cd -
94if [ "$ERROR_COUNT" != 0 ]; then
Tomás Gonzálezeb05c392025-06-12 15:48:54 +010095 echo "Some cargo checks have failed."
Tomás González010b6372025-04-29 17:13:47 +010096 exit 1
97fi
98
99exit 0