Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 311 lines (273 sloc) 8.986 kB
6d599c6 Add Atomthreads RTOS source files.
Kelvin Lawson authored
1 /*
2 * Copyright (c) 2010, Kelvin Lawson. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. No personal names or organizations' names associated with the
14 * Atomthreads project may be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE ATOMTHREADS PROJECT AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE
21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
28 */
29
8de1462 @kelvinlawson Remove unnecessary mods from the MIPS pull request (kernel and tests …
authored
30
6d599c6 Add Atomthreads RTOS source files.
Kelvin Lawson authored
31 #include "atom.h"
32 #include "atomqueue.h"
33 #include "atomtests.h"
34
35
36 /* Test queue size */
37 #define QUEUE_ENTRIES 16
38
39
2d909ba Add stack usage analysis. Used for all automated test modules (if ena…
Kelvin Lawson authored
40 /* Number of test threads */
41 #define NUM_TEST_THREADS 2
42
43
6d599c6 Add Atomthreads RTOS source files.
Kelvin Lawson authored
44 /* Test OS objects */
45 static ATOM_QUEUE queue1;
46 static uint8_t queue1_storage[QUEUE_ENTRIES];
2d909ba Add stack usage analysis. Used for all automated test modules (if ena…
Kelvin Lawson authored
47 static ATOM_TCB tcb[NUM_TEST_THREADS];
48 static uint8_t test_thread_stack[NUM_TEST_THREADS][TEST_THREAD_STACK_SIZE];
6d599c6 Add Atomthreads RTOS source files.
Kelvin Lawson authored
49
50
51 /* Test result tracking */
52 static volatile int g_result;
53
54
55 /* Forward declarations */
eafe07c TESTS: Function parameters cannot be named "data" when using Raisonan…
Kelvin Lawson authored
56 static void test1_thread_func (uint32_t param);
57 static void test2_thread_func (uint32_t param);
6d599c6 Add Atomthreads RTOS source files.
Kelvin Lawson authored
58
59
60 /**
61 * \b test_start
62 *
63 * Start queue test.
64 *
65 * This test exercises queue deletion, waking threads blocking on a queue
66 * in atomQueueGet() if the queue is deleted.
67 *
68 * Deletion wakeups are tested twice: once for a thread which is blocking
69 * in atomQueueGet() with a timeout and once for a thread which is
70 * blocking in atomQueueGet() with no timeout.
71 *
72 * Deletion of threads blocking in atomQueuePut() are tested in queue3.c.
73 *
74 * @retval Number of failures
75 */
76 uint32_t test_start (void)
77 {
78 int failures;
79
80 /* Default to zero failures */
81 failures = 0;
82
83 /* Test wakeup of threads on queue deletion (thread blocking with no timeout) */
84 g_result = 0;
85 if (atomQueueCreate (&queue1, &queue1_storage[0], sizeof(uint8_t), QUEUE_ENTRIES) != ATOM_OK)
86 {
87 ATOMLOG (_STR("Error creating test queue\n"));
88 failures++;
89 }
90
91 /* Create a test thread that will block because the queue is empty */
2d909ba Add stack usage analysis. Used for all automated test modules (if ena…
Kelvin Lawson authored
92 else if (atomThreadCreate(&tcb[0], TEST_THREAD_PRIO, test1_thread_func, 0,
af84aa9 @kelvinlawson Add support for architectures with stack alignment requirements in pr…
authored
93 &test_thread_stack[0][0],
94 TEST_THREAD_STACK_SIZE, TRUE) != ATOM_OK)
6d599c6 Add Atomthreads RTOS source files.
Kelvin Lawson authored
95 {
96 /* Fail */
97 ATOMLOG (_STR("Error creating test thread 1\n"));
98 failures++;
99 }
100 else
101 {
102
103 /*
104 * We have created an empty queue. We want to see that the other
105 * thread is woken up if its queue is deleted. This is indicated
106 * through g_result being set.
107 */
108
109 /* Wait for the other thread to start blocking on queue1 */
110 if (atomTimerDelay(SYSTEM_TICKS_PER_SEC) != ATOM_OK)
111 {
112 ATOMLOG (_STR("Failed timer delay\n"));
113 failures++;
114 }
115 else
116 {
117 /* The other thread will be blocking on queue1 now, delete queue1 */
118 if (atomQueueDelete(&queue1) != ATOM_OK)
119 {
120 ATOMLOG (_STR("Failed queue1 delete\n"));
121 failures++;
122 }
123 else
124 {
125 /* Queue1 deleted. The thread should now wake up and set g_result. */
126 atomTimerDelay (SYSTEM_TICKS_PER_SEC);
127 if (g_result == 0)
128 {
129 ATOMLOG (_STR("Notify fail\n"));
130 failures++;
131 }
132 else
133 {
134 /* Success */
135 }
136 }
137 }
138 }
139
140 /* Test wakeup of threads on semaphore deletion (thread blocking with timeout) */
141 g_result = 0;
142 if (atomQueueCreate (&queue1, &queue1_storage[0], sizeof(uint8_t), QUEUE_ENTRIES) != ATOM_OK)
143 {
144 ATOMLOG (_STR("Error creating test queue\n"));
145 failures++;
146 }
147
148 /* Create a test thread that will block because the queue is empty */
2d909ba Add stack usage analysis. Used for all automated test modules (if ena…
Kelvin Lawson authored
149 else if (atomThreadCreate(&tcb[1], TEST_THREAD_PRIO, test2_thread_func, 0,
af84aa9 @kelvinlawson Add support for architectures with stack alignment requirements in pr…
authored
150 &test_thread_stack[1][0],
151 TEST_THREAD_STACK_SIZE, TRUE) != ATOM_OK)
6d599c6 Add Atomthreads RTOS source files.
Kelvin Lawson authored
152 {
153 /* Fail */
154 ATOMLOG (_STR("Error creating test thread 2\n"));
155 failures++;
156 }
157 else
158 {
159
160 /*
161 * We have created an empty queue. We want to see that the other
162 * thread is woken up if its queue is deleted. This is indicated
163 * through g_result being set.
164 */
165
166 /* Wait for the other thread to start blocking on queue1 */
167 if (atomTimerDelay(SYSTEM_TICKS_PER_SEC) != ATOM_OK)
168 {
169 ATOMLOG (_STR("Failed timer delay\n"));
170 failures++;
171 }
172 else
173 {
174 /* The other thread will be blocking on queue1 now, delete queue1 */
175 if (atomQueueDelete(&queue1) != ATOM_OK)
176 {
177 ATOMLOG (_STR("Failed queue1 delete\n"));
178 failures++;
179 }
180 else
181 {
182 /* Queue1 deleted. The thread should now wake up and set g_result. */
183 atomTimerDelay (SYSTEM_TICKS_PER_SEC);
184 if (g_result == 0)
185 {
186 ATOMLOG (_STR("Notify fail\n"));
187 failures++;
188 }
189 else
190 {
191 /* Success */
192 }
193 }
194 }
195 }
196
2d909ba Add stack usage analysis. Used for all automated test modules (if ena…
Kelvin Lawson authored
197 /* Check thread stack usage (if enabled) */
198 #ifdef ATOM_STACK_CHECKING
6d599c6 Add Atomthreads RTOS source files.
Kelvin Lawson authored
199 {
2d909ba Add stack usage analysis. Used for all automated test modules (if ena…
Kelvin Lawson authored
200 uint32_t used_bytes, free_bytes;
201 int thread;
202
203 /* Check all threads */
204 for (thread = 0; thread < NUM_TEST_THREADS; thread++)
205 {
206 /* Check thread stack usage */
207 if (atomThreadStackCheck (&tcb[thread], &used_bytes, &free_bytes) != ATOM_OK)
208 {
209 ATOMLOG (_STR("StackCheck\n"));
210 failures++;
211 }
212 else
213 {
214 /* Check the thread did not use up to the end of stack */
215 if (free_bytes == 0)
216 {
217 ATOMLOG (_STR("StackOverflow %d\n"), thread);
218 failures++;
219 }
220
221 /* Log the stack usage */
222 #ifdef TESTS_LOG_STACK_USAGE
7d56170 STM8 port: Add UART support. Make use of full 1KB on Discovery. Impro…
Kelvin Lawson authored
223 ATOMLOG (_STR("StackUse:%d\n"), (int)used_bytes);
2d909ba Add stack usage analysis. Used for all automated test modules (if ena…
Kelvin Lawson authored
224 #endif
225 }
226 }
6d599c6 Add Atomthreads RTOS source files.
Kelvin Lawson authored
227 }
2d909ba Add stack usage analysis. Used for all automated test modules (if ena…
Kelvin Lawson authored
228 #endif
6d599c6 Add Atomthreads RTOS source files.
Kelvin Lawson authored
229
230 /* Quit */
231 return failures;
232 }
233
234
235 /**
236 * \b test1_thread_func
237 *
238 * Entry point for test thread 1.
239 *
eafe07c TESTS: Function parameters cannot be named "data" when using Raisonan…
Kelvin Lawson authored
240 * @param[in] param Unused (optional thread entry parameter)
6d599c6 Add Atomthreads RTOS source files.
Kelvin Lawson authored
241 *
242 * @return None
243 */
eafe07c TESTS: Function parameters cannot be named "data" when using Raisonan…
Kelvin Lawson authored
244 static void test1_thread_func (uint32_t param)
6d599c6 Add Atomthreads RTOS source files.
Kelvin Lawson authored
245 {
246 uint8_t status, msg;
247
eafe07c TESTS: Function parameters cannot be named "data" when using Raisonan…
Kelvin Lawson authored
248 /* Compiler warnings */
249 param = param;
250
6d599c6 Add Atomthreads RTOS source files.
Kelvin Lawson authored
251 /*
252 * Wait on queue1 with no timeout. We are expecting to be woken up
253 * by the main thread while blocking.
254 */
255 status = atomQueueGet(&queue1, 0, &msg);
256 if (status != ATOM_ERR_DELETED)
257 {
258 ATOMLOG (_STR("Test1 thread woke without deletion (%d)\n"), status);
259 }
260 else
261 {
262 /* We were woken due to deletion as expected, set g_result to notify success */
263 g_result = 1;
264 }
265
266 /* Wait forever */
267 while (1)
268 {
269 atomTimerDelay (SYSTEM_TICKS_PER_SEC);
270 }
271 }
272
273
274 /**
275 * \b test2_thread_func
276 *
277 * Entry point for test thread 2.
278 *
eafe07c TESTS: Function parameters cannot be named "data" when using Raisonan…
Kelvin Lawson authored
279 * @param[in] param Unused (optional thread entry parameter)
6d599c6 Add Atomthreads RTOS source files.
Kelvin Lawson authored
280 *
281 * @return None
282 */
eafe07c TESTS: Function parameters cannot be named "data" when using Raisonan…
Kelvin Lawson authored
283 static void test2_thread_func (uint32_t param)
6d599c6 Add Atomthreads RTOS source files.
Kelvin Lawson authored
284 {
285 uint8_t status, msg;
286
eafe07c TESTS: Function parameters cannot be named "data" when using Raisonan…
Kelvin Lawson authored
287 /* Compiler warnings */
288 param = param;
289
6d599c6 Add Atomthreads RTOS source files.
Kelvin Lawson authored
290 /*
291 * Wait on queue1 with timeout. We are expecting to be woken up
292 * by the main thread while blocking.
293 */
294 status = atomQueueGet(&queue1, (5 * SYSTEM_TICKS_PER_SEC), &msg);
295 if (status != ATOM_ERR_DELETED)
296 {
297 ATOMLOG (_STR("Test2 thread woke without deletion (%d)\n"), status);
298 }
299 else
300 {
301 /* We were woken due to deletion as expected, set g_result to notify success */
302 g_result = 1;
303 }
304
305 /* Wait forever */
306 while (1)
307 {
308 atomTimerDelay (SYSTEM_TICKS_PER_SEC);
309 }
310 }
Something went wrong with that request. Please try again.