mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-01-26 03:35:35 +00:00
Adds better support to debug generated code
The commit adds to the generate_code.pl script support to add #line directives to generated code to allow build breaks to be more easily found from the generated code.
This commit is contained in:
parent
a543d11d3a
commit
1594210a49
@ -21,13 +21,15 @@
|
||||
# test dispatch code as well as support functions. It contains the
|
||||
# following symbols which are substituted by this script during
|
||||
# processing:
|
||||
# TEST_FILENAME
|
||||
# TESTCASE_FILENAME
|
||||
# TESTCODE_FILENAME
|
||||
# SUITE_PRE_DEP
|
||||
# MAPPING_CODE
|
||||
# FUNCTION CODE
|
||||
# SUITE_POST_DEP
|
||||
# DEP_CHECK_CODE
|
||||
# DISPATCH_FUNCTION
|
||||
# !LINE_NO!
|
||||
#
|
||||
# - common helper code file - 'helpers.function'
|
||||
# Common helper functions
|
||||
@ -44,8 +46,8 @@
|
||||
#
|
||||
# - test data file - file name in the form 'test_suite_xxxx.data'
|
||||
# The test case parameters to to be used in execution of the test. The
|
||||
# file name is used to replace the symbol 'TEST_FILENAME' in the main code
|
||||
# file above.
|
||||
# file name is used to replace the symbol 'TESTCASE_FILENAME' in the main
|
||||
# code file above.
|
||||
#
|
||||
|
||||
use strict;
|
||||
@ -62,23 +64,52 @@ my $test_case_data = $suite_dir."/".$data_name.".data";
|
||||
my $line_separator = $/;
|
||||
undef $/;
|
||||
|
||||
|
||||
#
|
||||
# Open and read in the input files
|
||||
#
|
||||
|
||||
open(TEST_HELPERS, "$test_common_helper_file") or die "Opening test helpers
|
||||
'$test_common_helper_file': $!";
|
||||
my $test_common_helpers = <TEST_HELPERS>;
|
||||
close(TEST_HELPERS);
|
||||
|
||||
open(TEST_MAIN, "$test_main_file") or die "Opening test main '$test_main_file': $!";
|
||||
my $test_main = <TEST_MAIN>;
|
||||
my @test_main_lines = split/^/, <TEST_MAIN>;
|
||||
my $test_main;
|
||||
my $index = 1;
|
||||
for my $line (@test_main_lines) {
|
||||
$line =~ s/!LINE_NO!/$index/;
|
||||
$test_main = $test_main.$line;
|
||||
$index++;
|
||||
}
|
||||
close(TEST_MAIN);
|
||||
|
||||
open(TEST_CASES, "$test_case_file") or die "Opening test cases '$test_case_file': $!";
|
||||
my $test_cases = <TEST_CASES>;
|
||||
my @test_cases_lines = split/^/, <TEST_CASES>;
|
||||
my $test_cases;
|
||||
my $index = 1;
|
||||
for my $line (@test_cases_lines) {
|
||||
if ($line =~ /^\/\* BEGIN_CASE .*\*\//)
|
||||
{
|
||||
$line = $line."#line $index \"$test_case_file\"\n";
|
||||
}
|
||||
|
||||
$test_cases = $test_cases.$line;
|
||||
$index++;
|
||||
}
|
||||
|
||||
close(TEST_CASES);
|
||||
|
||||
open(TEST_DATA, "$test_case_data") or die "Opening test data '$test_case_data': $!";
|
||||
my $test_data = <TEST_DATA>;
|
||||
close(TEST_DATA);
|
||||
|
||||
|
||||
#
|
||||
# Find the headers, dependencies, and suites in the test cases file
|
||||
#
|
||||
|
||||
my ( $suite_header ) = $test_cases =~ /\/\* BEGIN_HEADER \*\/\n(.*?)\n\/\* END_HEADER \*\//s;
|
||||
my ( $suite_defines ) = $test_cases =~ /\/\* BEGIN_DEPENDENCIES\n \* (.*?)\n \* END_DEPENDENCIES/s;
|
||||
my ( $suite_helpers ) = $test_cases =~ /\/\* BEGIN_SUITE_HELPERS \*\/\n(.*?)\n\/\* END_SUITE_HELPERS \*\//s;
|
||||
@ -159,16 +190,19 @@ while($test_cases =~ /\/\* BEGIN_CASE *([\w:]*) \*\/\n(.*?)\n\/\* END_CASE \*\//
|
||||
my $function_decl = $2;
|
||||
|
||||
# Sanity checks of function
|
||||
if ($function_decl !~ /^void /)
|
||||
if ($function_decl !~ /^#line\s*.*\nvoid /)
|
||||
{
|
||||
die "Test function does not have 'void' as return type\n";
|
||||
die "Test function does not have 'void' as return type.\n" .
|
||||
"Function declaration:\n" .
|
||||
$function_decl;
|
||||
}
|
||||
if ($function_decl !~ /^void (\w+)\(\s*(.*?)\s*\)\s*{(.*)}/ms)
|
||||
if ($function_decl !~ /^(#line\s*.*)\nvoid (\w+)\(\s*(.*?)\s*\)\s*{(.*)}/ms)
|
||||
{
|
||||
die "Function declaration not in expected format\n";
|
||||
}
|
||||
my $function_name = $1;
|
||||
my $function_params = $2;
|
||||
my $line_directive = $1;
|
||||
my $function_name = $2;
|
||||
my $function_params = $3;
|
||||
my $function_pre_code;
|
||||
my $function_post_code;
|
||||
my $param_defs;
|
||||
@ -179,7 +213,7 @@ while($test_cases =~ /\/\* BEGIN_CASE *([\w:]*) \*\/\n(.*?)\n\/\* END_CASE \*\//
|
||||
my $mapping_regex = "".$function_name;
|
||||
my $mapping_count = 0;
|
||||
|
||||
$function_decl =~ s/^void /void test_suite_/;
|
||||
$function_decl =~ s/(^#line\s*.*)\nvoid /$1\nvoid test_suite_/;
|
||||
|
||||
# Add exit label if not present
|
||||
if ($function_decl !~ /^exit:$/m)
|
||||
@ -262,7 +296,8 @@ $function_post_code
|
||||
else
|
||||
END
|
||||
|
||||
my $function_code = $function_pre_code . $function_decl . "\n" . $function_post_code;
|
||||
my $function_code = $function_pre_code . $function_decl . "\n" .
|
||||
$function_post_code;
|
||||
$test_main =~ s/FUNCTION_CODE/$function_code\nFUNCTION_CODE/;
|
||||
}
|
||||
|
||||
@ -317,7 +352,8 @@ END
|
||||
|
||||
$dispatch_code =~ s/^(.+)/ $1/mg;
|
||||
|
||||
$test_main =~ s/TEST_FILENAME/$test_case_data/g;
|
||||
$test_main =~ s/TESTCASE_FILENAME/$test_case_data/g;
|
||||
$test_main =~ s/TESTCODE_FILENAME/$test_case_file/g;
|
||||
$test_main =~ s/FUNCTION_CODE//;
|
||||
$test_main =~ s/DEP_CHECK_CODE/$dep_check_code/;
|
||||
$test_main =~ s/DISPATCH_FUNCTION/$dispatch_code/;
|
||||
|
@ -1,3 +1,4 @@
|
||||
#line 1 "helpers.function"
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Headers */
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
#line 1 "main_test.function"
|
||||
SUITE_PRE_DEP
|
||||
#define TEST_SUITE_ACTIVE
|
||||
|
||||
@ -70,6 +71,8 @@ MAPPING_CODE
|
||||
FUNCTION_CODE
|
||||
SUITE_POST_DEP
|
||||
|
||||
#line !LINE_NO! "main_test.function"
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Test dispatch code */
|
||||
@ -111,6 +114,8 @@ DISPATCH_FUNCTION
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Main Test code */
|
||||
|
||||
#line !LINE_NO! "main_test.function"
|
||||
|
||||
#define USAGE \
|
||||
"Usage: %s [OPTIONS] files...\n\n" \
|
||||
" Command line arguments:\n" \
|
||||
@ -121,7 +126,7 @@ DISPATCH_FUNCTION
|
||||
" -v | --verbose Display full information about each test\n" \
|
||||
" -h | --help Display this information\n\n", \
|
||||
argv[0], \
|
||||
"TEST_FILENAME"
|
||||
"TESTCASE_FILENAME"
|
||||
|
||||
|
||||
int get_line( FILE *f, char *buf, size_t len )
|
||||
@ -234,7 +239,7 @@ static int run_test_snprintf( void )
|
||||
int main(int argc, const char *argv[])
|
||||
{
|
||||
/* Local Configurations and options */
|
||||
const char *default_filename = "TEST_FILENAME";
|
||||
const char *default_filename = "TESTCASE_FILENAME";
|
||||
const char *test_filename = NULL;
|
||||
const char **test_files = NULL;
|
||||
int testfile_count = 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user