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 "pal.h"
JimCarver 0:6b753f761943 18 #include "unity.h"
JimCarver 0:6b753f761943 19 #include "unity_fixture.h"
JimCarver 0:6b753f761943 20 #include "pal_rtos_test_utils.h"
JimCarver 0:6b753f761943 21 #include <string.h>
JimCarver 0:6b753f761943 22 #include <stdlib.h>
JimCarver 0:6b753f761943 23 #include "sotp.h"
JimCarver 0:6b753f761943 24 #include "pal_plat_rtos.h"
JimCarver 0:6b753f761943 25
JimCarver 0:6b753f761943 26 TEST_GROUP(pal_rtos);
JimCarver 0:6b753f761943 27
JimCarver 0:6b753f761943 28 //Sometimes you may want to get local data in a module,
JimCarver 0:6b753f761943 29 //for example if you need to pass a reference.
JimCarver 0:6b753f761943 30 //However, you should usually avoid this.
JimCarver 0:6b753f761943 31 //extern int Counter;
JimCarver 0:6b753f761943 32 threadsArgument_t g_threadsArg = {0};
JimCarver 0:6b753f761943 33 timerArgument_t g_timerArgs = {0};
JimCarver 0:6b753f761943 34 palMutexID_t mutex1 = NULLPTR;
JimCarver 0:6b753f761943 35 palMutexID_t mutex2 = NULLPTR;
JimCarver 0:6b753f761943 36 palSemaphoreID_t semaphore1 = NULLPTR;
JimCarver 0:6b753f761943 37 palRecursiveMutexParam_t* recursiveMutexData = NULL;
JimCarver 0:6b753f761943 38 #define PAL_RUNNING_TEST_TIME 5 //estimation on length of test in seconds
JimCarver 0:6b753f761943 39 #define PAL_TEST_HIGH_RES_TIMER 100
JimCarver 0:6b753f761943 40 #define PAL_TEST_HIGH_RES_TIMER2 10
JimCarver 0:6b753f761943 41 #define PAL_TEST_PERCENTAGE_LOW 95
JimCarver 0:6b753f761943 42 #define PAL_TEST_PERCENTAGE_HIGH 105
JimCarver 0:6b753f761943 43 #define PAL_TEST_PERCENTAGE_HUNDRED 100
JimCarver 0:6b753f761943 44
JimCarver 0:6b753f761943 45 //Forward declarations
JimCarver 0:6b753f761943 46 void palRunThreads(void);
JimCarver 0:6b753f761943 47
JimCarver 0:6b753f761943 48
JimCarver 0:6b753f761943 49 TEST_SETUP(pal_rtos)
JimCarver 0:6b753f761943 50 {
JimCarver 0:6b753f761943 51 palStatus_t status = PAL_SUCCESS;
JimCarver 0:6b753f761943 52 status = pal_init();
JimCarver 0:6b753f761943 53 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 54
JimCarver 0:6b753f761943 55 }
JimCarver 0:6b753f761943 56
JimCarver 0:6b753f761943 57 TEST_TEAR_DOWN(pal_rtos)
JimCarver 0:6b753f761943 58 {
JimCarver 0:6b753f761943 59 if (NULL != recursiveMutexData)
JimCarver 0:6b753f761943 60 {
JimCarver 0:6b753f761943 61 if (recursiveMutexData->higherPriorityThread != NULLPTR)
JimCarver 0:6b753f761943 62 {
JimCarver 0:6b753f761943 63 pal_osThreadTerminate(&(recursiveMutexData->higherPriorityThread));
JimCarver 0:6b753f761943 64 }
JimCarver 0:6b753f761943 65 if (recursiveMutexData->lowerPriorityThread != NULLPTR)
JimCarver 0:6b753f761943 66 {
JimCarver 0:6b753f761943 67 pal_osThreadTerminate(&(recursiveMutexData->lowerPriorityThread));
JimCarver 0:6b753f761943 68 }
JimCarver 0:6b753f761943 69 if (recursiveMutexData->mtx != NULLPTR)
JimCarver 0:6b753f761943 70 {
JimCarver 0:6b753f761943 71 pal_osMutexDelete(&(recursiveMutexData->mtx));
JimCarver 0:6b753f761943 72 }
JimCarver 0:6b753f761943 73 if (recursiveMutexData->sem != NULLPTR)
JimCarver 0:6b753f761943 74 {
JimCarver 0:6b753f761943 75 pal_osSemaphoreDelete(&recursiveMutexData->sem);
JimCarver 0:6b753f761943 76 }
JimCarver 0:6b753f761943 77 free(recursiveMutexData);
JimCarver 0:6b753f761943 78 recursiveMutexData = NULL;
JimCarver 0:6b753f761943 79 }
JimCarver 0:6b753f761943 80 pal_destroy();
JimCarver 0:6b753f761943 81 }
JimCarver 0:6b753f761943 82
JimCarver 0:6b753f761943 83 /*! \brief Sanity check of the kernel system tick API.
JimCarver 0:6b753f761943 84 * Fails if system tic value is zero (**note:** this can sometimes happen on wrap-around).
JimCarver 0:6b753f761943 85 *
JimCarver 0:6b753f761943 86 * | # | Step | Expected |
JimCarver 0:6b753f761943 87 * |---|--------------------------------|-------------|
JimCarver 0:6b753f761943 88 * | 1 | Get current tick count using `pal_osKernelSysTick` and check that it is not 0. | PAL_SUCCESS |
JimCarver 0:6b753f761943 89 */
JimCarver 0:6b753f761943 90 TEST(pal_rtos, pal_osKernelSysTick_Unity)
JimCarver 0:6b753f761943 91 {
JimCarver 0:6b753f761943 92 uint32_t tick1 = 0, tick2 = 0;
JimCarver 0:6b753f761943 93 /*#1*/
JimCarver 0:6b753f761943 94 tick1 = pal_osKernelSysTick();
JimCarver 0:6b753f761943 95 PAL_PRINTF("%" PRIu32 " %" PRIu32 "\n", tick1, tick2);
JimCarver 0:6b753f761943 96
JimCarver 0:6b753f761943 97 TEST_ASSERT_TRUE(tick2 != tick1);
JimCarver 0:6b753f761943 98 }
JimCarver 0:6b753f761943 99
JimCarver 0:6b753f761943 100 /*! \brief Sanity check of the kernel system tick API.
JimCarver 0:6b753f761943 101 * Fails if two calls return the same `sysTick` value.
JimCarver 0:6b753f761943 102 *
JimCarver 0:6b753f761943 103 * | # | Step | Expected |
JimCarver 0:6b753f761943 104 * |---|--------------------------------|-------------|
JimCarver 0:6b753f761943 105 * | 1 | Get current tick count using `pal_osKernelSysTick`. | PAL_SUCCESS |
JimCarver 0:6b753f761943 106 * | 2 | Get current tick count using `pal_osKernelSysTick`. | PAL_SUCCESS |
JimCarver 0:6b753f761943 107 * | 3 | Check that the two tick count values are not the same. | PAL_SUCCESS |
JimCarver 0:6b753f761943 108 */
JimCarver 0:6b753f761943 109 TEST(pal_rtos, pal_osKernelSysTick64_Unity)
JimCarver 0:6b753f761943 110 {
JimCarver 0:6b753f761943 111 uint64_t tick1 = 0, tick2 = 0;
JimCarver 0:6b753f761943 112 /*#1*/
JimCarver 0:6b753f761943 113 tick1 = pal_osKernelSysTick();
JimCarver 0:6b753f761943 114 /*#2*/
JimCarver 0:6b753f761943 115 tick2 = pal_osKernelSysTick();
JimCarver 0:6b753f761943 116 /*#3*/
JimCarver 0:6b753f761943 117 TEST_ASSERT_TRUE(tick2 >= tick1);
JimCarver 0:6b753f761943 118 }
JimCarver 0:6b753f761943 119
JimCarver 0:6b753f761943 120 /*! \brief Check the conversion from a non-zero `sysTick` value to microseconds.
JimCarver 0:6b753f761943 121 * Verify that the result is not 0.
JimCarver 0:6b753f761943 122 *
JimCarver 0:6b753f761943 123 * | # | Step | Expected |
JimCarver 0:6b753f761943 124 * |---|--------------------------------|-------------|
JimCarver 0:6b753f761943 125 * | 1 | Convert a nubmer in `sysTicks` to microseconds using `pal_osKernelSysTickMicroSec` and check it is not 0. | PAL_SUCCESS |
JimCarver 0:6b753f761943 126 */
JimCarver 0:6b753f761943 127 TEST(pal_rtos, pal_osKernelSysTickMicroSec_Unity)
JimCarver 0:6b753f761943 128 {
JimCarver 0:6b753f761943 129 uint64_t tick = 0;
JimCarver 0:6b753f761943 130 uint64_t microSec = 2000 * 1000;
JimCarver 0:6b753f761943 131 /*#1*/
JimCarver 0:6b753f761943 132 tick = pal_osKernelSysTickMicroSec(microSec);
JimCarver 0:6b753f761943 133 TEST_ASSERT_TRUE(0 != tick);
JimCarver 0:6b753f761943 134 }
JimCarver 0:6b753f761943 135
JimCarver 0:6b753f761943 136 /*! \brief Sanity check of non-zero values conversion between microseconds to ticks to milliseconds.
JimCarver 0:6b753f761943 137 * Verify that the result is correct when converting the input (microseconds) to the test output (milliseconds).
JimCarver 0:6b753f761943 138 *
JimCarver 0:6b753f761943 139 * | # | Step | Expected |
JimCarver 0:6b753f761943 140 * |---|--------------------------------|-------------|
JimCarver 0:6b753f761943 141 * | 1 | Convert a nubmer in `sysTicks` to mircorseconds using `pal_osKernelSysTickMicroSec` and check it is not 0. | PAL_SUCCESS |
JimCarver 0:6b753f761943 142 * | 2 | Convert a nubmer in `sysTicks` to milliseconds using `pal_osKernelSysMilliSecTick` and check the returned value. | PAL_SUCCESS |
JimCarver 0:6b753f761943 143 */
JimCarver 0:6b753f761943 144 TEST(pal_rtos, pal_osKernelSysMilliSecTick_Unity)
JimCarver 0:6b753f761943 145 {
JimCarver 0:6b753f761943 146 uint64_t tick = 0;
JimCarver 0:6b753f761943 147 uint64_t microSec = 200 * 1000;
JimCarver 0:6b753f761943 148 uint64_t milliseconds = 0;
JimCarver 0:6b753f761943 149 /*#1*/
JimCarver 0:6b753f761943 150 tick = pal_osKernelSysTickMicroSec(microSec);
JimCarver 0:6b753f761943 151 TEST_ASSERT_TRUE(0 != tick);
JimCarver 0:6b753f761943 152 /*#2*/
JimCarver 0:6b753f761943 153 milliseconds = pal_osKernelSysMilliSecTick(tick);
JimCarver 0:6b753f761943 154 TEST_ASSERT_EQUAL(microSec/1000, milliseconds);
JimCarver 0:6b753f761943 155
JimCarver 0:6b753f761943 156 }
JimCarver 0:6b753f761943 157
JimCarver 0:6b753f761943 158 /*! \brief Verify that the tick frequency function returns a non-zero value.
JimCarver 0:6b753f761943 159 *
JimCarver 0:6b753f761943 160 * | # | Step | Expected |
JimCarver 0:6b753f761943 161 * |---|--------------------------------|-------------|
JimCarver 0:6b753f761943 162 * | 1 | Get the kernel `sysTick` frequency and check that it is positive. | PAL_SUCCESS |
JimCarver 0:6b753f761943 163 */
JimCarver 0:6b753f761943 164 TEST(pal_rtos, pal_osKernelSysTickFrequency_Unity)
JimCarver 0:6b753f761943 165 {
JimCarver 0:6b753f761943 166 uint64_t frequency = 0;
JimCarver 0:6b753f761943 167 /*#1*/
JimCarver 0:6b753f761943 168 frequency = pal_osKernelSysTickFrequency();
JimCarver 0:6b753f761943 169
JimCarver 0:6b753f761943 170 TEST_ASSERT_TRUE(frequency > 0);
JimCarver 0:6b753f761943 171 }
JimCarver 0:6b753f761943 172
JimCarver 0:6b753f761943 173 /*! \brief Sanity check for the Delay API, verifying that `sysTick` increments after delay.
JimCarver 0:6b753f761943 174 * The test reads two system tick values. Between the two calls, it calls the delay function and
JimCarver 0:6b753f761943 175 * verifies that the tick values are different.
JimCarver 0:6b753f761943 176 *
JimCarver 0:6b753f761943 177 * | # | Step | Expected |
JimCarver 0:6b753f761943 178 * |---|--------------------------------|-------------|
JimCarver 0:6b753f761943 179 * | 1 | Get the kernel `sysTick` value. | PAL_SUCCESS |
JimCarver 0:6b753f761943 180 * | 2 | Sleep for a short period . | PAL_SUCCESS |
JimCarver 0:6b753f761943 181 * | 3 | Get the kernel `sysTick` value. | PAL_SUCCESS |
JimCarver 0:6b753f761943 182 * | 4 | Check that second tick value is greater than the first. | PAL_SUCCESS |
JimCarver 0:6b753f761943 183 */
JimCarver 0:6b753f761943 184 TEST(pal_rtos, pal_osDelay_Unity)
JimCarver 0:6b753f761943 185 {
JimCarver 0:6b753f761943 186 palStatus_t status = PAL_SUCCESS;
JimCarver 0:6b753f761943 187 uint32_t tick1 , tick2;
JimCarver 0:6b753f761943 188 /*#1*/
JimCarver 0:6b753f761943 189 tick1 = pal_osKernelSysTick();
JimCarver 0:6b753f761943 190 /*#2*/
JimCarver 0:6b753f761943 191 status = pal_osDelay(200);
JimCarver 0:6b753f761943 192 /*#3*/
JimCarver 0:6b753f761943 193 tick2 = pal_osKernelSysTick();
JimCarver 0:6b753f761943 194 /*#4*/
JimCarver 0:6b753f761943 195 TEST_ASSERT_TRUE(tick2 > tick1);
JimCarver 0:6b753f761943 196 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 197 }
JimCarver 0:6b753f761943 198
JimCarver 0:6b753f761943 199 /*! \brief Test for basic timing scenarios based on calls for the ticks and delay
JimCarver 0:6b753f761943 200 * functionality while verifying that results meet the defined deltas.
JimCarver 0:6b753f761943 201 *
JimCarver 0:6b753f761943 202 * | # | Step | Expected |
JimCarver 0:6b753f761943 203 * |---|--------------------------------|-------------|
JimCarver 0:6b753f761943 204 * | 1 | Get the kernel `sysTick` value. | PAL_SUCCESS |
JimCarver 0:6b753f761943 205 * | 2 | Sleep for a very short period. | PAL_SUCCESS |
JimCarver 0:6b753f761943 206 * | 3 | Get the kernel `sysTick` value. | PAL_SUCCESS |
JimCarver 0:6b753f761943 207 * | 4 | Check that second tick value is greater than the first. | PAL_SUCCESS |
JimCarver 0:6b753f761943 208 * | 5 | Get the kernel `sysTick` value. | PAL_SUCCESS |
JimCarver 0:6b753f761943 209 * | 6 | Sleep for a longer period. | PAL_SUCCESS |
JimCarver 0:6b753f761943 210 * | 7 | Get the kernel `sysTick` value. | PAL_SUCCESS |
JimCarver 0:6b753f761943 211 * | 8 | Check that second tick value is greated than the first. | PAL_SUCCESS |
JimCarver 0:6b753f761943 212 * | 9 | Calculate the difference between the ticks. | PAL_SUCCESS |
JimCarver 0:6b753f761943 213 * | 10 | Convert last sleep period to ticks. | PAL_SUCCESS |
JimCarver 0:6b753f761943 214 * | 11 | Check that the tick period is correct (same as sleep period +/-delta). | PAL_SUCCESS |
JimCarver 0:6b753f761943 215 */
JimCarver 0:6b753f761943 216 TEST(pal_rtos, BasicTimeScenario)
JimCarver 0:6b753f761943 217 {
JimCarver 0:6b753f761943 218 palStatus_t status = PAL_SUCCESS;
JimCarver 0:6b753f761943 219 uint64_t tick, tick1 , tick2 , tickDiff, tickDelta;
JimCarver 0:6b753f761943 220
JimCarver 0:6b753f761943 221 /*#1*/
JimCarver 0:6b753f761943 222 tick1 = pal_osKernelSysTick();
JimCarver 0:6b753f761943 223 /*#2*/
JimCarver 0:6b753f761943 224 status = pal_osDelay(1);
JimCarver 0:6b753f761943 225 /*#3*/
JimCarver 0:6b753f761943 226 tick2 = pal_osKernelSysTick();
JimCarver 0:6b753f761943 227
JimCarver 0:6b753f761943 228 /*#4*/
JimCarver 0:6b753f761943 229 TEST_ASSERT_TRUE(tick1 != tick2);
JimCarver 0:6b753f761943 230 TEST_ASSERT_TRUE(tick2 > tick1); // To check that the tick counts are incremental - be aware of wrap-arounds
JimCarver 0:6b753f761943 231 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 232 /****************************************/
JimCarver 0:6b753f761943 233 /*#5*/
JimCarver 0:6b753f761943 234 tick1 = pal_osKernelSysTick();
JimCarver 0:6b753f761943 235 /*#6*/
JimCarver 0:6b753f761943 236 status = pal_osDelay(2000);
JimCarver 0:6b753f761943 237 /*#7*/
JimCarver 0:6b753f761943 238 tick2 = pal_osKernelSysTick();
JimCarver 0:6b753f761943 239
JimCarver 0:6b753f761943 240 /*#8*/
JimCarver 0:6b753f761943 241 TEST_ASSERT_TRUE(tick1 != tick2);
JimCarver 0:6b753f761943 242 TEST_ASSERT_TRUE(tick2 > tick1);
JimCarver 0:6b753f761943 243 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 244
JimCarver 0:6b753f761943 245 /*#9*/
JimCarver 0:6b753f761943 246 tickDiff = tick2 - tick1;
JimCarver 0:6b753f761943 247 /*#10*/
JimCarver 0:6b753f761943 248 tick = pal_osKernelSysTickMicroSec(2000 * 1000);
JimCarver 0:6b753f761943 249 // 10 milliseconds delta
JimCarver 0:6b753f761943 250 /*#11*/
JimCarver 0:6b753f761943 251 tickDelta = pal_osKernelSysTickMicroSec(10 * 1000);
JimCarver 0:6b753f761943 252 TEST_ASSERT_TRUE((tick - tickDelta < tickDiff) && (tickDiff < tick + tickDelta));
JimCarver 0:6b753f761943 253 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 254 }
JimCarver 0:6b753f761943 255
JimCarver 0:6b753f761943 256 /*! \brief Create two timers: periodic and one-shot. Starts both timers,
JimCarver 0:6b753f761943 257 * then causes a delay to allow output from the timer functions to be printed on the console.
JimCarver 0:6b753f761943 258 *
JimCarver 0:6b753f761943 259 * | # | Step | Expected |
JimCarver 0:6b753f761943 260 * |---|--------------------------------------------------------------------------------------------------|--------------------------------|
JimCarver 0:6b753f761943 261 * | 1 | Create a one-shot timer, which calls `palTimerFunc1` when triggered, using `pal_osTimerCreate`. | PAL_SUCCESS |
JimCarver 0:6b753f761943 262 * | 2 | Create a periodic timer, which calls `palTimerFunc2` when triggered, using `pal_osTimerCreate`. | PAL_SUCCESS |
JimCarver 0:6b753f761943 263 * | 3 | Get the kernel `sysTick` value. | PAL_SUCCESS |
JimCarver 0:6b753f761943 264 * | 4 | Start the first timer using `pal_osTimerStart`. | PAL_SUCCESS |
JimCarver 0:6b753f761943 265 * | 5 | Get the kernel `sysTick` value. | PAL_SUCCESS |
JimCarver 0:6b753f761943 266 * | 6 | Start the first timer using `pal_osTimerStart`. | PAL_SUCCESS |
JimCarver 0:6b753f761943 267 * | 7 | Sleep for a period. | PAL_SUCCESS |
JimCarver 0:6b753f761943 268 * | 8 | Stop the second timer using `pal_osTimerStop`. | PAL_SUCCESS |
JimCarver 0:6b753f761943 269 * | 9 | Delete the first timer using `pal_osTimerDelete`. | PAL_SUCCESS |
JimCarver 0:6b753f761943 270 * | 10 | Delete the second timer using `pal_osTimerDelete`. | PAL_SUCCESS |
JimCarver 0:6b753f761943 271 * | 11 | Create a periodic timer, which calls `palTimerFunc3` when triggered, using `pal_osTimerCreate`. | PAL_SUCCESS |
JimCarver 0:6b753f761943 272 * | 12 | Create a periodic timer, which calls `palTimerFunc4` when triggered, using `pal_osTimerCreate`. | PAL_ERR_NO_HIGH_RES_TIMER_LEFT |
JimCarver 0:6b753f761943 273 * | 13 | Start the first timer using `pal_osTimerStart` as high res timer. | PAL_SUCCESS |
JimCarver 0:6b753f761943 274 * | 14 | Start the second timer using `pal_osTimerStart` as high res timer. | PAL_ERR_NO_HIGH_RES_TIMER_LEFT |
JimCarver 0:6b753f761943 275 * | 15 | Sleep for a period. | PAL_SUCCESS |
JimCarver 0:6b753f761943 276 * | 16 | Stop the second timer using `pal_osTimerStop`. | PAL_SUCCESS |
JimCarver 0:6b753f761943 277 * | 17 | Start the second timer using `pal_osTimerStart` as high res timer | PAL_SUCCESS |
JimCarver 0:6b753f761943 278 * | 18 | Sleep for a period. | PAL_SUCCESS |
JimCarver 0:6b753f761943 279 * | 19 | Delete the first timer using `pal_osTimerDelete`. | PAL_SUCCESS |
JimCarver 0:6b753f761943 280 * | 20 | Delete the second timer using `pal_osTimerDelete`. | PAL_SUCCESS |
JimCarver 0:6b753f761943 281 * | 21 | Create a periodic timer, which calls `palTimerFunc5` when triggered, using `pal_osTimerCreate`. | PAL_SUCCESS |
JimCarver 0:6b753f761943 282 * | 22 | Sleep for a period. | PAL_SUCCESS |
JimCarver 0:6b753f761943 283 * | 23 | Delete the first timer using `pal_osTimerDelete`. | PAL_SUCCESS |
JimCarver 0:6b753f761943 284 * | 24 | Stop the timer using `pal_osTimerStop`. and check the number of callbacks is correct | PAL_SUCCESS |
JimCarver 0:6b753f761943 285 * | 25 | Delete the timer using `pal_osTimerDelete`. | PAL_SUCCESS |
JimCarver 0:6b753f761943 286 * | 26 | Start the timer with zero millisec. | PAL_ERR_RTOS_VALUE |
JimCarver 0:6b753f761943 287 * | 27 | Delete the timer using `pal_osTimerDelete`. | PAL_SUCCESS |
JimCarver 0:6b753f761943 288 */
JimCarver 0:6b753f761943 289 TEST(pal_rtos, TimerUnityTest)
JimCarver 0:6b753f761943 290 {
JimCarver 0:6b753f761943 291 palStatus_t status = PAL_SUCCESS;
JimCarver 0:6b753f761943 292 palTimerID_t timerID1 = NULLPTR;
JimCarver 0:6b753f761943 293 palTimerID_t timerID2 = NULLPTR;
JimCarver 0:6b753f761943 294 /*#1*/
JimCarver 0:6b753f761943 295 status = pal_osTimerCreate(palTimerFunc1, NULL, palOsTimerOnce, &timerID1);
JimCarver 0:6b753f761943 296 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 297 /*#2*/
JimCarver 0:6b753f761943 298 status = pal_osTimerCreate(palTimerFunc2, NULL, palOsTimerPeriodic, &timerID2);
JimCarver 0:6b753f761943 299 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 300 /*#3*/
JimCarver 0:6b753f761943 301 g_timerArgs.ticksBeforeTimer = pal_osKernelSysTick();
JimCarver 0:6b753f761943 302 /*#4*/
JimCarver 0:6b753f761943 303 status = pal_osTimerStart(timerID1, 1000);
JimCarver 0:6b753f761943 304 PAL_PRINTF("ticks before Timer: 0 - %" PRIu32 "\n", g_timerArgs.ticksBeforeTimer);
JimCarver 0:6b753f761943 305 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 306 /*#5*/
JimCarver 0:6b753f761943 307 g_timerArgs.ticksBeforeTimer = pal_osKernelSysTick();
JimCarver 0:6b753f761943 308 /*#6*/
JimCarver 0:6b753f761943 309 status = pal_osTimerStart(timerID2, 1000);
JimCarver 0:6b753f761943 310 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 311 /*#7*/
JimCarver 0:6b753f761943 312 status = pal_osDelay(1500);
JimCarver 0:6b753f761943 313 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 314 /*#8*/
JimCarver 0:6b753f761943 315 status = pal_osTimerStop(timerID2);
JimCarver 0:6b753f761943 316 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 317 /*#9*/
JimCarver 0:6b753f761943 318 status = pal_osTimerDelete(&timerID1);
JimCarver 0:6b753f761943 319 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 320 TEST_ASSERT_EQUAL(NULLPTR, timerID1);
JimCarver 0:6b753f761943 321 /*#10*/
JimCarver 0:6b753f761943 322 status = pal_osTimerDelete(&timerID2);
JimCarver 0:6b753f761943 323 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 324 TEST_ASSERT_EQUAL(NULLPTR, timerID2);
JimCarver 0:6b753f761943 325
JimCarver 0:6b753f761943 326 g_timerArgs.ticksBeforeTimer = 0;
JimCarver 0:6b753f761943 327 g_timerArgs.ticksInFunc1 = 0;
JimCarver 0:6b753f761943 328 g_timerArgs.ticksInFunc2 = 0;
JimCarver 0:6b753f761943 329
JimCarver 0:6b753f761943 330 /*#11*/
JimCarver 0:6b753f761943 331 status = pal_osTimerCreate(palTimerFunc3, NULL, palOsTimerPeriodic, &timerID1);
JimCarver 0:6b753f761943 332 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 333
JimCarver 0:6b753f761943 334 /*#12*/
JimCarver 0:6b753f761943 335 status = pal_osTimerCreate(palTimerFunc4, NULL, palOsTimerPeriodic, &timerID2);
JimCarver 0:6b753f761943 336 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 337
JimCarver 0:6b753f761943 338 /*#13*/
JimCarver 0:6b753f761943 339 status = pal_osTimerStart(timerID1, PAL_TEST_HIGH_RES_TIMER);
JimCarver 0:6b753f761943 340 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 341
JimCarver 0:6b753f761943 342 /*#14*/
JimCarver 0:6b753f761943 343 status = pal_osTimerStart(timerID2, PAL_TEST_HIGH_RES_TIMER);
JimCarver 0:6b753f761943 344 if (PAL_SUCCESS == status) // behavior is slightly different for Linux due to high res timer limitation there (only one at a time supported there)
JimCarver 0:6b753f761943 345 {
JimCarver 0:6b753f761943 346 status = pal_osTimerStop(timerID2);
JimCarver 0:6b753f761943 347 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 348 }
JimCarver 0:6b753f761943 349 else
JimCarver 0:6b753f761943 350 {
JimCarver 0:6b753f761943 351 TEST_ASSERT_EQUAL_HEX(PAL_ERR_NO_HIGH_RES_TIMER_LEFT, status);
JimCarver 0:6b753f761943 352 }
JimCarver 0:6b753f761943 353 /*#15*/
JimCarver 0:6b753f761943 354 status = pal_osDelay(500);
JimCarver 0:6b753f761943 355 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 356
JimCarver 0:6b753f761943 357 /*#16*/
JimCarver 0:6b753f761943 358 status = pal_osTimerStop(timerID1);
JimCarver 0:6b753f761943 359 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 360
JimCarver 0:6b753f761943 361 /*#17*/
JimCarver 0:6b753f761943 362 status = pal_osTimerStart(timerID2, PAL_TEST_HIGH_RES_TIMER2);
JimCarver 0:6b753f761943 363 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 364
JimCarver 0:6b753f761943 365 /*#18*/
JimCarver 0:6b753f761943 366 status = pal_osDelay(PAL_TIME_TO_WAIT_SHORT_MS);
JimCarver 0:6b753f761943 367 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 368
JimCarver 0:6b753f761943 369 status = pal_osTimerStop(timerID2);
JimCarver 0:6b753f761943 370 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 371
JimCarver 0:6b753f761943 372 TEST_ASSERT_TRUE(g_timerArgs.ticksInFunc1 >= ((PAL_TIME_TO_WAIT_SHORT_MS / PAL_TEST_HIGH_RES_TIMER2)*PAL_TEST_PERCENTAGE_LOW)/ PAL_TEST_PERCENTAGE_HUNDRED); // check there is at least more than 95% of expected timer callbacks.
JimCarver 0:6b753f761943 373
JimCarver 0:6b753f761943 374 /*#19*/
JimCarver 0:6b753f761943 375 status = pal_osTimerDelete(&timerID1);
JimCarver 0:6b753f761943 376 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 377 TEST_ASSERT_EQUAL(NULLPTR, timerID1);
JimCarver 0:6b753f761943 378
JimCarver 0:6b753f761943 379 /*#20*/
JimCarver 0:6b753f761943 380 status = pal_osTimerDelete(&timerID2);
JimCarver 0:6b753f761943 381 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 382 TEST_ASSERT_EQUAL(NULLPTR, timerID2);
JimCarver 0:6b753f761943 383
JimCarver 0:6b753f761943 384 /*#21*/
JimCarver 0:6b753f761943 385 g_timerArgs.ticksBeforeTimer = 0;
JimCarver 0:6b753f761943 386 g_timerArgs.ticksInFunc1 = 0;
JimCarver 0:6b753f761943 387 g_timerArgs.ticksInFunc2 = 0;
JimCarver 0:6b753f761943 388
JimCarver 0:6b753f761943 389 status = pal_osTimerCreate(palTimerFunc5, NULL, palOsTimerPeriodic, &timerID1);
JimCarver 0:6b753f761943 390 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 391
JimCarver 0:6b753f761943 392 /*#22*/
JimCarver 0:6b753f761943 393 status = pal_osTimerStart(timerID1, PAL_TEST_HIGH_RES_TIMER);
JimCarver 0:6b753f761943 394 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 395
JimCarver 0:6b753f761943 396 /*#23*/
JimCarver 0:6b753f761943 397 status = pal_osDelay(PAL_TIME_TO_WAIT_MS);
JimCarver 0:6b753f761943 398 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 399
JimCarver 0:6b753f761943 400 /*#24*/
JimCarver 0:6b753f761943 401 status = pal_osTimerStop(timerID1);
JimCarver 0:6b753f761943 402 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 403
JimCarver 0:6b753f761943 404 TEST_ASSERT_TRUE(g_timerArgs.ticksInFunc1 >= ((PAL_TIME_TO_WAIT_MS / PAL_TEST_HIGH_RES_TIMER) * PAL_TEST_PERCENTAGE_LOW) / PAL_TEST_PERCENTAGE_HUNDRED); // check there is at least more than 95% of expected timer callbacks.
JimCarver 0:6b753f761943 405 TEST_ASSERT_TRUE(g_timerArgs.ticksInFunc1 <= ((PAL_TIME_TO_WAIT_MS / PAL_TEST_HIGH_RES_TIMER) * PAL_TEST_PERCENTAGE_HIGH) / PAL_TEST_PERCENTAGE_HUNDRED); // check there is at most less than 105% of expected timer callbacks.
JimCarver 0:6b753f761943 406
JimCarver 0:6b753f761943 407 /*#25*/
JimCarver 0:6b753f761943 408 status = pal_osTimerDelete(&timerID1);
JimCarver 0:6b753f761943 409 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 410 TEST_ASSERT_EQUAL(NULLPTR, timerID1);
JimCarver 0:6b753f761943 411
JimCarver 0:6b753f761943 412 /*#26*/
JimCarver 0:6b753f761943 413 status = pal_osTimerCreate(palTimerFunc5, NULL, palOsTimerPeriodic, &timerID1);
JimCarver 0:6b753f761943 414 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 415 status = pal_osTimerStart(timerID1, 0);
JimCarver 0:6b753f761943 416 TEST_ASSERT_EQUAL_HEX(PAL_ERR_RTOS_VALUE, status);
JimCarver 0:6b753f761943 417
JimCarver 0:6b753f761943 418 /*#27*/
JimCarver 0:6b753f761943 419 status = pal_osTimerDelete(&timerID1);
JimCarver 0:6b753f761943 420 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 421 }
JimCarver 0:6b753f761943 422
JimCarver 0:6b753f761943 423 /*! \brief Creates mutexes and semaphores and uses them to communicate between
JimCarver 0:6b753f761943 424 * the different threads it creates (as defined in `pal_rtos_test_utils.c`).
JimCarver 0:6b753f761943 425 * In this test, we check that thread communication is working as expected between the threads and in the designed order.
JimCarver 0:6b753f761943 426 * In one case, we expect the thread to fail to lock a mutex – (thread1).
JimCarver 0:6b753f761943 427 * Threads are created with different priorities (PAL enforces this attribute).
JimCarver 0:6b753f761943 428 * For each case, the thread function prints the expected result. The test code verifies this result as well.
JimCarver 0:6b753f761943 429 *
JimCarver 0:6b753f761943 430 * | # | Step | Expected |
JimCarver 0:6b753f761943 431 * |---|--------------------------------|-------------|
JimCarver 0:6b753f761943 432 * | 1 | Create a mutex using `pal_osMutexCreate`. | PAL_SUCCESS |
JimCarver 0:6b753f761943 433 * | 2 | Create a mutex using `pal_osMutexCreate`. | PAL_SUCCESS |
JimCarver 0:6b753f761943 434 * | 3 | Create a semaphore with count 1. | PAL_SUCCESS |
JimCarver 0:6b753f761943 435 * | 4 | Run the PAL test threads using the `palRunThreads` test function. | PAL_SUCCESS |
JimCarver 0:6b753f761943 436 * | 5 | Delete the semaphore using `pal_osSemaphoreDelete`. | PAL_SUCCESS |
JimCarver 0:6b753f761943 437 * | 6 | Delete the first mutex using `pal_osMutexDelete`. | PAL_SUCCESS |
JimCarver 0:6b753f761943 438 * | 7 | Delete the second mutex using `pal_osMutexDelete`. | PAL_SUCCESS |
JimCarver 0:6b753f761943 439 */
JimCarver 0:6b753f761943 440 TEST(pal_rtos, PrimitivesUnityTest1)
JimCarver 0:6b753f761943 441 {
JimCarver 0:6b753f761943 442 palStatus_t status = PAL_SUCCESS;
JimCarver 0:6b753f761943 443 /*#1*/
JimCarver 0:6b753f761943 444 status = pal_osMutexCreate(&mutex1);
JimCarver 0:6b753f761943 445 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 446 /*#2*/
JimCarver 0:6b753f761943 447 status = pal_osMutexCreate(&mutex2);
JimCarver 0:6b753f761943 448 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 449 /*#3*/
JimCarver 0:6b753f761943 450 status = pal_osSemaphoreCreate(1 ,&semaphore1);
JimCarver 0:6b753f761943 451 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 452 /*#4*/
JimCarver 0:6b753f761943 453 palRunThreads();
JimCarver 0:6b753f761943 454 /*#5*/
JimCarver 0:6b753f761943 455 status = pal_osSemaphoreDelete(&semaphore1);
JimCarver 0:6b753f761943 456 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 457 TEST_ASSERT_EQUAL(NULLPTR, semaphore1);
JimCarver 0:6b753f761943 458 /*#6*/
JimCarver 0:6b753f761943 459 status = pal_osMutexDelete(&mutex1);
JimCarver 0:6b753f761943 460 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 461 TEST_ASSERT_EQUAL(NULLPTR, mutex1);
JimCarver 0:6b753f761943 462 /*#7*/
JimCarver 0:6b753f761943 463 status = pal_osMutexDelete(&mutex2);
JimCarver 0:6b753f761943 464 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 465 TEST_ASSERT_EQUAL(NULLPTR, mutex2);
JimCarver 0:6b753f761943 466
JimCarver 0:6b753f761943 467 }
JimCarver 0:6b753f761943 468
JimCarver 0:6b753f761943 469 /*! \brief Verifies that several RTOS primitives APIs can handle invalid
JimCarver 0:6b753f761943 470 * arguments. The test calls each API with invalid arguments and verifies the result.
JimCarver 0:6b753f761943 471 * It also verifies that the semaphore wait API can accept NULL as the third parameter.
JimCarver 0:6b753f761943 472 *
JimCarver 0:6b753f761943 473 * | # | Step | Expected |
JimCarver 0:6b753f761943 474 * |---|------------------------------------------------------------------------------|--------------------------|
JimCarver 0:6b753f761943 475 * | 1 | Test thread creation with invalid arguments (`pal_osThreadCreateWithAlloc`). | PAL_ERR_INVALID_ARGUMENT |
JimCarver 0:6b753f761943 476 * | 2 | Test thread creation with invalid arguments (`pal_osThreadCreateWithAlloc`). | PAL_ERR_INVALID_ARGUMENT |
JimCarver 0:6b753f761943 477 * | 3 | Test thread creation with invalid arguments (`pal_osThreadCreateWithAlloc`). | PAL_ERR_INVALID_ARGUMENT |
JimCarver 0:6b753f761943 478 * | 4 | Test semaphore creation with invalid arguments (`pal_osSemaphoreCreate`). | PAL_ERR_INVALID_ARGUMENT |
JimCarver 0:6b753f761943 479 * | 5 | Test semaphore creation with invalid arguments (`pal_osSemaphoreCreate`). | PAL_ERR_INVALID_ARGUMENT |
JimCarver 0:6b753f761943 480 * | 6 | Test semaphore creation with invalid arguments (`pal_osSemaphoreCreate`). | PAL_ERR_INVALID_ARGUMENT |
JimCarver 0:6b753f761943 481 * | 7 | Test semaphore creation with invalid arguments (`pal_osSemaphoreCreate`). | PAL_ERR_INVALID_ARGUMENT |
JimCarver 0:6b753f761943 482 * | 8 | Test legacy thread create api (pal_osThreadCreate). | PAL_SUCCESS |
JimCarver 0:6b753f761943 483 * | 9 | Call pal_osThreadTerminate with NULL invalid parameter. | PAL_ERR_INVALID_ARGUMENT |
JimCarver 0:6b753f761943 484 */
JimCarver 0:6b753f761943 485 TEST(pal_rtos, PrimitivesUnityTest2)
JimCarver 0:6b753f761943 486 {
JimCarver 0:6b753f761943 487 #ifdef DEBUG
JimCarver 0:6b753f761943 488 palStatus_t status = PAL_SUCCESS;
JimCarver 0:6b753f761943 489 palThreadID_t threadID = NULLPTR;
JimCarver 0:6b753f761943 490 int32_t tmp = 0;
JimCarver 0:6b753f761943 491 /*#1*/
JimCarver 0:6b753f761943 492 //Check thread parameter validation
JimCarver 0:6b753f761943 493 status = pal_osThreadCreateWithAlloc(palThreadFunc1, NULL, PAL_osPriorityError, 1024, NULL, &threadID);
JimCarver 0:6b753f761943 494 TEST_ASSERT_EQUAL_HEX(PAL_ERR_INVALID_ARGUMENT, status);
JimCarver 0:6b753f761943 495 /*#2*/
JimCarver 0:6b753f761943 496 status = pal_osThreadCreateWithAlloc(palThreadFunc1, NULL, PAL_osPriorityIdle, 0, NULL, &threadID);
JimCarver 0:6b753f761943 497 TEST_ASSERT_EQUAL_HEX(PAL_ERR_INVALID_ARGUMENT, status);
JimCarver 0:6b753f761943 498 /*#3*/
JimCarver 0:6b753f761943 499 status = pal_osThreadCreateWithAlloc(palThreadFunc1, NULL, PAL_osPriorityIdle, 1024, NULL, NULL);
JimCarver 0:6b753f761943 500 TEST_ASSERT_EQUAL_HEX(PAL_ERR_INVALID_ARGUMENT, status);
JimCarver 0:6b753f761943 501
JimCarver 0:6b753f761943 502 /*#4*/
JimCarver 0:6b753f761943 503 //Check semaphore parameter validation
JimCarver 0:6b753f761943 504 status = pal_osSemaphoreCreate(1 ,NULL);
JimCarver 0:6b753f761943 505 TEST_ASSERT_EQUAL_HEX(PAL_ERR_INVALID_ARGUMENT, status);
JimCarver 0:6b753f761943 506 /*#5*/
JimCarver 0:6b753f761943 507 status = pal_osSemaphoreDelete(NULL);
JimCarver 0:6b753f761943 508 TEST_ASSERT_EQUAL_HEX(PAL_ERR_INVALID_ARGUMENT, status);
JimCarver 0:6b753f761943 509 /*#6*/
JimCarver 0:6b753f761943 510 status = pal_osSemaphoreWait(NULLPTR, 1000, &tmp);
JimCarver 0:6b753f761943 511 TEST_ASSERT_EQUAL_HEX(PAL_ERR_INVALID_ARGUMENT, status);
JimCarver 0:6b753f761943 512 /*#7*/
JimCarver 0:6b753f761943 513 status = pal_osSemaphoreRelease(NULLPTR);
JimCarver 0:6b753f761943 514 TEST_ASSERT_EQUAL_HEX(PAL_ERR_INVALID_ARGUMENT, status);
JimCarver 0:6b753f761943 515 /*#9*/
JimCarver 0:6b753f761943 516 status = pal_osThreadTerminate(NULL);
JimCarver 0:6b753f761943 517 TEST_ASSERT_EQUAL_HEX(PAL_ERR_INVALID_ARGUMENT, status);
JimCarver 0:6b753f761943 518 #endif
JimCarver 0:6b753f761943 519 }
JimCarver 0:6b753f761943 520
JimCarver 0:6b753f761943 521 /*! \brief Creates a semaphore with count=1 and a thread to
JimCarver 0:6b753f761943 522 * test that it waits forever (the test waits 5 seconds). Then deletes the semaphore
JimCarver 0:6b753f761943 523 * and terminates the thread.
JimCarver 0:6b753f761943 524 *
JimCarver 0:6b753f761943 525 * | # | Step | Expected |
JimCarver 0:6b753f761943 526 * |---|--------------------------------|-------------|
JimCarver 0:6b753f761943 527 * | 1 | Create a semaphore with count = 1 using `pal_osSemaphoreCreate`. | PAL_SUCCESS |
JimCarver 0:6b753f761943 528 * | 2 | Wait for the semaphore using `pal_osSemaphoreWait` (should not block). | PAL_SUCCESS |
JimCarver 0:6b753f761943 529 * | 3 | Create a thread running `palThreadFuncWaitForEverTestusing` and `pal_osThreadCreateWithAlloc`. | PAL_SUCCESS |
JimCarver 0:6b753f761943 530 * | 4 | Set time using `pal_osSetTime`. | PAL_SUCCESS |
JimCarver 0:6b753f761943 531 * | 5 | Wait for the semaphore using `pal_osSemaphoreWait` (should block; released by thread). | PAL_SUCCESS |
JimCarver 0:6b753f761943 532 * | 6 | Delete the semaphore using `pal_osSemaphoreDelete`. | PAL_SUCCESS |
JimCarver 0:6b753f761943 533 * | 7 | Terminate the thread using `pal_osThreadTerminate`. | PAL_SUCCESS |
JimCarver 0:6b753f761943 534 */
JimCarver 0:6b753f761943 535 TEST(pal_rtos, SemaphoreWaitForever)
JimCarver 0:6b753f761943 536 {
JimCarver 0:6b753f761943 537 int32_t count = 0;
JimCarver 0:6b753f761943 538 uint64_t timeElapsed = PAL_MIN_SEC_FROM_EPOCH;
JimCarver 0:6b753f761943 539 uint64_t timePassedInSec;
JimCarver 0:6b753f761943 540 palStatus_t status = PAL_SUCCESS;
JimCarver 0:6b753f761943 541 palThreadID_t threadID1 = PAL_INVALID_THREAD;
JimCarver 0:6b753f761943 542
JimCarver 0:6b753f761943 543 /*#1*/
JimCarver 0:6b753f761943 544 status = pal_osSemaphoreCreate(1 ,&semaphore1);
JimCarver 0:6b753f761943 545 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 546 /*#2*/
JimCarver 0:6b753f761943 547 status = pal_osSemaphoreWait(semaphore1, PAL_RTOS_WAIT_FOREVER, &count);
JimCarver 0:6b753f761943 548 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 549 /*#3*/
JimCarver 0:6b753f761943 550 status = pal_osSetTime(timeElapsed);
JimCarver 0:6b753f761943 551 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status); // More than current epoch time -> success
JimCarver 0:6b753f761943 552 status = pal_osThreadCreateWithAlloc(palThreadFuncWaitForEverTest, (void *)&semaphore1, PAL_osPriorityAboveNormal, PAL_TEST_THREAD_STACK_SIZE, NULL, &threadID1);
JimCarver 0:6b753f761943 553 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 554 /*#4*/
JimCarver 0:6b753f761943 555 status = pal_osSemaphoreWait(semaphore1, PAL_RTOS_WAIT_FOREVER, &count);
JimCarver 0:6b753f761943 556 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 557 /*#5*/
JimCarver 0:6b753f761943 558 timePassedInSec = pal_osGetTime();
JimCarver 0:6b753f761943 559 TEST_ASSERT_EQUAL_HEX(0, (timePassedInSec - timeElapsed) >= PAL_TIME_TO_WAIT_MS/2);
JimCarver 0:6b753f761943 560 /*#6*/
JimCarver 0:6b753f761943 561 status = pal_osSemaphoreDelete(&semaphore1);
JimCarver 0:6b753f761943 562 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 563 TEST_ASSERT_EQUAL(0, semaphore1);
JimCarver 0:6b753f761943 564 /*#7*/
JimCarver 0:6b753f761943 565 status = pal_osThreadTerminate(&threadID1);
JimCarver 0:6b753f761943 566 TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 567 }
JimCarver 0:6b753f761943 568
JimCarver 0:6b753f761943 569 /*! \brief Creates a semaphore and waits on it to verify the
JimCarver 0:6b753f761943 570 * available count for it. Also verifies that the semaphore release API works correctly.
JimCarver 0:6b753f761943 571 * In addition, it checks the semaphore parameter validation scenarios.
JimCarver 0:6b753f761943 572 *
JimCarver 0:6b753f761943 573 * | # | Step | Expected |
JimCarver 0:6b753f761943 574 * |---|--------------------------------|-------------|
JimCarver 0:6b753f761943 575 * | 1 | Create a semaphore with count = 2 using `pal_osSemaphoreCreate`. | PAL_SUCCESS |
JimCarver 0:6b753f761943 576 * | 2 | Wait for the semaphore using `pal_osSemaphoreWait` (should not block), and check count. | PAL_SUCCESS |
JimCarver 0:6b753f761943 577 * | 3 | Increase semaphore count by ten using `pal_osSemaphoreRelease` in a loop. | PAL_SUCCESS |
JimCarver 0:6b753f761943 578 * | 4 | Delete semaphore using `pal_osSemaphoreDelete`. | PAL_SUCCESS |
JimCarver 0:6b753f761943 579 * | 5 | Test semaphore creation with invalid arguments (`pal_osSemaphoreCreate`). | PAL_ERR_INVALID_ARGUMENT |
JimCarver 0:6b753f761943 580 * | 6 | Test semaphore deletion with invalid arguments (`pal_osSemaphoreDelete`). | PAL_ERR_INVALID_ARGUMENT |
JimCarver 0:6b753f761943 581 * | 7 | Test semaphore waiting with invalid arguments (`pal_osSemaphoreWait`). | PAL_ERR_INVALID_ARGUMENT |
JimCarver 0:6b753f761943 582 * | 8 | Test semaphore release with invalid arguments (`pal_osSemaphoreRelease`). | PAL_ERR_INVALID_ARGUMENT |
JimCarver 0:6b753f761943 583 */
JimCarver 0:6b753f761943 584 TEST(pal_rtos, SemaphoreBasicTest)
JimCarver 0:6b753f761943 585 {
JimCarver 0:6b753f761943 586
JimCarver 0:6b753f761943 587 palStatus_t status = PAL_SUCCESS;
JimCarver 0:6b753f761943 588 int counter = 0;
JimCarver 0:6b753f761943 589 /*#1*/
JimCarver 0:6b753f761943 590 status = pal_osSemaphoreCreate(2 ,&semaphore1);
JimCarver 0:6b753f761943 591 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 592 /*#2*/
JimCarver 0:6b753f761943 593 int32_t count = -1;
JimCarver 0:6b753f761943 594 status = pal_osSemaphoreWait(semaphore1, 1000, &count);
JimCarver 0:6b753f761943 595 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 596 TEST_ASSERT_EQUAL(1, count);
JimCarver 0:6b753f761943 597
JimCarver 0:6b753f761943 598 /*#3*/
JimCarver 0:6b753f761943 599 for(counter = 0; counter < 10; counter++)
JimCarver 0:6b753f761943 600 {
JimCarver 0:6b753f761943 601 status=pal_osSemaphoreRelease(semaphore1);
JimCarver 0:6b753f761943 602 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 603 }
JimCarver 0:6b753f761943 604 /*#4*/
JimCarver 0:6b753f761943 605 status=pal_osSemaphoreDelete(&semaphore1);
JimCarver 0:6b753f761943 606 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 607 TEST_ASSERT_EQUAL(0, semaphore1);
JimCarver 0:6b753f761943 608
JimCarver 0:6b753f761943 609
JimCarver 0:6b753f761943 610 #ifdef DEBUG
JimCarver 0:6b753f761943 611 //Check semaphore parameter validation
JimCarver 0:6b753f761943 612 int32_t tmp;
JimCarver 0:6b753f761943 613 /*#5*/
JimCarver 0:6b753f761943 614 status = pal_osSemaphoreCreate(1 ,NULL);
JimCarver 0:6b753f761943 615 TEST_ASSERT_EQUAL_HEX(PAL_ERR_INVALID_ARGUMENT, status);
JimCarver 0:6b753f761943 616 /*#6*/
JimCarver 0:6b753f761943 617 status = pal_osSemaphoreDelete(NULL);
JimCarver 0:6b753f761943 618 TEST_ASSERT_EQUAL_HEX(PAL_ERR_INVALID_ARGUMENT, status);
JimCarver 0:6b753f761943 619 /*#7*/
JimCarver 0:6b753f761943 620 status = pal_osSemaphoreWait(NULLPTR, 1000, &tmp);
JimCarver 0:6b753f761943 621 TEST_ASSERT_EQUAL_HEX(PAL_ERR_INVALID_ARGUMENT, status);
JimCarver 0:6b753f761943 622 /*#8*/
JimCarver 0:6b753f761943 623 status = pal_osSemaphoreRelease(NULLPTR);
JimCarver 0:6b753f761943 624 TEST_ASSERT_EQUAL_HEX(PAL_ERR_INVALID_ARGUMENT, status);
JimCarver 0:6b753f761943 625 #endif
JimCarver 0:6b753f761943 626 }
JimCarver 0:6b753f761943 627
JimCarver 0:6b753f761943 628
JimCarver 0:6b753f761943 629
JimCarver 0:6b753f761943 630 /*! \brief Performs a single atomic increment call
JimCarver 0:6b753f761943 631 * to an integer value and verifies that the result is as expected.
JimCarver 0:6b753f761943 632 *
JimCarver 0:6b753f761943 633 * | # | Step | Expected |
JimCarver 0:6b753f761943 634 * |---|--------------------------------|-------------|
JimCarver 0:6b753f761943 635 * | 1 | Call atomic increment using `pal_osAtomicIncrement` and check that the value was incremented. | PAL_SUCCESS |
JimCarver 0:6b753f761943 636 */
JimCarver 0:6b753f761943 637 TEST(pal_rtos, AtomicIncrementUnityTest)
JimCarver 0:6b753f761943 638 {
JimCarver 0:6b753f761943 639 int32_t num1 = 0;
JimCarver 0:6b753f761943 640 int32_t increment = 10;
JimCarver 0:6b753f761943 641 int32_t tmp = 0;
JimCarver 0:6b753f761943 642 int32_t original = num1;
JimCarver 0:6b753f761943 643 /*#1*/
JimCarver 0:6b753f761943 644 tmp = pal_osAtomicIncrement(&num1, increment);
JimCarver 0:6b753f761943 645
JimCarver 0:6b753f761943 646
JimCarver 0:6b753f761943 647 TEST_ASSERT_EQUAL(original + increment, tmp);
JimCarver 0:6b753f761943 648
JimCarver 0:6b753f761943 649 }
JimCarver 0:6b753f761943 650
JimCarver 0:6b753f761943 651 struct randBuf
JimCarver 0:6b753f761943 652 {
JimCarver 0:6b753f761943 653 uint8_t rand[6];
JimCarver 0:6b753f761943 654 };
JimCarver 0:6b753f761943 655
JimCarver 0:6b753f761943 656 /*! \brief Check the random APIs. For each API, the test calls the random API in a loop
JimCarver 0:6b753f761943 657 * and stores the result. When the loop finishes, we verify that the count of the
JimCarver 0:6b753f761943 658 * duplication in the stored values is less than the defined random margin value for each API.
JimCarver 0:6b753f761943 659 *
JimCarver 0:6b753f761943 660 * | # | Step | Expected |
JimCarver 0:6b753f761943 661 * |--- |-----------------------------------------------------------------------------|--------------------------|
JimCarver 0:6b753f761943 662 * | 1 | Fill array with random 32bit values using `pal_osRandom32bit` in a loop. | PAL_SUCCESS |
JimCarver 0:6b753f761943 663 * | 2 | Check array for matching values and make sure there are not too many. | PAL_SUCCESS |
JimCarver 0:6b753f761943 664 * | 3 | Fill array with random values using `pal_osRandomUniform` in a loop. | PAL_SUCCESS |
JimCarver 0:6b753f761943 665 * | 4 | Check array for matching values and make sure there are not too many. | PAL_SUCCESS |
JimCarver 0:6b753f761943 666 * | 5 | Fill array with random byte sequences using `pal_osRandomBuffer` in a loop. | PAL_SUCCESS |
JimCarver 0:6b753f761943 667 * | 6 | Check array for matching values and make sure there are not too many. | PAL_SUCCESS |
JimCarver 0:6b753f761943 668 * | 7 | Call pal_osRandom32bit with NULL output parameter. | PAL_ERR_INVALID_ARGUMENT |
JimCarver 0:6b753f761943 669 * | 8 | Call pal_osRandomBuffer with NULL output parameter. | PAL_ERR_INVALID_ARGUMENT |
JimCarver 0:6b753f761943 670 * | 9 | Call pal_osRandomUniform with NULL output parameter. | PAL_ERR_INVALID_ARGUMENT |
JimCarver 0:6b753f761943 671 * | 10 | Call pal_osRandomBuffer while pal is not initialized. | PAL_ERR_NOT_INITIALIZED |
JimCarver 0:6b753f761943 672 */
JimCarver 0:6b753f761943 673 TEST(pal_rtos, RandomUnityTest)
JimCarver 0:6b753f761943 674 {
JimCarver 0:6b753f761943 675 palStatus_t status = PAL_SUCCESS;
JimCarver 0:6b753f761943 676 uint32_t randomArray[PAL_RANDOM_ARRAY_TEST_SIZE];
JimCarver 0:6b753f761943 677 struct randBuf randomBufArray[PAL_RANDOM_BUFFER_ARRAY_TEST_SIZE];
JimCarver 0:6b753f761943 678 uint32_t randomMargin = 0;
JimCarver 0:6b753f761943 679
JimCarver 0:6b753f761943 680 memset(randomArray, 0x0, sizeof(randomArray));
JimCarver 0:6b753f761943 681 memset(randomBufArray, 0x0, sizeof(randomBufArray));
JimCarver 0:6b753f761943 682 /*#1*/
JimCarver 0:6b753f761943 683 for(int i = 0; i < PAL_RANDOM_ARRAY_TEST_SIZE ; ++i)
JimCarver 0:6b753f761943 684 {
JimCarver 0:6b753f761943 685 status = pal_osRandom32bit(&randomArray[i]);
JimCarver 0:6b753f761943 686 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 687 }
JimCarver 0:6b753f761943 688 /*#2*/
JimCarver 0:6b753f761943 689 for(int k = 0; k < PAL_RANDOM_ARRAY_TEST_SIZE ; ++k)
JimCarver 0:6b753f761943 690 {
JimCarver 0:6b753f761943 691 for (int j = k+1 ; j < PAL_RANDOM_ARRAY_TEST_SIZE ; ++j)
JimCarver 0:6b753f761943 692 {
JimCarver 0:6b753f761943 693 if (randomArray[k] == randomArray[j])
JimCarver 0:6b753f761943 694 {
JimCarver 0:6b753f761943 695 ++randomMargin;
JimCarver 0:6b753f761943 696 }
JimCarver 0:6b753f761943 697 }
JimCarver 0:6b753f761943 698 randomArray[k] = 0;
JimCarver 0:6b753f761943 699 }
JimCarver 0:6b753f761943 700 TEST_ASSERT_TRUE(20 >= randomMargin);
JimCarver 0:6b753f761943 701 randomMargin = 0;
JimCarver 0:6b753f761943 702 /*#5*/
JimCarver 0:6b753f761943 703 for (int i = 0; i < PAL_RANDOM_BUFFER_ARRAY_TEST_SIZE ; ++i)
JimCarver 0:6b753f761943 704 {
JimCarver 0:6b753f761943 705 status = pal_osRandomBuffer(randomBufArray[i].rand, sizeof(randomBufArray[i].rand));
JimCarver 0:6b753f761943 706 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 707 }
JimCarver 0:6b753f761943 708 /*#6*/
JimCarver 0:6b753f761943 709 for(int k = 0; k < PAL_RANDOM_BUFFER_ARRAY_TEST_SIZE ; ++k)
JimCarver 0:6b753f761943 710 {
JimCarver 0:6b753f761943 711 for (int j = k+1 ; j < PAL_RANDOM_BUFFER_ARRAY_TEST_SIZE ; ++j)
JimCarver 0:6b753f761943 712 {
JimCarver 0:6b753f761943 713 if(0 == memcmp(randomBufArray[k].rand, randomBufArray[j].rand, sizeof(uint8_t)*6))
JimCarver 0:6b753f761943 714 {
JimCarver 0:6b753f761943 715 ++randomMargin;
JimCarver 0:6b753f761943 716 }
JimCarver 0:6b753f761943 717 }
JimCarver 0:6b753f761943 718 }
JimCarver 0:6b753f761943 719
JimCarver 0:6b753f761943 720 TEST_ASSERT_TRUE(10 >= randomMargin);
JimCarver 0:6b753f761943 721
JimCarver 0:6b753f761943 722 #ifdef DEBUG
JimCarver 0:6b753f761943 723 /*#7*/
JimCarver 0:6b753f761943 724 status = pal_osRandom32bit(NULL);
JimCarver 0:6b753f761943 725 TEST_ASSERT_EQUAL_HEX(PAL_ERR_INVALID_ARGUMENT, status);
JimCarver 0:6b753f761943 726
JimCarver 0:6b753f761943 727 /*#8*/
JimCarver 0:6b753f761943 728 status = pal_osRandomBuffer(NULL, 0);
JimCarver 0:6b753f761943 729 TEST_ASSERT_EQUAL_HEX(PAL_ERR_INVALID_ARGUMENT, status);
JimCarver 0:6b753f761943 730
JimCarver 0:6b753f761943 731
JimCarver 0:6b753f761943 732 #endif
JimCarver 0:6b753f761943 733
JimCarver 0:6b753f761943 734 /*#10*/
JimCarver 0:6b753f761943 735 pal_destroy();
JimCarver 0:6b753f761943 736 status = pal_osRandomBuffer(randomBufArray[0].rand, sizeof(randomBufArray[0].rand));
JimCarver 0:6b753f761943 737 TEST_ASSERT_EQUAL_HEX(PAL_ERR_NOT_INITIALIZED, status);
JimCarver 0:6b753f761943 738 }
JimCarver 0:6b753f761943 739
JimCarver 0:6b753f761943 740
JimCarver 0:6b753f761943 741 /*! \brief call the random API in a PAL_RANDOM_TEST_LOOP loop.
JimCarver 0:6b753f761943 742 * | # | Step | Expected |
JimCarver 0:6b753f761943 743 * |---|--------------------------------|-------------|
JimCarver 0:6b753f761943 744 * | 1 | Call `pal_osRandomBuffer` in a PAL_RANDOM_TEST_LOOP loop . PAL_SUCCESS |
JimCarver 0:6b753f761943 745 */
JimCarver 0:6b753f761943 746 TEST(pal_rtos, loopRandomBigNumber)
JimCarver 0:6b753f761943 747 {
JimCarver 0:6b753f761943 748 palStatus_t status = PAL_SUCCESS;
JimCarver 0:6b753f761943 749 uint8_t loopRandomArray[PAL_RANDOM_ARRAY_TEST_SIZE];
JimCarver 0:6b753f761943 750
JimCarver 0:6b753f761943 751 for (int i = 0; i < PAL_RANDOM_TEST_LOOP; ++i)
JimCarver 0:6b753f761943 752 {
JimCarver 0:6b753f761943 753 status = pal_osRandomBuffer(loopRandomArray, sizeof(loopRandomArray));
JimCarver 0:6b753f761943 754 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 755 }
JimCarver 0:6b753f761943 756 }
JimCarver 0:6b753f761943 757
JimCarver 0:6b753f761943 758 /*! \brief Verify that PAL can handle multiple calls for `pal_init()` and `pal_destroy()`.
JimCarver 0:6b753f761943 759 *
JimCarver 0:6b753f761943 760 * | # | Step | Expected |
JimCarver 0:6b753f761943 761 * |---|------------------------------------------------------|-------------|
JimCarver 0:6b753f761943 762 * | 1 | Call `pal_init`. | PAL_SUCCESS |
JimCarver 0:6b753f761943 763 * | 2 | Call `pal_init`. | PAL_SUCCESS |
JimCarver 0:6b753f761943 764 * | 3 | Call `pal_init`. | PAL_SUCCESS |
JimCarver 0:6b753f761943 765 * | 4 | Call `pal_destroy` in a loop untill init count == 0. | PAL_SUCCESS |
JimCarver 0:6b753f761943 766 * | 5 | Call `pal_init`. | PAL_SUCCESS |
JimCarver 0:6b753f761943 767 * | 6 | Call `pal_RTOSInitialize`. | PAL_SUCCESS |
JimCarver 0:6b753f761943 768 * | 7 | Call `pal_destroy`. | PAL_SUCCESS |
JimCarver 0:6b753f761943 769 */
JimCarver 0:6b753f761943 770 TEST(pal_rtos, pal_init_test)
JimCarver 0:6b753f761943 771 {
JimCarver 0:6b753f761943 772 palStatus_t status = PAL_SUCCESS;
JimCarver 0:6b753f761943 773 int32_t initCounter = 0;
JimCarver 0:6b753f761943 774 /*#1*/
JimCarver 0:6b753f761943 775 status = pal_init();
JimCarver 0:6b753f761943 776 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 777 /*#2*/
JimCarver 0:6b753f761943 778 status = pal_init();
JimCarver 0:6b753f761943 779 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 780 /*#3*/
JimCarver 0:6b753f761943 781 status = pal_init();
JimCarver 0:6b753f761943 782 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 783
JimCarver 0:6b753f761943 784 /*#4*/
JimCarver 0:6b753f761943 785 do
JimCarver 0:6b753f761943 786 {
JimCarver 0:6b753f761943 787 initCounter = pal_destroy();
JimCarver 0:6b753f761943 788 //TEST_ASSERT_EQUAL_HEX(0, initCounter);
JimCarver 0:6b753f761943 789
JimCarver 0:6b753f761943 790 }while(initCounter != 0);
JimCarver 0:6b753f761943 791
JimCarver 0:6b753f761943 792 /*#5*/
JimCarver 0:6b753f761943 793 status = pal_init();
JimCarver 0:6b753f761943 794 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 795
JimCarver 0:6b753f761943 796 status = pal_RTOSInitialize(NULLPTR);
JimCarver 0:6b753f761943 797 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 798
JimCarver 0:6b753f761943 799 /*#7*/
JimCarver 0:6b753f761943 800 initCounter = pal_destroy();
JimCarver 0:6b753f761943 801 TEST_ASSERT_EQUAL_HEX(0, initCounter);
JimCarver 0:6b753f761943 802 }
JimCarver 0:6b753f761943 803
JimCarver 0:6b753f761943 804 /*! \brief Check derivation of keys from the platform's Root of Trust using the KDF algorithm.
JimCarver 0:6b753f761943 805 *
JimCarver 0:6b753f761943 806 *
JimCarver 0:6b753f761943 807 *
JimCarver 0:6b753f761943 808 * | # | Step | Expected |
JimCarver 0:6b753f761943 809 * |---|--------------------------------|-------------|
JimCarver 0:6b753f761943 810 * | 1 | Start a loop to perform the following steps. | |
JimCarver 0:6b753f761943 811 * | 2 | Derive a device key for encryption using `pal_osGetDeviceKey`. | PAL_SUCCESS |
JimCarver 0:6b753f761943 812 * | 3 | Derive a device key for signing using `pal_osGetDeviceKey`. | PAL_SUCCESS |
JimCarver 0:6b753f761943 813 * | 4 | Call `pal_osGetDeviceKey` with invalid arguments. | PAL_FAILURE |
JimCarver 0:6b753f761943 814 * | 5 | Call `pal_osGetDeviceKey` with invalid arguments. | PAL_FAILURE |
JimCarver 0:6b753f761943 815 * | 6 | Check that the derived signing and encryption keys are different. | PAL_SUCCESS |
JimCarver 0:6b753f761943 816 * | 7 | Check that all integrations of each type of derivation return the same value. | PAL_SUCCESS |
JimCarver 0:6b753f761943 817 */
JimCarver 0:6b753f761943 818 TEST(pal_rtos, GetDeviceKeyTest_CMAC)
JimCarver 0:6b753f761943 819 {
JimCarver 0:6b753f761943 820 palStatus_t status = PAL_SUCCESS;
JimCarver 0:6b753f761943 821 size_t keyLenBytes = 16;
JimCarver 0:6b753f761943 822 uint8_t timesToDerive = 4;
JimCarver 0:6b753f761943 823 unsigned char encKeyDerive[timesToDerive][keyLenBytes]; //16 bytes=128bit
JimCarver 0:6b753f761943 824 unsigned char signKeyDerive[timesToDerive][keyLenBytes]; //16 bytes=128bit
JimCarver 0:6b753f761943 825 /*#1*/
JimCarver 0:6b753f761943 826 for (int i=0; i < timesToDerive; i++)
JimCarver 0:6b753f761943 827 {
JimCarver 0:6b753f761943 828 /*#2*/
JimCarver 0:6b753f761943 829 status = pal_osGetDeviceKey(palOsStorageEncryptionKey128Bit, encKeyDerive[i], keyLenBytes);
JimCarver 0:6b753f761943 830 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 831 /*#3*/
JimCarver 0:6b753f761943 832 status = pal_osGetDeviceKey(palOsStorageSignatureKey128Bit, signKeyDerive[i], keyLenBytes);
JimCarver 0:6b753f761943 833 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 834 /*#4*/
JimCarver 0:6b753f761943 835 status = pal_osGetDeviceKey(palOsStorageSignatureKey128Bit, signKeyDerive[i], keyLenBytes-1);
JimCarver 0:6b753f761943 836 TEST_ASSERT_NOT_EQUAL(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 837 /*#5*/
JimCarver 0:6b753f761943 838 status = pal_osGetDeviceKey(palOsStorageSignatureKey128Bit, NULL, keyLenBytes);
JimCarver 0:6b753f761943 839 TEST_ASSERT_NOT_EQUAL(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 840 /*#6*/
JimCarver 0:6b753f761943 841 status = memcmp(encKeyDerive[i], signKeyDerive[i], keyLenBytes);
JimCarver 0:6b753f761943 842 TEST_ASSERT_NOT_EQUAL(status,0); //The keys MUST be different!
JimCarver 0:6b753f761943 843 /*#7*/
JimCarver 0:6b753f761943 844 if (i > 0) //Make sure key derivation is persistent every time
JimCarver 0:6b753f761943 845 {
JimCarver 0:6b753f761943 846 TEST_ASSERT_EQUAL_MEMORY(encKeyDerive[i-1], encKeyDerive[i], keyLenBytes);
JimCarver 0:6b753f761943 847 TEST_ASSERT_EQUAL_MEMORY(signKeyDerive[i-1], signKeyDerive[i], keyLenBytes);
JimCarver 0:6b753f761943 848
JimCarver 0:6b753f761943 849 } //if
JimCarver 0:6b753f761943 850
JimCarver 0:6b753f761943 851 } //for
JimCarver 0:6b753f761943 852
JimCarver 0:6b753f761943 853 }
JimCarver 0:6b753f761943 854
JimCarver 0:6b753f761943 855 /*! \brief Check derivation of keys from the platform's Root of Trust using the KDF algorithm.
JimCarver 0:6b753f761943 856 *
JimCarver 0:6b753f761943 857 *
JimCarver 0:6b753f761943 858 *
JimCarver 0:6b753f761943 859 * | # | Step | Expected |
JimCarver 0:6b753f761943 860 * |---|--------------------------------------------------------------------------------|---------------------|
JimCarver 0:6b753f761943 861 * | 1 | Start a loop to perform the following steps. | |
JimCarver 0:6b753f761943 862 * | 2 | Derive a device key for encryption using `pal_osGetDeviceKey`. | PAL_SUCCESS |
JimCarver 0:6b753f761943 863 * | 3 | Call `pal_osGetDeviceKey` with invalid arguments. | PAL_FAILURE |
JimCarver 0:6b753f761943 864 * | 4 | Call `pal_osGetDeviceKey` with invalid arguments. | PAL_FAILURE |
JimCarver 0:6b753f761943 865 * | 5 | Check that all integrations of each type of derivation return the same value. | PAL_SUCCESS |
JimCarver 0:6b753f761943 866 * | 6 | Call `pal_osGetDeviceKey` with invalid palDevKeyType_t. | PAL_ERR_GET_DEV_KEY |
JimCarver 0:6b753f761943 867 */
JimCarver 0:6b753f761943 868 TEST(pal_rtos, GetDeviceKeyTest_HMAC_SHA256)
JimCarver 0:6b753f761943 869 {
JimCarver 0:6b753f761943 870 palStatus_t status = PAL_SUCCESS;
JimCarver 0:6b753f761943 871 size_t keyLenBytes = 32;
JimCarver 0:6b753f761943 872 uint8_t timesToDerive = 4;
JimCarver 0:6b753f761943 873 unsigned char encKeyDerive[timesToDerive][keyLenBytes]; //32 bytes=256bit
JimCarver 0:6b753f761943 874 /*#1*/
JimCarver 0:6b753f761943 875 for (int i=0; i < timesToDerive; i++)
JimCarver 0:6b753f761943 876 {
JimCarver 0:6b753f761943 877 /*#2*/
JimCarver 0:6b753f761943 878 status = pal_osGetDeviceKey(palOsStorageHmacSha256, encKeyDerive[i], keyLenBytes);
JimCarver 0:6b753f761943 879 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 880 #ifdef DEBUG
JimCarver 0:6b753f761943 881 /*#3*/
JimCarver 0:6b753f761943 882 status = pal_osGetDeviceKey(palOsStorageHmacSha256, encKeyDerive[i], keyLenBytes-1);
JimCarver 0:6b753f761943 883 TEST_ASSERT_NOT_EQUAL(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 884 /*#4*/
JimCarver 0:6b753f761943 885 status = pal_osGetDeviceKey(palOsStorageHmacSha256, NULL, keyLenBytes);
JimCarver 0:6b753f761943 886 TEST_ASSERT_NOT_EQUAL(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 887 #endif
JimCarver 0:6b753f761943 888 /*#5*/
JimCarver 0:6b753f761943 889 if (i > 0) //Make sure key derivation is persistent every time
JimCarver 0:6b753f761943 890 {
JimCarver 0:6b753f761943 891 TEST_ASSERT_EQUAL_MEMORY(encKeyDerive[i-1], encKeyDerive[i], keyLenBytes);
JimCarver 0:6b753f761943 892 } //if
JimCarver 0:6b753f761943 893
JimCarver 0:6b753f761943 894 } //for
JimCarver 0:6b753f761943 895
JimCarver 0:6b753f761943 896 #ifdef DEBUG
JimCarver 0:6b753f761943 897 /*#6*/
JimCarver 0:6b753f761943 898 status = pal_osGetDeviceKey((palDevKeyType_t)999, encKeyDerive[0], keyLenBytes);
JimCarver 0:6b753f761943 899 TEST_ASSERT_EQUAL_HEX(PAL_ERR_INVALID_ARGUMENT, status);
JimCarver 0:6b753f761943 900 #endif
JimCarver 0:6b753f761943 901 }
JimCarver 0:6b753f761943 902
JimCarver 0:6b753f761943 903 /*! \brief Check the APIs `pal_osSetTime()` and `pal_osGetTime()` with different scenarios
JimCarver 0:6b753f761943 904 * for valid and non-valid scenarios and epoch values.
JimCarver 0:6b753f761943 905 * The test also checks that the time increases.
JimCarver 0:6b753f761943 906 *
JimCarver 0:6b753f761943 907 * | # | Step | Expected |
JimCarver 0:6b753f761943 908 * |---|--------------------------------|-------------|
JimCarver 0:6b753f761943 909 * | 1 | Start a loop for the following steps. | PAL_SUCCESS |
JimCarver 0:6b753f761943 910 * | 2 | Set time to invalid value using `pal_osSetTime`. | PAL_ERR_INVALID_TIME |
JimCarver 0:6b753f761943 911 * | 3 | Get time using `pal_osGetTime`. | PAL_SUCCESS |
JimCarver 0:6b753f761943 912 * | 4 | Set time to valid value using `pal_osSetTime`. | PAL_SUCCESS |
JimCarver 0:6b753f761943 913 * | 5 | Sleep. | PAL_SUCCESS |
JimCarver 0:6b753f761943 914 * | 6 | Get time using `pal_osGetTime` and check that it equals set time + sleep time. | PAL_SUCCESS |
JimCarver 0:6b753f761943 915 */
JimCarver 0:6b753f761943 916 TEST(pal_rtos, RealTimeClockTest1)
JimCarver 0:6b753f761943 917 {
JimCarver 0:6b753f761943 918 palStatus_t status;
JimCarver 0:6b753f761943 919 uint64_t curTime = 0;
JimCarver 0:6b753f761943 920 uint64_t lastTimeSeen = 0;
JimCarver 0:6b753f761943 921 const uint64_t minSecSinceEpoch = PAL_MIN_SEC_FROM_EPOCH + 1; //At least 47 years passed from 1.1.1970 in seconds
JimCarver 0:6b753f761943 922
JimCarver 0:6b753f761943 923 /*#1*/
JimCarver 0:6b753f761943 924 for (int i=0; i < 2; i++)
JimCarver 0:6b753f761943 925 {
JimCarver 0:6b753f761943 926 /*#2*/
JimCarver 0:6b753f761943 927 status = pal_osSetTime(3);
JimCarver 0:6b753f761943 928 TEST_ASSERT_EQUAL_HEX(PAL_ERR_INVALID_TIME, status); // Less than current epoch time -> error
JimCarver 0:6b753f761943 929
JimCarver 0:6b753f761943 930 /*#3*/
JimCarver 0:6b753f761943 931 curTime = pal_osGetTime();
JimCarver 0:6b753f761943 932 TEST_ASSERT_TRUE(lastTimeSeen <= curTime); //Time was not previously set; 0 is acceptable
JimCarver 0:6b753f761943 933 /*#4*/
JimCarver 0:6b753f761943 934 status = pal_osSetTime(minSecSinceEpoch);
JimCarver 0:6b753f761943 935 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status); // More than current epoch time -> success
JimCarver 0:6b753f761943 936 /*#5*/
JimCarver 0:6b753f761943 937 int milliDelay = 1500;
JimCarver 0:6b753f761943 938 pal_osDelay(milliDelay); //500 milliseconds
JimCarver 0:6b753f761943 939 /*#6*/
JimCarver 0:6b753f761943 940 curTime = pal_osGetTime();
JimCarver 0:6b753f761943 941 TEST_ASSERT_TRUE(curTime > minSecSinceEpoch);
JimCarver 0:6b753f761943 942 TEST_ASSERT_TRUE(curTime <= minSecSinceEpoch+(int)ceil((float)milliDelay/1000));
JimCarver 0:6b753f761943 943 lastTimeSeen = curTime;
JimCarver 0:6b753f761943 944 }
JimCarver 0:6b753f761943 945 }
JimCarver 0:6b753f761943 946
JimCarver 0:6b753f761943 947
JimCarver 0:6b753f761943 948 /*! \brief Check recursive mutex behavior.
JimCarver 0:6b753f761943 949 *
JimCarver 0:6b753f761943 950 * | # | Step | Expected |
JimCarver 0:6b753f761943 951 * |---|--------------------------------|-------------|
JimCarver 0:6b753f761943 952 * | 1 | Create a mutex using `pal_osMutexCreate`. | PAL_SUCCESS |
JimCarver 0:6b753f761943 953 * | 2 | Create a semaphore using `pal_osSemaphoreCreate`. | PAL_SUCCESS |
JimCarver 0:6b753f761943 954 * | 3 | Create a thread running `RecursiveLockThread` using `pal_osThreadCreateWithAlloc`. | PAL_SUCCESS |
JimCarver 0:6b753f761943 955 * | 4 | Create a thread running `RecursiveLockThread` using `pal_osThreadCreateWithAlloc`. | PAL_SUCCESS |
JimCarver 0:6b753f761943 956 * | 5 | Release the semaphore using `pal_osSemaphoreRelease`. | PAL_SUCCESS |
JimCarver 0:6b753f761943 957 * | 6 | Release the semaphore using `pal_osSemaphoreRelease`. | PAL_SUCCESS |
JimCarver 0:6b753f761943 958 * | 7 | Sleep for a short interval. | PAL_SUCCESS |
JimCarver 0:6b753f761943 959 * | 8 | Wait for the semaphore using `pal_osSemaphoreWait`. | PAL_SUCCESS |
JimCarver 0:6b753f761943 960 * | 9 | Wait for the semaphore using `pal_osSemaphoreWait`. | PAL_SUCCESS |
JimCarver 0:6b753f761943 961 * | 10 | Terminate the first thread using `pal_osThreadTerminate`. | PAL_SUCCESS |
JimCarver 0:6b753f761943 962 * | 11 | Terminate the second thread using `pal_osThreadTerminate`. | PAL_SUCCESS |
JimCarver 0:6b753f761943 963 * | 12 | Delete the mutex using `pal_osMutexDelete`. | PAL_SUCCESS |
JimCarver 0:6b753f761943 964 * | 13 | Delete the semaphore using `pal_osSemaphoreDelete`. | PAL_SUCCESS |
JimCarver 0:6b753f761943 965 */
JimCarver 0:6b753f761943 966 TEST(pal_rtos, Recursive_Mutex_Test)
JimCarver 0:6b753f761943 967 {
JimCarver 0:6b753f761943 968 palStatus_t status;
JimCarver 0:6b753f761943 969 int32_t val = 0;
JimCarver 0:6b753f761943 970
JimCarver 0:6b753f761943 971 recursiveMutexData = malloc(sizeof(palRecursiveMutexParam_t));
JimCarver 0:6b753f761943 972 TEST_ASSERT_NOT_NULL(recursiveMutexData);
JimCarver 0:6b753f761943 973 memset(recursiveMutexData, 0, sizeof(palRecursiveMutexParam_t));
JimCarver 0:6b753f761943 974 /*#1*/
JimCarver 0:6b753f761943 975 status = pal_osMutexCreate(&(recursiveMutexData->mtx));
JimCarver 0:6b753f761943 976 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 977 /*#2*/
JimCarver 0:6b753f761943 978 status = pal_osSemaphoreCreate(0, &(recursiveMutexData->sem));
JimCarver 0:6b753f761943 979 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 980 /*#3*/
JimCarver 0:6b753f761943 981 status = pal_osThreadCreateWithAlloc(RecursiveLockThread, (void*)recursiveMutexData, PAL_osPriorityHigh, PAL_TEST_THREAD_STACK_SIZE, NULL, &(recursiveMutexData->higherPriorityThread));
JimCarver 0:6b753f761943 982 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 983 /*#4*/
JimCarver 0:6b753f761943 984 status = pal_osThreadCreateWithAlloc(RecursiveLockThread, (void*)recursiveMutexData, PAL_osPriorityAboveNormal, PAL_TEST_THREAD_STACK_SIZE, NULL, &(recursiveMutexData->lowerPriorityThread));
JimCarver 0:6b753f761943 985 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 986 /*#5*/
JimCarver 0:6b753f761943 987 status = pal_osSemaphoreRelease(recursiveMutexData->sem);
JimCarver 0:6b753f761943 988 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 989 /*#6*/
JimCarver 0:6b753f761943 990 status = pal_osSemaphoreRelease(recursiveMutexData->sem);
JimCarver 0:6b753f761943 991 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 992 /*#7*/
JimCarver 0:6b753f761943 993 pal_osDelay(1000);
JimCarver 0:6b753f761943 994 /*#8*/
JimCarver 0:6b753f761943 995 status = pal_osSemaphoreWait(recursiveMutexData->sem, PAL_RTOS_WAIT_FOREVER, &val);
JimCarver 0:6b753f761943 996 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 997 /*#9*/
JimCarver 0:6b753f761943 998 status = pal_osSemaphoreWait(recursiveMutexData->sem, PAL_RTOS_WAIT_FOREVER, &val);
JimCarver 0:6b753f761943 999 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 1000 TEST_ASSERT_EQUAL(0, val);
JimCarver 0:6b753f761943 1001 TEST_ASSERT_EQUAL_HEX(NULLPTR, recursiveMutexData->activeThread);
JimCarver 0:6b753f761943 1002 /*#10*/
JimCarver 0:6b753f761943 1003 status = pal_osThreadTerminate(&(recursiveMutexData->higherPriorityThread));
JimCarver 0:6b753f761943 1004 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 1005 /*#11*/
JimCarver 0:6b753f761943 1006 status = pal_osThreadTerminate(&(recursiveMutexData->lowerPriorityThread));
JimCarver 0:6b753f761943 1007 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 1008 /*#12*/
JimCarver 0:6b753f761943 1009 status = pal_osMutexDelete(&(recursiveMutexData->mtx));
JimCarver 0:6b753f761943 1010 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 1011 /*#13*/
JimCarver 0:6b753f761943 1012 status = pal_osSemaphoreDelete(&recursiveMutexData->sem);
JimCarver 0:6b753f761943 1013 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 1014
JimCarver 0:6b753f761943 1015 TEST_ASSERT_EQUAL(400, recursiveMutexData->count);
JimCarver 0:6b753f761943 1016
JimCarver 0:6b753f761943 1017 free(recursiveMutexData);
JimCarver 0:6b753f761943 1018 recursiveMutexData = NULL;
JimCarver 0:6b753f761943 1019 }
JimCarver 0:6b753f761943 1020
JimCarver 0:6b753f761943 1021
JimCarver 0:6b753f761943 1022
JimCarver 0:6b753f761943 1023 /*! \brief Check Weak Set Time - Forword flow.
JimCarver 0:6b753f761943 1024 *
JimCarver 0:6b753f761943 1025 * | # | Step | Expected |
JimCarver 0:6b753f761943 1026 * |---|--------------------------------|-------------|
JimCarver 0:6b753f761943 1027 * | 1 | checking RTC and SOTP flow - not set SOTP SAVED TIME + LAST TIME BACK + RTC to new time | PAL_SUCCESS |
JimCarver 0:6b753f761943 1028 * | 2 | checking RTC and SOTP flow - not set SOTP SAVED TIME + LAST TIME BACK to new time but set RTC to new time | PAL_SUCCESS |
JimCarver 0:6b753f761943 1029 * | 3 | checking RTC and SOTP flow - set SOTP SAVED TIME + LAST TIME BACK + RTC to new time | PAL_SUCCESS |
JimCarver 0:6b753f761943 1030 */
JimCarver 0:6b753f761943 1031 TEST(pal_rtos, OsWeakSetTime_Forword)
JimCarver 0:6b753f761943 1032 {
JimCarver 0:6b753f761943 1033 palStatus_t status;
JimCarver 0:6b753f761943 1034 sotp_result_e sotpStatus = SOTP_SUCCESS;
JimCarver 0:6b753f761943 1035 uint64_t setTimeInSeconds = 0;
JimCarver 0:6b753f761943 1036 uint64_t curentTimeInSeconds=0;
JimCarver 0:6b753f761943 1037 uint64_t pal_Time = 0;
JimCarver 0:6b753f761943 1038 uint64_t sotpGetTime = 0;
JimCarver 0:6b753f761943 1039 uint16_t actualLenBytes = 0;
JimCarver 0:6b753f761943 1040
JimCarver 0:6b753f761943 1041 #if (PAL_USE_HW_RTC)
JimCarver 0:6b753f761943 1042 //This code is to preserve system time
JimCarver 0:6b753f761943 1043 uint64_t testStartTime = 0;
JimCarver 0:6b753f761943 1044 status = pal_plat_osGetRtcTime(&testStartTime);
JimCarver 0:6b753f761943 1045 #endif
JimCarver 0:6b753f761943 1046
JimCarver 0:6b753f761943 1047
JimCarver 0:6b753f761943 1048 /*#1*/
JimCarver 0:6b753f761943 1049 #if (PAL_USE_HW_RTC)
JimCarver 0:6b753f761943 1050 pal_plat_osSetRtcTime(PAL_MIN_RTC_SET_TIME);
JimCarver 0:6b753f761943 1051 #endif
JimCarver 0:6b753f761943 1052 pal_osSetTime(PAL_MIN_SEC_FROM_EPOCH + PAL_SECONDS_PER_DAY * 100);
JimCarver 0:6b753f761943 1053 curentTimeInSeconds = pal_osGetTime();
JimCarver 0:6b753f761943 1054
JimCarver 0:6b753f761943 1055 sotpStatus = sotp_set(SOTP_TYPE_SAVED_TIME, sizeof(uint64_t), (uint32_t *)&curentTimeInSeconds);
JimCarver 0:6b753f761943 1056 TEST_ASSERT_EQUAL_HEX(SOTP_SUCCESS, sotpStatus);
JimCarver 0:6b753f761943 1057
JimCarver 0:6b753f761943 1058 sotpStatus = sotp_set(SOTP_TYPE_LAST_TIME_BACK, sizeof(uint64_t), (uint32_t *)&curentTimeInSeconds);
JimCarver 0:6b753f761943 1059 TEST_ASSERT_EQUAL_HEX(SOTP_SUCCESS, sotpStatus);
JimCarver 0:6b753f761943 1060
JimCarver 0:6b753f761943 1061 #if (PAL_USE_HW_RTC)
JimCarver 0:6b753f761943 1062 uint64_t rtcTime = 0;
JimCarver 0:6b753f761943 1063 status = pal_plat_osSetRtcTime(curentTimeInSeconds);
JimCarver 0:6b753f761943 1064 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 1065 #endif//PAL_USE_HW_RTC
JimCarver 0:6b753f761943 1066
JimCarver 0:6b753f761943 1067 setTimeInSeconds = curentTimeInSeconds + (50 * PAL_ONE_SEC);
JimCarver 0:6b753f761943 1068 status = pal_osSetWeakTime(setTimeInSeconds);
JimCarver 0:6b753f761943 1069
JimCarver 0:6b753f761943 1070 pal_Time = pal_osGetTime();
JimCarver 0:6b753f761943 1071 if (pal_Time - setTimeInSeconds > 5)
JimCarver 0:6b753f761943 1072 {
JimCarver 0:6b753f761943 1073 status = PAL_ERR_GENERAL_BASE;
JimCarver 0:6b753f761943 1074 }
JimCarver 0:6b753f761943 1075 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 1076 #if PAL_USE_INTERNAL_FLASH
JimCarver 0:6b753f761943 1077 sotpStatus = sotp_get(SOTP_TYPE_SAVED_TIME, sizeof(uint64_t), (uint32_t*)&sotpGetTime, &actualLenBytes);
JimCarver 0:6b753f761943 1078 TEST_ASSERT_EQUAL_HEX(SOTP_SUCCESS, sotpStatus);
JimCarver 0:6b753f761943 1079 TEST_ASSERT_NOT_EQUAL(sotpGetTime, setTimeInSeconds);
JimCarver 0:6b753f761943 1080
JimCarver 0:6b753f761943 1081 sotpStatus = sotp_get(SOTP_TYPE_LAST_TIME_BACK, sizeof(uint64_t), (uint32_t*)&sotpGetTime, &actualLenBytes);
JimCarver 0:6b753f761943 1082 TEST_ASSERT_EQUAL_HEX(SOTP_SUCCESS, sotpStatus);
JimCarver 0:6b753f761943 1083 TEST_ASSERT_NOT_EQUAL(sotpGetTime, setTimeInSeconds);
JimCarver 0:6b753f761943 1084 #endif
JimCarver 0:6b753f761943 1085
JimCarver 0:6b753f761943 1086 #if (PAL_USE_HW_RTC)
JimCarver 0:6b753f761943 1087 status = pal_plat_osGetRtcTime(&rtcTime);
JimCarver 0:6b753f761943 1088 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 1089 TEST_ASSERT_NOT_EQUAL(rtcTime, setTimeInSeconds);
JimCarver 0:6b753f761943 1090 #endif//PAL_USE_HW_RTC
JimCarver 0:6b753f761943 1091
JimCarver 0:6b753f761943 1092 /*#2*/
JimCarver 0:6b753f761943 1093 curentTimeInSeconds = pal_osGetTime();
JimCarver 0:6b753f761943 1094 #if (PAL_USE_HW_RTC)
JimCarver 0:6b753f761943 1095 pal_plat_osSetRtcTime(curentTimeInSeconds);
JimCarver 0:6b753f761943 1096 #endif//PAL_USE_HW_RTC
JimCarver 0:6b753f761943 1097
JimCarver 0:6b753f761943 1098 setTimeInSeconds = curentTimeInSeconds+(200 * PAL_ONE_SEC);
JimCarver 0:6b753f761943 1099
JimCarver 0:6b753f761943 1100 status = pal_osSetWeakTime(setTimeInSeconds);
JimCarver 0:6b753f761943 1101 pal_Time = pal_osGetTime();
JimCarver 0:6b753f761943 1102 if (pal_Time - setTimeInSeconds > 5)
JimCarver 0:6b753f761943 1103 {
JimCarver 0:6b753f761943 1104 status = PAL_ERR_GENERAL_BASE;
JimCarver 0:6b753f761943 1105 }
JimCarver 0:6b753f761943 1106 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 1107
JimCarver 0:6b753f761943 1108 #if PAL_USE_INTERNAL_FLASH
JimCarver 0:6b753f761943 1109 sotpStatus = sotp_get(SOTP_TYPE_SAVED_TIME, sizeof(uint64_t), (uint32_t*)&sotpGetTime, &actualLenBytes);
JimCarver 0:6b753f761943 1110 TEST_ASSERT_EQUAL_HEX(SOTP_SUCCESS, sotpStatus);
JimCarver 0:6b753f761943 1111 TEST_ASSERT_NOT_EQUAL(sotpGetTime, setTimeInSeconds);
JimCarver 0:6b753f761943 1112
JimCarver 0:6b753f761943 1113 sotpStatus = sotp_get(SOTP_TYPE_LAST_TIME_BACK, sizeof(uint64_t), (uint32_t*)&sotpGetTime, &actualLenBytes);
JimCarver 0:6b753f761943 1114 TEST_ASSERT_EQUAL_HEX(SOTP_SUCCESS, sotpStatus);
JimCarver 0:6b753f761943 1115 TEST_ASSERT_NOT_EQUAL(sotpGetTime, setTimeInSeconds);
JimCarver 0:6b753f761943 1116 #endif
JimCarver 0:6b753f761943 1117
JimCarver 0:6b753f761943 1118 #if (PAL_USE_HW_RTC)
JimCarver 0:6b753f761943 1119 status = pal_plat_osGetRtcTime(&rtcTime);
JimCarver 0:6b753f761943 1120 TEST_ASSERT_EQUAL_UINT64(rtcTime, setTimeInSeconds);
JimCarver 0:6b753f761943 1121 #endif//PAL_USE_HW_RTC
JimCarver 0:6b753f761943 1122
JimCarver 0:6b753f761943 1123 /*#3*/
JimCarver 0:6b753f761943 1124 curentTimeInSeconds = pal_osGetTime();
JimCarver 0:6b753f761943 1125 sotpStatus = sotp_set(SOTP_TYPE_SAVED_TIME, sizeof(uint64_t), (uint32_t *)&curentTimeInSeconds);
JimCarver 0:6b753f761943 1126 TEST_ASSERT_EQUAL_HEX(SOTP_SUCCESS, sotpStatus);
JimCarver 0:6b753f761943 1127
JimCarver 0:6b753f761943 1128 sotpStatus = sotp_set(SOTP_TYPE_LAST_TIME_BACK, sizeof(uint64_t), (uint32_t *)&curentTimeInSeconds);
JimCarver 0:6b753f761943 1129 TEST_ASSERT_EQUAL_HEX(SOTP_SUCCESS, sotpStatus);
JimCarver 0:6b753f761943 1130
JimCarver 0:6b753f761943 1131 #if (PAL_USE_HW_RTC)
JimCarver 0:6b753f761943 1132 status = pal_plat_osSetRtcTime(curentTimeInSeconds);
JimCarver 0:6b753f761943 1133 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 1134 #endif//PAL_USE_HW_RTC
JimCarver 0:6b753f761943 1135
JimCarver 0:6b753f761943 1136 setTimeInSeconds = curentTimeInSeconds + PAL_MINIMUM_SOTP_FORWARD_LATENCY_SEC + (100 * PAL_ONE_SEC);
JimCarver 0:6b753f761943 1137 status = pal_osSetWeakTime(setTimeInSeconds);
JimCarver 0:6b753f761943 1138 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 1139
JimCarver 0:6b753f761943 1140 #if PAL_USE_INTERNAL_FLASH
JimCarver 0:6b753f761943 1141 sotpStatus = sotp_get(SOTP_TYPE_SAVED_TIME, sizeof(uint64_t), (uint32_t*)&sotpGetTime, &actualLenBytes);
JimCarver 0:6b753f761943 1142 TEST_ASSERT_EQUAL_HEX(SOTP_SUCCESS, sotpStatus);
JimCarver 0:6b753f761943 1143 TEST_ASSERT_EQUAL_UINT64(sotpGetTime, setTimeInSeconds);
JimCarver 0:6b753f761943 1144 #endif
JimCarver 0:6b753f761943 1145
JimCarver 0:6b753f761943 1146 #if (PAL_USE_HW_RTC)
JimCarver 0:6b753f761943 1147 status = pal_plat_osGetRtcTime(&rtcTime);
JimCarver 0:6b753f761943 1148 TEST_ASSERT_EQUAL_UINT64(rtcTime, setTimeInSeconds);
JimCarver 0:6b753f761943 1149 #endif//PAL_USE_HW_RTC
JimCarver 0:6b753f761943 1150
JimCarver 0:6b753f761943 1151 #if (PAL_USE_HW_RTC)
JimCarver 0:6b753f761943 1152 //restore System time
JimCarver 0:6b753f761943 1153 pal_plat_osSetRtcTime(testStartTime + PAL_RUNNING_TEST_TIME);
JimCarver 0:6b753f761943 1154 #endif
JimCarver 0:6b753f761943 1155 }
JimCarver 0:6b753f761943 1156
JimCarver 0:6b753f761943 1157 /*! \brief Check Weak Set Time - Backword flow.
JimCarver 0:6b753f761943 1158 *
JimCarver 0:6b753f761943 1159 * | # | Step | Expected |
JimCarver 0:6b753f761943 1160 * |---|--------------------------------|-------------|
JimCarver 0:6b753f761943 1161 * | 1 | checking SOTP flow - set SOTP SAVED TIME and LAST TIME BACK to new time | PAL_SUCCESS |
JimCarver 0:6b753f761943 1162 * | 2 | checking SOTP flow - not set SOTP SAVED TIME and LAST TIME BACK to new time | PAL_SUCCESS |
JimCarver 0:6b753f761943 1163 */
JimCarver 0:6b753f761943 1164 TEST(pal_rtos, OsWeakSetTime_Backword)
JimCarver 0:6b753f761943 1165 {
JimCarver 0:6b753f761943 1166 uint64_t setTimeInSeconds = 0;
JimCarver 0:6b753f761943 1167 uint64_t curentTimeInSeconds = 0;
JimCarver 0:6b753f761943 1168 palStatus_t status;
JimCarver 0:6b753f761943 1169 sotp_result_e sotpStatus = SOTP_SUCCESS;
JimCarver 0:6b753f761943 1170 uint64_t getTimeValueBackword = 0;
JimCarver 0:6b753f761943 1171 uint64_t pal_Time = 0;
JimCarver 0:6b753f761943 1172 #if (PAL_USE_HW_RTC)
JimCarver 0:6b753f761943 1173 //This code is to preserve system time
JimCarver 0:6b753f761943 1174 uint64_t testStartTime = 0;
JimCarver 0:6b753f761943 1175 status = pal_plat_osGetRtcTime(&testStartTime);
JimCarver 0:6b753f761943 1176 #endif
JimCarver 0:6b753f761943 1177
JimCarver 0:6b753f761943 1178 /*#1*/
JimCarver 0:6b753f761943 1179 #if (PAL_USE_HW_RTC)
JimCarver 0:6b753f761943 1180 pal_plat_osSetRtcTime(PAL_MIN_RTC_SET_TIME);
JimCarver 0:6b753f761943 1181 pal_osSetTime(PAL_MIN_SEC_FROM_EPOCH + PAL_SECONDS_PER_DAY * 100);
JimCarver 0:6b753f761943 1182 #endif
JimCarver 0:6b753f761943 1183 curentTimeInSeconds = pal_osGetTime();
JimCarver 0:6b753f761943 1184
JimCarver 0:6b753f761943 1185 getTimeValueBackword = curentTimeInSeconds - (3 * PAL_MINIMUM_SOTP_FORWARD_LATENCY_SEC);
JimCarver 0:6b753f761943 1186 sotpStatus = sotp_set(SOTP_TYPE_LAST_TIME_BACK, sizeof(uint64_t), (uint32_t *)&getTimeValueBackword);
JimCarver 0:6b753f761943 1187 TEST_ASSERT_EQUAL_HEX(SOTP_SUCCESS, sotpStatus);
JimCarver 0:6b753f761943 1188
JimCarver 0:6b753f761943 1189
JimCarver 0:6b753f761943 1190 setTimeInSeconds = curentTimeInSeconds - (6 * PAL_SECONDS_PER_MIN);
JimCarver 0:6b753f761943 1191 status = pal_osSetWeakTime(setTimeInSeconds);
JimCarver 0:6b753f761943 1192
JimCarver 0:6b753f761943 1193 pal_Time = pal_osGetTime();
JimCarver 0:6b753f761943 1194 if (pal_Time - setTimeInSeconds > 5)
JimCarver 0:6b753f761943 1195 {
JimCarver 0:6b753f761943 1196 status = PAL_ERR_GENERAL_BASE;
JimCarver 0:6b753f761943 1197 }
JimCarver 0:6b753f761943 1198 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 1199
JimCarver 0:6b753f761943 1200 uint64_t sotpGetTime = 0;
JimCarver 0:6b753f761943 1201 uint16_t actualLenBytes = 0;
JimCarver 0:6b753f761943 1202
JimCarver 0:6b753f761943 1203 #if PAL_USE_INTERNAL_FLASH
JimCarver 0:6b753f761943 1204 sotpStatus = sotp_get(SOTP_TYPE_SAVED_TIME, sizeof(uint64_t), (uint32_t*)&sotpGetTime, &actualLenBytes);
JimCarver 0:6b753f761943 1205 TEST_ASSERT_EQUAL_HEX(SOTP_SUCCESS, sotpStatus);
JimCarver 0:6b753f761943 1206 TEST_ASSERT_EQUAL_UINT64(sotpGetTime, setTimeInSeconds);
JimCarver 0:6b753f761943 1207
JimCarver 0:6b753f761943 1208 sotpStatus = sotp_get(SOTP_TYPE_LAST_TIME_BACK, sizeof(uint64_t), (uint32_t*)&sotpGetTime, &actualLenBytes);
JimCarver 0:6b753f761943 1209 TEST_ASSERT_EQUAL_HEX(SOTP_SUCCESS, sotpStatus);
JimCarver 0:6b753f761943 1210 TEST_ASSERT_EQUAL_UINT64(sotpGetTime, setTimeInSeconds);
JimCarver 0:6b753f761943 1211 #endif
JimCarver 0:6b753f761943 1212
JimCarver 0:6b753f761943 1213 /*#2*/
JimCarver 0:6b753f761943 1214 curentTimeInSeconds = pal_osGetTime();
JimCarver 0:6b753f761943 1215 getTimeValueBackword = curentTimeInSeconds - (3 * PAL_MINIMUM_SOTP_FORWARD_LATENCY_SEC);
JimCarver 0:6b753f761943 1216 sotpStatus = sotp_set(SOTP_TYPE_LAST_TIME_BACK, sizeof(uint64_t), (uint32_t *)&getTimeValueBackword);
JimCarver 0:6b753f761943 1217 TEST_ASSERT_EQUAL_HEX(SOTP_SUCCESS, sotpStatus);
JimCarver 0:6b753f761943 1218
JimCarver 0:6b753f761943 1219 sotpStatus = sotp_set(SOTP_TYPE_SAVED_TIME, sizeof(uint64_t), (uint32_t *)&getTimeValueBackword);
JimCarver 0:6b753f761943 1220 TEST_ASSERT_EQUAL_HEX(SOTP_SUCCESS, sotpStatus);
JimCarver 0:6b753f761943 1221
JimCarver 0:6b753f761943 1222 setTimeInSeconds = curentTimeInSeconds - (12 * PAL_SECONDS_PER_MIN);
JimCarver 0:6b753f761943 1223
JimCarver 0:6b753f761943 1224 status = pal_osSetWeakTime(setTimeInSeconds);
JimCarver 0:6b753f761943 1225 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 1226
JimCarver 0:6b753f761943 1227 #if PAL_USE_INTERNAL_FLASH
JimCarver 0:6b753f761943 1228 sotpStatus = sotp_get(SOTP_TYPE_SAVED_TIME, sizeof(uint64_t), (uint32_t*)&sotpGetTime, &actualLenBytes);
JimCarver 0:6b753f761943 1229 TEST_ASSERT_EQUAL_HEX(SOTP_SUCCESS, sotpStatus);
JimCarver 0:6b753f761943 1230 TEST_ASSERT_NOT_EQUAL(sotpGetTime, setTimeInSeconds);
JimCarver 0:6b753f761943 1231 sotpStatus = sotp_get(SOTP_TYPE_LAST_TIME_BACK, sizeof(uint64_t), (uint32_t*)&sotpGetTime, &actualLenBytes);
JimCarver 0:6b753f761943 1232 TEST_ASSERT_EQUAL_HEX(SOTP_SUCCESS, sotpStatus);
JimCarver 0:6b753f761943 1233 TEST_ASSERT_NOT_EQUAL(sotpGetTime, setTimeInSeconds);
JimCarver 0:6b753f761943 1234 #endif
JimCarver 0:6b753f761943 1235
JimCarver 0:6b753f761943 1236 #if (PAL_USE_HW_RTC)
JimCarver 0:6b753f761943 1237 //restore System time
JimCarver 0:6b753f761943 1238 pal_plat_osSetRtcTime(testStartTime + PAL_RUNNING_TEST_TIME);
JimCarver 0:6b753f761943 1239 #endif
JimCarver 0:6b753f761943 1240 }
JimCarver 0:6b753f761943 1241
JimCarver 0:6b753f761943 1242 /*! \brief Weak Strong Set Time- minimalStoredLag flow.
JimCarver 0:6b753f761943 1243 *
JimCarver 0:6b753f761943 1244 * | # | Step | Expected |
JimCarver 0:6b753f761943 1245 * |---|--------------------------------|-------------|
JimCarver 0:6b753f761943 1246 * | 1 | checking SOTP flow- set SOTP SAVED TIME to new time | PAL_SUCCESS |
JimCarver 0:6b753f761943 1247 * | 2 | checking SOTP flow- not set SOTP SAVED TIME to new time | PAL_SUCCESS |
JimCarver 0:6b753f761943 1248 */
JimCarver 0:6b753f761943 1249 TEST(pal_rtos, OsWeakSetTime_minimalStoredLag)
JimCarver 0:6b753f761943 1250 {
JimCarver 0:6b753f761943 1251 palStatus_t status;
JimCarver 0:6b753f761943 1252 sotp_result_e sotpStatus = SOTP_SUCCESS;
JimCarver 0:6b753f761943 1253 uint64_t setTimeInSeconds = 0;
JimCarver 0:6b753f761943 1254 uint64_t curentTimeInSeconds = 0;
JimCarver 0:6b753f761943 1255 uint64_t sotpGetTime = 0;
JimCarver 0:6b753f761943 1256 uint16_t actualLenBytes = 0;
JimCarver 0:6b753f761943 1257 uint64_t setSotpTimeValue = 0;
JimCarver 0:6b753f761943 1258
JimCarver 0:6b753f761943 1259 #if (PAL_USE_HW_RTC)
JimCarver 0:6b753f761943 1260 //This code is to preserve system time
JimCarver 0:6b753f761943 1261 uint64_t testStartTime = 0;
JimCarver 0:6b753f761943 1262 status = pal_plat_osGetRtcTime(&testStartTime);
JimCarver 0:6b753f761943 1263 #endif
JimCarver 0:6b753f761943 1264
JimCarver 0:6b753f761943 1265 /*#1*/
JimCarver 0:6b753f761943 1266 #if (PAL_USE_HW_RTC)
JimCarver 0:6b753f761943 1267 pal_plat_osSetRtcTime(PAL_MIN_RTC_SET_TIME);
JimCarver 0:6b753f761943 1268 #endif
JimCarver 0:6b753f761943 1269 pal_osSetTime(PAL_MIN_SEC_FROM_EPOCH + PAL_SECONDS_PER_DAY * 100);
JimCarver 0:6b753f761943 1270 curentTimeInSeconds = pal_osGetTime();
JimCarver 0:6b753f761943 1271 setTimeInSeconds = curentTimeInSeconds;
JimCarver 0:6b753f761943 1272
JimCarver 0:6b753f761943 1273 setSotpTimeValue = curentTimeInSeconds - (PAL_MINIMUM_STORAGE_LATENCY_SEC + 50);
JimCarver 0:6b753f761943 1274 sotpStatus = sotp_set(SOTP_TYPE_SAVED_TIME, sizeof(uint64_t), (uint32_t *)&setSotpTimeValue);
JimCarver 0:6b753f761943 1275 TEST_ASSERT_EQUAL_HEX(SOTP_SUCCESS, sotpStatus);
JimCarver 0:6b753f761943 1276
JimCarver 0:6b753f761943 1277 status = pal_osSetWeakTime(setTimeInSeconds);
JimCarver 0:6b753f761943 1278 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 1279
JimCarver 0:6b753f761943 1280 #if PAL_USE_INTERNAL_FLASH
JimCarver 0:6b753f761943 1281 sotpStatus = sotp_get(SOTP_TYPE_SAVED_TIME, sizeof(uint64_t), (uint32_t*)&sotpGetTime, &actualLenBytes);
JimCarver 0:6b753f761943 1282 TEST_ASSERT_EQUAL_HEX(SOTP_SUCCESS, sotpStatus);
JimCarver 0:6b753f761943 1283 TEST_ASSERT_EQUAL_UINT64(sotpGetTime, setTimeInSeconds);
JimCarver 0:6b753f761943 1284 #endif
JimCarver 0:6b753f761943 1285
JimCarver 0:6b753f761943 1286 /*#2*/
JimCarver 0:6b753f761943 1287 curentTimeInSeconds = pal_osGetTime();
JimCarver 0:6b753f761943 1288 setTimeInSeconds = curentTimeInSeconds - 50;
JimCarver 0:6b753f761943 1289
JimCarver 0:6b753f761943 1290 setSotpTimeValue = curentTimeInSeconds;
JimCarver 0:6b753f761943 1291 sotpStatus = sotp_set(SOTP_TYPE_LAST_TIME_BACK, sizeof(uint64_t), (uint32_t *)&setSotpTimeValue);
JimCarver 0:6b753f761943 1292 TEST_ASSERT_EQUAL_HEX(SOTP_SUCCESS, sotpStatus);
JimCarver 0:6b753f761943 1293
JimCarver 0:6b753f761943 1294 status = pal_osSetWeakTime(setTimeInSeconds);
JimCarver 0:6b753f761943 1295 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 1296
JimCarver 0:6b753f761943 1297 #if PAL_USE_INTERNAL_FLASH
JimCarver 0:6b753f761943 1298 sotpStatus = sotp_get(SOTP_TYPE_SAVED_TIME, sizeof(uint64_t), (uint32_t*)&sotpGetTime, &actualLenBytes);
JimCarver 0:6b753f761943 1299 TEST_ASSERT_EQUAL_HEX(SOTP_SUCCESS, sotpStatus);
JimCarver 0:6b753f761943 1300 TEST_ASSERT_NOT_EQUAL(sotpGetTime, setTimeInSeconds);
JimCarver 0:6b753f761943 1301 #endif
JimCarver 0:6b753f761943 1302
JimCarver 0:6b753f761943 1303 #if (PAL_USE_HW_RTC)
JimCarver 0:6b753f761943 1304 //restore System time
JimCarver 0:6b753f761943 1305 pal_plat_osSetRtcTime(testStartTime + PAL_RUNNING_TEST_TIME);
JimCarver 0:6b753f761943 1306 #endif
JimCarver 0:6b753f761943 1307 }
JimCarver 0:6b753f761943 1308
JimCarver 0:6b753f761943 1309 /*! \brief Check Strong Set Time.
JimCarver 0:6b753f761943 1310 *
JimCarver 0:6b753f761943 1311 * | # | Step | Expected |
JimCarver 0:6b753f761943 1312 * |---|--------------------------------|-------------|
JimCarver 0:6b753f761943 1313 * | 1 | checking RTC flow - set new RTC time | PAL_SUCCESS |
JimCarver 0:6b753f761943 1314 * | 2 | checking RTC flow - not set RTC new time | PAL_SUCCESS |
JimCarver 0:6b753f761943 1315 * | 3 | checking SOTP flow - set SOTP SAVED TIME and LAST TIME BACK to new time | PAL_SUCCESS |
JimCarver 0:6b753f761943 1316 * | 4 | checking SOTP flow - not set SOTP SAVED TIME and LAST TIME BACK to new time | PAL_SUCCESS |
JimCarver 0:6b753f761943 1317 */
JimCarver 0:6b753f761943 1318 TEST(pal_rtos, OsStrongSetTime)
JimCarver 0:6b753f761943 1319 {
JimCarver 0:6b753f761943 1320 palStatus_t status;
JimCarver 0:6b753f761943 1321 sotp_result_e sotpStatus = SOTP_SUCCESS;
JimCarver 0:6b753f761943 1322 uint64_t setTimeInSeconds = 0;
JimCarver 0:6b753f761943 1323 uint64_t curentTimeInSeconds = 0;
JimCarver 0:6b753f761943 1324 uint64_t pal_Time = 0;
JimCarver 0:6b753f761943 1325 uint64_t sotpGetTime = 0;
JimCarver 0:6b753f761943 1326 uint16_t actualLenBytes = 0;
JimCarver 0:6b753f761943 1327 uint64_t setSotpTimeValue = 0;
JimCarver 0:6b753f761943 1328
JimCarver 0:6b753f761943 1329 #if (PAL_USE_HW_RTC)
JimCarver 0:6b753f761943 1330 //This code is to preserve system time
JimCarver 0:6b753f761943 1331 uint64_t testStartTime = 0;
JimCarver 0:6b753f761943 1332 status = pal_plat_osGetRtcTime(&testStartTime);
JimCarver 0:6b753f761943 1333 #endif
JimCarver 0:6b753f761943 1334
JimCarver 0:6b753f761943 1335 /*#1*/
JimCarver 0:6b753f761943 1336 #if (PAL_USE_HW_RTC)
JimCarver 0:6b753f761943 1337 pal_plat_osSetRtcTime(PAL_MIN_RTC_SET_TIME);
JimCarver 0:6b753f761943 1338 #endif
JimCarver 0:6b753f761943 1339 pal_osSetTime(PAL_MIN_SEC_FROM_EPOCH + PAL_SECONDS_PER_DAY * 100);
JimCarver 0:6b753f761943 1340 curentTimeInSeconds = pal_osGetTime();
JimCarver 0:6b753f761943 1341 setTimeInSeconds = curentTimeInSeconds;
JimCarver 0:6b753f761943 1342
JimCarver 0:6b753f761943 1343 #if (PAL_USE_HW_RTC)
JimCarver 0:6b753f761943 1344 uint64_t rtcTime = 0;
JimCarver 0:6b753f761943 1345 rtcTime = curentTimeInSeconds - (50 + PAL_MINIMUM_RTC_LATENCY_SEC);
JimCarver 0:6b753f761943 1346 status = pal_plat_osSetRtcTime(rtcTime);
JimCarver 0:6b753f761943 1347 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 1348 #endif//PAL_USE_HW_RTC
JimCarver 0:6b753f761943 1349
JimCarver 0:6b753f761943 1350 status = pal_osSetStrongTime(setTimeInSeconds);
JimCarver 0:6b753f761943 1351 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 1352
JimCarver 0:6b753f761943 1353 #if (PAL_USE_HW_RTC)
JimCarver 0:6b753f761943 1354 status = pal_plat_osGetRtcTime(&rtcTime);
JimCarver 0:6b753f761943 1355 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 1356 TEST_ASSERT_EQUAL_UINT64(rtcTime, setTimeInSeconds);
JimCarver 0:6b753f761943 1357 #endif//PAL_USE_HW_RTC
JimCarver 0:6b753f761943 1358
JimCarver 0:6b753f761943 1359 pal_Time = pal_osGetTime();
JimCarver 0:6b753f761943 1360 if (pal_Time - setTimeInSeconds > 5)
JimCarver 0:6b753f761943 1361 {
JimCarver 0:6b753f761943 1362 status = PAL_ERR_GENERAL_BASE;
JimCarver 0:6b753f761943 1363 }
JimCarver 0:6b753f761943 1364 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 1365
JimCarver 0:6b753f761943 1366 /*#2*/
JimCarver 0:6b753f761943 1367 curentTimeInSeconds = pal_osGetTime();
JimCarver 0:6b753f761943 1368 setTimeInSeconds = curentTimeInSeconds;
JimCarver 0:6b753f761943 1369
JimCarver 0:6b753f761943 1370 #if (PAL_USE_HW_RTC)
JimCarver 0:6b753f761943 1371 rtcTime = curentTimeInSeconds;
JimCarver 0:6b753f761943 1372 status = pal_plat_osSetRtcTime(rtcTime - 50);
JimCarver 0:6b753f761943 1373 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 1374 #endif//PAL_USE_HW_RTC
JimCarver 0:6b753f761943 1375
JimCarver 0:6b753f761943 1376 status = pal_osSetStrongTime(setTimeInSeconds);
JimCarver 0:6b753f761943 1377
JimCarver 0:6b753f761943 1378 #if (PAL_USE_HW_RTC)
JimCarver 0:6b753f761943 1379 status = pal_plat_osGetRtcTime(&rtcTime);
JimCarver 0:6b753f761943 1380 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 1381 TEST_ASSERT_NOT_EQUAL(rtcTime, setTimeInSeconds);
JimCarver 0:6b753f761943 1382 #endif//PAL_USE_HW_RTC
JimCarver 0:6b753f761943 1383
JimCarver 0:6b753f761943 1384 pal_Time = pal_osGetTime();
JimCarver 0:6b753f761943 1385 if (pal_Time - setTimeInSeconds > 5){
JimCarver 0:6b753f761943 1386 status = PAL_ERR_GENERAL_BASE;
JimCarver 0:6b753f761943 1387 }
JimCarver 0:6b753f761943 1388 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 1389
JimCarver 0:6b753f761943 1390 /*#3*/
JimCarver 0:6b753f761943 1391 curentTimeInSeconds = pal_osGetTime();
JimCarver 0:6b753f761943 1392 setTimeInSeconds = curentTimeInSeconds;
JimCarver 0:6b753f761943 1393 setSotpTimeValue = curentTimeInSeconds - (PAL_MINIMUM_SOTP_FORWARD_LATENCY_SEC + 1*PAL_ONE_SEC);
JimCarver 0:6b753f761943 1394 sotpStatus = sotp_set(SOTP_TYPE_SAVED_TIME, sizeof(uint64_t), (uint32_t *)&setSotpTimeValue);
JimCarver 0:6b753f761943 1395 TEST_ASSERT_EQUAL_HEX(SOTP_SUCCESS, sotpStatus);
JimCarver 0:6b753f761943 1396
JimCarver 0:6b753f761943 1397 status = pal_osSetStrongTime(setTimeInSeconds);
JimCarver 0:6b753f761943 1398 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 1399
JimCarver 0:6b753f761943 1400 #if PAL_USE_INTERNAL_FLASH
JimCarver 0:6b753f761943 1401 sotpStatus = sotp_get(SOTP_TYPE_SAVED_TIME, sizeof(uint64_t), (uint32_t*)&sotpGetTime, &actualLenBytes);
JimCarver 0:6b753f761943 1402 TEST_ASSERT_EQUAL_HEX(SOTP_SUCCESS, sotpStatus);
JimCarver 0:6b753f761943 1403 TEST_ASSERT_EQUAL_UINT64(sotpGetTime, setTimeInSeconds);
JimCarver 0:6b753f761943 1404
JimCarver 0:6b753f761943 1405 sotpStatus = sotp_get(SOTP_TYPE_LAST_TIME_BACK, sizeof(uint64_t), (uint32_t*)&sotpGetTime, &actualLenBytes);
JimCarver 0:6b753f761943 1406 TEST_ASSERT_EQUAL_HEX(SOTP_SUCCESS, sotpStatus);
JimCarver 0:6b753f761943 1407 TEST_ASSERT_EQUAL_UINT64(sotpGetTime, setTimeInSeconds);
JimCarver 0:6b753f761943 1408 #endif
JimCarver 0:6b753f761943 1409
JimCarver 0:6b753f761943 1410 pal_Time = pal_osGetTime();
JimCarver 0:6b753f761943 1411 if (pal_Time - setTimeInSeconds > 5)
JimCarver 0:6b753f761943 1412 {
JimCarver 0:6b753f761943 1413 status = PAL_ERR_GENERAL_BASE;
JimCarver 0:6b753f761943 1414 }
JimCarver 0:6b753f761943 1415 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 1416
JimCarver 0:6b753f761943 1417 /*#4*/
JimCarver 0:6b753f761943 1418 curentTimeInSeconds = pal_osGetTime();
JimCarver 0:6b753f761943 1419 setTimeInSeconds = curentTimeInSeconds;
JimCarver 0:6b753f761943 1420
JimCarver 0:6b753f761943 1421 setSotpTimeValue = curentTimeInSeconds - 5;
JimCarver 0:6b753f761943 1422 sotpStatus = sotp_set(SOTP_TYPE_SAVED_TIME, sizeof(uint64_t), (uint32_t *)&setSotpTimeValue);
JimCarver 0:6b753f761943 1423 TEST_ASSERT_EQUAL_HEX(SOTP_SUCCESS, sotpStatus);
JimCarver 0:6b753f761943 1424
JimCarver 0:6b753f761943 1425 sotpStatus = sotp_set(SOTP_TYPE_LAST_TIME_BACK, sizeof(uint64_t), (uint32_t *)&setSotpTimeValue);
JimCarver 0:6b753f761943 1426 TEST_ASSERT_EQUAL_HEX(SOTP_SUCCESS, sotpStatus);
JimCarver 0:6b753f761943 1427
JimCarver 0:6b753f761943 1428 status = pal_osSetStrongTime(setTimeInSeconds);
JimCarver 0:6b753f761943 1429 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 1430
JimCarver 0:6b753f761943 1431 #if PAL_USE_INTERNAL_FLASH
JimCarver 0:6b753f761943 1432 sotpStatus = sotp_get(SOTP_TYPE_SAVED_TIME, sizeof(uint64_t), (uint32_t*)&sotpGetTime, &actualLenBytes);
JimCarver 0:6b753f761943 1433 TEST_ASSERT_EQUAL_HEX(SOTP_SUCCESS, sotpStatus);
JimCarver 0:6b753f761943 1434 TEST_ASSERT_NOT_EQUAL(sotpGetTime, setTimeInSeconds);
JimCarver 0:6b753f761943 1435
JimCarver 0:6b753f761943 1436 sotpStatus = sotp_get(SOTP_TYPE_LAST_TIME_BACK, sizeof(uint64_t), (uint32_t*)&sotpGetTime, &actualLenBytes);
JimCarver 0:6b753f761943 1437 TEST_ASSERT_EQUAL_HEX(SOTP_SUCCESS, sotpStatus);
JimCarver 0:6b753f761943 1438 TEST_ASSERT_NOT_EQUAL(sotpGetTime, setTimeInSeconds);
JimCarver 0:6b753f761943 1439 #endif
JimCarver 0:6b753f761943 1440
JimCarver 0:6b753f761943 1441 pal_Time = pal_osGetTime();
JimCarver 0:6b753f761943 1442 if (pal_Time - setTimeInSeconds > 5)
JimCarver 0:6b753f761943 1443 {
JimCarver 0:6b753f761943 1444 status = PAL_ERR_GENERAL_BASE;
JimCarver 0:6b753f761943 1445 }
JimCarver 0:6b753f761943 1446 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 1447
JimCarver 0:6b753f761943 1448 #if (PAL_USE_HW_RTC)
JimCarver 0:6b753f761943 1449 //restore System time
JimCarver 0:6b753f761943 1450 pal_plat_osSetRtcTime(testStartTime + PAL_RUNNING_TEST_TIME);
JimCarver 0:6b753f761943 1451 #endif
JimCarver 0:6b753f761943 1452 }
JimCarver 0:6b753f761943 1453
JimCarver 0:6b753f761943 1454
JimCarver 0:6b753f761943 1455 /*! \brief This test verify the functionality of the RTC
JimCarver 0:6b753f761943 1456 *
JimCarver 0:6b753f761943 1457 * | # | Step | Expected |
JimCarver 0:6b753f761943 1458 * |---|--------------------------------|-------------|
JimCarver 0:6b753f761943 1459 * | 1 | Get system RTC | PAL_SUCCESS |
JimCarver 0:6b753f761943 1460 * | 2 | set new RTC | PAL_SUCCESS |
JimCarver 0:6b753f761943 1461 * | 3 | delay for 2 seconds | PAL_SUCCESS |
JimCarver 0:6b753f761943 1462 * | 4 | get RTC & compare to RTC from (2) | PAL_SUCCESS |
JimCarver 0:6b753f761943 1463 * | 5 | restore system time from (1) | PAL_SUCCESS |
JimCarver 0:6b753f761943 1464 */
JimCarver 0:6b753f761943 1465 TEST(pal_rtos, pal_rtc)
JimCarver 0:6b753f761943 1466 {
JimCarver 0:6b753f761943 1467 #if (PAL_USE_HW_RTC)
JimCarver 0:6b753f761943 1468 palStatus_t status = PAL_SUCCESS;
JimCarver 0:6b753f761943 1469 uint64_t time1 = 0, sysTime = 0;
JimCarver 0:6b753f761943 1470
JimCarver 0:6b753f761943 1471 /*#1*/
JimCarver 0:6b753f761943 1472 status = pal_plat_osGetRtcTime(&sysTime);
JimCarver 0:6b753f761943 1473 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 1474
JimCarver 0:6b753f761943 1475 /*#2*/
JimCarver 0:6b753f761943 1476 status = pal_plat_osSetRtcTime(PAL_MIN_RTC_SET_TIME);
JimCarver 0:6b753f761943 1477 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 1478
JimCarver 0:6b753f761943 1479 /*#3*/
JimCarver 0:6b753f761943 1480 status = pal_osDelay(2000);
JimCarver 0:6b753f761943 1481 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 1482
JimCarver 0:6b753f761943 1483 /*#4*/
JimCarver 0:6b753f761943 1484 status = pal_plat_osGetRtcTime(&time1);
JimCarver 0:6b753f761943 1485 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 1486 TEST_ASSERT_TRUE(time1 - PAL_MIN_RTC_SET_TIME >= 1 * PAL_ONE_SEC);
JimCarver 0:6b753f761943 1487
JimCarver 0:6b753f761943 1488 /*#5*/
JimCarver 0:6b753f761943 1489 pal_plat_osSetRtcTime(sysTime + time1 - PAL_MIN_RTC_SET_TIME + 1); //add lost time from delay
JimCarver 0:6b753f761943 1490
JimCarver 0:6b753f761943 1491
JimCarver 0:6b753f761943 1492 #endif
JimCarver 0:6b753f761943 1493 }
JimCarver 0:6b753f761943 1494
JimCarver 0:6b753f761943 1495 // the following functions are not part of PAL's external API hence extern
JimCarver 0:6b753f761943 1496 extern palStatus_t pal_noiseWriteValue(const int32_t* data, uint8_t startBit, uint8_t lenBits, uint8_t* bitsWritten);
JimCarver 0:6b753f761943 1497 extern palStatus_t pal_noiseWriteBuffer(int32_t* buffer, uint16_t lenBits, uint16_t* bitsWritten);
JimCarver 0:6b753f761943 1498 extern palStatus_t pal_noiseRead(int32_t buffer[PAL_NOISE_BUFFER_LEN], bool partial, uint16_t* bitsRead);
JimCarver 0:6b753f761943 1499
JimCarver 0:6b753f761943 1500 /*! \brief This test verifies the functionality of noise collection
JimCarver 0:6b753f761943 1501 *
JimCarver 0:6b753f761943 1502 * | # | Step | Expected |
JimCarver 0:6b753f761943 1503 * |---|--------------------------------------------------------------------------------------------|-------------|
JimCarver 0:6b753f761943 1504 * | 1 | Reset the noise buffer by reading watever is available | PAL_SUCCESS |
JimCarver 0:6b753f761943 1505 * | 2 | Write an entire int32_t (all bits) and verify writes and that full read not possible | PAL_SUCCESS |
JimCarver 0:6b753f761943 1506 * | 3 | Write only some bits of the int32_t and verify writes and that full read not possible | PAL_SUCCESS |
JimCarver 0:6b753f761943 1507 * | 4 | Write only some bits of the int32_t, implicitly causing splitting the value into 2 indexes | PAL_SUCCESS |
JimCarver 0:6b753f761943 1508 * | 5 | Read whatever was collected thus far (partial read) and verify output | PAL_SUCCESS |
JimCarver 0:6b753f761943 1509 * | 6 | Try to read again and verify buffer is empty | PAL_SUCCESS |
JimCarver 0:6b753f761943 1510 * | 7 | Write a buffer excluding the last 7 bits of the last index and verify results | PAL_SUCCESS |
JimCarver 0:6b753f761943 1511 * | 8 | Fill the buffer and try to write some more data into it | PAL_SUCCESS |
JimCarver 0:6b753f761943 1512 */
JimCarver 0:6b753f761943 1513 TEST(pal_rtos, pal_noise)
JimCarver 0:6b753f761943 1514 {
JimCarver 0:6b753f761943 1515 palStatus_t status;
JimCarver 0:6b753f761943 1516 int32_t outBuffer[PAL_NOISE_BUFFER_LEN] = { 0 };
JimCarver 0:6b753f761943 1517 int32_t inBuffer[] = { 0xB76EC265, 0xD16ACE6E, 0xF56AAD6A };
JimCarver 0:6b753f761943 1518 uint16_t bitsWritten = 0;
JimCarver 0:6b753f761943 1519 uint16_t bitsRead = 0;
JimCarver 0:6b753f761943 1520 int32_t writeValue;
JimCarver 0:6b753f761943 1521 uint8_t i;
JimCarver 0:6b753f761943 1522
JimCarver 0:6b753f761943 1523 /*#1*/
JimCarver 0:6b753f761943 1524 pal_noiseRead(outBuffer, true, &bitsRead);
JimCarver 0:6b753f761943 1525 memset(outBuffer, 0, PAL_NOISE_SIZE_BYTES);
JimCarver 0:6b753f761943 1526
JimCarver 0:6b753f761943 1527 /*#2*/
JimCarver 0:6b753f761943 1528 writeValue = 0xCB76102A;
JimCarver 0:6b753f761943 1529 status = pal_noiseWriteValue(&writeValue, 0, 32, (uint8_t*)&bitsWritten); // write all bits
JimCarver 0:6b753f761943 1530 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 1531 TEST_ASSERT_EQUAL(32, bitsWritten);
JimCarver 0:6b753f761943 1532 status = pal_noiseRead(outBuffer, false, &bitsRead);
JimCarver 0:6b753f761943 1533 TEST_ASSERT_EQUAL_HEX(PAL_ERR_RTOS_NOISE_BUFFER_NOT_FULL, status);
JimCarver 0:6b753f761943 1534 TEST_ASSERT_EQUAL(0, bitsRead);
JimCarver 0:6b753f761943 1535
JimCarver 0:6b753f761943 1536 /*#3*/
JimCarver 0:6b753f761943 1537 status = pal_noiseWriteValue(&writeValue, 3, 20, (uint8_t*)&bitsWritten); // write some of the bits, starting at bit index 3
JimCarver 0:6b753f761943 1538 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 1539 TEST_ASSERT_EQUAL(20, bitsWritten);
JimCarver 0:6b753f761943 1540 status = pal_noiseRead(outBuffer, false, &bitsRead);
JimCarver 0:6b753f761943 1541 TEST_ASSERT_EQUAL_HEX(PAL_ERR_RTOS_NOISE_BUFFER_NOT_FULL, status);
JimCarver 0:6b753f761943 1542 TEST_ASSERT_EQUAL(0, bitsRead);
JimCarver 0:6b753f761943 1543
JimCarver 0:6b753f761943 1544 /*#4*/
JimCarver 0:6b753f761943 1545 status = pal_noiseWriteValue(&writeValue, 16, 16, (uint8_t*)&bitsWritten); // write some of the bits, starting at bit index 16, this functionality tests splitting the bits into 2 different indexes
JimCarver 0:6b753f761943 1546 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 1547 TEST_ASSERT_EQUAL(16, bitsWritten);
JimCarver 0:6b753f761943 1548 status = pal_noiseRead(outBuffer, false, &bitsRead);
JimCarver 0:6b753f761943 1549 TEST_ASSERT_EQUAL_HEX(PAL_ERR_RTOS_NOISE_BUFFER_NOT_FULL, status);
JimCarver 0:6b753f761943 1550 TEST_ASSERT_EQUAL(0, bitsRead);
JimCarver 0:6b753f761943 1551
JimCarver 0:6b753f761943 1552 /*#5*/
JimCarver 0:6b753f761943 1553 status = pal_noiseRead(outBuffer, true, &bitsRead); // read whatever collected (resets buffer)
JimCarver 0:6b753f761943 1554 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 1555 TEST_ASSERT_EQUAL(64, bitsRead); // even though we wrote 68 bits by now, output should be 64 since the last byte is not full so we should not receive it back
JimCarver 0:6b753f761943 1556 TEST_ASSERT_EQUAL_HEX(0xCB76102A, outBuffer[0]);
JimCarver 0:6b753f761943 1557 TEST_ASSERT_EQUAL_HEX(0xB76EC205, outBuffer[1]);
JimCarver 0:6b753f761943 1558 TEST_ASSERT_EQUAL_HEX(0, outBuffer[2]);
JimCarver 0:6b753f761943 1559 memset(outBuffer, 0, PAL_NOISE_SIZE_BYTES);
JimCarver 0:6b753f761943 1560
JimCarver 0:6b753f761943 1561 /*#6*/
JimCarver 0:6b753f761943 1562 status = pal_noiseRead(outBuffer, false, &bitsRead);
JimCarver 0:6b753f761943 1563 TEST_ASSERT_EQUAL_HEX(PAL_ERR_RTOS_NOISE_BUFFER_EMPTY, status);
JimCarver 0:6b753f761943 1564 TEST_ASSERT_EQUAL(0, bitsRead);
JimCarver 0:6b753f761943 1565
JimCarver 0:6b753f761943 1566 /*#7*/
JimCarver 0:6b753f761943 1567 status = pal_noiseWriteBuffer(inBuffer, ((sizeof(inBuffer) * CHAR_BIT) - 7), &bitsWritten); // write all except for the last 7 bits of index 2
JimCarver 0:6b753f761943 1568 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 1569 TEST_ASSERT_EQUAL(((sizeof(inBuffer) * CHAR_BIT) - 7), bitsWritten);
JimCarver 0:6b753f761943 1570 status = pal_noiseRead(outBuffer, false, &bitsRead);
JimCarver 0:6b753f761943 1571 TEST_ASSERT_EQUAL_HEX(PAL_ERR_RTOS_NOISE_BUFFER_NOT_FULL, status);
JimCarver 0:6b753f761943 1572 TEST_ASSERT_EQUAL(0, bitsRead);
JimCarver 0:6b753f761943 1573 status = pal_noiseRead(outBuffer, true, &bitsRead); // read whatever collected (resets buffer)
JimCarver 0:6b753f761943 1574 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 1575 TEST_ASSERT_NOT_EQUAL(0, bitsRead);
JimCarver 0:6b753f761943 1576 TEST_ASSERT_EQUAL_HEX(inBuffer[0], outBuffer[0]);
JimCarver 0:6b753f761943 1577 TEST_ASSERT_EQUAL_HEX(inBuffer[1], outBuffer[1]);
JimCarver 0:6b753f761943 1578 TEST_ASSERT_EQUAL_HEX(0x6AAD6A, outBuffer[2]);
JimCarver 0:6b753f761943 1579
JimCarver 0:6b753f761943 1580 /*#8*/
JimCarver 0:6b753f761943 1581 for (i = 0; i <= (sizeof(inBuffer) / sizeof(int32_t)); ++i)
JimCarver 0:6b753f761943 1582 {
JimCarver 0:6b753f761943 1583 status = pal_noiseWriteBuffer(inBuffer, (sizeof(inBuffer) * CHAR_BIT), &bitsWritten);
JimCarver 0:6b753f761943 1584 TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
JimCarver 0:6b753f761943 1585 TEST_ASSERT_EQUAL_HEX((sizeof(inBuffer) * CHAR_BIT), bitsWritten);
JimCarver 0:6b753f761943 1586 }
JimCarver 0:6b753f761943 1587 status = pal_noiseWriteBuffer(inBuffer, (sizeof(inBuffer) * CHAR_BIT), &bitsWritten);
JimCarver 0:6b753f761943 1588 TEST_ASSERT_EQUAL_HEX(PAL_ERR_RTOS_NOISE_BUFFER_FULL, status);
JimCarver 0:6b753f761943 1589 TEST_ASSERT_EQUAL_HEX(0, bitsWritten);
JimCarver 0:6b753f761943 1590 }