|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# ------------------------------------------------------------------------------ |
| 4 | +# Copyright (c) 2019, Arm Limited, All Rights Reserved |
| 5 | +# SPDX-License-Identifier: Apache-2.0 |
| 6 | +# |
| 7 | +# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 8 | +# not use this file except in compliance with the License. |
| 9 | +# You may obtain a copy of the License at |
| 10 | +# |
| 11 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +# |
| 13 | +# Unless required by applicable law or agreed to in writing, software |
| 14 | +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 15 | +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | +# See the License for the specific language governing permissions and |
| 17 | +# limitations under the License. |
| 18 | +# ------------------------------------------------------------------------------ |
| 19 | + |
| 20 | +set -e |
| 21 | + |
| 22 | +usage () { |
| 23 | + printf " |
| 24 | +Continuous Integration test script |
| 25 | +
|
| 26 | +This script will execute various tests targeting a platform with a |
| 27 | +single provider or all providers included. |
| 28 | +It is meant to be executed inside one of the container |
| 29 | +which Dockerfiles are in tests/per_provider/provider_cfg/*/ |
| 30 | +or tests/all_providers/ |
| 31 | +
|
| 32 | +Usage: ./tests/ci.sh PROVIDER_NAME |
| 33 | +where PROVIDER_NAME can be one of: |
| 34 | + - mbed-crypto |
| 35 | + - pkcs11 |
| 36 | + - tpm |
| 37 | + - all |
| 38 | +" |
| 39 | +} |
| 40 | + |
| 41 | +# Check if the PROVIDER_NAME was given. |
| 42 | +if [ $# -eq 0 ] |
| 43 | +then |
| 44 | + echo "error: a provider name needs to be given as input argument to that script." |
| 45 | + usage |
| 46 | + exit 1 |
| 47 | +fi |
| 48 | + |
| 49 | +# Switch amoung parameters |
| 50 | +if [[ $1 = "mbed-crypto" ]] |
| 51 | +then |
| 52 | + # Mbed Cyypto provider |
| 53 | + FEATURES="--no-default-features --features=$1-provider" |
| 54 | + CONFIG_PATH="tests/per_provider/provider_cfg/$1/config.toml" |
| 55 | +elif [[ $1 = "tpm" ]] |
| 56 | +then |
| 57 | + # TPM provider |
| 58 | + FEATURES="--no-default-features --features=$1-provider" |
| 59 | + CONFIG_PATH="tests/per_provider/provider_cfg/$1/config.toml" |
| 60 | + |
| 61 | + tpm_server & |
| 62 | + sleep 5 |
| 63 | + tpm2_startup -c -T mssim |
| 64 | +elif [[ $1 = "pkcs11" ]] |
| 65 | +then |
| 66 | + # PKCS11 provider |
| 67 | + FEATURES="--no-default-features --features=$1-provider" |
| 68 | + CONFIG_PATH="tests/per_provider/provider_cfg/$1/config.toml" |
| 69 | + |
| 70 | + # Find and append the slot number at the end of the configuration file. |
| 71 | + tests/per_provider/provider_cfg/pkcs11/find_slot_number.sh $CONFIG_PATH |
| 72 | +elif [[ $1 = "all" ]] |
| 73 | +then |
| 74 | + # All providers |
| 75 | + FEATURES="--all-features" |
| 76 | + CONFIG_PATH="tests/all_providers/config.toml" |
| 77 | + |
| 78 | + tpm_server & |
| 79 | + sleep 5 |
| 80 | + tpm2_startup -c -T mssim |
| 81 | + |
| 82 | + tests/per_provider/provider_cfg/pkcs11/find_slot_number.sh $CONFIG_PATH |
| 83 | +else |
| 84 | + echo "error: PROVIDER_NAME given (\"$1\") is invalid." |
| 85 | + usage |
| 86 | + exit 1 |
| 87 | +fi |
| 88 | + |
| 89 | +############## |
| 90 | +# Build test # |
| 91 | +############## |
| 92 | +RUST_BACKTRACE=1 cargo build -vv $FEATURES |
| 93 | + |
| 94 | +################# |
| 95 | +# Static checks # |
| 96 | +################# |
| 97 | +# On native target clippy or fmt might not be available. |
| 98 | +if rustup component list | grep -q fmt |
| 99 | +then |
| 100 | + cargo fmt --all -- --check |
| 101 | +fi |
| 102 | +if rustup component list | grep -q clippy |
| 103 | +then |
| 104 | + cargo clippy --all-targets $FEATURES -- -D warnings |
| 105 | +fi |
| 106 | + |
| 107 | +############################ |
| 108 | +# Unit tests and doc tests # |
| 109 | +############################ |
| 110 | +RUST_BACKTRACE=1 cargo test --lib $FEATURES |
| 111 | +RUST_BACKTRACE=1 cargo test --doc $FEATURES |
| 112 | + |
| 113 | +###################################### |
| 114 | +# Start Parsec for integration tests # |
| 115 | +###################################### |
| 116 | +RUST_BACKTRACE=1 cargo run -vv $FEATURES -- --config $CONFIG_PATH & |
| 117 | +SERVER_PID=$! |
| 118 | +# Sleep time needed to make sure Parsec is ready before launching the tests. |
| 119 | +sleep 5 |
| 120 | + |
| 121 | +if [[ $1 = "all" ]] |
| 122 | +then |
| 123 | + # All providers tests |
| 124 | + RUST_BACKTRACE=1 cargo test -vv $FEATURES all_providers |
| 125 | +else |
| 126 | + # Per provider tests |
| 127 | + ################ |
| 128 | + # Normal tests # |
| 129 | + ################ |
| 130 | + RUST_BACKTRACE=1 cargo test -vv $FEATURES normal_tests |
| 131 | + |
| 132 | + ##################### |
| 133 | + # Persistence tests # |
| 134 | + ##################### |
| 135 | + RUST_BACKTRACE=1 cargo test -vv $FEATURES persistent-before |
| 136 | + |
| 137 | + # Create a fake mapping file for the root application, the provider and a |
| 138 | + # key name of "Test Key". It contains a valid PSA Key ID. |
| 139 | + # It is tested in test "should_have_been_deleted". |
| 140 | + # This test does not make sense for the TPM provider. |
| 141 | + if [[ $1 = "mbed-crypto" ]] |
| 142 | + then |
| 143 | + # For Mbed Provider |
| 144 | + mkdir -p mappings/cm9vdA==/1 |
| 145 | + printf '\xe0\x19\xb2\x5c' > mappings/cm9vdA==/1/VGVzdCBLZXk\= |
| 146 | + elif [[ $1 = "pkcs11" ]] |
| 147 | + then |
| 148 | + # For PKCS 11 Provider |
| 149 | + mkdir -p mappings/cm9vdA==/2 |
| 150 | + printf '\xe0\x19\xb2\x5c' > mappings/cm9vdA==/2/VGVzdCBLZXk\= |
| 151 | + fi |
| 152 | + |
| 153 | + # Trigger a configuration reload to load the new mappings. |
| 154 | + kill -s SIGHUP $SERVER_PID |
| 155 | + |
| 156 | + RUST_BACKTRACE=1 cargo test -vv $FEATURES persistent-after |
| 157 | + |
| 158 | + ################ |
| 159 | + # Stress tests # |
| 160 | + ################ |
| 161 | + RUST_BACKTRACE=1 cargo test -vv $FEATURES stress_test |
| 162 | +fi |
| 163 | + |
| 164 | +kill $SERVER_PID |
| 165 | +cargo clean |
0 commit comments