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

This commit is contained in:
gdisirio 2009-02-18 12:58:35 +00:00
parent 6b6e5b95fb
commit 4c2be4a8e9
17 changed files with 208 additions and 67 deletions

View File

@ -80,6 +80,7 @@ Win32-MinGW - ChibiOS/RT simulator and demo into a WIN32 process,
- FIX: Fixed wrong assertions in chThdWait() and chHeapFree() (backported in
stable branch).
- FIX: Fixed a small problem in the chcore.c template file.
- NEW: Mailboxes (asynchronous messages) subsystem and test cases added.
- NEW: Mode flexible debug configuration options, removed the old CH_USE_DEBUG
and CH_USE_TRACE. Replaced with CH_DBG_ENABLE_ASSERTS, CH_DBG_ENABLE_TRACE
and CH_DBG_FILL_THREADS.

View File

@ -40,6 +40,7 @@ void trace_init(void) {
trace_buffer.tb_size = TRACE_BUFFER_SIZE;
trace_buffer.tb_ptr = &trace_buffer.tb_buffer[0];
}
/**
* @brief Inserts in the circular debug trace buffer a context switch record.
*

View File

@ -86,6 +86,7 @@ extern "C" {
#endif
#if CH_DBG_ENABLE_TRACE
extern TraceBuffer trace_buffer;
void trace_init(void);
void chDbgTrace(Thread *otp, Thread *ntp);
#endif
#if CH_DBG_ENABLE_ASSERTS

View File

@ -52,22 +52,33 @@ extern "C" {
#endif
/**
* Verifies if the mailbox has space for an immediate message.
* Returns the mailbox buffer size.
* @param[in] mbp the pointer to an initialized Mailbox object
*/
#define chMBSize(mbp) \
((mbp)->mb_top - (mbp)->mb_buffer)
/**
* Returns the free space into the mailbox.
* @param[in] mbp the pointer to an initialized Mailbox object
* @return The number of empty message slots.
* @note Can be invoked in any system state but if invoked out of a locked
* state then the returned value may change after reading.
* @note The returned value can be less than zero when there are waiting
* threads on the internal semaphore.
*/
#define chMBHasSpace(mbp) chSemGetCounterI(&(mbp)->mb_emptysem)
#define chMBGetEmpty(mbp) chSemGetCounterI(&(mbp)->mb_emptysem)
/**
* Verifies if the mailbox has incoming messages.
* Returns the number of messages into the mailbox.
* @param[in] mbp the pointer to an initialized Mailbox object
* @return The number of queued messages.
* @note Can be invoked in any system state but if invoked out of a locked
* state then the returned value may change after reading.
* @note The returned value can be less than zero when there are waiting
* threads on the internal semaphore.
*/
#define chMBContainsMessages(mbp) chSemGetCounterI(&(mbp)->mb_fullsem)
#define chMBGetFull(mbp) chSemGetCounterI(&(mbp)->mb_fullsem)
/**
* Returns the next message in the queue without removing it.

View File

@ -58,29 +58,27 @@ typedef struct {
} Queue;
/** Returns the queue's buffer size. */
#define chQSize(q) \
((q)->q_top - (q)->q_buffer)
#define chQSize(q) ((q)->q_top - (q)->q_buffer)
/** Returns the used space if used on an Input Queue and the empty space if
* used on an Output Queue. */
#define chQSpace(q) \
((q)->q_sem.s_cnt)
/**
* Returns the used space if used on an Input Queue and the empty space if
* used on an Output Queue.
* @note The returned value can be less than zero when there are waiting
* threads on the internal semaphore.
*/
#define chQSpace(q) chSemGetCounterI(&(q)->q_sem)
/** Evaluates to TRUE if the specified Input Queue is empty. */
#define chIQIsEmpty(q) \
(chQSpace(q) <= 0)
#define chIQIsEmpty(q) (chQSpace(q) <= 0)
/** Evaluates to TRUE if the specified Input Queue is full. */
#define chIQIsFull(q) \
(chQSpace(q) >= chQSize(q))
#define chIQIsFull(q) (chQSpace(q) >= chQSize(q))
/** Evaluates to TRUE if the specified Output Queue is empty. */
#define chOQIsEmpty(q) \
(chQSpace(q) >= chQSize(q))
#define chOQIsEmpty(q) (chQSpace(q) >= chQSize(q))
/** Evaluates to TRUE if the specified Output Queue is full. */
#define chOQIsFull(q) \
(chQSpace(q) <= 0)
#define chOQIsFull(q) (chQSpace(q) <= 0)
#ifdef __cplusplus
extern "C" {
@ -131,28 +129,30 @@ typedef struct {
} HalfDuplexQueue;
/** Returns the queue's buffer size. */
#define chHDQSize(q) \
((q)->hdq_top - (q)->hdq_buffer)
#define chHDQSize(q) ((q)->hdq_top - (q)->hdq_buffer)
/** Returns the queue space when in transmission mode. */
#define chHDQEmptySpace(q) \
((q)->hdq_osem.s_cnt)
/**
* Returns the queue space when in transmission mode.
* @note The returned value can be less than zero when there are waiting
* threads on the internal semaphore.
*/
#define chHDQEmptySpace(q) chSemGetCounterI(&(q)->hdq_osem)
/** Returns the number of the bytes in the queue when in receive mode. */
#define chHDQFilledSpace(q) \
((q)->hdq_isem.s_cnt)
/**
* Returns the number of the bytes in the queue when in receive mode.
* @note The returned value can be less than zero when there are waiting
* threads on the internal semaphore.
*/
#define chHDQFilledSpace(q) chSemGetCounterI(&(q)->hdq_isem)
/** Evaluates to TRUE if the queue is in transmit mode. */
#define chHDQIsTransmitting(q) \
(chHDQEmptySpace(q) < chHDQSize(q))
#define chHDQIsTransmitting(q) (chHDQEmptySpace(q) < chHDQSize(q))
/** Evaluates to TRUE if the queue is in receive mode. */
#define chHDQIsReceiving(q) \
(chHDQEmptySpaceQ(q) >= chHDQSize(q))
#define chHDQIsReceiving(q) (chHDQEmptySpaceQ(q) >= chHDQSize(q))
/** Evaluates to TRUE if the receive queue is full. */
#define chHDQIsFullReceive(q) \
(chHDQFilledSpace(q) >= chHDQSize(q))
#define chHDQIsFullReceive(q) (chHDQFilledSpace(q) >= chHDQSize(q))
#ifdef __cplusplus
extern "C" {

View File

@ -25,6 +25,7 @@
#include "testmtx.h"
#include "testcond.h"
#include "testmsg.h"
#include "testmbox.h"
#include "testevt.h"
#include "testheap.h"
#include "testpools.h"
@ -40,6 +41,7 @@ static const struct testcase **patterns[] = {
patternmtx,
patterncond,
patternmsg,
patternmbox,
patternevt,
patternheap,
patternpools,

View File

@ -1,8 +1,8 @@
# List of all the ChibiOS/RT test files.
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
../../test/testmbox.c ../../test/testevt.c ../../test/testheap.c \
../../test/testpools.c ../../test/testdyn.c ../../test/testbmk.c
# Required include directories
TESTINC = ../../test

View File

@ -55,7 +55,7 @@ static void cond1_execute(void) {
threads[2] = chThdCreateStatic(wa[2], WA_SIZE, prio+3, thread1, "C");
threads[3] = chThdCreateStatic(wa[3], WA_SIZE, prio+4, thread1, "B");
threads[4] = chThdCreateStatic(wa[4], WA_SIZE, prio+5, thread1, "A");
test_assert(prio == chThdGetPriority(), "priority return failure");
test_assert(prio == chThdGetPriority(), "#1"); /* Priority return failure.*/
chCondSignal(&c1);
chCondSignal(&c1);
chCondSignal(&c1);
@ -86,7 +86,7 @@ static void cond2_execute(void) {
threads[2] = chThdCreateStatic(wa[2], WA_SIZE, prio+3, thread1, "C");
threads[3] = chThdCreateStatic(wa[3], WA_SIZE, prio+4, thread1, "B");
threads[4] = chThdCreateStatic(wa[4], WA_SIZE, prio+5, thread1, "A");
test_assert(prio == chThdGetPriority(), "priority return failure");
test_assert(prio == chThdGetPriority(), "#1"); /* Priority return failure.*/
chCondBroadcast(&c1);
test_wait_threads();
test_assert_sequence("ABCDE");

View File

@ -52,15 +52,15 @@ static void dyn1_execute(void) {
(threads[2] == NULL) &&
(threads[3] == NULL) &&
(threads[4] == NULL),
"thread creation failed");
"#1"); /* Thread creation failed.*/
/* Claiming the memory from terminated threads. */
test_wait_threads();
test_assert_sequence("AB");
/* Heap status checked again.*/
test_assert(chHeapStatus(&n) == 1, "heap fragmented");
test_assert(n == sz, "heap size changed");
test_assert(chHeapStatus(&n) == 1, "#2"); /* Heap fragmented.*/
test_assert(n == sz, "#3"); /* Heap size changed.*/
}
}
@ -105,7 +105,7 @@ static void dyn2_execute(void) {
(threads[2] != NULL) &&
(threads[3] != NULL) &&
(threads[4] != NULL),
"thread creation failed");
"#1"); /* Thread creation failed.*/
/* Claiming the memory from terminated threads. */
test_wait_threads();
@ -113,8 +113,8 @@ static void dyn2_execute(void) {
/* Now the pool must be full again. */
for (i = 0; i < 5; i++)
test_assert(chPoolAlloc(&mp1) != NULL, "pool list empty");
test_assert(chPoolAlloc(&mp1) == NULL, "pool list not empty");
test_assert(chPoolAlloc(&mp1) != NULL, "#2"); /* Pool list empty.*/
test_assert(chPoolAlloc(&mp1) == NULL, "#3"); /* Pool list not empty.*/
}
const struct testcase testdyn2 = {

View File

@ -55,20 +55,20 @@ static void evt1_execute(void) {
*/
chEvtPend(5);
m = chEvtWaitOne(ALL_EVENTS);
test_assert(m == 1, "chEvtWaitOne() error");
test_assert(m == 1, "#1"); /* Single bit error.*/
m = chEvtWaitOne(ALL_EVENTS);
test_assert(m == 4, "chEvtWaitOne() error");
test_assert(m == 4, "#2"); /* Single bit error.*/
m = chEvtClear(0);
test_assert(m == 0, "stuck event");
test_assert(m == 0, "#3"); /* Stuck event.*/
/*
* Test on chEvtWaitAny().
*/
chEvtPend(5);
m = chEvtWaitAny(ALL_EVENTS);
test_assert(m == 5, "chEvtWaitAny() error");
test_assert(m == 5, "#4"); /* Unexpected pending.*/
m = chEvtClear(0);
test_assert(m == 0, "stuck event");
test_assert(m == 0, "#5"); /* Stuck event.*/
/*
* Test on chEvtWaitAll(), chEvtRegisterMask() and chEvtUnregister().
@ -82,13 +82,13 @@ static void evt1_execute(void) {
m = chEvtWaitAll(5);
test_assert_time_window(target_time, target_time + ALLOWED_DELAY);
m = chEvtClear(0);
test_assert(m == 0, "stuck event");
test_assert(m == 0, "#6"); /* Stuck event.*/
test_wait_threads();
chEvtUnregister(&es1, &el1);
chEvtUnregister(&es2, &el2);
test_assert(!chEvtIsListening(&es1), "stuck listener");
test_assert(!chEvtIsListening(&es2), "stuck listener");
test_assert(!chEvtIsListening(&es1), "#7"); /* Stuck listener.*/
test_assert(!chEvtIsListening(&es2), "#8"); /* Stuck listener.*/
}
const struct testcase testevt1 = {

View File

@ -47,7 +47,7 @@ static void heap1_execute(void) {
chHeapFree(p1); /* Does not merge */
chHeapFree(p2); /* Merges backward */
chHeapFree(p3); /* Merges both sides */
test_assert(chHeapStatus(&n) == 1, "heap fragmented #1");
test_assert(chHeapStatus(&n) == 1, "#1"); /* Heap fragmented.*/
/* Reverse order */
p1 = chHeapAlloc(SIZE);
@ -56,9 +56,9 @@ static void heap1_execute(void) {
chHeapFree(p3); /* Merges forward */
chHeapFree(p2); /* Merges forward */
chHeapFree(p1); /* Merges forward */
test_assert(chHeapStatus(&n) == 1, "heap fragmented #2");
test_assert(chHeapStatus(&n) == 1, "#2"); /* Heap fragmented.*/
test_assert(n == sz, "heap size changed");
test_assert(n == sz, "#3"); /* Heap size changed.*/
}
else {
test_print("--- Size : ");

101
test/testmbox.c Normal file
View File

@ -0,0 +1,101 @@
/*
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 CH_USE_MAILBOXES && CH_USE_SEMAPHORES_TIMEOUT
#define ALLOWED_DELAY MS2ST(5)
#define MB_SIZE 5
static msg_t mb1_buf[MB_SIZE];
static Mailbox mb1;
static char *mbox1_gettest(void) {
return "Mailboxes, queuing and timeouts";
}
static void mbox1_setup(void) {
chMBInit(&mb1, mb1_buf, MB_SIZE);
}
static void mbox1_execute(void) {
msg_t msg1, msg2;
unsigned i;
/* Testing initial space.*/
test_assert(chMBGetEmpty(&mb1) == MB_SIZE, "#1");
/* Testing enqueuing.*/
for (i = 0; i < MB_SIZE - 1; i++) {
msg1 = chMBPost(&mb1, 'B' + i, TIME_INFINITE);
test_assert(msg1 == RDY_OK, "#2");
}
msg1 = chMBPostAhead(&mb1, 'A', TIME_INFINITE);
test_assert(msg1 == RDY_OK, "#3");
/* Testing post timeout.*/
msg1 = chMBPost(&mb1, 'X', 1);
test_assert(msg1 == RDY_TIMEOUT, "#4");
/* Testing final conditions.*/
test_assert(chMBGetEmpty(&mb1) == 0, "#5");
test_assert(chMBGetFull(&mb1) == MB_SIZE, "#6");
test_assert(mb1.mb_rdptr == mb1.mb_wrptr, "#7");
/* Testing dequeuing.*/
for (i = 0; i < MB_SIZE; i++) {
msg1 = chMBFetch(&mb1, &msg2, TIME_INFINITE);
test_assert(msg1 == RDY_OK, "#8");
test_emit_token(msg2);
}
test_assert_sequence("ABCDE");
/* Testing fetch timeout.*/
msg1 = chMBFetch(&mb1, &msg2, 1);
test_assert(msg1 == RDY_TIMEOUT, "#9");
/* Testing final conditions.*/
test_assert(chMBGetEmpty(&mb1) == MB_SIZE, "#10");
test_assert(chMBGetFull(&mb1) == 0, "#11");
test_assert(mb1.mb_rdptr == mb1.mb_wrptr, "#12");
}
const struct testcase testmbox1 = {
mbox1_gettest,
mbox1_setup,
NULL,
mbox1_execute
};
#endif /* CH_USE_MAILBOXES && CH_USE_SEMAPHORES_TIMEOUT */
/*
* Test sequence for mailboxes pattern.
*/
const struct testcase *patternmbox[] = {
#if CH_USE_MAILBOXES && CH_USE_SEMAPHORES_TIMEOUT
&testmbox1,
#endif
NULL
};

25
test/testmbox.h Normal file
View File

@ -0,0 +1,25 @@
/*
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 _TESTMBOX_H_
#define _TESTMBOX_H_
extern const struct testcase *patternmbox[];
#endif /* _TESTMBOX_H_ */

View File

@ -56,7 +56,7 @@ static void mtx1_execute(void) {
threads[4] = chThdCreateStatic(wa[4], WA_SIZE, prio+5, thread1, "A");
chMtxUnlock();
test_wait_threads();
test_assert(prio == chThdGetPriority(), "priority return failure");
test_assert(prio == chThdGetPriority(), "#1"); /* Priority return failure.*/
test_assert_sequence("ABCDE");
}

View File

@ -44,10 +44,10 @@ static void pools1_execute(void) {
/* Empting the pool again. */
for (i = 0; i < MAX_THREADS; i++)
test_assert(chPoolAlloc(&mp1) != NULL, "pool list empty");
test_assert(chPoolAlloc(&mp1) != NULL, "#1"); /* Pool list empty.*/
/* Now must be empty. */
test_assert(chPoolAlloc(&mp1) == NULL, "pool list not empty");
test_assert(chPoolAlloc(&mp1) == NULL, "#2"); /* Pool list not empty.*/
}
const struct testcase testpools1 = {

View File

@ -86,8 +86,8 @@ static void sem2_execute(void) {
for (i = 0; i < 5; i++) {
test_emit_token('A' + i);
chSemWaitTimeout(&sem1, MS2ST(500));
test_assert(isempty(&sem1.s_queue), "queue not empty");
test_assert(&sem1.s_cnt != 0, "counter not zero");
test_assert(isempty(&sem1.s_queue), "#1"); /* Queue not empty */
test_assert(&sem1.s_cnt != 0, "#2"); /* Counter not zero */
}
test_assert_sequence("ABCDE");
test_assert_time_window(target_time, target_time + ALLOWED_DELAY);

View File

@ -1,27 +1,22 @@
After 1.0.0:
X Improve makefiles by adding an options head section and making it shared.
- Update C++ wrapper (Heap, Pools).
* Queues macros should not refer to the semaphore counters directly.
* Priority ordering option for semaphores.
* chSysLock() and chSysUnlock() with counter (option).
* OSEK-style chSysSuspendAll()/chSysResumeAll()/chSysEnable()/chSysDisable(),
implemented this as the new Suspended and Disabled states in 1.1.
X lwIP TCP/IP stack integration and demo.
X "Wide Queues" or Mailboxes, lwIP requires them.
X FatFS library integration and demo.
* Mailboxes subsystem (lwIP requires them).
* Multiple debug switches.
X Stack checks option.
* Threads profiling option.
- Objects registry.
* Idle loop hook macro.
* Switch the configuration options to TRUE/FALSE rather than def/undef.
After 1.2.0:
- Threads Pools manager in the library.
- New chThdCreate() that takes just two parameters, a pointer to a thread
descriptor and the tread parameter. It could wrap the current variants
or just be an alternative.
- Fix the names of the Queues macros, also do not refer to the semaphore
counters directly.
After 1.2.0:
- Minimal optional C-runtime library (complete enough for lwIP).
- OSEK-style simple tasks within the idle thread.
- Think to something for threads restart.
@ -30,6 +25,7 @@ After 1.2.0:
- Move the serial drivers implementations in library al keep the I/O channel
interface as part of the kernel. Better keep the core as compact as
possible.
- Update C++ wrapper (Heap, Pools, Mailboxes and any new feature).
Ideas for 2.x.x:
- Reference counter for threads, concept of detached threads, threads
@ -38,12 +34,15 @@ Ideas for 2.x.x:
- Multicore support.
Side projects:
X lwIP TCP/IP stack integration and demo.
X FatFS library integration and demo.
X ChibiOS Wizard, UML modeling and ChibiOS applications code and
documentation generator.
X OSEK layer.
- Posix layer.
X File System
- Visual debugger interfaced to OpenOCD.
- Objects registry.
Lower priority:
- More demos