aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/testmtx.c5
-rw-r--r--test/testsem.c54
-rw-r--r--test/testthd.c6
3 files changed, 63 insertions, 2 deletions
diff --git a/test/testmtx.c b/test/testmtx.c
index 339403127..9ca9edc85 100644
--- a/test/testmtx.c
+++ b/test/testmtx.c
@@ -452,6 +452,11 @@ static void mtx5_execute(void) {
test_assert(3, isempty(&m1.m_queue), "queue not empty");
test_assert(4, m1.m_owner == NULL, "still owned");
test_assert(5, chThdGetPriority() == prio, "wrong priority level");
+
+ chMtxLock(&m1);
+ chMtxUnlockAll();
+ test_assert(6, isempty(&m1.m_queue), "queue not empty");
+ test_assert(7, m1.m_owner == NULL, "still owned");
}
ROMCONST struct testcase testmtx5 = {
diff --git a/test/testsem.c b/test/testsem.c
index 798e3a65d..85535ed0a 100644
--- a/test/testsem.c
+++ b/test/testsem.c
@@ -189,7 +189,7 @@ ROMCONST struct testcase testsem2 = {
* @page test_sem_003 Atomic signal-wait test
*
* <h2>Description</h2>
- * This test case explicitly address the @p chSemWaitSignal() function. A
+ * This test case explicitly addresses the @p chSemWaitSignal() function. A
* thread is created that performs a wait and a signal operations.
* The tester thread is awakened from an atomic wait/signal operation.<br>
* The test expects that the semaphore wait function returns the correct value
@@ -229,6 +229,57 @@ ROMCONST struct testcase testsem3 = {
sem3_execute
};
#endif /* CH_USE_SEMSW */
+
+/**
+ * @page test_sem_004 Binary Wait and Signal
+ *
+ * <h2>Description</h2>
+ * This test case tests the binary semaphores functionality. The test both
+ * checks the binary semaphore status and the expected status of the underlying
+ * counting semaphore.
+ */
+static msg_t thread4(void *p) {
+
+ chBSemSignal((BinarySemaphore *)p);
+ return 0;
+}
+
+static void sem4_execute(void) {
+ BinarySemaphore bsem;
+
+ /* Creates a taken binary semaphore.*/
+ chBSemInit(&bsem, TRUE);
+ chBSemReset(&bsem, TRUE);
+ test_assert(1, chBSemGetStateI(&bsem) == TRUE, "not taken");
+
+ /* Starts a signaler thread at a lower priority.*/
+ threads[0] = chThdCreateStatic(wa[0], WA_SIZE,
+ chThdGetPriority()-1, thread4, &bsem);
+
+ /* Waits to be signaled.*/
+ chBSemWait(&bsem);
+
+ /* The binary semaphore is expected to be taken.*/
+ test_assert(2, chBSemGetStateI(&bsem) == TRUE, "not taken");
+
+ /* Releasing it, check both the binary semaphore state and the underlying
+ counter semaphore state..*/
+ chBSemSignal(&bsem);
+ test_assert(3, chBSemGetStateI(&bsem) == FALSE, "still taken");
+ test_assert(4, chSemGetCounterI(&bsem.bs_sem) == 1, "unexpected counter");
+
+ /* Checking signaling overflow, the counter must not go beyond 1.*/
+ chBSemSignal(&bsem);
+ test_assert(3, chBSemGetStateI(&bsem) == FALSE, "taken");
+ test_assert(5, chSemGetCounterI(&bsem.bs_sem) == 1, "unexpected counter");
+}
+
+ROMCONST struct testcase testsem4 = {
+ "Binary Semaphores, functionality",
+ NULL,
+ NULL,
+ sem4_execute
+};
#endif /* CH_USE_SEMAPHORES */
/**
@@ -241,6 +292,7 @@ ROMCONST struct testcase * ROMCONST patternsem[] = {
#if CH_USE_SEMSW
&testsem3,
#endif
+ &testsem4,
#endif
NULL
};
diff --git a/test/testthd.c b/test/testthd.c
index b12378320..8b0440248 100644
--- a/test/testthd.c
+++ b/test/testthd.c
@@ -100,7 +100,11 @@ static void thd2_execute(void) {
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");
+ /* Done this way for coverage of chThdCreateI() and chThdResume().*/
+ chSysLock();
+ threads[2] = chThdCreateI(wa[2], WA_SIZE, chThdGetPriority()-3, thread, "C");
+ chSysUnlock();
+ chThdResume(threads[2]);
test_wait_threads();
test_assert_sequence(1, "ABCDE");
}