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

master
gdisirio 2008-11-09 11:45:37 +00:00
parent 6776d06927
commit 0dd1ffc088
4 changed files with 140 additions and 4 deletions

View File

@ -23,6 +23,7 @@
#include "testrdy.h"
#include "testsem.h"
#include "testmtx.h"
#include "testcond.h"
#include "testmsg.h"
#include "testevt.h"
#include "testheap.h"
@ -44,6 +45,10 @@ static const struct testcase *tests[] = {
&testmtx1,
&testmtx2,
&testmtx3,
#ifdef CH_USE_CONDVARS
&testcond1,
&testcond2,
#endif
#endif
#ifdef CH_USE_MESSAGES
&testmsg1,

View File

@ -1,5 +1,5 @@
# List of all the ChibiOS/RT test files.
TESTSRC = ../../test/test.c ../../test/testrdy.c ../../test/testsem.c \
../../test/testmtx.c ../../test/testmsg.c ../../test/testevt.c \
../../test/testheap.c ../../test/testpools.c ../../test/testdyn.c \
../../test/testbmk.c
TESTSRC = ../../test/test.c ../../test/testrdy.c ../../test/testsem.c \
../../test/testmtx.c ../../test/testcond.c ../../test/testmsg.c \
../../test/testevt.c ../../test/testheap.c ../../test/testpools.c \
../../test/testdyn.c ../../test/testbmk.c

105
test/testcond.c Normal file
View File

@ -0,0 +1,105 @@
/*
ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio.
This file is part of ChibiOS/RT.
ChibiOS/RT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
ChibiOS/RT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <ch.h>
#include "test.h"
#if defined(CH_USE_CONDVARS) && defined(CH_USE_MUTEXES)
static Mutex m1;
static CondVar c1;
static char *cond1_gettest(void) {
return "CondVar, signal test";
}
static void cond1_setup(void) {
chCondInit(&c1);
chMtxInit(&m1);
}
static void cond1_teardown(void) {
}
static msg_t thread1(void *p) {
chMtxLock(&m1);
chCondWait(&c1);
test_emit_token(*(char *)p);
chMtxUnlock();
return 0;
}
static void cond1_execute(void) {
// Bacause priority inheritance.
tprio_t prio = chThdGetPriority();
threads[0] = chThdCreate(prio+1, 0, wa[0], STKSIZE, thread1, "E");
threads[1] = chThdCreate(prio+2, 0, wa[1], STKSIZE, thread1, "D");
threads[2] = chThdCreate(prio+3, 0, wa[2], STKSIZE, thread1, "C");
threads[3] = chThdCreate(prio+4, 0, wa[3], STKSIZE, thread1, "B");
threads[4] = chThdCreate(prio+5, 0, wa[4], STKSIZE, thread1, "A");
test_assert(prio == chThdGetPriority(), "priority return failure");
chCondSignal(&c1);
chCondSignal(&c1);
chCondSignal(&c1);
chCondSignal(&c1);
chCondSignal(&c1);
test_wait_threads();
test_assert_sequence("ABCDE");
}
const struct testcase testcond1 = {
cond1_gettest,
cond1_setup,
cond1_teardown,
cond1_execute
};
static char *cond2_gettest(void) {
return "CondVar, broadcast test";
}
static void cond2_execute(void) {
// Bacause priority inheritance.
tprio_t prio = chThdGetPriority();
threads[0] = chThdCreate(prio+1, 0, wa[0], STKSIZE, thread1, "E");
threads[1] = chThdCreate(prio+2, 0, wa[1], STKSIZE, thread1, "D");
threads[2] = chThdCreate(prio+3, 0, wa[2], STKSIZE, thread1, "C");
threads[3] = chThdCreate(prio+4, 0, wa[3], STKSIZE, thread1, "B");
threads[4] = chThdCreate(prio+5, 0, wa[4], STKSIZE, thread1, "A");
test_assert(prio == chThdGetPriority(), "priority return failure");
chCondBroadcast(&c1);
test_wait_threads();
test_assert_sequence("ABCDE");
}
const struct testcase testcond2 = {
cond2_gettest,
cond1_setup,
cond1_teardown,
cond2_execute
};
#endif /* defined(CH_USE_CONDVARS) && defined(CH_USE_MUTEXES) */

26
test/testcond.h Normal file
View File

@ -0,0 +1,26 @@
/*
ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio.
This file is part of ChibiOS/RT.
ChibiOS/RT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
ChibiOS/RT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TESTCOND_H_
#define _TESTCOND_H_
extern const struct testcase testcond1;
extern const struct testcase testcond2;
#endif /* _TESTCOND_H_ */