Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 228 lines (196 sloc) 6.716 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 "atommutex.h"
33 #include "atomtests.h"
34
35
2d909ba Add stack usage analysis. Used for all automated test modules (if ena…
Kelvin Lawson authored
36 /* Number of test threads */
37 #define NUM_TEST_THREADS 3
38
39
6d599c6 Add Atomthreads RTOS source files.
Kelvin Lawson authored
40 /* Test OS objects */
41 static ATOM_MUTEX mutex1;
2d909ba Add stack usage analysis. Used for all automated test modules (if ena…
Kelvin Lawson authored
42 static ATOM_TCB tcb[NUM_TEST_THREADS];
43 static uint8_t test_thread_stack[NUM_TEST_THREADS][TEST_THREAD_STACK_SIZE];
6d599c6 Add Atomthreads RTOS source files.
Kelvin Lawson authored
44
45
46 /* Test results */
47 static volatile int pass_flag[3];
48
49
50 /* Forward declarations */
eafe07c TESTS: Function parameters cannot be named "data" when using Raisonan…
Kelvin Lawson authored
51 static void test_thread_func (uint32_t param);
6d599c6 Add Atomthreads RTOS source files.
Kelvin Lawson authored
52
53
54 /**
55 * \b test_start
56 *
57 * Start mutex test.
58 *
59 * This test verifies the mutex deletion API, by deleting a mutex
60 * on which multiple threads are blocking, and checking that all three
61 * are woken up with an appropriate error code.
62 *
63 * @retval Number of failures
64 */
65 uint32_t test_start (void)
66 {
67 int failures;
68 int i;
69
70 /* Default to zero failures */
71 failures = 0;
72
73 /* Initialise pass status for all three threads to FALSE */
74 for (i = 0; i < 3; i++)
75 {
76 pass_flag[i] = FALSE;
77 }
78
79 /* Test wakeup of three threads on mutex deletion */
80 if (atomMutexCreate (&mutex1) != ATOM_OK)
81 {
82 ATOMLOG (_STR("Error creating mutex\n"));
83 failures++;
84 }
85
86 else
87 {
88 /* Take the mutex to ensure that all three test threads will block */
89 if (atomMutexGet (&mutex1, 0) != ATOM_OK)
90 {
91 ATOMLOG (_STR("Error taking mutex\n"));
92 failures++;
93 }
94
95 /* Create test thread 1 */
2d909ba Add stack usage analysis. Used for all automated test modules (if ena…
Kelvin Lawson authored
96 if (atomThreadCreate(&tcb[0], TEST_THREAD_PRIO, test_thread_func, 0,
af84aa9 @kelvinlawson Add support for architectures with stack alignment requirements in pr…
authored
97 &test_thread_stack[0][0],
98 TEST_THREAD_STACK_SIZE, TRUE) != ATOM_OK)
6d599c6 Add Atomthreads RTOS source files.
Kelvin Lawson authored
99 {
100 /* Fail */
101 ATOMLOG (_STR("Error creating test thread 1\n"));
102 failures++;
103 }
104
105 /* Create test thread 2 */
2d909ba Add stack usage analysis. Used for all automated test modules (if ena…
Kelvin Lawson authored
106 else if (atomThreadCreate(&tcb[1], TEST_THREAD_PRIO, test_thread_func, 1,
af84aa9 @kelvinlawson Add support for architectures with stack alignment requirements in pr…
authored
107 &test_thread_stack[1][0],
108 TEST_THREAD_STACK_SIZE, TRUE) != ATOM_OK)
6d599c6 Add Atomthreads RTOS source files.
Kelvin Lawson authored
109 {
110 /* Fail */
111 ATOMLOG (_STR("Error creating test thread 2\n"));
112 failures++;
113 }
114
115 /* Create test thread 3 */
2d909ba Add stack usage analysis. Used for all automated test modules (if ena…
Kelvin Lawson authored
116 else if (atomThreadCreate(&tcb[2], TEST_THREAD_PRIO, test_thread_func, 2,
af84aa9 @kelvinlawson Add support for architectures with stack alignment requirements in pr…
authored
117 &test_thread_stack[2][0],
118 TEST_THREAD_STACK_SIZE, TRUE) != ATOM_OK)
6d599c6 Add Atomthreads RTOS source files.
Kelvin Lawson authored
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 mutex1 */
129 atomTimerDelay (SYSTEM_TICKS_PER_SEC/4);
130
131 /* Delete mutex1 now that all three threads should be blocking */
132 if (atomMutexDelete (&mutex1) != 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
2d909ba Add stack usage analysis. Used for all automated test modules (if ena…
Kelvin Lawson authored
152 /* Check thread stack usage (if enabled) */
153 #ifdef ATOM_STACK_CHECKING
6d599c6 Add Atomthreads RTOS source files.
Kelvin Lawson authored
154 {
2d909ba Add stack usage analysis. Used for all automated test modules (if ena…
Kelvin Lawson authored
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
7d56170 STM8 port: Add UART support. Make use of full 1KB on Discovery. Impro…
Kelvin Lawson authored
178 ATOMLOG (_STR("StackUse:%d\n"), (int)used_bytes);
2d909ba Add stack usage analysis. Used for all automated test modules (if ena…
Kelvin Lawson authored
179 #endif
180 }
181 }
6d599c6 Add Atomthreads RTOS source files.
Kelvin Lawson authored
182 }
2d909ba Add stack usage analysis. Used for all automated test modules (if ena…
Kelvin Lawson authored
183 #endif
6d599c6 Add Atomthreads RTOS source files.
Kelvin Lawson authored
184
185 /* Quit */
186 return failures;
187 }
188
189
190 /**
191 * \b test_thread_func
192 *
193 * Entry point for test threads.
194 *
eafe07c TESTS: Function parameters cannot be named "data" when using Raisonan…
Kelvin Lawson authored
195 * @param[in] param Thread ID (0-2)
6d599c6 Add Atomthreads RTOS source files.
Kelvin Lawson authored
196 *
197 * @return None
198 */
eafe07c TESTS: Function parameters cannot be named "data" when using Raisonan…
Kelvin Lawson authored
199 static void test_thread_func (uint32_t param)
6d599c6 Add Atomthreads RTOS source files.
Kelvin Lawson authored
200 {
201 uint8_t status;
202 int thread_id;
203
204 /* Pull out the passed thread ID */
eafe07c TESTS: Function parameters cannot be named "data" when using Raisonan…
Kelvin Lawson authored
205 thread_id = (int)param;
6d599c6 Add Atomthreads RTOS source files.
Kelvin Lawson authored
206
207 /*
208 * Wait on mutex1 with timeout. We are expecting to be woken up
209 * by the main thread while blocking.
210 */
211 status = atomMutexGet(&mutex1, (5 * SYSTEM_TICKS_PER_SEC));
212 if (status != ATOM_ERR_DELETED)
213 {
214 ATOMLOG (_STR("Test1 thread woke without deletion (%d)\n"), status);
215 }
216 else
217 {
218 /* We were woken due to deletion as expected, set pass_flag to notify success */
219 pass_flag[thread_id] = TRUE;
220 }
221
222 /* Wait forever */
223 while (1)
224 {
225 atomTimerDelay (SYSTEM_TICKS_PER_SEC);
226 }
2d909ba Add stack usage analysis. Used for all automated test modules (if ena…
Kelvin Lawson authored
227 }
Something went wrong with that request. Please try again.