4 * This file is part of BeRTOS.
6 * Bertos is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 * As a special exception, you may use this file as part of a free software
21 * library without restriction. Specifically, if other files instantiate
22 * templates or use macros or inline functions from this file, or you compile
23 * this file and link it with other files to produce an executable, this
24 * file does not by itself cause the resulting executable to be covered by
25 * the GNU General Public License. This exception does not however
26 * invalidate any other reasons why the executable file might be covered by
27 * the GNU General Public License.
29 * Copyright 2004, 2008 Develer S.r.l. (http://www.develer.com/)
30 * Copyright 1999, 2000, 2001 Bernie Innocenti <bernie@codewiz.org>
33 * \brief Message test.
37 * \author Daniele Basile <asterix@develer.com>
39 * $test$: cp bertos/cfg/cfg_proc.h $cfgdir/
40 * $test$: echo "#undef CONFIG_KERN" >> $cfgdir/cfg_proc.h
41 * $test$: echo "#define CONFIG_KERN 1" >> $cfgdir/cfg_proc.h
42 * $test$: cp bertos/cfg/cfg_signal.h $cfgdir/
43 * $test$: echo "#undef CONFIG_KERN_SIGNALS" >> $cfgdir/cfg_signal.h
44 * $test$: echo "#define CONFIG_KERN_SIGNALS 1" >> $cfgdir/cfg_signal.h
47 #include "cfg/cfg_timer.h"
48 #include <cfg/debug.h>
50 #include <cfg/compiler.h>
53 #include <kern/proc.h>
54 #include <kern/signal.h>
56 #include <mware/event.h>
58 #include <drv/timer.h>
61 * In the nightly build test, signals are disables, so this
63 * Since this code is used when we run "make check" it will be
64 * compiled and therefor tested there.
66 #if CONFIG_KERN_SIGNALS
69 // Global settings for the test.
70 #define MAX_GLOBAL_COUNT 11040
71 #define TEST_TIME_OUT_MS 10
74 // Settings for the test message.
77 #define DELAY_PROC_T0 INC_PROC_T0*DELAY
80 #define DELAY_PROC_T1 INC_PROC_T1*DELAY
83 #define DELAY_PROC_T2 INC_PROC_T2*DELAY
86 #define DELAY_PROC_T3 INC_PROC_T3*DELAY
88 #define INC_PROC_T4 11
89 #define DELAY_PROC_T4 INC_PROC_T4*DELAY
91 #define INC_PROC_T5 13
92 #define DELAY_PROC_T5 INC_PROC_T5*DELAY
95 * These macros generate the code needed to create the test process functions.
97 #define RECV_PROC(num, sig) \
98 static void receiver_proc##num(void) \
104 kprintf("Proc[%d]..get message\n", num); \
105 rec_msg = containerof(msg_get(&test_port##num), TestMsg, msg); \
106 timer_delay(rec_msg->delay); \
107 rec_msg->result += rec_msg->val; \
108 kprintf("Proc[%d]..process message val[%d],delay[%d],res[%d]\n", num, rec_msg->val, rec_msg->delay, rec_msg->result); \
109 msg_reply(&rec_msg->msg); \
110 kprintf("Proc[%d] reply\n", num); \
114 #define SEND_MSG(num) \
116 kprintf("Main send message to proc[%d]\n", num); \
117 msg##num.msg.replyPort = &test_portMain; \
118 msg_put(&test_port##num, &msg##num.msg); \
121 #define RECV_STACK(num) static cpu_stack_t receiver_stack##num[CONFIG_KERN_MINSTACKSIZE / sizeof(cpu_stack_t)]
122 #define RECV_INIT_PROC(num) proc_new(receiver_proc##num, NULL, sizeof(receiver_stack##num), receiver_stack##num)
123 #define RECV_INIT_MSG(num, proc, sig) msg_initPort(&test_port##num, event_createSignal(proc, sig))
125 // A test message with the parameters and a result.
135 // Global count to check if the test is going ok.
136 static int count = 0;
139 static MsgPort test_port0;
140 static MsgPort test_port1;
141 static MsgPort test_port2;
142 static MsgPort test_port3;
143 static MsgPort test_port4;
144 static MsgPort test_port5;
147 * Generate the process to test message.
149 RECV_PROC(0, SIG_USER0)
150 RECV_PROC(1, SIG_USER1)
151 RECV_PROC(2, SIG_USER2)
152 RECV_PROC(3, SIG_USER3)
153 RECV_PROC(4, SIG_SYSTEM5)
154 RECV_PROC(5, SIG_SYSTEM6)
156 * These signal are already use from
157 * main process and the sig_waitWithTimeout functions, so we don't
160 * RECV_PROC(6, SIG_SINGLE)
161 * RECV_PROC(7, SIG_TIMEOUT)
172 * Help function to fill the message to send
174 static void fill_msg(TestMsg *msg, int val, int delay, int res)
184 int msg_testRun(void)
186 MsgPort test_portMain;
195 // Allocate and start the test process
196 struct Process *recv0 = RECV_INIT_PROC(0);
197 struct Process *recv1 = RECV_INIT_PROC(1);
198 struct Process *recv2 = RECV_INIT_PROC(2);
199 struct Process *recv3 = RECV_INIT_PROC(3);
200 struct Process *recv4 = RECV_INIT_PROC(4);
201 struct Process *recv5 = RECV_INIT_PROC(5);
203 kprintf("Run Message test..\n");
205 // Init port and message
206 RECV_INIT_MSG(Main, proc_current(), SIG_SINGLE);
207 RECV_INIT_MSG(0, recv0, SIG_USER0);
208 RECV_INIT_MSG(1, recv1, SIG_USER1);
209 RECV_INIT_MSG(2, recv2, SIG_USER2);
210 RECV_INIT_MSG(3, recv3, SIG_USER3);
211 RECV_INIT_MSG(4, recv4, SIG_SYSTEM5);
212 RECV_INIT_MSG(5, recv5, SIG_SYSTEM6);
214 // Fill-in first message and send it out.
215 fill_msg(&msg0, INC_PROC_T0, DELAY_PROC_T0, 0);
216 fill_msg(&msg1, INC_PROC_T1, DELAY_PROC_T1, 0);
217 fill_msg(&msg2, INC_PROC_T2, DELAY_PROC_T2, 0);
218 fill_msg(&msg3, INC_PROC_T3, DELAY_PROC_T3, 0);
219 fill_msg(&msg4, INC_PROC_T4, DELAY_PROC_T4, 0);
220 fill_msg(&msg5, INC_PROC_T5, DELAY_PROC_T5, 0);
223 // Send and wait the message
224 for (int i = 0; i < 23; ++i)
234 if(sig_waitTimeout(SIG_SINGLE, TEST_TIME_OUT_MS) && SIG_SINGLE)
236 // Wait for a reply...
237 reply = containerof(msg_get(&test_portMain), TestMsg, msg);
240 count += reply->result;
241 kprintf("Main recv[%d] count[%d]\n", reply->result, count);
246 if(count == MAX_GLOBAL_COUNT)
248 kprintf("Message test finished..ok!\n");
252 kprintf("Message test finished..fail!\n");
256 int msg_testSetup(void)
260 #if CONFIG_KERN_PREEMPT
261 kprintf("Init Interrupt (preempt mode)..");
266 kprintf("Init Timer..");
270 kprintf("Init Process..");
276 int msg_testTearDown(void)
278 kputs("TearDown Message test.\n");
284 #endif /* CONFIG_KERN_SIGNALS */