blob: 20ca89951d2b53912c572ef315fee6adebca67b6 [file] [log] [blame]
Gilles Peskine62cf2e82020-03-27 16:35:23 +01001#! /usr/bin/env bash
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01002
Manuel Pégourié-Gonnarda93f9882024-10-24 09:49:34 +02003# all.sh (transitional wrapper)
Simon Butcher3ea7f522016-03-07 23:22:10 +00004#
Bence Szépkúti1e148272020-08-07 13:07:28 +02005# Copyright The Mbed TLS Contributors
Dave Rodgman16799db2023-11-02 19:47:20 +00006# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
Gilles Peskine192c72f2017-12-21 15:59:21 +01007
Manuel Pégourié-Gonnard6ffebef2024-10-29 12:57:24 +01008# This is a transitional wrapper that's only meant for the CI.
9# Developers should directly invoke on or two of:
Manuel Pégourié-Gonnarda93f9882024-10-24 09:49:34 +020010# - tests/scripts/mbedtls-all.sh ...
11# - (cd tf-psa-crypto && tests/scripts/all.sh ...)
Manuel Pégourié-Gonnard6ffebef2024-10-29 12:57:24 +010012#
13# During the transition, it's illegal for a tf-psa-crypto component to have
14# the same name as an mbedtls components; since this wrapper handles both
15# sides at once, component names need to be globally unique. Once the
16# transition period is over, unicity on each side will be enough.
17#
18# For context, here are the steps of the transition:
19# 1. We have an all.sh in tf-psa-crypto but for now we don't invoke it directly
20# on the CI, only through this transitional wrapper in mbedtls. (tf-psa-crypto
21# doesn't have its own CI initially and runs Mbed TLS's instead.)
22# 2. We move all relevant components to tf-psa-crypto so that it gets the level of
23# coverage we want. We need to make sure the new names are unique.
24# 3. We change the CI job on tf-psa-crypto to stop checking out mbedtls and running
25# its all.sh - instead we do the normal thing of checking out tf-psa-crypto and
26# running its all.sh. (In two steps: (a) add the new job, (b) remove the old
27# one.)
28# 4. We remove the transitional wrapper in mbedtls and we're now free to rename
29# tf-psa-crypto components as we want. If we followed a consistent naming
30# pattern, this can be as simple as s/_tf_psa_crypto// in components-*.sh.
Manuel Pégourié-Gonnard7b556952024-10-09 11:18:43 +020031
Manuel Pégourié-Gonnard8da0e9e2024-10-23 09:42:47 +020032# This script must be invoked from the project's root.
33
Manuel Pégourié-Gonnard6ffebef2024-10-29 12:57:24 +010034# There are exactly 4 ways this is invoked in the CI:
35# 1. tests/scripts/all.sh --help
36# 2. tests/scripts/all.sh --list-all-components
37# 3. tests/scripts/all.sh --list-components
38# 4. tests/scripts/all.sh --seed 4 --keep-going single_component_name
39# This wrapper does not support other invocations.
40
Manuel Pégourié-Gonnarda93f9882024-10-24 09:49:34 +020041set -eu
Gilles Peskine8f073122018-11-27 15:58:47 +010042
Manuel Pégourié-Gonnard6ffebef2024-10-29 12:57:24 +010043# Cases 1-3
44if [ "$#" -eq 1 ]; then
45 if [ "$1" = '--help' ]; then
46 # It doesn't matter which one we use, they're the same
47 tests/scripts/mbedtls-all.sh "$1"
48 exit 0
49 fi
50 if [ "$1" = '--list-all-components' -o "$1" = '--list-components' ]; then
51 # Invoke both
52 tests/scripts/mbedtls-all.sh "$1"
53 (cd tf-psa-crypto && tests/scripts/all.sh "$1")
54 exit 0
55 fi
56fi
57
58if [ "$#" -ne 4 -o "$1" != '--seed' -o "$3" != '--keep-going' ]; then
59 echo "This invocation is not supported by the transitional wrapper." >&2
60 echo "See the comments at the top of $0." >&2
61 exit 1
62fi
63
64# Case 4: invoke the right all.sh for this component
65comp_name=$4
66
Manuel Pégourié-Gonnarda93f9882024-10-24 09:49:34 +020067# Get the list of components available on each side.
Manuel Pégourié-Gonnard6ffebef2024-10-29 12:57:24 +010068COMP_MBEDTLS=$(tests/scripts/mbedtls-all.sh --list-all-components | tr '\n' ' ')
69COMP_CRYPTO=$(cd tf-psa-crypto && tests/scripts/all.sh --list-all-components | tr '\n' ' ')
Manuel Pégourié-Gonnarda93f9882024-10-24 09:49:34 +020070
Manuel Pégourié-Gonnard6ffebef2024-10-29 12:57:24 +010071# tell if $1 is in space-separated list $2
72is_in() {
73 needle=$1
74 haystack=$2
75 case " $haystack " in
76 *" $needle "*) echo 1;;
77 *) echo 0;;
Manuel Pégourié-Gonnarda93f9882024-10-24 09:49:34 +020078 esac
Manuel Pégourié-Gonnard6ffebef2024-10-29 12:57:24 +010079}
Manuel Pégourié-Gonnarda93f9882024-10-24 09:49:34 +020080
Manuel Pégourié-Gonnard6ffebef2024-10-29 12:57:24 +010081is_crypto=$(is_in "$comp_name" "$COMP_CRYPTO")
82is_mbedtls=$(is_in "$comp_name" "$COMP_MBEDTLS")
Manuel Pégourié-Gonnarda93f9882024-10-24 09:49:34 +020083
Manuel Pégourié-Gonnard6ffebef2024-10-29 12:57:24 +010084# Component should be on exactly one side (see comment near the top).
85if [ "$is_crypto" -eq 1 -a "$is_mbedtls" -eq 1 ]; then
86 echo "Component '$comp_name' is both in crypto and Mbed TLS". >&2
87 echo "See the comments at the top of $0." >&2
88 exit 1
89fi
90if [ "$is_crypto" -eq 0 -a "$is_mbedtls" -eq 0 ]; then
91 echo "Component '$comp_name' is neither in crypto nor in Mbed TLS". >&2
92 echo "See the comments at the top of $0." >&2
93 exit 1
Manuel Pégourié-Gonnarda93f9882024-10-24 09:49:34 +020094fi
95
Manuel Pégourié-Gonnardd10f42f2024-10-30 09:52:36 +010096
Manuel Pégourié-Gonnard6ffebef2024-10-29 12:57:24 +010097# Invoke the real thing
98if [ "$is_crypto" -eq 1 ]; then
Manuel Pégourié-Gonnardd10f42f2024-10-30 09:52:36 +010099 # Make sure the path to the outcomes file is absolute. This is done by
100 # pre_prepare_outcome_file() however by the time it runs we've already
101 # changed the working directory, so do it now.
102 if [ -n "${MBEDTLS_TEST_OUTCOME_FILE+set}" ]; then
103 case "$MBEDTLS_TEST_OUTCOME_FILE" in
104 [!/]*) MBEDTLS_TEST_OUTCOME_FILE="$PWD/$MBEDTLS_TEST_OUTCOME_FILE";;
105 esac
106 export MBEDTLS_TEST_OUTCOME_FILE
107 fi
Manuel Pégourié-Gonnard6ffebef2024-10-29 12:57:24 +0100108 cd tf-psa-crypto
109 exec tests/scripts/all.sh "$@"
Manuel Pégourié-Gonnarda93f9882024-10-24 09:49:34 +0200110else
Manuel Pégourié-Gonnard6ffebef2024-10-29 12:57:24 +0100111 exec tests/scripts/mbedtls-all.sh "$@"
Manuel Pégourié-Gonnarda93f9882024-10-24 09:49:34 +0200112fi