Fixed bug 2789383.

git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/stable_1.2.x@958 35acf78f-673a-0410-8e92-d51de3d6d3f4
This commit is contained in:
gdisirio 2009-05-09 14:54:51 +00:00
parent 49759995f6
commit b3a622c720
4 changed files with 82 additions and 58 deletions

View File

@ -64,6 +64,7 @@ Win32-MinGW - ChibiOS/RT simulator and demo into a WIN32 process,
- FIX: Fixed macro in test.h (bug 2781176). - FIX: Fixed macro in test.h (bug 2781176).
- FIX: Fixed @file tag in sam7x_serial.c (bug 2788573). - FIX: Fixed @file tag in sam7x_serial.c (bug 2788573).
- FIX: Fixed sequence assertion in test.c (bug 2789377). - FIX: Fixed sequence assertion in test.c (bug 2789377).
- FIX: Fixed test_cpu_pulse() incorrect behavior (bug 2789383).
*** 1.2.1 *** *** 1.2.1 ***
- FIX: Fixed regression in MinGW demo (bug 2745153). - FIX: Fixed regression in MinGW demo (bug 2745153).

View File

@ -176,16 +176,17 @@ void test_wait_threads(void) {
chThdWait(threads[i]); chThdWait(threads[i]);
} }
void test_cpu_pulse(unsigned ms) { #if CH_DBG_THREADS_PROFILING
void test_cpu_pulse(unsigned duration) {
systime_t duration = MS2ST(ms); systime_t end = chThdSelf()->p_time + MS2ST(duration);
systime_t start = chTimeNow(); while (chThdSelf()->p_time < end) {
while (chTimeIsWithin(start, start + duration)) {
#if defined(WIN32) #if defined(WIN32)
ChkIntSources(); ChkIntSources();
#endif #endif
} }
} }
#endif
systime_t test_wait_tick(void) { systime_t test_wait_tick(void) {

View File

@ -69,8 +69,10 @@ extern "C" {
void test_terminate_threads(void); void test_terminate_threads(void);
void test_wait_threads(void); void test_wait_threads(void);
systime_t test_wait_tick(void); systime_t test_wait_tick(void);
void test_cpu_pulse(unsigned ms);
void test_start_timer(unsigned ms); void test_start_timer(unsigned ms);
#if CH_DBG_THREADS_PROFILING
void test_cpu_pulse(unsigned duration);
#endif
#if defined(WIN32) #if defined(WIN32)
void ChkIntSources(void); void ChkIntSources(void);
#endif #endif

View File

@ -75,6 +75,7 @@ const struct testcase testmtx1 = {
mtx1_execute mtx1_execute
}; };
#if CH_DBG_THREADS_PROFILING
static char *mtx2_gettest(void) { static char *mtx2_gettest(void) {
return "Mutexes, priority inheritance, simple case"; return "Mutexes, priority inheritance, simple case";
@ -85,45 +86,54 @@ static void mtx2_setup(void) {
chMtxInit(&m1); chMtxInit(&m1);
} }
static msg_t thread2(void *p) { /* Low priority thread */
static msg_t thread2L(void *p) {
chThdSleepMilliseconds(10);
chMtxLock(&m1); chMtxLock(&m1);
test_cpu_pulse(40);
chMtxUnlock(); chMtxUnlock();
test_emit_token(*(char *)p); test_cpu_pulse(10);
test_emit_token('C');
return 0; return 0;
} }
static msg_t thread3(void *p) { /* Medium priority thread */
static msg_t thread2M(void *p) {
chMtxLock(&m1);
chThdSleepMilliseconds(40);
chMtxUnlock();
test_emit_token(*(char *)p);
return 0;
}
static msg_t thread4(void *p) {
chThdSleepMilliseconds(20); chThdSleepMilliseconds(20);
test_cpu_pulse(50); test_cpu_pulse(40);
test_emit_token(*(char *)p); test_emit_token('B');
return 0;
}
/* High priority thread */
static msg_t thread2H(void *p) {
chThdSleepMilliseconds(40);
chMtxLock(&m1);
test_cpu_pulse(10);
chMtxUnlock();
test_emit_token('A');
return 0; return 0;
} }
/* /*
* Time * Time ----> 0 10 20 30 40 50 60 70 80 90 100
* 0 ++++++++++++++++++AL+....2++++++++++++++AU0------------------------------ * 0 ......AL++++++++++............2+++++++++++AU0---------------++++++G...
* 1 .....................++-------------------------------------------------- * 1 ..................++++++++++++------------------++++++++++++G.........
* 2 .......................++AL.............+++++++++AU++++++++++++++++++++++ * 2 .............................AL..........++++++AUG...................
*/ */
static void mtx2_execute(void) { static void mtx2_execute(void) {
systime_t time;
threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriority()-1, thread2, "A"); test_wait_tick();
threads[1] = chThdCreateStatic(wa[1], WA_SIZE, chThdGetPriority()-3, thread3, "C"); time = chTimeNow();
threads[2] = chThdCreateStatic(wa[2], WA_SIZE, chThdGetPriority()-2, thread4, "B"); threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriority()-1, thread2H, 0);
threads[1] = chThdCreateStatic(wa[1], WA_SIZE, chThdGetPriority()-2, thread2M, 0);
threads[2] = chThdCreateStatic(wa[2], WA_SIZE, chThdGetPriority()-3, thread2L, 0);
test_wait_threads(); test_wait_threads();
test_assert_sequence("ABC"); test_assert_sequence(1, "ABC");
test_assert_time_window(2, time + MS2ST(100), time + MS2ST(100) + ALLOWED_DELAY);
} }
const struct testcase testmtx2 = { const struct testcase testmtx2 = {
@ -140,78 +150,87 @@ static char *mtx3_gettest(void) {
static void mtx3_setup(void) { static void mtx3_setup(void) {
chMtxInit(&m1); chMtxInit(&m1); // Mutex B
chMtxInit(&m2); chMtxInit(&m2); // Mutex A
} }
static msg_t thread5(void *p) { /* Lowest priority thread */
static msg_t thread3LL(void *p) {
chMtxLock(&m1); chMtxLock(&m1);
test_cpu_pulse(50); test_cpu_pulse(30);
chMtxUnlock(); chMtxUnlock();
test_emit_token(*(char *)p); test_emit_token('E');
return 0; return 0;
} }
static msg_t thread6(void *p) { /* Low priority thread */
static msg_t thread3L(void *p) {
chThdSleepMilliseconds(10); chThdSleepMilliseconds(10);
chMtxLock(&m2); chMtxLock(&m2);
test_cpu_pulse(20); test_cpu_pulse(20);
chMtxLock(&m1); chMtxLock(&m1);
test_cpu_pulse(50); test_cpu_pulse(10);
chMtxUnlock(); chMtxUnlock();
test_cpu_pulse(20); test_cpu_pulse(10);
chMtxUnlock(); chMtxUnlock();
test_emit_token(*(char *)p); test_emit_token('D');
return 0; return 0;
} }
static msg_t thread7(void *p) { /* Medium priority thread */
static msg_t thread3M(void *p) {
chThdSleepMilliseconds(20); chThdSleepMilliseconds(20);
chMtxLock(&m2); chMtxLock(&m2);
test_cpu_pulse(50); test_cpu_pulse(10);
chMtxUnlock(); chMtxUnlock();
test_emit_token(*(char *)p); test_emit_token('C');
return 0; return 0;
} }
static msg_t thread8(void *p) { /* High priority thread */
static msg_t thread3H(void *p) {
chThdSleepMilliseconds(40); chThdSleepMilliseconds(40);
test_cpu_pulse(200); test_cpu_pulse(20);
test_emit_token(*(char *)p); test_emit_token('B');
return 0; return 0;
} }
static msg_t thread9(void *p) { /* Highest priority thread */
static msg_t thread3HH(void *p) {
chThdSleepMilliseconds(50); chThdSleepMilliseconds(50);
chMtxLock(&m2); chMtxLock(&m2);
test_cpu_pulse(50); test_cpu_pulse(10);
chMtxUnlock(); chMtxUnlock();
test_emit_token(*(char *)p); test_emit_token('A');
return 0; return 0;
} }
/* /*
* Time 0 10 20 30 40 50 * Time ----> 0 10 20 30 40 50 60 70 80 90 100 110
* 0 +++BL++------------------2++++------4+++++BU0-------------------------- * 0 ......BL++++------------2+++++------4+++++BU0---------------------------G.....
* 1 .......++AL++--2+++++++++BL.........4.....++++++++BU4++++AU1----------- * 1 ............AL++++2+++++BL----------4-----++++++BU4+++AU1---------------G.....
* 2 .............++AL............................................------++AU * 2 ..................AL----------------------------------------------++++++AUG...
* 3 ..............................++++-------------------------------++.... * 3 ..............................+++++++-----------------------++++++G...........
* 4 ..................................++AL...................++++AU++...... * 4 ....................................AL................++++++AUG...............
*/ */
static void mtx3_execute(void) { static void mtx3_execute(void) {
systime_t time;
threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriority()-5, thread5, "E"); test_wait_tick();
threads[1] = chThdCreateStatic(wa[1], WA_SIZE, chThdGetPriority()-4, thread6, "D"); time = chTimeNow();
threads[2] = chThdCreateStatic(wa[2], WA_SIZE, chThdGetPriority()-3, thread7, "C"); threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriority()-5, thread3LL, 0);
threads[3] = chThdCreateStatic(wa[3], WA_SIZE, chThdGetPriority()-2, thread8, "B"); threads[1] = chThdCreateStatic(wa[1], WA_SIZE, chThdGetPriority()-4, thread3L, 0);
threads[4] = chThdCreateStatic(wa[4], WA_SIZE, chThdGetPriority()-1, thread9, "A"); threads[2] = chThdCreateStatic(wa[2], WA_SIZE, chThdGetPriority()-3, thread3M, 0);
threads[3] = chThdCreateStatic(wa[3], WA_SIZE, chThdGetPriority()-2, thread3H, 0);
threads[4] = chThdCreateStatic(wa[4], WA_SIZE, chThdGetPriority()-1, thread3HH, 0);
test_wait_threads(); test_wait_threads();
test_assert_sequence("ABCDE"); test_assert_sequence(1, "ABCDE");
test_assert_time_window(2, time + MS2ST(110), time + MS2ST(110) + ALLOWED_DELAY);
} }
const struct testcase testmtx3 = { const struct testcase testmtx3 = {
@ -220,6 +239,7 @@ const struct testcase testmtx3 = {
NULL, NULL,
mtx3_execute mtx3_execute
}; };
#endif /* CH_DBG_THREADS_PROFILING */
#if CH_USE_CONDVARS #if CH_USE_CONDVARS
static char *mtx4_gettest(void) { static char *mtx4_gettest(void) {