Added more test cases.

git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@896 35acf78f-673a-0410-8e92-d51de3d6d3f4
This commit is contained in:
gdisirio 2009-04-12 13:00:42 +00:00
parent 9becc21691
commit 97817eb7dc
3 changed files with 128 additions and 25 deletions

View File

@ -84,8 +84,8 @@ Win32-MinGW - ChibiOS/RT simulator and demo into a WIN32 process,
- FIX: Removed usused list functions (bug 2755230)(backported in stable
branch).
- NEW: Added a code coverage analysis application under ./tests/coverage.
Currently the test suite explicitly covers about 74% of the kernel code,
it is not bad as a starting point.
- Added more test cases in order to improve code coverage (it was 74% in
version 1.2.0).
*** 1.2.0 ***
- Added license exception text to the 1.2.0 branch.

View File

@ -164,8 +164,10 @@ void test_wait_threads(void) {
int i;
for (i = 0; i < MAX_THREADS; i++)
if (threads[i])
if (threads[i] != NULL) {
chThdWait(threads[i]);
threads[i] = NULL;
}
}
void test_cpu_pulse(unsigned ms) {
@ -222,6 +224,8 @@ static void execute_test(const struct testcase *tcp) {
tcp->execute();
if (tcp->teardown != NULL)
tcp->teardown();
test_wait_threads();
}
msg_t TestThread(void *p) {

View File

@ -214,13 +214,110 @@ const struct testcase testmtx3 = {
mtx3_execute
};
#if CH_USE_CONDVARS
static char *mtx4_gettest(void) {
return "Mutexes, priority return";
}
static void mtx4_setup(void) {
chMtxInit(&m1);
chMtxInit(&m2);
}
static msg_t thread13(void *p) {
chThdSleepMilliseconds(50);
chMtxLock(&m2);
chMtxUnlock();
return 0;
}
static msg_t thread14(void *p) {
chThdSleepMilliseconds(150);
chMtxLock(&m1);
chMtxUnlock();
return 0;
}
static void mtx4_execute(void) {
tprio_t p, p1, p2;
p = chThdGetPriority();
p1 = p + 1;
p2 = p + 2;
threads[0] = chThdCreateStatic(wa[0], WA_SIZE, p1, thread13, "B");
threads[1] = chThdCreateStatic(wa[1], WA_SIZE, p2, thread14, "A");
chMtxLock(&m2);
test_assert(chThdGetPriority() == p, "#1");
chThdSleepMilliseconds(100);
test_assert(chThdGetPriority() == p1, "#2");
chMtxLock(&m1);
test_assert(chThdGetPriority() == p1, "#3");
chThdSleepMilliseconds(100);
test_assert(chThdGetPriority() == p2, "#4");
chMtxUnlock();
test_assert(chThdGetPriority() == p1, "#5");
chThdSleepMilliseconds(100);
test_assert(chThdGetPriority() == p1, "#6");
chMtxUnlockAll();
test_assert(chThdGetPriority() == p, "#7");
test_wait_threads();
}
const struct testcase testmtx4 = {
mtx4_gettest,
mtx4_setup,
NULL,
mtx4_execute
};
static char *mtx5_gettest(void) {
return "Mutexes, coverage";
}
static void mtx5_setup(void) {
chMtxInit(&m1);
}
static void mtx5_execute(void) {
bool_t b;
tprio_t prio;
prio = chThdGetPriority();
b = chMtxTryLock(&m1);
test_assert(b, "#1");
b = chMtxTryLock(&m1);
test_assert(!b, "#2");
chSysLock();
chMtxUnlockS();
chSysUnlock();
test_assert(isempty(&m1.m_queue), "#3"); /* Queue not empty */
test_assert(m1.m_owner == NULL, "#4"); /* Owned */
test_assert(chThdGetPriority() == prio, "#5");
}
const struct testcase testmtx5 = {
mtx5_gettest,
mtx5_setup,
NULL,
mtx5_execute
};
#if CH_USE_CONDVARS
static char *mtx6_gettest(void) {
return "CondVar, signal test";
}
static void mtx4_setup(void) {
static void mtx6_setup(void) {
chCondInit(&c1);
chMtxInit(&m1);
@ -235,7 +332,7 @@ static msg_t thread10(void *p) {
return 0;
}
static void mtx4_execute(void) {
static void mtx6_execute(void) {
tprio_t prio = chThdGetPriority();
threads[0] = chThdCreateStatic(wa[0], WA_SIZE, prio+1, thread10, "E");
@ -252,25 +349,25 @@ static void mtx4_execute(void) {
test_assert_sequence("ABCDE");
}
const struct testcase testmtx4 = {
mtx4_gettest,
mtx4_setup,
const struct testcase testmtx6 = {
mtx6_gettest,
mtx6_setup,
NULL,
mtx4_execute
mtx6_execute
};
static char *mtx5_gettest(void) {
static char *mtx7_gettest(void) {
return "CondVar, broadcast test";
}
static void mtx5_setup(void) {
static void mtx7_setup(void) {
chCondInit(&c1);
chMtxInit(&m1);
}
static void mtx5_execute(void) {
static void mtx7_execute(void) {
// Bacause priority inheritance.
tprio_t prio = chThdGetPriority();
@ -284,19 +381,19 @@ static void mtx5_execute(void) {
test_assert_sequence("ABCDE");
}
const struct testcase testmtx5 = {
mtx5_gettest,
mtx5_setup,
const struct testcase testmtx7 = {
mtx7_gettest,
mtx7_setup,
NULL,
mtx5_execute
mtx7_execute
};
static char *mtx6_gettest(void) {
static char *mtx8_gettest(void) {
return "CondVar, inheritance boost test";
}
static void mtx6_setup(void) {
static void mtx8_setup(void) {
chCondInit(&c1);
chMtxInit(&m1);
@ -322,7 +419,7 @@ static msg_t thread12(void *p) {
return 0;
}
static void mtx6_execute(void) {
static void mtx8_execute(void) {
tprio_t prio = chThdGetPriority();
threads[0] = chThdCreateStatic(wa[0], WA_SIZE, prio+1, thread11, "A");
@ -334,11 +431,11 @@ static void mtx6_execute(void) {
test_assert_sequence("ABC");
}
const struct testcase testmtx6 = {
mtx6_gettest,
mtx6_setup,
const struct testcase testmtx8 = {
mtx8_gettest,
mtx8_setup,
NULL,
mtx6_execute
mtx8_execute
};
#endif /* CH_USE_CONDVARS */
#endif /* CH_USE_MUTEXES */
@ -351,10 +448,12 @@ const struct testcase * const patternmtx[] = {
&testmtx1,
&testmtx2,
&testmtx3,
#if CH_USE_CONDVARS
&testmtx4,
&testmtx5,
#if CH_USE_CONDVARS
&testmtx6,
&testmtx7,
&testmtx8,
#endif
#endif
NULL