tests: Move mbedtls_param_failed() call location record
In preparation of moving mbedtls_param_failed() to test
common code, move mbedtls_param_failed() call location
record into a context dedicated to mbedtls_param_failed().
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
diff --git a/tests/suites/helpers.function b/tests/suites/helpers.function
index a5285a3..c80ffff 100644
--- a/tests/suites/helpers.function
+++ b/tests/suites/helpers.function
@@ -370,6 +370,21 @@
static test_info_t test_info;
#if defined(MBEDTLS_CHECK_PARAMS)
+typedef struct
+{
+ const char *failure_condition;
+ const char *file;
+ int line;
+}
+mbedtls_test_param_failed_location_record_t;
+
+typedef struct
+{
+ mbedtls_test_param_failed_location_record_t location_record;
+}
+param_failed_ctx_t;
+static param_failed_ctx_t param_failed_ctx;
+
jmp_buf param_fail_jmp;
jmp_buf jmp_tmp;
#endif
@@ -422,10 +437,29 @@
}
#if defined(MBEDTLS_CHECK_PARAMS)
+/**
+ * \brief Get the location record of the last call to
+ * mbedtls_test_param_failed().
+ *
+ * \note The call expectation is set up and active until the next call to
+ * mbedtls_test_param_failed_check_expected_call() or
+ * mbedtls_param_failed() that cancels it.
+ */
+void mbedtls_test_param_failed_get_location_record(
+ mbedtls_test_param_failed_location_record_t *location_record )
+{
+ *location_record = param_failed_ctx.location_record;
+}
+
void mbedtls_param_failed( const char *failure_condition,
const char *file,
int line )
{
+ /* Record the location of the failure */
+ param_failed_ctx.location_record.failure_condition = failure_condition;
+ param_failed_ctx.location_record.file = file;
+ param_failed_ctx.location_record.line = line;
+
/* If we are testing the callback function... */
if( test_info.paramfail_test_state == PARAMFAIL_TESTSTATE_PENDING )
{
@@ -435,11 +469,6 @@
{
/* ...else we treat this as an error */
- /* Record the location of the failure, but not as a failure yet, in case
- * it was part of the test */
- test_fail( failure_condition, line, file );
- test_info.result = TEST_RESULT_SUCCESS;
-
longjmp( param_fail_jmp, 1 );
}
}
diff --git a/tests/suites/main_test.function b/tests/suites/main_test.function
index 75656a8..28c7aa8 100644
--- a/tests/suites/main_test.function
+++ b/tests/suites/main_test.function
@@ -167,6 +167,8 @@
void execute_function_ptr(TestWrapper_t fp, void **params)
{
#if defined(MBEDTLS_CHECK_PARAMS)
+ mbedtls_test_param_failed_location_record_t location_record;
+
if ( setjmp( param_fail_jmp ) == 0 )
{
fp( params );
@@ -174,6 +176,10 @@
else
{
/* Unexpected parameter validation error */
+ mbedtls_test_param_failed_get_location_record( &location_record );
+ test_fail( location_record.failure_condition,
+ location_record.line,
+ location_record.file );
test_info.result = TEST_RESULT_FAILED;
}