Report step number when a test case fails
Allow test code to declare a "step number". Report the current step
number when a test fails.
diff --git a/tests/suites/helpers.function b/tests/suites/helpers.function
index 1a524a6..d45fd4e 100644
--- a/tests/suites/helpers.function
+++ b/tests/suites/helpers.function
@@ -393,6 +393,7 @@
const char *test;
const char *filename;
int line_no;
+ unsigned long step;
}
test_info;
@@ -423,6 +424,19 @@
/*----------------------------------------------------------------------------*/
/* Helper Functions */
+/** Set the test step number for failure reports.
+ *
+ * Call this function to display "step NNN" in addition to the line number
+ * and file name if a test fails. Typically the "step number" is the index
+ * of a for loop but it can be whatever you want.
+ *
+ * \param step The step number to report.
+ */
+void test_set_step( unsigned long step )
+{
+ test_info.step = step;
+}
+
void test_fail( const char *test, int line_no, const char* filename )
{
test_info.result = TEST_RESULT_FAILED;
diff --git a/tests/suites/host_test.function b/tests/suites/host_test.function
index 0f98d23..24d9b97 100644
--- a/tests/suites/host_test.function
+++ b/tests/suites/host_test.function
@@ -548,6 +548,7 @@
{
test_info.result = TEST_RESULT_SUCCESS;
test_info.paramfail_test_state = PARAMFAIL_TESTSTATE_IDLE;
+ test_info.step = (unsigned long)( -1 );
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
/* Suppress all output from the library unless we're verbose
@@ -624,9 +625,15 @@
{
total_errors++;
mbedtls_fprintf( stdout, "FAILED\n" );
- mbedtls_fprintf( stdout, " %s\n at line %d, %s\n",
- test_info.test, test_info.line_no,
- test_info.filename );
+ mbedtls_fprintf( stdout, " %s\n at ",
+ test_info.test );
+ if( test_info.step != (unsigned long)( -1 ) )
+ {
+ mbedtls_fprintf( stdout, "step %lu, ",
+ test_info.step );
+ }
+ mbedtls_fprintf( stdout, "line %d, %s",
+ test_info.line_no, test_info.filename );
}
fflush( stdout );
}
diff --git a/tests/suites/target_test.function b/tests/suites/target_test.function
index 91f7198..937e8dd 100644
--- a/tests/suites/target_test.function
+++ b/tests/suites/target_test.function
@@ -375,6 +375,7 @@
{
ret = 0;
test_info.result = TEST_RESULT_SUCCESS;
+ test_info.step = (unsigned long)( -1 );
data_len = 0;
data = receive_data( &data_len );