blob: 6901256f8c95a679ed778fd872abbed37d9da217 [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 *
Azim Khan191e9042017-06-09 12:39:00 +010018 */
Paul Bakkerde56ca12013-09-15 17:05:21 +020019
Gilles Peskine31f88a22020-04-14 19:39:56 +020020#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
21#if !defined(_POSIX_C_SOURCE)
nia1c0c8372020-06-11 12:03:45 +010022#define _POSIX_C_SOURCE 200112L // for fileno() from <stdio.h>
Gilles Peskine31f88a22020-04-14 19:39:56 +020023#endif
24#endif
25
Azim Khan191e9042017-06-09 12:39:00 +010026#if !defined(MBEDTLS_CONFIG_FILE)
27#include <mbedtls/config.h>
28#else
29#include MBEDTLS_CONFIG_FILE
30#endif
Paul Bakker19343182013-08-16 13:31:10 +020031
Hanno Becker1cfc5dd2018-11-12 13:18:45 +000032#if defined(MBEDTLS_USE_PSA_CRYPTO)
33#include "psa/crypto.h"
34#endif /* MBEDTLS_USE_PSA_CRYPTO */
SimonB152ea182016-02-15 23:27:28 +000035
Gilles Peskine2ff02c32019-11-29 12:17:21 +010036/* Test code may use deprecated identifiers only if the preprocessor symbol
37 * MBEDTLS_TEST_DEPRECATED is defined. When building tests, set
38 * MBEDTLS_TEST_DEPRECATED explicitly if MBEDTLS_DEPRECATED_WARNING is
39 * enabled but the corresponding warnings are not treated as errors.
40 */
Gilles Peskine841b14b2019-11-26 17:37:37 +010041#if !defined(MBEDTLS_DEPRECATED_REMOVED) && !defined(MBEDTLS_DEPRECATED_WARNING)
42#define MBEDTLS_TEST_DEPRECATED
43#endif
44
SimonB152ea182016-02-15 23:27:28 +000045/*----------------------------------------------------------------------------*/
Azim Khan191e9042017-06-09 12:39:00 +010046/* Common helper code */
SimonB152ea182016-02-15 23:27:28 +000047
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010048$test_common_helpers
Paul Bakkerde56ca12013-09-15 17:05:21 +020049
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010050#line $line_no "suites/main_test.function"
Azim Khan191e9042017-06-09 12:39:00 +010051
52
53/*----------------------------------------------------------------------------*/
54/* Test Suite Code */
55
56
57#define TEST_SUITE_ACTIVE
58
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010059$functions_code
Azim Khan191e9042017-06-09 12:39:00 +010060
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010061#line $line_no "suites/main_test.function"
SimonB15942102016-04-25 21:34:49 +010062
SimonB152ea182016-02-15 23:27:28 +000063
64/*----------------------------------------------------------------------------*/
65/* Test dispatch code */
66
Paul Bakker19343182013-08-16 13:31:10 +020067
Azim Khan191e9042017-06-09 12:39:00 +010068/**
69 * \brief Evaluates an expression/macro into its literal integer value.
70 * For optimizing space for embedded targets each expression/macro
71 * is identified by a unique identifier instead of string literals.
72 * Identifiers and evaluation code is generated by script:
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010073 * $generator_script
Azim Khan191e9042017-06-09 12:39:00 +010074 *
75 * \param exp_id Expression identifier.
76 * \param out_value Pointer to int to hold the integer.
77 *
78 * \return 0 if exp_id is found. 1 otherwise.
79 */
80int get_expression( int32_t exp_id, int32_t * out_value )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010081{
Azim Khanb1c2d0f2017-07-07 17:14:02 +010082 int ret = KEY_VALUE_MAPPING_FOUND;
83
84 (void) exp_id;
85 (void) out_value;
86
87 switch( exp_id )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010088 {
89$expression_code
90#line $line_no "suites/main_test.function"
Azim Khanb1c2d0f2017-07-07 17:14:02 +010091 default:
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010092 {
Azim Khanb1c2d0f2017-07-07 17:14:02 +010093 ret = KEY_VALUE_MAPPING_NOT_FOUND;
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010094 }
Azim Khanb1c2d0f2017-07-07 17:14:02 +010095 break;
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010096 }
Azim Khanb1c2d0f2017-07-07 17:14:02 +010097 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010098}
Paul Bakker19343182013-08-16 13:31:10 +020099
Paul Bakker19343182013-08-16 13:31:10 +0200100
Azim Khan191e9042017-06-09 12:39:00 +0100101/**
102 * \brief Checks if the dependency i.e. the compile flag is set.
103 * For optimizing space for embedded targets each dependency
104 * is identified by a unique identifier instead of string literals.
105 * Identifiers and check code is generated by script:
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100106 * $generator_script
Azim Khan191e9042017-06-09 12:39:00 +0100107 *
108 * \param exp_id Dependency identifier.
109 *
110 * \return DEPENDENCY_SUPPORTED if set else DEPENDENCY_NOT_SUPPORTED
111 */
112int dep_check( int dep_id )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100113{
Azim Khanb1c2d0f2017-07-07 17:14:02 +0100114 int ret = DEPENDENCY_NOT_SUPPORTED;
115
116 (void) dep_id;
117
118 switch( dep_id )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100119 {
120$dep_check_code
121#line $line_no "suites/main_test.function"
Azim Khanb1c2d0f2017-07-07 17:14:02 +0100122 default:
123 break;
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100124 }
Azim Khanb1c2d0f2017-07-07 17:14:02 +0100125 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100126}
Paul Bakker19343182013-08-16 13:31:10 +0200127
SimonB8ca7bc42016-04-17 23:24:50 +0100128
Azim Khan191e9042017-06-09 12:39:00 +0100129/**
130 * \brief Function pointer type for test function wrappers.
131 *
132 *
133 * \param void ** Pointer to void pointers. Represents an array of test
134 * function parameters.
135 *
136 * \return void
137 */
138typedef void (*TestWrapper_t)( void ** );
Simon Butcher65b1fa62016-05-23 23:18:26 +0100139
Azim Khan191e9042017-06-09 12:39:00 +0100140
141/**
142 * \brief Table of test function wrappers. Used by dispatch_test().
143 * This table is populated by script:
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100144 * $generator_script
Azim Khan191e9042017-06-09 12:39:00 +0100145 *
146 */
147TestWrapper_t test_funcs[] =
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100148{
149$dispatch_code
150#line $line_no "suites/main_test.function"
151};
Azim Khan191e9042017-06-09 12:39:00 +0100152
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500153/**
154 * \brief Execute the test function.
155 *
156 * This is a wrapper function around the test function execution
157 * to allow the setjmp() call used to catch any calls to the
158 * parameter failure callback, to be used. Calls to setjmp()
159 * can invalidate the state of any local auto variables.
160 *
161 * \param fp Function pointer to the test function
162 * \param params Parameters to pass
163 *
164 */
165void execute_function_ptr(TestWrapper_t fp, void **params)
166{
167#if defined(MBEDTLS_CHECK_PARAMS)
168 if ( setjmp( param_fail_jmp ) == 0 )
169 {
170 fp( params );
171 }
172 else
173 {
174 /* Unexpected parameter validation error */
Hanno Beckere69d0152019-07-05 13:31:30 +0100175 test_info.result = TEST_RESULT_FAILED;
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500176 }
177
178 memset( param_fail_jmp, 0, sizeof(jmp_buf) );
179#else
180 fp( params );
181#endif
182}
Azim Khan191e9042017-06-09 12:39:00 +0100183
184/**
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500185 * \brief Dispatches test functions based on function index.
Azim Khan191e9042017-06-09 12:39:00 +0100186 *
187 * \param exp_id Test function index.
188 *
189 * \return DISPATCH_TEST_SUCCESS if found
190 * DISPATCH_TEST_FN_NOT_FOUND if not found
191 * DISPATCH_UNSUPPORTED_SUITE if not compile time enabled.
192 */
k-stachowiak03954f22019-09-16 10:23:10 +0200193int dispatch_test( size_t func_idx, void ** params )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100194{
Azim Khan191e9042017-06-09 12:39:00 +0100195 int ret = DISPATCH_TEST_SUCCESS;
196 TestWrapper_t fp = NULL;
197
Mohammad Azim Khand2d01122018-07-18 17:48:37 +0100198 if ( func_idx < (int)( sizeof( test_funcs ) / sizeof( TestWrapper_t ) ) )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100199 {
Azim Khan191e9042017-06-09 12:39:00 +0100200 fp = test_funcs[func_idx];
201 if ( fp )
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500202 execute_function_ptr(fp, params);
Azim Khan191e9042017-06-09 12:39:00 +0100203 else
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100204 ret = DISPATCH_UNSUPPORTED_SUITE;
205 }
Azim Khan191e9042017-06-09 12:39:00 +0100206 else
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100207 {
208 ret = DISPATCH_TEST_FN_NOT_FOUND;
209 }
Azim Khan191e9042017-06-09 12:39:00 +0100210
Paul Bakker19343182013-08-16 13:31:10 +0200211 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100212}
Paul Bakker19343182013-08-16 13:31:10 +0200213
SimonB152ea182016-02-15 23:27:28 +0000214
Azim Khan13c6bfb2017-06-15 14:45:56 +0100215/**
216 * \brief Checks if test function is supported
217 *
218 * \param exp_id Test function index.
219 *
220 * \return DISPATCH_TEST_SUCCESS if found
221 * DISPATCH_TEST_FN_NOT_FOUND if not found
222 * DISPATCH_UNSUPPORTED_SUITE if not compile time enabled.
223 */
k-stachowiak03954f22019-09-16 10:23:10 +0200224int check_test( size_t func_idx )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100225{
Azim Khan13c6bfb2017-06-15 14:45:56 +0100226 int ret = DISPATCH_TEST_SUCCESS;
227 TestWrapper_t fp = NULL;
228
229 if ( func_idx < (int)( sizeof(test_funcs)/sizeof( TestWrapper_t ) ) )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100230 {
Azim Khan13c6bfb2017-06-15 14:45:56 +0100231 fp = test_funcs[func_idx];
232 if ( fp == NULL )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100233 ret = DISPATCH_UNSUPPORTED_SUITE;
234 }
Azim Khan13c6bfb2017-06-15 14:45:56 +0100235 else
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100236 {
237 ret = DISPATCH_TEST_FN_NOT_FOUND;
238 }
Azim Khan13c6bfb2017-06-15 14:45:56 +0100239
240 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100241}
Azim Khan13c6bfb2017-06-15 14:45:56 +0100242
243
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100244$platform_code
Azim Khan191e9042017-06-09 12:39:00 +0100245
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100246#line $line_no "suites/main_test.function"
Azim Khan191e9042017-06-09 12:39:00 +0100247
SimonB152ea182016-02-15 23:27:28 +0000248/*----------------------------------------------------------------------------*/
249/* Main Test code */
250
SimonB15942102016-04-25 21:34:49 +0100251
Azim Khan191e9042017-06-09 12:39:00 +0100252/**
253 * \brief Program main. Invokes platform specific execute_tests().
Gilles Peskine964faeb2017-09-29 18:00:25 +0200254 *
Azim Khan191e9042017-06-09 12:39:00 +0100255 * \param argc Command line arguments count.
256 * \param argv Array of command line arguments.
257 *
258 * \return Exit code.
Gilles Peskine964faeb2017-09-29 18:00:25 +0200259 */
Azim Khan191e9042017-06-09 12:39:00 +0100260int main( int argc, const char *argv[] )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100261{
Ronald Crone9c09f12020-06-08 16:44:58 +0200262 int ret = mbedtls_test_platform_setup();
Andrzej Kurekf13ca952018-04-18 04:14:31 -0400263 if( ret != 0 )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100264 {
Andrzej Kurekf13ca952018-04-18 04:14:31 -0400265 mbedtls_fprintf( stderr,
266 "FATAL: Failed to initialize platform - error %d\n",
267 ret );
268 return( -1 );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100269 }
Hanno Becker1cfc5dd2018-11-12 13:18:45 +0000270
Azim Khan191e9042017-06-09 12:39:00 +0100271 ret = execute_tests( argc, argv );
Ronald Crone9c09f12020-06-08 16:44:58 +0200272 mbedtls_test_platform_teardown();
Azim Khan191e9042017-06-09 12:39:00 +0100273 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100274}