Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
create.cpp
00001 /* 00002 * mbed Microcontroller Library 00003 * Copyright (c) 2006-2016 ARM Limited 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 * 00017 * Test cases to create KVs in the CFSTORE using the drv->Create() API call. 00018 */ 00019 00020 /** @file create.cpp Test cases to close KVs in the CFSTORE using the 00021 * drv->Create() API function. 00022 * 00023 * Please consult the documentation under the test-case functions for 00024 * a description of the individual test case. 00025 */ 00026 00027 #include "mbed.h" 00028 #include "mbed_stats.h" 00029 #include "cfstore_config.h" 00030 #include "cfstore_debug.h" 00031 #include "cfstore_test.h" 00032 #include "Driver_Common.h" 00033 #include "configuration_store.h" 00034 #include "utest/utest.h" 00035 #include "unity/unity.h" 00036 #include "greentea-client/test_env.h" 00037 #include "cfstore_utest.h" 00038 00039 #include <stdio.h> 00040 #include <stdlib.h> 00041 #include <string.h> 00042 #include <inttypes.h> 00043 00044 using namespace utest::v1; 00045 00046 #ifdef CFSTORE_DEBUG 00047 #define CFSTORE_CREATE_GREENTEA_TIMEOUT_S 360 00048 #else 00049 #define CFSTORE_CREATE_GREENTEA_TIMEOUT_S 60 00050 #endif 00051 #define CFSTORE_CREATE_MALLOC_SIZE 1024 00052 00053 static char cfstore_create_utest_msg_g[CFSTORE_UTEST_MSG_BUF_SIZE]; 00054 00055 /// @cond CFSTORE_DOXYGEN_DISABLE 00056 #define CFSTORE_CREATE_TEST_01_TABLE_HEAD_ENTRY_01 { "Lefkada.Vathi.Meganisi.Atokos.Vathi.Ithaki.PeriPigathi.AgiosAndreas.Sami.Kefalonia.AgiaEffimia.AgiaSofia.Fiskardo.Frikes.Kioni.Meganissi.Lefkada", "Penelope"} 00057 #define CFSTORE_CREATE_TEST_01_TABLE_HEAD_ENTRY_02 { "Iolcus.Lemnos.Salmydessus.Cyzicus.Cios.Berbryces.Symplegadese.IsleAres.Colchis.Anenea.Sirens.Scylia.Charybdis.Phaeacia.Triton.Iolcus", "Medea"} 00058 #define CFSTORE_CREATE_TEST_01_TABLE_HEAD_ENTRY_03 { "338.Chaeronea.336.Macedonia.334.Granicus.333.Issus.332.Tyre.331.Gaugamela.330.Persepolis.Philotas.Parmenion.329.Bactria.Oxus.Samarkand.328.Cleitus.327.Roxane.326.Hydaspes.Bucephalus.324.Hephaestion.323.AlexanderDies", "TheGreat"} 00059 #define CFSTORE_CREATE_TEST_01_TABLE_MID_ENTRY_01 { "0123456789abcdef0123456", "abcdefghijklmnopqrstuvwxyz"} 00060 #define CFSTORE_CREATE_TEST_01_TABLE_MID_ENTRY_02 { "0123456789abcdef0123456", "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"} 00061 #define CFSTORE_CREATE_TEST_01_TABLE_MID_ENTRY_03 { "0123456789abcdef0123456", "nopqrstuvwxyz"} 00062 #define CFSTORE_CREATE_TEST_01_TABLE_TAIL_ENTRY_01 { "Time.Will.Explain.It.All", "Aegeus"} 00063 #define CFSTORE_CREATE_TEST_01_TABLE_TAIL_ENTRY_02 { "Cleverness.Is.Not.Wisdom", "Bacchae"} 00064 #define CFSTORE_CREATE_TEST_01_TABLE_TAIL_ENTRY_03 { "Talk.Sense.To.A.Fool.And.He.Calls.You.Foolish", "Bacchae"} 00065 #define CFSTORE_CREATE_TEST_01_TABLE_TAIL_ENTRY_04 { "There.is.in.the.worst.of.fortune.the.best.of.chances.for.a.happy.change", "Iphigenia.in.Tauris"} 00066 00067 static cfstore_kv_data_t cfstore_create_test_01_data[] = { 00068 CFSTORE_CREATE_TEST_01_TABLE_MID_ENTRY_01, 00069 CFSTORE_CREATE_TEST_01_TABLE_MID_ENTRY_02, 00070 CFSTORE_CREATE_TEST_01_TABLE_MID_ENTRY_03, 00071 { NULL, NULL}, 00072 }; 00073 00074 /* table 1: to initialise cfstore with CFSTORE_CREATE_TEST_01_TABLE_MID_ENTRY_01 */ 00075 static cfstore_kv_data_t cfstore_create_test_01_data_step_01[] = { 00076 CFSTORE_CREATE_TEST_01_TABLE_HEAD_ENTRY_01, 00077 CFSTORE_CREATE_TEST_01_TABLE_HEAD_ENTRY_02, 00078 CFSTORE_CREATE_TEST_01_TABLE_HEAD_ENTRY_03, 00079 CFSTORE_CREATE_TEST_01_TABLE_MID_ENTRY_01, 00080 CFSTORE_CREATE_TEST_01_TABLE_TAIL_ENTRY_01, 00081 CFSTORE_CREATE_TEST_01_TABLE_TAIL_ENTRY_02, 00082 CFSTORE_CREATE_TEST_01_TABLE_TAIL_ENTRY_03, 00083 CFSTORE_CREATE_TEST_01_TABLE_TAIL_ENTRY_04, 00084 { NULL, NULL}, 00085 }; 00086 00087 /* table 2: to CFSTORE_CREATE_TEST_01_TABLE_MID_ENTRY_01 grown to CFSTORE_CREATE_TEST_01_TABLE_MID_ENTRY_02 */ 00088 static cfstore_kv_data_t cfstore_create_test_01_data_step_02[] = { 00089 CFSTORE_CREATE_TEST_01_TABLE_HEAD_ENTRY_01, 00090 CFSTORE_CREATE_TEST_01_TABLE_HEAD_ENTRY_02, 00091 CFSTORE_CREATE_TEST_01_TABLE_HEAD_ENTRY_03, 00092 CFSTORE_CREATE_TEST_01_TABLE_MID_ENTRY_02, 00093 CFSTORE_CREATE_TEST_01_TABLE_TAIL_ENTRY_01, 00094 CFSTORE_CREATE_TEST_01_TABLE_TAIL_ENTRY_02, 00095 CFSTORE_CREATE_TEST_01_TABLE_TAIL_ENTRY_03, 00096 CFSTORE_CREATE_TEST_01_TABLE_TAIL_ENTRY_04, 00097 { NULL, NULL}, 00098 }; 00099 00100 /* table 3: to CFSTORE_CREATE_TEST_01_TABLE_MID_ENTRY_02 shrunk to CFSTORE_CREATE_TEST_01_TABLE_MID_ENTRY_03 */ 00101 static cfstore_kv_data_t cfstore_create_test_01_data_step_03[] = { 00102 CFSTORE_CREATE_TEST_01_TABLE_HEAD_ENTRY_01, 00103 CFSTORE_CREATE_TEST_01_TABLE_HEAD_ENTRY_02, 00104 CFSTORE_CREATE_TEST_01_TABLE_HEAD_ENTRY_03, 00105 CFSTORE_CREATE_TEST_01_TABLE_MID_ENTRY_03, 00106 CFSTORE_CREATE_TEST_01_TABLE_TAIL_ENTRY_01, 00107 CFSTORE_CREATE_TEST_01_TABLE_TAIL_ENTRY_02, 00108 CFSTORE_CREATE_TEST_01_TABLE_TAIL_ENTRY_03, 00109 CFSTORE_CREATE_TEST_01_TABLE_TAIL_ENTRY_04, 00110 { NULL, NULL}, 00111 }; 00112 00113 /* table 3: CFSTORE_CREATE_TEST_01_TABLE_MID_ENTRY_03 deleted */ 00114 static cfstore_kv_data_t cfstore_create_test_01_data_step_04[] = { 00115 CFSTORE_CREATE_TEST_01_TABLE_HEAD_ENTRY_01, 00116 CFSTORE_CREATE_TEST_01_TABLE_HEAD_ENTRY_02, 00117 CFSTORE_CREATE_TEST_01_TABLE_HEAD_ENTRY_03, 00118 CFSTORE_CREATE_TEST_01_TABLE_TAIL_ENTRY_01, 00119 CFSTORE_CREATE_TEST_01_TABLE_TAIL_ENTRY_02, 00120 CFSTORE_CREATE_TEST_01_TABLE_TAIL_ENTRY_03, 00121 CFSTORE_CREATE_TEST_01_TABLE_TAIL_ENTRY_04, 00122 { NULL, NULL}, 00123 }; 00124 /// @endcond 00125 00126 /* support functions */ 00127 00128 /* @brief support function for generating value blob data */ 00129 static int32_t cfstore_create_kv_value_gen(char* value, const size_t len) 00130 { 00131 size_t i = 0; 00132 size_t cpy_size = 0; 00133 00134 CFSTORE_FENTRYLOG("%s:entered\n", __func__); 00135 CFSTORE_TEST_UTEST_MESSAGE(cfstore_create_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: value pointer is null.\n", __func__); 00136 TEST_ASSERT_MESSAGE(value != NULL, cfstore_create_utest_msg_g); 00137 00138 while(i < len) 00139 { 00140 cpy_size = len - i > CFSTORE_TEST_BYTE_DATA_TABLE_SIZE ? CFSTORE_TEST_BYTE_DATA_TABLE_SIZE : len - i; 00141 memcpy(value + i, cfstore_test_byte_data_table, cpy_size); 00142 i += cpy_size; 00143 } 00144 return ARM_DRIVER_OK; 00145 } 00146 00147 00148 static char* CFSTORE_CREATE_KV_CREATE_NO_TAG = NULL; 00149 00150 /** @brief 00151 * 00152 * support function to create a KV 00153 * - a kv name is generated with the length name_len 00154 * - a kv value blob is generated with the length value_len 00155 * 00156 * @param name_len the length of the kv_name 00157 * @param name_tag tag to append to name, intended to enable large number of unique strings 00158 * @param value_buf buffer to use for storing the generated value data 00159 * @param value_len the length of the value to generate 00160 * 00161 */ 00162 static int32_t cfstore_create_kv_create(size_t name_len, char* name_tag, char* value_buf, size_t value_len) 00163 { 00164 int32_t ret = ARM_DRIVER_OK; 00165 size_t name_len_ex = name_len; 00166 char kv_name[CFSTORE_KEY_NAME_MAX_LENGTH+1]; /* extra char for terminating null */ 00167 ARM_CFSTORE_KEYDESC kdesc; 00168 00169 CFSTORE_FENTRYLOG("%s:entered\n", __func__); 00170 memset(kv_name, 0, CFSTORE_KEY_NAME_MAX_LENGTH+1); 00171 memset(&kdesc, 0, sizeof(kdesc)); 00172 kdesc.drl = ARM_RETENTION_WHILE_DEVICE_ACTIVE; 00173 00174 name_len_ex = name_len; 00175 if(name_tag){ 00176 name_len_ex += strlen(name_tag); 00177 } 00178 CFSTORE_TEST_UTEST_MESSAGE(cfstore_create_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: max supported KV name length for testing exceeded.\n", __func__); 00179 TEST_ASSERT_MESSAGE(name_len_ex < CFSTORE_KEY_NAME_MAX_LENGTH+1, cfstore_create_utest_msg_g); 00180 00181 ret = cfstore_test_kv_name_gen(kv_name, name_len); 00182 CFSTORE_TEST_UTEST_MESSAGE(cfstore_create_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: unable to generate kv_name.\n", __func__); 00183 TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK , cfstore_create_utest_msg_g); 00184 00185 /* append name tag */ 00186 if(name_tag){ 00187 strncat(kv_name, name_tag, CFSTORE_KEY_NAME_MAX_LENGTH); 00188 } 00189 00190 CFSTORE_TEST_UTEST_MESSAGE(cfstore_create_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: kv_name is not the correct length (name_len_ex=%d, expected=%d).\n", __func__, (int) strlen(kv_name), (int) name_len_ex); 00191 TEST_ASSERT_MESSAGE(strlen(kv_name) == name_len_ex, cfstore_create_utest_msg_g); 00192 00193 ret = cfstore_create_kv_value_gen(value_buf, value_len); 00194 CFSTORE_TEST_UTEST_MESSAGE(cfstore_create_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: unable to generate kv_name.\n", __func__); 00195 TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK , cfstore_create_utest_msg_g); 00196 00197 ret = cfstore_test_create(kv_name, value_buf, &value_len, &kdesc); 00198 00199 if(ret == ARM_CFSTORE_DRIVER_ERROR_OUT_OF_MEMORY){ 00200 CFSTORE_ERRLOG("%s: Error: out of memory\n", __func__); 00201 return ret; 00202 } 00203 00204 CFSTORE_TEST_UTEST_MESSAGE(cfstore_create_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to create KV in store for kv_name_good(ret=%d).\n", __func__, (int) ret); 00205 TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_create_utest_msg_g); 00206 00207 return ret; 00208 } 00209 00210 00211 /* @brief cfstore_create_test_01() support function change the size of a value blob in the cfstore */ 00212 static int32_t cfstore_create_test_KV_change(const cfstore_kv_data_t* old_node, const cfstore_kv_data_t* new_node ) 00213 { 00214 int32_t ret = ARM_DRIVER_ERROR; 00215 size_t len = 0; 00216 ARM_CFSTORE_DRIVER* drv = &cfstore_driver; 00217 ARM_CFSTORE_HANDLE_INIT(hkey); 00218 ARM_CFSTORE_FMODE flags; 00219 ARM_CFSTORE_KEYDESC kdesc; 00220 00221 CFSTORE_DBGLOG("%s:entered\n", __func__); 00222 memset(&flags, 0, sizeof(flags)); 00223 memset(&kdesc, 0, sizeof(kdesc)); 00224 00225 /* check node key_names are identical */ 00226 if(strncmp(old_node->key_name, new_node->key_name, strlen(old_node->key_name)) != 0){ 00227 CFSTORE_ERRLOG("%s:old and new entries so not have the same key_name (old_key_name=%s, new_key_name=%s).\n", __func__, old_node->key_name, new_node->key_name); 00228 return ret; 00229 } 00230 len = strlen(new_node->value); 00231 /* supply NULL key descriptor to open a pre-existing key for increasing the blob size */ 00232 ret = drv->Create(new_node->key_name, len, NULL, hkey); 00233 if(ret < ARM_DRIVER_OK){ 00234 CFSTORE_ERRLOG("%s:Error: failed to change size of KV (key_name=%s)(ret=%d).\n", __func__, new_node->key_name, (int) ret); 00235 goto out1; 00236 } 00237 len = strlen(new_node->value); 00238 ret = drv->Write(hkey, new_node->value, &len); 00239 if(ret < ARM_DRIVER_OK){ 00240 CFSTORE_ERRLOG("%s:Error: failed to write KV (key_name=%s)(ret=%d).\n", __func__, new_node->key_name, (int) ret); 00241 goto out2; 00242 } 00243 if(len != strlen(new_node->value)){ 00244 CFSTORE_DBGLOG("%s:Failed wrote (%d) rather than the correct number of bytes (%d).\n", __func__, (int) len, (int) strlen(cfstore_create_test_01_data[1].value)); 00245 goto out2; 00246 } 00247 out2: 00248 drv->Close(hkey); 00249 out1: 00250 return ret; 00251 } 00252 00253 /* report whether built/configured for flash sync or async mode */ 00254 static control_t cfstore_create_test_00(const size_t call_count) 00255 { 00256 int32_t ret = ARM_DRIVER_ERROR; 00257 00258 (void) call_count; 00259 ret = cfstore_test_startup(); 00260 CFSTORE_TEST_UTEST_MESSAGE(cfstore_create_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to perform test startup (ret=%d).\n", __func__, (int) ret); 00261 TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_create_utest_msg_g); 00262 return CaseNext; 00263 } 00264 00265 00266 /** @brief Test case to change the value blob size of pre-existing key. 00267 * 00268 * The test does the following: 00269 * - creates a cfstore with ~10 entries. 00270 * - for a mid-cfstore entry, double the value blob size. 00271 * - check all the cfstore entries can be read correctly and their 00272 * data agrees with the data supplied upon creation. 00273 * - shrink the mid-entry value blob size to be ~half the initial size. 00274 * - check all the cfstore entries can be read correctly and their 00275 * data agrees with the data supplied upon creation. 00276 * 00277 * @return on success returns CaseNext to continue to next test case, otherwise will assert on errors. 00278 */ 00279 control_t cfstore_create_test_01_end(const size_t call_count) 00280 { 00281 int32_t ret = ARM_DRIVER_ERROR; 00282 ARM_CFSTORE_FMODE flags; 00283 cfstore_kv_data_t* node = NULL; 00284 ARM_CFSTORE_DRIVER* drv = &cfstore_driver; 00285 00286 CFSTORE_FENTRYLOG("%s:entered\n", __func__); 00287 (void) call_count; 00288 memset(&flags, 0, sizeof(flags)); 00289 00290 ret = cfstore_test_create_table(cfstore_create_test_01_data_step_01); 00291 CFSTORE_TEST_UTEST_MESSAGE(cfstore_create_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Failed to add cfstore_create_test_01_data_head (ret=%d).\n", __func__, (int) ret); 00292 TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_create_utest_msg_g); 00293 00294 /* find cfstore_create_test_01_data[0] and grow the KV MID_ENTRY_01 to MID_ENTRY_02 */ 00295 ret = cfstore_create_test_KV_change(&cfstore_create_test_01_data[0], &cfstore_create_test_01_data[1]); 00296 CFSTORE_TEST_UTEST_MESSAGE(cfstore_create_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Failed to increase size of KV (ret=%d).\n", __func__, (int) ret); 00297 TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_create_utest_msg_g); 00298 00299 /* Now check that the KVs are all present and correct */ 00300 node = cfstore_create_test_01_data_step_02; 00301 while(node->key_name != NULL) 00302 { 00303 ret = cfstore_test_check_node_correct(node); 00304 CFSTORE_TEST_UTEST_MESSAGE(cfstore_create_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:node (key_name=\"%s\", value=\"%s\") not correct in cfstore\n", __func__, node->key_name, node->value); 00305 TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_create_utest_msg_g); 00306 node++; 00307 } 00308 /* revert CFSTORE_LOG for more trace */ 00309 CFSTORE_DBGLOG("KV successfully increased in size and other KVs remained unchanged.%s", "\n"); 00310 /* Shrink the KV from KV MID_ENTRY_02 to MID_ENTRY_03 */ 00311 ret = cfstore_create_test_KV_change(&cfstore_create_test_01_data[1], &cfstore_create_test_01_data[2]); 00312 CFSTORE_TEST_UTEST_MESSAGE(cfstore_create_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Failed to decrease size of KV (ret=%d).\n", __func__, (int) ret); 00313 TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_create_utest_msg_g); 00314 00315 /* Now check that the KVs are all present and correct */ 00316 node = cfstore_create_test_01_data_step_03; 00317 while(node->key_name != NULL) 00318 { 00319 ret = cfstore_test_check_node_correct(node); 00320 CFSTORE_TEST_UTEST_MESSAGE(cfstore_create_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:node (key_name=\"%s\", value=\"%s\") not correct in cfstore\n", __func__, node->key_name, node->value); 00321 TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_create_utest_msg_g); 00322 node++; 00323 } 00324 /* revert CFSTORE_LOG for more trace */ 00325 CFSTORE_DBGLOG("KV successfully decreased in size and other KVs remained unchanged.%s", "\n"); 00326 00327 /* Delete the KV */ 00328 ret = cfstore_test_delete(cfstore_create_test_01_data[2].key_name); 00329 CFSTORE_TEST_UTEST_MESSAGE(cfstore_create_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:failed to delete node(key_name=\"%s\")\n", __func__, node->key_name); 00330 TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_create_utest_msg_g); 00331 00332 /* Now check that the KVs are all present and correct */ 00333 node = cfstore_create_test_01_data_step_04; 00334 while(node->key_name != NULL) 00335 { 00336 ret = cfstore_test_check_node_correct(node); 00337 CFSTORE_TEST_UTEST_MESSAGE(cfstore_create_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:node (key_name=\"%s\", value=\"%s\") not correct in cfstore\n", __func__, node->key_name, node->value); 00338 TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_create_utest_msg_g); 00339 node++; 00340 } 00341 ret = drv->Uninitialize(); 00342 CFSTORE_TEST_UTEST_MESSAGE(cfstore_create_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Uninitialize() call failed.\n", __func__); 00343 TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_create_utest_msg_g); 00344 return CaseNext; 00345 } 00346 00347 00348 static int32_t cfstore_create_test_02_core(const size_t call_count) 00349 { 00350 int32_t ret = ARM_DRIVER_ERROR; 00351 uint32_t i = 0; 00352 uint32_t bytes_stored = 0; 00353 const uint32_t max_num_kvs_create = 10; 00354 const size_t kv_name_min_len = CFSTORE_KEY_NAME_MAX_LENGTH - max_num_kvs_create; 00355 const size_t kv_value_min_len = CFSTORE_TEST_BYTE_DATA_TABLE_SIZE; 00356 const size_t max_value_buf_size = kv_value_min_len * (max_num_kvs_create +1); 00357 char value_buf[max_value_buf_size]; 00358 00359 CFSTORE_FENTRYLOG("%s:entered\n", __func__); 00360 (void) call_count; 00361 memset(value_buf, 0, max_value_buf_size); 00362 00363 for(i = 0; i < max_num_kvs_create; i++) 00364 { 00365 memset(value_buf, 0, max_value_buf_size); 00366 ret = cfstore_create_kv_create(kv_name_min_len +i, CFSTORE_CREATE_KV_CREATE_NO_TAG, value_buf, kv_value_min_len * (i+1)); 00367 bytes_stored += kv_name_min_len + i; /* kv_name */ 00368 bytes_stored += kv_value_min_len * (i+1); /* kv value blob */ 00369 bytes_stored += 8; /* kv overhead */ 00370 if(ret == ARM_CFSTORE_DRIVER_ERROR_OUT_OF_MEMORY){ 00371 CFSTORE_ERRLOG("Out of memory on %d-th KV, trying to allocate memory totalling %d.\n", (int) i, (int) bytes_stored); 00372 break; 00373 } 00374 CFSTORE_DBGLOG("Successfully stored %d-th KV bytes, totalling %d.\n", (int) i, (int) bytes_stored); 00375 } 00376 ret = cfstore_test_delete_all(); 00377 CFSTORE_TEST_UTEST_MESSAGE(cfstore_create_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to delete_all() attributes to clean up after test (ret=%d).\n", __func__, (int) ret); 00378 TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_create_utest_msg_g); 00379 return ret; 00380 } 00381 00382 00383 /**@brief 00384 * 00385 * Test case to create ~10 kvs. The amount of data store in the cfstore is as follows: 00386 * - 10 kvs 00387 * - kv name lengths are ~220 => ~ 2200 bytes 00388 * - value blob length is 1x256, 2x256, 3x256, ... 10x256)) = 256(1+2+3+4+..10) = 256*10*11/2 = 14080 00389 * - kv overhead = 8bytes/kv = 8 * 10 = 80bytes 00390 * - total = (220*10)+256*10*11/2 10*8 = 143800 bytes 00391 * 00392 * @return on success returns CaseNext to continue to next test case, otherwise will assert on errors. 00393 */ 00394 control_t cfstore_create_test_02_end(const size_t call_count) 00395 { 00396 int32_t ret; 00397 ARM_CFSTORE_DRIVER* drv = &cfstore_driver; 00398 00399 CFSTORE_FENTRYLOG("%s:entered\n", __func__); 00400 (void) call_count; 00401 00402 ret = cfstore_create_test_02_core(call_count); 00403 CFSTORE_TEST_UTEST_MESSAGE(cfstore_create_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: something went wrong (ret=%d).\n", __func__, (int) ret); 00404 TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_create_utest_msg_g); 00405 00406 CFSTORE_TEST_UTEST_MESSAGE(cfstore_create_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Uninitialize() call failed.\n", __func__); 00407 TEST_ASSERT_MESSAGE(drv->Uninitialize() >= ARM_DRIVER_OK, cfstore_create_utest_msg_g); 00408 return CaseNext; 00409 } 00410 00411 00412 /**@brief 00413 * 00414 * Test to create the ~100 kvs to make the device run out of memory. 00415 * 00416 * @return on success returns CaseNext to continue to next test case, otherwise will assert on errors. 00417 */ 00418 control_t cfstore_create_test_03_end(const size_t call_count) 00419 { 00420 int32_t i = 0; 00421 int32_t ret; 00422 ARM_CFSTORE_DRIVER* drv = &cfstore_driver; 00423 00424 CFSTORE_FENTRYLOG("%s:entered\n", __func__); 00425 for(i = 0; i < 100; i++) 00426 { 00427 ret = cfstore_create_test_02_core(call_count); 00428 CFSTORE_TEST_UTEST_MESSAGE(cfstore_create_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: something went wrong (ret=%d).\n", __func__, (int) ret); 00429 TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_create_utest_msg_g); 00430 /* revert CFSTORE_LOG for more trace */ 00431 CFSTORE_DBGLOG("Successfully completed create/destroy loop %d.\n", (int) i); 00432 } 00433 CFSTORE_TEST_UTEST_MESSAGE(cfstore_create_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Uninitialize() call failed.\n", __func__); 00434 TEST_ASSERT_MESSAGE(drv->Uninitialize() >= ARM_DRIVER_OK, cfstore_create_utest_msg_g); 00435 return CaseNext; 00436 } 00437 00438 00439 /**@brief 00440 * 00441 * Test to create the 100 kvs to make the device run out of memory. 00442 * The amount of data store in the cfstore is as follows: 00443 * - total = (220*100)+256*100*101/2 100*8 = 1315600 = 1.315x10^6 00444 * 00445 * @return on success returns CaseNext to continue to next test case, otherwise will assert on errors. 00446 */ 00447 control_t cfstore_create_test_04_end(const size_t call_count) 00448 { 00449 int32_t ret = ARM_DRIVER_ERROR; 00450 uint32_t i = 0; 00451 uint32_t bytes_stored = 0; 00452 const uint32_t max_num_kvs_create = 100; 00453 const size_t kv_name_min_len = CFSTORE_KEY_NAME_MAX_LENGTH - max_num_kvs_create; 00454 const size_t kv_value_min_len = CFSTORE_TEST_BYTE_DATA_TABLE_SIZE; 00455 const size_t max_value_buf_size = kv_value_min_len/8 * (max_num_kvs_create +1); 00456 char* value_buf = NULL; 00457 ARM_CFSTORE_DRIVER* drv = &cfstore_driver; 00458 00459 CFSTORE_FENTRYLOG("%s:entered\n", __func__); 00460 (void) call_count; 00461 00462 CFSTORE_LOG("%s: cfstore_test_dump: dump here contents of CFSTORE so we know whats present\n", __func__); 00463 ret = cfstore_test_dump(); 00464 CFSTORE_TEST_UTEST_MESSAGE(cfstore_create_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: D.1.1 cfstore_test_dump failed (ret=%d).\n", __func__, (int) ret); 00465 TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_create_utest_msg_g); 00466 00467 value_buf = (char*) malloc(max_value_buf_size); 00468 CFSTORE_TEST_UTEST_MESSAGE(cfstore_create_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: out of memory.\n", __func__); 00469 TEST_ASSERT_MESSAGE(value_buf != NULL, cfstore_create_utest_msg_g); 00470 00471 for(i = 0; i < max_num_kvs_create; i++) 00472 { 00473 memset(value_buf, 0, max_value_buf_size); 00474 ret = cfstore_create_kv_create(kv_name_min_len +i, CFSTORE_CREATE_KV_CREATE_NO_TAG, value_buf, kv_value_min_len/8 * (i+1)); 00475 bytes_stored += kv_name_min_len + i; /* kv_name */ 00476 bytes_stored += kv_value_min_len/8 * (i+1); /* kv value blob */ 00477 bytes_stored += 8; /* kv overhead */ 00478 if(ret == ARM_CFSTORE_DRIVER_ERROR_OUT_OF_MEMORY){ 00479 CFSTORE_ERRLOG("Out of memory on %d-th KV, trying to allocate memory totalling %d.\n", (int) i, (int) bytes_stored); 00480 break; 00481 } 00482 /* revert CFSTORE_LOG for more trace */ 00483 CFSTORE_DBGLOG("Successfully stored %d-th KV bytes, totalling %d.\n", (int) i, (int) bytes_stored); 00484 } 00485 ret = cfstore_test_delete_all(); 00486 CFSTORE_TEST_UTEST_MESSAGE(cfstore_create_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to delete_all() attributes to clean up after test (ret=%d).\n", __func__, (int) ret); 00487 TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_create_utest_msg_g); 00488 free(value_buf); 00489 CFSTORE_TEST_UTEST_MESSAGE(cfstore_create_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Uninitialize() call failed.\n", __func__); 00490 TEST_ASSERT_MESSAGE(drv->Uninitialize() >= ARM_DRIVER_OK, cfstore_create_utest_msg_g); 00491 return CaseNext; 00492 } 00493 00494 00495 /** 00496 * @brief Support function for test cases 05 00497 * 00498 * Create enough KV's to consume the whole of available memory 00499 */ 00500 int32_t cfstore_create_test_05_core(const size_t call_count) 00501 { 00502 int32_t ret = ARM_DRIVER_ERROR; 00503 uint32_t i = 0; 00504 const uint32_t max_num_kvs_create = 200; 00505 const size_t kv_name_tag_len = 3; 00506 const size_t kv_name_min_len = 10; 00507 const size_t kv_value_min_len = CFSTORE_TEST_BYTE_DATA_TABLE_SIZE; 00508 const size_t max_value_buf_size = kv_value_min_len/64 * (max_num_kvs_create+1); 00509 char kv_name_tag_buf[kv_name_tag_len+1]; 00510 char* value_buf = NULL; 00511 ARM_CFSTORE_DRIVER* drv = &cfstore_driver; 00512 00513 CFSTORE_FENTRYLOG("%s:entered\n", __func__); 00514 00515 /* Initialize() */ 00516 cfstore_utest_default_start(call_count); 00517 00518 value_buf = (char*) malloc(max_value_buf_size); 00519 CFSTORE_TEST_UTEST_MESSAGE(cfstore_create_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: out of memory.\n", __func__); 00520 TEST_ASSERT_MESSAGE(value_buf != NULL, cfstore_create_utest_msg_g); 00521 00522 for(i = 0; i < max_num_kvs_create; i++) 00523 { 00524 memset(value_buf, 0, max_value_buf_size); 00525 snprintf(kv_name_tag_buf, kv_name_tag_len+1, "%0d", (int) i); 00526 ret = cfstore_create_kv_create(kv_name_min_len, kv_name_tag_buf, value_buf, kv_value_min_len/64 * (i+1)); 00527 if(ret == ARM_CFSTORE_DRIVER_ERROR_OUT_OF_MEMORY){ 00528 CFSTORE_ERRLOG("Out of memory on %d-th KV.\n", (int) i); 00529 break; 00530 } 00531 /* revert CFSTORE_LOG for more trace */ 00532 CFSTORE_DBGLOG("Successfully stored %d-th KV.\n", (int) i); 00533 } 00534 ret = cfstore_test_delete_all(); 00535 CFSTORE_TEST_UTEST_MESSAGE(cfstore_create_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to delete_all() attributes to clean up after test.\n", __func__); 00536 TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_create_utest_msg_g); 00537 free(value_buf); 00538 CFSTORE_TEST_UTEST_MESSAGE(cfstore_create_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Uninitialize() call failed.\n", __func__); 00539 TEST_ASSERT_MESSAGE(drv->Uninitialize() >= ARM_DRIVER_OK, cfstore_create_utest_msg_g); 00540 return ret; 00541 } 00542 00543 00544 /** 00545 * @brief Test case to check cfstore recovers from out of memory 00546 * errors without leaking memory 00547 * 00548 * This test case does the following: 00549 * 1. Start loop. 00550 * 2. Initializes CFSTORE. 00551 * 3. Creates as many KVs as required to run out of memory. The number of bytes B 00552 * allocated before running out of memory is recorded. 00553 * 4. For loop i, check that B_i = B_i-1 for i>0 i.e. that no memory has been leaked 00554 * 5. Uninitialize(), which should clean up any cfstore internal state including 00555 * freeing the internal memeory area. 00556 * 6. Repeat from step 1 N times. 00557 */ 00558 control_t cfstore_create_test_05(const size_t call_count) 00559 { 00560 uint32_t i = 0; 00561 int32_t ret = ARM_DRIVER_ERROR; 00562 const uint32_t max_loops = 50; 00563 mbed_stats_heap_t stats_before; 00564 mbed_stats_heap_t stats_after; 00565 00566 mbed_stats_heap_get(&stats_before); 00567 00568 CFSTORE_FENTRYLOG("%s:entered\n", __func__); 00569 for(i = 0; i < max_loops; i++) { 00570 ret = cfstore_create_test_05_core(call_count); 00571 CFSTORE_TEST_UTEST_MESSAGE(cfstore_create_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: cfstore_create_test_05_core() failed (ret = %d.\n", __func__, (int) ret); 00572 TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_create_utest_msg_g); 00573 00574 mbed_stats_heap_get(&stats_after); 00575 if(i > 1) { 00576 CFSTORE_TEST_UTEST_MESSAGE(cfstore_create_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: memory leak: stored %d bytes on loop %d, but %d bytes on loop %d .\n", __func__, (int) stats_after.current_size, (int) i, (int) stats_before.current_size, (int) i-1); 00577 TEST_ASSERT_MESSAGE(stats_after.current_size == stats_before.current_size, cfstore_create_utest_msg_g); 00578 TEST_ASSERT(stats_after.alloc_fail_cnt > stats_before.alloc_fail_cnt); 00579 } 00580 stats_before = stats_after; 00581 } 00582 return CaseNext; 00583 } 00584 00585 00586 /// @cond CFSTORE_DOXYGEN_DISABLE 00587 /* structure to encode test data */ 00588 typedef struct cfstore_create_key_name_validate_t { 00589 const char* key_name; 00590 uint32_t f_allowed : 1; 00591 } cfstore_create_key_name_validate_t; 00592 00593 /* data table encoding test data */ 00594 cfstore_create_key_name_validate_t cfstore_create_test_06_data[] = { 00595 /* ruler for measuring text strings */ 00596 /* 1 1 1 1 1 1 1 1 1 1 2 2 2 */ 00597 /* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 */ 00598 /* 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 */ 00599 { "", false}, 00600 { "abc.{1}.efg", true }, 00601 { "abc.{1.efg", false }, 00602 { "abc.1}.efg", false }, 00603 { "abc.{{1}}.efg", false }, 00604 { "abc.{}.efg", true }, 00605 { "abc.}1{.efg", false }, 00606 { ".piety.demands.us.to.honour.truth.above.our.friends", false }, 00607 { "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.{100000000}", false }, 00608 { NULL, false}, 00609 }; 00610 /// @endcond 00611 00612 00613 /** 00614 * @brief Test whether a key name can be created or not. 00615 * 00616 * @param key_name 00617 * name of the key to create in the store 00618 * @param should_create 00619 * if true, then create KV should succeed, otherwise should fail. 00620 * 00621 * @return on success returns CaseNext to continue to next test case, otherwise will assert on errors. 00622 */ 00623 bool cfstore_create_key_name_validate(const char *key_name, bool should_create) 00624 { 00625 bool bret = false; 00626 char* test_data = (char*) "test_data"; 00627 int32_t ret = ARM_DRIVER_ERROR; 00628 ARM_CFSTORE_SIZE len = 0; 00629 ARM_CFSTORE_KEYDESC kdesc; 00630 00631 CFSTORE_FENTRYLOG("%s:entered\r\n", __func__); 00632 memset(&kdesc, 0, sizeof(kdesc)); 00633 00634 /* create */ 00635 kdesc.drl = ARM_RETENTION_WHILE_DEVICE_ACTIVE; 00636 len = strlen(test_data); 00637 ret = cfstore_test_create((const char*) key_name, test_data, &len, &kdesc); 00638 /* dont not use any functions that require finding the created item as they may not work, 00639 * depending on the construction of the test key_name & match strings */ 00640 if(should_create == true) 00641 { 00642 if(ret < ARM_DRIVER_OK){ 00643 CFSTORE_ERRLOG("%s:Error: failed to create kv (key_name=%s.\r\n", __func__, key_name); 00644 return bret; 00645 } 00646 CFSTORE_DBGLOG("%s:Success: Create() behaved as expected.\r\n", __func__); 00647 /* delete using the actual name */ 00648 ret = cfstore_test_delete((const char*) key_name); 00649 if(ret < ARM_DRIVER_OK){ 00650 CFSTORE_ERRLOG("%s:Error: failed to delete kv (key_name=%s)(ret=%d).\r\n", __func__, key_name, (int)ret); 00651 } 00652 bret = true; 00653 } 00654 else 00655 { 00656 if(ret >= ARM_DRIVER_OK){ 00657 CFSTORE_ERRLOG("%s:Error: created kv (key_name=%s) when Create() should have failed.\r\n", __func__, key_name); 00658 return bret; 00659 } 00660 /* the operation failed which was the expected result hence return true*/ 00661 bret = true; 00662 } 00663 return bret; 00664 } 00665 00666 /** @brief 00667 * 00668 * Test that key names with non-matching braces etc do no get created. 00669 * 00670 * @return on success returns CaseNext to continue to next test case, otherwise will assert on errors. 00671 */ 00672 control_t cfstore_create_test_06_end(const size_t call_count) 00673 { 00674 bool ret = false; 00675 int32_t ret32 = ARM_DRIVER_ERROR; 00676 ARM_CFSTORE_DRIVER* drv = &cfstore_driver; 00677 cfstore_create_key_name_validate_t* node = cfstore_create_test_06_data; 00678 00679 (void) call_count; 00680 00681 while(node->key_name != NULL) 00682 { 00683 ret = cfstore_create_key_name_validate(node->key_name, node->f_allowed); 00684 CFSTORE_TEST_UTEST_MESSAGE(cfstore_create_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: test failed (ret=%d, key_name=%s, f_allowed=%d)\n", __func__, (int) ret, node->key_name, (int) node->f_allowed); 00685 TEST_ASSERT_MESSAGE(ret == true, cfstore_create_utest_msg_g); 00686 node++; 00687 } 00688 00689 ret32 = drv->Uninitialize(); 00690 CFSTORE_TEST_UTEST_MESSAGE(cfstore_create_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Uninitialize() call failed.\n", __func__); 00691 TEST_ASSERT_MESSAGE(ret32 >= ARM_DRIVER_OK, cfstore_create_utest_msg_g); 00692 return CaseNext; 00693 } 00694 00695 00696 /** @brief Test case to change the value blob size of pre-existing 00697 * key in a way that causes the memory area to realloc-ed, 00698 * 00699 * The test is a modified version of cfstore_create_test_01_end which 00700 * - creates KVs, 00701 * - mallocs a memory object on the heap 00702 * - increases the size of one of the existing KVs, causing the 00703 * internal memory area to be realloc-ed. 00704 * 00705 * In detail, the test does the following: 00706 * 1. creates a cfstore with ~10 entries. This causes the configuration 00707 * store to realloc() heap memory for KV storage. 00708 * 2. mallocs a memory object on heap. 00709 * 3. for a mid-cfstore entry, double the value blob size. This will cause the 00710 * cfstore memory area to be realloced. 00711 * 4. check all the cfstore entries can be read correctly and their 00712 * data agrees with the data supplied upon creation. 00713 * 5. shrink the mid-entry value blob size to be ~half the initial size. 00714 * check all the cfstore entries can be read correctly and their 00715 * data agrees with the data supplied upon creation. 00716 * 00717 * @return on success returns CaseNext to continue to next test case, otherwise will assert on errors. 00718 */ 00719 control_t cfstore_create_test_07_end(const size_t call_count) 00720 { 00721 int32_t ret = ARM_DRIVER_ERROR; 00722 void *test_buf1 = NULL; 00723 ARM_CFSTORE_FMODE flags; 00724 cfstore_kv_data_t* node = NULL; 00725 ARM_CFSTORE_DRIVER* drv = &cfstore_driver; 00726 00727 CFSTORE_FENTRYLOG("%s:entered\n", __func__); 00728 (void) call_count; 00729 memset(&flags, 0, sizeof(flags)); 00730 00731 /* step 1 */ 00732 ret = cfstore_test_create_table(cfstore_create_test_01_data_step_01); 00733 CFSTORE_TEST_UTEST_MESSAGE(cfstore_create_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Failed to add cfstore_create_test_01_data_head (ret=%d).\n", __func__, (int) ret); 00734 TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_create_utest_msg_g); 00735 00736 /* step 2 */ 00737 test_buf1 = malloc(CFSTORE_CREATE_MALLOC_SIZE); 00738 CFSTORE_TEST_UTEST_MESSAGE(cfstore_create_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to allocate memory (test_buf1=%p)\n", __func__, test_buf1); 00739 TEST_ASSERT_MESSAGE(test_buf1 != NULL, cfstore_create_utest_msg_g); 00740 00741 /* step 3. find cfstore_create_test_01_data[0] and grow the KV MID_ENTRY_01 to MID_ENTRY_02 */ 00742 ret = cfstore_create_test_KV_change(&cfstore_create_test_01_data[0], &cfstore_create_test_01_data[1]); 00743 CFSTORE_TEST_UTEST_MESSAGE(cfstore_create_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Failed to increase size of KV (ret=%d).\n", __func__, (int) ret); 00744 TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_create_utest_msg_g); 00745 00746 /* step 4. Now check that the KVs are all present and correct */ 00747 node = cfstore_create_test_01_data_step_02; 00748 while(node->key_name != NULL) 00749 { 00750 ret = cfstore_test_check_node_correct(node); 00751 CFSTORE_TEST_UTEST_MESSAGE(cfstore_create_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:node (key_name=\"%s\", value=\"%s\") not correct in cfstore\n", __func__, node->key_name, node->value); 00752 TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_create_utest_msg_g); 00753 node++; 00754 } 00755 /* revert CFSTORE_LOG for more trace */ 00756 CFSTORE_DBGLOG("KV successfully increased in size and other KVs remained unchanged.%s", "\n"); 00757 00758 /* Shrink the KV from KV MID_ENTRY_02 to MID_ENTRY_03 */ 00759 ret = cfstore_create_test_KV_change(&cfstore_create_test_01_data[1], &cfstore_create_test_01_data[2]); 00760 CFSTORE_TEST_UTEST_MESSAGE(cfstore_create_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Failed to decrease size of KV (ret=%d).\n", __func__, (int) ret); 00761 TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_create_utest_msg_g); 00762 00763 /* Step 5. Now check that the KVs are all present and correct */ 00764 node = cfstore_create_test_01_data_step_03; 00765 while(node->key_name != NULL) 00766 { 00767 ret = cfstore_test_check_node_correct(node); 00768 CFSTORE_TEST_UTEST_MESSAGE(cfstore_create_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:node (key_name=\"%s\", value=\"%s\") not correct in cfstore\n", __func__, node->key_name, node->value); 00769 TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_create_utest_msg_g); 00770 node++; 00771 } 00772 /* revert CFSTORE_LOG for more trace */ 00773 CFSTORE_DBGLOG("KV successfully decreased in size and other KVs remained unchanged.%s", "\n"); 00774 00775 /* Delete the KV */ 00776 ret = cfstore_test_delete(cfstore_create_test_01_data[2].key_name); 00777 CFSTORE_TEST_UTEST_MESSAGE(cfstore_create_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:failed to delete node(key_name=\"%s\")\n", __func__, node->key_name); 00778 TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_create_utest_msg_g); 00779 00780 /* Now check that the KVs are all present and correct */ 00781 node = cfstore_create_test_01_data_step_04; 00782 while(node->key_name != NULL) 00783 { 00784 ret = cfstore_test_check_node_correct(node); 00785 CFSTORE_TEST_UTEST_MESSAGE(cfstore_create_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:node (key_name=\"%s\", value=\"%s\") not correct in cfstore\n", __func__, node->key_name, node->value); 00786 TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_create_utest_msg_g); 00787 node++; 00788 } 00789 00790 free(test_buf1); 00791 ret = drv->Uninitialize(); 00792 CFSTORE_TEST_UTEST_MESSAGE(cfstore_create_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Uninitialize() call failed.\n", __func__); 00793 TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_create_utest_msg_g); 00794 return CaseNext; 00795 } 00796 00797 00798 /// @cond CFSTORE_DOXYGEN_DISABLE 00799 utest::v1::status_t greentea_setup(const size_t number_of_cases) 00800 { 00801 GREENTEA_SETUP(CFSTORE_CREATE_GREENTEA_TIMEOUT_S, "default_auto"); 00802 return greentea_test_setup_handler(number_of_cases); 00803 } 00804 00805 Case cases[] = { 00806 /* 1 2 3 4 5 6 7 */ 00807 /* 1234567890123456789012345678901234567890123456789012345678901234567890 */ 00808 Case("CREATE_test_00", cfstore_create_test_00), 00809 Case("CREATE_test_01_start", cfstore_utest_default_start), 00810 Case("CREATE_test_01_end", cfstore_create_test_01_end), 00811 Case("CREATE_test_02_start", cfstore_utest_default_start), 00812 Case("CREATE_test_02_end", cfstore_create_test_02_end), 00813 Case("CREATE_test_03_start", cfstore_utest_default_start), 00814 Case("CREATE_test_03_end", cfstore_create_test_03_end), 00815 Case("CREATE_test_04_start", cfstore_utest_default_start), 00816 Case("CREATE_test_04_end", cfstore_create_test_04_end), 00817 #if defined(MBED_HEAP_STATS_ENABLED) && MBED_HEAP_STATS_ENABLED && !defined(__ICCARM__) 00818 Case("CREATE_test_05", cfstore_create_test_05), 00819 #endif 00820 Case("CREATE_test_06_start", cfstore_utest_default_start), 00821 Case("CREATE_test_06_end", cfstore_create_test_06_end), 00822 Case("CREATE_test_07_start", cfstore_utest_default_start), 00823 Case("CREATE_test_07_end", cfstore_create_test_07_end), 00824 }; 00825 00826 00827 /* Declare your test specification with a custom setup handler */ 00828 Specification specification(greentea_setup, cases); 00829 00830 int main() 00831 { 00832 return !Harness::run(specification); 00833 } 00834 /// @endcond 00835
Generated on Tue Aug 9 2022 00:37:04 by
1.7.2