From 039a6c7349a3525842d1ffb8f0317cc6fcc3e454 Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Thu, 31 Mar 2016 10:10:43 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@9188 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- test/rt/source/test/test_sequence_003.c | 3 + test/rt/source/test/test_sequence_004.c | 6 +- test/rt/source/test/test_sequence_005.c | 112 ++++++++++++++++++++++++++++++-- 3 files changed, 114 insertions(+), 7 deletions(-) (limited to 'test/rt/source') diff --git a/test/rt/source/test/test_sequence_003.c b/test/rt/source/test/test_sequence_003.c index 0e4b1fb7f..443dd7e0b 100644 --- a/test/rt/source/test/test_sequence_003.c +++ b/test/rt/source/test/test_sequence_003.c @@ -40,7 +40,10 @@ static thread_reference_t tr1; static THD_FUNCTION(thread1, p) { + chSysLock(); chThdResumeI(&tr1, MSG_OK); + chSchRescheduleS(); + chSysUnlock(); test_emit_token(*(char *)p); } diff --git a/test/rt/source/test/test_sequence_004.c b/test/rt/source/test/test_sequence_004.c index e4d29ff3b..666d442dc 100644 --- a/test/rt/source/test/test_sequence_004.c +++ b/test/rt/source/test/test_sequence_004.c @@ -418,6 +418,10 @@ static const testcase_t test_004_005 = { * . */ +static void test_004_006_teardown(void) { + test_wait_threads(); +} + static void test_004_006_execute(void) { binary_semaphore_t bsem; msg_t msg; @@ -477,7 +481,7 @@ static void test_004_006_execute(void) { static const testcase_t test_004_006 = { "Testing Binary Semaphores special case", NULL, - NULL, + test_004_006_teardown, test_004_006_execute }; diff --git a/test/rt/source/test/test_sequence_005.c b/test/rt/source/test/test_sequence_005.c index 1d67f07ea..ebe7b79b3 100644 --- a/test/rt/source/test/test_sequence_005.c +++ b/test/rt/source/test/test_sequence_005.c @@ -42,6 +42,7 @@ * - @subpage test_005_006 * - @subpage test_005_007 * - @subpage test_005_008 + * - @subpage test_005_009 * . */ @@ -214,6 +215,13 @@ static THD_FUNCTION(thread8, p) { chMtxUnlock(&m1); chMtxUnlock(&m2); } + +static THD_FUNCTION(thread9, p) { + + chMtxLock(&m2); + test_emit_token(*(char *)p); + chMtxUnlock(&m2); +} #endif /* CH_CFG_USE_CONDVARS */ /**************************************************************************** @@ -869,7 +877,6 @@ static const testcase_t test_005_007 = { static void test_005_008_setup(void) { chCondObjectInit(&c1); chMtxObjectInit(&m1); - chMtxObjectInit(&m2); } static void test_005_008_execute(void) { @@ -879,11 +886,11 @@ static void test_005_008_execute(void) { test_set_step(1); { tprio_t prio = chThdGetPriorityX(); - threads[0] = chThdCreateStatic(wa[0], WA_SIZE, prio+1, thread8, "E"); - threads[1] = chThdCreateStatic(wa[1], WA_SIZE, prio+2, thread8, "D"); - threads[2] = chThdCreateStatic(wa[2], WA_SIZE, prio+3, thread8, "C"); - threads[3] = chThdCreateStatic(wa[3], WA_SIZE, prio+4, thread8, "B"); - threads[4] = chThdCreateStatic(wa[4], WA_SIZE, prio+5, thread8, "A"); + threads[0] = chThdCreateStatic(wa[0], WA_SIZE, prio+1, thread6, "E"); + threads[1] = chThdCreateStatic(wa[1], WA_SIZE, prio+2, thread6, "D"); + threads[2] = chThdCreateStatic(wa[2], WA_SIZE, prio+3, thread6, "C"); + threads[3] = chThdCreateStatic(wa[3], WA_SIZE, prio+4, thread6, "B"); + threads[4] = chThdCreateStatic(wa[4], WA_SIZE, prio+5, thread6, "A"); } /* [5.8.2] Broarcasting on the condition variable then waiting for @@ -904,6 +911,98 @@ static const testcase_t test_005_008 = { }; #endif /* CH_CFG_USE_CONDVARS */ +/** + * @page test_005_009 [5.9] Condition Variable priority boost test + * + *

Description

+ * This test case verifies the priority boost of a thread waiting on a + * conditional variable queue. It tests this very specific situation in + * order to improve code coverage. The created threads perform the + * following operations: TA{lock(M2), lock(M1), wait(C1), unlock(M1), + * unlock(M2)}, TB{lock(M2), wait(C1), unlock(M2)}. TC{lock(M1), + * unlock(M1)}. + * + *

Test Steps

+ * - [5.9.1] Reading current base priority. + * - [5.9.2] Thread A is created at priority P(+1), it locks M2, locks + * M1 and goes to wait on C1. + * - [5.9.3] Thread C is created at priority P(+2), it enqueues on M1 + * and boosts TA priority at P(+2). + * - [5.9.4] Thread B is created at priority P(+3), it enqueues on M2 + * and boosts TA priority at P(+3). + * - [5.9.5] Signaling C1: TA wakes up, unlocks M1 and priority goes to + * P(+2). TB locks M1, unlocks M1 and completes. TA unlocks M2 and + * priority goes to P(+1). TC waits on C1. TA completes. + * - [5.9.6] Signaling C1: TC wakes up, unlocks M1 and completes. + * - [5.9.7] Checking the order of operations. + * . + */ + +static void test_005_009_setup(void) { + chCondObjectInit(&c1); + chMtxObjectInit(&m1); + chMtxObjectInit(&m2); +} + +static void test_005_009_execute(void) { + tprio_t prio; + + /* [5.9.1] Reading current base priority.*/ + test_set_step(1); + { + prio = chThdGetPriorityX(); + } + + /* [5.9.2] Thread A is created at priority P(+1), it locks M2, locks + M1 and goes to wait on C1.*/ + test_set_step(2); + { + threads[0] = chThdCreateStatic(wa[0], WA_SIZE, prio+1, thread8, "A"); + } + + /* [5.9.3] Thread C is created at priority P(+2), it enqueues on M1 + and boosts TA priority at P(+2).*/ + test_set_step(3); + { + threads[1] = chThdCreateStatic(wa[1], WA_SIZE, prio+2, thread6, "C"); + } + + /* [5.9.4] Thread B is created at priority P(+3), it enqueues on M2 + and boosts TA priority at P(+3).*/ + test_set_step(4); + { + threads[2] = chThdCreateStatic(wa[2], WA_SIZE, prio+3, thread9, "B"); + } + + /* [5.9.5] Signaling C1: TA wakes up, unlocks M1 and priority goes to + P(+2). TB locks M1, unlocks M1 and completes. TA unlocks M2 and + priority goes to P(+1). TC waits on C1. TA completes.*/ + test_set_step(5); + { + chCondSignal(&c1); + } + + /* [5.9.6] Signaling C1: TC wakes up, unlocks M1 and completes.*/ + test_set_step(6); + { + chCondSignal(&c1); + } + + /* [5.9.7] Checking the order of operations.*/ + test_set_step(7); + { + test_wait_threads(); + test_assert_sequence("ABC", "invalid sequence"); + } +} + +static const testcase_t test_005_009 = { + "Condition Variable priority boost test", + test_005_009_setup, + NULL, + test_005_009_execute +}; + /**************************************************************************** * Exported data. ****************************************************************************/ @@ -928,6 +1027,7 @@ const testcase_t * const test_sequence_005[] = { #if (CH_CFG_USE_CONDVARS) || defined(__DOXYGEN__) &test_005_008, #endif + &test_005_009, NULL }; -- cgit v1.2.3