2014-04-22 20:16:15 +00:00
|
|
|
#!/usr/bin/env perl
|
2016-02-10 23:50:28 +00:00
|
|
|
|
|
|
|
# generate_code.pl
|
|
|
|
#
|
2016-04-17 22:24:50 +00:00
|
|
|
# This file is part of mbed TLS (https://tls.mbed.org)
|
|
|
|
#
|
2016-03-01 18:35:02 +00:00
|
|
|
# Copyright (c) 2009-2016, ARM Limited, All Rights Reserved
|
|
|
|
#
|
2016-02-15 23:27:28 +00:00
|
|
|
# Purpose
|
|
|
|
#
|
2016-02-10 23:50:28 +00:00
|
|
|
# Generates the test suite code given inputs of the test suite directory that
|
|
|
|
# contain the test suites, and the test suite file names for the test code and
|
|
|
|
# test data.
|
2009-06-28 21:50:27 +00:00
|
|
|
#
|
2016-02-10 23:50:28 +00:00
|
|
|
# Usage: generate_code.pl <suite dir> <code file> <data file> [main code file]
|
2016-02-15 23:27:28 +00:00
|
|
|
#
|
|
|
|
# Structure of files
|
|
|
|
#
|
|
|
|
# - main code file - 'main_test.function'
|
|
|
|
# Template file that contains the main() function for the test suite,
|
|
|
|
# test dispatch code as well as support functions. It contains the
|
|
|
|
# following symbols which are substituted by this script during
|
|
|
|
# processing:
|
2016-04-25 20:34:49 +00:00
|
|
|
# TESTCASE_FILENAME
|
|
|
|
# TESTCODE_FILENAME
|
2016-02-15 23:27:28 +00:00
|
|
|
# SUITE_PRE_DEP
|
|
|
|
# MAPPING_CODE
|
|
|
|
# FUNCTION CODE
|
|
|
|
# SUITE_POST_DEP
|
|
|
|
# DEP_CHECK_CODE
|
|
|
|
# DISPATCH_FUNCTION
|
2016-04-25 20:34:49 +00:00
|
|
|
# !LINE_NO!
|
2016-02-15 23:27:28 +00:00
|
|
|
#
|
|
|
|
# - common helper code file - 'helpers.function'
|
|
|
|
# Common helper functions
|
|
|
|
#
|
|
|
|
# - test suite code file - file name in the form 'test_suite_xxx.function'
|
|
|
|
# Code file that contains the actual test cases. The file contains a
|
|
|
|
# series of code sequences delimited by the following:
|
|
|
|
# BEGIN_HEADER / END_HEADER - list of headers files
|
|
|
|
# BEGIN_SUITE_HELPERS / END_SUITE_HELPERS - helper functions common to
|
|
|
|
# the test suite
|
|
|
|
# BEGIN_CASE / END_CASE - the test cases in the test suite. Each test
|
|
|
|
# case contains at least one function that is used to create the
|
|
|
|
# dispatch code.
|
|
|
|
#
|
|
|
|
# - 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
|
2016-04-25 20:34:49 +00:00
|
|
|
# file name is used to replace the symbol 'TESTCASE_FILENAME' in the main
|
|
|
|
# code file above.
|
2016-02-15 23:27:28 +00:00
|
|
|
#
|
2017-09-29 13:45:12 +00:00
|
|
|
# A test data file consists of a sequence of paragraphs separated by
|
|
|
|
# a single empty line. Line breaks may be in Unix (LF) or Windows (CRLF)
|
|
|
|
# format. Lines starting with the character '#' are ignored
|
|
|
|
# (the parser behaves as if they were not present).
|
|
|
|
#
|
|
|
|
# Each paragraph describes one test case and must consist of: (1) one
|
|
|
|
# line which is the test case name; (2) an optional line starting with
|
|
|
|
# the 11-character prefix "depends_on:"; (3) a line containing the test
|
|
|
|
# function to execute and its parameters.
|
|
|
|
#
|
|
|
|
# A depends_on: line consists of a list of compile-time options
|
|
|
|
# separated by the character ':', with no whitespace. The test case
|
|
|
|
# is executed only if this compilation option is enabled in config.h.
|
|
|
|
#
|
|
|
|
# The last line of each paragraph contains a test function name and
|
|
|
|
# a list of parameters separated by the character ':'. Running the
|
|
|
|
# test case calls this function with the specified parameters. Each
|
|
|
|
# parameter may either be an integer written in decimal or hexadecimal,
|
|
|
|
# or a string surrounded by double quotes which may not contain the
|
|
|
|
# ':' character.
|
|
|
|
#
|
2009-06-28 21:50:27 +00:00
|
|
|
|
|
|
|
use strict;
|
|
|
|
|
|
|
|
my $suite_dir = shift or die "Missing suite directory";
|
|
|
|
my $suite_name = shift or die "Missing suite name";
|
2011-07-13 14:54:54 +00:00
|
|
|
my $data_name = shift or die "Missing data name";
|
2015-01-14 19:23:00 +00:00
|
|
|
my $test_main_file = do { my $arg = shift; defined($arg) ? $arg : $suite_dir."/main_test.function" };
|
2011-07-13 14:54:54 +00:00
|
|
|
my $test_file = $data_name.".c";
|
2016-02-15 23:27:28 +00:00
|
|
|
my $test_common_helper_file = $suite_dir."/helpers.function";
|
2009-06-28 21:50:27 +00:00
|
|
|
my $test_case_file = $suite_dir."/".$suite_name.".function";
|
2013-08-16 11:31:10 +00:00
|
|
|
my $test_case_data = $suite_dir."/".$data_name.".data";
|
2009-06-28 21:50:27 +00:00
|
|
|
|
|
|
|
my $line_separator = $/;
|
|
|
|
undef $/;
|
|
|
|
|
2016-04-25 20:34:49 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# Open and read in the input files
|
|
|
|
#
|
|
|
|
|
2016-02-15 23:27:28 +00:00
|
|
|
open(TEST_HELPERS, "$test_common_helper_file") or die "Opening test helpers
|
|
|
|
'$test_common_helper_file': $!";
|
|
|
|
my $test_common_helpers = <TEST_HELPERS>;
|
2009-06-28 21:50:27 +00:00
|
|
|
close(TEST_HELPERS);
|
|
|
|
|
2013-08-16 11:31:10 +00:00
|
|
|
open(TEST_MAIN, "$test_main_file") or die "Opening test main '$test_main_file': $!";
|
2016-04-25 20:34:49 +00:00
|
|
|
my @test_main_lines = split/^/, <TEST_MAIN>;
|
|
|
|
my $test_main;
|
2016-05-02 20:31:51 +00:00
|
|
|
my $index = 2;
|
2016-04-25 20:34:49 +00:00
|
|
|
for my $line (@test_main_lines) {
|
|
|
|
$line =~ s/!LINE_NO!/$index/;
|
|
|
|
$test_main = $test_main.$line;
|
|
|
|
$index++;
|
|
|
|
}
|
2013-08-16 11:31:10 +00:00
|
|
|
close(TEST_MAIN);
|
|
|
|
|
2009-06-28 21:50:27 +00:00
|
|
|
open(TEST_CASES, "$test_case_file") or die "Opening test cases '$test_case_file': $!";
|
2016-04-25 20:34:49 +00:00
|
|
|
my @test_cases_lines = split/^/, <TEST_CASES>;
|
|
|
|
my $test_cases;
|
2016-05-02 20:31:51 +00:00
|
|
|
my $index = 2;
|
2016-04-25 20:34:49 +00:00
|
|
|
for my $line (@test_cases_lines) {
|
2016-05-02 20:58:19 +00:00
|
|
|
if ($line =~ /^\/\* BEGIN_SUITE_HELPERS .*\*\//)
|
|
|
|
{
|
|
|
|
$line = $line."#line $index \"$test_case_file\"\n";
|
|
|
|
}
|
|
|
|
|
2016-04-25 20:34:49 +00:00
|
|
|
if ($line =~ /^\/\* BEGIN_CASE .*\*\//)
|
|
|
|
{
|
|
|
|
$line = $line."#line $index \"$test_case_file\"\n";
|
|
|
|
}
|
|
|
|
|
2016-05-02 14:52:52 +00:00
|
|
|
$line =~ s/!LINE_NO!/$index/;
|
|
|
|
|
2016-04-25 20:34:49 +00:00
|
|
|
$test_cases = $test_cases.$line;
|
|
|
|
$index++;
|
|
|
|
}
|
|
|
|
|
2009-06-28 21:50:27 +00:00
|
|
|
close(TEST_CASES);
|
2013-08-16 11:31:10 +00:00
|
|
|
|
|
|
|
open(TEST_DATA, "$test_case_data") or die "Opening test data '$test_case_data': $!";
|
|
|
|
my $test_data = <TEST_DATA>;
|
|
|
|
close(TEST_DATA);
|
|
|
|
|
2016-04-25 20:34:49 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# Find the headers, dependencies, and suites in the test cases file
|
|
|
|
#
|
|
|
|
|
2013-08-20 09:48:36 +00:00
|
|
|
my ( $suite_header ) = $test_cases =~ /\/\* BEGIN_HEADER \*\/\n(.*?)\n\/\* END_HEADER \*\//s;
|
|
|
|
my ( $suite_defines ) = $test_cases =~ /\/\* BEGIN_DEPENDENCIES\n \* (.*?)\n \* END_DEPENDENCIES/s;
|
2016-02-15 23:27:28 +00:00
|
|
|
my ( $suite_helpers ) = $test_cases =~ /\/\* BEGIN_SUITE_HELPERS \*\/\n(.*?)\n\/\* END_SUITE_HELPERS \*\//s;
|
2011-05-26 13:16:06 +00:00
|
|
|
|
|
|
|
my $requirements;
|
|
|
|
if ($suite_defines =~ /^depends_on:/)
|
|
|
|
{
|
|
|
|
( $requirements ) = $suite_defines =~ /^depends_on:(.*)$/;
|
|
|
|
}
|
2013-08-16 11:31:10 +00:00
|
|
|
|
2011-05-26 13:16:06 +00:00
|
|
|
my @var_req_arr = split(/:/, $requirements);
|
|
|
|
my $suite_pre_code;
|
|
|
|
my $suite_post_code;
|
2013-08-16 11:31:10 +00:00
|
|
|
my $dispatch_code;
|
|
|
|
my $mapping_code;
|
|
|
|
my %mapping_values;
|
2011-05-26 13:16:06 +00:00
|
|
|
|
|
|
|
while (@var_req_arr)
|
|
|
|
{
|
|
|
|
my $req = shift @var_req_arr;
|
2015-03-23 12:59:10 +00:00
|
|
|
$req =~ s/(!?)(.*)/$1defined($2)/;
|
2011-05-26 13:16:06 +00:00
|
|
|
|
2015-03-23 12:59:10 +00:00
|
|
|
$suite_pre_code .= "#if $req\n";
|
2011-05-26 13:16:06 +00:00
|
|
|
$suite_post_code .= "#endif /* $req */\n";
|
|
|
|
}
|
2009-06-28 21:50:27 +00:00
|
|
|
|
|
|
|
$/ = $line_separator;
|
|
|
|
|
|
|
|
open(TEST_FILE, ">$test_file") or die "Opening destination file '$test_file': $!";
|
|
|
|
print TEST_FILE << "END";
|
2016-02-15 23:27:28 +00:00
|
|
|
/*
|
|
|
|
* *** THIS FILE HAS BEEN MACHINE GENERATED ***
|
|
|
|
*
|
|
|
|
* This file has been machine generated using the script: $0
|
|
|
|
*
|
|
|
|
* Test file : $test_file
|
|
|
|
*
|
|
|
|
* The following files were used to create this file.
|
|
|
|
*
|
|
|
|
* Main code file : $test_main_file
|
|
|
|
* Helper file : $test_common_helper_file
|
|
|
|
* Test suite file : $test_case_file
|
2016-03-01 18:35:02 +00:00
|
|
|
* Test suite data : $test_case_data
|
2016-02-15 23:27:28 +00:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* This file is part of mbed TLS (https://tls.mbed.org)
|
|
|
|
*/
|
|
|
|
|
2015-04-08 10:49:31 +00:00
|
|
|
#if !defined(MBEDTLS_CONFIG_FILE)
|
2015-03-09 17:05:11 +00:00
|
|
|
#include <mbedtls/config.h>
|
2014-04-29 10:39:06 +00:00
|
|
|
#else
|
2015-04-08 10:49:31 +00:00
|
|
|
#include MBEDTLS_CONFIG_FILE
|
2014-04-29 10:39:06 +00:00
|
|
|
#endif
|
2011-05-26 13:16:06 +00:00
|
|
|
|
2016-02-15 23:27:28 +00:00
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
2016-02-17 23:34:30 +00:00
|
|
|
/* Common helper code */
|
2016-02-15 23:27:28 +00:00
|
|
|
|
|
|
|
$test_common_helpers
|
|
|
|
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
/* Test Suite Code */
|
2015-02-06 13:43:58 +00:00
|
|
|
|
2013-09-15 15:05:21 +00:00
|
|
|
$suite_pre_code
|
2009-06-28 21:50:27 +00:00
|
|
|
$suite_header
|
2016-02-15 23:27:28 +00:00
|
|
|
$suite_helpers
|
2013-09-15 15:05:21 +00:00
|
|
|
$suite_post_code
|
2009-06-28 21:50:27 +00:00
|
|
|
|
|
|
|
END
|
|
|
|
|
2013-08-20 10:06:33 +00:00
|
|
|
$test_main =~ s/SUITE_PRE_DEP/$suite_pre_code/;
|
|
|
|
$test_main =~ s/SUITE_POST_DEP/$suite_post_code/;
|
|
|
|
|
2013-08-20 09:48:36 +00:00
|
|
|
while($test_cases =~ /\/\* BEGIN_CASE *([\w:]*) \*\/\n(.*?)\n\/\* END_CASE \*\//msg)
|
2009-06-28 21:50:27 +00:00
|
|
|
{
|
2013-08-16 11:31:10 +00:00
|
|
|
my $function_deps = $1;
|
2013-08-20 09:48:36 +00:00
|
|
|
my $function_decl = $2;
|
|
|
|
|
|
|
|
# Sanity checks of function
|
2016-04-25 20:34:49 +00:00
|
|
|
if ($function_decl !~ /^#line\s*.*\nvoid /)
|
2013-08-20 09:48:36 +00:00
|
|
|
{
|
2016-04-25 20:34:49 +00:00
|
|
|
die "Test function does not have 'void' as return type.\n" .
|
|
|
|
"Function declaration:\n" .
|
|
|
|
$function_decl;
|
2013-08-20 09:48:36 +00:00
|
|
|
}
|
2016-04-25 20:34:49 +00:00
|
|
|
if ($function_decl !~ /^(#line\s*.*)\nvoid (\w+)\(\s*(.*?)\s*\)\s*{(.*)}/ms)
|
2013-08-20 09:48:36 +00:00
|
|
|
{
|
|
|
|
die "Function declaration not in expected format\n";
|
|
|
|
}
|
2016-04-25 20:34:49 +00:00
|
|
|
my $line_directive = $1;
|
|
|
|
my $function_name = $2;
|
|
|
|
my $function_params = $3;
|
2013-08-16 11:31:10 +00:00
|
|
|
my $function_pre_code;
|
|
|
|
my $function_post_code;
|
|
|
|
my $param_defs;
|
|
|
|
my $param_checks;
|
|
|
|
my @dispatch_params;
|
2013-08-20 09:48:36 +00:00
|
|
|
my @var_def_arr = split(/,\s*/, $function_params);
|
2013-08-16 11:31:10 +00:00
|
|
|
my $i = 1;
|
|
|
|
my $mapping_regex = "".$function_name;
|
|
|
|
my $mapping_count = 0;
|
|
|
|
|
2016-04-25 20:34:49 +00:00
|
|
|
$function_decl =~ s/(^#line\s*.*)\nvoid /$1\nvoid test_suite_/;
|
2013-08-20 09:48:36 +00:00
|
|
|
|
2014-07-10 12:59:25 +00:00
|
|
|
# Add exit label if not present
|
|
|
|
if ($function_decl !~ /^exit:$/m)
|
|
|
|
{
|
|
|
|
$function_decl =~ s/}\s*$/\nexit:\n return;\n}/;
|
|
|
|
}
|
|
|
|
|
2013-08-16 11:31:10 +00:00
|
|
|
if ($function_deps =~ /^depends_on:/)
|
2009-10-03 19:57:10 +00:00
|
|
|
{
|
2013-08-16 11:31:10 +00:00
|
|
|
( $function_deps ) = $function_deps =~ /^depends_on:(.*)$/;
|
|
|
|
}
|
2009-10-03 19:57:10 +00:00
|
|
|
|
2013-08-16 11:31:10 +00:00
|
|
|
foreach my $req (split(/:/, $function_deps))
|
|
|
|
{
|
|
|
|
$function_pre_code .= "#ifdef $req\n";
|
|
|
|
$function_post_code .= "#endif /* $req */\n";
|
2009-10-03 19:57:10 +00:00
|
|
|
}
|
|
|
|
|
2013-08-16 11:31:10 +00:00
|
|
|
foreach my $def (@var_def_arr)
|
2009-10-03 19:57:10 +00:00
|
|
|
{
|
2013-08-16 11:31:10 +00:00
|
|
|
# Handle the different parameter types
|
2013-08-20 09:48:36 +00:00
|
|
|
if( substr($def, 0, 4) eq "int " )
|
2013-08-16 11:31:10 +00:00
|
|
|
{
|
|
|
|
$param_defs .= " int param$i;\n";
|
2016-04-17 22:24:50 +00:00
|
|
|
$param_checks .= " if( verify_int( params[$i], ¶m$i ) != 0 ) return( DISPATCH_INVALID_TEST_DATA );\n";
|
2013-08-16 11:31:10 +00:00
|
|
|
push @dispatch_params, "param$i";
|
|
|
|
|
|
|
|
$mapping_regex .= ":([\\d\\w |\\+\\-\\(\\)]+)";
|
|
|
|
$mapping_count++;
|
|
|
|
}
|
2013-08-20 09:48:36 +00:00
|
|
|
elsif( substr($def, 0, 6) eq "char *" )
|
2013-08-16 11:31:10 +00:00
|
|
|
{
|
|
|
|
$param_defs .= " char *param$i = params[$i];\n";
|
2016-04-17 22:24:50 +00:00
|
|
|
$param_checks .= " if( verify_string( ¶m$i ) != 0 ) return( DISPATCH_INVALID_TEST_DATA );\n";
|
2013-08-16 11:31:10 +00:00
|
|
|
push @dispatch_params, "param$i";
|
2017-02-02 14:36:49 +00:00
|
|
|
$mapping_regex .= ":(?:\\\\.|[^:\n])+";
|
2013-08-16 11:31:10 +00:00
|
|
|
}
|
2013-08-20 09:48:36 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
die "Parameter declaration not of supported type (int, char *)\n";
|
|
|
|
}
|
2013-08-16 11:31:10 +00:00
|
|
|
$i++;
|
|
|
|
|
|
|
|
}
|
2009-10-03 19:57:10 +00:00
|
|
|
|
2013-08-16 11:31:10 +00:00
|
|
|
# Find non-integer values we should map for this function
|
|
|
|
if( $mapping_count)
|
|
|
|
{
|
|
|
|
my @res = $test_data =~ /^$mapping_regex/msg;
|
|
|
|
foreach my $value (@res)
|
|
|
|
{
|
2013-10-17 12:58:24 +00:00
|
|
|
next unless ($value !~ /^\d+$/);
|
|
|
|
if ( $mapping_values{$value} ) {
|
|
|
|
${ $mapping_values{$value} }{$function_pre_code} = 1;
|
|
|
|
} else {
|
|
|
|
$mapping_values{$value} = { $function_pre_code => 1 };
|
|
|
|
}
|
2013-08-16 11:31:10 +00:00
|
|
|
}
|
2009-10-03 19:57:10 +00:00
|
|
|
}
|
|
|
|
|
2013-08-16 11:31:10 +00:00
|
|
|
my $call_params = join ", ", @dispatch_params;
|
|
|
|
my $param_count = @var_def_arr + 1;
|
|
|
|
$dispatch_code .= << "END";
|
|
|
|
if( strcmp( params[0], "$function_name" ) == 0 )
|
|
|
|
{
|
|
|
|
$function_pre_code
|
|
|
|
$param_defs
|
|
|
|
if( cnt != $param_count )
|
|
|
|
{
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_fprintf( stderr, "\\nIncorrect argument count (%d != %d)\\n", cnt, $param_count );
|
2016-04-17 22:24:50 +00:00
|
|
|
return( DISPATCH_INVALID_TEST_DATA );
|
2013-08-16 11:31:10 +00:00
|
|
|
}
|
2009-10-03 19:57:10 +00:00
|
|
|
|
2013-08-16 11:31:10 +00:00
|
|
|
$param_checks
|
2013-08-20 09:48:36 +00:00
|
|
|
test_suite_$function_name( $call_params );
|
2016-04-17 22:24:50 +00:00
|
|
|
return ( DISPATCH_TEST_SUCCESS );
|
2013-08-16 11:31:10 +00:00
|
|
|
$function_post_code
|
2016-04-17 22:24:50 +00:00
|
|
|
return ( DISPATCH_UNSUPPORTED_SUITE );
|
2013-08-16 11:31:10 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
END
|
2009-06-28 21:50:27 +00:00
|
|
|
|
2016-04-25 20:34:49 +00:00
|
|
|
my $function_code = $function_pre_code . $function_decl . "\n" .
|
|
|
|
$function_post_code;
|
2013-08-20 09:48:36 +00:00
|
|
|
$test_main =~ s/FUNCTION_CODE/$function_code\nFUNCTION_CODE/;
|
2013-08-16 11:31:10 +00:00
|
|
|
}
|
2009-06-28 21:50:27 +00:00
|
|
|
|
2013-08-16 11:31:10 +00:00
|
|
|
# Find specific case dependencies that we should be able to check
|
|
|
|
# and make check code
|
|
|
|
my $dep_check_code;
|
2009-06-28 21:50:27 +00:00
|
|
|
|
2017-07-23 09:24:22 +00:00
|
|
|
my @res = $test_data =~ /^depends_on:([!:\w]+)/msg;
|
2013-08-16 11:31:10 +00:00
|
|
|
my %case_deps;
|
|
|
|
foreach my $deps (@res)
|
|
|
|
{
|
|
|
|
foreach my $dep (split(/:/, $deps))
|
2009-06-28 21:50:27 +00:00
|
|
|
{
|
2013-08-16 11:31:10 +00:00
|
|
|
$case_deps{$dep} = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while( my ($key, $value) = each(%case_deps) )
|
|
|
|
{
|
2017-07-23 09:24:22 +00:00
|
|
|
if( substr($key, 0, 1) eq "!" )
|
|
|
|
{
|
|
|
|
my $key = substr($key, 1);
|
|
|
|
$dep_check_code .= << "END";
|
|
|
|
if( strcmp( str, "!$key" ) == 0 )
|
|
|
|
{
|
|
|
|
#if !defined($key)
|
|
|
|
return( DEPENDENCY_SUPPORTED );
|
|
|
|
#else
|
|
|
|
return( DEPENDENCY_NOT_SUPPORTED );
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
END
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$dep_check_code .= << "END";
|
2013-08-16 11:31:10 +00:00
|
|
|
if( strcmp( str, "$key" ) == 0 )
|
|
|
|
{
|
|
|
|
#if defined($key)
|
2016-04-17 22:24:50 +00:00
|
|
|
return( DEPENDENCY_SUPPORTED );
|
2013-08-16 11:31:10 +00:00
|
|
|
#else
|
2016-04-17 22:24:50 +00:00
|
|
|
return( DEPENDENCY_NOT_SUPPORTED );
|
2013-08-16 11:31:10 +00:00
|
|
|
#endif
|
2009-06-28 21:50:27 +00:00
|
|
|
}
|
|
|
|
END
|
2017-07-23 09:24:22 +00:00
|
|
|
}
|
2009-06-28 21:50:27 +00:00
|
|
|
}
|
|
|
|
|
2013-08-16 11:31:10 +00:00
|
|
|
# Make mapping code
|
|
|
|
while( my ($key, $value) = each(%mapping_values) )
|
|
|
|
{
|
2013-10-17 12:58:24 +00:00
|
|
|
my $key_mapping_code = << "END";
|
2013-08-16 11:31:10 +00:00
|
|
|
if( strcmp( str, "$key" ) == 0 )
|
|
|
|
{
|
|
|
|
*value = ( $key );
|
2016-04-17 22:24:50 +00:00
|
|
|
return( KEY_VALUE_MAPPING_FOUND );
|
2009-06-28 21:50:27 +00:00
|
|
|
}
|
2013-08-16 11:31:10 +00:00
|
|
|
END
|
2013-10-17 12:58:24 +00:00
|
|
|
|
|
|
|
# handle depenencies, unless used at least one without depends
|
|
|
|
if ($value->{""}) {
|
|
|
|
$mapping_code .= $key_mapping_code;
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
for my $ifdef ( keys %$value ) {
|
|
|
|
(my $endif = $ifdef) =~ s!ifdef!endif //!g;
|
|
|
|
$mapping_code .= $ifdef . $key_mapping_code . $endif;
|
|
|
|
}
|
2013-08-16 11:31:10 +00:00
|
|
|
}
|
2011-05-26 13:16:06 +00:00
|
|
|
|
2013-08-16 11:31:10 +00:00
|
|
|
$dispatch_code =~ s/^(.+)/ $1/mg;
|
|
|
|
|
2016-04-25 20:34:49 +00:00
|
|
|
$test_main =~ s/TESTCASE_FILENAME/$test_case_data/g;
|
|
|
|
$test_main =~ s/TESTCODE_FILENAME/$test_case_file/g;
|
2013-08-16 11:31:10 +00:00
|
|
|
$test_main =~ s/FUNCTION_CODE//;
|
|
|
|
$test_main =~ s/DEP_CHECK_CODE/$dep_check_code/;
|
|
|
|
$test_main =~ s/DISPATCH_FUNCTION/$dispatch_code/;
|
|
|
|
$test_main =~ s/MAPPING_CODE/$mapping_code/;
|
2013-07-03 12:00:49 +00:00
|
|
|
|
2013-08-16 11:31:10 +00:00
|
|
|
print TEST_FILE << "END";
|
|
|
|
$test_main
|
2009-06-28 21:50:27 +00:00
|
|
|
END
|
|
|
|
|
|
|
|
close(TEST_FILE);
|