aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Cosgrove <tom.cosgrove@arm.com>2024-06-19 11:03:05 +0100
committerGitHub <noreply@github.com>2024-06-19 11:03:05 +0100
commit125440d3444780a6c0f32758fdbc6f4a5000953a (patch)
tree8130be47711d20984bfcc96fae5a61ffac90ffde
parentde0d7e6cd06e712581adb6d65aa3440d2d02e263 (diff)
parenta60d9223d602ef4fc29ef2917691c8abfa695b77 (diff)
downloadmbedtls-125440d3444780a6c0f32758fdbc6f4a5000953a.zip
mbedtls-125440d3444780a6c0f32758fdbc6f4a5000953a.tar.gz
mbedtls-125440d3444780a6c0f32758fdbc6f4a5000953a.tar.bz2
Merge pull request #9278 from valeriosetti/fix-psasim-logs
psa_sim: improve log prints
-rw-r--r--tests/psa-client-server/psasim/include/util.h12
-rw-r--r--tests/psa-client-server/psasim/src/client.c2
-rw-r--r--tests/psa-client-server/psasim/src/psa_ff_client.c7
-rw-r--r--tests/psa-client-server/psasim/src/psa_sim_crypto_client.c2
-rwxr-xr-xtests/psa-client-server/psasim/src/psa_sim_generate.pl2
-rw-r--r--tests/psa-client-server/psasim/src/psa_sim_serialise.c19
-rwxr-xr-xtests/psa-client-server/psasim/src/psa_sim_serialise.pl12
7 files changed, 34 insertions, 22 deletions
diff --git a/tests/psa-client-server/psasim/include/util.h b/tests/psa-client-server/psasim/include/util.h
index 558149f..5eb8238 100644
--- a/tests/psa-client-server/psasim/include/util.h
+++ b/tests/psa-client-server/psasim/include/util.h
@@ -13,20 +13,18 @@
#if defined(DEBUG)
#define INFO(fmt, ...) \
fprintf(stdout, "Info (%s - %d): " fmt "\n", __FILE__, __LINE__, ##__VA_ARGS__)
+#else /* !DEBUG */
+#define INFO(...)
+#endif /* DEBUG*/
#define ERROR(fmt, ...) \
- fprintf(stdout, "Error (%s - %d): " fmt "\n", __FILE__, __LINE__, ##__VA_ARGS__)
+ fprintf(stderr, "Error (%s - %d): " fmt "\n", __FILE__, __LINE__, ##__VA_ARGS__)
#define FATAL(fmt, ...) \
{ \
- fprintf(stdout, "Fatal (%s - %d): " fmt "\n", __FILE__, __LINE__, ##__VA_ARGS__); \
+ fprintf(stderr, "Fatal (%s - %d): " fmt "\n", __FILE__, __LINE__, ##__VA_ARGS__); \
abort(); \
}
-#else /* DEBUG */
-#define INFO(...)
-#define ERROR(...)
-#define FATAL(...)
-#endif /* DEBUG*/
#define PROJECT_ID 'M'
#define PATHNAMESIZE 256
diff --git a/tests/psa-client-server/psasim/src/client.c b/tests/psa-client-server/psasim/src/client.c
index a8c9e08..4c63abf 100644
--- a/tests/psa-client-server/psasim/src/client.c
+++ b/tests/psa-client-server/psasim/src/client.c
@@ -7,12 +7,14 @@
/* Includes from mbedtls */
#include "psa/crypto.h"
+#include "util.h"
int main()
{
/* psa_crypto_init() connects to the server */
psa_status_t status = psa_crypto_init();
if (status != PSA_SUCCESS) {
+ ERROR("psa_crypto_init returned %d", status);
return 1;
}
diff --git a/tests/psa-client-server/psasim/src/psa_ff_client.c b/tests/psa-client-server/psasim/src/psa_ff_client.c
index 21a43b3..0d6bbf3 100644
--- a/tests/psa-client-server/psasim/src/psa_ff_client.c
+++ b/tests/psa-client-server/psasim/src/psa_ff_client.c
@@ -199,7 +199,6 @@ static psa_status_t process_response(int rx_qid, vectors_t *vecs, int type,
default:
FATAL(" ERROR: unknown internal message type: %ld",
response.message_type);
- return ret;
}
}
}
@@ -301,10 +300,10 @@ psa_handle_t psa_connect(uint32_t sid, uint32_t minor_version)
handles[idx].valid = 1;
return idx;
} else {
- INFO("Server didn't like you");
+ ERROR("Server didn't like you");
}
} else {
- INFO("Couldn't contact RoT service. Does it exist?");
+ ERROR("Couldn't contact RoT service. Does it exist?");
if (__psa_ff_client_security_state == 0) {
ERROR("Invalid SID");
@@ -339,7 +338,7 @@ uint32_t psa_version(uint32_t sid)
}
}
}
- INFO("psa_version failed: does the service exist?");
+ ERROR("psa_version failed: does the service exist?");
return PSA_VERSION_NONE;
}
diff --git a/tests/psa-client-server/psasim/src/psa_sim_crypto_client.c b/tests/psa-client-server/psasim/src/psa_sim_crypto_client.c
index 2ffb615..758e9b2 100644
--- a/tests/psa-client-server/psasim/src/psa_sim_crypto_client.c
+++ b/tests/psa-client-server/psasim/src/psa_sim_crypto_client.c
@@ -22,7 +22,7 @@
#include "psa/crypto.h"
#define CLIENT_PRINT(fmt, ...) \
- PRINT("Client: " fmt, ##__VA_ARGS__)
+ INFO("Client: " fmt, ##__VA_ARGS__)
static psa_handle_t handle = -1;
diff --git a/tests/psa-client-server/psasim/src/psa_sim_generate.pl b/tests/psa-client-server/psasim/src/psa_sim_generate.pl
index ee3894f..15f5794 100755
--- a/tests/psa-client-server/psasim/src/psa_sim_generate.pl
+++ b/tests/psa-client-server/psasim/src/psa_sim_generate.pl
@@ -302,7 +302,7 @@ sub client_calls_header
#include "psa/crypto.h"
#define CLIENT_PRINT(fmt, ...) \
- PRINT("Client: " fmt, ##__VA_ARGS__)
+ INFO("Client: " fmt, ##__VA_ARGS__)
static psa_handle_t handle = -1;
diff --git a/tests/psa-client-server/psasim/src/psa_sim_serialise.c b/tests/psa-client-server/psasim/src/psa_sim_serialise.c
index 9e8c38b..aaf47db 100644
--- a/tests/psa-client-server/psasim/src/psa_sim_serialise.c
+++ b/tests/psa-client-server/psasim/src/psa_sim_serialise.c
@@ -10,6 +10,7 @@
*/
#include "psa_sim_serialise.h"
+#include "util.h"
#include <stdlib.h>
#include <string.h>
@@ -71,8 +72,7 @@ static ssize_t allocate_hash_operation_slot(void)
{
psasim_client_handle_t handle = next_hash_operation_handle++;
if (next_hash_operation_handle == 0) { /* wrapped around */
- fprintf(stderr, "MAX HASH HANDLES REACHED\n");
- exit(1);
+ FATAL("Hash operation handle wrapped");
}
for (ssize_t i = 0; i < MAX_LIVE_HANDLES_PER_CLASS; i++) {
@@ -82,6 +82,8 @@ static ssize_t allocate_hash_operation_slot(void)
}
}
+ ERROR("All slots are currently used. Unable to allocate a new one.");
+
return -1; /* all in use */
}
@@ -94,7 +96,9 @@ static ssize_t find_hash_slot_by_handle(psasim_client_handle_t handle)
}
}
- return -1; /* all in use */
+ ERROR("Unable to find slot by handle %u", handle);
+
+ return -1; /* not found */
}
static psa_aead_operation_t aead_operations[MAX_LIVE_HANDLES_PER_CLASS];
@@ -106,8 +110,7 @@ static ssize_t allocate_aead_operation_slot(void)
{
psasim_client_handle_t handle = next_aead_operation_handle++;
if (next_aead_operation_handle == 0) { /* wrapped around */
- fprintf(stderr, "MAX HASH HANDLES REACHED\n");
- exit(1);
+ FATAL("Aead operation handle wrapped");
}
for (ssize_t i = 0; i < MAX_LIVE_HANDLES_PER_CLASS; i++) {
@@ -117,6 +120,8 @@ static ssize_t allocate_aead_operation_slot(void)
}
}
+ ERROR("All slots are currently used. Unable to allocate a new one.");
+
return -1; /* all in use */
}
@@ -129,7 +134,9 @@ static ssize_t find_aead_slot_by_handle(psasim_client_handle_t handle)
}
}
- return -1; /* all in use */
+ ERROR("Unable to find slot by handle %u", handle);
+
+ return -1; /* not found */
}
size_t psasim_serialise_begin_needs(void)
diff --git a/tests/psa-client-server/psasim/src/psa_sim_serialise.pl b/tests/psa-client-server/psasim/src/psa_sim_serialise.pl
index e09bb81..c795fd4 100755
--- a/tests/psa-client-server/psasim/src/psa_sim_serialise.pl
+++ b/tests/psa-client-server/psasim/src/psa_sim_serialise.pl
@@ -724,6 +724,7 @@ sub c_header
*/
#include "psa_sim_serialise.h"
+#include "util.h"
#include <stdlib.h>
#include <string.h>
@@ -788,6 +789,8 @@ sub define_operation_type_data_and_functions
{
my ($type) = @_; # e.g. 'hash' rather than 'psa_hash_operation_t'
+ my $utype = ucfirst($type);
+
return <<EOF;
static psa_${type}_operation_t ${type}_operations[MAX_LIVE_HANDLES_PER_CLASS];
@@ -799,8 +802,7 @@ static ssize_t allocate_${type}_operation_slot(void)
{
psasim_client_handle_t handle = next_${type}_operation_handle++;
if (next_${type}_operation_handle == 0) { /* wrapped around */
- fprintf(stderr, "MAX HASH HANDLES REACHED\\n");
- exit(1);
+ FATAL("$utype operation handle wrapped");
}
for (ssize_t i = 0; i < MAX_LIVE_HANDLES_PER_CLASS; i++) {
@@ -810,6 +812,8 @@ static ssize_t allocate_${type}_operation_slot(void)
}
}
+ ERROR("All slots are currently used. Unable to allocate a new one.");
+
return -1; /* all in use */
}
@@ -822,7 +826,9 @@ static ssize_t find_${type}_slot_by_handle(psasim_client_handle_t handle)
}
}
- return -1; /* all in use */
+ ERROR("Unable to find slot by handle %u", handle);
+
+ return -1; /* not found */
}
EOF
}