summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDinh Cong Toan <toan.dinhcong@vn.bosch.com>2021-06-18 13:10:49 +0700
committerSaya Sugiura <39760799+ssugiura@users.noreply.github.com>2021-06-30 10:54:59 +0900
commit05e4ad2339a24bcf38663eca37a5292a4038d423 (patch)
tree64fda022db9a54d900ad5bba658a0640c8da0d74 /tests
parent8770cbb37583b2c4654e582874d604ee50d8f68d (diff)
downloadDLT-daemon-05e4ad2339a24bcf38663eca37a5292a4038d423.tar.gz
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 <toan.dinhcong@vn.bosch.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/gtest_dlt_common.cpp35
1 files changed, 31 insertions, 4 deletions
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)
{