Gilles Peskine | 62cf2e8 | 2020-03-27 16:35:23 +0100 | [diff] [blame] | 1 | #! /usr/bin/env bash |
Manuel Pégourié-Gonnard | 80955ee | 2014-03-19 18:29:01 +0100 | [diff] [blame] | 2 | |
Manuel Pégourié-Gonnard | a93f988 | 2024-10-24 09:49:34 +0200 | [diff] [blame] | 3 | # all.sh (transitional wrapper) |
Simon Butcher | 3ea7f52 | 2016-03-07 23:22:10 +0000 | [diff] [blame] | 4 | # |
Bence Szépkúti | 1e14827 | 2020-08-07 13:07:28 +0200 | [diff] [blame] | 5 | # Copyright The Mbed TLS Contributors |
Dave Rodgman | 16799db | 2023-11-02 19:47:20 +0000 | [diff] [blame] | 6 | # SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later |
Gilles Peskine | 192c72f | 2017-12-21 15:59:21 +0100 | [diff] [blame] | 7 | |
Manuel Pégourié-Gonnard | 6ffebef | 2024-10-29 12:57:24 +0100 | [diff] [blame] | 8 | # This is a transitional wrapper that's only meant for the CI. |
| 9 | # Developers should directly invoke on or two of: |
Manuel Pégourié-Gonnard | a93f988 | 2024-10-24 09:49:34 +0200 | [diff] [blame] | 10 | # - tests/scripts/mbedtls-all.sh ... |
| 11 | # - (cd tf-psa-crypto && tests/scripts/all.sh ...) |
Manuel Pégourié-Gonnard | 6ffebef | 2024-10-29 12:57:24 +0100 | [diff] [blame] | 12 | # |
| 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é-Gonnard | 7b55695 | 2024-10-09 11:18:43 +0200 | [diff] [blame] | 31 | |
Manuel Pégourié-Gonnard | 8da0e9e | 2024-10-23 09:42:47 +0200 | [diff] [blame] | 32 | # This script must be invoked from the project's root. |
| 33 | |
Manuel Pégourié-Gonnard | 6ffebef | 2024-10-29 12:57:24 +0100 | [diff] [blame] | 34 | # 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é-Gonnard | a93f988 | 2024-10-24 09:49:34 +0200 | [diff] [blame] | 41 | set -eu |
Gilles Peskine | 8f07312 | 2018-11-27 15:58:47 +0100 | [diff] [blame] | 42 | |
Manuel Pégourié-Gonnard | 6ffebef | 2024-10-29 12:57:24 +0100 | [diff] [blame] | 43 | # Cases 1-3 |
| 44 | if [ "$#" -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 |
| 56 | fi |
| 57 | |
Manuel Pégourié-Gonnard | dea700d | 2024-11-04 11:40:44 +0100 | [diff] [blame^] | 58 | if [ "$#" -ne 4 -o "${1:-unset}" != '--seed' -o "${3:-unset}" != '--keep-going' ]; then |
Manuel Pégourié-Gonnard | 6ffebef | 2024-10-29 12:57:24 +0100 | [diff] [blame] | 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 |
| 62 | fi |
| 63 | |
| 64 | # Case 4: invoke the right all.sh for this component |
| 65 | comp_name=$4 |
| 66 | |
Manuel Pégourié-Gonnard | a93f988 | 2024-10-24 09:49:34 +0200 | [diff] [blame] | 67 | # Get the list of components available on each side. |
Manuel Pégourié-Gonnard | 6ffebef | 2024-10-29 12:57:24 +0100 | [diff] [blame] | 68 | COMP_MBEDTLS=$(tests/scripts/mbedtls-all.sh --list-all-components | tr '\n' ' ') |
| 69 | COMP_CRYPTO=$(cd tf-psa-crypto && tests/scripts/all.sh --list-all-components | tr '\n' ' ') |
Manuel Pégourié-Gonnard | a93f988 | 2024-10-24 09:49:34 +0200 | [diff] [blame] | 70 | |
Manuel Pégourié-Gonnard | 6ffebef | 2024-10-29 12:57:24 +0100 | [diff] [blame] | 71 | # tell if $1 is in space-separated list $2 |
| 72 | is_in() { |
| 73 | needle=$1 |
| 74 | haystack=$2 |
| 75 | case " $haystack " in |
| 76 | *" $needle "*) echo 1;; |
| 77 | *) echo 0;; |
Manuel Pégourié-Gonnard | a93f988 | 2024-10-24 09:49:34 +0200 | [diff] [blame] | 78 | esac |
Manuel Pégourié-Gonnard | 6ffebef | 2024-10-29 12:57:24 +0100 | [diff] [blame] | 79 | } |
Manuel Pégourié-Gonnard | a93f988 | 2024-10-24 09:49:34 +0200 | [diff] [blame] | 80 | |
Manuel Pégourié-Gonnard | 6ffebef | 2024-10-29 12:57:24 +0100 | [diff] [blame] | 81 | is_crypto=$(is_in "$comp_name" "$COMP_CRYPTO") |
| 82 | is_mbedtls=$(is_in "$comp_name" "$COMP_MBEDTLS") |
Manuel Pégourié-Gonnard | a93f988 | 2024-10-24 09:49:34 +0200 | [diff] [blame] | 83 | |
Manuel Pégourié-Gonnard | 6ffebef | 2024-10-29 12:57:24 +0100 | [diff] [blame] | 84 | # Component should be on exactly one side (see comment near the top). |
| 85 | if [ "$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 |
| 89 | fi |
| 90 | if [ "$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é-Gonnard | a93f988 | 2024-10-24 09:49:34 +0200 | [diff] [blame] | 94 | fi |
| 95 | |
Manuel Pégourié-Gonnard | d10f42f | 2024-10-30 09:52:36 +0100 | [diff] [blame] | 96 | |
Manuel Pégourié-Gonnard | 6ffebef | 2024-10-29 12:57:24 +0100 | [diff] [blame] | 97 | # Invoke the real thing |
| 98 | if [ "$is_crypto" -eq 1 ]; then |
Manuel Pégourié-Gonnard | d10f42f | 2024-10-30 09:52:36 +0100 | [diff] [blame] | 99 | # 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é-Gonnard | 6ffebef | 2024-10-29 12:57:24 +0100 | [diff] [blame] | 108 | cd tf-psa-crypto |
| 109 | exec tests/scripts/all.sh "$@" |
Manuel Pégourié-Gonnard | a93f988 | 2024-10-24 09:49:34 +0200 | [diff] [blame] | 110 | else |
Manuel Pégourié-Gonnard | 6ffebef | 2024-10-29 12:57:24 +0100 | [diff] [blame] | 111 | exec tests/scripts/mbedtls-all.sh "$@" |
Manuel Pégourié-Gonnard | a93f988 | 2024-10-24 09:49:34 +0200 | [diff] [blame] | 112 | fi |