mirror of
				https://github.com/cuberite/polarssl.git
				synced 2025-11-03 20:22:59 -05:00 
			
		
		
		
	Simplification of the tests
Signed-off-by: TRodziewicz <tomasz.rodziewicz@mobica.com>
This commit is contained in:
		
							parent
							
								
									7019955c76
								
							
						
					
					
						commit
						2d0769d149
					
				@ -58,9 +58,6 @@
 | 
			
		||||
 *          It allows a library function to return a value and return an error
 | 
			
		||||
 *          code that can be tested.
 | 
			
		||||
 *
 | 
			
		||||
 *          This macro is not suitable for negative parameter validation tests,
 | 
			
		||||
 *          as it assumes the test step will not create an error.
 | 
			
		||||
 *
 | 
			
		||||
 *          Failing the test means:
 | 
			
		||||
 *          - Mark this test case as failed.
 | 
			
		||||
 *          - Print a message identifying the failure.
 | 
			
		||||
 | 
			
		||||
@ -204,15 +204,6 @@ int mbedtls_test_hexcmp( uint8_t * a, uint8_t * b,
 | 
			
		||||
    return ret;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void mbedtls_param_failed( const char *failure_condition,
 | 
			
		||||
                           const char *file,
 | 
			
		||||
                           int line )
 | 
			
		||||
{
 | 
			
		||||
    (void) failure_condition;
 | 
			
		||||
    (void) file;
 | 
			
		||||
    (void) line;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#if defined(MBEDTLS_TEST_HOOKS)
 | 
			
		||||
void mbedtls_test_err_add_check( int high, int low,
 | 
			
		||||
                                 const char *file, int line )
 | 
			
		||||
 | 
			
		||||
@ -158,31 +158,6 @@ $dispatch_code
 | 
			
		||||
#line $line_no "suites/main_test.function"
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * \brief        Execute the test function.
 | 
			
		||||
 *
 | 
			
		||||
 *               This is a wrapper function around the test function execution
 | 
			
		||||
 *               to allow the setjmp() call used to catch any calls to the
 | 
			
		||||
 *               parameter failure callback, to be used. Calls to setjmp()
 | 
			
		||||
 *               can invalidate the state of any local auto variables.
 | 
			
		||||
 *
 | 
			
		||||
 * \param fp     Function pointer to the test function.
 | 
			
		||||
 * \param params Parameters to pass to the #TestWrapper_t wrapper function.
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
void execute_function_ptr(TestWrapper_t fp, void **params)
 | 
			
		||||
{
 | 
			
		||||
#if defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG)
 | 
			
		||||
    mbedtls_test_enable_insecure_external_rng( );
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
    fp( params );
 | 
			
		||||
 | 
			
		||||
#if defined(MBEDTLS_TEST_MUTEX_USAGE)
 | 
			
		||||
    mbedtls_test_mutex_usage_check( );
 | 
			
		||||
#endif /* MBEDTLS_TEST_MUTEX_USAGE */
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * \brief        Dispatches test functions based on function index.
 | 
			
		||||
 *
 | 
			
		||||
@ -203,7 +178,17 @@ int dispatch_test( size_t func_idx, void ** params )
 | 
			
		||||
    {
 | 
			
		||||
        fp = test_funcs[func_idx];
 | 
			
		||||
        if ( fp )
 | 
			
		||||
            execute_function_ptr(fp, params);
 | 
			
		||||
        {
 | 
			
		||||
            #if defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG)
 | 
			
		||||
                mbedtls_test_enable_insecure_external_rng( );
 | 
			
		||||
            #endif
 | 
			
		||||
 | 
			
		||||
                fp( params );
 | 
			
		||||
 | 
			
		||||
            #if defined(MBEDTLS_TEST_MUTEX_USAGE)
 | 
			
		||||
                mbedtls_test_mutex_usage_check( );
 | 
			
		||||
            #endif /* MBEDTLS_TEST_MUTEX_USAGE */
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
            ret = DISPATCH_UNSUPPORTED_SUITE;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -213,15 +213,12 @@ void cipher_invalid_param_conditional( )
 | 
			
		||||
    mbedtls_cipher_context_t valid_ctx;
 | 
			
		||||
 | 
			
		||||
    mbedtls_operation_t invalid_operation = 100;
 | 
			
		||||
    mbedtls_cipher_padding_t valid_mode = MBEDTLS_PADDING_ZEROS;
 | 
			
		||||
    unsigned char valid_buffer[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 };
 | 
			
		||||
    int valid_size = sizeof(valid_buffer);
 | 
			
		||||
    int valid_bitlen = valid_size * 8;
 | 
			
		||||
    const mbedtls_cipher_info_t *valid_info = mbedtls_cipher_info_from_type(
 | 
			
		||||
        *( mbedtls_cipher_list() ) );
 | 
			
		||||
 | 
			
		||||
    (void)valid_mode; /* In some configurations this is unused */
 | 
			
		||||
 | 
			
		||||
    TEST_EQUAL(
 | 
			
		||||
        MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA,
 | 
			
		||||
        mbedtls_cipher_setkey( &valid_ctx,
 | 
			
		||||
 | 
			
		||||
@ -1,3 +1,6 @@
 | 
			
		||||
RSA parameter validation
 | 
			
		||||
rsa_invalid_param:
 | 
			
		||||
 | 
			
		||||
RSA init-free-free
 | 
			
		||||
rsa_init_free:0
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -17,6 +17,25 @@
 | 
			
		||||
 * END_DEPENDENCIES
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
/* BEGIN_CASE depends_on:NOT_DEFINED */
 | 
			
		||||
void rsa_invalid_param( )
 | 
			
		||||
{
 | 
			
		||||
    mbedtls_rsa_context ctx;
 | 
			
		||||
    const int valid_padding = MBEDTLS_RSA_PKCS_V21;
 | 
			
		||||
    const int invalid_padding = 42;
 | 
			
		||||
    unsigned char buf[42] = { 0 };
 | 
			
		||||
    size_t olen;
 | 
			
		||||
 | 
			
		||||
    TEST_INVALID_PARAM( mbedtls_rsa_init( &ctx, invalid_padding, 0 ) );
 | 
			
		||||
 | 
			
		||||
    TEST_INVALID_PARAM( mbedtls_rsa_set_padding( &ctx,
 | 
			
		||||
                                                 invalid_padding, 0 ) );
 | 
			
		||||
 | 
			
		||||
exit:
 | 
			
		||||
    return;
 | 
			
		||||
}
 | 
			
		||||
/* END_CASE */
 | 
			
		||||
 | 
			
		||||
/* BEGIN_CASE */
 | 
			
		||||
void rsa_init_free( int reinit )
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user