BA
/
BaBoRo1
Embed:
(wiki syntax)
Show/hide line numbers
cfstore_test.c
00001 /* @file cfstore_test.c 00002 * 00003 * mbed Microcontroller Library 00004 * Copyright (c) 2006-2016 ARM Limited 00005 * 00006 * Licensed under the Apache License, Version 2.0 (the "License"); 00007 * you may not use this file except in compliance with the License. 00008 * You may obtain a copy of the License at 00009 * 00010 * http://www.apache.org/licenses/LICENSE-2.0 00011 * 00012 * Unless required by applicable law or agreed to in writing, software 00013 * distributed under the License is distributed on an "AS IS" BASIS, 00014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00015 * See the License for the specific language governing permissions and 00016 * limitations under the License. 00017 * 00018 * test support code implementation file. 00019 */ 00020 00021 // This file is deprecated so deprecation warnings when building it are silenced 00022 #if defined ( __CC_ARM ) 00023 #pragma diag_suppress 1361 // Deprecated declaration 00024 #elif defined ( __GNUC__ ) 00025 #pragma GCC diagnostic ignored "-Wdeprecated-declarations" 00026 #endif 00027 00028 #include "cfstore_config.h" 00029 #include "cfstore_debug.h" 00030 #include "cfstore_test.h" 00031 #include "configuration_store.h" 00032 00033 #ifdef CFSTORE_CONFIG_BACKEND_FLASH_ENABLED 00034 #include "flash_journal_strategy_sequential.h" 00035 #include "flash_journal.h" 00036 #include "Driver_Common.h" 00037 #endif /* CFSTORE_CONFIG_BACKEND_FLASH_ENABLED */ 00038 00039 #include <stdio.h> 00040 #include <stdlib.h> 00041 #include <string.h> 00042 #include <assert.h> 00043 #include <inttypes.h> 00044 #include <ctype.h> 00045 00046 00047 /* ruler for measuring text strings */ 00048 /* 1 1 1 1 1 1 1 1 1 1 2 2 2 */ 00049 /* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 */ 00050 /* 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 */ 00051 00052 const uint8_t cfstore_test_byte_data_table[CFSTORE_TEST_BYTE_DATA_TABLE_SIZE] = { 00053 0x2d, 0xf3, 0x31, 0x4c, 0x11, 0x4f, 0xde, 0x0d, 0xbd, 0xbc, 0xa6, 0x78, 0x36, 0x5c, 0x1d, 0x28, 00054 0x5f, 0xa9, 0x10, 0x65, 0x54, 0x45, 0x21, 0x1a, 0x88, 0xfe, 0x76, 0x45, 0xb9, 0xac, 0x65, 0x9a, 00055 0x34, 0x9d, 0x73, 0x10, 0xb4, 0xa9, 0x2e, 0x90, 0x95, 0x68, 0xac, 0xfe, 0xc5, 0x2d, 0x15, 0x03, 00056 0x34, 0x70, 0xf1, 0x1d, 0x48, 0xa1, 0xa0, 0xed, 0x5c, 0x2f, 0xf5, 0x2b, 0xb9, 0x84, 0xbb, 0x45, 00057 0x32, 0xdd, 0xb1, 0x33, 0x95, 0x2a, 0xbc, 0x26, 0xf0, 0x89, 0xba, 0xf4, 0xbd, 0xf9, 0x5d, 0x2e, 00058 0x6e, 0x11, 0xc6, 0xa7, 0x78, 0xfc, 0xc9, 0x0e, 0x6b, 0x38, 0xba, 0x14, 0x1b, 0xab, 0x4c, 0x20, 00059 0x91, 0xe4, 0xb0, 0xf1, 0x2b, 0x14, 0x07, 0x6b, 0xb5, 0xcd, 0xe3, 0x49, 0x75, 0xac, 0xe8, 0x98, 00060 0xf1, 0x58, 0x8f, 0xd9, 0xc4, 0x8f, 0x00, 0x17, 0xb5, 0x06, 0x6a, 0x33, 0xbd, 0xa7, 0x40, 0x5a, 00061 0xbf, 0x49, 0xf7, 0x27, 0x1b, 0x4c, 0x3e, 0x6f, 0xe3, 0x08, 0x1f, 0xfd, 0xa6, 0xd4, 0xc7, 0x5f, 00062 0xa4, 0xa6, 0x82, 0xad, 0x19, 0xd5, 0x5c, 0xd8, 0x3a, 0x49, 0x85, 0xc9, 0x21, 0x83, 0xf6, 0xc6, 00063 0x84, 0xf9, 0x76, 0x89, 0xf3, 0x2d, 0x17, 0x50, 0x97, 0x38, 0x48, 0x9a, 0xe1, 0x82, 0xcd, 0xac, 00064 0xa8, 0x1d, 0xd7, 0x96, 0x5e, 0xb3, 0x08, 0xa8, 0x3a, 0xc7, 0x2b, 0x05, 0xaf, 0xdc, 0x16, 0xdf, 00065 0x48, 0x0f, 0x2a, 0x7e, 0x3a, 0x82, 0xd7, 0x80, 0xd6, 0x49, 0x27, 0x5d, 0xe3, 0x07, 0x62, 0xb3, 00066 0xc3, 0x6c, 0xba, 0xb2, 0xaa, 0x9f, 0xd9, 0x03, 0x0d, 0x27, 0xa8, 0xe0, 0xd6, 0xee, 0x79, 0x4b, 00067 0xd6, 0x97, 0x99, 0xb7, 0x11, 0xd6, 0x0d, 0x34, 0xae, 0x99, 0x4a, 0x93, 0x95, 0xd0, 0x5a, 0x34, 00068 0x19, 0xa2, 0x69, 0x57, 0xcf, 0x7c, 0x3d, 0x98, 0x88, 0x5d, 0x04, 0xf2, 0xd7, 0xac, 0xa5, 0x63 00069 }; 00070 00071 00072 /* @brief set of test data for sequential write tests */ 00073 cfstore_test_rw_data_entry_t cfstore_test_rw_data_table[] = 00074 { 00075 { 25, 'z' }, 00076 { 00, 'a' }, 00077 { 24, 'y' }, 00078 { 01, 'b' }, 00079 { 23, 'x' }, 00080 { 02, 'c' }, 00081 { 22, 'w' }, 00082 { 03, 'd' }, 00083 { 21, 'v' }, 00084 { 04, 'e' }, 00085 { 20, 'u' }, 00086 { 05, 'f' }, 00087 { 19, 't' }, 00088 { 06, 'g' }, 00089 { 18, 's' }, 00090 { 07, 'h' }, 00091 { 17, 'r' }, 00092 { 8, 'i' }, 00093 { 16, 'q' }, 00094 { 9, 'j' }, 00095 { 15, 'p' }, 00096 { 10, 'k' }, 00097 { 14, 'o' }, 00098 { 11, 'l' }, 00099 { 13, 'n' }, 00100 { 12, 'm' }, 00101 { CFSTORE_TEST_RW_TABLE_SENTINEL, '@' }, 00102 }; 00103 00104 const char* cfstore_test_opcode_str[] = 00105 { 00106 "UNDEFINED", 00107 "CFSTORE_OPCODE_CLOSE", 00108 "CFSTORE_OPCODE_CREATE", 00109 "CFSTORE_OPCODE_DELETE", 00110 "CFSTORE_OPCODE_FIND", 00111 "CFSTORE_OPCODE_FLUSH", 00112 "CFSTORE_OPCODE_GET_KEY_NAME", 00113 "CFSTORE_OPCODE_GET_STATUS", 00114 "CFSTORE_OPCODE_GET_VALUE_LEN", 00115 "CFSTORE_OPCODE_INITIALIZE", 00116 "CFSTORE_OPCODE_OPEN", 00117 "CFSTORE_OPCODE_POWER_CONTROL", 00118 "CFSTORE_OPCODE_READ", 00119 "CFSTORE_OPCODE_RSEEK", 00120 "CFSTORE_OPCODE_UNINITIALIZE", 00121 "CFSTORE_OPCODE_WRITE", 00122 "CFSTORE_OPCODE_MAX" 00123 }; 00124 00125 00126 static int32_t cfstore_test_dump_print_array(const char* data, ARM_CFSTORE_SIZE len) 00127 { 00128 int i; 00129 char buf[80]; 00130 char sbuf[80]; 00131 char* outbuf = buf; 00132 char* soutbuf = sbuf; 00133 00134 memset(outbuf, 0, 80); 00135 memset(soutbuf, 0, 80); 00136 outbuf += sprintf(outbuf, " "); 00137 soutbuf += sprintf(soutbuf, " "); 00138 for (i = 0; i < (int) len; i++){ 00139 outbuf += sprintf(outbuf, "%02X ", data[i]); 00140 00141 if( !(isalnum( (int) data[i]) || ispunct( (int) data[i])) ){ 00142 *soutbuf++ = '*'; 00143 } else { 00144 *soutbuf++ = data[i]; 00145 } 00146 00147 if( (i % 16 == 0) && i > 0){ 00148 CFSTORE_LOG("%s", buf); 00149 CFSTORE_LOG("%s\n", sbuf); 00150 outbuf = buf; 00151 soutbuf = sbuf; 00152 memset(outbuf, 0, 80); 00153 memset(soutbuf, 0, 80); 00154 outbuf += sprintf(outbuf, " "); 00155 soutbuf += sprintf(soutbuf, " "); 00156 } 00157 } 00158 if(i % 16){ 00159 /* Pad the end of the string to align string data. */ 00160 while(i % 16){ 00161 outbuf += sprintf(outbuf, " "); 00162 i++; 00163 } 00164 CFSTORE_LOG("%s", buf); 00165 CFSTORE_LOG(" %s", sbuf); 00166 } 00167 CFSTORE_LOG("%s", "\n"); 00168 return ARM_DRIVER_OK; 00169 } 00170 00171 00172 /* @brief function to dump contents of cfstore 00173 */ 00174 int32_t cfstore_test_dump(void) 00175 { 00176 const char* key_name_query = "*"; 00177 char* read_buf = NULL; 00178 char key_name[CFSTORE_KEY_NAME_MAX_LENGTH+1]; 00179 uint8_t len = CFSTORE_KEY_NAME_MAX_LENGTH+1; 00180 ARM_CFSTORE_SIZE vlen = 0; 00181 int32_t ret = ARM_DRIVER_ERROR; 00182 ARM_CFSTORE_DRIVER* drv = &cfstore_driver; 00183 ARM_CFSTORE_HANDLE_INIT(next); 00184 ARM_CFSTORE_HANDLE_INIT(prev); 00185 ARM_CFSTORE_CAPABILITIES caps = cfstore_driver.GetCapabilities(); 00186 00187 CFSTORE_FENTRYLOG("%s:entered\n", __func__); 00188 00189 CFSTORE_LOG("CFSTORE Flash Entries%s", "\n"); 00190 CFSTORE_LOG("=====================%s", "\n\n"); 00191 while((ret = drv->Find(key_name_query, prev, next)) == ARM_DRIVER_OK) 00192 { 00193 len = CFSTORE_KEY_NAME_MAX_LENGTH+1; 00194 ret = drv->GetKeyName(next, key_name, &len); 00195 if(ret < ARM_DRIVER_OK){ 00196 CFSTORE_ERRLOG("Error: failed to get key name%s", "\n"); 00197 break; 00198 } 00199 ret = drv->GetValueLen(next, &vlen); 00200 if(ret < ARM_DRIVER_OK){ 00201 CFSTORE_ERRLOG("Error: failed to get value length%s", "\n"); 00202 break; 00203 } 00204 read_buf = (char*) malloc(vlen+1); 00205 if(read_buf == NULL){ 00206 CFSTORE_ERRLOG("Error: failed to malloc() read buffer%s", "\n"); 00207 break; 00208 } 00209 ret = drv->Read(next, read_buf, &vlen); 00210 if(ret < ARM_DRIVER_OK){ 00211 CFSTORE_ERRLOG("Error: failed to read key value%s", "\n"); 00212 free(read_buf); 00213 break; 00214 } 00215 CFSTORE_LOG(" keyname : %s\n", key_name); 00216 CFSTORE_LOG(" name len : %d\n", (int) len); 00217 CFSTORE_LOG(" value len : %d\n", (int) vlen); 00218 CFSTORE_LOG(" data :%s", "\n"); 00219 cfstore_test_dump_print_array((const char*) read_buf, vlen); 00220 CFSTORE_LOG("%s", ".\n"); 00221 free(read_buf); 00222 CFSTORE_HANDLE_SWAP(prev, next); 00223 } 00224 CFSTORE_LOG("%s", ".\n"); 00225 CFSTORE_LOG(" caps.asynchronous_ops : %d\n", (int) caps.asynchronous_ops); 00226 CFSTORE_LOG("%s", ".\n"); 00227 CFSTORE_LOG("== End ==============%s", "\n\n"); 00228 00229 if(ret == ARM_CFSTORE_DRIVER_ERROR_KEY_NOT_FOUND) { 00230 /* As expected, no more keys have been found by the Find(). */ 00231 ret = ARM_DRIVER_OK; 00232 } 00233 return ret; 00234 } 00235 00236 00237 /* @brief test startup code to reset flash 00238 */ 00239 int32_t cfstore_test_startup(void) 00240 { 00241 int32_t ret = ARM_DRIVER_ERROR; 00242 ARM_CFSTORE_DRIVER* cfstore_drv = &cfstore_driver; 00243 ARM_CFSTORE_CAPABILITIES caps = cfstore_driver.GetCapabilities(); 00244 00245 CFSTORE_LOG("INITIALIZING: caps.asynchronous_ops=%d\n", (int) caps.asynchronous_ops); 00246 00247 /* Dump contents of CFSTORE */ 00248 ret = cfstore_drv->Initialize(NULL, NULL); 00249 if(ret < ARM_DRIVER_OK){ 00250 CFSTORE_ERRLOG("%s:Error: failed to initialize CFSTORE (ret=%d)\n", __func__, (int) ret); 00251 return ARM_DRIVER_ERROR; 00252 } 00253 ret = cfstore_test_dump(); 00254 if(ret < ARM_DRIVER_OK){ 00255 CFSTORE_ERRLOG("%s:Error: failed to dump CFSTORE (ret=%d)\n", __func__, (int) ret); 00256 return ARM_DRIVER_ERROR; 00257 } 00258 ret = cfstore_drv->Uninitialize(); 00259 if(ret < ARM_DRIVER_OK){ 00260 CFSTORE_ERRLOG("%s:Error: failed to uninitialize CFSTORE (ret=%d)\n", __func__, (int) ret); 00261 return ARM_DRIVER_ERROR; 00262 } 00263 00264 #ifdef CFSTORE_CONFIG_BACKEND_FLASH_ENABLED 00265 00266 static FlashJournal_t jrnl; 00267 extern ARM_DRIVER_STORAGE ARM_Driver_Storage_MTD_K64F; 00268 const ARM_DRIVER_STORAGE *drv = &ARM_Driver_Storage_MTD_K64F; 00269 00270 ret = FlashJournal_initialize(&jrnl, drv, &FLASH_JOURNAL_STRATEGY_SEQUENTIAL, NULL); 00271 if(ret < JOURNAL_STATUS_OK){ 00272 CFSTORE_ERRLOG("%s:Error: failed to initialize flash journaling layer (ret=%d)\n", __func__, (int) ret); 00273 return ARM_DRIVER_ERROR; 00274 } 00275 ret = FlashJournal_reset(&jrnl); 00276 if(ret < JOURNAL_STATUS_OK){ 00277 CFSTORE_ERRLOG("%s:Error: failed to reset flash journal (ret=%d)\n", __func__, (int) ret); 00278 return ARM_DRIVER_ERROR; 00279 } 00280 00281 #endif /* CFSTORE_CONFIG_BACKEND_FLASH_ENABLED */ 00282 00283 return ARM_DRIVER_OK; 00284 } 00285 00286 00287 /* @brief test utility function to check a node appears correctly in the cfstore 00288 * @note this function expects cfstore to have been initialised with 00289 * a call to ARM_CFSTORE_DRIVER::Initialize() 00290 */ 00291 int32_t cfstore_test_check_node_correct(const cfstore_kv_data_t* node) 00292 { 00293 char* read_buf; 00294 int32_t ret = ARM_DRIVER_ERROR; 00295 ARM_CFSTORE_SIZE len = 0; 00296 ARM_CFSTORE_DRIVER* drv = &cfstore_driver; 00297 ARM_CFSTORE_HANDLE_INIT(hkey); 00298 ARM_CFSTORE_FMODE flags; 00299 00300 CFSTORE_FENTRYLOG("%s:entered\r\n", __func__); 00301 memset(&flags, 0, sizeof(flags)); 00302 00303 ret = drv->Open(node->key_name, flags, hkey); 00304 if(ret < ARM_DRIVER_OK){ 00305 CFSTORE_ERRLOG("%s:Error: failed to open node (key_name=\"%s\", value=\"%s\")(ret=%d)\r\n", __func__, node->key_name, node->value, (int) ret); 00306 goto out0; 00307 } 00308 len = strlen(node->value) + 1; 00309 read_buf = (char*) malloc(len); 00310 if(read_buf == NULL) { 00311 CFSTORE_ERRLOG("%s:Error: failed to allocated read buffer \r\n", __func__); 00312 goto out1; 00313 } 00314 memset(read_buf, 0, len); 00315 ret = drv->Read(hkey, read_buf, &len); 00316 if(ret < ARM_DRIVER_OK){ 00317 CFSTORE_ERRLOG("%s:Error: failed to write key (key_name=\"%s\", value=\"%s\")\r\n", __func__, node->key_name, node->value); 00318 goto out2; 00319 } 00320 /* check read data is as expected */ 00321 if(strncmp(read_buf, node->value, strlen(node->value)) != 0){ 00322 CFSTORE_ERRLOG("%s:Error: read value data (%s) != KV value data (key_name=\"%s\", value=\"%s\")\r\n", __func__, read_buf, node->key_name, node->value); 00323 ret = ARM_DRIVER_ERROR; 00324 } 00325 out2: 00326 if(read_buf) free(read_buf); 00327 out1: 00328 drv->Close(hkey); 00329 hkey = NULL; 00330 out0: 00331 return ret; 00332 } 00333 00334 00335 /* @brief test utility function to delete the cfstore key identified by key_name 00336 * @note this function expects cfstore to have been initialised with 00337 * a call to ARM_CFSTORE_DRIVER::Initialize() 00338 */ 00339 int32_t cfstore_test_delete(const char* key_name) 00340 { 00341 int32_t ret = ARM_DRIVER_ERROR; 00342 ARM_CFSTORE_DRIVER* drv = &cfstore_driver; 00343 ARM_CFSTORE_HANDLE_INIT(hkey); 00344 ARM_CFSTORE_FMODE flags; 00345 00346 CFSTORE_FENTRYLOG("%s:entered.\r\n", __func__); 00347 memset(&flags, 0, sizeof(flags)); 00348 ret = drv->Open(key_name, flags, hkey); 00349 if(ret < ARM_DRIVER_OK){ 00350 return ret; 00351 } 00352 if(hkey != NULL){ 00353 ret = drv->Delete(hkey); 00354 drv->Close(hkey); 00355 } 00356 return ret; 00357 } 00358 00359 /* @brief test utility function to delete all of the KVs in the cfstore 00360 * @note this function expects cfstore to have been initialised with 00361 * a call to ARM_CFSTORE_DRIVER::Initialize() 00362 */ 00363 int32_t cfstore_test_delete_all(void) 00364 { 00365 const char* key_name_query = "*"; 00366 char key_name[CFSTORE_KEY_NAME_MAX_LENGTH+1]; 00367 uint8_t len = CFSTORE_KEY_NAME_MAX_LENGTH+1; 00368 int32_t ret = ARM_DRIVER_ERROR; 00369 ARM_CFSTORE_DRIVER* drv = &cfstore_driver; 00370 ARM_CFSTORE_HANDLE_INIT(next); 00371 ARM_CFSTORE_HANDLE_INIT(prev); 00372 00373 CFSTORE_FENTRYLOG("%s:entered.\r\n", __func__); 00374 while((ret = drv->Find(key_name_query, prev, next)) == ARM_DRIVER_OK) 00375 { 00376 len = CFSTORE_KEY_NAME_MAX_LENGTH+1; 00377 drv->GetKeyName(next, key_name, &len); 00378 CFSTORE_TP(CFSTORE_TP_DELETE, "%s:deleting key_name=%s, len=%d\r\n", __func__, key_name, (int) len); 00379 ret = drv->Delete(next); 00380 if(ret < ARM_DRIVER_OK){ 00381 CFSTORE_ERRLOG("%s:Error: failed to delete key_name=%s, len=%d\r\n", __func__, key_name, (int) len); 00382 return ret; 00383 } 00384 CFSTORE_HANDLE_SWAP(prev, next); 00385 } 00386 if(ret == ARM_CFSTORE_DRIVER_ERROR_KEY_NOT_FOUND) { 00387 /* as expected, no more keys have been found by the Find()*/ 00388 ret = ARM_DRIVER_OK; 00389 } 00390 CFSTORE_FENTRYLOG("%s:exiting (ret=%d).\r\n", __func__, (int) ret); 00391 return ret; 00392 } 00393 00394 00395 /* @brief test utility function to create a KV in the cfstore 00396 * @note this function expects cfstore to have been initialised with 00397 * a call to ARM_CFSTORE_DRIVER::Initialize() 00398 */ 00399 int32_t cfstore_test_create(const char* key_name, const char* data, ARM_CFSTORE_SIZE* len, ARM_CFSTORE_KEYDESC* kdesc) 00400 { 00401 int32_t ret = ARM_DRIVER_ERROR; 00402 ARM_CFSTORE_SIZE value_len = 0; 00403 ARM_CFSTORE_DRIVER* drv = &cfstore_driver; 00404 ARM_CFSTORE_HANDLE_INIT(hkey); 00405 00406 CFSTORE_FENTRYLOG("%s:entered.\r\n", __func__); 00407 value_len = *len; 00408 kdesc->drl = ARM_RETENTION_WHILE_DEVICE_ACTIVE; 00409 ret = drv->Create(key_name, value_len, kdesc, hkey); 00410 if(ret < ARM_DRIVER_OK){ 00411 return ret; 00412 } 00413 value_len = *len; 00414 ret = drv->Write(hkey, data, &value_len); 00415 if(ret < ARM_DRIVER_OK){ 00416 drv->Close(hkey); 00417 return ret; 00418 } 00419 if(value_len != *len){ 00420 drv->Close(hkey); 00421 return ARM_DRIVER_ERROR; 00422 } 00423 drv->Close(hkey); 00424 return ret; 00425 } 00426 00427 /* @brief test utility function to create KVs from the supplied table 00428 * @note this function expects cfstore to have been initialised with 00429 * a call to ARM_CFSTORE_DRIVER::Initialize() 00430 */ 00431 int32_t cfstore_test_create_table(const cfstore_kv_data_t* table) 00432 { 00433 int32_t ret = ARM_DRIVER_ERROR; 00434 ARM_CFSTORE_SIZE len = 0; 00435 cfstore_kv_data_t* node = NULL; 00436 ARM_CFSTORE_KEYDESC kdesc; 00437 00438 (void) node; /* suppresses warning when building release */ 00439 CFSTORE_FENTRYLOG("%s:entered.\r\n", __func__); 00440 memset(&kdesc, 0, sizeof(kdesc)); 00441 kdesc.drl = ARM_RETENTION_WHILE_DEVICE_ACTIVE; 00442 while(table->key_name != NULL) 00443 { 00444 len = strlen(table->value); 00445 ret = cfstore_test_create(table->key_name, table->value, &len, &kdesc); 00446 if(ret < ARM_DRIVER_OK){ 00447 CFSTORE_ERRLOG("%s:Error: failed to create node (key_name=\"%s\", value=\"%s\")\r\n", __func__, node->key_name, node->value); 00448 return ret; 00449 } 00450 table++; 00451 } 00452 return ret; 00453 } 00454 00455 cfstore_kv_data_t cfstore_test_init_1_data[] = { 00456 CFSTORE_INIT_1_TABLE_HEAD, 00457 { "b", "1"}, 00458 { "c", "12"}, 00459 { "d", "123"}, 00460 { "e", "1234"}, 00461 { "g", "12345"}, 00462 { "h", "123456"}, 00463 { "i", "1234567"}, 00464 { "j", "12345678"}, 00465 { "k", "123456789"}, 00466 { "l", "1234567890"}, 00467 { "m", "12345678901"}, 00468 { "n", "123456789012"}, 00469 { "o", "1234567890123"}, 00470 { "p", "12345678901234"}, 00471 { "q", "123456789012345"}, 00472 { "r", "1234567890123456"}, 00473 { "0", "a"}, 00474 { "01", "ab"}, 00475 { "012", "abc"}, 00476 { "0123", "abcd"}, 00477 { "01234", "abcde"}, 00478 { "012345", "abcdef"}, 00479 { "0123456", "abcdefg"}, 00480 { "01234567", "abcdefgh"}, 00481 { "012345678", "abcdefghi"}, 00482 { "0123456789", "abcdefghj"}, 00483 { "0123456789a", "abcdefghjk"}, 00484 { "0123456789ab", "abcdefghjkl"}, 00485 { "0123456789abc", "abcdefghjklm"}, 00486 { "0123456789abcd", "abcdefghjklmn"}, 00487 { "0123456789abcde", "abcdefghjklmno"}, 00488 { "0123456789abcdef", "abcdefghjklmnop"}, 00489 { "0123456789abcdef0", "abcdefghjklmnopq"}, 00490 { "0123456789abcdef01", "abcdefghjklmnopqr"}, 00491 { "0123456789abcdef012", "abcdefghjklmnopqrs"}, 00492 { "0123456789abcdef0123", "abcdefghjklmnopqrst"}, 00493 { "0123456789abcdef01234", "abcdefghjklmnopqrstu"}, 00494 { "0123456789abcdef012345", "abcdefghjklmnopqrstuv"}, 00495 CFSTORE_INIT_1_TABLE_MID_NODE, 00496 { "0123456789abcdef01234567", "abcdefghjklmnopqrstuvwx"}, 00497 { "0123456789abcdef012345678", "abcdefghjklmnopqrstuvwxy"}, 00498 { "0123456789abcdef0123456789", "abcdefghjklmnopqrstuvwxyz"}, 00499 { "0123456789abcdef0123456789a", "b"}, 00500 { "0123456789abcdef0123456789ab", "c"}, 00501 { "0123456789abcdef0123456789abc", "d"}, 00502 { "0123456789abcdef0123456789abcd", "e"}, 00503 { "0123456789abcdef0123456789abcde", "f"}, 00504 { "0123456789abcdef0123456789abcdef", "g"}, 00505 { "com.arm.mbed.wifi.accesspoint.essid", ""}, 00506 { "com.arm.mbed.wifi.accesspoint.essid2", ""}, 00507 { "yotta.your-yotta-registry-module-name.module1", ""}, 00508 { "yotta.hello-world.animal{wobbly-dog}{foot}frontLeft", "missing"}, 00509 { "yotta.hello-world.animal{wobbly-dog}{foot}frontRight", "present"}, 00510 { "yotta.hello-world.animal{wobbly-dog}{foot}backLeft", "half present"}, 00511 { "piety.demands.us.to.honour.truth.above.our.friends", "Aristotle"}, 00512 { "basement.medicine.pavement.government.trenchcoat.off.cough.off.kid.did.when.again.alleyway.friend.cap.pen.dollarbills.ten.foot.soot.put.but.anyway.say.May.DA.kid.did.toes.bows.those.hose.nose.clothes.man.blows.well.well", "TheRollingStone" }, 00513 CFSTORE_INIT_1_TABLE_TAIL, 00514 { NULL, NULL}, 00515 }; 00516 00517 00518 /* @brief utility test function to initialise cfstore sram area with some 00519 * KV's to manipulate 00520 * @note this function expects cfstore to have been initialised with 00521 * a call to ARM_CFSTORE_DRIVER::Initialize() 00522 */ 00523 int32_t cfstore_test_init_1(void) 00524 { 00525 char* read_buf = NULL; 00526 const uint8_t key_name_max_len = CFSTORE_KEY_NAME_MAX_LENGTH+1; 00527 uint8_t key_name_len = 0; 00528 char key_name_buf[CFSTORE_KEY_NAME_MAX_LENGTH+1]; 00529 int32_t ret = ARM_DRIVER_ERROR; 00530 ARM_CFSTORE_SIZE len = 0; 00531 ARM_CFSTORE_SIZE max_len = 0; 00532 ARM_CFSTORE_DRIVER* drv = &cfstore_driver; 00533 cfstore_kv_data_t* node = NULL; 00534 ARM_CFSTORE_KEYDESC kdesc; 00535 ARM_CFSTORE_HANDLE_INIT(hkey); 00536 00537 CFSTORE_FENTRYLOG("%s:entered\r\n", __func__); 00538 memset(&kdesc, 0, sizeof(kdesc)); 00539 memset(key_name_buf, 0, CFSTORE_KEY_NAME_MAX_LENGTH+1); 00540 00541 /*scan for max length of value blob*/ 00542 node = cfstore_test_init_1_data; 00543 while(node->key_name != NULL) 00544 { 00545 len = strlen(node->value); 00546 if(len > max_len){ 00547 max_len = len; 00548 max_len++; 00549 } 00550 node++; 00551 } 00552 read_buf = (char*) malloc(max_len); 00553 if(read_buf == NULL) { 00554 CFSTORE_ERRLOG("%s:Error: failed to allocated read buffer \r\n", __func__); 00555 return ret; 00556 } 00557 kdesc.drl = ARM_RETENTION_WHILE_DEVICE_ACTIVE; 00558 node = cfstore_test_init_1_data; 00559 while(node->key_name != NULL) 00560 { 00561 CFSTORE_DBGLOG("%s:About to create new node (key_name=\"%s\", value=\"%s\")\r\n", __func__, node->key_name, node->value); 00562 ret = drv->Create(node->key_name, strlen(node->value), &kdesc, hkey); 00563 if(ret < ARM_DRIVER_OK){ 00564 CFSTORE_ERRLOG("%s:Error: failed to create node (key_name=\"%s\", value=\"%s\")\r\n", __func__, node->key_name, node->value); 00565 return ret; 00566 } 00567 00568 CFSTORE_DBGLOG("%s:length of KV=%d (key_name=\"%s\", value=\"%s\")\r\n", __func__, (int) len, node->key_name, node->value); 00569 len = strlen(node->value); 00570 ret = drv->Write(hkey, (char*) node->value, &len); 00571 if(ret < ARM_DRIVER_OK){ 00572 CFSTORE_ERRLOG("%s:Error: failed to write key (key_name=\"%s\", value=\"%s\")\r\n", __func__, node->key_name, node->value); 00573 drv->Close(hkey); 00574 return ret; 00575 } 00576 if(len != strlen(node->value)){ 00577 CFSTORE_ERRLOG("%s:Error: failed to write full value data (key_name=\"%s\", value=\"%s\"), len=%d\r\n", __func__, node->key_name, node->value, (int) len); 00578 drv->Close(hkey); 00579 return ARM_DRIVER_ERROR; 00580 } 00581 /* read the data back*/ 00582 len = strlen(node->value); 00583 memset(read_buf, 0, max_len); 00584 ret = drv->Read(hkey, read_buf, &len); 00585 if(ret < ARM_DRIVER_OK){ 00586 CFSTORE_ERRLOG("%s:Error: failed to read key (key_name=\"%s\", value=\"%s\")\r\n", __func__, node->key_name, node->value); 00587 drv->Close(hkey); 00588 return ret; 00589 } 00590 if(len != strlen(node->value)){ 00591 CFSTORE_ERRLOG("%s:Error: failed to read full value data (key_name=\"%s\", value=\"%s\"), len=%d, ret=%d\r\n", __func__, node->key_name, node->value, (int) len, (int) ret); 00592 drv->Close(hkey); 00593 return ARM_DRIVER_ERROR; 00594 } 00595 key_name_len = key_name_max_len; 00596 memset(key_name_buf, 0, key_name_len); 00597 drv->GetKeyName(hkey, key_name_buf, &key_name_len); 00598 if(len != strlen(node->value)){ 00599 CFSTORE_ERRLOG("%s:Error: failed to GetKeyName() (key_name=\"%s\", value=\"%s\"), len=%d\r\n", __func__, node->key_name, node->value, (int) len); 00600 drv->Close(hkey); 00601 return ARM_DRIVER_ERROR; 00602 } 00603 /* revert CFSTORE_LOG for more trace */ 00604 CFSTORE_DBGLOG("Created KV successfully (key_name=\"%s\", value=\"%s\")\r\n", key_name_buf, read_buf); 00605 drv->Close(hkey); 00606 node++; 00607 } 00608 free(read_buf); 00609 return ret; 00610 } 00611 00612 /* @brief test utility function to check a particular KV exists in the 00613 * cfstore using Find() interface 00614 * @note this function expects cfstore to have been initialised with 00615 * a call to ARM_CFSTORE_DRIVER::Initialize() 00616 */ 00617 int32_t cfstore_test_kv_is_found(const char* key_name, bool* bfound) 00618 { 00619 CFSTORE_FENTRYLOG("%s:entered.\r\n", __func__); 00620 int32_t ret = ARM_DRIVER_ERROR; 00621 ARM_CFSTORE_HANDLE_INIT(prev); 00622 ARM_CFSTORE_HANDLE_INIT(next); 00623 ARM_CFSTORE_DRIVER* drv = &cfstore_driver; 00624 00625 CFSTORE_ASSERT(bfound != NULL); 00626 CFSTORE_ASSERT(key_name != NULL); 00627 *bfound = 0; 00628 00629 ret = drv->Find(key_name, prev, next); 00630 if(ret == ARM_DRIVER_OK){ 00631 *bfound = 1; 00632 CFSTORE_DBGLOG("%s:Found key_name=\"%s\", about to call close.\r\n", __func__, key_name); 00633 drv->Close(next); 00634 } 00635 return ret; 00636 } 00637 00638 00639 /* @brief support function for generating a kv_name 00640 * @param name buffer to hold kv name 00641 * @param len length of kv name to generate 00642 * @note braces are not included in the generated names as the names are 00643 * of varible length and theyre may be unmatched 00644 * 00645 */ 00646 #define CFSTORE_TEST_KV_NAME_BUF_MAX_DATA (10+26+26+4) 00647 int32_t cfstore_test_kv_name_gen(char* name, const size_t len) 00648 { 00649 size_t i; 00650 const char buf[CFSTORE_TEST_KV_NAME_BUF_MAX_DATA+1] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-_@"; 00651 CFSTORE_FENTRYLOG("%s:entered\n", __func__); 00652 for(i = 0; i < len; i++) 00653 { 00654 name[i] = buf[i % CFSTORE_TEST_KV_NAME_BUF_MAX_DATA]; 00655 } 00656 return ARM_DRIVER_OK; 00657 } 00658 00659 /* @brief test utility function to read the value blob of a specified KV 00660 * @note this function expects cfstore to have been initialised with 00661 * a call to ARM_CFSTORE_DRIVER::Initialize() 00662 */ 00663 int32_t cfstore_test_read(const char* key_name, char* data, ARM_CFSTORE_SIZE* len) 00664 { 00665 int32_t ret = ARM_DRIVER_ERROR; 00666 ARM_CFSTORE_DRIVER* drv = &cfstore_driver; 00667 ARM_CFSTORE_HANDLE_INIT(hkey); 00668 ARM_CFSTORE_FMODE flags; 00669 00670 CFSTORE_FENTRYLOG("%s:entered\r\n", __func__); 00671 memset(&flags, 0, sizeof(flags)); 00672 if(key_name == NULL) { 00673 CFSTORE_ERRLOG("%s:invalid key_name argument \r\n", __func__); 00674 goto out0; 00675 } 00676 if(data == NULL) { 00677 CFSTORE_ERRLOG("%s:invalid data argument \r\n", __func__); 00678 goto out0; 00679 } 00680 if(len == NULL) { 00681 CFSTORE_ERRLOG("%s:invalid len argument \r\n", __func__); 00682 goto out0; 00683 } 00684 ret = drv->Open(key_name, flags, hkey); 00685 if(ret < ARM_DRIVER_OK){ 00686 CFSTORE_ERRLOG("%s:Error: failed to open node (key_name=\"%s\")(ret=%d)\r\n", __func__, key_name, (int) ret); 00687 goto out1; 00688 } 00689 ret = drv->Read(hkey, data, len); 00690 if(ret < ARM_DRIVER_OK){ 00691 CFSTORE_ERRLOG("%s:Error: failed to read key (key_name=\"%s\"\r\n", __func__, key_name); 00692 goto out2; 00693 } 00694 out2: 00695 drv->Close(hkey); 00696 out1: 00697 out0: 00698 return ret; 00699 } 00700 00701 /* @brief write the value blob of a specified KV 00702 * @note this function expects cfstore to have been initialised with 00703 * a call to ARM_CFSTORE_DRIVER::Initialize() 00704 */ 00705 int32_t cfstore_test_write(const char* key_name, const char* data, ARM_CFSTORE_SIZE* len) 00706 { 00707 int32_t ret = ARM_DRIVER_ERROR; 00708 ARM_CFSTORE_DRIVER* drv = &cfstore_driver; 00709 ARM_CFSTORE_HANDLE_INIT(hkey); 00710 ARM_CFSTORE_FMODE flags; 00711 00712 CFSTORE_FENTRYLOG("%s:entered\r\n", __func__); 00713 memset(&flags, 0, sizeof(flags)); 00714 if(key_name == NULL) { 00715 CFSTORE_ERRLOG("%s:Error: invalid key_name argument \r\n", __func__); 00716 goto out0; 00717 } 00718 if(data == NULL) { 00719 CFSTORE_ERRLOG("%s:Error: invalid data argument \r\n", __func__); 00720 goto out0; 00721 } 00722 if(len == NULL) { 00723 CFSTORE_ERRLOG("%s:Error: invalid len argument \r\n", __func__); 00724 goto out0; 00725 } 00726 flags.write = 1; 00727 ret = drv->Open(key_name, flags, hkey); 00728 if(ret < ARM_DRIVER_OK){ 00729 CFSTORE_ERRLOG("%s:Error: failed to open node (key_name=\"%s\")(ret=%d)\r\n", __func__, key_name, (int) ret); 00730 goto out1; 00731 } 00732 ret = drv->Write(hkey, data, len); 00733 if(ret < ARM_DRIVER_OK){ 00734 CFSTORE_ERRLOG("%s:Error: failed to write key (key_name=\"%s\")\r\n", __func__, key_name); 00735 goto out2; 00736 } 00737 out2: 00738 drv->Close(hkey); 00739 out1: 00740 out0: 00741 return ret; 00742 } 00743 00744
Generated on Tue Jul 12 2022 12:21:45 by
