Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 271 lines (237 sloc) 7.986 kb
6d599c67 » Kelvin Lawson
2010-01-14 Add Atomthreads RTOS source files.
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
8de14626 »
2011-07-28 Remove unnecessary mods from the MIPS pull request (kernel and tests …
30
6d599c67 » Kelvin Lawson
2010-01-14 Add Atomthreads RTOS source files.
31 #include "atom.h"
32 #include "atomqueue.h"
33 #include "atomtests.h"
34
35
36 /* Test queue size */
37 #define QUEUE_ENTRIES 8
38
39
2d909ba2 » Kelvin Lawson
2010-03-01 Add stack usage analysis. Used for all automated test modules (if ena…
40 /* Number of test threads */
41 #define NUM_TEST_THREADS 1
42
43
6d599c67 » Kelvin Lawson
2010-01-14 Add Atomthreads RTOS source files.
44 /* Test OS objects */
45 static ATOM_QUEUE queue1;
46 static uint32_t queue1_storage[QUEUE_ENTRIES];
2d909ba2 » Kelvin Lawson
2010-03-01 Add stack usage analysis. Used for all automated test modules (if ena…
47 static ATOM_TCB tcb[NUM_TEST_THREADS];
48 static uint8_t test_thread_stack[NUM_TEST_THREADS][TEST_THREAD_STACK_SIZE];
6d599c67 » Kelvin Lawson
2010-01-14 Add Atomthreads RTOS source files.
49
50
51 /* Test message values (more values than can fit in an entire 8 message queue) */
52 uint32_t test_values[] =
53 {
54 0x12345678,
55 0xFF000000,
56 0x00FF0000,
57 0x0000FF00,
58 0x000000FF,
59 0xF000000F,
60 0x0F0000F0,
61 0x00F00F00,
62 0x000FF000,
63 0x87654321,
64 0xABCD0000,
65 0x0000CDEF
66 };
67
68 /* Test result tracking */
69 static volatile int g_result;
70
71
72 /* Forward declarations */
eafe07ce » Kelvin Lawson
2010-06-07 TESTS: Function parameters cannot be named "data" when using Raisonan…
73 static void test1_thread_func (uint32_t param);
6d599c67 » Kelvin Lawson
2010-01-14 Add Atomthreads RTOS source files.
74
75
76 /**
77 * \b test_start
78 *
79 * Start queue test.
80 *
81 * This tests basic operation of queues.
82 *
83 * The main test thread creates a second thread and posts
84 * a series of messages to the second thread. The message
85 * values are checked against the expected values.
86 *
87 * We test using 4-byte messages.
88 *
89 * @retval Number of failures
90 */
91 uint32_t test_start (void)
92 {
93 int failures, count;
94 int num_entries;
95 uint32_t msg;
96
97 /* Default to zero failures */
98 failures = 0;
99 g_result = 0;
100
101 /* Create test queue */
102 if (atomQueueCreate (&queue1, (uint8_t *)&queue1_storage[0], sizeof(queue1_storage[0]), QUEUE_ENTRIES) != ATOM_OK)
103 {
104 ATOMLOG (_STR("Error creating test queue\n"));
105 failures++;
106 }
107
108 /* Create a test thread that will block because the queue is empty */
2d909ba2 » Kelvin Lawson
2010-03-01 Add stack usage analysis. Used for all automated test modules (if ena…
109 else if (atomThreadCreate(&tcb[0], TEST_THREAD_PRIO + 1, test1_thread_func, 0,
af84aa98 »
2011-05-27 Add support for architectures with stack alignment requirements in pr…
110 &test_thread_stack[0][0],
111 TEST_THREAD_STACK_SIZE, TRUE) != ATOM_OK)
6d599c67 » Kelvin Lawson
2010-01-14 Add Atomthreads RTOS source files.
112 {
113 /* Fail */
114 ATOMLOG (_STR("Error creating test thread 1\n"));
115 failures++;
116 }
117 else
118 {
119
120 /*
121 * We have created an empty queue and a thread which should now
122 * be blocking on the queue. The test thread is lower priority
123 * than us.
124 */
125
126 /* Wait for the other thread to start blocking on queue1 */
127 if (atomTimerDelay(SYSTEM_TICKS_PER_SEC) != ATOM_OK)
128 {
129 ATOMLOG (_STR("Failed timer delay\n"));
130 failures++;
131 }
132 else
133 {
134 /*
135 * Post all entries in the test array to the queue.
136 * Because the second thread is lower priority than
137 * us, we will post 8 messages until the queue is
138 * full without waking up the second thread at all.
139 * At that point, we will block and the second
140 * thread will remove one message from the queue.
141 * With a spare entry in the queue, this thread
142 * will wake up again and post another message.
143 * This will continue until this thread has posted
144 * all messages, at which point the second thread
145 * will drain all remaining messages from the
146 * queue.
147 *
148 * Through this scheme we are able to test posting
149 * to the queue at all possible fill levels.
150 */
151 num_entries = sizeof(test_values) / sizeof(test_values[0]);
152 for (count = 0; count < num_entries; count++)
153 {
154 /* Increment through and post all test values to the queue */
155 msg = test_values[count];
156 if (atomQueuePut (&queue1, 0, (uint8_t *)&msg) != ATOM_OK)
157 {
158 ATOMLOG (_STR("Failed post\n"));
159 failures++;
160 }
161 }
162
163 /* Sleep a while for the second thread to finish */
164 atomTimerDelay (SYSTEM_TICKS_PER_SEC);
165
166 /* Check that the second thread has found all test values */
167 if (g_result != 1)
168 {
169 ATOMLOG (_STR("Bad test vals\n"));
170 failures++;
171 }
172 }
173 }
174
2d909ba2 » Kelvin Lawson
2010-03-01 Add stack usage analysis. Used for all automated test modules (if ena…
175 /* Check thread stack usage (if enabled) */
176 #ifdef ATOM_STACK_CHECKING
6d599c67 » Kelvin Lawson
2010-01-14 Add Atomthreads RTOS source files.
177 {
2d909ba2 » Kelvin Lawson
2010-03-01 Add stack usage analysis. Used for all automated test modules (if ena…
178 uint32_t used_bytes, free_bytes;
179 int thread;
180
181 /* Check all threads */
182 for (thread = 0; thread < NUM_TEST_THREADS; thread++)
183 {
184 /* Check thread stack usage */
185 if (atomThreadStackCheck (&tcb[thread], &used_bytes, &free_bytes) != ATOM_OK)
186 {
187 ATOMLOG (_STR("StackCheck\n"));
188 failures++;
189 }
190 else
191 {
192 /* Check the thread did not use up to the end of stack */
193 if (free_bytes == 0)
194 {
195 ATOMLOG (_STR("StackOverflow %d\n"), thread);
196 failures++;
197 }
198
199 /* Log the stack usage */
200 #ifdef TESTS_LOG_STACK_USAGE
7d56170c » Kelvin Lawson
2010-03-09 STM8 port: Add UART support. Make use of full 1KB on Discovery. Impro…
201 ATOMLOG (_STR("StackUse:%d\n"), (int)used_bytes);
2d909ba2 » Kelvin Lawson
2010-03-01 Add stack usage analysis. Used for all automated test modules (if ena…
202 #endif
203 }
204 }
6d599c67 » Kelvin Lawson
2010-01-14 Add Atomthreads RTOS source files.
205 }
2d909ba2 » Kelvin Lawson
2010-03-01 Add stack usage analysis. Used for all automated test modules (if ena…
206 #endif
6d599c67 » Kelvin Lawson
2010-01-14 Add Atomthreads RTOS source files.
207
208 /* Quit */
209 return failures;
210 }
211
212
213 /**
214 * \b test1_thread_func
215 *
216 * Entry point for test thread 1.
217 *
eafe07ce » Kelvin Lawson
2010-06-07 TESTS: Function parameters cannot be named "data" when using Raisonan…
218 * @param[in] param Unused (optional thread entry parameter)
6d599c67 » Kelvin Lawson
2010-01-14 Add Atomthreads RTOS source files.
219 *
220 * @return None
221 */
eafe07ce » Kelvin Lawson
2010-06-07 TESTS: Function parameters cannot be named "data" when using Raisonan…
222 static void test1_thread_func (uint32_t param)
6d599c67 » Kelvin Lawson
2010-01-14 Add Atomthreads RTOS source files.
223 {
224 uint32_t msg;
225 int num_entries, count, failures;
226
eafe07ce » Kelvin Lawson
2010-06-07 TESTS: Function parameters cannot be named "data" when using Raisonan…
227 /* Compiler warnings */
228 param = param;
229
6d599c67 » Kelvin Lawson
2010-01-14 Add Atomthreads RTOS source files.
230 /* Default to no errors */
231 failures = 0;
232
233 /*
234 * Loop receiving messages until we have received the number of
235 * values in the test array.
236 */
237 num_entries = sizeof(test_values) / sizeof(test_values[0]);
238 for (count = 0; count < num_entries; count++)
239 {
240 /* Receive a value from the queue */
241 if (atomQueueGet (&queue1, 0, (uint8_t *)&msg) != ATOM_OK)
242 {
243 ATOMLOG (_STR("Failed get\n"));
244 failures++;
245 }
246
247 /* Check that we received the expected value */
248 else if (msg != test_values[count])
249 {
250 ATOMLOG (_STR("Val%d\n"), count);
251 failures++;
252 }
253 }
254
255 /*
256 * Set g_result to indicate success if we had no failures.
257 * Thread-protection is not required on g_result because it
258 * is only ever set by this thread.
259 */
260 if (failures == 0)
261 {
262 /* No failures */
263 g_result = 1;
264 }
265
266 /* Wait forever */
267 while (1)
268 {
269 atomTimerDelay (SYSTEM_TICKS_PER_SEC);
270 }
271 }
Something went wrong with that request. Please try again.