MPS Reader Tests: Continue fetching after reclaim() was rejected

Signed-off-by: Hanno Becker <hanno.becker@arm.com>
This commit is contained in:
Hanno Becker 2021-01-12 08:43:58 +00:00
parent cb2a88ed38
commit e1f173c36f
2 changed files with 38 additions and 0 deletions

View File

@ -63,3 +63,6 @@ mbedtls_mps_reader_reclaim_data_left:1
MPS Reader: Reclaim with data remaining #2 MPS Reader: Reclaim with data remaining #2
mbedtls_mps_reader_reclaim_data_left:2 mbedtls_mps_reader_reclaim_data_left:2
MPS Reader: Reclaim with data remaining, continue fetching
mbedtls_mps_reader_reclaim_data_left_retry:

View File

@ -559,3 +559,38 @@ void mbedtls_mps_reader_reclaim_data_left( int option )
mbedtls_reader_free( &rd ); mbedtls_reader_free( &rd );
} }
/* END_CASE */ /* END_CASE */
/* BEGIN_CASE depends_on:TEST_SUITE_MPS_READER */
void mbedtls_mps_reader_reclaim_data_left_retry()
{
/* This test exercises the behaviour of the MPS reader when an attempt
* by the producer to reclaim the reader fails because of more data pending
* to be processed, and the consumer subsequently fetches more data. */
unsigned char buf[100];
unsigned char *tmp;
mbedtls_reader rd;
for( int i=0; (unsigned) i < sizeof( buf ); i++ )
buf[i] = (unsigned char) i;
/* Preparation (lower layer) */
mbedtls_reader_init( &rd, NULL, 0 );
TEST_ASSERT( mbedtls_reader_feed( &rd, buf, sizeof( buf ) ) == 0 );
/* Consumption (upper layer) */
TEST_ASSERT( mbedtls_reader_get( &rd, 50, &tmp, NULL ) == 0 );
ASSERT_COMPARE( tmp, 50, buf, 50 );
TEST_ASSERT( mbedtls_reader_commit( &rd ) == 0 );
TEST_ASSERT( mbedtls_reader_get( &rd, 50, &tmp, NULL ) == 0 );
ASSERT_COMPARE( tmp, 50, buf + 50, 50 );
/* Preparation */
TEST_ASSERT( mbedtls_reader_reclaim( &rd, NULL ) ==
MBEDTLS_ERR_MPS_READER_DATA_LEFT );
/* Consumption */
TEST_ASSERT( mbedtls_reader_get( &rd, 50, &tmp, NULL ) == 0 );
ASSERT_COMPARE( tmp, 50, buf + 50, 50 );
TEST_ASSERT( mbedtls_reader_commit( &rd ) == 0 );
/* Wrapup */
TEST_ASSERT( mbedtls_reader_reclaim( &rd, NULL ) == 0 );
mbedtls_reader_free( &rd );
}
/* END_CASE */