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