git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6700 35acf78f-673a-0410-8e92-d51de3d6d3f4

This commit is contained in:
gdisirio 2014-02-11 09:59:20 +00:00
parent 47f0e8fb7f
commit 4541bd732a
3 changed files with 85 additions and 5 deletions

View File

@ -44,6 +44,7 @@ const testcase_t * const *test_suite[] = {
/*===========================================================================*/ /*===========================================================================*/
semaphore_t gsem1, gsem2; semaphore_t gsem1, gsem2;
thread_reference_t gtr1;
/* /*
* Support thread. * Support thread.
@ -63,6 +64,7 @@ THD_FUNCTION(test_support, arg) {
if (chSemGetCounterI(&gsem1) < 0) if (chSemGetCounterI(&gsem1) < 0)
chSemSignalI(&gsem1); chSemSignalI(&gsem1);
chSemResetI(&gsem2, 0); chSemResetI(&gsem2, 0);
chThdResumeI(&gtr1, MSG_OK);
chSchRescheduleS(); chSchRescheduleS();
chSysUnlock(); chSysUnlock();

View File

@ -48,6 +48,7 @@ extern const testcase_t * const *test_suite[];
extern "C" { extern "C" {
#endif #endif
extern semaphore_t gsem1, gsem2; extern semaphore_t gsem1, gsem2;
extern thread_reference_t gtr1;
extern THD_WORKING_AREA(wa_test_support, 128); extern THD_WORKING_AREA(wa_test_support, 128);
THD_FUNCTION(test_support, arg); THD_FUNCTION(test_support, arg);
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -38,6 +38,7 @@
****************************************************************************/ ****************************************************************************/
static semaphore_t sem1; static semaphore_t sem1;
static thread_reference_t tr1;
/**************************************************************************** /****************************************************************************
* Test cases. * Test cases.
@ -86,7 +87,7 @@ static void test_002_001_execute(void) {
test_assert_lock(chSemGetCounterI(&sem1) == 0, test_assert_lock(chSemGetCounterI(&sem1) == 0,
"wrong counter value"); "wrong counter value");
test_assert(MSG_OK == msg, test_assert(MSG_OK == msg,
"wrong timeout message"); "wrong returned message");
} }
/* The function chSemSignal() is invoked, after return the counter /* The function chSemSignal() is invoked, after return the counter
@ -128,6 +129,12 @@ static const testcase_t test_002_001 = {
* None. * None.
* *
* <h2>Test Steps</h2> * <h2>Test Steps</h2>
* - The function chSemWait() is invoked, after return the counter and
* the returned message are tested. The semaphore is signaled by another
* thread.
* - The function chSemWait() is invoked, after return the counter and
* the returned message are tested. The semaphore is reset by another
* thread.
* . * .
*/ */
@ -154,7 +161,7 @@ static void test_002_002_execute(void) {
test_assert_lock(chSemGetCounterI(&gsem1) == 0, test_assert_lock(chSemGetCounterI(&gsem1) == 0,
"wrong counter value"); "wrong counter value");
test_assert(MSG_OK == msg, test_assert(MSG_OK == msg,
"wrong timeout message"); "wrong returned message");
} }
/* The function chSemWait() is invoked, after return the counter and /* The function chSemWait() is invoked, after return the counter and
@ -168,7 +175,7 @@ static void test_002_002_execute(void) {
test_assert_lock(chSemGetCounterI(&gsem2) == 0, test_assert_lock(chSemGetCounterI(&gsem2) == 0,
"wrong counter value"); "wrong counter value");
test_assert(MSG_RESET == msg, test_assert(MSG_RESET == msg,
"wrong timeout message"); "wrong returned message");
} }
} }
@ -225,9 +232,9 @@ static void test_002_003_execute(void) {
"wrong timeout message"); "wrong timeout message");
} }
/* The function chSemWait() is invoked, after return the system /* The function chSemWaitTimeout() is invoked, after return the system
time, the counter and the returned message are tested.*/ time, the counter and the returned message are tested.*/
test_set_step(1); test_set_step(2);
{ {
time = chVTGetSystemTimeX(); time = chVTGetSystemTimeX();
msg = chSemWaitTimeout(&sem1, 100); msg = chSemWaitTimeout(&sem1, 100);
@ -247,6 +254,73 @@ static const testcase_t test_002_003 = {
test_002_003_teardown, test_002_003_teardown,
test_002_003_execute test_002_003_execute
}; };
#endif /* TRUE */
#if TRUE || defined(__DOXYGEN__)
/**
* @page test_002_004 Suspend and Resume functionality
*
* <h2>Description</h2>
* The functionality of chThdSuspendTimeoutS() and chThdResumeI() is
* tested.
*
* <h2>Conditions</h2>
* None.
*
* <h2>Test Steps</h2>
* - The function chThdSuspendTimeoutS() is invoked, the thread is
* remotely resumed with message @p MSG_OK. On return the message
* and the state of the reference are tested.
* - The function chThdSuspendTimeoutS() is invoked, the thread is
* not resumed so a timeout must occur. On return the message
* and the state of the reference are tested.
* .
*/
static void test_002_004_setup(void) {
tr1 = NULL;
}
static void test_002_004_execute(void) {
systime_t time;
msg_t msg;
/* The function chThdSuspendTimeoutS() is invoked, the thread is
remotely resumed with message @p MSG_OK. On return the message
and the state of the reference are tested.*/
test_set_step(1);
{
msg = chThdSuspendTimeoutS(&gtr1, TIME_INFINITE);
test_assert(NULL == gtr1,
"not NULL");
test_assert(MSG_OK == msg,
"wrong returned message");
}
/* The function chThdSuspendTimeoutS() is invoked, the thread is
not resumed so a timeout must occur. On return the message
and the state of the reference are tested.*/
test_set_step(2);
{
time = chVTGetSystemTimeX();
msg = chThdSuspendTimeoutS(&gtr1, 100);
test_assert_time_window(time + 100,
time + 100 + 1,
"out of time window");
test_assert(NULL == gtr1,
"not NULL");
test_assert(MSG_TIMEOUT == msg,
"wrong returned message");
}
}
static const testcase_t test_002_004 = {
"suspend and resume functionality",
test_002_004_setup,
NULL,
test_002_004_execute
};
#endif /* TRUE */ #endif /* TRUE */
/**************************************************************************** /****************************************************************************
@ -265,6 +339,9 @@ const testcase_t * const test_sequence_002[] = {
#endif #endif
#if TRUE || defined(__DOXYGEN__) #if TRUE || defined(__DOXYGEN__)
&test_002_003, &test_002_003,
#endif
#if TRUE || defined(__DOXYGEN__)
&test_002_004,
#endif #endif
NULL NULL
}; };