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 * __MBEDTLS_TEST_TEMPLATE__GENERATOR_SCRIPT
7 *
8 * Test file      : __MBEDTLS_TEST_TEMPLATE__TEST_FILE
9 *
10 * The following files were used to create this file.
11 *
12 *      Main code file      : __MBEDTLS_TEST_TEMPLATE__TEST_MAIN_FILE
13 *      Platform code file  : __MBEDTLS_TEST_TEMPLATE__TEST_PLATFORM_FILE
14 *      Helper file         : __MBEDTLS_TEST_TEMPLATE__TEST_COMMON_HELPER_FILE
15 *      Test suite file     : __MBEDTLS_TEST_TEMPLATE__TEST_CASE_FILE
16 *      Test suite data     : __MBEDTLS_TEST_TEMPLATE__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#include "mbedtls/build_info.h"
27
28/* Test code may use deprecated identifiers only if the preprocessor symbol
29 * MBEDTLS_TEST_DEPRECATED is defined. When building tests, set
30 * MBEDTLS_TEST_DEPRECATED explicitly if MBEDTLS_DEPRECATED_WARNING is
31 * enabled but the corresponding warnings are not treated as errors.
32 */
33#if !defined(MBEDTLS_DEPRECATED_REMOVED) && !defined(MBEDTLS_DEPRECATED_WARNING)
34#define MBEDTLS_TEST_DEPRECATED
35#endif
36
37/*----------------------------------------------------------------------------*/
38/* Common helper code */
39
40__MBEDTLS_TEST_TEMPLATE__TEST_COMMON_HELPERS
41
42#line __MBEDTLS_TEST_TEMPLATE__LINE_NO "suites/main_test.function"
43
44
45/*----------------------------------------------------------------------------*/
46/* Test Suite Code */
47
48
49#define TEST_SUITE_ACTIVE
50
51__MBEDTLS_TEST_TEMPLATE__FUNCTIONS_CODE
52
53#line __MBEDTLS_TEST_TEMPLATE__LINE_NO "suites/main_test.function"
54
55
56/*----------------------------------------------------------------------------*/
57/* Test dispatch code */
58
59
60/**
61 * \brief       Evaluates an expression/macro into its literal integer value.
62 *              For optimizing space for embedded targets each expression/macro
63 *              is identified by a unique identifier instead of string literals.
64 *              Identifiers and evaluation code is generated by script:
65 *              __MBEDTLS_TEST_TEMPLATE__GENERATOR_SCRIPT
66 *
67 * \param exp_id    Expression identifier.
68 * \param out_value Pointer to int to hold the integer.
69 *
70 * \return       0 if exp_id is found. 1 otherwise.
71 */
72int get_expression(int32_t exp_id, int32_t *out_value)
73{
74    int ret = KEY_VALUE_MAPPING_FOUND;
75
76    (void) exp_id;
77    (void) out_value;
78
79    switch (exp_id) {
80    __MBEDTLS_TEST_TEMPLATE__EXPRESSION_CODE
81#line __MBEDTLS_TEST_TEMPLATE__LINE_NO "suites/main_test.function"
82        default:
83        {
84            ret = KEY_VALUE_MAPPING_NOT_FOUND;
85        }
86        break;
87    }
88    return ret;
89}
90
91
92/**
93 * \brief       Checks if the dependency i.e. the compile flag is set.
94 *              For optimizing space for embedded targets each dependency
95 *              is identified by a unique identifier instead of string literals.
96 *              Identifiers and check code is generated by script:
97 *              __MBEDTLS_TEST_TEMPLATE__GENERATOR_SCRIPT
98 *
99 * \param dep_id    Dependency identifier.
100 *
101 * \return       DEPENDENCY_SUPPORTED if set else DEPENDENCY_NOT_SUPPORTED
102 */
103int dep_check(int dep_id)
104{
105    int ret = DEPENDENCY_NOT_SUPPORTED;
106
107    (void) dep_id;
108
109    switch (dep_id) {
110    __MBEDTLS_TEST_TEMPLATE__DEP_CHECK_CODE
111#line __MBEDTLS_TEST_TEMPLATE__LINE_NO "suites/main_test.function"
112        default:
113            break;
114    }
115    return ret;
116}
117
118
119/**
120 * \brief       Function pointer type for test function wrappers.
121 *
122 * A test function wrapper decodes the parameters and passes them to the
123 * underlying test function. Both the wrapper and the underlying function
124 * return void. Test wrappers assume that they are passed a suitable
125 * parameter array and do not perform any error detection.
126 *
127 * \param param_array   The array of parameters. Each element is a `void *`
128 *                      which the wrapper casts to the correct type and
129 *                      dereferences. Each wrapper function hard-codes the
130 *                      number and types of the parameters.
131 */
132typedef void (*TestWrapper_t)(void **param_array);
133
134
135/**
136 * \brief       Table of test function wrappers. Used by dispatch_test().
137 *              This table is populated by script:
138 *              __MBEDTLS_TEST_TEMPLATE__GENERATOR_SCRIPT
139 *
140 */
141TestWrapper_t test_funcs[] =
142{
143    __MBEDTLS_TEST_TEMPLATE__DISPATCH_CODE
144#line __MBEDTLS_TEST_TEMPLATE__LINE_NO "suites/main_test.function"
145};
146
147/**
148 * \brief        Dispatches test functions based on function index.
149 *
150 * \param func_idx    Test function index.
151 * \param params      The array of parameters to pass to the test function.
152 *                    It will be decoded by the #TestWrapper_t wrapper function.
153 *
154 * \return       DISPATCH_TEST_SUCCESS if found
155 *               DISPATCH_TEST_FN_NOT_FOUND if not found
156 *               DISPATCH_UNSUPPORTED_SUITE if not compile time enabled.
157 */
158int dispatch_test(size_t func_idx, void **params)
159{
160    int ret = DISPATCH_TEST_SUCCESS;
161    TestWrapper_t fp = NULL;
162
163    if (func_idx < (int) (sizeof(test_funcs) / sizeof(TestWrapper_t))) {
164        fp = test_funcs[func_idx];
165        if (fp) {
166            #if defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG)
167            mbedtls_test_enable_insecure_external_rng();
168            #endif
169
170            fp(params);
171
172            #if defined(MBEDTLS_TEST_MUTEX_USAGE)
173            mbedtls_test_mutex_usage_check();
174            #endif /* MBEDTLS_TEST_MUTEX_USAGE */
175        } else {
176            ret = DISPATCH_UNSUPPORTED_SUITE;
177        }
178    } else {
179        ret = DISPATCH_TEST_FN_NOT_FOUND;
180    }
181
182    return ret;
183}
184
185
186/**
187 * \brief       Checks if test function is supported in this build-time
188 *              configuration.
189 *
190 * \param func_idx    Test function index.
191 *
192 * \return       DISPATCH_TEST_SUCCESS if found
193 *               DISPATCH_TEST_FN_NOT_FOUND if not found
194 *               DISPATCH_UNSUPPORTED_SUITE if not compile time enabled.
195 */
196int check_test(size_t func_idx)
197{
198    int ret = DISPATCH_TEST_SUCCESS;
199    TestWrapper_t fp = NULL;
200
201    if (func_idx < (int) (sizeof(test_funcs)/sizeof(TestWrapper_t))) {
202        fp = test_funcs[func_idx];
203        if (fp == NULL) {
204            ret = DISPATCH_UNSUPPORTED_SUITE;
205        }
206    } else {
207        ret = DISPATCH_TEST_FN_NOT_FOUND;
208    }
209
210    return ret;
211}
212
213
214__MBEDTLS_TEST_TEMPLATE__PLATFORM_CODE
215
216#line __MBEDTLS_TEST_TEMPLATE__LINE_NO "suites/main_test.function"
217
218/*----------------------------------------------------------------------------*/
219/* Main Test code */
220
221
222/**
223 * \brief       Program main. Invokes platform specific execute_tests().
224 *
225 * \param argc      Command line arguments count.
226 * \param argv      Array of command line arguments.
227 *
228 * \return       Exit code.
229 */
230int main(int argc, const char *argv[])
231{
232#if defined(MBEDTLS_TEST_HOOKS)
233    extern void (*mbedtls_test_hook_test_fail)(const char *test, int line, const char *file);
234    mbedtls_test_hook_test_fail = &mbedtls_test_fail;
235#if defined(MBEDTLS_ERROR_C)
236    mbedtls_test_hook_error_add = &mbedtls_test_err_add_check;
237#endif
238#endif
239
240    int ret = mbedtls_test_platform_setup();
241    if (ret != 0) {
242        mbedtls_fprintf(stderr,
243                        "FATAL: Failed to initialize platform - error %d\n",
244                        ret);
245        return -1;
246    }
247
248    ret = execute_tests(argc, argv);
249    mbedtls_test_platform_teardown();
250    return ret;
251}
252