diff options
Diffstat (limited to 'test/nil')
-rw-r--r-- | test/nil/test_root.c | 6 | ||||
-rw-r--r-- | test/nil/test_sequence_002.c | 108 |
2 files changed, 101 insertions, 13 deletions
diff --git a/test/nil/test_root.c b/test/nil/test_root.c index 49c1d7862..a8efacba7 100644 --- a/test/nil/test_root.c +++ b/test/nil/test_root.c @@ -51,8 +51,7 @@ thread_reference_t gtr1; */
THD_WORKING_AREA(wa_test_support, 128);
THD_FUNCTION(test_support, arg) {
-
- (void)arg;
+ thread_t *tp = (thread_t *)arg;
/* Initializing global resources.*/
chSemObjectInit(&gsem1, 0);
@@ -65,10 +64,11 @@ THD_FUNCTION(test_support, arg) { chSemSignalI(&gsem1);
chSemResetI(&gsem2, 0);
chThdResumeI(>r1, MSG_OK);
+ chEvtSignalI(tp, 0x55);
chSchRescheduleS();
chSysUnlock();
- chThdSleepMilliseconds(500);
+ chThdSleepMilliseconds(250);
}
}
diff --git a/test/nil/test_sequence_002.c b/test/nil/test_sequence_002.c index ddb6379ff..a687e7f0f 100644 --- a/test/nil/test_sequence_002.c +++ b/test/nil/test_sequence_002.c @@ -222,9 +222,9 @@ static void test_002_003_execute(void) { test_set_step(1);
{
time = chVTGetSystemTimeX();
- msg = chSemWaitTimeout(&sem1, 100);
- test_assert_time_window(time + 100,
- time + 100 + 1,
+ msg = chSemWaitTimeout(&sem1, MS2ST(1000));
+ test_assert_time_window(time + MS2ST(1000),
+ time + MS2ST(1000) + 1,
"out of time window");
test_assert_lock(chSemGetCounterI(&sem1) == 0,
"wrong counter value");
@@ -237,9 +237,9 @@ static void test_002_003_execute(void) { test_set_step(2);
{
time = chVTGetSystemTimeX();
- msg = chSemWaitTimeout(&sem1, 100);
- test_assert_time_window(time + 100,
- time + 100 + 1,
+ msg = chSemWaitTimeout(&sem1, MS2ST(1000));
+ test_assert_time_window(time + MS2ST(1000),
+ time + MS2ST(1000) + 1,
"out of time window");
test_assert_lock(chSemGetCounterI(&sem1) == 0,
"wrong counter value");
@@ -304,11 +304,11 @@ static void test_002_004_execute(void) { test_set_step(2);
{
time = chVTGetSystemTimeX();
- msg = chThdSuspendTimeoutS(>r1, 100);
- test_assert_time_window(time + 100,
- time + 100 + 1,
+ msg = chThdSuspendTimeoutS(&tr1, MS2ST(1000));
+ test_assert_time_window(time + MS2ST(1000),
+ time + MS2ST(1000) + 1,
"out of time window");
- test_assert(NULL == gtr1,
+ test_assert(NULL == tr1,
"not NULL");
test_assert(MSG_TIMEOUT == msg,
"wrong returned message");
@@ -323,6 +323,91 @@ static const testcase_t test_002_004 = { };
#endif /* TRUE */
+#if TRUE || defined(__DOXYGEN__)
+/**
+ * @page test_002_005 Events functionality
+ *
+ * <h2>Description</h2>
+ * Event flags functionality is tested.
+ *
+ * <h2>Conditions</h2>
+ * None.
+ *
+ * <h2>Test Steps</h2>
+ * - A set of event flags are set on the current thread then the
+ * function chVTGetSystemTimeX() is invoked, the function is supposed to
+ * return immediately because the event flags are already pending,
+ * after return the events mask is tested.
+ * - The pending event flags mask is cleared then the function
+ * chVTGetSystemTimeX() is invoked, after return the events
+ * mask is tested. The thread is signaled by another thread.
+ * -
+ * . The function chVTGetSystemTimeX() is invoked, no event can
+ * wakeup the thread, the function must return because timeout.
+ */
+
+static void test_002_005_setup(void) {
+
+ chSemObjectInit(&sem1, 0);
+}
+
+static void test_002_005_execute(void) {
+ systime_t time;
+ eventmask_t events;
+
+ /* A set of event flags are set on the current thread then the
+ function chVTGetSystemTimeX() is invoked, the function is supposed to
+ return immediately because the event flags are already pending,
+ after return the events mask is tested.*/
+ test_set_step(1);
+ {
+ time = chVTGetSystemTimeX();
+ chEvtSignalI(chThdGetSelfX(), 0x55);
+ events = chEvtWaitAnyTimeout(ALL_EVENTS, MS2ST(1000));
+ test_assert((eventmask_t)0 != events,
+ "timed out");
+ test_assert((eventmask_t)0x55 == events,
+ "wrong events mask");
+ }
+
+ /* The pending event flags mask is cleared then the function
+ chVTGetSystemTimeX() is invoked, after return the events
+ mask is tested. The thread is signaled by another thread.*/
+ test_set_step(2);
+ {
+ time = chVTGetSystemTimeX();
+ chThdGetSelfX()->epmask = 0;
+ events = chEvtWaitAnyTimeout(ALL_EVENTS, MS2ST(1000));
+ test_assert((eventmask_t)0 != events,
+ "timed out");
+ test_assert((eventmask_t)0x55 == events,
+ "wrong events mask");
+ }
+
+ /* The function chVTGetSystemTimeX() is invoked, no event can
+ wakeup the thread, the function must return because timeout.*/
+ test_set_step(3);
+ {
+ chSysLock();
+ time = chVTGetSystemTimeX();
+ events = chEvtWaitAnyTimeoutS(0, MS2ST(1000));
+ chSysUnlock();
+ test_assert_time_window(time + MS2ST(1000),
+ time + MS2ST(1000) + 1,
+ "out of time window");
+ test_assert((eventmask_t)0 == events,
+ "wrong events mask");
+ }
+}
+
+static const testcase_t test_002_005 = {
+ "events functionality",
+ test_002_005_setup,
+ NULL,
+ test_002_005_execute
+};
+#endif /* TRUE */
+
/****************************************************************************
* Exported data.
****************************************************************************/
@@ -343,5 +428,8 @@ const testcase_t * const test_sequence_002[] = { #if TRUE || defined(__DOXYGEN__)
&test_002_004,
#endif
+#if TRUE || defined(__DOXYGEN__)
+ &test_002_005,
+#endif
NULL
};
|