1# components-psasim.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 test components that are executed by all.sh
7
8################################################################
9#### Remote Procedure Call PSA Testing
10################################################################
11
12# Helper function for controlling (start & stop) the psasim server.
13helper_psasim_server() {
14    OPERATION=$1
15    if [ "$OPERATION" == "start" ]; then
16        msg "start server in tests"
17        (
18            cd tests
19            ../$PSASIM_PATH/test/start_server.sh
20        )
21        msg "start server in tf-psa-crypto/tests"
22        (
23            cd tf-psa-crypto/tests
24            ../../$PSASIM_PATH/test/start_server.sh
25        )
26    else
27        msg "terminate server in tests"
28        (
29            # This will kill both servers and clean up all the message queues,
30            # and clear temporary files in tests
31            cd tests
32            ../$PSASIM_PATH/test/kill_servers.sh
33        )
34        msg "terminate server in tf-psa-crypto/tests"
35        (
36            # This just clears temporary files in tf-psa-crypto/tests
37            cd tf-psa-crypto/tests
38            ../../$PSASIM_PATH/test/kill_servers.sh
39        )
40    fi
41}
42
43component_test_psasim() {
44    msg "build server library and application"
45    scripts/config.py crypto
46    helper_psasim_config server
47    helper_psasim_build server
48
49    helper_psasim_cleanup_before_client
50
51    msg "build library for client"
52    helper_psasim_config client
53    helper_psasim_build client
54
55    msg "build basic psasim client"
56    make -C $PSASIM_PATH CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS" test/psa_client_base
57    msg "test basic psasim client"
58    $PSASIM_PATH/test/run_test.sh psa_client_base
59
60    msg "build full psasim client"
61    make -C $PSASIM_PATH CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS" test/psa_client_full
62    msg "test full psasim client"
63    $PSASIM_PATH/test/run_test.sh psa_client_full
64
65    helper_psasim_server kill
66    make -C $PSASIM_PATH clean
67}
68
69component_test_suite_with_psasim()
70{
71    msg "build server library and application"
72    helper_psasim_config server
73    # Modify server's library configuration here (if needed)
74    helper_psasim_build server
75
76    helper_psasim_cleanup_before_client
77
78    msg "build client library"
79    helper_psasim_config client
80    # PAKE functions are still unsupported from PSASIM
81    scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_JPAKE
82    scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
83    helper_psasim_build client
84
85    msg "build test suites"
86    make PSASIM=1 CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS" tests
87
88    helper_psasim_server start
89
90    # psasim takes an extremely long execution time on some test suites so we
91    # exclude them from the list.
92    SKIP_TEST_SUITES="constant_time_hmac,lmots,lms"
93    export SKIP_TEST_SUITES
94
95    msg "run test suites"
96    make PSASIM=1 test
97
98    helper_psasim_server kill
99}
100