aboutsummaryrefslogtreecommitdiffstats
path: root/test/nil
diff options
context:
space:
mode:
Diffstat (limited to 'test/nil')
-rw-r--r--test/nil/test_root.c27
-rw-r--r--test/nil/test_root.h3
-rw-r--r--test/nil/test_sequence_002.c135
3 files changed, 141 insertions, 24 deletions
diff --git a/test/nil/test_root.c b/test/nil/test_root.c
index fb835b88d..cd3c8b681 100644
--- a/test/nil/test_root.c
+++ b/test/nil/test_root.c
@@ -43,4 +43,31 @@ const testcase_t * const *test_suite[] = {
/* Shared code. */
/*===========================================================================*/
+semaphore_t gsem1, gsem2;
+
+/*
+ * Support thread.
+ */
+THD_WORKING_AREA(wa_test_support, 128);
+THD_FUNCTION(test_support, arg) {
+
+ (void)arg;
+
+ /* Initializing global resources.*/
+ chSemObjectInit(&gsem1, 0);
+ chSemObjectInit(&gsem2, 0);
+
+ /* Waiting for button push and activation of the test suite.*/
+ while (true) {
+ chSysLock();
+ if (chSemGetCounterI(&gsem1) < 0)
+ chSemSignalI(&gsem1);
+ chSemResetI(&gsem2, 0);
+ chSchRescheduleS();
+ chSysUnlock();
+
+ chThdSleepMilliseconds(500);
+ }
+}
+
/** @} */
diff --git a/test/nil/test_root.h b/test/nil/test_root.h
index 0d000c415..51a100922 100644
--- a/test/nil/test_root.h
+++ b/test/nil/test_root.h
@@ -47,6 +47,9 @@ extern const testcase_t * const *test_suite[];
#ifdef __cplusplus
extern "C" {
#endif
+ extern semaphore_t gsem1, gsem2;
+ extern THD_WORKING_AREA(wa_test_support, 128);
+ THD_FUNCTION(test_support, arg);
#ifdef __cplusplus
}
#endif
diff --git a/test/nil/test_sequence_002.c b/test/nil/test_sequence_002.c
index cc9f03b08..9fa425c18 100644
--- a/test/nil/test_sequence_002.c
+++ b/test/nil/test_sequence_002.c
@@ -19,12 +19,13 @@
#include "test_root.h"
/**
- * @page test_sequence_002 Semaphores functionality
+ * @page test_sequence_002 Synchronization primitives
*
* File: @ref test_sequence_002.c
*
* <h2>Description</h2>
- * This sequence tests the ChibiOS/NIL functionalities related to semaphores.
+ * This sequence tests the ChibiOS/NIL functionalities related to
+ * threads synchronization.
*
* <h2>Test Cases</h2>
* - @subpage test_002_001
@@ -54,12 +55,12 @@ static semaphore_t sem1;
* None.
*
* <h2>Test Steps</h2>
- * - The function chSemWait() is invoked, the Semaphore counter is tested
- * for correct value after the call.
- * - The function chSemSignal() is invoked, the Semaphore counter is tested
- * for correct value after the call.
- * - The function chSemReset() is invoked, the Semaphore counter is tested
- * for correct value after the call.
+ * - The function chSemWait() is invoked, after return the counter and
+ * the returned message are tested.
+ * - The function chSemSignal() is invoked, after return the counter
+ * is tested.
+ * - The function chSemReset() is invoked, after return the counter
+ * is tested.
* .
*/
@@ -75,17 +76,21 @@ static void test_002_001_teardown(void) {
static void test_002_001_execute(void) {
- /* The function chSemWait() is invoked, the Semaphore counter is tested
- for correct value after the call.*/
+ /* The function chSemWait() is invoked, after return the counter and
+ the returned message are tested.*/
test_set_step(1);
{
- chSemWait(&sem1);
+ msg_t msg;
+
+ msg = chSemWait(&sem1);
test_assert_lock(chSemGetCounterI(&sem1) == 0,
"wrong counter value");
+ test_assert(MSG_OK == msg,
+ "wrong timeout message");
}
- /* The function chSemSignal() is invoked, the Semaphore counter is tested
- for correct value after the call.*/
+ /* The function chSemSignal() is invoked, after return the counter
+ is tested.*/
test_set_step(2);
{
chSemSignal(&sem1);
@@ -93,8 +98,8 @@ static void test_002_001_execute(void) {
"wrong counter value");
}
- /* The function chSemReset() is invoked, the Semaphore counter is tested
- for correct value after the call.*/
+ /* The function chSemReset() is invoked, after return the counter
+ is tested.*/
test_set_step(3);
{
chSemReset(&sem1, 2);
@@ -113,17 +118,16 @@ static const testcase_t test_002_001 = {
#if TRUE || defined(__DOXYGEN__)
/**
- * @page test_002_002 Semaphore timeouts
+ * @page test_002_002 Semaphore primitives, with state change
*
* <h2>Description</h2>
- * Timeouts on semaphores are tested.
+ * Wait, Signal and Reset primitives are tested. The testing thread
+ * triggers a state change.
*
* <h2>Conditions</h2>
* None.
*
* <h2>Test Steps</h2>
- * - The function chSemWaitTimeout() is invoked, after return the system
- * time, the counter and the returned message are tested.
* .
*/
@@ -138,6 +142,71 @@ static void test_002_002_teardown(void) {
}
static void test_002_002_execute(void) {
+
+ /* The function chSemWait() is invoked, after return the counter and
+ the returned message are tested. The semaphore is signaled by another
+ thread.*/
+ test_set_step(1);
+ {
+ msg_t msg;
+
+ msg = chSemWait(&gsem1);
+ test_assert_lock(chSemGetCounterI(&gsem1) == 0,
+ "wrong counter value");
+ test_assert(MSG_OK == msg,
+ "wrong timeout message");
+ }
+
+ /* The function chSemWait() is invoked, after return the counter and
+ the returned message are tested. The semaphore is reset by another
+ thread.*/
+ test_set_step(2);
+ {
+ msg_t msg;
+
+ msg = chSemWait(&gsem2);
+ test_assert_lock(chSemGetCounterI(&gsem2) == 0,
+ "wrong counter value");
+ test_assert(MSG_RESET == msg,
+ "wrong timeout message");
+ }
+}
+
+static const testcase_t test_002_002 = {
+ "semaphore primitives, with state change",
+ test_002_002_setup,
+ test_002_002_teardown,
+ test_002_002_execute
+};
+#endif /* TRUE */
+
+#if TRUE || defined(__DOXYGEN__)
+/**
+ * @page test_002_003 Semaphores timeout
+ *
+ * <h2>Description</h2>
+ * Timeout on semaphores is tested.
+ *
+ * <h2>Conditions</h2>
+ * None.
+ *
+ * <h2>Test Steps</h2>
+ * - The function chSemWaitTimeout() is invoked, after return the system
+ * time, the counter and the returned message are tested.
+ * .
+ */
+
+static void test_002_003_setup(void) {
+
+ chSemObjectInit(&sem1, 0);
+}
+
+static void test_002_003_teardown(void) {
+
+ chSemReset(&sem1, 0);
+}
+
+static void test_002_003_execute(void) {
systime_t time;
msg_t msg;
@@ -155,13 +224,28 @@ static void test_002_002_execute(void) {
test_assert(MSG_TIMEOUT == msg,
"wrong timeout message");
}
+
+ /* The function chSemWait() is invoked, after return the system
+ time, the counter and the returned message are tested.*/
+ test_set_step(1);
+ {
+ time = chVTGetSystemTimeX();
+ msg = chSemWaitTimeout(&sem1, 100);
+ test_assert_time_window(time + 100,
+ time + 100 + 1,
+ "out of time window");
+ test_assert_lock(chSemGetCounterI(&sem1) == 0,
+ "wrong counter value");
+ test_assert(MSG_TIMEOUT == msg,
+ "wrong timeout message");
+ }
}
-static const testcase_t test_002_002 = {
- "semaphore timeouts",
- test_002_002_setup,
- test_002_002_teardown,
- test_002_002_execute
+static const testcase_t test_002_003 = {
+ "semaphores timeout",
+ test_002_003_setup,
+ test_002_003_teardown,
+ test_002_003_execute
};
#endif /* TRUE */
@@ -179,5 +263,8 @@ const testcase_t * const test_sequence_002[] = {
#if TRUE || defined(__DOXYGEN__)
&test_002_002,
#endif
+#if TRUE || defined(__DOXYGEN__)
+ &test_002_003,
+#endif
NULL
};