Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 228 lines (195 sloc) 6.743 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 3
42
43
6d599c67 » Kelvin Lawson
2010-01-14 Add Atomthreads RTOS source files.
44 /* Test OS objects */
45 static ATOM_QUEUE queue1;
46 static uint8_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 results */
52 static volatile int pass_flag[3];
53
54
55 /* Forward declarations */
eafe07ce » Kelvin Lawson
2010-06-07 TESTS: Function parameters cannot be named "data" when using Raisonan…
56 static void test_thread_func (uint32_t param);
6d599c67 » Kelvin Lawson
2010-01-14 Add Atomthreads RTOS source files.
57
58
59 /**
60 * \b test_start
61 *
62 * Start queue test.
63 *
64 * This test verifies the queue deletion API, by deleting a queue
65 * on which multiple threads are blocking, and checking that all three
66 * are woken up with an appropriate error code.
67 *
68 * @retval Number of failures
69 */
70 uint32_t test_start (void)
71 {
72 int failures;
73 int i;
74
75 /* Default to zero failures */
76 failures = 0;
77
78 /* Initialise pass status for all three threads to FALSE */
79 for (i = 0; i < 3; i++)
80 {
81 pass_flag[i] = FALSE;
82 }
83
84 /* Test wakeup of three threads on queue deletion */
85 if (atomQueueCreate (&queue1, &queue1_storage[0], sizeof(queue1_storage[0]), QUEUE_ENTRIES) != ATOM_OK)
86 {
87 ATOMLOG (_STR("Error creating Q\n"));
88 failures++;
89 }
90
91 else
92 {
93 /* The queue is empty so all three test threads will block */
94
95 /* Create test thread 1 */
2d909ba2 » Kelvin Lawson
2010-03-01 Add stack usage analysis. Used for all automated test modules (if ena…
96 if (atomThreadCreate(&tcb[0], TEST_THREAD_PRIO, test_thread_func, 0,
af84aa98 »
2011-05-27 Add support for architectures with stack alignment requirements in pr…
97 &test_thread_stack[0][0],
98 TEST_THREAD_STACK_SIZE, TRUE) != ATOM_OK)
6d599c67 » Kelvin Lawson
2010-01-14 Add Atomthreads RTOS source files.
99 {
100 /* Fail */
101 ATOMLOG (_STR("Error creating test thread 1\n"));
102 failures++;
103 }
104
105 /* Create test thread 2 */
2d909ba2 » Kelvin Lawson
2010-03-01 Add stack usage analysis. Used for all automated test modules (if ena…
106 else if (atomThreadCreate(&tcb[1], TEST_THREAD_PRIO, test_thread_func, 1,
af84aa98 »
2011-05-27 Add support for architectures with stack alignment requirements in pr…
107 &test_thread_stack[1][0],
108 TEST_THREAD_STACK_SIZE, TRUE) != ATOM_OK)
6d599c67 » Kelvin Lawson
2010-01-14 Add Atomthreads RTOS source files.
109 {
110 /* Fail */
111 ATOMLOG (_STR("Error creating test thread 2\n"));
112 failures++;
113 }
114
115 /* Create test thread 3 */
2d909ba2 » Kelvin Lawson
2010-03-01 Add stack usage analysis. Used for all automated test modules (if ena…
116 else if (atomThreadCreate(&tcb[2], TEST_THREAD_PRIO, test_thread_func, 2,
af84aa98 »
2011-05-27 Add support for architectures with stack alignment requirements in pr…
117 &test_thread_stack[2][0],
118 TEST_THREAD_STACK_SIZE, TRUE) != ATOM_OK)
6d599c67 » Kelvin Lawson
2010-01-14 Add Atomthreads RTOS source files.
119 {
120 /* Fail */
121 ATOMLOG (_STR("Error creating test thread 3\n"));
122 failures++;
123 }
124
125 /* Test threads now created */
126 else
127 {
128 /* Wait a while for threads to start blocking on queue1 */
129 atomTimerDelay (SYSTEM_TICKS_PER_SEC/4);
130
131 /* Delete queue1 now that all three threads should be blocking */
132 if (atomQueueDelete (&queue1) != ATOM_OK)
133 {
134 ATOMLOG (_STR("Delete fail\n"));
135 failures++;
136 }
137 else
138 {
139 /* Wait a while for all three threads to wake up */
140 atomTimerDelay (SYSTEM_TICKS_PER_SEC/4);
141
142 /* Check that all three threads have passed */
143 if ((pass_flag[0] != TRUE) || (pass_flag[1] != TRUE) || (pass_flag[2] != TRUE))
144 {
145 ATOMLOG (_STR("Thread fail\n"));
146 failures++;
147 }
148 }
149 }
150 }
151
2d909ba2 » Kelvin Lawson
2010-03-01 Add stack usage analysis. Used for all automated test modules (if ena…
152 /* Check thread stack usage (if enabled) */
153 #ifdef ATOM_STACK_CHECKING
6d599c67 » Kelvin Lawson
2010-01-14 Add Atomthreads RTOS source files.
154 {
2d909ba2 » Kelvin Lawson
2010-03-01 Add stack usage analysis. Used for all automated test modules (if ena…
155 uint32_t used_bytes, free_bytes;
156 int thread;
157
158 /* Check all threads */
159 for (thread = 0; thread < NUM_TEST_THREADS; thread++)
160 {
161 /* Check thread stack usage */
162 if (atomThreadStackCheck (&tcb[thread], &used_bytes, &free_bytes) != ATOM_OK)
163 {
164 ATOMLOG (_STR("StackCheck\n"));
165 failures++;
166 }
167 else
168 {
169 /* Check the thread did not use up to the end of stack */
170 if (free_bytes == 0)
171 {
172 ATOMLOG (_STR("StackOverflow %d\n"), thread);
173 failures++;
174 }
175
176 /* Log the stack usage */
177 #ifdef TESTS_LOG_STACK_USAGE
7d56170c » Kelvin Lawson
2010-03-09 STM8 port: Add UART support. Make use of full 1KB on Discovery. Impro…
178 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…
179 #endif
180 }
181 }
6d599c67 » Kelvin Lawson
2010-01-14 Add Atomthreads RTOS source files.
182 }
2d909ba2 » Kelvin Lawson
2010-03-01 Add stack usage analysis. Used for all automated test modules (if ena…
183 #endif
6d599c67 » Kelvin Lawson
2010-01-14 Add Atomthreads RTOS source files.
184
185 /* Quit */
186 return failures;
187 }
188
189
190 /**
191 * \b test_thread_func
192 *
193 * Entry point for test threads.
194 *
eafe07ce » Kelvin Lawson
2010-06-07 TESTS: Function parameters cannot be named "data" when using Raisonan…
195 * @param[in] param Thread ID (0-2)
6d599c67 » Kelvin Lawson
2010-01-14 Add Atomthreads RTOS source files.
196 *
197 * @return None
198 */
eafe07ce » Kelvin Lawson
2010-06-07 TESTS: Function parameters cannot be named "data" when using Raisonan…
199 static void test_thread_func (uint32_t param)
6d599c67 » Kelvin Lawson
2010-01-14 Add Atomthreads RTOS source files.
200 {
201 uint8_t status;
202 uint8_t msg;
203 int thread_id;
204
205 /* Pull out the passed thread ID */
eafe07ce » Kelvin Lawson
2010-06-07 TESTS: Function parameters cannot be named "data" when using Raisonan…
206 thread_id = (int)param;
6d599c67 » Kelvin Lawson
2010-01-14 Add Atomthreads RTOS source files.
207
208 /*
209 * Wait on queue1 with timeout. We are expecting to be woken up
210 * by the main thread while blocking.
211 */
212 status = atomQueueGet(&queue1, (5 * SYSTEM_TICKS_PER_SEC), &msg);
213 if (status != ATOM_ERR_DELETED)
214 {
215 ATOMLOG (_STR("Test1 thread woke without deletion (%d)\n"), status);
216 }
217 else
218 {
219 /* We were woken due to deletion as expected, set pass_flag to notify success */
220 pass_flag[thread_id] = TRUE;
221 }
222
223 /* Wait forever */
224 while (1)
225 {
226 atomTimerDelay (SYSTEM_TICKS_PER_SEC);
227 }
2d909ba2 » Kelvin Lawson
2010-03-01 Add stack usage analysis. Used for all automated test modules (if ena…
228 }
Something went wrong with that request. Please try again.