From 2f2d81c3994fdbc67066260d6245e32c5d315f97 Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Sun, 30 Sep 2018 10:36:00 +0000 Subject: Pipes test code complete. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@12309 110e8d01-0319-4d1e-a829-52ad28d1bb01 --- test/oslib/configuration.xml | 145 ++++++++++++++++++- test/oslib/source/test/oslib_test_sequence_002.c | 176 ++++++++++++++++++----- 2 files changed, 287 insertions(+), 34 deletions(-) (limited to 'test') diff --git a/test/oslib/configuration.xml b/test/oslib/configuration.xml index 643a68508..a828b51d0 100644 --- a/test/oslib/configuration.xml +++ b/test/oslib/configuration.xml @@ -456,7 +456,7 @@ static const uint8_t pipe_pattern[] = "0123456789ABCDEF";]]> - Filling and emptying a pipe, non blocking. + Pipes normal API, non-blocking tests. The pipe functionality is tested by loading and emptying it, all conditions are tested. @@ -473,10 +473,89 @@ static const uint8_t pipe_pattern[] = "0123456789ABCDEF";]]> - + + + + + + + + + + + + + + + Resetting pipe. + + + + + + + + + + + Writing data, must fail. + + + + + + + + + + + Reading data, must fail. + + + + + + + + + + + Reactivating pipe. + + + + + + + + Filling whole pipe. @@ -669,6 +748,68 @@ test_assert(memcmp(pipe_pattern, buf, PIPE_SIZE) == 0, "content mismatch");]]> + + + Pipe timeouts. + + + The pipe API is tested for timeouts. + + + + + + + + + + + + + + + + + + + + Reading while pipe is empty. + + + + + + + + + + + Writing a string larger than pipe buffer. + + + + + + + + + + diff --git a/test/oslib/source/test/oslib_test_sequence_002.c b/test/oslib/source/test/oslib_test_sequence_002.c index 55c706874..3f72a5055 100644 --- a/test/oslib/source/test/oslib_test_sequence_002.c +++ b/test/oslib/source/test/oslib_test_sequence_002.c @@ -37,6 +37,7 @@ * *

Test Cases

* - @subpage oslib_test_002_001 + * - @subpage oslib_test_002_002 * . */ @@ -60,23 +61,28 @@ static const uint8_t pipe_pattern[] = "0123456789ABCDEF"; ****************************************************************************/ /** - * @page oslib_test_002_001 [2.1] Filling and emptying a pipe, non blocking + * @page oslib_test_002_001 [2.1] Pipes normal API, non-blocking tests * *

Description

* The pipe functionality is tested by loading and emptying it, all * conditions are tested. * *

Test Steps

- * - [2.1.1] Filling whole pipe. - * - [2.1.2] Emptying pipe. - * - [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. + * - [2.1.1]. + * - [2.1.2] Resetting pipe. + * - [2.1.3] Writing data, must fail. + * - [2.1.4] Reading data, must fail. + * - [2.1.5] Reactivating pipe. + * - [2.1.6] Filling whole pipe. + * - [2.1.7] Emptying pipe. + * - [2.1.8] Small write. + * - [2.1.9] Filling remaining space. + * - [2.1.10] Small Read. + * - [2.1.11] Reading remaining data. + * - [2.1.12] Small Write. + * - [2.1.13] Small Read. + * - [2.1.14] Write wrapping buffer boundary. + * - [2.1.15] Read wrapping buffer boundary. * . */ @@ -85,10 +91,62 @@ static void oslib_test_002_001_setup(void) { } static void oslib_test_002_001_execute(void) { - unsigned i; - /* [2.1.1] Filling whole pipe.*/ + /* [2.1.1].*/ test_set_step(1); + { + } + + /* [2.1.2] Resetting pipe.*/ + test_set_step(2); + { + chPipeReset(&pipe1); + + test_assert((pipe1.rdptr == pipe1.buffer) && + (pipe1.wrptr == pipe1.buffer) && + (pipe1.cnt == 0), + "invalid pipe state"); + } + + /* [2.1.3] Writing data, must fail.*/ + test_set_step(3); + { + msg_t msg; + + msg = chPipeWriteTimeout(&pipe1, pipe_pattern, PIPE_SIZE, TIME_IMMEDIATE); + test_assert(msg == MSG_RESET, "not reset"); + test_assert((pipe1.rdptr == pipe1.buffer) && + (pipe1.wrptr == pipe1.buffer) && + (pipe1.cnt == 0), + "invalid pipe state"); + } + + /* [2.1.4] Reading data, must fail.*/ + test_set_step(4); + { + msg_t msg; + uint8_t buf[PIPE_SIZE]; + + msg = chPipeReadTimeout(&pipe1, buf, PIPE_SIZE, TIME_IMMEDIATE); + test_assert(msg == MSG_RESET, "not reset"); + test_assert((pipe1.rdptr == pipe1.buffer) && + (pipe1.wrptr == pipe1.buffer) && + (pipe1.cnt == 0), + "invalid pipe state"); + } + + /* [2.1.5] Reactivating pipe.*/ + test_set_step(5); + { + chPipeResume(&pipe1); + test_assert((pipe1.rdptr == pipe1.buffer) && + (pipe1.wrptr == pipe1.buffer) && + (pipe1.cnt == 0), + "invalid pipe state"); + } + + /* [2.1.6] Filling whole pipe.*/ + test_set_step(6); { msg_t msg; @@ -100,8 +158,8 @@ static void oslib_test_002_001_execute(void) { "invalid pipe state"); } - /* [2.1.2] Emptying pipe.*/ - test_set_step(2); + /* [2.1.7] Emptying pipe.*/ + test_set_step(7); { msg_t msg; uint8_t buf[PIPE_SIZE]; @@ -115,8 +173,8 @@ static void oslib_test_002_001_execute(void) { test_assert(memcmp(pipe_pattern, buf, PIPE_SIZE) == 0, "content mismatch"); } - /* [2.1.3] Small write.*/ - test_set_step(3); + /* [2.1.8] Small write.*/ + test_set_step(8); { msg_t msg; @@ -128,8 +186,8 @@ static void oslib_test_002_001_execute(void) { "invalid pipe state"); } - /* [2.1.4] Filling remaining space.*/ - test_set_step(4); + /* [2.1.9] Filling remaining space.*/ + test_set_step(9); { msg_t msg; @@ -141,8 +199,8 @@ static void oslib_test_002_001_execute(void) { "invalid pipe state"); } - /* [2.1.5] Small Read.*/ - test_set_step(5); + /* [2.1.10] Small Read.*/ + test_set_step(10); { msg_t msg; uint8_t buf[PIPE_SIZE]; @@ -156,8 +214,8 @@ static void oslib_test_002_001_execute(void) { test_assert(memcmp(pipe_pattern, buf, 4) == 0, "content mismatch"); } - /* [2.1.6] Reading remaining data.*/ - test_set_step(6); + /* [2.1.11] Reading remaining data.*/ + test_set_step(11); { msg_t msg; uint8_t buf[PIPE_SIZE]; @@ -171,8 +229,8 @@ static void oslib_test_002_001_execute(void) { test_assert(memcmp(pipe_pattern, buf, PIPE_SIZE - 4) == 0, "content mismatch"); } - /* [2.1.7] Small Write.*/ - test_set_step(7); + /* [2.1.12] Small Write.*/ + test_set_step(12); { msg_t msg; @@ -184,8 +242,8 @@ static void oslib_test_002_001_execute(void) { "invalid pipe state"); } - /* [2.1.8] Small Read.*/ - test_set_step(8); + /* [2.1.13] Small Read.*/ + test_set_step(13); { msg_t msg; uint8_t buf[PIPE_SIZE]; @@ -199,8 +257,8 @@ static void oslib_test_002_001_execute(void) { test_assert(memcmp(pipe_pattern, buf, 5) == 0, "content mismatch"); } - /* [2.1.9] Write wrapping buffer boundary.*/ - test_set_step(9); + /* [2.1.14] Write wrapping buffer boundary.*/ + test_set_step(14); { msg_t msg; @@ -212,8 +270,8 @@ static void oslib_test_002_001_execute(void) { "invalid pipe state"); } - /* [2.1.10] Read wrapping buffer boundary.*/ - test_set_step(10); + /* [2.1.15] Read wrapping buffer boundary.*/ + test_set_step(15); { msg_t msg; uint8_t buf[PIPE_SIZE]; @@ -229,12 +287,65 @@ static void oslib_test_002_001_execute(void) { } static const testcase_t oslib_test_002_001 = { - "Filling and emptying a pipe, non blocking", + "Pipes normal API, non-blocking tests", oslib_test_002_001_setup, NULL, oslib_test_002_001_execute }; +/** + * @page oslib_test_002_002 [2.2] Pipe timeouts + * + *

Description

+ * The pipe API is tested for timeouts. + * + *

Test Steps

+ * - [2.2.1] Reading while pipe is empty. + * - [2.2.2] Writing a string larger than pipe buffer. + * . + */ + +static void oslib_test_002_002_setup(void) { + chPipeObjectInit(&pipe1, buffer, PIPE_SIZE / 2); +} + +static void oslib_test_002_002_execute(void) { + + /* [2.2.1] Reading while pipe is empty.*/ + test_set_step(1); + { + msg_t msg; + uint8_t buf[PIPE_SIZE]; + + msg = chPipeReadTimeout(&pipe1, buf, PIPE_SIZE, TIME_IMMEDIATE); + test_assert(msg == 0, "wrong size"); + test_assert((pipe1.rdptr == pipe1.buffer) && + (pipe1.wrptr == pipe1.buffer) && + (pipe1.cnt == 0), + "invalid pipe state"); + } + + /* [2.2.2] Writing a string larger than pipe buffer.*/ + test_set_step(2); + { + msg_t msg; + + msg = chPipeWriteTimeout(&pipe1, pipe_pattern, PIPE_SIZE, TIME_IMMEDIATE); + test_assert(msg == PIPE_SIZE / 2, "wrong size"); + test_assert((pipe1.rdptr == pipe1.wrptr) && + (pipe1.wrptr == pipe1.buffer) && + (pipe1.cnt == PIPE_SIZE / 2), + "invalid pipe state"); + } +} + +static const testcase_t oslib_test_002_002 = { + "Pipe timeouts", + oslib_test_002_002_setup, + NULL, + oslib_test_002_002_execute +}; + /**************************************************************************** * Exported data. ****************************************************************************/ @@ -244,6 +355,7 @@ static const testcase_t oslib_test_002_001 = { */ const testcase_t * const oslib_test_sequence_002_array[] = { &oslib_test_002_001, + &oslib_test_002_002, NULL }; -- cgit v1.2.3