Skip to content

Commit 28a39bd

Browse files
committed
Merge pull request #244 from simonqhughes/master
Integrating configuration-store into mbed-os
2 parents e48f764 + 34f3c5d commit 28a39bd

File tree

64 files changed

+17364
-0
lines changed

Some content is hidden

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

64 files changed

+17364
-0
lines changed

TESTS/cfstore/add_del/add_del.cpp

Lines changed: 378 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,378 @@
1+
/** @file add_del.cpp
2+
*
3+
* mbed Microcontroller Library
4+
* Copyright (c) 2006-2016 ARM Limited
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* Test cases to add and delete KVs in the CFSTORE.
19+
*/
20+
#if defined __MBED__ && ! defined TOOLCHAIN_GCC_ARM
21+
22+
23+
#include <stdio.h>
24+
#include <stdlib.h>
25+
#include <string.h>
26+
#include <inttypes.h>
27+
28+
#ifdef TARGET_LIKE_FRDM_K64F_GCC
29+
#include <mbed-drivers/mbed.h>
30+
#endif
31+
32+
#include "cfstore_config.h"
33+
#include <Driver_Common.h>
34+
#include "cfstore_debug.h"
35+
#include "cfstore_test.h"
36+
#include <configuration-store/configuration_store.h>
37+
#include "utest/utest.h"
38+
#include "unity/unity.h"
39+
#include "greentea-client/test_env.h"
40+
#ifdef YOTTA_CFG_CFSTORE_UVISOR
41+
#include "uvisor-lib/uvisor-lib.h"
42+
#include "cfstore_uvisor.h"
43+
#endif /* YOTTA_CFG_CFSTORE_UVISOR */
44+
45+
using namespace utest::v1;
46+
47+
static control_t cfstore_add_del_test_00(const size_t call_count)
48+
{
49+
(void) call_count;
50+
printf("Not implemented for ARM toolchain\n");
51+
return CaseNext;
52+
}
53+
54+
55+
utest::v1::status_t greentea_setup(const size_t number_of_cases)
56+
{
57+
GREENTEA_SETUP(100, "default_auto");
58+
return greentea_test_setup_handler(number_of_cases);
59+
}
60+
61+
Case cases[] = {
62+
/* 1 2 3 4 5 6 7 */
63+
/* 1234567890123456789012345678901234567890123456789012345678901234567890 */
64+
Case("ADD_DEL_test_00", cfstore_add_del_test_00),
65+
};
66+
67+
68+
/* Declare your test specification with a custom setup handler */
69+
Specification specification(greentea_setup, cases);
70+
71+
int main()
72+
{
73+
return !Harness::run(specification);
74+
}
75+
76+
77+
#else
78+
79+
80+
#include <stdio.h>
81+
#include <stdlib.h>
82+
#include <string.h>
83+
#include <inttypes.h>
84+
85+
#ifdef TARGET_LIKE_FRDM_K64F_GCC
86+
#include <mbed-drivers/mbed.h>
87+
#endif
88+
89+
#include "cfstore_config.h"
90+
//#include <flash-abstraction/Driver_Common.h>
91+
#include <Driver_Common.h>
92+
#include "cfstore_debug.h"
93+
#include "cfstore_test.h"
94+
#include <configuration-store/configuration_store.h>
95+
#include "utest/utest.h"
96+
#include "unity/unity.h"
97+
#include "greentea-client/test_env.h"
98+
#include "cfstore_utest.h"
99+
#ifdef YOTTA_CFG_CFSTORE_UVISOR
100+
#include "uvisor-lib/uvisor-lib.h"
101+
#include "cfstore_uvisor.h"
102+
#endif /* YOTTA_CFG_CFSTORE_UVISOR */
103+
104+
using namespace utest::v1;
105+
106+
static char cfstore_add_del_utest_msg_g[CFSTORE_UTEST_MSG_BUF_SIZE];
107+
108+
#ifdef YOTTA_CFG_CFSTORE_UVISOR
109+
/* Create the main box ACL list for the application.
110+
* The main ACL gets inherited by all the other boxes
111+
*/
112+
CFSTORE_UVISOR_MAIN_ACL(cfstore_acl_uvisor_box_add_del_g);
113+
114+
/* Enable uVisor. */
115+
UVISOR_SET_MODE_ACL(UVISOR_ENABLED, cfstore_acl_uvisor_box_add_del_g);
116+
#endif /* YOTTA_CFG_CFSTORE_UVISOR */
117+
118+
static cfstore_kv_data_t cfstore_add_del_test_07_data[] = {
119+
CFSTORE_INIT_1_TABLE_MID_NODE,
120+
{ NULL, NULL},
121+
};
122+
123+
124+
/* report whether built/configured for flash sync or async mode */
125+
static control_t cfstore_add_del_test_00(const size_t call_count)
126+
{
127+
(void) call_count;
128+
ARM_CFSTORE_CAPABILITIES caps = cfstore_driver.GetCapabilities();
129+
CFSTORE_LOG("INITIALIZING: caps.asynchronous_ops=%lu\n", caps.asynchronous_ops);
130+
return CaseNext;
131+
}
132+
133+
/**
134+
* @brief test to open() a pre-existing key and try to write it, which should fail
135+
*
136+
* @return status code
137+
* ARM_DRIVER_OK, the test passed successfully
138+
* ret < ARM_DRIVER_OK, the test failed with the return code
139+
* supplying more details
140+
*/
141+
static control_t cfstore_add_del_test_01_end(const size_t call_count)
142+
{
143+
bool bfound = false;
144+
int32_t ret = ARM_DRIVER_ERROR;
145+
ARM_CFSTORE_SIZE len = 0;
146+
ARM_CFSTORE_DRIVER* drv = &cfstore_driver;
147+
ARM_CFSTORE_KEYDESC kdesc;
148+
ARM_CFSTORE_HANDLE_INIT(hkey);
149+
ARM_CFSTORE_FMODE flags;
150+
151+
CFSTORE_FENTRYLOG("%s:entered\n", __func__);
152+
(void) call_count;
153+
CFSTORE_LOG("cfstore_add_del_test_07: Start%s", "\n");
154+
memset(&kdesc, 0, sizeof(kdesc));
155+
memset(&flags, 0, sizeof(flags));
156+
157+
kdesc.drl = ARM_RETENTION_WHILE_DEVICE_ACTIVE;
158+
len = strlen(cfstore_add_del_test_07_data[0].value);
159+
160+
ret = cfstore_test_create(cfstore_add_del_test_07_data[0].key_name, (char*) cfstore_add_del_test_07_data[0].value, &len, &kdesc);
161+
CFSTORE_TEST_UTEST_MESSAGE(cfstore_add_del_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to create KV in store (ret=%" PRId32 ").\n", __func__, ret);
162+
TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_add_del_utest_msg_g);
163+
164+
/* now delete KV*/
165+
ret = drv->Open(cfstore_add_del_test_07_data[0].key_name, flags, hkey);
166+
CFSTORE_TEST_UTEST_MESSAGE(cfstore_add_del_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to Open() (ret=%" PRId32 ").\n", __func__, ret);
167+
TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_add_del_utest_msg_g);
168+
169+
if(hkey != NULL){
170+
ret = drv->Delete(hkey);
171+
drv->Close(hkey);
172+
hkey = NULL;
173+
}
174+
/* check that the KV has been deleted */
175+
printf("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);
176+
ret = cfstore_test_kv_is_found(cfstore_add_del_test_07_data[0].key_name, &bfound);
177+
CFSTORE_TEST_UTEST_MESSAGE(cfstore_add_del_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error failed to delete a key (ret=%" PRId32 ").\n", __func__, ret);
178+
TEST_ASSERT_MESSAGE(ret == ARM_CFSTORE_DRIVER_ERROR_KEY_NOT_FOUND, cfstore_add_del_utest_msg_g);
179+
180+
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);
181+
TEST_ASSERT_MESSAGE(bfound == false, cfstore_add_del_utest_msg_g);
182+
183+
ret = drv->Uninitialize();
184+
CFSTORE_TEST_UTEST_MESSAGE(cfstore_add_del_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Uninitialize() call failed.\n", __func__);
185+
TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_add_del_utest_msg_g);
186+
return CaseNext;
187+
}
188+
189+
190+
static cfstore_kv_data_t cfstore_add_del_test_08_data[] = {
191+
CFSTORE_INIT_1_TABLE_HEAD,
192+
CFSTORE_INIT_1_TABLE_MID_NODE,
193+
CFSTORE_INIT_1_TABLE_TAIL,
194+
{ NULL, NULL},
195+
};
196+
197+
198+
/**
199+
* @brief test to add small number of KVs e.g. 3, and then delete them.
200+
* basic delete test:
201+
* - add key(s)
202+
* - delete key(s)
203+
* - make sure can't find key in cfstore
204+
*
205+
* @return status code
206+
* ARM_DRIVER_OK, the test passed successfully
207+
* ret < ARM_DRIVER_OK, the test failed with the return code
208+
* supplying more details
209+
*/
210+
static control_t cfstore_add_del_test_02_end(const size_t call_count)
211+
{
212+
bool bResult = true; // We'll do "&=" cumulative checking.
213+
int32_t ret = ARM_DRIVER_ERROR;
214+
ARM_CFSTORE_SIZE len = 0;
215+
ARM_CFSTORE_KEYDESC kdesc;
216+
cfstore_kv_data_t* node = NULL;
217+
ARM_CFSTORE_DRIVER* drv = &cfstore_driver;
218+
219+
CFSTORE_FENTRYLOG("%s:entered\n", __func__);
220+
(void) call_count;
221+
CFSTORE_LOG("%s: Start\n", __func__);
222+
memset(&kdesc, 0, sizeof(kdesc));
223+
224+
/* create */
225+
kdesc.drl = ARM_RETENTION_WHILE_DEVICE_ACTIVE;
226+
node = cfstore_add_del_test_08_data;
227+
while(node->key_name != NULL)
228+
{
229+
len = strlen(node->value);
230+
ret = cfstore_test_create(node->key_name, (char*) node->value, &len, &kdesc);
231+
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);
232+
TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_add_del_utest_msg_g);
233+
CFSTORE_LOG("Created KV successfully (key_name=\"%s\", value=\"%s\")\n", node->key_name, node->value);
234+
node++;
235+
}
236+
237+
/* test delete all */
238+
ret = cfstore_test_delete_all();
239+
CFSTORE_TEST_UTEST_MESSAGE(cfstore_add_del_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to delete all KVs.\n", __func__);
240+
TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_add_del_utest_msg_g);
241+
242+
/* check there are no KVs present as expected */
243+
node = cfstore_add_del_test_08_data;
244+
while(node->key_name != NULL)
245+
{
246+
ret = cfstore_test_kv_is_found(node->key_name, &bResult);
247+
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__);
248+
TEST_ASSERT_MESSAGE(ret == ARM_CFSTORE_DRIVER_ERROR_KEY_NOT_FOUND && bResult == false, cfstore_add_del_utest_msg_g);
249+
CFSTORE_LOG("Found KV successfully (key_name=\"%s\")\n", node->key_name);
250+
node++;
251+
}
252+
ret = drv->Uninitialize();
253+
CFSTORE_TEST_UTEST_MESSAGE(cfstore_add_del_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Uninitialize() call failed.\n", __func__);
254+
TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_add_del_utest_msg_g);
255+
return CaseNext;
256+
}
257+
258+
/**
259+
* @brief add ~50 KVs, and then delete entries at the start, middle and end of sram area
260+
*
261+
* @return status code
262+
* ARM_DRIVER_OK, the test passed successfully
263+
* ret < ARM_DRIVER_OK, the test failed with the return code
264+
* supplying more details
265+
*/
266+
static control_t cfstore_add_del_test_03_end(const size_t call_count)
267+
{
268+
bool bfound = false;
269+
int32_t ret = ARM_DRIVER_ERROR;
270+
ARM_CFSTORE_FMODE flags;
271+
cfstore_kv_data_t *node;
272+
ARM_CFSTORE_DRIVER* drv = &cfstore_driver;
273+
274+
CFSTORE_FENTRYLOG("%s:entered\n", __func__);
275+
(void) call_count;
276+
memset(&flags, 0, sizeof(flags));
277+
278+
ret = cfstore_test_init_1();
279+
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__);
280+
TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_add_del_utest_msg_g);
281+
282+
/* delete some keys */
283+
node = cfstore_add_del_test_08_data;
284+
while(node->key_name != NULL)
285+
{
286+
CFSTORE_DBGLOG("%s:about to delete key (key_name=%s).\n", __func__, node->key_name);
287+
cfstore_test_delete(node->key_name);
288+
CFSTORE_TEST_UTEST_MESSAGE(cfstore_add_del_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error failed to delete a key (ret=%" PRId32 ").\n", __func__, ret);
289+
TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_add_del_utest_msg_g);
290+
CFSTORE_LOG("Deleted KV successfully (key_name=\"%s\")\n", node->key_name);
291+
node++;
292+
}
293+
/* check the keys have been deleted */
294+
node = cfstore_add_del_test_08_data;
295+
while(node->key_name != NULL)
296+
{
297+
ret = cfstore_test_kv_is_found(node->key_name, &bfound);
298+
CFSTORE_TEST_UTEST_MESSAGE(cfstore_add_del_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to delete a key (ret=%" PRId32 ").\n", __func__, ret);
299+
TEST_ASSERT_MESSAGE(ret == ARM_CFSTORE_DRIVER_ERROR_KEY_NOT_FOUND, cfstore_add_del_utest_msg_g);
300+
301+
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);
302+
TEST_ASSERT_MESSAGE(bfound == false, cfstore_add_del_utest_msg_g);
303+
node++;
304+
}
305+
306+
/* clean up by deleting all remaining KVs. this is not part of the test */
307+
ret = cfstore_test_delete_all();
308+
CFSTORE_TEST_UTEST_MESSAGE(cfstore_add_del_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error failed to delete a all KVs (ret=%" PRId32 ").\n", __func__, ret);
309+
TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_add_del_utest_msg_g);
310+
311+
ret = drv->Uninitialize();
312+
CFSTORE_TEST_UTEST_MESSAGE(cfstore_add_del_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to initialize CFSTORE (ret=%" PRId32 ")\n", __func__, ret);
313+
TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_add_del_utest_msg_g);
314+
return CaseNext;
315+
}
316+
317+
318+
/**
319+
* @brief test as per test_09 but using delete_all() on all init_1 data.
320+
*
321+
* @return status code
322+
* ARM_DRIVER_OK, the test passed successfully
323+
* ret < ARM_DRIVER_OK, the test failed with the return code
324+
* supplying more details
325+
*/
326+
static control_t cfstore_add_del_test_04(const size_t call_count)
327+
{
328+
(void) call_count;
329+
/*todo: implement test */
330+
CFSTORE_TEST_UTEST_MESSAGE(cfstore_add_del_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Warn: Not implemented\n", __func__);
331+
CFSTORE_LOG("%s: WARN: requires implementation\n", __func__);
332+
TEST_ASSERT_MESSAGE(true, cfstore_add_del_utest_msg_g);
333+
return CaseNext;
334+
}
335+
336+
337+
utest::v1::status_t greentea_setup(const size_t number_of_cases)
338+
{
339+
GREENTEA_SETUP(100, "default_auto");
340+
return greentea_test_setup_handler(number_of_cases);
341+
}
342+
343+
Case cases[] = {
344+
/* 1 2 3 4 5 6 7 */
345+
/* 1234567890123456789012345678901234567890123456789012345678901234567890 */
346+
Case("ADD_DEL_test_00", cfstore_add_del_test_00),
347+
Case("ADD_DEL_test_01_start", cfstore_utest_default_start),
348+
Case("ADD_DEL_test_01_end", cfstore_add_del_test_01_end),
349+
Case("ADD_DEL_test_02_start", cfstore_utest_default_start),
350+
Case("ADD_DEL_test_02_end", cfstore_add_del_test_02_end),
351+
Case("ADD_DEL_test_03_start", cfstore_utest_default_start),
352+
Case("ADD_DEL_test_03_end", cfstore_add_del_test_03_end),
353+
Case("ADD_DEL_test_04", cfstore_add_del_test_04),
354+
};
355+
356+
357+
/* Declare your test specification with a custom setup handler */
358+
Specification specification(greentea_setup, cases);
359+
360+
#if defined CFSTORE_CONFIG_MBED_OS_VERSION && CFSTORE_CONFIG_MBED_OS_VERSION == 3
361+
/* mbedosV3*/
362+
void app_start(int argc __unused, char** argv __unused)
363+
{
364+
/* Run the test specification */
365+
Harness::run(specification);
366+
}
367+
#endif /* CFSTORE_CONFIG_MBED_OS_VERSION == 3 */
368+
369+
#if defined CFSTORE_CONFIG_MBED_OS_VERSION && CFSTORE_CONFIG_MBED_OS_VERSION == 4
370+
/* mbedosV3++*/
371+
int main()
372+
{
373+
return !Harness::run(specification);
374+
}
375+
#endif /* CFSTORE_CONFIG_MBED_OS_VERSION == 4 */
376+
377+
378+
#endif // __MBED__ && ! defined TOOLCHAIN_GCC_ARM

0 commit comments

Comments
 (0)