Fork for workshops

Committer:
JimCarver
Date:
Fri Oct 12 21:22:49 2018 +0000
Revision:
0:6b753f761943
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JimCarver 0:6b753f761943 1 /*******************************************************************************
JimCarver 0:6b753f761943 2 * Copyright 2016, 2017 ARM Ltd.
JimCarver 0:6b753f761943 3 *
JimCarver 0:6b753f761943 4 * Licensed under the Apache License, Version 2.0 (the "License");
JimCarver 0:6b753f761943 5 * you may not use this file except in compliance with the License.
JimCarver 0:6b753f761943 6 * You may obtain a copy of the License at
JimCarver 0:6b753f761943 7 *
JimCarver 0:6b753f761943 8 * http://www.apache.org/licenses/LICENSE-2.0
JimCarver 0:6b753f761943 9 *
JimCarver 0:6b753f761943 10 * Unless required by applicable law or agreed to in writing, software
JimCarver 0:6b753f761943 11 * distributed under the License is distributed on an "AS IS" BASIS,
JimCarver 0:6b753f761943 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
JimCarver 0:6b753f761943 13 * See the License for the specific language governing permissions and
JimCarver 0:6b753f761943 14 * limitations under the License.
JimCarver 0:6b753f761943 15 *******************************************************************************/
JimCarver 0:6b753f761943 16
JimCarver 0:6b753f761943 17 #include <stdio.h>
JimCarver 0:6b753f761943 18 #include "pal.h"
JimCarver 0:6b753f761943 19 #include "pal_rtos_test_utils.h"
JimCarver 0:6b753f761943 20
JimCarver 0:6b753f761943 21 #include "pal_BSP.h"
JimCarver 0:6b753f761943 22 #include "unity_fixture.h"
JimCarver 0:6b753f761943 23
JimCarver 0:6b753f761943 24 #include "pal.h"
JimCarver 0:6b753f761943 25
JimCarver 0:6b753f761943 26
JimCarver 0:6b753f761943 27 extern threadsArgument_t g_threadsArg;
JimCarver 0:6b753f761943 28 timerArgument_t timerArgs;
JimCarver 0:6b753f761943 29
JimCarver 0:6b753f761943 30 void palThreadFunc1(void const *argument)
JimCarver 0:6b753f761943 31 {
JimCarver 0:6b753f761943 32 volatile palThreadID_t threadID;
JimCarver 0:6b753f761943 33 threadsArgument_t *tmp = (threadsArgument_t*)argument;
JimCarver 0:6b753f761943 34 #ifdef MUTEX_UNITY_TEST
JimCarver 0:6b753f761943 35 palStatus_t status = PAL_SUCCESS;
JimCarver 0:6b753f761943 36 PAL_PRINTF("palThreadFunc1::before mutex\n");
JimCarver 0:6b753f761943 37 status = pal_osMutexWait(mutex1, 100);
JimCarver 0:6b753f761943 38 PAL_PRINTF("palThreadFunc1::after mutex: 0x%08x\n", status);
JimCarver 0:6b753f761943 39 PAL_PRINTF("palThreadFunc1::after mutex (expected): 0x%08x\n", PAL_ERR_RTOS_TIMEOUT);
JimCarver 0:6b753f761943 40 TEST_ASSERT_EQUAL_HEX(PAL_ERR_RTOS_TIMEOUT, status);
JimCarver 0:6b753f761943 41 return; // for Mutex scenario, this should end here
JimCarver 0:6b753f761943 42 #endif //MUTEX_UNITY_TEST
JimCarver 0:6b753f761943 43
JimCarver 0:6b753f761943 44 tmp->arg1 = 10;
JimCarver 0:6b753f761943 45 threadID = pal_osThreadGetId();
JimCarver 0:6b753f761943 46 TEST_ASSERT_NOT_EQUAL(threadID, NULLPTR);
JimCarver 0:6b753f761943 47 PAL_PRINTF("palThreadFunc1::Thread ID is %"PRIuPTR " \n", threadID);
JimCarver 0:6b753f761943 48 #ifdef MUTEX_UNITY_TEST
JimCarver 0:6b753f761943 49 status = pal_osMutexRelease(mutex1);
JimCarver 0:6b753f761943 50 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 51 #endif //MUTEX_UNITY_TEST
JimCarver 0:6b753f761943 52 PAL_PRINTF("palThreadFunc1::STAAAAM\n");
JimCarver 0:6b753f761943 53 }
JimCarver 0:6b753f761943 54
JimCarver 0:6b753f761943 55 void palThreadFunc2(void const *argument)
JimCarver 0:6b753f761943 56 {
JimCarver 0:6b753f761943 57 volatile palThreadID_t threadID;
JimCarver 0:6b753f761943 58 threadsArgument_t *tmp = (threadsArgument_t*)argument;
JimCarver 0:6b753f761943 59 #ifdef MUTEX_UNITY_TEST
JimCarver 0:6b753f761943 60 palStatus_t status = PAL_SUCCESS;
JimCarver 0:6b753f761943 61 PAL_PRINTF("palThreadFunc2::before mutex\n");
JimCarver 0:6b753f761943 62 status = pal_osMutexWait(mutex2, 300);
JimCarver 0:6b753f761943 63 PAL_PRINTF("palThreadFunc2::after mutex: 0x%08x\n", status);
JimCarver 0:6b753f761943 64 PAL_PRINTF("palThreadFunc2::after mutex (expected): 0x%08x\n", PAL_SUCCESS);
JimCarver 0:6b753f761943 65 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 66 #endif //MUTEX_UNITY_TEST
JimCarver 0:6b753f761943 67
JimCarver 0:6b753f761943 68 tmp->arg2 = 20;
JimCarver 0:6b753f761943 69 threadID = pal_osThreadGetId();
JimCarver 0:6b753f761943 70 TEST_ASSERT_NOT_EQUAL(threadID, NULLPTR);
JimCarver 0:6b753f761943 71 PAL_PRINTF("palThreadFunc2::Thread ID is %"PRIuPTR "\n", threadID);
JimCarver 0:6b753f761943 72 #ifdef MUTEX_UNITY_TEST
JimCarver 0:6b753f761943 73 status = pal_osMutexRelease(mutex2);
JimCarver 0:6b753f761943 74 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 75 #endif //MUTEX_UNITY_TEST
JimCarver 0:6b753f761943 76 PAL_PRINTF("palThreadFunc2::STAAAAM\n");
JimCarver 0:6b753f761943 77 }
JimCarver 0:6b753f761943 78
JimCarver 0:6b753f761943 79 void palThreadFunc3(void const *argument)
JimCarver 0:6b753f761943 80 {
JimCarver 0:6b753f761943 81 volatile palThreadID_t threadID;
JimCarver 0:6b753f761943 82 threadsArgument_t *tmp = (threadsArgument_t*)argument;
JimCarver 0:6b753f761943 83
JimCarver 0:6b753f761943 84 #ifdef SEMAPHORE_UNITY_TEST
JimCarver 0:6b753f761943 85 palStatus_t status = PAL_SUCCESS;
JimCarver 0:6b753f761943 86 uint32_t semaphoresAvailable = 10;
JimCarver 0:6b753f761943 87 status = pal_osSemaphoreWait(semaphore1, 200, &semaphoresAvailable);
JimCarver 0:6b753f761943 88
JimCarver 0:6b753f761943 89 if (PAL_SUCCESS == status)
JimCarver 0:6b753f761943 90 {
JimCarver 0:6b753f761943 91 PAL_PRINTF("palThreadFunc3::semaphoresAvailable: %d\n", semaphoresAvailable);
JimCarver 0:6b753f761943 92 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 93 }
JimCarver 0:6b753f761943 94 else if(PAL_ERR_RTOS_TIMEOUT == status)
JimCarver 0:6b753f761943 95 {
JimCarver 0:6b753f761943 96 PAL_PRINTF("palThreadFunc3::semaphoresAvailable: %d\n", semaphoresAvailable);
JimCarver 0:6b753f761943 97 PAL_PRINTF("palThreadFunc3::status: 0x%08x\n", status);
JimCarver 0:6b753f761943 98 PAL_PRINTF("palThreadFunc3::failed to get Semaphore as expected\n", status);
JimCarver 0:6b753f761943 99 TEST_ASSERT_EQUAL_HEX(PAL_ERR_RTOS_TIMEOUT, status);
JimCarver 0:6b753f761943 100 return;
JimCarver 0:6b753f761943 101 }
JimCarver 0:6b753f761943 102 pal_osDelay(6000);
JimCarver 0:6b753f761943 103 #endif //SEMAPHORE_UNITY_TEST
JimCarver 0:6b753f761943 104 tmp->arg3 = 30;
JimCarver 0:6b753f761943 105 threadID = pal_osThreadGetId();
JimCarver 0:6b753f761943 106 TEST_ASSERT_NOT_EQUAL(threadID, NULLPTR);
JimCarver 0:6b753f761943 107 PAL_PRINTF("palThreadFunc3::Thread ID is %"PRIuPTR "\n", threadID);
JimCarver 0:6b753f761943 108
JimCarver 0:6b753f761943 109 #ifdef SEMAPHORE_UNITY_TEST
JimCarver 0:6b753f761943 110 status = pal_osSemaphoreRelease(semaphore1);
JimCarver 0:6b753f761943 111 PAL_PRINTF("palThreadFunc3::pal_osSemaphoreRelease res: 0x%08x\n", status);
JimCarver 0:6b753f761943 112 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 113 #endif //SEMAPHORE_UNITY_TEST
JimCarver 0:6b753f761943 114 PAL_PRINTF("palThreadFunc3::STAAAAM\n");
JimCarver 0:6b753f761943 115 }
JimCarver 0:6b753f761943 116
JimCarver 0:6b753f761943 117 void palThreadFunc4(void const *argument)
JimCarver 0:6b753f761943 118 {
JimCarver 0:6b753f761943 119 volatile palThreadID_t threadID;
JimCarver 0:6b753f761943 120 threadsArgument_t *tmp = (threadsArgument_t*)argument;
JimCarver 0:6b753f761943 121 #ifdef MUTEX_UNITY_TEST
JimCarver 0:6b753f761943 122 palStatus_t status = PAL_SUCCESS;
JimCarver 0:6b753f761943 123 PAL_PRINTF("palThreadFunc4::before mutex\n");
JimCarver 0:6b753f761943 124 status = pal_osMutexWait(mutex1, 200);
JimCarver 0:6b753f761943 125 PAL_PRINTF("palThreadFunc4::after mutex: 0x%08x\n", status);
JimCarver 0:6b753f761943 126 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 127 pal_osDelay(3500); //wait 3.5 seconds to make sure that the next thread arrive to this point
JimCarver 0:6b753f761943 128 #endif //MUTEX_UNITY_TEST
JimCarver 0:6b753f761943 129
JimCarver 0:6b753f761943 130 tmp->arg4 = 40;
JimCarver 0:6b753f761943 131 threadID = pal_osThreadGetId();
JimCarver 0:6b753f761943 132 TEST_ASSERT_NOT_EQUAL(threadID, NULLPTR);
JimCarver 0:6b753f761943 133 PAL_PRINTF("Thread ID is %"PRIuPTR "\n", threadID);
JimCarver 0:6b753f761943 134
JimCarver 0:6b753f761943 135 #ifdef MUTEX_UNITY_TEST
JimCarver 0:6b753f761943 136 status = pal_osMutexRelease(mutex1);
JimCarver 0:6b753f761943 137 PAL_PRINTF("palThreadFunc4::after release mutex: 0x%08x\n", status);
JimCarver 0:6b753f761943 138 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 139 #endif //MUTEX_UNITY_TEST
JimCarver 0:6b753f761943 140 PAL_PRINTF("palThreadFunc4::STAAAAM\n");
JimCarver 0:6b753f761943 141 }
JimCarver 0:6b753f761943 142
JimCarver 0:6b753f761943 143 void palThreadFunc5(void const *argument)
JimCarver 0:6b753f761943 144 {
JimCarver 0:6b753f761943 145 volatile palThreadID_t threadID;
JimCarver 0:6b753f761943 146 threadsArgument_t *tmp = (threadsArgument_t*)argument;
JimCarver 0:6b753f761943 147 #ifdef MUTEX_UNITY_TEST
JimCarver 0:6b753f761943 148 palStatus_t status = PAL_SUCCESS;
JimCarver 0:6b753f761943 149 PAL_PRINTF("palThreadFunc5::before mutex\n");
JimCarver 0:6b753f761943 150 status = pal_osMutexWait(mutex1, 4500);
JimCarver 0:6b753f761943 151 PAL_PRINTF("palThreadFunc5::after mutex: 0x%08x\n", status);
JimCarver 0:6b753f761943 152 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 153 #endif //MUTEX_UNITY_TEST
JimCarver 0:6b753f761943 154 tmp->arg5 = 50;
JimCarver 0:6b753f761943 155 threadID = pal_osThreadGetId();
JimCarver 0:6b753f761943 156 TEST_ASSERT_NOT_EQUAL(threadID, NULLPTR);
JimCarver 0:6b753f761943 157 PAL_PRINTF("Thread ID is %"PRIuPTR "\n", threadID);
JimCarver 0:6b753f761943 158 #ifdef MUTEX_UNITY_TEST
JimCarver 0:6b753f761943 159 status = pal_osMutexRelease(mutex1);
JimCarver 0:6b753f761943 160 PAL_PRINTF("palThreadFunc5::after release mutex: 0x%08x\n", status);
JimCarver 0:6b753f761943 161 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 162 #endif //MUTEX_UNITY_TEST
JimCarver 0:6b753f761943 163 PAL_PRINTF("palThreadFunc5::STAAAAM\n");
JimCarver 0:6b753f761943 164 }
JimCarver 0:6b753f761943 165
JimCarver 0:6b753f761943 166 void palThreadFunc6(void const *argument)
JimCarver 0:6b753f761943 167 {
JimCarver 0:6b753f761943 168 volatile palThreadID_t threadID;
JimCarver 0:6b753f761943 169 threadsArgument_t *tmp = (threadsArgument_t*)argument;
JimCarver 0:6b753f761943 170 #ifdef SEMAPHORE_UNITY_TEST
JimCarver 0:6b753f761943 171 palStatus_t status = PAL_SUCCESS;
JimCarver 0:6b753f761943 172 uint32_t semaphoresAvailable = 10;
JimCarver 0:6b753f761943 173 status = pal_osSemaphoreWait(123456, 200, &semaphoresAvailable); //MUST fail, since there is no semaphore with ID=3
JimCarver 0:6b753f761943 174 PAL_PRINTF("palThreadFunc6::semaphoresAvailable: %d\n", semaphoresAvailable);
JimCarver 0:6b753f761943 175 TEST_ASSERT_EQUAL_HEX(PAL_ERR_RTOS_PARAMETER, status);
JimCarver 0:6b753f761943 176 return;
JimCarver 0:6b753f761943 177 #endif //SEMAPHORE_UNITY_TEST
JimCarver 0:6b753f761943 178 tmp->arg6 = 60;
JimCarver 0:6b753f761943 179 threadID = pal_osThreadGetId();
JimCarver 0:6b753f761943 180 TEST_ASSERT_NOT_EQUAL(threadID, NULLPTR);
JimCarver 0:6b753f761943 181 PAL_PRINTF("Thread ID is %"PRIuPTR "\n", threadID);
JimCarver 0:6b753f761943 182 #ifdef SEMAPHORE_UNITY_TEST
JimCarver 0:6b753f761943 183 status = pal_osSemaphoreRelease(123456);
JimCarver 0:6b753f761943 184 PAL_PRINTF("palThreadFunc6::pal_osSemaphoreRelease res: 0x%08x\n", status);
JimCarver 0:6b753f761943 185 TEST_ASSERT_EQUAL_HEX(PAL_ERR_RTOS_PARAMETER, status);
JimCarver 0:6b753f761943 186 #endif //SEMAPHORE_UNITY_TEST
JimCarver 0:6b753f761943 187 PAL_PRINTF("palThreadFunc6::STAAAAM\n");
JimCarver 0:6b753f761943 188 }
JimCarver 0:6b753f761943 189
JimCarver 0:6b753f761943 190
JimCarver 0:6b753f761943 191 void palTimerFunc1(void const *argument)
JimCarver 0:6b753f761943 192 {
JimCarver 0:6b753f761943 193 g_timerArgs.ticksInFunc1 = pal_osKernelSysTick();
JimCarver 0:6b753f761943 194 PAL_PRINTF("ticks in palTimerFunc1: 0 - %" PRIu32 "\n", g_timerArgs.ticksInFunc1);
JimCarver 0:6b753f761943 195 PAL_PRINTF("Once Timer function was called\n");
JimCarver 0:6b753f761943 196 }
JimCarver 0:6b753f761943 197
JimCarver 0:6b753f761943 198 void palTimerFunc2(void const *argument)
JimCarver 0:6b753f761943 199 {
JimCarver 0:6b753f761943 200 g_timerArgs.ticksInFunc2 = pal_osKernelSysTick();
JimCarver 0:6b753f761943 201 PAL_PRINTF("ticks in palTimerFunc2: 0 - %" PRIu32 "\n", g_timerArgs.ticksInFunc2);
JimCarver 0:6b753f761943 202 PAL_PRINTF("Periodic Timer function was called\n");
JimCarver 0:6b753f761943 203 }
JimCarver 0:6b753f761943 204
JimCarver 0:6b753f761943 205 void palTimerFunc3(void const *argument)
JimCarver 0:6b753f761943 206 {
JimCarver 0:6b753f761943 207 static int counter =0;
JimCarver 0:6b753f761943 208 counter++;
JimCarver 0:6b753f761943 209 }
JimCarver 0:6b753f761943 210
JimCarver 0:6b753f761943 211 void palTimerFunc4(void const *argument)
JimCarver 0:6b753f761943 212 {
JimCarver 0:6b753f761943 213 static int counter =0;
JimCarver 0:6b753f761943 214 counter++;
JimCarver 0:6b753f761943 215 g_timerArgs.ticksInFunc1 = counter;
JimCarver 0:6b753f761943 216 }
JimCarver 0:6b753f761943 217
JimCarver 0:6b753f761943 218 void palTimerFunc5(void const *argument) // function to count calls + wait alternatin short and long periods for timer drift test
JimCarver 0:6b753f761943 219 {
JimCarver 0:6b753f761943 220 static int counter = 0;
JimCarver 0:6b753f761943 221 counter++;
JimCarver 0:6b753f761943 222 g_timerArgs.ticksInFunc1 = counter;
JimCarver 0:6b753f761943 223 if (counter % 2 == 0)
JimCarver 0:6b753f761943 224 {
JimCarver 0:6b753f761943 225 pal_osDelay(PAL_TIMER_TEST_TIME_TO_WAIT_MS_LONG);
JimCarver 0:6b753f761943 226 }
JimCarver 0:6b753f761943 227 else
JimCarver 0:6b753f761943 228 {
JimCarver 0:6b753f761943 229 pal_osDelay(PAL_TIMER_TEST_TIME_TO_WAIT_MS_SHORT);
JimCarver 0:6b753f761943 230 }
JimCarver 0:6b753f761943 231 }
JimCarver 0:6b753f761943 232
JimCarver 0:6b753f761943 233
JimCarver 0:6b753f761943 234 void palThreadFuncWaitForEverTest(void const *argument)
JimCarver 0:6b753f761943 235 {
JimCarver 0:6b753f761943 236 pal_osDelay(PAL_TIME_TO_WAIT_MS/2);
JimCarver 0:6b753f761943 237 pal_osSemaphoreRelease(*((palSemaphoreID_t*)(argument)));
JimCarver 0:6b753f761943 238 }
JimCarver 0:6b753f761943 239
JimCarver 0:6b753f761943 240 void palRunThreads()
JimCarver 0:6b753f761943 241 {
JimCarver 0:6b753f761943 242 palStatus_t status = PAL_SUCCESS;
JimCarver 0:6b753f761943 243 palThreadID_t threadID1 = NULLPTR;
JimCarver 0:6b753f761943 244 palThreadID_t threadID2 = NULLPTR;
JimCarver 0:6b753f761943 245 palThreadID_t threadID3 = NULLPTR;
JimCarver 0:6b753f761943 246 palThreadID_t threadID4 = NULLPTR;
JimCarver 0:6b753f761943 247 palThreadID_t threadID5 = NULLPTR;
JimCarver 0:6b753f761943 248 palThreadID_t threadID6 = NULLPTR;
JimCarver 0:6b753f761943 249
JimCarver 0:6b753f761943 250 status = pal_osThreadCreateWithAlloc(palThreadFunc1, &g_threadsArg, PAL_osPriorityIdle, PAL_TEST_THREAD_STACK_SIZE, NULL, &threadID1);
JimCarver 0:6b753f761943 251 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 252
JimCarver 0:6b753f761943 253 status = pal_osThreadCreateWithAlloc(palThreadFunc2, &g_threadsArg, PAL_osPriorityLow, PAL_TEST_THREAD_STACK_SIZE, NULL, &threadID2);
JimCarver 0:6b753f761943 254 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 255
JimCarver 0:6b753f761943 256 status = pal_osThreadCreateWithAlloc(palThreadFunc3, &g_threadsArg, PAL_osPriorityNormal, PAL_TEST_THREAD_STACK_SIZE, NULL, &threadID3);
JimCarver 0:6b753f761943 257 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 258
JimCarver 0:6b753f761943 259 status = pal_osThreadCreateWithAlloc(palThreadFunc4, &g_threadsArg, PAL_osPriorityBelowNormal, PAL_TEST_THREAD_STACK_SIZE, NULL, &threadID4);
JimCarver 0:6b753f761943 260 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 261
JimCarver 0:6b753f761943 262 status = pal_osDelay(PAL_RTOS_THREAD_CLEANUP_TIMER_MILISEC * 2); // dealy to work around mbedOS timer issue (starting more than 6 timers at once will cause a hang)
JimCarver 0:6b753f761943 263 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 264
JimCarver 0:6b753f761943 265 status = pal_osThreadCreateWithAlloc(palThreadFunc5, &g_threadsArg, PAL_osPriorityAboveNormal, PAL_TEST_THREAD_STACK_SIZE, NULL, &threadID5);
JimCarver 0:6b753f761943 266 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 267
JimCarver 0:6b753f761943 268 status = pal_osThreadCreateWithAlloc(palThreadFunc6, &g_threadsArg, PAL_osPriorityHigh, PAL_TEST_THREAD_STACK_SIZE, NULL, &threadID6);
JimCarver 0:6b753f761943 269 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 270
JimCarver 0:6b753f761943 271 pal_osDelay(PAL_TIME_TO_WAIT_MS/5);
JimCarver 0:6b753f761943 272
JimCarver 0:6b753f761943 273 status = pal_osThreadTerminate(&threadID1);
JimCarver 0:6b753f761943 274 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 275
JimCarver 0:6b753f761943 276 status = pal_osThreadTerminate(&threadID2);
JimCarver 0:6b753f761943 277 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 278
JimCarver 0:6b753f761943 279 status = pal_osThreadTerminate(&threadID3);
JimCarver 0:6b753f761943 280 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 281
JimCarver 0:6b753f761943 282 status = pal_osThreadTerminate(&threadID4);
JimCarver 0:6b753f761943 283 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 284
JimCarver 0:6b753f761943 285 status = pal_osThreadTerminate(&threadID5);
JimCarver 0:6b753f761943 286 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 287
JimCarver 0:6b753f761943 288 status = pal_osThreadTerminate(&threadID6);
JimCarver 0:6b753f761943 289 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 290 }
JimCarver 0:6b753f761943 291
JimCarver 0:6b753f761943 292 void RecursiveLockThread(void const *param)
JimCarver 0:6b753f761943 293 {
JimCarver 0:6b753f761943 294 size_t i = 0;
JimCarver 0:6b753f761943 295 palStatus_t status;
JimCarver 0:6b753f761943 296 palRecursiveMutexParam_t *actualParams = (palRecursiveMutexParam_t*)param;
JimCarver 0:6b753f761943 297 size_t countbeforeStart = 0;
JimCarver 0:6b753f761943 298 volatile palThreadID_t threadID = 10;
JimCarver 0:6b753f761943 299
JimCarver 0:6b753f761943 300 status = pal_osSemaphoreWait(actualParams->sem, PAL_RTOS_WAIT_FOREVER, NULL);
JimCarver 0:6b753f761943 301 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 302
JimCarver 0:6b753f761943 303 for (i = 0; i < 100; ++i)
JimCarver 0:6b753f761943 304 {
JimCarver 0:6b753f761943 305 status = pal_osMutexWait(actualParams->mtx, PAL_RTOS_WAIT_FOREVER);
JimCarver 0:6b753f761943 306 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 307 if (i == 0)
JimCarver 0:6b753f761943 308 {
JimCarver 0:6b753f761943 309 countbeforeStart = actualParams->count;
JimCarver 0:6b753f761943 310 TEST_ASSERT_EQUAL_HEX(NULLPTR, actualParams->activeThread);
JimCarver 0:6b753f761943 311 actualParams->activeThread = pal_osThreadGetId();
JimCarver 0:6b753f761943 312 }
JimCarver 0:6b753f761943 313 actualParams->count++;
JimCarver 0:6b753f761943 314 threadID = pal_osThreadGetId();
JimCarver 0:6b753f761943 315 TEST_ASSERT_NOT_EQUAL(NULLPTR, threadID);
JimCarver 0:6b753f761943 316 TEST_ASSERT_EQUAL(actualParams->activeThread, threadID);
JimCarver 0:6b753f761943 317 pal_osDelay(1);
JimCarver 0:6b753f761943 318 }
JimCarver 0:6b753f761943 319
JimCarver 0:6b753f761943 320 threadID = 10;
JimCarver 0:6b753f761943 321 pal_osDelay(50);
JimCarver 0:6b753f761943 322 TEST_ASSERT_EQUAL(100, actualParams->count - countbeforeStart);
JimCarver 0:6b753f761943 323 for (i = 0; i < 100; ++i)
JimCarver 0:6b753f761943 324 {
JimCarver 0:6b753f761943 325 threadID = pal_osThreadGetId();
JimCarver 0:6b753f761943 326 TEST_ASSERT_NOT_EQUAL(NULLPTR, threadID);
JimCarver 0:6b753f761943 327 TEST_ASSERT_EQUAL(actualParams->activeThread, threadID);
JimCarver 0:6b753f761943 328 actualParams->count++;
JimCarver 0:6b753f761943 329 if (i == 99)
JimCarver 0:6b753f761943 330 {
JimCarver 0:6b753f761943 331 TEST_ASSERT_EQUAL(200, actualParams->count - countbeforeStart);
JimCarver 0:6b753f761943 332 actualParams->activeThread = NULLPTR;
JimCarver 0:6b753f761943 333 }
JimCarver 0:6b753f761943 334
JimCarver 0:6b753f761943 335 status = pal_osMutexRelease(actualParams->mtx);
JimCarver 0:6b753f761943 336 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 337 pal_osDelay(1);
JimCarver 0:6b753f761943 338 }
JimCarver 0:6b753f761943 339
JimCarver 0:6b753f761943 340 status = pal_osSemaphoreRelease(actualParams->sem);
JimCarver 0:6b753f761943 341 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 342 }
JimCarver 0:6b753f761943 343