mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-27 04:54:15 +01:00
MPS Reader Tests: Add test for feed-{get,get,...}-commit-reclaim
Signed-off-by: Hanno Becker <hanno.becker@arm.com>
This commit is contained in:
parent
0e4edfc083
commit
dbd8a96487
@ -9,3 +9,9 @@ mbedtls_mps_reader_no_pausing_single_step_multiple_rounds:0
|
||||
|
||||
MPS Reader: Single step, multiple rounds, pausing enabled but unused
|
||||
mbedtls_mps_reader_no_pausing_single_step_multiple_rounds:1
|
||||
|
||||
MPS Reader: Multiple steps, single round, pausing disabled
|
||||
mbedtls_mps_reader_no_pausing_multiple_steps_single_round:0
|
||||
|
||||
MPS Reader: Multiple steps, single round, pausing enabled but unused
|
||||
mbedtls_mps_reader_no_pausing_multiple_steps_single_round:1
|
||||
|
@ -111,3 +111,52 @@ void mbedtls_mps_reader_no_pausing_single_step_multiple_rounds( int with_acc )
|
||||
mbedtls_reader_free( &rd );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:TEST_SUITE_MPS_READER */
|
||||
void mbedtls_mps_reader_no_pausing_multiple_steps_single_round( int with_acc )
|
||||
{
|
||||
/* This test exercises one round of the following:
|
||||
* - The 'producing' layer provides a buffer
|
||||
* - The 'consuming' layer fetches it in multiple calls
|
||||
* to `mbedtls_reader_get()`, without comitting in between.
|
||||
* - After processing, the consuming layer commit the data
|
||||
* and returns back to the producing layer.
|
||||
*
|
||||
* Parameters:
|
||||
* - with_acc: 0 if the reader should be initialized without accumulator.
|
||||
* 1 if the reader should be initialized with accumulator.
|
||||
*
|
||||
* Whether the accumulator is present or not should not matter,
|
||||
* since the consumer's request can be fulfilled from the data
|
||||
* that the producer has provided.
|
||||
*/
|
||||
|
||||
/* Lower layer provides data that the upper layer fully consumes
|
||||
* through multiple `get` calls. */
|
||||
unsigned char buf[100];
|
||||
unsigned char acc[10];
|
||||
unsigned char *tmp;
|
||||
mbedtls_mps_size_t tmp_len;
|
||||
mbedtls_reader rd;
|
||||
for( int i=0; (unsigned) i < sizeof( buf ); i++ )
|
||||
buf[i] = (unsigned char) i;
|
||||
|
||||
/* Preparation (lower layer) */
|
||||
if( with_acc == 0 )
|
||||
mbedtls_reader_init( &rd, NULL, 0 );
|
||||
else
|
||||
mbedtls_reader_init( &rd, acc, sizeof( acc ) );
|
||||
TEST_ASSERT( mbedtls_reader_feed( &rd, buf, sizeof( buf ) ) == 0 );
|
||||
/* Consumption (upper layer) */
|
||||
TEST_ASSERT( mbedtls_reader_get( &rd, 10, &tmp, NULL ) == 0 );
|
||||
ASSERT_COMPARE( tmp, 10, buf, 10 );
|
||||
TEST_ASSERT( mbedtls_reader_get( &rd, 70, &tmp, NULL ) == 0 );
|
||||
ASSERT_COMPARE( tmp, 70, buf + 10, 70 );
|
||||
TEST_ASSERT( mbedtls_reader_get( &rd, 30, &tmp, &tmp_len ) == 0 );
|
||||
ASSERT_COMPARE( tmp, tmp_len, buf + 80, 20 );
|
||||
TEST_ASSERT( mbedtls_reader_commit( &rd ) == 0 );
|
||||
/* Wrapup (lower layer) */
|
||||
TEST_ASSERT( mbedtls_reader_reclaim( &rd, NULL ) == 0 );
|
||||
mbedtls_reader_free( &rd );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
Loading…
Reference in New Issue
Block a user