mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-04-16 08:42:50 +00:00
psa_sim: improve log prints
- always print ERROR and FATAL messages because they should never occur, but when they do it's important to see them immediately; - keep INFO prints under DEBUG guard; - set client's PRINT as INFO message because otherwise it will mess test_suites's output; - change some error messages from INFO to ERROR because that's what they are. Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
This commit is contained in:
parent
7c52100fbd
commit
2eb8cc7d9d
@ -13,20 +13,18 @@
|
|||||||
#if defined(DEBUG)
|
#if defined(DEBUG)
|
||||||
#define INFO(fmt, ...) \
|
#define INFO(fmt, ...) \
|
||||||
fprintf(stdout, "Info (%s - %d): " fmt "\n", __FILE__, __LINE__, ##__VA_ARGS__)
|
fprintf(stdout, "Info (%s - %d): " fmt "\n", __FILE__, __LINE__, ##__VA_ARGS__)
|
||||||
|
#else /* !DEBUG */
|
||||||
|
#define INFO(...)
|
||||||
|
#endif /* DEBUG*/
|
||||||
|
|
||||||
#define ERROR(fmt, ...) \
|
#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, ...) \
|
#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(); \
|
abort(); \
|
||||||
}
|
}
|
||||||
#else /* DEBUG */
|
|
||||||
#define INFO(...)
|
|
||||||
#define ERROR(...)
|
|
||||||
#define FATAL(...)
|
|
||||||
#endif /* DEBUG*/
|
|
||||||
|
|
||||||
#define PROJECT_ID 'M'
|
#define PROJECT_ID 'M'
|
||||||
#define PATHNAMESIZE 256
|
#define PATHNAMESIZE 256
|
||||||
|
@ -7,12 +7,14 @@
|
|||||||
|
|
||||||
/* Includes from mbedtls */
|
/* Includes from mbedtls */
|
||||||
#include "psa/crypto.h"
|
#include "psa/crypto.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
/* psa_crypto_init() connects to the server */
|
/* psa_crypto_init() connects to the server */
|
||||||
psa_status_t status = psa_crypto_init();
|
psa_status_t status = psa_crypto_init();
|
||||||
if (status != PSA_SUCCESS) {
|
if (status != PSA_SUCCESS) {
|
||||||
|
ERROR("psa_crypto_init returned %d", status);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,7 +199,6 @@ static psa_status_t process_response(int rx_qid, vectors_t *vecs, int type,
|
|||||||
default:
|
default:
|
||||||
FATAL(" ERROR: unknown internal message type: %ld",
|
FATAL(" ERROR: unknown internal message type: %ld",
|
||||||
response.message_type);
|
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;
|
handles[idx].valid = 1;
|
||||||
return idx;
|
return idx;
|
||||||
} else {
|
} else {
|
||||||
INFO("Server didn't like you");
|
ERROR("Server didn't like you");
|
||||||
}
|
}
|
||||||
} else {
|
} 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) {
|
if (__psa_ff_client_security_state == 0) {
|
||||||
ERROR("Invalid SID");
|
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;
|
return PSA_VERSION_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
#include "psa/crypto.h"
|
#include "psa/crypto.h"
|
||||||
|
|
||||||
#define CLIENT_PRINT(fmt, ...) \
|
#define CLIENT_PRINT(fmt, ...) \
|
||||||
PRINT("Client: " fmt, ##__VA_ARGS__)
|
INFO("Client: " fmt, ##__VA_ARGS__)
|
||||||
|
|
||||||
static psa_handle_t handle = -1;
|
static psa_handle_t handle = -1;
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "psa_sim_serialise.h"
|
#include "psa_sim_serialise.h"
|
||||||
|
#include "util.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.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++;
|
psasim_client_handle_t handle = next_hash_operation_handle++;
|
||||||
if (next_hash_operation_handle == 0) { /* wrapped around */
|
if (next_hash_operation_handle == 0) { /* wrapped around */
|
||||||
fprintf(stderr, "MAX HASH HANDLES REACHED\n");
|
FATAL("Hash operation handle wrapped");
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (ssize_t i = 0; i < MAX_LIVE_HANDLES_PER_CLASS; i++) {
|
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 */
|
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];
|
static psa_aead_operation_t aead_operations[MAX_LIVE_HANDLES_PER_CLASS];
|
||||||
@ -706,3 +710,9 @@ int psasim_deserialise_mbedtls_svc_key_id_t(uint8_t **pos,
|
|||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void psa_sim_serialize_reset(void)
|
||||||
|
{
|
||||||
|
memset(hash_operation_handles, 0, sizeof(hash_operation_handles));
|
||||||
|
memset(hash_operations, 0, sizeof(hash_operations));
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user