mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-11-21 12:40:51 +03:00
Merge branch 'development' into buffer-sharing-merge
This commit is contained in:
@@ -16,6 +16,9 @@
|
||||
#if defined(MBEDTLS_TEST_HOOKS) && defined(MBEDTLS_PSA_CRYPTO_C)
|
||||
#include <test/psa_memory_poisoning_wrappers.h>
|
||||
#endif
|
||||
#if defined(MBEDTLS_THREADING_C)
|
||||
#include "mbedtls/threading.h"
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Static global variables */
|
||||
@@ -24,7 +27,288 @@
|
||||
static mbedtls_platform_context platform_ctx;
|
||||
#endif
|
||||
|
||||
mbedtls_test_info_t mbedtls_test_info;
|
||||
static mbedtls_test_info_t mbedtls_test_info;
|
||||
|
||||
#ifdef MBEDTLS_THREADING_C
|
||||
mbedtls_threading_mutex_t mbedtls_test_info_mutex;
|
||||
#endif /* MBEDTLS_THREADING_C */
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Mbedtls Test Info accessors
|
||||
*
|
||||
* NOTE - there are two types of accessors here: public accessors and internal
|
||||
* accessors. The public accessors have prototypes in helpers.h and lock
|
||||
* mbedtls_test_info_mutex (if mutexes are enabled). The _internal accessors,
|
||||
* which are expected to be used from this module *only*, do not lock the mutex.
|
||||
* These are designed to be called from within public functions which already
|
||||
* hold the mutex. The main reason for this difference is the need to set
|
||||
* multiple test data values atomically (without releasing the mutex) to prevent
|
||||
* race conditions. */
|
||||
|
||||
mbedtls_test_result_t mbedtls_test_get_result(void)
|
||||
{
|
||||
mbedtls_test_result_t result;
|
||||
|
||||
#ifdef MBEDTLS_THREADING_C
|
||||
mbedtls_mutex_lock(&mbedtls_test_info_mutex);
|
||||
#endif /* MBEDTLS_THREADING_C */
|
||||
|
||||
result = mbedtls_test_info.result;
|
||||
|
||||
#ifdef MBEDTLS_THREADING_C
|
||||
mbedtls_mutex_unlock(&mbedtls_test_info_mutex);
|
||||
#endif /* MBEDTLS_THREADING_C */
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static void mbedtls_test_set_result_internal(mbedtls_test_result_t result, const char *test,
|
||||
int line_no, const char *filename)
|
||||
{
|
||||
/* Internal function only - mbedtls_test_info_mutex should be held prior
|
||||
* to calling this function. */
|
||||
|
||||
mbedtls_test_info.result = result;
|
||||
mbedtls_test_info.test = test;
|
||||
mbedtls_test_info.line_no = line_no;
|
||||
mbedtls_test_info.filename = filename;
|
||||
}
|
||||
|
||||
const char *mbedtls_test_get_test(void)
|
||||
{
|
||||
const char *test;
|
||||
|
||||
#ifdef MBEDTLS_THREADING_C
|
||||
mbedtls_mutex_lock(&mbedtls_test_info_mutex);
|
||||
#endif /* MBEDTLS_THREADING_C */
|
||||
|
||||
test = mbedtls_test_info.test;
|
||||
|
||||
#ifdef MBEDTLS_THREADING_C
|
||||
mbedtls_mutex_unlock(&mbedtls_test_info_mutex);
|
||||
#endif /* MBEDTLS_THREADING_C */
|
||||
|
||||
return test;
|
||||
}
|
||||
const char *mbedtls_get_test_filename(void)
|
||||
{
|
||||
const char *filename;
|
||||
|
||||
#ifdef MBEDTLS_THREADING_C
|
||||
mbedtls_mutex_lock(&mbedtls_test_info_mutex);
|
||||
#endif /* MBEDTLS_THREADING_C */
|
||||
|
||||
/* It should be ok just to pass back the pointer here, as it is going to
|
||||
* be a pointer into non changing data. */
|
||||
filename = mbedtls_test_info.filename;
|
||||
|
||||
#ifdef MBEDTLS_THREADING_C
|
||||
mbedtls_mutex_unlock(&mbedtls_test_info_mutex);
|
||||
#endif /* MBEDTLS_THREADING_C */
|
||||
|
||||
return filename;
|
||||
}
|
||||
|
||||
int mbedtls_test_get_line_no(void)
|
||||
{
|
||||
int line_no;
|
||||
|
||||
#ifdef MBEDTLS_THREADING_C
|
||||
mbedtls_mutex_lock(&mbedtls_test_info_mutex);
|
||||
#endif /* MBEDTLS_THREADING_C */
|
||||
|
||||
line_no = mbedtls_test_info.line_no;
|
||||
|
||||
#ifdef MBEDTLS_THREADING_C
|
||||
mbedtls_mutex_unlock(&mbedtls_test_info_mutex);
|
||||
#endif /* MBEDTLS_THREADING_C */
|
||||
|
||||
return line_no;
|
||||
}
|
||||
|
||||
void mbedtls_test_increment_step(void)
|
||||
{
|
||||
#ifdef MBEDTLS_THREADING_C
|
||||
mbedtls_mutex_lock(&mbedtls_test_info_mutex);
|
||||
#endif /* MBEDTLS_THREADING_C */
|
||||
|
||||
++mbedtls_test_info.step;
|
||||
|
||||
#ifdef MBEDTLS_THREADING_C
|
||||
mbedtls_mutex_unlock(&mbedtls_test_info_mutex);
|
||||
#endif /* MBEDTLS_THREADING_C */
|
||||
}
|
||||
|
||||
unsigned long mbedtls_test_get_step(void)
|
||||
{
|
||||
unsigned long step;
|
||||
|
||||
#ifdef MBEDTLS_THREADING_C
|
||||
mbedtls_mutex_lock(&mbedtls_test_info_mutex);
|
||||
#endif /* MBEDTLS_THREADING_C */
|
||||
|
||||
step = mbedtls_test_info.step;
|
||||
|
||||
#ifdef MBEDTLS_THREADING_C
|
||||
mbedtls_mutex_unlock(&mbedtls_test_info_mutex);
|
||||
#endif /* MBEDTLS_THREADING_C */
|
||||
|
||||
return step;
|
||||
}
|
||||
|
||||
static void mbedtls_test_reset_step_internal(void)
|
||||
{
|
||||
/* Internal function only - mbedtls_test_info_mutex should be held prior
|
||||
* to calling this function. */
|
||||
|
||||
mbedtls_test_info.step = (unsigned long) (-1);
|
||||
}
|
||||
|
||||
void mbedtls_test_set_step(unsigned long step)
|
||||
{
|
||||
#ifdef MBEDTLS_THREADING_C
|
||||
mbedtls_mutex_lock(&mbedtls_test_info_mutex);
|
||||
#endif /* MBEDTLS_THREADING_C */
|
||||
|
||||
mbedtls_test_info.step = step;
|
||||
|
||||
#ifdef MBEDTLS_THREADING_C
|
||||
mbedtls_mutex_unlock(&mbedtls_test_info_mutex);
|
||||
#endif /* MBEDTLS_THREADING_C */
|
||||
}
|
||||
|
||||
void mbedtls_test_get_line1(char *line)
|
||||
{
|
||||
#ifdef MBEDTLS_THREADING_C
|
||||
mbedtls_mutex_lock(&mbedtls_test_info_mutex);
|
||||
#endif /* MBEDTLS_THREADING_C */
|
||||
|
||||
memcpy(line, mbedtls_test_info.line1, MBEDTLS_TEST_LINE_LENGTH);
|
||||
|
||||
#ifdef MBEDTLS_THREADING_C
|
||||
mbedtls_mutex_unlock(&mbedtls_test_info_mutex);
|
||||
#endif /* MBEDTLS_THREADING_C */
|
||||
}
|
||||
|
||||
static void mbedtls_test_set_line1_internal(const char *line)
|
||||
{
|
||||
/* Internal function only - mbedtls_test_info_mutex should be held prior
|
||||
* to calling this function. */
|
||||
|
||||
if (line == NULL) {
|
||||
memset(mbedtls_test_info.line1, 0, MBEDTLS_TEST_LINE_LENGTH);
|
||||
} else {
|
||||
memcpy(mbedtls_test_info.line1, line, MBEDTLS_TEST_LINE_LENGTH);
|
||||
}
|
||||
}
|
||||
|
||||
void mbedtls_test_get_line2(char *line)
|
||||
{
|
||||
#ifdef MBEDTLS_THREADING_C
|
||||
mbedtls_mutex_lock(&mbedtls_test_info_mutex);
|
||||
#endif /* MBEDTLS_THREADING_C */
|
||||
|
||||
memcpy(line, mbedtls_test_info.line2, MBEDTLS_TEST_LINE_LENGTH);
|
||||
|
||||
#ifdef MBEDTLS_THREADING_C
|
||||
mbedtls_mutex_unlock(&mbedtls_test_info_mutex);
|
||||
#endif /* MBEDTLS_THREADING_C */
|
||||
}
|
||||
|
||||
static void mbedtls_test_set_line2_internal(const char *line)
|
||||
{
|
||||
/* Internal function only - mbedtls_test_info_mutex should be held prior
|
||||
* to calling this function. */
|
||||
|
||||
if (line == NULL) {
|
||||
memset(mbedtls_test_info.line2, 0, MBEDTLS_TEST_LINE_LENGTH);
|
||||
} else {
|
||||
memcpy(mbedtls_test_info.line2, line, MBEDTLS_TEST_LINE_LENGTH);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#if defined(MBEDTLS_TEST_MUTEX_USAGE)
|
||||
const char *mbedtls_test_get_mutex_usage_error(void)
|
||||
{
|
||||
const char *usage_error;
|
||||
|
||||
#ifdef MBEDTLS_THREADING_C
|
||||
mbedtls_mutex_lock(&mbedtls_test_info_mutex);
|
||||
#endif /* MBEDTLS_THREADING_C */
|
||||
|
||||
usage_error = mbedtls_test_info.mutex_usage_error;
|
||||
|
||||
#ifdef MBEDTLS_THREADING_C
|
||||
mbedtls_mutex_unlock(&mbedtls_test_info_mutex);
|
||||
#endif /* MBEDTLS_THREADING_C */
|
||||
|
||||
return usage_error;
|
||||
}
|
||||
|
||||
void mbedtls_test_set_mutex_usage_error(const char *msg)
|
||||
{
|
||||
#ifdef MBEDTLS_THREADING_C
|
||||
mbedtls_mutex_lock(&mbedtls_test_info_mutex);
|
||||
#endif /* MBEDTLS_THREADING_C */
|
||||
|
||||
if (mbedtls_test_info.mutex_usage_error == NULL || msg == NULL) {
|
||||
mbedtls_test_info.mutex_usage_error = msg;
|
||||
}
|
||||
|
||||
#ifdef MBEDTLS_THREADING_C
|
||||
mbedtls_mutex_unlock(&mbedtls_test_info_mutex);
|
||||
#endif /* MBEDTLS_THREADING_C */
|
||||
}
|
||||
#endif // #if defined(MBEDTLS_TEST_MUTEX_USAGE)
|
||||
|
||||
#if defined(MBEDTLS_BIGNUM_C)
|
||||
|
||||
unsigned mbedtls_test_get_case_uses_negative_0(void)
|
||||
{
|
||||
unsigned test_case_uses_negative_0 = 0;
|
||||
#ifdef MBEDTLS_THREADING_C
|
||||
mbedtls_mutex_lock(&mbedtls_test_info_mutex);
|
||||
#endif /* MBEDTLS_THREADING_C */
|
||||
test_case_uses_negative_0 = mbedtls_test_info.case_uses_negative_0;
|
||||
|
||||
#ifdef MBEDTLS_THREADING_C
|
||||
mbedtls_mutex_unlock(&mbedtls_test_info_mutex);
|
||||
#endif /* MBEDTLS_THREADING_C */
|
||||
|
||||
return test_case_uses_negative_0;
|
||||
}
|
||||
|
||||
static void mbedtls_test_set_case_uses_negative_0_internal(unsigned uses)
|
||||
{
|
||||
/* Internal function only - mbedtls_test_info_mutex should be held prior
|
||||
* to calling this function. */
|
||||
|
||||
mbedtls_test_info.case_uses_negative_0 = uses;
|
||||
}
|
||||
|
||||
void mbedtls_test_increment_case_uses_negative_0(void)
|
||||
{
|
||||
#ifdef MBEDTLS_THREADING_C
|
||||
mbedtls_mutex_lock(&mbedtls_test_info_mutex);
|
||||
#endif /* MBEDTLS_THREADING_C */
|
||||
|
||||
++mbedtls_test_info.case_uses_negative_0;
|
||||
|
||||
#ifdef MBEDTLS_THREADING_C
|
||||
mbedtls_mutex_unlock(&mbedtls_test_info_mutex);
|
||||
#endif /* MBEDTLS_THREADING_C */
|
||||
}
|
||||
|
||||
#endif /* MBEDTLS_BIGNUM_C */
|
||||
|
||||
#ifdef MBEDTLS_TEST_MUTEX_USAGE
|
||||
mbedtls_threading_mutex_t *mbedtls_test_get_info_mutex(void)
|
||||
{
|
||||
return &mbedtls_test_info_mutex;
|
||||
}
|
||||
|
||||
#endif /* MBEDTLS_TEST_MUTEX_USAGE */
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Helper Functions */
|
||||
@@ -54,6 +338,10 @@ int mbedtls_test_platform_setup(void)
|
||||
ret = mbedtls_platform_setup(&platform_ctx);
|
||||
#endif /* MBEDTLS_PLATFORM_C */
|
||||
|
||||
#ifdef MBEDTLS_THREADING_C
|
||||
mbedtls_mutex_init(&mbedtls_test_info_mutex);
|
||||
#endif /* MBEDTLS_THREADING_C */
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -64,6 +352,9 @@ void mbedtls_test_platform_teardown(void)
|
||||
&& defined(MBEDTLS_TEST_MEMORY_CAN_POISON)
|
||||
mbedtls_poison_test_hooks_teardown();
|
||||
#endif
|
||||
#ifdef MBEDTLS_THREADING_C
|
||||
mbedtls_mutex_free(&mbedtls_test_info_mutex);
|
||||
#endif /* MBEDTLS_THREADING_C */
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
mbedtls_platform_teardown(&platform_ctx);
|
||||
@@ -85,48 +376,63 @@ int mbedtls_test_ascii2uc(const char c, unsigned char *uc)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void mbedtls_test_fail_internal(const char *test, int line_no, const char *filename)
|
||||
{
|
||||
/* Internal function only - mbedtls_test_info_mutex should be held prior
|
||||
* to calling this function. */
|
||||
|
||||
/* Don't use accessor, we already hold mutex. */
|
||||
if (mbedtls_test_info.result != MBEDTLS_TEST_RESULT_FAILED) {
|
||||
/* If we have already recorded the test as having failed then don't
|
||||
* overwrite any previous information about the failure. */
|
||||
mbedtls_test_set_result_internal(MBEDTLS_TEST_RESULT_FAILED, test, line_no, filename);
|
||||
}
|
||||
}
|
||||
|
||||
void mbedtls_test_fail(const char *test, int line_no, const char *filename)
|
||||
{
|
||||
if (mbedtls_test_info.result == MBEDTLS_TEST_RESULT_FAILED) {
|
||||
/* We've already recorded the test as having failed. Don't
|
||||
* overwrite any previous information about the failure. */
|
||||
return;
|
||||
}
|
||||
mbedtls_test_info.result = MBEDTLS_TEST_RESULT_FAILED;
|
||||
mbedtls_test_info.test = test;
|
||||
mbedtls_test_info.line_no = line_no;
|
||||
mbedtls_test_info.filename = filename;
|
||||
#ifdef MBEDTLS_THREADING_C
|
||||
mbedtls_mutex_lock(&mbedtls_test_info_mutex);
|
||||
#endif /* MBEDTLS_THREADING_C */
|
||||
|
||||
mbedtls_test_fail_internal(test, line_no, filename);
|
||||
|
||||
#ifdef MBEDTLS_THREADING_C
|
||||
mbedtls_mutex_unlock(&mbedtls_test_info_mutex);
|
||||
#endif /* MBEDTLS_THREADING_C */
|
||||
}
|
||||
|
||||
void mbedtls_test_skip(const char *test, int line_no, const char *filename)
|
||||
{
|
||||
mbedtls_test_info.result = MBEDTLS_TEST_RESULT_SKIPPED;
|
||||
mbedtls_test_info.test = test;
|
||||
mbedtls_test_info.line_no = line_no;
|
||||
mbedtls_test_info.filename = filename;
|
||||
}
|
||||
#ifdef MBEDTLS_THREADING_C
|
||||
mbedtls_mutex_lock(&mbedtls_test_info_mutex);
|
||||
#endif /* MBEDTLS_THREADING_C */
|
||||
|
||||
void mbedtls_test_set_step(unsigned long step)
|
||||
{
|
||||
mbedtls_test_info.step = step;
|
||||
}
|
||||
mbedtls_test_set_result_internal(MBEDTLS_TEST_RESULT_SKIPPED, test, line_no, filename);
|
||||
|
||||
#if defined(MBEDTLS_BIGNUM_C)
|
||||
unsigned mbedtls_test_case_uses_negative_0 = 0;
|
||||
#endif
|
||||
#ifdef MBEDTLS_THREADING_C
|
||||
mbedtls_mutex_unlock(&mbedtls_test_info_mutex);
|
||||
#endif /* MBEDTLS_THREADING_C */
|
||||
}
|
||||
|
||||
void mbedtls_test_info_reset(void)
|
||||
{
|
||||
mbedtls_test_info.result = MBEDTLS_TEST_RESULT_SUCCESS;
|
||||
mbedtls_test_info.step = (unsigned long) (-1);
|
||||
mbedtls_test_info.test = 0;
|
||||
mbedtls_test_info.line_no = 0;
|
||||
mbedtls_test_info.filename = 0;
|
||||
memset(mbedtls_test_info.line1, 0, sizeof(mbedtls_test_info.line1));
|
||||
memset(mbedtls_test_info.line2, 0, sizeof(mbedtls_test_info.line2));
|
||||
#ifdef MBEDTLS_THREADING_C
|
||||
mbedtls_mutex_lock(&mbedtls_test_info_mutex);
|
||||
#endif /* MBEDTLS_THREADING_C */
|
||||
|
||||
mbedtls_test_set_result_internal(MBEDTLS_TEST_RESULT_SUCCESS, 0, 0, 0);
|
||||
mbedtls_test_reset_step_internal();
|
||||
mbedtls_test_set_line1_internal(NULL);
|
||||
mbedtls_test_set_line2_internal(NULL);
|
||||
|
||||
#if defined(MBEDTLS_BIGNUM_C)
|
||||
mbedtls_test_case_uses_negative_0 = 0;
|
||||
mbedtls_test_set_case_uses_negative_0_internal(0);
|
||||
#endif
|
||||
|
||||
#ifdef MBEDTLS_THREADING_C
|
||||
mbedtls_mutex_unlock(&mbedtls_test_info_mutex);
|
||||
#endif /* MBEDTLS_THREADING_C */
|
||||
}
|
||||
|
||||
int mbedtls_test_equal(const char *test, int line_no, const char *filename,
|
||||
@@ -139,20 +445,31 @@ int mbedtls_test_equal(const char *test, int line_no, const char *filename,
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (mbedtls_test_info.result == MBEDTLS_TEST_RESULT_FAILED) {
|
||||
/* We've already recorded the test as having failed. Don't
|
||||
#ifdef MBEDTLS_THREADING_C
|
||||
mbedtls_mutex_lock(&mbedtls_test_info_mutex);
|
||||
#endif /* MBEDTLS_THREADING_C */
|
||||
|
||||
/* Don't use accessor, as we already hold mutex. */
|
||||
if (mbedtls_test_info.result != MBEDTLS_TEST_RESULT_FAILED) {
|
||||
/* If we've already recorded the test as having failed then don't
|
||||
* overwrite any previous information about the failure. */
|
||||
return 0;
|
||||
|
||||
char buf[MBEDTLS_TEST_LINE_LENGTH];
|
||||
mbedtls_test_fail_internal(test, line_no, filename);
|
||||
(void) mbedtls_snprintf(buf, sizeof(buf),
|
||||
"lhs = 0x%016llx = %lld",
|
||||
value1, (long long) value1);
|
||||
mbedtls_test_set_line1_internal(buf);
|
||||
(void) mbedtls_snprintf(buf, sizeof(buf),
|
||||
"rhs = 0x%016llx = %lld",
|
||||
value2, (long long) value2);
|
||||
mbedtls_test_set_line2_internal(buf);
|
||||
}
|
||||
mbedtls_test_fail(test, line_no, filename);
|
||||
(void) mbedtls_snprintf(mbedtls_test_info.line1,
|
||||
sizeof(mbedtls_test_info.line1),
|
||||
"lhs = 0x%016llx = %lld",
|
||||
value1, (long long) value1);
|
||||
(void) mbedtls_snprintf(mbedtls_test_info.line2,
|
||||
sizeof(mbedtls_test_info.line2),
|
||||
"rhs = 0x%016llx = %lld",
|
||||
value2, (long long) value2);
|
||||
|
||||
#ifdef MBEDTLS_THREADING_C
|
||||
mbedtls_mutex_unlock(&mbedtls_test_info_mutex);
|
||||
#endif /* MBEDTLS_THREADING_C */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -166,20 +483,31 @@ int mbedtls_test_le_u(const char *test, int line_no, const char *filename,
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (mbedtls_test_info.result == MBEDTLS_TEST_RESULT_FAILED) {
|
||||
/* We've already recorded the test as having failed. Don't
|
||||
#ifdef MBEDTLS_THREADING_C
|
||||
mbedtls_mutex_lock(&mbedtls_test_info_mutex);
|
||||
#endif /* MBEDTLS_THREADING_C */
|
||||
|
||||
/* Don't use accessor, we already hold mutex. */
|
||||
if (mbedtls_test_info.result != MBEDTLS_TEST_RESULT_FAILED) {
|
||||
/* If we've already recorded the test as having failed then don't
|
||||
* overwrite any previous information about the failure. */
|
||||
return 0;
|
||||
|
||||
char buf[MBEDTLS_TEST_LINE_LENGTH];
|
||||
mbedtls_test_fail_internal(test, line_no, filename);
|
||||
(void) mbedtls_snprintf(buf, sizeof(buf),
|
||||
"lhs = 0x%016llx = %llu",
|
||||
value1, value1);
|
||||
mbedtls_test_set_line1_internal(buf);
|
||||
(void) mbedtls_snprintf(buf, sizeof(buf),
|
||||
"rhs = 0x%016llx = %llu",
|
||||
value2, value2);
|
||||
mbedtls_test_set_line2_internal(buf);
|
||||
}
|
||||
mbedtls_test_fail(test, line_no, filename);
|
||||
(void) mbedtls_snprintf(mbedtls_test_info.line1,
|
||||
sizeof(mbedtls_test_info.line1),
|
||||
"lhs = 0x%016llx = %llu",
|
||||
value1, value1);
|
||||
(void) mbedtls_snprintf(mbedtls_test_info.line2,
|
||||
sizeof(mbedtls_test_info.line2),
|
||||
"rhs = 0x%016llx = %llu",
|
||||
value2, value2);
|
||||
|
||||
#ifdef MBEDTLS_THREADING_C
|
||||
mbedtls_mutex_unlock(&mbedtls_test_info_mutex);
|
||||
#endif /* MBEDTLS_THREADING_C */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -193,20 +521,31 @@ int mbedtls_test_le_s(const char *test, int line_no, const char *filename,
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (mbedtls_test_info.result == MBEDTLS_TEST_RESULT_FAILED) {
|
||||
/* We've already recorded the test as having failed. Don't
|
||||
#ifdef MBEDTLS_THREADING_C
|
||||
mbedtls_mutex_lock(&mbedtls_test_info_mutex);
|
||||
#endif /* MBEDTLS_THREADING_C */
|
||||
|
||||
/* Don't use accessor, we already hold mutex. */
|
||||
if (mbedtls_test_info.result != MBEDTLS_TEST_RESULT_FAILED) {
|
||||
/* If we've already recorded the test as having failed then don't
|
||||
* overwrite any previous information about the failure. */
|
||||
return 0;
|
||||
|
||||
char buf[MBEDTLS_TEST_LINE_LENGTH];
|
||||
mbedtls_test_fail_internal(test, line_no, filename);
|
||||
(void) mbedtls_snprintf(buf, sizeof(buf),
|
||||
"lhs = 0x%016llx = %lld",
|
||||
(unsigned long long) value1, value1);
|
||||
mbedtls_test_set_line1_internal(buf);
|
||||
(void) mbedtls_snprintf(buf, sizeof(buf),
|
||||
"rhs = 0x%016llx = %lld",
|
||||
(unsigned long long) value2, value2);
|
||||
mbedtls_test_set_line2_internal(buf);
|
||||
}
|
||||
mbedtls_test_fail(test, line_no, filename);
|
||||
(void) mbedtls_snprintf(mbedtls_test_info.line1,
|
||||
sizeof(mbedtls_test_info.line1),
|
||||
"lhs = 0x%016llx = %lld",
|
||||
(unsigned long long) value1, value1);
|
||||
(void) mbedtls_snprintf(mbedtls_test_info.line2,
|
||||
sizeof(mbedtls_test_info.line2),
|
||||
"rhs = 0x%016llx = %lld",
|
||||
(unsigned long long) value2, value2);
|
||||
|
||||
#ifdef MBEDTLS_THREADING_C
|
||||
mbedtls_mutex_unlock(&mbedtls_test_info_mutex);
|
||||
#endif /* MBEDTLS_THREADING_C */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user