2008-06-26 10:54:55 +00:00
|
|
|
/*
|
|
|
|
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"
|
|
|
|
|
|
|
|
static msg_t thread(void *p) {
|
|
|
|
|
|
|
|
test_emit_token(*(char *)p);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-04-13 08:15:51 +00:00
|
|
|
static char *thd1_gettest(void) {
|
2008-06-26 10:54:55 +00:00
|
|
|
|
2009-04-13 08:15:51 +00:00
|
|
|
return "Threads, enqueuing test #1";
|
2008-06-26 10:54:55 +00:00
|
|
|
}
|
|
|
|
|
2009-04-13 08:15:51 +00:00
|
|
|
static void thd1_execute(void) {
|
2008-06-26 10:54:55 +00:00
|
|
|
|
2008-11-29 10:54:24 +00:00
|
|
|
threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriority()-5, thread, "E");
|
|
|
|
threads[1] = chThdCreateStatic(wa[1], WA_SIZE, chThdGetPriority()-4, thread, "D");
|
|
|
|
threads[2] = chThdCreateStatic(wa[2], WA_SIZE, chThdGetPriority()-3, thread, "C");
|
|
|
|
threads[3] = chThdCreateStatic(wa[3], WA_SIZE, chThdGetPriority()-2, thread, "B");
|
|
|
|
threads[4] = chThdCreateStatic(wa[4], WA_SIZE, chThdGetPriority()-1, thread, "A");
|
2008-06-26 10:54:55 +00:00
|
|
|
test_wait_threads();
|
2009-04-25 11:12:10 +00:00
|
|
|
test_assert_sequence(1, "ABCDE");
|
2008-06-26 10:54:55 +00:00
|
|
|
}
|
|
|
|
|
2009-04-13 08:15:51 +00:00
|
|
|
const struct testcase testthd1 = {
|
|
|
|
thd1_gettest,
|
2009-02-16 18:22:49 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2009-04-13 08:15:51 +00:00
|
|
|
thd1_execute
|
2008-06-26 10:54:55 +00:00
|
|
|
};
|
|
|
|
|
2009-04-13 08:15:51 +00:00
|
|
|
static char *thd2_gettest(void) {
|
2008-06-26 10:54:55 +00:00
|
|
|
|
2009-04-13 08:15:51 +00:00
|
|
|
return "Threads, enqueuing test #2";
|
2008-06-26 10:54:55 +00:00
|
|
|
}
|
|
|
|
|
2009-04-13 08:15:51 +00:00
|
|
|
static void thd2_execute(void) {
|
2008-06-26 10:54:55 +00:00
|
|
|
|
2008-11-29 10:54:24 +00:00
|
|
|
threads[1] = chThdCreateStatic(wa[1], WA_SIZE, chThdGetPriority()-4, thread, "D");
|
|
|
|
threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriority()-5, thread, "E");
|
|
|
|
threads[4] = chThdCreateStatic(wa[4], WA_SIZE, chThdGetPriority()-1, thread, "A");
|
|
|
|
threads[3] = chThdCreateStatic(wa[3], WA_SIZE, chThdGetPriority()-2, thread, "B");
|
|
|
|
threads[2] = chThdCreateStatic(wa[2], WA_SIZE, chThdGetPriority()-3, thread, "C");
|
2008-06-26 10:54:55 +00:00
|
|
|
test_wait_threads();
|
2009-04-25 11:12:10 +00:00
|
|
|
test_assert_sequence(1, "ABCDE");
|
2008-06-26 10:54:55 +00:00
|
|
|
}
|
|
|
|
|
2009-04-13 08:15:51 +00:00
|
|
|
const struct testcase testthd2 = {
|
|
|
|
thd2_gettest,
|
2009-02-16 18:22:49 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2009-04-13 08:15:51 +00:00
|
|
|
thd2_execute
|
|
|
|
};
|
|
|
|
|
|
|
|
static char *thd3_gettest(void) {
|
|
|
|
|
|
|
|
return "Threads, priority change";
|
|
|
|
}
|
|
|
|
|
|
|
|
static void thd3_execute(void) {
|
|
|
|
tprio_t prio, p1;
|
|
|
|
|
|
|
|
prio = chThdGetPriority();
|
|
|
|
p1 = chThdSetPriority(prio + 1);
|
2009-04-25 11:12:10 +00:00
|
|
|
test_assert(1, p1 == prio,
|
|
|
|
"unexpected returned priority level");
|
|
|
|
test_assert(2, chThdGetPriority() == prio + 1,
|
|
|
|
"unexpected priority level");
|
2009-04-13 08:15:51 +00:00
|
|
|
p1 = chThdSetPriority(p1);
|
2009-04-25 11:12:10 +00:00
|
|
|
test_assert(3, p1 == prio + 1,
|
|
|
|
"unexpected returned priority level");
|
|
|
|
test_assert(4, chThdGetPriority() == prio,
|
|
|
|
"unexpected priority level");
|
2009-04-16 15:06:49 +00:00
|
|
|
|
|
|
|
#if CH_USE_MUTEXES
|
|
|
|
/* Simulates a priority boost situation (p_prio > p_realprio).*/
|
|
|
|
chSysLock();
|
|
|
|
chThdSelf()->p_prio += 2;
|
|
|
|
chSysUnlock();
|
2009-04-25 11:12:10 +00:00
|
|
|
test_assert(5, chThdGetPriority() == prio + 2,
|
|
|
|
"unexpected priority level");
|
|
|
|
|
2009-04-16 15:06:49 +00:00
|
|
|
/* Tries to raise but below the boost level. */
|
|
|
|
p1 = chThdSetPriority(prio + 1);
|
2009-04-25 11:12:10 +00:00
|
|
|
test_assert(6, p1 == prio,
|
|
|
|
"unexpected returned priority level");
|
|
|
|
test_assert(7, chThdSelf()->p_prio == prio + 2,
|
|
|
|
"unexpected priority level");
|
|
|
|
test_assert(8, chThdSelf()->p_realprio == prio + 1,
|
|
|
|
"unexpected returned real priority level");
|
2009-04-16 15:06:49 +00:00
|
|
|
|
|
|
|
/* Tries to raise above the boost level. */
|
|
|
|
p1 = chThdSetPriority(prio + 3);
|
2009-04-25 11:12:10 +00:00
|
|
|
test_assert(9, p1 == prio + 1,
|
|
|
|
"unexpected returned priority level");
|
|
|
|
test_assert(10, chThdSelf()->p_prio == prio + 3,
|
|
|
|
"unexpected priority level");
|
|
|
|
test_assert(11, chThdSelf()->p_realprio == prio + 3,
|
|
|
|
"unexpected real priority level");
|
2009-04-16 15:06:49 +00:00
|
|
|
|
|
|
|
chSysLock();
|
|
|
|
chThdSelf()->p_prio = prio;
|
|
|
|
chThdSelf()->p_realprio = prio;
|
|
|
|
chSysUnlock();
|
|
|
|
#endif
|
2009-04-13 08:15:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const struct testcase testthd3 = {
|
|
|
|
thd3_gettest,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
thd3_execute
|
|
|
|
};
|
|
|
|
|
|
|
|
static char *thd4_gettest(void) {
|
|
|
|
|
|
|
|
return "Threads, delays";
|
|
|
|
}
|
|
|
|
|
|
|
|
static void thd4_execute(void) {
|
|
|
|
systime_t time;
|
|
|
|
|
2009-04-17 14:53:04 +00:00
|
|
|
test_wait_tick();
|
|
|
|
|
2009-04-13 08:15:51 +00:00
|
|
|
/* Timeouts in microseconds.*/
|
|
|
|
time = chTimeNow();
|
|
|
|
chThdSleepMicroseconds(100000);
|
2009-04-25 11:12:10 +00:00
|
|
|
test_assert_time_window(1, time + US2ST(100000), time + US2ST(100000) + 1);
|
2009-04-13 08:15:51 +00:00
|
|
|
|
|
|
|
/* Timeouts in milliseconds.*/
|
|
|
|
time = chTimeNow();
|
|
|
|
chThdSleepMilliseconds(100);
|
2009-04-25 11:12:10 +00:00
|
|
|
test_assert_time_window(2, time + MS2ST(100), time + MS2ST(100) + 1);
|
2009-04-13 08:15:51 +00:00
|
|
|
|
|
|
|
/* Timeouts in seconds.*/
|
|
|
|
time = chTimeNow();
|
|
|
|
chThdSleepSeconds(1);
|
2009-04-25 11:12:10 +00:00
|
|
|
test_assert_time_window(3, time + S2ST(1), time + S2ST(1) + 1);
|
2009-04-13 08:15:51 +00:00
|
|
|
|
|
|
|
/* Absolute timelines.*/
|
|
|
|
time = chTimeNow() + MS2ST(100);
|
|
|
|
chThdSleepUntil(time);
|
2009-04-25 11:12:10 +00:00
|
|
|
test_assert_time_window(4, time, time + 1);
|
2009-04-13 08:15:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const struct testcase testthd4 = {
|
|
|
|
thd4_gettest,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
thd4_execute
|
2008-06-26 10:54:55 +00:00
|
|
|
};
|
2009-02-16 18:22:49 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Test sequence for ready list pattern.
|
|
|
|
*/
|
2009-04-13 08:15:51 +00:00
|
|
|
const struct testcase * const patternthd[] = {
|
|
|
|
&testthd1,
|
|
|
|
&testthd2,
|
|
|
|
&testthd3,
|
|
|
|
&testthd4,
|
2009-02-16 18:22:49 +00:00
|
|
|
NULL
|
|
|
|
};
|