aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2009-04-12 08:38:51 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2009-04-12 08:38:51 +0000
commit2d1d900b6d11a3f7ef5ff3e0f7f02faa40d8b25f (patch)
tree66d1012f259cee25974f2f72b9851c3ed6b305a8
parent0e27db08794a9ce9205cf45f1b4189d89616ef05 (diff)
downloadChibiOS-2d1d900b6d11a3f7ef5ff3e0f7f02faa40d8b25f.tar.gz
ChibiOS-2d1d900b6d11a3f7ef5ff3e0f7f02faa40d8b25f.tar.bz2
ChibiOS-2d1d900b6d11a3f7ef5ff3e0f7f02faa40d8b25f.zip
Fixed bug 2755170.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@890 35acf78f-673a-0410-8e92-d51de3d6d3f4
-rw-r--r--readme.txt2
-rw-r--r--src/chsem.c4
-rw-r--r--test/testsem.c45
3 files changed, 40 insertions, 11 deletions
diff --git a/readme.txt b/readme.txt
index 48a925e78..bc129dd72 100644
--- a/readme.txt
+++ b/readme.txt
@@ -77,6 +77,8 @@ Win32-MinGW - ChibiOS/RT simulator and demo into a WIN32 process,
*** 1.3.0 ***
- FIX: Fixed regression in MinGW demo (bug 2745153)(backported in stable
branch).
+- FIX: Fixed problem with the timeout constant TIME_IMMEDIATE, added a
+ specific test in the test suite (bug 2755170)(backported in stable branch).
- NEW: Added a code coverage analysis application under ./tests/coverage.
Currently the test suite explicitly covers about 74% of the kernel code,
it is not bad as a starting point.
diff --git a/src/chsem.c b/src/chsem.c
index 21f80c284..085f4014b 100644
--- a/src/chsem.c
+++ b/src/chsem.c
@@ -174,8 +174,10 @@ msg_t chSemWaitTimeoutS(Semaphore *sp, systime_t time) {
chDbgCheck(sp != NULL, "chSemWaitTimeoutS");
if (--sp->s_cnt < 0) {
- if (TIME_IMMEDIATE == time)
+ if (TIME_IMMEDIATE == time) {
+ sp->s_cnt++;
return RDY_TIMEOUT;
+ }
sem_insert(currp, &sp->s_queue);
currp->p_wtsemp = sp;
return chSchGoSleepTimeoutS(PRWTSEM, time);
diff --git a/test/testsem.c b/test/testsem.c
index e6153fa8d..d6e432a36 100644
--- a/test/testsem.c
+++ b/test/testsem.c
@@ -37,7 +37,7 @@ static void sem1_setup(void) {
chSemInit(&sem1, 0);
}
-static msg_t thread(void *p) {
+static msg_t thread1(void *p) {
chSemWait(&sem1);
test_emit_token(*(char *)p);
@@ -46,11 +46,11 @@ static msg_t thread(void *p) {
static void sem1_execute(void) {
- threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriority()+5, thread, "A");
- threads[1] = chThdCreateStatic(wa[1], WA_SIZE, chThdGetPriority()+1, thread, "B");
- threads[2] = chThdCreateStatic(wa[2], WA_SIZE, chThdGetPriority()+3, thread, "C");
- threads[3] = chThdCreateStatic(wa[3], WA_SIZE, chThdGetPriority()+4, thread, "D");
- threads[4] = chThdCreateStatic(wa[4], WA_SIZE, chThdGetPriority()+2, thread, "E");
+ threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriority()+5, thread1, "A");
+ threads[1] = chThdCreateStatic(wa[1], WA_SIZE, chThdGetPriority()+1, thread1, "B");
+ threads[2] = chThdCreateStatic(wa[2], WA_SIZE, chThdGetPriority()+3, thread1, "C");
+ threads[3] = chThdCreateStatic(wa[3], WA_SIZE, chThdGetPriority()+4, thread1, "D");
+ threads[4] = chThdCreateStatic(wa[4], WA_SIZE, chThdGetPriority()+2, thread1, "E");
chSemSignal(&sem1);
chSemSignal(&sem1);
chSemSignal(&sem1);
@@ -82,21 +82,46 @@ static void sem2_setup(void) {
chSemInit(&sem1, 0);
}
+static msg_t thread2(void *p) {
+
+ chThdSleepMilliseconds(50);
+ chSemSignal(&sem1);
+ return 0;
+}
+
static void sem2_execute(void) {
int i;
systime_t target_time;
msg_t msg;
- msg= chSemWaitTimeout(&sem1, TIME_IMMEDIATE);
+ /*
+ * Testing special case TIME_IMMEDIATE.
+ */
+ msg = chSemWaitTimeout(&sem1, TIME_IMMEDIATE);
test_assert(msg == RDY_TIMEOUT, "#1");
+ test_assert(isempty(&sem1.s_queue), "#2"); /* Queue not empty */
+ test_assert(sem1.s_cnt == 0, "#3"); /* Counter not zero */
+
+ /*
+ * Testing not timeout condition.
+ */
+ threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriority()-1, thread2, "A");
+ msg = chSemWaitTimeout(&sem1, MS2ST(500));
+ test_wait_threads();
+ test_assert(msg == RDY_OK, "#4");
+ test_assert(isempty(&sem1.s_queue), "#5"); /* Queue not empty */
+ test_assert(sem1.s_cnt == 0, "#6"); /* Counter not zero */
+ /*
+ * Testing timeout condition.
+ */
target_time = chTimeNow() + MS2ST(5 * 500);
for (i = 0; i < 5; i++) {
test_emit_token('A' + i);
msg = chSemWaitTimeout(&sem1, MS2ST(500));
- test_assert(msg == RDY_TIMEOUT, "#2");
- test_assert(isempty(&sem1.s_queue), "#3"); /* Queue not empty */
- test_assert(&sem1.s_cnt != 0, "#4"); /* Counter not zero */
+ test_assert(msg == RDY_TIMEOUT, "#7");
+ test_assert(isempty(&sem1.s_queue), "#8"); /* Queue not empty */
+ test_assert(sem1.s_cnt == 0, "#9"); /* Counter not zero */
}
test_assert_sequence("ABCDE");
test_assert_time_window(target_time, target_time + ALLOWED_DELAY);