blob: df4f547c77b9a97d34df200d5e89bf274412fe1f [file] [log] [blame]
Minos Galanakis6aab5b72024-07-25 14:24:37 +01001# components.sh
2#
3# Copyright The Mbed TLS Contributors
4# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
5
6# This file contains the test components that are executed by all.sh
7
8# The functions below are named as follows:
9# * component_XXX: independent components. They can be run in any order.
10# * component_check_XXX: quick tests that aren't worth parallelizing.
11# * component_build_XXX: build things but don't run them.
12# * component_test_XXX: build and test.
13# * component_release_XXX: tests that the CI should skip during PR testing.
14# * support_XXX: if support_XXX exists and returns false then
15# component_XXX is not run by default.
16
17# Each component must start by invoking `msg` with a short informative message.
18#
19# Warning: due to the way bash detects errors, the failure of a command
20# inside 'if' or '!' is not detected. Use the 'not' function instead of '!'.
21#
22# Each component is executed in a separate shell process. The component
23# fails if any command in it returns a non-zero status.
24#
25# The framework in all.sh performs some cleanup tasks after each component.
26# This means that components can assume that the working directory is in a
27# cleaned-up state, and don't need to perform the cleanup themselves.
28# * Run `make clean`.
29# * Restore `include/mbedtls/mbedtls_config.h` from a backup made before running
30# the component.
31# * Check out `Makefile`, `library/Makefile`, `programs/Makefile`,
32# `tests/Makefile` and `programs/fuzz/Makefile` from git.
33# This cleans up after an in-tree use of CMake.
34#
35# The tests are roughly in order from fastest to slowest. This doesn't
36# have to be exact, but in general you should add slower tests towards
37# the end and fast checks near the beginning.
38
39
40################################################################
41#### Build and test many configurations and targets
42################################################################
Minos Galanakisada21b02024-07-26 12:34:19 +010043
44# Helper function for controlling (start & stop) the psasim server.
45helper_psasim_server() {
46 OPERATION=$1
47 if [ "$OPERATION" == "start" ]; then
48 (
49 cd tests
50 msg "start server in tests"
51 psa-client-server/psasim/test/start_server.sh
52 msg "start server in tf-psa-crypto/tests"
53 cd ../tf-psa-crypto/tests
54 ../../tests/psa-client-server/psasim/test/start_server.sh
55 )
56 else
57 (
58 msg "terminate servers and cleanup"
59 tests/psa-client-server/psasim//test/kill_servers.sh
60
61 # Remove temporary files and logs
62 cd tests
63 rm -f psa_notify_*
64 rm -f psa_service_*
65 rm -f psa_server.log
66
67 cd ../tf-psa-crypto/tests
68 rm -f psa_notify_*
69 rm -f psa_service_*
70 rm -f psa_server.log
71 )
72 fi
73}
74
Minos Galanakisada21b02024-07-26 12:34:19 +010075component_test_no_rsa_key_pair_generation() {
76 msg "build: default config minus PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE"
77 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
78 scripts/config.py unset MBEDTLS_GENPRIME
79 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE
80 make
81
82 msg "test: default config minus PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE"
83 make test
84}
85
Minos Galanakisada21b02024-07-26 12:34:19 +010086component_test_full_no_cipher () {
87 msg "build: full no CIPHER"
88
89 scripts/config.py full
90 scripts/config.py unset MBEDTLS_CIPHER_C
91
92 # The built-in implementation of the following algs/key-types depends
93 # on CIPHER_C so we disable them.
94 # This does not hold for KEY_TYPE_CHACHA20 and ALG_CHACHA20_POLY1305
95 # so we keep them enabled.
96 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CCM_STAR_NO_TAG
97 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CMAC
98 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CBC_NO_PADDING
99 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CBC_PKCS7
100 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CFB
101 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CTR
102 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_ECB_NO_PADDING
103 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_OFB
104 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128
105 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_STREAM_CIPHER
106 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_KEY_TYPE_DES
107
108 # The following modules directly depends on CIPHER_C
109 scripts/config.py unset MBEDTLS_CMAC_C
110 scripts/config.py unset MBEDTLS_NIST_KW_C
111
112 make
113
114 # Ensure that CIPHER_C was not re-enabled
115 not grep mbedtls_cipher_init ${BUILTIN_SRC_PATH}/cipher.o
116
117 msg "test: full no CIPHER"
118 make test
119}
120
Minos Galanakisdb7b1bb2024-07-26 13:39:09 +0100121component_test_psasim () {
Minos Galanakisada21b02024-07-26 12:34:19 +0100122 msg "build server library and application"
123 scripts/config.py crypto
124 helper_psasim_config server
125 helper_psasim_build server
126
127 helper_psasim_cleanup_before_client
128
129 msg "build library for client"
130 helper_psasim_config client
131 helper_psasim_build client
132
133 msg "build basic psasim client"
134 make -C tests/psa-client-server/psasim CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS" test/psa_client_base
135 msg "test basic psasim client"
136 tests/psa-client-server/psasim/test/run_test.sh psa_client_base
137
138 msg "build full psasim client"
139 make -C tests/psa-client-server/psasim CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS" test/psa_client_full
140 msg "test full psasim client"
141 tests/psa-client-server/psasim/test/run_test.sh psa_client_full
142
143 make -C tests/psa-client-server/psasim clean
144}
145
Minos Galanakisdb7b1bb2024-07-26 13:39:09 +0100146component_test_suite_with_psasim () {
Minos Galanakisada21b02024-07-26 12:34:19 +0100147 msg "build server library and application"
148 helper_psasim_config server
149 # Modify server's library configuration here (if needed)
150 helper_psasim_build server
151
152 helper_psasim_cleanup_before_client
153
154 msg "build client library"
155 helper_psasim_config client
156 # PAKE functions are still unsupported from PSASIM
157 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_JPAKE
158 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
159 helper_psasim_build client
160
161 msg "build test suites"
162 make PSASIM=1 CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS" tests
163
164 helper_psasim_server kill
165 helper_psasim_server start
166
167 # psasim takes an extremely long execution time on some test suites so we
168 # exclude them from the list.
169 SKIP_TEST_SUITES="constant_time_hmac,lmots,lms"
170 export SKIP_TEST_SUITES
171
172 msg "run test suites"
173 make PSASIM=1 test
174
175 helper_psasim_server kill
Minos Galanakis85c78f52024-07-26 14:11:08 +0100176}