ChibiOS/RT Architecture - Reference Manual - Guides |
00001 /* 00002 ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio. 00003 00004 This file is part of ChibiOS/RT. 00005 00006 ChibiOS/RT is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 3 of the License, or 00009 (at your option) any later version. 00010 00011 ChibiOS/RT is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program. If not, see <http://www.gnu.org/licenses/>. 00018 00019 --- 00020 00021 A special exception to the GPL can be applied should you wish to distribute 00022 a combined work that includes ChibiOS/RT, without being obliged to provide 00023 the source code for any proprietary components. See the file exception.txt 00024 for full details of how and when the exception can be applied. 00025 */ 00026 00027 #include "ch.h" 00028 #include "test.h" 00029 00030 /** 00031 * @page test_mbox Mailboxes test 00032 * 00033 * File: @ref testmbox.c 00034 * 00035 * <h2>Description</h2> 00036 * This module implements the test sequence for the @ref mailboxes subsystem. 00037 * 00038 * <h2>Objective</h2> 00039 * Objective of the test module is to cover 100% of the @ref mailboxes 00040 * subsystem code.<br> 00041 * Note that the @ref mailboxes subsystem depends on the @ref semaphores 00042 * subsystem that has to met its testing objectives as well. 00043 * 00044 * <h2>Preconditions</h2> 00045 * The module requires the following kernel options: 00046 * - @p CH_USE_MAILBOXES 00047 * . 00048 * In case some of the required options are not enabled then some or all tests 00049 * may be skipped. 00050 * 00051 * <h2>Test Cases</h2> 00052 * - @subpage test_mbox_001 00053 * . 00054 * @file testmbox.c 00055 * @brief Mailboxes test source file 00056 * @file testmbox.h 00057 * @brief Mailboxes header file 00058 */ 00059 00060 #if CH_USE_MAILBOXES 00061 00062 #define ALLOWED_DELAY MS2ST(5) 00063 #define MB_SIZE 5 00064 00065 /* 00066 * Note, the static initializers are not really required because the 00067 * variables are explicitly initialized in each test case. It is done in order 00068 * to test the macros. 00069 */ 00070 static MAILBOX_DECL(mb1, test.wa.T0, MB_SIZE); 00071 00072 /** 00073 * @page test_mbox_001 Queuing and timeouts 00074 * 00075 * <h2>Description</h2> 00076 * Messages are posted/fetched from a mailbox in carefully designed sequences 00077 * in order to stimulate all the possible code paths inside the mailbox.<br> 00078 * The test expects to find a consistent mailbox status after each operation. 00079 */ 00080 00081 static char *mbox1_gettest(void) { 00082 00083 return "Mailboxes, queuing and timeouts"; 00084 } 00085 00086 static void mbox1_setup(void) { 00087 00088 chMBInit(&mb1, (msg_t *)test.wa.T0, MB_SIZE); 00089 } 00090 00091 static void mbox1_execute(void) { 00092 msg_t msg1, msg2; 00093 unsigned i; 00094 00095 /* 00096 * Testing initial space. 00097 */ 00098 test_assert(1, chMBGetEmpty(&mb1) == MB_SIZE, "wrong size"); 00099 00100 /* 00101 * Testing enqueuing and backward circularity. 00102 */ 00103 for (i = 0; i < MB_SIZE - 1; i++) { 00104 msg1 = chMBPost(&mb1, 'B' + i, TIME_INFINITE); 00105 test_assert(2, msg1 == RDY_OK, "wrong wake-up message"); 00106 } 00107 msg1 = chMBPostAhead(&mb1, 'A', TIME_INFINITE); 00108 test_assert(3, msg1 == RDY_OK, "wrong wake-up message"); 00109 00110 /* 00111 * Testing post timeout. 00112 */ 00113 msg1 = chMBPost(&mb1, 'X', 1); 00114 test_assert(4, msg1 == RDY_TIMEOUT, "wrong wake-up message"); 00115 00116 /* 00117 * Testing final conditions. 00118 */ 00119 test_assert(5, chMBGetEmpty(&mb1) == 0, "still empty"); 00120 test_assert(6, chMBGetFull(&mb1) == MB_SIZE, "not full"); 00121 test_assert(7, mb1.mb_rdptr == mb1.mb_wrptr, "pointers not aligned"); 00122 00123 /* 00124 * Testing dequeuing. 00125 */ 00126 for (i = 0; i < MB_SIZE; i++) { 00127 msg1 = chMBFetch(&mb1, &msg2, TIME_INFINITE); 00128 test_assert(8, msg1 == RDY_OK, "wrong wake-up message"); 00129 test_emit_token(msg2); 00130 } 00131 test_assert_sequence(9, "ABCDE"); 00132 00133 /* 00134 * Testing buffer circularity. 00135 */ 00136 msg1 = chMBPost(&mb1, 'B' + i, TIME_INFINITE); 00137 test_assert(10, msg1 == RDY_OK, "wrong wake-up message"); 00138 msg1 = chMBFetch(&mb1, &msg2, TIME_INFINITE); 00139 test_assert(11, msg1 == RDY_OK, "wrong wake-up message"); 00140 test_assert(12, mb1.mb_buffer == mb1.mb_wrptr, "write pointer not aligned to base"); 00141 test_assert(13, mb1.mb_buffer == mb1.mb_rdptr, "read pointer not aligned to base"); 00142 00143 /* 00144 * Testing fetch timeout. 00145 */ 00146 msg1 = chMBFetch(&mb1, &msg2, 1); 00147 test_assert(14, msg1 == RDY_TIMEOUT, "wrong wake-up message"); 00148 00149 /* 00150 * Testing final conditions. 00151 */ 00152 test_assert(15, chMBGetEmpty(&mb1) == MB_SIZE, "not empty"); 00153 test_assert(16, chMBGetFull(&mb1) == 0, "still full"); 00154 test_assert(17, mb1.mb_rdptr == mb1.mb_wrptr, "pointers not aligned"); 00155 00156 /* 00157 * Testing reset. 00158 */ 00159 chMBReset(&mb1); 00160 00161 /* 00162 * Re-testing final conditions. 00163 */ 00164 test_assert(18, chMBGetEmpty(&mb1) == MB_SIZE, "not empty"); 00165 test_assert(19, chMBGetFull(&mb1) == 0, "still full"); 00166 test_assert(20, mb1.mb_buffer == mb1.mb_wrptr, "write pointer not aligned to base"); 00167 test_assert(21, mb1.mb_buffer == mb1.mb_rdptr, "read pointer not aligned to base"); 00168 } 00169 00170 const struct testcase testmbox1 = { 00171 mbox1_gettest, 00172 mbox1_setup, 00173 NULL, 00174 mbox1_execute 00175 }; 00176 00177 #endif /* CH_USE_MAILBOXES */ 00178 00179 /** 00180 * @brief Test sequence for mailboxes. 00181 */ 00182 const struct testcase * const patternmbox[] = { 00183 #if CH_USE_MAILBOXES 00184 &testmbox1, 00185 #endif 00186 NULL 00187 };