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 <arturx.kloniecki@linux.intel.com>
This commit is contained in:
Artur Kloniecki 2020-08-10 10:57:50 +02:00 committed by Janusz Jankowski
parent de514ca0ff
commit 2d1b17a55e
1 changed files with 23 additions and 8 deletions

View File

@ -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);
}