• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#line 2 "suites/main_test.function"
2/*
3 * *** THIS FILE HAS BEEN MACHINE GENERATED ***
4 *
5 * This file has been machine generated using the script:
6 * $generator_script
7 *
8 * Test file      : $test_file
9 *
10 * The following files were used to create this file.
11 *
12 *      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
17 *
18 */
19
20#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
21#if !defined(_POSIX_C_SOURCE)
22#define _POSIX_C_SOURCE 200112L // for fileno() from <stdio.h>
23#endif
24#endif
25
26#if !defined(MBEDTLS_CONFIG_FILE)
27#include <mbedtls/config.h>
28#else
29#include MBEDTLS_CONFIG_FILE
30#endif
31
32#if defined(MBEDTLS_USE_PSA_CRYPTO)
33#include "psa/crypto.h"
34#endif /* MBEDTLS_USE_PSA_CRYPTO */
35
36#if defined(MBEDTLS_TEST_HOOKS)
37#include "mbedtls/error.h"
38#endif
39
40/* Test code may use deprecated identifiers only if the preprocessor symbol
41 * MBEDTLS_TEST_DEPRECATED is defined. When building tests, set
42 * MBEDTLS_TEST_DEPRECATED explicitly if MBEDTLS_DEPRECATED_WARNING is
43 * enabled but the corresponding warnings are not treated as errors.
44 */
45#if !defined(MBEDTLS_DEPRECATED_REMOVED) && !defined(MBEDTLS_DEPRECATED_WARNING)
46#define MBEDTLS_TEST_DEPRECATED
47#endif
48
49/*----------------------------------------------------------------------------*/
50/* Common helper code */
51
52$test_common_helpers
53
54#line $line_no "suites/main_test.function"
55
56
57/*----------------------------------------------------------------------------*/
58/* Test Suite Code */
59
60
61#define TEST_SUITE_ACTIVE
62
63$functions_code
64
65#line $line_no "suites/main_test.function"
66
67
68/*----------------------------------------------------------------------------*/
69/* Test dispatch code */
70
71
72/**
73 * \brief       Evaluates an expression/macro into its literal integer value.
74 *              For optimizing space for embedded targets each expression/macro
75 *              is identified by a unique identifier instead of string literals.
76 *              Identifiers and evaluation code is generated by script:
77 *              $generator_script
78 *
79 * \param exp_id    Expression identifier.
80 * \param out_value Pointer to int to hold the integer.
81 *
82 * \return       0 if exp_id is found. 1 otherwise.
83 */
84int get_expression( int32_t exp_id, int32_t * out_value )
85{
86    int ret = KEY_VALUE_MAPPING_FOUND;
87
88    (void) exp_id;
89    (void) out_value;
90
91    switch( exp_id )
92    {
93$expression_code
94#line $line_no "suites/main_test.function"
95        default:
96           {
97                ret = KEY_VALUE_MAPPING_NOT_FOUND;
98           }
99           break;
100    }
101    return( ret );
102}
103
104
105/**
106 * \brief       Checks if the dependency i.e. the compile flag is set.
107 *              For optimizing space for embedded targets each dependency
108 *              is identified by a unique identifier instead of string literals.
109 *              Identifiers and check code is generated by script:
110 *              $generator_script
111 *
112 * \param dep_id    Dependency identifier.
113 *
114 * \return       DEPENDENCY_SUPPORTED if set else DEPENDENCY_NOT_SUPPORTED
115 */
116int dep_check( int dep_id )
117{
118    int ret = DEPENDENCY_NOT_SUPPORTED;
119
120    (void) dep_id;
121
122    switch( dep_id )
123    {
124$dep_check_code
125#line $line_no "suites/main_test.function"
126        default:
127            break;
128    }
129    return( ret );
130}
131
132
133/**
134 * \brief       Function pointer type for test function wrappers.
135 *
136 * A test function wrapper decodes the parameters and passes them to the
137 * underlying test function. Both the wrapper and the underlying function
138 * return void. Test wrappers assume that they are passed a suitable
139 * parameter array and do not perform any error detection.
140 *
141 * \param param_array   The array of parameters. Each element is a `void *`
142 *                      which the wrapper casts to the correct type and
143 *                      dereferences. Each wrapper function hard-codes the
144 *                      number and types of the parameters.
145 */
146typedef void (*TestWrapper_t)( void **param_array );
147
148
149/**
150 * \brief       Table of test function wrappers. Used by dispatch_test().
151 *              This table is populated by script:
152 *              $generator_script
153 *
154 */
155TestWrapper_t test_funcs[] =
156{
157$dispatch_code
158#line $line_no "suites/main_test.function"
159};
160
161/**
162 * \brief        Execute the test function.
163 *
164 *               This is a wrapper function around the test function execution
165 *               to allow the setjmp() call used to catch any calls to the
166 *               parameter failure callback, to be used. Calls to setjmp()
167 *               can invalidate the state of any local auto variables.
168 *
169 * \param fp     Function pointer to the test function.
170 * \param params Parameters to pass to the #TestWrapper_t wrapper function.
171 *
172 */
173void execute_function_ptr(TestWrapper_t fp, void **params)
174{
175#if defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG)
176    mbedtls_test_enable_insecure_external_rng( );
177#endif
178
179#if defined(MBEDTLS_CHECK_PARAMS)
180    mbedtls_test_param_failed_location_record_t location_record;
181
182    if ( setjmp( mbedtls_test_param_failed_get_state_buf( ) ) == 0 )
183    {
184        fp( params );
185    }
186    else
187    {
188        /* Unexpected parameter validation error */
189        mbedtls_test_param_failed_get_location_record( &location_record );
190        mbedtls_test_fail( location_record.failure_condition,
191                           location_record.line,
192                           location_record.file );
193    }
194
195    mbedtls_test_param_failed_reset_state( );
196#else
197    fp( params );
198#endif
199
200#if defined(MBEDTLS_TEST_MUTEX_USAGE)
201    mbedtls_test_mutex_usage_check( );
202#endif /* MBEDTLS_TEST_MUTEX_USAGE */
203}
204
205/**
206 * \brief        Dispatches test functions based on function index.
207 *
208 * \param func_idx    Test function index.
209 * \param params      The array of parameters to pass to the test function.
210 *                    It will be decoded by the #TestWrapper_t wrapper function.
211 *
212 * \return       DISPATCH_TEST_SUCCESS if found
213 *               DISPATCH_TEST_FN_NOT_FOUND if not found
214 *               DISPATCH_UNSUPPORTED_SUITE if not compile time enabled.
215 */
216int dispatch_test( size_t func_idx, void ** params )
217{
218    int ret = DISPATCH_TEST_SUCCESS;
219    TestWrapper_t fp = NULL;
220
221    if ( func_idx < (int)( sizeof( test_funcs ) / sizeof( TestWrapper_t ) ) )
222    {
223        fp = test_funcs[func_idx];
224        if ( fp )
225            execute_function_ptr(fp, params);
226        else
227            ret = DISPATCH_UNSUPPORTED_SUITE;
228    }
229    else
230    {
231        ret = DISPATCH_TEST_FN_NOT_FOUND;
232    }
233
234    return( ret );
235}
236
237
238/**
239 * \brief       Checks if test function is supported in this build-time
240 *              configuration.
241 *
242 * \param func_idx    Test function index.
243 *
244 * \return       DISPATCH_TEST_SUCCESS if found
245 *               DISPATCH_TEST_FN_NOT_FOUND if not found
246 *               DISPATCH_UNSUPPORTED_SUITE if not compile time enabled.
247 */
248int check_test( size_t func_idx )
249{
250    int ret = DISPATCH_TEST_SUCCESS;
251    TestWrapper_t fp = NULL;
252
253    if ( func_idx < (int)( sizeof(test_funcs)/sizeof( TestWrapper_t ) ) )
254    {
255        fp = test_funcs[func_idx];
256        if ( fp == NULL )
257            ret = DISPATCH_UNSUPPORTED_SUITE;
258    }
259    else
260    {
261        ret = DISPATCH_TEST_FN_NOT_FOUND;
262    }
263
264    return( ret );
265}
266
267
268$platform_code
269
270#line $line_no "suites/main_test.function"
271
272/*----------------------------------------------------------------------------*/
273/* Main Test code */
274
275
276/**
277 * \brief       Program main. Invokes platform specific execute_tests().
278 *
279 * \param argc      Command line arguments count.
280 * \param argv      Array of command line arguments.
281 *
282 * \return       Exit code.
283 */
284int main( int argc, const char *argv[] )
285{
286#if defined(MBEDTLS_TEST_HOOKS) && defined (MBEDTLS_ERROR_C)
287    mbedtls_test_hook_error_add = &mbedtls_test_err_add_check;
288#endif
289
290    int ret = mbedtls_test_platform_setup();
291    if( ret != 0 )
292    {
293        mbedtls_fprintf( stderr,
294                         "FATAL: Failed to initialize platform - error %d\n",
295                         ret );
296        return( -1 );
297    }
298
299    ret = execute_tests( argc, argv );
300    mbedtls_test_platform_teardown();
301    return( ret );
302}
303