Hanno Becker | 09d880a | 2021-01-12 07:43:30 +0000 | [diff] [blame^] | 1 | /* BEGIN_HEADER */ |
| 2 | |
| 3 | #include <stdlib.h> |
| 4 | |
| 5 | /* TODO: How are test suites supposed to include internal headers? */ |
| 6 | #include "../library/mps/reader.h" |
| 7 | |
| 8 | /* |
| 9 | * Compile-time configuration for test suite. |
| 10 | */ |
| 11 | |
| 12 | /* Comment/Uncomment this to disable/enable the |
| 13 | * testing of the various MPS layers. |
| 14 | * This can be useful for time-consuming instrumentation |
| 15 | * tasks such as the conversion of E-ACSL annotations |
| 16 | * into runtime assertions. */ |
| 17 | #define TEST_SUITE_MPS_READER |
| 18 | |
| 19 | /* End of compile-time configuration. */ |
| 20 | |
| 21 | /* END_HEADER */ |
| 22 | |
| 23 | /* BEGIN_CASE depends_on:TEST_SUITE_MPS_READER */ |
| 24 | void mbedtls_mps_reader_no_pausing_single_step_single_round( int with_acc ) |
| 25 | { |
| 26 | /* This test exercises the most basic use of the MPS reader: |
| 27 | * - The 'producing' layer provides a buffer |
| 28 | * - The 'consuming' layer fetches it in a single go. |
| 29 | * - After processing, the consuming layer commit the data |
| 30 | * and returns back to the producing layer. |
| 31 | * |
| 32 | * Parameters: |
| 33 | * - with_acc: 0 if the reader should be initialized without accumulator. |
| 34 | * 1 if the reader should be initialized with accumulator. |
| 35 | * |
| 36 | * Whether the accumulator is present or not should not matter, |
| 37 | * since the consumer's request can be fulfilled from the data |
| 38 | * that the producer has provided. |
| 39 | */ |
| 40 | unsigned char bufA[100]; |
| 41 | unsigned char acc[10]; |
| 42 | unsigned char *tmp; |
| 43 | mbedtls_reader rd; |
| 44 | for( int i=0; (unsigned) i < sizeof( bufA ); i++ ) |
| 45 | bufA[i] = (unsigned char) i; |
| 46 | |
| 47 | /* Preparation (lower layer) */ |
| 48 | if( with_acc == 0 ) |
| 49 | mbedtls_reader_init( &rd, NULL, 0 ); |
| 50 | else |
| 51 | mbedtls_reader_init( &rd, acc, sizeof( acc ) ); |
| 52 | TEST_ASSERT( mbedtls_reader_feed( &rd, bufA, sizeof( bufA ) ) == 0 ); |
| 53 | /* Consumption (upper layer) */ |
| 54 | /* Consume exactly what's available */ |
| 55 | TEST_ASSERT( mbedtls_reader_get( &rd, 100, &tmp, NULL ) == 0 ); |
| 56 | ASSERT_COMPARE( tmp, 100, bufA, 100 ); |
| 57 | TEST_ASSERT( mbedtls_reader_commit( &rd ) == 0 ); |
| 58 | /* Wrapup (lower layer) */ |
| 59 | TEST_ASSERT( mbedtls_reader_reclaim( &rd, NULL ) == 0 ); |
| 60 | mbedtls_reader_free( &rd ); |
| 61 | } |
| 62 | /* END_CASE */ |