git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6699 35acf78f-673a-0410-8e92-d51de3d6d3f4
This commit is contained in:
parent
7f3221216d
commit
47f0e8fb7f
|
@ -78,7 +78,7 @@ static THD_FUNCTION(Thread2, arg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Hello thread.
|
* Tester thread.
|
||||||
*/
|
*/
|
||||||
THD_WORKING_AREA(waThread3, 128);
|
THD_WORKING_AREA(waThread3, 128);
|
||||||
THD_FUNCTION(Thread3, arg) {
|
THD_FUNCTION(Thread3, arg) {
|
||||||
|
@ -111,6 +111,7 @@ THD_FUNCTION(Thread3, arg) {
|
||||||
THD_TABLE_BEGIN
|
THD_TABLE_BEGIN
|
||||||
THD_TABLE_ENTRY(waThread1, "blinker1", Thread1, NULL)
|
THD_TABLE_ENTRY(waThread1, "blinker1", Thread1, NULL)
|
||||||
THD_TABLE_ENTRY(waThread2, "blinker2", Thread2, NULL)
|
THD_TABLE_ENTRY(waThread2, "blinker2", Thread2, NULL)
|
||||||
|
THD_TABLE_ENTRY(wa_test_support, "test_support", test_support, NULL)
|
||||||
THD_TABLE_ENTRY(waThread3, "tester", Thread3, NULL)
|
THD_TABLE_ENTRY(waThread3, "tester", Thread3, NULL)
|
||||||
THD_TABLE_END
|
THD_TABLE_END
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@
|
||||||
* @note This number is not inclusive of the idle thread which is
|
* @note This number is not inclusive of the idle thread which is
|
||||||
* Implicitly handled.
|
* Implicitly handled.
|
||||||
*/
|
*/
|
||||||
#define NIL_CFG_NUM_THREADS 3
|
#define NIL_CFG_NUM_THREADS 4
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
|
|
|
@ -566,7 +566,6 @@ void chSemSignalI(semaphore_t *sp) {
|
||||||
while (true) {
|
while (true) {
|
||||||
/* Is this thread waiting on this semaphore?*/
|
/* Is this thread waiting on this semaphore?*/
|
||||||
if (tr->u1.semp == sp) {
|
if (tr->u1.semp == sp) {
|
||||||
sp->cnt++;
|
|
||||||
|
|
||||||
chDbgAssert(NIL_THD_IS_WTSEM(tr), "not waiting");
|
chDbgAssert(NIL_THD_IS_WTSEM(tr), "not waiting");
|
||||||
|
|
||||||
|
|
|
@ -181,6 +181,12 @@ extern "C" {
|
||||||
/* Module inline functions. */
|
/* Module inline functions. */
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
|
|
||||||
|
/*===========================================================================*/
|
||||||
|
/* Late inclusions. */
|
||||||
|
/*===========================================================================*/
|
||||||
|
|
||||||
|
#include "test_root.h"
|
||||||
|
|
||||||
#endif /* _CH_TEST_H_ */
|
#endif /* _CH_TEST_H_ */
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
|
@ -43,4 +43,31 @@ const testcase_t * const *test_suite[] = {
|
||||||
/* Shared code. */
|
/* 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
|
@ -47,6 +47,9 @@ extern const testcase_t * const *test_suite[];
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
extern semaphore_t gsem1, gsem2;
|
||||||
|
extern THD_WORKING_AREA(wa_test_support, 128);
|
||||||
|
THD_FUNCTION(test_support, arg);
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -19,12 +19,13 @@
|
||||||
#include "test_root.h"
|
#include "test_root.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @page test_sequence_002 Semaphores functionality
|
* @page test_sequence_002 Synchronization primitives
|
||||||
*
|
*
|
||||||
* File: @ref test_sequence_002.c
|
* File: @ref test_sequence_002.c
|
||||||
*
|
*
|
||||||
* <h2>Description</h2>
|
* <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>
|
* <h2>Test Cases</h2>
|
||||||
* - @subpage test_002_001
|
* - @subpage test_002_001
|
||||||
|
@ -54,12 +55,12 @@ static semaphore_t sem1;
|
||||||
* None.
|
* None.
|
||||||
*
|
*
|
||||||
* <h2>Test Steps</h2>
|
* <h2>Test Steps</h2>
|
||||||
* - The function chSemWait() is invoked, the Semaphore counter is tested
|
* - The function chSemWait() is invoked, after return the counter and
|
||||||
* for correct value after the call.
|
* the returned message are tested.
|
||||||
* - The function chSemSignal() is invoked, the Semaphore counter is tested
|
* - The function chSemSignal() is invoked, after return the counter
|
||||||
* for correct value after the call.
|
* is tested.
|
||||||
* - The function chSemReset() is invoked, the Semaphore counter is tested
|
* - The function chSemReset() is invoked, after return the counter
|
||||||
* for correct value after the call.
|
* is tested.
|
||||||
* .
|
* .
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -75,17 +76,21 @@ static void test_002_001_teardown(void) {
|
||||||
|
|
||||||
static void test_002_001_execute(void) {
|
static void test_002_001_execute(void) {
|
||||||
|
|
||||||
/* The function chSemWait() is invoked, the Semaphore counter is tested
|
/* The function chSemWait() is invoked, after return the counter and
|
||||||
for correct value after the call.*/
|
the returned message are tested.*/
|
||||||
test_set_step(1);
|
test_set_step(1);
|
||||||
{
|
{
|
||||||
chSemWait(&sem1);
|
msg_t msg;
|
||||||
|
|
||||||
|
msg = chSemWait(&sem1);
|
||||||
test_assert_lock(chSemGetCounterI(&sem1) == 0,
|
test_assert_lock(chSemGetCounterI(&sem1) == 0,
|
||||||
"wrong counter value");
|
"wrong counter value");
|
||||||
|
test_assert(MSG_OK == msg,
|
||||||
|
"wrong timeout message");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The function chSemSignal() is invoked, the Semaphore counter is tested
|
/* The function chSemSignal() is invoked, after return the counter
|
||||||
for correct value after the call.*/
|
is tested.*/
|
||||||
test_set_step(2);
|
test_set_step(2);
|
||||||
{
|
{
|
||||||
chSemSignal(&sem1);
|
chSemSignal(&sem1);
|
||||||
|
@ -93,8 +98,8 @@ static void test_002_001_execute(void) {
|
||||||
"wrong counter value");
|
"wrong counter value");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The function chSemReset() is invoked, the Semaphore counter is tested
|
/* The function chSemReset() is invoked, after return the counter
|
||||||
for correct value after the call.*/
|
is tested.*/
|
||||||
test_set_step(3);
|
test_set_step(3);
|
||||||
{
|
{
|
||||||
chSemReset(&sem1, 2);
|
chSemReset(&sem1, 2);
|
||||||
|
@ -113,17 +118,16 @@ static const testcase_t test_002_001 = {
|
||||||
|
|
||||||
#if TRUE || defined(__DOXYGEN__)
|
#if TRUE || defined(__DOXYGEN__)
|
||||||
/**
|
/**
|
||||||
* @page test_002_002 Semaphore timeouts
|
* @page test_002_002 Semaphore primitives, with state change
|
||||||
*
|
*
|
||||||
* <h2>Description</h2>
|
* <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>
|
* <h2>Conditions</h2>
|
||||||
* None.
|
* None.
|
||||||
*
|
*
|
||||||
* <h2>Test Steps</h2>
|
* <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) {
|
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;
|
systime_t time;
|
||||||
msg_t msg;
|
msg_t msg;
|
||||||
|
|
||||||
|
@ -155,13 +224,28 @@ static void test_002_002_execute(void) {
|
||||||
test_assert(MSG_TIMEOUT == msg,
|
test_assert(MSG_TIMEOUT == msg,
|
||||||
"wrong timeout message");
|
"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 = {
|
static const testcase_t test_002_003 = {
|
||||||
"semaphore timeouts",
|
"semaphores timeout",
|
||||||
test_002_002_setup,
|
test_002_003_setup,
|
||||||
test_002_002_teardown,
|
test_002_003_teardown,
|
||||||
test_002_002_execute
|
test_002_003_execute
|
||||||
};
|
};
|
||||||
#endif /* TRUE */
|
#endif /* TRUE */
|
||||||
|
|
||||||
|
@ -178,6 +262,9 @@ const testcase_t * const test_sequence_002[] = {
|
||||||
#endif
|
#endif
|
||||||
#if TRUE || defined(__DOXYGEN__)
|
#if TRUE || defined(__DOXYGEN__)
|
||||||
&test_002_002,
|
&test_002_002,
|
||||||
|
#endif
|
||||||
|
#if TRUE || defined(__DOXYGEN__)
|
||||||
|
&test_002_003,
|
||||||
#endif
|
#endif
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue