From 05e4ad2339a24bcf38663eca37a5292a4038d423 Mon Sep 17 00:00:00 2001 From: Dinh Cong Toan Date: Fri, 18 Jun 2021 13:10:49 +0700 Subject: dlt_common: correct read/write position In dlt_buffer_read_block() and dlt_buffer_write_block(), read/write position should be updated in case these positions are equal to the size of ringbuffer. Adding boundary check in gtest_dlt_common.cpp Signed-off-by: Dinh Cong Toan --- tests/gtest_dlt_common.cpp | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/gtest_dlt_common.cpp b/tests/gtest_dlt_common.cpp index 9afb830..4e08d9a 100644 --- a/tests/gtest_dlt_common.cpp +++ b/tests/gtest_dlt_common.cpp @@ -1277,8 +1277,20 @@ TEST(t_dlt_buffer_write_block, normal) } TEST(t_dlt_buffer_write_block, abnormal) { - /* actual no abnormal test cases */ - /* because of void funktion and missing gtest tools for that */ + /* Boundary check of write position */ + DltBuffer buf; + const char *data = "data"; + int write = DLT_USER_RINGBUFFER_MIN_SIZE; + write -= sizeof(DltBufferHead); + int size = sizeof(data); + // when write = buf->size, it should not throw any warning + // and write should equal to size. + EXPECT_LE(DLT_RETURN_OK, + dlt_buffer_init_dynamic(&buf,DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, + DLT_USER_RINGBUFFER_STEP_SIZE)); + EXPECT_NO_THROW(dlt_buffer_write_block(&buf, &write, (unsigned char *)&data, size)); + EXPECT_EQ(size , write); + EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); } TEST(t_dlt_buffer_write_block, nullpointer) { @@ -1358,8 +1370,23 @@ TEST(t_dlt_buffer_read_block, normal) } TEST(t_dlt_buffer_read_block, abnormal) { - /* actual no abnormal test cases */ - /* because of void funktion and missing gtest tools for that */ + /* Boundary check of read position */ + DltBuffer buf; + /* Buffer to read data from DltBuffer */ + unsigned char *data_read; + data_read = (unsigned char *) calloc(1000, sizeof(char)); + int read = DLT_USER_RINGBUFFER_MIN_SIZE; + read -= sizeof(DltBufferHead); + int size = 1000; + // when read = buf->size, it should not throw any warning + // and read position should equal to size. + EXPECT_LE(DLT_RETURN_OK, + dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, + DLT_USER_RINGBUFFER_STEP_SIZE)); + EXPECT_NO_THROW(dlt_buffer_read_block(&buf, &read, data_read, size)); + EXPECT_EQ(size,read); + EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); + free(data_read); } TEST(t_dlt_buffer_read_block, nullpointer) { -- cgit v1.2.1