From 0b5c313cdaff47b5180b30afd449ba7925169743 Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Sun, 30 Sep 2018 06:34:55 +0000 Subject: Enhanced tests on pipes, added check on reset state. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@12308 110e8d01-0319-4d1e-a829-52ad28d1bb01 --- test/oslib/configuration.xml | 133 ++++++++++++++++++++--- test/oslib/source/test/oslib_test_sequence_002.c | 119 ++++++++++++++++++-- 2 files changed, 229 insertions(+), 23 deletions(-) (limited to 'test') diff --git a/test/oslib/configuration.xml b/test/oslib/configuration.xml index 723f47727..643a68508 100644 --- a/test/oslib/configuration.xml +++ b/test/oslib/configuration.xml @@ -444,7 +444,9 @@ test_assert(msg1 == MSG_TIMEOUT, "wrong wake-up message");]]> CH_CFG_USE_PIPES - + +#define PIPE_SIZE 16 static uint8_t buffer[PIPE_SIZE]; static PIPE_DECL(pipe1, buffer, PIPE_SIZE); @@ -506,6 +508,43 @@ uint8_t buf[PIPE_SIZE]; msg = chPipeReadTimeout(&pipe1, buf, PIPE_SIZE, TIME_IMMEDIATE); test_assert(msg == PIPE_SIZE, "wrong size"); +test_assert((pipe1.rdptr == pipe1.buffer) && + (pipe1.wrptr == pipe1.buffer) && + (pipe1.cnt == 0), + "invalid pipe state"); +test_assert(memcmp(pipe_pattern, buf, PIPE_SIZE) == 0, "content mismatch");]]> + + + + + Small write. + + + + + + + + + + + Filling remaining space. + + + + + + - - + Small Read. + + + + + + + + + + + Reading remaining data. - + - - + Small Write. - + - - + Small Read. - + - - + Write wrapping buffer boundary. - + + + + + + Read wrapping buffer boundary. + + + + + + diff --git a/test/oslib/source/test/oslib_test_sequence_002.c b/test/oslib/source/test/oslib_test_sequence_002.c index 406b4f21d..55c706874 100644 --- a/test/oslib/source/test/oslib_test_sequence_002.c +++ b/test/oslib/source/test/oslib_test_sequence_002.c @@ -46,6 +46,8 @@ * Shared code. ****************************************************************************/ +#include + #define PIPE_SIZE 16 static uint8_t buffer[PIPE_SIZE]; @@ -58,7 +60,7 @@ static const uint8_t pipe_pattern[] = "0123456789ABCDEF"; ****************************************************************************/ /** - * @page oslib_test_002_001 [2.1] Loading and emptying a pipe, non blocking + * @page oslib_test_002_001 [2.1] Filling and emptying a pipe, non blocking * *

Description

* The pipe functionality is tested by loading and emptying it, all @@ -67,10 +69,14 @@ static const uint8_t pipe_pattern[] = "0123456789ABCDEF"; *

Test Steps

* - [2.1.1] Filling whole pipe. * - [2.1.2] Emptying pipe. - * - [2.1.3]. - * - [2.1.4]. - * - [2.1.5]. - * - [2.1.6]. + * - [2.1.3] Small write. + * - [2.1.4] Filling remaining space. + * - [2.1.5] Small Read. + * - [2.1.6] Reading remaining data. + * - [2.1.7] Small Write. + * - [2.1.8] Small Read. + * - [2.1.9] Write wrapping buffer boundary. + * - [2.1.10] Read wrapping buffer boundary. * . */ @@ -106,31 +112,124 @@ static void oslib_test_002_001_execute(void) { (pipe1.wrptr == pipe1.buffer) && (pipe1.cnt == 0), "invalid pipe state"); + test_assert(memcmp(pipe_pattern, buf, PIPE_SIZE) == 0, "content mismatch"); } - /* [2.1.3].*/ + /* [2.1.3] Small write.*/ test_set_step(3); { + msg_t msg; + + msg = chPipeWriteTimeout(&pipe1, pipe_pattern, 4, TIME_IMMEDIATE); + test_assert(msg == 4, "wrong size"); + test_assert((pipe1.rdptr != pipe1.wrptr) && + (pipe1.rdptr == pipe1.buffer) && + (pipe1.cnt == 4), + "invalid pipe state"); } - /* [2.1.4].*/ + /* [2.1.4] Filling remaining space.*/ test_set_step(4); { + msg_t msg; + + msg = chPipeWriteTimeout(&pipe1, pipe_pattern, PIPE_SIZE - 4, TIME_IMMEDIATE); + test_assert(msg == PIPE_SIZE - 4, "wrong size"); + test_assert((pipe1.rdptr == pipe1.buffer) && + (pipe1.wrptr == pipe1.buffer) && + (pipe1.cnt == PIPE_SIZE), + "invalid pipe state"); } - /* [2.1.5].*/ + /* [2.1.5] Small Read.*/ test_set_step(5); { + msg_t msg; + uint8_t buf[PIPE_SIZE]; + + msg = chPipeReadTimeout(&pipe1, buf, 4, TIME_IMMEDIATE); + test_assert(msg == 4, "wrong size"); + test_assert((pipe1.rdptr != pipe1.buffer) && + (pipe1.wrptr == pipe1.buffer) && + (pipe1.cnt == PIPE_SIZE - 4), + "invalid pipe state"); + test_assert(memcmp(pipe_pattern, buf, 4) == 0, "content mismatch"); } - /* [2.1.6].*/ + /* [2.1.6] Reading remaining data.*/ test_set_step(6); { + msg_t msg; + uint8_t buf[PIPE_SIZE]; + + msg = chPipeReadTimeout(&pipe1, buf, PIPE_SIZE - 4, TIME_IMMEDIATE); + test_assert(msg == PIPE_SIZE - 4, "wrong size"); + test_assert((pipe1.rdptr == pipe1.buffer) && + (pipe1.wrptr == pipe1.buffer) && + (pipe1.cnt == 0), + "invalid pipe state"); + test_assert(memcmp(pipe_pattern, buf, PIPE_SIZE - 4) == 0, "content mismatch"); + } + + /* [2.1.7] Small Write.*/ + test_set_step(7); + { + msg_t msg; + + msg = chPipeWriteTimeout(&pipe1, pipe_pattern, 5, TIME_IMMEDIATE); + test_assert(msg == 5, "wrong size"); + test_assert((pipe1.rdptr != pipe1.wrptr) && + (pipe1.rdptr == pipe1.buffer) && + (pipe1.cnt == 5), + "invalid pipe state"); + } + + /* [2.1.8] Small Read.*/ + test_set_step(8); + { + msg_t msg; + uint8_t buf[PIPE_SIZE]; + + msg = chPipeReadTimeout(&pipe1, buf, 5, TIME_IMMEDIATE); + test_assert(msg == 5, "wrong size"); + test_assert((pipe1.rdptr == pipe1.wrptr) && + (pipe1.wrptr != pipe1.buffer) && + (pipe1.cnt == 0), + "invalid pipe state"); + test_assert(memcmp(pipe_pattern, buf, 5) == 0, "content mismatch"); + } + + /* [2.1.9] Write wrapping buffer boundary.*/ + test_set_step(9); + { + msg_t msg; + + msg = chPipeWriteTimeout(&pipe1, pipe_pattern, PIPE_SIZE, TIME_IMMEDIATE); + test_assert(msg == PIPE_SIZE, "wrong size"); + test_assert((pipe1.rdptr == pipe1.wrptr) && + (pipe1.wrptr != pipe1.buffer) && + (pipe1.cnt == PIPE_SIZE), + "invalid pipe state"); + } + + /* [2.1.10] Read wrapping buffer boundary.*/ + test_set_step(10); + { + msg_t msg; + uint8_t buf[PIPE_SIZE]; + + msg = chPipeReadTimeout(&pipe1, buf, PIPE_SIZE, TIME_IMMEDIATE); + test_assert(msg == PIPE_SIZE, "wrong size"); + test_assert((pipe1.rdptr == pipe1.wrptr) && + (pipe1.wrptr != pipe1.buffer) && + (pipe1.cnt == 0), + "invalid pipe state"); + test_assert(memcmp(pipe_pattern, buf, PIPE_SIZE) == 0, "content mismatch"); } } static const testcase_t oslib_test_002_001 = { - "Loading and emptying a pipe, non blocking", + "Filling and emptying a pipe, non blocking", oslib_test_002_001_setup, NULL, oslib_test_002_001_execute -- cgit v1.2.3