Markus Pfeiffer | a26a005 | 2014-04-22 20:16:15 +0000 | [diff] [blame] | 1 | #!/usr/bin/env perl |
SimonB | 3ddf355 | 2016-02-10 23:50:28 +0000 | [diff] [blame] | 2 | |
| 3 | # generate_code.pl |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 4 | # |
SimonB | 8ca7bc4 | 2016-04-17 23:24:50 +0100 | [diff] [blame] | 5 | # This file is part of mbed TLS (https://tls.mbed.org) |
| 6 | # |
Simon Butcher | 64d60da | 2016-03-01 18:35:02 +0000 | [diff] [blame] | 7 | # Copyright (c) 2009-2016, ARM Limited, All Rights Reserved |
| 8 | # |
SimonB | 152ea18 | 2016-02-15 23:27:28 +0000 | [diff] [blame] | 9 | # Purpose |
| 10 | # |
SimonB | 3ddf355 | 2016-02-10 23:50:28 +0000 | [diff] [blame] | 11 | # Generates the test suite code given inputs of the test suite directory that |
| 12 | # contain the test suites, and the test suite file names for the test code and |
| 13 | # test data. |
| 14 | # |
| 15 | # Usage: generate_code.pl <suite dir> <code file> <data file> [main code file] |
SimonB | 152ea18 | 2016-02-15 23:27:28 +0000 | [diff] [blame] | 16 | # |
| 17 | # Structure of files |
| 18 | # |
| 19 | # - main code file - 'main_test.function' |
| 20 | # Template file that contains the main() function for the test suite, |
| 21 | # test dispatch code as well as support functions. It contains the |
| 22 | # following symbols which are substituted by this script during |
| 23 | # processing: |
SimonB | 1594210 | 2016-04-25 21:34:49 +0100 | [diff] [blame] | 24 | # TESTCASE_FILENAME |
| 25 | # TESTCODE_FILENAME |
SimonB | 152ea18 | 2016-02-15 23:27:28 +0000 | [diff] [blame] | 26 | # SUITE_PRE_DEP |
| 27 | # MAPPING_CODE |
| 28 | # FUNCTION CODE |
| 29 | # SUITE_POST_DEP |
| 30 | # DEP_CHECK_CODE |
| 31 | # DISPATCH_FUNCTION |
SimonB | 1594210 | 2016-04-25 21:34:49 +0100 | [diff] [blame] | 32 | # !LINE_NO! |
SimonB | 152ea18 | 2016-02-15 23:27:28 +0000 | [diff] [blame] | 33 | # |
| 34 | # - common helper code file - 'helpers.function' |
| 35 | # Common helper functions |
| 36 | # |
| 37 | # - test suite code file - file name in the form 'test_suite_xxx.function' |
| 38 | # Code file that contains the actual test cases. The file contains a |
| 39 | # series of code sequences delimited by the following: |
| 40 | # BEGIN_HEADER / END_HEADER - list of headers files |
| 41 | # BEGIN_SUITE_HELPERS / END_SUITE_HELPERS - helper functions common to |
| 42 | # the test suite |
| 43 | # BEGIN_CASE / END_CASE - the test cases in the test suite. Each test |
| 44 | # case contains at least one function that is used to create the |
| 45 | # dispatch code. |
| 46 | # |
| 47 | # - test data file - file name in the form 'test_suite_xxxx.data' |
| 48 | # The test case parameters to to be used in execution of the test. The |
SimonB | 1594210 | 2016-04-25 21:34:49 +0100 | [diff] [blame] | 49 | # file name is used to replace the symbol 'TESTCASE_FILENAME' in the main |
| 50 | # code file above. |
SimonB | 152ea18 | 2016-02-15 23:27:28 +0000 | [diff] [blame] | 51 | # |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 52 | |
| 53 | use strict; |
| 54 | |
| 55 | my $suite_dir = shift or die "Missing suite directory"; |
| 56 | my $suite_name = shift or die "Missing suite name"; |
Paul Bakker | 46c1794 | 2011-07-13 14:54:54 +0000 | [diff] [blame] | 57 | my $data_name = shift or die "Missing data name"; |
Rich Evans | f4253c7 | 2015-01-14 19:23:00 +0000 | [diff] [blame] | 58 | my $test_main_file = do { my $arg = shift; defined($arg) ? $arg : $suite_dir."/main_test.function" }; |
Paul Bakker | 46c1794 | 2011-07-13 14:54:54 +0000 | [diff] [blame] | 59 | my $test_file = $data_name.".c"; |
SimonB | 152ea18 | 2016-02-15 23:27:28 +0000 | [diff] [blame] | 60 | my $test_common_helper_file = $suite_dir."/helpers.function"; |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 61 | my $test_case_file = $suite_dir."/".$suite_name.".function"; |
Paul Bakker | 1934318 | 2013-08-16 13:31:10 +0200 | [diff] [blame] | 62 | my $test_case_data = $suite_dir."/".$data_name.".data"; |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 63 | |
| 64 | my $line_separator = $/; |
| 65 | undef $/; |
| 66 | |
SimonB | 1594210 | 2016-04-25 21:34:49 +0100 | [diff] [blame] | 67 | |
| 68 | # |
| 69 | # Open and read in the input files |
| 70 | # |
| 71 | |
SimonB | 152ea18 | 2016-02-15 23:27:28 +0000 | [diff] [blame] | 72 | open(TEST_HELPERS, "$test_common_helper_file") or die "Opening test helpers |
| 73 | '$test_common_helper_file': $!"; |
| 74 | my $test_common_helpers = <TEST_HELPERS>; |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 75 | close(TEST_HELPERS); |
| 76 | |
Paul Bakker | 1934318 | 2013-08-16 13:31:10 +0200 | [diff] [blame] | 77 | open(TEST_MAIN, "$test_main_file") or die "Opening test main '$test_main_file': $!"; |
SimonB | 1594210 | 2016-04-25 21:34:49 +0100 | [diff] [blame] | 78 | my @test_main_lines = split/^/, <TEST_MAIN>; |
| 79 | my $test_main; |
| 80 | my $index = 1; |
| 81 | for my $line (@test_main_lines) { |
| 82 | $line =~ s/!LINE_NO!/$index/; |
| 83 | $test_main = $test_main.$line; |
| 84 | $index++; |
| 85 | } |
Paul Bakker | 1934318 | 2013-08-16 13:31:10 +0200 | [diff] [blame] | 86 | close(TEST_MAIN); |
| 87 | |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 88 | open(TEST_CASES, "$test_case_file") or die "Opening test cases '$test_case_file': $!"; |
SimonB | 1594210 | 2016-04-25 21:34:49 +0100 | [diff] [blame] | 89 | my @test_cases_lines = split/^/, <TEST_CASES>; |
| 90 | my $test_cases; |
| 91 | my $index = 1; |
| 92 | for my $line (@test_cases_lines) { |
| 93 | if ($line =~ /^\/\* BEGIN_CASE .*\*\//) |
| 94 | { |
| 95 | $line = $line."#line $index \"$test_case_file\"\n"; |
| 96 | } |
| 97 | |
SimonB | c1d2eb3 | 2016-05-02 15:52:52 +0100 | [diff] [blame^] | 98 | $line =~ s/!LINE_NO!/$index/; |
| 99 | |
SimonB | 1594210 | 2016-04-25 21:34:49 +0100 | [diff] [blame] | 100 | $test_cases = $test_cases.$line; |
| 101 | $index++; |
| 102 | } |
| 103 | |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 104 | close(TEST_CASES); |
Paul Bakker | 1934318 | 2013-08-16 13:31:10 +0200 | [diff] [blame] | 105 | |
| 106 | open(TEST_DATA, "$test_case_data") or die "Opening test data '$test_case_data': $!"; |
| 107 | my $test_data = <TEST_DATA>; |
| 108 | close(TEST_DATA); |
| 109 | |
SimonB | 1594210 | 2016-04-25 21:34:49 +0100 | [diff] [blame] | 110 | |
| 111 | # |
| 112 | # Find the headers, dependencies, and suites in the test cases file |
| 113 | # |
| 114 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 115 | my ( $suite_header ) = $test_cases =~ /\/\* BEGIN_HEADER \*\/\n(.*?)\n\/\* END_HEADER \*\//s; |
| 116 | my ( $suite_defines ) = $test_cases =~ /\/\* BEGIN_DEPENDENCIES\n \* (.*?)\n \* END_DEPENDENCIES/s; |
SimonB | 152ea18 | 2016-02-15 23:27:28 +0000 | [diff] [blame] | 117 | my ( $suite_helpers ) = $test_cases =~ /\/\* BEGIN_SUITE_HELPERS \*\/\n(.*?)\n\/\* END_SUITE_HELPERS \*\//s; |
Paul Bakker | 5690efc | 2011-05-26 13:16:06 +0000 | [diff] [blame] | 118 | |
| 119 | my $requirements; |
| 120 | if ($suite_defines =~ /^depends_on:/) |
| 121 | { |
| 122 | ( $requirements ) = $suite_defines =~ /^depends_on:(.*)$/; |
| 123 | } |
Paul Bakker | 1934318 | 2013-08-16 13:31:10 +0200 | [diff] [blame] | 124 | |
Paul Bakker | 5690efc | 2011-05-26 13:16:06 +0000 | [diff] [blame] | 125 | my @var_req_arr = split(/:/, $requirements); |
| 126 | my $suite_pre_code; |
| 127 | my $suite_post_code; |
Paul Bakker | 1934318 | 2013-08-16 13:31:10 +0200 | [diff] [blame] | 128 | my $dispatch_code; |
| 129 | my $mapping_code; |
| 130 | my %mapping_values; |
Paul Bakker | 5690efc | 2011-05-26 13:16:06 +0000 | [diff] [blame] | 131 | |
| 132 | while (@var_req_arr) |
| 133 | { |
| 134 | my $req = shift @var_req_arr; |
Manuel Pégourié-Gonnard | e46c6c3 | 2015-03-23 13:59:10 +0100 | [diff] [blame] | 135 | $req =~ s/(!?)(.*)/$1defined($2)/; |
Paul Bakker | 5690efc | 2011-05-26 13:16:06 +0000 | [diff] [blame] | 136 | |
Manuel Pégourié-Gonnard | e46c6c3 | 2015-03-23 13:59:10 +0100 | [diff] [blame] | 137 | $suite_pre_code .= "#if $req\n"; |
Paul Bakker | 5690efc | 2011-05-26 13:16:06 +0000 | [diff] [blame] | 138 | $suite_post_code .= "#endif /* $req */\n"; |
| 139 | } |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 140 | |
| 141 | $/ = $line_separator; |
| 142 | |
| 143 | open(TEST_FILE, ">$test_file") or die "Opening destination file '$test_file': $!"; |
| 144 | print TEST_FILE << "END"; |
SimonB | 152ea18 | 2016-02-15 23:27:28 +0000 | [diff] [blame] | 145 | /* |
| 146 | * *** THIS FILE HAS BEEN MACHINE GENERATED *** |
| 147 | * |
| 148 | * This file has been machine generated using the script: $0 |
| 149 | * |
| 150 | * Test file : $test_file |
| 151 | * |
| 152 | * The following files were used to create this file. |
| 153 | * |
| 154 | * Main code file : $test_main_file |
| 155 | * Helper file : $test_common_helper_file |
| 156 | * Test suite file : $test_case_file |
Simon Butcher | 64d60da | 2016-03-01 18:35:02 +0000 | [diff] [blame] | 157 | * Test suite data : $test_case_data |
SimonB | 152ea18 | 2016-02-15 23:27:28 +0000 | [diff] [blame] | 158 | * |
| 159 | * |
| 160 | * This file is part of mbed TLS (https://tls.mbed.org) |
| 161 | */ |
| 162 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 163 | #if !defined(MBEDTLS_CONFIG_FILE) |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 164 | #include <mbedtls/config.h> |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 165 | #else |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 166 | #include MBEDTLS_CONFIG_FILE |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 167 | #endif |
Paul Bakker | 5690efc | 2011-05-26 13:16:06 +0000 | [diff] [blame] | 168 | |
SimonB | 152ea18 | 2016-02-15 23:27:28 +0000 | [diff] [blame] | 169 | |
| 170 | /*----------------------------------------------------------------------------*/ |
SimonB | 0269dad | 2016-02-17 23:34:30 +0000 | [diff] [blame] | 171 | /* Common helper code */ |
SimonB | 152ea18 | 2016-02-15 23:27:28 +0000 | [diff] [blame] | 172 | |
| 173 | $test_common_helpers |
| 174 | |
| 175 | |
| 176 | /*----------------------------------------------------------------------------*/ |
| 177 | /* Test Suite Code */ |
Rich Evans | 00ab470 | 2015-02-06 13:43:58 +0000 | [diff] [blame] | 178 | |
Paul Bakker | de56ca1 | 2013-09-15 17:05:21 +0200 | [diff] [blame] | 179 | $suite_pre_code |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 180 | $suite_header |
SimonB | 152ea18 | 2016-02-15 23:27:28 +0000 | [diff] [blame] | 181 | $suite_helpers |
Paul Bakker | de56ca1 | 2013-09-15 17:05:21 +0200 | [diff] [blame] | 182 | $suite_post_code |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 183 | |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 184 | END |
| 185 | |
Paul Bakker | b34fef2 | 2013-08-20 12:06:33 +0200 | [diff] [blame] | 186 | $test_main =~ s/SUITE_PRE_DEP/$suite_pre_code/; |
| 187 | $test_main =~ s/SUITE_POST_DEP/$suite_post_code/; |
| 188 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 189 | while($test_cases =~ /\/\* BEGIN_CASE *([\w:]*) \*\/\n(.*?)\n\/\* END_CASE \*\//msg) |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 190 | { |
Paul Bakker | 1934318 | 2013-08-16 13:31:10 +0200 | [diff] [blame] | 191 | my $function_deps = $1; |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 192 | my $function_decl = $2; |
| 193 | |
| 194 | # Sanity checks of function |
SimonB | 1594210 | 2016-04-25 21:34:49 +0100 | [diff] [blame] | 195 | if ($function_decl !~ /^#line\s*.*\nvoid /) |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 196 | { |
SimonB | 1594210 | 2016-04-25 21:34:49 +0100 | [diff] [blame] | 197 | die "Test function does not have 'void' as return type.\n" . |
| 198 | "Function declaration:\n" . |
| 199 | $function_decl; |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 200 | } |
SimonB | 1594210 | 2016-04-25 21:34:49 +0100 | [diff] [blame] | 201 | if ($function_decl !~ /^(#line\s*.*)\nvoid (\w+)\(\s*(.*?)\s*\)\s*{(.*)}/ms) |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 202 | { |
| 203 | die "Function declaration not in expected format\n"; |
| 204 | } |
SimonB | 1594210 | 2016-04-25 21:34:49 +0100 | [diff] [blame] | 205 | my $line_directive = $1; |
| 206 | my $function_name = $2; |
| 207 | my $function_params = $3; |
Paul Bakker | 1934318 | 2013-08-16 13:31:10 +0200 | [diff] [blame] | 208 | my $function_pre_code; |
| 209 | my $function_post_code; |
Paul Bakker | 1934318 | 2013-08-16 13:31:10 +0200 | [diff] [blame] | 210 | my $param_defs; |
| 211 | my $param_checks; |
| 212 | my @dispatch_params; |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 213 | my @var_def_arr = split(/,\s*/, $function_params); |
Paul Bakker | 1934318 | 2013-08-16 13:31:10 +0200 | [diff] [blame] | 214 | my $i = 1; |
| 215 | my $mapping_regex = "".$function_name; |
| 216 | my $mapping_count = 0; |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 217 | |
SimonB | 1594210 | 2016-04-25 21:34:49 +0100 | [diff] [blame] | 218 | $function_decl =~ s/(^#line\s*.*)\nvoid /$1\nvoid test_suite_/; |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 219 | |
Paul Bakker | 318d0fe | 2014-07-10 14:59:25 +0200 | [diff] [blame] | 220 | # Add exit label if not present |
| 221 | if ($function_decl !~ /^exit:$/m) |
| 222 | { |
| 223 | $function_decl =~ s/}\s*$/\nexit:\n return;\n}/; |
| 224 | } |
| 225 | |
Paul Bakker | 1934318 | 2013-08-16 13:31:10 +0200 | [diff] [blame] | 226 | if ($function_deps =~ /^depends_on:/) |
Paul Bakker | ccff167 | 2009-10-03 19:57:10 +0000 | [diff] [blame] | 227 | { |
Paul Bakker | 1934318 | 2013-08-16 13:31:10 +0200 | [diff] [blame] | 228 | ( $function_deps ) = $function_deps =~ /^depends_on:(.*)$/; |
Paul Bakker | ccff167 | 2009-10-03 19:57:10 +0000 | [diff] [blame] | 229 | } |
| 230 | |
Paul Bakker | 1934318 | 2013-08-16 13:31:10 +0200 | [diff] [blame] | 231 | foreach my $req (split(/:/, $function_deps)) |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 232 | { |
Paul Bakker | 1934318 | 2013-08-16 13:31:10 +0200 | [diff] [blame] | 233 | $function_pre_code .= "#ifdef $req\n"; |
| 234 | $function_post_code .= "#endif /* $req */\n"; |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 235 | } |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 236 | |
Paul Bakker | 1934318 | 2013-08-16 13:31:10 +0200 | [diff] [blame] | 237 | foreach my $def (@var_def_arr) |
| 238 | { |
| 239 | # Handle the different parameter types |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 240 | if( substr($def, 0, 4) eq "int " ) |
Paul Bakker | 1934318 | 2013-08-16 13:31:10 +0200 | [diff] [blame] | 241 | { |
| 242 | $param_defs .= " int param$i;\n"; |
SimonB | 8ca7bc4 | 2016-04-17 23:24:50 +0100 | [diff] [blame] | 243 | $param_checks .= " if( verify_int( params[$i], ¶m$i ) != 0 ) return( DISPATCH_INVALID_TEST_DATA );\n"; |
Paul Bakker | 1934318 | 2013-08-16 13:31:10 +0200 | [diff] [blame] | 244 | push @dispatch_params, "param$i"; |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 245 | |
Paul Bakker | 1934318 | 2013-08-16 13:31:10 +0200 | [diff] [blame] | 246 | $mapping_regex .= ":([\\d\\w |\\+\\-\\(\\)]+)"; |
| 247 | $mapping_count++; |
| 248 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 249 | elsif( substr($def, 0, 6) eq "char *" ) |
Paul Bakker | 1934318 | 2013-08-16 13:31:10 +0200 | [diff] [blame] | 250 | { |
| 251 | $param_defs .= " char *param$i = params[$i];\n"; |
SimonB | 8ca7bc4 | 2016-04-17 23:24:50 +0100 | [diff] [blame] | 252 | $param_checks .= " if( verify_string( ¶m$i ) != 0 ) return( DISPATCH_INVALID_TEST_DATA );\n"; |
Paul Bakker | 1934318 | 2013-08-16 13:31:10 +0200 | [diff] [blame] | 253 | push @dispatch_params, "param$i"; |
Manuel Pégourié-Gonnard | 23c0608 | 2015-04-17 10:22:30 +0200 | [diff] [blame] | 254 | $mapping_regex .= ":[^:\n]+"; |
Paul Bakker | 1934318 | 2013-08-16 13:31:10 +0200 | [diff] [blame] | 255 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 256 | else |
| 257 | { |
| 258 | die "Parameter declaration not of supported type (int, char *)\n"; |
| 259 | } |
Paul Bakker | 1934318 | 2013-08-16 13:31:10 +0200 | [diff] [blame] | 260 | $i++; |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 261 | |
Paul Bakker | 1934318 | 2013-08-16 13:31:10 +0200 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | # Find non-integer values we should map for this function |
| 265 | if( $mapping_count) |
| 266 | { |
| 267 | my @res = $test_data =~ /^$mapping_regex/msg; |
| 268 | foreach my $value (@res) |
| 269 | { |
Manuel Pégourié-Gonnard | 18c443d | 2013-10-17 14:58:24 +0200 | [diff] [blame] | 270 | next unless ($value !~ /^\d+$/); |
| 271 | if ( $mapping_values{$value} ) { |
| 272 | ${ $mapping_values{$value} }{$function_pre_code} = 1; |
| 273 | } else { |
| 274 | $mapping_values{$value} = { $function_pre_code => 1 }; |
| 275 | } |
Paul Bakker | 1934318 | 2013-08-16 13:31:10 +0200 | [diff] [blame] | 276 | } |
| 277 | } |
| 278 | |
| 279 | my $call_params = join ", ", @dispatch_params; |
| 280 | my $param_count = @var_def_arr + 1; |
| 281 | $dispatch_code .= << "END"; |
| 282 | if( strcmp( params[0], "$function_name" ) == 0 ) |
| 283 | { |
| 284 | $function_pre_code |
| 285 | $param_defs |
| 286 | if( cnt != $param_count ) |
| 287 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 288 | mbedtls_fprintf( stderr, "\\nIncorrect argument count (%d != %d)\\n", cnt, $param_count ); |
SimonB | 8ca7bc4 | 2016-04-17 23:24:50 +0100 | [diff] [blame] | 289 | return( DISPATCH_INVALID_TEST_DATA ); |
Paul Bakker | 1934318 | 2013-08-16 13:31:10 +0200 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | $param_checks |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 293 | test_suite_$function_name( $call_params ); |
SimonB | 8ca7bc4 | 2016-04-17 23:24:50 +0100 | [diff] [blame] | 294 | return ( DISPATCH_TEST_SUCCESS ); |
Paul Bakker | 1934318 | 2013-08-16 13:31:10 +0200 | [diff] [blame] | 295 | $function_post_code |
SimonB | 8ca7bc4 | 2016-04-17 23:24:50 +0100 | [diff] [blame] | 296 | return ( DISPATCH_UNSUPPORTED_SUITE ); |
Paul Bakker | 1934318 | 2013-08-16 13:31:10 +0200 | [diff] [blame] | 297 | } |
| 298 | else |
| 299 | END |
| 300 | |
SimonB | 1594210 | 2016-04-25 21:34:49 +0100 | [diff] [blame] | 301 | my $function_code = $function_pre_code . $function_decl . "\n" . |
| 302 | $function_post_code; |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 303 | $test_main =~ s/FUNCTION_CODE/$function_code\nFUNCTION_CODE/; |
Paul Bakker | 1934318 | 2013-08-16 13:31:10 +0200 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | # Find specific case dependencies that we should be able to check |
| 307 | # and make check code |
| 308 | my $dep_check_code; |
| 309 | |
| 310 | my @res = $test_data =~ /^depends_on:([\w:]+)/msg; |
| 311 | my %case_deps; |
| 312 | foreach my $deps (@res) |
| 313 | { |
| 314 | foreach my $dep (split(/:/, $deps)) |
| 315 | { |
| 316 | $case_deps{$dep} = 1; |
| 317 | } |
| 318 | } |
| 319 | while( my ($key, $value) = each(%case_deps) ) |
| 320 | { |
| 321 | $dep_check_code .= << "END"; |
| 322 | if( strcmp( str, "$key" ) == 0 ) |
| 323 | { |
| 324 | #if defined($key) |
SimonB | 8ca7bc4 | 2016-04-17 23:24:50 +0100 | [diff] [blame] | 325 | return( DEPENDENCY_SUPPORTED ); |
Paul Bakker | 1934318 | 2013-08-16 13:31:10 +0200 | [diff] [blame] | 326 | #else |
SimonB | 8ca7bc4 | 2016-04-17 23:24:50 +0100 | [diff] [blame] | 327 | return( DEPENDENCY_NOT_SUPPORTED ); |
Paul Bakker | 1934318 | 2013-08-16 13:31:10 +0200 | [diff] [blame] | 328 | #endif |
| 329 | } |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 330 | END |
| 331 | } |
| 332 | |
Paul Bakker | 1934318 | 2013-08-16 13:31:10 +0200 | [diff] [blame] | 333 | # Make mapping code |
| 334 | while( my ($key, $value) = each(%mapping_values) ) |
| 335 | { |
Manuel Pégourié-Gonnard | 18c443d | 2013-10-17 14:58:24 +0200 | [diff] [blame] | 336 | my $key_mapping_code = << "END"; |
Paul Bakker | 1934318 | 2013-08-16 13:31:10 +0200 | [diff] [blame] | 337 | if( strcmp( str, "$key" ) == 0 ) |
| 338 | { |
| 339 | *value = ( $key ); |
SimonB | 8ca7bc4 | 2016-04-17 23:24:50 +0100 | [diff] [blame] | 340 | return( KEY_VALUE_MAPPING_FOUND ); |
Paul Bakker | 1934318 | 2013-08-16 13:31:10 +0200 | [diff] [blame] | 341 | } |
| 342 | END |
Manuel Pégourié-Gonnard | 18c443d | 2013-10-17 14:58:24 +0200 | [diff] [blame] | 343 | |
| 344 | # handle depenencies, unless used at least one without depends |
| 345 | if ($value->{""}) { |
| 346 | $mapping_code .= $key_mapping_code; |
| 347 | next; |
| 348 | } |
| 349 | for my $ifdef ( keys %$value ) { |
| 350 | (my $endif = $ifdef) =~ s!ifdef!endif //!g; |
| 351 | $mapping_code .= $ifdef . $key_mapping_code . $endif; |
| 352 | } |
Paul Bakker | 1934318 | 2013-08-16 13:31:10 +0200 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | $dispatch_code =~ s/^(.+)/ $1/mg; |
| 356 | |
SimonB | 1594210 | 2016-04-25 21:34:49 +0100 | [diff] [blame] | 357 | $test_main =~ s/TESTCASE_FILENAME/$test_case_data/g; |
| 358 | $test_main =~ s/TESTCODE_FILENAME/$test_case_file/g; |
Paul Bakker | 1934318 | 2013-08-16 13:31:10 +0200 | [diff] [blame] | 359 | $test_main =~ s/FUNCTION_CODE//; |
| 360 | $test_main =~ s/DEP_CHECK_CODE/$dep_check_code/; |
| 361 | $test_main =~ s/DISPATCH_FUNCTION/$dispatch_code/; |
| 362 | $test_main =~ s/MAPPING_CODE/$mapping_code/; |
| 363 | |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 364 | print TEST_FILE << "END"; |
Paul Bakker | 1934318 | 2013-08-16 13:31:10 +0200 | [diff] [blame] | 365 | $test_main |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 366 | END |
| 367 | |
Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 368 | close(TEST_FILE); |