From 567e0ad8f1bcddab312d521076e944e970816b90 Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Wed, 3 Feb 2021 12:07:01 +0000 Subject: [PATCH] Add documentation and minor style changes Add doxygen style documentation to `mbedtls_test_fail`, `mbedtls_test_skip`, `mbedtls_test_set_step` and `mbedtls_test_info_reset`. This should make it easier to understand how the test infrastructure is used. Also make some minor style changes to meet the coding standards and make it more obvious that `mbedtls_test_info.step` was being incremented. Signed-off-by: Chris Jones --- tests/include/test/helpers.h | 31 +++++++++++++++++++--- tests/suites/host_test.function | 4 +-- tests/suites/target_test.function | 2 +- tests/suites/test_suite_asn1parse.function | 4 ++- 4 files changed, 33 insertions(+), 8 deletions(-) diff --git a/tests/include/test/helpers.h b/tests/include/test/helpers.h index 258c6bae4..50d07fca6 100644 --- a/tests/include/test/helpers.h +++ b/tests/include/test/helpers.h @@ -70,19 +70,42 @@ extern mbedtls_test_info_t mbedtls_test_info; int mbedtls_test_platform_setup( void ); void mbedtls_test_platform_teardown( void ); +/** + * \brief Record the given, usually current, test as a failure. + * + * \param test Name of the test to fail. + * \param line_no Line number where the failure originated. + * \param filename Filename where the failure originated. + */ void mbedtls_test_fail( const char *test, int line_no, const char* filename ); + +/** + * \brief Record the given, usually current, test as skipped. + * + * \param test Name of the test to skip. + * \param line_no Line number where the test skipped. + * \param filename Filename where the test skipped. + */ void mbedtls_test_skip( const char *test, int line_no, const char* filename ); -/** Set the test step number for failure reports. +/** + * \brief 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. + * \note 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 mbedtls_test_set_step( unsigned long step ); +/** + * \brief Reset mbedtls_test_info to a ready/starting state. + * + * \note Clears the test, line_no, filename, step and result from any + * previously stored values and initialises them ready to be used. + */ void mbedtls_test_info_reset( void ); /** diff --git a/tests/suites/host_test.function b/tests/suites/host_test.function index f3454086c..3138c3365 100644 --- a/tests/suites/host_test.function +++ b/tests/suites/host_test.function @@ -601,7 +601,7 @@ int execute_tests( int argc , const char ** argv ) } /* Initialize the struct that holds information about the last test */ - mbedtls_test_info_reset(); + mbedtls_test_info_reset( ); /* Now begin to execute the tests in the testfiles */ for ( testfile_index = 0; @@ -683,7 +683,7 @@ int execute_tests( int argc , const char ** argv ) // If there are no unmet dependencies execute the test if( unmet_dep_count == 0 ) { - mbedtls_test_info_reset(); + mbedtls_test_info_reset( ); #if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) /* Suppress all output from the library unless we're verbose diff --git a/tests/suites/target_test.function b/tests/suites/target_test.function index 8afe70eaf..637a79d5e 100644 --- a/tests/suites/target_test.function +++ b/tests/suites/target_test.function @@ -384,7 +384,7 @@ int execute_tests( int args, const char ** argv ) while ( 1 ) { ret = 0; - mbedtls_test_info_reset(); + mbedtls_test_info_reset( ); data_len = 0; data = receive_data( &data_len ); diff --git a/tests/suites/test_suite_asn1parse.function b/tests/suites/test_suite_asn1parse.function index 21b3ab610..47a43407d 100644 --- a/tests/suites/test_suite_asn1parse.function +++ b/tests/suites/test_suite_asn1parse.function @@ -594,6 +594,7 @@ void get_sequence_of( const data_t *input, int tag, unsigned char *p = input->x; const char *rest = description; unsigned long n; + unsigned int step = 0; TEST_EQUAL( mbedtls_asn1_get_sequence_of( &p, input->x + input->len, &head, tag ), @@ -614,7 +615,7 @@ void get_sequence_of( const data_t *input, int tag, cur = &head; while( *rest ) { - mbedtls_test_set_step( mbedtls_test_info.step + 1 ); + mbedtls_test_set_step( step ); TEST_ASSERT( cur != NULL ); TEST_EQUAL( cur->buf.tag, tag ); n = strtoul( rest, (char **) &rest, 0 ); @@ -625,6 +626,7 @@ void get_sequence_of( const data_t *input, int tag, if( *rest ) ++rest; cur = cur->next; + ++step; } TEST_ASSERT( cur == NULL ); }