Skip to content

Commit 1e069aa

Browse files
authored
Merge pull request #2250 from c1728p9/feature_storage
Update of #2203
2 parents 09f9c0e + 1799ace commit 1e069aa

File tree

79 files changed

+23268
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+23268
-2
lines changed
Lines changed: 309 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,309 @@
1+
/*
2+
* mbed Microcontroller Library
3+
* Copyright (c) 2006-2016 ARM Limited
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*/
18+
19+
/** @file add_del.cpp Test cases to add and delete key-value pairs in the CFSTORE.
20+
*
21+
* Please consult the documentation under the test-case functions for
22+
* a description of the individual test case.
23+
*/
24+
25+
#include "mbed.h"
26+
#include "cfstore_config.h"
27+
#include "Driver_Common.h"
28+
#include "cfstore_debug.h"
29+
#include "cfstore_test.h"
30+
#include "configuration_store.h"
31+
#include "utest/utest.h"
32+
#include "unity/unity.h"
33+
#include "greentea-client/test_env.h"
34+
#include "cfstore_utest.h"
35+
36+
#ifdef YOTTA_CFG_CFSTORE_UVISOR
37+
#include "uvisor-lib/uvisor-lib.h"
38+
#include "cfstore_uvisor.h"
39+
#endif /* YOTTA_CFG_CFSTORE_UVISOR */
40+
41+
#include <stdio.h>
42+
#include <stdlib.h>
43+
#include <string.h>
44+
#include <inttypes.h>
45+
46+
using namespace utest::v1;
47+
48+
static char cfstore_add_del_utest_msg_g[CFSTORE_UTEST_MSG_BUF_SIZE];
49+
50+
#ifdef YOTTA_CFG_CFSTORE_UVISOR
51+
/* Create the main box ACL list for the application.
52+
* The main ACL gets inherited by all the other boxes
53+
*/
54+
CFSTORE_UVISOR_MAIN_ACL(cfstore_acl_uvisor_box_add_del_g);
55+
56+
/* Enable uVisor. */
57+
UVISOR_SET_MODE_ACL(UVISOR_ENABLED, cfstore_acl_uvisor_box_add_del_g);
58+
#endif /* YOTTA_CFG_CFSTORE_UVISOR */
59+
60+
static cfstore_kv_data_t cfstore_add_del_test_07_data[] = {
61+
CFSTORE_INIT_1_TABLE_MID_NODE,
62+
{ NULL, NULL},
63+
};
64+
65+
66+
/* report whether built/configured for flash sync or async mode */
67+
static control_t cfstore_add_del_test_00(const size_t call_count)
68+
{
69+
int32_t ret = ARM_DRIVER_ERROR;
70+
71+
(void) call_count;
72+
ret = cfstore_test_startup();
73+
CFSTORE_TEST_UTEST_MESSAGE(cfstore_add_del_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to perform test startup (ret=%d).\n", __func__, (int) ret);
74+
TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_add_del_utest_msg_g);
75+
return CaseNext;
76+
}
77+
78+
/** @brief
79+
*
80+
* This test case does the following:
81+
* - creates a KV.
82+
* - deletes the KV.
83+
* - checks that the deleted KV can no longer be found in the store.
84+
*
85+
* @return on success returns CaseNext to continue to next test case, otherwise will assert on errors.
86+
*/
87+
control_t cfstore_add_del_test_01_end(const size_t call_count)
88+
{
89+
bool bfound = false;
90+
int32_t ret = ARM_DRIVER_ERROR;
91+
ARM_CFSTORE_SIZE len = 0;
92+
ARM_CFSTORE_DRIVER* drv = &cfstore_driver;
93+
ARM_CFSTORE_KEYDESC kdesc;
94+
ARM_CFSTORE_HANDLE_INIT(hkey);
95+
ARM_CFSTORE_FMODE flags;
96+
97+
CFSTORE_FENTRYLOG("%s:entered\n", __func__);
98+
(void) call_count;
99+
memset(&kdesc, 0, sizeof(kdesc));
100+
memset(&flags, 0, sizeof(flags));
101+
102+
kdesc.drl = ARM_RETENTION_WHILE_DEVICE_ACTIVE;
103+
len = strlen(cfstore_add_del_test_07_data[0].value);
104+
105+
ret = cfstore_test_create(cfstore_add_del_test_07_data[0].key_name, (char*) cfstore_add_del_test_07_data[0].value, &len, &kdesc);
106+
CFSTORE_TEST_UTEST_MESSAGE(cfstore_add_del_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to create KV in store (ret=%d).\n", __func__, (int) ret);
107+
TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_add_del_utest_msg_g);
108+
109+
/* now delete KV*/
110+
ret = drv->Open(cfstore_add_del_test_07_data[0].key_name, flags, hkey);
111+
CFSTORE_TEST_UTEST_MESSAGE(cfstore_add_del_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to Open() (ret=%d).\n", __func__, (int) ret);
112+
TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_add_del_utest_msg_g);
113+
114+
if(hkey != NULL){
115+
ret = drv->Delete(hkey);
116+
drv->Close(hkey);
117+
hkey = NULL;
118+
}
119+
/* check that the KV has been deleted */
120+
/* revert to CFSTORE_LOG if more trace required */
121+
CFSTORE_DBGLOG("LOG: WARNING: About to look for non-existent key (key_name=%s) (which will generate internal trace reporting errors if debug trace enabled).\n", cfstore_add_del_test_07_data[0].key_name);
122+
ret = cfstore_test_kv_is_found(cfstore_add_del_test_07_data[0].key_name, &bfound);
123+
CFSTORE_TEST_UTEST_MESSAGE(cfstore_add_del_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error failed to delete a key (ret=%d).\n", __func__, (int) ret);
124+
TEST_ASSERT_MESSAGE(ret == ARM_CFSTORE_DRIVER_ERROR_KEY_NOT_FOUND, cfstore_add_del_utest_msg_g);
125+
126+
CFSTORE_TEST_UTEST_MESSAGE(cfstore_add_del_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Test failed: found KV that was previously deleted (key_name=%s)\n", __func__, cfstore_add_del_test_07_data[0].key_name);
127+
TEST_ASSERT_MESSAGE(bfound == false, cfstore_add_del_utest_msg_g);
128+
129+
ret = drv->Uninitialize();
130+
CFSTORE_TEST_UTEST_MESSAGE(cfstore_add_del_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Uninitialize() call failed.\n", __func__);
131+
TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_add_del_utest_msg_g);
132+
return CaseNext;
133+
}
134+
135+
136+
static cfstore_kv_data_t cfstore_add_del_test_08_data[] = {
137+
CFSTORE_INIT_1_TABLE_HEAD,
138+
CFSTORE_INIT_1_TABLE_MID_NODE,
139+
CFSTORE_INIT_1_TABLE_TAIL,
140+
{ NULL, NULL},
141+
};
142+
143+
144+
/** @brief
145+
*
146+
* This test case adds a small number of KVs (~3), and then delete them.
147+
* - add key(s)
148+
* - delete key(s)
149+
* - make sure can't find key in cfstore
150+
* - loop over the above a number of times.
151+
*
152+
* @return on success returns CaseNext to continue to next test case, otherwise will assert on errors.
153+
*/
154+
control_t cfstore_add_del_test_02_end(const size_t call_count)
155+
{
156+
bool bResult = true; // We'll do "&=" cumulative checking.
157+
int32_t ret = ARM_DRIVER_ERROR;
158+
ARM_CFSTORE_SIZE len = 0;
159+
ARM_CFSTORE_KEYDESC kdesc;
160+
cfstore_kv_data_t* node = NULL;
161+
ARM_CFSTORE_DRIVER* drv = &cfstore_driver;
162+
163+
CFSTORE_FENTRYLOG("%s:entered\n", __func__);
164+
(void) call_count;
165+
memset(&kdesc, 0, sizeof(kdesc));
166+
167+
/* create */
168+
kdesc.drl = ARM_RETENTION_WHILE_DEVICE_ACTIVE;
169+
node = cfstore_add_del_test_08_data;
170+
while(node->key_name != NULL)
171+
{
172+
len = strlen(node->value);
173+
ret = cfstore_test_create(node->key_name, (char*) node->value, &len, &kdesc);
174+
CFSTORE_TEST_UTEST_MESSAGE(cfstore_add_del_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to create kv (key_name=%s.\n", __func__, node->key_name);
175+
TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_add_del_utest_msg_g);
176+
/* revert CFSTORE_LOG for more trace */
177+
CFSTORE_DBGLOG("Created KV successfully (key_name=\"%s\", value=\"%s\")\n", node->key_name, node->value);
178+
node++;
179+
}
180+
181+
/* test delete all */
182+
ret = cfstore_test_delete_all();
183+
CFSTORE_TEST_UTEST_MESSAGE(cfstore_add_del_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to delete all KVs.\n", __func__);
184+
TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_add_del_utest_msg_g);
185+
186+
/* check there are no KVs present as expected */
187+
node = cfstore_add_del_test_08_data;
188+
while(node->key_name != NULL)
189+
{
190+
ret = cfstore_test_kv_is_found(node->key_name, &bResult);
191+
CFSTORE_TEST_UTEST_MESSAGE(cfstore_add_del_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: found key when should not be present.\n", __func__);
192+
TEST_ASSERT_MESSAGE(ret == ARM_CFSTORE_DRIVER_ERROR_KEY_NOT_FOUND && bResult == false, cfstore_add_del_utest_msg_g);
193+
/* revert CFSTORE_LOG for more trace */
194+
CFSTORE_DBGLOG("Found KV successfully (key_name=\"%s\")\n", node->key_name);
195+
node++;
196+
}
197+
ret = drv->Uninitialize();
198+
CFSTORE_TEST_UTEST_MESSAGE(cfstore_add_del_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Uninitialize() call failed.\n", __func__);
199+
TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_add_del_utest_msg_g);
200+
return CaseNext;
201+
}
202+
203+
/** @brief
204+
*
205+
* This test case adds ~50 KVs, and then delete entries at the start,
206+
* middle and end of list.
207+
*
208+
* @return on success returns CaseNext to continue to next test case, otherwise will assert on errors.
209+
*/
210+
control_t cfstore_add_del_test_03_end(const size_t call_count)
211+
{
212+
bool bfound = false;
213+
int32_t ret = ARM_DRIVER_ERROR;
214+
ARM_CFSTORE_FMODE flags;
215+
cfstore_kv_data_t *node;
216+
ARM_CFSTORE_DRIVER* drv = &cfstore_driver;
217+
218+
CFSTORE_FENTRYLOG("%s:entered\n", __func__);
219+
(void) call_count;
220+
memset(&flags, 0, sizeof(flags));
221+
222+
ret = cfstore_test_init_1();
223+
CFSTORE_TEST_UTEST_MESSAGE(cfstore_add_del_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to initialise cfstore area with entries\n", __func__);
224+
TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_add_del_utest_msg_g);
225+
226+
/* delete some keys */
227+
node = cfstore_add_del_test_08_data;
228+
while(node->key_name != NULL)
229+
{
230+
CFSTORE_DBGLOG("%s:about to delete key (key_name=%s).\n", __func__, node->key_name);
231+
cfstore_test_delete(node->key_name);
232+
CFSTORE_TEST_UTEST_MESSAGE(cfstore_add_del_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error failed to delete a key (ret=%d).\n", __func__, (int) ret);
233+
TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_add_del_utest_msg_g);
234+
/* revert CFSTORE_LOG for more trace */
235+
CFSTORE_DBGLOG("Deleted KV successfully (key_name=\"%s\")\n", node->key_name);
236+
node++;
237+
}
238+
/* check the keys have been deleted */
239+
node = cfstore_add_del_test_08_data;
240+
while(node->key_name != NULL)
241+
{
242+
ret = cfstore_test_kv_is_found(node->key_name, &bfound);
243+
CFSTORE_TEST_UTEST_MESSAGE(cfstore_add_del_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to delete a key (ret=%d).\n", __func__, (int) ret);
244+
TEST_ASSERT_MESSAGE(ret == ARM_CFSTORE_DRIVER_ERROR_KEY_NOT_FOUND, cfstore_add_del_utest_msg_g);
245+
246+
CFSTORE_TEST_UTEST_MESSAGE(cfstore_add_del_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Test failed: found KV that was previously deleted (key_name=%s)\n", __func__, node->key_name);
247+
TEST_ASSERT_MESSAGE(bfound == false, cfstore_add_del_utest_msg_g);
248+
node++;
249+
}
250+
251+
/* clean up by deleting all remaining KVs. this is not part of the test */
252+
ret = cfstore_test_delete_all();
253+
CFSTORE_TEST_UTEST_MESSAGE(cfstore_add_del_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error failed to delete a all KVs (ret=%d).\n", __func__, (int) ret);
254+
TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_add_del_utest_msg_g);
255+
256+
ret = drv->Uninitialize();
257+
CFSTORE_TEST_UTEST_MESSAGE(cfstore_add_del_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to initialize CFSTORE (ret=%d)\n", __func__, (int) ret);
258+
TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_add_del_utest_msg_g);
259+
return CaseNext;
260+
}
261+
262+
263+
/** @brief
264+
*
265+
* This test case is as per test_03 but using delete_all() on all init_1 data.
266+
* This test case is yet to be implemented.
267+
*
268+
* @return on success returns CaseNext to continue to next test case, otherwise will assert on errors.
269+
*/
270+
control_t cfstore_add_del_test_04(const size_t call_count)
271+
{
272+
(void) call_count;
273+
/*todo: implement test */
274+
CFSTORE_TEST_UTEST_MESSAGE(cfstore_add_del_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Warn: Not implemented\n", __func__);
275+
CFSTORE_DBGLOG("%s: WARN: requires implementation\n", __func__);
276+
TEST_ASSERT_MESSAGE(true, cfstore_add_del_utest_msg_g);
277+
return CaseNext;
278+
}
279+
280+
281+
/// @cond CFSTORE_DOXYGEN_DISABLE
282+
utest::v1::status_t greentea_setup(const size_t number_of_cases)
283+
{
284+
GREENTEA_SETUP(100, "default_auto");
285+
return greentea_test_setup_handler(number_of_cases);
286+
}
287+
288+
Case cases[] = {
289+
/* 1 2 3 4 5 6 7 */
290+
/* 1234567890123456789012345678901234567890123456789012345678901234567890 */
291+
Case("ADD_DEL_test_00", cfstore_add_del_test_00),
292+
Case("ADD_DEL_test_01_start", cfstore_utest_default_start),
293+
Case("ADD_DEL_test_01_end", cfstore_add_del_test_01_end),
294+
Case("ADD_DEL_test_02_start", cfstore_utest_default_start),
295+
Case("ADD_DEL_test_02_end", cfstore_add_del_test_02_end),
296+
Case("ADD_DEL_test_03_start", cfstore_utest_default_start),
297+
Case("ADD_DEL_test_03_end", cfstore_add_del_test_03_end),
298+
Case("ADD_DEL_test_04", cfstore_add_del_test_04),
299+
};
300+
301+
302+
/* Declare your test specification with a custom setup handler */
303+
Specification specification(greentea_setup, cases);
304+
305+
int main()
306+
{
307+
return !Harness::run(specification);
308+
}
309+
/// @endcond

0 commit comments

Comments
 (0)