Clean up whitespace.
[bertos.git] / bertos / kern / signal_test.c
1 /**
2  * \file
3  * <!--
4  * This file is part of BeRTOS.
5  *
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.
10  *
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.
15  *
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
19  *
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.
28  *
29  * Copyright 2004, 2008 Develer S.r.l. (http://www.develer.com/)
30  * Copyright 1999, 2000, 2001 Bernie Innocenti <bernie@codewiz.org>
31  * -->
32  *
33  * \brief Signals test.
34  *
35  * \version $Id$
36  *
37  * \author Daniele Basile <asterix@develer.com>
38  */
39
40 #include <cfg/cfg_timer.h>
41 #include <cfg/debug.h>
42 #include <cfg/test.h>
43
44 #include <kern/signal.h>
45 #include <kern/proc.h>
46 #include <kern/irq.h>
47
48 #include <drv/timer.h>
49
50 // Set mask with all signal that we want to test.
51 int test_signal[] = {
52         SIG_USER0,
53         SIG_USER1,
54         SIG_USER2,
55         SIG_USER3,
56         SIG_TIMEOUT,
57         SIG_SYSTEM5,
58         SIG_SYSTEM6,
59         SIG_SINGLE
60 };
61
62 // Current signal to send
63 int count = 0;
64
65 sigmask_t sig_to_master;
66 sigmask_t sig_to_slave;
67
68 /*
69  * These macros generate the code needed to create the test process functions.
70  */
71 #define PROC_TEST_SLAVE(index, signal) static void proc_test##index(void) \
72 { \
73         for(;;) \
74         { \
75                 kprintf("> Slave [%d]: Wait signal [%d]\n", index, signal); \
76                 sig_wait(signal); \
77                 kprintf("> Slave [%d]: send signal [%d]\n", index, signal); \
78                 sig_signal(proc_currentUserData(), signal); \
79         } \
80 } \
81
82 #define MAIN_CHECK_SIGNAL(index, slave) \
83         do { \
84                 kprintf("> Main: send signal [%d]\n", test_signal[index]); \
85                 sig_signal(slave, test_signal[index]); \
86                 kprintf("> Main: wait signal [%d]\n", test_signal[index]); \
87                 sig_wait(test_signal[index]); \
88                 count++; \
89         } while(0) \
90
91 #define PROC_TEST_SLAVE_STACK(index) static cpu_stack_t proc_test##index##_stack[CONFIG_KERN_MINSTACKSIZE / sizeof(cpu_stack_t)];
92 #define PROC_TEST_SLAVE_INIT(index, master_process) proc_new(proc_test##index, master_process, sizeof(proc_test##index##_stack), proc_test##index##_stack)
93
94 // Generate the code for signal test.
95 PROC_TEST_SLAVE(0, SIG_USER0)
96 PROC_TEST_SLAVE(1, SIG_USER1)
97 PROC_TEST_SLAVE(2, SIG_USER2)
98 PROC_TEST_SLAVE(3, SIG_USER3)
99 PROC_TEST_SLAVE(4, SIG_TIMEOUT)
100 PROC_TEST_SLAVE(5, SIG_SYSTEM5)
101 PROC_TEST_SLAVE(6, SIG_SYSTEM6)
102 PROC_TEST_SLAVE(7, SIG_SINGLE)
103
104 PROC_TEST_SLAVE_STACK(0)
105 PROC_TEST_SLAVE_STACK(1)
106 PROC_TEST_SLAVE_STACK(2)
107 PROC_TEST_SLAVE_STACK(3)
108 PROC_TEST_SLAVE_STACK(4)
109 PROC_TEST_SLAVE_STACK(5)
110 PROC_TEST_SLAVE_STACK(6)
111 PROC_TEST_SLAVE_STACK(7)
112
113 /**
114  * Run signal test
115  */
116 int signal_testRun(void)
117 {
118         struct Process *main_process = proc_current();
119         struct Process *slave_0;
120         struct Process *slave_1;
121         struct Process *slave_2;
122         struct Process *slave_3;
123         struct Process *slave_4;
124         struct Process *slave_5;
125         struct Process *slave_6;
126         struct Process *slave_7;
127
128         kprintf("Run Signal test..\n");
129         slave_0 = PROC_TEST_SLAVE_INIT(0, main_process);
130         slave_1 = PROC_TEST_SLAVE_INIT(1, main_process);
131         slave_2 = PROC_TEST_SLAVE_INIT(2, main_process);
132         slave_3 = PROC_TEST_SLAVE_INIT(3, main_process);
133         slave_4 = PROC_TEST_SLAVE_INIT(4, main_process);
134         slave_5 = PROC_TEST_SLAVE_INIT(5, main_process);
135         slave_6 = PROC_TEST_SLAVE_INIT(6, main_process);
136         slave_7 = PROC_TEST_SLAVE_INIT(7, main_process);
137
138         MAIN_CHECK_SIGNAL(0, slave_0);
139         MAIN_CHECK_SIGNAL(1, slave_1);
140         MAIN_CHECK_SIGNAL(2, slave_2);
141         MAIN_CHECK_SIGNAL(3, slave_3);
142         MAIN_CHECK_SIGNAL(4, slave_4);
143         MAIN_CHECK_SIGNAL(5, slave_5);
144         MAIN_CHECK_SIGNAL(6, slave_6);
145         MAIN_CHECK_SIGNAL(7, slave_7);
146
147         if(count == countof(test_signal))
148         {
149                 kprintf("Signal test finished..ok!\n");
150                 return 0;
151         }
152
153         kprintf("Signal test finished..fail!\n");
154         return -1;
155 }
156
157 int signal_testSetup(void)
158 {
159         kdbg_init();
160
161         #if CONFIG_KERN_PREEMPT
162                 kprintf("Init Interrupt (preempt mode)..");
163                 irq_init();
164                 kprintf("Done.\n");
165         #endif
166
167         kprintf("Init Timer..");
168         timer_init();
169         kprintf("Done.\n");
170
171         kprintf("Init Process..");
172         proc_init();
173         kprintf("Done.\n");
174         return 0;
175 }
176
177 int signal_testTearDown(void)
178 {
179         kputs("TearDown Signal test.\n");
180         return 0;
181 }
182
183 TEST_MAIN(signal);