aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorGiovanni Di Sirio <gdisirio@gmail.com>2018-09-30 10:36:00 +0000
committerGiovanni Di Sirio <gdisirio@gmail.com>2018-09-30 10:36:00 +0000
commit2f2d81c3994fdbc67066260d6245e32c5d315f97 (patch)
tree6e16f013c1f6e3d9e2c29affdb3c9cf6f7c8b864 /test
parent0b5c313cdaff47b5180b30afd449ba7925169743 (diff)
downloadChibiOS-2f2d81c3994fdbc67066260d6245e32c5d315f97.tar.gz
ChibiOS-2f2d81c3994fdbc67066260d6245e32c5d315f97.tar.bz2
ChibiOS-2f2d81c3994fdbc67066260d6245e32c5d315f97.zip
Pipes test code complete.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@12309 110e8d01-0319-4d1e-a829-52ad28d1bb01
Diffstat (limited to 'test')
-rw-r--r--test/oslib/configuration.xml145
-rw-r--r--test/oslib/source/test/oslib_test_sequence_002.c176
2 files changed, 287 insertions, 34 deletions
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";]]></value>
<cases>
<case>
<brief>
- <value>Filling and emptying a pipe, non blocking.</value>
+ <value>Pipes normal API, non-blocking tests.</value>
</brief>
<description>
<value>The pipe functionality is tested by loading and emptying it, all conditions are tested.</value>
@@ -473,12 +473,91 @@ static const uint8_t pipe_pattern[] = "0123456789ABCDEF";]]></value>
<value/>
</teardown_code>
<local_variables>
- <value><![CDATA[unsigned i;]]></value>
+ <value></value>
</local_variables>
</various_code>
<steps>
<step>
<description>
+ <value></value>
+ </description>
+ <tags>
+ <value></value>
+ </tags>
+ <code>
+ <value><![CDATA[]]></value>
+ </code>
+ </step>
+ <step>
+ <description>
+ <value>Resetting pipe.</value>
+ </description>
+ <tags>
+ <value></value>
+ </tags>
+ <code>
+ <value><![CDATA[chPipeReset(&pipe1);
+
+test_assert((pipe1.rdptr == pipe1.buffer) &&
+ (pipe1.wrptr == pipe1.buffer) &&
+ (pipe1.cnt == 0),
+ "invalid pipe state");]]></value>
+ </code>
+ </step>
+ <step>
+ <description>
+ <value>Writing data, must fail.</value>
+ </description>
+ <tags>
+ <value></value>
+ </tags>
+ <code>
+ <value><![CDATA[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");]]></value>
+ </code>
+ </step>
+ <step>
+ <description>
+ <value>Reading data, must fail.</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 == MSG_RESET, "not reset");
+test_assert((pipe1.rdptr == pipe1.buffer) &&
+ (pipe1.wrptr == pipe1.buffer) &&
+ (pipe1.cnt == 0),
+ "invalid pipe state");]]></value>
+ </code>
+ </step>
+ <step>
+ <description>
+ <value>Reactivating pipe.</value>
+ </description>
+ <tags>
+ <value></value>
+ </tags>
+ <code>
+ <value><![CDATA[chPipeResume(&pipe1);
+test_assert((pipe1.rdptr == pipe1.buffer) &&
+ (pipe1.wrptr == pipe1.buffer) &&
+ (pipe1.cnt == 0),
+ "invalid pipe state");]]></value>
+ </code>
+ </step>
+ <step>
+ <description>
<value>Filling whole pipe.</value>
</description>
<tags>
@@ -669,6 +748,68 @@ test_assert(memcmp(pipe_pattern, buf, PIPE_SIZE) == 0, "content mismatch");]]></
</step>
</steps>
</case>
+ <case>
+ <brief>
+ <value>Pipe timeouts.</value>
+ </brief>
+ <description>
+ <value>The pipe API is tested for timeouts.</value>
+ </description>
+ <condition>
+ <value>
+ </value>
+ </condition>
+ <various_code>
+ <setup_code>
+ <value><![CDATA[chPipeObjectInit(&pipe1, buffer, PIPE_SIZE / 2);]]></value>
+ </setup_code>
+ <teardown_code>
+ <value/>
+ </teardown_code>
+ <local_variables>
+ <value></value>
+ </local_variables>
+ </various_code>
+ <steps>
+ <step>
+ <description>
+ <value>Reading while pipe is empty.</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 == 0, "wrong size");
+test_assert((pipe1.rdptr == pipe1.buffer) &&
+ (pipe1.wrptr == pipe1.buffer) &&
+ (pipe1.cnt == 0),
+ "invalid pipe state");]]></value>
+ </code>
+ </step>
+ <step>
+ <description>
+ <value>Writing a string larger than pipe buffer.</value>
+ </description>
+ <tags>
+ <value></value>
+ </tags>
+ <code>
+ <value><![CDATA[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");]]></value>
+ </code>
+ </step>
+ </steps>
+ </case>
</cases>
</sequence>
<sequence>
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 @@
*
* <h2>Test Cases</h2>
* - @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
*
* <h2>Description</h2>
* The pipe functionality is tested by loading and emptying it, all
* conditions are tested.
*
* <h2>Test Steps</h2>
- * - [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,11 +91,63 @@ 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;
msg = chPipeWriteTimeout(&pipe1, pipe_pattern, PIPE_SIZE, TIME_IMMEDIATE);
@@ -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
+ *
+ * <h2>Description</h2>
+ * The pipe API is tested for timeouts.
+ *
+ * <h2>Test Steps</h2>
+ * - [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
};