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 5000
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 NORETURN 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); \
111 kprintf("Proc[%d] reply\n", num); \
115 #define SEND_MSG(num) \
117 kprintf("Main send message to proc[%d]\n", num); \
118 msg##num.msg.replyPort = &test_portMain; \
119 msg_put(&test_port##num, &msg##num.msg); \
122 #define RECV_STACK(num) PROC_DEFINE_STACK(receiver_stack##num, KERN_MINSTACKSIZE * 2)
123 #define RECV_INIT_PROC(num) proc_new(receiver_proc##num, NULL, sizeof(receiver_stack##num), receiver_stack##num)
124 #define RECV_INIT_MSG(num, proc, sig) msg_initPort(&test_port##num, event_createSignal(proc, sig))
126 // A test message with the parameters and a result.
136 // Global count to check if the test is going ok.
137 static int count = 0;
138 static int process_num;
141 static MsgPort test_port0;
142 static MsgPort test_port1;
143 static MsgPort test_port2;
144 static MsgPort test_port3;
145 static MsgPort test_port4;
146 static MsgPort test_port5;
149 * Generate the process to test message.
151 RECV_PROC(0, SIG_USER0)
152 RECV_PROC(1, SIG_USER1)
153 RECV_PROC(2, SIG_USER2)
154 RECV_PROC(3, SIG_USER3)
155 RECV_PROC(4, SIG_SYSTEM5)
156 RECV_PROC(5, SIG_SYSTEM6)
158 * These signal are already use from
159 * main process and the sig_waitWithTimeout functions, so we don't
162 * RECV_PROC(6, SIG_SINGLE)
163 * RECV_PROC(7, SIG_TIMEOUT)
174 * Help function to fill the message to send
176 static void fill_msg(TestMsg *msg, int val, int delay, int res)
186 int msg_testRun(void)
188 MsgPort test_portMain;
197 // Allocate and start the test process
198 struct Process *recv0 = RECV_INIT_PROC(0);
199 struct Process *recv1 = RECV_INIT_PROC(1);
200 struct Process *recv2 = RECV_INIT_PROC(2);
201 struct Process *recv3 = RECV_INIT_PROC(3);
202 struct Process *recv4 = RECV_INIT_PROC(4);
203 struct Process *recv5 = RECV_INIT_PROC(5);
205 kprintf("Run Message test..\n");
207 // Init port and message
208 RECV_INIT_MSG(Main, proc_current(), SIG_SINGLE);
209 RECV_INIT_MSG(0, recv0, SIG_USER0);
210 RECV_INIT_MSG(1, recv1, SIG_USER1);
211 RECV_INIT_MSG(2, recv2, SIG_USER2);
212 RECV_INIT_MSG(3, recv3, SIG_USER3);
213 RECV_INIT_MSG(4, recv4, SIG_SYSTEM5);
214 RECV_INIT_MSG(5, recv5, SIG_SYSTEM6);
216 // Fill-in first message and send it out.
217 fill_msg(&msg0, INC_PROC_T0, DELAY_PROC_T0, 0);
218 fill_msg(&msg1, INC_PROC_T1, DELAY_PROC_T1, 0);
219 fill_msg(&msg2, INC_PROC_T2, DELAY_PROC_T2, 0);
220 fill_msg(&msg3, INC_PROC_T3, DELAY_PROC_T3, 0);
221 fill_msg(&msg4, INC_PROC_T4, DELAY_PROC_T4, 0);
222 fill_msg(&msg5, INC_PROC_T5, DELAY_PROC_T5, 0);
225 // Send and wait the message
226 for (int i = 0; i < 23; ++i)
237 sigmask_t sigs = sig_waitTimeout(SIG_SINGLE, ms_to_ticks(TEST_TIME_OUT_MS));
238 if (sigs & SIG_SINGLE)
240 // Wait for a reply...
241 while ((reply = (TestMsg *)msg_get(&test_portMain)))
243 count += reply->result;
244 kprintf("Main recv[%d] count[%d]\n", reply->result, count);
248 if (process_num == 6)
251 if (sigs & SIG_TIMEOUT)
253 kputs("Main: sig timeout\n");
259 if(count == MAX_GLOBAL_COUNT)
261 kprintf("Message test finished..ok!\n");
266 kprintf("Message test finished..fail!\n");
270 int msg_testSetup(void)
274 kprintf("Init Timer..");
278 kprintf("Init Process..");
284 int msg_testTearDown(void)
286 kputs("TearDown Message test.\n");
292 #endif /* CONFIG_KERN_SIGNALS */