MPS Reader Tests: Accumulator too small
Signed-off-by: Hanno Becker <hanno.becker@arm.com>
diff --git a/tests/suites/test_suite_mps.data b/tests/suites/test_suite_mps.data
index e9bc43d..b7333a3 100644
--- a/tests/suites/test_suite_mps.data
+++ b/tests/suites/test_suite_mps.data
@@ -24,3 +24,6 @@
MPS Reader: Pausing needed but disabled
mbedtls_mps_reader_pausing_needed_disabled:
+
+MPS Reader: Pausing needed + enabled, but buffer too small
+mbedtls_mps_reader_pausing_needed_buffer_too_small:
diff --git a/tests/suites/test_suite_mps.function b/tests/suites/test_suite_mps.function
index aeaad27..f5bb95b 100644
--- a/tests/suites/test_suite_mps.function
+++ b/tests/suites/test_suite_mps.function
@@ -236,3 +236,36 @@
mbedtls_reader_free( &rd );
}
/* END_CASE */
+
+/* BEGIN_CASE depends_on:TEST_SUITE_MPS_READER */
+void mbedtls_mps_reader_pausing_needed_buffer_too_small()
+{
+ /* This test exercises the behaviour of the MPS reader with accumulator
+ * in the situation where a read requests goes beyond the bounds of the
+ * current read buffer, _and_ the reader's accumulator is too small to
+ * hold the requested amount of data.
+ *
+ * In this case, we expect the reader to fail. */
+
+ unsigned char buf[100];
+ unsigned char acc[10];
+ 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, acc, sizeof( acc ) );
+ 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, 100, &tmp, NULL ) ==
+ MBEDTLS_ERR_MPS_READER_OUT_OF_DATA );
+ /* Wrapup (lower layer) */
+ TEST_ASSERT( mbedtls_reader_reclaim( &rd, NULL ) ==
+ MBEDTLS_ERR_MPS_READER_ACCUMULATOR_TOO_SMALL );
+ mbedtls_reader_free( &rd );
+}
+/* END_CASE */