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