blob: ab6167f2fa4f85de72a9f2b253c691815bec06c2 [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
Tomás González3286e4b2025-06-05 18:25:09 +010024# 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
26SSH_PARAMS="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o PubkeyAcceptedKeyTypes=+ssh-rsa -p 29418 -i ${CI_BOT_KEY}"
27REPO_SSH_URL="ssh://${CI_BOT_USERNAME}@review.trustedfirmware.org:29418/${REPO_SPACE}/${REPO_NAME}"
28export GIT_SSH_COMMAND="ssh ${SSH_PARAMS}"
29
30cd "${REPO_NAME}"
31
32if [ "$REPO_NAME" == "trusted-firmware-a" ] && ["$IS_CONTINUOUS_INTEGRATION" == 1 ]; then
Tomás González010b6372025-04-29 17:13:47 +010033 git remote set-url origin ${REPO_SSH_URL}
34 git fetch origin
35fi
36
37TEST_CASE="cargo test checks"
38
39echo "# ${TEST_CASE}"
40echo >> "$LOG_TEST_FILENAME"
41echo "****** $TEST_CASE ******" >> "$LOG_TEST_FILENAME"
42echo >> "$LOG_TEST_FILENAME"
43
Tomás González010b6372025-04-29 17:13:47 +010044ERROR_COUNT=0
45
46# Run cargo test
47
Tomás González3286e4b2025-06-05 18:25:09 +010048if [ "$REPO_NAME" == "trusted-firmware-a" ]; then
Tomás Gonzálezafd25082025-06-10 11:44:55 +010049 # These tests are platform independent. However, we are specifying a platform:
50 # The fvp platform is expected to cover all platform independent features that can be tested
51 # with cargo test.
52 IFS=" " read -a all_features <<< "$(make PLAT=fvp --silent list_features)"
Tomás González3286e4b2025-06-05 18:25:09 +010053else
Tomás Gonzálezeb05c392025-06-12 15:48:54 +010054 IFS=" " read -a all_features <<< ${TEST_FEATURES}
55 if [ ${#all_features[@]} = 0 ]; then
56 all_features+=("")
57 fi
Tomás González3286e4b2025-06-05 18:25:09 +010058fi
59
Tomás González010b6372025-04-29 17:13:47 +010060for features in "${all_features[@]}"; do
Tomás Gonzálezafd25082025-06-10 11:44:55 +010061 features=$(echo $features | sed "s/'//g")
Tomás González010b6372025-04-29 17:13:47 +010062 echo "cargo test features: '$features'" >> "$LOG_TEST_FILENAME" 2>&1
63 cargo test --features=$features >> "$LOG_TEST_FILENAME" 2>&1
64
65 if [ "$?" != 0 ]; then
66 echo "cargo test --features='$features': FAILURE"
67 ((ERROR_COUNT++))
68 else
69 echo "cargo test --features='$features': PASS"
70 fi
71
72 echo "-------------------------------------" >> "$LOG_TEST_FILENAME" 2>&1
73done
74
75echo
76
Tomás Gonzálezeb05c392025-06-12 15:48:54 +010077# Run cargo doc
78
Tomás González2e7e1562025-06-18 14:34:34 +010079if [ "$REPO_NAME" != "trusted-firmware-a" ]; then
80 echo "cargo doc --no-deps" >> "$LOG_TEST_FILENAME" 2>&1
Tomás Gonzálezeb05c392025-06-12 15:48:54 +010081
Tomás González2e7e1562025-06-18 14:34:34 +010082 RUSTDOCFLAGS="-D warnings" cargo doc --no-deps >> "$LOG_TEST_FILENAME" 2>&1
Tomás Gonzálezeb05c392025-06-12 15:48:54 +010083
Tomás González2e7e1562025-06-18 14:34:34 +010084 if [ "$?" != 0 ]; then
85 echo "cargo doc: FAILURE"
86 ((ERROR_COUNT++))
87 else
88 echo "cargo doc: PASS"
89 fi
90
91 echo "-------------------------------------" >> "$LOG_TEST_FILENAME" 2>&1
Tomás Gonzálezeb05c392025-06-12 15:48:54 +010092fi
93
Tomás González010b6372025-04-29 17:13:47 +010094cd -
95if [ "$ERROR_COUNT" != 0 ]; then
Tomás Gonzálezeb05c392025-06-12 15:48:54 +010096 echo "Some cargo checks have failed."
Tomás González010b6372025-04-29 17:13:47 +010097 exit 1
98fi
99
100exit 0