aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorGiovanni Di Sirio <gdisirio@gmail.com>2018-09-30 06:34:55 +0000
committerGiovanni Di Sirio <gdisirio@gmail.com>2018-09-30 06:34:55 +0000
commit0b5c313cdaff47b5180b30afd449ba7925169743 (patch)
tree70630b922d3f1f374fff303e1fba3196248f6598 /test
parent8fa2bcdad9edb41d01c9ccf1ebbbe135713bf9c0 (diff)
downloadChibiOS-0b5c313cdaff47b5180b30afd449ba7925169743.tar.gz
ChibiOS-0b5c313cdaff47b5180b30afd449ba7925169743.tar.bz2
ChibiOS-0b5c313cdaff47b5180b30afd449ba7925169743.zip
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
Diffstat (limited to 'test')
-rw-r--r--test/oslib/configuration.xml133
-rw-r--r--test/oslib/source/test/oslib_test_sequence_002.c119
2 files changed, 229 insertions, 23 deletions
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");]]></value>
<value>CH_CFG_USE_PIPES</value>
</condition>
<shared_code>
- <value><![CDATA[#define PIPE_SIZE 16
+ <value><![CDATA[#include <string.h>
+
+#define PIPE_SIZE 16
static uint8_t buffer[PIPE_SIZE];
static PIPE_DECL(pipe1, buffer, PIPE_SIZE);
@@ -508,56 +510,161 @@ 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");]]></value>
+ </code>
+ </step>
+ <step>
+ <description>
+ <value>Small write.</value>
+ </description>
+ <tags>
+ <value></value>
+ </tags>
+ <code>
+ <value><![CDATA[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");]]></value>
+ </code>
+ </step>
+ <step>
+ <description>
+ <value>Filling remaining space.</value>
+ </description>
+ <tags>
+ <value></value>
+ </tags>
+ <code>
+ <value><![CDATA[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");]]></value>
</code>
</step>
<step>
<description>
- <value>
- </value>
+ <value>Small Read.</value>
+ </description>
+ <tags>
+ <value></value>
+ </tags>
+ <code>
+ <value><![CDATA[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");]]></value>
+ </code>
+ </step>
+ <step>
+ <description>
+ <value>Reading remaining data.</value>
</description>
<tags>
<value></value>
</tags>
<code>
- <value><![CDATA[]]></value>
+ <value><![CDATA[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");]]></value>
</code>
</step>
<step>
<description>
- <value>
- </value>
+ <value>Small Write.</value>
</description>
<tags>
<value></value>
</tags>
<code>
- <value><![CDATA[]]></value>
+ <value><![CDATA[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");]]></value>
</code>
</step>
<step>
<description>
- <value>
- </value>
+ <value>Small Read.</value>
</description>
<tags>
<value></value>
</tags>
<code>
- <value><![CDATA[]]></value>
+ <value><![CDATA[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");]]></value>
</code>
</step>
<step>
<description>
- <value>
- </value>
+ <value>Write wrapping buffer boundary.</value>
</description>
<tags>
<value></value>
</tags>
<code>
- <value><![CDATA[]]></value>
+ <value><![CDATA[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");]]></value>
+ </code>
+ </step>
+ <step>
+ <description>
+ <value>Read wrapping buffer boundary.</value>
+ </description>
+ <tags>
+ <value></value>
+ </tags>
+ <code>
+ <value><![CDATA[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");]]></value>
</code>
</step>
</steps>
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 <string.h>
+
#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
*
* <h2>Description</h2>
* The pipe functionality is tested by loading and emptying it, all
@@ -67,10 +69,14 @@ static const uint8_t pipe_pattern[] = "0123456789ABCDEF";
* <h2>Test Steps</h2>
* - [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