From 2d1b17a55ea00130283dd65cec9f34d6d81b642f Mon Sep 17 00:00:00 2001 From: Artur Kloniecki Date: Mon, 10 Aug 2020 10:57:50 +0200 Subject: [PATCH] test: buffer: read and write to buffer byte by byte. Currently buffer is filled by memcpy_s and verified by memcmp, which would require more UT maintenance during upcoming buffer changes. With this change, usage of the buffer better reflects real-life usage. Signed-off-by: Artur Kloniecki --- test/cmocka/src/audio/buffer/buffer_wrap.c | 31 ++++++++++++++++------ 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/test/cmocka/src/audio/buffer/buffer_wrap.c b/test/cmocka/src/audio/buffer/buffer_wrap.c index 295278b1b..13ab76916 100644 --- a/test/cmocka/src/audio/buffer/buffer_wrap.c +++ b/test/cmocka/src/audio/buffer/buffer_wrap.c @@ -33,17 +33,26 @@ static void test_audio_buffer_write_fill_10_bytes_and_write_5(void **state) uint8_t bytes[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; - memcpy_s(buf->stream.w_ptr, test_buf_desc.size, &bytes, 10); - comp_update_buffer_produce(buf, 10); + int i; + uint8_t *ptr; - assert_int_equal(audio_stream_get_avail_bytes(&buf->stream), 10); + for (i = 0; i < ARRAY_SIZE(bytes); i++) { + ptr = audio_stream_write_frag(&buf->stream, i, sizeof(uint8_t)); + *ptr = bytes[i]; + } + comp_update_buffer_produce(buf, sizeof(bytes)); + + assert_int_equal(audio_stream_get_avail_bytes(&buf->stream), sizeof(bytes)); assert_int_equal(audio_stream_get_free_bytes(&buf->stream), 0); assert_ptr_equal(buf->stream.w_ptr, buf->stream.r_ptr); uint8_t more_bytes[5] = {10, 11, 12, 13, 14}; - memcpy_s(buf->stream.w_ptr, test_buf_desc.size, &more_bytes, 5); - comp_update_buffer_produce(buf, 5); + for (i = 0; i < ARRAY_SIZE(more_bytes); i++) { + ptr = audio_stream_write_frag(&buf->stream, i, sizeof(uint8_t)); + *ptr = more_bytes[i]; + } + comp_update_buffer_produce(buf, sizeof(more_bytes)); uint8_t ref_1[5] = {5, 6, 7, 8, 9}; uint8_t ref_2[5] = {10, 11, 12, 13, 14}; @@ -51,9 +60,15 @@ static void test_audio_buffer_write_fill_10_bytes_and_write_5(void **state) assert_int_equal(audio_stream_get_avail_bytes(&buf->stream), 10); assert_int_equal(audio_stream_get_free_bytes(&buf->stream), 0); assert_ptr_equal(buf->stream.w_ptr, buf->stream.r_ptr); - assert_int_equal(memcmp(buf->stream.r_ptr, &ref_1, 5), 0); - comp_update_buffer_consume(buf, 5); - assert_int_equal(memcmp(buf->stream.r_ptr, &ref_2, 5), 0); + for (i = 0; i < ARRAY_SIZE(ref_1); i++) { + ptr = audio_stream_read_frag(&buf->stream, i, sizeof(uint8_t)); + assert_int_equal(*ptr, ref_1[i]); + } + comp_update_buffer_consume(buf, sizeof(ref_1)); + for (i = 0; i < ARRAY_SIZE(ref_2); i++) { + ptr = audio_stream_read_frag(&buf->stream, i, sizeof(uint8_t)); + assert_int_equal(*ptr, ref_2[i]); + } buffer_free(buf); }