blob: af4b84e3bd3153f8178f7c6054bc8a845ac15c0d [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
Gilles Peskine31f88a22020-04-14 19:39:56 +020022#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
23#if !defined(_POSIX_C_SOURCE)
24#define _POSIX_C_SOURCE 1 // for fileno() from <stdio.h>
25#endif
26#endif
27
Azim Khan191e9042017-06-09 12:39:00 +010028#if !defined(MBEDTLS_CONFIG_FILE)
29#include <mbedtls/config.h>
30#else
31#include MBEDTLS_CONFIG_FILE
32#endif
Paul Bakker19343182013-08-16 13:31:10 +020033
Hanno Becker1cfc5dd2018-11-12 13:18:45 +000034#if defined(MBEDTLS_USE_PSA_CRYPTO)
35#include "psa/crypto.h"
36#endif /* MBEDTLS_USE_PSA_CRYPTO */
SimonB152ea182016-02-15 23:27:28 +000037
Gilles Peskine2ff02c32019-11-29 12:17:21 +010038/* Test code may use deprecated identifiers only if the preprocessor symbol
39 * MBEDTLS_TEST_DEPRECATED is defined. When building tests, set
40 * MBEDTLS_TEST_DEPRECATED explicitly if MBEDTLS_DEPRECATED_WARNING is
41 * enabled but the corresponding warnings are not treated as errors.
42 */
Gilles Peskine841b14b2019-11-26 17:37:37 +010043#if !defined(MBEDTLS_DEPRECATED_REMOVED) && !defined(MBEDTLS_DEPRECATED_WARNING)
44#define MBEDTLS_TEST_DEPRECATED
45#endif
46
SimonB152ea182016-02-15 23:27:28 +000047/*----------------------------------------------------------------------------*/
Azim Khan191e9042017-06-09 12:39:00 +010048/* Common helper code */
SimonB152ea182016-02-15 23:27:28 +000049
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010050$test_common_helpers
Paul Bakkerde56ca12013-09-15 17:05:21 +020051
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010052#line $line_no "suites/main_test.function"
Azim Khan191e9042017-06-09 12:39:00 +010053
54
55/*----------------------------------------------------------------------------*/
56/* Test Suite Code */
57
58
59#define TEST_SUITE_ACTIVE
60
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010061$functions_code
Azim Khan191e9042017-06-09 12:39:00 +010062
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010063#line $line_no "suites/main_test.function"
SimonB15942102016-04-25 21:34:49 +010064
SimonB152ea182016-02-15 23:27:28 +000065
66/*----------------------------------------------------------------------------*/
67/* Test dispatch code */
68
Paul Bakker19343182013-08-16 13:31:10 +020069
Azim Khan191e9042017-06-09 12:39:00 +010070/**
71 * \brief Evaluates an expression/macro into its literal integer value.
72 * For optimizing space for embedded targets each expression/macro
73 * is identified by a unique identifier instead of string literals.
74 * Identifiers and evaluation code is generated by script:
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010075 * $generator_script
Azim Khan191e9042017-06-09 12:39:00 +010076 *
77 * \param exp_id Expression identifier.
78 * \param out_value Pointer to int to hold the integer.
79 *
80 * \return 0 if exp_id is found. 1 otherwise.
81 */
82int get_expression( int32_t exp_id, int32_t * out_value )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010083{
Azim Khanb1c2d0f2017-07-07 17:14:02 +010084 int ret = KEY_VALUE_MAPPING_FOUND;
85
86 (void) exp_id;
87 (void) out_value;
88
89 switch( exp_id )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010090 {
91$expression_code
92#line $line_no "suites/main_test.function"
Azim Khanb1c2d0f2017-07-07 17:14:02 +010093 default:
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010094 {
Azim Khanb1c2d0f2017-07-07 17:14:02 +010095 ret = KEY_VALUE_MAPPING_NOT_FOUND;
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010096 }
Azim Khanb1c2d0f2017-07-07 17:14:02 +010097 break;
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010098 }
Azim Khanb1c2d0f2017-07-07 17:14:02 +010099 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100100}
Paul Bakker19343182013-08-16 13:31:10 +0200101
Paul Bakker19343182013-08-16 13:31:10 +0200102
Azim Khan191e9042017-06-09 12:39:00 +0100103/**
104 * \brief Checks if the dependency i.e. the compile flag is set.
105 * For optimizing space for embedded targets each dependency
106 * is identified by a unique identifier instead of string literals.
107 * Identifiers and check code is generated by script:
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100108 * $generator_script
Azim Khan191e9042017-06-09 12:39:00 +0100109 *
110 * \param exp_id Dependency identifier.
111 *
112 * \return DEPENDENCY_SUPPORTED if set else DEPENDENCY_NOT_SUPPORTED
113 */
114int dep_check( int dep_id )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100115{
Azim Khanb1c2d0f2017-07-07 17:14:02 +0100116 int ret = DEPENDENCY_NOT_SUPPORTED;
117
118 (void) dep_id;
119
120 switch( dep_id )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100121 {
122$dep_check_code
123#line $line_no "suites/main_test.function"
Azim Khanb1c2d0f2017-07-07 17:14:02 +0100124 default:
125 break;
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100126 }
Azim Khanb1c2d0f2017-07-07 17:14:02 +0100127 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100128}
Paul Bakker19343182013-08-16 13:31:10 +0200129
SimonB8ca7bc42016-04-17 23:24:50 +0100130
Azim Khan191e9042017-06-09 12:39:00 +0100131/**
132 * \brief Function pointer type for test function wrappers.
133 *
134 *
135 * \param void ** Pointer to void pointers. Represents an array of test
136 * function parameters.
137 *
138 * \return void
139 */
140typedef void (*TestWrapper_t)( void ** );
Simon Butcher65b1fa62016-05-23 23:18:26 +0100141
Azim Khan191e9042017-06-09 12:39:00 +0100142
143/**
144 * \brief Table of test function wrappers. Used by dispatch_test().
145 * This table is populated by script:
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100146 * $generator_script
Azim Khan191e9042017-06-09 12:39:00 +0100147 *
148 */
149TestWrapper_t test_funcs[] =
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100150{
151$dispatch_code
152#line $line_no "suites/main_test.function"
153};
Azim Khan191e9042017-06-09 12:39:00 +0100154
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500155/**
156 * \brief Execute the test function.
157 *
158 * This is a wrapper function around the test function execution
159 * to allow the setjmp() call used to catch any calls to the
160 * parameter failure callback, to be used. Calls to setjmp()
161 * can invalidate the state of any local auto variables.
162 *
163 * \param fp Function pointer to the test function
164 * \param params Parameters to pass
165 *
166 */
167void execute_function_ptr(TestWrapper_t fp, void **params)
168{
169#if defined(MBEDTLS_CHECK_PARAMS)
170 if ( setjmp( param_fail_jmp ) == 0 )
171 {
172 fp( params );
173 }
174 else
175 {
176 /* Unexpected parameter validation error */
Hanno Beckere69d0152019-07-05 13:31:30 +0100177 test_info.result = TEST_RESULT_FAILED;
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500178 }
179
180 memset( param_fail_jmp, 0, sizeof(jmp_buf) );
181#else
182 fp( params );
183#endif
184}
Azim Khan191e9042017-06-09 12:39:00 +0100185
186/**
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500187 * \brief Dispatches test functions based on function index.
Azim Khan191e9042017-06-09 12:39:00 +0100188 *
189 * \param exp_id Test function index.
190 *
191 * \return DISPATCH_TEST_SUCCESS if found
192 * DISPATCH_TEST_FN_NOT_FOUND if not found
193 * DISPATCH_UNSUPPORTED_SUITE if not compile time enabled.
194 */
k-stachowiak03954f22019-09-16 10:23:10 +0200195int dispatch_test( size_t func_idx, void ** params )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100196{
Azim Khan191e9042017-06-09 12:39:00 +0100197 int ret = DISPATCH_TEST_SUCCESS;
198 TestWrapper_t fp = NULL;
199
Mohammad Azim Khand2d01122018-07-18 17:48:37 +0100200 if ( func_idx < (int)( sizeof( test_funcs ) / sizeof( TestWrapper_t ) ) )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100201 {
Azim Khan191e9042017-06-09 12:39:00 +0100202 fp = test_funcs[func_idx];
203 if ( fp )
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500204 execute_function_ptr(fp, params);
Azim Khan191e9042017-06-09 12:39:00 +0100205 else
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100206 ret = DISPATCH_UNSUPPORTED_SUITE;
207 }
Azim Khan191e9042017-06-09 12:39:00 +0100208 else
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100209 {
210 ret = DISPATCH_TEST_FN_NOT_FOUND;
211 }
Azim Khan191e9042017-06-09 12:39:00 +0100212
Paul Bakker19343182013-08-16 13:31:10 +0200213 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100214}
Paul Bakker19343182013-08-16 13:31:10 +0200215
SimonB152ea182016-02-15 23:27:28 +0000216
Azim Khan13c6bfb2017-06-15 14:45:56 +0100217/**
218 * \brief Checks if test function is supported
219 *
220 * \param exp_id Test function index.
221 *
222 * \return DISPATCH_TEST_SUCCESS if found
223 * DISPATCH_TEST_FN_NOT_FOUND if not found
224 * DISPATCH_UNSUPPORTED_SUITE if not compile time enabled.
225 */
k-stachowiak03954f22019-09-16 10:23:10 +0200226int check_test( size_t func_idx )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100227{
Azim Khan13c6bfb2017-06-15 14:45:56 +0100228 int ret = DISPATCH_TEST_SUCCESS;
229 TestWrapper_t fp = NULL;
230
231 if ( func_idx < (int)( sizeof(test_funcs)/sizeof( TestWrapper_t ) ) )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100232 {
Azim Khan13c6bfb2017-06-15 14:45:56 +0100233 fp = test_funcs[func_idx];
234 if ( fp == NULL )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100235 ret = DISPATCH_UNSUPPORTED_SUITE;
236 }
Azim Khan13c6bfb2017-06-15 14:45:56 +0100237 else
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100238 {
239 ret = DISPATCH_TEST_FN_NOT_FOUND;
240 }
Azim Khan13c6bfb2017-06-15 14:45:56 +0100241
242 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100243}
Azim Khan13c6bfb2017-06-15 14:45:56 +0100244
245
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100246$platform_code
Azim Khan191e9042017-06-09 12:39:00 +0100247
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100248#line $line_no "suites/main_test.function"
Azim Khan191e9042017-06-09 12:39:00 +0100249
SimonB152ea182016-02-15 23:27:28 +0000250/*----------------------------------------------------------------------------*/
251/* Main Test code */
252
SimonB15942102016-04-25 21:34:49 +0100253
Azim Khan191e9042017-06-09 12:39:00 +0100254/**
255 * \brief Program main. Invokes platform specific execute_tests().
Gilles Peskine964faeb2017-09-29 18:00:25 +0200256 *
Azim Khan191e9042017-06-09 12:39:00 +0100257 * \param argc Command line arguments count.
258 * \param argv Array of command line arguments.
259 *
260 * \return Exit code.
Gilles Peskine964faeb2017-09-29 18:00:25 +0200261 */
Azim Khan191e9042017-06-09 12:39:00 +0100262int main( int argc, const char *argv[] )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100263{
Ronald Crone9c09f12020-06-08 16:44:58 +0200264 int ret = mbedtls_test_platform_setup();
Andrzej Kurekf13ca952018-04-18 04:14:31 -0400265 if( ret != 0 )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100266 {
Andrzej Kurekf13ca952018-04-18 04:14:31 -0400267 mbedtls_fprintf( stderr,
268 "FATAL: Failed to initialize platform - error %d\n",
269 ret );
270 return( -1 );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100271 }
Hanno Becker1cfc5dd2018-11-12 13:18:45 +0000272
Azim Khan191e9042017-06-09 12:39:00 +0100273 ret = execute_tests( argc, argv );
Ronald Crone9c09f12020-06-08 16:44:58 +0200274 mbedtls_test_platform_teardown();
Azim Khan191e9042017-06-09 12:39:00 +0100275 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100276}