MPS Reader Tests: Test feed() of NULL buffer

Signed-off-by: Hanno Becker <hanno.becker@arm.com>
This commit is contained in:
Hanno Becker 2021-01-12 09:40:05 +00:00
parent 223b72e40e
commit 2b8bad3e80
2 changed files with 41 additions and 0 deletions

View File

@ -117,3 +117,6 @@ mbedtls_reader_inconsistent_usage:7
MPS Reader: Pausing, inconsistent continuation, #8
mbedtls_reader_inconsistent_usage:8
MPS Reader: Feed with invalid buffer (NULL)
mbedtls_mps_reader_feed_empty:0

View File

@ -1059,3 +1059,41 @@ void mbedtls_reader_inconsistent_usage( int option )
mbedtls_reader_free( &rd );
}
/* END_CASE */
/* BEGIN_CASE depends_on:TEST_SUITE_MPS_READER */
void mbedtls_mps_reader_feed_empty( int option )
{
/* This test exercises the behaviour of the reader when it is
* fed a NULL buffer. */
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 );
switch( option )
{
case 0: /* NULL buffer */
TEST_ASSERT( mbedtls_reader_feed( &rd, NULL, sizeof( buf ) ) ==
MBEDTLS_ERR_MPS_READER_INVALID_ARG );
break;
default:
TEST_ASSERT( 0 );
break;
}
/* Subsequent feed-calls should still succeed. */
TEST_ASSERT( mbedtls_reader_feed( &rd, buf, sizeof( buf ) ) == 0 );
/* Consumption (upper layer) */
TEST_ASSERT( mbedtls_reader_get( &rd, 100, &tmp, NULL ) == 0 );
ASSERT_COMPARE( tmp, 100, buf, 100 );
TEST_ASSERT( mbedtls_reader_commit( &rd ) == 0 );
/* Wrapup */
TEST_ASSERT( mbedtls_reader_reclaim( &rd, NULL ) == 0 );
mbedtls_reader_free( &rd );
}
/* END_CASE */