FRDM K64F Metronome

Committer:
ram54288
Date:
Sun May 14 18:37:05 2017 +0000
Revision:
0:dbad57390bd1
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ram54288 0:dbad57390bd1 1 /*
ram54288 0:dbad57390bd1 2 * Copyright (c) 2016 ARM Limited. All rights reserved.
ram54288 0:dbad57390bd1 3 * SPDX-License-Identifier: Apache-2.0
ram54288 0:dbad57390bd1 4 * Licensed under the Apache License, Version 2.0 (the License); you may
ram54288 0:dbad57390bd1 5 * not use this file except in compliance with the License.
ram54288 0:dbad57390bd1 6 * You may obtain a copy of the License at
ram54288 0:dbad57390bd1 7 *
ram54288 0:dbad57390bd1 8 * http://www.apache.org/licenses/LICENSE-2.0
ram54288 0:dbad57390bd1 9 *
ram54288 0:dbad57390bd1 10 * Unless required by applicable law or agreed to in writing, software
ram54288 0:dbad57390bd1 11 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
ram54288 0:dbad57390bd1 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ram54288 0:dbad57390bd1 13 * See the License for the specific language governing permissions and
ram54288 0:dbad57390bd1 14 * limitations under the License.
ram54288 0:dbad57390bd1 15 */
ram54288 0:dbad57390bd1 16
ram54288 0:dbad57390bd1 17 #include "pal_rtos.h"
ram54288 0:dbad57390bd1 18 #include "unity.h"
ram54288 0:dbad57390bd1 19 #include "unity_fixture.h"
ram54288 0:dbad57390bd1 20 #include "pal_rtos_test_utils.h"
ram54288 0:dbad57390bd1 21 #include "pal.h"
ram54288 0:dbad57390bd1 22 #include "pal_rtos_test_utils.h"
ram54288 0:dbad57390bd1 23
ram54288 0:dbad57390bd1 24 TEST_GROUP(pal_rtos);
ram54288 0:dbad57390bd1 25
ram54288 0:dbad57390bd1 26 //sometimes you may want to get at local data in a module.
ram54288 0:dbad57390bd1 27 //for example: If you plan to pass by reference, this could be useful
ram54288 0:dbad57390bd1 28 //however, it should often be avoided
ram54288 0:dbad57390bd1 29 //extern int Counter;
ram54288 0:dbad57390bd1 30 uint32_t g_threadStorage[20] = { 0 };
ram54288 0:dbad57390bd1 31 threadsArgument_t g_threadsArg = {0};
ram54288 0:dbad57390bd1 32 timerArgument_t g_timerArgs = {0};
ram54288 0:dbad57390bd1 33 palMutexID_t mutex1 = NULLPTR;
ram54288 0:dbad57390bd1 34 palMutexID_t mutex2 = NULLPTR;
ram54288 0:dbad57390bd1 35 palSemaphoreID_t semaphore1 = NULLPTR;
ram54288 0:dbad57390bd1 36
ram54288 0:dbad57390bd1 37 //forward declarations
ram54288 0:dbad57390bd1 38 void palRunThreads();
ram54288 0:dbad57390bd1 39
ram54288 0:dbad57390bd1 40
ram54288 0:dbad57390bd1 41 TEST_SETUP(pal_rtos)
ram54288 0:dbad57390bd1 42 {
ram54288 0:dbad57390bd1 43 //This is run before EACH TEST
ram54288 0:dbad57390bd1 44 //Counter = 0x5a5a;
ram54288 0:dbad57390bd1 45 }
ram54288 0:dbad57390bd1 46
ram54288 0:dbad57390bd1 47 TEST_TEAR_DOWN(pal_rtos)
ram54288 0:dbad57390bd1 48 {
ram54288 0:dbad57390bd1 49 }
ram54288 0:dbad57390bd1 50
ram54288 0:dbad57390bd1 51 TEST(pal_rtos, pal_osKernelSysTick_Unity)
ram54288 0:dbad57390bd1 52 {
ram54288 0:dbad57390bd1 53 uint32_t tick1 = 0, tick2 = 0;
ram54288 0:dbad57390bd1 54 tick1 = pal_osKernelSysTick();
ram54288 0:dbad57390bd1 55 tick2 = pal_osKernelSysTick();
ram54288 0:dbad57390bd1 56
ram54288 0:dbad57390bd1 57 TEST_ASSERT_TRUE(tick2 != tick1);
ram54288 0:dbad57390bd1 58 }
ram54288 0:dbad57390bd1 59
ram54288 0:dbad57390bd1 60 TEST(pal_rtos, pal_osKernelSysTick64_Unity)
ram54288 0:dbad57390bd1 61 {
ram54288 0:dbad57390bd1 62 uint64_t tick1 = 0, tick2 = 0;
ram54288 0:dbad57390bd1 63
ram54288 0:dbad57390bd1 64 tick1 = pal_osKernelSysTick64();
ram54288 0:dbad57390bd1 65 tick2 = pal_osKernelSysTick64();
ram54288 0:dbad57390bd1 66
ram54288 0:dbad57390bd1 67 TEST_ASSERT_TRUE(tick2 > tick1);
ram54288 0:dbad57390bd1 68 }
ram54288 0:dbad57390bd1 69
ram54288 0:dbad57390bd1 70 TEST(pal_rtos, pal_osKernelSysTickMicroSec_Unity)
ram54288 0:dbad57390bd1 71 {
ram54288 0:dbad57390bd1 72 uint64_t tick = 0;
ram54288 0:dbad57390bd1 73 uint64_t microSec = 2000 * 1000;
ram54288 0:dbad57390bd1 74
ram54288 0:dbad57390bd1 75 tick = pal_osKernelSysTickMicroSec(microSec);
ram54288 0:dbad57390bd1 76 TEST_ASSERT_TRUE(0 != tick);
ram54288 0:dbad57390bd1 77 }
ram54288 0:dbad57390bd1 78
ram54288 0:dbad57390bd1 79 TEST(pal_rtos, pal_osKernelSysMilliSecTick_Unity)
ram54288 0:dbad57390bd1 80 {
ram54288 0:dbad57390bd1 81 uint64_t tick = 0;
ram54288 0:dbad57390bd1 82 uint64_t microSec = 2000 * 1000;
ram54288 0:dbad57390bd1 83 uint64_t milliseconds = 0;
ram54288 0:dbad57390bd1 84
ram54288 0:dbad57390bd1 85 tick = pal_osKernelSysTickMicroSec(microSec);
ram54288 0:dbad57390bd1 86 TEST_ASSERT_TRUE(0 != tick);
ram54288 0:dbad57390bd1 87
ram54288 0:dbad57390bd1 88 milliseconds = pal_osKernelSysMilliSecTick(tick);
ram54288 0:dbad57390bd1 89 TEST_ASSERT_EQUAL(milliseconds, microSec/1000);
ram54288 0:dbad57390bd1 90 }
ram54288 0:dbad57390bd1 91
ram54288 0:dbad57390bd1 92
ram54288 0:dbad57390bd1 93 TEST(pal_rtos, pal_osKernelSysTickFrequency_Unity)
ram54288 0:dbad57390bd1 94 {
ram54288 0:dbad57390bd1 95 uint64_t frequency = 0;
ram54288 0:dbad57390bd1 96
ram54288 0:dbad57390bd1 97 frequency = pal_osKernelSysTickFrequency();
ram54288 0:dbad57390bd1 98
ram54288 0:dbad57390bd1 99 TEST_ASSERT_TRUE(frequency > 0);
ram54288 0:dbad57390bd1 100 }
ram54288 0:dbad57390bd1 101
ram54288 0:dbad57390bd1 102 TEST(pal_rtos, pal_osDelay_Unity)
ram54288 0:dbad57390bd1 103 {
ram54288 0:dbad57390bd1 104 palStatus_t status = PAL_SUCCESS;
ram54288 0:dbad57390bd1 105 uint32_t tick1 , tick2;
ram54288 0:dbad57390bd1 106
ram54288 0:dbad57390bd1 107 tick1 = pal_osKernelSysTick();
ram54288 0:dbad57390bd1 108 status = pal_osDelay(200);
ram54288 0:dbad57390bd1 109 tick2 = pal_osKernelSysTick();
ram54288 0:dbad57390bd1 110
ram54288 0:dbad57390bd1 111 TEST_ASSERT_TRUE(tick2 > tick1);
ram54288 0:dbad57390bd1 112 TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
ram54288 0:dbad57390bd1 113 }
ram54288 0:dbad57390bd1 114
ram54288 0:dbad57390bd1 115 TEST(pal_rtos, BasicTimeScenario)
ram54288 0:dbad57390bd1 116 {
ram54288 0:dbad57390bd1 117 palStatus_t status = PAL_SUCCESS;
ram54288 0:dbad57390bd1 118 uint32_t tick, tick1 , tick2 , index, tickDiff, tickDelta;
ram54288 0:dbad57390bd1 119 uint32_t tmp = 0;
ram54288 0:dbad57390bd1 120
ram54288 0:dbad57390bd1 121 tick1 = pal_osKernelSysTick();
ram54288 0:dbad57390bd1 122 for(index = 0 ; index < 2000 ; ++index)
ram54288 0:dbad57390bd1 123 ++tmp;
ram54288 0:dbad57390bd1 124 tick2 = pal_osKernelSysTick();
ram54288 0:dbad57390bd1 125
ram54288 0:dbad57390bd1 126 TEST_ASSERT_TRUE(tick1 != tick2);
ram54288 0:dbad57390bd1 127 TEST_ASSERT_TRUE(tick2 > tick1); // to check that the tick counts are incremantal - be aware of wrap-arounds
ram54288 0:dbad57390bd1 128
ram54288 0:dbad57390bd1 129 /****************************************/
ram54288 0:dbad57390bd1 130 tick1 = pal_osKernelSysTick();
ram54288 0:dbad57390bd1 131 status = pal_osDelay(2000);
ram54288 0:dbad57390bd1 132 tick2 = pal_osKernelSysTick();
ram54288 0:dbad57390bd1 133
ram54288 0:dbad57390bd1 134 TEST_ASSERT_TRUE(tick1 != tick2);
ram54288 0:dbad57390bd1 135 TEST_ASSERT_TRUE(tick2 > tick1);
ram54288 0:dbad57390bd1 136 TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
ram54288 0:dbad57390bd1 137
ram54288 0:dbad57390bd1 138 tickDiff = tick2 - tick1;
ram54288 0:dbad57390bd1 139 tick = pal_osKernelSysTickMicroSec(2000 * 1000);
ram54288 0:dbad57390bd1 140 // 10 milliseconds delta
ram54288 0:dbad57390bd1 141 tickDelta = pal_osKernelSysTickMicroSec(10 * 1000);
ram54288 0:dbad57390bd1 142 TEST_ASSERT_TRUE((tick - tickDelta < tickDiff) && (tickDiff < tick + tickDelta));
ram54288 0:dbad57390bd1 143 TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
ram54288 0:dbad57390bd1 144 }
ram54288 0:dbad57390bd1 145
ram54288 0:dbad57390bd1 146 TEST(pal_rtos, TimerUnityTest)
ram54288 0:dbad57390bd1 147 {
ram54288 0:dbad57390bd1 148 palStatus_t status = PAL_SUCCESS;
ram54288 0:dbad57390bd1 149 palTimerID_t timerID1 = NULLPTR;
ram54288 0:dbad57390bd1 150 palTimerID_t timerID2 = NULLPTR;
ram54288 0:dbad57390bd1 151 status = pal_init();
ram54288 0:dbad57390bd1 152 TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
ram54288 0:dbad57390bd1 153
ram54288 0:dbad57390bd1 154 status = pal_osTimerCreate(palTimerFunc1, NULL, palOsTimerOnce, &timerID1);
ram54288 0:dbad57390bd1 155 TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
ram54288 0:dbad57390bd1 156
ram54288 0:dbad57390bd1 157 status = pal_osTimerCreate(palTimerFunc2, NULL, palOsTimerPeriodic, &timerID2);
ram54288 0:dbad57390bd1 158 TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
ram54288 0:dbad57390bd1 159
ram54288 0:dbad57390bd1 160 g_timerArgs.ticksBeforeTimer = pal_osKernelSysTick();
ram54288 0:dbad57390bd1 161 status = pal_osTimerStart(timerID1, 1000);
ram54288 0:dbad57390bd1 162 TEST_PRINTF("ticks before Timer: 0 - %d\n", g_timerArgs.ticksBeforeTimer);
ram54288 0:dbad57390bd1 163 TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
ram54288 0:dbad57390bd1 164
ram54288 0:dbad57390bd1 165 g_timerArgs.ticksBeforeTimer = pal_osKernelSysTick();
ram54288 0:dbad57390bd1 166 status = pal_osTimerStart(timerID2, 1000);
ram54288 0:dbad57390bd1 167 TEST_PRINTF("ticks before Timer: 1 - %d\n", g_timerArgs.ticksBeforeTimer);
ram54288 0:dbad57390bd1 168 TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
ram54288 0:dbad57390bd1 169
ram54288 0:dbad57390bd1 170 status = pal_osDelay(1500);
ram54288 0:dbad57390bd1 171 TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
ram54288 0:dbad57390bd1 172
ram54288 0:dbad57390bd1 173 status = pal_osTimerStop(timerID2);
ram54288 0:dbad57390bd1 174 TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
ram54288 0:dbad57390bd1 175
ram54288 0:dbad57390bd1 176 status = pal_osTimerDelete(&timerID1);
ram54288 0:dbad57390bd1 177 TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
ram54288 0:dbad57390bd1 178 TEST_ASSERT_EQUAL(NULL, timerID1);
ram54288 0:dbad57390bd1 179
ram54288 0:dbad57390bd1 180 status = pal_osTimerDelete(&timerID2);
ram54288 0:dbad57390bd1 181 TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
ram54288 0:dbad57390bd1 182 TEST_ASSERT_EQUAL(NULL, timerID2);
ram54288 0:dbad57390bd1 183 }
ram54288 0:dbad57390bd1 184
ram54288 0:dbad57390bd1 185 TEST(pal_rtos, PrimitivesUnityTest1)
ram54288 0:dbad57390bd1 186 {
ram54288 0:dbad57390bd1 187 palStatus_t status = PAL_SUCCESS;
ram54288 0:dbad57390bd1 188 status = pal_init(NULL);
ram54288 0:dbad57390bd1 189 TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
ram54288 0:dbad57390bd1 190
ram54288 0:dbad57390bd1 191 status = pal_osMutexCreate(&mutex1);
ram54288 0:dbad57390bd1 192 TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
ram54288 0:dbad57390bd1 193
ram54288 0:dbad57390bd1 194 status = pal_osMutexCreate(&mutex2);
ram54288 0:dbad57390bd1 195 TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
ram54288 0:dbad57390bd1 196
ram54288 0:dbad57390bd1 197 status = pal_osSemaphoreCreate(1 ,&semaphore1);
ram54288 0:dbad57390bd1 198 TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
ram54288 0:dbad57390bd1 199
ram54288 0:dbad57390bd1 200 palRunThreads();
ram54288 0:dbad57390bd1 201
ram54288 0:dbad57390bd1 202 //! sleep for 10 seconds to let the threads finish their functions
ram54288 0:dbad57390bd1 203 status = pal_osDelay(10000);
ram54288 0:dbad57390bd1 204 TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
ram54288 0:dbad57390bd1 205
ram54288 0:dbad57390bd1 206 status = pal_osSemaphoreDelete(&semaphore1);
ram54288 0:dbad57390bd1 207 TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
ram54288 0:dbad57390bd1 208 TEST_ASSERT_EQUAL(NULL, semaphore1);
ram54288 0:dbad57390bd1 209
ram54288 0:dbad57390bd1 210 status = pal_osMutexDelete(&mutex1);
ram54288 0:dbad57390bd1 211 TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
ram54288 0:dbad57390bd1 212 TEST_ASSERT_EQUAL(NULL, mutex1);
ram54288 0:dbad57390bd1 213
ram54288 0:dbad57390bd1 214 status = pal_osMutexDelete(&mutex2);
ram54288 0:dbad57390bd1 215 TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
ram54288 0:dbad57390bd1 216 TEST_ASSERT_EQUAL(NULL, mutex2);
ram54288 0:dbad57390bd1 217
ram54288 0:dbad57390bd1 218 }
ram54288 0:dbad57390bd1 219
ram54288 0:dbad57390bd1 220 TEST(pal_rtos, PrimitivesUnityTest2)
ram54288 0:dbad57390bd1 221 {
ram54288 0:dbad57390bd1 222 palStatus_t status = PAL_SUCCESS;
ram54288 0:dbad57390bd1 223 int32_t tmp = 0;
ram54288 0:dbad57390bd1 224 palThreadID_t threadID = NULLPTR;
ram54288 0:dbad57390bd1 225 uint32_t stack1; //we have small stack just to pass NON-NULL paramter
ram54288 0:dbad57390bd1 226
ram54288 0:dbad57390bd1 227 //Check Thread parameter validation
ram54288 0:dbad57390bd1 228 status = pal_osThreadCreate(NULL, NULL, PAL_osPriorityIdle, 1024, &stack1, NULL, &threadID);
ram54288 0:dbad57390bd1 229 TEST_ASSERT_EQUAL(PAL_ERR_INVALID_ARGUMENT, status);
ram54288 0:dbad57390bd1 230
ram54288 0:dbad57390bd1 231 status = pal_osThreadCreate(palThreadFunc1, NULL, PAL_osPriorityError, 1024, &stack1, NULL, &threadID);
ram54288 0:dbad57390bd1 232 TEST_ASSERT_EQUAL(PAL_ERR_INVALID_ARGUMENT, status);
ram54288 0:dbad57390bd1 233
ram54288 0:dbad57390bd1 234 status = pal_osThreadCreate(palThreadFunc1, NULL, PAL_osPriorityIdle, 0, &stack1, NULL, &threadID);
ram54288 0:dbad57390bd1 235 TEST_ASSERT_EQUAL(PAL_ERR_INVALID_ARGUMENT, status);
ram54288 0:dbad57390bd1 236
ram54288 0:dbad57390bd1 237 status = pal_osThreadCreate(palThreadFunc1, NULL, PAL_osPriorityIdle, 1024, NULL, NULL, &threadID);
ram54288 0:dbad57390bd1 238 TEST_ASSERT_EQUAL(PAL_ERR_INVALID_ARGUMENT, status);
ram54288 0:dbad57390bd1 239
ram54288 0:dbad57390bd1 240 status = pal_osThreadCreate(palThreadFunc1, NULL, PAL_osPriorityIdle, 1024, &stack1, NULL, NULL);
ram54288 0:dbad57390bd1 241 TEST_ASSERT_EQUAL(PAL_ERR_INVALID_ARGUMENT, status);
ram54288 0:dbad57390bd1 242
ram54288 0:dbad57390bd1 243 //Check Semaphore parameter validation
ram54288 0:dbad57390bd1 244 status = pal_osSemaphoreCreate(1 ,NULL);
ram54288 0:dbad57390bd1 245 TEST_ASSERT_EQUAL(PAL_ERR_INVALID_ARGUMENT, status);
ram54288 0:dbad57390bd1 246
ram54288 0:dbad57390bd1 247 status = pal_osSemaphoreDelete(NULL);
ram54288 0:dbad57390bd1 248 TEST_ASSERT_EQUAL(PAL_ERR_INVALID_ARGUMENT, status);
ram54288 0:dbad57390bd1 249
ram54288 0:dbad57390bd1 250 status = pal_osSemaphoreWait(NULLPTR, 1000, &tmp);
ram54288 0:dbad57390bd1 251 TEST_ASSERT_EQUAL(PAL_ERR_INVALID_ARGUMENT, status);
ram54288 0:dbad57390bd1 252
ram54288 0:dbad57390bd1 253 status = pal_osSemaphoreWait(tmp, 1000, NULL);
ram54288 0:dbad57390bd1 254 TEST_ASSERT_EQUAL(PAL_ERR_INVALID_ARGUMENT, status);
ram54288 0:dbad57390bd1 255
ram54288 0:dbad57390bd1 256 status = pal_osSemaphoreRelease(NULLPTR);
ram54288 0:dbad57390bd1 257 TEST_ASSERT_EQUAL(PAL_ERR_INVALID_ARGUMENT, status);
ram54288 0:dbad57390bd1 258 }
ram54288 0:dbad57390bd1 259
ram54288 0:dbad57390bd1 260 TEST(pal_rtos, MemoryPoolUnityTest)
ram54288 0:dbad57390bd1 261 {
ram54288 0:dbad57390bd1 262 palStatus_t status = PAL_SUCCESS;
ram54288 0:dbad57390bd1 263 palMemoryPoolID_t poolID1 = NULLPTR;
ram54288 0:dbad57390bd1 264 palMemoryPoolID_t poolID2 = NULLPTR;
ram54288 0:dbad57390bd1 265 uint8_t* ptr1[MEMORY_POOL1_BLOCK_COUNT] = {0};
ram54288 0:dbad57390bd1 266 uint8_t* ptr2[MEMORY_POOL2_BLOCK_COUNT] = {0};
ram54288 0:dbad57390bd1 267
ram54288 0:dbad57390bd1 268 status = pal_init(NULL);
ram54288 0:dbad57390bd1 269 TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
ram54288 0:dbad57390bd1 270
ram54288 0:dbad57390bd1 271 status = pal_osPoolCreate(MEMORY_POOL1_BLOCK_SIZE, MEMORY_POOL1_BLOCK_COUNT, &poolID1);
ram54288 0:dbad57390bd1 272 TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
ram54288 0:dbad57390bd1 273
ram54288 0:dbad57390bd1 274 status = pal_osPoolCreate(MEMORY_POOL2_BLOCK_SIZE, MEMORY_POOL2_BLOCK_COUNT, &poolID2);
ram54288 0:dbad57390bd1 275 TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
ram54288 0:dbad57390bd1 276
ram54288 0:dbad57390bd1 277 for(uint8_t block1 = 0 ; block1 < MEMORY_POOL1_BLOCK_COUNT; ++block1)
ram54288 0:dbad57390bd1 278 {
ram54288 0:dbad57390bd1 279 ptr1[block1] = pal_osPoolAlloc(poolID1);
ram54288 0:dbad57390bd1 280 TEST_ASSERT_NOT_EQUAL(ptr1[block1], NULL);
ram54288 0:dbad57390bd1 281 }
ram54288 0:dbad57390bd1 282 for(uint8_t block2 = 0 ; block2 < MEMORY_POOL2_BLOCK_COUNT; ++block2)
ram54288 0:dbad57390bd1 283 {
ram54288 0:dbad57390bd1 284 ptr2[block2] = pal_osPoolCAlloc(poolID2);
ram54288 0:dbad57390bd1 285 TEST_ASSERT_NOT_EQUAL(ptr2[block2], NULL);
ram54288 0:dbad57390bd1 286 }
ram54288 0:dbad57390bd1 287
ram54288 0:dbad57390bd1 288 for(uint8_t freeblock1 = 0; freeblock1 < MEMORY_POOL1_BLOCK_COUNT; ++freeblock1)
ram54288 0:dbad57390bd1 289 {
ram54288 0:dbad57390bd1 290 status = pal_osPoolFree(poolID1, ptr1[freeblock1]);
ram54288 0:dbad57390bd1 291 TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
ram54288 0:dbad57390bd1 292 }
ram54288 0:dbad57390bd1 293
ram54288 0:dbad57390bd1 294 for(uint8_t freeblock2 = 0; freeblock2 < MEMORY_POOL2_BLOCK_COUNT; ++freeblock2)
ram54288 0:dbad57390bd1 295 {
ram54288 0:dbad57390bd1 296 status = pal_osPoolFree(poolID2, ptr2[freeblock2]);
ram54288 0:dbad57390bd1 297 TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
ram54288 0:dbad57390bd1 298 }
ram54288 0:dbad57390bd1 299
ram54288 0:dbad57390bd1 300 status = pal_osPoolDestroy(&poolID1);
ram54288 0:dbad57390bd1 301 TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
ram54288 0:dbad57390bd1 302 TEST_ASSERT_EQUAL(poolID1, NULL);
ram54288 0:dbad57390bd1 303 status = pal_osPoolDestroy(&poolID2);
ram54288 0:dbad57390bd1 304 TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
ram54288 0:dbad57390bd1 305 TEST_ASSERT_EQUAL(poolID2, NULL);
ram54288 0:dbad57390bd1 306 }
ram54288 0:dbad57390bd1 307
ram54288 0:dbad57390bd1 308
ram54288 0:dbad57390bd1 309 TEST(pal_rtos, MessageUnityTest)
ram54288 0:dbad57390bd1 310 {
ram54288 0:dbad57390bd1 311 palStatus_t status = PAL_SUCCESS;
ram54288 0:dbad57390bd1 312 palMessageQID_t messageQID = NULLPTR;
ram54288 0:dbad57390bd1 313 uint32_t infoToSend = 3215;
ram54288 0:dbad57390bd1 314 uint32_t infoToGet = 0;
ram54288 0:dbad57390bd1 315
ram54288 0:dbad57390bd1 316 status = pal_init(NULL);
ram54288 0:dbad57390bd1 317 TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
ram54288 0:dbad57390bd1 318
ram54288 0:dbad57390bd1 319 status = pal_osMessageQueueCreate(10, &messageQID);
ram54288 0:dbad57390bd1 320 TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
ram54288 0:dbad57390bd1 321
ram54288 0:dbad57390bd1 322 status = pal_osMessagePut(messageQID, infoToSend, 1500);
ram54288 0:dbad57390bd1 323 TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
ram54288 0:dbad57390bd1 324
ram54288 0:dbad57390bd1 325 status = pal_osMessageGet(messageQID, 1500, &infoToGet);
ram54288 0:dbad57390bd1 326
ram54288 0:dbad57390bd1 327 TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
ram54288 0:dbad57390bd1 328 TEST_ASSERT_EQUAL_UINT32(infoToSend, infoToGet);
ram54288 0:dbad57390bd1 329
ram54288 0:dbad57390bd1 330 status = pal_osMessageQueueDestroy(&messageQID);
ram54288 0:dbad57390bd1 331 TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
ram54288 0:dbad57390bd1 332 TEST_ASSERT_EQUAL(messageQID, NULL);
ram54288 0:dbad57390bd1 333 }
ram54288 0:dbad57390bd1 334
ram54288 0:dbad57390bd1 335 TEST(pal_rtos, AtomicIncrementUnityTest)
ram54288 0:dbad57390bd1 336 {
ram54288 0:dbad57390bd1 337 int32_t num1 = 0;
ram54288 0:dbad57390bd1 338 int32_t increment = 10;
ram54288 0:dbad57390bd1 339 int32_t tmp = 0;
ram54288 0:dbad57390bd1 340 int32_t original = num1;
ram54288 0:dbad57390bd1 341
ram54288 0:dbad57390bd1 342 tmp = pal_osAtomicIncrement(&num1, increment);
ram54288 0:dbad57390bd1 343
ram54288 0:dbad57390bd1 344
ram54288 0:dbad57390bd1 345 TEST_ASSERT_EQUAL(original + increment, tmp);
ram54288 0:dbad57390bd1 346
ram54288 0:dbad57390bd1 347 }
ram54288 0:dbad57390bd1 348
ram54288 0:dbad57390bd1 349 TEST(pal_rtos, pal_init_test)
ram54288 0:dbad57390bd1 350 {
ram54288 0:dbad57390bd1 351 palStatus_t status = PAL_SUCCESS;
ram54288 0:dbad57390bd1 352
ram54288 0:dbad57390bd1 353 status = pal_init();
ram54288 0:dbad57390bd1 354 TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
ram54288 0:dbad57390bd1 355
ram54288 0:dbad57390bd1 356 status = pal_init();
ram54288 0:dbad57390bd1 357 TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
ram54288 0:dbad57390bd1 358
ram54288 0:dbad57390bd1 359 status = pal_init();
ram54288 0:dbad57390bd1 360 TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
ram54288 0:dbad57390bd1 361
ram54288 0:dbad57390bd1 362 pal_destroy();
ram54288 0:dbad57390bd1 363
ram54288 0:dbad57390bd1 364 pal_destroy();
ram54288 0:dbad57390bd1 365
ram54288 0:dbad57390bd1 366 pal_destroy();
ram54288 0:dbad57390bd1 367
ram54288 0:dbad57390bd1 368 pal_destroy();
ram54288 0:dbad57390bd1 369 }
ram54288 0:dbad57390bd1 370
ram54288 0:dbad57390bd1 371 TEST(pal_rtos, CustomizedTest)
ram54288 0:dbad57390bd1 372 {
ram54288 0:dbad57390bd1 373 palStatus_t status = PAL_SUCCESS;
ram54288 0:dbad57390bd1 374 palThreadID_t threadID1 = NULLPTR;
ram54288 0:dbad57390bd1 375 palThreadID_t threadID2 = NULLPTR;
ram54288 0:dbad57390bd1 376 uint32_t *stack1 = (uint32_t*)malloc(sizeof(uint32_t) * 512);
ram54288 0:dbad57390bd1 377 uint32_t *stack2 = (uint32_t*)malloc(sizeof(uint32_t) * 512);
ram54288 0:dbad57390bd1 378
ram54288 0:dbad57390bd1 379
ram54288 0:dbad57390bd1 380 status = pal_osThreadCreate(palThreadFuncCustom1, NULL, PAL_osPriorityAboveNormal, 1024, stack1, NULL, &threadID1);
ram54288 0:dbad57390bd1 381 TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
ram54288 0:dbad57390bd1 382
ram54288 0:dbad57390bd1 383 status = pal_osThreadCreate(palThreadFuncCustom2, NULL, PAL_osPriorityHigh, 1024, stack2, NULL, &threadID2);
ram54288 0:dbad57390bd1 384 TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
ram54288 0:dbad57390bd1 385
ram54288 0:dbad57390bd1 386 pal_osDelay(3000);
ram54288 0:dbad57390bd1 387
ram54288 0:dbad57390bd1 388 status = pal_osThreadTerminate(&threadID1);
ram54288 0:dbad57390bd1 389 TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
ram54288 0:dbad57390bd1 390
ram54288 0:dbad57390bd1 391 status = pal_osThreadTerminate(&threadID2);
ram54288 0:dbad57390bd1 392 TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
ram54288 0:dbad57390bd1 393
ram54288 0:dbad57390bd1 394
ram54288 0:dbad57390bd1 395 status = pal_osThreadCreate(palThreadFuncCustom1, NULL, PAL_osPriorityAboveNormal, 1024, stack1, NULL, &threadID1);
ram54288 0:dbad57390bd1 396 TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
ram54288 0:dbad57390bd1 397
ram54288 0:dbad57390bd1 398 status = pal_osThreadCreate(palThreadFuncCustom2, NULL, PAL_osPriorityHigh, 1024, stack2, NULL, &threadID2);
ram54288 0:dbad57390bd1 399 TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
ram54288 0:dbad57390bd1 400
ram54288 0:dbad57390bd1 401 pal_osDelay(3000);
ram54288 0:dbad57390bd1 402 status = pal_osThreadTerminate(&threadID1);
ram54288 0:dbad57390bd1 403 TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
ram54288 0:dbad57390bd1 404
ram54288 0:dbad57390bd1 405 status = pal_osThreadTerminate(&threadID2);
ram54288 0:dbad57390bd1 406 TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
ram54288 0:dbad57390bd1 407 pal_osDelay(500);
ram54288 0:dbad57390bd1 408
ram54288 0:dbad57390bd1 409 free(stack1);
ram54288 0:dbad57390bd1 410 free(stack2);
ram54288 0:dbad57390bd1 411
ram54288 0:dbad57390bd1 412 }
ram54288 0:dbad57390bd1 413