Simple interface for Mbed Cloud Client
Embed:
(wiki syntax)
Show/hide line numbers
pal_update_test.c
00001 /******************************************************************************* 00002 * Copyright 2016, 2017 ARM Ltd. 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 *******************************************************************************/ 00016 00017 #include "pal.h" 00018 #include "unity.h" 00019 #include "unity_fixture.h" 00020 #include "string.h" 00021 #include "mbed_trace.h" 00022 00023 00024 #define KILOBYTE 1024 00025 00026 #define FIRST_IMAGE_INDEX 0 00027 00028 TEST_GROUP(pal_update); 00029 00030 00031 palBuffer_t g_writeBuffer = {0}; 00032 palBuffer_t g_readBuffer = {0}; 00033 palImageHeaderDeails_t g_imageHeader = {0}; 00034 uint8_t g_isTestDone; 00035 00036 00037 uint8_t numberofBlocks = 0; 00038 00039 /*! \brief Sanity test the update test are running. 00040 */ 00041 TEST_SETUP(pal_update) 00042 { 00043 PAL_LOG(INFO, "running new test\r\n"); 00044 00045 } 00046 00047 typedef enum _updateTestState 00048 { 00049 test_init = 1, 00050 test_write, 00051 test_commit, 00052 test_read 00053 }updateTestState; 00054 00055 PAL_PRIVATE void stateAdvance(palImageEvents_t state) 00056 { 00057 PAL_PRINTF("Finished event %d\r\n",state); 00058 state++; 00059 PAL_PRINTF("Starting event %d\r\n",state); 00060 int rc = PAL_SUCCESS; 00061 PAL_PRINTF("Write ptr = (%p - %p) read ptr = (%p - %p)\r\n", 00062 g_writeBuffer.buffer,g_writeBuffer.buffer + g_writeBuffer.maxBufferLength, 00063 g_readBuffer.buffer, g_readBuffer.buffer + g_readBuffer.maxBufferLength); 00064 switch (state) 00065 { 00066 case PAL_IMAGE_EVENT_PREPARE: 00067 rc = pal_imagePrepare(FIRST_IMAGE_INDEX, &g_imageHeader); 00068 PAL_PRINTF("pal_imagePrepare returned %d \r\n",rc); 00069 break; 00070 case PAL_IMAGE_EVENT_WRITE: 00071 rc = pal_imageWrite(FIRST_IMAGE_INDEX, 0, (palConstBuffer_t*)&g_writeBuffer); 00072 PAL_PRINTF("pal_imageWrite returned %d \r\n",rc); 00073 TEST_ASSERT_TRUE(rc >= 0); 00074 break; 00075 case PAL_IMAGE_EVENT_FINALIZE: 00076 rc = pal_imageFinalize(FIRST_IMAGE_INDEX); 00077 PAL_PRINTF("pal_imageFinalize returned %d \r\n",rc); 00078 TEST_ASSERT_TRUE(rc >= 0); 00079 break; 00080 case PAL_IMAGE_EVENT_READTOBUFFER: 00081 rc = pal_imageReadToBuffer(FIRST_IMAGE_INDEX,0,&g_readBuffer); 00082 TEST_ASSERT_TRUE(rc >= 0); 00083 PAL_PRINTF("pal_imageReadToBuffer with offset %d return %d \r\n",0,rc); 00084 break; 00085 case PAL_IMAGE_EVENT_ACTIVATE: 00086 PAL_PRINTF("Checking the output\r\n"); 00087 PAL_PRINTF("\r\ng_readBuffer bufferLength=%" PRIu32 "\r\n",g_readBuffer.maxBufferLength); 00088 00089 00090 TEST_ASSERT_EQUAL_MEMORY(g_writeBuffer.buffer,g_readBuffer.buffer,g_readBuffer.maxBufferLength); 00091 PAL_PRINTF("write ptr = %p read ptr = %p\r\n",g_writeBuffer.buffer,g_readBuffer.buffer); 00092 00093 free(g_readBuffer.buffer); 00094 free(g_writeBuffer.buffer); 00095 pal_imageDeInit(); 00096 g_isTestDone = 1; 00097 break; 00098 default: 00099 PAL_PRINTF("Error - this should not happen\r\n"); 00100 PAL_PRINTF("Write ptr = %p read ptr = %p\r\n",g_writeBuffer.buffer,g_readBuffer.buffer); 00101 free(g_readBuffer.buffer); 00102 free(g_writeBuffer.buffer); 00103 pal_imageDeInit(); 00104 g_isTestDone = 1; 00105 } 00106 } 00107 00108 00109 00110 00111 00112 00113 void printBuffer(uint8_t* buffer, size_t bufSize) 00114 { 00115 size_t i = 0; 00116 PAL_PRINTF("0x"); 00117 for (i=0;i < bufSize;i++) 00118 { 00119 PAL_PRINTF("%x",buffer[i]); 00120 } 00121 PAL_PRINTF("\r\n"); 00122 } 00123 00124 00125 PAL_PRIVATE void fillBuffer(uint8_t* buffer, size_t bufSize) 00126 { 00127 size_t i = 0; 00128 uint8_t value = 0; 00129 int8_t step = -1; 00130 PAL_PRINTF("Filling buffer size %zu\r\n",bufSize); 00131 for(i=0; i < bufSize ; i++) 00132 { 00133 buffer[i] = value; 00134 if ((0 == value) || (255 == value)) 00135 { 00136 step*=-1; 00137 } 00138 value+=step; 00139 } 00140 PAL_PRINTF("Buffer is full\r\n"); 00141 00142 } 00143 00144 00145 TEST_TEAR_DOWN(pal_update) 00146 { 00147 } 00148 00149 00150 00151 void pal_update_xK(int sizeInK) 00152 { 00153 00154 palStatus_t rc = PAL_SUCCESS; 00155 if (!(sizeInK % KILOBYTE)) 00156 { 00157 PAL_PRINTF("\n-====== PAL_UPDATE_%dKb ======- \n",sizeInK / KILOBYTE); 00158 } 00159 else 00160 { 00161 PAL_PRINTF("\n-====== PAL_UPDATE_%db ======- \n",sizeInK); 00162 } 00163 uint8_t *writeData = (uint8_t*)malloc(sizeInK); 00164 uint8_t *readData = (uint8_t*)malloc(sizeInK); 00165 00166 TEST_ASSERT_TRUE(writeData != NULL); 00167 TEST_ASSERT_TRUE(readData != NULL); 00168 00169 uint64_t version = 11111111; 00170 uint32_t hash = 0x22222222; 00171 00172 g_isTestDone = 0; 00173 00174 g_imageHeader.version = version; 00175 00176 g_imageHeader.hash.buffer =(uint8_t*)&hash; 00177 g_imageHeader.hash.bufferLength = sizeof(hash); 00178 g_imageHeader.hash.maxBufferLength = sizeof(hash); 00179 00180 g_imageHeader.imageSize = sizeInK; 00181 00182 g_writeBuffer.buffer = writeData; 00183 g_writeBuffer.bufferLength = sizeInK; 00184 g_writeBuffer.maxBufferLength = sizeInK; 00185 00186 PAL_PRINTF("write buffer length %" PRIu32 " max length %" PRIu32 "\r\n",g_writeBuffer.bufferLength,g_writeBuffer.maxBufferLength); 00187 fillBuffer(g_writeBuffer.buffer,g_writeBuffer.bufferLength); 00188 00189 g_readBuffer.buffer = readData; 00190 g_readBuffer.maxBufferLength = sizeInK; 00191 00192 00193 rc =pal_imageInitAPI(stateAdvance); 00194 PAL_PRINTF("pal_imageInitAPI returned %" PRIu32 " \r\n",rc); 00195 TEST_ASSERT_TRUE(rc >= 0); 00196 00197 /*Wait until the async test finishes*/ 00198 while (!g_isTestDone) 00199 pal_osDelay(5); //Make the OS switch context 00200 00201 } 00202 00203 /*! \brief Writing a 1Kb image and verifying its value. 00204 * \test 00205 * This test simulates a state machine for writing and reading a 1Kb image. 00206 * 00207 * | # | Step | Expected | 00208 * |---|--------------------------------|-------------| 00209 * | 1 | Initialize the test. | Success | 00210 * | 2 | `pal_imagePrepare` | PAL_SUCCESS | 00211 * | 3 | `pal_imageWrite` | PAL_SUCCESS | 00212 * | 4 | `pal_imageFinalize` | PAL_SUCCESS | 00213 * | 5 | `pal_imageReadToBuffer` | PAL_SUCCESS | 00214 * | 6 | Compare the written image with the read image. | memcmp == 0 | 00215 */ 00216 00217 TEST(pal_update, pal_update_1k) 00218 { 00219 pal_update_xK(1*KILOBYTE); 00220 } 00221 00222 00223 /*! \brief Writing a 2Kb image and verifying its value. 00224 * \test 00225 * This test simulates a state machine for writing and reading a 2Kb image. 00226 * 00227 * | # | Step | Expected | 00228 * |---|--------------------------------|-------------| 00229 * | 1 | Initialize the test. | Success | 00230 * | 2 | `pal_imagePrepare` | PAL_SUCCESS | 00231 * | 3 | `pal_imageWrite` | PAL_SUCCESS | 00232 * | 4 | `pal_imageFinalize` | PAL_SUCCESS | 00233 * | 5 | `pal_imageReadToBuffer` | PAL_SUCCESS | 00234 * | 6 | Compare the written image with the read image. | memcmp == 0 | 00235 */ 00236 00237 TEST(pal_update, pal_update_2k) 00238 { 00239 pal_update_xK(2*KILOBYTE); 00240 } 00241 00242 /*! \brief Writing a 4Kb image and verifying its value. 00243 * \test 00244 * This test simulates a state machine for writing and reading a 4Kb image. 00245 * 00246 * | # | Step | Expected | 00247 * |---|--------------------------------|-------------| 00248 * | 1 | Initialize the test. | Success | 00249 * | 2 | `pal_imagePrepare` | PAL_SUCCESS | 00250 * | 3 | `pal_imageWrite` | PAL_SUCCESS | 00251 * | 4 | `pal_imageFinalize` | PAL_SUCCESS | 00252 * | 5 | `pal_imageReadToBuffer` | PAL_SUCCESS | 00253 * | 6 | Compare the written image with the read image. | memcmp == 0 | 00254 */ 00255 00256 TEST(pal_update, pal_update_4k) 00257 { 00258 pal_update_xK(4*KILOBYTE); 00259 } 00260 00261 /*! \brief Writing an 8Kb image and verifying its value. 00262 * \test 00263 * This test simulates a state machine for writing and reading an 8Kb image. 00264 * 00265 * | # | Step | Expected | 00266 * |---|--------------------------------|-------------| 00267 * | 1 | Initialize the test. | Success | 00268 * | 2 | `pal_imagePrepare` | PAL_SUCCESS | 00269 * | 3 | `pal_imageWrite` | PAL_SUCCESS | 00270 * | 4 | `pal_imageFinalize` | PAL_SUCCESS | 00271 * | 5 | `pal_imageReadToBuffer` | PAL_SUCCESS | 00272 * | 6 | Compare the written image with the read image. | memcmp == 0 | 00273 */ 00274 00275 TEST(pal_update, pal_update_8k) 00276 { 00277 pal_update_xK(8*KILOBYTE); 00278 } 00279 00280 /*! \brief Writing a 16Kb image and verifying its value. 00281 * \test 00282 * This test simulates a state machine for writing and reading a 16Kb image. 00283 * 00284 * | # | Step | Expected | 00285 * |---|--------------------------------|-------------| 00286 * | 1 | Initialize the test. | Success | 00287 * | 2 | `pal_imagePrepare` | PAL_SUCCESS | 00288 * | 3 | `pal_imageWrite` | PAL_SUCCESS | 00289 * | 4 | `pal_imageFinalize` | PAL_SUCCESS | 00290 * | 5 | `pal_imageReadToBuffer` | PAL_SUCCESS | 00291 * | 6 | Compare the written image with the read image. | memcmp == 0 | 00292 */ 00293 00294 TEST(pal_update, pal_update_16k) 00295 { 00296 pal_update_xK(16*KILOBYTE); 00297 } 00298 00299 00300 /*! \brief Writing a small image (5b) and verifying its value. 00301 * \test 00302 * This test simulates a state machine for writing and reading a 5b image. 00303 * 00304 * | # | Step | Expected | 00305 * |---|--------------------------------|-------------| 00306 * | 1 | Initialize the test. | Success | 00307 * | 2 | `pal_imagePrepare` | PAL_SUCCESS | 00308 * | 3 | `pal_imageWrite` | PAL_SUCCESS | 00309 * | 4 | `pal_imageFinalize` | PAL_SUCCESS | 00310 * | 5 | `pal_imageReadToBuffer` | PAL_SUCCESS | 00311 * | 6 | Compare the written image with the read image. | memcmp == 0 | 00312 */ 00313 00314 00315 TEST(pal_update,pal_update_writeSmallChunk_5b) 00316 { 00317 pal_update_xK(5); 00318 } 00319 00320 00321 /*! \brief Writing an unaligned image of 1001b and verifying its value. 00322 * \test 00323 * This test simulates a state machine for writing and reading a 51001b image. 00324 * 00325 * | # | Step | Expected | 00326 * |---|--------------------------------|-------------| 00327 * | 1 | Initialize the test. | Success | 00328 * | 2 | `pal_imagePrepare` | PAL_SUCCESS | 00329 * | 3 | `pal_imageWrite` | PAL_SUCCESS | 00330 * | 4 | `pal_imageFinalize` | PAL_SUCCESS | 00331 * | 5 | `pal_imageReadToBuffer` | PAL_SUCCESS | 00332 * | 6 | Compare the written image with the read image. | memcmp == 0 | 00333 */ 00334 00335 00336 TEST(pal_update,pal_update_writeUnaligned_1001b) 00337 { 00338 //1039 is a prime number so probably never aligned. 00339 pal_update_xK(1039); 00340 } 00341 00342 00343 00344 00345 PAL_PRIVATE void multiWriteMultiRead(palImageEvents_t state) 00346 { 00347 int rc = PAL_SUCCESS; 00348 static uint8_t counter = 0; 00349 static uint8_t *writeBase = NULL; 00350 static uint8_t *readBase = NULL; 00351 if (NULL == writeBase) 00352 { 00353 writeBase = g_writeBuffer.buffer; 00354 g_writeBuffer.maxBufferLength = g_writeBuffer.maxBufferLength/numberofBlocks; 00355 g_writeBuffer.bufferLength = g_writeBuffer.bufferLength/numberofBlocks; 00356 00357 readBase = g_readBuffer.buffer; 00358 g_readBuffer.maxBufferLength = g_readBuffer.maxBufferLength/numberofBlocks; 00359 } 00360 PAL_PRINTF("Finished event %d\r\n",state); 00361 if (PAL_IMAGE_EVENT_WRITE == state) // Just wrote data 00362 { 00363 counter++; 00364 if (numberofBlocks == counter) // Wrote all needed blocks 00365 { 00366 state++; // Advance to next state 00367 counter = 0; //Initialize counter 00368 } 00369 } 00370 else if (PAL_IMAGE_EVENT_READTOBUFFER == state) // Just read data 00371 { 00372 counter++ ; 00373 if (numberofBlocks == counter) // Read all needed blocks 00374 { 00375 state++; // Advance to next state 00376 counter = 0; 00377 } 00378 } 00379 else 00380 { 00381 state++; // Advance to next state 00382 } 00383 00384 PAL_PRINTF("Starting event %d\r\n",state); 00385 00386 switch (state) 00387 { 00388 case PAL_IMAGE_EVENT_PREPARE: 00389 rc = pal_imagePrepare(FIRST_IMAGE_INDEX, &g_imageHeader); 00390 PAL_PRINTF("pal_imagePrepare returned %d \r\n",rc); 00391 break; 00392 case PAL_IMAGE_EVENT_WRITE: 00393 PAL_PRINTF("Write KILOBYTE * %d = %d\r\n",counter,KILOBYTE*(counter)); 00394 g_writeBuffer.buffer = &writeBase[KILOBYTE*(counter)];// Writing 1k every time 00395 rc = pal_imageWrite(FIRST_IMAGE_INDEX, KILOBYTE*(counter),(palConstBuffer_t*)&g_writeBuffer); 00396 PAL_PRINTF("pal_imageWrite returned %d \r\n",rc); 00397 TEST_ASSERT_TRUE(rc >= 0); 00398 break; 00399 case PAL_IMAGE_EVENT_FINALIZE: 00400 rc = pal_imageFinalize(FIRST_IMAGE_INDEX); 00401 PAL_PRINTF("pal_imageFinalize returned %d \r\n",rc); 00402 TEST_ASSERT_TRUE(rc >= 0); 00403 break; 00404 case PAL_IMAGE_EVENT_READTOBUFFER: 00405 PAL_PRINTF("Read KILOBYTE * %d = %d\r\n",counter, KILOBYTE*(counter)); 00406 g_readBuffer.buffer = &readBase[KILOBYTE*(counter)];// Writing 1k every time 00407 g_readBuffer.bufferLength = 0; 00408 rc = pal_imageReadToBuffer(FIRST_IMAGE_INDEX, KILOBYTE*(counter),&g_readBuffer); 00409 PAL_PRINTF("pal_imageReadToBuffer with offset %d return %d \r\n",0,rc); 00410 break; 00411 case PAL_IMAGE_EVENT_ACTIVATE: 00412 00413 PAL_PRINTF("Checking the output\r\n"); 00414 00415 TEST_ASSERT_TRUE(rc >= 0); 00416 TEST_ASSERT_TRUE(!memcmp(readBase,writeBase,numberofBlocks*KILOBYTE)); 00417 free(writeBase); 00418 free(readBase); 00419 pal_imageDeInit(); 00420 g_isTestDone = 1; 00421 break; 00422 default: 00423 PAL_PRINTF("Error\r\n"); 00424 free(writeBase); 00425 free(readBase); 00426 pal_imageDeInit(); 00427 g_isTestDone = 1; 00428 break; 00429 } 00430 } 00431 00432 00433 /*! \brief Writing a 4Kb image and reading it with a 1Kb buffer. 00434 * \test 00435 * This test simulates a state machine for writing and reading a 4Kb image. 00436 * 00437 * | # | Step | Expected | 00438 * |---|--------------------------------|-------------| 00439 * | 1 | Initialize the test. | Success | 00440 * | 2 | `pal_imagePrepare` | PAL_SUCCESS | 00441 * | 3 | `pal_imageWrite` | PAL_SUCCESS | 00442 * | 4 | `pal_imageFinalize` | PAL_SUCCESS | 00443 * | 5 | `pal_imageReadToBuffer` | PAL_SUCCESS | 00444 * | 6 | Compare the written image with the read image. | memcmp == 0 | 00445 */ 00446 00447 TEST(pal_update, pal_update_4k_write_1k_4_times) 00448 { 00449 palStatus_t rc = PAL_SUCCESS; 00450 00451 uint8_t *writeData = (uint8_t*)malloc(4*KILOBYTE); 00452 uint8_t *readData = (uint8_t*)malloc(4*KILOBYTE); 00453 00454 00455 TEST_ASSERT_TRUE(writeData != NULL); 00456 TEST_ASSERT_TRUE(readData != NULL); 00457 00458 uint64_t version = 11111111; 00459 uint32_t hash = 0x22222222; 00460 g_isTestDone = 0; 00461 00462 g_imageHeader.version = version; 00463 00464 g_imageHeader.hash.buffer =(uint8_t*)&hash; 00465 g_imageHeader.hash.bufferLength = sizeof(hash); 00466 g_imageHeader.hash.maxBufferLength = sizeof(hash); 00467 00468 g_imageHeader.imageSize = 4*KILOBYTE; 00469 00470 fillBuffer(writeData,4*KILOBYTE); 00471 00472 g_writeBuffer.buffer = writeData; 00473 g_writeBuffer.bufferLength = 4*KILOBYTE; 00474 g_writeBuffer.maxBufferLength = 4*KILOBYTE; 00475 PAL_PRINTF("pal_update_4k"); 00476 PAL_PRINTF("Write buffer length %" PRIu32 " max length %" PRIu32 "\r\n",g_writeBuffer.bufferLength,g_writeBuffer.maxBufferLength); 00477 fillBuffer(g_writeBuffer.buffer,g_writeBuffer.bufferLength); 00478 00479 g_readBuffer.buffer = readData; 00480 g_readBuffer.maxBufferLength = 4*KILOBYTE; 00481 00482 numberofBlocks = 4; 00483 00484 rc = pal_imageInitAPI(multiWriteMultiRead); 00485 PAL_PRINTF("pal_imageInitAPI returned %" PRIu32 " \r\n",rc); 00486 TEST_ASSERT_TRUE(rc >= 0); 00487 /*Wait until the async test finishes*/ 00488 while (!g_isTestDone) 00489 pal_osDelay(5); // Make the OS switch context 00490 00491 } 00492 00493 /*! \brief Writing a different image with incrementing size. 00494 * \test 00495 * 00496 * | # | Step | Expected | 00497 * |---|--------------------------------|-------------| 00498 * | 1 | Initialize the test. | Success | 00499 * | 2 | `1kb_image` | Success | 00500 * | 3 | `2kb_image` | Success | 00501 * | 4 | `4kb_image` | Success | 00502 * | 5 | `8kb_image` | Success | 00503 * | 6 | `16kb_image` | Success | 00504 * | 7 | `32kb_image` | Success | 00505 */ 00506 TEST(pal_update, pal_update_stressTest) 00507 { 00508 uint8_t it,j; 00509 PAL_PRINTF("****************************************************\r\n"); 00510 PAL_PRINTF("******* Testing multiple writes sequentially *******\r\n"); 00511 PAL_PRINTF("****************************************************\r\n"); 00512 for (j=0; j < 5; j++) 00513 { 00514 PAL_PRINTF("1\r\n"); 00515 for (it = 1; it < 32; it*=2) 00516 { 00517 pal_update_xK(it*KILOBYTE); 00518 00519 } 00520 } 00521 } 00522 00523 00524 00525 00526 00527 00528 PAL_PRIVATE void readStateMachine(palImageEvents_t state) 00529 { 00530 static uint8_t *readData = NULL ; 00531 static uint32_t bytesWasRead = 0; 00532 int rc = PAL_SUCCESS; 00533 PAL_PRINTF("Finished event %d\r\n",state); 00534 /*If just finished reading*/ 00535 if (PAL_IMAGE_EVENT_READTOBUFFER == state) 00536 { 00537 PAL_PRINTF("g_readBuffer.bufferLength %" PRIu32 "\r\n",g_readBuffer.bufferLength); 00538 if (0 < g_readBuffer.bufferLength) 00539 { 00540 PAL_PRINTF("Writing %" PRIu32 " bytes to readData[%" PRIu32 "]\r\n",g_readBuffer.bufferLength,bytesWasRead); 00541 memcpy(&readData[bytesWasRead],g_readBuffer.buffer,g_readBuffer.bufferLength); 00542 bytesWasRead+=g_readBuffer.bufferLength; 00543 } 00544 else 00545 { 00546 state++; 00547 } 00548 } 00549 else 00550 { 00551 state++; 00552 } 00553 PAL_PRINTF("Starting event %d\r\n",state); 00554 switch (state) 00555 { 00556 case PAL_IMAGE_EVENT_PREPARE: 00557 bytesWasRead = 0; 00558 PAL_PRINTF("Allocating %" PRIu32 " byes for test \r\n",g_writeBuffer.maxBufferLength); 00559 readData = (uint8_t*)malloc(g_writeBuffer.maxBufferLength); 00560 TEST_ASSERT_TRUE(readData != NULL); 00561 rc = pal_imagePrepare(FIRST_IMAGE_INDEX,&g_imageHeader); 00562 PAL_PRINTF("pal_imagePrepare returned %d \r\n",rc); 00563 break; 00564 case PAL_IMAGE_EVENT_WRITE: 00565 rc = pal_imageWrite(FIRST_IMAGE_INDEX,0,(palConstBuffer_t*)&g_writeBuffer); 00566 PAL_PRINTF("pal_imageWrite returned %d \r\n",rc); 00567 TEST_ASSERT_TRUE(rc >= 0); 00568 break; 00569 case PAL_IMAGE_EVENT_FINALIZE: 00570 rc = pal_imageFinalize(FIRST_IMAGE_INDEX); 00571 PAL_PRINTF("pal_imageFinalize returned %d \r\n",rc); 00572 TEST_ASSERT_TRUE(rc >= 0); 00573 break; 00574 case PAL_IMAGE_EVENT_READTOBUFFER: 00575 g_readBuffer.bufferLength = 0; 00576 memset(g_readBuffer.buffer,0,g_readBuffer.maxBufferLength); 00577 rc = pal_imageReadToBuffer(FIRST_IMAGE_INDEX,bytesWasRead,&g_readBuffer); 00578 PAL_PRINTF("pal_imageReadToBuffer with offset %" PRIu32 " return %d \r\n",bytesWasRead,rc); 00579 //TEST_ASSERT_TRUE((rc >= 0) || (rc != -10)); 00580 break; 00581 case PAL_IMAGE_EVENT_ACTIVATE: 00582 PAL_PRINTF("Checking the output\r\n"); 00583 PAL_PRINTF("\r\ng_readBuffer bufferLength=%" PRIu32 "\r\n",g_readBuffer.maxBufferLength); 00584 TEST_ASSERT_TRUE(!memcmp(readData,g_writeBuffer.buffer,g_writeBuffer.bufferLength)); 00585 PAL_PRINTF("write ptr = %p read ptr = %p\r\n",g_writeBuffer.buffer,g_readBuffer.buffer); 00586 free(g_readBuffer.buffer); 00587 free(g_writeBuffer.buffer); 00588 free(readData); 00589 pal_imageDeInit(); 00590 g_isTestDone = 1; 00591 break; 00592 default: 00593 PAL_PRINTF("Error - this should not happen\r\n"); 00594 PAL_PRINTF("write ptr = %p read ptr = %p\r\n",g_writeBuffer.buffer,g_readBuffer.buffer); 00595 free(g_readBuffer.buffer); 00596 free(g_writeBuffer.buffer); 00597 free(readData); 00598 pal_imageDeInit(); 00599 g_isTestDone = 1; 00600 TEST_ASSERT_TRUE(rc >= 0); 00601 } 00602 } 00603 00604 00605 00606 /*! \brief Writing an image and verifying its value by multiple reads. 00607 * \test 00608 * This test simulates a state machine for writing and reading an image. 00609 * 00610 * | # | Step | Expected | 00611 * |---|--------------------------------|-------------| 00612 * | 1 | Initialize the test. | Success | 00613 * | 2 | `pal_imagePrepare` | PAL_SUCCESS | 00614 * | 3 | `pal_imageWrite` | PAL_SUCCESS | 00615 * | 4 | `pal_imageFinalize` | PAL_SUCCESS | 00616 * | 5 | `pal_imageReadToBuffer` | PAL_SUCCESS | 00617 * | 6 | Compare the written image with the read image. | memcmp == 0 | 00618 */ 00619 00620 TEST(pal_update, pal_update_Read) 00621 { 00622 uint32_t sizeIn=1500; 00623 palStatus_t rc = PAL_SUCCESS; 00624 PAL_PRINTF("\n-====== PAL_UPDATE_READ TEST %" PRIu32 " b ======- \n",sizeIn); 00625 uint8_t *writeData = (uint8_t*)malloc(sizeIn); 00626 uint8_t *readData = (uint8_t*)malloc(sizeIn/5); 00627 00628 TEST_ASSERT_TRUE(writeData != NULL); 00629 TEST_ASSERT_TRUE(readData != NULL); 00630 00631 uint64_t version = 11111111; 00632 uint32_t hash = 0x22222222; 00633 00634 g_isTestDone = 0; 00635 00636 g_imageHeader.version = version; 00637 00638 g_imageHeader.hash.buffer = (uint8_t*)&hash; 00639 g_imageHeader.hash.bufferLength = sizeof(hash); 00640 g_imageHeader.hash.maxBufferLength = sizeof(hash); 00641 00642 g_imageHeader.imageSize = sizeIn; 00643 00644 g_writeBuffer.buffer = writeData; 00645 g_writeBuffer.bufferLength = sizeIn; 00646 g_writeBuffer.maxBufferLength = sizeIn; 00647 00648 PAL_PRINTF("write buffer length %" PRIu32 " max length %" PRIu32 "\r\n",g_writeBuffer.bufferLength,g_writeBuffer.maxBufferLength); 00649 fillBuffer(g_writeBuffer.buffer,g_writeBuffer.bufferLength); 00650 00651 g_readBuffer.buffer = readData; 00652 g_readBuffer.maxBufferLength = sizeIn/5; 00653 g_readBuffer.bufferLength = 0; 00654 00655 rc =pal_imageInitAPI(readStateMachine); 00656 PAL_PRINTF("pal_imageInitAPI returned %" PRIu32 " \r\n",rc); 00657 TEST_ASSERT_TRUE(rc >= 0); 00658 00659 /*Wait until the async test finishes*/ 00660 while (!g_isTestDone) 00661 pal_osDelay(5); // Make the OS switch context 00662 00663 }
Generated on Tue Jul 12 2022 19:01:36 by 1.7.2