blob: 8bd408ca95c073b98bc6d3a520973b8a14200e92 [file] [log] [blame]
Azim Khan1de892b2017-06-09 15:02:36 +01001#line 2 "suites/main_test.function"
Azim Khan191e9042017-06-09 12:39:00 +01002/*
3 * *** THIS FILE HAS BEEN MACHINE GENERATED ***
4 *
5 * This file has been machine generated using the script:
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +01006 * $generator_script
Azim Khan191e9042017-06-09 12:39:00 +01007 *
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +01008 * Test file : $test_file
Azim Khan191e9042017-06-09 12:39:00 +01009 *
10 * The following files were used to create this file.
11 *
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010012 * Main code file : $test_main_file
13 * Platform code file : $test_platform_file
14 * Helper file : $test_common_helper_file
15 * Test suite file : $test_case_file
16 * Test suite data : $test_case_data_file
Azim Khan191e9042017-06-09 12:39:00 +010017 *
18 *
Mohammad Azim Khand2d01122018-07-18 17:48:37 +010019 * This file is part of Mbed TLS (https://tls.mbed.org)
Azim Khan191e9042017-06-09 12:39:00 +010020 */
Paul Bakkerde56ca12013-09-15 17:05:21 +020021
Azim Khan191e9042017-06-09 12:39:00 +010022#if !defined(MBEDTLS_CONFIG_FILE)
23#include <mbedtls/config.h>
24#else
25#include MBEDTLS_CONFIG_FILE
26#endif
Paul Bakker19343182013-08-16 13:31:10 +020027
Hanno Becker1cfc5dd2018-11-12 13:18:45 +000028#if defined(MBEDTLS_USE_PSA_CRYPTO)
29#include "psa/crypto.h"
30#endif /* MBEDTLS_USE_PSA_CRYPTO */
SimonB152ea182016-02-15 23:27:28 +000031
32/*----------------------------------------------------------------------------*/
Azim Khan191e9042017-06-09 12:39:00 +010033/* Common helper code */
SimonB152ea182016-02-15 23:27:28 +000034
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010035$test_common_helpers
Paul Bakkerde56ca12013-09-15 17:05:21 +020036
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010037#line $line_no "suites/main_test.function"
Azim Khan191e9042017-06-09 12:39:00 +010038
39
40/*----------------------------------------------------------------------------*/
41/* Test Suite Code */
42
43
44#define TEST_SUITE_ACTIVE
45
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010046$functions_code
Azim Khan191e9042017-06-09 12:39:00 +010047
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010048#line $line_no "suites/main_test.function"
SimonB15942102016-04-25 21:34:49 +010049
SimonB152ea182016-02-15 23:27:28 +000050
51/*----------------------------------------------------------------------------*/
52/* Test dispatch code */
53
Paul Bakker19343182013-08-16 13:31:10 +020054
Azim Khan191e9042017-06-09 12:39:00 +010055/**
56 * \brief Evaluates an expression/macro into its literal integer value.
57 * For optimizing space for embedded targets each expression/macro
58 * is identified by a unique identifier instead of string literals.
59 * Identifiers and evaluation code is generated by script:
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010060 * $generator_script
Azim Khan191e9042017-06-09 12:39:00 +010061 *
62 * \param exp_id Expression identifier.
63 * \param out_value Pointer to int to hold the integer.
64 *
65 * \return 0 if exp_id is found. 1 otherwise.
66 */
67int get_expression( int32_t exp_id, int32_t * out_value )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010068{
Azim Khanb1c2d0f2017-07-07 17:14:02 +010069 int ret = KEY_VALUE_MAPPING_FOUND;
70
71 (void) exp_id;
72 (void) out_value;
73
74 switch( exp_id )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010075 {
76$expression_code
77#line $line_no "suites/main_test.function"
Azim Khanb1c2d0f2017-07-07 17:14:02 +010078 default:
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010079 {
Azim Khanb1c2d0f2017-07-07 17:14:02 +010080 ret = KEY_VALUE_MAPPING_NOT_FOUND;
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010081 }
Azim Khanb1c2d0f2017-07-07 17:14:02 +010082 break;
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010083 }
Azim Khanb1c2d0f2017-07-07 17:14:02 +010084 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010085}
Paul Bakker19343182013-08-16 13:31:10 +020086
Paul Bakker19343182013-08-16 13:31:10 +020087
Azim Khan191e9042017-06-09 12:39:00 +010088/**
89 * \brief Checks if the dependency i.e. the compile flag is set.
90 * For optimizing space for embedded targets each dependency
91 * is identified by a unique identifier instead of string literals.
92 * Identifiers and check code is generated by script:
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010093 * $generator_script
Azim Khan191e9042017-06-09 12:39:00 +010094 *
95 * \param exp_id Dependency identifier.
96 *
97 * \return DEPENDENCY_SUPPORTED if set else DEPENDENCY_NOT_SUPPORTED
98 */
99int dep_check( int dep_id )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100100{
Azim Khanb1c2d0f2017-07-07 17:14:02 +0100101 int ret = DEPENDENCY_NOT_SUPPORTED;
102
103 (void) dep_id;
104
105 switch( dep_id )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100106 {
107$dep_check_code
108#line $line_no "suites/main_test.function"
Azim Khanb1c2d0f2017-07-07 17:14:02 +0100109 default:
110 break;
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100111 }
Azim Khanb1c2d0f2017-07-07 17:14:02 +0100112 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100113}
Paul Bakker19343182013-08-16 13:31:10 +0200114
SimonB8ca7bc42016-04-17 23:24:50 +0100115
Azim Khan191e9042017-06-09 12:39:00 +0100116/**
117 * \brief Function pointer type for test function wrappers.
118 *
119 *
120 * \param void ** Pointer to void pointers. Represents an array of test
121 * function parameters.
122 *
123 * \return void
124 */
125typedef void (*TestWrapper_t)( void ** );
Simon Butcher65b1fa62016-05-23 23:18:26 +0100126
Azim Khan191e9042017-06-09 12:39:00 +0100127
128/**
129 * \brief Table of test function wrappers. Used by dispatch_test().
130 * This table is populated by script:
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100131 * $generator_script
Azim Khan191e9042017-06-09 12:39:00 +0100132 *
133 */
134TestWrapper_t test_funcs[] =
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100135{
136$dispatch_code
137#line $line_no "suites/main_test.function"
138};
Azim Khan191e9042017-06-09 12:39:00 +0100139
140
141/**
142 * \brief Dispatches test functions based on function index.
143 *
144 * \param exp_id Test function index.
145 *
146 * \return DISPATCH_TEST_SUCCESS if found
147 * DISPATCH_TEST_FN_NOT_FOUND if not found
148 * DISPATCH_UNSUPPORTED_SUITE if not compile time enabled.
149 */
150int dispatch_test( int func_idx, void ** params )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100151{
Azim Khan191e9042017-06-09 12:39:00 +0100152 int ret = DISPATCH_TEST_SUCCESS;
153 TestWrapper_t fp = NULL;
154
Mohammad Azim Khand2d01122018-07-18 17:48:37 +0100155 if ( func_idx < (int)( sizeof( test_funcs ) / sizeof( TestWrapper_t ) ) )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100156 {
Azim Khan191e9042017-06-09 12:39:00 +0100157 fp = test_funcs[func_idx];
158 if ( fp )
159 fp( params );
160 else
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100161 ret = DISPATCH_UNSUPPORTED_SUITE;
162 }
Azim Khan191e9042017-06-09 12:39:00 +0100163 else
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100164 {
165 ret = DISPATCH_TEST_FN_NOT_FOUND;
166 }
Azim Khan191e9042017-06-09 12:39:00 +0100167
Paul Bakker19343182013-08-16 13:31:10 +0200168 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100169}
Paul Bakker19343182013-08-16 13:31:10 +0200170
SimonB152ea182016-02-15 23:27:28 +0000171
Azim Khan13c6bfb2017-06-15 14:45:56 +0100172/**
173 * \brief Checks if test function is supported
174 *
175 * \param exp_id Test function index.
176 *
177 * \return DISPATCH_TEST_SUCCESS if found
178 * DISPATCH_TEST_FN_NOT_FOUND if not found
179 * DISPATCH_UNSUPPORTED_SUITE if not compile time enabled.
180 */
181int check_test( int func_idx )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100182{
Azim Khan13c6bfb2017-06-15 14:45:56 +0100183 int ret = DISPATCH_TEST_SUCCESS;
184 TestWrapper_t fp = NULL;
185
186 if ( func_idx < (int)( sizeof(test_funcs)/sizeof( TestWrapper_t ) ) )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100187 {
Azim Khan13c6bfb2017-06-15 14:45:56 +0100188 fp = test_funcs[func_idx];
189 if ( fp == NULL )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100190 ret = DISPATCH_UNSUPPORTED_SUITE;
191 }
Azim Khan13c6bfb2017-06-15 14:45:56 +0100192 else
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100193 {
194 ret = DISPATCH_TEST_FN_NOT_FOUND;
195 }
Azim Khan13c6bfb2017-06-15 14:45:56 +0100196
197 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100198}
Azim Khan13c6bfb2017-06-15 14:45:56 +0100199
200
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100201$platform_code
Azim Khan191e9042017-06-09 12:39:00 +0100202
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100203#line $line_no "suites/main_test.function"
Azim Khan191e9042017-06-09 12:39:00 +0100204
SimonB152ea182016-02-15 23:27:28 +0000205/*----------------------------------------------------------------------------*/
206/* Main Test code */
207
SimonB15942102016-04-25 21:34:49 +0100208
Azim Khan191e9042017-06-09 12:39:00 +0100209/**
210 * \brief Program main. Invokes platform specific execute_tests().
Gilles Peskine964faeb2017-09-29 18:00:25 +0200211 *
Azim Khan191e9042017-06-09 12:39:00 +0100212 * \param argc Command line arguments count.
213 * \param argv Array of command line arguments.
214 *
215 * \return Exit code.
Gilles Peskine964faeb2017-09-29 18:00:25 +0200216 */
Azim Khan191e9042017-06-09 12:39:00 +0100217int main( int argc, const char *argv[] )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100218{
Azim Khan191e9042017-06-09 12:39:00 +0100219 int ret = platform_setup();
Andrzej Kurekf13ca952018-04-18 04:14:31 -0400220 if( ret != 0 )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100221 {
Andrzej Kurekf13ca952018-04-18 04:14:31 -0400222 mbedtls_fprintf( stderr,
223 "FATAL: Failed to initialize platform - error %d\n",
224 ret );
225 return( -1 );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100226 }
Hanno Becker1cfc5dd2018-11-12 13:18:45 +0000227
228#if defined(MBEDTLS_USE_PSA_CRYPTO)
229 {
230 psa_status_t status;
231 status = psa_crypto_init();
232 if( status != PSA_SUCCESS )
233 {
234 mbedtls_fprintf( stderr,
235 "FATAL: Failed to initialize PSA Crypto - error %d\n",
236 status );
237 return( -1 );
238 }
239 }
240#endif /* MBEDTLS_USE_PSA_CRYPTO */
241
Azim Khan191e9042017-06-09 12:39:00 +0100242 ret = execute_tests( argc, argv );
Andrzej Kurek32a675f2018-04-13 06:16:04 -0400243 platform_teardown();
Azim Khan191e9042017-06-09 12:39:00 +0100244 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100245}