aboutsummaryrefslogtreecommitdiffstats
path: root/test/testmtx.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/testmtx.c')
-rw-r--r--test/testmtx.c143
1 files changed, 121 insertions, 22 deletions
diff --git a/test/testmtx.c b/test/testmtx.c
index c8050e887..feaeb2338 100644
--- a/test/testmtx.c
+++ b/test/testmtx.c
@@ -214,14 +214,111 @@ const struct testcase testmtx3 = {
mtx3_execute
};
-#if CH_USE_CONDVARS
static char *mtx4_gettest(void) {
- return "CondVar, signal test";
+ 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 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