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_msg Messages test 00032 * 00033 * File: @ref testmsg.c 00034 * 00035 * <h2>Description</h2> 00036 * This module implements the test sequence for the @ref messages subsystem. 00037 * 00038 * <h2>Objective</h2> 00039 * Objective of the test module is to cover 100% of the @ref messages 00040 * subsystem code. 00041 * 00042 * <h2>Preconditions</h2> 00043 * The module requires the following kernel options: 00044 * - @p CH_USE_MESSAGES 00045 * . 00046 * In case some of the required options are not enabled then some or all tests 00047 * may be skipped. 00048 * 00049 * <h2>Test Cases</h2> 00050 * - @subpage test_msg_001 00051 * . 00052 * @file testmsg.c 00053 * @brief Messages test source file 00054 * @file testmsg.h 00055 * @brief Messages header file 00056 */ 00057 00058 #if CH_USE_MESSAGES 00059 00060 /** 00061 * @page test_msg_001 Messages Server loop 00062 * 00063 * <h2>Description</h2> 00064 * A thread is spawned that sends four messages back to the tester thread.<br> 00065 * The test expect to receive the messages in the correct sequence and to 00066 * not find a fifth message waiting. 00067 */ 00068 00069 static char *msg1_gettest(void) { 00070 00071 return "Messages, loop"; 00072 } 00073 00074 static msg_t thread(void *p) { 00075 00076 chMsgSend(p, 'A'); 00077 chMsgSend(p, 'B'); 00078 chMsgSend(p, 'C'); 00079 chMsgSend(p, 'D'); 00080 return 0; 00081 } 00082 00083 static void msg1_execute(void) { 00084 msg_t msg; 00085 00086 /* 00087 * Testing the whole messages loop. 00088 */ 00089 threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriority() + 1, 00090 thread, chThdSelf()); 00091 chMsgRelease(msg = chMsgWait()); 00092 test_emit_token(msg); 00093 chMsgRelease(msg = chMsgWait()); 00094 test_emit_token(msg); 00095 chMsgRelease(msg = chMsgWait()); 00096 test_emit_token(msg); 00097 test_assert_sequence(1, "ABC"); 00098 00099 /* 00100 * Testing message fetch using chMsgGet(). 00101 * Note, the following is valid because the sender has higher priority than 00102 * the receiver. 00103 */ 00104 msg = chMsgGet(); 00105 test_assert(1, msg != 0, "no message"); 00106 chMsgRelease(0); 00107 test_assert(2, msg == 'D', "wrong message"); 00108 00109 /* 00110 * Must not have pending messages. 00111 */ 00112 msg = chMsgGet(); 00113 test_assert(3, msg == 0, "unknown message"); 00114 } 00115 00116 const struct testcase testmsg1 = { 00117 msg1_gettest, 00118 NULL, 00119 NULL, 00120 msg1_execute 00121 }; 00122 00123 #endif /* CH_USE_MESSAGES */ 00124 00125 /** 00126 * @brief Test sequence for messages. 00127 */ 00128 const struct testcase * const patternmsg[] = { 00129 #if CH_USE_MESSAGES 00130 &testmsg1, 00131 #endif 00132 NULL 00133 };