psasim: merge all AUT programs into a single executable
This makes both building and testing much faster.
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
diff --git a/tests/psa-client-server/psasim/src/aut_main.c b/tests/psa-client-server/psasim/src/aut_main.c
new file mode 100644
index 0000000..e1012a5
--- /dev/null
+++ b/tests/psa-client-server/psasim/src/aut_main.c
@@ -0,0 +1,53 @@
+/**
+ * This is the base AUT that exectues all other AUTs meant to test PSA APIs
+ * through PSASIM.
+ */
+
+/*
+ * Copyright The Mbed TLS Contributors
+ * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
+ */
+
+/* First include Mbed TLS headers to get the Mbed TLS configuration and
+ * platform definitions that we'll use in this program. Also include
+ * standard C headers for functions we'll use here. */
+#include "mbedtls/build_info.h"
+
+#include "psa/crypto.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+int psa_hash_compute_main(void);
+int psa_hash_main(void);
+int psa_aead_main(char *cipher_name);
+
+#define TEST_MODULE(main_func) \
+ do { \
+ char title[128] = { 0 }; \
+ char separator[128] = { 0 }; \
+ int title_len = snprintf(title, sizeof(title), "=== Test: %s ===", #main_func); \
+ memset(separator, '=', title_len); \
+ printf("%s\n%s\n%s\n", separator, title, separator); \
+ ret = main_func; \
+ if (ret != 0) { \
+ goto exit; \
+ } \
+ } while (0)
+
+int main()
+{
+ int ret;
+
+ TEST_MODULE(psa_hash_compute_main());
+ TEST_MODULE(psa_hash_main());
+
+ TEST_MODULE(psa_aead_main("aes128-gcm"));
+ TEST_MODULE(psa_aead_main("aes256-gcm"));
+ TEST_MODULE(psa_aead_main("aes128-gcm_8"));
+ TEST_MODULE(psa_aead_main("chachapoly"));
+
+exit:
+ return (ret != 0) ? 1 : 0;
+}
diff --git a/tests/psa-client-server/psasim/src/aut_psa_aead_demo.c b/tests/psa-client-server/psasim/src/aut_psa_aead.c
similarity index 97%
rename from tests/psa-client-server/psasim/src/aut_psa_aead_demo.c
rename to tests/psa-client-server/psasim/src/aut_psa_aead.c
index 4a46c40..aa9dfb0 100644
--- a/tests/psa-client-server/psasim/src/aut_psa_aead_demo.c
+++ b/tests/psa-client-server/psasim/src/aut_psa_aead.c
@@ -46,7 +46,7 @@
!defined(MBEDTLS_AES_C) || !defined(MBEDTLS_GCM_C) || \
!defined(MBEDTLS_CHACHAPOLY_C) || \
defined(MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER))
-int main(void)
+int psa_aead_main(void)
{
printf("MBEDTLS_PSA_CRYPTO_CLIENT or "
"MBEDTLS_PSA_CRYPTO_C and/or "
@@ -257,21 +257,15 @@
/*
* Main function
*/
-int main(int argc, char **argv)
+int psa_aead_main(char *cipher_name)
{
psa_status_t status = PSA_SUCCESS;
- /* Check usage */
- if (argc != 2) {
- puts(usage);
- return EXIT_FAILURE;
- }
-
/* Initialize the PSA crypto library. */
PSA_CHECK(psa_crypto_init());
/* Run the demo */
- PSA_CHECK(aead_demo(argv[1]));
+ PSA_CHECK(aead_demo(cipher_name));
/* Deinitialize the PSA crypto library. */
mbedtls_psa_crypto_free();
diff --git a/tests/psa-client-server/psasim/src/aut_psa_hash.c b/tests/psa-client-server/psasim/src/aut_psa_hash.c
index 6c2c07e..0446e7a 100644
--- a/tests/psa-client-server/psasim/src/aut_psa_hash.c
+++ b/tests/psa-client-server/psasim/src/aut_psa_hash.c
@@ -1,13 +1,4 @@
/*
- * Example computing a SHA-256 hash using the PSA Crypto API
- *
- * The example computes the SHA-256 hash of a test string using the
- * one-shot API call psa_hash_compute() and the using multi-part
- * operation, which requires psa_hash_setup(), psa_hash_update() and
- * psa_hash_finish(). The multi-part operation is popular on embedded
- * devices where a rolling hash needs to be computed.
- *
- *
* Copyright The Mbed TLS Contributors
* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
*/
@@ -20,33 +11,13 @@
#include "mbedtls/build_info.h"
#include "mbedtls/platform.h"
-/* Information about hashing with the PSA API can be
- * found here:
- * https://arm-software.github.io/psa-api/crypto/1.1/api/ops/hashes.html
- *
- * The algorithm used by this demo is SHA 256.
- * Please see include/psa/crypto_values.h to see the other
- * algorithms that are supported by Mbed TLS.
- * If you switch to a different algorithm you will need to update
- * the hash data in the EXAMPLE_HASH_VALUE macro below. */
-
-#if !defined(MBEDTLS_PSA_CRYPTO_CLIENT) && \
- (!defined(MBEDTLS_PSA_CRYPTO_C) || !defined(PSA_WANT_ALG_SHA_256))
-int main(void)
-{
- mbedtls_printf("MBEDTLS_PSA_CRYPTO_C and PSA_WANT_ALG_SHA_256"
- "not defined, and not MBEDTLS_PSA_CRYPTO_CLIENT.\r\n");
- return EXIT_SUCCESS;
-}
-#else
-
#define HASH_ALG PSA_ALG_SHA_256
-const uint8_t sample_message[] = "Hello World!";
+static const uint8_t sample_message[] = "Hello World!";
/* sample_message is terminated with a null byte which is not part of
* the message itself so we make sure to subtract it in order to get
* the message length. */
-const size_t sample_message_length = sizeof(sample_message) - 1;
+static const size_t sample_message_length = sizeof(sample_message) - 1;
#define EXPECTED_HASH_VALUE { \
0x7f, 0x83, 0xb1, 0x65, 0x7f, 0xf1, 0xfc, 0x53, 0xb9, 0x2d, 0xc1, 0x81, \
@@ -54,10 +25,10 @@
0x4a, 0xdd, 0xd2, 0x00, 0x12, 0x6d, 0x90, 0x69 \
}
-const uint8_t expected_hash[] = EXPECTED_HASH_VALUE;
-const size_t expected_hash_len = sizeof(expected_hash);
+static const uint8_t expected_hash[] = EXPECTED_HASH_VALUE;
+static const size_t expected_hash_len = sizeof(expected_hash);
-int main(void)
+int psa_hash_main(void)
{
psa_status_t status;
uint8_t hash[PSA_HASH_LENGTH(HASH_ALG)];
@@ -157,4 +128,3 @@
psa_hash_abort(&cloned_hash_operation);
return EXIT_FAILURE;
}
-#endif /* !MBEDTLS_PSA_CRYPTO_C || !PSA_WANT_ALG_SHA_256 */
diff --git a/tests/psa-client-server/psasim/src/aut_psa_hash_compute.c b/tests/psa-client-server/psasim/src/aut_psa_hash_compute.c
index 70c3e5b..959e0c3 100644
--- a/tests/psa-client-server/psasim/src/aut_psa_hash_compute.c
+++ b/tests/psa-client-server/psasim/src/aut_psa_hash_compute.c
@@ -1,15 +1,4 @@
/*
- * API(s) under test: psa_hash_compute()
- *
- * Taken from programs/psa/psa_hash.c, and calls to all hash APIs
- * but psa_hash_compute() removed.
- *
- * Example computing a SHA-256 hash using the PSA Crypto API
- *
- * The example computes the SHA-256 hash of a test string using the
- * one-shot API call psa_hash_compute().
- *
- *
* Copyright The Mbed TLS Contributors
* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
*/
@@ -22,33 +11,13 @@
#include "mbedtls/build_info.h"
#include "mbedtls/platform.h"
-/* Information about hashing with the PSA API can be
- * found here:
- * https://arm-software.github.io/psa-api/crypto/1.1/api/ops/hashes.html
- *
- * The algorithm used by this demo is SHA 256.
- * Please see include/psa/crypto_values.h to see the other
- * algorithms that are supported by Mbed TLS.
- * If you switch to a different algorithm you will need to update
- * the hash data in the EXAMPLE_HASH_VALUE macro below. */
-
-#if !defined(MBEDTLS_PSA_CRYPTO_CLIENT) && \
- (!defined(MBEDTLS_PSA_CRYPTO_C) || !defined(PSA_WANT_ALG_SHA_256))
-int main(void)
-{
- mbedtls_printf("MBEDTLS_PSA_CRYPTO_C and PSA_WANT_ALG_SHA_256"
- "not defined, and not MBEDTLS_PSA_CRYPTO_CLIENT.\r\n");
- return EXIT_SUCCESS;
-}
-#else
-
#define HASH_ALG PSA_ALG_SHA_256
-const uint8_t sample_message[] = "Hello World!";
+static const uint8_t sample_message[] = "Hello World!";
/* sample_message is terminated with a null byte which is not part of
* the message itself so we make sure to subtract it in order to get
* the message length. */
-const size_t sample_message_length = sizeof(sample_message) - 1;
+static const size_t sample_message_length = sizeof(sample_message) - 1;
#define EXPECTED_HASH_VALUE { \
0x7f, 0x83, 0xb1, 0x65, 0x7f, 0xf1, 0xfc, 0x53, 0xb9, 0x2d, 0xc1, 0x81, \
@@ -56,10 +25,10 @@
0x4a, 0xdd, 0xd2, 0x00, 0x12, 0x6d, 0x90, 0x69 \
}
-const uint8_t expected_hash[] = EXPECTED_HASH_VALUE;
-const size_t expected_hash_len = sizeof(expected_hash);
+static const uint8_t expected_hash[] = EXPECTED_HASH_VALUE;
+static const size_t expected_hash_len = sizeof(expected_hash);
-int main(void)
+int psa_hash_compute_main(void)
{
psa_status_t status;
uint8_t hash[PSA_HASH_LENGTH(HASH_ALG)];
@@ -110,4 +79,3 @@
cleanup:
return EXIT_FAILURE;
}
-#endif /* !MBEDTLS_PSA_CRYPTO_C || !PSA_WANT_ALG_SHA_256 */