aboutsummaryrefslogtreecommitdiffstats
path: root/test/rt/testthd.c
diff options
context:
space:
mode:
authorGiovanni Di Sirio <gdisirio@gmail.com>2016-04-01 12:13:54 +0000
committerGiovanni Di Sirio <gdisirio@gmail.com>2016-04-01 12:13:54 +0000
commit7b1bf2a147db46f7bfd504cab01a2a941f01d022 (patch)
tree37a1f736582b073a817a683ecdf3a9590d3f053e /test/rt/testthd.c
parentb472786cd29099d704c42c5130555ab50e061394 (diff)
downloadChibiOS-7b1bf2a147db46f7bfd504cab01a2a941f01d022.tar.gz
ChibiOS-7b1bf2a147db46f7bfd504cab01a2a941f01d022.tar.bz2
ChibiOS-7b1bf2a147db46f7bfd504cab01a2a941f01d022.zip
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@9194 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'test/rt/testthd.c')
-rw-r--r--test/rt/testthd.c234
1 files changed, 0 insertions, 234 deletions
diff --git a/test/rt/testthd.c b/test/rt/testthd.c
deleted file mode 100644
index f270c90a6..000000000
--- a/test/rt/testthd.c
+++ /dev/null
@@ -1,234 +0,0 @@
-/*
- ChibiOS - Copyright (C) 2006..2016 Giovanni Di Sirio
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-*/
-
-#include "ch.h"
-#include "test.h"
-
-/**
- * @page test_threads Threads and Scheduler test
- *
- * File: @ref testthd.c
- *
- * <h2>Description</h2>
- * This module implements the test sequence for the @ref scheduler,
- * @ref threads and @ref time subsystems.<br>
- * Note that the tests on those subsystems are formally required but most of
- * their functionality is already demonstrated because the test suite itself
- * depends on them, anyway double check is good.
- *
- * <h2>Objective</h2>
- * Objective of the test module is to cover 100% of the subsystems code.
- *
- * <h2>Preconditions</h2>
- * None.
- *
- * <h2>Test Cases</h2>
- * - @subpage test_threads_001
- * - @subpage test_threads_002
- * - @subpage test_threads_003
- * - @subpage test_threads_004
- * .
- * @file testthd.c
- * @brief Threads and Scheduler test source file
- * @file testthd.h
- * @brief Threads and Scheduler test header file
- */
-
-/**
- * @page test_threads_001 Ready List functionality #1
- *
- * <h2>Description</h2>
- * Five threads, with increasing priority, are enqueued in the ready list
- * and atomically executed.<br>
- * The test expects the threads to perform their operations in increasing
- * priority order regardless of the initial order.
- */
-
-static THD_FUNCTION(thread, p) {
-
- test_emit_token(*(char *)p);
-}
-
-static void thd1_execute(void) {
-
- threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriorityX()-5, thread, "E");
- threads[1] = chThdCreateStatic(wa[1], WA_SIZE, chThdGetPriorityX()-4, thread, "D");
- threads[2] = chThdCreateStatic(wa[2], WA_SIZE, chThdGetPriorityX()-3, thread, "C");
- threads[3] = chThdCreateStatic(wa[3], WA_SIZE, chThdGetPriorityX()-2, thread, "B");
- threads[4] = chThdCreateStatic(wa[4], WA_SIZE, chThdGetPriorityX()-1, thread, "A");
- test_wait_threads();
- test_assert_sequence(1, "ABCDE");
-}
-
-ROMCONST struct testcase testthd1 = {
- "Threads, enqueuing test #1",
- NULL,
- NULL,
- thd1_execute
-};
-
-/**
- * @page test_threads_002 Ready List functionality #2
- *
- * <h2>Description</h2>
- * Five threads, with pseudo-random priority, are enqueued in the ready list
- * and atomically executed.<br>
- * The test expects the threads to perform their operations in increasing
- * priority order regardless of the initial order.
- */
-
-static void thd2_execute(void) {
-
- threads[1] = chThdCreateStatic(wa[1], WA_SIZE, chThdGetPriorityX()-4, thread, "D");
- threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriorityX()-5, thread, "E");
- threads[4] = chThdCreateStatic(wa[4], WA_SIZE, chThdGetPriorityX()-1, thread, "A");
- threads[3] = chThdCreateStatic(wa[3], WA_SIZE, chThdGetPriorityX()-2, thread, "B");
- threads[2] = chThdCreateStatic(wa[2], WA_SIZE, chThdGetPriorityX()-3, thread, "C");
- test_wait_threads();
- test_assert_sequence(1, "ABCDE");
-}
-
-ROMCONST struct testcase testthd2 = {
- "Threads, enqueuing test #2",
- NULL,
- NULL,
- thd2_execute
-};
-
-/**
- * @page test_threads_003 Threads priority change test
- *
- * <h2>Description</h2>
- * A series of priority changes are performed on the current thread in order
- * to verify that the priority change happens as expected.<br>
- * If the @p CH_CFG_USE_MUTEXES option is enabled then the priority changes are
- * also tested under priority inheritance boosted priority state.
- */
-
-static void thd3_execute(void) {
- tprio_t prio, p1;
-
- prio = chThdGetPriorityX();
- p1 = chThdSetPriority(prio + 1);
- test_assert(1, p1 == prio,
- "unexpected returned priority level");
- test_assert(2, chThdGetPriorityX() == prio + 1,
- "unexpected priority level");
- p1 = chThdSetPriority(p1);
- test_assert(3, p1 == prio + 1,
- "unexpected returned priority level");
- test_assert(4, chThdGetPriorityX() == prio,
- "unexpected priority level");
-
-#if CH_CFG_USE_MUTEXES || defined(__DOXYGEN__)
- /* Simulates a priority boost situation (p_prio > p_realprio).*/
- chSysLock();
- chThdGetSelfX()->prio += 2;
- chSysUnlock();
- test_assert(5, chThdGetPriorityX() == prio + 2,
- "unexpected priority level");
-
- /* Tries to raise but below the boost level. */
- p1 = chThdSetPriority(prio + 1);
- test_assert(6, p1 == prio,
- "unexpected returned priority level");
- test_assert(7, chThdGetSelfX()->prio == prio + 2,
- "unexpected priority level");
- test_assert(8, chThdGetSelfX()->realprio == prio + 1,
- "unexpected returned real priority level");
-
- /* Tries to raise above the boost level. */
- p1 = chThdSetPriority(prio + 3);
- test_assert(9, p1 == prio + 1,
- "unexpected returned priority level");
- test_assert(10, chThdGetSelfX()->prio == prio + 3,
- "unexpected priority level");
- test_assert(11, chThdGetSelfX()->realprio == prio + 3,
- "unexpected real priority level");
-
- chSysLock();
- chThdGetSelfX()->prio = prio;
- chThdGetSelfX()->realprio = prio;
- chSysUnlock();
-#endif
-}
-
-ROMCONST struct testcase testthd3 = {
- "Threads, priority change",
- NULL,
- NULL,
- thd3_execute
-};
-
-/**
- * @page test_threads_004 Threads delays test
- *
- * <h2>Description</h2>
- * Delay APIs and associated macros are tested, the invoking thread is verified
- * to wake up at the exact expected time.
- */
-
-static void thd4_execute(void) {
- systime_t time;
-
- test_wait_tick();
-
- /* Timeouts in microseconds.*/
- time = chVTGetSystemTime();
- chThdSleepMicroseconds(100000);
- test_assert_time_window(1,
- time + US2ST(100000),
- time + US2ST(100000) + CH_CFG_ST_TIMEDELTA + 1);
-
- /* Timeouts in milliseconds.*/
- time = chVTGetSystemTime();
- chThdSleepMilliseconds(100);
- test_assert_time_window(2,
- time + MS2ST(100),
- time + MS2ST(100) + CH_CFG_ST_TIMEDELTA + 1);
-
- /* Timeouts in seconds.*/
- time = chVTGetSystemTime();
- chThdSleepSeconds(1);
- test_assert_time_window(3,
- time + S2ST(1),
- time + S2ST(1) + CH_CFG_ST_TIMEDELTA + 1);
-
- /* Absolute timelines.*/
- time = chVTGetSystemTime() + MS2ST(100);
- chThdSleepUntil(time);
- test_assert_time_window(4,
- time,
- time + CH_CFG_ST_TIMEDELTA + 1);
-}
-
-ROMCONST struct testcase testthd4 = {
- "Threads, delays",
- NULL,
- NULL,
- thd4_execute
-};
-
-/**
- * @brief Test sequence for threads.
- */
-ROMCONST struct testcase * ROMCONST patternthd[] = {
- &testthd1,
- &testthd2,
- &testthd3,
- &testthd4,
- NULL
-};