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.
36 * \author Daniele Basile <asterix@develer.com>
38 * $test$: cp bertos/cfg/cfg_proc.h $cfgdir/
39 * $test$: echo "#undef CONFIG_KERN" >> $cfgdir/cfg_proc.h
40 * $test$: echo "#define CONFIG_KERN 1" >> $cfgdir/cfg_proc.h
41 * $test$: cp bertos/cfg/cfg_signal.h $cfgdir/
42 * $test$: echo "#undef CONFIG_KERN_SIGNALS" >> $cfgdir/cfg_signal.h
43 * $test$: echo "#define CONFIG_KERN_SIGNALS 1" >> $cfgdir/cfg_signal.h
46 #include "cfg/cfg_timer.h"
47 #include <cfg/debug.h>
49 #include <cfg/compiler.h>
52 #include <kern/proc.h>
53 #include <kern/signal.h>
55 #include <mware/event.h>
57 #include <drv/timer.h>
60 * In the nightly build test, signals are disables, so this
62 * Since this code is used when we run "make check" it will be
63 * compiled and therefor tested there.
65 #if CONFIG_KERN_SIGNALS
68 // Global settings for the test.
69 #define MAX_GLOBAL_COUNT 11040
70 #define TEST_TIME_OUT_MS 5000
73 // Settings for the test message.
76 #define DELAY_PROC_T0 INC_PROC_T0*DELAY
79 #define DELAY_PROC_T1 INC_PROC_T1*DELAY
82 #define DELAY_PROC_T2 INC_PROC_T2*DELAY
85 #define DELAY_PROC_T3 INC_PROC_T3*DELAY
87 #define INC_PROC_T4 11
88 #define DELAY_PROC_T4 INC_PROC_T4*DELAY
90 #define INC_PROC_T5 13
91 #define DELAY_PROC_T5 INC_PROC_T5*DELAY
94 * These macros generate the code needed to create the test process functions.
96 #define RECV_PROC(num, sig) \
97 static NORETURN void receiver_proc##num(void) \
103 kprintf("Proc[%d]..get message\n", num); \
104 rec_msg = containerof(msg_get(&test_port##num), TestMsg, msg); \
105 timer_delay(rec_msg->delay); \
106 rec_msg->result += rec_msg->val; \
107 kprintf("Proc[%d]..process message val[%d],delay[%d],res[%d]\n", num, rec_msg->val, rec_msg->delay, rec_msg->result); \
108 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) PROC_DEFINE_STACK(receiver_stack##num, KERN_MINSTACKSIZE * 2)
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;
137 static int process_num;
140 static MsgPort test_port0;
141 static MsgPort test_port1;
142 static MsgPort test_port2;
143 static MsgPort test_port3;
144 static MsgPort test_port4;
145 static MsgPort test_port5;
148 * Generate the process to test message.
150 RECV_PROC(0, SIG_USER0)
151 RECV_PROC(1, SIG_USER1)
152 RECV_PROC(2, SIG_USER2)
153 RECV_PROC(3, SIG_USER3)
154 RECV_PROC(4, SIG_SYSTEM5)
155 RECV_PROC(5, SIG_SYSTEM6)
157 * These signal are already use from
158 * main process and the sig_waitWithTimeout functions, so we don't
161 * RECV_PROC(6, SIG_SINGLE)
162 * RECV_PROC(7, SIG_TIMEOUT)
173 * Help function to fill the message to send
175 static void fill_msg(TestMsg *msg, int val, int delay, int res)
185 int msg_testRun(void)
187 MsgPort test_portMain;
196 // Allocate and start the test process
197 struct Process *recv0 = RECV_INIT_PROC(0);
198 struct Process *recv1 = RECV_INIT_PROC(1);
199 struct Process *recv2 = RECV_INIT_PROC(2);
200 struct Process *recv3 = RECV_INIT_PROC(3);
201 struct Process *recv4 = RECV_INIT_PROC(4);
202 struct Process *recv5 = RECV_INIT_PROC(5);
204 kprintf("Run Message test..\n");
206 // Init port and message
207 RECV_INIT_MSG(Main, proc_current(), SIG_SINGLE);
208 RECV_INIT_MSG(0, recv0, SIG_USER0);
209 RECV_INIT_MSG(1, recv1, SIG_USER1);
210 RECV_INIT_MSG(2, recv2, SIG_USER2);
211 RECV_INIT_MSG(3, recv3, SIG_USER3);
212 RECV_INIT_MSG(4, recv4, SIG_SYSTEM5);
213 RECV_INIT_MSG(5, recv5, SIG_SYSTEM6);
215 // Fill-in first message and send it out.
216 fill_msg(&msg0, INC_PROC_T0, DELAY_PROC_T0, 0);
217 fill_msg(&msg1, INC_PROC_T1, DELAY_PROC_T1, 0);
218 fill_msg(&msg2, INC_PROC_T2, DELAY_PROC_T2, 0);
219 fill_msg(&msg3, INC_PROC_T3, DELAY_PROC_T3, 0);
220 fill_msg(&msg4, INC_PROC_T4, DELAY_PROC_T4, 0);
221 fill_msg(&msg5, INC_PROC_T5, DELAY_PROC_T5, 0);
224 // Send and wait the message
225 for (int i = 0; i < 23; ++i)
236 sigmask_t sigs = sig_waitTimeout(SIG_SINGLE, ms_to_ticks(TEST_TIME_OUT_MS));
237 if (sigs & SIG_SINGLE)
239 // Wait for a reply...
240 while ((reply = (TestMsg *)msg_get(&test_portMain)))
242 count += reply->result;
243 kprintf("Main recv[%d] count[%d]\n", reply->result, count);
247 if (process_num == 6)
250 if (sigs & SIG_TIMEOUT)
252 kputs("Main: sig timeout\n");
258 if(count == MAX_GLOBAL_COUNT)
260 kprintf("Message test finished..ok!\n");
265 kprintf("Message test finished..fail!\n");
269 int msg_testSetup(void)
273 kprintf("Init Timer..");
277 kprintf("Init Process..");
283 int msg_testTearDown(void)
285 kputs("TearDown Message test.\n");
291 #endif /* CONFIG_KERN_SIGNALS */