Less obscure test suites template

This commit is contained in:
Mohammad Azim Khan 2018-07-19 11:32:30 +01:00
parent d2d0112ca8
commit 5cb7017077
2 changed files with 63 additions and 62 deletions

View file

@ -122,7 +122,7 @@ dependency checks, expression evaluation and function dispatch. These
functions are populated with checks and return codes by this script.
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:
============
@ -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
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.
{functions_code} <-- Test functions are substituted here
$functions_code <-- Test functions are substituted here
from the input test_suit_xyz.function
file. C preprocessor checks are generated
for the build dependencies specified
@ -143,21 +143,21 @@ the test source file:
functions with code to expand the
string parameters read from the data
file.
{expression_code} <-- This script enumerates the
$expression_code <-- This script enumerates the
expressions in the .data file and
generates code to handle enumerated
expression Ids and return the values.
{dep_check_code} <-- This script enumerates all
$dep_check_code <-- This script enumerates all
build dependencies and generate
code to handle enumerated build
dependency Id and return status: if
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
and generates the initializer for the
function table in the template
file.
{platform_code} <-- Platform specific setup and test
$platform_code <-- Platform specific setup and test
dispatch code.
"""
@ -167,6 +167,7 @@ import io
import os
import re
import sys
import string
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):
# Update line number. +1 as #line directive sets next line number
snippets['line_no'] = line_no + 1
code = line.format(**snippets)
code = string.Template(line).substitute(**snippets)
c_f.write(code)

View file

@ -3,17 +3,17 @@
* *** THIS FILE HAS BEEN MACHINE GENERATED ***
*
* 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.
*
* Main code file : {test_main_file}
* Platform code file : {test_platform_file}
* Helper file : {test_common_helper_file}
* Test suite file : {test_case_file}
* Test suite data : {test_case_data_file}
* Main code file : $test_main_file
* Platform code file : $test_platform_file
* Helper file : $test_common_helper_file
* Test suite file : $test_case_file
* Test suite data : $test_case_data_file
*
*
* This file is part of Mbed TLS (https://tls.mbed.org)
@ -29,9 +29,9 @@
/*----------------------------------------------------------------------------*/
/* 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
{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
* is identified by a unique identifier instead of string literals.
* Identifiers and evaluation code is generated by script:
* {generator_script}
* $generator_script
*
* \param exp_id Expression identifier.
* \param out_value Pointer to int to hold the integer.
@ -62,24 +62,24 @@
* \return 0 if exp_id is found. 1 otherwise.
*/
int get_expression( int32_t exp_id, int32_t * out_value )
{{
{
int ret = KEY_VALUE_MAPPING_FOUND;
(void) exp_id;
(void) out_value;
switch( exp_id )
{{
{expression_code}
#line {line_no} "suites/main_test.function"
{
$expression_code
#line $line_no "suites/main_test.function"
default:
{{
{
ret = KEY_VALUE_MAPPING_NOT_FOUND;
}}
}
break;
}}
}
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
* is identified by a unique identifier instead of string literals.
* Identifiers and check code is generated by script:
* {generator_script}
* $generator_script
*
* \param exp_id Dependency identifier.
*
* \return DEPENDENCY_SUPPORTED if set else DEPENDENCY_NOT_SUPPORTED
*/
int dep_check( int dep_id )
{{
{
int ret = DEPENDENCY_NOT_SUPPORTED;
(void) dep_id;
switch( dep_id )
{{
{dep_check_code}
#line {line_no} "suites/main_test.function"
{
$dep_check_code
#line $line_no "suites/main_test.function"
default:
break;
}}
}
return( ret );
}}
}
/**
@ -125,14 +125,14 @@ typedef void (*TestWrapper_t)( void ** );
/**
* \brief Table of test function wrappers. Used by dispatch_test().
* This table is populated by script:
* {generator_script}
* $generator_script
*
*/
TestWrapper_t test_funcs[] =
{{
{dispatch_code}
#line {line_no} "suites/main_test.function"
}};
{
$dispatch_code
#line $line_no "suites/main_test.function"
};
/**
@ -145,25 +145,25 @@ TestWrapper_t test_funcs[] =
* DISPATCH_UNSUPPORTED_SUITE if not compile time enabled.
*/
int dispatch_test( int func_idx, void ** params )
{{
{
int ret = DISPATCH_TEST_SUCCESS;
TestWrapper_t fp = NULL;
if ( func_idx < (int)( sizeof( test_funcs ) / sizeof( TestWrapper_t ) ) )
{{
{
fp = test_funcs[func_idx];
if ( fp )
fp( params );
else
ret = ( DISPATCH_UNSUPPORTED_SUITE );
}}
ret = DISPATCH_UNSUPPORTED_SUITE;
}
else
{{
ret = ( DISPATCH_TEST_FN_NOT_FOUND );
}}
{
ret = DISPATCH_TEST_FN_NOT_FOUND;
}
return( ret );
}}
}
/**
@ -176,28 +176,28 @@ int dispatch_test( int func_idx, void ** params )
* DISPATCH_UNSUPPORTED_SUITE if not compile time enabled.
*/
int check_test( int func_idx )
{{
{
int ret = DISPATCH_TEST_SUCCESS;
TestWrapper_t fp = NULL;
if ( func_idx < (int)( sizeof(test_funcs)/sizeof( TestWrapper_t ) ) )
{{
{
fp = test_funcs[func_idx];
if ( fp == NULL )
ret = ( DISPATCH_UNSUPPORTED_SUITE );
}}
ret = DISPATCH_UNSUPPORTED_SUITE;
}
else
{{
ret = ( DISPATCH_TEST_FN_NOT_FOUND );
}}
{
ret = DISPATCH_TEST_FN_NOT_FOUND;
}
return( ret );
}}
}
{platform_code}
$platform_code
#line {line_no} "suites/main_test.function"
#line $line_no "suites/main_test.function"
/*----------------------------------------------------------------------------*/
/* Main Test code */
@ -212,17 +212,17 @@ int check_test( int func_idx )
* \return Exit code.
*/
int main( int argc, const char *argv[] )
{{
{
int ret = platform_setup();
if( ret != 0 )
{{
{
mbedtls_fprintf( stderr,
"FATAL: Failed to initialize platform - error %d\n",
ret );
return( -1 );
}}
}
ret = execute_tests( argc, argv );
platform_teardown();
return( ret );
}}
}