diff --git a/tests/scripts/generate_code.pl b/tests/scripts/generate_code.pl index 17824c775..548c68cd2 100755 --- a/tests/scripts/generate_code.pl +++ b/tests/scripts/generate_code.pl @@ -87,11 +87,37 @@ my $test_common_helpers = ; close(TEST_HELPERS); open(TEST_MAIN, "$test_main_file") or die "Opening test main '$test_main_file': $!"; -my $test_main = ; +my @test_main_lines = split/^/, ; +my $test_main; +my $index = 2; +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 = ; +my @test_cases_lines = split/^/, ; +my $test_cases; +my $index = 2; +for my $line (@test_cases_lines) { + if ($line =~ /^\/\* BEGIN_SUITE_HELPERS .*\*\//) + { + $line = $line."#line $index \"$test_case_file\"\n"; + } + + if ($line =~ /^\/\* BEGIN_CASE .*\*\//) + { + $line = $line."#line $index \"$test_case_file\"\n"; + } + + $line =~ s/!LINE_NO!/$index/; + + $test_cases = $test_cases.$line; + $index++; +} + close(TEST_CASES); open(TEST_DATA, "$test_case_data") or die "Opening test data '$test_case_data': $!"; @@ -178,16 +204,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"; + "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; @@ -198,7 +227,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) diff --git a/tests/suites/helpers.function b/tests/suites/helpers.function index cad7072ce..4c3a235f7 100644 --- a/tests/suites/helpers.function +++ b/tests/suites/helpers.function @@ -1,3 +1,4 @@ +#line 1 "helpers.function" /*----------------------------------------------------------------------------*/ /* Headers */ diff --git a/tests/suites/main_test.function b/tests/suites/main_test.function index 7fee3d876..948f72e11 100644 --- a/tests/suites/main_test.function +++ b/tests/suites/main_test.function @@ -1,4 +1,5 @@ SUITE_PRE_DEP +#line !LINE_NO! "main_test.function" #define TEST_SUITE_ACTIVE int verify_string( char **str ) @@ -69,6 +70,7 @@ MAPPING_CODE FUNCTION_CODE SUITE_POST_DEP +#line !LINE_NO! "main_test.function" /*----------------------------------------------------------------------------*/ @@ -80,6 +82,7 @@ int dep_check( char *str ) return( 1 ); DEP_CHECK_CODE +#line !LINE_NO! "main_test.function" return( 1 ); } @@ -93,6 +96,7 @@ int dispatch_test(int cnt, char *params[50]) #if defined(TEST_SUITE_ACTIVE) DISPATCH_FUNCTION { +#line !LINE_NO! "main_test.function" mbedtls_fprintf( stdout, "FAILED\nSkipping unknown test function '%s'\n", params[0] ); fflush( stdout ); return( 1 );