mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-12-23 15:25:29 +00:00
Less obscure test suites template
This commit is contained in:
parent
d2d0112ca8
commit
5cb7017077
|
@ -122,7 +122,7 @@ dependency checks, expression evaluation and function dispatch. These
|
||||||
functions are populated with checks and return codes by this script.
|
functions are populated with checks and return codes by this script.
|
||||||
|
|
||||||
Template file contains "replacement" fields that are formatted
|
Template file contains "replacement" fields that are formatted
|
||||||
strings processed by Python str.format() method.
|
strings processed by Python string.Template.substitute() method.
|
||||||
|
|
||||||
This script:
|
This script:
|
||||||
============
|
============
|
||||||
|
@ -132,9 +132,9 @@ code that is generated or read from helpers and platform files.
|
||||||
This script replaces following fields in the template and generates
|
This script replaces following fields in the template and generates
|
||||||
the test source file:
|
the test source file:
|
||||||
|
|
||||||
{test_common_helpers} <-- All common code from helpers.function
|
$test_common_helpers <-- All common code from helpers.function
|
||||||
is substituted here.
|
is substituted here.
|
||||||
{functions_code} <-- Test functions are substituted here
|
$functions_code <-- Test functions are substituted here
|
||||||
from the input test_suit_xyz.function
|
from the input test_suit_xyz.function
|
||||||
file. C preprocessor checks are generated
|
file. C preprocessor checks are generated
|
||||||
for the build dependencies specified
|
for the build dependencies specified
|
||||||
|
@ -143,21 +143,21 @@ the test source file:
|
||||||
functions with code to expand the
|
functions with code to expand the
|
||||||
string parameters read from the data
|
string parameters read from the data
|
||||||
file.
|
file.
|
||||||
{expression_code} <-- This script enumerates the
|
$expression_code <-- This script enumerates the
|
||||||
expressions in the .data file and
|
expressions in the .data file and
|
||||||
generates code to handle enumerated
|
generates code to handle enumerated
|
||||||
expression Ids and return the values.
|
expression Ids and return the values.
|
||||||
{dep_check_code} <-- This script enumerates all
|
$dep_check_code <-- This script enumerates all
|
||||||
build dependencies and generate
|
build dependencies and generate
|
||||||
code to handle enumerated build
|
code to handle enumerated build
|
||||||
dependency Id and return status: if
|
dependency Id and return status: if
|
||||||
the dependency is defined or not.
|
the dependency is defined or not.
|
||||||
{dispatch_code} <-- This script enumerates the functions
|
$dispatch_code <-- This script enumerates the functions
|
||||||
specified in the input test data file
|
specified in the input test data file
|
||||||
and generates the initializer for the
|
and generates the initializer for the
|
||||||
function table in the template
|
function table in the template
|
||||||
file.
|
file.
|
||||||
{platform_code} <-- Platform specific setup and test
|
$platform_code <-- Platform specific setup and test
|
||||||
dispatch code.
|
dispatch code.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
@ -167,6 +167,7 @@ import io
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
import string
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
|
|
||||||
|
@ -967,7 +968,7 @@ def write_test_source_file(template_file, c_file, snippets):
|
||||||
for line_no, line in enumerate(template_f.readlines(), 1):
|
for line_no, line in enumerate(template_f.readlines(), 1):
|
||||||
# Update line number. +1 as #line directive sets next line number
|
# Update line number. +1 as #line directive sets next line number
|
||||||
snippets['line_no'] = line_no + 1
|
snippets['line_no'] = line_no + 1
|
||||||
code = line.format(**snippets)
|
code = string.Template(line).substitute(**snippets)
|
||||||
c_f.write(code)
|
c_f.write(code)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,17 +3,17 @@
|
||||||
* *** THIS FILE HAS BEEN MACHINE GENERATED ***
|
* *** THIS FILE HAS BEEN MACHINE GENERATED ***
|
||||||
*
|
*
|
||||||
* This file has been machine generated using the script:
|
* This file has been machine generated using the script:
|
||||||
* {generator_script}
|
* $generator_script
|
||||||
*
|
*
|
||||||
* Test file : {test_file}
|
* Test file : $test_file
|
||||||
*
|
*
|
||||||
* The following files were used to create this file.
|
* The following files were used to create this file.
|
||||||
*
|
*
|
||||||
* Main code file : {test_main_file}
|
* Main code file : $test_main_file
|
||||||
* Platform code file : {test_platform_file}
|
* Platform code file : $test_platform_file
|
||||||
* Helper file : {test_common_helper_file}
|
* Helper file : $test_common_helper_file
|
||||||
* Test suite file : {test_case_file}
|
* Test suite file : $test_case_file
|
||||||
* Test suite data : {test_case_data_file}
|
* Test suite data : $test_case_data_file
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* This file is part of Mbed TLS (https://tls.mbed.org)
|
* This file is part of Mbed TLS (https://tls.mbed.org)
|
||||||
|
@ -29,9 +29,9 @@
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/* Common helper code */
|
/* Common helper code */
|
||||||
|
|
||||||
{test_common_helpers}
|
$test_common_helpers
|
||||||
|
|
||||||
#line {line_no} "suites/main_test.function"
|
#line $line_no "suites/main_test.function"
|
||||||
|
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
@ -40,9 +40,9 @@
|
||||||
|
|
||||||
#define TEST_SUITE_ACTIVE
|
#define TEST_SUITE_ACTIVE
|
||||||
|
|
||||||
{functions_code}
|
$functions_code
|
||||||
|
|
||||||
#line {line_no} "suites/main_test.function"
|
#line $line_no "suites/main_test.function"
|
||||||
|
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
@ -54,7 +54,7 @@
|
||||||
* For optimizing space for embedded targets each expression/macro
|
* For optimizing space for embedded targets each expression/macro
|
||||||
* is identified by a unique identifier instead of string literals.
|
* is identified by a unique identifier instead of string literals.
|
||||||
* Identifiers and evaluation code is generated by script:
|
* Identifiers and evaluation code is generated by script:
|
||||||
* {generator_script}
|
* $generator_script
|
||||||
*
|
*
|
||||||
* \param exp_id Expression identifier.
|
* \param exp_id Expression identifier.
|
||||||
* \param out_value Pointer to int to hold the integer.
|
* \param out_value Pointer to int to hold the integer.
|
||||||
|
@ -62,24 +62,24 @@
|
||||||
* \return 0 if exp_id is found. 1 otherwise.
|
* \return 0 if exp_id is found. 1 otherwise.
|
||||||
*/
|
*/
|
||||||
int get_expression( int32_t exp_id, int32_t * out_value )
|
int get_expression( int32_t exp_id, int32_t * out_value )
|
||||||
{{
|
{
|
||||||
int ret = KEY_VALUE_MAPPING_FOUND;
|
int ret = KEY_VALUE_MAPPING_FOUND;
|
||||||
|
|
||||||
(void) exp_id;
|
(void) exp_id;
|
||||||
(void) out_value;
|
(void) out_value;
|
||||||
|
|
||||||
switch( exp_id )
|
switch( exp_id )
|
||||||
{{
|
{
|
||||||
{expression_code}
|
$expression_code
|
||||||
#line {line_no} "suites/main_test.function"
|
#line $line_no "suites/main_test.function"
|
||||||
default:
|
default:
|
||||||
{{
|
{
|
||||||
ret = KEY_VALUE_MAPPING_NOT_FOUND;
|
ret = KEY_VALUE_MAPPING_NOT_FOUND;
|
||||||
}}
|
}
|
||||||
break;
|
break;
|
||||||
}}
|
}
|
||||||
return( ret );
|
return( ret );
|
||||||
}}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -87,27 +87,27 @@ int get_expression( int32_t exp_id, int32_t * out_value )
|
||||||
* For optimizing space for embedded targets each dependency
|
* For optimizing space for embedded targets each dependency
|
||||||
* is identified by a unique identifier instead of string literals.
|
* is identified by a unique identifier instead of string literals.
|
||||||
* Identifiers and check code is generated by script:
|
* Identifiers and check code is generated by script:
|
||||||
* {generator_script}
|
* $generator_script
|
||||||
*
|
*
|
||||||
* \param exp_id Dependency identifier.
|
* \param exp_id Dependency identifier.
|
||||||
*
|
*
|
||||||
* \return DEPENDENCY_SUPPORTED if set else DEPENDENCY_NOT_SUPPORTED
|
* \return DEPENDENCY_SUPPORTED if set else DEPENDENCY_NOT_SUPPORTED
|
||||||
*/
|
*/
|
||||||
int dep_check( int dep_id )
|
int dep_check( int dep_id )
|
||||||
{{
|
{
|
||||||
int ret = DEPENDENCY_NOT_SUPPORTED;
|
int ret = DEPENDENCY_NOT_SUPPORTED;
|
||||||
|
|
||||||
(void) dep_id;
|
(void) dep_id;
|
||||||
|
|
||||||
switch( dep_id )
|
switch( dep_id )
|
||||||
{{
|
{
|
||||||
{dep_check_code}
|
$dep_check_code
|
||||||
#line {line_no} "suites/main_test.function"
|
#line $line_no "suites/main_test.function"
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}}
|
}
|
||||||
return( ret );
|
return( ret );
|
||||||
}}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -125,14 +125,14 @@ typedef void (*TestWrapper_t)( void ** );
|
||||||
/**
|
/**
|
||||||
* \brief Table of test function wrappers. Used by dispatch_test().
|
* \brief Table of test function wrappers. Used by dispatch_test().
|
||||||
* This table is populated by script:
|
* This table is populated by script:
|
||||||
* {generator_script}
|
* $generator_script
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
TestWrapper_t test_funcs[] =
|
TestWrapper_t test_funcs[] =
|
||||||
{{
|
{
|
||||||
{dispatch_code}
|
$dispatch_code
|
||||||
#line {line_no} "suites/main_test.function"
|
#line $line_no "suites/main_test.function"
|
||||||
}};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -145,25 +145,25 @@ TestWrapper_t test_funcs[] =
|
||||||
* DISPATCH_UNSUPPORTED_SUITE if not compile time enabled.
|
* DISPATCH_UNSUPPORTED_SUITE if not compile time enabled.
|
||||||
*/
|
*/
|
||||||
int dispatch_test( int func_idx, void ** params )
|
int dispatch_test( int func_idx, void ** params )
|
||||||
{{
|
{
|
||||||
int ret = DISPATCH_TEST_SUCCESS;
|
int ret = DISPATCH_TEST_SUCCESS;
|
||||||
TestWrapper_t fp = NULL;
|
TestWrapper_t fp = NULL;
|
||||||
|
|
||||||
if ( func_idx < (int)( sizeof( test_funcs ) / sizeof( TestWrapper_t ) ) )
|
if ( func_idx < (int)( sizeof( test_funcs ) / sizeof( TestWrapper_t ) ) )
|
||||||
{{
|
{
|
||||||
fp = test_funcs[func_idx];
|
fp = test_funcs[func_idx];
|
||||||
if ( fp )
|
if ( fp )
|
||||||
fp( params );
|
fp( params );
|
||||||
else
|
else
|
||||||
ret = ( DISPATCH_UNSUPPORTED_SUITE );
|
ret = DISPATCH_UNSUPPORTED_SUITE;
|
||||||
}}
|
}
|
||||||
else
|
else
|
||||||
{{
|
{
|
||||||
ret = ( DISPATCH_TEST_FN_NOT_FOUND );
|
ret = DISPATCH_TEST_FN_NOT_FOUND;
|
||||||
}}
|
}
|
||||||
|
|
||||||
return( ret );
|
return( ret );
|
||||||
}}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -176,28 +176,28 @@ int dispatch_test( int func_idx, void ** params )
|
||||||
* DISPATCH_UNSUPPORTED_SUITE if not compile time enabled.
|
* DISPATCH_UNSUPPORTED_SUITE if not compile time enabled.
|
||||||
*/
|
*/
|
||||||
int check_test( int func_idx )
|
int check_test( int func_idx )
|
||||||
{{
|
{
|
||||||
int ret = DISPATCH_TEST_SUCCESS;
|
int ret = DISPATCH_TEST_SUCCESS;
|
||||||
TestWrapper_t fp = NULL;
|
TestWrapper_t fp = NULL;
|
||||||
|
|
||||||
if ( func_idx < (int)( sizeof(test_funcs)/sizeof( TestWrapper_t ) ) )
|
if ( func_idx < (int)( sizeof(test_funcs)/sizeof( TestWrapper_t ) ) )
|
||||||
{{
|
{
|
||||||
fp = test_funcs[func_idx];
|
fp = test_funcs[func_idx];
|
||||||
if ( fp == NULL )
|
if ( fp == NULL )
|
||||||
ret = ( DISPATCH_UNSUPPORTED_SUITE );
|
ret = DISPATCH_UNSUPPORTED_SUITE;
|
||||||
}}
|
}
|
||||||
else
|
else
|
||||||
{{
|
{
|
||||||
ret = ( DISPATCH_TEST_FN_NOT_FOUND );
|
ret = DISPATCH_TEST_FN_NOT_FOUND;
|
||||||
}}
|
}
|
||||||
|
|
||||||
return( ret );
|
return( ret );
|
||||||
}}
|
}
|
||||||
|
|
||||||
|
|
||||||
{platform_code}
|
$platform_code
|
||||||
|
|
||||||
#line {line_no} "suites/main_test.function"
|
#line $line_no "suites/main_test.function"
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/* Main Test code */
|
/* Main Test code */
|
||||||
|
@ -212,17 +212,17 @@ int check_test( int func_idx )
|
||||||
* \return Exit code.
|
* \return Exit code.
|
||||||
*/
|
*/
|
||||||
int main( int argc, const char *argv[] )
|
int main( int argc, const char *argv[] )
|
||||||
{{
|
{
|
||||||
int ret = platform_setup();
|
int ret = platform_setup();
|
||||||
if( ret != 0 )
|
if( ret != 0 )
|
||||||
{{
|
{
|
||||||
mbedtls_fprintf( stderr,
|
mbedtls_fprintf( stderr,
|
||||||
"FATAL: Failed to initialize platform - error %d\n",
|
"FATAL: Failed to initialize platform - error %d\n",
|
||||||
ret );
|
ret );
|
||||||
return( -1 );
|
return( -1 );
|
||||||
}}
|
}
|
||||||
ret = execute_tests( argc, argv );
|
ret = execute_tests( argc, argv );
|
||||||
platform_teardown();
|
platform_teardown();
|
||||||
return( ret );
|
return( ret );
|
||||||
}}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue