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 2008 Develer S.r.l. (http://www.develer.com/)
33 * \brief Test kernel process.
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$: echo "#undef CONFIG_KERN_PRI" >> $cfgdir/cfg_proc.h
42 * $test$: echo "#define CONFIG_KERN_PRI 1" >> $cfgdir/cfg_proc.h
43 * $test$: cp bertos/cfg/cfg_monitor.h $cfgdir/
44 * $test$: echo "#undef CONFIG_KERN_MONITOR" >> $cfgdir/cfg_monitor.h
45 * $test$: echo "#define CONFIG_KERN_MONITOR 1" >> $cfgdir/cfg_monitor.h
46 * $test$: cp bertos/cfg/cfg_signal.h $cfgdir/
47 * $test$: echo "#undef CONFIG_KERN_SIGNALS" >> $cfgdir/cfg_signal.h
48 * $test$: echo "#define CONFIG_KERN_SIGNALS 1" >> $cfgdir/cfg_signal.h
51 #include <kern/proc.h>
53 #include <kern/monitor.h>
55 #include <drv/timer.h>
59 // Global settings for the test.
62 // Settings for the test process.
65 #define DELAY_PROC_T1 INC_PROC_T1*DELAY
68 #define DELAY_PROC_T2 INC_PROC_T2*DELAY
71 #define DELAY_PROC_T3 INC_PROC_T3*DELAY
74 #define DELAY_PROC_T4 INC_PROC_T4*DELAY
76 #define INC_PROC_T5 11
77 #define DELAY_PROC_T5 INC_PROC_T5*DELAY
79 #define INC_PROC_T6 13
80 #define DELAY_PROC_T6 INC_PROC_T6*DELAY
82 #define INC_PROC_T7 17
83 #define DELAY_PROC_T7 INC_PROC_T7*DELAY
85 #define INC_PROC_T8 19
86 #define DELAY_PROC_T8 INC_PROC_T8*DELAY
88 //Global count for each process.
89 unsigned int t1_count = 0;
90 unsigned int t2_count = 0;
91 unsigned int t3_count = 0;
92 unsigned int t4_count = 0;
93 unsigned int t5_count = 0;
94 unsigned int t6_count = 0;
95 unsigned int t7_count = 0;
96 unsigned int t8_count = 0;
99 * These macros generate the code needed to create the test process functions.
101 #define PROC_TEST(num) static void proc_test##num(void) \
103 for (int i = 0; i < INC_PROC_T##num; ++i) \
106 kprintf("> Process[%d]: count[%d]\n", num, t##num##_count); \
107 timer_delay(DELAY_PROC_T##num); \
111 #define PROC_TEST_STACK(num) static cpu_stack_t proc_test##num##_stack[700 / sizeof(cpu_stack_t)];
112 #define PROC_TEST_INIT(num) proc_new(proc_test##num, NULL, sizeof(proc_test##num##_stack), proc_test##num##_stack);
124 // Define process stacks for test.
134 // Define params to test priority
135 #define PROC_PRI_TEST(num) static void proc_pri_test##num(void) \
137 struct Process *main_proc = (struct Process *) proc_currentUserData(); \
138 sig_signal(main_proc, SIG_USER##num); \
141 // Default priority is 0
142 #define PROC_PRI_TEST_INIT(num, proc) \
144 struct Process *p = proc_new(proc_pri_test##num, (proc), sizeof(proc_test##num##_stack), proc_test##num##_stack); \
145 proc_setPri(p, num + 1); \
155 * Process scheduling test
157 int proc_testRun(void)
160 kprintf("Run Process test..\n");
162 //Init the process tests
171 kputs("> Main: Processes created\n");
173 for (int i = 0; i < 30; ++i)
180 if( t1_count == INC_PROC_T1 &&
181 t2_count == INC_PROC_T2 &&
182 t3_count == INC_PROC_T3 &&
183 t4_count == INC_PROC_T4 &&
184 t5_count == INC_PROC_T5 &&
185 t6_count == INC_PROC_T6 &&
186 t7_count == INC_PROC_T7 &&
187 t8_count == INC_PROC_T8)
189 kputs("> Main: process test finished..ok!\n");
194 kputs("> Main: process test..fail!\n");
198 #if CONFIG_KERN_SIGNALS
199 // test process priority
200 // main process must have the higher priority to check signals received
201 proc_setPri(proc_current(), 10);
203 struct Process *curr = proc_current();
204 // the order in which the processes are created is important!
205 PROC_PRI_TEST_INIT(0, curr);
206 PROC_PRI_TEST_INIT(1, curr);
207 PROC_PRI_TEST_INIT(2, curr);
209 // signals must be: USER2, 1, 0 in order
210 sigmask_t signals = sig_wait(SIG_USER0 | SIG_USER1 | SIG_USER2);
211 if (!(signals & SIG_USER2))
214 signals = sig_wait(SIG_USER0 | SIG_USER1 | SIG_USER2);
215 if (!(signals & SIG_USER1))
218 signals = sig_wait(SIG_USER0 | SIG_USER1 | SIG_USER2);
219 if (!(signals & SIG_USER0))
222 // All processes must have quit by now, but just in case...
223 signals = sig_waitTimeout(SIG_USER0 | SIG_USER1 | SIG_USER2, 200);
224 if (signals & (SIG_USER0 | SIG_USER1 | SIG_USER2))
227 if (signals & SIG_TIMEOUT)
229 kputs("Priority test successfull.\n");
235 kputs("Priority test failed.\n");
244 int proc_testSetup(void)
248 #if CONFIG_KERN_PREEMPT
249 kprintf("Init Interrupt (preempt mode)..");
254 kprintf("Init Timer..");
258 kprintf("Init Process..");
265 int proc_testTearDown(void)
267 kputs("TearDown Process test.\n");