• 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 1 // for fileno() from <stdio.h>
23#endif
24#endif
25
26/*
27 * for arc4random_buf() from <stdlib.h>
28 */
29#if defined(__NetBSD__)
30#define _NETBSD_SOURCE 1
31#elif defined(__OpenBSD__)
32#define _BSD_SOURCE 1
33#endif
34
35#if !defined(MBEDTLS_CONFIG_FILE)
36#include <mbedtls/config.h>
37#else
38#include MBEDTLS_CONFIG_FILE
39#endif
40
41
42/*----------------------------------------------------------------------------*/
43/* Common helper code */
44
45$test_common_helpers
46
47#line $line_no "suites/main_test.function"
48
49
50/*----------------------------------------------------------------------------*/
51/* Test Suite Code */
52
53
54#define TEST_SUITE_ACTIVE
55
56$functions_code
57
58#line $line_no "suites/main_test.function"
59
60
61/*----------------------------------------------------------------------------*/
62/* Test dispatch code */
63
64
65/**
66 * \brief       Evaluates an expression/macro into its literal integer value.
67 *              For optimizing space for embedded targets each expression/macro
68 *              is identified by a unique identifier instead of string literals.
69 *              Identifiers and evaluation code is generated by script:
70 *              $generator_script
71 *
72 * \param exp_id    Expression identifier.
73 * \param out_value Pointer to int to hold the integer.
74 *
75 * \return       0 if exp_id is found. 1 otherwise.
76 */
77int get_expression( int32_t exp_id, int32_t * out_value )
78{
79    int ret = KEY_VALUE_MAPPING_FOUND;
80
81    (void) exp_id;
82    (void) out_value;
83
84    switch( exp_id )
85    {
86$expression_code
87#line $line_no "suites/main_test.function"
88        default:
89           {
90                ret = KEY_VALUE_MAPPING_NOT_FOUND;
91           }
92           break;
93    }
94    return( ret );
95}
96
97
98/**
99 * \brief       Checks if the dependency i.e. the compile flag is set.
100 *              For optimizing space for embedded targets each dependency
101 *              is identified by a unique identifier instead of string literals.
102 *              Identifiers and check code is generated by script:
103 *              $generator_script
104 *
105 * \param exp_id    Dependency identifier.
106 *
107 * \return       DEPENDENCY_SUPPORTED if set else DEPENDENCY_NOT_SUPPORTED
108 */
109int dep_check( int dep_id )
110{
111    int ret = DEPENDENCY_NOT_SUPPORTED;
112
113    (void) dep_id;
114
115    switch( dep_id )
116    {
117$dep_check_code
118#line $line_no "suites/main_test.function"
119        default:
120            break;
121    }
122    return( ret );
123}
124
125
126/**
127 * \brief       Function pointer type for test function wrappers.
128 *
129 *
130 * \param void **   Pointer to void pointers. Represents an array of test
131 *                  function parameters.
132 *
133 * \return       void
134 */
135typedef void (*TestWrapper_t)( void ** );
136
137
138/**
139 * \brief       Table of test function wrappers. Used by dispatch_test().
140 *              This table is populated by script:
141 *              $generator_script
142 *
143 */
144TestWrapper_t test_funcs[] =
145{
146$dispatch_code
147#line $line_no "suites/main_test.function"
148};
149
150/**
151 * \brief        Execute the test function.
152 *
153 *               This is a wrapper function around the test function execution
154 *               to allow the setjmp() call used to catch any calls to the
155 *               parameter failure callback, to be used. Calls to setjmp()
156 *               can invalidate the state of any local auto variables.
157 *
158 * \param fp     Function pointer to the test function
159 * \param params Parameters to pass
160 *
161 */
162void execute_function_ptr(TestWrapper_t fp, void **params)
163{
164#if defined(MBEDTLS_CHECK_PARAMS)
165    if ( setjmp( param_fail_jmp ) == 0 )
166    {
167        fp( params );
168    }
169    else
170    {
171        /* Unexpected parameter validation error */
172        test_info.result = TEST_RESULT_FAILED;
173    }
174
175    memset( param_fail_jmp, 0, sizeof(jmp_buf) );
176#else
177    fp( params );
178#endif
179
180#if defined(MBEDTLS_TEST_MUTEX_USAGE)
181    mbedtls_test_mutex_usage_check( );
182#endif /* MBEDTLS_TEST_MUTEX_USAGE */
183}
184
185/**
186 * \brief        Dispatches test functions based on function index.
187 *
188 * \param exp_id    Test function index.
189 *
190 * \return       DISPATCH_TEST_SUCCESS if found
191 *               DISPATCH_TEST_FN_NOT_FOUND if not found
192 *               DISPATCH_UNSUPPORTED_SUITE if not compile time enabled.
193 */
194int dispatch_test( size_t func_idx, void ** params )
195{
196    int ret = DISPATCH_TEST_SUCCESS;
197    TestWrapper_t fp = NULL;
198
199    if ( func_idx < (int)( sizeof( test_funcs ) / sizeof( TestWrapper_t ) ) )
200    {
201        fp = test_funcs[func_idx];
202        if ( fp )
203            execute_function_ptr(fp, params);
204        else
205            ret = DISPATCH_UNSUPPORTED_SUITE;
206    }
207    else
208    {
209        ret = DISPATCH_TEST_FN_NOT_FOUND;
210    }
211
212    return( ret );
213}
214
215
216/**
217 * \brief       Checks if test function is supported
218 *
219 * \param exp_id    Test function index.
220 *
221 * \return       DISPATCH_TEST_SUCCESS if found
222 *               DISPATCH_TEST_FN_NOT_FOUND if not found
223 *               DISPATCH_UNSUPPORTED_SUITE if not compile time enabled.
224 */
225int check_test( size_t func_idx )
226{
227    int ret = DISPATCH_TEST_SUCCESS;
228    TestWrapper_t fp = NULL;
229
230    if ( func_idx < (int)( sizeof(test_funcs)/sizeof( TestWrapper_t ) ) )
231    {
232        fp = test_funcs[func_idx];
233        if ( fp == NULL )
234            ret = DISPATCH_UNSUPPORTED_SUITE;
235    }
236    else
237    {
238        ret = DISPATCH_TEST_FN_NOT_FOUND;
239    }
240
241    return( ret );
242}
243
244
245$platform_code
246
247#line $line_no "suites/main_test.function"
248
249/*----------------------------------------------------------------------------*/
250/* Main Test code */
251
252
253/**
254 * \brief       Program main. Invokes platform specific execute_tests().
255 *
256 * \param argc      Command line arguments count.
257 * \param argv      Array of command line arguments.
258 *
259 * \return       Exit code.
260 */
261int main( int argc, const char *argv[] )
262{
263    int ret = platform_setup();
264    if( ret != 0 )
265    {
266        mbedtls_fprintf( stderr,
267                         "FATAL: Failed to initialize platform - error %d\n",
268                         ret );
269        return( -1 );
270    }
271    ret = execute_tests( argc, argv );
272    platform_teardown();
273    return( ret );
274}
275
276