Skip to content

Commit 2d1548f

Browse files
Merge pull request #274 from PrzemekWirkus/devel_gt_rebase_09062016
[test porting] Development branch rebase 09/06/2016
2 parents 76dc58f + 3b3745e commit 2d1548f

File tree

293 files changed

+102222
-336
lines changed

Some content is hidden

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

293 files changed

+102222
-336
lines changed

Jenkinsfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ try {
4848
dir("mbed-os") {
4949
checkout scm
5050
sh "mbed deploy --protocol ssh"
51-
sh "mbed compile -m ${target} -t ${toolchain} -c"
51+
sh "mbed compile --tests -m ${target} -t ${toolchain} -c"
5252
}
5353
}
5454
}

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[![CircleCI](https://circleci.com/gh/ARMmbed/mbed-os.svg?style=svg)](https://circleci.com/gh/ARMmbed/mbed-os)
2+
3+
---
4+
5+
# mbed-os

TESTS/cfstore/add_del/add_del.cpp

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

0 commit comments

Comments
 (0)