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:
parent
9becc21691
commit
97817eb7dc
|
@ -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
|
- FIX: Removed usused list functions (bug 2755230)(backported in stable
|
||||||
branch).
|
branch).
|
||||||
- NEW: Added a code coverage analysis application under ./tests/coverage.
|
- NEW: Added a code coverage analysis application under ./tests/coverage.
|
||||||
Currently the test suite explicitly covers about 74% of the kernel code,
|
- Added more test cases in order to improve code coverage (it was 74% in
|
||||||
it is not bad as a starting point.
|
version 1.2.0).
|
||||||
|
|
||||||
*** 1.2.0 ***
|
*** 1.2.0 ***
|
||||||
- Added license exception text to the 1.2.0 branch.
|
- Added license exception text to the 1.2.0 branch.
|
||||||
|
|
|
@ -164,8 +164,10 @@ void test_wait_threads(void) {
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < MAX_THREADS; i++)
|
for (i = 0; i < MAX_THREADS; i++)
|
||||||
if (threads[i])
|
if (threads[i] != NULL) {
|
||||||
chThdWait(threads[i]);
|
chThdWait(threads[i]);
|
||||||
|
threads[i] = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_cpu_pulse(unsigned ms) {
|
void test_cpu_pulse(unsigned ms) {
|
||||||
|
@ -222,6 +224,8 @@ static void execute_test(const struct testcase *tcp) {
|
||||||
tcp->execute();
|
tcp->execute();
|
||||||
if (tcp->teardown != NULL)
|
if (tcp->teardown != NULL)
|
||||||
tcp->teardown();
|
tcp->teardown();
|
||||||
|
|
||||||
|
test_wait_threads();
|
||||||
}
|
}
|
||||||
|
|
||||||
msg_t TestThread(void *p) {
|
msg_t TestThread(void *p) {
|
||||||
|
|
143
test/testmtx.c
143
test/testmtx.c
|
@ -214,13 +214,110 @@ const struct testcase testmtx3 = {
|
||||||
mtx3_execute
|
mtx3_execute
|
||||||
};
|
};
|
||||||
|
|
||||||
#if CH_USE_CONDVARS
|
|
||||||
static char *mtx4_gettest(void) {
|
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";
|
return "CondVar, signal test";
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mtx4_setup(void) {
|
static void mtx6_setup(void) {
|
||||||
|
|
||||||
chCondInit(&c1);
|
chCondInit(&c1);
|
||||||
chMtxInit(&m1);
|
chMtxInit(&m1);
|
||||||
|
@ -235,7 +332,7 @@ static msg_t thread10(void *p) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mtx4_execute(void) {
|
static void mtx6_execute(void) {
|
||||||
|
|
||||||
tprio_t prio = chThdGetPriority();
|
tprio_t prio = chThdGetPriority();
|
||||||
threads[0] = chThdCreateStatic(wa[0], WA_SIZE, prio+1, thread10, "E");
|
threads[0] = chThdCreateStatic(wa[0], WA_SIZE, prio+1, thread10, "E");
|
||||||
|
@ -252,25 +349,25 @@ static void mtx4_execute(void) {
|
||||||
test_assert_sequence("ABCDE");
|
test_assert_sequence("ABCDE");
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct testcase testmtx4 = {
|
const struct testcase testmtx6 = {
|
||||||
mtx4_gettest,
|
mtx6_gettest,
|
||||||
mtx4_setup,
|
mtx6_setup,
|
||||||
NULL,
|
NULL,
|
||||||
mtx4_execute
|
mtx6_execute
|
||||||
};
|
};
|
||||||
|
|
||||||
static char *mtx5_gettest(void) {
|
static char *mtx7_gettest(void) {
|
||||||
|
|
||||||
return "CondVar, broadcast test";
|
return "CondVar, broadcast test";
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mtx5_setup(void) {
|
static void mtx7_setup(void) {
|
||||||
|
|
||||||
chCondInit(&c1);
|
chCondInit(&c1);
|
||||||
chMtxInit(&m1);
|
chMtxInit(&m1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mtx5_execute(void) {
|
static void mtx7_execute(void) {
|
||||||
|
|
||||||
// Bacause priority inheritance.
|
// Bacause priority inheritance.
|
||||||
tprio_t prio = chThdGetPriority();
|
tprio_t prio = chThdGetPriority();
|
||||||
|
@ -284,19 +381,19 @@ static void mtx5_execute(void) {
|
||||||
test_assert_sequence("ABCDE");
|
test_assert_sequence("ABCDE");
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct testcase testmtx5 = {
|
const struct testcase testmtx7 = {
|
||||||
mtx5_gettest,
|
mtx7_gettest,
|
||||||
mtx5_setup,
|
mtx7_setup,
|
||||||
NULL,
|
NULL,
|
||||||
mtx5_execute
|
mtx7_execute
|
||||||
};
|
};
|
||||||
|
|
||||||
static char *mtx6_gettest(void) {
|
static char *mtx8_gettest(void) {
|
||||||
|
|
||||||
return "CondVar, inheritance boost test";
|
return "CondVar, inheritance boost test";
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mtx6_setup(void) {
|
static void mtx8_setup(void) {
|
||||||
|
|
||||||
chCondInit(&c1);
|
chCondInit(&c1);
|
||||||
chMtxInit(&m1);
|
chMtxInit(&m1);
|
||||||
|
@ -322,7 +419,7 @@ static msg_t thread12(void *p) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mtx6_execute(void) {
|
static void mtx8_execute(void) {
|
||||||
|
|
||||||
tprio_t prio = chThdGetPriority();
|
tprio_t prio = chThdGetPriority();
|
||||||
threads[0] = chThdCreateStatic(wa[0], WA_SIZE, prio+1, thread11, "A");
|
threads[0] = chThdCreateStatic(wa[0], WA_SIZE, prio+1, thread11, "A");
|
||||||
|
@ -334,11 +431,11 @@ static void mtx6_execute(void) {
|
||||||
test_assert_sequence("ABC");
|
test_assert_sequence("ABC");
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct testcase testmtx6 = {
|
const struct testcase testmtx8 = {
|
||||||
mtx6_gettest,
|
mtx8_gettest,
|
||||||
mtx6_setup,
|
mtx8_setup,
|
||||||
NULL,
|
NULL,
|
||||||
mtx6_execute
|
mtx8_execute
|
||||||
};
|
};
|
||||||
#endif /* CH_USE_CONDVARS */
|
#endif /* CH_USE_CONDVARS */
|
||||||
#endif /* CH_USE_MUTEXES */
|
#endif /* CH_USE_MUTEXES */
|
||||||
|
@ -351,10 +448,12 @@ const struct testcase * const patternmtx[] = {
|
||||||
&testmtx1,
|
&testmtx1,
|
||||||
&testmtx2,
|
&testmtx2,
|
||||||
&testmtx3,
|
&testmtx3,
|
||||||
#if CH_USE_CONDVARS
|
|
||||||
&testmtx4,
|
&testmtx4,
|
||||||
&testmtx5,
|
&testmtx5,
|
||||||
|
#if CH_USE_CONDVARS
|
||||||
&testmtx6,
|
&testmtx6,
|
||||||
|
&testmtx7,
|
||||||
|
&testmtx8,
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
NULL
|
NULL
|
||||||
|
|
Loading…
Reference in New Issue