diff options
author | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2011-08-12 11:10:19 +0000 |
---|---|---|
committer | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2011-08-12 11:10:19 +0000 |
commit | 43752ee8d132fc57028a9ff15156c5bfcd81c013 (patch) | |
tree | eb4a8eafaaac4084e1c0c307850a8ce17939e58f /os | |
parent | e0309ba9738efc707f8c43de43e04d2c62a32e8c (diff) | |
download | ChibiOS-43752ee8d132fc57028a9ff15156c5bfcd81c013.tar.gz ChibiOS-43752ee8d132fc57028a9ff15156c5bfcd81c013.tar.bz2 ChibiOS-43752ee8d132fc57028a9ff15156c5bfcd81c013.zip |
Extended state check to all kernel I-class and s-class APIs, corrected some test cases where call protocol rules were not strictly observerd. No the whole test suite pass with the state checker enabled.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3223 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os')
-rw-r--r-- | os/kernel/include/chdebug.h | 4 | ||||
-rw-r--r-- | os/kernel/src/chcond.c | 4 | ||||
-rw-r--r-- | os/kernel/src/chdebug.c | 34 | ||||
-rw-r--r-- | os/kernel/src/chevents.c | 2 | ||||
-rw-r--r-- | os/kernel/src/chmboxes.c | 6 | ||||
-rw-r--r-- | os/kernel/src/chmemcore.c | 2 | ||||
-rw-r--r-- | os/kernel/src/chmempools.c | 2 | ||||
-rw-r--r-- | os/kernel/src/chmtx.c | 3 | ||||
-rw-r--r-- | os/kernel/src/chqueues.c | 8 | ||||
-rw-r--r-- | os/kernel/src/chschd.c | 13 | ||||
-rw-r--r-- | os/kernel/src/chsem.c | 13 | ||||
-rw-r--r-- | os/kernel/src/chsys.c | 2 | ||||
-rw-r--r-- | os/kernel/src/chthreads.c | 2 | ||||
-rw-r--r-- | os/kernel/src/chvt.c | 2 |
14 files changed, 86 insertions, 11 deletions
diff --git a/os/kernel/include/chdebug.h b/os/kernel/include/chdebug.h index 3bfadb750..f3bf6b026 100644 --- a/os/kernel/include/chdebug.h +++ b/os/kernel/include/chdebug.h @@ -86,6 +86,8 @@ #define dbg_check_unlock_from_isr()
#define dbg_check_enter_isr()
#define dbg_check_leave_isr()
+#define chDbgCheckClassI();
+#define chDbgCheckClassS();
#endif
/*===========================================================================*/
@@ -211,6 +213,8 @@ extern "C" { void dbg_check_unlock_from_isr(void);
void dbg_check_enter_isr(void);
void dbg_check_leave_isr(void);
+ void chDbgCheckClassI(void);
+ void chDbgCheckClassS(void);
#endif
#if CH_DBG_ENABLE_TRACE || defined(__DOXYGEN__)
void _trace_init(void);
diff --git a/os/kernel/src/chcond.c b/os/kernel/src/chcond.c index 456fc454f..d1aeb75af 100644 --- a/os/kernel/src/chcond.c +++ b/os/kernel/src/chcond.c @@ -86,6 +86,7 @@ void chCondSignal(CondVar *cp) { */
void chCondSignalI(CondVar *cp) {
+ chDbgCheckClassI();
chDbgCheck(cp != NULL, "chCondSignalI");
if (notempty(&cp->c_queue))
@@ -120,6 +121,7 @@ void chCondBroadcast(CondVar *cp) { */
void chCondBroadcastI(CondVar *cp) {
+ chDbgCheckClassI();
chDbgCheck(cp != NULL, "chCondBroadcastI");
/* Empties the condition variable queue and inserts all the Threads into the
@@ -177,6 +179,7 @@ msg_t chCondWaitS(CondVar *cp) { Mutex *mp;
msg_t msg;
+ chDbgCheckClassS();
chDbgCheck(cp != NULL, "chCondWaitS");
chDbgAssert(ctp->p_mtxlist != NULL,
"chCondWaitS(), #1",
@@ -261,6 +264,7 @@ msg_t chCondWaitTimeoutS(CondVar *cp, systime_t time) { Mutex *mp;
msg_t msg;
+ chDbgCheckClassS();
chDbgCheck((cp != NULL) && (time != TIME_IMMEDIATE), "chCondWaitTimeoutS");
chDbgAssert(currp->p_mtxlist != NULL,
"chCondWaitTimeoutS(), #1",
diff --git a/os/kernel/src/chdebug.c b/os/kernel/src/chdebug.c index 28d4f7520..8fd081c05 100644 --- a/os/kernel/src/chdebug.c +++ b/os/kernel/src/chdebug.c @@ -35,6 +35,8 @@ * - SV#7, misplaced @p chSysUnlockFromIsr().
* - SV#8, misplaced @p CH_IRQ_PROLOGUE().
* - SV#9, misplaced @p CH_IRQ_EPILOGUE().
+ * - SV#10, misplaced I-class function.
+ * - SV#11, misplaced S-class function.
* .
* - Trace buffer.
* - Parameters check.
@@ -153,7 +155,7 @@ void dbg_check_unlock_from_isr(void) { void dbg_check_enter_isr(void) {
port_lock_from_isr();
- if (dbg_isr_cnt < 0)
+ if ((dbg_isr_cnt < 0) || (dbg_lock_cnt != 0))
chDbgPanic("SV#8");
dbg_isr_cnt++;
port_unlock_from_isr();
@@ -167,12 +169,40 @@ void dbg_check_enter_isr(void) { void dbg_check_leave_isr(void) {
port_lock_from_isr();
- if (dbg_isr_cnt <= 0)
+ if ((dbg_isr_cnt <= 0) || (dbg_lock_cnt != 0))
chDbgPanic("SV#9");
dbg_isr_cnt--;
port_unlock_from_isr();
}
+/**
+ * @brief I-class functions context check.
+ * @details Verifies that the system is in an appropriate state for invoking
+ * an I-class API function. A panic is generated if the state is
+ * not compatible.
+ *
+ * @api
+ */
+void chDbgCheckClassI(void) {
+
+ if ((dbg_isr_cnt < 0) || (dbg_lock_cnt <= 0))
+ chDbgPanic("SV#10");
+}
+
+/**
+ * @brief S-class functions context check.
+ * @details Verifies that the system is in an appropriate state for invoking
+ * an S-class API function. A panic is generated if the state is
+ * not compatible.
+ *
+ * @api
+ */
+void chDbgCheckClassS(void) {
+
+ if ((dbg_isr_cnt != 0) || (dbg_lock_cnt <= 0))
+ chDbgPanic("SV#11");
+}
+
#endif /* CH_DBG_SYSTEM_STATE_CHECK */
/*===========================================================================*/
diff --git a/os/kernel/src/chevents.c b/os/kernel/src/chevents.c index d74ad2dc4..7193e3a12 100644 --- a/os/kernel/src/chevents.c +++ b/os/kernel/src/chevents.c @@ -185,6 +185,7 @@ void chEvtSignalFlags(Thread *tp, eventmask_t mask) { */
void chEvtSignalFlagsI(Thread *tp, eventmask_t mask) {
+ chDbgCheckClassI();
chDbgCheck(tp != NULL, "chEvtSignalI");
tp->p_epending |= mask;
@@ -237,6 +238,7 @@ void chEvtBroadcastFlags(EventSource *esp, eventmask_t mask) { void chEvtBroadcastFlagsI(EventSource *esp, eventmask_t mask) {
EventListener *elp;
+ chDbgCheckClassI();
chDbgCheck(esp != NULL, "chEvtBroadcastMaskI");
elp = esp->es_next;
diff --git a/os/kernel/src/chmboxes.c b/os/kernel/src/chmboxes.c index af6ee5ea8..bf5fdfe29 100644 --- a/os/kernel/src/chmboxes.c +++ b/os/kernel/src/chmboxes.c @@ -143,6 +143,7 @@ msg_t chMBPost(Mailbox *mbp, msg_t msg, systime_t time) { msg_t chMBPostS(Mailbox *mbp, msg_t msg, systime_t time) {
msg_t rdymsg;
+ chDbgCheckClassS();
chDbgCheck(mbp != NULL, "chMBPostS");
rdymsg = chSemWaitTimeoutS(&mbp->mb_emptysem, time);
@@ -172,6 +173,7 @@ msg_t chMBPostS(Mailbox *mbp, msg_t msg, systime_t time) { */
msg_t chMBPostI(Mailbox *mbp, msg_t msg) {
+ chDbgCheckClassI();
chDbgCheck(mbp != NULL, "chMBPostI");
if (chSemGetCounterI(&mbp->mb_emptysem) <= 0)
@@ -234,6 +236,7 @@ msg_t chMBPostAhead(Mailbox *mbp, msg_t msg, systime_t time) { msg_t chMBPostAheadS(Mailbox *mbp, msg_t msg, systime_t time) {
msg_t rdymsg;
+ chDbgCheckClassS();
chDbgCheck(mbp != NULL, "chMBPostAheadS");
rdymsg = chSemWaitTimeoutS(&mbp->mb_emptysem, time);
@@ -263,6 +266,7 @@ msg_t chMBPostAheadS(Mailbox *mbp, msg_t msg, systime_t time) { */
msg_t chMBPostAheadI(Mailbox *mbp, msg_t msg) {
+ chDbgCheckClassI();
chDbgCheck(mbp != NULL, "chMBPostAheadI");
if (chSemGetCounterI(&mbp->mb_emptysem) <= 0)
@@ -325,6 +329,7 @@ msg_t chMBFetch(Mailbox *mbp, msg_t *msgp, systime_t time) { msg_t chMBFetchS(Mailbox *mbp, msg_t *msgp, systime_t time) {
msg_t rdymsg;
+ chDbgCheckClassS();
chDbgCheck((mbp != NULL) && (msgp != NULL), "chMBFetchS");
rdymsg = chSemWaitTimeoutS(&mbp->mb_fullsem, time);
@@ -354,6 +359,7 @@ msg_t chMBFetchS(Mailbox *mbp, msg_t *msgp, systime_t time) { */
msg_t chMBFetchI(Mailbox *mbp, msg_t *msgp) {
+ chDbgCheckClassI();
chDbgCheck((mbp != NULL) && (msgp != NULL), "chMBFetchI");
if (chSemGetCounterI(&mbp->mb_fullsem) <= 0)
diff --git a/os/kernel/src/chmemcore.c b/os/kernel/src/chmemcore.c index 311d170c5..0eac9a429 100644 --- a/os/kernel/src/chmemcore.c +++ b/os/kernel/src/chmemcore.c @@ -105,6 +105,8 @@ void *chCoreAlloc(size_t size) { void *chCoreAllocI(size_t size) {
void *p;
+ chDbgCheckClassI();
+
size = MEM_ALIGN_NEXT(size);
if ((size_t)(endmem - nextmem) < size)
return NULL;
diff --git a/os/kernel/src/chmempools.c b/os/kernel/src/chmempools.c index 38adc3d49..767bfda09 100644 --- a/os/kernel/src/chmempools.c +++ b/os/kernel/src/chmempools.c @@ -72,6 +72,7 @@ void chPoolInit(MemoryPool *mp, size_t size, memgetfunc_t provider) { void *chPoolAllocI(MemoryPool *mp) {
void *objp;
+ chDbgCheckClassI();
chDbgCheck(mp != NULL, "chPoolAllocI");
if ((objp = mp->mp_next) != NULL)
@@ -114,6 +115,7 @@ void *chPoolAlloc(MemoryPool *mp) { void chPoolFreeI(MemoryPool *mp, void *objp) {
struct pool_header *php = objp;
+ chDbgCheckClassI();
chDbgCheck((mp != NULL) && (objp != NULL) && MEM_IS_ALIGNED(objp),
"chPoolFreeI");
diff --git a/os/kernel/src/chmtx.c b/os/kernel/src/chmtx.c index 21b92e388..7d5bbe15e 100644 --- a/os/kernel/src/chmtx.c +++ b/os/kernel/src/chmtx.c @@ -114,6 +114,7 @@ void chMtxLock(Mutex *mp) { void chMtxLockS(Mutex *mp) {
Thread *ctp = currp;
+ chDbgCheckClassS();
chDbgCheck(mp != NULL, "chMtxLockS");
/* Ia the mutex already locked? */
@@ -225,6 +226,7 @@ bool_t chMtxTryLock(Mutex *mp) { */
bool_t chMtxTryLockS(Mutex *mp) {
+ chDbgCheckClassS();
chDbgCheck(mp != NULL, "chMtxTryLockS");
if (mp->m_owner != NULL)
@@ -309,6 +311,7 @@ Mutex *chMtxUnlockS(void) { Thread *ctp = currp;
Mutex *ump, *mp;
+ chDbgCheckClassS();
chDbgAssert(ctp->p_mtxlist != NULL,
"chMtxUnlockS(), #1",
"owned mutexes list empty");
diff --git a/os/kernel/src/chqueues.c b/os/kernel/src/chqueues.c index 8532f8307..cf3d21732 100644 --- a/os/kernel/src/chqueues.c +++ b/os/kernel/src/chqueues.c @@ -108,6 +108,8 @@ void chIQInit(InputQueue *iqp, uint8_t *bp, size_t size, qnotify_t infy) { */
void chIQResetI(InputQueue *iqp) {
+ chDbgCheckClassI();
+
iqp->q_rdptr = iqp->q_wrptr = iqp->q_buffer;
iqp->q_counter = 0;
while (notempty(&iqp->q_waiting))
@@ -129,6 +131,8 @@ void chIQResetI(InputQueue *iqp) { */
msg_t chIQPutI(InputQueue *iqp, uint8_t b) {
+ chDbgCheckClassI();
+
if (chIQIsFullI(iqp))
return Q_FULL;
@@ -284,6 +288,8 @@ void chOQInit(OutputQueue *oqp, uint8_t *bp, size_t size, qnotify_t onfy) { */
void chOQResetI(OutputQueue *oqp) {
+ chDbgCheckClassI();
+
oqp->q_rdptr = oqp->q_wrptr = oqp->q_buffer;
oqp->q_counter = chQSizeI(oqp);
while (notempty(&oqp->q_waiting))
@@ -349,6 +355,8 @@ msg_t chOQPutTimeout(OutputQueue *oqp, uint8_t b, systime_t time) { msg_t chOQGetI(OutputQueue *oqp) {
uint8_t b;
+ chDbgCheckClassI();
+
if (chOQIsEmptyI(oqp))
return Q_EMPTY;
diff --git a/os/kernel/src/chschd.c b/os/kernel/src/chschd.c index e989f4039..b481a0b6a 100644 --- a/os/kernel/src/chschd.c +++ b/os/kernel/src/chschd.c @@ -75,7 +75,8 @@ void _scheduler_init(void) { Thread *chSchReadyI(Thread *tp) {
Thread *cp;
- /* Integrity check.*/
+ /* Integrity checks.*/
+ chDbgCheckClassI();
chDbgAssert((tp->p_state != THD_STATE_READY) &&
(tp->p_state != THD_STATE_FINAL),
"chSchReadyI(), #1",
@@ -107,6 +108,8 @@ Thread *chSchReadyI(Thread *tp) { void chSchGoSleepS(tstate_t newstate) {
Thread *otp;
+ chDbgCheckClassS();
+
(otp = currp)->p_state = newstate;
#if CH_TIME_QUANTUM > 0
rlist.r_preempt = CH_TIME_QUANTUM;
@@ -173,6 +176,8 @@ static void wakeup(void *p) { */
msg_t chSchGoSleepTimeoutS(tstate_t newstate, systime_t time) {
+ chDbgCheckClassS();
+
if (TIME_INFINITE != time) {
VirtualTimer vt;
@@ -207,6 +212,8 @@ msg_t chSchGoSleepTimeoutS(tstate_t newstate, systime_t time) { #if !defined(PORT_OPTIMIZED_WAKEUPS) || defined(__DOXYGEN__)
void chSchWakeupS(Thread *ntp, msg_t msg) {
+ chDbgCheckClassS();
+
ntp->p_u.rdymsg = msg;
/* If the waken thread has a not-greater priority than the current
one then it is just inserted in the ready list else it made
@@ -237,6 +244,8 @@ void chSchWakeupS(Thread *ntp, msg_t msg) { void chSchDoRescheduleI(void) {
Thread *otp;
+ chDbgCheckClassI();
+
#if CH_TIME_QUANTUM > 0
rlist.r_preempt = CH_TIME_QUANTUM;
#endif
@@ -259,6 +268,8 @@ void chSchDoRescheduleI(void) { #if !defined(PORT_OPTIMIZED_RESCHEDULES) || defined(__DOXYGEN__)
void chSchRescheduleS(void) {
+ chDbgCheckClassS();
+
if (chSchIsRescRequiredI())
chSchDoRescheduleI();
}
diff --git a/os/kernel/src/chsem.c b/os/kernel/src/chsem.c index c22a568ea..bf985bead 100644 --- a/os/kernel/src/chsem.c +++ b/os/kernel/src/chsem.c @@ -129,8 +129,8 @@ void chSemReset(Semaphore *sp, cnt_t n) { void chSemResetI(Semaphore *sp, cnt_t n) {
cnt_t cnt;
+ chDbgCheckClassI();
chDbgCheck((sp != NULL) && (n >= 0), "chSemResetI");
-
chDbgAssert(((sp->s_cnt >= 0) && isempty(&sp->s_queue)) ||
((sp->s_cnt < 0) && notempty(&sp->s_queue)),
"chSemResetI(), #1",
@@ -177,8 +177,8 @@ msg_t chSemWait(Semaphore *sp) { */
msg_t chSemWaitS(Semaphore *sp) {
+ chDbgCheckClassS();
chDbgCheck(sp != NULL, "chSemWaitS");
-
chDbgAssert(((sp->s_cnt >= 0) && isempty(&sp->s_queue)) ||
((sp->s_cnt < 0) && notempty(&sp->s_queue)),
"chSemWaitS(), #1",
@@ -242,8 +242,8 @@ msg_t chSemWaitTimeout(Semaphore *sp, systime_t time) { */
msg_t chSemWaitTimeoutS(Semaphore *sp, systime_t time) {
+ chDbgCheckClassS();
chDbgCheck(sp != NULL, "chSemWaitTimeoutS");
-
chDbgAssert(((sp->s_cnt >= 0) && isempty(&sp->s_queue)) ||
((sp->s_cnt < 0) && notempty(&sp->s_queue)),
"chSemWaitTimeoutS(), #1",
@@ -271,7 +271,6 @@ msg_t chSemWaitTimeoutS(Semaphore *sp, systime_t time) { void chSemSignal(Semaphore *sp) {
chDbgCheck(sp != NULL, "chSemSignal");
-
chDbgAssert(((sp->s_cnt >= 0) && isempty(&sp->s_queue)) ||
((sp->s_cnt < 0) && notempty(&sp->s_queue)),
"chSemSignal(), #1",
@@ -296,8 +295,8 @@ void chSemSignal(Semaphore *sp) { */
void chSemSignalI(Semaphore *sp) {
+ chDbgCheckClassI();
chDbgCheck(sp != NULL, "chSemSignalI");
-
chDbgAssert(((sp->s_cnt >= 0) && isempty(&sp->s_queue)) ||
((sp->s_cnt < 0) && notempty(&sp->s_queue)),
"chSemSignalI(), #1",
@@ -327,8 +326,8 @@ void chSemSignalI(Semaphore *sp) { */
void chSemAddCounterI(Semaphore *sp, cnt_t n) {
+ chDbgCheckClassI();
chDbgCheck((sp != NULL) && (n > 0), "chSemAddCounterI");
-
chDbgAssert(((sp->s_cnt >= 0) && isempty(&sp->s_queue)) ||
((sp->s_cnt < 0) && notempty(&sp->s_queue)),
"chSemAddCounterI(), #1",
@@ -361,12 +360,10 @@ msg_t chSemSignalWait(Semaphore *sps, Semaphore *spw) { msg_t msg;
chDbgCheck((sps != NULL) && (spw != NULL), "chSemSignalWait");
-
chDbgAssert(((sps->s_cnt >= 0) && isempty(&sps->s_queue)) ||
((sps->s_cnt < 0) && notempty(&sps->s_queue)),
"chSemSignalWait(), #1",
"inconsistent semaphore");
-
chDbgAssert(((spw->s_cnt >= 0) && isempty(&spw->s_queue)) ||
((spw->s_cnt < 0) && notempty(&spw->s_queue)),
"chSemSignalWait(), #2",
diff --git a/os/kernel/src/chsys.c b/os/kernel/src/chsys.c index 6c63e113f..866ee81a8 100644 --- a/os/kernel/src/chsys.c +++ b/os/kernel/src/chsys.c @@ -128,6 +128,8 @@ void chSysInit(void) { */
void chSysTimerHandlerI(void) {
+ chDbgCheckClassI();
+
#if CH_TIME_QUANTUM > 0
/* Running thread has not used up quantum yet? */
if (rlist.r_preempt > 0)
diff --git a/os/kernel/src/chthreads.c b/os/kernel/src/chthreads.c index 182de7673..19accdb55 100644 --- a/os/kernel/src/chthreads.c +++ b/os/kernel/src/chthreads.c @@ -154,6 +154,8 @@ Thread *chThdCreateI(void *wsp, size_t size, /* Thread structure is layed out in the lower part of the thread workspace */
Thread *tp = wsp;
+ chDbgCheckClassI();
+
chDbgCheck((wsp != NULL) && (size >= THD_WA_SIZE(0)) &&
(prio <= HIGHPRIO) && (pf != NULL),
"chThdCreateI");
diff --git a/os/kernel/src/chvt.c b/os/kernel/src/chvt.c index 4674c728e..fb8e0b0c1 100644 --- a/os/kernel/src/chvt.c +++ b/os/kernel/src/chvt.c @@ -70,6 +70,7 @@ void _vt_init(void) { void chVTSetI(VirtualTimer *vtp, systime_t time, vtfunc_t vtfunc, void *par) {
VirtualTimer *p;
+ chDbgCheckClassI();
chDbgCheck((vtp != NULL) && (vtfunc != NULL) && (time != TIME_IMMEDIATE),
"chVTSetI");
@@ -98,6 +99,7 @@ void chVTSetI(VirtualTimer *vtp, systime_t time, vtfunc_t vtfunc, void *par) { */
void chVTResetI(VirtualTimer *vtp) {
+ chDbgCheckClassI();
chDbgCheck(vtp != NULL, "chVTResetI");
chDbgAssert(vtp->vt_func != NULL,
"chVTResetI(), #1",
|