diff --git a/.astyleignore b/.astyleignore index deb5634..8a75ff1 100644 --- a/.astyleignore +++ b/.astyleignore @@ -16,7 +16,6 @@ ^features/nanostack/sal-stack-nanostack ^features/nanostack/targets ^features/netsocket/emac-drivers -^features/storage/FEATURE_STORAGE ^features/storage/filesystem/fat/ChaN ^features/storage/filesystem/littlefs/littlefs/ ^features/unsupported/ diff --git a/doxyfile_options b/doxyfile_options index 0914f29..b74069e 100644 --- a/doxyfile_options +++ b/doxyfile_options @@ -843,8 +843,6 @@ */cmsis/* \ */features/cryptocell/* \ */features/mbedtls/* \ - */features/storage/cfstore/* \ - */features/storage/FEATURE_STORAGE/* \ */features/unsupported/* \ */features/lwipstack/* \ */features/nanostack/sal-stack-nanostack/* \ diff --git a/doxygen_options.json b/doxygen_options.json index 31f805d..156f42c 100644 --- a/doxygen_options.json +++ b/doxygen_options.json @@ -10,7 +10,7 @@ "EXPAND_AS_DEFINED": "", "SKIP_FUNCTION_MACROS": "NO", "STRIP_CODE_COMMENTS": "NO", - "EXCLUDE_PATTERNS": "*/tools/* */targets/* */features/mbedtls/* */features/storage/cfstore/* */features/storage/FEATURE_STORAGE/* */features/unsupported/* */BUILD/* */rtos/TARGET_CORTEX/rtx*/* */cmsis/* */features/lwipstack/* */nanostack/sal-stack-nanostack/* */nanostack/coap-service/* */ble/generic/* */ble/pal/* */mbed-trace/* */mbed-coap/* */nanostack-libservice/* */mbed-client-randlib/* */nanostack/sal-stack-nanostack-eventloop/* */components/802.15.4_RF/* */components/wifi/* */features/nfc/stack/* */UNITTESTS/* */features/cryptocell/*", + "EXCLUDE_PATTERNS": "*/tools/* */targets/* */features/mbedtls/* */features/unsupported/* */BUILD/* */rtos/TARGET_CORTEX/rtx*/* */cmsis/* */features/lwipstack/* */nanostack/sal-stack-nanostack/* */nanostack/coap-service/* */ble/generic/* */ble/pal/* */mbed-trace/* */mbed-coap/* */nanostack-libservice/* */mbed-client-randlib/* */nanostack/sal-stack-nanostack-eventloop/* */components/802.15.4_RF/* */components/wifi/* */features/nfc/stack/* */UNITTESTS/* */features/cryptocell/*", "ALPHABETICAL_INDEX": "NO", "CASE_SENSE_NAMES": "NO", "DOT_MULTI_TARGETS": "YES", diff --git a/features/nanostack/nanostack-hal-mbed-cmsis-rtos/cs_nvm/cs_nvm.c b/features/nanostack/nanostack-hal-mbed-cmsis-rtos/cs_nvm/cs_nvm.c deleted file mode 100644 index 4b9eed9..0000000 --- a/features/nanostack/nanostack-hal-mbed-cmsis-rtos/cs_nvm/cs_nvm.c +++ /dev/null @@ -1,663 +0,0 @@ -/* - * Copyright (c) 2016, 2018, Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * NVM adaptation to Configuration Store that is storing Key-Value pairs to SRAM or flash. - */ - -/* - * Application needs to enable MBED_CONF_NANOSTACK_HAL_NVM_CFSTORE in its configuration in - * order to use configuration-store. Application also needs to define storage area start - * address in flash (CONFIG_HARDWARE_MTD_START_ADDR) and storage size (CONFIG_HARDWARE_MTD_SIZE). - */ -#if MBED_CONF_NANOSTACK_HAL_NVM_CFSTORE - -#include -#include -#include -#include "configuration-store/configuration_store.h" -// #define HAVE_DEBUG -#include "ns_trace.h" -#include "nsdynmemLIB.h" -#include "eventOS_event_timer.h" -#include "platform/arm_hal_nvm.h" - -#define TRACE_GROUP "pnvm" - -// Timeout for polling response from configuration store -#define NVM_CB_POLLING_TIMEOUT 50 - -// Check if synchronous mode is enabled -#define IS_SYNC_MODE(cs_ctx) ((cs_ctx)->capabilities.asynchronous_ops == 0) - -// NVM internal states -typedef enum cfstore_state_t { - NVM_STATE_NONE, - NVM_STATE_INIT_DONE, - NVM_STATE_CREATING, - NVM_STATE_CREATE_DONE, - NVM_STATE_OPENING, - NVM_STATE_OPEN_DONE, - NVM_STATE_WRITING, - NVM_STATE_WRITE_DONE, - NVM_STATE_CLOSING, - NVM_STATE_CLOSE_DONE, - NVM_STATE_FLUSHING, - NVM_STATE_FLUSH_DONE, - NVM_STATE_READING, - NVM_STATE_READ_DONE, - NVM_STATE_DELETING, - NVM_STATE_DELETE_DONE, - NVM_STATE_UNINITIALIZING, - NVM_STATE_UNINIT_DONE -} nvm_state_e; - -// NVM context -typedef struct cfstore_context_s { - ARM_CFSTORE_CAPABILITIES capabilities; - //TODO: Fix hkey length once CFSTORE_HANDLE_BUFSIZE becomes visible - uint8_t hkey[/*CFSTORE_HANDLE_BUFSIZE*/40]; // Handle to the key in process - ARM_CFSTORE_SIZE data_len; // Data length cfstore is using - nvm_state_e state; // current nvm_state_e - timeout_t *callback_timer; // timer handle for informing client - nvm_callback *client_cb; // callback provided by client - void *client_context; // context provided by client - platform_nvm_status client_status; // status to be returned to client - uint8_t *client_buf; // buffer provided by client - uint16_t *client_buf_len; // client buffer length -} cs_context_t; - -ARM_CFSTORE_DRIVER *drv = &cfstore_driver; -static cs_context_t *cs_context_ptr = NULL; - -// forward declarations -static bool nvm_write_internal(cs_context_t *cf_context); -static bool nvm_read_internal(cs_context_t *cf_context); -static bool nvm_delete_internal(cs_context_t *cf_context); -static bool nvm_close_internal(cs_context_t *cf_context); -static bool nvm_status_check(cs_context_t *cf_context); -static platform_nvm_status nvm_error_map(int32_t cs_error); -static void nvm_fsm_timer_start(void); -static void nvm_fsm_timer_cb(void *arg); - -/** - * Configuration store callback - */ -static void configuration_store_cb(int32_t status, ARM_CFSTORE_OPCODE cmd_code, void *ctx, ARM_CFSTORE_HANDLE handle) -{ - tr_debug("configuration_store_cb status=%d, cmd_code=%d, ctx=%x, hndl=%x", (int)status, (int)cmd_code, (unsigned int)ctx, (unsigned int)handle); - cs_context_t *cf_context = (cs_context_t *)ctx; - - switch (cmd_code) { - case CFSTORE_OPCODE_INITIALIZE: - tr_debug("CFSTORE_OPCODE_INITIALIZE %d", (int)status); - cf_context->state = NVM_STATE_INIT_DONE; - cf_context->client_status = nvm_error_map(status); - break; - case CFSTORE_OPCODE_POWER_CONTROL: - tr_debug("CFSTORE_OPCODE_POWER_CONTROL %d", (int)status); - // do nothing for power control - break; - case CFSTORE_OPCODE_CREATE: - tr_debug("CFSTORE_OPCODE_CREATE %d", (int)status); - cf_context->client_status = nvm_error_map(status); - cf_context->state = NVM_STATE_CREATE_DONE; - if (status >= ARM_DRIVER_OK) { - // key created successfully, close the key - if (nvm_close_internal(cf_context) == false) { - // closing failed - // Ignore errors in close as closing recreated keys returns error - // cf_context->state = NVM_STATE_CLOSE_DONE; - // cf_context->client_status = PLATFORM_NVM_ERROR; - } else { - // closing OK, wait for CFSTORE_OPCODE_CLOSE callback - } - } - break; - case CFSTORE_OPCODE_OPEN: - tr_debug("CFSTORE_OPCODE_OPEN %d", (int)status); - if (status < ARM_DRIVER_OK) { - // opening failed, do not continue any further - cf_context->client_status = nvm_error_map(status); - cf_context->state = NVM_STATE_OPEN_DONE; - break; - } - // proceed to client action read/write/delete - if (cf_context->state == NVM_STATE_WRITING) { - if (nvm_write_internal(cf_context) == false) { - /* reading failed set client_status */ - cf_context->client_status = PLATFORM_NVM_ERROR; - } else { - // writing OK, wait for CFSTORE_OPCODE_WRITE callback - } - } else if (cf_context->state == NVM_STATE_READING) { - if (nvm_read_internal(cf_context) == false) { - /* reading failed set client_status */ - cf_context->client_status = PLATFORM_NVM_ERROR; - } else { - // reading in progress, wait for CFSTORE_OPCODE_READ callback - } - } else if (cf_context->state == NVM_STATE_DELETING) { - if (nvm_delete_internal(cf_context) == false) { - /* reading failed set client_status */ - cf_context->client_status = PLATFORM_NVM_ERROR; - } else { - // deleting in progress, wait for CFSTORE_OPCODE_DELETE callback - } - } - - if (cf_context->client_status == PLATFORM_NVM_ERROR) { - // read/write/delete operation failed, close the handle - if (nvm_close_internal(cf_context) == false) { - cf_context->state = NVM_STATE_CLOSE_DONE; - cf_context->client_status = PLATFORM_NVM_ERROR; - } - } - break; - case CFSTORE_OPCODE_WRITE: - tr_debug("CFSTORE_OPCODE_WRITE %d", (int)status); - cf_context->state = NVM_STATE_WRITE_DONE; - *cf_context->client_buf_len = cf_context->data_len; - if (nvm_close_internal(cf_context) == false) { - /* writing failed set status and start callback timer */ - cf_context->state = NVM_STATE_CLOSE_DONE; - cf_context->client_status = PLATFORM_NVM_ERROR; - } else { - // closing OK, wait for CFSTORE_OPCODE_CLOSE callback - } - break; - case CFSTORE_OPCODE_READ: - tr_debug("CFSTORE_OPCODE_READ %d", (int)status); - cf_context->state = NVM_STATE_READ_DONE; - if (nvm_close_internal(cf_context) == false) { - cf_context->state = NVM_STATE_CLOSE_DONE; - cf_context->client_status = PLATFORM_NVM_ERROR; - } else { - // closing OK, wait for CFSTORE_OPCODE_CLOSE callback - *cf_context->client_buf_len = (uint16_t)status; // save the bytes read - } - break; - case CFSTORE_OPCODE_DELETE: - tr_debug("CFSTORE_OPCODE_DELETE %d", (int)status); - if (nvm_close_internal(cf_context) == false) { - /* closing failed set client_status */ - cf_context->state = NVM_STATE_CLOSE_DONE; - cf_context->client_status = PLATFORM_NVM_ERROR; - } else { - // closing OK, wait for CFSTORE_OPCODE_CLOSE callback - } - break; - case CFSTORE_OPCODE_CLOSE: - tr_debug("CFSTORE_OPCODE_CLOSE %d", (int)status); - cf_context->state = NVM_STATE_CLOSE_DONE; - // client_status is already set by read/write/delete operation, do not override it - break; - case CFSTORE_OPCODE_UNINITIALIZE: - tr_debug("CFSTORE_OPCODE_UNINITIALIZE %d", (int)status); - cf_context->state = NVM_STATE_UNINIT_DONE; - cf_context->client_status = nvm_error_map(status); - break; - case CFSTORE_OPCODE_FLUSH: - tr_debug("CFSTORE_OPCODE_FLUSH %d", (int)status); - cf_context->state = NVM_STATE_FLUSH_DONE; - cf_context->client_status = nvm_error_map(status); - break; - - default: - tr_debug("unhandled cmd_code %d", cmd_code); - break; - } - - return; -} - -static int nvm_fsm_update(cs_context_t *cs_context) -{ - int ret_val = 0; - - tr_debug("nvm_fsm_update() state=%d", (int)cs_context->state); - switch (cs_context->state) { - case NVM_STATE_UNINIT_DONE: - cs_context->client_cb(cs_context->client_status, cs_context->client_context); - cs_context->state = NVM_STATE_NONE; - if (cs_context->client_status == PLATFORM_NVM_OK) { - ns_dyn_mem_free(cs_context_ptr); - cs_context_ptr = NULL; - } - ret_val = 1; - break; - case NVM_STATE_INIT_DONE: - case NVM_STATE_CREATE_DONE: - case NVM_STATE_OPEN_DONE: - case NVM_STATE_WRITE_DONE: - case NVM_STATE_READ_DONE: - case NVM_STATE_DELETE_DONE: - case NVM_STATE_CLOSE_DONE: - case NVM_STATE_FLUSH_DONE: - cs_context->state = NVM_STATE_NONE; - cs_context->client_cb(cs_context->client_status, cs_context->client_context); - ret_val = 1; - break; - - default: - tr_error("unknown state %d", cs_context->state); - break; - } - - return ret_val; -} - -/** - * Initialize NVM - */ -platform_nvm_status platform_nvm_init(nvm_callback *callback, void *context) -{ - int32_t ret; - - tr_debug("platform_nvm_init()"); - - if (callback == NULL || cs_context_ptr) { - return PLATFORM_NVM_ERROR; - } - - if (cs_context_ptr == NULL) { - cs_context_ptr = ns_dyn_mem_alloc(sizeof(cs_context_t)); - } - - if (cs_context_ptr == NULL) { - return PLATFORM_NVM_ERROR; - } - - memset(cs_context_ptr, 0, sizeof(cs_context_t)); - cs_context_ptr->client_cb = callback; - cs_context_ptr->client_context = context; - - cs_context_ptr->capabilities = drv->GetCapabilities(); - - tr_debug("mode: %s", IS_SYNC_MODE(cs_context_ptr) ? "sync" : "async"); - - ret = drv->Initialize(configuration_store_cb, cs_context_ptr); - if (ret < ARM_DRIVER_OK) { - tr_error("initialisation failed %d", (int)ret); - ns_dyn_mem_free(cs_context_ptr); - cs_context_ptr = NULL; - return PLATFORM_NVM_ERROR; - } - - drv->PowerControl(ARM_POWER_FULL); - - // start timer to report initialization status back to client - nvm_fsm_timer_start(); - return PLATFORM_NVM_OK; -} - -/* - * Deinitialize NVM. - */ -platform_nvm_status platform_nvm_finalize(nvm_callback *callback, void *context) -{ - int32_t ret; - - tr_debug("platform_nvm_deinit()"); - - if (!nvm_status_check(cs_context_ptr)) { - return PLATFORM_NVM_ERROR; - } - - if (callback == NULL) { - return PLATFORM_NVM_ERROR; - } - - cs_context_ptr->client_cb = callback; - cs_context_ptr->client_context = context; - cs_context_ptr->state = NVM_STATE_UNINITIALIZING; - cs_context_ptr->client_status = PLATFORM_NVM_OK; - drv->PowerControl(ARM_POWER_OFF); - ret = drv->Uninitialize(); - - if (ret < ARM_DRIVER_OK) { - tr_error("deinit failed %d", (int)ret); - cs_context_ptr->state = NVM_STATE_UNINIT_DONE; - cs_context_ptr->client_status = nvm_error_map(ret); - } - - nvm_fsm_timer_start(); - return PLATFORM_NVM_OK; -} - -/* - * Create key to NVM - */ -platform_nvm_status platform_nvm_key_create(nvm_callback *callback, const char *key_name, uint16_t value_len, uint32_t flags, void *context) -{ - int32_t ret; - ARM_CFSTORE_KEYDESC keydesc; - (void)flags; - - tr_debug("platform_nvm_key_create() %s len=%d", key_name, value_len); - - if (callback == NULL || key_name == NULL) { - return PLATFORM_NVM_ERROR; - } - - if (!nvm_status_check(cs_context_ptr)) { - return PLATFORM_NVM_ERROR; - } - - cs_context_ptr->client_cb = callback; - cs_context_ptr->client_context = context; - cs_context_ptr->state = NVM_STATE_CREATING; - cs_context_ptr->client_status = PLATFORM_NVM_OK; - - memset(&keydesc, 0, sizeof(ARM_CFSTORE_KEYDESC)); - keydesc.drl = ARM_RETENTION_NVM; - - ret = drv->Create(key_name, value_len, &keydesc, cs_context_ptr->hkey); - if (ret < ARM_DRIVER_OK) { - if (ret == ARM_CFSTORE_DRIVER_ERROR_PREEXISTING_KEY) { - tr_debug("adjust value len to %d", value_len); - ret = drv->Create(key_name, value_len, NULL, cs_context_ptr->hkey); - } - } - - if (ret < ARM_DRIVER_OK) { - tr_error("Key creation failed %d", (int)ret); - cs_context_ptr->state = NVM_STATE_CREATE_DONE; - cs_context_ptr->client_status = nvm_error_map(ret); - } - - nvm_fsm_timer_start(); - - return PLATFORM_NVM_OK; -} - -/** - * Delete key from NVM - */ -platform_nvm_status platform_nvm_key_delete(nvm_callback *callback, const char *key_name, void *context) -{ - int32_t ret; - ARM_CFSTORE_FMODE flags; - - tr_debug("platform_nvm_key_delete() %s", key_name); - - if (callback == NULL || key_name == NULL) { - return PLATFORM_NVM_ERROR; - } - - if (!nvm_status_check(cs_context_ptr)) { - return PLATFORM_NVM_ERROR; - } - - cs_context_ptr->client_cb = callback; - cs_context_ptr->client_context = context; - cs_context_ptr->client_status = PLATFORM_NVM_OK; - cs_context_ptr->state = NVM_STATE_DELETING; - - memset(&flags, 0, sizeof(ARM_CFSTORE_FMODE)); - flags.read = 1; - flags.write = 1; - ret = drv->Open(key_name, flags, cs_context_ptr->hkey); - - if (ret < ARM_DRIVER_OK) { - tr_error("Key delete, open failed %d", (int)ret); - cs_context_ptr->state = NVM_STATE_DELETE_DONE; - cs_context_ptr->client_status = nvm_error_map(ret); - } - - // start callback timer in both asynch and synch mode - nvm_fsm_timer_start(); - - return PLATFORM_NVM_OK; -} - -/** - * Reading from NVM - */ -platform_nvm_status platform_nvm_read(nvm_callback *callback, const char *key_name, void *buf, uint16_t *buf_len, void *context) -{ - int32_t ret; - ARM_CFSTORE_FMODE flags; - - tr_debug("platform_nvm_read()"); - - if (callback == NULL || key_name == NULL || buf == NULL || buf_len == NULL) { - return PLATFORM_NVM_ERROR; - } - - if (!nvm_status_check(cs_context_ptr)) { - return PLATFORM_NVM_ERROR; - } - cs_context_ptr->client_cb = callback; - cs_context_ptr->client_context = context; - cs_context_ptr->client_buf = buf; - cs_context_ptr->client_buf_len = buf_len; - cs_context_ptr->data_len = *buf_len; - cs_context_ptr->client_status = PLATFORM_NVM_OK; - cs_context_ptr->state = NVM_STATE_READING; - - // Open handle for reading - memset(&flags, 0, sizeof(ARM_CFSTORE_FMODE)); - flags.read = 1; - ret = drv->Open(key_name, flags, cs_context_ptr->hkey); - - if (ret < ARM_DRIVER_OK) { - tr_error("Read failed to open handle %d", (int)ret); - cs_context_ptr->state = NVM_STATE_READ_DONE; - cs_context_ptr->client_status = nvm_error_map(ret); - } - - // start callback timer in both async and synch mode - nvm_fsm_timer_start(); - - return PLATFORM_NVM_OK; -} - -/** - * Write to NVM. - */ -platform_nvm_status platform_nvm_write(nvm_callback *callback, const char *key_name, const void *data, uint16_t *data_len, void *context) -{ - int32_t ret; - ARM_CFSTORE_FMODE flags; - tr_debug("platform_nvm_write()"); - - if (callback == NULL || key_name == NULL || data == NULL || data_len == NULL) { - return PLATFORM_NVM_ERROR; - } - - if (!nvm_status_check(cs_context_ptr)) { - return PLATFORM_NVM_ERROR; - } - cs_context_ptr->client_cb = callback; - cs_context_ptr->client_context = context; - cs_context_ptr->client_buf = (void *)data; - cs_context_ptr->client_buf_len = data_len; - cs_context_ptr->data_len = *data_len; - cs_context_ptr->client_status = PLATFORM_NVM_OK; - cs_context_ptr->state = NVM_STATE_WRITING; - - // Open handle for writing, execution continues in callback - memset(&flags, 0, sizeof(ARM_CFSTORE_FMODE)); - flags.write = 1; - ret = drv->Open(key_name, flags, cs_context_ptr->hkey); - - if (ret < ARM_DRIVER_OK) { - tr_error("Write failed %d", (int)ret); - cs_context_ptr->state = NVM_STATE_WRITE_DONE; - cs_context_ptr->client_status = nvm_error_map(ret); - } - - // start callback timer in both asynch and synch mode - nvm_fsm_timer_start(); - - return PLATFORM_NVM_OK; -} - -/** - * Flush the NVM - */ -platform_nvm_status platform_nvm_flush(nvm_callback *callback, void *context) -{ - tr_debug("platform_nvm_flush()"); - - int32_t ret; - - if (callback == NULL) { - return PLATFORM_NVM_ERROR; - } - - if (!nvm_status_check(cs_context_ptr)) { - return PLATFORM_NVM_ERROR; - } - - cs_context_ptr->client_cb = callback; - cs_context_ptr->client_context = context; - cs_context_ptr->client_status = PLATFORM_NVM_OK; - cs_context_ptr->state = NVM_STATE_FLUSHING; - - ret = drv->Flush(); - - if (ret < ARM_DRIVER_OK) { - cs_context_ptr->state = NVM_STATE_FLUSH_DONE; - cs_context_ptr->client_status = nvm_error_map(ret); - } - - // start callback timer in both asynch and synch mode - nvm_fsm_timer_start(); - - return PLATFORM_NVM_OK; -} - -static bool nvm_write_internal(cs_context_t *cf_context) -{ - int32_t ret; - cf_context->state = NVM_STATE_WRITING; - ret = drv->Write(cf_context->hkey, (const char *)cf_context->client_buf, &cf_context->data_len); - - if (ret >= ARM_DRIVER_OK) { - return true; - } else { - tr_error("Write failed %d", (int)ret); - return false; - } -} - -static bool nvm_read_internal(cs_context_t *cf_context) -{ - int32_t ret; - cf_context->state = NVM_STATE_READING; - ret = drv->Read(cf_context->hkey, (void *)cf_context->client_buf, &cf_context->data_len); - - if (ret >= ARM_DRIVER_OK) { - return true; - } else { - tr_error("Read failed %d", (int)ret); - return false; - } -} - -static bool nvm_delete_internal(cs_context_t *cf_context) -{ - int32_t ret; - cf_context->state = NVM_STATE_DELETING; - ret = drv->Delete(cf_context->hkey); - - if (ret >= ARM_DRIVER_OK) { - return true; - } else { - tr_error("Delete failed %d", (int)ret); - return false; - } -} - -static bool nvm_close_internal(cs_context_t *cf_context) -{ - int32_t ret; - cf_context->state = NVM_STATE_CLOSING; - ret = drv->Close(cf_context->hkey); - - if (ret >= ARM_DRIVER_OK) { - return true; - } else { - tr_error("Close failed %d", (int)ret); - return false; - } -} - -/* - * Check NVM state before executing client action - */ -static bool nvm_status_check(cs_context_t *cf_context) -{ - if (!cs_context_ptr) { - // not initialized - tr_error("NVM not initialized"); - return false; - } - - if (cf_context->state != NVM_STATE_NONE) { - tr_error("NVM busy, operation in progress %d", cf_context->state); - return false; - } - - return true; -} - -static platform_nvm_status nvm_error_map(int32_t cs_error) -{ - platform_nvm_status client_error; - - if (cs_error >= ARM_DRIVER_OK) { - return PLATFORM_NVM_OK; - } - - switch (cs_error) { - case ARM_CFSTORE_DRIVER_ERROR_KEY_NOT_FOUND: - client_error = PLATFORM_NVM_KEY_NOT_FOUND; - break; - default: - client_error = PLATFORM_NVM_ERROR; - break; - } - - return client_error; -} - -static void nvm_fsm_timer_cb(void *args) -{ - (void) args; - switch (nvm_fsm_update(cs_context_ptr)) { - case 0: - // Nothing processed, restart timer - tr_debug("nvm_fsm_timer_cb not handled event in () %d", (int)cs_context_ptr->state); - nvm_fsm_timer_start(); - break; - default: - break; - } -} - -/* - * Start timer for polling callback from - */ -static void nvm_fsm_timer_start(void) -{ - cs_context_ptr->callback_timer = eventOS_timeout_ms(nvm_fsm_timer_cb, NVM_CB_POLLING_TIMEOUT, NULL); -} - -#endif /* MBED_CONF_NANOSTACK_HAL_NVM_CFSTORE */ diff --git a/features/nanostack/nanostack-hal-mbed-cmsis-rtos/cs_nvm/test/test_cs_nvm_unit/unittest/MakefileWorker.mk b/features/nanostack/nanostack-hal-mbed-cmsis-rtos/cs_nvm/test/test_cs_nvm_unit/unittest/MakefileWorker.mk deleted file mode 100644 index 2096ced..0000000 --- a/features/nanostack/nanostack-hal-mbed-cmsis-rtos/cs_nvm/test/test_cs_nvm_unit/unittest/MakefileWorker.mk +++ /dev/null @@ -1,562 +0,0 @@ -#--------- -# -# MakefileWorker.mk -# -# Include this helper file in your makefile -# It makes -# A static library -# A test executable -# -# See this example for parameter settings -# examples/Makefile -# -#---------- -# Inputs - these variables describe what to build -# -# INCLUDE_DIRS - Directories used to search for include files. -# This generates a -I for each directory -# SRC_DIRS - Directories containing source file to built into the library -# SRC_FILES - Specific source files to build into library. Helpful when not all code -# in a directory can be built for test (hopefully a temporary situation) -# TEST_SRC_DIRS - Directories containing unit test code build into the unit test runner -# These do not go in a library. They are explicitly included in the test runner -# TEST_SRC_FILES - Specific source files to build into the unit test runner -# These do not go in a library. They are explicitly included in the test runner -# MOCKS_SRC_DIRS - Directories containing mock source files to build into the test runner -# These do not go in a library. They are explicitly included in the test runner -#---------- -# You can adjust these variables to influence how to build the test target -# and where to put and name outputs -# See below to determine defaults -# COMPONENT_NAME - the name of the thing being built -# TEST_TARGET - name the test executable. By default it is -# $(COMPONENT_NAME)_tests -# Helpful if you want 1 > make files in the same directory with different -# executables as output. -# CPPUTEST_HOME - where CppUTest home dir found -# TARGET_PLATFORM - Influences how the outputs are generated by modifying the -# CPPUTEST_OBJS_DIR and CPPUTEST_LIB_DIR to use a sub-directory under the -# normal objs and lib directories. Also modifies where to search for the -# CPPUTEST_LIB to link against. -# CPPUTEST_OBJS_DIR - a directory where o and d files go -# CPPUTEST_LIB_DIR - a directory where libs go -# CPPUTEST_ENABLE_DEBUG - build for debug -# CPPUTEST_USE_MEM_LEAK_DETECTION - Links with overridden new and delete -# CPPUTEST_USE_STD_CPP_LIB - Set to N to keep the standard C++ library out -# of the test harness -# CPPUTEST_USE_GCOV - Turn on coverage analysis -# Clean then build with this flag set to Y, then 'make gcov' -# CPPUTEST_MAPFILE - generate a map file -# CPPUTEST_WARNINGFLAGS - overly picky by default -# OTHER_MAKEFILE_TO_INCLUDE - a hook to use this makefile to make -# other targets. Like CSlim, which is part of fitnesse -# CPPUTEST_USE_VPATH - Use Make's VPATH functionality to support user -# specification of source files and directories that aren't below -# the user's Makefile in the directory tree, like: -# SRC_DIRS += ../../lib/foo -# It defaults to N, and shouldn't be necessary except in the above case. -#---------- -# -# Other flags users can initialize to sneak in their settings -# CPPUTEST_CXXFLAGS - flags for the C++ compiler -# CPPUTEST_CPPFLAGS - flags for the C++ AND C preprocessor -# CPPUTEST_CFLAGS - flags for the C complier -# CPPUTEST_LDFLAGS - Linker flags -#---------- - -# Some behavior is weird on some platforms. Need to discover the platform. - -# Platforms -UNAME_OUTPUT = "$(shell uname -a)" -MACOSX_STR = Darwin -MINGW_STR = MINGW -CYGWIN_STR = CYGWIN -LINUX_STR = Linux -SUNOS_STR = SunOS -UNKNWOWN_OS_STR = Unknown - -# Compilers -CC_VERSION_OUTPUT ="$(shell $(CXX) -v 2>&1)" -CLANG_STR = clang -SUNSTUDIO_CXX_STR = SunStudio - -UNAME_OS = $(UNKNWOWN_OS_STR) - -ifeq ($(findstring $(MINGW_STR),$(UNAME_OUTPUT)),$(MINGW_STR)) - UNAME_OS = $(MINGW_STR) -endif - -ifeq ($(findstring $(CYGWIN_STR),$(UNAME_OUTPUT)),$(CYGWIN_STR)) - UNAME_OS = $(CYGWIN_STR) -endif - -ifeq ($(findstring $(LINUX_STR),$(UNAME_OUTPUT)),$(LINUX_STR)) - UNAME_OS = $(LINUX_STR) -endif - -ifeq ($(findstring $(MACOSX_STR),$(UNAME_OUTPUT)),$(MACOSX_STR)) - UNAME_OS = $(MACOSX_STR) -#lion has a problem with the 'v' part of -a - UNAME_OUTPUT = "$(shell uname -pmnrs)" -endif - -ifeq ($(findstring $(SUNOS_STR),$(UNAME_OUTPUT)),$(SUNOS_STR)) - UNAME_OS = $(SUNOS_STR) - - SUNSTUDIO_CXX_ERR_STR = CC -flags -ifeq ($(findstring $(SUNSTUDIO_CXX_ERR_STR),$(CC_VERSION_OUTPUT)),$(SUNSTUDIO_CXX_ERR_STR)) - CC_VERSION_OUTPUT ="$(shell $(CXX) -V 2>&1)" - COMPILER_NAME = $(SUNSTUDIO_CXX_STR) -endif -endif - -ifeq ($(findstring $(CLANG_STR),$(CC_VERSION_OUTPUT)),$(CLANG_STR)) - COMPILER_NAME = $(CLANG_STR) -endif - -#Kludge for mingw, it does not have cc.exe, but gcc.exe will do -ifeq ($(UNAME_OS),$(MINGW_STR)) - CC := gcc -endif - -#And another kludge. Exception handling in gcc 4.6.2 is broken when linking the -# Standard C++ library as a shared library. Unbelievable. -ifeq ($(UNAME_OS),$(MINGW_STR)) - CPPUTEST_LDFLAGS += -static -endif -ifeq ($(UNAME_OS),$(CYGWIN_STR)) - CPPUTEST_LDFLAGS += -static -endif - - -#Kludge for MacOsX gcc compiler on Darwin9 who can't handle pendantic -ifeq ($(UNAME_OS),$(MACOSX_STR)) -ifeq ($(findstring Version 9,$(UNAME_OUTPUT)),Version 9) - CPPUTEST_PEDANTIC_ERRORS = N -endif -endif - -ifndef COMPONENT_NAME - COMPONENT_NAME = name_this_in_the_makefile -endif - -# Debug on by default -ifndef CPPUTEST_ENABLE_DEBUG - CPPUTEST_ENABLE_DEBUG = Y -endif - -# new and delete for memory leak detection on by default -ifndef CPPUTEST_USE_MEM_LEAK_DETECTION - CPPUTEST_USE_MEM_LEAK_DETECTION = Y -endif - -# Use the standard C library -ifndef CPPUTEST_USE_STD_C_LIB - CPPUTEST_USE_STD_C_LIB = Y -endif - -# Use the standard C++ library -ifndef CPPUTEST_USE_STD_CPP_LIB - CPPUTEST_USE_STD_CPP_LIB = Y -endif - -# Use gcov, off by default -ifndef CPPUTEST_USE_GCOV - CPPUTEST_USE_GCOV = N -endif - -ifndef CPPUTEST_PEDANTIC_ERRORS - CPPUTEST_PEDANTIC_ERRORS = Y -endif - -# Default warnings -ifndef CPPUTEST_WARNINGFLAGS - CPPUTEST_WARNINGFLAGS = -Wall -Wextra -Wshadow -Wswitch-default -Wswitch-enum -Wconversion -ifeq ($(CPPUTEST_PEDANTIC_ERRORS), Y) -# CPPUTEST_WARNINGFLAGS += -pedantic-errors - CPPUTEST_WARNINGFLAGS += -pedantic -endif -ifeq ($(UNAME_OS),$(LINUX_STR)) - CPPUTEST_WARNINGFLAGS += -Wsign-conversion -endif - CPPUTEST_CXX_WARNINGFLAGS = -Woverloaded-virtual - CPPUTEST_C_WARNINGFLAGS = -Wstrict-prototypes -endif - -#Wonderful extra compiler warnings with clang -ifeq ($(COMPILER_NAME),$(CLANG_STR)) -# -Wno-disabled-macro-expansion -> Have to disable the macro expansion warning as the operator new overload warns on that. -# -Wno-padded -> I sort-of like this warning but if there is a bool at the end of the class, it seems impossible to remove it! (except by making padding explicit) -# -Wno-global-constructors Wno-exit-time-destructors -> Great warnings, but in CppUTest it is impossible to avoid as the automatic test registration depends on the global ctor and dtor -# -Wno-weak-vtables -> The TEST_GROUP macro declares a class and will automatically inline its methods. Thats ok as they are only in one translation unit. Unfortunately, the warning can't detect that, so it must be disabled. - CPPUTEST_CXX_WARNINGFLAGS += -Weverything -Wno-disabled-macro-expansion -Wno-padded -Wno-global-constructors -Wno-exit-time-destructors -Wno-weak-vtables - CPPUTEST_C_WARNINGFLAGS += -Weverything -Wno-padded -endif - -# Uhm. Maybe put some warning flags for SunStudio here? -ifeq ($(COMPILER_NAME),$(SUNSTUDIO_CXX_STR)) - CPPUTEST_CXX_WARNINGFLAGS = - CPPUTEST_C_WARNINGFLAGS = -endif - -# Default dir for temporary files (d, o) -ifndef CPPUTEST_OBJS_DIR -ifndef TARGET_PLATFORM - CPPUTEST_OBJS_DIR = objs -else - CPPUTEST_OBJS_DIR = objs/$(TARGET_PLATFORM) -endif -endif - -# Default dir for the outout library -ifndef CPPUTEST_LIB_DIR -ifndef TARGET_PLATFORM - CPPUTEST_LIB_DIR = lib -else - CPPUTEST_LIB_DIR = lib/$(TARGET_PLATFORM) -endif -endif - -# No map by default -ifndef CPPUTEST_MAP_FILE - CPPUTEST_MAP_FILE = N -endif - -# No extentions is default -ifndef CPPUTEST_USE_EXTENSIONS - CPPUTEST_USE_EXTENSIONS = N -endif - -# No VPATH is default -ifndef CPPUTEST_USE_VPATH - CPPUTEST_USE_VPATH := N -endif -# Make empty, instead of 'N', for usage in $(if ) conditionals -ifneq ($(CPPUTEST_USE_VPATH), Y) - CPPUTEST_USE_VPATH := -endif - -ifndef TARGET_PLATFORM -#CPPUTEST_LIB_LINK_DIR = $(CPPUTEST_HOME)/lib -CPPUTEST_LIB_LINK_DIR = /usr/lib/x86_64-linux-gnu -else -CPPUTEST_LIB_LINK_DIR = $(CPPUTEST_HOME)/lib/$(TARGET_PLATFORM) -endif - -# -------------------------------------- -# derived flags in the following area -# -------------------------------------- - -# Without the C library, we'll need to disable the C++ library and ... -ifeq ($(CPPUTEST_USE_STD_C_LIB), N) - CPPUTEST_USE_STD_CPP_LIB = N - CPPUTEST_USE_MEM_LEAK_DETECTION = N - CPPUTEST_CPPFLAGS += -DCPPUTEST_STD_C_LIB_DISABLED - CPPUTEST_CPPFLAGS += -nostdinc -endif - -CPPUTEST_CPPFLAGS += -DCPPUTEST_COMPILATION - -ifeq ($(CPPUTEST_USE_MEM_LEAK_DETECTION), N) - CPPUTEST_CPPFLAGS += -DCPPUTEST_MEM_LEAK_DETECTION_DISABLED -else - ifndef CPPUTEST_MEMLEAK_DETECTOR_NEW_MACRO_FILE - CPPUTEST_MEMLEAK_DETECTOR_NEW_MACRO_FILE = -include $(CPPUTEST_HOME)/include/CppUTest/MemoryLeakDetectorNewMacros.h - endif - ifndef CPPUTEST_MEMLEAK_DETECTOR_MALLOC_MACRO_FILE - CPPUTEST_MEMLEAK_DETECTOR_MALLOC_MACRO_FILE = -include $(CPPUTEST_HOME)/include/CppUTest/MemoryLeakDetectorMallocMacros.h - endif -endif - -ifeq ($(CPPUTEST_ENABLE_DEBUG), Y) - CPPUTEST_CXXFLAGS += -g - CPPUTEST_CFLAGS += -g - CPPUTEST_LDFLAGS += -g -endif - -ifeq ($(CPPUTEST_USE_STD_CPP_LIB), N) - CPPUTEST_CPPFLAGS += -DCPPUTEST_STD_CPP_LIB_DISABLED -ifeq ($(CPPUTEST_USE_STD_C_LIB), Y) - CPPUTEST_CXXFLAGS += -nostdinc++ -endif -endif - -ifdef $(GMOCK_HOME) - GTEST_HOME = $(GMOCK_HOME)/gtest - CPPUTEST_CPPFLAGS += -I$(GMOCK_HOME)/include - GMOCK_LIBRARY = $(GMOCK_HOME)/lib/.libs/libgmock.a - LD_LIBRARIES += $(GMOCK_LIBRARY) - CPPUTEST_CPPFLAGS += -DINCLUDE_GTEST_TESTS - CPPUTEST_WARNINGFLAGS = - CPPUTEST_CPPFLAGS += -I$(GTEST_HOME)/include -I$(GTEST_HOME) - GTEST_LIBRARY = $(GTEST_HOME)/lib/.libs/libgtest.a - LD_LIBRARIES += $(GTEST_LIBRARY) -endif - - -ifeq ($(CPPUTEST_USE_GCOV), Y) - CPPUTEST_CXXFLAGS += -fprofile-arcs -ftest-coverage - CPPUTEST_CFLAGS += -fprofile-arcs -ftest-coverage -endif - -CPPUTEST_CXXFLAGS += $(CPPUTEST_WARNINGFLAGS) $(CPPUTEST_CXX_WARNINGFLAGS) -CPPUTEST_CPPFLAGS += $(CPPUTEST_WARNINGFLAGS) -CPPUTEST_CXXFLAGS += $(CPPUTEST_MEMLEAK_DETECTOR_NEW_MACRO_FILE) -CPPUTEST_CPPFLAGS += $(CPPUTEST_MEMLEAK_DETECTOR_MALLOC_MACRO_FILE) -CPPUTEST_CFLAGS += $(CPPUTEST_C_WARNINGFLAGS) - -TARGET_MAP = $(COMPONENT_NAME).map.txt -ifeq ($(CPPUTEST_MAP_FILE), Y) - CPPUTEST_LDFLAGS += -Wl,-map,$(TARGET_MAP) -endif - -# Link with CppUTest lib -CPPUTEST_LIB = $(CPPUTEST_LIB_LINK_DIR)/libCppUTest.a - -ifeq ($(CPPUTEST_USE_EXTENSIONS), Y) -CPPUTEST_LIB += $(CPPUTEST_LIB_LINK_DIR)/libCppUTestExt.a -endif - -ifdef CPPUTEST_STATIC_REALTIME - LD_LIBRARIES += -lrt -endif - -TARGET_LIB = \ - $(CPPUTEST_LIB_DIR)/lib$(COMPONENT_NAME).a - -ifndef TEST_TARGET - ifndef TARGET_PLATFORM - TEST_TARGET = $(COMPONENT_NAME)_tests - else - TEST_TARGET = $(COMPONENT_NAME)_$(TARGET_PLATFORM)_tests - endif -endif - -#Helper Functions -get_src_from_dir = $(wildcard $1/*.cpp) $(wildcard $1/*.cc) $(wildcard $1/*.c) -get_dirs_from_dirspec = $(wildcard $1) -get_src_from_dir_list = $(foreach dir, $1, $(call get_src_from_dir,$(dir))) -__src_to = $(subst .c,$1, $(subst .cc,$1, $(subst .cpp,$1,$(if $(CPPUTEST_USE_VPATH),$(notdir $2),$2)))) -src_to = $(addprefix $(CPPUTEST_OBJS_DIR)/,$(call __src_to,$1,$2)) -src_to_o = $(call src_to,.o,$1) -src_to_d = $(call src_to,.d,$1) -src_to_gcda = $(call src_to,.gcda,$1) -src_to_gcno = $(call src_to,.gcno,$1) -time = $(shell date +%s) -delta_t = $(eval minus, $1, $2) -debug_print_list = $(foreach word,$1,echo " $(word)";) echo; - -#Derived -STUFF_TO_CLEAN += $(TEST_TARGET) $(TEST_TARGET).exe $(TARGET_LIB) $(TARGET_MAP) - -SRC += $(call get_src_from_dir_list, $(SRC_DIRS)) $(SRC_FILES) -OBJ = $(call src_to_o,$(SRC)) - -STUFF_TO_CLEAN += $(OBJ) - -TEST_SRC += $(call get_src_from_dir_list, $(TEST_SRC_DIRS)) $(TEST_SRC_FILES) -TEST_OBJS = $(call src_to_o,$(TEST_SRC)) -STUFF_TO_CLEAN += $(TEST_OBJS) - - -MOCKS_SRC += $(call get_src_from_dir_list, $(MOCKS_SRC_DIRS)) -MOCKS_OBJS = $(call src_to_o,$(MOCKS_SRC)) -STUFF_TO_CLEAN += $(MOCKS_OBJS) - -ALL_SRC = $(SRC) $(TEST_SRC) $(MOCKS_SRC) - -# If we're using VPATH -ifeq ($(CPPUTEST_USE_VPATH), Y) -# gather all the source directories and add them - VPATH += $(sort $(dir $(ALL_SRC))) -# Add the component name to the objs dir path, to differentiate between same-name objects - CPPUTEST_OBJS_DIR := $(addsuffix /$(COMPONENT_NAME),$(CPPUTEST_OBJS_DIR)) -endif - -#Test coverage with gcov -GCOV_OUTPUT = gcov_output.txt -GCOV_REPORT = gcov_report.txt -GCOV_ERROR = gcov_error.txt -GCOV_GCDA_FILES = $(call src_to_gcda, $(ALL_SRC)) -GCOV_GCNO_FILES = $(call src_to_gcno, $(ALL_SRC)) -TEST_OUTPUT = $(TEST_TARGET).txt -STUFF_TO_CLEAN += \ - $(GCOV_OUTPUT)\ - $(GCOV_REPORT)\ - $(GCOV_REPORT).html\ - $(GCOV_ERROR)\ - $(GCOV_GCDA_FILES)\ - $(GCOV_GCNO_FILES)\ - $(TEST_OUTPUT) - -#The gcda files for gcov need to be deleted before each run -#To avoid annoying messages. -GCOV_CLEAN = $(SILENCE)rm -f $(GCOV_GCDA_FILES) $(GCOV_OUTPUT) $(GCOV_REPORT) $(GCOV_ERROR) -RUN_TEST_TARGET = $(SILENCE) $(GCOV_CLEAN) ; echo "Running $(TEST_TARGET)"; ./$(TEST_TARGET) $(CPPUTEST_EXE_FLAGS) -ojunit - -ifeq ($(CPPUTEST_USE_GCOV), Y) - - ifeq ($(COMPILER_NAME),$(CLANG_STR)) - LD_LIBRARIES += --coverage - else - LD_LIBRARIES += -lgcov - endif -endif - - -INCLUDES_DIRS_EXPANDED = $(call get_dirs_from_dirspec, $(INCLUDE_DIRS)) -INCLUDES += $(foreach dir, $(INCLUDES_DIRS_EXPANDED), -I$(dir)) -MOCK_DIRS_EXPANDED = $(call get_dirs_from_dirspec, $(MOCKS_SRC_DIRS)) -INCLUDES += $(foreach dir, $(MOCK_DIRS_EXPANDED), -I$(dir)) - -CPPUTEST_CPPFLAGS += $(INCLUDES) $(CPPUTESTFLAGS) - -DEP_FILES = $(call src_to_d, $(ALL_SRC)) -STUFF_TO_CLEAN += $(DEP_FILES) $(PRODUCTION_CODE_START) $(PRODUCTION_CODE_END) -STUFF_TO_CLEAN += $(STDLIB_CODE_START) $(MAP_FILE) cpputest_*.xml junit_run_output - -# We'll use the CPPUTEST_CFLAGS etc so that you can override AND add to the CppUTest flags -CFLAGS = $(CPPUTEST_CFLAGS) $(CPPUTEST_ADDITIONAL_CFLAGS) -CPPFLAGS = $(CPPUTEST_CPPFLAGS) $(CPPUTEST_ADDITIONAL_CPPFLAGS) -CXXFLAGS = $(CPPUTEST_CXXFLAGS) $(CPPUTEST_ADDITIONAL_CXXFLAGS) -LDFLAGS = $(CPPUTEST_LDFLAGS) $(CPPUTEST_ADDITIONAL_LDFLAGS) - -# Don't consider creating the archive a warning condition that does STDERR output -ARFLAGS := $(ARFLAGS)c - -DEP_FLAGS=-MMD -MP - -# Some macros for programs to be overridden. For some reason, these are not in Make defaults -RANLIB = ranlib - -# Targets - -.PHONY: all -all: start $(TEST_TARGET) - $(RUN_TEST_TARGET) - -.PHONY: start -start: $(TEST_TARGET) - $(SILENCE)START_TIME=$(call time) - -.PHONY: all_no_tests -all_no_tests: $(TEST_TARGET) - -.PHONY: flags -flags: - @echo - @echo "OS ${UNAME_OS}" - @echo "Compile C and C++ source with CPPFLAGS:" - @$(call debug_print_list,$(CPPFLAGS)) - @echo "Compile C++ source with CXXFLAGS:" - @$(call debug_print_list,$(CXXFLAGS)) - @echo "Compile C source with CFLAGS:" - @$(call debug_print_list,$(CFLAGS)) - @echo "Link with LDFLAGS:" - @$(call debug_print_list,$(LDFLAGS)) - @echo "Link with LD_LIBRARIES:" - @$(call debug_print_list,$(LD_LIBRARIES)) - @echo "Create libraries with ARFLAGS:" - @$(call debug_print_list,$(ARFLAGS)) - -TEST_DEPS = $(TEST_OBJS) $(MOCKS_OBJS) $(PRODUCTION_CODE_START) $(TARGET_LIB) $(USER_LIBS) $(PRODUCTION_CODE_END) $(CPPUTEST_LIB) $(STDLIB_CODE_START) -test-deps: $(TEST_DEPS) - -$(TEST_TARGET): $(TEST_DEPS) - @echo Linking $@ - $(SILENCE)$(CXX) -o $@ $^ $(LD_LIBRARIES) $(LDFLAGS) - -$(TARGET_LIB): $(OBJ) - @echo Building archive $@ - $(SILENCE)mkdir -p $(dir $@) - $(SILENCE)$(AR) $(ARFLAGS) $@ $^ - $(SILENCE)$(RANLIB) $@ - -test: $(TEST_TARGET) - $(RUN_TEST_TARGET) | tee $(TEST_OUTPUT) - -vtest: $(TEST_TARGET) - $(RUN_TEST_TARGET) -v | tee $(TEST_OUTPUT) - -$(CPPUTEST_OBJS_DIR)/%.o: %.cc - @echo compiling $(notdir $<) - $(SILENCE)mkdir -p $(dir $@) - $(SILENCE)$(COMPILE.cpp) $(DEP_FLAGS) $(OUTPUT_OPTION) $< - -$(CPPUTEST_OBJS_DIR)/%.o: %.cpp - @echo compiling $(notdir $<) - $(SILENCE)mkdir -p $(dir $@) - $(SILENCE)$(COMPILE.cpp) $(DEP_FLAGS) $(OUTPUT_OPTION) $< - -$(CPPUTEST_OBJS_DIR)/%.o: %.c - @echo compiling $(notdir $<) - $(SILENCE)mkdir -p $(dir $@) - $(SILENCE)$(COMPILE.c) $(DEP_FLAGS) $(OUTPUT_OPTION) $< - -ifneq "$(MAKECMDGOALS)" "clean" --include $(DEP_FILES) -endif - -.PHONY: clean -clean: - @echo Making clean - $(SILENCE)$(RM) $(STUFF_TO_CLEAN) - $(SILENCE)rm -rf gcov objs #$(CPPUTEST_OBJS_DIR) - $(SILENCE)rm -rf $(CPPUTEST_LIB_DIR) - $(SILENCE)find . -name "*.gcno" | xargs rm -f - $(SILENCE)find . -name "*.gcda" | xargs rm -f - -#realclean gets rid of all gcov, o and d files in the directory tree -#not just the ones made by this makefile -.PHONY: realclean -realclean: clean - $(SILENCE)rm -rf gcov - $(SILENCE)find . -name "*.gdcno" | xargs rm -f - $(SILENCE)find . -name "*.[do]" | xargs rm -f - -gcov: test -ifeq ($(CPPUTEST_USE_VPATH), Y) - $(SILENCE)gcov --object-directory $(CPPUTEST_OBJS_DIR) $(SRC) >> $(GCOV_OUTPUT) 2>> $(GCOV_ERROR) -else - $(SILENCE)for d in $(SRC_DIRS) ; do \ - gcov --object-directory $(CPPUTEST_OBJS_DIR)/$$d $$d/*.c $$d/*.cpp >> $(GCOV_OUTPUT) 2>>$(GCOV_ERROR) ; \ - done - $(SILENCE)for f in $(SRC_FILES) ; do \ - gcov --object-directory $(CPPUTEST_OBJS_DIR)/$$f $$f >> $(GCOV_OUTPUT) 2>>$(GCOV_ERROR) ; \ - done -endif -# $(CPPUTEST_HOME)/scripts/filterGcov.sh $(GCOV_OUTPUT) $(GCOV_ERROR) $(GCOV_REPORT) $(TEST_OUTPUT) - /usr/share/cpputest/scripts/filterGcov.sh $(GCOV_OUTPUT) $(GCOV_ERROR) $(GCOV_REPORT) $(TEST_OUTPUT) - $(SILENCE)cat $(GCOV_REPORT) - $(SILENCE)mkdir -p gcov - $(SILENCE)mv *.gcov gcov - $(SILENCE)mv gcov_* gcov - @echo "See gcov directory for details" - -.PHONEY: format -format: - $(CPPUTEST_HOME)/scripts/reformat.sh $(PROJECT_HOME_DIR) - -.PHONEY: debug -debug: - @echo - @echo "Target Source files:" - @$(call debug_print_list,$(SRC)) - @echo "Target Object files:" - @$(call debug_print_list,$(OBJ)) - @echo "Test Source files:" - @$(call debug_print_list,$(TEST_SRC)) - @echo "Test Object files:" - @$(call debug_print_list,$(TEST_OBJS)) - @echo "Mock Source files:" - @$(call debug_print_list,$(MOCKS_SRC)) - @echo "Mock Object files:" - @$(call debug_print_list,$(MOCKS_OBJS)) - @echo "All Input Dependency files:" - @$(call debug_print_list,$(DEP_FILES)) - @echo Stuff to clean: - @$(call debug_print_list,$(STUFF_TO_CLEAN)) - @echo Includes: - @$(call debug_print_list,$(INCLUDES)) - --include $(OTHER_MAKEFILE_TO_INCLUDE) diff --git a/features/nanostack/nanostack-hal-mbed-cmsis-rtos/cs_nvm/test/test_cs_nvm_unit/unittest/cs_nvm/csnvmtest.cpp b/features/nanostack/nanostack-hal-mbed-cmsis-rtos/cs_nvm/test/test_cs_nvm_unit/unittest/cs_nvm/csnvmtest.cpp deleted file mode 100644 index ee1e188..0000000 --- a/features/nanostack/nanostack-hal-mbed-cmsis-rtos/cs_nvm/test/test_cs_nvm_unit/unittest/cs_nvm/csnvmtest.cpp +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (c) 2016, 2018, Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "CppUTest/TestHarness.h" -#include "test_cs_nvm.h" - -TEST_GROUP(CS_NVM) -{ - void setup() { - - } - - void teardown() { - - } -}; - -TEST(CS_NVM, test_cs_nvm_operation_in_progress) -{ - CHECK(test_cs_nvm_operation_in_progress() == true); -} - -TEST(CS_NVM, test_cs_nvm_flush) -{ - CHECK(test_cs_nvm_flush() == true); -} - -TEST(CS_NVM, test_cs_nvm_write_failure_in_close) -{ - CHECK(test_cs_nvm_write_failure_in_close() == true); -} - -TEST(CS_NVM, test_cs_nvm_write_failure) -{ - CHECK(test_cs_nvm_write_failure() == true); -} - -TEST(CS_NVM, test_cs_nvm_write) -{ - CHECK(test_cs_nvm_write() == true); -} - -TEST(CS_NVM, test_cs_nvm_read_failure_in_close) -{ - CHECK(test_cs_nvm_read_failure_in_close() == true); -} - -TEST(CS_NVM, test_cs_nvm_read_failure) -{ - CHECK(test_cs_nvm_read_failure() == true); -} - -TEST(CS_NVM, test_cs_nvm_read) -{ - CHECK(test_cs_nvm_read() == true); -} - -TEST(CS_NVM, test_cs_nvm_key_delete_failure_in_close) -{ - CHECK(test_cs_nvm_key_delete_failure_in_close() == true); -} - -TEST(CS_NVM, test_cs_nvm_key_delete) -{ - CHECK(test_cs_nvm_key_delete() == true); -} - -TEST(CS_NVM, test_cs_nvm_key_create) -{ - CHECK(test_cs_nvm_key_create() == true); -} - -TEST(CS_NVM, test_cs_nvm_init_finalize) -{ - CHECK(test_cs_nvm_init_finalize() == true); -} - diff --git a/features/nanostack/nanostack-hal-mbed-cmsis-rtos/cs_nvm/test/test_cs_nvm_unit/unittest/cs_nvm/main.cpp b/features/nanostack/nanostack-hal-mbed-cmsis-rtos/cs_nvm/test/test_cs_nvm_unit/unittest/cs_nvm/main.cpp deleted file mode 100644 index d6a8a57..0000000 --- a/features/nanostack/nanostack-hal-mbed-cmsis-rtos/cs_nvm/test/test_cs_nvm_unit/unittest/cs_nvm/main.cpp +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2015, 2018, Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "CppUTest/CommandLineTestRunner.h" -#include "CppUTest/TestPlugin.h" -#include "CppUTest/TestRegistry.h" -#include "CppUTestExt/MockSupportPlugin.h" -int main(int ac, char **av) -{ - return CommandLineTestRunner::RunAllTests(ac, av); -} - -IMPORT_TEST_GROUP(CS_NVM); - diff --git a/features/nanostack/nanostack-hal-mbed-cmsis-rtos/cs_nvm/test/test_cs_nvm_unit/unittest/cs_nvm/test_cs_nvm.c b/features/nanostack/nanostack-hal-mbed-cmsis-rtos/cs_nvm/test/test_cs_nvm_unit/unittest/cs_nvm/test_cs_nvm.c deleted file mode 100644 index 915a82e..0000000 --- a/features/nanostack/nanostack-hal-mbed-cmsis-rtos/cs_nvm/test/test_cs_nvm_unit/unittest/cs_nvm/test_cs_nvm.c +++ /dev/null @@ -1,1044 +0,0 @@ -/* - * Copyright (c) 2016, 2018, Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "platform/arm_hal_nvm.h" - -#include "test_cs_nvm.h" -#include "nsdynmemLIB_stub.h" -#include "configuration_store_stub.h" - -#define TEST_NS_NVM_HELPER_CONTEXT_CLEAR 0xffff -#define TEST_PLATFORM_NVM_STATUS_CLEAR 0xffff - -#define TEST_NS_NVM_HELPER_CONTEXT1 0x01 -#define TEST_NS_NVM_HELPER_CONTEXT2 0x02 -#define TEST_NS_NVM_HELPER_CONTEXT3 0x03 - -const char *key_name = "testkey"; -uint8_t buf[100]; -uint16_t buf_len; -uint16_t data_len; - -typedef struct { - platform_nvm_status status; - void *ctx; -} test_platform_nvm_api_callback_t; - -static test_platform_nvm_api_callback_t *active_cb_data_ptr; -static test_platform_nvm_api_callback_t cb_data = {TEST_PLATFORM_NVM_STATUS_CLEAR, TEST_NS_NVM_HELPER_CONTEXT_CLEAR}; - -void test_nvm_callback(platform_nvm_status status, void *context) -{ - active_cb_data_ptr->status = status; - active_cb_data_ptr->ctx = context; -} - -static void test_callback_data_clear(test_platform_nvm_api_callback_t *callback_data_ptr) -{ - callback_data_ptr->status = TEST_PLATFORM_NVM_STATUS_CLEAR; - callback_data_ptr->ctx = TEST_NS_NVM_HELPER_CONTEXT_CLEAR; -} - -static bool test_callback_executed(test_platform_nvm_api_callback_t *callback_data_ptr) -{ - if (callback_data_ptr->status != TEST_PLATFORM_NVM_STATUS_CLEAR) { - return true; - } - if (callback_data_ptr->ctx != TEST_NS_NVM_HELPER_CONTEXT_CLEAR) { - return true; - } - return false; -} - -static bool test_nvm_initialize() -{ - platform_nvm_status ret; - active_cb_data_ptr = &cb_data; - test_callback_data_clear(active_cb_data_ptr); - - // OK initialization - cfstore_stub.ret_val = ARM_DRIVER_OK; - cfstore_stub.cmd_code = CFSTORE_OPCODE_INITIALIZE; - nsdynmemlib_stub.returnCounter = 1; - ret = platform_nvm_init(test_nvm_callback, TEST_NS_NVM_HELPER_CONTEXT1); - if (ret != PLATFORM_NVM_OK) { - return false; - } - - // simulate configuration_store callback and cs_nvm timer callback - cfstore_stub.cmd_code = CFSTORE_OPCODE_POWER_CONTROL; - test_cfstore_callback_trigger(); - - // simulate configuration_store callback and cs_nvm timer callback - cfstore_stub.cmd_code = CFSTORE_OPCODE_INITIALIZE; - test_cfstore_callback_trigger(); - test_eventOS_timeout_trigger(); - if (active_cb_data_ptr->status != PLATFORM_NVM_OK || active_cb_data_ptr->ctx != TEST_NS_NVM_HELPER_CONTEXT1) { - return false; - } - - return true; -} - -static bool test_nvm_finalize() -{ - platform_nvm_status ret; - active_cb_data_ptr = &cb_data; - test_callback_data_clear(active_cb_data_ptr); - - // finalize NVM - OK - cfstore_stub.ret_val = ARM_DRIVER_OK; - ret = platform_nvm_finalize(test_nvm_callback, TEST_NS_NVM_HELPER_CONTEXT2); - if (ret != PLATFORM_NVM_OK) { - return false; - } - - // simulate configuration_store callback and cs_nvm timer callback - cfstore_stub.cmd_code = CFSTORE_OPCODE_POWER_CONTROL; - test_cfstore_callback_trigger(); - - // simulate configuration_store callback and cs_nvm timer callback - cfstore_stub.cmd_code = CFSTORE_OPCODE_UNINITIALIZE; - test_callback_data_clear(active_cb_data_ptr); - test_cfstore_callback_trigger(); - test_eventOS_timeout_trigger(); - if (active_cb_data_ptr->status != PLATFORM_NVM_OK || active_cb_data_ptr->ctx != TEST_NS_NVM_HELPER_CONTEXT2) { - return false; - } - return true; -} - -bool test_cs_nvm_init_finalize() -{ - platform_nvm_status ret; - active_cb_data_ptr = &cb_data; - test_callback_data_clear(active_cb_data_ptr); - - // No callback - fail - cfstore_stub.ret_val = ARM_DRIVER_OK; - cfstore_stub.cmd_code = CFSTORE_OPCODE_INITIALIZE; - ret = platform_nvm_init(NULL, TEST_NS_NVM_HELPER_CONTEXT1); - if (ret != PLATFORM_NVM_ERROR) { - return false; - } - - // memory allocation fails - nsdynmemlib_stub.returnCounter = 0; - ret = platform_nvm_init(test_nvm_callback, TEST_NS_NVM_HELPER_CONTEXT1); - if (ret != PLATFORM_NVM_ERROR) { - return false; - } - - // configuration-store returns failure - cfstore_stub.ret_val = ARM_DRIVER_ERROR; - nsdynmemlib_stub.returnCounter = 1; - ret = platform_nvm_init(test_nvm_callback, TEST_NS_NVM_HELPER_CONTEXT1); - if (ret != PLATFORM_NVM_ERROR) { - return false; - } - - // OK initialization - cfstore_stub.ret_val = ARM_DRIVER_OK; - nsdynmemlib_stub.returnCounter = 1; - ret = platform_nvm_init(test_nvm_callback, TEST_NS_NVM_HELPER_CONTEXT1); - if (ret != PLATFORM_NVM_OK) { - return false; - } - - // simulate configuration_store callback and cs_nvm timer callback - cfstore_stub.cmd_code = CFSTORE_OPCODE_POWER_CONTROL; - test_cfstore_callback_trigger(); - - // simulate configuration_store callback and cs_nvm timer callback - cfstore_stub.cmd_code = CFSTORE_OPCODE_INITIALIZE; - test_cfstore_callback_trigger(); - test_eventOS_timeout_trigger(); - if (active_cb_data_ptr->status != PLATFORM_NVM_OK || active_cb_data_ptr->ctx != TEST_NS_NVM_HELPER_CONTEXT1) { - return false; - } - - // Already initialized - ret = platform_nvm_init(test_nvm_callback, TEST_NS_NVM_HELPER_CONTEXT1); - if (ret != PLATFORM_NVM_ERROR) { - return false; - } - - // finalize NVM - no callback - ret = platform_nvm_finalize(NULL, TEST_NS_NVM_HELPER_CONTEXT2); - if (ret != PLATFORM_NVM_ERROR) { - return false; - } - - // finalize NVM - configuration-store error - cfstore_stub.ret_val = ARM_DRIVER_ERROR; - ret = platform_nvm_finalize(test_nvm_callback, TEST_NS_NVM_HELPER_CONTEXT2); - if (ret != PLATFORM_NVM_OK) { - return false; - } - cfstore_stub.cmd_code = CFSTORE_OPCODE_UNINITIALIZE; - test_cfstore_callback_trigger(); - test_eventOS_timeout_trigger(); - if (active_cb_data_ptr->status != PLATFORM_NVM_ERROR || active_cb_data_ptr->ctx != TEST_NS_NVM_HELPER_CONTEXT2) { - return false; - } - - // finalize NVM - OK - if (!test_nvm_finalize()) { - return false; - } - - // finalize - already finalized - ret = platform_nvm_finalize(test_nvm_callback, TEST_NS_NVM_HELPER_CONTEXT2); - if (ret != PLATFORM_NVM_ERROR) { - return false; - } - - return true; -} - -bool test_cs_nvm_key_create() -{ - platform_nvm_status ret; - active_cb_data_ptr = &cb_data; - test_callback_data_clear(active_cb_data_ptr); - - // OK initialization - if (!test_nvm_initialize()) { - return false; - } - - // Test - no callback - ret = platform_nvm_key_create(NULL, key_name, data_len, 0, TEST_NS_NVM_HELPER_CONTEXT2); - if (ret != PLATFORM_NVM_ERROR) { - return false; - } - - // No key_name - ret = platform_nvm_key_create(test_nvm_callback, NULL, data_len, 0, TEST_NS_NVM_HELPER_CONTEXT2); - if (ret != PLATFORM_NVM_ERROR) { - return false; - } - - // configuration-store returns error - test_callback_data_clear(active_cb_data_ptr); - cfstore_stub.ret_val = ARM_DRIVER_ERROR; - ret = platform_nvm_key_create(test_nvm_callback, key_name, data_len, 0, TEST_NS_NVM_HELPER_CONTEXT2); - if (ret != PLATFORM_NVM_OK) { - return false; - } - // simulate configuration_store callback and cs_nvm timer callback - cfstore_stub.cmd_code = CFSTORE_OPCODE_CREATE; - test_cfstore_callback_trigger(); - test_eventOS_timeout_trigger(); - if (active_cb_data_ptr->status != PLATFORM_NVM_ERROR || active_cb_data_ptr->ctx != TEST_NS_NVM_HELPER_CONTEXT2) { - return false; - } - - //OK key creation - test_callback_data_clear(active_cb_data_ptr); - cfstore_stub.ret_val = ARM_DRIVER_OK; - ret = platform_nvm_key_create(test_nvm_callback, key_name, data_len, 0, TEST_NS_NVM_HELPER_CONTEXT3); - if (ret != PLATFORM_NVM_OK) { - return false; - } - - // create callback - cfstore_stub.cmd_code = CFSTORE_OPCODE_CREATE; - test_callback_data_clear(active_cb_data_ptr); - test_cfstore_callback_trigger(); - test_eventOS_timeout_trigger(); - - // close callback - cfstore_stub.cmd_code = CFSTORE_OPCODE_CLOSE; - test_cfstore_callback_trigger(); - test_eventOS_timeout_trigger(); - if (active_cb_data_ptr->status != PLATFORM_NVM_OK || active_cb_data_ptr->ctx != TEST_NS_NVM_HELPER_CONTEXT3) { - return false; - } - - //OK key creation - close failing - test_callback_data_clear(active_cb_data_ptr); - cfstore_stub.ret_val = ARM_DRIVER_OK; - cfstore_stub.close_ret_val = ARM_DRIVER_ERROR; - ret = platform_nvm_key_create(test_nvm_callback, key_name, data_len, 0, TEST_NS_NVM_HELPER_CONTEXT3); - if (ret != PLATFORM_NVM_OK) { - return false; - } - - // create callback - cfstore_stub.cmd_code = CFSTORE_OPCODE_CREATE; - test_callback_data_clear(active_cb_data_ptr); - test_cfstore_callback_trigger(); - - // close callback - cfstore_stub.cmd_code = CFSTORE_OPCODE_CLOSE; - test_cfstore_callback_trigger(); - test_eventOS_timeout_trigger(); - if (active_cb_data_ptr->status != PLATFORM_NVM_ERROR || active_cb_data_ptr->ctx != TEST_NS_NVM_HELPER_CONTEXT3) { - return false; - } - - // OK key re-creation failure - test_callback_data_clear(active_cb_data_ptr); - cfstore_stub.ret_val = ARM_CFSTORE_DRIVER_ERROR_PREEXISTING_KEY; - ret = platform_nvm_key_create(test_nvm_callback, key_name, data_len, 0, TEST_NS_NVM_HELPER_CONTEXT3); - if (ret != PLATFORM_NVM_OK) { - return false; - } - - cfstore_stub.cmd_code = CFSTORE_OPCODE_CREATE; - test_callback_data_clear(active_cb_data_ptr); - test_cfstore_callback_trigger(); - test_eventOS_timeout_trigger(); - - if (active_cb_data_ptr->status != PLATFORM_NVM_ERROR || active_cb_data_ptr->ctx != TEST_NS_NVM_HELPER_CONTEXT3) { - return false; - } - - // finalize NVM - OK - if (!test_nvm_finalize()) { - return false; - } - - // Create - not initialized - ret = platform_nvm_key_create(test_nvm_callback, key_name, data_len, 0, TEST_NS_NVM_HELPER_CONTEXT3); - if (ret != PLATFORM_NVM_ERROR) { - return false; - } - - return true; -} - -bool test_cs_nvm_key_delete() -{ - platform_nvm_status ret; - active_cb_data_ptr = &cb_data; - test_callback_data_clear(active_cb_data_ptr); - - // NVM not initialized - ret = platform_nvm_key_delete(test_nvm_callback, key_name, TEST_NS_NVM_HELPER_CONTEXT1); - if (ret != PLATFORM_NVM_ERROR) { - return false; - } - - if (!test_nvm_initialize()) { - return false; - } - - test_callback_data_clear(active_cb_data_ptr); - - // No callback - ret = platform_nvm_key_delete(NULL, key_name, TEST_NS_NVM_HELPER_CONTEXT1); - if (ret != PLATFORM_NVM_ERROR) { - return false; - } - - // No key_name - ret = platform_nvm_key_delete(test_nvm_callback, NULL, TEST_NS_NVM_HELPER_CONTEXT1); - if (ret != PLATFORM_NVM_ERROR) { - return false; - } - - // Configuration-store returns error in OPEN directly - cfstore_stub.ret_val = ARM_DRIVER_ERROR; - ret = platform_nvm_key_delete(test_nvm_callback, key_name, TEST_NS_NVM_HELPER_CONTEXT1); - if (ret != PLATFORM_NVM_OK) { - return false; - } - // simulate failing configuration store - test_callback_data_clear(active_cb_data_ptr); - test_eventOS_timeout_trigger(); - if (active_cb_data_ptr->status != PLATFORM_NVM_ERROR || active_cb_data_ptr->ctx != TEST_NS_NVM_HELPER_CONTEXT1) { - return false; - } - - // Configuration-store returns error in DELETE - cfstore_stub.ret_val = ARM_DRIVER_OK; - cfstore_stub.delete_ret_val = ARM_DRIVER_ERROR; - test_callback_data_clear(active_cb_data_ptr); - ret = platform_nvm_key_delete(test_nvm_callback, key_name, TEST_NS_NVM_HELPER_CONTEXT1); - if (ret != PLATFORM_NVM_OK) { - return false; - } - - cfstore_stub.cmd_code = CFSTORE_OPCODE_OPEN; - cfstore_stub.close_ret_val = ARM_DRIVER_OK; - test_callback_data_clear(active_cb_data_ptr); - test_cfstore_callback_trigger(); - test_eventOS_timeout_trigger(); // should not have any effect as state is opening - if (test_callback_executed(active_cb_data_ptr)) { - return false; - } - - cfstore_stub.ret_val = ARM_DRIVER_OK; - cfstore_stub.cmd_code = CFSTORE_OPCODE_CLOSE; - test_cfstore_callback_trigger(); - test_eventOS_timeout_trigger(); - - if (active_cb_data_ptr->status != PLATFORM_NVM_ERROR || active_cb_data_ptr->ctx != TEST_NS_NVM_HELPER_CONTEXT1) { - return false; - } - - // OK delete - cfstore_stub.ret_val = ARM_DRIVER_OK; - cfstore_stub.delete_ret_val = ARM_DRIVER_OK; - ret = platform_nvm_key_delete(test_nvm_callback, key_name, TEST_NS_NVM_HELPER_CONTEXT1); - if (ret != PLATFORM_NVM_OK) { - return false; - } - - // simulate open - cfstore_stub.cmd_code = CFSTORE_OPCODE_OPEN; - test_callback_data_clear(active_cb_data_ptr); - test_cfstore_callback_trigger(); - test_eventOS_timeout_trigger(); // should not have any effect as state is opening - if (test_callback_executed(active_cb_data_ptr)) { - return false; - } - - // simulate delete - cfstore_stub.cmd_code = CFSTORE_OPCODE_DELETE; - test_callback_data_clear(active_cb_data_ptr); - test_cfstore_callback_trigger(); - test_eventOS_timeout_trigger(); // should not have any effect since state is deleting - if (test_callback_executed(active_cb_data_ptr)) { - return false; - } - - // simulate close - cfstore_stub.cmd_code = CFSTORE_OPCODE_CLOSE; - test_callback_data_clear(active_cb_data_ptr); - test_cfstore_callback_trigger(); - test_eventOS_timeout_trigger(); //trigger callback - - if (active_cb_data_ptr->status != PLATFORM_NVM_OK || active_cb_data_ptr->ctx != TEST_NS_NVM_HELPER_CONTEXT1) { - return false; - } - - if (!test_nvm_finalize()) { - return false; - } - - return true; -} - -bool test_cs_nvm_key_delete_failure_in_close() -{ - platform_nvm_status ret; - active_cb_data_ptr = &cb_data; - - if (!test_nvm_initialize()) { - return false; - } - test_callback_data_clear(active_cb_data_ptr); - - // Delete is OK but closing fails - cfstore_stub.ret_val = ARM_DRIVER_OK; - cfstore_stub.read_ret_val = ARM_DRIVER_OK; - cfstore_stub.close_ret_val = ARM_DRIVER_ERROR; - test_callback_data_clear(active_cb_data_ptr); - ret = platform_nvm_key_delete(test_nvm_callback, key_name, TEST_NS_NVM_HELPER_CONTEXT2); - if (ret != PLATFORM_NVM_OK) { - return false; - } - - // simulate open - cfstore_stub.cmd_code = CFSTORE_OPCODE_OPEN; - test_callback_data_clear(active_cb_data_ptr); - test_cfstore_callback_trigger(); - test_eventOS_timeout_trigger(); // should not have any effect as state is opening - if (test_callback_executed(active_cb_data_ptr)) { - return false; - } - - // simulate delete - cfstore_stub.cmd_code = CFSTORE_OPCODE_DELETE; - test_callback_data_clear(active_cb_data_ptr); - test_cfstore_callback_trigger(); - - // simulate close - cfstore_stub.cmd_code = CFSTORE_OPCODE_CLOSE; - test_callback_data_clear(active_cb_data_ptr); - test_cfstore_callback_trigger(); - test_eventOS_timeout_trigger(); //trigger callback - - if (active_cb_data_ptr->status != PLATFORM_NVM_ERROR || active_cb_data_ptr->ctx != TEST_NS_NVM_HELPER_CONTEXT2) { - return false; - } - - if (!test_nvm_finalize()) { - return false; - } - - return true; -} - -bool test_cs_nvm_read() -{ - platform_nvm_status ret; - active_cb_data_ptr = &cb_data; - test_callback_data_clear(active_cb_data_ptr); - cfstore_stub.ret_val = ARM_DRIVER_OK; - cfstore_stub.read_ret_val = ARM_DRIVER_OK; - cfstore_stub.close_ret_val = ARM_DRIVER_OK; - - // read uninitialized - ret = platform_nvm_read(test_nvm_callback, key_name, buf, &buf_len, TEST_NS_NVM_HELPER_CONTEXT1); - if (ret != PLATFORM_NVM_ERROR) { - return false; - } - - if (!test_nvm_initialize()) { - return false; - } - test_callback_data_clear(active_cb_data_ptr); - - // no callback - ret = platform_nvm_read(NULL, key_name, buf, &buf_len, TEST_NS_NVM_HELPER_CONTEXT1); - if (ret != PLATFORM_NVM_ERROR) { - return false; - } - - // no key_name - ret = platform_nvm_read(test_nvm_callback, NULL, buf, &buf_len, TEST_NS_NVM_HELPER_CONTEXT1); - if (ret != PLATFORM_NVM_ERROR) { - return false; - } - - // no buf - ret = platform_nvm_read(test_nvm_callback, key_name, NULL, &buf_len, TEST_NS_NVM_HELPER_CONTEXT1); - if (ret != PLATFORM_NVM_ERROR) { - return false; - } - - // no buf_len - ret = platform_nvm_read(test_nvm_callback, key_name, buf, NULL, TEST_NS_NVM_HELPER_CONTEXT1); - if (ret != PLATFORM_NVM_ERROR) { - return false; - } - - // OK - ret = platform_nvm_read(test_nvm_callback, key_name, buf, &buf_len, TEST_NS_NVM_HELPER_CONTEXT1); - if (ret != PLATFORM_NVM_OK) { - return false; - } - - // simulate open - cfstore_stub.cmd_code = CFSTORE_OPCODE_OPEN; - test_callback_data_clear(active_cb_data_ptr); - test_cfstore_callback_trigger(); - test_eventOS_timeout_trigger(); // should not have any effect as state is opening - if (test_callback_executed(active_cb_data_ptr)) { - return false; - } - - // simulate read - cfstore_stub.cmd_code = CFSTORE_OPCODE_READ; - test_callback_data_clear(active_cb_data_ptr); - test_cfstore_callback_trigger(); - test_eventOS_timeout_trigger(); // should not have any effect since state is deleting - if (test_callback_executed(active_cb_data_ptr)) { - return false; - } - - // simulate close - cfstore_stub.cmd_code = CFSTORE_OPCODE_CLOSE; - test_callback_data_clear(active_cb_data_ptr); - test_cfstore_callback_trigger(); - test_eventOS_timeout_trigger(); //trigger callback - - if (active_cb_data_ptr->status != PLATFORM_NVM_OK || active_cb_data_ptr->ctx != TEST_NS_NVM_HELPER_CONTEXT1) { - return false; - } - - test_callback_data_clear(active_cb_data_ptr); - if (!test_nvm_finalize()) { - return false; - } - - return true; -} - -bool test_cs_nvm_read_failure() -{ - platform_nvm_status ret; - active_cb_data_ptr = &cb_data; - - if (!test_nvm_initialize()) { - return false; - } - test_callback_data_clear(active_cb_data_ptr); - - // Open fails - cfstore_stub.ret_val = ARM_DRIVER_ERROR; - ret = platform_nvm_read(test_nvm_callback, key_name, buf, &buf_len, TEST_NS_NVM_HELPER_CONTEXT2); - if (ret != PLATFORM_NVM_OK) { - return false; - } - cfstore_stub.cmd_code = CFSTORE_OPCODE_OPEN; - test_callback_data_clear(active_cb_data_ptr); - test_cfstore_callback_trigger(); - test_eventOS_timeout_trigger(); // should not have any effect as state is opening - if (active_cb_data_ptr->status != PLATFORM_NVM_ERROR || active_cb_data_ptr->ctx != TEST_NS_NVM_HELPER_CONTEXT2) { - return false; - } - - // Read fails - cfstore_stub.ret_val = ARM_DRIVER_OK; - cfstore_stub.read_ret_val = ARM_DRIVER_OK; - cfstore_stub.close_ret_val = ARM_DRIVER_OK; - test_callback_data_clear(active_cb_data_ptr); - ret = platform_nvm_read(test_nvm_callback, key_name, buf, &buf_len, TEST_NS_NVM_HELPER_CONTEXT2); - if (ret != PLATFORM_NVM_OK) { - return false; - } - - // simulate open - cfstore_stub.cmd_code = CFSTORE_OPCODE_OPEN; - cfstore_stub.read_ret_val = ARM_DRIVER_ERROR; - test_callback_data_clear(active_cb_data_ptr); - test_cfstore_callback_trigger(); - test_eventOS_timeout_trigger(); // should not have any effect as state is opening - if (test_callback_executed(active_cb_data_ptr)) { - return false; - } - - // simulate read - cfstore_stub.cmd_code = CFSTORE_OPCODE_READ; - test_callback_data_clear(active_cb_data_ptr); - test_cfstore_callback_trigger(); - test_eventOS_timeout_trigger(); // should not have any effect since state is deleting - if (test_callback_executed(active_cb_data_ptr)) { - return false; - } - - // simulate close - cfstore_stub.cmd_code = CFSTORE_OPCODE_CLOSE; - test_callback_data_clear(active_cb_data_ptr); - test_cfstore_callback_trigger(); - test_eventOS_timeout_trigger(); //trigger callback - - if (active_cb_data_ptr->status != PLATFORM_NVM_ERROR || active_cb_data_ptr->ctx != TEST_NS_NVM_HELPER_CONTEXT2) { - return false; - } - - if (!test_nvm_finalize()) { - return false; - } - - return true; -} - -bool test_cs_nvm_read_failure_in_close() -{ - platform_nvm_status ret; - active_cb_data_ptr = &cb_data; - - if (!test_nvm_initialize()) { - return false; - } - test_callback_data_clear(active_cb_data_ptr); - - // Open fails - cfstore_stub.ret_val = ARM_DRIVER_ERROR; - ret = platform_nvm_read(test_nvm_callback, key_name, buf, &buf_len, TEST_NS_NVM_HELPER_CONTEXT2); - if (ret != PLATFORM_NVM_OK) { - return false; - } - cfstore_stub.cmd_code = CFSTORE_OPCODE_OPEN; - test_callback_data_clear(active_cb_data_ptr); - test_cfstore_callback_trigger(); - test_eventOS_timeout_trigger(); // should not have any effect as state is opening - if (active_cb_data_ptr->status != PLATFORM_NVM_ERROR || active_cb_data_ptr->ctx != TEST_NS_NVM_HELPER_CONTEXT2) { - return false; - } - - // Read is OK but closing fails - cfstore_stub.ret_val = ARM_DRIVER_OK; - cfstore_stub.read_ret_val = ARM_DRIVER_OK; - cfstore_stub.close_ret_val = ARM_DRIVER_ERROR; - test_callback_data_clear(active_cb_data_ptr); - ret = platform_nvm_read(test_nvm_callback, key_name, buf, &buf_len, TEST_NS_NVM_HELPER_CONTEXT2); - if (ret != PLATFORM_NVM_OK) { - return false; - } - - // simulate open - cfstore_stub.cmd_code = CFSTORE_OPCODE_OPEN; - test_callback_data_clear(active_cb_data_ptr); - test_cfstore_callback_trigger(); - test_eventOS_timeout_trigger(); // should not have any effect as state is opening - if (test_callback_executed(active_cb_data_ptr)) { - return false; - } - - // simulate read - cfstore_stub.cmd_code = CFSTORE_OPCODE_READ; - test_callback_data_clear(active_cb_data_ptr); - test_cfstore_callback_trigger(); - - // simulate close - cfstore_stub.cmd_code = CFSTORE_OPCODE_CLOSE; - test_callback_data_clear(active_cb_data_ptr); - test_cfstore_callback_trigger(); - test_eventOS_timeout_trigger(); //trigger callback - - if (active_cb_data_ptr->status != PLATFORM_NVM_ERROR || active_cb_data_ptr->ctx != TEST_NS_NVM_HELPER_CONTEXT2) { - return false; - } - - if (!test_nvm_finalize()) { - return false; - } - - return true; -} - -bool test_cs_nvm_write() -{ - platform_nvm_status ret; - active_cb_data_ptr = &cb_data; - test_callback_data_clear(active_cb_data_ptr); - cfstore_stub.ret_val = ARM_DRIVER_OK; - cfstore_stub.read_ret_val = ARM_DRIVER_OK; - cfstore_stub.close_ret_val = ARM_DRIVER_OK; - - // write uninitialized - ret = platform_nvm_write(test_nvm_callback, key_name, buf, &buf_len, TEST_NS_NVM_HELPER_CONTEXT1); - if (ret != PLATFORM_NVM_ERROR) { - return false; - } - - if (!test_nvm_initialize()) { - return false; - } - test_callback_data_clear(active_cb_data_ptr); - - // no callback - ret = platform_nvm_write(NULL, key_name, buf, &buf_len, TEST_NS_NVM_HELPER_CONTEXT1); - if (ret != PLATFORM_NVM_ERROR) { - return false; - } - - // no key_name - ret = platform_nvm_write(test_nvm_callback, NULL, buf, &buf_len, TEST_NS_NVM_HELPER_CONTEXT1); - if (ret != PLATFORM_NVM_ERROR) { - return false; - } - - // no buf - ret = platform_nvm_write(test_nvm_callback, key_name, NULL, &buf_len, TEST_NS_NVM_HELPER_CONTEXT1); - if (ret != PLATFORM_NVM_ERROR) { - return false; - } - - // no buf_len - ret = platform_nvm_write(test_nvm_callback, key_name, buf, NULL, TEST_NS_NVM_HELPER_CONTEXT1); - if (ret != PLATFORM_NVM_ERROR) { - return false; - } - - // OK - ret = platform_nvm_write(test_nvm_callback, key_name, buf, &buf_len, TEST_NS_NVM_HELPER_CONTEXT1); - if (ret != PLATFORM_NVM_OK) { - return false; - } - - // simulate open - cfstore_stub.cmd_code = CFSTORE_OPCODE_OPEN; - test_callback_data_clear(active_cb_data_ptr); - test_cfstore_callback_trigger(); - test_eventOS_timeout_trigger(); // should not have any effect as state is opening - if (test_callback_executed(active_cb_data_ptr)) { - return false; - } - - // simulate write - cfstore_stub.cmd_code = CFSTORE_OPCODE_WRITE; - test_callback_data_clear(active_cb_data_ptr); - test_cfstore_callback_trigger(); - test_eventOS_timeout_trigger(); // should not have any effect since state is deleting - if (test_callback_executed(active_cb_data_ptr)) { - return false; - } - - // simulate close - cfstore_stub.cmd_code = CFSTORE_OPCODE_CLOSE; - test_callback_data_clear(active_cb_data_ptr); - test_cfstore_callback_trigger(); - test_eventOS_timeout_trigger(); //trigger callback - - if (active_cb_data_ptr->status != PLATFORM_NVM_OK || active_cb_data_ptr->ctx != TEST_NS_NVM_HELPER_CONTEXT1) { - return false; - } - - test_callback_data_clear(active_cb_data_ptr); - if (!test_nvm_finalize()) { - return false; - } - - return true; -} - -bool test_cs_nvm_write_failure() -{ - platform_nvm_status ret; - active_cb_data_ptr = &cb_data; - test_callback_data_clear(active_cb_data_ptr); - - if (!test_nvm_initialize()) { - return false; - } - test_callback_data_clear(active_cb_data_ptr); - - // write fails on open - cfstore_stub.ret_val = ARM_DRIVER_ERROR; - cfstore_stub.write_ret_val = ARM_DRIVER_OK; - cfstore_stub.close_ret_val = ARM_DRIVER_OK; - ret = platform_nvm_write(test_nvm_callback, key_name, buf, &buf_len, TEST_NS_NVM_HELPER_CONTEXT1); - if (ret != PLATFORM_NVM_OK) { - return false; - } - // simulate open - cfstore_stub.cmd_code = CFSTORE_OPCODE_OPEN; - test_callback_data_clear(active_cb_data_ptr); - test_cfstore_callback_trigger(); - test_eventOS_timeout_trigger(); // should not have any effect as state is opening - if (active_cb_data_ptr->status != PLATFORM_NVM_ERROR || active_cb_data_ptr->ctx != TEST_NS_NVM_HELPER_CONTEXT1) { - return false; - } - - // write fails on write and also close fails - cfstore_stub.ret_val = ARM_DRIVER_OK; - cfstore_stub.write_ret_val = ARM_DRIVER_ERROR; - cfstore_stub.close_ret_val = ARM_DRIVER_ERROR; - ret = platform_nvm_write(test_nvm_callback, key_name, buf, &buf_len, TEST_NS_NVM_HELPER_CONTEXT1); - if (ret != PLATFORM_NVM_OK) { - return false; - } - // simulate open, write - fails and close fails - cfstore_stub.cmd_code = CFSTORE_OPCODE_OPEN; - test_callback_data_clear(active_cb_data_ptr); - test_cfstore_callback_trigger(); - test_eventOS_timeout_trigger(); // should not have any effect as state is opening - - if (active_cb_data_ptr->status != PLATFORM_NVM_ERROR || active_cb_data_ptr->ctx != TEST_NS_NVM_HELPER_CONTEXT1) { - return false; - } - - test_callback_data_clear(active_cb_data_ptr); - if (!test_nvm_finalize()) { - return false; - } - - return true; -} - -bool test_cs_nvm_write_failure_in_close() -{ - platform_nvm_status ret; - active_cb_data_ptr = &cb_data; - - if (!test_nvm_initialize()) { - return false; - } - test_callback_data_clear(active_cb_data_ptr); - - // write is OK but closing fails - cfstore_stub.ret_val = ARM_DRIVER_OK; - cfstore_stub.write_ret_val = ARM_DRIVER_OK; - cfstore_stub.close_ret_val = ARM_DRIVER_ERROR; - test_callback_data_clear(active_cb_data_ptr); - ret = platform_nvm_write(test_nvm_callback, key_name, buf, &buf_len, TEST_NS_NVM_HELPER_CONTEXT2); - if (ret != PLATFORM_NVM_OK) { - return false; - } - - // simulate open - cfstore_stub.cmd_code = CFSTORE_OPCODE_OPEN; - test_callback_data_clear(active_cb_data_ptr); - test_cfstore_callback_trigger(); - test_eventOS_timeout_trigger(); // should not have any effect as state is opening - if (test_callback_executed(active_cb_data_ptr)) { - return false; - } - - // simulate write - cfstore_stub.cmd_code = CFSTORE_OPCODE_WRITE; - test_callback_data_clear(active_cb_data_ptr); - test_cfstore_callback_trigger(); - - // simulate close - cfstore_stub.cmd_code = CFSTORE_OPCODE_CLOSE; - test_callback_data_clear(active_cb_data_ptr); - test_cfstore_callback_trigger(); - test_eventOS_timeout_trigger(); //trigger callback - - if (active_cb_data_ptr->status != PLATFORM_NVM_ERROR || active_cb_data_ptr->ctx != TEST_NS_NVM_HELPER_CONTEXT2) { - return false; - } - - if (!test_nvm_finalize()) { - return false; - } - - return true; -} - -bool test_cs_nvm_flush() -{ - platform_nvm_status ret; - active_cb_data_ptr = &cb_data; - test_callback_data_clear(active_cb_data_ptr); - cfstore_stub.ret_val = ARM_DRIVER_OK; - cfstore_stub.write_ret_val = ARM_DRIVER_OK; - cfstore_stub.close_ret_val = ARM_DRIVER_OK; - - // flush with NVM uninitialized - ret = platform_nvm_flush(test_nvm_callback, TEST_NS_NVM_HELPER_CONTEXT3); - if (ret != PLATFORM_NVM_ERROR) { - return false; - } - - if (!test_nvm_initialize()) { - return false; - } - test_callback_data_clear(active_cb_data_ptr); - - // no callback - ret = platform_nvm_flush(NULL, TEST_NS_NVM_HELPER_CONTEXT1); - if (ret != PLATFORM_NVM_ERROR) { - return false; - } - - // flush failure - cfstore_stub.ret_val = ARM_DRIVER_ERROR; - ret = platform_nvm_flush(test_nvm_callback, TEST_NS_NVM_HELPER_CONTEXT3); - if (ret != PLATFORM_NVM_OK) { - return false; - } - // simulate flush - cfstore_stub.cmd_code = CFSTORE_OPCODE_FLUSH; - test_callback_data_clear(active_cb_data_ptr); - test_cfstore_callback_trigger(); - test_eventOS_timeout_trigger(); // should not have any effect as state is opening - if (active_cb_data_ptr->status != PLATFORM_NVM_ERROR || active_cb_data_ptr->ctx != TEST_NS_NVM_HELPER_CONTEXT3) { - return false; - } - - // OK flush - cfstore_stub.ret_val = ARM_DRIVER_OK; - ret = platform_nvm_flush(test_nvm_callback, TEST_NS_NVM_HELPER_CONTEXT3); - if (ret != PLATFORM_NVM_OK) { - return false; - } - // simulate flush - cfstore_stub.cmd_code = CFSTORE_OPCODE_FLUSH; - test_callback_data_clear(active_cb_data_ptr); - test_cfstore_callback_trigger(); - test_eventOS_timeout_trigger(); // should not have any effect as state is opening - if (active_cb_data_ptr->status != PLATFORM_NVM_OK || active_cb_data_ptr->ctx != TEST_NS_NVM_HELPER_CONTEXT3) { - return false; - } - - test_callback_data_clear(active_cb_data_ptr); - if (!test_nvm_finalize()) { - return false; - } - - return true; -} - -bool test_cs_nvm_operation_in_progress() -{ - platform_nvm_status ret; - active_cb_data_ptr = &cb_data; - test_callback_data_clear(active_cb_data_ptr); - cfstore_stub.ret_val = ARM_DRIVER_OK; - cfstore_stub.write_ret_val = ARM_DRIVER_OK; - cfstore_stub.close_ret_val = ARM_DRIVER_OK; - - - if (!test_nvm_initialize()) { - return false; - } - - // Make key - test_callback_data_clear(active_cb_data_ptr); - cfstore_stub.ret_val = ARM_CFSTORE_DRIVER_ERROR_KEY_NOT_FOUND; - ret = platform_nvm_key_create(test_nvm_callback, key_name, data_len, 0, TEST_NS_NVM_HELPER_CONTEXT3); - if (ret != PLATFORM_NVM_OK) { - return false; - } - - // make new requests while key creation is in progress - ret = platform_nvm_init(test_nvm_callback, TEST_NS_NVM_HELPER_CONTEXT1); - if (ret != PLATFORM_NVM_ERROR) { - return false; - } - ret = platform_nvm_key_create(test_nvm_callback, key_name, data_len, 0, TEST_NS_NVM_HELPER_CONTEXT3); - if (ret != PLATFORM_NVM_ERROR) { - return false; - } - ret = platform_nvm_key_delete(test_nvm_callback, key_name, TEST_NS_NVM_HELPER_CONTEXT1); - if (ret != PLATFORM_NVM_ERROR) { - return false; - } - ret = platform_nvm_read(test_nvm_callback, key_name, buf, &buf_len, TEST_NS_NVM_HELPER_CONTEXT1); - if (ret != PLATFORM_NVM_ERROR) { - return false; - } - ret = platform_nvm_write(test_nvm_callback, key_name, buf, &buf_len, TEST_NS_NVM_HELPER_CONTEXT1); - if (ret != PLATFORM_NVM_ERROR) { - return false; - } - ret = platform_nvm_flush(test_nvm_callback, TEST_NS_NVM_HELPER_CONTEXT3); - if (ret != PLATFORM_NVM_ERROR) { - return false; - } - ret = platform_nvm_finalize(test_nvm_callback, TEST_NS_NVM_HELPER_CONTEXT2); - if (ret != PLATFORM_NVM_ERROR) { - return false; - } - - // continue with key creation - cfstore_stub.cmd_code = CFSTORE_OPCODE_CREATE; - test_callback_data_clear(active_cb_data_ptr); - test_cfstore_callback_trigger(); - test_eventOS_timeout_trigger(); - if (active_cb_data_ptr->status != PLATFORM_NVM_KEY_NOT_FOUND || active_cb_data_ptr->ctx != TEST_NS_NVM_HELPER_CONTEXT3) { - return false; - } - - // test2, check that other cmd_codes are not handled/affecting - cfstore_stub.cmd_code = CFSTORE_OPCODE_MAX; - test_callback_data_clear(active_cb_data_ptr); - test_cfstore_callback_trigger(); - test_eventOS_timeout_trigger(); - if (test_callback_executed(active_cb_data_ptr)) { - return false; - } - - if (!test_nvm_finalize()) { - return false; - } - - return true; -} - diff --git a/features/nanostack/nanostack-hal-mbed-cmsis-rtos/cs_nvm/test/test_cs_nvm_unit/unittest/cs_nvm/test_cs_nvm.h b/features/nanostack/nanostack-hal-mbed-cmsis-rtos/cs_nvm/test/test_cs_nvm_unit/unittest/cs_nvm/test_cs_nvm.h deleted file mode 100644 index b14537d..0000000 --- a/features/nanostack/nanostack-hal-mbed-cmsis-rtos/cs_nvm/test/test_cs_nvm_unit/unittest/cs_nvm/test_cs_nvm.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2016, 2018, Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef TEST_NS_NVM_HELPER_H -#define TEST_NS_NVM_HELPER_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -bool test_cs_nvm_init_finalize(); -bool test_cs_nvm_key_create(); -bool test_cs_nvm_key_delete(); -bool test_cs_nvm_key_delete_failure_in_close(); -bool test_cs_nvm_read(); -bool test_cs_nvm_read_failure(); -bool test_cs_nvm_read_failure_in_close(); -bool test_cs_nvm_write(); -bool test_cs_nvm_write_failure(); -bool test_cs_nvm_write_failure_in_close(); -bool test_cs_nvm_flush(); -bool test_cs_nvm_operation_in_progress(); - -#ifdef __cplusplus -} -#endif - -#endif // TEST_NS_NVM_HELPER_H - diff --git a/features/nanostack/nanostack-hal-mbed-cmsis-rtos/cs_nvm/test/test_cs_nvm_unit/unittest/makefile_defines.txt b/features/nanostack/nanostack-hal-mbed-cmsis-rtos/cs_nvm/test/test_cs_nvm_unit/unittest/makefile_defines.txt deleted file mode 100644 index 24b1669..0000000 --- a/features/nanostack/nanostack-hal-mbed-cmsis-rtos/cs_nvm/test/test_cs_nvm_unit/unittest/makefile_defines.txt +++ /dev/null @@ -1,19 +0,0 @@ -#--- Inputs ----# -CPPUTEST_HOME = /usr -CPPUTEST_USE_EXTENSIONS = Y -CPPUTEST_USE_VPATH = Y -CPPUTEST_USE_GCOV = Y -CPP_PLATFORM = gcc -INCLUDE_DIRS =\ - .\ - ../stubs\ - ../../../../..\ - ../../../../../../../core/configuration-store/\ - ../../../../../../../core/flash-abstraction/\ - ../../../../../../nanostack-libservice/mbed-client-libservice/\ - ../../../../../../sal-stack-nanostack-eventloop/nanostack-event-loop/\ - /usr/include\ - $(CPPUTEST_HOME)/include\ - -CPPUTESTFLAGS = -D__thumb2__ -w -CPPUTEST_CFLAGS += -std=gnu99 diff --git a/features/nanostack/nanostack-hal-mbed-cmsis-rtos/cs_nvm/test/test_cs_nvm_unit/unittest/run_tests b/features/nanostack/nanostack-hal-mbed-cmsis-rtos/cs_nvm/test/test_cs_nvm_unit/unittest/run_tests deleted file mode 100644 index 94ec5b9..0000000 --- a/features/nanostack/nanostack-hal-mbed-cmsis-rtos/cs_nvm/test/test_cs_nvm_unit/unittest/run_tests +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/bash -echo -echo Build M2M API unit tests -echo - -# Remember to add new test folder to Makefile -make clean -make all - -echo -echo Create results -echo -mkdir results - -find ./ -name '*.xml' | xargs cp -t ./results/ - -echo -echo Create coverage document -echo -mkdir coverages -cd coverages - -#copy the .gcda & .gcno for all test projects (no need to modify -#cp ../../../source/*.gc* . -#find ../ -name '*.gcda' | xargs cp -t . -#find ../ -name '*.gcno' | xargs cp -t . -#find . -name "test*" -type f -delete -#find . -name "*test*" -type f -delete -#find . -name "*stub*" -type f -delete -#rm -rf main.* - -lcov -q -d ../. -c -o app.info -lcov -q -r app.info "/test*" -o app.info -lcov -q -r app.info "/usr*" -o app.info -genhtml --no-branch-coverage app.info -cd .. -echo -echo -echo -echo Have a nice bug hunt! -echo -echo -echo diff --git a/features/nanostack/nanostack-hal-mbed-cmsis-rtos/cs_nvm/test/test_cs_nvm_unit/unittest/stubs/configuration_store_stub.c b/features/nanostack/nanostack-hal-mbed-cmsis-rtos/cs_nvm/test/test_cs_nvm_unit/unittest/stubs/configuration_store_stub.c deleted file mode 100644 index 556c159..0000000 --- a/features/nanostack/nanostack-hal-mbed-cmsis-rtos/cs_nvm/test/test_cs_nvm_unit/unittest/stubs/configuration_store_stub.c +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Copyright (c) 2016, 2018, Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include "configuration_store_stub.h" - -configuration_store_stub_data_t cfstore_stub = {ARM_DRIVER_OK, ARM_DRIVER_OK, ARM_DRIVER_OK, ARM_DRIVER_OK, ARM_DRIVER_OK, 0, NULL, NULL, NULL}; - -static int32_t test_cfstore_close(ARM_CFSTORE_HANDLE hkey) -{ - return cfstore_stub.close_ret_val; -} - -static int32_t test_cfstore_create(const char *key_name, ARM_CFSTORE_SIZE value_len, const ARM_CFSTORE_KEYDESC *kdesc, ARM_CFSTORE_HANDLE hkey) -{ - return cfstore_stub.ret_val; -} - -static int32_t test_cfstore_delete(ARM_CFSTORE_HANDLE hkey) -{ - return cfstore_stub.delete_ret_val; -} - -static int32_t test_cfstore_find(const char *key_name_query, const ARM_CFSTORE_HANDLE previous, ARM_CFSTORE_HANDLE next) -{ - return ARM_DRIVER_OK; -} - -static int32_t test_cfstore_flush(void) -{ - return cfstore_stub.ret_val; -} - -ARM_CFSTORE_CAPABILITIES test_cfstore_get_capabilities(void) -{ - static ARM_CFSTORE_CAPABILITIES cfstore_caps_g = { .asynchronous_ops = 1 }; - return cfstore_caps_g; -} - -static int32_t test_cfstore_get_key_name(ARM_CFSTORE_HANDLE hkey, char *key_name, uint8_t *key_name_len) -{ - return ARM_DRIVER_OK; -} - -static ARM_CFSTORE_STATUS test_cfstore_get_status(void) -{ - ARM_CFSTORE_STATUS status; - return status; -} - -static int32_t test_cfstore_get_value_len(ARM_CFSTORE_HANDLE hkey, ARM_CFSTORE_SIZE *value_len) -{ - return ARM_DRIVER_OK; -} - -ARM_DRIVER_VERSION test_cfstore_get_version(void) -{ - static const ARM_DRIVER_VERSION cfstore_driver_version_g = { .api = ARM_CFSTORE_API_VERSION, .drv = ARM_CFSTORE_DRV_VERSION }; - return cfstore_driver_version_g; -} - -static int32_t test_cfstore_initialise(ARM_CFSTORE_CALLBACK callback, void *client_context) -{ - cfstore_stub.callback = callback; - cfstore_stub.client_context = client_context; - return cfstore_stub.ret_val; -} - -static int32_t test_cfstore_open(const char *key_name, ARM_CFSTORE_FMODE flags, ARM_CFSTORE_HANDLE hkey) -{ - return cfstore_stub.ret_val; -} - -static int32_t test_cfstore_power_control(ARM_POWER_STATE state) -{ - return ARM_DRIVER_OK; -} - -static int32_t test_cfstore_read(ARM_CFSTORE_HANDLE hkey, void *data, ARM_CFSTORE_SIZE *len) -{ - return cfstore_stub.read_ret_val; -} - -static int32_t test_cfstore_rseek(ARM_CFSTORE_HANDLE hkey, ARM_CFSTORE_OFFSET offset) -{ - return ARM_DRIVER_OK; -} - -static int32_t test_cfstore_uninitialise(void) -{ - return cfstore_stub.ret_val; -} - -static int32_t test_cfstore_write(ARM_CFSTORE_HANDLE hkey, const char *data, ARM_CFSTORE_SIZE *len) -{ - return cfstore_stub.write_ret_val; -} - -ARM_CFSTORE_DRIVER cfstore_driver = { - .Close = test_cfstore_close, - .Create = test_cfstore_create, - .Delete = test_cfstore_delete, - .Find = test_cfstore_find, - .Flush = test_cfstore_flush, - .GetCapabilities = test_cfstore_get_capabilities, - .GetKeyName = test_cfstore_get_key_name, - .GetStatus = test_cfstore_get_status, - .GetValueLen = test_cfstore_get_value_len, - .GetVersion = test_cfstore_get_version, - .Initialize = test_cfstore_initialise, - .Open = test_cfstore_open, - .PowerControl = test_cfstore_power_control, - .Read = test_cfstore_read, - .Rseek = test_cfstore_rseek, - .Uninitialize = test_cfstore_uninitialise, - .Write = test_cfstore_write, -}; - - -void test_cfstore_callback_trigger() -{ - cfstore_stub.callback(cfstore_stub.ret_val, cfstore_stub.cmd_code, cfstore_stub.client_context, cfstore_stub.handle); -} - diff --git a/features/nanostack/nanostack-hal-mbed-cmsis-rtos/cs_nvm/test/test_cs_nvm_unit/unittest/stubs/configuration_store_stub.h b/features/nanostack/nanostack-hal-mbed-cmsis-rtos/cs_nvm/test/test_cs_nvm_unit/unittest/stubs/configuration_store_stub.h deleted file mode 100644 index 418b230..0000000 --- a/features/nanostack/nanostack-hal-mbed-cmsis-rtos/cs_nvm/test/test_cs_nvm_unit/unittest/stubs/configuration_store_stub.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2016, 2018, Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef __CONFIGURATION_STORE_STUB_H__ -#define __CONFIGURATION_STORE_STUB_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -#include "stdint.h" - -typedef struct { - int32_t ret_val; - int32_t delete_ret_val; - int32_t read_ret_val; - int32_t close_ret_val; - int32_t write_ret_val; - ARM_CFSTORE_OPCODE cmd_code; - void *client_context; - ARM_CFSTORE_HANDLE handle; - ARM_CFSTORE_CALLBACK callback; -} configuration_store_stub_data_t; - -extern configuration_store_stub_data_t cfstore_stub; - -void test_cfstore_callback_trigger(void); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/features/nanostack/nanostack-hal-mbed-cmsis-rtos/cs_nvm/test/test_cs_nvm_unit/unittest/stubs/ns_trace_stub.c b/features/nanostack/nanostack-hal-mbed-cmsis-rtos/cs_nvm/test/test_cs_nvm_unit/unittest/stubs/ns_trace_stub.c deleted file mode 100644 index d58eb4c..0000000 --- a/features/nanostack/nanostack-hal-mbed-cmsis-rtos/cs_nvm/test/test_cs_nvm_unit/unittest/stubs/ns_trace_stub.c +++ /dev/null @@ -1,217 +0,0 @@ -/* - * Copyright (c) 2014-2016, 2018, Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include - -#include "ns_trace.h" -#include "ip6string.h" -#include "common_functions.h" - -#if defined(_WIN32) || defined(__unix__) || defined(__unix) || defined(unix) -#ifndef MEM_ALLOC -#define MEM_ALLOC malloc -#endif -#ifndef MEM_FREE -#define MEM_FREE free -#endif -#else -#include "nsdynmemLIB.h" -#ifndef MEM_ALLOC -#define MEM_ALLOC ns_dyn_mem_alloc -#endif -#ifndef MEM_FREE -#define MEM_FREE ns_dyn_mem_free -#endif -#endif - -#define VT100_COLOR_ERROR "\x1b[31m" -#define VT100_COLOR_WARN "\x1b[33m" -#define VT100_COLOR_INFO "\x1b[39m" -#define VT100_COLOR_DEBUG "\x1b[90m" - -/** default max trace line size in bytes */ -#define DEFAULT_TRACE_LINE_LENGTH 1024 -/** default max temporary buffer size in bytes, used in - trace_ipv6, trace_array and trace_strn */ -#define DEFAULT_TRACE_TMP_LINE_LEN 128 -/** default max filters (include/exclude) length in bytes */ -#define DEFAULT_TRACE_FILTER_LENGTH 24 - -static void default_print(const char *str); - -typedef struct { - /** trace configuration bits */ - uint8_t trace_config; - /** exclude filters list, related group name */ - char *filters_exclude; - /** include filters list, related group name */ - char *filters_include; - /** Filters length */ - int filters_length; - /** trace line */ - char *line; - /** trace line length */ - int line_length; - /** temporary data */ - char *tmp_data; - /** temporary data array length */ - int tmp_data_length; - /** temporary data pointer */ - char *tmp_data_ptr; - - /** prefix function, which can be used to put time to the trace line */ - char *(*prefix_f)(size_t); - /** suffix function, which can be used to some string to the end of trace line */ - char *(*suffix_f)(void); - /** print out function. Can be redirect to flash for example. */ - void (*printf)(const char *); - /** print out function for TRACE_LEVEL_CMD */ - void (*cmd_printf)(const char *); -} trace_s; - -static trace_s m_trace = { - .filters_exclude = 0, - .filters_include = 0, - .line = 0, - .tmp_data = 0, - .prefix_f = 0, - .suffix_f = 0, - .printf = 0, - .cmd_printf = 0 -}; - -int trace_init(void) -{ - return 0; -} -void trace_free(void) -{ - -} - -void set_trace_config(uint8_t config) -{ - -} -uint8_t get_trace_config(void) -{ - return 0; -} -void set_trace_prefix_function(char *(*pref_f)(size_t)) -{ -} - -void set_trace_suffix_function(char *(*suffix_f)(void)) -{ -} - -void set_trace_print_function(void (*printf)(const char *)) -{ -} - -void set_trace_cmdprint_function(void (*printf)(const char *)) -{ -} - -void set_trace_exclude_filters(char *filters) -{ -} -const char *get_trace_exclude_filters(void) -{ - return NULL; -} - -const char *get_trace_include_filters(void) -{ - return NULL; -} - -void set_trace_include_filters(char *filters) -{ -} - -static int8_t trace_skip(int8_t dlevel, const char *grp) -{ - return 0; -} - -static void default_print(const char *str) -{ -} - -void tracef(uint8_t dlevel, const char *grp, const char *fmt, ...) -{ - -} -const char *trace_last(void) -{ - return ""; -} - -/* Helping functions */ -#define tmp_data_left() m_trace.tmp_data_length-(m_trace.tmp_data_ptr-m_trace.tmp_data) -char *trace_ipv6(const void *addr_ptr) -{ - return ""; -} - -char *trace_ipv6_prefix(const uint8_t *prefix, uint8_t prefix_len) -{ - return ""; -} - -char *trace_array(const uint8_t *buf, uint16_t len) -{ - return ""; -} - -// rest of debug print functions will be obsolete and will be overridden with new trace interface.. -void debugf(const char *fmt, ...) -{ -} - -void debug(const char *s) -{ -} - -void debug_put(char c) -{ -} - -void debug_hex(uint8_t x) -{ -} - -void debug_int(int i) -{ -} - -void printf_array(const void *buf, uint16_t len) -{ -} - -void printf_ipv6_address(const void *addr_ptr) -{ -} - -void printf_string(const void *ptr, uint16_t len) -{ -} - diff --git a/features/nanostack/nanostack-hal-mbed-cmsis-rtos/cs_nvm/test/test_cs_nvm_unit/unittest/stubs/nsdynmemLIB_stub.c b/features/nanostack/nanostack-hal-mbed-cmsis-rtos/cs_nvm/test/test_cs_nvm_unit/unittest/stubs/nsdynmemLIB_stub.c deleted file mode 100644 index e870047..0000000 --- a/features/nanostack/nanostack-hal-mbed-cmsis-rtos/cs_nvm/test/test_cs_nvm_unit/unittest/stubs/nsdynmemLIB_stub.c +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2014-2016, 2018, Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "nsdynmemLIB_stub.h" -#include -#include -#include "nsdynmemLIB.h" -#include "platform/arm_hal_interrupt.h" -#include - -nsdynmemlib_stub_data_t nsdynmemlib_stub; - -void ns_dyn_mem_init(uint8_t *heap, uint16_t h_size, void (*passed_fptr)(heap_fail_t), mem_stat_t *info_ptr) -{ -} - -void *ns_dyn_mem_alloc(int16_t alloc_size) -{ - if (nsdynmemlib_stub.returnCounter > 0) { - nsdynmemlib_stub.returnCounter--; - return malloc(alloc_size); - } else { - return (nsdynmemlib_stub.expectedPointer); - } -} - -void *ns_dyn_mem_temporary_alloc(int16_t alloc_size) -{ - if (nsdynmemlib_stub.returnCounter > 0) { - nsdynmemlib_stub.returnCounter--; - return malloc(alloc_size); - } else { - return (nsdynmemlib_stub.expectedPointer); - } -} - -void ns_dyn_mem_free(void *block) -{ - free(block); -} - diff --git a/features/nanostack/nanostack-hal-mbed-cmsis-rtos/cs_nvm/test/test_cs_nvm_unit/unittest/stubs/nsdynmemLIB_stub.h b/features/nanostack/nanostack-hal-mbed-cmsis-rtos/cs_nvm/test/test_cs_nvm_unit/unittest/stubs/nsdynmemLIB_stub.h deleted file mode 100644 index 4ab78ec..0000000 --- a/features/nanostack/nanostack-hal-mbed-cmsis-rtos/cs_nvm/test/test_cs_nvm_unit/unittest/stubs/nsdynmemLIB_stub.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2015-2016, 2018, Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef __NSDYNMEMLIB_STUB_H__ -#define __NSDYNMEMLIB_STUB_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -#include "stdint.h" - -typedef struct { - uint8_t returnCounter; - void *expectedPointer; -} nsdynmemlib_stub_data_t; - -extern nsdynmemlib_stub_data_t nsdynmemlib_stub; - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/features/nanostack/nanostack-hal-mbed-cmsis-rtos/cs_nvm/test/test_cs_nvm_unit/unittest/stubs/timeout_stub.c b/features/nanostack/nanostack-hal-mbed-cmsis-rtos/cs_nvm/test/test_cs_nvm_unit/unittest/stubs/timeout_stub.c deleted file mode 100644 index 4e18eb5..0000000 --- a/features/nanostack/nanostack-hal-mbed-cmsis-rtos/cs_nvm/test/test_cs_nvm_unit/unittest/stubs/timeout_stub.c +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2016, 2018, Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "eventOS_event_timer.h" - -static void (*test_callback)(void *); -static void *test_args; - -timeout_t *eventOS_timeout_ms(void (*callback)(void *), uint32_t ms, void *arg) -{ - test_callback = callback; - test_args = arg; - return NULL; -} - -void eventOS_timeout_cancel(timeout_t *t) -{ - -} - -void test_eventOS_timeout_trigger() -{ - test_callback(test_args); -} - diff --git a/features/nanostack/nanostack-hal-mbed-cmsis-rtos/mbed_lib.json b/features/nanostack/nanostack-hal-mbed-cmsis-rtos/mbed_lib.json index 86e1c91..81d69b7 100644 --- a/features/nanostack/nanostack-hal-mbed-cmsis-rtos/mbed_lib.json +++ b/features/nanostack/nanostack-hal-mbed-cmsis-rtos/mbed_lib.json @@ -1,10 +1,6 @@ { "name": "nanostack-hal", "config": { - "nvm_cfstore": { - "help": "Use cfstore as a NVM storage. Else RAM simulation will be used", - "value": false - }, "event_loop_thread_stack_size": { "help": "Define event-loop thread stack size. [bytes]", "value": 6144 diff --git a/features/nanostack/nanostack-hal-mbed-cmsis-rtos/nvm/nvm_ram.c b/features/nanostack/nanostack-hal-mbed-cmsis-rtos/nvm/nvm_ram.c index 12a6974..167cb6d 100644 --- a/features/nanostack/nanostack-hal-mbed-cmsis-rtos/nvm/nvm_ram.c +++ b/features/nanostack/nanostack-hal-mbed-cmsis-rtos/nvm/nvm_ram.c @@ -15,14 +15,6 @@ * limitations under the License. */ -#ifdef MBED_CONF_NANOSTACK_HAL_NVM_CFSTORE -# if MBED_CONF_NANOSTACK_HAL_NVM_CFSTORE -# define IGNORE_SIMULATED_NVM_STORAGE -# else -# undef IGNORE_SIMULATED_NVM_STORAGE -# endif -#endif - /* * Define flag IGNORE_SIMULATED_NVM_STORAGE to ignore usage of simulated NVM and use * platform specific NVM instead. diff --git a/features/storage/FEATURE_STORAGE/TESTS/.mbedignore b/features/storage/FEATURE_STORAGE/TESTS/.mbedignore deleted file mode 100644 index 72e8ffc..0000000 --- a/features/storage/FEATURE_STORAGE/TESTS/.mbedignore +++ /dev/null @@ -1 +0,0 @@ -* diff --git a/features/storage/FEATURE_STORAGE/TESTS/cfstore/add_del/add_del.cpp b/features/storage/FEATURE_STORAGE/TESTS/cfstore/add_del/add_del.cpp deleted file mode 100644 index a5359a8..0000000 --- a/features/storage/FEATURE_STORAGE/TESTS/cfstore/add_del/add_del.cpp +++ /dev/null @@ -1,391 +0,0 @@ -/* - * mbed Microcontroller Library - * Copyright (c) 2006-2016 ARM Limited - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -/** @file add_del.cpp Test cases to add and delete key-value pairs in the CFSTORE. - * - * Please consult the documentation under the test-case functions for - * a description of the individual test case. - */ - -#include "mbed.h" -#include "cfstore_config.h" -#include "Driver_Common.h" -#include "cfstore_debug.h" -#include "cfstore_test.h" -#include "configuration_store.h" -#include "utest/utest.h" -#include "unity/unity.h" -#include "greentea-client/test_env.h" -#include "cfstore_utest.h" - -#include -#include -#include -#include - -using namespace utest::v1; - -#define CFSTORE_ADD_DEL_MALLOC_SIZE 1024 - -static char cfstore_add_del_utest_msg_g[CFSTORE_UTEST_MSG_BUF_SIZE]; - -static cfstore_kv_data_t cfstore_add_del_test_07_data[] = { - CFSTORE_INIT_1_TABLE_MID_NODE, - { NULL, NULL}, -}; - - -/* report whether built/configured for flash sync or async mode */ -static control_t cfstore_add_del_test_00(const size_t call_count) -{ - int32_t ret = ARM_DRIVER_ERROR; - - (void) call_count; - ret = cfstore_test_startup(); - 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); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_add_del_utest_msg_g); - return CaseNext; -} - -/** @brief - * - * This test case does the following: - * - creates a KV. - * - deletes the KV. - * - checks that the deleted KV can no longer be found in the store. - * - * @return on success returns CaseNext to continue to next test case, otherwise will assert on errors. - */ -control_t cfstore_add_del_test_01_end(const size_t call_count) -{ - bool bfound = false; - int32_t ret = ARM_DRIVER_ERROR; - ARM_CFSTORE_SIZE len = 0; - ARM_CFSTORE_DRIVER* drv = &cfstore_driver; - ARM_CFSTORE_KEYDESC kdesc; - ARM_CFSTORE_HANDLE_INIT(hkey); - ARM_CFSTORE_FMODE flags; - - CFSTORE_FENTRYLOG("%s:entered\n", __func__); - (void) call_count; - memset(&kdesc, 0, sizeof(kdesc)); - memset(&flags, 0, sizeof(flags)); - - kdesc.drl = ARM_RETENTION_WHILE_DEVICE_ACTIVE; - len = strlen(cfstore_add_del_test_07_data[0].value); - - ret = cfstore_test_create(cfstore_add_del_test_07_data[0].key_name, (char*) cfstore_add_del_test_07_data[0].value, &len, &kdesc); - 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); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_add_del_utest_msg_g); - - /* now delete KV*/ - ret = drv->Open(cfstore_add_del_test_07_data[0].key_name, flags, hkey); - 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); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_add_del_utest_msg_g); - - if(hkey != NULL){ - ret = drv->Delete(hkey); - drv->Close(hkey); - hkey = NULL; - } - /* check that the KV has been deleted */ - /* revert to CFSTORE_LOG if more trace required */ - 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); - ret = cfstore_test_kv_is_found(cfstore_add_del_test_07_data[0].key_name, &bfound); - 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); - TEST_ASSERT_MESSAGE(ret == ARM_CFSTORE_DRIVER_ERROR_KEY_NOT_FOUND, cfstore_add_del_utest_msg_g); - - 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); - TEST_ASSERT_MESSAGE(bfound == false, cfstore_add_del_utest_msg_g); - - ret = drv->Uninitialize(); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_add_del_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Uninitialize() call failed.\n", __func__); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_add_del_utest_msg_g); - return CaseNext; -} - - -static cfstore_kv_data_t cfstore_add_del_test_08_data[] = { - CFSTORE_INIT_1_TABLE_HEAD, - CFSTORE_INIT_1_TABLE_MID_NODE, - CFSTORE_INIT_1_TABLE_TAIL, - { NULL, NULL}, -}; - - -/** @brief - * - * This test case adds a small number of KVs (~3), and then delete them. - * - add key(s) - * - delete key(s) - * - make sure can't find key in cfstore - * - loop over the above a number of times. - * - * @return on success returns CaseNext to continue to next test case, otherwise will assert on errors. - */ -control_t cfstore_add_del_test_02_end(const size_t call_count) -{ - bool bResult = true; // We'll do "&=" cumulative checking. - int32_t ret = ARM_DRIVER_ERROR; - ARM_CFSTORE_SIZE len = 0; - ARM_CFSTORE_KEYDESC kdesc; - cfstore_kv_data_t* node = NULL; - ARM_CFSTORE_DRIVER* drv = &cfstore_driver; - - CFSTORE_FENTRYLOG("%s:entered\n", __func__); - (void) call_count; - memset(&kdesc, 0, sizeof(kdesc)); - - /* create */ - kdesc.drl = ARM_RETENTION_WHILE_DEVICE_ACTIVE; - node = cfstore_add_del_test_08_data; - while(node->key_name != NULL) - { - len = strlen(node->value); - ret = cfstore_test_create(node->key_name, (char*) node->value, &len, &kdesc); - 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); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_add_del_utest_msg_g); - /* revert CFSTORE_LOG for more trace */ - CFSTORE_DBGLOG("Created KV successfully (key_name=\"%s\", value=\"%s\")\n", node->key_name, node->value); - node++; - } - - /* test delete all */ - ret = cfstore_test_delete_all(); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_add_del_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to delete all KVs.\n", __func__); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_add_del_utest_msg_g); - - /* check there are no KVs present as expected */ - node = cfstore_add_del_test_08_data; - while(node->key_name != NULL) - { - ret = cfstore_test_kv_is_found(node->key_name, &bResult); - 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__); - TEST_ASSERT_MESSAGE(ret == ARM_CFSTORE_DRIVER_ERROR_KEY_NOT_FOUND && bResult == false, cfstore_add_del_utest_msg_g); - /* revert CFSTORE_LOG for more trace */ - CFSTORE_DBGLOG("Found KV successfully (key_name=\"%s\")\n", node->key_name); - node++; - } - ret = drv->Uninitialize(); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_add_del_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Uninitialize() call failed.\n", __func__); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_add_del_utest_msg_g); - return CaseNext; -} - -/** @brief - * - * This test case adds ~50 KVs, and then delete entries at the start, - * middle and end of list. - * - * @return on success returns CaseNext to continue to next test case, otherwise will assert on errors. - */ -control_t cfstore_add_del_test_03_end(const size_t call_count) -{ - bool bfound = false; - int32_t ret = ARM_DRIVER_ERROR; - ARM_CFSTORE_FMODE flags; - cfstore_kv_data_t *node; - ARM_CFSTORE_DRIVER* drv = &cfstore_driver; - - CFSTORE_FENTRYLOG("%s:entered\n", __func__); - (void) call_count; - memset(&flags, 0, sizeof(flags)); - - ret = cfstore_test_init_1(); - 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__); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_add_del_utest_msg_g); - - /* delete some keys */ - node = cfstore_add_del_test_08_data; - while(node->key_name != NULL) - { - CFSTORE_DBGLOG("%s:about to delete key (key_name=%s).\n", __func__, node->key_name); - cfstore_test_delete(node->key_name); - 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); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_add_del_utest_msg_g); - /* revert CFSTORE_LOG for more trace */ - CFSTORE_DBGLOG("Deleted KV successfully (key_name=\"%s\")\n", node->key_name); - node++; - } - /* check the keys have been deleted */ - node = cfstore_add_del_test_08_data; - while(node->key_name != NULL) - { - ret = cfstore_test_kv_is_found(node->key_name, &bfound); - 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); - TEST_ASSERT_MESSAGE(ret == ARM_CFSTORE_DRIVER_ERROR_KEY_NOT_FOUND, cfstore_add_del_utest_msg_g); - - 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); - TEST_ASSERT_MESSAGE(bfound == false, cfstore_add_del_utest_msg_g); - node++; - } - - /* clean up by deleting all remaining KVs. this is not part of the test */ - ret = cfstore_test_delete_all(); - 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); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_add_del_utest_msg_g); - - ret = drv->Uninitialize(); - 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); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_add_del_utest_msg_g); - return CaseNext; -} - - -/** @brief - * - * This test case is as per test_03 but using delete_all() on all init_1 data. - * This test case is yet to be implemented. - * - * @return on success returns CaseNext to continue to next test case, otherwise will assert on errors. - */ -control_t cfstore_add_del_test_04(const size_t call_count) -{ - (void) call_count; - /*todo: implement test */ - CFSTORE_TEST_UTEST_MESSAGE(cfstore_add_del_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Warn: Not implemented\n", __func__); - CFSTORE_DBGLOG("%s: WARN: requires implementation\n", __func__); - TEST_ASSERT_MESSAGE(true, cfstore_add_del_utest_msg_g); - return CaseNext; -} - -/** @brief Delete an attribute after an internal realloc of the cfstore memory area - * - * This test case goes through the following steps: - * 1. Creates attribute att_1 of size x, and write some data. This causes an internal - * cfstore realloc to allocate heap memory for the attribute. - * 2. Allocates some memory on the heap. Typically, this will be immediately after the - * memory used by cfstore for the KV area. This means that if any cfstore reallocs are - * made to increase size the memory area will have to move. - * 3. Creates attribute att_2 of size y. This causes an internal cfstore realloc to move - * the KV memory area to a new location. - * 4. Delete att_1. This causes an internal realloc to shrink the area and tests that the - * internal data structures that contain pointers to different parts of the KV area - * are updated correctly. - * 5. Allocates some memory on the heap. If the heap has been corrupted, this will likely trigger - * a crash - * - * @return on success returns CaseNext to continue to next test case, otherwise will assert on errors. - */ -control_t cfstore_add_del_test_05_end(const size_t call_count) -{ - char data[] = "some test data"; - char filename[] = "file1"; - char filename2[] = "file2"; - int32_t ret = ARM_DRIVER_ERROR; - void *test_buf1 = NULL; - void *test_buf2 = NULL; - ARM_CFSTORE_DRIVER *cfstoreDriver = &cfstore_driver; - ARM_CFSTORE_KEYDESC keyDesc1; - ARM_CFSTORE_HANDLE_INIT(hkey1); - ARM_CFSTORE_KEYDESC keyDesc2; - ARM_CFSTORE_HANDLE_INIT(hkey2); - ARM_CFSTORE_SIZE count = sizeof(data); - - CFSTORE_FENTRYLOG("%s:entered\n", __func__); - (void) call_count; - - /* step 1 */ - memset(&keyDesc1, 0, sizeof(keyDesc1)); - keyDesc1.drl = ARM_RETENTION_NVM; - keyDesc1.flags.read = true; - keyDesc1.flags.write = true; - ret = cfstoreDriver->Create(filename, 1024, &keyDesc1, hkey1); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_add_del_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to create attribute 1 (ret=%d)\n", __func__, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_add_del_utest_msg_g); - - /* Write data to file */ - ret = cfstoreDriver->Write(hkey1, (const char *)data, &count); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_add_del_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to write to attribute 1 (ret=%d)\n", __func__, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_add_del_utest_msg_g); - - /* step 2 */ - test_buf1 = malloc(CFSTORE_ADD_DEL_MALLOC_SIZE); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_add_del_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to allocate memory (test_buf1=%p)\n", __func__, test_buf1); - TEST_ASSERT_MESSAGE(test_buf1 != NULL, cfstore_add_del_utest_msg_g); - - /* step 3 */ - memset(&keyDesc2, 0, sizeof(keyDesc2)); - keyDesc2.drl = ARM_RETENTION_NVM; - keyDesc2.flags.read = true; - keyDesc2.flags.write = true; - ret = cfstoreDriver->Create(filename2, 1024, &keyDesc2, hkey2); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_add_del_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to create attribute 2 (ret=%d)\n", __func__, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_add_del_utest_msg_g); - - /* Write data to file */ - count = sizeof(data); - ret = cfstoreDriver->Write(hkey2, (const char *)data, &count); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_add_del_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to write to attribute 2 (ret=%d)\n", __func__, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_add_del_utest_msg_g); - - /* step 4 */ - ret = cfstoreDriver->Delete(hkey1); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_add_del_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to delete to attribute 1 (ret=%d)\n", __func__, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_add_del_utest_msg_g); - - ret = cfstoreDriver->Close(hkey1); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_add_del_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to close to attribute 1 (ret=%d)\n", __func__, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_add_del_utest_msg_g); - - /* step 5 */ - test_buf2 = malloc(CFSTORE_ADD_DEL_MALLOC_SIZE); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_add_del_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to allocate memory (test_buf2=%p)\n", __func__, test_buf2); - TEST_ASSERT_MESSAGE(test_buf2 != NULL, cfstore_add_del_utest_msg_g); - - /* clean up */ - ret = cfstoreDriver->Close(hkey2); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_add_del_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to close to attribute 2 (ret=%d)\n", __func__, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_add_del_utest_msg_g); - free(test_buf2); - free(test_buf1); - - return CaseNext; -} - -/// @cond CFSTORE_DOXYGEN_DISABLE -utest::v1::status_t greentea_setup(const size_t number_of_cases) -{ - GREENTEA_SETUP(300, "default_auto"); - return greentea_test_setup_handler(number_of_cases); -} - -Case cases[] = { - /* 1 2 3 4 5 6 7 */ - /* 1234567890123456789012345678901234567890123456789012345678901234567890 */ - Case("ADD_DEL_test_00", cfstore_add_del_test_00), - Case("ADD_DEL_test_01_start", cfstore_utest_default_start), - Case("ADD_DEL_test_01_end", cfstore_add_del_test_01_end), - Case("ADD_DEL_test_02_start", cfstore_utest_default_start), - Case("ADD_DEL_test_02_end", cfstore_add_del_test_02_end), - Case("ADD_DEL_test_03_start", cfstore_utest_default_start), - Case("ADD_DEL_test_03_end", cfstore_add_del_test_03_end), - Case("ADD_DEL_test_04", cfstore_add_del_test_04), - Case("ADD_DEL_test_05_start", cfstore_utest_default_start), - Case("ADD_DEL_test_05_end", cfstore_add_del_test_05_end), -}; - - -/* Declare your test specification with a custom setup handler */ -Specification specification(greentea_setup, cases); - -int main() -{ - return !Harness::run(specification); -} -/// @endcond diff --git a/features/storage/FEATURE_STORAGE/TESTS/cfstore/close/close.cpp b/features/storage/FEATURE_STORAGE/TESTS/cfstore/close/close.cpp deleted file mode 100644 index 3375b92..0000000 --- a/features/storage/FEATURE_STORAGE/TESTS/cfstore/close/close.cpp +++ /dev/null @@ -1,241 +0,0 @@ -/* - * mbed Microcontroller Library - * Copyright (c) 2006-2016 ARM Limited - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** @file close.cpp Test cases to close KVs in the CFSTORE using the drv->Close() API function. - * - * Please consult the documentation under the test-case functions for - * a description of the individual test case. - */ - -#include "mbed.h" -#include "cfstore_config.h" -#include "Driver_Common.h" -#include "configuration_store.h" -#include "cfstore_test.h" -#include "cfstore_debug.h" -#include "utest/utest.h" -#include "unity/unity.h" -#include "greentea-client/test_env.h" -#include "cfstore_utest.h" - -#include -#include -#include - -using namespace utest::v1; - -static char cfstore_close_utest_msg_g[CFSTORE_UTEST_MSG_BUF_SIZE]; - -/* KV data for test_01 */ -static cfstore_kv_data_t cfstore_close_test_01_kv_data[] = { - { "yotta.hello-world.animal{wobbly-dog}{foot}frontLeft", "first_data_"}, - { "yotta.hello-world.animal{wobbly-dog}{foot}frontLeft", "second_data"}, - { NULL, NULL}, -}; - - -/* report whether built/configured for flash sync or async mode */ -static control_t cfstore_close_test_00(const size_t call_count) -{ - int32_t ret = ARM_DRIVER_ERROR; - - (void) call_count; - ret = cfstore_test_startup(); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_close_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to perform test startup (ret=%d).\n", __func__, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_close_utest_msg_g); - return CaseNext; -} - - -/** @brief - * - * The is a basic test case which does the following: - * - 01. create a key with handle hkey1 - * - 02. write data of hkey1 - * - 03. opens KV with 2nd handle, hkey2 - * - 04. read data with hkey2 and make sure its the same as that written with hkey1 - * - 05. write new data with hkey2 - * - 06. delete hkey2 - * - 07. close hkey2 - * - 08. read hkey1 and make sure the data is the newly written data i.e. the key hasnt - * been deleted yet - * - 09. try to open KV and make sure unable to do so, as KV is deleting - * - 10. close hkey1 - * - 11. try to open KV and make sure unable to do so because its now been deleted - * - 12. create new KV with same key_name to make sure can re-create the key again. - * - * @return on success returns CaseNext to continue to next test case, otherwise will assert on errors. - */ -control_t cfstore_close_test_01_end(const size_t call_count) -{ - char read_buf[CFSTORE_KEY_NAME_MAX_LENGTH]; - int32_t ret = ARM_DRIVER_ERROR; - ARM_CFSTORE_SIZE len = 0; - ARM_CFSTORE_DRIVER* drv = &cfstore_driver; - ARM_CFSTORE_KEYDESC kdesc; - ARM_CFSTORE_HANDLE_INIT(hkey1); - ARM_CFSTORE_HANDLE_INIT(hkey2); - cfstore_kv_data_t *node; - ARM_CFSTORE_FMODE flags; - - CFSTORE_DBGLOG("%s:entered\n", __func__); - (void) call_count; - node = &cfstore_close_test_01_kv_data[0]; - memset(&kdesc, 0, sizeof(kdesc)); - memset(&flags, 0, sizeof(flags)); - memset(read_buf, 0, CFSTORE_KEY_NAME_MAX_LENGTH); - - /* step 01 */ - kdesc.drl = ARM_RETENTION_WHILE_DEVICE_ACTIVE; - CFSTORE_DBGLOG("%s:About to create new node (key_name=\"%s\", value=\"%s\")\n", __func__, node->key_name, node->value); - ret = drv->Create(node->key_name, strlen(node->value), &kdesc, hkey1); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_close_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to create node (key_name=\"%s\", value=\"%s\")(ret=%d)\n", __func__, node->key_name, node->value, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_close_utest_msg_g); - CFSTORE_DBGLOG("%s:length of KV=%d (key_name=\"%s\", value=\"%s\")\n", __func__, (int) len, node->key_name, node->value); - - /* step 02 */ - len = strlen(node->value); - ret = drv->Write(hkey1, (char*) node->value, &len); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_close_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to write key (key_name=\"%s\", value=\"%s\")(ret=%d)\n", __func__, node->key_name, node->value, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_close_utest_msg_g); - - CFSTORE_TEST_UTEST_MESSAGE(cfstore_close_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to write full value data (key_name=\"%s\", value=\"%s\"), len=%d, (ret=%d)\n", __func__, node->key_name, node->value, (int) len, (int) ret); - TEST_ASSERT_MESSAGE(len == strlen(node->value), cfstore_close_utest_msg_g); - /* revert to CFSTORE_LOG if more trace required */ - CFSTORE_DBGLOG("Created KV successfully (key_name=\"%s\", value=\"%s\")\n", node->key_name, node->value); - - /* step 03: Now open second handle while keeping first handle open */ - flags.read = true; - flags.write = true; - ret = drv->Open(node->key_name, flags, hkey2); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_close_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to open node (key_name=\"%s\", value=\"%s\")(ret=%d)\n", __func__, node->key_name, node->value, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_close_utest_msg_g); - len = strlen(node->value) + 1; - /* revert to CFSTORE_LOG if more trace required */ - CFSTORE_DBGLOG("Opened KV successfully (key_name=\"%s\", value=\"%s\")\n", node->key_name, node->value); - - /* step 04 */ - ret = drv->Read(hkey2, read_buf, &len); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_close_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to read key (key_name=\"%s\", value=\"%s\")\n", __func__, node->key_name, node->value); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_close_utest_msg_g); - - /* check read data is as expected */ - CFSTORE_TEST_UTEST_MESSAGE(cfstore_close_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: read value data (%s) != KV value data (key_name=\"%s\", value=\"%s\")\n", __func__, read_buf, node->key_name, node->value); - TEST_ASSERT_MESSAGE(strncmp(read_buf, node->value, strlen(node->value)) == 0, cfstore_close_utest_msg_g); - - /* step 05 write new data using hkey2 */ - node = &cfstore_close_test_01_kv_data[1]; - len = strlen(node->value); - ret = drv->Write(hkey2, (char*) node->value, &len); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_close_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to write key with 2nd handle (key_name=\"%s\", value=\"%s\")(ret=%d)\n", __func__, node->key_name, node->value, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_close_utest_msg_g); - - CFSTORE_TEST_UTEST_MESSAGE(cfstore_close_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to write full value data (key_name=\"%s\", value=\"%s\"), len=%d, (ret=%d)\n", __func__, node->key_name, node->value, (int) len, (int) ret); - TEST_ASSERT_MESSAGE(len == strlen(node->value), cfstore_close_utest_msg_g); - /* revert to CFSTORE_LOG if more trace required */ - CFSTORE_DBGLOG("Wrote KV successfully with new data (key_name=\"%s\", value=\"%s\")\n", node->key_name, node->value); - - /* step 06 delete hkey2 */ - ret = drv->Delete(hkey2); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_close_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to Delete KV with 2nd handle (key_name=\"%s\", value=\"%s\")(ret=%d)\n", __func__, node->key_name, node->value, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_close_utest_msg_g); - - /* step 07 close hkey2 */ - ret = drv->Close(hkey2); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_close_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to Close KV with 2nd handle (key_name=\"%s\", value=\"%s\")(ret=%d)\n", __func__, node->key_name, node->value, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_close_utest_msg_g); - - /* step 08 read hkey1 for updated data */ - len = strlen(node->value) + 1; - memset(read_buf, 0, len); - ret = drv->Read(hkey1, read_buf, &len); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_close_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to read key with hkey1 (key_name=\"%s\", value=\"%s\")\n", __func__, node->key_name, node->value); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_close_utest_msg_g); - - /* check read data is as expected */ - CFSTORE_TEST_UTEST_MESSAGE(cfstore_close_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: read value data (%s) != KV value data (key_name=\"%s\", value=\"%s\")\n", __func__, read_buf, node->key_name, node->value); - TEST_ASSERT_MESSAGE(strncmp(read_buf, node->value, strlen(node->value)) == 0, cfstore_close_utest_msg_g); - - /* step 09 */ - ret = drv->Open(node->key_name, flags, hkey2); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_close_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Should not be able to open pre-existing key in deleting state (key_name=\"%s\", value=\"%s\")(ret=%d)\n", __func__, node->key_name, node->value, (int) ret); - TEST_ASSERT_MESSAGE(ret == ARM_CFSTORE_DRIVER_ERROR_PREEXISTING_KEY_DELETING || ret == ARM_CFSTORE_DRIVER_ERROR_KEY_NOT_FOUND, cfstore_close_utest_msg_g); - - /* step 10 close hkey1 */ - ret = drv->Close(hkey1); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_close_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to Close KV with 1st handle (key_name=\"%s\", value=\"%s\")(ret=%d)\n", __func__, node->key_name, node->value, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_close_utest_msg_g); - - /* step 11 try to open KV and make sure unable to do so because its now been deleted */ - ret = drv->Open(node->key_name, flags, hkey1); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_close_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Should not be able to open key as it should not be present in the CFSTORE (key_name=\"%s\", value=\"%s\")(ret=%d)\n", __func__, node->key_name, node->value, (int) ret); - TEST_ASSERT_MESSAGE(ret == ARM_CFSTORE_DRIVER_ERROR_KEY_NOT_FOUND, cfstore_close_utest_msg_g); - - /* step 12. create new KV with same key_name to make sure can re-create the key again. */ - node = &cfstore_close_test_01_kv_data[0]; - len = strlen(node->value); - kdesc.drl = ARM_RETENTION_WHILE_DEVICE_ACTIVE; - CFSTORE_DBGLOG("%s:About to create new node (key_name=\"%s\", value=\"%s\")\n", __func__, node->key_name, node->value); - ret = drv->Create(node->key_name, strlen(node->value), &kdesc, hkey1); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_close_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to create node (key_name=\"%s\", value=\"%s\")(ret=%d)\n", __func__, node->key_name, node->value, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_close_utest_msg_g); - CFSTORE_DBGLOG("%s:length of KV=%d (key_name=\"%s\", value=\"%s\")\n", __func__, (int) len, node->key_name, node->value); - - len = strlen(node->value); - ret = drv->Write(hkey1, (char*) node->value, &len); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_close_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to write key (key_name=\"%s\", value=\"%s\")(ret=%d)\n", __func__, node->key_name, node->value, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_close_utest_msg_g); - - CFSTORE_TEST_UTEST_MESSAGE(cfstore_close_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to write full value data (key_name=\"%s\", value=\"%s\"), len=%d, (ret=%d)\n", __func__, node->key_name, node->value, (int) len, (int) ret); - TEST_ASSERT_MESSAGE(len == strlen(node->value), cfstore_close_utest_msg_g); - - /* revert to CFSTORE_LOG if more trace required */ - CFSTORE_DBGLOG("Created KV successfully (key_name=\"%s\", value=\"%s\")\n", node->key_name, node->value); - - ret = drv->Uninitialize(); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_close_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Uninitialize() call failed.\n", __func__); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_close_utest_msg_g); - return CaseNext; -} - - -/// @cond CFSTORE_DOXYGEN_DISABLE -utest::v1::status_t greentea_setup(const size_t number_of_cases) -{ - GREENTEA_SETUP(100, "default_auto"); - return greentea_test_setup_handler(number_of_cases); -} - -Case cases[] = { - /* 1 2 3 4 5 6 7 */ - /* 1234567890123456789012345678901234567890123456789012345678901234567890 */ - Case("CLOSE_test_00", cfstore_close_test_00), - Case("CLOSE_test_01_start", cfstore_utest_default_start), - Case("CLOSE_test_01_end", cfstore_close_test_01_end) -}; - - -/* Declare your test specification with a custom setup handler */ -Specification specification(greentea_setup, cases); - -int main() -{ - return !Harness::run(specification); -} -/// @endcond - - diff --git a/features/storage/FEATURE_STORAGE/TESTS/cfstore/create/create.cpp b/features/storage/FEATURE_STORAGE/TESTS/cfstore/create/create.cpp deleted file mode 100644 index c009e32..0000000 --- a/features/storage/FEATURE_STORAGE/TESTS/cfstore/create/create.cpp +++ /dev/null @@ -1,835 +0,0 @@ -/* - * mbed Microcontroller Library - * Copyright (c) 2006-2016 ARM Limited - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Test cases to create KVs in the CFSTORE using the drv->Create() API call. - */ - -/** @file create.cpp Test cases to close KVs in the CFSTORE using the - * drv->Create() API function. - * - * Please consult the documentation under the test-case functions for - * a description of the individual test case. - */ - -#include "mbed.h" -#include "mbed_stats.h" -#include "cfstore_config.h" -#include "cfstore_debug.h" -#include "cfstore_test.h" -#include "Driver_Common.h" -#include "configuration_store.h" -#include "utest/utest.h" -#include "unity/unity.h" -#include "greentea-client/test_env.h" -#include "cfstore_utest.h" - -#include -#include -#include -#include - -using namespace utest::v1; - -#ifdef CFSTORE_DEBUG -#define CFSTORE_CREATE_GREENTEA_TIMEOUT_S 360 -#else -#define CFSTORE_CREATE_GREENTEA_TIMEOUT_S 60 -#endif -#define CFSTORE_CREATE_MALLOC_SIZE 1024 - -static char cfstore_create_utest_msg_g[CFSTORE_UTEST_MSG_BUF_SIZE]; - -/// @cond CFSTORE_DOXYGEN_DISABLE -#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"} -#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"} -#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"} -#define CFSTORE_CREATE_TEST_01_TABLE_MID_ENTRY_01 { "0123456789abcdef0123456", "abcdefghijklmnopqrstuvwxyz"} -#define CFSTORE_CREATE_TEST_01_TABLE_MID_ENTRY_02 { "0123456789abcdef0123456", "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"} -#define CFSTORE_CREATE_TEST_01_TABLE_MID_ENTRY_03 { "0123456789abcdef0123456", "nopqrstuvwxyz"} -#define CFSTORE_CREATE_TEST_01_TABLE_TAIL_ENTRY_01 { "Time.Will.Explain.It.All", "Aegeus"} -#define CFSTORE_CREATE_TEST_01_TABLE_TAIL_ENTRY_02 { "Cleverness.Is.Not.Wisdom", "Bacchae"} -#define CFSTORE_CREATE_TEST_01_TABLE_TAIL_ENTRY_03 { "Talk.Sense.To.A.Fool.And.He.Calls.You.Foolish", "Bacchae"} -#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"} - -static cfstore_kv_data_t cfstore_create_test_01_data[] = { - CFSTORE_CREATE_TEST_01_TABLE_MID_ENTRY_01, - CFSTORE_CREATE_TEST_01_TABLE_MID_ENTRY_02, - CFSTORE_CREATE_TEST_01_TABLE_MID_ENTRY_03, - { NULL, NULL}, -}; - -/* table 1: to initialise cfstore with CFSTORE_CREATE_TEST_01_TABLE_MID_ENTRY_01 */ -static cfstore_kv_data_t cfstore_create_test_01_data_step_01[] = { - CFSTORE_CREATE_TEST_01_TABLE_HEAD_ENTRY_01, - CFSTORE_CREATE_TEST_01_TABLE_HEAD_ENTRY_02, - CFSTORE_CREATE_TEST_01_TABLE_HEAD_ENTRY_03, - CFSTORE_CREATE_TEST_01_TABLE_MID_ENTRY_01, - CFSTORE_CREATE_TEST_01_TABLE_TAIL_ENTRY_01, - CFSTORE_CREATE_TEST_01_TABLE_TAIL_ENTRY_02, - CFSTORE_CREATE_TEST_01_TABLE_TAIL_ENTRY_03, - CFSTORE_CREATE_TEST_01_TABLE_TAIL_ENTRY_04, - { NULL, NULL}, -}; - -/* table 2: to CFSTORE_CREATE_TEST_01_TABLE_MID_ENTRY_01 grown to CFSTORE_CREATE_TEST_01_TABLE_MID_ENTRY_02 */ -static cfstore_kv_data_t cfstore_create_test_01_data_step_02[] = { - CFSTORE_CREATE_TEST_01_TABLE_HEAD_ENTRY_01, - CFSTORE_CREATE_TEST_01_TABLE_HEAD_ENTRY_02, - CFSTORE_CREATE_TEST_01_TABLE_HEAD_ENTRY_03, - CFSTORE_CREATE_TEST_01_TABLE_MID_ENTRY_02, - CFSTORE_CREATE_TEST_01_TABLE_TAIL_ENTRY_01, - CFSTORE_CREATE_TEST_01_TABLE_TAIL_ENTRY_02, - CFSTORE_CREATE_TEST_01_TABLE_TAIL_ENTRY_03, - CFSTORE_CREATE_TEST_01_TABLE_TAIL_ENTRY_04, - { NULL, NULL}, -}; - -/* table 3: to CFSTORE_CREATE_TEST_01_TABLE_MID_ENTRY_02 shrunk to CFSTORE_CREATE_TEST_01_TABLE_MID_ENTRY_03 */ -static cfstore_kv_data_t cfstore_create_test_01_data_step_03[] = { - CFSTORE_CREATE_TEST_01_TABLE_HEAD_ENTRY_01, - CFSTORE_CREATE_TEST_01_TABLE_HEAD_ENTRY_02, - CFSTORE_CREATE_TEST_01_TABLE_HEAD_ENTRY_03, - CFSTORE_CREATE_TEST_01_TABLE_MID_ENTRY_03, - CFSTORE_CREATE_TEST_01_TABLE_TAIL_ENTRY_01, - CFSTORE_CREATE_TEST_01_TABLE_TAIL_ENTRY_02, - CFSTORE_CREATE_TEST_01_TABLE_TAIL_ENTRY_03, - CFSTORE_CREATE_TEST_01_TABLE_TAIL_ENTRY_04, - { NULL, NULL}, -}; - -/* table 3: CFSTORE_CREATE_TEST_01_TABLE_MID_ENTRY_03 deleted */ -static cfstore_kv_data_t cfstore_create_test_01_data_step_04[] = { - CFSTORE_CREATE_TEST_01_TABLE_HEAD_ENTRY_01, - CFSTORE_CREATE_TEST_01_TABLE_HEAD_ENTRY_02, - CFSTORE_CREATE_TEST_01_TABLE_HEAD_ENTRY_03, - CFSTORE_CREATE_TEST_01_TABLE_TAIL_ENTRY_01, - CFSTORE_CREATE_TEST_01_TABLE_TAIL_ENTRY_02, - CFSTORE_CREATE_TEST_01_TABLE_TAIL_ENTRY_03, - CFSTORE_CREATE_TEST_01_TABLE_TAIL_ENTRY_04, - { NULL, NULL}, -}; -/// @endcond - -/* support functions */ - -/* @brief support function for generating value blob data */ -static int32_t cfstore_create_kv_value_gen(char* value, const size_t len) -{ - size_t i = 0; - size_t cpy_size = 0; - - CFSTORE_FENTRYLOG("%s:entered\n", __func__); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_create_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: value pointer is null.\n", __func__); - TEST_ASSERT_MESSAGE(value != NULL, cfstore_create_utest_msg_g); - - while(i < len) - { - cpy_size = len - i > CFSTORE_TEST_BYTE_DATA_TABLE_SIZE ? CFSTORE_TEST_BYTE_DATA_TABLE_SIZE : len - i; - memcpy(value + i, cfstore_test_byte_data_table, cpy_size); - i += cpy_size; - } - return ARM_DRIVER_OK; -} - - -static char* CFSTORE_CREATE_KV_CREATE_NO_TAG = NULL; - -/** @brief - * - * support function to create a KV - * - a kv name is generated with the length name_len - * - a kv value blob is generated with the length value_len - * - * @param name_len the length of the kv_name - * @param name_tag tag to append to name, intended to enable large number of unique strings - * @param value_buf buffer to use for storing the generated value data - * @param value_len the length of the value to generate - * - */ -static int32_t cfstore_create_kv_create(size_t name_len, char* name_tag, char* value_buf, size_t value_len) -{ - int32_t ret = ARM_DRIVER_OK; - size_t name_len_ex = name_len; - char kv_name[CFSTORE_KEY_NAME_MAX_LENGTH+1]; /* extra char for terminating null */ - ARM_CFSTORE_KEYDESC kdesc; - - CFSTORE_FENTRYLOG("%s:entered\n", __func__); - memset(kv_name, 0, CFSTORE_KEY_NAME_MAX_LENGTH+1); - memset(&kdesc, 0, sizeof(kdesc)); - kdesc.drl = ARM_RETENTION_WHILE_DEVICE_ACTIVE; - - name_len_ex = name_len; - if(name_tag){ - name_len_ex += strlen(name_tag); - } - 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__); - TEST_ASSERT_MESSAGE(name_len_ex < CFSTORE_KEY_NAME_MAX_LENGTH+1, cfstore_create_utest_msg_g); - - ret = cfstore_test_kv_name_gen(kv_name, name_len); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_create_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: unable to generate kv_name.\n", __func__); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK , cfstore_create_utest_msg_g); - - /* append name tag */ - if(name_tag){ - strncat(kv_name, name_tag, CFSTORE_KEY_NAME_MAX_LENGTH); - } - - 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); - TEST_ASSERT_MESSAGE(strlen(kv_name) == name_len_ex, cfstore_create_utest_msg_g); - - ret = cfstore_create_kv_value_gen(value_buf, value_len); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_create_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: unable to generate kv_name.\n", __func__); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK , cfstore_create_utest_msg_g); - - ret = cfstore_test_create(kv_name, value_buf, &value_len, &kdesc); - - if(ret == ARM_CFSTORE_DRIVER_ERROR_OUT_OF_MEMORY){ - CFSTORE_ERRLOG("%s: Error: out of memory\n", __func__); - return ret; - } - - 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); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_create_utest_msg_g); - - return ret; -} - - -/* @brief cfstore_create_test_01() support function change the size of a value blob in the cfstore */ -static int32_t cfstore_create_test_KV_change(const cfstore_kv_data_t* old_node, const cfstore_kv_data_t* new_node ) -{ - int32_t ret = ARM_DRIVER_ERROR; - size_t len = 0; - ARM_CFSTORE_DRIVER* drv = &cfstore_driver; - ARM_CFSTORE_HANDLE_INIT(hkey); - ARM_CFSTORE_FMODE flags; - ARM_CFSTORE_KEYDESC kdesc; - - CFSTORE_DBGLOG("%s:entered\n", __func__); - memset(&flags, 0, sizeof(flags)); - memset(&kdesc, 0, sizeof(kdesc)); - - /* check node key_names are identical */ - if(strncmp(old_node->key_name, new_node->key_name, strlen(old_node->key_name)) != 0){ - 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); - return ret; - } - len = strlen(new_node->value); - /* supply NULL key descriptor to open a pre-existing key for increasing the blob size */ - ret = drv->Create(new_node->key_name, len, NULL, hkey); - if(ret < ARM_DRIVER_OK){ - CFSTORE_ERRLOG("%s:Error: failed to change size of KV (key_name=%s)(ret=%d).\n", __func__, new_node->key_name, (int) ret); - goto out1; - } - len = strlen(new_node->value); - ret = drv->Write(hkey, new_node->value, &len); - if(ret < ARM_DRIVER_OK){ - CFSTORE_ERRLOG("%s:Error: failed to write KV (key_name=%s)(ret=%d).\n", __func__, new_node->key_name, (int) ret); - goto out2; - } - if(len != strlen(new_node->value)){ - 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)); - goto out2; - } -out2: - drv->Close(hkey); -out1: - return ret; -} - -/* report whether built/configured for flash sync or async mode */ -static control_t cfstore_create_test_00(const size_t call_count) -{ - int32_t ret = ARM_DRIVER_ERROR; - - (void) call_count; - ret = cfstore_test_startup(); - 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); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_create_utest_msg_g); - return CaseNext; -} - - -/** @brief Test case to change the value blob size of pre-existing key. - * - * The test does the following: - * - creates a cfstore with ~10 entries. - * - for a mid-cfstore entry, double the value blob size. - * - check all the cfstore entries can be read correctly and their - * data agrees with the data supplied upon creation. - * - shrink the mid-entry value blob size to be ~half the initial size. - * - check all the cfstore entries can be read correctly and their - * data agrees with the data supplied upon creation. - * - * @return on success returns CaseNext to continue to next test case, otherwise will assert on errors. - */ -control_t cfstore_create_test_01_end(const size_t call_count) -{ - int32_t ret = ARM_DRIVER_ERROR; - ARM_CFSTORE_FMODE flags; - cfstore_kv_data_t* node = NULL; - ARM_CFSTORE_DRIVER* drv = &cfstore_driver; - - CFSTORE_FENTRYLOG("%s:entered\n", __func__); - (void) call_count; - memset(&flags, 0, sizeof(flags)); - - ret = cfstore_test_create_table(cfstore_create_test_01_data_step_01); - 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); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_create_utest_msg_g); - - /* find cfstore_create_test_01_data[0] and grow the KV MID_ENTRY_01 to MID_ENTRY_02 */ - ret = cfstore_create_test_KV_change(&cfstore_create_test_01_data[0], &cfstore_create_test_01_data[1]); - 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); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_create_utest_msg_g); - - /* Now check that the KVs are all present and correct */ - node = cfstore_create_test_01_data_step_02; - while(node->key_name != NULL) - { - ret = cfstore_test_check_node_correct(node); - 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); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_create_utest_msg_g); - node++; - } - /* revert CFSTORE_LOG for more trace */ - CFSTORE_DBGLOG("KV successfully increased in size and other KVs remained unchanged.%s", "\n"); - /* Shrink the KV from KV MID_ENTRY_02 to MID_ENTRY_03 */ - ret = cfstore_create_test_KV_change(&cfstore_create_test_01_data[1], &cfstore_create_test_01_data[2]); - 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); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_create_utest_msg_g); - - /* Now check that the KVs are all present and correct */ - node = cfstore_create_test_01_data_step_03; - while(node->key_name != NULL) - { - ret = cfstore_test_check_node_correct(node); - 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); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_create_utest_msg_g); - node++; - } - /* revert CFSTORE_LOG for more trace */ - CFSTORE_DBGLOG("KV successfully decreased in size and other KVs remained unchanged.%s", "\n"); - - /* Delete the KV */ - ret = cfstore_test_delete(cfstore_create_test_01_data[2].key_name); - 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); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_create_utest_msg_g); - - /* Now check that the KVs are all present and correct */ - node = cfstore_create_test_01_data_step_04; - while(node->key_name != NULL) - { - ret = cfstore_test_check_node_correct(node); - 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); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_create_utest_msg_g); - node++; - } - ret = drv->Uninitialize(); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_create_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Uninitialize() call failed.\n", __func__); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_create_utest_msg_g); - return CaseNext; -} - - -static int32_t cfstore_create_test_02_core(const size_t call_count) -{ - int32_t ret = ARM_DRIVER_ERROR; - uint32_t i = 0; - uint32_t bytes_stored = 0; - const uint32_t max_num_kvs_create = 10; - const size_t kv_name_min_len = CFSTORE_KEY_NAME_MAX_LENGTH - max_num_kvs_create; - const size_t kv_value_min_len = CFSTORE_TEST_BYTE_DATA_TABLE_SIZE; - const size_t max_value_buf_size = kv_value_min_len * (max_num_kvs_create +1); - char value_buf[max_value_buf_size]; - - CFSTORE_FENTRYLOG("%s:entered\n", __func__); - (void) call_count; - memset(value_buf, 0, max_value_buf_size); - - for(i = 0; i < max_num_kvs_create; i++) - { - memset(value_buf, 0, max_value_buf_size); - ret = cfstore_create_kv_create(kv_name_min_len +i, CFSTORE_CREATE_KV_CREATE_NO_TAG, value_buf, kv_value_min_len * (i+1)); - bytes_stored += kv_name_min_len + i; /* kv_name */ - bytes_stored += kv_value_min_len * (i+1); /* kv value blob */ - bytes_stored += 8; /* kv overhead */ - if(ret == ARM_CFSTORE_DRIVER_ERROR_OUT_OF_MEMORY){ - CFSTORE_ERRLOG("Out of memory on %d-th KV, trying to allocate memory totalling %d.\n", (int) i, (int) bytes_stored); - break; - } - CFSTORE_DBGLOG("Successfully stored %d-th KV bytes, totalling %d.\n", (int) i, (int) bytes_stored); - } - ret = cfstore_test_delete_all(); - 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); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_create_utest_msg_g); - return ret; -} - - -/**@brief - * - * Test case to create ~10 kvs. The amount of data store in the cfstore is as follows: - * - 10 kvs - * - kv name lengths are ~220 => ~ 2200 bytes - * - value blob length is 1x256, 2x256, 3x256, ... 10x256)) = 256(1+2+3+4+..10) = 256*10*11/2 = 14080 - * - kv overhead = 8bytes/kv = 8 * 10 = 80bytes - * - total = (220*10)+256*10*11/2 10*8 = 143800 bytes - * - * @return on success returns CaseNext to continue to next test case, otherwise will assert on errors. - */ -control_t cfstore_create_test_02_end(const size_t call_count) -{ - int32_t ret; - ARM_CFSTORE_DRIVER* drv = &cfstore_driver; - - CFSTORE_FENTRYLOG("%s:entered\n", __func__); - (void) call_count; - - ret = cfstore_create_test_02_core(call_count); - 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); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_create_utest_msg_g); - - CFSTORE_TEST_UTEST_MESSAGE(cfstore_create_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Uninitialize() call failed.\n", __func__); - TEST_ASSERT_MESSAGE(drv->Uninitialize() >= ARM_DRIVER_OK, cfstore_create_utest_msg_g); - return CaseNext; -} - - -/**@brief - * - * Test to create the ~100 kvs to make the device run out of memory. - * - * @return on success returns CaseNext to continue to next test case, otherwise will assert on errors. - */ -control_t cfstore_create_test_03_end(const size_t call_count) -{ - int32_t i = 0; - int32_t ret; - ARM_CFSTORE_DRIVER* drv = &cfstore_driver; - - CFSTORE_FENTRYLOG("%s:entered\n", __func__); - for(i = 0; i < 100; i++) - { - ret = cfstore_create_test_02_core(call_count); - 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); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_create_utest_msg_g); - /* revert CFSTORE_LOG for more trace */ - CFSTORE_DBGLOG("Successfully completed create/destroy loop %d.\n", (int) i); - } - CFSTORE_TEST_UTEST_MESSAGE(cfstore_create_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Uninitialize() call failed.\n", __func__); - TEST_ASSERT_MESSAGE(drv->Uninitialize() >= ARM_DRIVER_OK, cfstore_create_utest_msg_g); - return CaseNext; -} - - -/**@brief - * - * Test to create the 100 kvs to make the device run out of memory. - * The amount of data store in the cfstore is as follows: - * - total = (220*100)+256*100*101/2 100*8 = 1315600 = 1.315x10^6 - * - * @return on success returns CaseNext to continue to next test case, otherwise will assert on errors. - */ -control_t cfstore_create_test_04_end(const size_t call_count) -{ - int32_t ret = ARM_DRIVER_ERROR; - uint32_t i = 0; - uint32_t bytes_stored = 0; - const uint32_t max_num_kvs_create = 100; - const size_t kv_name_min_len = CFSTORE_KEY_NAME_MAX_LENGTH - max_num_kvs_create; - const size_t kv_value_min_len = CFSTORE_TEST_BYTE_DATA_TABLE_SIZE; - const size_t max_value_buf_size = kv_value_min_len/8 * (max_num_kvs_create +1); - char* value_buf = NULL; - ARM_CFSTORE_DRIVER* drv = &cfstore_driver; - - CFSTORE_FENTRYLOG("%s:entered\n", __func__); - (void) call_count; - - CFSTORE_LOG("%s: cfstore_test_dump: dump here contents of CFSTORE so we know whats present\n", __func__); - ret = cfstore_test_dump(); - 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); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_create_utest_msg_g); - - value_buf = (char*) malloc(max_value_buf_size); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_create_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: out of memory.\n", __func__); - TEST_ASSERT_MESSAGE(value_buf != NULL, cfstore_create_utest_msg_g); - - for(i = 0; i < max_num_kvs_create; i++) - { - memset(value_buf, 0, max_value_buf_size); - 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)); - bytes_stored += kv_name_min_len + i; /* kv_name */ - bytes_stored += kv_value_min_len/8 * (i+1); /* kv value blob */ - bytes_stored += 8; /* kv overhead */ - if(ret == ARM_CFSTORE_DRIVER_ERROR_OUT_OF_MEMORY){ - CFSTORE_ERRLOG("Out of memory on %d-th KV, trying to allocate memory totalling %d.\n", (int) i, (int) bytes_stored); - break; - } - /* revert CFSTORE_LOG for more trace */ - CFSTORE_DBGLOG("Successfully stored %d-th KV bytes, totalling %d.\n", (int) i, (int) bytes_stored); - } - ret = cfstore_test_delete_all(); - 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); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_create_utest_msg_g); - free(value_buf); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_create_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Uninitialize() call failed.\n", __func__); - TEST_ASSERT_MESSAGE(drv->Uninitialize() >= ARM_DRIVER_OK, cfstore_create_utest_msg_g); - return CaseNext; -} - - -/** - * @brief Support function for test cases 05 - * - * Create enough KV's to consume the whole of available memory - */ -int32_t cfstore_create_test_05_core(const size_t call_count) -{ - int32_t ret = ARM_DRIVER_ERROR; - uint32_t i = 0; - const uint32_t max_num_kvs_create = 200; - const size_t kv_name_tag_len = 3; - const size_t kv_name_min_len = 10; - const size_t kv_value_min_len = CFSTORE_TEST_BYTE_DATA_TABLE_SIZE; - const size_t max_value_buf_size = kv_value_min_len/64 * (max_num_kvs_create+1); - char kv_name_tag_buf[kv_name_tag_len+1]; - char* value_buf = NULL; - ARM_CFSTORE_DRIVER* drv = &cfstore_driver; - - CFSTORE_FENTRYLOG("%s:entered\n", __func__); - - /* Initialize() */ - cfstore_utest_default_start(call_count); - - value_buf = (char*) malloc(max_value_buf_size); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_create_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: out of memory.\n", __func__); - TEST_ASSERT_MESSAGE(value_buf != NULL, cfstore_create_utest_msg_g); - - for(i = 0; i < max_num_kvs_create; i++) - { - memset(value_buf, 0, max_value_buf_size); - snprintf(kv_name_tag_buf, kv_name_tag_len+1, "%0d", (int) i); - ret = cfstore_create_kv_create(kv_name_min_len, kv_name_tag_buf, value_buf, kv_value_min_len/64 * (i+1)); - if(ret == ARM_CFSTORE_DRIVER_ERROR_OUT_OF_MEMORY){ - CFSTORE_ERRLOG("Out of memory on %d-th KV.\n", (int) i); - break; - } - /* revert CFSTORE_LOG for more trace */ - CFSTORE_DBGLOG("Successfully stored %d-th KV.\n", (int) i); - } - ret = cfstore_test_delete_all(); - 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__); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_create_utest_msg_g); - free(value_buf); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_create_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Uninitialize() call failed.\n", __func__); - TEST_ASSERT_MESSAGE(drv->Uninitialize() >= ARM_DRIVER_OK, cfstore_create_utest_msg_g); - return ret; -} - - -/** - * @brief Test case to check cfstore recovers from out of memory - * errors without leaking memory - * - * This test case does the following: - * 1. Start loop. - * 2. Initializes CFSTORE. - * 3. Creates as many KVs as required to run out of memory. The number of bytes B - * allocated before running out of memory is recorded. - * 4. For loop i, check that B_i = B_i-1 for i>0 i.e. that no memory has been leaked - * 5. Uninitialize(), which should clean up any cfstore internal state including - * freeing the internal memeory area. - * 6. Repeat from step 1 N times. - */ -control_t cfstore_create_test_05(const size_t call_count) -{ - uint32_t i = 0; - int32_t ret = ARM_DRIVER_ERROR; - const uint32_t max_loops = 50; - mbed_stats_heap_t stats_before; - mbed_stats_heap_t stats_after; - - mbed_stats_heap_get(&stats_before); - - CFSTORE_FENTRYLOG("%s:entered\n", __func__); - for(i = 0; i < max_loops; i++) { - ret = cfstore_create_test_05_core(call_count); - 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); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_create_utest_msg_g); - - mbed_stats_heap_get(&stats_after); - if(i > 1) { - 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); - TEST_ASSERT_MESSAGE(stats_after.current_size == stats_before.current_size, cfstore_create_utest_msg_g); - TEST_ASSERT(stats_after.alloc_fail_cnt > stats_before.alloc_fail_cnt); - } - stats_before = stats_after; - } - return CaseNext; -} - - -/// @cond CFSTORE_DOXYGEN_DISABLE -/* structure to encode test data */ -typedef struct cfstore_create_key_name_validate_t { - const char* key_name; - uint32_t f_allowed : 1; -} cfstore_create_key_name_validate_t; - -/* data table encoding test data */ -cfstore_create_key_name_validate_t cfstore_create_test_06_data[] = { - /* ruler for measuring text strings */ - /* 1 1 1 1 1 1 1 1 1 1 2 2 2 */ - /* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 */ - /* 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 */ - { "", false}, - { "abc.{1}.efg", true }, - { "abc.{1.efg", false }, - { "abc.1}.efg", false }, - { "abc.{{1}}.efg", false }, - { "abc.{}.efg", true }, - { "abc.}1{.efg", false }, - { ".piety.demands.us.to.honour.truth.above.our.friends", false }, - { "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 }, - { NULL, false}, -}; -/// @endcond - - -/** - * @brief Test whether a key name can be created or not. - * - * @param key_name - * name of the key to create in the store - * @param should_create - * if true, then create KV should succeed, otherwise should fail. - * - * @return on success returns CaseNext to continue to next test case, otherwise will assert on errors. - */ -bool cfstore_create_key_name_validate(const char *key_name, bool should_create) -{ - bool bret = false; - char* test_data = (char*) "test_data"; - int32_t ret = ARM_DRIVER_ERROR; - ARM_CFSTORE_SIZE len = 0; - ARM_CFSTORE_KEYDESC kdesc; - - CFSTORE_FENTRYLOG("%s:entered\r\n", __func__); - memset(&kdesc, 0, sizeof(kdesc)); - - /* create */ - kdesc.drl = ARM_RETENTION_WHILE_DEVICE_ACTIVE; - len = strlen(test_data); - ret = cfstore_test_create((const char*) key_name, test_data, &len, &kdesc); - /* dont not use any functions that require finding the created item as they may not work, - * depending on the construction of the test key_name & match strings */ - if(should_create == true) - { - if(ret < ARM_DRIVER_OK){ - CFSTORE_ERRLOG("%s:Error: failed to create kv (key_name=%s.\r\n", __func__, key_name); - return bret; - } - CFSTORE_DBGLOG("%s:Success: Create() behaved as expected.\r\n", __func__); - /* delete using the actual name */ - ret = cfstore_test_delete((const char*) key_name); - if(ret < ARM_DRIVER_OK){ - CFSTORE_ERRLOG("%s:Error: failed to delete kv (key_name=%s)(ret=%d).\r\n", __func__, key_name, (int)ret); - } - bret = true; - } - else - { - if(ret >= ARM_DRIVER_OK){ - CFSTORE_ERRLOG("%s:Error: created kv (key_name=%s) when Create() should have failed.\r\n", __func__, key_name); - return bret; - } - /* the operation failed which was the expected result hence return true*/ - bret = true; - } - return bret; -} - -/** @brief - * - * Test that key names with non-matching braces etc do no get created. - * - * @return on success returns CaseNext to continue to next test case, otherwise will assert on errors. - */ -control_t cfstore_create_test_06_end(const size_t call_count) -{ - bool ret = false; - int32_t ret32 = ARM_DRIVER_ERROR; - ARM_CFSTORE_DRIVER* drv = &cfstore_driver; - cfstore_create_key_name_validate_t* node = cfstore_create_test_06_data; - - (void) call_count; - - while(node->key_name != NULL) - { - ret = cfstore_create_key_name_validate(node->key_name, node->f_allowed); - 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); - TEST_ASSERT_MESSAGE(ret == true, cfstore_create_utest_msg_g); - node++; - } - - ret32 = drv->Uninitialize(); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_create_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Uninitialize() call failed.\n", __func__); - TEST_ASSERT_MESSAGE(ret32 >= ARM_DRIVER_OK, cfstore_create_utest_msg_g); - return CaseNext; -} - - -/** @brief Test case to change the value blob size of pre-existing - * key in a way that causes the memory area to realloc-ed, - * - * The test is a modified version of cfstore_create_test_01_end which - * - creates KVs, - * - mallocs a memory object on the heap - * - increases the size of one of the existing KVs, causing the - * internal memory area to be realloc-ed. - * - * In detail, the test does the following: - * 1. creates a cfstore with ~10 entries. This causes the configuration - * store to realloc() heap memory for KV storage. - * 2. mallocs a memory object on heap. - * 3. for a mid-cfstore entry, double the value blob size. This will cause the - * cfstore memory area to be realloced. - * 4. check all the cfstore entries can be read correctly and their - * data agrees with the data supplied upon creation. - * 5. shrink the mid-entry value blob size to be ~half the initial size. - * check all the cfstore entries can be read correctly and their - * data agrees with the data supplied upon creation. - * - * @return on success returns CaseNext to continue to next test case, otherwise will assert on errors. - */ -control_t cfstore_create_test_07_end(const size_t call_count) -{ - int32_t ret = ARM_DRIVER_ERROR; - void *test_buf1 = NULL; - ARM_CFSTORE_FMODE flags; - cfstore_kv_data_t* node = NULL; - ARM_CFSTORE_DRIVER* drv = &cfstore_driver; - - CFSTORE_FENTRYLOG("%s:entered\n", __func__); - (void) call_count; - memset(&flags, 0, sizeof(flags)); - - /* step 1 */ - ret = cfstore_test_create_table(cfstore_create_test_01_data_step_01); - 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); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_create_utest_msg_g); - - /* step 2 */ - test_buf1 = malloc(CFSTORE_CREATE_MALLOC_SIZE); - 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); - TEST_ASSERT_MESSAGE(test_buf1 != NULL, cfstore_create_utest_msg_g); - - /* step 3. find cfstore_create_test_01_data[0] and grow the KV MID_ENTRY_01 to MID_ENTRY_02 */ - ret = cfstore_create_test_KV_change(&cfstore_create_test_01_data[0], &cfstore_create_test_01_data[1]); - 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); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_create_utest_msg_g); - - /* step 4. Now check that the KVs are all present and correct */ - node = cfstore_create_test_01_data_step_02; - while(node->key_name != NULL) - { - ret = cfstore_test_check_node_correct(node); - 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); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_create_utest_msg_g); - node++; - } - /* revert CFSTORE_LOG for more trace */ - CFSTORE_DBGLOG("KV successfully increased in size and other KVs remained unchanged.%s", "\n"); - - /* Shrink the KV from KV MID_ENTRY_02 to MID_ENTRY_03 */ - ret = cfstore_create_test_KV_change(&cfstore_create_test_01_data[1], &cfstore_create_test_01_data[2]); - 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); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_create_utest_msg_g); - - /* Step 5. Now check that the KVs are all present and correct */ - node = cfstore_create_test_01_data_step_03; - while(node->key_name != NULL) - { - ret = cfstore_test_check_node_correct(node); - 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); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_create_utest_msg_g); - node++; - } - /* revert CFSTORE_LOG for more trace */ - CFSTORE_DBGLOG("KV successfully decreased in size and other KVs remained unchanged.%s", "\n"); - - /* Delete the KV */ - ret = cfstore_test_delete(cfstore_create_test_01_data[2].key_name); - 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); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_create_utest_msg_g); - - /* Now check that the KVs are all present and correct */ - node = cfstore_create_test_01_data_step_04; - while(node->key_name != NULL) - { - ret = cfstore_test_check_node_correct(node); - 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); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_create_utest_msg_g); - node++; - } - - free(test_buf1); - ret = drv->Uninitialize(); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_create_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Uninitialize() call failed.\n", __func__); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_create_utest_msg_g); - return CaseNext; -} - - -/// @cond CFSTORE_DOXYGEN_DISABLE -utest::v1::status_t greentea_setup(const size_t number_of_cases) -{ - GREENTEA_SETUP(CFSTORE_CREATE_GREENTEA_TIMEOUT_S, "default_auto"); - return greentea_test_setup_handler(number_of_cases); -} - -Case cases[] = { - /* 1 2 3 4 5 6 7 */ - /* 1234567890123456789012345678901234567890123456789012345678901234567890 */ - Case("CREATE_test_00", cfstore_create_test_00), - Case("CREATE_test_01_start", cfstore_utest_default_start), - Case("CREATE_test_01_end", cfstore_create_test_01_end), - Case("CREATE_test_02_start", cfstore_utest_default_start), - Case("CREATE_test_02_end", cfstore_create_test_02_end), - Case("CREATE_test_03_start", cfstore_utest_default_start), - Case("CREATE_test_03_end", cfstore_create_test_03_end), - Case("CREATE_test_04_start", cfstore_utest_default_start), - Case("CREATE_test_04_end", cfstore_create_test_04_end), -#if defined(MBED_HEAP_STATS_ENABLED) && MBED_HEAP_STATS_ENABLED && !defined(__ICCARM__) - Case("CREATE_test_05", cfstore_create_test_05), -#endif - Case("CREATE_test_06_start", cfstore_utest_default_start), - Case("CREATE_test_06_end", cfstore_create_test_06_end), - Case("CREATE_test_07_start", cfstore_utest_default_start), - Case("CREATE_test_07_end", cfstore_create_test_07_end), -}; - - -/* Declare your test specification with a custom setup handler */ -Specification specification(greentea_setup, cases); - -int main() -{ - return !Harness::run(specification); -} -/// @endcond - diff --git a/features/storage/FEATURE_STORAGE/TESTS/cfstore/dump/dump.cpp b/features/storage/FEATURE_STORAGE/TESTS/cfstore/dump/dump.cpp deleted file mode 100644 index 4d1f4d4..0000000 --- a/features/storage/FEATURE_STORAGE/TESTS/cfstore/dump/dump.cpp +++ /dev/null @@ -1,83 +0,0 @@ -/* - * mbed Microcontroller Library - * Copyright (c) 2006-2016 ARM Limited - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Simple tool (implemented as a test case) to dump cfstore contents. - */ - -/** @file dump.cpp test binary for dumping CFSTORE configuration. - */ - -#include "mbed.h" -#include "cfstore_config.h" -#include "cfstore_test.h" -#include "cfstore_debug.h" -#include "Driver_Common.h" -#include "configuration_store.h" -#include "utest/utest.h" -#include "unity/unity.h" -#include "greentea-client/test_env.h" -#include "cfstore_utest.h" - -#include -#include -#include -#include -#include - -using namespace utest::v1; - - -control_t cfstore_dump_test_01_end(const size_t call_count) -{ - int32_t ret = ARM_DRIVER_ERROR; - ARM_CFSTORE_DRIVER* drv = &cfstore_driver; - - ret = cfstore_test_dump(); - if(ret < ARM_DRIVER_OK){ - CFSTORE_LOG("Error: failed to dump CFSTORE contents%s", "\n"); - } - ret = drv->Uninitialize(); - if(ret < ARM_DRIVER_OK){ - CFSTORE_LOG("Error: failed to Uninitialize() CFSTORE%s", "\n"); - } - return CaseNext; -} - - -/// @cond CFSTORE_DOXYGEN_DISABLE -utest::v1::status_t greentea_setup(const size_t number_of_cases) -{ - GREENTEA_SETUP(400, "default_auto"); - return greentea_test_setup_handler(number_of_cases); -} - -Case cases[] = { - /* 1 2 3 4 5 6 7 */ - /* 1234567890123456789012345678901234567890123456789012345678901234567890 */ - Case("DUMP_test_01_start", cfstore_utest_default_start), - Case("DUMP_test_01_end", cfstore_dump_test_01_end), -}; - - -/* Declare your test specification with a custom setup handler */ -Specification specification(greentea_setup, cases); - -int main() -{ - return !Harness::run(specification); -} -/// @endcond - diff --git a/features/storage/FEATURE_STORAGE/TESTS/cfstore/example1/example1.cpp b/features/storage/FEATURE_STORAGE/TESTS/cfstore/example1/example1.cpp deleted file mode 100644 index 534ccc0..0000000 --- a/features/storage/FEATURE_STORAGE/TESTS/cfstore/example1/example1.cpp +++ /dev/null @@ -1,1003 +0,0 @@ -/* - * mbed Microcontroller Library - * Copyright (c) 2006-2016 ARM Limited - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -/** @file example1.cpp Test case to demonstrates each API function works correctly. - * - * \par Example 1 Notes - * - * The example test does the following CFSTORE operations: - * - initialises - * - creates a key-value pair (KV). - * - writes the data for the KV - * - closes KV. - * - flushes the KV to flash - * - opens KV for reading. - * - reads KV and checks the value blob was the same as previously written. - * - closes KV. - * - finds a KV (there is only 1 to find). - * - for the KV returned, get the key name. - * - for the KV returned, get the value length. - * - for the KV returned, delete the KV. - * - find another KV (which fails as there are no more keys to find). - * - flushes the updated state to flash to store the removal of the deleted KV. - * - uninitialises - * - stops - * - * This test is coded so as to work in the following modes: - * - flash sync mode i.e. with caps.asynchronous_ops == false - * - flash async mode i.e. with caps.asynchronous_ops == true - * - * The dual async/sync mode support with the same code is more complicated - * than if the implementation just supported sync mode for example. However, - * it has the benefit of being more versatile. - * - * The test leaves the flash in the same state as at the beginning of the test so - * it can be run a second time on the device without flashing, and the test should - * still work. - * - * \par How to Build Example1 as a Stand-alone Application - * - * This example can be build as a stand-alone application as follows: - * - Create a new mbed application using the `mbed new .` command. - * - Copy this file example1.cpp from the to the top level application directory and rename the file to main.cpp. - * - Build the application with `mbed compile -v -m -t -DCFSTORE_EXAMPLE1_APP` e.g. `mbed compile -v -m K64F -t GCC_ARM -DCFSTORE_EXAMPLE1_APP`. - */ -#if defined __MBED__ && ! defined TOOLCHAIN_GCC_ARM - -#include "mbed.h" -#include "cfstore_config.h" -#include "Driver_Common.h" -#include "cfstore_debug.h" -#include "cfstore_test.h" -#include "configuration_store.h" -#include "utest/utest.h" -#include "unity/unity.h" -#include "greentea-client/test_env.h" - -#include -#include -#include -#include - -using namespace utest::v1; - -static control_t cfstore_example1_test_00(const size_t call_count) -{ - (void) call_count; - printf("Not implemented for ARM toolchain\n"); - return CaseNext; -} - - -utest::v1::status_t greentea_setup(const size_t number_of_cases) -{ - GREENTEA_SETUP(100, "default_auto"); - return greentea_test_setup_handler(number_of_cases); -} - -Case cases[] = { - /* 1 2 3 4 5 6 7 */ - /* 1234567890123456789012345678901234567890123456789012345678901234567890 */ - Case("EXAMPLE1_test_00", cfstore_example1_test_00), -}; - - -/* Declare your test specification with a custom setup handler */ -Specification specification(greentea_setup, cases); - -int main() -{ - return !Harness::run(specification); -} - - -#else - - -#include "mbed.h" - -#ifndef CFSTORE_EXAMPLE1_APP -/* when built as Configuration-Store example, include greentea support otherwise omit */ -#include "utest/utest.h" -#include "unity/unity.h" -#include "greentea-client/test_env.h" - -#else // CFSTORE_EXAMPLE1_APP -// map utest types for building as stand alone example -#define control_t void -#define CaseNext -#endif // CFSTORE_EXAMPLE1_APP - -#include "cfstore_config.h" -#include "configuration_store.h" - -#ifdef CFSTORE_CONFIG_BACKEND_FLASH_ENABLED -#include "flash_journal_strategy_sequential.h" -#include "flash_journal.h" -#include "Driver_Common.h" -#endif /* CFSTORE_CONFIG_BACKEND_FLASH_ENABLED */ - -#include -#include -#include - -/// @cond CFSTORE_DOXYGEN_DISABLE -#ifndef CFSTORE_EXAMPLE1_APP -using namespace utest::v1; -#endif - - -#define CFSTORE_EX1_TEST_ASSERT(Expr) if (!(Expr)) { printf("%s:%u: assertion failure\r\n", __FUNCTION__, __LINE__); while (1) ;} -#define CFSTORE_EX1_TEST_ASSERT_EQUAL(expected, actual) if ((expected) != (actual)) {printf("%s:%u: assertion failure\r\n", __FUNCTION__, __LINE__); while (1) ;} -#define CFSTORE_EX1_TEST_ASSERT_NOT_EQUAL(expected, actual) if ((expected) == (actual)) {printf("%s:%u: assertion failure\r\n", __FUNCTION__, __LINE__); while (1) ;} - -#define CFSTORE_EX1_TEST_ASSERT_MSG(Expr, _fmt, ...) \ - do \ - { \ - if (!(Expr)) \ - { \ - printf(_fmt, __VA_ARGS__); \ - while (1) ; \ - } \ - }while(0); - -#define CFSTORE_EX1_LOG(_fmt, ...) \ - do \ - { \ - printf(_fmt, __VA_ARGS__); \ - }while(0); - - -const char* cfstore_ex_opcode_str[] = -{ - "UNDEFINED", - "CFSTORE_OPCODE_CLOSE", - "CFSTORE_OPCODE_CREATE", - "CFSTORE_OPCODE_DELETE", - "CFSTORE_OPCODE_FIND", - "CFSTORE_OPCODE_FLUSH", - "CFSTORE_OPCODE_GET_KEY_NAME", - "CFSTORE_OPCODE_GET_STATUS", - "CFSTORE_OPCODE_GET_VALUE_LEN", - "CFSTORE_OPCODE_INITIALIZE", - "CFSTORE_OPCODE_OPEN", - "CFSTORE_OPCODE_POWER_CONTROL", - "CFSTORE_OPCODE_READ", - "CFSTORE_OPCODE_RSEEK", - "CFSTORE_OPCODE_UNINITIALIZE", - "CFSTORE_OPCODE_WRITE", - "CFSTORE_OPCODE_MAX" -}; - -bool cfstore_example1_done = false; -const char* cfstore_ex_kv_name = "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.well.well"; -const char* cfstore_ex_kv_value = "TheRollingStone"; -#define CFSTORE_EX1_RSEEK_OFFSET 10 /* offset to S of Stone */ - -typedef enum cfstore_ex_state_t { - CFSTORE_EX_STATE_INITIALIZING = 1, - CFSTORE_EX_STATE_INIT_DONE, - CFSTORE_EX_STATE_CREATING, - CFSTORE_EX_STATE_CREATE_DONE, - CFSTORE_EX_STATE_WRITING, - CFSTORE_EX_STATE_WRITE_DONE, - CFSTORE_EX_STATE_CLOSING1, - CFSTORE_EX_STATE_CLOSE_DONE1, - CFSTORE_EX_STATE_FLUSHING1, - CFSTORE_EX_STATE_FLUSH_DONE1, - CFSTORE_EX_STATE_OPENING, - CFSTORE_EX_STATE_OPEN_DONE, - CFSTORE_EX_STATE_READING1, - CFSTORE_EX_STATE_READ_DONE1, - CFSTORE_EX_STATE_RSEEKING, - CFSTORE_EX_STATE_RSEEK_DONE, - CFSTORE_EX_STATE_READING2, - CFSTORE_EX_STATE_READ_DONE2, - CFSTORE_EX_STATE_CLOSING2, - CFSTORE_EX_STATE_CLOSE_DONE2, - CFSTORE_EX_STATE_FINDING1, - CFSTORE_EX_STATE_FIND_DONE1, - CFSTORE_EX_STATE_GETTING_KEY_NAME, - CFSTORE_EX_STATE_GET_KEY_NAME_DONE, - CFSTORE_EX_STATE_GETTING_VALUE_LEN, - CFSTORE_EX_STATE_GET_VALUE_LEN_DONE, - CFSTORE_EX_STATE_DELETING, - CFSTORE_EX_STATE_DELETE_DONE, - CFSTORE_EX_STATE_FINDING2, - CFSTORE_EX_STATE_FIND_DONE2, - CFSTORE_EX_STATE_FLUSHING2, - CFSTORE_EX_STATE_FLUSH_DONE2, - CFSTORE_EX_STATE_UNINITIALIZING, - CFSTORE_EX_STATE_UNINIT_DONE -} cfstore_ex_state_t; - -typedef struct cfstore_example1_ctx_t -{ - ARM_CFSTORE_CAPABILITIES caps; - uint8_t hkey[CFSTORE_HANDLE_BUFSIZE]; - uint8_t hkey_next_buf[CFSTORE_HANDLE_BUFSIZE]; - uint8_t hkey_prev_buf[CFSTORE_HANDLE_BUFSIZE]; - ARM_CFSTORE_HANDLE hkey_next; - ARM_CFSTORE_HANDLE hkey_prev; - cfstore_ex_state_t state; - ARM_CFSTORE_SIZE len; - ARM_CFSTORE_KEYDESC kdesc; - ARM_CFSTORE_FMODE flags; - char value[CFSTORE_KEY_NAME_MAX_LENGTH+1]; - /* callback attributes*/ - int32_t callback_status; - ARM_CFSTORE_HANDLE callback_handle; -} cfstore_example1_ctx_t; - -static cfstore_example1_ctx_t cfstore_example1_ctx_g; - -extern ARM_CFSTORE_DRIVER cfstore_driver; -ARM_CFSTORE_DRIVER *cfstore_drv = &cfstore_driver; - -/* forward declarations */ -static void cfstore_ex_fms_update(cfstore_example1_ctx_t* ctx); -/// @endcond - - -#ifdef CFSTORE_CONFIG_BACKEND_FLASH_ENABLED - -#define CFSTORE_FLASH_START_FORMAT (FLASH_JOURNAL_OPCODE_RESET + 0x00010000) - -typedef enum cfstore_ex_flash_state_t { - CFSTORE_EX_FLASH_STATE_STARTING = 1, - CFSTORE_EX_FLASH_STATE_FORMATTING, - CFSTORE_EX_FLASH_STATE_INITIALIZING, - CFSTORE_EX_FLASH_STATE_RESETTING, - CFSTORE_EX_FLASH_STATE_READY, -} cfstore_ex_flash_state_t; - -typedef struct cfstore_example1_flash_ctx_t -{ - volatile cfstore_ex_flash_state_t state; -} cfstore_example1_flash_ctx_t; - -static cfstore_example1_flash_ctx_t cfstore_example1_flash_ctx_g; - - -static void cfstore_ex_flash_journal_callback(int32_t status, FlashJournal_OpCode_t cmd_code) -{ - static FlashJournal_t jrnl; - extern ARM_DRIVER_STORAGE ARM_Driver_Storage_MTD_K64F; - const ARM_DRIVER_STORAGE *drv = &ARM_Driver_Storage_MTD_K64F; - - - if(cmd_code == (FlashJournal_OpCode_t) CFSTORE_FLASH_START_FORMAT) { - CFSTORE_EX1_LOG("FORMATTING%s", "\n"); - status = flashJournalStrategySequential_format(drv, 4, cfstore_ex_flash_journal_callback); - CFSTORE_EX1_TEST_ASSERT_MSG(status >= JOURNAL_STATUS_OK, "%s:Error: FlashJournal_format() failed (status=%d)\r\n", __func__, (int) status); - if(status == 0) { - /* async completion pending */ - return; - } - /* status > 0 implies operation completed synchronously - * intentional fall through */ - } - - switch(cmd_code) - { - case FLASH_JOURNAL_OPCODE_FORMAT: - /* format done */ - CFSTORE_EX1_TEST_ASSERT_MSG(status > JOURNAL_STATUS_OK, "%s:Error: FlashJournal_format() failed (status=%d)\r\n", __func__, (int) status); - cfstore_example1_flash_ctx_g.state = CFSTORE_EX_FLASH_STATE_INITIALIZING; - - CFSTORE_EX1_LOG("FLASH INITIALIZING%s", "\n"); - status = FlashJournal_initialize(&jrnl, drv, &FLASH_JOURNAL_STRATEGY_SEQUENTIAL, NULL); - CFSTORE_EX1_TEST_ASSERT_MSG(status >= JOURNAL_STATUS_OK, "%s:Error: FlashJournal_initialize() failed (status=%d)\r\n", __func__, (int) status); - if(status == 0) { - /* async completion pending */ - break; - } - /* status > 0 implies operation completed synchronously - * intentional fall through */ - case FLASH_JOURNAL_OPCODE_INITIALIZE: - /* initialize done */ - CFSTORE_EX1_TEST_ASSERT_MSG(status > JOURNAL_STATUS_OK, "%s:Error: FlashJournal_initialize() failed (status=%d)\r\n", __func__, (int) status); - cfstore_example1_flash_ctx_g.state = CFSTORE_EX_FLASH_STATE_RESETTING; - - CFSTORE_EX1_LOG("FLASH RESETTING%s", "\n"); - status = FlashJournal_reset(&jrnl); - CFSTORE_EX1_TEST_ASSERT_MSG(status >= JOURNAL_STATUS_OK, "%s:Error: FlashJournal_reset() failed (status=%d)\r\n", __func__, (int) status); - /* intentional fall through */ - case FLASH_JOURNAL_OPCODE_RESET: - /* reset done */ - CFSTORE_EX1_LOG("FLASH RESET DONE%s", "\n"); - cfstore_example1_flash_ctx_g.state = CFSTORE_EX_FLASH_STATE_READY; - break; - - default: - CFSTORE_EX1_LOG("%s:Error: notification of unsupported cmd_code event (status=%d, cmd_code=%d)\n", __func__, (int) status, (int) cmd_code); - return; - } - return; -} -#endif /* CFSTORE_CONFIG_BACKEND_FLASH_ENABLED */ - - - -/* @brief test startup code to reset flash for testing purposes. - */ -static int32_t cfstore_test_startup(void) -{ - ARM_CFSTORE_CAPABILITIES caps = cfstore_driver.GetCapabilities(); - CFSTORE_EX1_LOG("INITIALIZING: caps.asynchronous_ops=%d\n", (int) caps.asynchronous_ops); - -#ifdef CFSTORE_CONFIG_BACKEND_FLASH_ENABLED - - memset(&cfstore_example1_flash_ctx_g, 0, sizeof(cfstore_example1_flash_ctx_g)); - cfstore_example1_flash_ctx_g.state = CFSTORE_EX_FLASH_STATE_STARTING; - cfstore_ex_flash_journal_callback(JOURNAL_STATUS_OK, (FlashJournal_OpCode_t) CFSTORE_FLASH_START_FORMAT); - while(cfstore_example1_flash_ctx_g.state != CFSTORE_EX_FLASH_STATE_READY) { - /* spin */ - } - -#endif /* CFSTORE_CONFIG_BACKEND_FLASH_ENABLED */ - - return ARM_DRIVER_OK; -} - - -static void cfstore_ex_callback(int32_t status, ARM_CFSTORE_OPCODE cmd_code, void *client_context, ARM_CFSTORE_HANDLE handle) -{ - (void) handle; - - cfstore_example1_ctx_t* ctx = (cfstore_example1_ctx_t*) client_context; - - /* CFSTORE_EX1_LOG("%s:entered: status=%d, cmd_code=%d (%s) handle=%p\r\n", __func__, (int) status, (int) cmd_code, cfstore_ex_opcode_str[cmd_code], handle); */ - switch(cmd_code) - { - case CFSTORE_OPCODE_INITIALIZE: - ctx->state = CFSTORE_EX_STATE_INIT_DONE; - break; - case CFSTORE_OPCODE_CREATE: - ctx->state = CFSTORE_EX_STATE_CREATE_DONE; - break; - case CFSTORE_OPCODE_WRITE: - ctx->state = CFSTORE_EX_STATE_WRITE_DONE; - break; - case CFSTORE_OPCODE_CLOSE: - switch(ctx->state) - { - case(CFSTORE_EX_STATE_CLOSING1): - ctx->state = CFSTORE_EX_STATE_CLOSE_DONE1; - break; - case(CFSTORE_EX_STATE_CLOSING2): - ctx->state = CFSTORE_EX_STATE_CLOSE_DONE2; - break; - default: - CFSTORE_EX1_TEST_ASSERT_MSG(false, "%s:Error: unknown Close() error (line=%u)\r\n", __func__, __LINE__); - /* The following 'break' statement generates ARMCC #111-D: statement is unreachable warning - * and hence is commented out. Re-instate if previous assert is removed. - * break; */ - } - break; - case CFSTORE_OPCODE_FLUSH: - switch(ctx->state) - { - case(CFSTORE_EX_STATE_FLUSHING1): - ctx->state = CFSTORE_EX_STATE_FLUSH_DONE1; - break; - case(CFSTORE_EX_STATE_FLUSHING2): - ctx->state = CFSTORE_EX_STATE_FLUSH_DONE2; - break; - default: - CFSTORE_EX1_TEST_ASSERT_MSG(false, "%s:Error: unknown Find() error (line=%u)\r\n", __func__, __LINE__); - /* The following 'break' statement generates ARMCC #111-D: statement is unreachable warning - * and hence is commented out. Re-instate if previous assert is removed. - * break; */ - } - break; - case CFSTORE_OPCODE_OPEN: - ctx->state = CFSTORE_EX_STATE_OPEN_DONE; - break; - case CFSTORE_OPCODE_FIND: - switch(ctx->state) - { - case(CFSTORE_EX_STATE_FINDING1): - ctx->state = CFSTORE_EX_STATE_FIND_DONE1; - break; - case(CFSTORE_EX_STATE_FINDING2): - ctx->state = CFSTORE_EX_STATE_FIND_DONE2; - break; - default: - CFSTORE_EX1_TEST_ASSERT_MSG(false, "%s:Error: unknown Find() error (line=%u)\r\n", __func__, __LINE__); - /* The following 'break' statement generates ARMCC #111-D: statement is unreachable warning - * and hence is commented out. Re-instate if previous assert is removed. - * break; */ - } - break; - case CFSTORE_OPCODE_GET_KEY_NAME: - ctx->state = CFSTORE_EX_STATE_GET_KEY_NAME_DONE; - break; - case CFSTORE_OPCODE_GET_VALUE_LEN: - ctx->state = CFSTORE_EX_STATE_GET_VALUE_LEN_DONE; - break; - case CFSTORE_OPCODE_READ: - switch(ctx->state) - { - case(CFSTORE_EX_STATE_READING1): - ctx->state = CFSTORE_EX_STATE_READ_DONE1; - break; - case(CFSTORE_EX_STATE_READING2): - ctx->state = CFSTORE_EX_STATE_READ_DONE2; - break; - default: - CFSTORE_EX1_TEST_ASSERT_MSG(false, "%s:Error: unknown Read() error (line=%u)\r\n", __func__, __LINE__); - /* The following 'break' statement generates ARMCC #111-D: statement is unreachable warning - * and hence is commented out. Re-instate if previous assert is removed. - * break; */ - } - break; - case CFSTORE_OPCODE_RSEEK: - ctx->state = CFSTORE_EX_STATE_RSEEK_DONE; - break; - case CFSTORE_OPCODE_DELETE: - ctx->state = CFSTORE_EX_STATE_DELETE_DONE; - break; - case CFSTORE_OPCODE_UNINITIALIZE: - ctx->state = CFSTORE_EX_STATE_UNINIT_DONE; - break; - case CFSTORE_OPCODE_GET_STATUS: - case CFSTORE_OPCODE_POWER_CONTROL: - default: - CFSTORE_EX1_TEST_ASSERT_MSG(false, "%s:Error: received asynchronous notification for opcode=%d (%s)\r\b", __func__, cmd_code, cmd_code < CFSTORE_OPCODE_MAX ? cfstore_ex_opcode_str[cmd_code] : "unknown"); - /* The following 'break' statement generates ARMCC #111-D: statement is unreachable warning - * and hence is commented out. Re-instate if previous assert is removed. - * break; */ - } - ctx->callback_status = status; - ctx->callback_handle = handle; - cfstore_ex_fms_update(ctx); - return; -} - -static void cfstore_ex_fms_update(cfstore_example1_ctx_t* ctx) -{ - int32_t ret; - - switch (ctx->state) - { - case CFSTORE_EX_STATE_INITIALIZING: - CFSTORE_EX1_LOG("INITIALIZING%s", "\r\n"); - // note that cfstore_ex_callback() for cmd_code==CFSTORE_OPCODE_INITIALIZE can be invoked before Initialize() has returned - ret = cfstore_drv->Initialize(cfstore_ex_callback, ctx); - CFSTORE_EX1_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: Initialize() should return ret >= 0 for async/synch modes(ret=%ld)\r\n", __func__, ret); - if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == false) { - ctx->state = CFSTORE_EX_STATE_INIT_DONE; - break; - } else if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == true) { - // await pending notification of completion. - break; - } - CFSTORE_EX1_TEST_ASSERT_MSG(false, "%s:Error: unknown error (line=%u)\r\n", __func__, __LINE__); - /* The following 'break' statement generates ARMCC #111-D: statement is unreachable warning - * and hence is commented out. Re-instate if previous assert is removed. - * break; */ - - case CFSTORE_EX_STATE_INIT_DONE: - CFSTORE_EX1_LOG("INIT_DONE%s", "\r\n"); - CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_status >= ARM_DRIVER_OK, "%s:Error: Initialize() completion failed (status=%ld)\r\n", __func__, ctx->callback_status); - CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_handle == NULL, "%s:Error: the cfstore_ex_callback(cmd_code==CFSTORE_OPCODE_INITIALIZE) received non-NULL handle (%p)\r\n", __func__, ctx->callback_handle); - ctx->state = CFSTORE_EX_STATE_CREATING; - // intentional fall-through - - case CFSTORE_EX_STATE_CREATING: - CFSTORE_EX1_LOG("CREATING%s", "\r\n"); - memset(&ctx->kdesc, 0, sizeof(ARM_CFSTORE_KEYDESC)); - ctx->kdesc.drl = ARM_RETENTION_NVM; - ctx->len = strlen(cfstore_ex_kv_value); - // note that cfstore_ex_callback() for cmd_code==CFSTORE_OPCODE_CREATE can be invoked before Create() has returned - ret = cfstore_drv->Create(cfstore_ex_kv_name, ctx->len, &ctx->kdesc, ctx->hkey); - CFSTORE_EX1_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: Create() failed (ret=%ld)\r\n", __func__, ret); - if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == false) { - ctx->state = CFSTORE_EX_STATE_CREATE_DONE; - break; - } else if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == true) { - // await pending notification of completion. - break; - } - CFSTORE_EX1_TEST_ASSERT_MSG(false, "%s:Error: unknown error (line=%u)\r\n", __func__, __LINE__); - /* The following 'break' statement generates ARMCC #111-D: statement is unreachable warning - * and hence is commented out. Re-instate if previous assert is removed. - * break; */ - - case CFSTORE_EX_STATE_CREATE_DONE: - CFSTORE_EX1_LOG("CREATE_DONE%s", "\r\n"); - CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_status >= ARM_DRIVER_OK, "%s:Error: Create() completion failed (status=%ld)\r\n", __func__, ctx->callback_status); - CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_handle == ctx->hkey, "%s:Error: the cfstore_ex_callback(cmd_code==CFSTORE_OPCODE_CREATE) received handle (%p) is not the hkey supplied to Create()(%p)\r\n", __func__, ctx->callback_handle, ctx->hkey); - ctx->state = CFSTORE_EX_STATE_WRITING; - // intentional fall-through - - case CFSTORE_EX_STATE_WRITING: - CFSTORE_EX1_LOG("WRITING%s", "\r\n"); - ctx->len = strlen(cfstore_ex_kv_value); - // note that cfstore_ex_callback() for cmd_code==CFSTORE_OPCODE_WRITE can be invoked before Write() has returned - ret = cfstore_drv->Write(ctx->hkey, cfstore_ex_kv_value, &ctx->len); - CFSTORE_EX1_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: Write() failed (ret=%ld)\r\n", __func__, ret); - if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == false) { - ctx->state = CFSTORE_EX_STATE_WRITE_DONE; - break; - } else if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == true) { - // await pending notification of completion. - break; - } - CFSTORE_EX1_TEST_ASSERT_MSG(false, "%s:Error: unknown error (line=%u)\r\n", __func__, __LINE__); - /* The following 'break' statement generates ARMCC #111-D: statement is unreachable warning - * and hence is commented out. Re-instate if previous assert is removed. - * break; */ - - case CFSTORE_EX_STATE_WRITE_DONE: - CFSTORE_EX1_LOG("WRITE_DONE%s", "\r\n"); - CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_status >= ARM_DRIVER_OK, "%s:Error: Write() completion failed (status=%ld)\r\n", __func__, ctx->callback_status); - CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_status == (int32_t) strlen(cfstore_ex_kv_value), "%s:Error: Write() number of octets written (i.e. completion status (%ld)) != strlen(ctx->value)(%ld)\r\n", __func__, ctx->callback_status, (int32_t) strlen(cfstore_ex_kv_value)); - CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_status == (int32_t) ctx->len, "%s:Error: Write() number of octets written (i.e. completion status (%ld)) != updated value of len parameter (%ld)\r\n", __func__, ctx->callback_status, (int32_t) ctx->len); - CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_handle == ctx->hkey, "%s:Error: the cfstore_ex_callback(cmd_code==CFSTORE_OPCODE_WRITE) received handle (%p) is not the hkey supplied to Write()(%p)\r\n", __func__, ctx->callback_handle, ctx->hkey); - ctx->state = CFSTORE_EX_STATE_CLOSING1; - // intentional fall-through - - case CFSTORE_EX_STATE_CLOSING1: - CFSTORE_EX1_LOG("CLOSING1%s", "\r\n"); - // note that cfstore_ex_callback() for cmd_code==CFSTORE_OPCODE_CLOSE can be invoked before Close() has returned - ret = cfstore_drv->Close(ctx->hkey); - CFSTORE_EX1_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: Close() failed (ret=%ld)\r\n", __func__, ret); - if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == false) { - ctx->state = CFSTORE_EX_STATE_CLOSE_DONE1; - break; - } else if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == true) { - // await pending notification of completion. - break; - } - CFSTORE_EX1_TEST_ASSERT_MSG(false, "%s:Error: unknown error (line=%u)\r\n", __func__, __LINE__); - /* The following 'break' statement generates ARMCC #111-D: statement is unreachable warning - * and hence is commented out. Re-instate if previous assert is removed. - * break; */ - - case CFSTORE_EX_STATE_CLOSE_DONE1: - CFSTORE_EX1_LOG("CLOSE_DONE1%s", "\r\n"); - CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_status >= ARM_DRIVER_OK, "%s:Error: Close() completion failed (status=%ld)\r\n", __func__, ctx->callback_status); - CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_handle == NULL, "%s:Error: the cfstore_ex_callback(cmd_code==CFSTORE_OPCODE_CLOSE) received non-NULL handle (%p)\r\n", __func__, ctx->callback_handle); - ctx->state = CFSTORE_EX_STATE_FLUSHING1; - // intentional fall-through - - case CFSTORE_EX_STATE_FLUSHING1: - CFSTORE_EX1_LOG("FLUSHING1%s", "\r\n"); - // note that cfstore_ex_callback() for cmd_code==CFSTORE_OPCODE_FLUSH can be invoked before Flush() has returned - ret = cfstore_drv->Flush(); - CFSTORE_EX1_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: Flush() failed (ret=%ld)\r\n", __func__, ret); - if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == false) { - ctx->state = CFSTORE_EX_STATE_FLUSH_DONE1; - break; - } else if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == true) { - // await pending notification of completion. - break; - } - CFSTORE_EX1_TEST_ASSERT_MSG(false, "%s:Error: unknown error (line=%u)\r\n", __func__, __LINE__); - /* The following 'break' statement generates ARMCC #111-D: statement is unreachable warning - * and hence is commented out. Re-instate if previous assert is removed. - * break; */ - - case CFSTORE_EX_STATE_FLUSH_DONE1: - CFSTORE_EX1_LOG("FLUSH_DONE1%s", "\r\n"); - CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_status >= ARM_DRIVER_OK, "%s:Error: Flush() completion failed (status=%ld)\r\n", __func__, ctx->callback_status); - CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_handle == NULL, "%s:Error: the cfstore_ex_callback(cmd_code==CFSTORE_OPCODE_FLUSH) received non-NULL handle (%p)\r\n", __func__, ctx->callback_handle); - ctx->state = CFSTORE_EX_STATE_OPENING; - // intentional fall-through - - case CFSTORE_EX_STATE_OPENING: - CFSTORE_EX1_LOG("OPENING%s", "\r\n"); - memset(&ctx->flags, 0, sizeof(ctx->flags)); - memset(&ctx->hkey, 0, CFSTORE_HANDLE_BUFSIZE); - // note that cfstore_ex_callback() for cmd_code==CFSTORE_OPCODE_OPEN can be invoked before Open() has returned - ret = cfstore_drv->Open(cfstore_ex_kv_name, ctx->flags, ctx->hkey); - CFSTORE_EX1_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: Open() failed (ret=%ld)\r\n", __func__, ret); - if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == false) { - ctx->state = CFSTORE_EX_STATE_OPEN_DONE; - break; - } else if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == true) { - // await pending notification of completion. - break; - } - CFSTORE_EX1_TEST_ASSERT_MSG(false, "%s:Error: unknown error (line=%u)\r\n", __func__, __LINE__); - /* The following 'break' statement generates ARMCC #111-D: statement is unreachable warning - * and hence is commented out. Re-instate if previous assert is removed. - * break; */ - - case CFSTORE_EX_STATE_OPEN_DONE: - CFSTORE_EX1_LOG("OPEN_DONE%s", "\r\n"); - CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_status >= ARM_DRIVER_OK, "%s:Error: Open() completion failed (status=%ld)\r\n", __func__, ctx->callback_status); - CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_handle == ctx->hkey, "%s:Error: the cfstore_ex_callback(cmd_code==CFSTORE_OPCODE_OPEN) received handle (%p) is not the hkey supplied to Open()(%p)\r\n", __func__, ctx->callback_handle, ctx->hkey); - ctx->state = CFSTORE_EX_STATE_READING1; - // intentional fall-through - - case CFSTORE_EX_STATE_READING1: - CFSTORE_EX1_LOG("READING1%s", "\r\n"); - ctx->len = CFSTORE_KEY_NAME_MAX_LENGTH; - memset(ctx->value, 0, CFSTORE_KEY_NAME_MAX_LENGTH+1); - // note that cfstore_ex_callback() for cmd_code==CFSTORE_OPCODE_READ can be invoked before Read() has returned - ret = cfstore_drv->Read(ctx->hkey, ctx->value, &ctx->len); - CFSTORE_EX1_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: Read() failed (ret=%ld)\r\n", __func__, ret); - if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == false) { - ctx->state = CFSTORE_EX_STATE_READ_DONE1; - break; - } else if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == true) { - // await pending notification of completion. - break; - } - CFSTORE_EX1_TEST_ASSERT_MSG(false, "%s:Error: unknown error (line=%u)\r\n", __func__, __LINE__); - /* The following 'break' statement generates ARMCC #111-D: statement is unreachable warning - * and hence is commented out. Re-instate if previous assert is removed. - * break; */ - - case CFSTORE_EX_STATE_READ_DONE1: - CFSTORE_EX1_LOG("READ_DONE1%s", "\r\n"); - CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_status >= ARM_DRIVER_OK, "%s:Error: Read() completion failed (status=%ld)\r\n", __func__, ctx->callback_status); - CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_status == (int32_t) strlen(cfstore_ex_kv_value), "%s:Error: Read() number of octets read (i.e. completion status (%ld)) != strlen(ctx->value)(%ld)\r\n", __func__, ctx->callback_status, (int32_t) strlen(cfstore_ex_kv_value)); - CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_status == (int32_t) ctx->len, "%s:Error: Read() number of octets read (i.e. completion status (%ld)) != updated value of len parameter (%ld)\r\n", __func__, ctx->callback_status, (int32_t) ctx->len); - CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_handle == ctx->hkey, "%s:Error: the cfstore_ex_callback(cmd_code==CFSTORE_OPCODE_READ) received handle (%p) is not the hkey supplied to Read()(%p)\r\n", __func__, ctx->callback_handle, ctx->hkey); - CFSTORE_EX1_TEST_ASSERT_MSG(strncmp(ctx->value, cfstore_ex_kv_value, strlen(cfstore_ex_kv_value)) == 0, "%s:Error: the read value (%s) is not as expected (%s)\r\n", __func__, ctx->value, cfstore_ex_kv_value); - ctx->state = CFSTORE_EX_STATE_RSEEKING; - // intentional fall-through - - case CFSTORE_EX_STATE_RSEEKING: - CFSTORE_EX1_LOG("RSEEKING%s", "\r\n"); - // note that cfstore_ex_callback() for cmd_code==CFSTORE_OPCODE_READ can be invoked before Read() has returned - ret = cfstore_drv->Rseek(ctx->hkey, CFSTORE_EX1_RSEEK_OFFSET); - CFSTORE_EX1_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: Rseek() failed (ret=%ld)\r\n", __func__, ret); - if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == false) { - ctx->state = CFSTORE_EX_STATE_RSEEK_DONE; - break; - } else if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == true) { - // await pending notification of completion. - break; - } - CFSTORE_EX1_TEST_ASSERT_MSG(false, "%s:Error: unknown error (line=%u)\r\n", __func__, __LINE__); - /* The following 'break' statement generates ARMCC #111-D: statement is unreachable warning - * and hence is commented out. Re-instate if previous assert is removed. - * break; */ - - case CFSTORE_EX_STATE_RSEEK_DONE: - CFSTORE_EX1_LOG("RSEEK_DONE%s", "\r\n"); - CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_status >= ARM_DRIVER_OK, "%s:Error: Read() completion failed (status=%ld)\r\n", __func__, ctx->callback_status); - CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_handle == ctx->hkey, "%s:Error: the cfstore_ex_callback(cmd_code==CFSTORE_OPCODE_RSEEK) received handle (%p) is not the hkey supplied to Read()(%p)\r\n", __func__, ctx->callback_handle, ctx->hkey); - ctx->state = CFSTORE_EX_STATE_READING2; - // intentional fall-through - - case CFSTORE_EX_STATE_READING2: - CFSTORE_EX1_LOG("READING2%s", "\r\n"); - ctx->len = CFSTORE_KEY_NAME_MAX_LENGTH; - memset(ctx->value, 0, CFSTORE_KEY_NAME_MAX_LENGTH+1); - // note that cfstore_ex_callback() for cmd_code==CFSTORE_OPCODE_READ can be invoked before Read() has returned - ret = cfstore_drv->Read(ctx->hkey, ctx->value, &ctx->len); - CFSTORE_EX1_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: Read() failed (ret=%ld)\r\n", __func__, ret); - if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == false) { - ctx->state = CFSTORE_EX_STATE_READ_DONE2; - break; - } else if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == true) { - // await pending notification of completion. - break; - } - CFSTORE_EX1_TEST_ASSERT_MSG(false, "%s:Error: unknown error (line=%u)\r\n", __func__, __LINE__); - /* The following 'break' statement generates ARMCC #111-D: statement is unreachable warning - * and hence is commented out. Re-instate if previous assert is removed. - * break; */ - - case CFSTORE_EX_STATE_READ_DONE2: - CFSTORE_EX1_LOG("READ_DONE2%s", "\r\n"); - CFSTORE_EX1_LOG("%s: value=%s\r\n", __func__, ctx->value); - CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_status >= ARM_DRIVER_OK, "%s:Error: Read() completion failed (status=%ld)\r\n", __func__, ctx->callback_status); - CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_status == (int32_t) strlen(&cfstore_ex_kv_value[CFSTORE_EX1_RSEEK_OFFSET]), "%s:Error: Read() number of octets read (i.e. completion status (%ld)) != strlen(ctx->value)(%ld)\r\n", __func__, ctx->callback_status, (int32_t) strlen(&cfstore_ex_kv_value[CFSTORE_EX1_RSEEK_OFFSET])); - CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_status == (int32_t) ctx->len, "%s:Error: Read() number of octets read (i.e. completion status (%ld)) != updated value of len parameter (%ld)\r\n", __func__, ctx->callback_status, (int32_t) ctx->len); - CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_handle == ctx->hkey, "%s:Error: the cfstore_ex_callback(cmd_code==CFSTORE_OPCODE_READ) received handle (%p) is not the hkey supplied to Read()(%p)\r\n", __func__, ctx->callback_handle, ctx->hkey); - CFSTORE_EX1_TEST_ASSERT_MSG(strncmp(ctx->value, &cfstore_ex_kv_value[CFSTORE_EX1_RSEEK_OFFSET], strlen(&cfstore_ex_kv_value[CFSTORE_EX1_RSEEK_OFFSET])) == 0, "%s:Error: the read value (%s) is not as expected (%s)\r\n", __func__, ctx->value, &cfstore_ex_kv_value[CFSTORE_EX1_RSEEK_OFFSET]); - ctx->state = CFSTORE_EX_STATE_CLOSING2; - // intentional fall-through - - case CFSTORE_EX_STATE_CLOSING2: - CFSTORE_EX1_LOG("CLOSING2%s", "\r\n"); - // note that cfstore_ex_callback() for cmd_code==CFSTORE_OPCODE_CLOSE can be invoked before Close() has returned - ret = cfstore_drv->Close(ctx->hkey); - CFSTORE_EX1_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: Close() failed (ret=%ld)\r\n", __func__, ret); - if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == false) { - ctx->state = CFSTORE_EX_STATE_CLOSE_DONE2; - break; - } else if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == true) { - // await pending notification of completion. - break; - } - CFSTORE_EX1_TEST_ASSERT_MSG(false, "%s:Error: unknown error (line=%u)\r\n", __func__, __LINE__); - /* The following 'break' statement generates ARMCC #111-D: statement is unreachable warning - * and hence is commented out. Re-instate if previous assert is removed. - * break; */ - - case CFSTORE_EX_STATE_CLOSE_DONE2: - CFSTORE_EX1_LOG("CLOSE_DONE2%s", "\r\n"); - CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_status >= ARM_DRIVER_OK, "%s:Error: Close() completion failed (status=%ld)\r\n", __func__, ctx->callback_status); - CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_handle == NULL, "%s:Error: the cfstore_ex_callback(cmd_code==CFSTORE_OPCODE_CLOSE) received non-NULL handle (%p)\r\n", __func__, ctx->callback_handle); - ctx->state = CFSTORE_EX_STATE_FINDING1; - // intentional fall-through - - case CFSTORE_EX_STATE_FINDING1: - CFSTORE_EX1_LOG("FINDING1%s", "\r\n"); - // note that cfstore_ex_callback() for cmd_code==CFSTORE_OPCODE_FIND can be invoked before Find() has returned - ret = cfstore_drv->Find("*", ctx->hkey_next, ctx->hkey_prev); - CFSTORE_EX1_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: Find() failed (ret=%ld)\r\n", __func__, ret); - if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == false) { - ctx->state = CFSTORE_EX_STATE_FIND_DONE1; - break; - } else if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == true) { - // await pending notification of completion. - break; - } - CFSTORE_EX1_TEST_ASSERT_MSG(false, "%s:Error: unknown error (line=%u)\r\n", __func__, __LINE__); - /* The following 'break' statement generates ARMCC #111-D: statement is unreachable warning - * and hence is commented out. Re-instate if previous assert is removed. - * break; */ - - case CFSTORE_EX_STATE_FIND_DONE1: - CFSTORE_EX1_LOG("FIND_DONE1%s", "\r\n"); - CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_status == ARM_DRIVER_OK, "%s:Error: Find() completion failed (status=%ld)\r\n", __func__, ctx->callback_status); - CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_handle == ctx->hkey_prev, "%s:Error: the cfstore_ex_callback(cmd_code==CFSTORE_OPCODE_FIND) received handle (%p) is not the hkey supplied to Find()(%p)\r\n", __func__, ctx->callback_handle, ctx->hkey_prev); - ctx->state = CFSTORE_EX_STATE_GETTING_KEY_NAME; - // intentional fall-through - - case CFSTORE_EX_STATE_GETTING_KEY_NAME: - CFSTORE_EX1_LOG("GETTING_KEY_NAME%s", "\r\n"); - ctx->len = CFSTORE_KEY_NAME_MAX_LENGTH; - memset(ctx->value, 0, CFSTORE_KEY_NAME_MAX_LENGTH+1); - // note that cfstore_ex_callback() for cmd_code==CFSTORE_OPCODE_GET_KEY_NAME can be invoked before GetKeyName() has returned - ret = cfstore_drv->GetKeyName(ctx->hkey_prev, ctx->value, (uint8_t*) &ctx->len); - CFSTORE_EX1_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: GetKeyName() failed (ret=%ld)\r\n", __func__, ret); - if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == false) { - ctx->state = CFSTORE_EX_STATE_GET_KEY_NAME_DONE; - break; - } else if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == true) { - // await pending notification of completion. - break; - } - CFSTORE_EX1_TEST_ASSERT_MSG(false, "%s:Error: unknown error (line=%u)\r\n", __func__, __LINE__); - /* The following 'break' statement generates ARMCC #111-D: statement is unreachable warning - * and hence is commented out. Re-instate if previous assert is removed. - * break; */ - - case CFSTORE_EX_STATE_GET_KEY_NAME_DONE: - CFSTORE_EX1_LOG("GET_KEY_NAME_DONE%s", "\r\n"); - CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_status >= ARM_DRIVER_OK, "%s:Error: GetKeyName() completion failed (status=%ld)\r\n", __func__, ctx->callback_status); - CFSTORE_EX1_TEST_ASSERT_MSG( ((int32_t) ctx->len == ((int32_t) strlen(cfstore_ex_kv_name)+1)), "%s:Error: GetKeyName() updated value of len parameter (%ld) != strlen(cfstore_ex_kv_name) (%ld) (\r\n", __func__, (int32_t) ctx->len, (int32_t) strlen(cfstore_ex_kv_name)); - CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_handle == ctx->hkey_prev, "%s:Error: the cfstore_ex_callback(cmd_code==CFSTORE_OPCODE_GET_KEY_NAME) received handle (%p) is not the hkey supplied to GetKeyName()(%p)\r\n", __func__, ctx->callback_handle, ctx->hkey_prev); - CFSTORE_EX1_TEST_ASSERT_MSG(strncmp(ctx->value, cfstore_ex_kv_name, strlen(cfstore_ex_kv_name)) == 0, "%s:Error: the key name (%s) is not as expected (%s)\r\n", __func__, ctx->value, cfstore_ex_kv_name); - ctx->state = CFSTORE_EX_STATE_GETTING_VALUE_LEN; - // intentional fall-through - - case CFSTORE_EX_STATE_GETTING_VALUE_LEN: - CFSTORE_EX1_LOG("GETTING_VALUE_LEN%s", "\r\n"); - ctx->len = CFSTORE_KEY_NAME_MAX_LENGTH; - // note that cfstore_ex_callback() for cmd_code==CFSTORE_OPCODE_GET_VALUE_LEN can be invoked before GetValueLen() has returned - ret = cfstore_drv->GetValueLen(ctx->hkey_prev, &ctx->len); - CFSTORE_EX1_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: GetValueLen() failed (ret=%ld)\r\n", __func__, ret); - if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == false) { - ctx->state = CFSTORE_EX_STATE_GET_VALUE_LEN_DONE; - break; - } else if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == true) { - // await pending notification of completion. - break; - } - CFSTORE_EX1_TEST_ASSERT_MSG(false, "%s:Error: unknown error (line=%u)\r\n", __func__, __LINE__); - /* The following 'break' statement generates ARMCC #111-D: statement is unreachable warning - * and hence is commented out. Re-instate if previous assert is removed. - * break; */ - - case CFSTORE_EX_STATE_GET_VALUE_LEN_DONE: - CFSTORE_EX1_LOG("GET_VALUE_LEN_DONE%s", "\r\n"); - CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_status >= ARM_DRIVER_OK, "%s:Error: GetValueLen() completion failed (status=%ld)\r\n", __func__, ctx->callback_status); - CFSTORE_EX1_TEST_ASSERT_MSG((int32_t) ctx->len == (int32_t) strlen(cfstore_ex_kv_value), "%s:Error: GetValueLen() updated value of len parameter (%ld) != strlen(cfstore_ex_kv_value)(%ld) \r\n", __func__, (int32_t) ctx->len, (int32_t) strlen(cfstore_ex_kv_value)); - CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_handle == ctx->hkey_prev, "%s:Error: the cfstore_ex_callback(cmd_code==CFSTORE_OPCODE_GET_VALUE_LEN) received handle (%p) is not the hkey supplied to GetValueLen()(%p)\r\n", __func__, ctx->callback_handle, ctx->hkey_prev); - ctx->state = CFSTORE_EX_STATE_DELETING; - // intentional fall-through - - case CFSTORE_EX_STATE_DELETING: - CFSTORE_EX1_LOG("DELETING%s", "\r\n"); - // note that cfstore_ex_callback() for cmd_code==CFSTORE_OPCODE_DELETE can be invoked before Delete() has returned - ret = cfstore_drv->Delete(ctx->callback_handle); - CFSTORE_EX1_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: Close() failed (ret=%ld)\r\n", __func__, ret); - if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == false) { - ctx->state = CFSTORE_EX_STATE_DELETE_DONE; - break; - } else if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == true) { - // await pending notification of completion. - break; - } - CFSTORE_EX1_TEST_ASSERT_MSG(false, "%s:Error: unknown error (line=%u)\r\n", __func__, __LINE__); - /* The following 'break' statement generates ARMCC #111-D: statement is unreachable warning - * and hence is commented out. Re-instate if previous assert is removed. - * break; */ - - case CFSTORE_EX_STATE_DELETE_DONE: - CFSTORE_EX1_LOG("DELETE_DONE%s", "\r\n"); - CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_status >= ARM_DRIVER_OK, "%s:Error: Delete() completion failed (status=%ld)\r\n", __func__, ctx->callback_status); - CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_handle == NULL, "%s:Error: the cfstore_ex_callback(cmd_code==CFSTORE_OPCODE_DELETE) received non-NULL handle (%p)\r\n", __func__, ctx->callback_handle); - CFSTORE_HANDLE_SWAP(ctx->hkey_prev, ctx->hkey_next); - ctx->state = CFSTORE_EX_STATE_FINDING2; - // intentional fall-through - - case CFSTORE_EX_STATE_FINDING2: - CFSTORE_EX1_LOG("FINDING2%s", "\r\n"); - // note that cfstore_ex_callback() for cmd_code==CFSTORE_OPCODE_FIND can be invoked before Find() has returned - ret = cfstore_drv->Find("*", ctx->hkey_next, ctx->hkey_prev); - CFSTORE_EX1_TEST_ASSERT_MSG(ret == ARM_CFSTORE_DRIVER_ERROR_KEY_NOT_FOUND, "%s:Error: Find() failed to return expected value of ARM_CFSTORE_DRIVER_ERROR_KEY_NOT_FOUND (ret=%ld)\r\n", __func__, ret); - if(ret == ARM_CFSTORE_DRIVER_ERROR_KEY_NOT_FOUND && ctx->caps.asynchronous_ops == false) { - ctx->state = CFSTORE_EX_STATE_FIND_DONE2; - break; - } else if(ret == ARM_CFSTORE_DRIVER_ERROR_KEY_NOT_FOUND && ctx->caps.asynchronous_ops == true) { - // await pending notification of completion. - break; - } - CFSTORE_EX1_TEST_ASSERT_MSG(false, "%s:Error: unknown error (line=%u)\r\n", __func__, __LINE__); - /* The following 'break' statement generates ARMCC #111-D: statement is unreachable warning - * and hence is commented out. Re-instate if previous assert is removed. - * break; */ - - case CFSTORE_EX_STATE_FIND_DONE2: - CFSTORE_EX1_LOG("FIND_DONE2%s", "\r\n"); - CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_status == ARM_CFSTORE_DRIVER_ERROR_KEY_NOT_FOUND, "%s:Error: Find() completion should have been ARM_CFSTORE_DRIVER_ERROR_KEY_NOT_FOUND (status=%ld)\r\n", __func__, ctx->callback_status); - ctx->state = CFSTORE_EX_STATE_FLUSHING2; - // intentional fall-through - - case CFSTORE_EX_STATE_FLUSHING2: - CFSTORE_EX1_LOG("FLUSHING2%s", "\r\n"); - // note that cfstore_ex_callback() for cmd_code==CFSTORE_OPCODE_FLUSH can be invoked before Flush() has returned - ret = cfstore_drv->Flush(); - CFSTORE_EX1_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error:2: Flush() failed (ret=%ld)\r\n", __func__, ret); - if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == false) { - ctx->state = CFSTORE_EX_STATE_FLUSH_DONE2; - break; - } else if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == true) { - // await pending notification of completion. - break; - } - CFSTORE_EX1_TEST_ASSERT_MSG(false, "%s:Error: unknown error (line=%u)\r\n", __func__, __LINE__); - /* The following 'break' statement generates ARMCC #111-D: statement is unreachable warning - * and hence is commented out. Re-instate if previous assert is removed. - * break; */ - - case CFSTORE_EX_STATE_FLUSH_DONE2: - CFSTORE_EX1_LOG("FLUSH_DONE2%s", "\r\n"); - CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_status >= ARM_DRIVER_OK, "%s:Error: Flush() completion failed (status=%ld)\r\n", __func__, ctx->callback_status); - CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_handle == NULL, "%s:Error: the cfstore_ex_callback(cmd_code==CFSTORE_OPCODE_FLUSH) received non-NULL handle (%p)\r\n", __func__, ctx->callback_handle); - ctx->state = CFSTORE_EX_STATE_UNINITIALIZING; - // intentional fall-through - - case CFSTORE_EX_STATE_UNINITIALIZING: - CFSTORE_EX1_LOG("UNINITIALIZING%s", "\r\n"); - ret = cfstore_drv->Uninitialize(); - CFSTORE_EX1_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: Uninitialize() should return ret >= 0 for async/synch modes(ret=%ld)\r\n", __func__, ret); - if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == false) { - ctx->state = CFSTORE_EX_STATE_UNINIT_DONE; - break; - } else if(ret >= ARM_DRIVER_OK && ctx->caps.asynchronous_ops == true) { - // await pending notification of completion. - break; - } - CFSTORE_EX1_TEST_ASSERT_MSG(false, "%s:Error: unknown error (line=%u)\r\n", __func__, __LINE__); - /* The following 'break' statement generates ARMCC #111-D: statement is unreachable warning - * and hence is commented out. Re-instate if previous assert is removed. - * break; */ - - case CFSTORE_EX_STATE_UNINIT_DONE: - CFSTORE_EX1_LOG("UNINIT_DONE%s", "\r\n"); - CFSTORE_EX1_TEST_ASSERT_MSG(ctx->callback_handle == NULL, "%s:Error: the cfstore_ex_callback(cmd_code==CFSTORE_OPCODE_UNINITIALIZE) received non-NULL handle (%p)\r\n", __func__, ctx->callback_handle); - cfstore_example1_done = true; - CFSTORE_EX1_LOG("***************%s", "\r\n"); - CFSTORE_EX1_LOG("*** SUCCESS ***%s", "\r\n"); - CFSTORE_EX1_LOG("***************%s", "\r\n"); - break; - } -} - -static control_t cfstore_example1_app_start(const size_t call_count) -{ - cfstore_example1_ctx_t* ctx = &cfstore_example1_ctx_g; - - (void) call_count; - - /* initialise the context */ - memset(ctx, 0, sizeof(cfstore_example1_ctx_t)); - cfstore_example1_done = false; - ctx->hkey_next = ctx->hkey_next_buf; - ctx->hkey_prev = ctx->hkey_prev_buf; - ctx->callback_status = ARM_DRIVER_ERROR; - ctx->state = CFSTORE_EX_STATE_INITIALIZING; - ctx->caps = cfstore_drv->GetCapabilities(); - cfstore_ex_fms_update(ctx); - - /* main application worker loop */ - while (!cfstore_example1_done) - { - // do some work - CFSTORE_EX1_LOG("%s: going to sleep!\r\n", __func__); - -#if defined CFSTORE_CONFIG_MBED_OS_VERSION && CFSTORE_CONFIG_MBED_OS_VERSION == 3 - __WFE(); -#endif /* CFSTORE_CONFIG_MBED_OS_VERSION == 3 */ - -#if defined CFSTORE_CONFIG_MBED_OS_VERSION && CFSTORE_CONFIG_MBED_OS_VERSION == 4 - /* mbedosV3++ - * todo: port __WFE() - */ -#endif /* CFSTORE_CONFIG_MBED_OS_VERSION == 4 */ - CFSTORE_EX1_LOG("%s: woke up!\r\n", __func__); - } - return CaseNext; -} - -#ifndef CFSTORE_EXAMPLE1_APP -/* when built as Configuration-Store example, include greentea support otherwise omit */ - -/* report whether built/configured for flash sync or async mode */ -static control_t cfstore_example1_test_00(const size_t call_count) -{ - int32_t ret = ARM_DRIVER_ERROR; - (void) call_count; - - ret = cfstore_test_startup(); - CFSTORE_EX1_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: failed to perform test startup (ret=%d).\n", __func__, (int) ret); - return CaseNext; -} - -/// @cond CFSTORE_DOXYGEN_DISABLE -utest::v1::status_t greentea_setup(const size_t number_of_cases) -{ - GREENTEA_SETUP(25, "default_auto"); - return greentea_test_setup_handler(number_of_cases); -} - -Case cases[] = { - /* 1 2 3 4 5 6 7 */ - /* 1234567890123456789012345678901234567890123456789012345678901234567890 */ - Case("EXAMPLE1_test_00", cfstore_example1_test_00), - Case("EXAMPLE1_test_01_start", cfstore_example1_app_start), -}; - - -/* Declare your test specification with a custom setup handler */ -Specification specification(greentea_setup, cases); - -int main() -{ - return !Harness::run(specification); -} -/// @endcond - - -#else // CFSTORE_EXAMPLE1_APP - -// stand alone Configuration-Store-Example -void app_start(int argc __unused, char** argv __unused) -{ - cfstore_example1_app_start(0); -} - - - -#endif // CFSTORE_EXAMPLE1_APP - - -#endif // __MBED__ && ! defined TOOLCHAIN_GCC_ARM diff --git a/features/storage/FEATURE_STORAGE/TESTS/cfstore/example2/example2.cpp b/features/storage/FEATURE_STORAGE/TESTS/cfstore/example2/example2.cpp deleted file mode 100644 index 2a96ea0..0000000 --- a/features/storage/FEATURE_STORAGE/TESTS/cfstore/example2/example2.cpp +++ /dev/null @@ -1,256 +0,0 @@ -/* - * mbed Microcontroller Library - * Copyright (c) 2006-2016 ARM Limited - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -/** @file example2.cpp Test case to demonstrate a subset of the API functions each work correctly. - * - * Overview of test: - * - initialises cfstore - * - creates a key called "com.arm.mbed.spv.assets.asset2.payload" with value blob length = 15 = strlen("Grumpy old man")+1. - * - writes the data for the key to be "Grumpy old man" - * - closes kv. - * - opens kv for reading/writing - * - reads the value blob and checks its == "Grumpy old man" - * - writes the first 11 chars of the value blob to be "Grumpy man" plus a NULL; - * - reads the value blob back and checks its as expected - * - * This test is coded so as to work in the following modes: - * - flash sync mode i.e. with caps.asynchronous_ops == false - * - flash async mode i.e. with caps.asynchronous_ops == true - */ -#include "mbed.h" -#include "cfstore_config.h" -#include "cfstore_test.h" -#include "cfstore_debug.h" -#include "Driver_Common.h" -#include "configuration_store.h" -#include "utest/utest.h" -#include "unity/unity.h" -#include "greentea-client/test_env.h" - -#include -#include -#include -#include -#include - -using namespace utest::v1; - -static char cfstore_example2_utest_msg_g[CFSTORE_UTEST_MSG_BUF_SIZE]; - -/* defines */ -/// @cond CFSTORE_DOXYGEN_DISABLE -#define PvMemSet memset -#define PvStrLen strlen -/// @endcond - -/* report whether built/configured for flash sync or async mode */ -static control_t cfstore_example2_test_00(const size_t call_count) -{ - int32_t ret = ARM_DRIVER_ERROR; - - (void) call_count; - ret = cfstore_test_startup(); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_example2_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to perform test startup (ret=%d).\n", __func__, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_example2_utest_msg_g); - return CaseNext; -} - -/// @cond CFSTORE_DOXYGEN_DISABLE -ARM_CFSTORE_DRIVER *drv = &cfstore_driver; -/// @endcond - - -static int32_t CreateKeyValueStore( - const char *keyName, - const char *data, - ARM_CFSTORE_SIZE *dataLength, - ARM_CFSTORE_KEYDESC *keyDesc) -{ - int32_t cfsStatus = ARM_DRIVER_ERROR; - ARM_CFSTORE_SIZE valueLength = 0; - ARM_CFSTORE_HANDLE_INIT(hkey); - - valueLength = *dataLength; - cfsStatus = drv->Create(keyName, valueLength, keyDesc, hkey); - TEST_ASSERT_EQUAL(ARM_DRIVER_OK, cfsStatus); - - valueLength = *dataLength; - cfsStatus = drv->Write(hkey, data, &valueLength); - /* - * (1) Note the following: - * - if cfsStatus > 0 then Write() has completed synchronously and returned the number of bytes written (irrespective of the caps.asynchronous_ops attribute). - * - if cfsStatus == ARM_DRIVER_OK then: - * - if caps.asynchronous_ops == true then the operation will be completed with registered client callback passed to Initialize(). - * - if caps.asynchronous_ops == false then the operation has completed synchronously and no bytes were written. - * - if cfsStatus < ARM_DRIVER_OK then an error has occurred - */ - CFSTORE_TEST_UTEST_MESSAGE(cfstore_example2_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to write key (rc=%d)\n", __func__, (int) cfsStatus); - TEST_ASSERT_MESSAGE(cfsStatus >= ARM_DRIVER_OK, cfstore_example2_utest_msg_g); - - CFSTORE_TEST_UTEST_MESSAGE(cfstore_example2_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%sError: valueLength(%d) does not match the expected dataLength(%d)\n", __func__, (int) valueLength, (int) *dataLength); - TEST_ASSERT_MESSAGE(*dataLength == valueLength, cfstore_example2_utest_msg_g); - - CFSTORE_TEST_UTEST_MESSAGE(cfstore_example2_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%sError: Write() return value cfsStatus(%d) does not match the expected dataLength(%d)\n", __func__, (int) cfsStatus, (int) *dataLength); - TEST_ASSERT_MESSAGE((int32_t) *dataLength == cfsStatus, cfstore_example2_utest_msg_g); - - drv->Close(hkey); - /* CreateKeyValueStore() returns what was returned from Write(). See (1) above for description. */ - return cfsStatus; -} - -static control_t cfstore_example2_test_01(const size_t call_count) -{ - int32_t cfsStatus; - ARM_CFSTORE_HANDLE_INIT(hkey); - ARM_CFSTORE_HANDLE_INIT(updatedKeyH); - ARM_CFSTORE_FMODE flags; - ARM_CFSTORE_KEYDESC kdesc; - ARM_CFSTORE_SIZE valueLen; - char* ptr = NULL; - - const char key[] = "com.arm.mbed.spv.assets.asset2.payload"; - const char value[] = "Grumpy old man"; - - (void) call_count; - - // It must not exceed the value_len field specified when the Key-Value pair was created - const char newDataToWrite[] = "Grumpy man"; - - char readBuf[CFSTORE_KEY_NAME_MAX_LENGTH + 1]; - ARM_CFSTORE_SIZE len = 0; - - // Write a key-value pair - - PvMemSet(&kdesc, 0, sizeof(kdesc)); - PvMemSet(&flags, 0, sizeof(flags)); - PvMemSet(readBuf, 0, CFSTORE_KEY_NAME_MAX_LENGTH + 1); - - kdesc.drl = ARM_RETENTION_WHILE_DEVICE_ACTIVE; - /* The length supplied to Write() is the number of octets to store in the blob. - * Specifying the following value for valueLen will store the terminating null to - * a string, for example. - */ - valueLen = PvStrLen(value) + 1; - - cfsStatus = drv->Initialize(NULL, NULL); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_example2_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Initialize() failed (cfsStatus=%d)\n", __func__, (int) cfsStatus); - TEST_ASSERT_MESSAGE(cfsStatus >= ARM_DRIVER_OK, cfstore_example2_utest_msg_g); - - cfsStatus = CreateKeyValueStore(key, value, &valueLen, &kdesc); - - /* CreateKeyValueStore() returns the number of characters written, which can vary between 0 and the supplied arg valueLen - * - in the case that this example is compiled for flash mode sync, CreateKeyValueStore(), on success should always return valueLen - * - in the case that this example is compiled for flash mode async, CreateKeyValueStore() on success may return a value 0 to valueLen - * with async notification of the completed transaction. - */ - CFSTORE_TEST_UTEST_MESSAGE(cfstore_example2_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%sError: valueLen(%d) does not match the expected returned value from CreateKeyValueStore(%d)\n", __func__, (int) valueLen, (int) cfsStatus); - TEST_ASSERT_MESSAGE(cfsStatus == (int32_t) valueLen, cfstore_example2_utest_msg_g); - - // Read key-value pair with 'Write' permission - - flags.read = true; - flags.write = true; - cfsStatus = drv->Open(key, flags, hkey); - TEST_ASSERT_EQUAL(ARM_DRIVER_OK, cfsStatus); - - len = sizeof(readBuf); - cfsStatus = drv->Read(hkey, readBuf, &len); - /* Read() returns the number of characters read, which can vary between 0 and the size of the value blob, and the size of the supplied buffer */ - CFSTORE_TEST_UTEST_MESSAGE(cfstore_example2_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Read() returned value (%d) does not match the created length of the value blob(%d)\n", __func__, (int) cfsStatus, (int) PvStrLen(value) + 1); - TEST_ASSERT_MESSAGE(cfsStatus == (int32_t) (PvStrLen(value) + 1), cfstore_example2_utest_msg_g); - - CFSTORE_TEST_UTEST_MESSAGE(cfstore_example2_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Read() returned len value (%d) does not match the created length of the value blob(%d)\n", __func__, (int) len, (int) PvStrLen(value) + 1); - TEST_ASSERT_MESSAGE(len == PvStrLen(value) + 1, cfstore_example2_utest_msg_g); - - /* Note: - * - original data = "Grumpy old man", which is 14+1 chars inc NULL - * - New data = "Grumpy man" which is 10+1 chars inc NULL - * - when the key "com.arm.mbed.spv.assets.asset2.payload"; was created, it was created with a value blob size of 14+1=15 chars. - * - The new data is shorter that the old data so it will be accommodated in the value blob - * - The size of the value blob will stay the same. - */ - // Update the value and value length - /* note len set to sizeof(newDataToWrite) which includes the terminating null of the string */ - len = sizeof(newDataToWrite); - cfsStatus = drv->Write(hkey, newDataToWrite, &len); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_example2_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Write() returned cfsStatus value (%d) does not match the length of new data written(%d)\n", __func__, (int) cfsStatus, (int) sizeof(newDataToWrite)); - TEST_ASSERT_MESSAGE(cfsStatus == (int32_t) sizeof(newDataToWrite), cfstore_example2_utest_msg_g); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_example2_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Write() returned len (%d) does not match the length of new data written(%d)\n", __func__, (int) len, (int) sizeof(newDataToWrite)); - TEST_ASSERT_MESSAGE((int32_t) len == (int32_t) sizeof(newDataToWrite), cfstore_example2_utest_msg_g); - - drv->Close(hkey); - - // Check that the value was updated - flags.write = false; - cfsStatus = drv->Open(key, flags, updatedKeyH); - TEST_ASSERT_EQUAL(ARM_DRIVER_OK, cfsStatus); - - len = CFSTORE_KEY_NAME_MAX_LENGTH; - PvMemSet(readBuf, 0, len); - cfsStatus = drv->Read(updatedKeyH, readBuf, &len); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_example2_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Read() returned value (%d) does not match the created length of the value blob(%d)\n", __func__, (int) cfsStatus, (int) PvStrLen(value) + 1); - TEST_ASSERT_MESSAGE(cfsStatus == (int32_t) (PvStrLen(value) + 1), cfstore_example2_utest_msg_g); - - CFSTORE_TEST_UTEST_MESSAGE(cfstore_example2_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Read() returned len value (%d) does not match the created length of the value blob(%d)\n", __func__, (int) len, (int) PvStrLen(value) + 1); - TEST_ASSERT_MESSAGE(len == (PvStrLen(value) + 1), cfstore_example2_utest_msg_g); - - /* convert any terminating nulls to '=' */ - while( (ptr = (char*) memchr(readBuf, 0, (PvStrLen(value) + 1))) != NULL) - { - *ptr = '='; - } - /* check the data is as expected */ - CFSTORE_TEST_UTEST_MESSAGE(cfstore_example2_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Read() returned unexpected string (%s) where nulls have been converted to '=' chars\n", __func__, readBuf); - TEST_ASSERT_MESSAGE(strncmp(readBuf, "Grumpy man=man=", (PvStrLen(value) + 1)) == 0, cfstore_example2_utest_msg_g); - - /* revert to CFSTORE_LOG if more trace required */ - CFSTORE_DBGLOG("Success: New value of KV (%s) value blob (with nulls converted to '=') = (%s)\n", key, readBuf); - - drv->Close(updatedKeyH); - - cfsStatus = drv->Uninitialize(); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_example2_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Uninitialize() failed (cfsStatus=%d)\n", __func__, (int) cfsStatus); - TEST_ASSERT_MESSAGE(cfsStatus >= ARM_DRIVER_OK, cfstore_example2_utest_msg_g); - - return CaseNext; -} - - -/// @cond CFSTORE_DOXYGEN_DISABLE -utest::v1::status_t greentea_setup(const size_t number_of_cases) -{ - GREENTEA_SETUP(400, "default_auto"); - return greentea_test_setup_handler(number_of_cases); -} - -Case cases[] = { - /* 1 2 3 4 5 6 7 */ - /* 1234567890123456789012345678901234567890123456789012345678901234567890 */ - Case("EXAMPLE2_test_00", cfstore_example2_test_00), - Case("EXAMPLE2_test_01", cfstore_example2_test_01), -}; - - -/* Declare your test specification with a custom setup handler */ -Specification specification(greentea_setup, cases); - -int main() -{ - return !Harness::run(specification); -} -/// @endcond diff --git a/features/storage/FEATURE_STORAGE/TESTS/cfstore/example3/example3.cpp b/features/storage/FEATURE_STORAGE/TESTS/cfstore/example3/example3.cpp deleted file mode 100644 index dfe5be6..0000000 --- a/features/storage/FEATURE_STORAGE/TESTS/cfstore/example3/example3.cpp +++ /dev/null @@ -1,326 +0,0 @@ -/* - * mbed Microcontroller Library - * Copyright (c) 2006-2016 ARM Limited - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -/** @file example3.cpp Test case to demonstrate each API function works correctly. - * - * \par Example 3 Notes - * - * Example3 is a synchronous mode example for creating key-values in the persistent storage. - * - * The flash-journal synchronous mode example test does the following CFSTORE operations: - * - initialises - * - creates a key-value pair (KV). - * - writes the data for the KV - * - closes KV. - * - flushes the KV to flash - * - opens KV for reading. - * - reads KV and checks the value blob was the same as previously written. - * - closes KV. - * - finds a KV (there is only 1 to find). - * - for the KV returned, get the key name. - * - for the KV returned, get the value length. - * - for the KV returned, delete the KV. - * - find another KV (which fails as there are no more keys to find). - * - flushes the updated state to flash to store the removal of the deleted KV. - * - uninitialises - * - stops - * - * This test is coded so as to work only in flash journal sync mode - * i.e. with caps.asynchronous_ops == false - * - * The test leaves the flash in the same state as at the beginning of the test so - * it can be run a second time on the device without flashing, and the test should - * still work. - * - * \par How to Build Example3 as a Stand-alone Application - * - * This example can be build as a stand-alone application as follows: - * - Create a new mbed application using the `mbed new .` command. - * - Copy this file example3.cpp from the to the top level application directory and rename the file to main.cpp. - * - Build the application with `mbed compile -v -m -t -DCFSTORE_EXAMPLE3_APP` e.g. `mbed compile -v -m K64F -t GCC_ARM -DCFSTORE_EXAMPLE3_APP`. - * - */ -#include "mbed.h" -#ifndef CFSTORE_EXAMPLE3_APP -/* when built as Configuration-Store example, include greentea support otherwise omit */ -#include "utest/utest.h" -#include "unity/unity.h" -#include "greentea-client/test_env.h" -#else // CFSTORE_EXAMPLE3_APP -/* map utest types for building as stand alone example */ -#define control_t void -#define CaseNext -#endif // CFSTORE_EXAMPLE3_APP - -#include "cfstore_config.h" -#include "cfstore_test.h" -#include "configuration_store.h" - - -#include -#include -#include - -#ifndef CFSTORE_EXAMPLE3_APP -using namespace utest::v1; -#endif - - -/// @cond CFSTORE_DOXYGEN_DISABLE -#define CFSTORE_EX1_TEST_ASSERT(Expr) if (!(Expr)) { printf("%s:%u: assertion failure\r\n", __FUNCTION__, __LINE__); while (1) ;} -#define CFSTORE_EX1_TEST_ASSERT_EQUAL(expected, actual) if ((expected) != (actual)) {printf("%s:%u: assertion failure\r\n", __FUNCTION__, __LINE__); while (1) ;} -#define CFSTORE_EX1_TEST_ASSERT_NOT_EQUAL(expected, actual) if ((expected) == (actual)) {printf("%s:%u: assertion failure\r\n", __FUNCTION__, __LINE__); while (1) ;} - -#define CFSTORE_EX1_TEST_ASSERT_MSG(Expr, _fmt, ...) \ - do \ - { \ - if (!(Expr)) \ - { \ - printf(_fmt, __VA_ARGS__); \ - while (1) ; \ - } \ - }while(0); - -#define CFSTORE_EX1_LOG(_fmt, ...) \ - do \ - { \ - printf(_fmt, __VA_ARGS__); \ - }while(0); - - -const char* cfstore_ex3_opcode_str[] = -{ - "UNDEFINED", - "CFSTORE_OPCODE_CLOSE", - "CFSTORE_OPCODE_CREATE", - "CFSTORE_OPCODE_DELETE", - "CFSTORE_OPCODE_FIND", - "CFSTORE_OPCODE_FLUSH", - "CFSTORE_OPCODE_GET_KEY_NAME", - "CFSTORE_OPCODE_GET_STATUS", - "CFSTORE_OPCODE_GET_VALUE_LEN", - "CFSTORE_OPCODE_INITIALIZE", - "CFSTORE_OPCODE_OPEN", - "CFSTORE_OPCODE_POWER_CONTROL", - "CFSTORE_OPCODE_READ", - "CFSTORE_OPCODE_RSEEK", - "CFSTORE_OPCODE_UNINITIALIZE", - "CFSTORE_OPCODE_WRITE", - "CFSTORE_OPCODE_MAX" -}; - -const char* cfstore_ex3_kv_name = "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.well.well"; -const char* cfstore_ex3_kv_value = "TheRollingStone"; -#define CFSTORE_EX1_RSEEK_OFFSET 10 /* offset to S of Stone */ - -typedef struct cfstore_example3_ctx_t -{ - ARM_CFSTORE_CAPABILITIES caps; - uint8_t hkey[CFSTORE_HANDLE_BUFSIZE]; - uint8_t hkey_next_buf[CFSTORE_HANDLE_BUFSIZE]; - uint8_t hkey_prev_buf[CFSTORE_HANDLE_BUFSIZE]; - ARM_CFSTORE_HANDLE hkey_next; - ARM_CFSTORE_HANDLE hkey_prev; - ARM_CFSTORE_SIZE len; - ARM_CFSTORE_KEYDESC kdesc; - ARM_CFSTORE_FMODE flags; - char value[CFSTORE_KEY_NAME_MAX_LENGTH+1]; -} cfstore_example3_ctx_t; - -static cfstore_example3_ctx_t cfstore_example3_ctx_g; - -extern ARM_CFSTORE_DRIVER cfstore_driver; -ARM_CFSTORE_DRIVER *cfstore_drv = &cfstore_driver; -/// @endcond - - -static void cfstore_ex3_test_01(cfstore_example3_ctx_t* ctx) -{ - int32_t ret; - - CFSTORE_EX1_LOG("INITIALIZING%s", "\r\n"); - ret = cfstore_drv->Initialize(NULL, NULL); - CFSTORE_EX1_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: Initialize() should return ret >= 0 for async/synch modes(ret=%ld)\r\n", __func__, ret); - - CFSTORE_EX1_LOG("CREATING%s", "\r\n"); - memset(&ctx->kdesc, 0, sizeof(ARM_CFSTORE_KEYDESC)); - ctx->kdesc.drl = ARM_RETENTION_NVM; - ctx->len = strlen(cfstore_ex3_kv_value); - ret = cfstore_drv->Create(cfstore_ex3_kv_name, ctx->len, &ctx->kdesc, ctx->hkey); - CFSTORE_EX1_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: Create() failed (ret=%ld)\r\n", __func__, ret); - - CFSTORE_EX1_LOG("WRITING%s", "\r\n"); - ctx->len = strlen(cfstore_ex3_kv_value); - ret = cfstore_drv->Write(ctx->hkey, cfstore_ex3_kv_value, &ctx->len); - CFSTORE_EX1_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: Write() failed (ret=%ld)\r\n", __func__, ret); - - CFSTORE_EX1_TEST_ASSERT_MSG(ret == (int32_t) strlen(cfstore_ex3_kv_value), "%s:Error: Write() number of octets written (i.e. completion status (%ld)) != strlen(ctx->value)(%ld)\r\n", __func__, ret, (int32_t) strlen(cfstore_ex3_kv_value)); - CFSTORE_EX1_TEST_ASSERT_MSG(ret == (int32_t) ctx->len, "%s:Error: Write() number of octets written (i.e. completion status (%ld)) != updated value of len parameter (%ld)\r\n", __func__, ret, (int32_t) ctx->len); - - CFSTORE_EX1_LOG("CLOSING1%s", "\r\n"); - ret = cfstore_drv->Close(ctx->hkey); - CFSTORE_EX1_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: Close() failed (ret=%ld)\r\n", __func__, ret); - - CFSTORE_EX1_LOG("FLUSHING1%s", "\r\n"); - ret = cfstore_drv->Flush(); - CFSTORE_EX1_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: Flush() failed (ret=%ld)\r\n", __func__, ret); - - CFSTORE_EX1_LOG("OPENING%s", "\r\n"); - memset(&ctx->flags, 0, sizeof(ctx->flags)); - memset(&ctx->hkey, 0, CFSTORE_HANDLE_BUFSIZE); - ret = cfstore_drv->Open(cfstore_ex3_kv_name, ctx->flags, ctx->hkey); - CFSTORE_EX1_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: Open() failed (ret=%ld)\r\n", __func__, ret); - - CFSTORE_EX1_LOG("READING1%s", "\r\n"); - ctx->len = CFSTORE_KEY_NAME_MAX_LENGTH; - memset(ctx->value, 0, CFSTORE_KEY_NAME_MAX_LENGTH+1); - ret = cfstore_drv->Read(ctx->hkey, ctx->value, &ctx->len); - CFSTORE_EX1_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: Read() failed (ret=%ld)\r\n", __func__, ret); - - CFSTORE_EX1_TEST_ASSERT_MSG(ret == (int32_t) strlen(cfstore_ex3_kv_value), "%s:Error: Read() number of octets read (i.e. completion status (%ld)) != strlen(ctx->value)(%ld)\r\n", __func__, ret, (int32_t) strlen(cfstore_ex3_kv_value)); - CFSTORE_EX1_TEST_ASSERT_MSG(ret == (int32_t) ctx->len, "%s:Error: Read() number of octets read (i.e. completion status (%ld)) != updated value of len parameter (%ld)\r\n", __func__, ret, (int32_t) ctx->len); - CFSTORE_EX1_TEST_ASSERT_MSG(strncmp(ctx->value, cfstore_ex3_kv_value, strlen(cfstore_ex3_kv_value)) == 0, "%s:Error: the read value (%s) is not as expected (%s)\r\n", __func__, ctx->value, cfstore_ex3_kv_value); - - CFSTORE_EX1_LOG("RSEEKING%s", "\r\n"); - ret = cfstore_drv->Rseek(ctx->hkey, CFSTORE_EX1_RSEEK_OFFSET); - CFSTORE_EX1_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: Rseek() failed (ret=%ld)\r\n", __func__, ret); - - CFSTORE_EX1_LOG("READING2%s", "\r\n"); - ctx->len = CFSTORE_KEY_NAME_MAX_LENGTH; - memset(ctx->value, 0, CFSTORE_KEY_NAME_MAX_LENGTH+1); - ret = cfstore_drv->Read(ctx->hkey, ctx->value, &ctx->len); - CFSTORE_EX1_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: Read() failed (ret=%ld)\r\n", __func__, ret); - CFSTORE_EX1_TEST_ASSERT_MSG(ret == (int32_t) strlen(&cfstore_ex3_kv_value[CFSTORE_EX1_RSEEK_OFFSET]), "%s:Error: Read() number of octets read (i.e. completion status (%ld)) != strlen(ctx->value)(%ld)\r\n", __func__, ret, (int32_t) strlen(&cfstore_ex3_kv_value[CFSTORE_EX1_RSEEK_OFFSET])); - CFSTORE_EX1_TEST_ASSERT_MSG(ret == (int32_t) ctx->len, "%s:Error: Read() number of octets read (i.e. completion status (%ld)) != updated value of len parameter (%ld)\r\n", __func__, ret, (int32_t) ctx->len); - CFSTORE_EX1_TEST_ASSERT_MSG(strncmp(ctx->value, &cfstore_ex3_kv_value[CFSTORE_EX1_RSEEK_OFFSET], strlen(&cfstore_ex3_kv_value[CFSTORE_EX1_RSEEK_OFFSET])) == 0, "%s:Error: the read value (%s) is not as expected (%s)\r\n", __func__, ctx->value, &cfstore_ex3_kv_value[CFSTORE_EX1_RSEEK_OFFSET]); - - CFSTORE_EX1_LOG("CLOSING2%s", "\r\n"); - ret = cfstore_drv->Close(ctx->hkey); - CFSTORE_EX1_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: Close() failed (ret=%ld)\r\n", __func__, ret); - - CFSTORE_EX1_LOG("FINDING1%s", "\r\n"); - ret = cfstore_drv->Find("*", ctx->hkey_next, ctx->hkey_prev); - CFSTORE_EX1_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: Find() failed (ret=%ld)\r\n", __func__, ret); - - CFSTORE_EX1_LOG("GETTING_KEY_NAME%s", "\r\n"); - ctx->len = CFSTORE_KEY_NAME_MAX_LENGTH; - memset(ctx->value, 0, CFSTORE_KEY_NAME_MAX_LENGTH+1); - ret = cfstore_drv->GetKeyName(ctx->hkey_prev, ctx->value, (uint8_t*) &ctx->len); - CFSTORE_EX1_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: GetKeyName() failed (ret=%ld)\r\n", __func__, ret); - CFSTORE_EX1_TEST_ASSERT_MSG( ((int32_t) ctx->len == ((int32_t) strlen(cfstore_ex3_kv_name)+1)), "%s:Error: GetKeyName() updated value of len parameter (%ld) != strlen(cfstore_ex3_kv_name) (%ld) (\r\n", __func__, (int32_t) ctx->len, (int32_t) strlen(cfstore_ex3_kv_name)); - CFSTORE_EX1_TEST_ASSERT_MSG(strncmp(ctx->value, cfstore_ex3_kv_name, strlen(cfstore_ex3_kv_name)) == 0, "%s:Error: the key name (%s) is not as expected (%s)\r\n", __func__, ctx->value, cfstore_ex3_kv_name); - - CFSTORE_EX1_LOG("GETTING_VALUE_LEN%s", "\r\n"); - ctx->len = CFSTORE_KEY_NAME_MAX_LENGTH; - ret = cfstore_drv->GetValueLen(ctx->hkey_prev, &ctx->len); - CFSTORE_EX1_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: GetValueLen() failed (ret=%ld)\r\n", __func__, ret); - CFSTORE_EX1_TEST_ASSERT_MSG((int32_t) ctx->len == (int32_t) strlen(cfstore_ex3_kv_value), "%s:Error: GetValueLen() updated value of len parameter (%ld) != strlen(cfstore_ex3_kv_value)(%ld) \r\n", __func__, (int32_t) ctx->len, (int32_t) strlen(cfstore_ex3_kv_value)); - - CFSTORE_EX1_LOG("DELETING%s", "\r\n"); - ret = cfstore_drv->Delete(ctx->hkey_prev); - CFSTORE_EX1_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: Close() failed (ret=%ld)\r\n", __func__, ret); - CFSTORE_HANDLE_SWAP(ctx->hkey_prev, ctx->hkey_next); - - CFSTORE_EX1_LOG("FINDING2%s", "\r\n"); - ret = cfstore_drv->Find("*", ctx->hkey_next, ctx->hkey_prev); - CFSTORE_EX1_TEST_ASSERT_MSG(ret == ARM_CFSTORE_DRIVER_ERROR_KEY_NOT_FOUND, "%s:Error: Find() failed to return expected value of ARM_CFSTORE_DRIVER_ERROR_KEY_NOT_FOUND (ret=%ld)\r\n", __func__, ret); - - CFSTORE_EX1_LOG("FLUSHING2%s", "\r\n"); - ret = cfstore_drv->Flush(); - CFSTORE_EX1_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error:2: Flush() failed (ret=%ld)\r\n", __func__, ret); - - CFSTORE_EX1_LOG("UNINITIALIZING%s", "\r\n"); - ret = cfstore_drv->Uninitialize(); - CFSTORE_EX1_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: Uninitialize() should return ret >= 0 for synch mode(ret=%ld)\r\n", __func__, ret); - CFSTORE_EX1_LOG("***************%s", "\r\n"); - CFSTORE_EX1_LOG("*** SUCCESS ***%s", "\r\n"); - CFSTORE_EX1_LOG("***************%s", "\r\n"); - return; -} - -static control_t cfstore_example3_app_start(const size_t call_count) -{ - cfstore_example3_ctx_t* ctx = &cfstore_example3_ctx_g; - - (void) call_count; - - /* initialise the context */ - memset(ctx, 0, sizeof(cfstore_example3_ctx_t)); - ctx->hkey_next = ctx->hkey_next_buf; - ctx->hkey_prev = ctx->hkey_prev_buf; - ctx->caps = cfstore_drv->GetCapabilities(); - CFSTORE_EX1_LOG("%s:INITIALIZING: caps.asynchronous_ops=%lu\n", __func__, ctx->caps.asynchronous_ops); - if(ctx->caps.asynchronous_ops == 1){ - /* This is a sync mode only test. If this test is not built for sync mode, then skip testing return true - * This means the test will conveniently pass when run in CI as part of async mode testing */ - CFSTORE_EX1_LOG("*** Skipping test as binary built for flash journal async mode, and this test is sync-only%s", "\n"); - return CaseNext; - } - cfstore_ex3_test_01(ctx); - return CaseNext; -} - -#ifndef CFSTORE_EXAMPLE3_APP -/* when built as Configuration-Store example, include greentea support otherwise omit */ - -/* report whether built/configured for flash sync or async mode */ -static control_t cfstore_example3_test_00(const size_t call_count) -{ - int32_t ret = ARM_DRIVER_ERROR; - - (void) call_count; - ret = cfstore_test_startup(); - CFSTORE_EX1_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: failed to perform test startup (ret=%d).\n", __func__, (int) ret); - return CaseNext; -} - -/// @cond CFSTORE_DOXYGEN_DISABLE -utest::v1::status_t greentea_setup(const size_t number_of_cases) -{ - GREENTEA_SETUP(100, "default_auto"); - return greentea_test_setup_handler(number_of_cases); -} - -Case cases[] = { - /* 1 2 3 4 5 6 7 */ - /* 1234567890123456789012345678901234567890123456789012345678901234567890 */ - Case("EXAMPLE3_test_00", cfstore_example3_test_00), - Case("EXAMPLE3_test_01_start", cfstore_example3_app_start), -}; - - -/* Declare your test specification with a custom setup handler */ -Specification specification(greentea_setup, cases); - -int main() -{ - return !Harness::run(specification); -} -/// @endcond - - -#else // CFSTORE_EXAMPLE3_APP - -// stand alone Configuration-Store-Example -void app_start(int argc __unused, char** argv __unused) -{ - cfstore_example3_app_start(0); -} - - -#endif // CFSTORE_EXAMPLE3_APP diff --git a/features/storage/FEATURE_STORAGE/TESTS/cfstore/example4/example4.cpp b/features/storage/FEATURE_STORAGE/TESTS/cfstore/example4/example4.cpp deleted file mode 100644 index 125126f..0000000 --- a/features/storage/FEATURE_STORAGE/TESTS/cfstore/example4/example4.cpp +++ /dev/null @@ -1,205 +0,0 @@ -/* - * mbed Microcontroller Library - * Copyright (c) 2006-2016 ARM Limited - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -/** @file example4.cpp Test case to demonstrate a subset of the API functions each work correctly. - * - * Test case created from Issue 10 code supplied by Motti Gondabi. The code: - * - creates a KV - * - writes the KV - * - closes the KV - * - flushes the KV - * - opens the KV. - * - deletes the KV. - * - flushes empty configuration store. - * - * The test case makes sure that the implementation can flush an empty configuration store - * without causing errors. This has only been possible since flash-journal-strategy-sequential - * v0.4.0. - */ - -#include "mbed.h" -#include "cfstore_config.h" -#include "cfstore_test.h" -#include "cfstore_debug.h" -#include "Driver_Common.h" -#include "configuration_store.h" -#include "utest/utest.h" -#include "unity/unity.h" -#include "greentea-client/test_env.h" - -#include -#include -#include -#include -#include - -using namespace utest::v1; - -static char cfstore_example4_utest_msg_g[CFSTORE_UTEST_MSG_BUF_SIZE]; - -/* defines */ -/// @cond CFSTORE_DOXYGEN_DISABLE -#define PvMemSet memset -#define PvStrLen strlen -#define PvKeyValue_t cfstore_kv_data_t - -ARM_CFSTORE_DRIVER *gCfStoreDriver = &cfstore_driver; -/// @endcond - -static control_t cfstore_example4_test_00(const size_t call_count) -{ - int32_t ret = ARM_DRIVER_ERROR; - ARM_CFSTORE_CAPABILITIES caps;; - - (void) call_count; - - /* initialise the context */ - caps = gCfStoreDriver->GetCapabilities(); - CFSTORE_LOG("%s:INITIALIZING: caps.asynchronous_ops=%lu\n", __func__, caps.asynchronous_ops); - if(caps.asynchronous_ops == 1){ - /* This is a sync mode only test. If this test is not built for sync mode, then skip testing return true - * This means the test will conveniently pass when run in CI as part of async mode testing */ - CFSTORE_LOG("*** Skipping test as binary built for flash journal async mode, and this test is sync-only%s", "\n"); - return CaseNext; - } - ret = cfstore_test_startup(); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_example4_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to perform test startup (ret=%d).\n", __func__, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_example4_utest_msg_g); - return CaseNext; -} - - -/* used for sync mode build only */ -#if defined STORAGE_DRIVER_CONFIG_HARDWARE_MTD_ASYNC_OPS && STORAGE_DRIVER_CONFIG_HARDWARE_MTD_ASYNC_OPS==0 - -static const PvKeyValue_t testDataKeyValue[] = { - { "com.arm.mbed.spv.assets.dtls", "This Is my DTLS Secret" }, - { "com.arm.mbed.spv.assets.asset1.payload", "The Rolling Stone" }, - { "com.arm.mbed.spv.assets.asset2.payload", "Grumpy old man" }, - { "com.arm.mbed.spv.assets.asset3.payload", "Delete this asset payload" }, -}; - - -static int32_t CreateKeyValueStore( - const char *keyName, - const char *data, - ARM_CFSTORE_SIZE *dataLength, - ARM_CFSTORE_KEYDESC *keyDesc) -{ - int32_t cfsStatus = ARM_DRIVER_ERROR; - ARM_CFSTORE_SIZE valueLength = 0; - ARM_CFSTORE_HANDLE_INIT(hkey); - - valueLength = *dataLength; - cfsStatus = gCfStoreDriver->Create(keyName, valueLength, keyDesc, hkey); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_example4_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Create() failed (cfsStatus=%d)\n", __func__, (int) cfsStatus); - TEST_ASSERT_MESSAGE(cfsStatus >= ARM_DRIVER_OK, cfstore_example4_utest_msg_g); - - valueLength = *dataLength; - cfsStatus = gCfStoreDriver->Write(hkey, data, &valueLength); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_example4_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Write() failed (cfsStatus=%d)\n", __func__, (int) cfsStatus); - TEST_ASSERT_MESSAGE(cfsStatus >= ARM_DRIVER_OK, cfstore_example4_utest_msg_g); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_example4_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: valueLength != *dataLength\n", __func__); - TEST_ASSERT_MESSAGE(valueLength == *dataLength, cfstore_example4_utest_msg_g); - - cfsStatus = gCfStoreDriver->Close(hkey); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_example4_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Close() failed (cfsStatus=%d)\n", __func__, (int) cfsStatus); - TEST_ASSERT_MESSAGE(cfsStatus >= ARM_DRIVER_OK, cfstore_example4_utest_msg_g); - - cfsStatus = gCfStoreDriver->Flush(); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_example4_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Flush() failed (cfsStatus=%d)\n", __func__, (int) cfsStatus); - TEST_ASSERT_MESSAGE(cfsStatus >= ARM_DRIVER_OK, cfstore_example4_utest_msg_g); - - return ARM_DRIVER_OK; -} - - -static control_t cfstore_example4_test_01(const size_t call_count) -{ - int32_t cfsStatus = ARM_DRIVER_ERROR; - ARM_CFSTORE_KEYDESC kdesc; - ARM_CFSTORE_SIZE valueLen; - ARM_CFSTORE_FMODE flags; - ARM_CFSTORE_HANDLE_INIT(hkey); - - (void) call_count; - PvMemSet(&kdesc, 0, sizeof(kdesc)); - - kdesc.drl = ARM_RETENTION_NVM; - valueLen = PvStrLen(testDataKeyValue[0].value); - - cfsStatus = gCfStoreDriver->Initialize(NULL, NULL); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_example4_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Initialize() failed (cfsStatus=%d)\n", __func__, (int) cfsStatus); - TEST_ASSERT_MESSAGE(cfsStatus >= ARM_DRIVER_OK, cfstore_example4_utest_msg_g); - - cfsStatus = CreateKeyValueStore(testDataKeyValue[0].key_name, testDataKeyValue[0].value, &valueLen, &kdesc); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_example4_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: CreateKeyValueStore() failed (cfsStatus=%d)\n", __func__, (int) cfsStatus); - TEST_ASSERT_MESSAGE(cfsStatus >= ARM_DRIVER_OK, cfstore_example4_utest_msg_g); - - PvMemSet(&flags, 0, sizeof(flags)); - - cfsStatus = gCfStoreDriver->Open(testDataKeyValue[0].key_name, flags, hkey); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_example4_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Open() failed (cfsStatus=%d)\n", __func__, (int) cfsStatus); - TEST_ASSERT_MESSAGE(cfsStatus >= ARM_DRIVER_OK, cfstore_example4_utest_msg_g); - - cfsStatus = gCfStoreDriver->Delete(hkey); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_example4_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Delete() failed (cfsStatus=%d)\n", __func__, (int) cfsStatus); - TEST_ASSERT_MESSAGE(cfsStatus >= ARM_DRIVER_OK, cfstore_example4_utest_msg_g); - - cfsStatus = gCfStoreDriver->Close(hkey); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_example4_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Close() failed (cfsStatus=%d)\n", __func__, (int) cfsStatus); - TEST_ASSERT_MESSAGE(cfsStatus >= ARM_DRIVER_OK, cfstore_example4_utest_msg_g); - - cfsStatus = gCfStoreDriver->Flush(); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_example4_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Flush() failed (cfsStatus=%d)\n", __func__, (int) cfsStatus); - TEST_ASSERT_MESSAGE(cfsStatus >= ARM_DRIVER_OK, cfstore_example4_utest_msg_g); - - cfsStatus = gCfStoreDriver->Uninitialize(); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_example4_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Uninitialize() failed (cfsStatus=%d)\n", __func__, (int) cfsStatus); - TEST_ASSERT_MESSAGE(cfsStatus >= ARM_DRIVER_OK, cfstore_example4_utest_msg_g); - - return CaseNext; -} -#endif // STORAGE_DRIVER_CONFIG_HARDWARE_MTD_ASYNC_OPS - - -/// @cond CFSTORE_DOXYGEN_DISABLE -utest::v1::status_t greentea_setup(const size_t number_of_cases) -{ - GREENTEA_SETUP(400, "default_auto"); - return greentea_test_setup_handler(number_of_cases); -} - -Case cases[] = { - /* 1 2 3 4 5 6 7 */ - /* 1234567890123456789012345678901234567890123456789012345678901234567890 */ - Case("EXAMPLE4_test_00", cfstore_example4_test_00), -#if defined STORAGE_DRIVER_CONFIG_HARDWARE_MTD_ASYNC_OPS && STORAGE_DRIVER_CONFIG_HARDWARE_MTD_ASYNC_OPS==0 - Case("EXAMPLE4_test_01", cfstore_example4_test_01), -#endif // STORAGE_DRIVER_CONFIG_HARDWARE_MTD_ASYNC_OPS -}; - - -/* Declare your test specification with a custom setup handler */ -Specification specification(greentea_setup, cases); - -int main() -{ - return !Harness::run(specification); -} -/// @endcond diff --git a/features/storage/FEATURE_STORAGE/TESTS/cfstore/example5/example5.cpp b/features/storage/FEATURE_STORAGE/TESTS/cfstore/example5/example5.cpp deleted file mode 100644 index 267b15a..0000000 --- a/features/storage/FEATURE_STORAGE/TESTS/cfstore/example5/example5.cpp +++ /dev/null @@ -1,330 +0,0 @@ -/* - * mbed Microcontroller Library - * Copyright (c) 2006-2016 ARM Limited - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Test cases to add and delete KVs in the CFSTORE. - */ - - -/** @file example5.cpp - * - * Test case to demonstrate each API function works correctly. - * - * \par Example 5 Notes - * - * This flash-journal synchronous mode example test does the following CFSTORE operations: - * - initialises - * - creates a key-value pair (KV). - * - writes the data for the KV - * - closes KV. - * - flushes the KV to flash - * - flushes the KV to flash again - * - uninitialises - * - initialises - * - opens KV for reading. - * - deletes KV - * - closes KV. - * - flushes the updated state to flash to store the removal of the deleted KV. - * - uninitialises - * - stops - * - * This test is coded so as to work only in flash journal sync mode - * i.e. with caps.asynchronous_ops == false - * - * The test leaves the flash in the same state as at the beginning of the test so - * it can be run a second time on the device without flashing, and the test should - * still work. - * - * \par How to Build Example5 as a Stand-alone Application - * - * This example can be build as a stand-alone application as follows: - * - Create a new mbed application using the `mbed new .` command. - * - Copy this file example5.cpp from the to the top level application directory and rename the file to main.cpp. - * - Build the application with `mbed compile -v -m -t -DCFSTORE_EXAMPLE5_APP` e.g. `mbed compile -v -m K64F -t GCC_ARM -DCFSTORE_EXAMPLE5_APP`. - */ - -#include "mbed.h" -#include "Driver_Common.h" - -#ifndef CFSTORE_EXAMPLE5_APP -/* when built as Configuration-Store example, include greentea support otherwise omit */ -#include "utest/utest.h" -#include "unity/unity.h" -#include "greentea-client/test_env.h" -#else // CFSTORE_EXAMPLE5_APP -/* map utest types for building as stand alone example */ -#define control_t void -#define CaseNext -#endif // CFSTORE_EXAMPLE5_APP - -#include "cfstore_config.h" -#include "configuration_store.h" - -#ifdef CFSTORE_CONFIG_BACKEND_FLASH_ENABLED -#include "flash_journal_strategy_sequential.h" -#include "flash_journal.h" -#include "Driver_Common.h" -#endif /* CFSTORE_CONFIG_BACKEND_FLASH_ENABLED */ - -#include -#include -#include - - -#ifndef CFSTORE_EXAMPLE5_APP -using namespace utest::v1; -#endif - - -/// @cond CFSTORE_DOXYGEN_DISABLE -#define CFSTORE_EX5_TEST_ASSERT(Expr) if (!(Expr)) { printf("%s:%u: assertion failure\r\n", __FUNCTION__, __LINE__); while (1) ;} -#define CFSTORE_EX5_TEST_ASSERT_EQUAL(expected, actual) if ((expected) != (actual)) {printf("%s:%u: assertion failure\r\n", __FUNCTION__, __LINE__); while (1) ;} -#define CFSTORE_EX5_TEST_ASSERT_NOT_EQUAL(expected, actual) if ((expected) == (actual)) {printf("%s:%u: assertion failure\r\n", __FUNCTION__, __LINE__); while (1) ;} - -#define CFSTORE_EX5_TEST_ASSERT_MSG(Expr, _fmt, ...) \ - do \ - { \ - if (!(Expr)) \ - { \ - printf(_fmt, __VA_ARGS__); \ - while (1) ; \ - } \ - }while(0); - -#define CFSTORE_EX5_LOG(_fmt, ...) \ - do \ - { \ - printf(_fmt, __VA_ARGS__); \ - }while(0); - - -const char* cfstore_ex5_opcode_str[] = -{ - "UNDEFINED", - "CFSTORE_OPCODE_CLOSE", - "CFSTORE_OPCODE_CREATE", - "CFSTORE_OPCODE_DELETE", - "CFSTORE_OPCODE_FIND", - "CFSTORE_OPCODE_FLUSH", - "CFSTORE_OPCODE_GET_KEY_NAME", - "CFSTORE_OPCODE_GET_STATUS", - "CFSTORE_OPCODE_GET_VALUE_LEN", - "CFSTORE_OPCODE_INITIALIZE", - "CFSTORE_OPCODE_OPEN", - "CFSTORE_OPCODE_POWER_CONTROL", - "CFSTORE_OPCODE_READ", - "CFSTORE_OPCODE_RSEEK", - "CFSTORE_OPCODE_UNINITIALIZE", - "CFSTORE_OPCODE_WRITE", - "CFSTORE_OPCODE_MAX" -}; - -const char* cfstore_ex5_kv_name = "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.well.well"; -const char* cfstore_ex5_kv_value = "TheRollingStone"; -#define CFSTORE_EX5_RSEEK_OFFSET 10 /* offset to S of Stone */ - -/// @cond CFSTORE_DOXYGEN_DISABLE -typedef struct cfstore_EXAMPLE5_ctx_t -{ - ARM_CFSTORE_CAPABILITIES caps; - uint8_t hkey[CFSTORE_HANDLE_BUFSIZE]; - uint8_t hkey_next_buf[CFSTORE_HANDLE_BUFSIZE]; - uint8_t hkey_prev_buf[CFSTORE_HANDLE_BUFSIZE]; - ARM_CFSTORE_HANDLE hkey_next; - ARM_CFSTORE_HANDLE hkey_prev; - ARM_CFSTORE_SIZE len; - ARM_CFSTORE_KEYDESC kdesc; - ARM_CFSTORE_FMODE flags; - char value[CFSTORE_KEY_NAME_MAX_LENGTH+1]; -} cfstore_EXAMPLE5_ctx_t; - -static cfstore_EXAMPLE5_ctx_t cfstore_EXAMPLE5_ctx_g; - -extern ARM_CFSTORE_DRIVER cfstore_driver; -ARM_CFSTORE_DRIVER *cfstore_drv = &cfstore_driver; -/// @endcond - - -/* @brief test startup code to reset flash - */ -int32_t cfstore_test_startup(void) -{ - ARM_CFSTORE_CAPABILITIES caps = cfstore_driver.GetCapabilities(); - CFSTORE_EX5_LOG("INITIALIZING: caps.asynchronous_ops=%d\n", (int) caps.asynchronous_ops); - -#ifdef CFSTORE_CONFIG_BACKEND_FLASH_ENABLED - int32_t ret = ARM_DRIVER_ERROR; - static FlashJournal_t jrnl; - extern ARM_DRIVER_STORAGE ARM_Driver_Storage_MTD_K64F; - const ARM_DRIVER_STORAGE *drv = &ARM_Driver_Storage_MTD_K64F; - - ret = FlashJournal_initialize(&jrnl, drv, &FLASH_JOURNAL_STRATEGY_SEQUENTIAL, NULL); - CFSTORE_EX5_TEST_ASSERT_MSG(ret >= JOURNAL_STATUS_OK, "%s:Error: FlashJournal_initialize() failed (ret=%d)\r\n", __func__, (int) ret); - - ret = FlashJournal_reset(&jrnl); - CFSTORE_EX5_TEST_ASSERT_MSG(ret >= JOURNAL_STATUS_OK, "%s:Error: FlashJournal_reset() failed (ret=%d)\r\n", __func__, (int) ret); -#endif /* CFSTORE_CONFIG_BACKEND_FLASH_ENABLED */ - - return ARM_DRIVER_OK; -} - - -static void cfstore_ex5_test_01(cfstore_EXAMPLE5_ctx_t* ctx) -{ - int32_t ret; - - CFSTORE_EX5_LOG("INITIALIZING1%s", "\r\n"); - ret = cfstore_drv->Initialize(NULL, NULL); - CFSTORE_EX5_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: Initialize() should return ret >= 0 for async/synch modes(ret=%ld)\r\n", __func__, ret); - - CFSTORE_EX5_LOG("CREATING%s", "\r\n"); - memset(&ctx->kdesc, 0, sizeof(ARM_CFSTORE_KEYDESC)); - ctx->kdesc.drl = ARM_RETENTION_NVM; - ctx->len = strlen(cfstore_ex5_kv_value); - ret = cfstore_drv->Create(cfstore_ex5_kv_name, ctx->len, &ctx->kdesc, ctx->hkey); - CFSTORE_EX5_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: Create() failed (ret=%ld)\r\n", __func__, ret); - - CFSTORE_EX5_LOG("WRITING%s", "\r\n"); - ctx->len = strlen(cfstore_ex5_kv_value); - ret = cfstore_drv->Write(ctx->hkey, cfstore_ex5_kv_value, &ctx->len); - CFSTORE_EX5_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: Write() failed (ret=%ld)\r\n", __func__, ret); - - CFSTORE_EX5_TEST_ASSERT_MSG(ret == (int32_t) strlen(cfstore_ex5_kv_value), "%s:Error: Write() number of octets written (i.e. completion status (%ld)) != strlen(ctx->value)(%ld)\r\n", __func__, ret, (int32_t) strlen(cfstore_ex5_kv_value)); - CFSTORE_EX5_TEST_ASSERT_MSG(ret == (int32_t) ctx->len, "%s:Error: Write() number of octets written (i.e. completion status (%ld)) != updated value of len parameter (%ld)\r\n", __func__, ret, (int32_t) ctx->len); - - CFSTORE_EX5_LOG("CLOSING1%s", "\r\n"); - ret = cfstore_drv->Close(ctx->hkey); - CFSTORE_EX5_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: Close() failed (ret=%ld)\r\n", __func__, ret); - - CFSTORE_EX5_LOG("FLUSHING1%s", "\r\n"); - ret = cfstore_drv->Flush(); - CFSTORE_EX5_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: Flush() failed (ret=%ld)\r\n", __func__, ret); - -#ifdef CFSTORE_CONFIG_BACKEND_FLASH_ENABLED - /* CFSTORE_CONFIG_BACKEND_FLASH_ENABLED => flash storage support present. - * if this was not the case (i.e. cfstore running SRAM in memory mode) then - * we dont compile in the Uninitialize()/Initialize() as the - * Uninitialize() clears the sram */ - CFSTORE_EX5_LOG("UNINITIALIZING1%s", "\r\n"); - ret = cfstore_drv->Uninitialize(); - CFSTORE_EX5_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: Uninitialize() should return ret >= 0 for synch mode(ret=%ld)\r\n", __func__, ret); - - CFSTORE_EX5_LOG("INITIALIZING2%s", "\r\n"); - ret = cfstore_drv->Initialize(NULL, NULL); - CFSTORE_EX5_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: Initialize() should return ret >= 0 for async/synch modes(ret=%ld)\r\n", __func__, ret); -#endif - - CFSTORE_EX5_LOG("OPENING%s", "\r\n"); - memset(&ctx->flags, 0, sizeof(ctx->flags)); - memset(&ctx->hkey, 0, CFSTORE_HANDLE_BUFSIZE); - ret = cfstore_drv->Open(cfstore_ex5_kv_name, ctx->flags, ctx->hkey); - CFSTORE_EX5_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: Open() failed (ret=%ld)\r\n", __func__, ret); - - CFSTORE_EX5_LOG("DELETE1%s", "\r\n"); - ctx->len = CFSTORE_KEY_NAME_MAX_LENGTH; - memset(ctx->value, 0, CFSTORE_KEY_NAME_MAX_LENGTH + 1); - ret = cfstore_drv->Delete(ctx->hkey); - CFSTORE_EX5_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: Delete() failed (ret=%ld)\r\n", __func__, ret); - - CFSTORE_EX5_LOG("CLOSING2%s", "\r\n"); - ret = cfstore_drv->Close(ctx->hkey); - CFSTORE_EX5_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: Close() failed (ret=%ld)\r\n", __func__, ret); - - CFSTORE_EX5_LOG("FLUSHING3%s", "\r\n"); - ret = cfstore_drv->Flush(); - CFSTORE_EX5_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: Flush() failed (ret=%ld)\r\n", __func__, ret); - - CFSTORE_EX5_LOG("OPEN2 %s", "\r\n"); - memset(&ctx->flags, 0, sizeof(ctx->flags)); - memset(&ctx->hkey, 0, CFSTORE_HANDLE_BUFSIZE); - ret = cfstore_drv->Open(cfstore_ex5_kv_name, ctx->flags, ctx->hkey); - CFSTORE_EX5_TEST_ASSERT_MSG(ret == ARM_CFSTORE_DRIVER_ERROR_KEY_NOT_FOUND, "%s:Error: Find() failed to return expected value of ARM_CFSTORE_DRIVER_ERROR_KEY_NOT_FOUND (ret=%ld)\r\n", __func__, ret); - - CFSTORE_EX5_LOG("FLUSHING2%s", "\r\n"); - ret = cfstore_drv->Flush(); - CFSTORE_EX5_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error:2: Flush() failed (ret=%ld)\r\n", __func__, ret); - - CFSTORE_EX5_LOG("UNINITIALIZING3%s", "\r\n"); - ret = cfstore_drv->Uninitialize(); - CFSTORE_EX5_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: Uninitialize() should return ret >= 0 for synch mode(ret=%ld)\r\n", __func__, ret); - CFSTORE_EX5_LOG("***************%s", "\r\n"); - CFSTORE_EX5_LOG("*** SUCCESS ***%s", "\r\n"); - CFSTORE_EX5_LOG("***************%s", "\r\n"); - return; -} - -static control_t cfstore_EXAMPLE5_app_start(const size_t call_count) -{ - int32_t ret = ARM_DRIVER_ERROR; - cfstore_EXAMPLE5_ctx_t* ctx = &cfstore_EXAMPLE5_ctx_g; - - (void) call_count; - - /* initialise the context */ - memset(ctx, 0, sizeof(cfstore_EXAMPLE5_ctx_t)); - ctx->hkey_next = ctx->hkey_next_buf; - ctx->hkey_prev = ctx->hkey_prev_buf; - ctx->caps = cfstore_drv->GetCapabilities(); - CFSTORE_EX5_LOG("%s:INITIALIZING: caps.asynchronous_ops=%lu\n", __func__, ctx->caps.asynchronous_ops); - if(ctx->caps.asynchronous_ops){ - /* This is a sync mode only test. If this test is not built for sync mode, then skip testing return true - * This means the test will conveniently pass when run in CI as part of async mode testing */ - CFSTORE_EX5_LOG("*** Skipping test as binary built for flash journal async mode, and this test is sync-only%s", "\n"); - return CaseNext; - } - ret = cfstore_test_startup(); - CFSTORE_EX5_TEST_ASSERT_MSG(ret >= ARM_DRIVER_OK, "%s:Error: failed to perform test startup (ret=%d).\n", __func__, (int) ret); - cfstore_ex5_test_01(ctx); - return CaseNext; -} - -#ifndef CFSTORE_EXAMPLE5_APP -/* when built as Configuration-Store example, include greentea support otherwise omit */ - -/// @cond CFSTORE_DOXYGEN_DISABLE -utest::v1::status_t greentea_setup(const size_t number_of_cases) -{ - GREENTEA_SETUP(100, "default_auto"); - return greentea_test_setup_handler(number_of_cases); -} - -Case cases[] = { - /* 1 2 3 4 5 6 7 */ - /* 1234567890123456789012345678901234567890123456789012345678901234567890 */ - Case("EXAMPLE5_test_01_start", cfstore_EXAMPLE5_app_start), -}; - - -/* Declare your test specification with a custom setup handler */ -Specification specification(greentea_setup, cases); - - -int main() -{ - return !Harness::run(specification); -} -/// @endcond - - -#else // CFSTORE_EXAMPLE5_APP - -// stand alone Configuration-Store-Example -void app_start(int argc __unused, char** argv __unused) -{ - cfstore_EXAMPLE5_app_start(0); -} - - -#endif // CFSTORE_EXAMPLE5_APP diff --git a/features/storage/FEATURE_STORAGE/TESTS/cfstore/find/find.cpp b/features/storage/FEATURE_STORAGE/TESTS/cfstore/find/find.cpp deleted file mode 100644 index 71c7a1e..0000000 --- a/features/storage/FEATURE_STORAGE/TESTS/cfstore/find/find.cpp +++ /dev/null @@ -1,537 +0,0 @@ -/* - * mbed Microcontroller Library - * Copyright (c) 2006-2016 ARM Limited - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ - -/** @file find.cpp Test cases to find KVs in the CFSTORE using the drv->Find() interface. - * - * Please consult the documentation under the test-case functions for - * a description of the individual test case. - */ - -#include "mbed.h" -#include "cfstore_config.h" -#include "cfstore_test.h" -#include "cfstore_debug.h" -#include "Driver_Common.h" -#include "configuration_store.h" -#include "utest/utest.h" -#include "unity/unity.h" -#include "greentea-client/test_env.h" -#include "cfstore_utest.h" - -#include -#include -#include -#include -#include - -using namespace utest::v1; - -static char cfstore_find_utest_msg_g[CFSTORE_UTEST_MSG_BUF_SIZE]; - - - -/* report whether built/configured for flash sync or async mode */ -static control_t cfstore_find_test_00(const size_t call_count) -{ - int32_t ret = ARM_DRIVER_ERROR; - - (void) call_count; - ret = cfstore_test_startup(); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_find_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to perform test startup (ret=%d).\n", __func__, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_find_utest_msg_g); - return CaseNext; -} - -/** @brief test to call cfstore_find() with a key_name string that exceeds - * the maximum length - * @return on success returns CaseNext to continue to next test case, otherwise will assert on errors. - */ -control_t cfstore_find_test_01(const size_t call_count) -{ - (void) call_count; - /*todo: implement test */ - CFSTORE_TEST_UTEST_MESSAGE(cfstore_find_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Warn: Not implemented\n", __func__); - CFSTORE_DBGLOG("%s: WARN: requires implementation\n", __func__); - TEST_ASSERT_MESSAGE(true, cfstore_find_utest_msg_g); - return CaseNext; -} - - -/** @brief test to call cfstore_find() with key_name that in includes - * illegal characters - * - the character can be at the beginning of the key_name - * - the character can be at the end of the key_name - * - the character can be somewhere within the key_name string - * - * @return on success returns CaseNext to continue to next test case, otherwise will assert on errors. - */ -control_t cfstore_find_test_02(const size_t call_count) -{ - /*todo: implement test - * - * specify the allowable characters in a set. - * e.g. "0123456789ABCDEFGHIJKLMNOPQRSTUVQXYZabcdefghijklmnopqrstuvwxyz.[]*" - * and use this set as the sell of allowable character codes. - * All other 0-255 values for character codes should not be found in the key_name string - * but the function should be tested for what happens in that case. - * - * Some code may be common here with other functions requiring a key_name e.g. cfstore_find( - */ - (void) call_count; - /*todo: implement test */ - CFSTORE_TEST_UTEST_MESSAGE(cfstore_find_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Warn: Not implemented\n", __func__); - CFSTORE_DBGLOG("%s: WARN: requires implementation\n", __func__); - TEST_ASSERT_MESSAGE(true, cfstore_find_utest_msg_g); - return CaseNext; -} - - -/** @brief test to call cfstore_find() with key_name that in includes - * illegal characters - * - the character can be at the beginning of the key_name - * - the character can be at the end of the key_name - * - the character can be somewhere within the key_name string - * - * @return on success returns CaseNext to continue to next test case, otherwise will assert on errors. - */ -control_t cfstore_find_test_03_end(const size_t call_count) -{ - char* read_buf = NULL; - const uint8_t key_name_max_len = CFSTORE_KEY_NAME_MAX_LENGTH+1; - char key_name_buf[key_name_max_len]; - int32_t ret = ARM_DRIVER_ERROR; - ARM_CFSTORE_SIZE len = 0; - ARM_CFSTORE_SIZE max_len = 0; - cfstore_kv_data_t* node; - cfstore_kv_data_t* client_node = cfstore_test_init_1_data; - ARM_CFSTORE_DRIVER* drv = &cfstore_driver; - ARM_CFSTORE_KEYDESC kdesc; - ARM_CFSTORE_HANDLE_INIT(prev); - ARM_CFSTORE_HANDLE_INIT(next); - - CFSTORE_DBGLOG("%s:entered\r\n", __func__); - (void) call_count; - memset(&kdesc, 0, sizeof(kdesc)); - memset(key_name_buf, 0, CFSTORE_KEY_NAME_MAX_LENGTH+1); - - /*scan for max length of value blob*/ - node = client_node; - while(node->key_name != NULL) - { - len = strlen(node->value); - if(len > max_len){ - max_len = len; - } - node++; - } - max_len++; /* space for a terminating null, if required */ - read_buf = (char*) malloc(max_len); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_find_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Failed to allocated read buffer \r\n", __func__); - TEST_ASSERT_MESSAGE(read_buf != NULL, cfstore_find_utest_msg_g); - - ret = cfstore_test_init_1(); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_find_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to initialise cfstore area with entries\r\n", __func__); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_find_utest_msg_g); - - /* now find and read back the key values */ - ret = ARM_DRIVER_ERROR; - node = client_node; - while(node->key_name != NULL) - { - CFSTORE_DBGLOG("%s:About to find node (key_name=\"%s\", value=\"%s\")\r\n", __func__, node->key_name, node->value); - ret = drv->Find(node->key_name, prev, next); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_find_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Failed to find node (key_name=\"%s\", value=\"%s\")\r\n", __func__, node->key_name, node->value); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_find_utest_msg_g); - - CFSTORE_TEST_UTEST_MESSAGE(cfstore_find_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Find failed to return valid key handle\r\n", __func__); - TEST_ASSERT_MESSAGE(next != NULL, cfstore_find_utest_msg_g); - - ret = drv->GetValueLen(next, &len); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_find_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to write key (key_name=\"%s\", value=\"%s\")\r\n", __func__, node->key_name, node->value); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_find_utest_msg_g); - - if(len > 0) { - ret = drv->Read(next, read_buf, &len); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_find_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to read value (key_name=\"%s\", value=\"%s\")\r\n", __func__, node->key_name, node->value); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_find_utest_msg_g); - - /* check read data is as expected */ - CFSTORE_TEST_UTEST_MESSAGE(cfstore_find_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Read value data (%s) != KV value data (key_name=\"%s\", value=\"%s\")\r\n", __func__, read_buf, node->key_name, node->value); - TEST_ASSERT_MESSAGE(strncmp(read_buf, node->value, strlen(node->value)) == 0, cfstore_find_utest_msg_g); - - } - read_buf[len] = '\0'; - /* revert to CFSTORE_LOG if more trace required */ - CFSTORE_DBGLOG("Successfully found KV and read value data (key_name=\"%s\", value=\"%s\")\r\n", node->key_name, read_buf); - memset(read_buf, 0, len); - drv->Close(next); - node++; - } - - ret = drv->Uninitialize(); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_find_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Uninitialize() call failed.\n", __func__); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_find_utest_msg_g); - return CaseNext; -} - - -/** @brief TODO: write test that uses cfstore_find_test_04_kv_data to grow {key, value} - * from 1 char to 221 chars long. - * @return on success returns CaseNext to continue to next test case, otherwise will assert on errors. - */ -/* - * use this data: - * static cfstore_kv_data_t cfstore_find_test_04_kv_data[] = { - * { "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef", "abcdefghjklmnopqrstuvwxyzabcdefghjklmnopqrstuvwxyzabcdefghjklmnopqrstuvwxyzabcdefghjklmnopqrstuvwxyzabcdefghjklmnopqrstuvwxyzabcdefghjklmnopqrstuvwxyzabcdefghjklmnopqrstuvwxyzabcdefghjklmnopqrstuvwxyzabcdefghjklmnopqrstuvwxyz"}, - * { NULL, NULL}, - * }; - * - */ -control_t cfstore_find_test_04(const size_t call_count) -{ - /*todo: implement test - * - * */ - (void) call_count; - /*todo: implement test */ - CFSTORE_TEST_UTEST_MESSAGE(cfstore_find_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Warn: Not implemented\n", __func__); - CFSTORE_DBGLOG("%s: WARN: requires implementation\n", __func__); - TEST_ASSERT_MESSAGE(true, cfstore_find_utest_msg_g); - return CaseNext; -} - - -/** - * @brief function to test whether a key name is valid, can be added to the - * cfstore and found by a wildcard string - * - * @param key_name - * name of the key to create in the store - * @param match - * string to use to try and find key_name in the cfstore - * @param should_find - * if true, then 'match' should find 'key_name' in the store - * if false, then 'match' should not find 'key_name' in the store - * - * @return status code - * ARM_DRIVER_OK, the test passed successfully - * ret < ARM_DRIVER_OK, the test failed with the return code - * supplying more details - */ -static bool cfstore_find_key_name_validate(const char *key_name, const char *match, bool should_find) -{ - bool bret = true; - bool btest_status = false; - char* test_data = (char*) "test_data"; - int32_t ret = ARM_DRIVER_ERROR; - ARM_CFSTORE_SIZE len = 0; - ARM_CFSTORE_KEYDESC kdesc; - - CFSTORE_FENTRYLOG("%s:entered\r\n", __func__); - memset(&kdesc, 0, sizeof(kdesc)); - - /* create */ - kdesc.drl = ARM_RETENTION_WHILE_DEVICE_ACTIVE; - len = strlen(test_data); - ret = cfstore_test_create((const char*) key_name, test_data, &len, &kdesc); - if(ret < ARM_DRIVER_OK){ - CFSTORE_ERRLOG("%s:Error: failed to create kv (key_name=%s.\r\n", "cfstore_find_test_05_ex", key_name); - return ret; - } - ret = cfstore_test_kv_is_found(match, &bret); - if(ret < ARM_DRIVER_OK && ret != ARM_CFSTORE_DRIVER_ERROR_KEY_NOT_FOUND){ - CFSTORE_ERRLOG("%s:Error: cfstore_test_kv_is_found() failed.\r\n", "cfstore_find_test_05_ex"); - return ret; - } - /* dont not use any functions that require finding the created item as they may not work, - * depending on the construction of the test key_name & match strings */ - if(should_find == bret) - { - CFSTORE_DBGLOG("%s:Success: Find() behaved as expected.\r\n", "cfstore_find_test_05_ex"); - btest_status = true; - } - else - { - CFSTORE_ERRLOG("cfstore_find_test_05_ex: Failed match on %s vs. %s\n", key_name, match); - } - /*delete using the actual name */ - ret = cfstore_test_delete((const char*) key_name); - if(ret < ARM_DRIVER_OK){ - CFSTORE_ERRLOG("%s:Error: failed to delete kv (key_name=%s)(ret=%d).\r\n", "cfstore_find_test_05_ex", key_name, (int)ret); - } - return btest_status; -} - - -/// @cond CFSTORE_DOXYGEN_DISABLE -typedef struct cfstore_find_key_name_validate_t { - const char* key_name; - const char* match; - uint32_t f_allowed : 1; -} cfstore_find_key_name_validate_t; - -cfstore_find_key_name_validate_t cfstore_find_test_05_data[] = { - { "yotta.hello-world.animal{wobbly-dog}{foot}backLeft", "yotta.hello-world.animal{*}{foot}backLeft", true}, - { "yotta.hello-world.animal{wobbly-dog}{foot}backLeft", "yotta.hello-world.animal{wobbly-dog}{*}backLeft", true}, - { "yotta.hello-world.animal{wobbly-dog}{foot}backLeft", "yotta.hello-world.animal{wobbly-dog}{*}*", true}, - { "yotta.hello-world.animal{1}{foot}backLeft", "yotta.hello-world.animal{?}{foot}backLeft", false}, - { "xyz", "xyz", true}, - { "xyzijkXYZ", "XYZ", false}, - { "xyzijkXYZ", "*XYZ", true}, - { "xyzijkXYZ", "xyz*XYZ", true}, - { "xyzijkXYZ", "*yz*XYZ", true}, - { "xyzijkXYZ", "*ijk*", true}, - { NULL, NULL, false}, -}; -/// @endcond - - -/** @brief test whether a key name in the above table are valid, can be added to the - * cfstore and found by a wildcard string - * - * @return on success returns CaseNext to continue to next test case, otherwise will assert on errors. - */ -control_t cfstore_find_test_05_end(const size_t call_count) -{ - bool ret = false; - int32_t ret32 = ARM_DRIVER_ERROR; - ARM_CFSTORE_DRIVER* drv = &cfstore_driver; - cfstore_find_key_name_validate_t* node = cfstore_find_test_05_data; - - (void) call_count; - - while(node->key_name != NULL) - { - ret = cfstore_find_key_name_validate(node->key_name, node->match, node->f_allowed); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_find_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: test failed (ret=%d)\n", __func__, (int) ret); - TEST_ASSERT_MESSAGE(ret == true, cfstore_find_utest_msg_g); - node++; - } - - ret32 = drv->Uninitialize(); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_find_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Uninitialize() call failed.\n", __func__); - TEST_ASSERT_MESSAGE(ret32 >= ARM_DRIVER_OK, cfstore_find_utest_msg_g); - return CaseNext; -} - - -/// @cond CFSTORE_DOXYGEN_DISABLE -#define CFSTORE_FIND_TEST_06_ENTRY_MATCH_03 { "0123456789abcdef0123456.yxxx.3", "abcdefghijklmnopqrstuvwxyz"} -#define CFSTORE_FIND_TEST_06_ENTRY_MATCH_05 { "0123456789abcdef0123456.yxxx.5", "abcdefghijklmnopqrstuvwxyz"} -#define CFSTORE_FIND_TEST_06_ENTRY_MATCH_07 { "0123456789abcdef0123456.yxxx.7", "abcdefghijklmnopqrstuvwxyz"} -#define CFSTORE_FIND_TEST_06_ENTRY_MATCH_09 { "0123456789abcdef0123456.yxxx.9", "abcdefghijklmnopqrstuvwxyz"} - -#define CFSTORE_FIND_TEST_06_ENTRY_NOMATCH_01 { "0123456789abcdef0123456.xxxx.1", "abcdefghijklmnopqrstuvwxyz"} -#define CFSTORE_FIND_TEST_06_ENTRY_NOMATCH_02 { "0123456789abcdef0123456.xxxx.2", "abcdefghijklmnopqrstuvwxyz"} -#define CFSTORE_FIND_TEST_06_ENTRY_NOMATCH_04 { "0123456789abcdef0123456.xxxx.4", "abcdefghijklmnopqrstuvwxyz"} -#define CFSTORE_FIND_TEST_06_ENTRY_NOMATCH_06 { "0123456789abcdef0123456.xxxx.6", "abcdefghijklmnopqrstuvwxyz"} -#define CFSTORE_FIND_TEST_06_ENTRY_NOMATCH_08 { "0123456789abcdef0123456.xxxx.8", "abcdefghijklmnopqrstuvwxyz"} -#define CFSTORE_FIND_TEST_06_ENTRY_NOMATCH_10 { "0123456789abcdef0123456.xxxx.10", "abcdefghijklmnopqrstuvwxyz"} -#define CFSTORE_FIND_TEST_06_ENTRY_NOMATCH_11 { "0123456789abcdef0123456.xxxx.11", "abcdefghijklmnopqrstuvwxyz"} - -/* table 1: to initialise cfstore with CFSTORE_CREATE_TEST_01_TABLE_MID_ENTRY_01 */ -static cfstore_kv_data_t cfstore_find_test_06_data[] = { - CFSTORE_FIND_TEST_06_ENTRY_NOMATCH_01, - CFSTORE_FIND_TEST_06_ENTRY_NOMATCH_02, - CFSTORE_FIND_TEST_06_ENTRY_MATCH_03, - CFSTORE_FIND_TEST_06_ENTRY_NOMATCH_04, - CFSTORE_FIND_TEST_06_ENTRY_MATCH_05, - CFSTORE_FIND_TEST_06_ENTRY_NOMATCH_06, - CFSTORE_FIND_TEST_06_ENTRY_MATCH_07, - CFSTORE_FIND_TEST_06_ENTRY_NOMATCH_08, - CFSTORE_FIND_TEST_06_ENTRY_MATCH_09, - CFSTORE_FIND_TEST_06_ENTRY_NOMATCH_10, - CFSTORE_FIND_TEST_06_ENTRY_NOMATCH_11, - { NULL, NULL}, -}; - -static cfstore_kv_data_t cfstore_find_test_06_data_match_results[] = { - CFSTORE_FIND_TEST_06_ENTRY_MATCH_03, - CFSTORE_FIND_TEST_06_ENTRY_MATCH_05, - CFSTORE_FIND_TEST_06_ENTRY_MATCH_07, - CFSTORE_FIND_TEST_06_ENTRY_MATCH_09, - { NULL, NULL}, -}; -/// @endcond - - -/** - * @brief test to use find to find at least 2 entries in the cfstore, - * but the query string doesnt match the last 2 entries in the - * store. - * - * @return on success returns CaseNext to continue to next test case, otherwise will assert on errors. - */ -control_t cfstore_find_test_06_end(const size_t call_count) -{ - const char* key_name_query = "0123456789abcdef0123456.y*"; - char key_name[CFSTORE_KEY_NAME_MAX_LENGTH+1]; - uint8_t len = CFSTORE_KEY_NAME_MAX_LENGTH+1; - int32_t ret = ARM_DRIVER_ERROR; - int32_t find_count = 0; - ARM_CFSTORE_DRIVER* drv = &cfstore_driver; - ARM_CFSTORE_HANDLE_INIT(next); - ARM_CFSTORE_HANDLE_INIT(prev); - cfstore_kv_data_t* node = NULL; - - ret = cfstore_test_create_table(cfstore_find_test_06_data); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_find_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Failed to add cfstore_find_test_06_data table data (ret=%d).\n", __func__, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_find_utest_msg_g); - - while((ret = drv->Find(key_name_query, prev, next)) == ARM_DRIVER_OK) - { - len = CFSTORE_KEY_NAME_MAX_LENGTH+1; - ret = drv->GetKeyName(next, key_name, &len); - if(ret < ARM_DRIVER_OK){ - CFSTORE_ERRLOG("Error: failed to get key name%s", "\n"); - break; - } - CFSTORE_LOG("%s:Found entry key_name=%s\n", __func__, key_name); - node = cfstore_find_test_06_data_match_results; - while(node->key_name != NULL){ - if(strncmp(node->key_name, key_name, CFSTORE_KEY_NAME_MAX_LENGTH) == 0){ - find_count++; - break; - } - node++; - } - CFSTORE_TEST_UTEST_MESSAGE(cfstore_find_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: unable to find match in match table for %s.\n", __func__, key_name); - TEST_ASSERT_MESSAGE(node->key_name != NULL, cfstore_find_utest_msg_g); - - CFSTORE_HANDLE_SWAP(prev, next); - } - - CFSTORE_TEST_UTEST_MESSAGE(cfstore_find_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: find_count=%d doesnt match the number of entries in match table = %d.\n", __func__, (int) find_count, (int) (sizeof(cfstore_find_test_06_data_match_results)/sizeof(cfstore_kv_data_t))-1); - TEST_ASSERT_MESSAGE(find_count == (sizeof(cfstore_find_test_06_data_match_results)/sizeof(cfstore_kv_data_t))-1, cfstore_find_utest_msg_g); - - CFSTORE_TEST_UTEST_MESSAGE(cfstore_find_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: expected ret == ARM_CFSTORE_DRIVER_ERROR_KEY_NOT_FOUND, but ret = %d.\n", __func__, (int) ret); - TEST_ASSERT_MESSAGE(ret == ARM_CFSTORE_DRIVER_ERROR_KEY_NOT_FOUND, cfstore_find_utest_msg_g); - - ret = drv->Uninitialize(); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_find_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Uninitialize() call failed.\n", __func__); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_find_utest_msg_g); - return CaseNext; -} - -/** - * @brief test case to check Find() with previous NULL pointer works - * - * @return on success returns CaseNext to continue to next test case, otherwise will assert on errors. - */ -control_t cfstore_find_test_07_end(const size_t call_count) -{ - const char* key_name_query = "0123456789abcdef0123456.y*"; - char key_name[CFSTORE_KEY_NAME_MAX_LENGTH+1]; - uint8_t len = CFSTORE_KEY_NAME_MAX_LENGTH+1; - int32_t ret = ARM_DRIVER_ERROR; - int32_t find_count = 0; - ARM_CFSTORE_DRIVER* drv = &cfstore_driver; - ARM_CFSTORE_HANDLE_INIT(next); - cfstore_kv_data_t* node = NULL; - - ret = cfstore_test_create_table(cfstore_find_test_06_data); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_find_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Failed to add cfstore_find_test_06_data table data (ret=%d).\n", __func__, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_find_utest_msg_g); - - while(true) - { - - ret = drv->Find(key_name_query, NULL, next); - if(ret == ARM_CFSTORE_DRIVER_ERROR_KEY_NOT_FOUND) { - /* no more attributes found matching search criteria.*/ - break; - } - - CFSTORE_TEST_UTEST_MESSAGE(cfstore_find_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Find() failed(ret=%d).\n", __func__, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_find_utest_msg_g); - - len = CFSTORE_KEY_NAME_MAX_LENGTH+1; - ret = drv->GetKeyName(next, key_name, &len); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_find_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to get key name for next (ret=%d).\n", __func__, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_find_utest_msg_g); - - CFSTORE_LOG("%s:Found entry key_name=%s\n", __func__, key_name); - node = cfstore_find_test_06_data_match_results; - while(node->key_name != NULL){ - if(strncmp(node->key_name, key_name, CFSTORE_KEY_NAME_MAX_LENGTH) == 0){ - find_count++; - break; - } - node++; - } - CFSTORE_TEST_UTEST_MESSAGE(cfstore_find_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: unable to find match in match table for %s.\n", __func__, key_name); - TEST_ASSERT_MESSAGE(node->key_name != NULL, cfstore_find_utest_msg_g); - - /* delete the KV so it wont be found when queried is repeated*/ - ret = drv->Delete(next); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_find_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Delete() on next handled failed(ret=%d).\n", __func__, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_find_utest_msg_g); - - ret = drv->Close(next); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_find_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Close() on next handled failed(ret=%d).\n", __func__, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_find_utest_msg_g); - } - - CFSTORE_TEST_UTEST_MESSAGE(cfstore_find_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: find_count=%d doesnt match the number of entries in match table = %d.\n", __func__, (int) find_count, (int) (sizeof(cfstore_find_test_06_data_match_results)/sizeof(cfstore_kv_data_t))-1); - TEST_ASSERT_MESSAGE(find_count == (sizeof(cfstore_find_test_06_data_match_results)/sizeof(cfstore_kv_data_t))-1, cfstore_find_utest_msg_g); - - CFSTORE_TEST_UTEST_MESSAGE(cfstore_find_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: expected ret == ret == ARM_CFSTORE_DRIVER_ERROR_KEY_NOT_FOUND, but ret = %d.\n", __func__, (int) ret); - TEST_ASSERT_MESSAGE(ret == ARM_CFSTORE_DRIVER_ERROR_KEY_NOT_FOUND, cfstore_find_utest_msg_g); - - ret = drv->Uninitialize(); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_find_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Uninitialize() call failed.\n", __func__); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_find_utest_msg_g); - return CaseNext; -} - - -/// @cond CFSTORE_DOXYGEN_DISABLE -utest::v1::status_t greentea_setup(const size_t number_of_cases) -{ - GREENTEA_SETUP(400, "default_auto"); - return greentea_test_setup_handler(number_of_cases); -} - -Case cases[] = { - /* 1 2 3 4 5 6 7 */ - /* 1234567890123456789012345678901234567890123456789012345678901234567890 */ - Case("FIND_test_00", cfstore_find_test_00), - Case("FIND_test_01", cfstore_find_test_01), - Case("FIND_test_02", cfstore_find_test_02), - Case("FIND_test_03_start", cfstore_utest_default_start), - Case("FIND_test_03_end", cfstore_find_test_03_end), - Case("FIND_test_04", cfstore_find_test_04), - Case("FIND_test_05_start", cfstore_utest_default_start), - Case("FIND_test_05_end", cfstore_find_test_05_end), - Case("FIND_test_06_start", cfstore_utest_default_start), - Case("FIND_test_06_end", cfstore_find_test_06_end), - Case("FIND_test_07_start", cfstore_utest_default_start), - Case("FIND_test_07_end", cfstore_find_test_07_end), -}; - - -/* Declare your test specification with a custom setup handler */ -Specification specification(greentea_setup, cases); - -int main() -{ - return !Harness::run(specification); -} -/// @endcond - diff --git a/features/storage/FEATURE_STORAGE/TESTS/cfstore/find2/find2.cpp b/features/storage/FEATURE_STORAGE/TESTS/cfstore/find2/find2.cpp deleted file mode 100644 index 3448cb8..0000000 --- a/features/storage/FEATURE_STORAGE/TESTS/cfstore/find2/find2.cpp +++ /dev/null @@ -1,237 +0,0 @@ -/* - * mbed Microcontroller Library - * Copyright (c) 2006-2016 ARM Limited - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -/** @file find2.cpp Test cases to find KVs in the CFSTORE using the drv->Find() interface. - * - * Please consult the documentation under the test-case functions for - * a description of the individual test case. - */ - -#include "mbed.h" -#include "cfstore_config.h" -#include "cfstore_test.h" -#include "cfstore_debug.h" -#include "Driver_Common.h" -#include "configuration_store.h" -#include "utest/utest.h" -#include "unity/unity.h" -#include "greentea-client/test_env.h" - -#include -#include -#include -#include -#include - -using namespace utest::v1; - -static char cfstore_find2_utest_msg_g[CFSTORE_UTEST_MSG_BUF_SIZE]; - - -/// @cond CFSTORE_DOXYGEN_DISABLE -#ifdef CFSTORE_DEBUG -#define CFSTORE_FIND2_GREENTEA_TIMEOUT_S 360 -#else -#define CFSTORE_FIND2_GREENTEA_TIMEOUT_S 60 -#endif -#define CFSTORE_FIND2_TEST_02_VALUE_SIZE 191 - -extern ARM_CFSTORE_DRIVER cfstore_driver; - -void cfstore_find2_callback(int32_t status, ARM_CFSTORE_OPCODE cmd_code, void *client_context, ARM_CFSTORE_HANDLE handle) -{ - (void) status; - (void) cmd_code; - (void) client_context; - (void) handle; - return; -} -/// @endcond - -/* report whether built/configured for flash sync or async mode */ -static control_t cfstore_find2_test_00(const size_t call_count) -{ - int32_t ret = ARM_DRIVER_ERROR; - - (void) call_count; - ret = cfstore_test_startup(); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_find2_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to perform test startup (ret=%d).\n", __func__, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_find2_utest_msg_g); - return CaseNext; -} - - -static control_t cfstore_find2_test_01(const size_t call_count) -{ - char keyBuffer[128] = "com.arm.mbed.manifest-manager.root.AQAAAAAAAAA-.manifest"; - int32_t rc; - ARM_CFSTORE_HANDLE_INIT(hkey); - ARM_CFSTORE_HANDLE_INIT(prev); - - // Initialize the config store - (void) call_count; - cfstore_driver.Initialize(cfstore_find2_callback, NULL); - cfstore_driver.PowerControl(ARM_POWER_FULL); - - // Find the target key - rc = cfstore_driver.Find(keyBuffer, prev, hkey); - - // If the target key was not found - if (rc == ARM_CFSTORE_DRIVER_ERROR_KEY_NOT_FOUND) { - ARM_CFSTORE_KEYDESC kdesc = { - .acl = { - .perm_owner_read = 1, - .perm_owner_write = 1, - .perm_owner_execute = 0, - .perm_other_read = 1, - .perm_other_write = 0, - .perm_other_execute = 0, - /* added initialisers */ - .reserved = 0 - }, .drl = ARM_RETENTION_WHILE_DEVICE_ACTIVE, - .security = { - .acls = 1, - .rollback_protection = 0, - .tamper_proof = 0, - .internal_flash = 0, - /* added initialisers */ - .reserved1 = 0, - .software_attacks = 0, - .board_level_attacks = 0, - .chip_level_attacks = 0, - .side_channel_attacks = 0, - .reserved2 = 0 - }, - .flags = { - .continuous = 0, - .lazy_flush = 1, - .flush_on_close = 1, - .read = 0, - .write = 1, - .execute = 0, - .storage_detect = 1, - /* added initialisers */ - .reserved = 0 - } - }; - - // Create the target key - rc = cfstore_driver.Create(keyBuffer, 191, &kdesc, hkey); - } - return CaseNext; -} - - -/* fixed version of brendans code */ -static control_t cfstore_find2_test_02(const size_t call_count) -{ - char keyBuffer[128] = "com.arm.mbed.manifest-manager.root.AQAAAAAAAAA-.manifest"; - - int32_t rc; - ARM_CFSTORE_HANDLE_INIT(hkey); - ARM_CFSTORE_HANDLE_INIT(prev); - ARM_CFSTORE_SIZE length; - char value[CFSTORE_FIND2_TEST_02_VALUE_SIZE]; - - // Initialize the config store - (void) call_count; - cfstore_driver.Initialize(NULL, NULL); /* non-null client_callback not supported for MBED_V_0_1_x */ - cfstore_driver.PowerControl(ARM_POWER_FULL); - memset(value, 0, 191); - - // Find the target key - rc = cfstore_driver.Find(keyBuffer, prev, hkey); - - // If the target key was not found - if (rc == ARM_CFSTORE_DRIVER_ERROR_KEY_NOT_FOUND) { - ARM_CFSTORE_KEYDESC kdesc = { - .acl = { - .perm_owner_read = 1, - .perm_owner_write = 1, - .perm_owner_execute = 0, - .perm_other_read = 1, - .perm_other_write = 0, - .perm_other_execute = 0, - .reserved = 0 - }, .drl = ARM_RETENTION_WHILE_DEVICE_ACTIVE, /* DATA_RETENTION_NVM not supported for MBED_V_0_1_x */ - .security = { - .acls = 0, /* protection against internal software attacks using ACLs not supported for MBED_V_0_1_x */ - .rollback_protection = 0, - .tamper_proof = 0, - .internal_flash = 0, - .reserved1 = 0, - .software_attacks = 0, - .board_level_attacks = 0, - .chip_level_attacks = 0, - .side_channel_attacks = 0, - .reserved2 = 0 - }, - .flags = { - .continuous = 0, - .lazy_flush = 0, /* lazy flush not supported for MBED_V_0_1_x */ - .flush_on_close = 0, /* flush on close not supported for MBED_V_0_1_x */ - .read = 0, - .write = 1, - .execute = 0, - .storage_detect = 0, /* storage detect supported for MBED_V_0_1_x */ - /* added initialisers */ - .reserved = 0 - - } - }; - - // Create the target key - rc = cfstore_driver.Create(keyBuffer, 191, &kdesc, hkey); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_find2_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%sError: failed to create key\n", __func__); - TEST_ASSERT_MESSAGE(rc >= ARM_DRIVER_OK, cfstore_find2_utest_msg_g); - - strncpy(value, "MyValueData", CFSTORE_FIND2_TEST_02_VALUE_SIZE); - length = strlen(value); - rc = cfstore_driver.Write(hkey, value, &length); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_find2_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%sError: failed to write key\n", __func__); - TEST_ASSERT_MESSAGE(rc >= ARM_DRIVER_OK, cfstore_find2_utest_msg_g); - /* revert to CFSTORE_LOG if more trace required */ - CFSTORE_DBGLOG("Success!%s", "\n"); - } - return CaseNext; -} - -/// @cond CFSTORE_DOXYGEN_DISABLE -utest::v1::status_t greentea_setup(const size_t number_of_cases) -{ - GREENTEA_SETUP(CFSTORE_FIND2_GREENTEA_TIMEOUT_S, "default_auto"); - return greentea_test_setup_handler(number_of_cases); -} - -Case cases[] = { - /* 1 2 3 4 5 6 7 */ - /* 1234567890123456789012345678901234567890123456789012345678901234567890 */ - Case("FIND2_test_00", cfstore_find2_test_00), - Case("FIND2_test_01", cfstore_find2_test_01), - Case("FIND2_test_02", cfstore_find2_test_02), -}; - - -/* Declare your test specification with a custom setup handler */ -Specification specification(greentea_setup, cases); - -int main() -{ - return !Harness::run(specification); -} -/// @endcond diff --git a/features/storage/FEATURE_STORAGE/TESTS/cfstore/flash/flash.cpp b/features/storage/FEATURE_STORAGE/TESTS/cfstore/flash/flash.cpp deleted file mode 100644 index edaf0ae..0000000 --- a/features/storage/FEATURE_STORAGE/TESTS/cfstore/flash/flash.cpp +++ /dev/null @@ -1,688 +0,0 @@ -/* - * mbed Microcontroller Library - * Copyright (c) 2006-2016 ARM Limited - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** @file flash.cpp Test cases to flush KVs in the CFSTORE using the Flash-Journal interface. - * - * Please consult the documentation under the test-case functions for - * a description of the individual test case. - */ - -#include "cfstore_config.h" -#include "cfstore_test.h" -#include "cfstore_debug.h" -#include "Driver_Common.h" -#include "configuration_store.h" -#include "utest/utest.h" -#include "unity/unity.h" -#include "greentea-client/test_env.h" - -#ifdef CFSTORE_CONFIG_BACKEND_FLASH_ENABLED -#include "flash_journal_strategy_sequential.h" -#include "flash_journal.h" -#include "Driver_Common.h" -#endif /* CFSTORE_CONFIG_BACKEND_FLASH_ENABLED */ - - -#include -#include -#include -#include - -using namespace utest::v1; - - - - -/* shared code common to both sync and async test cases */ - -/* - * Defines - * - */ -/// @cond CFSTORE_DOXYGEN_DISABLE -#define CFSTORE_FREE free -#define CFSTORE_MALLOC malloc -#define CFSTORE_REALLOC realloc -#define CFSTORE_FLASH_STACK_BUF_SIZE 64 -#define CFSTORE_FLASH_K64F_CURRENT_PROGRAM_UNIT_SIZE 8 -#define CFSTORE_TEST_DATA_KEYNAME "com.arm.mbed.configurationstore.test.flush.cfstoreflushtest02" -#define CFSTORE_TEST_DATA_KEYNAME_SHORT "com.arm" -#define CFSTORE_TEST_DATA_VALUE_INIT "\1" -#define CFSTORE_TEST_DATA_KEYNAME_SIZE (sizeof(CFSTORE_TEST_DATA_KEYNAME) - 1) -#define CFSTORE_TEST_DATA_VALUE_SIZE (sizeof(CFSTORE_TEST_DATA_VALUE_INIT) - 1) -#define CFSTORE_FLASH_UTEST_MSG_BUF_SIZE 256 -#define CFSTORE_FLASH_MTD_ASYNC_OPS_ON 1 -#define CFSTORE_FLASH_MTD_ASYNC_OPS_OFF 0 -#define CFSTORE_FLASH_CASE_TIMEOUT_MS 5000 -/// @endcond - -/* - * Globals - */ - -/// @cond CFSTORE_DOXYGEN_DISABLE -char cfstore_flash_utest_msg_g[CFSTORE_FLASH_UTEST_MSG_BUF_SIZE]; -/// @endcond - -#ifdef CFSTORE_CONFIG_BACKEND_FLASH_ENABLED -uint16_t cfstore_flash_mtd_async_ops_g = 0; -extern ARM_DRIVER_STORAGE ARM_Driver_Storage_MTD_K64F; - - -/* KV data for test_01 */ -static cfstore_kv_data_t cfstore_flush_test_01_kv_data[] = { - { CFSTORE_TEST_DATA_KEYNAME, CFSTORE_TEST_DATA_VALUE_INIT}, - { NULL, NULL}, -}; - - -/* @brief key value header structure defining key_name length, value length - * @note - * 8 bytes long */ -typedef struct cfstore_area_header_t -{ - uint32_t vlength; - uint8_t klength; - uint8_t perm_owner_read : 1; - uint8_t perm_owner_write : 1; - uint8_t perm_owner_execute : 1; - uint8_t perm_other_read : 1; - uint8_t perm_other_write : 1; - uint8_t perm_other_execute : 1; - uint8_t reserved : 2; - uint8_t refcount; - struct flags_t { - uint8_t deleting : 1; - uint8_t reserved : 7; - } flags ; -} cfstore_area_header_t; - - -/* @brief data structure for managing test data */ -typedef struct cfstore_flash_data_blob_t { - cfstore_area_header_t hdr; - uint8_t data[CFSTORE_TEST_DATA_KEYNAME_SIZE + CFSTORE_TEST_DATA_VALUE_SIZE]; /* 61 bytes for key_name, 1 byte for value */ -} cfstore_flash_data_blob_t; - -/* - * Defines - * - * CFSTORE_FLASH_AREA_SIZE_MIN - * valid sizes of areas should always be greater than the size of the header, and therefore - * greater than this value, which is defined as smaller than the header size - */ -#define CFSTORE_FLASH_AREA_SIZE_MIN (sizeof(cfstore_area_header_t) - 1) - -/* - * Shared implementation between sync and async tests - */ - -/* print key name string from area where key_name is not null terminated*/ -static void cfstore_dump_key_name(uint8_t* keyname, uint8_t len, const char* tag) -{ - char blob_data[CFSTORE_KEY_NAME_MAX_LENGTH]; - - (void) tag; - assert(keyname != NULL); - assert(tag != NULL); - assert(len > 0); - memcpy(blob_data, keyname, len); - blob_data[len] = '\0'; - CFSTORE_DBGLOG("%s:keyname=%s\r\n", tag, blob_data); -} - -/* @brief test fsm states and events */ -typedef enum cfstore_flash_fsm_state_t { - cfstore_flash_fsm_state_initializing = 0, - cfstore_flash_fsm_state_reading, - cfstore_flash_fsm_state_writing, - cfstore_flash_fsm_state_committing, - cfstore_flash_fsm_state_max -} cfstore_flash_fsm_state_t; - -/* @brief test fsm events */ -typedef enum cfstore_flash_fsm_event_t { - cfstore_flash_fsm_event_init_done = 0, - cfstore_flash_fsm_event_read_done, - cfstore_flash_fsm_event_write_done, - cfstore_flash_fsm_event_commit_done, - cfstore_flash_fsm_event_max, -} cfstore_flash_fsm_event_t; - -typedef void (*cfstore_flash_fsm_handler)(void* ctx); - -typedef struct cfstore_fsm_t -{ - cfstore_flash_fsm_state_t state; - cfstore_flash_fsm_event_t event; -} cfstore_fsm_t; - -typedef struct cfstore_flash_ctx_t -{ - uint8_t* area_0_head; - uint8_t* area_0_tail; - FlashJournal_t jrnl; - uint64_t expected_blob_size; - cfstore_fsm_t fsm; - int32_t status; - FlashJournal_OpCode_t cmd_code; - uint64_t expected_read_size; -} cfstore_flash_ctx_t; - -/* - * Globals - */ -static cfstore_flash_ctx_t cfstore_flash_ctx_g; -static const char* cfstore_flash_opcode_str[] = -{ - "FLASH_JOURNAL_OPCODE_INITIALIZE", - "FLASH_JOURNAL_OPCODE_GET_INFO", - "FLASH_JOURNAL_OPCODE_READ_BLOB", - "FLASH_JOURNAL_OPCODE_LOG_BLOB", - "FLASH_JOURNAL_OPCODE_COMMIT", - "FLASH_JOURNAL_OPCODE_RESET", -}; - -#ifdef CFSTORE_DEBUG -static const char* cfstore_flash_state_str[] = -{ - "initializing", - "reading", - "writing", - "committing", - "unknown" -}; - -static const char* cfstore_flash_event_str[] = -{ - "init_done", - "read_done", - "write_done", - "commit_done", - "unknown" -}; -#endif /* CFSTORE_DEBUG */ - -/* - * Forward decl - */ -static void cfstore_fsm_state_handle_event(cfstore_fsm_t* fsm, cfstore_flash_fsm_event_t event, void* context); -static void cfstore_fsm_state_set(cfstore_fsm_t* fsm, cfstore_flash_fsm_state_t new_state, void* ctx); - -/* - * context related methods - */ - -/* @brief get a pointer to the global context data structure */ -static cfstore_flash_ctx_t* cfstore_flash_ctx_get(void) -{ - return &cfstore_flash_ctx_g; -} - - -/* @brief flash journal asynchronous callback handler */ -void cfstore_flash_test_01_callback(int32_t status, FlashJournal_OpCode_t cmd_code) -{ - cfstore_flash_ctx_t* ctx = cfstore_flash_ctx_get(); - - CFSTORE_FENTRYLOG("%s:entered: status=%d, cmd_code=%d (%s)\r\n", __func__, (int) status, (int) cmd_code, cfstore_flash_opcode_str[cmd_code]); - switch(cmd_code) - { - case FLASH_JOURNAL_OPCODE_INITIALIZE: - ctx->fsm.event = cfstore_flash_fsm_event_init_done; - break; - case FLASH_JOURNAL_OPCODE_READ_BLOB: - ctx->fsm.event = cfstore_flash_fsm_event_read_done; - break; - case FLASH_JOURNAL_OPCODE_LOG_BLOB: - ctx->fsm.event = cfstore_flash_fsm_event_write_done; - break; - case FLASH_JOURNAL_OPCODE_COMMIT: - ctx->fsm.event = cfstore_flash_fsm_event_commit_done; - break; - case FLASH_JOURNAL_OPCODE_GET_INFO: - case FLASH_JOURNAL_OPCODE_RESET: - default: - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flash_utest_msg_g, CFSTORE_FLASH_UTEST_MSG_BUF_SIZE, "%s:Error: received asynchronous notification for opcode=%d (%s) when api call should have been synchronous", __func__, cmd_code, cmd_code <= FLASH_JOURNAL_OPCODE_RESET ? cfstore_flash_opcode_str[cmd_code] : "unknown"); - TEST_ASSERT_MESSAGE(false, cfstore_flash_utest_msg_g) - return; - } - ctx->status = status; - ctx->cmd_code = cmd_code; - cfstore_fsm_state_handle_event(&ctx->fsm, ctx->fsm.event, (void*) ctx); - return; -} - - -/* @brief fsm handler called on entry to initializing state */ -static void cfstore_flash_fsm_init_on_entry(void* context) -{ - /* round up cfstore_flash_data_blob_t to nearest k64f program unit size */ - const ARM_DRIVER_STORAGE *drv = &ARM_Driver_Storage_MTD_K64F; - FlashJournal_Info_t info; - FlashJournal_Status_t status = JOURNAL_STATUS_ERROR; - cfstore_flash_ctx_t* ctx = (cfstore_flash_ctx_t*) context; - - /* check that the mtd is in synchronous mode */ - CFSTORE_FENTRYLOG("%s:entered: \r\n", __func__); - memset(&info, 0, sizeof(info)); - - /* FlashJournal_initialize() is potentially asynchronous */ - status = (FlashJournal_Status_t) FlashJournal_initialize(&ctx->jrnl, drv, &FLASH_JOURNAL_STRATEGY_SEQUENTIAL, cfstore_flash_test_01_callback); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flash_utest_msg_g, CFSTORE_FLASH_UTEST_MSG_BUF_SIZE, "%s:Error: failed to initialize flash journaling layer (status=%d)\r\n", __func__, status); - TEST_ASSERT_MESSAGE(status >= JOURNAL_STATUS_OK, cfstore_flash_utest_msg_g); - /* if status > 0, expect async callback, otherwise initialisation has been completed */ - if(status > 0) { - cfstore_flash_test_01_callback(status, FLASH_JOURNAL_OPCODE_INITIALIZE); - } - return; -} - -/* brief callback handler when in state initializing */ -static void cfstore_flash_fsm_initializing(void* context) -{ - cfstore_flash_ctx_t* ctx = (cfstore_flash_ctx_t*) context; - - CFSTORE_FENTRYLOG("%s:entered\r\n", __func__); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flash_utest_msg_g, CFSTORE_FLASH_UTEST_MSG_BUF_SIZE, "%s:Error: entered handler(%s) but not in initializing state (fsm->state=%d)\r\n", __func__, __func__, (int) ctx->fsm.state); - TEST_ASSERT_MESSAGE(ctx->fsm.state == cfstore_flash_fsm_state_initializing, cfstore_flash_utest_msg_g); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flash_utest_msg_g, CFSTORE_FLASH_UTEST_MSG_BUF_SIZE, "%s:Error: cmd_code code (%d) is not as expected (%d)\r\n", __func__, ctx->cmd_code, FLASH_JOURNAL_OPCODE_INITIALIZE); - TEST_ASSERT_MESSAGE(ctx->cmd_code == FLASH_JOURNAL_OPCODE_INITIALIZE, cfstore_flash_utest_msg_g); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flash_utest_msg_g, CFSTORE_FLASH_UTEST_MSG_BUF_SIZE, "%s:Error: status=%d\r\n", __func__, (int) ctx->status); - TEST_ASSERT_MESSAGE(ctx->status >= JOURNAL_STATUS_OK, cfstore_flash_utest_msg_g); - /* only change state if status > 0*/ - if(ctx->status > 0){ - cfstore_fsm_state_set(&ctx->fsm, cfstore_flash_fsm_state_reading, ctx); - } -} - -/* static void cfstore_flash_fsm_init_on_exit(void* context){ (void) context;} */ - -/* brief callback handler called when entering the reading state - * note - * flash journal has initialised successfully. now - */ -static void cfstore_flash_fsm_read_on_entry(void* context) -{ - uint8_t* ptr = NULL; - int32_t ret = 0; - FlashJournal_Info_t info; - FlashJournal_Status_t status = JOURNAL_STATUS_ERROR; - cfstore_flash_ctx_t* ctx = (cfstore_flash_ctx_t*) context; - - CFSTORE_FENTRYLOG("%s:entered\r\n", __func__); - CFSTORE_ASSERT(ctx != NULL); - /* drv->GetInfo() is synchronous */ - status = FlashJournal_getInfo(&ctx->jrnl, &info); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flash_utest_msg_g, CFSTORE_FLASH_UTEST_MSG_BUF_SIZE, "%s:Error: failed get journal info (status=%d)\r\n", __func__, (int) status); - TEST_ASSERT_MESSAGE(status == JOURNAL_STATUS_OK, cfstore_flash_utest_msg_g); - CFSTORE_DBGLOG("%s:FlashJournal_getInfo() done. info.sizeofJournaledBlob=%lu\r\n", __func__, (long unsigned int) info.sizeofJournaledBlob); - - if(info.sizeofJournaledBlob > 0) - { - /* setup the expected blob size for writing - * This is a multiple of program unit so the write doesnt fail due to unaligned log */ - ctx->expected_blob_size = sizeof(cfstore_flash_data_blob_t); - if(ctx->expected_blob_size % CFSTORE_FLASH_K64F_CURRENT_PROGRAM_UNIT_SIZE > 0){ - ctx->expected_blob_size += (CFSTORE_FLASH_K64F_CURRENT_PROGRAM_UNIT_SIZE - (sizeof(cfstore_flash_data_blob_t) % CFSTORE_FLASH_K64F_CURRENT_PROGRAM_UNIT_SIZE)); - } - /* test that a blob size is the expected size for flash data that has been written before */ - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flash_utest_msg_g, CFSTORE_FLASH_UTEST_MSG_BUF_SIZE, "%s:Error: info.sizeofJournaledBlob does not match expect size. expected_blob_size (%lu) != info.sizeofJournaledBlob (%lu)\r\n", __func__, (unsigned long int) ctx->expected_blob_size, (unsigned long int) info.sizeofJournaledBlob); - TEST_ASSERT_EQUAL_INT64_MESSAGE(ctx->expected_blob_size, info.sizeofJournaledBlob, cfstore_flash_utest_msg_g); - - /* grow the area by the size of the stored blob */ - ptr = (uint8_t*) CFSTORE_REALLOC((void*) ctx->area_0_head, ctx->expected_blob_size); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flash_utest_msg_g, CFSTORE_FLASH_UTEST_MSG_BUF_SIZE, "%s:realloc failed flash blob (size=%d)\r\n", __func__, (int)info.sizeofJournaledBlob); - TEST_ASSERT_MESSAGE(ptr != NULL, cfstore_flash_utest_msg_g); - memset(ptr, 0, ctx->expected_blob_size); - if(ptr != ctx->area_0_head){ - CFSTORE_DBGLOG("%s:cfstore_ctx_g.area_0_head pointer changed (cfstore_ctx_g.area_0_head=%p, ptr=%p)\r\n", __func__, ctx->area_0_head, ptr); - ctx->area_0_head = ptr; - ctx->area_0_tail = ctx->area_0_head + info.sizeofJournaledBlob; - } - ret = FlashJournal_read(&ctx->jrnl, (void*) ctx->area_0_head, info.sizeofJournaledBlob); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flash_utest_msg_g, CFSTORE_FLASH_UTEST_MSG_BUF_SIZE, "%s:Error: unable to read flash journal (ret=%d. info.sizeofJournaledBlob=%d)\r\n", __func__, (int) ret, (int) info.sizeofJournaledBlob); - TEST_ASSERT_MESSAGE(ret >= JOURNAL_STATUS_OK, cfstore_flash_utest_msg_g); - if(ret > 0){ - /* read has completed synchronously*/ - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flash_utest_msg_g, CFSTORE_FLASH_UTEST_MSG_BUF_SIZE, "%s:Error: unable to read all data from flash journal (expected size=%lu, read=%d)\r\n", __func__, (unsigned long int)info.sizeofJournaledBlob, (int) ret); - TEST_ASSERT_EQUAL_INT32_MESSAGE( (int32_t) info.sizeofJournaledBlob, ret, cfstore_flash_utest_msg_g); - cfstore_flash_test_01_callback(ret, FLASH_JOURNAL_OPCODE_READ_BLOB); - } - } else { - /* there is no blob, move to next state. need a +ve status value to indicate async completion - * to the fsm reading state handler. use CFSTORE_FLASH_AREA_SIZE_MIN for this value */ - ctx->expected_blob_size = CFSTORE_FLASH_AREA_SIZE_MIN; - status = (FlashJournal_Status_t) CFSTORE_FLASH_AREA_SIZE_MIN; - cfstore_flash_test_01_callback(status, FLASH_JOURNAL_OPCODE_READ_BLOB); - } - return; -} - -/* @brief fsm handler when in reading state */ -void cfstore_flash_fsm_reading(void* context) -{ - int32_t ret = 0; - cfstore_flash_ctx_t* ctx = (cfstore_flash_ctx_t*) context; - cfstore_flash_data_blob_t *blob = NULL; - - CFSTORE_FENTRYLOG("%s:entered\r\n", __func__); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flash_utest_msg_g, CFSTORE_FLASH_UTEST_MSG_BUF_SIZE, "%s:Error: entered handler(%s) but not in reading state (fsm->state=%d)\r\n", __func__, __func__, (int) ctx->fsm.state); - TEST_ASSERT_MESSAGE(ctx->fsm.state == cfstore_flash_fsm_state_reading, cfstore_flash_utest_msg_g); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flash_utest_msg_g, CFSTORE_FLASH_UTEST_MSG_BUF_SIZE, "%s:Error: cmd_code code (%d) is not as expected (%d)\r\n", __func__, ctx->cmd_code, FLASH_JOURNAL_OPCODE_READ_BLOB); - TEST_ASSERT_MESSAGE(ctx->cmd_code == FLASH_JOURNAL_OPCODE_READ_BLOB, cfstore_flash_utest_msg_g); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flash_utest_msg_g, CFSTORE_FLASH_UTEST_MSG_BUF_SIZE, "%s:Error: status=%d\r\n", __func__, (int) ctx->status); - TEST_ASSERT_MESSAGE(ctx->status >= JOURNAL_STATUS_OK, cfstore_flash_utest_msg_g); - - if(ctx->status > 0) - { - if(ctx->status > (int32_t) CFSTORE_FLASH_AREA_SIZE_MIN) - { - /* check the correct amount of data was read, which is the status code */ - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flash_utest_msg_g, CFSTORE_FLASH_UTEST_MSG_BUF_SIZE, "%s:Error: unable to read all data from flash journal (expected size=%lu, read=%d)\r\n", __func__, (unsigned long int) ctx->expected_blob_size, (int) ctx->status); - /* ctx->status contains the status of the read that was completed */ - TEST_ASSERT_EQUAL_INT64_MESSAGE(ctx->expected_blob_size, (int32_t) ctx->status, cfstore_flash_utest_msg_g); - if(ctx->area_0_head != NULL) - { - /* check the key_name read from flash is correct */ - blob = (cfstore_flash_data_blob_t*) ctx->area_0_head; - cfstore_dump_key_name(blob->data, CFSTORE_TEST_DATA_KEYNAME_SIZE, __func__); - ret = memcmp(blob->data, cfstore_flush_test_01_kv_data[0].key_name, strlen(cfstore_flush_test_01_kv_data[0].key_name)); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flash_utest_msg_g, CFSTORE_FLASH_UTEST_MSG_BUF_SIZE, "%s:Error: incorrect key_name read from flash (expected 0 from memcpy(keyname, flash_data), actual was non-zero)", __func__); - TEST_ASSERT_EQUAL_INT_MESSAGE(0, ret, cfstore_flash_utest_msg_g); - } - } - cfstore_fsm_state_set(&ctx->fsm, cfstore_flash_fsm_state_writing, ctx); - } -} - -/* void cfstore_flash_fsm_read_on_exit(void* context){ (void) context;} */ - -/* @brief on entry to writing state, update value */ -void cfstore_flash_fsm_write_on_entry(void* context) -{ - uint8_t value = 0; - int32_t ret = 0; - cfstore_flash_ctx_t* ctx = (cfstore_flash_ctx_t*) context; - cfstore_flash_data_blob_t *blob = NULL; - - CFSTORE_FENTRYLOG("%s:entered:\r\n", __func__); - /* allocate memory for data if not already done so */ - if(ctx->area_0_head == NULL) - { - /* This is a multiple of program unit so the write doesnt fail due to unaligned log */ - ctx->expected_blob_size = sizeof(cfstore_flash_data_blob_t); - if(ctx->expected_blob_size % CFSTORE_FLASH_K64F_CURRENT_PROGRAM_UNIT_SIZE > 0){ - ctx->expected_blob_size += (CFSTORE_FLASH_K64F_CURRENT_PROGRAM_UNIT_SIZE - (sizeof(cfstore_flash_data_blob_t) % CFSTORE_FLASH_K64F_CURRENT_PROGRAM_UNIT_SIZE)); - } - ctx->area_0_head = (uint8_t*) CFSTORE_REALLOC((void*) ctx->area_0_head, ctx->expected_blob_size); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flash_utest_msg_g, CFSTORE_FLASH_UTEST_MSG_BUF_SIZE, "%s:Error: unable to allocate memory for context\r\n", __func__); - TEST_ASSERT_MESSAGE(ctx->area_0_head != NULL, cfstore_flash_utest_msg_g); - ctx->area_0_tail = ctx->area_0_head + ctx->expected_blob_size; - memset(ctx->area_0_head, 0, ctx->expected_blob_size); - /* setup data to write to flash */ - blob = (cfstore_flash_data_blob_t*) ctx->area_0_head; - blob->hdr.klength = strlen(cfstore_flush_test_01_kv_data->key_name); - blob->hdr.vlength= 1; - blob->hdr.perm_owner_read = true; - blob->hdr.perm_owner_write = true; - blob->hdr.refcount = 1; - memcpy((void*) blob->data, (const void*) cfstore_flush_test_01_kv_data->key_name, strlen(cfstore_flush_test_01_kv_data->key_name)); - memcpy((void*) &blob->data[CFSTORE_TEST_DATA_KEYNAME_SIZE], (const void*) cfstore_flush_test_01_kv_data->value, strlen(cfstore_flush_test_01_kv_data->value)); - } - if(ctx->area_0_head != NULL) - { - /* data has been read */ - /* check the key_name read from flash is correct */ - blob = (cfstore_flash_data_blob_t*) ctx->area_0_head; - value = (uint8_t) blob->data[CFSTORE_TEST_DATA_KEYNAME_SIZE]; - CFSTORE_DBGLOG("INFO: value read from flash = %u\r\n", value); - /* update the value */ - value++; - memcpy((void*) &blob->data[CFSTORE_TEST_DATA_KEYNAME_SIZE], (const void*) &value, sizeof(uint8_t)); - } - - ret = FlashJournal_log(&ctx->jrnl, (const void*) ctx->area_0_head, ctx->expected_blob_size); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flash_utest_msg_g, CFSTORE_FLASH_UTEST_MSG_BUF_SIZE, "%s:Error: ret = JOURNAL_STATUS_SMALL_LOG_REQUEST, bailing out.", __func__); - TEST_ASSERT_MESSAGE(ret != (int32_t) JOURNAL_STATUS_SMALL_LOG_REQUEST, cfstore_flash_utest_msg_g); - - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flash_utest_msg_g, CFSTORE_FLASH_UTEST_MSG_BUF_SIZE, "%s:Error: failed to perform log operation to flash journal (ret=%d)\r\n", __func__, (int) ret); - TEST_ASSERT_MESSAGE(ret >= 0, cfstore_flash_utest_msg_g); - if(ret > 0){ - /* write has completed synchronously*/ - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flash_utest_msg_g, CFSTORE_FLASH_UTEST_MSG_BUF_SIZE, "%s:Error: unable to write all data from flash journal (expected size=%lu, read=%d)\r\n", __func__, (unsigned long int) ctx->expected_blob_size, (int) ret); - TEST_ASSERT_EQUAL_INT32_MESSAGE(ret, (int32_t) ctx->expected_blob_size, cfstore_flash_utest_msg_g); - cfstore_flash_test_01_callback(ret, FLASH_JOURNAL_OPCODE_LOG_BLOB); - } - /* wait for async completion handler*/ -} - -/* @brief fsm handler when in reading state */ -void cfstore_flash_fsm_writing(void* context) -{ - cfstore_flash_ctx_t* ctx = (cfstore_flash_ctx_t*) context; - - CFSTORE_FENTRYLOG("%s:entered:\r\n", __func__); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flash_utest_msg_g, CFSTORE_FLASH_UTEST_MSG_BUF_SIZE, "%s:Error: entered handler(%s) but not in writing state (fsm->state=%d)\r\n", __func__, __func__, (int) ctx->fsm.state); - TEST_ASSERT_MESSAGE(ctx->fsm.state == cfstore_flash_fsm_state_writing, cfstore_flash_utest_msg_g); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flash_utest_msg_g, CFSTORE_FLASH_UTEST_MSG_BUF_SIZE, "%s:Error: cmd_code code (%d) is not as expected (%d)\r\n", __func__, ctx->cmd_code, FLASH_JOURNAL_OPCODE_LOG_BLOB); - TEST_ASSERT_MESSAGE(ctx->cmd_code == FLASH_JOURNAL_OPCODE_LOG_BLOB, cfstore_flash_utest_msg_g); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flash_utest_msg_g, CFSTORE_FLASH_UTEST_MSG_BUF_SIZE, "%s:Error: status=%d\r\n", __func__, (int) ctx->status); - TEST_ASSERT_MESSAGE(ctx->status >= JOURNAL_STATUS_OK, cfstore_flash_utest_msg_g); - - if(ctx->status > 0){ - /* check the correct amount of data was written */ - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flash_utest_msg_g, CFSTORE_FLASH_UTEST_MSG_BUF_SIZE, "%s:Error: unable to write all data from flash journal (expected size=%lu, read=%d)\r\n", __func__, (unsigned long int) ctx->expected_blob_size, (int) ctx->status); - TEST_ASSERT_EQUAL_INT64_MESSAGE(ctx->expected_blob_size, ctx->status, cfstore_flash_utest_msg_g); - cfstore_fsm_state_set(&ctx->fsm, cfstore_flash_fsm_state_committing, ctx); - } - return; -} - -/* void cfstore_flash_fsm_write_on_exit(void* ctx){(void) ctx;} */ - -/* @brief fsm handler when entering committing state */ -void cfstore_flash_fsm_commit_on_entry(void* context) -{ - int32_t ret = 0; - cfstore_flash_ctx_t* ctx = (cfstore_flash_ctx_t*) context; - - CFSTORE_FENTRYLOG("%s:entered:\r\n", __func__); - ret = FlashJournal_commit(&ctx->jrnl); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flash_utest_msg_g, CFSTORE_FLASH_UTEST_MSG_BUF_SIZE, "%s:Error: failed to perform commit operation to flash journal (ret=%d)\r\n", __func__, (int) ret); - TEST_ASSERT_MESSAGE(ret >= (int32_t) JOURNAL_STATUS_OK, cfstore_flash_utest_msg_g); - /* for flash-journal-strategy-sequential version >0.4.0, commit() return no longer reports size of commit block */ - if(ret > 0){ - Harness::validate_callback(); - } - /* wait for async completion handler*/ - return; -} - - -/* @brief fsm handler when in committing state */ -void cfstore_flash_fsm_committing(void* context) -{ - cfstore_flash_ctx_t* ctx = (cfstore_flash_ctx_t*) context; - - CFSTORE_FENTRYLOG("%s:entered\r\n", __func__); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flash_utest_msg_g, CFSTORE_FLASH_UTEST_MSG_BUF_SIZE, "%s:Error: entered handler(%s) but not in committing state (fsm->state=%d)\r\n", __func__, __func__, (int) ctx->fsm.state); - TEST_ASSERT_MESSAGE(ctx->fsm.state == cfstore_flash_fsm_state_committing, cfstore_flash_utest_msg_g); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flash_utest_msg_g, CFSTORE_FLASH_UTEST_MSG_BUF_SIZE, "%s:Error: cmd_code code (%d) is not as expected (%d)\r\n", __func__, ctx->cmd_code, FLASH_JOURNAL_OPCODE_COMMIT); - TEST_ASSERT_MESSAGE(ctx->cmd_code == FLASH_JOURNAL_OPCODE_COMMIT, cfstore_flash_utest_msg_g); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flash_utest_msg_g, CFSTORE_FLASH_UTEST_MSG_BUF_SIZE, "%s:Error: status=%d\r\n", __func__, (int) ctx->status); - TEST_ASSERT_MESSAGE(ctx->status >= JOURNAL_STATUS_OK, cfstore_flash_utest_msg_g); - - /* check the correct amount of data was written */ - /* for flash-journal-strategy-sequential version >0.4.0, commit() return no longer reports size of commit block */ - Harness::validate_callback(); -} - -/* @brief fsm handler when exiting committing state */ -void cfstore_flash_fsm_commit_on_exit(void* context) -{ - cfstore_flash_ctx_t* ctx = (cfstore_flash_ctx_t*) context; - - CFSTORE_FENTRYLOG("%s:entered\r\n", __func__); - /* test done. clean up*/ - if(ctx->area_0_head){ - CFSTORE_FREE(ctx->area_0_head); - ctx->area_0_head = NULL; - } - Harness::validate_callback(); - } - -#define cfstore_flash_fsm_null NULL - -/* handler functions while in state */ -static cfstore_flash_fsm_handler cfstore_flash_fsm[cfstore_flash_fsm_state_max][cfstore_flash_fsm_event_max] = -{ -/* state\event: init_done read_done write_done commit_done */ -/* initialising */ {cfstore_flash_fsm_initializing, cfstore_flash_fsm_null, cfstore_flash_fsm_null, cfstore_flash_fsm_null }, -/* reading */ {cfstore_flash_fsm_null, cfstore_flash_fsm_reading, cfstore_flash_fsm_null, cfstore_flash_fsm_null }, -/* writing */ {cfstore_flash_fsm_null, cfstore_flash_fsm_null, cfstore_flash_fsm_writing, cfstore_flash_fsm_null }, -/* committing */ {cfstore_flash_fsm_null, cfstore_flash_fsm_null, cfstore_flash_fsm_null, cfstore_flash_fsm_committing }, -}; - - -/* handler functions for entering the state*/ -cfstore_flash_fsm_handler cfstore_flash_fsm_on_entry[cfstore_flash_fsm_state_max] = -{ - cfstore_flash_fsm_init_on_entry, - cfstore_flash_fsm_read_on_entry, - cfstore_flash_fsm_write_on_entry, - cfstore_flash_fsm_commit_on_entry, -}; - -/* handler functions for exiting state, currently none used */ -cfstore_flash_fsm_handler cfstore_flash_fsm_on_exit[cfstore_flash_fsm_state_max] = -{ - NULL, NULL, NULL, NULL, -}; - - -/* @brief inject event into fsm */ -static void cfstore_fsm_state_handle_event(cfstore_fsm_t* fsm, cfstore_flash_fsm_event_t event, void* context) -{ - cfstore_flash_ctx_t* ctx = (cfstore_flash_ctx_t*) context; - - CFSTORE_FENTRYLOG("%s:entered: fsm=%p, event=%d (%s), ctx=%p\r\n", __func__, fsm, (int) event, cfstore_flash_event_str[event], ctx); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flash_utest_msg_g, CFSTORE_FLASH_UTEST_MSG_BUF_SIZE, "%s:Error: invalid event (%d)\r\n", __func__, (int) event); - TEST_ASSERT_MESSAGE(event < cfstore_flash_fsm_event_max, cfstore_flash_utest_msg_g); - fsm->event = event; - if(cfstore_flash_fsm[fsm->state][fsm->event] != NULL){ - cfstore_flash_fsm[fsm->state][fsm->event](ctx); - } - - /* do not clear context data set by caller as it may be used later - * fsm->event = cfstore_flash_fsm_event_max; - * ctx->status = 0; - * ctx->cmd_code = (FlashJournal_OpCode_t)((int) FLASH_JOURNAL_OPCODE_RESET+1); - */ - return; -} - - -/* @brief function to move to new fsm state, calling state exit function for old state and entry function for new state */ -static void cfstore_fsm_state_set(cfstore_fsm_t* fsm, cfstore_flash_fsm_state_t new_state, void* ctx) -{ - CFSTORE_FENTRYLOG("%s:entered: fsm=%p, new_state=%d, ctx=%p\r\n", __func__, fsm, (int) new_state, ctx); - CFSTORE_DBGLOG("%s:FSM:REQ RX:%s:%s\r\n", __func__, cfstore_flash_state_str[fsm->state], cfstore_flash_state_str[new_state]); - TEST_ASSERT_MESSAGE(fsm != NULL, "fsm is not a valid pointer"); - TEST_ASSERT_MESSAGE(new_state < cfstore_flash_fsm_state_max, "new_state is not a valid state"); - TEST_ASSERT_MESSAGE(ctx != NULL, "ctx is not a valid pointer"); - TEST_ASSERT_MESSAGE(fsm->state < cfstore_flash_fsm_state_max, "fsm->state is not a valid state"); - - if(cfstore_flash_fsm_on_exit[fsm->state] != NULL){ - cfstore_flash_fsm_on_exit[fsm->state](ctx); - } - fsm->state = new_state; - if(cfstore_flash_fsm_on_entry[new_state] != NULL){ - cfstore_flash_fsm_on_entry[new_state](ctx); - } - CFSTORE_DBGLOG("%s:FSM:REQ DONE:\r\n", __func__); - return; -} - -/* @brief initialize global context data structure */ -static void cfstore_flash_ctx_init(cfstore_flash_ctx_t* ctx) -{ - TEST_ASSERT_MESSAGE(ctx != NULL, "ctx is NULL"); - - CFSTORE_FENTRYLOG("%s:entered\r\n", __func__); - memset(&cfstore_flash_ctx_g, 0, sizeof(cfstore_flash_ctx_g)); -} - - -/* @brief asynchronous test 01 */ -static control_t cfstore_flash_journal_async_test_01(void) -{ - cfstore_flash_ctx_t* ctx = cfstore_flash_ctx_get(); - - CFSTORE_FENTRYLOG("%s:entered: \r\n", __func__); - cfstore_flash_mtd_async_ops_g = CFSTORE_FLASH_MTD_ASYNC_OPS_ON; - cfstore_flash_ctx_init(ctx); - cfstore_fsm_state_set(&ctx->fsm, cfstore_flash_fsm_state_initializing, ctx); - - /* allow time for work to be done */ - return CaseTimeout(CFSTORE_FLASH_CASE_TIMEOUT_MS); -} - -#endif /* CFSTORE_CONFIG_BACKEND_FLASH_ENABLED */ - - -/* report whether built/configured for flash sync or async mode */ -static control_t cfstore_flash_test_00(const size_t call_count) -{ - int32_t ret = ARM_DRIVER_ERROR; - - (void) call_count; - ret = cfstore_test_startup(); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flash_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to perform test startup (ret=%d).\n", __func__, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flash_utest_msg_g); - -#ifndef CFSTORE_CONFIG_BACKEND_FLASH_ENABLED - CFSTORE_LOG("INITIALIZING: BACKEND=SRAM. Skipping flash test%s", "\n"); -#endif - return CaseNext; -} - -/// @cond CFSTORE_DOXYGEN_DISABLE -/* Specify all your test cases here */ -Case cases[] = { - Case("flash_journal_async_test_00", cfstore_flash_test_00), -#ifdef CFSTORE_CONFIG_BACKEND_FLASH_ENABLED - Case("flash_journal_async_test_01", cfstore_flash_journal_async_test_01), -#endif -}; - - -utest::v1::status_t greentea_setup(const size_t number_of_cases) -{ - GREENTEA_SETUP(100, "default_auto"); - return greentea_test_setup_handler(number_of_cases); -} - -/* Declare your test specification with a custom setup handler */ -Specification specification(greentea_setup, cases); - - -int main() -{ - return !Harness::run(specification); -} -/// @endcond diff --git a/features/storage/FEATURE_STORAGE/TESTS/cfstore/flash_set/flash_set.cpp b/features/storage/FEATURE_STORAGE/TESTS/cfstore/flash_set/flash_set.cpp deleted file mode 100644 index b5f6697..0000000 --- a/features/storage/FEATURE_STORAGE/TESTS/cfstore/flash_set/flash_set.cpp +++ /dev/null @@ -1,103 +0,0 @@ -/* - * mbed Microcontroller Library - * Copyright (c) 2006-2016 ARM Limited - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -/** @file flash_set.cpp Test tool to set flash to some data - */ - -#include "mbed.h" -#include "cfstore_config.h" -#include "Driver_Common.h" -#include "cfstore_debug.h" -#include "cfstore_test.h" -#include "configuration_store.h" -#include "utest/utest.h" -#include "unity/unity.h" -#include "greentea-client/test_env.h" -#include "cfstore_utest.h" - -#include -#include -#include -#include - -using namespace utest::v1; - - - - -/** - * @brief add ~50 KVs and store them in flash - * - * @return on success returns CaseNext to continue to next test case, otherwise will assert on errors. - */ -static control_t cfstore_flash_set_test_01_end(const size_t call_count) -{ - int32_t ret = ARM_DRIVER_ERROR; - ARM_CFSTORE_FMODE flags; - ARM_CFSTORE_DRIVER* drv = &cfstore_driver; - ARM_CFSTORE_CAPABILITIES caps = cfstore_driver.GetCapabilities(); - - CFSTORE_FENTRYLOG("%s:entered\n", __func__); - (void) call_count; - memset(&flags, 0, sizeof(flags)); - - CFSTORE_LOG("caps.asynchronous_ops : %d\n", (int) caps.asynchronous_ops); - ret = cfstore_test_init_1(); - if(ret < ARM_DRIVER_OK){ - CFSTORE_ERRLOG("%s:Error: failed to write data to falsh.", __func__); - } - ret = drv->Flush(); - if(ret < ARM_DRIVER_OK){ - CFSTORE_ERRLOG("%s:Flush() call failed (ret=%d).\r\n", __func__, (int) ret); - } -#ifdef CFSTORE_DEBUG - ret = cfstore_test_dump(); - if(ret < ARM_DRIVER_OK){ - CFSTORE_ERRLOG("Error: failed to dump CFSTORE contents%s", "\n"); - } -#endif /* CFSTORE_DEBUG */ - ret = drv->Uninitialize(); - if(ret < ARM_DRIVER_OK){ - CFSTORE_ERRLOG("Error: failed to Uninitialize() CFSTORE%s", "\n"); - } - return CaseNext; -} - -/// @cond CFSTORE_DOXYGEN_DISABLE -utest::v1::status_t greentea_setup(const size_t number_of_cases) -{ - GREENTEA_SETUP(100, "default_auto"); - return greentea_test_setup_handler(number_of_cases); -} - -Case cases[] = { - /* 1 2 3 4 5 6 7 */ - /* 1234567890123456789012345678901234567890123456789012345678901234567890 */ - Case("FLASH_SET_test_01_start", cfstore_utest_default_start), - Case("FLASH_SET_test_01_end", cfstore_flash_set_test_01_end), -}; - - -/* Declare your test specification with a custom setup handler */ -Specification specification(greentea_setup, cases); - -int main() -{ - return !Harness::run(specification); -} -/// @endcond diff --git a/features/storage/FEATURE_STORAGE/TESTS/cfstore/flush/flush.cpp b/features/storage/FEATURE_STORAGE/TESTS/cfstore/flush/flush.cpp deleted file mode 100644 index 210ceb0..0000000 --- a/features/storage/FEATURE_STORAGE/TESTS/cfstore/flush/flush.cpp +++ /dev/null @@ -1,629 +0,0 @@ -/* - * mbed Microcontroller Library - * Copyright (c) 2006-2016 ARM Limited - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** @file flush.cpp Test cases to flush KVs in the CFSTORE using the drv->Flush() interface. - * - * Please consult the documentation under the test-case functions for - * a description of the individual test case. - */ - -#if defined __MBED__ && ! defined TOOLCHAIN_GCC_ARM - - -#include "mbed.h" -#include "cfstore_config.h" -#include "Driver_Common.h" -#include "cfstore_debug.h" -#include "cfstore_test.h" -#include "configuration_store.h" -#include "utest/utest.h" -#include "unity/unity.h" -#include "greentea-client/test_env.h" - -#include -#include -#include -#include - -using namespace utest::v1; - -static control_t cfstore_flush_test_00(const size_t call_count) -{ - (void) call_count; - CFSTORE_LOG("%s:Not implemented for ARM toolchain\n", __func__); - return CaseNext; -} - - -utest::v1::status_t greentea_setup(const size_t number_of_cases) -{ - GREENTEA_SETUP(100, "default_auto"); - return greentea_test_setup_handler(number_of_cases); -} - -Case cases[] = { - /* 1 2 3 4 5 6 7 */ - /* 1234567890123456789012345678901234567890123456789012345678901234567890 */ - Case("FLUSH_test_00", cfstore_flush_test_00), -}; - - -/* Declare your test specification with a custom setup handler */ -Specification specification(greentea_setup, cases); - -int main() -{ - return !Harness::run(specification); -} - - -#else - - - -#include "mbed.h" -#include "cfstore_config.h" -#include "cfstore_test.h" -#include "cfstore_debug.h" -#include "Driver_Common.h" -#include "configuration_store.h" -#include "utest/utest.h" -#include "unity/unity.h" -#include "greentea-client/test_env.h" - -#include -#include -#include -#include - -using namespace utest::v1; - -/* - * Defines - */ -/// @cond CFSTORE_DOXYGEN_DISABLE -#define CFSTORE_FLUSH_UTEST_MSG_BUF_SIZE 256 -#define cfstore_flush_fsm_null NULL -#define CFSTORE_FLUSH_CASE_TIMEOUT_MS 10000 -#define CFSTORE_FLUSH_FSM_LOOPS 20 - -#ifdef CFSTORE_DEBUG -#define CFSTORE_FLUSH_GREENTEA_TIMEOUT_S 360 -#else -#define CFSTORE_FLUSH_GREENTEA_TIMEOUT_S 60 -#endif - -/* - * Globals - * - * cfstore_flush_utest_msg_g - * buffer for storing TEST_ASSERT_xxx_MESSAGE messages - */ -char cfstore_flush_utest_msg_g[CFSTORE_FLUSH_UTEST_MSG_BUF_SIZE]; - - - - - -#ifdef TARGET_LIKE_X86_LINUX_NATIVE - -/** @brief basic Flush() test - * - * @return on success returns CaseNext to continue to next test case, otherwise will assert on errors. - */ -int32_t cfstore_flush_test_01_x86_sync(void) -{ - int32_t ret = ARM_DRIVER_ERROR; - ARM_CFSTORE_DRIVER* drv = &cfstore_driver; - - ret = drv->Initialize(NULL, NULL); - if(ret != ARM_DRIVER_OK){ - CFSTORE_ERRLOG("%s:Initialize() call failed (ret=%d).\r\n", __func__, (int) ret); - goto out0; - } - ret = drv->Flush(); - if(ret != ARM_DRIVER_OK){ - CFSTORE_ERRLOG("%s:Flush() call failed (ret=%d).\r\n", __func__, (int) ret); - } - ret = drv->Uninitialize(); - if(ret != ARM_DRIVER_OK){ - CFSTORE_ERRLOG("%s:Initialize() call failed to Uninitialise(ret=%d).\r\n", __func__, (int) ret); - goto out0; - } - out0: - return ret; -} -#endif /* TARGET_LIKE_X86_LINUX_NATIVE */ - -/* KV data for test_03 */ -static cfstore_kv_data_t cfstore_flush_test_02_kv_data[] = { - { "com.arm.mbed.configurationstore.test.flush.cfstoreflushtest02", "1"}, - /* 1 2 3 4 5 6 7 */ - /* 1234567890123456789012345678901234567890123456789012345678901234567890 */ - { NULL, NULL}, -}; - - -/* async test version */ - -/* @brief test fsm states and events */ -typedef enum cfstore_flush_fsm_state_t { - cfstore_flush_fsm_state_stopped = 0, - cfstore_flush_fsm_state_initializing, - cfstore_flush_fsm_state_flushing, - cfstore_flush_fsm_state_uninitializing, - cfstore_flush_fsm_state_max -} cfstore_flush_fsm_state_t; - -/* @brief test fsm events */ -typedef enum cfstore_flush_fsm_event_t { - cfstore_flush_fsm_event_init_done = 0, - cfstore_flush_fsm_event_flush_done, - cfstore_flush_fsm_event_uninit_done, - cfstore_flush_fsm_event_max, -} cfstore_flush_fsm_event_t; - -typedef void (*cfstore_flush_fsm_handler)(void* ctx); - -/// @cond CFSTORE_DOXYGEN_DISABLE -typedef struct cfstore_fsm_t -{ - cfstore_flush_fsm_state_t state; - cfstore_flush_fsm_event_t event; -} cfstore_fsm_t; -/// @endcond - -/// @cond CFSTORE_DOXYGEN_DISABLE -typedef struct cfstore_flush_ctx_t -{ - int32_t loops_done; - cfstore_fsm_t fsm; - int32_t status; - ARM_CFSTORE_OPCODE cmd_code; -} cfstore_flush_ctx_t; -/// @endcond - - -/* - * Globals - */ -static cfstore_flush_ctx_t cfstore_flush_ctx_g; - -#ifdef CFSTORE_DEBUG -static const char* cfstore_flush_state_str[] = -{ - "stopped", - "initializing", - "flushing", - "uninitializing", - "unknown" -}; - -static const char* cfstore_flush_event_str[] = -{ - "init_done", - "flush_done", - "uninit_done", - "unknown" -}; -#endif - -/// @endcond - -/* - * Forward decl - */ -static void cfstore_flush_fsm_state_handle_event(cfstore_fsm_t* fsm, cfstore_flush_fsm_event_t event, void* context); -static void cfstore_flush_fsm_state_set(cfstore_fsm_t* fsm, cfstore_flush_fsm_state_t new_state, void* ctx); -/* - * context related methods - */ - -/* @brief get a pointer to the global context data structure */ -static cfstore_flush_ctx_t* cfstore_flush_ctx_get(void) -{ - return &cfstore_flush_ctx_g; -} - -/* @brief initialize global context data structure */ -static void cfstore_flush_ctx_init(cfstore_flush_ctx_t* ctx) -{ - TEST_ASSERT_MESSAGE(ctx != NULL, "ctx is NULL"); - - CFSTORE_FENTRYLOG("%s:entered\r\n", __func__); - memset(&cfstore_flush_ctx_g, 0, sizeof(cfstore_flush_ctx_g)); -} - - -/* @brief cfstore asynchronous callback handler */ -void cfstore_flush_test_01_callback(int32_t status, ARM_CFSTORE_OPCODE cmd_code, void *client_context, ARM_CFSTORE_HANDLE handle) -{ - cfstore_flush_ctx_t* ctx = (cfstore_flush_ctx_t*) client_context; - - CFSTORE_FENTRYLOG("%s:entered: status=%d, cmd_code=%d (%s) ctx=%p, handle=%p\r\n", __func__, (int) status, (int) cmd_code, cfstore_test_opcode_str[cmd_code], ctx, handle); - (void) handle; - switch(cmd_code) - { - case CFSTORE_OPCODE_INITIALIZE: - ctx->fsm.event = cfstore_flush_fsm_event_init_done; - break; - case CFSTORE_OPCODE_FLUSH: - ctx->fsm.event = cfstore_flush_fsm_event_flush_done; - break; - case CFSTORE_OPCODE_UNINITIALIZE: - ctx->fsm.event = cfstore_flush_fsm_event_uninit_done; - break; - case CFSTORE_OPCODE_CLOSE: - case CFSTORE_OPCODE_CREATE: - case CFSTORE_OPCODE_DELETE: - case CFSTORE_OPCODE_FIND: - case CFSTORE_OPCODE_GET_KEY_NAME: - case CFSTORE_OPCODE_GET_STATUS: - case CFSTORE_OPCODE_GET_VALUE_LEN: - case CFSTORE_OPCODE_OPEN: - case CFSTORE_OPCODE_POWER_CONTROL: - case CFSTORE_OPCODE_READ: - case CFSTORE_OPCODE_RSEEK: - case CFSTORE_OPCODE_WRITE: - default: - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush_utest_msg_g, CFSTORE_FLUSH_UTEST_MSG_BUF_SIZE, "%s:WARN: received asynchronous notification for opcode=%d (%s) when api call should have been synchronous", __func__, cmd_code, cmd_code < CFSTORE_OPCODE_MAX ? cfstore_test_opcode_str[cmd_code] : "unknown"); - CFSTORE_DBGLOG("%s:WARN: received asynchronous notification for opcode=%d (%s) when api call should have been synchronous", __func__, cmd_code, cmd_code < CFSTORE_OPCODE_MAX ? cfstore_test_opcode_str[cmd_code] : "unknown"); - /* TEST_ASSERT_MESSAGE(false, cfstore_flush_utest_msg_g) */ - return; - } - ctx->status = status; - ctx->cmd_code = cmd_code; - cfstore_flush_fsm_state_handle_event(&ctx->fsm, ctx->fsm.event, client_context); - return; -} - -/* @brief fsm handler called on entry to stopping state */ -static void cfstore_flush_fsm_stop_on_entry(void* context) -{ - (void) context; - CFSTORE_FENTRYLOG("%s:entered:\r\n", __func__); - Harness::validate_callback(); - return; -} - -/* @brief fsm handler called on entry to initializing state */ -static void cfstore_flush_fsm_init_on_entry(void* context) -{ - int32_t ret = ARM_DRIVER_ERROR; - cfstore_flush_ctx_t* ctx = (cfstore_flush_ctx_t*) context; - const ARM_CFSTORE_DRIVER* drv = &cfstore_driver; - - /* check that the mtd is in synchronous mode */ - CFSTORE_FENTRYLOG("%s:entered: callback=%p, ctx=%p\r\n", __func__, cfstore_flush_test_01_callback, ctx); - ret = drv->Initialize(cfstore_flush_test_01_callback, ctx); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush_utest_msg_g, CFSTORE_FLUSH_UTEST_MSG_BUF_SIZE, "%s:Error: failed to initialize CFSTORE (ret=%d)\r\n", __func__, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush_utest_msg_g); - CFSTORE_DBGLOG("%s:debug: ret=%d\r\n", __func__, (int) ret); - return; -} - -/* brief callback handler when in state initializing */ -static void cfstore_flush_fsm_initializing(void* context) -{ - cfstore_flush_ctx_t* ctx = (cfstore_flush_ctx_t*) context; - - CFSTORE_FENTRYLOG("%s:entered\r\n", __func__); - CFSTORE_FENTRYLOG("%s:entered: status = %d\r\n", __func__, (int) ctx->status); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush_utest_msg_g, CFSTORE_FLUSH_UTEST_MSG_BUF_SIZE, "%s:Error: entered handler(%s) but not in initializing state (fsm->state=%d)\r\n", __func__, __func__, (int) ctx->fsm.state); - TEST_ASSERT_MESSAGE(ctx->fsm.state == cfstore_flush_fsm_state_initializing, cfstore_flush_utest_msg_g); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush_utest_msg_g, CFSTORE_FLUSH_UTEST_MSG_BUF_SIZE, "%s:Error: cmd_code code (%d) is not as expected (%d)\r\n", __func__, ctx->cmd_code, CFSTORE_OPCODE_INITIALIZE); - TEST_ASSERT_MESSAGE(ctx->cmd_code == CFSTORE_OPCODE_INITIALIZE, cfstore_flush_utest_msg_g); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush_utest_msg_g, CFSTORE_FLUSH_UTEST_MSG_BUF_SIZE, "%s:Error: status=%d\r\n", __func__, (int) ctx->status); - TEST_ASSERT_MESSAGE(ctx->status >= ARM_DRIVER_OK, cfstore_flush_utest_msg_g); - /* only change state if status >= 0*/ - if(ctx->status >= 0){ - cfstore_flush_fsm_state_set(&ctx->fsm, cfstore_flush_fsm_state_flushing, ctx); - } - return; -} - -/* static void cfstore_flush_fsm_init_on_exit(void* context){ (void) context;} */ - - -/* @brief fsm handler called on entry to flushing state */ -static void cfstore_flush_fsm_flush_on_entry(void* context) -{ - bool bfound = false; - int32_t ivalue = 0; - int32_t ret = ARM_DRIVER_ERROR; - ARM_CFSTORE_DRIVER* drv = &cfstore_driver; - const char* key_name_query = "*"; - char value[CFSTORE_KEY_NAME_MAX_LENGTH+1]; - ARM_CFSTORE_SIZE len = CFSTORE_KEY_NAME_MAX_LENGTH+1; - ARM_CFSTORE_HANDLE_INIT(next); - ARM_CFSTORE_HANDLE_INIT(prev); - ARM_CFSTORE_KEYDESC kdesc; - cfstore_flush_ctx_t* ctx = (cfstore_flush_ctx_t*) context; - - /* check that the mtd is in synchronous mode */ - CFSTORE_FENTRYLOG("%s:entered: \r\n", __func__); - memset(&kdesc, 0, sizeof(kdesc)); - - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush_utest_msg_g, CFSTORE_FLUSH_UTEST_MSG_BUF_SIZE, "%s:Error: entered handler(%s) but not in flushing state (fsm->state=%d)\r\n", __func__, __func__, (int) ctx->fsm.state); - TEST_ASSERT_MESSAGE(ctx->fsm.state == cfstore_flush_fsm_state_flushing, cfstore_flush_utest_msg_g); - /* try to read key; should not be found */ - ret = cfstore_test_kv_is_found(cfstore_flush_test_02_kv_data->key_name, &bfound); - if(ret != ARM_DRIVER_OK && ret != ARM_CFSTORE_DRIVER_ERROR_KEY_NOT_FOUND){ - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush_utest_msg_g, CFSTORE_FLUSH_UTEST_MSG_BUF_SIZE, "%s:Error: cfstore_test_kv_is_found() call failed (ret=%d).\r\n", __func__, (int) ret); - TEST_ASSERT_MESSAGE(false, cfstore_flush_utest_msg_g); - } - - if(!bfound) - { - /* first time start up. nothing is stored in cfstore flash. check this is the case */ - while(drv->Find(key_name_query, prev, next) == ARM_DRIVER_OK) - { - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush_utest_msg_g, CFSTORE_FLUSH_UTEST_MSG_BUF_SIZE, "%s:Error: have found an entry in cfstore when none should be present", __func__); - TEST_ASSERT_MESSAGE(false, cfstore_flush_utest_msg_g); - } - /* no entries found, which is correct. - * store a value */ - len = strlen(cfstore_flush_test_02_kv_data->value); - ret = cfstore_test_create(cfstore_flush_test_02_kv_data->key_name, cfstore_flush_test_02_kv_data->value, &len, &kdesc); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush_utest_msg_g, CFSTORE_FLUSH_UTEST_MSG_BUF_SIZE, "%s:Error:1: failed to write kv data (ret=%d).\r\n", __func__, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush_utest_msg_g); - /* flush to flash */ - ret = drv->Flush(); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush_utest_msg_g, CFSTORE_FLUSH_UTEST_MSG_BUF_SIZE, "%s:Error: failed to flush data to cfstore flash (ret=%d).\r\n", __func__, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush_utest_msg_g); - /* revert to CFSTORE_LOG if more trace required */ - CFSTORE_DBGLOG("FLUSH: Success pending for new KV creation (name=%s, value=%s)\n", cfstore_flush_test_02_kv_data->key_name, cfstore_flush_test_02_kv_data->value); - } else { - /*read the value, increment by 1 and write value back */ - len = CFSTORE_KEY_NAME_MAX_LENGTH+1; - ret = cfstore_test_read(cfstore_flush_test_02_kv_data->key_name, value, &len); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush_utest_msg_g, CFSTORE_FLUSH_UTEST_MSG_BUF_SIZE, "%s:Error: failed to read kv data (ret=%d).\r\n", __func__, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush_utest_msg_g); - - ivalue = atoi(value); - /* revert to CFSTORE_LOG if more trace required */ - CFSTORE_DBGLOG("FLUSH: Read KV from flash (name=%s, value=%d)\n", cfstore_flush_test_02_kv_data->key_name, (int) ivalue); - /* increment value */ - ++ivalue; - snprintf(value, CFSTORE_KEY_NAME_MAX_LENGTH+1, "%d", (int) ivalue); - len = strlen(value); - ret = cfstore_test_write(cfstore_flush_test_02_kv_data->key_name, value, &len); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush_utest_msg_g, CFSTORE_FLUSH_UTEST_MSG_BUF_SIZE, "%s:Error: failed to write kv data (ret=%d).\r\n", __func__, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush_utest_msg_g); - - /* flush to flash */ - ret = drv->Flush(); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush_utest_msg_g, CFSTORE_FLUSH_UTEST_MSG_BUF_SIZE, "%s:Error: failed to flush data to cfstore flash (ret=%d).\r\n", __func__, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush_utest_msg_g); - /* revert to CFSTORE_LOG if more trace required */ - CFSTORE_DBGLOG("FLUSH: Success pending for new KV value to flash (name=%s, value=%d)\n", cfstore_flush_test_02_kv_data->key_name, (int) ivalue); - } - return; -} - - -/* brief callback handler when in state flushing */ -static void cfstore_flush_fsm_flushing(void* context) -{ - cfstore_flush_ctx_t* ctx = (cfstore_flush_ctx_t*) context; - - CFSTORE_FENTRYLOG("%s:entered\r\n", __func__); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush_utest_msg_g, CFSTORE_FLUSH_UTEST_MSG_BUF_SIZE, "%s:Error: entered handler(%s) but not in flushing state (fsm->state=%d)\r\n", __func__, __func__, (int) ctx->fsm.state); - TEST_ASSERT_MESSAGE(ctx->fsm.state == cfstore_flush_fsm_state_flushing, cfstore_flush_utest_msg_g); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush_utest_msg_g, CFSTORE_FLUSH_UTEST_MSG_BUF_SIZE, "%s:Error: cmd_code code (%d) is not as expected (%d)\r\n", __func__, ctx->cmd_code, CFSTORE_OPCODE_FLUSH); - TEST_ASSERT_MESSAGE(ctx->cmd_code == CFSTORE_OPCODE_FLUSH, cfstore_flush_utest_msg_g); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush_utest_msg_g, CFSTORE_FLUSH_UTEST_MSG_BUF_SIZE, "%s:Error: status=%d\r\n", __func__, (int) ctx->status); - TEST_ASSERT_MESSAGE(ctx->status >= ARM_DRIVER_OK, cfstore_flush_utest_msg_g); - /* only change state if status >= 0*/ - if(ctx->status >= 0){ - /* revert to CFSTORE_LOG if more trace required */ - CFSTORE_DBGLOG("FLUSH: Successfully flushed data to flash.%s", "\n"); - cfstore_flush_fsm_state_set(&ctx->fsm, cfstore_flush_fsm_state_uninitializing, ctx); - } - return; -} - -/* static void cfstore_flush_fsm_flush_on_exit(void* context){ (void) context;} */ - - -/* @brief fsm handler called on entry to uninitializing state */ -static void cfstore_flush_fsm_uninit_on_entry(void* context) -{ - int32_t ret = ARM_DRIVER_ERROR; - cfstore_flush_ctx_t* ctx = (cfstore_flush_ctx_t*) context; - const ARM_CFSTORE_DRIVER* drv = &cfstore_driver; - - /* check that the mtd is in synchronous mode */ - CFSTORE_FENTRYLOG("%s:entered: \r\n", __func__); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush_utest_msg_g, CFSTORE_FLUSH_UTEST_MSG_BUF_SIZE, "%s:Error: entered handler(%s) but not in uninitializing state (fsm->state=%d)\r\n", __func__, __func__, (int) ctx->fsm.state); - TEST_ASSERT_MESSAGE(ctx->fsm.state == cfstore_flush_fsm_state_uninitializing, cfstore_flush_utest_msg_g); - ret = drv->Uninitialize(); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush_utest_msg_g, CFSTORE_FLUSH_UTEST_MSG_BUF_SIZE, "%s:Error: failed to uninitialize CFSTORE (ret=%d)\r\n", __func__, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush_utest_msg_g); - return; -} - -/* brief callback handler when in state uninitializing */ -static void cfstore_flush_fsm_uninitializing(void* context) -{ - cfstore_flush_ctx_t* ctx = (cfstore_flush_ctx_t*) context; - - CFSTORE_FENTRYLOG("%s:entered\r\n", __func__); - CFSTORE_DBGLOG("%s:ctx->status=%d, ctx->loops_done=%d\r\n", __func__, (int) ctx->status, (int) ctx->loops_done); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush_utest_msg_g, CFSTORE_FLUSH_UTEST_MSG_BUF_SIZE, "%s:Error: entered handler(%s) but not in uninitializing state (fsm->state=%d)\r\n", __func__, __func__, (int) ctx->fsm.state); - TEST_ASSERT_MESSAGE(ctx->fsm.state == cfstore_flush_fsm_state_uninitializing, cfstore_flush_utest_msg_g); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush_utest_msg_g, CFSTORE_FLUSH_UTEST_MSG_BUF_SIZE, "%s:Error: cmd_code code (%d) is not as expected (%d)\r\n", __func__, ctx->cmd_code, CFSTORE_OPCODE_UNINITIALIZE); - TEST_ASSERT_MESSAGE(ctx->cmd_code == CFSTORE_OPCODE_UNINITIALIZE, cfstore_flush_utest_msg_g); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush_utest_msg_g, CFSTORE_FLUSH_UTEST_MSG_BUF_SIZE, "%s:Error: status=%d\r\n", __func__, (int) ctx->status); - TEST_ASSERT_MESSAGE(ctx->status >= ARM_DRIVER_OK, cfstore_flush_utest_msg_g); - /* only change state if status >= 0*/ - if(ctx->status >= ARM_DRIVER_OK){ - ++ctx->loops_done; - if(ctx->loops_done < CFSTORE_FLUSH_FSM_LOOPS){ - cfstore_flush_fsm_state_set(&ctx->fsm, cfstore_flush_fsm_state_initializing, ctx); - } else { - /* move to init state */ - cfstore_flush_fsm_state_set(&ctx->fsm, cfstore_flush_fsm_state_stopped, ctx); - } - } - return; -} - -/* static void cfstore_flush_fsm_uninit_on_exit(void* context) {(void)context;} */ - - - -/* handler functions while in state */ -static cfstore_flush_fsm_handler cfstore_flush_fsm[cfstore_flush_fsm_state_max][cfstore_flush_fsm_event_max] = -{ -/* state\event: init_done flush_done unint_done */ -/* stopped */ {cfstore_flush_fsm_null, cfstore_flush_fsm_null, cfstore_flush_fsm_null }, -/* initialising */ {cfstore_flush_fsm_initializing, cfstore_flush_fsm_null, cfstore_flush_fsm_null }, -/* flushing */ {cfstore_flush_fsm_null, cfstore_flush_fsm_flushing, cfstore_flush_fsm_null }, -/* uninitializing */ {cfstore_flush_fsm_null, cfstore_flush_fsm_null, cfstore_flush_fsm_uninitializing } -}; - - -/* handler functions for entering the state*/ -static cfstore_flush_fsm_handler cfstore_flush_fsm_on_entry[cfstore_flush_fsm_state_max] = -{ - cfstore_flush_fsm_stop_on_entry, - cfstore_flush_fsm_init_on_entry, - cfstore_flush_fsm_flush_on_entry, - cfstore_flush_fsm_uninit_on_entry -}; - -/* handler functions for exiting state, currently none used */ -static cfstore_flush_fsm_handler cfstore_flush_fsm_on_exit[cfstore_flush_fsm_state_max] = -{ - cfstore_flush_fsm_null, - cfstore_flush_fsm_null, - cfstore_flush_fsm_null, - cfstore_flush_fsm_null -}; - - -/* @brief inject event into fsm */ -static void cfstore_flush_fsm_state_handle_event(cfstore_fsm_t* fsm, cfstore_flush_fsm_event_t event, void* context) -{ - cfstore_flush_ctx_t* ctx = (cfstore_flush_ctx_t*) context; - - CFSTORE_FENTRYLOG("%s:entered: fsm=%p, state=(%s), event=%d (%s), ctx=%p\r\n", __func__, fsm, cfstore_flush_state_str[fsm->state], (int) event, cfstore_flush_event_str[event], ctx); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush_utest_msg_g, CFSTORE_FLUSH_UTEST_MSG_BUF_SIZE, "%s:Error: invalid event (%d)\r\n", __func__, (int) event); - TEST_ASSERT_MESSAGE(event < cfstore_flush_fsm_event_max, cfstore_flush_utest_msg_g); - fsm->event = event; - if(cfstore_flush_fsm[fsm->state][fsm->event] != NULL){ - cfstore_flush_fsm[fsm->state][fsm->event](ctx); - } - - /* do not clear context data set by caller as it may be used later - * fsm->event = cfstore_flush_fsm_event_max; - * ctx->status = 0; - * ctx->cmd_code = (FlashJournal_OpCode_t)((int) FLASH_JOURNAL_OPCODE_RESET+1); - */ - return; -} - - -/* @brief function to move to new fsm state, calling state exit function for old state and entry function for new state */ -static void cfstore_flush_fsm_state_set(cfstore_fsm_t* fsm, cfstore_flush_fsm_state_t new_state, void* ctx) -{ - #ifdef CFSTORE_DEBUG - cfstore_flush_fsm_state_t old_state = fsm->state; - #endif - - CFSTORE_FENTRYLOG("%s:entered: fsm=%p, ctx=%p\r\n", __func__, fsm, ctx); - #ifdef CFSTORE_DEBUG - CFSTORE_DBGLOG("%s:FSM:REQ RX:%s:%s\r\n", __func__, cfstore_flush_state_str[fsm->state], cfstore_flush_state_str[new_state]); - #endif - TEST_ASSERT_MESSAGE(fsm != NULL, "fsm is not a valid pointer"); - TEST_ASSERT_MESSAGE(new_state < cfstore_flush_fsm_state_max, "new_state is not a valid state"); - TEST_ASSERT_MESSAGE(ctx != NULL, "ctx is not a valid pointer"); - TEST_ASSERT_MESSAGE(fsm->state < cfstore_flush_fsm_state_max, "fsm->state is not a valid state"); - - if(cfstore_flush_fsm_on_exit[fsm->state] != NULL){ - cfstore_flush_fsm_on_exit[fsm->state](ctx); - } - fsm->state = new_state; - if(cfstore_flush_fsm_on_entry[new_state] != NULL){ - cfstore_flush_fsm_on_entry[new_state](ctx); - } - #ifdef CFSTORE_DEBUG - CFSTORE_DBGLOG("%s:FSM:REQ DONE fsm=%p, fsm->state (old_state)=%s, new_state=%s, ctx=%p\r\n", __func__, fsm, cfstore_flush_state_str[old_state], cfstore_flush_state_str[new_state], ctx); - #endif - return; -} - - -/* @brief asynchronous test 01 */ -static control_t cfstore_flush_test_02_k64f(void) -{ - cfstore_flush_ctx_t* ctx = cfstore_flush_ctx_get(); - ARM_CFSTORE_CAPABILITIES caps; - const ARM_CFSTORE_DRIVER* drv = &cfstore_driver; - - CFSTORE_FENTRYLOG("%s:entered: \r\n", __func__); - memset(&caps, 0, sizeof(caps)); - caps = drv->GetCapabilities(); - if(caps.asynchronous_ops == false){ - /* This is a async mode only test. If this test is not built for sync mode, then skip testing return true - * This means the test will conveniently pass when run in CI as part of async mode testing */ - CFSTORE_LOG("*** Skipping test as binary built for flash journal sync mode, and this test is async-only%s", "\n"); - return CaseNext; - } - - cfstore_flush_ctx_init(ctx); - cfstore_flush_fsm_state_set(&ctx->fsm, cfstore_flush_fsm_state_initializing, ctx); - return CaseTimeout(CFSTORE_FLUSH_GREENTEA_TIMEOUT_S*1000); -} - -/* report whether built/configured for flash sync or async mode */ -static control_t cfstore_flush_test_00(const size_t call_count) -{ - int32_t ret = ARM_DRIVER_ERROR; - - (void) call_count; - ret = cfstore_test_startup(); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to perform test startup (ret=%d).\n", __func__, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush_utest_msg_g); - return CaseNext; -} - -/// @cond CFSTORE_DOXYGEN_DISABLE -utest::v1::status_t greentea_setup(const size_t number_of_cases) -{ - GREENTEA_SETUP(CFSTORE_FLUSH_GREENTEA_TIMEOUT_S, "default_auto"); - return greentea_test_setup_handler(number_of_cases); -} - -Case cases[] = { - Case("FLUSH_test_00", cfstore_flush_test_00), - Case("FLUSH_test_01", cfstore_flush_test_02_k64f), -}; - - -/* Declare your test specification with a custom setup handler */ -Specification specification(greentea_setup, cases); - -int main() -{ - return !Harness::run(specification); -} -/// @endcond - - -#endif // __MBED__ && ! defined TOOLCHAIN_GCC_ARM diff --git a/features/storage/FEATURE_STORAGE/TESTS/cfstore/flush2/flush2.cpp b/features/storage/FEATURE_STORAGE/TESTS/cfstore/flush2/flush2.cpp deleted file mode 100644 index beeb221..0000000 --- a/features/storage/FEATURE_STORAGE/TESTS/cfstore/flush2/flush2.cpp +++ /dev/null @@ -1,270 +0,0 @@ -/* - * mbed Microcontroller Library - * Copyright (c) 2006-2016 ARM Limited - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** @file flush2.cpp Test cases to flush KVs in the CFSTORE using the drv->Flush() interface. - * - * Please consult the documentation under the test-case functions for - * a description of the individual test case. - */ - -#include "mbed.h" -#include "utest/utest.h" -#include "unity/unity.h" -#include "cfstore_config.h" -#include "configuration_store.h" -#include "greentea-client/test_env.h" -#include "cfstore_test.h" -#include "cfstore_debug.h" - -#include -#include -#include -#include - -using namespace utest::v1; - -/// @cond CFSTORE_DOXYGEN_DISABLE -/* - * Defines - */ -#define CFSTORE_FLUSH_UTEST_MSG_BUF_SIZE 256 -#define cfstore_flush_fsm_null NULL -#define CFSTORE_FLUSH_CASE_TIMEOUT_MS 10000 - - - -/* - * Globals - * - * cfstore_flush_utest_msg_g - * buffer for storing TEST_ASSERT_xxx_MESSAGE messages - */ -static char cfstore_flush_utest_msg_g[CFSTORE_FLUSH_UTEST_MSG_BUF_SIZE]; - -/* KV data for test_03 */ -static cfstore_kv_data_t cfstore_flush_test_02_kv_data[] = { - { "com.arm.mbed.configurationstore.test.flush.cfstoreflushtest02", "1"}, - /* 1 2 3 4 5 6 7 */ - /* 1234567890123456789012345678901234567890123456789012345678901234567890 */ - { NULL, NULL}, -}; - -/* async test version */ - -typedef struct cfstore_flush_ctx_t -{ - int32_t status; - ARM_CFSTORE_OPCODE cmd_code; -} cfstore_flush_ctx_t; -/// @endcond - -/* - * Globals - */ -static cfstore_flush_ctx_t cfstore_flush_ctx_g; - -/* - * context related methods - */ - -/* @brief get a pointer to the global context data structure */ -static cfstore_flush_ctx_t* cfstore_flush_ctx_get(void) -{ - return &cfstore_flush_ctx_g; -} - -/* @brief initialize global context data structure */ -static void cfstore_flush_ctx_init(cfstore_flush_ctx_t* ctx) -{ - TEST_ASSERT_MESSAGE(ctx != NULL, "ctx is NULL"); - - CFSTORE_FENTRYLOG("%s:entered\r\n", __func__); - memset(&cfstore_flush_ctx_g, 0, sizeof(cfstore_flush_ctx_g)); -} - - -/* report whether built/configured for flash sync or async mode */ -static control_t cfstore_flush2_test_00(const size_t call_count) -{ - int32_t ret = ARM_DRIVER_ERROR; - - (void) call_count; - ret = cfstore_test_startup(); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to perform test startup (ret=%d).\n", __func__, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush_utest_msg_g); - return CaseNext; -} - -/** - * @brief - * - * - * @return on success returns CaseNext to continue to next test case, otherwise will assert on errors. - */ -control_t cfstore_flush2_test_01_start(const size_t call_count) -{ - int32_t ret = ARM_DRIVER_ERROR; - cfstore_flush_ctx_t* ctx = cfstore_flush_ctx_get(); - const ARM_CFSTORE_DRIVER* drv = &cfstore_driver; - - /* check that the mtd is in synchronous mode */ - CFSTORE_FENTRYLOG("%s:entered:\r\n", __func__); - (void) call_count; - cfstore_flush_ctx_init(ctx); - ret = drv->Initialize(cfstore_utest_default_callback, ctx); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush_utest_msg_g, CFSTORE_FLUSH_UTEST_MSG_BUF_SIZE, "%s:Error: failed to initialize CFSTORE (ret=%d)\r\n", __func__, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush_utest_msg_g); - return CaseTimeout(100000); -} - - -/** - * @brief - * - * - * @return on success returns CaseNext to continue to next test case, otherwise will assert on errors. - */ -control_t cfstore_flush2_test_01_mid(const size_t call_count) -{ - - bool bfound = false; - int32_t ivalue = 0; - int32_t ret = ARM_DRIVER_ERROR; - ARM_CFSTORE_DRIVER* drv = &cfstore_driver; - const char* key_name_query = "*"; - char value[CFSTORE_KEY_NAME_MAX_LENGTH+1]; - ARM_CFSTORE_SIZE len = CFSTORE_KEY_NAME_MAX_LENGTH+1; - ARM_CFSTORE_HANDLE_INIT(next); - ARM_CFSTORE_HANDLE_INIT(prev); - ARM_CFSTORE_KEYDESC kdesc; - - /* check that the mtd is in synchronous mode */ - CFSTORE_FENTRYLOG("%s:entered: \r\n", __func__); - (void) call_count; - memset(&kdesc, 0, sizeof(kdesc)); - - /* try to read key; should not be found */ - ret = cfstore_test_kv_is_found(cfstore_flush_test_02_kv_data->key_name, &bfound); - if(ret != ARM_DRIVER_OK && ret != ARM_CFSTORE_DRIVER_ERROR_KEY_NOT_FOUND){ - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush_utest_msg_g, CFSTORE_FLUSH_UTEST_MSG_BUF_SIZE, "%s:Error: cfstore_test_kv_is_found() call failed (ret=%d).\r\n", __func__, (int) ret); - TEST_ASSERT_MESSAGE(false, cfstore_flush_utest_msg_g); - } - - if(!bfound) - { - /* first time start up. nothing is stored in cfstore flash. check this is the case */ - while(drv->Find(key_name_query, prev, next) == ARM_DRIVER_OK) - { - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush_utest_msg_g, CFSTORE_FLUSH_UTEST_MSG_BUF_SIZE, "%s:Error: have found an entry in cfstore when none should be present", __func__); - TEST_ASSERT_MESSAGE(false, cfstore_flush_utest_msg_g); - } - /* no entries found, which is correct. - * store a value */ - len = strlen(cfstore_flush_test_02_kv_data->value); - ret = cfstore_test_create(cfstore_flush_test_02_kv_data->key_name, cfstore_flush_test_02_kv_data->value, &len, &kdesc); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush_utest_msg_g, CFSTORE_FLUSH_UTEST_MSG_BUF_SIZE, "%s:Error:1: failed to write kv data (ret=%d).\r\n", __func__, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush_utest_msg_g); - /* flush to flash */ - ret = drv->Flush(); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush_utest_msg_g, CFSTORE_FLUSH_UTEST_MSG_BUF_SIZE, "%s:Error: failed to flush data to cfstore flash (ret=%d).\r\n", __func__, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush_utest_msg_g); - - } else { - /*read the value, increment by 1 and write value back */ - len = CFSTORE_KEY_NAME_MAX_LENGTH+1; - ret = cfstore_test_read(cfstore_flush_test_02_kv_data->key_name, value, &len); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush_utest_msg_g, CFSTORE_FLUSH_UTEST_MSG_BUF_SIZE, "%s:Error: failed to read kv data (ret=%d).\r\n", __func__, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush_utest_msg_g); - - /* increment value */ - ivalue = atoi(value); - ++ivalue; - snprintf(value, CFSTORE_KEY_NAME_MAX_LENGTH+1, "%d", (int) ivalue); - len = strlen(value); - ret = cfstore_test_write(cfstore_flush_test_02_kv_data->key_name, value, &len); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush_utest_msg_g, CFSTORE_FLUSH_UTEST_MSG_BUF_SIZE, "%s:Error: failed to write kv data (ret=%d).\r\n", __func__, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush_utest_msg_g); - - /* flush to flash */ - ret = drv->Flush(); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush_utest_msg_g, CFSTORE_FLUSH_UTEST_MSG_BUF_SIZE, "%s:Error: failed to flush data to cfstore flash (ret=%d).\r\n", __func__, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush_utest_msg_g); - } - return CaseTimeout(100000); -} - -/** - * @brief - * - * - * @return on success returns CaseNext to continue to next test case, otherwise will assert on errors. - */ -control_t cfstore_flush2_test_01_end(const size_t call_count) -{ - const ARM_CFSTORE_DRIVER* drv = &cfstore_driver; - - CFSTORE_FENTRYLOG("%s:entered:\r\n", __func__); - (void) call_count; - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Uninitialize() call failed.\n", __func__); - TEST_ASSERT_MESSAGE(drv->Uninitialize() >= ARM_DRIVER_OK, cfstore_flush_utest_msg_g); - return CaseNext; -} - - -/** - * @brief test to open(create) a very large value, write the data, close, then flush. - * for a N keys simultaneously. - * - * @return on success returns CaseNext to continue to next test case, otherwise will assert on errors. - */ -control_t cfstore_flush2_test_02(const size_t call_count) -{ - (void) call_count; - //todo: implement test - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Warn: Not implemented\n", __func__); - CFSTORE_DBGLOG("%s: WARN: requires implementation\n", __func__); - TEST_ASSERT_MESSAGE(true, cfstore_flush_utest_msg_g); - return CaseNext; -} - - -/// @cond CFSTORE_DOXYGEN_DISABLE -utest::v1::status_t greentea_setup(const size_t number_of_cases) -{ - // Call the default reporting function- - GREENTEA_SETUP(100, "default_auto"); - return greentea_test_setup_handler(number_of_cases); -} - -Case cases[] = { - Case("CFSTORE_FLUSH2_test_00", cfstore_flush2_test_00), - Case("CFSTORE_FLUSH2_test_01_start", cfstore_flush2_test_01_start), - Case("CFSTORE_FLUSH2_test_01_mid", cfstore_flush2_test_01_mid), - Case("CFSTORE_FLUSH2_test_01_end", cfstore_flush2_test_01_end), - Case("CFSTORE_FLUSH2_test_02_start", cfstore_utest_default_start), - Case("CFSTORE_FLUSH2_test_02_end", cfstore_flush2_test_02), -}; - - -// Declare your test specification with a custom setup handler -Specification specification(greentea_setup, cases); - -int main() -{ - return !Harness::run(specification); -} -/// @endcond diff --git a/features/storage/FEATURE_STORAGE/TESTS/cfstore/flush3/flush3.cpp b/features/storage/FEATURE_STORAGE/TESTS/cfstore/flush3/flush3.cpp deleted file mode 100644 index 98f1b6e..0000000 --- a/features/storage/FEATURE_STORAGE/TESTS/cfstore/flush3/flush3.cpp +++ /dev/null @@ -1,867 +0,0 @@ -/* - * mbed Microcontroller Library - * Copyright (c) 2006-2016 ARM Limited - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** @file flush3.cpp Test cases to flush KVs in the CFSTORE using the drv->Flush() interface. - * - * Please consult the documentation under the test-case functions for - * a description of the individual test case. - * - * CFSTORE flash-journal sync mode test for github issue Heap Corruption by Jenia Kogan: - * https://github.com/ARMmbed/configuration-store/issues/17 - * No evidence of heap corruption has been found but the test case put together to - * investiage that problem did result in a bug being found, that being that - * when the last attribute was deleted from CFSTORE, this was not properly committed to - * flash, so that CFSTORE was re-initialised, the old attribute was read back from - * flash into the store. This has now been fixed. - */ - -#include "mbed.h" -#include "cfstore_config.h" -#include "Driver_Common.h" -#include "cfstore_debug.h" -#include "cfstore_test.h" -#include "configuration_store.h" -#include "utest/utest.h" -#include "unity/unity.h" -#include "greentea-client/test_env.h" - - -#include -#include -#include -#include - -using namespace utest::v1; - -static char cfstore_flush3_utest_msg_g[CFSTORE_UTEST_MSG_BUF_SIZE]; - -/// @cond CFSTORE_DOXYGEN_DISABLE -#ifdef CFSTORE_DEBUG -#define CFSTORE_FLUSH3_GREENTEA_TIMEOUT_S 1000 -#else -#define CFSTORE_FLUSH3_GREENTEA_TIMEOUT_S 100 -#endif -/// @endcond - -/* used for sync mode build only */ -#if defined STORAGE_DRIVER_CONFIG_HARDWARE_MTD_ASYNC_OPS && STORAGE_DRIVER_CONFIG_HARDWARE_MTD_ASYNC_OPS==0 - -#define CFSTORE_UNUSED_PARAM(param) (void)(param) - -int32_t cfstore_flush3_end(void) -{ - int32_t cfsStatus; - ARM_CFSTORE_DRIVER *cfstoreDriver = &cfstore_driver; - - CFSTORE_DBGLOG("%s:IN\n", __func__); - cfsStatus = cfstoreDriver->Uninitialize(); - if(cfsStatus < ARM_DRIVER_OK){ - CFSTORE_DBGLOG("CFStore Finalization failed (err %ld)\n", cfsStatus); - return ARM_DRIVER_ERROR; - } - CFSTORE_DBGLOG("%s:OUT:returning ARM_DRIVER_OK\n", __func__); - return ARM_DRIVER_OK; -} - - -int32_t cfstore_flush3_delete_file(const char *fileDir, size_t maxFilePathSize, const char *fileName) -{ - int32_t cfsStatus; - int32_t status = ARM_DRIVER_OK; - - ARM_CFSTORE_DRIVER *cfstoreDriver = &cfstore_driver; - ARM_CFSTORE_FMODE flags; - ARM_CFSTORE_HANDLE_INIT(hkey); - - CFSTORE_DBGLOG("%s:IN. File name %s\n", __func__, fileName); - - CFSTORE_UNUSED_PARAM(fileDir); - CFSTORE_UNUSED_PARAM(maxFilePathSize); - - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Uninitialize Cfstore\n", __func__); - TEST_ASSERT_MESSAGE(cfstoreDriver != NULL, cfstore_flush3_utest_msg_g); - - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Invalid file name\n", __func__); - TEST_ASSERT_MESSAGE(fileName != NULL, cfstore_flush3_utest_msg_g); - - memset(&flags, 0, sizeof(flags)); - flags.write = true; - cfsStatus = cfstoreDriver->Open(fileName, flags, hkey); - if (cfsStatus == ARM_CFSTORE_DRIVER_ERROR_KEY_NOT_FOUND) { - /* printf added: modification to original code supplied by Jenia Kogan. */ - CFSTORE_DBGLOG("%s: cfsStatus == ARM_CFSTORE_DRIVER_ERROR_KEY_NOT_FOUND. returning success\n", __func__); - return ARM_DRIVER_OK; - } - if(cfsStatus < ARM_DRIVER_OK){ - CFSTORE_DBGLOG("Open failed (err %ld)\n", cfsStatus); - return ARM_DRIVER_ERROR; - } - cfsStatus = cfstoreDriver->Delete(hkey); - if(cfsStatus < ARM_DRIVER_OK){ - CFSTORE_DBGLOG("Failed deleting (%s) failed (err %ld)\n", fileName, cfsStatus); - status = ARM_DRIVER_ERROR; - goto out; - } -out: - cfsStatus = cfstoreDriver->Close(hkey); - if(cfsStatus < ARM_DRIVER_OK){ - CFSTORE_DBGLOG("Close failed (err %ld)\n", cfsStatus); - return ARM_DRIVER_ERROR; - } - /* Flash-to-flash only on success */ - if (status == ARM_DRIVER_OK) { - cfsStatus = cfstoreDriver->Flush(); - if(cfsStatus < ARM_DRIVER_OK){ - CFSTORE_DBGLOG("Flush to flash failed (err %ld)\n", cfsStatus); - return ARM_DRIVER_ERROR; - } - } - CFSTORE_DBGLOG("%s:OUT: status=%d\n", __func__, (int) status); - return status; -} - - -int32_t cfstore_flush3_read_file(const char *fileDir, size_t maxFilePathSize, const char *fileName, uint8_t *buff, size_t buffSize) -{ - int32_t cfsStatus; - int32_t status = ARM_DRIVER_OK; - - ARM_CFSTORE_DRIVER *cfstoreDriver = &cfstore_driver; - ARM_CFSTORE_FMODE flags; - ARM_CFSTORE_SIZE readCount = buffSize; - ARM_CFSTORE_HANDLE_INIT(hkey); - - CFSTORE_DBGLOG("%s:IN. File name %s, buffer %p, buffsize %d\n", __func__, fileName, buff, buffSize); - - CFSTORE_UNUSED_PARAM(fileDir); - CFSTORE_UNUSED_PARAM(maxFilePathSize); - - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Uninitialize Cfstore\n", __func__); - TEST_ASSERT_MESSAGE(cfstoreDriver != NULL, cfstore_flush3_utest_msg_g); - - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Invalid file name\n", __func__); - TEST_ASSERT_MESSAGE(fileName != NULL, cfstore_flush3_utest_msg_g); - - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Invalid buff\n", __func__); - TEST_ASSERT_MESSAGE(buff != NULL, cfstore_flush3_utest_msg_g); - - memset(&flags, 0, sizeof(flags)); - flags.read = true; - - cfsStatus = cfstoreDriver->Open(fileName, flags, hkey); - if(cfsStatus == ARM_CFSTORE_DRIVER_ERROR_KEY_NOT_FOUND){ - CFSTORE_DBGLOG("File (%s) not found (err %ld)\n", fileName, cfsStatus); - return ARM_CFSTORE_DRIVER_ERROR_KEY_NOT_FOUND; - - } - if(cfsStatus < ARM_DRIVER_OK){ - CFSTORE_DBGLOG("Open failed (err %ld)\n", cfsStatus); - return ARM_DRIVER_ERROR; - } - cfsStatus = cfstoreDriver->Read(hkey, buff, &readCount); - if(cfsStatus < ARM_DRIVER_OK){ - CFSTORE_DBGLOG("Read failed (err %ld)\n", cfsStatus); - status = ARM_DRIVER_ERROR; - goto out; - } - if(readCount < buffSize){ - CFSTORE_DBGLOG("Read failed, amount is %zu while requested %zu\n", readCount, buffSize); - status = ARM_DRIVER_ERROR; - goto out; - } -out: - cfsStatus = cfstoreDriver->Close(hkey); - if(cfsStatus < ARM_DRIVER_OK){ - CFSTORE_DBGLOG("Close failed (err %ld)\n", cfsStatus); - return ARM_DRIVER_ERROR; - } - CFSTORE_DBGLOG("%s:OUT: status=%d\n", __func__, (int) status); - return status; -} - -int32_t cfstore_flush3_write_file(const char *fileDir, size_t maxFilePathSize, const char *fileName, const uint8_t *buff, size_t buffSize) -{ - int32_t cfsStatus; - int32_t status = ARM_DRIVER_ERROR; - - ARM_CFSTORE_DRIVER *cfstoreDriver = &cfstore_driver; - ARM_CFSTORE_SIZE writeCount = buffSize; - ARM_CFSTORE_KEYDESC keyDesc; - ARM_CFSTORE_HANDLE_INIT(hkey); - - CFSTORE_DBGLOG("%s:IN. File name %s, buffer %p, buffsize %d\n", __func__, fileName, buff, buffSize); - - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Uninitialize Cfstore\n", __func__); - TEST_ASSERT_MESSAGE(cfstoreDriver != NULL, cfstore_flush3_utest_msg_g); - - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Invalid file name\n", __func__); - TEST_ASSERT_MESSAGE(fileName != NULL, cfstore_flush3_utest_msg_g); - - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Invalid buff\n", __func__); - TEST_ASSERT_MESSAGE(buff != NULL, cfstore_flush3_utest_msg_g); - - /* We always deleting the old file and recreating a new one to preserve simplicity */ - CFSTORE_DBGLOG("Before delete%s", "\n"); - - /* Delete the old file */ - status = cfstore_flush3_delete_file(fileDir, maxFilePathSize, fileName); - if(status != ARM_DRIVER_OK){ - CFSTORE_DBGLOG("Failed deleting (%s)\n", fileName); - return status; - } - - CFSTORE_DBGLOG("After delete%s", "\n"); - /* Create a new file */ - memset(&keyDesc, 0, sizeof(keyDesc)); - keyDesc.drl = ARM_RETENTION_NVM; - keyDesc.flags.read = true; - keyDesc.flags.write = true; - cfsStatus = cfstoreDriver->Create(fileName, buffSize, &keyDesc, hkey); - if(cfsStatus < ARM_DRIVER_OK){ - CFSTORE_DBGLOG("Fail creating (%s) key-store (%ld)\n", fileName, cfsStatus); - return ARM_DRIVER_ERROR; - } - CFSTORE_DBGLOG("After create%s", "\n"); - cfsStatus = cfstoreDriver->Write(hkey, (const char *)buff, &writeCount); - if(cfsStatus < ARM_DRIVER_OK){ - CFSTORE_DBGLOG("Write failed (err %ld)\n", cfsStatus); - status = ARM_DRIVER_ERROR; - goto out; - } - if(writeCount != buffSize){ - CFSTORE_DBGLOG("Write failed, amount is %d while requested is %d\n", (int)writeCount, (int)buffSize); - status = ARM_DRIVER_ERROR; - goto out; - } - CFSTORE_DBGLOG("After write%s", "\n"); -out: - cfsStatus = cfstoreDriver->Close(hkey); - if(cfsStatus < ARM_DRIVER_OK){ - CFSTORE_DBGLOG("Close failed (err %ld)\n", cfsStatus); - return ARM_DRIVER_ERROR; - } - CFSTORE_DBGLOG("After close%s", "\n"); - /* Flash-to-flash only on success */ - if (status == ARM_DRIVER_OK) { - cfsStatus = cfstoreDriver->Flush(); - if(cfsStatus < ARM_DRIVER_OK){ - CFSTORE_DBGLOG("Flush to flash failed(err %ld)\n", cfsStatus); - return ARM_DRIVER_ERROR; - } - CFSTORE_DBGLOG("After flush%s", "\n"); - } - CFSTORE_DBGLOG("%s:OUT: status=%d\n", __func__, (int) status); - return status; -} - - -int32_t cfstore_flush3_start(void) -{ - int32_t status = ARM_DRIVER_OK; - int32_t cfsStatus; - ARM_CFSTORE_DRIVER *cfstoreDriver = &cfstore_driver; - ARM_CFSTORE_CAPABILITIES caps; - - CFSTORE_DBGLOG("%s:IN\n", __func__); - - /* Initialize configuration store */ - cfsStatus = cfstoreDriver->Initialize(NULL, NULL); - if(cfsStatus < ARM_DRIVER_OK){ - CFSTORE_DBGLOG("CFStore Initialization failed (err %lu)\n", cfsStatus); - return ARM_DRIVER_ERROR; - } - /* Get capabilities */ - memset(&caps, 0, sizeof(caps)); - caps = cfstoreDriver->GetCapabilities(); - if(caps.asynchronous_ops == true){ - CFSTORE_DBGLOG("%s:Please configure CFstore to work in synchronous mode. This can be change in config.json file.\n", __func__); - status = ARM_DRIVER_ERROR; - goto out; - } - CFSTORE_DBGLOG("%s:OUT: returning ARM_DRIVER_OK\n", __func__); - return ARM_DRIVER_OK; /* init succeeded */ - -out: - /* init failed */ - (void) cfstore_flush3_end(); - CFSTORE_DBGLOG("%s:OUT: status=%d\n", __func__, (int) status); - return status; -} - -int32_t cfstore_flush3_check_data(uint8_t* data, int32_t len, uint8_t val) -{ - int i; - for(i = 0; i < len; i++) { - if(data[i] != val){ - /* found byte which doesnt have the expected data value */ - return ARM_DRIVER_ERROR; - } - } - return ARM_DRIVER_OK; -} - -/* @brief test case to recreate the transactions documented in the - * issue 17 trace log. - * - * the test case was created by recreating the entries found in the - * log report grepped from the trace log attached to githug issue 17: - * 20160622_1321_grep_pv_configuration_store_issue_17_heap_corruption.txt - * - * This is what the test is intended to do: - * - A (setup) - * - cfstore_flush3_start - * - cfstore_flush3_write_file(com.arm.mbed.spv.sst.meta, len: 2280) to create KV - * - cfstore_flush3_write_file(com.arm.mbed.spv.sst.node.0, len: 220) to create KV - * - cfstore_flush3_end - * - B (setup?) - * - cfstore_flush3_start - * - cfstore_flush3_read_file(com.arm.mbed.spv.sst.meta) - * - cfstore_flush3_read_file(com.arm.mbed.spv.sst.node.0) - * - cfstore_flush3_end - * - C (delete everything) - * - cfstore_flush3_start - * - cfstore_flush3_delete_file(com.arm.mbed.spv.sst.node.0). this will work as the KV is present - * - cfstore_flush3_delete_file(com.arm.mbed.spv.sst.node.x) where x = {1..29} - * - cfstore_flush3_delete_file(name com.arm.mbed.spv.sst.meta). - * - this should work as the KV is present - * - however, its is seen to fail in the trace log for the issue. - * - cfstore_flush3_end - * - D - * - cfstore_flush3_start - * - cfstore_flush3_read_file(com.arm.mbed.spv.sst.meta). readd 2280 bytes and check correct - * - this should fail as the kv has been deleted. - * - cfstore_flush3_write_file(com.arm.mbed.spv.sst.node.0, len: 220) to create KV - * - cfstore_flush3_write_file(com.arm.mbed.spv.sst.meta, len: 2280) to create KV - * - cfstore_flush3_end - * - E - * - run C-D again, to delete everything - * - F - * - cfstore_flush3_start - * - cfstore_flush3_read_file(com.arm.mbed.spv.sst.meta). readd 2280 bytes and check correct - * - this should fail as the kv has been deleted. - * - cfstore_flush3_write_file(com.arm.mbed.spv.sst.node.0, len: 220) to create KV - * - cfstore_flush3_write_file(com.arm.mbed.spv.sst.meta, len: 2280) to create KV - * - cfstore_flush3_write_file(com.arm.mbed.spv.sst.node.0, len: 816) to create KV - * - cfstore_flush3_write_file(com.arm.mbed.spv.sst.meta, len: 2280) to create KV - * - cfstore_flush3_write_file(com.arm.mbed.spv.sst.node.1, len: 217) to create KV - * - cfstore_flush3_write_file(com.arm.mbed.spv.sst.meta, len: 2280) to create KV - * - cfstore_flush3_write_file(com.arm.mbed.spv.sst.node.0, len: 818) to create KV - * - cfstore_flush3_write_file(com.arm.mbed.spv.sst.meta, len: 2280) to create KV - * - cfstore_flush3_end - * - G - * - cfstore_flush3_start - * - cfstore_flush3_read_file(com.arm.mbed.spv.sst.meta) 2280 bytes should be read - * - cfstore_flush3_read_file(com.arm.mbed.spv.sst.node.0) 818 bytes should be read - * - cfstore_flush3_read_file(com.arm.mbed.spv.sst.node.1) 217 bytes should be read - * - cfstore_flush3_read_file(com.arm.mbed.spv.sst.node.1) 217 bytes should be read - * - cfstore_flush3_read_file(com.arm.mbed.spv.sst.node.1) 217 bytes should be read - * - cfstore_flush3_read_file(com.arm.mbed.spv.sst.node.1) 217 bytes should be read - * - cfstore_flush3_write_file(com.arm.mbed.spv.sst.node.2, len: 235) to create KV - * - cfstore_flush3_write_file(com.arm.mbed.spv.sst.meta, len: 2280) to create KV - * - cfstore_flush3_end - * - * The issue reported heap corruption. To this end, a heap buffer - * is allocated and checked as a canary against heap corruption - */ - -#define CFSTORE_FLUSH3_TEST_DATA_CHAR 'A' /* 0b1010 bit pattern */ -#define CFSTORE_FLUSH3_HEAP_DATA_CHAR 'Z' -#define CFSTORE_FLUSH3_TEST_DATA_BUF_LEN 3000 /* 2280 was the largest buffer used*/ - -#ifdef TARGET_K64F -#define CFSTORE_FLUSH3_TEST_HEAP_BUF_LEN 87500 /* alloc a heap buffer to use up some memory: value tuned to K64F */ -#else -#define CFSTORE_FLUSH3_TEST_HEAP_BUF_LEN 1000 /* alloc a heap buffer to use up some memory (minimal for non-k64f targets until tuned */ -#endif /* TARGET_K64F */ - -static control_t cfstore_flush3_test_01(const size_t call_count) -{ - int32_t i; - int32_t ret = ARM_DRIVER_ERROR; - const char* kv_name_root = "com.arm.mbed.spv.sst"; - const char* kv_name_node= "node"; - const char* kv_name_meta= "meta"; - char kv_name[CFSTORE_KEY_NAME_MAX_LENGTH+1]; - uint8_t data[CFSTORE_FLUSH3_TEST_DATA_BUF_LEN]; - void* heap_buf = NULL; - - (void) call_count; - heap_buf = malloc(CFSTORE_FLUSH3_TEST_HEAP_BUF_LEN); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: malloc() failed .\n", __func__); - TEST_ASSERT_MESSAGE(heap_buf != NULL, cfstore_flush3_utest_msg_g); - memset(heap_buf, CFSTORE_FLUSH3_HEAP_DATA_CHAR, CFSTORE_FLUSH3_TEST_HEAP_BUF_LEN); - - CFSTORE_DBGLOG("%s: - A (setup)\n", __func__); - CFSTORE_DBGLOG("%s: - cfstore_flush3_start\n", __func__); - ret = cfstore_flush3_start(); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: A.1 cfstore_flush3_start() failed (ret=%d).\n", __func__, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush3_utest_msg_g); - - CFSTORE_DBGLOG("%s: cfstore_flush3_write_file(com.arm.mbed.spv.sst.meta, len: 2280) to create KV\n", __func__); - memset(data, CFSTORE_FLUSH3_TEST_DATA_CHAR, CFSTORE_FLUSH3_TEST_DATA_BUF_LEN); - snprintf(kv_name, CFSTORE_KEY_NAME_MAX_LENGTH, "%s.%s", (char*) kv_name_root, kv_name_meta); - ret = cfstore_flush3_write_file(NULL, CFSTORE_KEY_NAME_MAX_LENGTH, (const char*) kv_name, (const uint8_t*) data, 2280); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: A.2 cfstore_flush3_write_file() failed (ret=%d, kv_name=%s).\n", __func__, (int) ret, kv_name); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush3_utest_msg_g); - - CFSTORE_DBGLOG("%s: cfstore_flush3_write_file(com.arm.mbed.spv.sst.node.0, len: 220) to create KV\n", __func__); - snprintf(kv_name, CFSTORE_KEY_NAME_MAX_LENGTH, "%s.%s.0", (char*) kv_name_root, (char*) kv_name_node); - ret = cfstore_flush3_write_file(NULL, CFSTORE_KEY_NAME_MAX_LENGTH, (const char*) kv_name, (const uint8_t*) data, 220); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: A.3 cfstore_flush3_write_file() failed (ret=%d, kv_name=%s).\n", __func__, (int) ret, kv_name); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush3_utest_msg_g); - - CFSTORE_DBGLOG("%s: - cfstore_flush3_end\n", __func__); - ret = cfstore_flush3_end(); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: A.4 cfstore_flush3_end() failed (ret=%d).\n", __func__, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush3_utest_msg_g); - - CFSTORE_DBGLOG("%s: check for heap corruption\n", __func__); - ret = cfstore_flush3_check_data((uint8_t*) heap_buf, CFSTORE_FLUSH3_TEST_HEAP_BUF_LEN, CFSTORE_FLUSH3_HEAP_DATA_CHAR); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: A.5 cfstore_flush3_check_data() failed for heap (ret=%d, kv_name=%s).\n", __func__, (int) ret, kv_name); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush3_utest_msg_g); - - CFSTORE_DBGLOG("%s: - B\n", __func__); - CFSTORE_DBGLOG("%s: - cfstore_flush3_start\n", __func__); - ret = cfstore_flush3_start(); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: B.1 cfstore_flush3_start() failed (ret=%d).\n", __func__, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush3_utest_msg_g); - - CFSTORE_DBGLOG("%s: cfstore_flush3_read_file(com.arm.mbed.spv.sst.meta). read 2280\n", __func__); - memset(data, 0, CFSTORE_FLUSH3_TEST_DATA_BUF_LEN); - snprintf(kv_name, CFSTORE_KEY_NAME_MAX_LENGTH, "%s.%s", (char*) kv_name_root, (char*) kv_name_meta); - ret = cfstore_flush3_read_file(NULL, CFSTORE_KEY_NAME_MAX_LENGTH, (const char*) kv_name, data, 2280); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: B.2 cfstore_flush3_read_file() failed (ret=%d, kv_name=%s).\n", __func__, (int) ret, kv_name); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush3_utest_msg_g); - - ret = cfstore_flush3_check_data(data, 2280, CFSTORE_FLUSH3_TEST_DATA_CHAR); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: B.3 cfstore_flush3_check_data() failed (ret=%d, kv_name=%s).\n", __func__, (int) ret, kv_name); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush3_utest_msg_g); - - CFSTORE_DBGLOG("%s: cfstore_flush3_read_file(com.arm.mbed.spv.sst.node.0). read 220\n", __func__); - memset(data, 0, CFSTORE_FLUSH3_TEST_DATA_BUF_LEN); - snprintf(kv_name, CFSTORE_KEY_NAME_MAX_LENGTH, "%s.%s.0", (char*) kv_name_root, (char*) kv_name_node); - ret = cfstore_flush3_read_file(NULL, CFSTORE_KEY_NAME_MAX_LENGTH, (const char*) kv_name, data, 220); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: B.4 cfstore_flush3_read_file() failed (ret=%d, kv_name=%s).\n", __func__, (int) ret, kv_name); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush3_utest_msg_g); - - ret = cfstore_flush3_check_data(data, 220, CFSTORE_FLUSH3_TEST_DATA_CHAR); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: B.5 cfstore_flush3_check_data() failed (ret=%d, kv_name=%s).\n", __func__, (int) ret, kv_name); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush3_utest_msg_g); - - CFSTORE_DBGLOG("%s: - cfstore_flush3_end\n", __func__); - ret = cfstore_flush3_end(); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: B.6 cfstore_flush3_end() failed (ret=%d).\n", __func__, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush3_utest_msg_g); - - CFSTORE_DBGLOG("%s: check for heap corruption\n", __func__); - ret = cfstore_flush3_check_data((uint8_t*) heap_buf, CFSTORE_FLUSH3_TEST_HEAP_BUF_LEN, CFSTORE_FLUSH3_HEAP_DATA_CHAR); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: B.7 cfstore_flush3_check_data() failed for heap (ret=%d, kv_name=%s).\n", __func__, (int) ret, kv_name); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush3_utest_msg_g); - - CFSTORE_DBGLOG("%s: - C (delete everything)\n", __func__); - CFSTORE_DBGLOG("%s: - cfstore_flush3_start\n", __func__); - ret = cfstore_flush3_start(); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: C.1 cfstore_flush3_start() failed (ret=%d).\n", __func__, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush3_utest_msg_g); - - CFSTORE_DBGLOG("%s: cfstore_flush3_delete_file(com.arm.mbed.spv.sst.node.0). this will work as the KV is present\n", __func__); - snprintf(kv_name, CFSTORE_KEY_NAME_MAX_LENGTH, "%s.%s.0", (char*) kv_name_root, (char*) kv_name_node); - ret = cfstore_flush3_delete_file(NULL, CFSTORE_KEY_NAME_MAX_LENGTH, (const char*) kv_name); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: C.2 cfstore_flush3_delete_file() failed (ret=%d, kv_name=%s).\n", __func__, (int) ret, kv_name); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush3_utest_msg_g); - - CFSTORE_DBGLOG("%s: cfstore_flush3_delete_file(com.arm.mbed.spv.sst.node.x) where x = {1..29}, each of which should fail\n", __func__); - for(i = 1; i <= 29; i++){ - snprintf(kv_name, CFSTORE_KEY_NAME_MAX_LENGTH, "%s.%s.%d", (char*) kv_name_root, (char*) kv_name_node, (int) i); - ret = cfstore_flush3_delete_file(NULL, CFSTORE_KEY_NAME_MAX_LENGTH, (const char*) kv_name); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: C.%d cfstore_flush3_delete_file() failed (ret=%d, kv_name=%s).\n", __func__, (int) i+2, (int) ret, kv_name); - /* The delete operations are expected to fail as the keys dont exist - * but cfstore_flush3_delete_file() returns ARM_DRIVER_OK when key isnt found, so cant test the return code. - */ - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush3_utest_msg_g); - } - - CFSTORE_DBGLOG("%s: cfstore_flush3_delete_file(name com.arm.mbed.spv.sst.meta). this is expected to succeed as the KV is present\n", __func__); - snprintf(kv_name, CFSTORE_KEY_NAME_MAX_LENGTH, "%s.%s", (char*) kv_name_root, (char*) kv_name_meta); - ret = cfstore_flush3_delete_file(NULL, CFSTORE_KEY_NAME_MAX_LENGTH, (const char*) kv_name); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: C.32 cfstore_flush3_delete_file() failed (ret=%d, kv_name=%s).\n", __func__, (int) ret, kv_name); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush3_utest_msg_g); - -#ifdef CFSTORE_DEBUG - CFSTORE_DBGLOG("%s: cfstore_test_dump: dump here contents of CFSTORE so we know whats present\n", __func__); - ret = cfstore_test_dump(); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: D.1.1 cfstore_test_dump failed (ret=%d).\n", __func__, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush3_utest_msg_g); -#endif /* CFSTORE_DEBUG */ - - CFSTORE_DBGLOG("%s: - cfstore_flush3_end\n", __func__); - ret = cfstore_flush3_end(); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: C.33 cfstore_flush3_end() failed (ret=%d, kv_name=%s).\n", __func__, (int) ret, kv_name); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush3_utest_msg_g); - - CFSTORE_DBGLOG("%s: check for heap corruption\n", __func__); - ret = cfstore_flush3_check_data((uint8_t*) heap_buf, CFSTORE_FLUSH3_TEST_HEAP_BUF_LEN, CFSTORE_FLUSH3_HEAP_DATA_CHAR); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: C.34 cfstore_flush3_check_data() failed for heap (ret=%d, kv_name=%s).\n", __func__, (int) ret, kv_name); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush3_utest_msg_g); - - CFSTORE_DBGLOG("%s: - D\n", __func__); - CFSTORE_DBGLOG("%s: - cfstore_flush3_start\n", __func__); - ret = cfstore_flush3_start(); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: D.1 cfstore_flush3_start() failed (ret=%d, kv_name=%s).\n", __func__, (int) ret, kv_name); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush3_utest_msg_g); - -#ifdef CFSTORE_DEBUG - CFSTORE_DBGLOG("%s: cfstore_test_dump: dump here contents of CFSTORE so we know whats present\n", __func__); - ret = cfstore_test_dump(); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: D.1.1 cfstore_test_dump failed (ret=%d).\n", __func__, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush3_utest_msg_g); -#endif /* CFSTORE_DEBUG */ - - CFSTORE_DBGLOG("%s: cfstore_flush3_read_file(com.arm.mbed.spv.sst.meta). this should fail as the kv has been deleted.\n", __func__); - memset(data, 0, CFSTORE_FLUSH3_TEST_DATA_BUF_LEN); - snprintf(kv_name, CFSTORE_KEY_NAME_MAX_LENGTH, "%s.%s", (char*) kv_name_root, (char*) kv_name_meta); - ret = cfstore_flush3_read_file(NULL, CFSTORE_KEY_NAME_MAX_LENGTH, (const char*) kv_name, data, 2280); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: D.2 cfstore_flush3_read_file() succeeded when expected to fail (ret=%d, kv_name=%s).\n", __func__, (int) ret, kv_name); - TEST_ASSERT_MESSAGE(ret < ARM_DRIVER_OK, cfstore_flush3_utest_msg_g); - - CFSTORE_DBGLOG("%s: cfstore_flush3_write_file(com.arm.mbed.spv.sst.node.0, len: 220) to create KV.\n", __func__); - memset(data, CFSTORE_FLUSH3_TEST_DATA_CHAR, CFSTORE_FLUSH3_TEST_DATA_BUF_LEN); - snprintf(kv_name, CFSTORE_KEY_NAME_MAX_LENGTH, "%s.%s.0", (char*) kv_name_root, (char*) kv_name_node); - ret = cfstore_flush3_write_file(NULL, CFSTORE_KEY_NAME_MAX_LENGTH, (const char*) kv_name, (const uint8_t*) data, 220); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: D.3 cfstore_flush3_write_file() failed (ret=%d, kv_name=%s).\n", __func__, (int) ret, kv_name); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush3_utest_msg_g); - - CFSTORE_DBGLOG("%s: cfstore_flush3_write_file(com.arm.mbed.spv.sst.meta, len: 2280) to create KV.\n", __func__); - memset(data, CFSTORE_FLUSH3_TEST_DATA_CHAR, CFSTORE_FLUSH3_TEST_DATA_BUF_LEN); - snprintf(kv_name, CFSTORE_KEY_NAME_MAX_LENGTH, "%s.%s", (char*) kv_name_root, (char*) kv_name_meta); - ret = cfstore_flush3_write_file(NULL, CFSTORE_KEY_NAME_MAX_LENGTH, (const char*) kv_name, (const uint8_t*) data, 2280); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: D.4 cfstore_flush3_write_file() failed (ret=%d, kv_name=%s).\n", __func__, (int) ret, kv_name); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush3_utest_msg_g); - - CFSTORE_DBGLOG("%s: - cfstore_flush3_end\n", __func__); - ret = cfstore_flush3_end(); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: D.5 cfstore_flush3_end() failed (ret=%d).\n", __func__, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush3_utest_msg_g); - - CFSTORE_DBGLOG("%s: check for heap corruption\n", __func__); - ret = cfstore_flush3_check_data((uint8_t*) heap_buf, CFSTORE_FLUSH3_TEST_HEAP_BUF_LEN, CFSTORE_FLUSH3_HEAP_DATA_CHAR); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: D.6 cfstore_flush3_check_data() failed for heap (ret=%d, kv_name=%s).\n", __func__, (int) ret, kv_name); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush3_utest_msg_g); - - CFSTORE_DBGLOG("%s: - E: run C-D again, to delete everything\n", __func__); - CFSTORE_DBGLOG("%s: - cfstore_flush3_start\n", __func__); - ret = cfstore_flush3_start(); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: E.1 cfstore_flush3_start() failed (ret=%d).\n", __func__, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush3_utest_msg_g); - - CFSTORE_DBGLOG("%s: cfstore_flush3_delete_file(com.arm.mbed.spv.sst.node.0). this will work as the KV is present.\n", __func__); - snprintf(kv_name, CFSTORE_KEY_NAME_MAX_LENGTH, "%s.%s.0", (char*) kv_name_root, (char*) kv_name_node); - ret = cfstore_flush3_delete_file(NULL, CFSTORE_KEY_NAME_MAX_LENGTH, (const char*) kv_name); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: E.2 cfstore_flush3_delete_file() failed (ret=%d, kv_name=%s).\n", __func__, (int) ret, kv_name); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush3_utest_msg_g); - - CFSTORE_DBGLOG("%s: cfstore_flush3_delete_file(com.arm.mbed.spv.sst.node.x) where x = {1..29}, each of which should fail.\n", __func__); - for(i = 1; i <= 29; i++){ - snprintf(kv_name, CFSTORE_KEY_NAME_MAX_LENGTH, "%s.%s.%d", (char*) kv_name_root, (char*) kv_name_node, (int) i); - ret = cfstore_flush3_delete_file(NULL, CFSTORE_KEY_NAME_MAX_LENGTH, (const char*) kv_name); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: E.%d cfstore_flush3_delete_file() failed (ret=%d, kv_name=%s).\n", __func__, (int) i+2, (int) ret, kv_name); - /* The delete operations are expected to fail as the keys dont exist - * but cfstore_flush3_delete_file() returns ARM_DRIVER_OK when key isnt found, so cant test the return code. - */ - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush3_utest_msg_g); - } - - CFSTORE_DBGLOG("%s: cfstore_flush3_delete_file(name com.arm.mbed.spv.sst.meta). this is expected to succeed as the KV is present.\n", __func__); - snprintf(kv_name, CFSTORE_KEY_NAME_MAX_LENGTH, "%s.%s", (char*) kv_name_root, (char*) kv_name_meta); - ret = cfstore_flush3_delete_file(NULL, CFSTORE_KEY_NAME_MAX_LENGTH, (const char*) kv_name); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: E.32 cfstore_flush3_delete_file() failed (ret=%d, kv_name=%s).\n", __func__, (int) ret, kv_name); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush3_utest_msg_g); - - CFSTORE_DBGLOG("%s: - cfstore_flush3_end\n", __func__); - ret = cfstore_flush3_end(); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: E.33 cfstore_flush3_end() failed (ret=%d, kv_name=%s).\n", __func__, (int) ret, kv_name); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush3_utest_msg_g); - - CFSTORE_DBGLOG("%s: check for heap corruption\n", __func__); - ret = cfstore_flush3_check_data((uint8_t*) heap_buf, CFSTORE_FLUSH3_TEST_HEAP_BUF_LEN, CFSTORE_FLUSH3_HEAP_DATA_CHAR); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: E.34 cfstore_flush3_check_data() failed for heap (ret=%d, kv_name=%s).\n", __func__, (int) ret, kv_name); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush3_utest_msg_g); - - CFSTORE_DBGLOG("%s: - F\n", __func__); - CFSTORE_DBGLOG("%s: - cfstore_flush3_start\n", __func__); - ret = cfstore_flush3_start(); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: F.1 cfstore_flush3_start() failed (ret=%d).\n", __func__, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush3_utest_msg_g); - - CFSTORE_DBGLOG("%s: cfstore_flush3_read_file(com.arm.mbed.spv.sst.meta). this should fail as the kv has been deleted.\n", __func__); - memset(data, 0, CFSTORE_FLUSH3_TEST_DATA_BUF_LEN); - snprintf(kv_name, CFSTORE_KEY_NAME_MAX_LENGTH, "%s.%s", (char*) kv_name_root, (char*) kv_name_meta); - ret = cfstore_flush3_read_file(NULL, CFSTORE_KEY_NAME_MAX_LENGTH, (const char*) kv_name, data, 2280); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: F.2 cfstore_flush3_read_file() succeeded when expected to fail (ret=%d, kv_name=%s).\n", __func__, (int) ret, kv_name); - TEST_ASSERT_MESSAGE(ret < ARM_DRIVER_OK, cfstore_flush3_utest_msg_g); - - memset(data, CFSTORE_FLUSH3_TEST_DATA_CHAR, CFSTORE_FLUSH3_TEST_DATA_BUF_LEN); - /* cfstore_flush3_write_file(com.arm.mbed.spv.sst.node.0, len: 220) to create KV */ - snprintf(kv_name, CFSTORE_KEY_NAME_MAX_LENGTH, "%s.%s.0", (char*) kv_name_root, (char*) kv_name_node); - ret = cfstore_flush3_write_file(NULL, CFSTORE_KEY_NAME_MAX_LENGTH, (const char*) kv_name, (const uint8_t*) data, 220); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: F.3 cfstore_flush3_write_file() failed (ret=%d, kv_name=%s).\n", __func__, (int) ret, kv_name); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush3_utest_msg_g); - - CFSTORE_DBGLOG("%s: cfstore_flush3_write_file(com.arm.mbed.spv.sst.meta, len: 2280) to create KV.\n", __func__); - snprintf(kv_name, CFSTORE_KEY_NAME_MAX_LENGTH, "%s.%s", (char*) kv_name_root, (char*) kv_name_meta); - ret = cfstore_flush3_write_file(NULL, CFSTORE_KEY_NAME_MAX_LENGTH, (const char*) kv_name, (const uint8_t*) data, 2280); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: F.4 cfstore_flush3_write_file() failed (ret=%d, kv_name=%s).\n", __func__, (int) ret, kv_name); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush3_utest_msg_g); - - CFSTORE_DBGLOG("%s: cfstore_flush3_write_file(com.arm.mbed.spv.sst.node.0, len: 816) to create KV.\n", __func__); - snprintf(kv_name, CFSTORE_KEY_NAME_MAX_LENGTH, "%s.%s.0", (char*) kv_name_root, (char*) kv_name_node); - ret = cfstore_flush3_write_file(NULL, CFSTORE_KEY_NAME_MAX_LENGTH, (const char*) kv_name, (const uint8_t*) data, 816); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: F.5 cfstore_flush3_write_file() failed (ret=%d, kv_name=%s).\n", __func__, (int) ret, kv_name); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush3_utest_msg_g); - - CFSTORE_DBGLOG("%s: cfstore_flush3_write_file(com.arm.mbed.spv.sst.meta, len: 2280) to create KV.\n", __func__); - snprintf(kv_name, CFSTORE_KEY_NAME_MAX_LENGTH, "%s.%s", (char*) kv_name_root, (char*) kv_name_meta); - ret = cfstore_flush3_write_file(NULL, CFSTORE_KEY_NAME_MAX_LENGTH, (const char*) kv_name, (const uint8_t*) data, 2280); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: F.6 cfstore_flush3_write_file() failed (ret=%d, kv_name=%s).\n", __func__, (int) ret, kv_name); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush3_utest_msg_g); - - CFSTORE_DBGLOG("%s: cfstore_flush3_write_file(com.arm.mbed.spv.sst.node.1, len: 217) to create KV.\n", __func__); - snprintf(kv_name, CFSTORE_KEY_NAME_MAX_LENGTH, "%s.%s.1", (char*) kv_name_root, (char*) kv_name_node); - ret = cfstore_flush3_write_file(NULL, CFSTORE_KEY_NAME_MAX_LENGTH, (const char*) kv_name, (const uint8_t*) data, 217); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: F.7 cfstore_flush3_write_file() failed (ret=%d, kv_name=%s).\n", __func__, (int) ret, kv_name); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush3_utest_msg_g); - - CFSTORE_DBGLOG("%s: cfstore_flush3_write_file(com.arm.mbed.spv.sst.meta, len: 2280) to create KV.\n", __func__); - snprintf(kv_name, CFSTORE_KEY_NAME_MAX_LENGTH, "%s.%s", (char*) kv_name_root, (char*) kv_name_meta); - ret = cfstore_flush3_write_file(NULL, CFSTORE_KEY_NAME_MAX_LENGTH, (const char*) kv_name, (const uint8_t*) data, 2280); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: F.8 cfstore_flush3_write_file() failed (ret=%d, kv_name=%s).\n", __func__, (int) ret, kv_name); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush3_utest_msg_g); - - CFSTORE_DBGLOG("%s: cfstore_flush3_write_file(com.arm.mbed.spv.sst.node.0, len: 818) to create KV.\n", __func__); - snprintf(kv_name, CFSTORE_KEY_NAME_MAX_LENGTH, "%s.%s.0", (char*) kv_name_root, (char*) kv_name_node); - ret = cfstore_flush3_write_file(NULL, CFSTORE_KEY_NAME_MAX_LENGTH, (const char*) kv_name, (const uint8_t*) data, 818); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: F.9 cfstore_flush3_write_file() failed (ret=%d, kv_name=%s).\n", __func__, (int) ret, kv_name); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush3_utest_msg_g); - - CFSTORE_DBGLOG("%s: cfstore_flush3_write_file(com.arm.mbed.spv.sst.meta, len: 2280) to create KV.\n", __func__); - snprintf(kv_name, CFSTORE_KEY_NAME_MAX_LENGTH, "%s.%s", (char*) kv_name_root, (char*) kv_name_meta); - ret = cfstore_flush3_write_file(NULL, CFSTORE_KEY_NAME_MAX_LENGTH, (const char*) kv_name, (const uint8_t*) data, 2280); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: F.10 cfstore_flush3_write_file() failed (ret=%d, kv_name=%s).\n", __func__, (int) ret, kv_name); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush3_utest_msg_g); - - CFSTORE_DBGLOG("%s: - cfstore_flush3_end\n", __func__); - ret = cfstore_flush3_end(); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: F.11 cfstore_flush3_end() failed (ret=%d, kv_name=%s).\n", __func__, (int) ret, kv_name); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush3_utest_msg_g); - - CFSTORE_DBGLOG("%s: check for heap corruption\n", __func__); - ret = cfstore_flush3_check_data((uint8_t*) heap_buf, CFSTORE_FLUSH3_TEST_HEAP_BUF_LEN, CFSTORE_FLUSH3_HEAP_DATA_CHAR); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: F.12 cfstore_flush3_check_data() failed for heap (ret=%d, kv_name=%s).\n", __func__, (int) ret, kv_name); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush3_utest_msg_g); - - CFSTORE_DBGLOG("%s: - G\n", __func__); - CFSTORE_DBGLOG("%s: - cfstore_flush3_start\n", __func__); - ret = cfstore_flush3_start(); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: G.1 cfstore_flush3_start() failed (ret=%d).\n", __func__, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush3_utest_msg_g); - - CFSTORE_DBGLOG("%s: cfstore_flush3_read_file(com.arm.mbed.spv.sst.meta) 2280 bytes should be read.\n", __func__); - memset(data, 0, CFSTORE_FLUSH3_TEST_DATA_BUF_LEN); - snprintf(kv_name, CFSTORE_KEY_NAME_MAX_LENGTH, "%s.%s", (char*) kv_name_root, (char*) kv_name_meta); - ret = cfstore_flush3_read_file(NULL, CFSTORE_KEY_NAME_MAX_LENGTH, (const char*) kv_name, data, 2280); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: G.2 cfstore_flush3_read_file() failed (ret=%d, kv_name=%s).\n", __func__, (int) ret, kv_name); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush3_utest_msg_g); - - ret = cfstore_flush3_check_data(data, 2280, CFSTORE_FLUSH3_TEST_DATA_CHAR); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: G.3 cfstore_flush3_check_data() failed (ret=%d, kv_name=%s).\n", __func__, (int) ret, kv_name); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush3_utest_msg_g); - - CFSTORE_DBGLOG("%s: cfstore_flush3_read_file(com.arm.mbed.spv.sst.node.0) 818 bytes should be read.\n", __func__); - memset(data, 0, CFSTORE_FLUSH3_TEST_DATA_BUF_LEN); - snprintf(kv_name, CFSTORE_KEY_NAME_MAX_LENGTH, "%s.%s.0", (char*) kv_name_root, (char*) kv_name_node); - ret = cfstore_flush3_read_file(NULL, CFSTORE_KEY_NAME_MAX_LENGTH, (const char*) kv_name, data, 818); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: G.4 cfstore_flush3_read_file() failed (ret=%d, kv_name=%s).\n", __func__, (int) ret, kv_name); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush3_utest_msg_g); - - ret = cfstore_flush3_check_data(data, 818, CFSTORE_FLUSH3_TEST_DATA_CHAR); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: G.5 cfstore_flush3_check_data() failed (ret=%d, kv_name=%s).\n", __func__, (int) ret, kv_name); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush3_utest_msg_g); - - CFSTORE_DBGLOG("%s: cfstore_flush3_read_file(com.arm.mbed.spv.sst.node.1) 217 bytes should be read. repeat 4 times.\n", __func__); - for(i = 0; i < 4; i++){ - memset(data, 0, CFSTORE_FLUSH3_TEST_DATA_BUF_LEN); - snprintf(kv_name, CFSTORE_KEY_NAME_MAX_LENGTH, "%s.%s.1", (char*) kv_name_root, (char*) kv_name_node); - ret = cfstore_flush3_read_file(NULL, CFSTORE_KEY_NAME_MAX_LENGTH, (const char*) kv_name, data, 217); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: G.%d.1 cfstore_flush3_read_file() failed (ret=%d, kv_name=%s).\n", __func__, (int) i+6, (int) ret, kv_name); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush3_utest_msg_g); - - ret = cfstore_flush3_check_data(data, 217, CFSTORE_FLUSH3_TEST_DATA_CHAR); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: G.%d.2 cfstore_flush3_check_data() failed (ret=%d, kv_name=%s).\n", __func__, (int) i+6, (int) ret, kv_name); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush3_utest_msg_g); - } - - memset(data, CFSTORE_FLUSH3_TEST_DATA_CHAR, CFSTORE_FLUSH3_TEST_DATA_BUF_LEN); - CFSTORE_DBGLOG("%s: cfstore_flush3_write_file(com.arm.mbed.spv.sst.node.2, len: 235) to create KV.\n", __func__); - snprintf(kv_name, CFSTORE_KEY_NAME_MAX_LENGTH, "%s.%s.0", (char*) kv_name_root, (char*) kv_name_node); - ret = cfstore_flush3_write_file(NULL, CFSTORE_KEY_NAME_MAX_LENGTH, (const char*) kv_name, (const uint8_t*) data, 235); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: F.3 cfstore_flush3_write_file() failed (ret=%d, kv_name=%s).\n", __func__, (int) ret, kv_name); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush3_utest_msg_g); - - CFSTORE_DBGLOG("%s: cfstore_flush3_write_file(com.arm.mbed.spv.sst.meta, len: 2280) to create KV.\n", __func__); - memset(data, CFSTORE_FLUSH3_TEST_DATA_CHAR, CFSTORE_FLUSH3_TEST_DATA_BUF_LEN); - snprintf(kv_name, CFSTORE_KEY_NAME_MAX_LENGTH, "%s.%s", (char*) kv_name_root, (char*) kv_name_meta); - ret = cfstore_flush3_write_file(NULL, CFSTORE_KEY_NAME_MAX_LENGTH, (const char*) kv_name, (const uint8_t*) data, 2280); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: A.2 cfstore_flush3_write_file() failed (ret=%d, kv_name=%s).\n", __func__, (int) ret, kv_name); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush3_utest_msg_g); - - CFSTORE_DBGLOG("%s: - cfstore_flush3_end\n", __func__); - ret = cfstore_flush3_end(); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: F.11 cfstore_flush3_end() failed (ret=%d, kv_name=%s).\n", __func__, (int) ret, kv_name); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush3_utest_msg_g); - - CFSTORE_DBGLOG("%s: check for heap corruption\n", __func__); - ret = cfstore_flush3_check_data((uint8_t*) heap_buf, CFSTORE_FLUSH3_TEST_HEAP_BUF_LEN, CFSTORE_FLUSH3_HEAP_DATA_CHAR); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: A.5 cfstore_flush3_check_data() failed for heap (ret=%d, kv_name=%s).\n", __func__, (int) ret, kv_name); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush3_utest_msg_g); - - if(heap_buf){ - free(heap_buf); - } - - return CaseNext; -} - - -/* @brief simple flush test */ -static control_t cfstore_flush3_test_02(const size_t call_count) -{ - int32_t cfsStatus = ARM_DRIVER_ERROR; - ARM_CFSTORE_KEYDESC kdesc; - ARM_CFSTORE_FMODE flags; - ARM_CFSTORE_SIZE len = strlen("key0"); - ARM_CFSTORE_HANDLE_INIT(hkey); - ARM_CFSTORE_DRIVER* drv = &cfstore_driver; - - (void) call_count; - memset(&kdesc, 0, sizeof(kdesc)); - memset(&flags, 0, sizeof(flags)); - - CFSTORE_DBGLOG("%s:Initialize()\n", __func__); - cfsStatus = drv->Initialize(NULL, NULL); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error:%d:cfsStatus=%d", __func__, __LINE__, (int) cfsStatus); - TEST_ASSERT_MESSAGE(cfsStatus >= ARM_DRIVER_OK, cfstore_flush3_utest_msg_g); - - CFSTORE_DBGLOG("%s:Create()\n", __func__); - cfsStatus = drv->Create("key0", len, &kdesc, hkey); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error:%d:cfsStatus=%d", __func__, __LINE__, (int) cfsStatus); - TEST_ASSERT_MESSAGE(cfsStatus >= ARM_DRIVER_OK, cfstore_flush3_utest_msg_g); - - len = strlen("some-value"); - CFSTORE_DBGLOG("%s:Write()\n", __func__); - cfsStatus = drv->Write(hkey, "some-value", &len); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error:%d:cfsStatus=%d", __func__, __LINE__, (int) cfsStatus); - TEST_ASSERT_MESSAGE(cfsStatus >= ARM_DRIVER_OK, cfstore_flush3_utest_msg_g); - - CFSTORE_DBGLOG("%s:Close()\n", __func__); - cfsStatus = drv->Close(hkey); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error:%d:cfsStatus=%d", __func__, __LINE__, (int) cfsStatus); - TEST_ASSERT_MESSAGE(cfsStatus >= ARM_DRIVER_OK, cfstore_flush3_utest_msg_g); - - CFSTORE_DBGLOG("%s:Flush()\n", __func__); - cfsStatus = drv->Flush(); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error:%d:cfsStatus=%d", __func__, __LINE__, (int) cfsStatus); - TEST_ASSERT_MESSAGE(cfsStatus >= ARM_DRIVER_OK, cfstore_flush3_utest_msg_g); - - CFSTORE_DBGLOG("%s:Open()\n", __func__); - cfsStatus = drv->Open("key0", flags, hkey); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error:%d:cfsStatus=%d", __func__, __LINE__, (int) cfsStatus); - TEST_ASSERT_MESSAGE(cfsStatus >= ARM_DRIVER_OK, cfstore_flush3_utest_msg_g); - - CFSTORE_DBGLOG("%s:Delete()\n", __func__); - cfsStatus = drv->Delete(hkey); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error:%d:cfsStatus=%d", __func__, __LINE__, (int) cfsStatus); - TEST_ASSERT_MESSAGE(cfsStatus >= ARM_DRIVER_OK, cfstore_flush3_utest_msg_g); - - CFSTORE_DBGLOG("%s:Close()\n", __func__); - cfsStatus = drv->Close(hkey); /////// <--- cfsStatus = ARM_CFSTORE_DRIVER_ERROR_PREEXISTING_KEY - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error:%d:cfsStatus=%d", __func__, __LINE__, (int) cfsStatus); - TEST_ASSERT_MESSAGE(cfsStatus >= ARM_DRIVER_OK, cfstore_flush3_utest_msg_g); - - CFSTORE_DBGLOG("%s:got status = %d\n", __func__, (int) cfsStatus); - - CFSTORE_DBGLOG("%s:Uninitialize()\n", __func__); - cfsStatus = drv->Uninitialize(); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error:%d:cfsStatus=%d", __func__, __LINE__, (int) cfsStatus); - TEST_ASSERT_MESSAGE(cfsStatus >= ARM_DRIVER_OK, cfstore_flush3_utest_msg_g); - - return CaseNext; -} - -#endif /* STORAGE_DRIVER_CONFIG_HARDWARE_MTD_ASYNC_OPS && STORAGE_DRIVER_CONFIG_HARDWARE_MTD_ASYNC_OPS==0 */ - - -static control_t cfstore_flush3_test_00(const size_t call_count) -{ - int32_t ret = ARM_DRIVER_ERROR; - ARM_CFSTORE_CAPABILITIES caps;; - ARM_CFSTORE_DRIVER* drv = &cfstore_driver; - - (void) call_count; - - /* initialise the context */ - caps = drv->GetCapabilities(); - CFSTORE_LOG("%s:INITIALIZING: caps.asynchronous_ops=%lu\n", __func__, caps.asynchronous_ops); - if(caps.asynchronous_ops == 1){ - /* This is a sync mode only test. If this test is not built for sync mode, then skip testing return true - * This means the test will conveniently pass when run in CI as part of async mode testing */ - CFSTORE_LOG("*** Skipping test as binary built for flash journal async mode, and this test is sync-only%s", "\n"); - return CaseNext; - } - ret = cfstore_test_startup(); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush3_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to perform test startup (ret=%d).\n", __func__, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush3_utest_msg_g); - return CaseNext; -} - -/// @cond CFSTORE_DOXYGEN_DISABLE -utest::v1::status_t greentea_setup(const size_t number_of_cases) -{ - GREENTEA_SETUP(CFSTORE_FLUSH3_GREENTEA_TIMEOUT_S, "default_auto"); - return greentea_test_setup_handler(number_of_cases); -} - -Case cases[] = { - /* 1 2 3 4 5 6 7 */ - /* 1234567890123456789012345678901234567890123456789012345678901234567890 */ - Case("FLUSH3_test_00", cfstore_flush3_test_00), -#if defined STORAGE_DRIVER_CONFIG_HARDWARE_MTD_ASYNC_OPS && STORAGE_DRIVER_CONFIG_HARDWARE_MTD_ASYNC_OPS==0 - Case("FLUSH3_test_01", cfstore_flush3_test_01), - Case("FLUSH3_test_02", cfstore_flush3_test_02), -#endif // STORAGE_DRIVER_CONFIG_HARDWARE_MTD_ASYNC_OPS -}; - - -/* Declare your test specification with a custom setup handler */ -Specification specification(greentea_setup, cases); - -/* mbedosV3++*/ -int main() -{ - return !Harness::run(specification); -} -/// @cond - diff --git a/features/storage/FEATURE_STORAGE/TESTS/cfstore/init/init.cpp b/features/storage/FEATURE_STORAGE/TESTS/cfstore/init/init.cpp deleted file mode 100644 index ea59f3f..0000000 --- a/features/storage/FEATURE_STORAGE/TESTS/cfstore/init/init.cpp +++ /dev/null @@ -1,153 +0,0 @@ -/* - * mbed Microcontroller Library - * Copyright (c) 2006-2016 ARM Limited - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** @file init.cpp Test cases to test CFSTORE initialization/uninitialization code. - * - * Please consult the documentation under the test-case functions for - * a description of the individual test case. - */ - -#include "mbed.h" -#include "Driver_Common.h" -#include "cfstore_config.h" -#include "cfstore_test.h" -#include "cfstore_debug.h" -#include "configuration_store.h" -#include "utest/utest.h" -#include "unity/unity.h" -#include "greentea-client/test_env.h" - -#include -#include -#include -#include - -using namespace utest::v1; - -static char cfstore_init_utest_msg_g[CFSTORE_UTEST_MSG_BUF_SIZE]; - -/// @cond CFSTORE_DOXYGEN_DISABLE -typedef struct cfstore_init_ctx_t -{ - ARM_CFSTORE_CAPABILITIES caps; -} cfstore_init_ctx_t; - -static cfstore_init_ctx_t cfstore_init_ctx_g; -extern ARM_CFSTORE_DRIVER cfstore_driver; -ARM_CFSTORE_DRIVER *cfstore_drv = &cfstore_driver; -/// @endcond - - -/* report whether built/configured for flash sync or async mode */ -static control_t cfstore_init_test_00(const size_t call_count) -{ - int32_t ret = ARM_DRIVER_ERROR; - - (void) call_count; - ret = cfstore_test_startup(); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_init_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to perform test startup (ret=%d).\n", __func__, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_init_utest_msg_g); - return CaseNext; -} - -static void cfstore_init_test_01(cfstore_init_ctx_t* ctx) -{ - int32_t ret; - - (void) ctx; - CFSTORE_DBGLOG("INITIALIZING%s", "\r\n"); - ret = cfstore_drv->Initialize(NULL, NULL); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_init_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Initialize() should return ret >= 0 for async/synch modes(ret=%ld)\r\n", __func__, ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_init_utest_msg_g); - - CFSTORE_DBGLOG("FLUSHING1%s", "\r\n"); - ret = cfstore_drv->Flush(); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_init_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Flush() failed (ret=%ld)\r\n", __func__, ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_init_utest_msg_g); - - CFSTORE_DBGLOG("UNINITIALIZING%s", "\r\n"); - ret = cfstore_drv->Uninitialize(); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_init_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Uninitialize() should return ret >= 0 for synch mode(ret=%ld)\r\n", __func__, ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_init_utest_msg_g); - - CFSTORE_DBGLOG("***************%s", "\r\n"); - CFSTORE_DBGLOG("*** SUCCESS ***%s", "\r\n"); - CFSTORE_DBGLOG("***************%s", "\r\n"); - return; -} - -static control_t cfstore_init_app_start(const size_t call_count) -{ - cfstore_init_ctx_t* ctx = &cfstore_init_ctx_g; - - (void) call_count; - - /* initialise the context */ - memset(ctx, 0, sizeof(cfstore_init_ctx_t)); - ctx->caps = cfstore_drv->GetCapabilities(); - CFSTORE_LOG("%s:INITIALIZING: caps.asynchronous_ops=%lu\n", __func__, ctx->caps.asynchronous_ops); - if(ctx->caps.asynchronous_ops == 1){ - /* This is a sync mode only test. If this test is not built for sync mode, then skip testing return true - * This means the test will conveniently pass when run in CI as part of async mode testing */ - CFSTORE_LOG("*** Skipping test as binary built for flash journal async mode, and this test is sync-only%s", "\n"); - return CaseNext; - } - cfstore_init_test_01(ctx); - return CaseNext; -} - -#ifndef YOTTA_CONFIGURATION_STORE_INIT_VERSION_STRING - - -/* when built as Configuration-Store example, include greentea support otherwise omit */ - -/// @cond CFSTORE_DOXYGEN_DISABLE -utest::v1::status_t greentea_setup(const size_t number_of_cases) -{ - GREENTEA_SETUP(100, "default_auto"); - return greentea_test_setup_handler(number_of_cases); -} - -Case cases[] = { - /* 1 2 3 4 5 6 7 */ - /* 1234567890123456789012345678901234567890123456789012345678901234567890 */ - Case("INIT_test_00", cfstore_init_test_00), - Case("INIT_test_01_start", cfstore_init_app_start), -}; - - -/* Declare your test specification with a custom setup handler */ -Specification specification(greentea_setup, cases); - -int main() -{ - return !Harness::run(specification); -} -/// @endcond - - -#else // YOTTA_CONFIGURATION_STORE_INIT_VERSION_STRING - - -// stand alone Configuration-Store-Example -void app_start(int argc __unused, char** argv __unused) -{ - cfstore_init_app_start(0); -} - - -#endif // YOTTA_CONFIGURATION_STORE_INIT_VERSION_STRING diff --git a/features/storage/FEATURE_STORAGE/TESTS/cfstore/misc/misc.cpp b/features/storage/FEATURE_STORAGE/TESTS/cfstore/misc/misc.cpp deleted file mode 100644 index f1ba8b0..0000000 --- a/features/storage/FEATURE_STORAGE/TESTS/cfstore/misc/misc.cpp +++ /dev/null @@ -1,327 +0,0 @@ -/* - * mbed Microcontroller Library - * Copyright (c) 2006-2016 ARM Limited - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** @file misc.cpp Test cases for miscellaneous API drv->Xxx() functions. - * - * Please consult the documentation under the test-case functions for - * a description of the individual test case. - */ - -#include "mbed.h" -#include "cfstore_config.h" -#include "cfstore_test.h" -#include "cfstore_debug.h" -#include "Driver_Common.h" -#include "cfstore_config.h" -#include "configuration_store.h" -#include "utest/utest.h" -#include "unity/unity.h" -#include "greentea-client/test_env.h" -#include "cfstore_utest.h" - -#include -#include -#include - -using namespace utest::v1; - -static char cfstore_misc_utest_msg_g[CFSTORE_UTEST_MSG_BUF_SIZE]; - - - -/* report whether built/configured for flash sync or async mode */ -static control_t cfstore_misc_test_00(const size_t call_count) -{ - int32_t ret = ARM_DRIVER_ERROR; - - (void) call_count; - ret = cfstore_test_startup(); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_misc_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to perform test startup (ret=%d).\n", __func__, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_misc_utest_msg_g); - return CaseNext; -} - - -/** @brief basic PowerControl() test - * - * @return on success returns CaseNext to continue to next test case, otherwise will assert on errors. - */ -control_t cfstore_misc_test_00_start(const size_t call_count) -{ - int32_t ret = ARM_DRIVER_ERROR; - ARM_CFSTORE_DRIVER* drv = &cfstore_driver; - ARM_POWER_STATE state = ARM_POWER_OFF; - - CFSTORE_FENTRYLOG("%s:entered\n", __func__); - (void) call_count; - - /* try setting the power control state before initialised, which should fail */ - ret = drv->PowerControl(state); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_misc_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Eror: PowerControl() call should have failed as CFSTORE not initialised, but the call succeeded\r\n", __func__); - TEST_ASSERT_MESSAGE(ret < ARM_DRIVER_OK, cfstore_misc_utest_msg_g); - - ret = drv->Initialize(cfstore_utest_default_callback, NULL); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_misc_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to initialize CFSTORE (ret=%d)\n", __func__, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_misc_utest_msg_g); - return CaseTimeout(CFSTORE_UTEST_DEFAULT_TIMEOUT_MS); -} - -static control_t cfstore_misc_test_00_end(const size_t call_count) -{ - int32_t ret = ARM_DRIVER_ERROR; - ARM_CFSTORE_DRIVER* drv = &cfstore_driver; - ARM_POWER_STATE state = ARM_POWER_OFF; - - CFSTORE_FENTRYLOG("%s:entered\n", __func__); - (void) call_count; - - while(state <= ARM_POWER_FULL) - { - ret = drv->PowerControl(state); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_misc_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: PowerControl() call failed\r\n", __func__); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_misc_utest_msg_g); - state = (ARM_POWER_STATE)((uint32_t) state + 1); - } - /*try invalid value which should fail*/ - ret = drv->PowerControl((ARM_POWER_STATE ) 0xffffffff); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_misc_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:ERror: PowerControl() did not fail with bad value 0xffffffff (not as expected)\r\n", __func__); - TEST_ASSERT_MESSAGE(ret < ARM_DRIVER_OK, cfstore_misc_utest_msg_g); - - ret = drv->Uninitialize(); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_misc_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Uninitialize() call failed.\n", __func__); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_misc_utest_msg_g); - return CaseNext; -} - - -/** @brief basic GetVersion() test - * - */ -control_t cfstore_misc_test_01(const size_t call_count) -{ - ARM_CFSTORE_DRIVER* drv = &cfstore_driver; - ARM_DRIVER_VERSION version; - - CFSTORE_FENTRYLOG("%s:entered\n", __func__); - (void) call_count; - memset(&version, 0, sizeof(version)); - - version = drv->GetVersion(); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_misc_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:GetVersion() failed to return correct API version.\r\n", __func__); - TEST_ASSERT_MESSAGE(version.api == ARM_CFSTORE_API_VERSION, cfstore_misc_utest_msg_g); - - CFSTORE_TEST_UTEST_MESSAGE(cfstore_misc_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:GetVersion() to return correct driver version.\r\n", __func__); - TEST_ASSERT_MESSAGE(version.drv == ARM_CFSTORE_DRV_VERSION, cfstore_misc_utest_msg_g); - return CaseNext; -} - - -/* KV data for test_03 */ -static cfstore_kv_data_t cfstore_misc_test_03_kv_data[] = { - /* 1 2 3 4 5 6 7 */ - /* 1234567890123456789012345678901234567890123456789012345678901234567890 */ - { "The.principles.of.least.action.in.quantum.mechanics", "DoctoralThesis"}, - { "Space.Time.Approach.to.Quantum.Electrodynamic", " PhysicalReview766)"}, - { "An.Operator.Calculus.Having.Applications.in.Quantum.Electrodynamics", "PhysicalReview84)"}, - { NULL, NULL}, -}; - - -/** @brief basic GetKeyName() test - * - * @return on success returns CaseNext to continue to next test case, otherwise will assert on errors. - */ -control_t cfstore_misc_test_02_end(const size_t call_count) -{ - uint8_t key_name_len = 0; - char key_name_buf[CFSTORE_KEY_NAME_MAX_LENGTH+1]; - int32_t ret = ARM_DRIVER_ERROR; - ARM_CFSTORE_DRIVER* drv = &cfstore_driver; - cfstore_kv_data_t* node = NULL; - ARM_CFSTORE_HANDLE_INIT(hkey); - ARM_CFSTORE_FMODE flags; - - CFSTORE_FENTRYLOG("%s:entered\r\n", __func__); - (void) call_count; - memset(key_name_buf, 0, CFSTORE_KEY_NAME_MAX_LENGTH+1); - /* dont set any flags to get default settings */ - memset(&flags, 0, sizeof(flags)); - - ret = cfstore_test_create_table(cfstore_misc_test_03_kv_data); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_misc_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: unable to create keys from table.\r\n", __func__); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_misc_utest_msg_g); - - node = cfstore_misc_test_03_kv_data; - while(node->key_name != NULL) - { - CFSTORE_DBGLOG("%s:About to open KV (key_name=\"%s\", value=\"%s\")\r\n", __func__, node->key_name, node->value); - ret = drv->Open(node->key_name, flags, hkey); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_misc_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Failed to open node (key_name=\"%s\", value=\"%s\")(ret=%d)\r\n", __func__, node->key_name, node->value, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_misc_utest_msg_g); - - key_name_len = CFSTORE_KEY_NAME_MAX_LENGTH+1; - memset(key_name_buf, 0, key_name_len); - drv->GetKeyName(hkey, key_name_buf, &key_name_len); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_misc_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to GetKeyName() (key_name (expected)=\"%s\", key_name (returned)=\"%s\", value=\"%s\"), len return=%d, len expected=%d\r\n", __func__, node->key_name, key_name_buf, node->value, (int) key_name_len, (int) strlen(node->key_name)); - TEST_ASSERT_MESSAGE(key_name_len == strlen(node->key_name)+1, cfstore_misc_utest_msg_g); - - /* revert to CFSTORE_LOG if more trace required */ - CFSTORE_DBGLOG("GetKeyName() successfully reported key_name (key_name=\"%s\")\r\n", key_name_buf); - ret = drv->Close(hkey); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_misc_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Failed to close key (key_name=\"%s\", value=\"%s\")\r\n", __func__, node->key_name, node->value); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_misc_utest_msg_g); - node++; - } - - cfstore_test_delete_all(); - ret = drv->Uninitialize(); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_misc_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Uninitialize() call failed.\n", __func__); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_misc_utest_msg_g); - return CaseNext; -} - - -/** @brief basic GetValueLen() test - * - * @return on success returns CaseNext to continue to next test case, otherwise will assert on errors. - */ -control_t cfstore_misc_test_03_end(const size_t call_count) -{ - int32_t ret = ARM_DRIVER_ERROR; - ARM_CFSTORE_SIZE len = 0; - ARM_CFSTORE_DRIVER* drv = &cfstore_driver; - cfstore_kv_data_t* node = NULL; - ARM_CFSTORE_HANDLE_INIT(hkey); - ARM_CFSTORE_FMODE flags; - - CFSTORE_FENTRYLOG("%s:entered\n", __func__); - (void) call_count; - /* dont set any flags to get default settings */ - memset(&flags, 0, sizeof(flags)); - - ret = cfstore_test_create_table(cfstore_misc_test_03_kv_data); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_misc_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: unable to create keys from table.\r\n", __func__); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_misc_utest_msg_g); - - node = cfstore_misc_test_03_kv_data; - while(node->key_name != NULL) - { - CFSTORE_DBGLOG("%s:About to open KV (key_name=\"%s\", value=\"%s\")\r\n", __func__, node->key_name, node->value); - ret = drv->Open(node->key_name, flags, hkey); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_misc_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Failed to open node (key_name=\"%s\", value=\"%s\")(ret=%d)\r\n", __func__, node->key_name, node->value, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_misc_utest_msg_g); - - drv->GetValueLen(hkey, &len); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_misc_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Errro: GetValueLen() retrieve incorrect length of value blob(expected=%d, returned=%d)\r\n", __func__, (int) strlen(node->value), (int) len); - TEST_ASSERT_MESSAGE(len == strlen(node->value), cfstore_misc_utest_msg_g); - /* revert to CFSTORE_LOG if more trace required */ - CFSTORE_DBGLOG("GetValueLen() successfully reported correct value blob length%s", "\r\n"); - - ret = drv->Close(hkey); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_misc_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Failed to close key (key_name=\"%s\", value=\"%s\")\r\n", __func__, node->key_name, node->value); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_misc_utest_msg_g); - node++; - } - cfstore_test_delete_all(); - ret = drv->Uninitialize(); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_misc_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Uninitialize() call failed.\n", __func__); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_misc_utest_msg_g); - return CaseNext; -} - - -/** @brief basic GetStatus() test - * - * @return on success returns CaseNext to continue to next test case, otherwise will assert on errors. - */ -control_t cfstore_misc_test_04_start(const size_t call_count) -{ - int32_t ret = ARM_DRIVER_ERROR; - ARM_CFSTORE_STATUS status; - ARM_CFSTORE_DRIVER* drv = &cfstore_driver; - - CFSTORE_FENTRYLOG("%s:entered\n", __func__); - (void) call_count; - - status = drv->GetStatus(); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_misc_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: GetStatus() before initialisation should have reported error, but reported no error.\r\n", __func__); - TEST_ASSERT_MESSAGE(status.error == 1, cfstore_misc_utest_msg_g); - - ret = drv->Initialize(cfstore_utest_default_callback, NULL); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_misc_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to initialize CFSTORE (ret=%d)\n", __func__, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_misc_utest_msg_g); - return CaseTimeout(CFSTORE_UTEST_DEFAULT_TIMEOUT_MS); -} - -/** @brief basic GetStatus() test - * - * @return on success returns CaseNext to continue to next test case, otherwise will assert on errors. - */ -control_t cfstore_misc_test_04_end(const size_t call_count) -{ - int32_t ret = ARM_DRIVER_ERROR; - ARM_CFSTORE_DRIVER* drv = &cfstore_driver; - ARM_CFSTORE_STATUS status; - - CFSTORE_FENTRYLOG("%s:entered\n", __func__); - (void) call_count; - - status = drv->GetStatus(); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_misc_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: GetStatus() but reported error.\r\n", __func__); - TEST_ASSERT_MESSAGE(status.error == 0, cfstore_misc_utest_msg_g); - - CFSTORE_TEST_UTEST_MESSAGE(cfstore_misc_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: GetStatus() reported operation in progress.\r\n", __func__); - TEST_ASSERT_MESSAGE(status.in_progress == 0, cfstore_misc_utest_msg_g); - - ret = drv->Uninitialize(); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_misc_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Uninitialize() call failed.\n", __func__); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_misc_utest_msg_g); - return CaseNext; -} - - -/// @cond CFSTORE_DOXYGEN_DISABLE -utest::v1::status_t greentea_setup(const size_t number_of_cases) -{ - GREENTEA_SETUP(200, "default_auto"); - return greentea_test_setup_handler(number_of_cases); -} - -Case cases[] = { - /* 1 2 3 4 5 6 7 */ - /* 1234567890123456789012345678901234567890123456789012345678901234567890 */ - Case("MISC_test_00", cfstore_misc_test_00), - Case("MISC_test_00_start", cfstore_misc_test_00_start), - Case("MISC_test_00_end", cfstore_misc_test_00_end), - Case("MISC_test_01", cfstore_misc_test_01), - Case("MISC_test_02_start", cfstore_utest_default_start), - Case("MISC_test_02_end", cfstore_misc_test_02_end), - Case("MISC_test_03_start", cfstore_utest_default_start), - Case("MISC_test_03_end", cfstore_misc_test_03_end), - Case("MISC_test_04_start", cfstore_misc_test_04_start), - Case("MISC_test_05_end", cfstore_misc_test_04_end), -}; - - -/* Declare your test specification with a custom setup handler */ -Specification specification(greentea_setup, cases); - -int main() -{ - return !Harness::run(specification); -} -/// @endcond diff --git a/features/storage/FEATURE_STORAGE/TESTS/cfstore/open/open.cpp b/features/storage/FEATURE_STORAGE/TESTS/cfstore/open/open.cpp deleted file mode 100644 index 4ee0cd8..0000000 --- a/features/storage/FEATURE_STORAGE/TESTS/cfstore/open/open.cpp +++ /dev/null @@ -1,633 +0,0 @@ -/* - * mbed Microcontroller Library - * Copyright (c) 2006-2016 ARM Limited - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** @file open.cpp Test cases to open KVs in the CFSTORE using the drv->Open() interface. - * - * Please consult the documentation under the test-case functions for - * a description of the individual test case. - */ - -#include "mbed.h" -#include "cfstore_config.h" -#include "cfstore_test.h" -#include "cfstore_debug.h" -#include "Driver_Common.h" -#include "configuration_store.h" -#include "utest/utest.h" -#include "unity/unity.h" -#include "greentea-client/test_env.h" -#include "cfstore_utest.h" - -#include -#include -#include /*rand()*/ -#include - -using namespace utest::v1; - -static char cfstore_open_utest_msg_g[CFSTORE_UTEST_MSG_BUF_SIZE]; - - - -/// @cond CFSTORE_DOXYGEN_DISABLE -#ifdef CFSTORE_DEBUG -#define CFSTORE_OPEN_GREENTEA_TIMEOUT_S 3000 -#else -#define CFSTORE_OPEN_GREENTEA_TIMEOUT_S 1000 -#endif -/// @endcond - - -/* support functions */ - -/* - * open tests that focus on testing cfstore_open() - * cfstore_handle_t cfstore_open(const char* key_name, char* data, ARM_CFSTORE_SIZE* len, cfstore_key_desc_t* kdesc) - */ - -/* KV data for test_01 */ -static cfstore_kv_data_t cfstore_open_test_01_kv_data[] = { - { "yotta.hello-world.animal{wobbly-dog}{foot}frontLeft", "missing"}, - { NULL, NULL}, -}; - - -/* report whether built/configured for flash sync or async mode */ -static control_t cfstore_open_test_00(const size_t call_count) -{ - int32_t ret = ARM_DRIVER_ERROR; - - (void) call_count; - ret = cfstore_test_startup(); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_open_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to perform test startup (ret=%d).\n", __func__, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_open_utest_msg_g); - return CaseNext; -} - -/** @brief - * Basic open test which does the following: - * - creates KV with default rw perms and writes some data to the value blob. - * - closes the newly created KV. - * - opens the KV with the default permissions (r-only) - * - reads the KV data and checks its the same as the previously created data. - * - closes the opened key - * - * @return on success returns CaseNext to continue to next test case, otherwise will assert on errors. - */ -control_t cfstore_open_test_01_end(const size_t call_count) -{ - char* read_buf; - int32_t ret = ARM_DRIVER_ERROR; - ARM_CFSTORE_SIZE len = 0; - ARM_CFSTORE_DRIVER* drv = &cfstore_driver; - ARM_CFSTORE_KEYDESC kdesc; - ARM_CFSTORE_HANDLE_INIT(hkey); - cfstore_kv_data_t *node; - ARM_CFSTORE_FMODE flags; - - CFSTORE_DBGLOG("%s:entered\n", __func__); - (void) call_count; - node = cfstore_open_test_01_kv_data; - memset(&kdesc, 0, sizeof(kdesc)); - memset(&flags, 0, sizeof(flags)); - - kdesc.drl = ARM_RETENTION_WHILE_DEVICE_ACTIVE; - CFSTORE_DBGLOG("%s:About to create new node (key_name=\"%s\", value=\"%s\")\n", __func__, node->key_name, node->value); - ret = drv->Create(node->key_name, strlen(node->value), &kdesc, hkey); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_open_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to create node (key_name=\"%s\", value=\"%s\")(ret=%d)\n", __func__, node->key_name, node->value, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_open_utest_msg_g); - - CFSTORE_DBGLOG("%s:length of KV=%d (key_name=\"%s\", value=\"%s\")\n", __func__, (int) len, node->key_name, node->value); - len = strlen(node->value); - ret = drv->Write(hkey, (char*) node->value, &len); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_open_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to write key (key_name=\"%s\", value=\"%s\")(ret=%d)\n", __func__, node->key_name, node->value, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_open_utest_msg_g); - - CFSTORE_TEST_UTEST_MESSAGE(cfstore_open_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to write full value data (key_name=\"%s\", value=\"%s\"), len=%d, (ret=%d)\n", __func__, node->key_name, node->value, (int) len, (int) ret); - TEST_ASSERT_MESSAGE(len == strlen(node->value), cfstore_open_utest_msg_g); - - CFSTORE_DBGLOG("Created KV successfully (key_name=\"%s\", value=\"%s\")\n", node->key_name, node->value); - ret = drv->Close(hkey); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_open_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to close handle (ret=%d)\n", __func__, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_open_utest_msg_g); - - /* now open the newly created key */ - ret = drv->Open(node->key_name, flags, hkey); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_open_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to open node (key_name=\"%s\", value=\"%s\")(ret=%d)\n", __func__, node->key_name, node->value, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_open_utest_msg_g); - - len = strlen(node->value) + 1; - read_buf = (char*) malloc(len); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_open_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to allocated read buffer \n", __func__); - TEST_ASSERT_MESSAGE(read_buf != NULL, cfstore_open_utest_msg_g); - - CFSTORE_DBGLOG("Opened KV successfully (key_name=\"%s\", value=\"%s\")\n", node->key_name, node->value); - memset(read_buf, 0, len); - ret = drv->Read(hkey, read_buf, &len); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_open_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to write key (key_name=\"%s\", value=\"%s\")\n", __func__, node->key_name, node->value); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_open_utest_msg_g); - - /* check read data is as expected */ - CFSTORE_TEST_UTEST_MESSAGE(cfstore_open_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: read value data (%s) != KV value data (key_name=\"%s\", value=\"%s\")\n", __func__, read_buf, node->key_name, node->value); - TEST_ASSERT_MESSAGE(strncmp(read_buf, node->value, strlen(node->value)) == 0, cfstore_open_utest_msg_g); - - if(read_buf){ - free(read_buf); - } - CFSTORE_TEST_UTEST_MESSAGE(cfstore_open_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Close() call failed.\n", __func__); - TEST_ASSERT_MESSAGE(drv->Close(hkey) >= ARM_DRIVER_OK, cfstore_open_utest_msg_g); - - ret = drv->Uninitialize(); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_open_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Uninitialize() call failed.\n", __func__); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_open_utest_msg_g); - return CaseNext; -} - -static cfstore_kv_data_t cfstore_open_test_02_data[] = { - CFSTORE_INIT_1_TABLE_MID_NODE, - { NULL, NULL}, -}; - -/** - * @brief test to open() a pre-existing key and try to write it, which should fail - * as by default pre-existing keys are opened read-only - * - * Basic open test which does the following: - * - creates KV with default rw perms and writes some data to the value blob. - * - closes the newly created KV. - * - opens the KV with the default permissions (read-only) - * - tries to write the KV data which should fail because KV was not opened with write flag set. - * - closes the opened key - * - * @return on success returns CaseNext to continue to next test case, otherwise will assert on errors. - */ -control_t cfstore_open_test_02_end(const size_t call_count) -{ - int32_t ret = ARM_DRIVER_ERROR; - ARM_CFSTORE_SIZE len = 0; - ARM_CFSTORE_DRIVER* drv = &cfstore_driver; - ARM_CFSTORE_KEYDESC kdesc; - ARM_CFSTORE_HANDLE_INIT(hkey); - ARM_CFSTORE_FMODE flags; - - CFSTORE_FENTRYLOG("%s:entered\n", __func__); - (void) call_count; - memset(&kdesc, 0, sizeof(kdesc)); - /* dont set any flags to get default settings */ - memset(&flags, 0, sizeof(flags)); - kdesc.drl = ARM_RETENTION_WHILE_DEVICE_ACTIVE; - len = strlen(cfstore_open_test_02_data[0].value); - ret = cfstore_test_create(cfstore_open_test_02_data[0].key_name, (char*) cfstore_open_test_02_data[0].value, &len, &kdesc); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_open_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to create KV in store (ret=%d).\n", __func__, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_open_utest_msg_g); - - /* by default, owner of key opens with read-only permissions*/ - ret = drv->Open(cfstore_open_test_02_data[0].key_name, flags, hkey); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_open_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to open node (key_name=\"%s\")(ret=%d)\n", __func__, cfstore_open_test_02_data[0].key_name, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_open_utest_msg_g); - - len = strlen(cfstore_open_test_02_data[0].value); - ret = drv->Write(hkey, cfstore_open_test_02_data[0].value, &len); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_open_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: call to Write() succeeded when should have failed (key_name=\"%s\")(ret=%d).\n", __func__, cfstore_open_test_02_data[0].key_name, (int) ret); - TEST_ASSERT_MESSAGE(ret == ARM_CFSTORE_DRIVER_ERROR_KEY_READ_ONLY, cfstore_open_utest_msg_g); - - CFSTORE_TEST_UTEST_MESSAGE(cfstore_open_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Close() call failed.\n", __func__); - TEST_ASSERT_MESSAGE(drv->Close(hkey) >= ARM_DRIVER_OK, cfstore_open_utest_msg_g); - - ret = drv->Uninitialize(); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_open_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Uninitialize() call failed.\n", __func__); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_open_utest_msg_g); - return CaseNext; -} - - -/** - * @brief test to open() a pre-existing key and try to write it, which should succeed - * because the key was opened read-write permissions explicitly - * - * Basic open test which does the following: - * - creates KV with default rw perms and writes some data to the value blob. - * - closes the newly created KV. - * - opens the KV with the rw permissions (non default) - * - tries to write the KV data which should succeeds because KV was opened with write flag set. - * - closes the opened key - * - * @return on success returns CaseNext to continue to next test case, otherwise will assert on errors. - */ -control_t cfstore_open_test_03_end(const size_t call_count) -{ - int32_t ret = ARM_DRIVER_ERROR; - ARM_CFSTORE_SIZE len = 0; - ARM_CFSTORE_DRIVER* drv = &cfstore_driver; - ARM_CFSTORE_KEYDESC kdesc; - ARM_CFSTORE_HANDLE_INIT(hkey); - ARM_CFSTORE_FMODE flags; - - CFSTORE_FENTRYLOG("%s:entered\n", __func__); - (void) call_count; - memset(&kdesc, 0, sizeof(kdesc)); - /* dont set any flags to get default settings */ - memset(&flags, 0, sizeof(flags)); - kdesc.drl = ARM_RETENTION_WHILE_DEVICE_ACTIVE; - len = strlen(cfstore_open_test_02_data[0].value); - ret = cfstore_test_create(cfstore_open_test_02_data[0].key_name, (char*) cfstore_open_test_02_data[0].value, &len, &kdesc); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_open_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to create KV in store (ret=%d).\n", __func__, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_open_utest_msg_g); - - /* opens with read-write permissions*/ - flags.read = true; - flags.write = true; - ret = drv->Open(cfstore_open_test_02_data[0].key_name, flags, hkey); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_open_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to open node (key_name=\"%s\")(ret=%d)\n", __func__, cfstore_open_test_02_data[0].key_name, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_open_utest_msg_g); - - len = strlen(cfstore_open_test_02_data[0].value); - ret = drv->Write(hkey, cfstore_open_test_02_data[0].value, &len); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_open_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: call to Write() failed when should have succeeded (key_name=\"%s\")(ret=%d).\n", __func__, cfstore_open_test_02_data[0].key_name, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_open_utest_msg_g); - - CFSTORE_TEST_UTEST_MESSAGE(cfstore_open_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Close() call failed.\n", __func__); - TEST_ASSERT_MESSAGE(drv->Close(hkey) >= ARM_DRIVER_OK, cfstore_open_utest_msg_g); - - ret = drv->Uninitialize(); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_open_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Uninitialize() call failed.\n", __func__); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_open_utest_msg_g); - return CaseNext; -} - - - -/** @brief test to call cfstore_open() with a key_name string that exceeds - * the maximum length - * - * @return on success returns CaseNext to continue to next test case, otherwise will assert on errors. - */ -control_t cfstore_open_test_04_end(const size_t call_count) -{ - char kv_name_good[CFSTORE_KEY_NAME_MAX_LENGTH+1]; /* extra char for terminating null */ - char kv_name_bad[CFSTORE_KEY_NAME_MAX_LENGTH+2]; - int32_t ret = ARM_DRIVER_ERROR; - ARM_CFSTORE_SIZE len = 0; - ARM_CFSTORE_DRIVER* drv = &cfstore_driver; - ARM_CFSTORE_KEYDESC kdesc; - ARM_CFSTORE_FMODE flags; - - CFSTORE_FENTRYLOG("%s:entered\n", __func__); - (void) call_count; - memset(kv_name_good, 0, CFSTORE_KEY_NAME_MAX_LENGTH+1); - memset(kv_name_bad, 0, CFSTORE_KEY_NAME_MAX_LENGTH+2); - memset(&kdesc, 0, sizeof(kdesc)); - /* dont set any flags to get default settings */ - memset(&flags, 0, sizeof(flags)); - - len = CFSTORE_KEY_NAME_MAX_LENGTH; - ret = cfstore_test_kv_name_gen(kv_name_good, len); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_open_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: unable to generate kv_name_good.\n", __func__); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK , cfstore_open_utest_msg_g); - - CFSTORE_TEST_UTEST_MESSAGE(cfstore_open_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: kv_name_good is not the correct length (len=%d, expected=%d).\n", __func__, (int) strlen(kv_name_good), (int) len); - TEST_ASSERT_MESSAGE(strlen(kv_name_good) == CFSTORE_KEY_NAME_MAX_LENGTH, cfstore_open_utest_msg_g); - - ret = cfstore_test_create(kv_name_good, kv_name_good, &len, &kdesc); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_open_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); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_open_utest_msg_g); - - len = CFSTORE_KEY_NAME_MAX_LENGTH+1; - ret = cfstore_test_kv_name_gen(kv_name_bad, len); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_open_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: unable to generate kv_name_bad.\n", __func__); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK , cfstore_open_utest_msg_g); - - CFSTORE_TEST_UTEST_MESSAGE(cfstore_open_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: kv_name_bad is not the correct length (len=%d, expected=%d).\n", __func__, (int) strlen(kv_name_bad), (int) len); - TEST_ASSERT_MESSAGE(strlen(kv_name_bad) == CFSTORE_KEY_NAME_MAX_LENGTH+1, cfstore_open_utest_msg_g); - - memset(&kdesc, 0, sizeof(kdesc)); - ret = cfstore_test_create(kv_name_bad, kv_name_bad, &len, &kdesc); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_open_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: created KV in store for kv_name_bad when should have failed(ret=%d).\n", __func__, (int) ret); - TEST_ASSERT_MESSAGE(ret < ARM_DRIVER_OK, cfstore_open_utest_msg_g); - - ret = drv->Uninitialize(); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_open_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Uninitialize() call failed.\n", __func__); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_open_utest_msg_g); - return CaseNext; -} - - -/// @cond CFSTORE_DOXYGEN_DISABLE -typedef struct cfstore_open_kv_name_ascii_node { - uint32_t code; - uint32_t f_allowed : 1; -} cfstore_open_kv_name_ascii_node; -/// @endcond - -static const uint32_t cfstore_open_kv_name_ascii_table_code_sentinel_g = 256; - -/*@brief table recording ascii character codes permitted in kv names */ -static cfstore_open_kv_name_ascii_node cfstore_open_kv_name_ascii_table[] = -{ - {0, false}, /* codes 0-44 not allowed */ - {45, true}, /* codes 45-46 == [-.] allowed */ - {47, false}, /* code 47 not allowed */ - {48, true}, /* codes 48-57 not allowed */ - {58, false}, /* codes 46-64 not allowed */ - {64, true}, /* codes 64-91 allowed [@A-Z] */ - {91, false}, /* code 91-96 not allowed */ - {95, true}, /* code 95 allowed '_' */ - {96, false}, /* codes 96 not allowed */ - {97, true}, /* codes 65-90 allowed [A-Z] and {*/ - {123, false}, /* codes 123 '}' not allowed on its own*/ - {124, false}, /* codes 124 not allowed */ - {125, false}, /* code 125 '}' not allowed on its own*/ - {126, false}, /* codes 126-255 not allowed */ - {cfstore_open_kv_name_ascii_table_code_sentinel_g, false}, /* sentinel */ -}; - -/// @cond CFSTORE_DOXYGEN_DISABLE -enum cfstore_open_kv_name_pos { - cfstore_open_kv_name_pos_start = 0x0, - cfstore_open_kv_name_pos_mid, - cfstore_open_kv_name_pos_end, - cfstore_open_kv_name_pos_max -}; -/// @endcond - -/** @brief test to call cfstore_open() with key_name that in includes - * illegal characters - * - the character(s) can be at the beginning of the key_name - * - the character(s) can be at the end of the key_name - * - the character(s) can be somewhere within the key_name string - * - a max-length string of random characters (legal and illegal) - * - a max-length string of random illegal characters only - * - * @return on success returns CaseNext to continue to next test case, otherwise will assert on errors. - */ -control_t cfstore_open_test_05_end(const size_t call_count) -{ - bool f_allowed = false; - char kv_name[CFSTORE_KEY_NAME_MAX_LENGTH+1]; /* extra char for terminating null */ - uint32_t j = 0; - int32_t ret = ARM_DRIVER_OK; - size_t name_len = CFSTORE_KEY_NAME_MAX_LENGTH; - ARM_CFSTORE_KEYDESC kdesc; - cfstore_open_kv_name_ascii_node* node = NULL; - uint32_t pos; - ARM_CFSTORE_DRIVER* drv = &cfstore_driver; - - CFSTORE_FENTRYLOG("%s:entered\n", __func__); - (void) call_count; - -#ifdef CFSTORE_DEBUG - /* symbol only used why debug is enabled */ - const char* pos_str = NULL; -#endif - - /* create bad keyname strings with invalid character code at start of keyname */ - node = cfstore_open_kv_name_ascii_table; - while(node->code != cfstore_open_kv_name_ascii_table_code_sentinel_g) - { - /* loop over range */ - for(j = node->code; j < (node+1)->code; j++) - { - /* set the start, mid, last character of the name to the test char code */ - for(pos = (uint32_t) cfstore_open_kv_name_pos_start; pos < (uint32_t) cfstore_open_kv_name_pos_max; pos++) - { - name_len = CFSTORE_KEY_NAME_MAX_LENGTH; - memset(kv_name, 0, CFSTORE_KEY_NAME_MAX_LENGTH+1); - memset(&kdesc, 0, sizeof(kdesc)); - kdesc.drl = ARM_RETENTION_WHILE_DEVICE_ACTIVE; - - ret = cfstore_test_kv_name_gen(kv_name, name_len); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_open_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: unable to generate kv_name.\n", __func__); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK , cfstore_open_utest_msg_g); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_open_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: kv_name incorrect length (len=%d, expected= %d).\n", __func__, (int) strlen(kv_name), (int) name_len); - TEST_ASSERT_MESSAGE(strlen(kv_name) == name_len, cfstore_open_utest_msg_g); - - /* overwrite a char at the pos start, mid, end of the kv_name with an ascii char code (both illegal and legal)*/ - switch(pos) - { - case cfstore_open_kv_name_pos_start: - kv_name[0] = (char) j; - break; - case cfstore_open_kv_name_pos_mid: - /* create bad keyname strings with invalid character code in the middle of keyname */ - kv_name[name_len/2] = (char) j; - break; - case cfstore_open_kv_name_pos_end: - /* create bad keyname strings with invalid character code at end of keyname */ - kv_name[name_len-1] = (char) j; - break; - default: - CFSTORE_TEST_UTEST_MESSAGE(cfstore_open_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: unexpected value of pos (pos=%d).\n", __func__, (int) pos); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_open_utest_msg_g); - break; - } - -#ifdef CFSTORE_DEBUG - /* processing only required when debug trace enabled */ - switch(pos) - { - case cfstore_open_kv_name_pos_start: - pos_str = "start"; - break; - case cfstore_open_kv_name_pos_mid: - pos_str = "middle"; - break; - case cfstore_open_kv_name_pos_end: - pos_str = "end"; - break; - default: - break; - } -#endif - ret = cfstore_test_create(kv_name, kv_name, &name_len, &kdesc); - - /* special cases */ - switch(j) - { - case 0 : - case 46 : - switch(pos) - { - /* for code = 0 (null terminator). permitted at mid and end of string */ - /* for code = 46 ('.'). permitted at mid and end of string but not at start */ - case cfstore_open_kv_name_pos_start: - f_allowed = false; - break; - case cfstore_open_kv_name_pos_mid: - case cfstore_open_kv_name_pos_end: - default: - f_allowed = true; - break; - } - break; - default: - f_allowed = node->f_allowed; - break; - } - if(f_allowed == true) - { - CFSTORE_TEST_UTEST_MESSAGE(cfstore_open_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to create KV in store when kv_name contains valid characters (code=%d, ret=%d).\n", __func__, (int) j, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_open_utest_msg_g); - /* revert CFSTORE_LOG for more trace */ - CFSTORE_DBGLOG("Successfully created a KV with valid keyname containing ascii character code %d (%c) at the %s of the keyname.\n", (int) j, (int) j, pos_str); - CFSTORE_LOG("%c", '.'); - - ret = cfstore_test_delete(kv_name); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_open_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to delete KV previously created (code=%d, ret=%d).\n", __func__, (int) j, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_open_utest_msg_g); - } - else - { /*node->f_allowed == false => not allowed to create kv name with ascii code */ - CFSTORE_TEST_UTEST_MESSAGE(cfstore_open_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: created KV in store when kv_name contains an invalid character (code=%d, ret=%d).\n", __func__, (int) j, (int) ret); - TEST_ASSERT_MESSAGE(ret < ARM_DRIVER_OK, cfstore_open_utest_msg_g); - /* revert CFSTORE_LOG for more trace */ - CFSTORE_DBGLOG("Successfully failed to create a KV with an invalid keyname containing ascii character code %d at the %s of the keyname.\n", (int) j, pos_str); - CFSTORE_LOG("%c", '.'); - } - } - } - node++; - } - - CFSTORE_LOG("%c", '\n'); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_open_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Uninitialize() call failed.\n", __func__); - TEST_ASSERT_MESSAGE(drv->Uninitialize() >= ARM_DRIVER_OK, cfstore_open_utest_msg_g); - return CaseNext; -} - - -static const char cfstore_open_ascii_illegal_buf_g[] = "!\"�$%&'()*+,./:;<=>?@[\\]^_`{|}~"; /* 31 chars */ - -/** @brief test to call cfstore_open() with key_name that in includes - * illegal characters - * - a max-length string of random illegal characters only - * - * @return on success returns CaseNext to continue to next test case, otherwise will assert on errors. - */ -control_t cfstore_open_test_06_end(const size_t call_count) -{ - char kv_name[CFSTORE_KEY_NAME_MAX_LENGTH+1]; /* extra char for terminating null */ - size_t i = 0; - uint32_t pos = 0; - int32_t ret = ARM_DRIVER_OK; - size_t name_len = CFSTORE_KEY_NAME_MAX_LENGTH; - ARM_CFSTORE_KEYDESC kdesc; - size_t buf_data_max = 0; - ARM_CFSTORE_DRIVER* drv = &cfstore_driver; - - CFSTORE_FENTRYLOG("%s:entered\n", __func__); - (void) call_count; - - /* create bad keyname strings with invalid character code at start of keyname */ - buf_data_max = strlen(cfstore_open_ascii_illegal_buf_g); - name_len = CFSTORE_KEY_NAME_MAX_LENGTH; - memset(kv_name, 0, CFSTORE_KEY_NAME_MAX_LENGTH+1); - kdesc.drl = ARM_RETENTION_WHILE_DEVICE_ACTIVE; - - /* generate a kv name of illegal chars*/ - for(i = 0; i < name_len; i++) - { - pos = rand() % (buf_data_max+1); - kv_name[i] = cfstore_open_ascii_illegal_buf_g[pos]; - } - - ret = cfstore_test_create(kv_name, kv_name, &name_len, &kdesc); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_open_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: created KV in store when kv_name contains invalid characters (ret=%d).\n", __func__, (int) ret); - TEST_ASSERT_MESSAGE(ret < ARM_DRIVER_OK, cfstore_open_utest_msg_g); - - CFSTORE_TEST_UTEST_MESSAGE(cfstore_open_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Uninitialize() call failed.\n", __func__); - TEST_ASSERT_MESSAGE(drv->Uninitialize() >= ARM_DRIVER_OK, cfstore_open_utest_msg_g); - return CaseNext; -} - -/** @brief test to call cfstore_open() with key_name that in includes - * illegal characters - * - a max-length string of random characters (legal and illegal) - * - * @return on success returns CaseNext to continue to next test case, otherwise will assert on errors. - */ -control_t cfstore_open_test_07_end(const size_t call_count) -{ - char kv_name[CFSTORE_KEY_NAME_MAX_LENGTH+1]; /* extra char for terminating null */ - size_t i = 0; - int32_t ret = ARM_DRIVER_OK; - size_t name_len = CFSTORE_KEY_NAME_MAX_LENGTH; - ARM_CFSTORE_KEYDESC kdesc; - size_t buf_data_max = 0; - ARM_CFSTORE_DRIVER* drv = &cfstore_driver; - - CFSTORE_FENTRYLOG("%s:entered\n", __func__); - (void) call_count; - - /* create bad keyname strings with invalid character code at start of keyname */ - buf_data_max = strlen(cfstore_open_ascii_illegal_buf_g); - name_len = CFSTORE_KEY_NAME_MAX_LENGTH; - memset(kv_name, 0, CFSTORE_KEY_NAME_MAX_LENGTH+1); - kdesc.drl = ARM_RETENTION_WHILE_DEVICE_ACTIVE; - - ret = cfstore_test_kv_name_gen(kv_name, name_len); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_open_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: unable to generate kv_name.\n", __func__); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK , cfstore_open_utest_msg_g); - - /* pepper the illegal chars across the string*/ - for(i++; i < buf_data_max; i++){ - kv_name[rand() % (name_len+1)] = cfstore_open_ascii_illegal_buf_g[i]; - } - ret = cfstore_test_create(kv_name, kv_name, &name_len, &kdesc); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_open_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: created KV in store when kv_name contains invalid characters (ret=%d).\n", __func__, (int) ret); - TEST_ASSERT_MESSAGE(ret < ARM_DRIVER_OK, cfstore_open_utest_msg_g); - - CFSTORE_TEST_UTEST_MESSAGE(cfstore_open_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Uninitialize() call failed.\n", __func__); - TEST_ASSERT_MESSAGE(drv->Uninitialize() >= ARM_DRIVER_OK, cfstore_open_utest_msg_g); - return CaseNext; -} - -/// @cond CFSTORE_DOXYGEN_DISABLE -utest::v1::status_t greentea_setup(const size_t number_of_cases) -{ - GREENTEA_SETUP(CFSTORE_OPEN_GREENTEA_TIMEOUT_S, "default_auto"); - return greentea_test_setup_handler(number_of_cases); -} - -Case cases[] = { - /* 1 2 3 4 5 6 7 */ - /* 1234567890123456789012345678901234567890123456789012345678901234567890 */ - Case("OPEN_test_00", cfstore_open_test_00), - Case("OPEN_test_01_start", cfstore_utest_default_start), - Case("OPEN_test_01_end", cfstore_open_test_01_end), - Case("OPEN_test_02_start", cfstore_utest_default_start), - Case("OPEN_test_02_end", cfstore_open_test_02_end), - Case("OPEN_test_03_start", cfstore_utest_default_start), - Case("OPEN_test_03_end", cfstore_open_test_03_end), - Case("OPEN_test_04_start", cfstore_utest_default_start), - Case("OPEN_test_04_end", cfstore_open_test_04_end), - Case("OPEN_test_05_start", cfstore_utest_default_start), - Case("OPEN_test_05_end", cfstore_open_test_05_end), - Case("OPEN_test_06_start", cfstore_utest_default_start), - Case("OPEN_test_06_end", cfstore_open_test_06_end), - Case("OPEN_test_07_start", cfstore_utest_default_start), - Case("OPEN_test_07_end", cfstore_open_test_07_end), -}; - - -/* Declare your test specification with a custom setup handler */ -Specification specification(greentea_setup, cases); - -int main() -{ - return !Harness::run(specification); -} -/// @endcond diff --git a/features/storage/FEATURE_STORAGE/TESTS/cfstore/read/read.cpp b/features/storage/FEATURE_STORAGE/TESTS/cfstore/read/read.cpp deleted file mode 100644 index 741fad6..0000000 --- a/features/storage/FEATURE_STORAGE/TESTS/cfstore/read/read.cpp +++ /dev/null @@ -1,180 +0,0 @@ -/* - * mbed Microcontroller Library - * Copyright (c) 2006-2016 ARM Limited - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** @file read.cpp Test cases to read KVs in the CFSTORE using the drv->Read() API call. - * - * Please consult the documentation under the test-case functions for - * a description of the individual test case. - */ - -#include "mbed.h" -#include "cfstore_config.h" -#include "cfstore_test.h" -#include "cfstore_debug.h" -#include "Driver_Common.h" -#include "configuration_store.h" -#include "utest/utest.h" -#include "unity/unity.h" -#include "greentea-client/test_env.h" -#include "cfstore_utest.h" - -#include -#include -#include - -using namespace utest::v1; - -static char cfstore_read_utest_msg_g[CFSTORE_UTEST_MSG_BUF_SIZE]; - - - -/* KV data for test_01 */ -static cfstore_kv_data_t cfstore_read_test_01_kv_data[] = { - CFSTORE_INIT_1_TABLE_MID_NODE, - { NULL, NULL}, -}; - -/* report whether built/configured for flash sync or async mode */ -static control_t cfstore_read_test_00(const size_t call_count) -{ - int32_t ret = ARM_DRIVER_ERROR; - - (void) call_count; - ret = cfstore_test_startup(); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_read_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to perform test startup (ret=%d).\n", __func__, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_read_utest_msg_g); - return CaseNext; -} - - -/* @brief check char at offset is as expected */ -static int32_t cfstore_read_seek_test(ARM_CFSTORE_HANDLE hkey, uint32_t offset, const char expected) -{ - ARM_CFSTORE_SIZE len = 1; - char read_buf[1]; - int32_t ret = ARM_DRIVER_ERROR; - ARM_CFSTORE_DRIVER* drv = &cfstore_driver; - - ret = drv->Rseek(hkey, offset); - if(ret < ARM_DRIVER_OK){ - CFSTORE_ERRLOG("%s:failed to Rseek() to desired offset (offset=%d) (ret=%d).\n", __func__, (int) offset, (int) ret); - goto out0; - } - ret = drv->Read(hkey, read_buf, &len); - if(ret < ARM_DRIVER_OK){ - CFSTORE_ERRLOG("%s:failed to Read() (offset=%d)(ret=%d).\n", __func__, (int) offset, (int) ret); - goto out0; - } - if(read_buf[0] != expected){ - ret = ARM_DRIVER_ERROR; - goto out0; - } -out0: - return ret; -} - -/** @brief - * - * @return on success returns CaseNext to continue to next test case, otherwise will assert on errors. - */ -control_t cfstore_read_test_01_end(const size_t call_count) -{ - int32_t ret = ARM_DRIVER_ERROR; - ARM_CFSTORE_SIZE len = 0; - ARM_CFSTORE_DRIVER* drv = &cfstore_driver; - ARM_CFSTORE_KEYDESC kdesc; - ARM_CFSTORE_HANDLE_INIT(hkey); - cfstore_test_rw_data_entry_t *node; - ARM_CFSTORE_FMODE flags; - - CFSTORE_DBGLOG("%s:entered\n", __func__); - (void) call_count; - memset(&kdesc, 0, sizeof(kdesc)); - memset(&flags, 0, sizeof(flags)); - - /* create a key for reading */ - kdesc.drl = ARM_RETENTION_WHILE_DEVICE_ACTIVE; - len = strlen(cfstore_read_test_01_kv_data[0].value); - ret = cfstore_test_create(cfstore_read_test_01_kv_data[0].key_name, (char*) cfstore_read_test_01_kv_data[0].value, &len, &kdesc); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_read_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to create KV in store (ret=%d).\n", __func__, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_read_utest_msg_g); - - /* now open the newly created key */ - ret = drv->Open(cfstore_read_test_01_kv_data[0].key_name, flags, hkey); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_read_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to open node (key_name=\"%s\", value=\"%s\")(ret=%d)\n", __func__, cfstore_read_test_01_kv_data[0].key_name, cfstore_read_test_01_kv_data[0].value, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_read_utest_msg_g); - - /* seek back and forth in key and check the characters are as expected */ - node = cfstore_test_rw_data_table; - while(node->offset != CFSTORE_TEST_RW_TABLE_SENTINEL) - { - ret = cfstore_read_seek_test(hkey, node->offset, node->rw_char); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_read_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Rseek() to offset (%d) didn't read expected char (\'%c\') (ret=%d)\n", __func__, (int) node->offset, node->rw_char, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_read_utest_msg_g); - node++; - } - CFSTORE_TEST_UTEST_MESSAGE(cfstore_read_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Close() call failed.\n", __func__); - TEST_ASSERT_MESSAGE(drv->Close(hkey) >= ARM_DRIVER_OK, cfstore_read_utest_msg_g); - - ret = drv->Uninitialize(); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_read_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Uninitialize() call failed.\n", __func__); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_read_utest_msg_g); - return CaseNext; -} - - -/** @brief - * - * @return on success returns CaseNext to continue to next test case, otherwise will assert on errors. - */ -control_t cfstore_read_test_02_end(const size_t call_count) -{ - (void) call_count; - /*todo: implement test */ - CFSTORE_TEST_UTEST_MESSAGE(cfstore_read_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Warn: Not implemented\n", __func__); - CFSTORE_DBGLOG("%s: WARN: requires implementation\n", __func__); - TEST_ASSERT_MESSAGE(true, cfstore_read_utest_msg_g); - return CaseNext; -} - - -/// @cond CFSTORE_DOXYGEN_DISABLE -utest::v1::status_t greentea_setup(const size_t number_of_cases) -{ - GREENTEA_SETUP(200, "default_auto"); - return greentea_test_setup_handler(number_of_cases); -} - -Case cases[] = { - /* 1 2 3 4 5 6 7 */ - /* 1234567890123456789012345678901234567890123456789012345678901234567890 */ - Case("READ_test_00", cfstore_read_test_00), - Case("READ_test_01_start", cfstore_utest_default_start), - Case("READ_test_01_end", cfstore_read_test_01_end), - Case("READ_test_02_start", cfstore_utest_default_start), - Case("READ_test_02_end", cfstore_read_test_02_end), -}; - - -/* Declare your test specification with a custom setup handler */ -Specification specification(greentea_setup, cases); - -int main() -{ - return !Harness::run(specification); -} -/// @endcond diff --git a/features/storage/FEATURE_STORAGE/TESTS/cfstore/write/write.cpp b/features/storage/FEATURE_STORAGE/TESTS/cfstore/write/write.cpp deleted file mode 100644 index 8f8421c..0000000 --- a/features/storage/FEATURE_STORAGE/TESTS/cfstore/write/write.cpp +++ /dev/null @@ -1,185 +0,0 @@ -/* - * mbed Microcontroller Library - * Copyright (c) 2006-2016 ARM Limited - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** @file write.cpp Test cases to write KVs in the CFSTORE using the drv->Write() API call. - * - * Please consult the documentation under the test-case functions for - * a description of the individual test case. - */ - -#include "mbed.h" -#include "cfstore_config.h" -#include "cfstore_test.h" -#include "cfstore_debug.h" -#include "Driver_Common.h" -#include "configuration_store.h" -#include "utest/utest.h" -#include "unity/unity.h" -#include "greentea-client/test_env.h" -#include "cfstore_utest.h" - -#include -#include -#include - -using namespace utest::v1; - -static char cfstore_write_utest_msg_g[CFSTORE_UTEST_MSG_BUF_SIZE]; - - - -/* - * write tests - * cfstore_handle_t cfstore_write() - */ - -/* KV data for test_01 */ -static cfstore_kv_data_t cfstore_write_test_01_kv_data[] = { - CFSTORE_INIT_1_TABLE_MID_NODE, - { NULL, NULL}, -}; - - -/* report whether built/configured for flash sync or async mode */ -static control_t cfstore_write_test_00(const size_t call_count) -{ - int32_t ret = ARM_DRIVER_ERROR; - - (void) call_count; - ret = cfstore_test_startup(); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_write_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to perform test startup (ret=%d).\n", __func__, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_write_utest_msg_g); - return CaseNext; -} - -/** @brief test to write many times to an open KV to test data is appended - * sequentially to the end of the value blob - * - * @return on success returns CaseNext to continue to next test case, otherwise will assert on errors. - */ -control_t cfstore_write_test_01_end(const size_t call_count) -{ - char read_buf[CFSTORE_KEY_NAME_MAX_LENGTH+1]; - uint32_t i = 0; - int32_t ret = ARM_DRIVER_ERROR; - ARM_CFSTORE_SIZE len = 0; - ARM_CFSTORE_DRIVER* drv = &cfstore_driver; - ARM_CFSTORE_KEYDESC kdesc; - ARM_CFSTORE_HANDLE_INIT(hkey); - ARM_CFSTORE_FMODE flags; - - CFSTORE_DBGLOG("%s:entered\n", __func__); - (void) call_count; - memset(read_buf, 0, CFSTORE_KEY_NAME_MAX_LENGTH+1); - memset(&kdesc, 0, sizeof(kdesc)); - memset(&flags, 0, sizeof(flags)); - - /* create an empty KV of the required length */ - kdesc.drl = ARM_RETENTION_WHILE_DEVICE_ACTIVE; - len = strlen(cfstore_write_test_01_kv_data[0].value); - ret = cfstore_test_create(cfstore_write_test_01_kv_data[0].key_name, "one", &len, &kdesc); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_write_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to create new KV (key_name=%s, ret=%d).\n", __func__, cfstore_write_test_01_kv_data[0].key_name, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_write_utest_msg_g); - - /* now open the newly created key and write repeated to created the string */ - flags.write = true; - ret = drv->Open(cfstore_write_test_01_kv_data[0].key_name, flags, hkey); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_write_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to open node (key_name=\"%s\", value=\"%s\")(ret=%d)\n", __func__, cfstore_write_test_01_kv_data[0].key_name, cfstore_write_test_01_kv_data[0].value, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_write_utest_msg_g); - - for(i = 0; i < strlen(cfstore_write_test_01_kv_data[0].value); i++) - { - len = 1; - ret = drv->Write(hkey, &cfstore_write_test_01_kv_data[0].value[i], &len); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_write_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Write failed for char (\'%c\') (ret=%d)\n", __func__, cfstore_write_test_01_kv_data[0].value[i], (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_write_utest_msg_g); - } - /* check that the value created in the key is as expected*/ - len = CFSTORE_KEY_NAME_MAX_LENGTH+1; - ret = drv->Read(hkey, read_buf, &len); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_write_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Read failed (ret=%d)\n", __func__, (int) ret); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_write_utest_msg_g); - - /* check node key_names are identical */ - CFSTORE_TEST_UTEST_MESSAGE(cfstore_write_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: KV value (%s) is not as expected (%s).\n", __func__, read_buf, cfstore_write_test_01_kv_data[0].value); - TEST_ASSERT_MESSAGE(strncmp(read_buf, cfstore_write_test_01_kv_data[0].value, strlen(cfstore_write_test_01_kv_data[0].value)) == 0, cfstore_write_utest_msg_g); - - CFSTORE_TEST_UTEST_MESSAGE(cfstore_write_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Close() call failed.\n", __func__); - TEST_ASSERT_MESSAGE(drv->Close(hkey) >= ARM_DRIVER_OK, cfstore_write_utest_msg_g); - - cfstore_test_delete_all(); - ret = drv->Uninitialize(); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_write_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Uninitialize() call failed.\n", __func__); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_write_utest_msg_g); - return CaseNext; -} - -/** @brief test to write with a NULL buffer, which should fail gracefully - * - * @return on success returns CaseNext to continue to next test case, otherwise will assert on errors. - */ -control_t cfstore_write_test_02_end(const size_t call_count) -{ - int32_t ret = ARM_DRIVER_ERROR; - ARM_CFSTORE_SIZE len = 0; - ARM_CFSTORE_KEYDESC kdesc; - ARM_CFSTORE_DRIVER* drv = &cfstore_driver; - - CFSTORE_DBGLOG("%s:entered\n", __func__); - (void) call_count; - memset(&kdesc, 0, sizeof(kdesc)); - - /* create an empty KV of the required length */ - kdesc.drl = ARM_RETENTION_WHILE_DEVICE_ACTIVE; - len = strlen(cfstore_write_test_01_kv_data[0].value); - ret = cfstore_test_create(cfstore_write_test_01_kv_data[0].key_name, NULL, &len, &kdesc); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_write_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error KV creation should have failed due to null write buffer but something else happended (ret=%d).\n", __func__, (int) ret); - TEST_ASSERT_MESSAGE(ret == ARM_CFSTORE_DRIVER_ERROR_INVALID_WRITE_BUFFER, cfstore_write_utest_msg_g); - - ret = drv->Uninitialize(); - CFSTORE_TEST_UTEST_MESSAGE(cfstore_write_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Uninitialize() call failed.\n", __func__); - TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_write_utest_msg_g); - return CaseNext; -} - - -/// @cond CFSTORE_DOXYGEN_DISABLE -utest::v1::status_t greentea_setup(const size_t number_of_cases) -{ - GREENTEA_SETUP(200, "default_auto"); - return greentea_test_setup_handler(number_of_cases); -} - -Case cases[] = { - /* 1 2 3 4 5 6 7 */ - /* 1234567890123456789012345678901234567890123456789012345678901234567890 */ - Case("WRITE_test_00", cfstore_write_test_00), - Case("WRITE_test_01_start", cfstore_utest_default_start), - Case("WRITE_test_01_end", cfstore_write_test_01_end), - Case("WRITE_test_02_start", cfstore_utest_default_start), - Case("WRITE_test_02_end", cfstore_write_test_02_end), -}; - - -/* Declare your test specification with a custom setup handler */ -Specification specification(greentea_setup, cases); - -int main() -{ - return !Harness::run(specification); -} -/// @endcond diff --git a/features/storage/FEATURE_STORAGE/TESTS/flash_journal/basicAPI/basicAPI.cpp b/features/storage/FEATURE_STORAGE/TESTS/flash_journal/basicAPI/basicAPI.cpp deleted file mode 100644 index cf42fc7..0000000 --- a/features/storage/FEATURE_STORAGE/TESTS/flash_journal/basicAPI/basicAPI.cpp +++ /dev/null @@ -1,1162 +0,0 @@ -/* - * Copyright (c) 2006-2016, ARM Limited, All Rights Reserved - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifdef TARGET_LIKE_POSIX -#define AVOID_GREENTEA -#endif - -#ifndef AVOID_GREENTEA -#include "greentea-client/test_env.h" -#endif -#include "utest/utest.h" -#include "unity/unity.h" - -#include "flash-journal-strategy-sequential/flash_journal_crc.h" -#include "flash-journal-strategy-sequential/flash_journal_strategy_sequential.h" -#include "flash-journal-strategy-sequential/flash_journal_private.h" -#include -#include - -using namespace utest::v1; - -extern ARM_DRIVER_STORAGE ARM_Driver_Storage_MTD_K64F; -const ARM_DRIVER_STORAGE *drv = &ARM_Driver_Storage_MTD_K64F; - -FlashJournal_t journal; - -static const size_t BUFFER_SIZE = 8192; -static uint8_t buffer[BUFFER_SIZE]; - -static const size_t SIZEOF_SMALL_WRITE = 8; -static const size_t SIZEOF_LARGE_WRITE = BUFFER_SIZE; -static int32_t callbackStatus; - -void callbackHandler(int32_t status, FlashJournal_OpCode_t cmd_code) -{ - callbackStatus = status; - - switch (cmd_code) { - case FLASH_JOURNAL_OPCODE_INITIALIZE: - //printf("journal_callbackHandler: callback for init with status %" PRId32 "\n", status); - break; - - case FLASH_JOURNAL_OPCODE_READ_BLOB: - //printf("journal_callbackHandler: callback for read with status %" PRId32 "\n", status); - break; - - case FLASH_JOURNAL_OPCODE_LOG_BLOB: - //printf("journal_callbackHandler: callback for log with status %" PRId32 "\n", status); - break; - - case FLASH_JOURNAL_OPCODE_COMMIT: - //printf("journal_callbackHandler: callback for commit with status %" PRId32 "\n", status); - break; - - case FLASH_JOURNAL_OPCODE_RESET: - //printf("journal_callbackHandler: callback for reset with status %" PRId32 "\n", status); - break; - - case FLASH_JOURNAL_OPCODE_FORMAT: - //printf("journal_callbackHandler: callback for format with status %" PRId32 "\n", status); - break; - - default: - //printf("journal_callbackHandler: callback for opcode %u with status %" PRId32 "\n", cmd_code, status); - break; - } - Harness::validate_callback(); // Validate the callback -} - -control_t test_format(const size_t call_count) -{ - int32_t rc; - //printf("test_format: entered with call_count %" PRIu32 "\n", (uint32_t)call_count); - - ARM_STORAGE_INFO mtdInfo; - rc = drv->GetInfo(&mtdInfo); - TEST_ASSERT_EQUAL(ARM_DRIVER_OK, rc); - TEST_ASSERT(mtdInfo.total_storage > 0); - - if (call_count == 1) { - rc = flashJournalStrategySequential_format(drv, 4 /* numSlots */, callbackHandler); - TEST_ASSERT(rc >= JOURNAL_STATUS_OK); - if (rc == JOURNAL_STATUS_OK) { - return CaseTimeout(200) + CaseRepeatAll; - } - TEST_ASSERT_EQUAL(1, rc); /* synchronous completion is expected to return 1. */ - } - - return CaseNext; -} - -void test_initializeBeforeCreate() -{ - int32_t rc = FlashJournal_initialize(&journal, drv, &FLASH_JOURNAL_STRATEGY_SEQUENTIAL, callbackHandler); - TEST_ASSERT((rc == 1) || (rc == JOURNAL_STATUS_NOT_FORMATTED)); -} - -control_t test_initialize() -{ - int32_t rc = FlashJournal_initialize(&journal, drv, &FLASH_JOURNAL_STRATEGY_SEQUENTIAL, callbackHandler); - TEST_ASSERT(rc >= JOURNAL_STATUS_OK); - if (rc == JOURNAL_STATUS_OK) { - return CaseTimeout(200); - } - - /* ensure that something got written into the memory of journal_t */ - FlashJournal_t mockJournal; - memset(&mockJournal, 0, sizeof(FlashJournal_t)); - TEST_ASSERT_NOT_EQUAL(0, memcmp(&mockJournal, &journal, sizeof(FlashJournal_t))); - - FlashJournal_Info_t info; - rc = FlashJournal_getInfo(&journal, &info); - TEST_ASSERT_EQUAL(JOURNAL_STATUS_OK, rc); - TEST_ASSERT(info.capacity > 0); - - return CaseNext; -} - -control_t test_resetAndInitialize(const size_t call_count) -{ - int32_t rc; - FlashJournal_Info_t info; - SequentialFlashJournal_t *sequentialJournal = (SequentialFlashJournal_t *)&journal; - - static uint64_t previousCapacity; - - static enum { - NEEDS_INITIAL_RESET, - NEEDS_INITIALIZE_FOLLOWING_RESET, - NEEDS_VERIFICATION_FOLLOWING_INITIALIZE, - } state; - - //printf("test_resetAndInitialize: entered with call_count %" PRIu32 "\n", (uint32_t)call_count); - if (call_count == 1) { - state = NEEDS_INITIAL_RESET; - } - - switch (state) { - case NEEDS_INITIAL_RESET: - rc = FlashJournal_getInfo(&journal, &info); - TEST_ASSERT_EQUAL(JOURNAL_STATUS_OK, rc); - TEST_ASSERT(info.capacity > 0); - previousCapacity = info.capacity; - - //printf("test_resetAndInitialize: calling reset()\n"); - rc = FlashJournal_reset(&journal); - TEST_ASSERT_NOT_EQUAL(JOURNAL_STATUS_UNSUPPORTED, rc); - TEST_ASSERT(rc >= JOURNAL_STATUS_OK); - state = NEEDS_INITIALIZE_FOLLOWING_RESET; - if (rc == JOURNAL_STATUS_OK) { - TEST_ASSERT_EQUAL(1, drv->GetCapabilities().asynchronous_ops); - return CaseTimeout(1000) + CaseRepeatAll; - } - TEST_ASSERT_EQUAL(1, rc); /* synchronous completion of reset() is expected to return 1 */ - - /* fall through */ - case NEEDS_INITIALIZE_FOLLOWING_RESET: - /* ensure that the journal has been re-initialized */ - TEST_ASSERT_EQUAL(0, sequentialJournal->nextSequenceNumber); - TEST_ASSERT_EQUAL((uint32_t)-1, sequentialJournal->currentBlobIndex); - TEST_ASSERT_EQUAL(SEQUENTIAL_JOURNAL_STATE_INITIALIZED, sequentialJournal->state); - - rc = FlashJournal_getInfo(&journal, &info); - TEST_ASSERT_EQUAL(JOURNAL_STATUS_OK, rc); - TEST_ASSERT(info.capacity > 0); - TEST_ASSERT_EQUAL(previousCapacity, info.capacity); - TEST_ASSERT_EQUAL(0, info.sizeofJournaledBlob); - - /* attempt an initialize following reset() */ - //printf("test_resetAndInitialize: calling initialize() after reset\n"); - rc = FlashJournal_initialize(&journal, drv, &FLASH_JOURNAL_STRATEGY_SEQUENTIAL, callbackHandler); - TEST_ASSERT(rc >= JOURNAL_STATUS_OK); - state = NEEDS_VERIFICATION_FOLLOWING_INITIALIZE; - if (rc == JOURNAL_STATUS_OK) { - return CaseTimeout(200); - } - TEST_ASSERT_EQUAL(1, rc); /* synchronous completion of initialize() is expected to return 1 */ - - /* fall through */ - case NEEDS_VERIFICATION_FOLLOWING_INITIALIZE: - default: - //printf("test_resetAndInitialize: verification\n"); - TEST_ASSERT_EQUAL(0, sequentialJournal->nextSequenceNumber); - TEST_ASSERT_EQUAL((uint32_t)-1, sequentialJournal->currentBlobIndex); - TEST_ASSERT_EQUAL(SEQUENTIAL_JOURNAL_STATE_INITIALIZED, sequentialJournal->state); - - rc = FlashJournal_getInfo(&journal, &info); - TEST_ASSERT_EQUAL(JOURNAL_STATUS_OK, rc); - TEST_ASSERT(info.capacity > 0); - TEST_ASSERT_EQUAL(previousCapacity, info.capacity); - TEST_ASSERT_EQUAL(0, info.sizeofJournaledBlob); - break; - } - - return CaseNext; -} - -control_t test_commitWithoutLogs(const size_t call_count) -{ - int32_t rc; - - //printf("test_commitWithoutLogs: entered with call_count %" PRIu32 "\n", (uint32_t)call_count); - - switch (call_count) { - case 1: - /* initialize */ - rc = FlashJournal_initialize(&journal, drv, &FLASH_JOURNAL_STRATEGY_SEQUENTIAL, callbackHandler); - TEST_ASSERT(rc >= ARM_DRIVER_OK); - if (rc == ARM_DRIVER_OK) { - return CaseTimeout(200) + CaseRepeatAll; - } - TEST_ASSERT_EQUAL(1, rc); /* synchronous completion of initialize() is expected to return 1 */ - return CaseRepeatAll; - - case 2: - rc = FlashJournal_commit(&journal); - //printf("commit returned %" PRId32 "\r\n", rc); - TEST_ASSERT(rc >= JOURNAL_STATUS_OK); - if (rc == JOURNAL_STATUS_OK) { - TEST_ASSERT_EQUAL(1, drv->GetCapabilities().asynchronous_ops); - return CaseTimeout(500) + CaseRepeatAll; - } - - /* intentional fall through*/ - callbackStatus = rc; - - case 3: - TEST_ASSERT_EQUAL(1, callbackStatus); - break; - } - - return CaseNext; -} - -control_t test_logSmallWithoutCommit(const size_t call_count) -{ - int32_t rc; - - //printf("test_logSmallWithoutCommit: entered with call_count %" PRIu32 "\n", (uint32_t)call_count); - - switch (call_count) { - case 1: - /* initialize */ - rc = FlashJournal_initialize(&journal, drv, &FLASH_JOURNAL_STRATEGY_SEQUENTIAL, callbackHandler); - TEST_ASSERT(rc >= ARM_DRIVER_OK); - if (rc == ARM_DRIVER_OK) { - return CaseTimeout(200) + CaseRepeatAll; - } - TEST_ASSERT_EQUAL(1, rc); /* synchronous completion of initialize() is expected to return 1 */ - return CaseRepeatAll; - - case 2: - /* log without commit */ - memset(buffer, 0xAA, SIZEOF_SMALL_WRITE); - rc = FlashJournal_log(&journal, buffer, SIZEOF_SMALL_WRITE); - TEST_ASSERT(rc >= JOURNAL_STATUS_OK); - if (rc == JOURNAL_STATUS_OK) { - TEST_ASSERT_EQUAL(1, drv->GetCapabilities().asynchronous_ops); - return CaseTimeout(500) + CaseRepeatAll; - } - /* else, fall through to synchronous verification */ - - default: - rc = FlashJournal_read(&journal, buffer, SIZEOF_SMALL_WRITE); - TEST_ASSERT(rc < JOURNAL_STATUS_OK); - return CaseNext; - } -} - -template -control_t test_logSmallAndCommit(const size_t call_count) -{ - int32_t rc; - - //printf("test_logSmallAndCommit: entered with call_count %" PRIu32 "\n", (uint32_t)call_count); - - switch (call_count) { - case 1: - memset(buffer, PATTERN, SIZEOF_SMALL_WRITE); - rc = FlashJournal_log(&journal, buffer, SIZEOF_SMALL_WRITE); - TEST_ASSERT(rc >= JOURNAL_STATUS_OK); - if (rc == JOURNAL_STATUS_OK) { - TEST_ASSERT_EQUAL(1, drv->GetCapabilities().asynchronous_ops); - return CaseTimeout(500) + CaseRepeatAll; - } - /* else, fall through to synchronous verification */ - - case 2: - rc = FlashJournal_commit(&journal); - TEST_ASSERT(rc >= JOURNAL_STATUS_OK); - if (rc == JOURNAL_STATUS_OK) { - TEST_ASSERT_EQUAL(1, drv->GetCapabilities().asynchronous_ops); - return CaseTimeout(500) + CaseRepeatAll; - } - /* else, fall through to synchronous verification */ - - case 3: - { - FlashJournal_Info_t info; - rc = FlashJournal_getInfo(&journal, &info); - TEST_ASSERT_EQUAL(JOURNAL_STATUS_OK, rc); - TEST_ASSERT_EQUAL(SIZEOF_SMALL_WRITE, info.sizeofJournaledBlob); - } - - rc = FlashJournal_read(&journal, buffer, SIZEOF_SMALL_WRITE); - TEST_ASSERT(rc >= JOURNAL_STATUS_OK); - if (rc == JOURNAL_STATUS_OK) { - TEST_ASSERT_EQUAL(1, drv->GetCapabilities().asynchronous_ops); - return CaseTimeout(500) + CaseRepeatAll; - } - - TEST_ASSERT_EQUAL(SIZEOF_SMALL_WRITE, rc); - /* intentional fall-through */ - - default: - for (unsigned i = 0; i < SIZEOF_SMALL_WRITE; i++) { - // printf("index %u value %x\n", i, buffer[i]); - TEST_ASSERT_EQUAL(PATTERN, buffer[i]); - } - - return CaseNext; - } -} - -control_t test_initializeAfterLogSmallAndCommit(const size_t call_count) -{ - int32_t rc; - - //printf("test_initializeAfterLogSmallAndCommit: entered with call_count %" PRIu32 "\n", (uint32_t)call_count); - - if (call_count == 1) { - rc = FlashJournal_initialize(&journal, drv, &FLASH_JOURNAL_STRATEGY_SEQUENTIAL, callbackHandler); - TEST_ASSERT(rc >= JOURNAL_STATUS_OK); - if (rc == JOURNAL_STATUS_OK) { - //printf("asynchronous_ops for init\n"); - return CaseTimeout(200) + CaseRepeatAll; - } - TEST_ASSERT_EQUAL(1, rc); /* synchronous completion of initialize() is expected to return 1 */ - } - - FlashJournal_Info_t info; - rc = FlashJournal_getInfo(&journal, &info); - TEST_ASSERT_EQUAL(JOURNAL_STATUS_OK, rc); - TEST_ASSERT_EQUAL(SIZEOF_SMALL_WRITE, info.sizeofJournaledBlob); - - return CaseNext; -} - -control_t test_logLargeWithoutCommit(const size_t call_count) -{ - int32_t rc; - - //printf("test_logLargeWithoutCommit: entered with call_count %" PRIu32 "\n", (uint32_t)call_count); - - switch (call_count) { - case 1: - rc = FlashJournal_initialize(&journal, drv, &FLASH_JOURNAL_STRATEGY_SEQUENTIAL, callbackHandler); - TEST_ASSERT(rc >= ARM_DRIVER_OK); - if (rc == ARM_DRIVER_OK) { - return CaseTimeout(200) + CaseRepeatAll; - } - TEST_ASSERT_EQUAL(1, rc); /* synchronous completion of initialize() is expected to return 1 */ - return CaseRepeatAll; - - case 2: - memset(buffer, 0xAA, SIZEOF_LARGE_WRITE); - rc = FlashJournal_log(&journal, buffer, SIZEOF_LARGE_WRITE); - TEST_ASSERT(rc >= JOURNAL_STATUS_OK); - if (rc == JOURNAL_STATUS_OK) { - TEST_ASSERT_EQUAL(1, drv->GetCapabilities().asynchronous_ops); - return CaseTimeout(5000) + CaseRepeatAll; - } - /* intentional fall-through */ - - case 3: - default: - rc = FlashJournal_read(&journal, buffer, SIZEOF_LARGE_WRITE); - TEST_ASSERT(rc < JOURNAL_STATUS_OK); - return CaseNext; - } -} - -template -control_t test_logLargeAndCommit(const size_t call_count) -{ - int32_t rc; - - //printf("test_logLargeAndCommit: entered with call_count %" PRIu32 "\n", (uint32_t)call_count); - - switch (call_count) { - case 1: - memset(buffer, PATTERN, SIZEOF_LARGE_WRITE); - rc = FlashJournal_log(&journal, buffer, SIZEOF_LARGE_WRITE); - TEST_ASSERT(rc >= JOURNAL_STATUS_OK); - if (rc == JOURNAL_STATUS_OK) { - TEST_ASSERT_EQUAL(1, drv->GetCapabilities().asynchronous_ops); - return CaseTimeout(500) + CaseRepeatAll; - } - /* intentional fall-through */ - - case 2: - rc = FlashJournal_commit(&journal); - TEST_ASSERT(rc >= JOURNAL_STATUS_OK); - if (rc == JOURNAL_STATUS_OK) { - TEST_ASSERT_EQUAL(1, drv->GetCapabilities().asynchronous_ops); - return CaseTimeout(500) + CaseRepeatAll; - } - /* intentional fall-through */ - - case 3: - { - FlashJournal_Info_t info; - rc = FlashJournal_getInfo(&journal, &info); - TEST_ASSERT_EQUAL(JOURNAL_STATUS_OK, rc); - TEST_ASSERT_EQUAL(SIZEOF_LARGE_WRITE, info.sizeofJournaledBlob); - } - - rc = FlashJournal_read(&journal, buffer, SIZEOF_LARGE_WRITE); - TEST_ASSERT(rc >= JOURNAL_STATUS_OK); - if (rc == JOURNAL_STATUS_OK) { - TEST_ASSERT_EQUAL(1, drv->GetCapabilities().asynchronous_ops); - return CaseTimeout(500) + CaseRepeatAll; - } - - TEST_ASSERT_EQUAL(SIZEOF_LARGE_WRITE, rc); - /* intentional fall-through */ - - default: - for (unsigned i = 0; i < SIZEOF_LARGE_WRITE; i++) { - // printf("index %u value %x\n", i, buffer[i]); - TEST_ASSERT_EQUAL(PATTERN, buffer[i]); - } - - return CaseNext; - } -} - -control_t test_initializeAfterLogLargeAndCommit(const size_t call_count) -{ - int32_t rc; - - //printf("test_initializeAfterLogLargeAndCommit: entered with call_count %" PRIu32 "\n", (uint32_t)call_count); - - if (call_count == 1) { - rc = FlashJournal_initialize(&journal, drv, &FLASH_JOURNAL_STRATEGY_SEQUENTIAL, callbackHandler); - TEST_ASSERT(rc >= JOURNAL_STATUS_OK); - if (rc == JOURNAL_STATUS_OK) { - //printf("test_initializeAfterLogLargeAndCommit: asynchronous_ops for init\n"); - return CaseTimeout(200) + CaseRepeatAll; - } - TEST_ASSERT_EQUAL(1, rc); /* synchronous completion of initialize() is expected to return 1 */ - } - - FlashJournal_Info_t info; - rc = FlashJournal_getInfo(&journal, &info); - TEST_ASSERT_EQUAL(JOURNAL_STATUS_OK, rc); - TEST_ASSERT_EQUAL(SIZEOF_LARGE_WRITE, info.sizeofJournaledBlob); - - return CaseNext; -} - -template -control_t test_logLargeAndReadSmallChunks(const size_t call_count) -{ - int32_t rc; - - //printf("test_logLargeAndReadSmallChunks: entered with call_count %" PRIu32 "\n", (uint32_t)call_count); - - static const size_t SMALL_CHUNK_COUNT = 4; - - switch (call_count) { - case 1: - memset(buffer, PATTERN, SIZEOF_LARGE_WRITE); - rc = FlashJournal_log(&journal, buffer, SIZEOF_LARGE_WRITE); - TEST_ASSERT(rc >= JOURNAL_STATUS_OK); - if (rc == JOURNAL_STATUS_OK) { - TEST_ASSERT_EQUAL(1, drv->GetCapabilities().asynchronous_ops); - return CaseTimeout(500) + CaseRepeatAll; - } - /* intentional fall-through */ - - case 2: - rc = FlashJournal_commit(&journal); - TEST_ASSERT(rc >= JOURNAL_STATUS_OK); - if (rc == JOURNAL_STATUS_OK) { - TEST_ASSERT_EQUAL(1, drv->GetCapabilities().asynchronous_ops); - return CaseTimeout(500) + CaseRepeatAll; - } - /* intentional fall-through */ - - case 3: - { - FlashJournal_Info_t info; - rc = FlashJournal_getInfo(&journal, &info); - TEST_ASSERT_EQUAL(JOURNAL_STATUS_OK, rc); - TEST_ASSERT_EQUAL(SIZEOF_LARGE_WRITE, info.sizeofJournaledBlob); - } - /* intentional fall-through */ - - default: - break; - } - - if (call_count > 3) { - if (drv->GetCapabilities().asynchronous_ops) { - if (callbackStatus == 0) { - return CaseNext; /* termination condition */ - } - TEST_ASSERT_EQUAL(SIZEOF_LARGE_WRITE / SMALL_CHUNK_COUNT, callbackStatus); - } - - for (unsigned i = 0; i < SIZEOF_LARGE_WRITE / SMALL_CHUNK_COUNT; i++) { - // printf("index %u value %x\n", i, buffer[i]); - TEST_ASSERT_EQUAL(PATTERN, buffer[i]); - } - } - - while ((rc = FlashJournal_read(&journal, buffer, SIZEOF_LARGE_WRITE / SMALL_CHUNK_COUNT)) != JOURNAL_STATUS_EMPTY) { - // printf("read returned %" PRId32 "\n", rc); - TEST_ASSERT(rc >= JOURNAL_STATUS_OK); - if (rc == JOURNAL_STATUS_OK) { - TEST_ASSERT_EQUAL(1, drv->GetCapabilities().asynchronous_ops); - return CaseTimeout(500) + CaseRepeatAll; - } - - TEST_ASSERT_EQUAL(SIZEOF_LARGE_WRITE / SMALL_CHUNK_COUNT, rc); - for (unsigned i = 0; i < SIZEOF_LARGE_WRITE / SMALL_CHUNK_COUNT; i++) { - // printf("index %u value %x\n", i, buffer[i]); - TEST_ASSERT_EQUAL(PATTERN, buffer[i]); - } - }; - - return CaseNext; -} - -template -control_t test_readLargeInSmallOddChunks(const size_t call_count) -{ - int32_t rc; - - //printf("test_readLargeInSmallOddChunks<0x%02x, %" PRIu32 ">: entered with call_count %" PRIu32 "\n", PATTERN, (uint32_t)SIZEOF_READS, (uint32_t)call_count); - - if (call_count == 1) { - FlashJournal_Info_t info; - rc = FlashJournal_getInfo(&journal, &info); - TEST_ASSERT_EQUAL(JOURNAL_STATUS_OK, rc); - TEST_ASSERT_EQUAL(SIZEOF_LARGE_WRITE, info.sizeofJournaledBlob); - TEST_ASSERT(SIZEOF_READS < info.sizeofJournaledBlob); - } else { - if (drv->GetCapabilities().asynchronous_ops) { - if (callbackStatus == 0) { - return CaseNext; /* termination condition */ - } - TEST_ASSERT_EQUAL(SIZEOF_READS, callbackStatus); - } - - for (unsigned i = 0; i < SIZEOF_READS; i++) { - // printf("index %u value %x\n", i, buffer[i]); - TEST_ASSERT_EQUAL(PATTERN, buffer[i]); - } - } - - while ((rc = FlashJournal_read(&journal, buffer, SIZEOF_READS)) != JOURNAL_STATUS_EMPTY) { - // printf("read returned %" PRId32 "\n", rc); - TEST_ASSERT(rc >= JOURNAL_STATUS_OK); - if (rc == JOURNAL_STATUS_OK) { - TEST_ASSERT_EQUAL(1, drv->GetCapabilities().asynchronous_ops); - return CaseTimeout(500) + CaseRepeatAll; - } - - TEST_ASSERT(rc <= (int32_t)SIZEOF_READS); - for (unsigned i = 0; i < (unsigned)rc; i++) { - // printf("index %u value %x\n", i, buffer[i]); - TEST_ASSERT_EQUAL(PATTERN, buffer[i]); - } - }; - - return CaseNext; -} - -template -control_t test_logPattern(size_t call_count) -{ - int32_t rc = JOURNAL_STATUS_OK; - - //printf("test_logpattern: entered with call_count %" PRIu32 "\n", (uint32_t)call_count); - - switch (call_count) { - case 1: - for (unsigned index = 0; index < SIZEOF_LARGE_WRITE; index++) { - buffer[index] = (uint8_t)(PATTERN ^ index); - } - rc = FlashJournal_log(&journal, buffer, SIZEOF_LARGE_WRITE); - TEST_ASSERT(rc >= JOURNAL_STATUS_OK); - if (rc == JOURNAL_STATUS_OK) { - TEST_ASSERT_EQUAL(1, drv->GetCapabilities().asynchronous_ops); - return CaseTimeout(500) + CaseRepeatAll; - } - /* intentional fall-through */ - call_count = 2; - - case 2: - rc = FlashJournal_commit(&journal); - TEST_ASSERT(rc >= JOURNAL_STATUS_OK); - if (rc == JOURNAL_STATUS_OK) { - TEST_ASSERT_EQUAL(1, drv->GetCapabilities().asynchronous_ops); - return CaseTimeout(500) + CaseRepeatAll; - } - callbackStatus = rc; - /* intentional fall-through */ - call_count = 3; - - case 3: - { - FlashJournal_Info_t info; - rc = FlashJournal_getInfo(&journal, &info); - TEST_ASSERT_EQUAL(JOURNAL_STATUS_OK, rc); - TEST_ASSERT_EQUAL(SIZEOF_LARGE_WRITE, info.sizeofJournaledBlob); - } - /* intentional fall-through */ - call_count = 4; - - case 4: - TEST_ASSERT_EQUAL(1, callbackStatus); - - rc = FlashJournal_read(&journal, buffer, SIZEOF_LARGE_WRITE); - TEST_ASSERT(rc >= JOURNAL_STATUS_OK); - if (rc == JOURNAL_STATUS_OK) { - TEST_ASSERT_EQUAL(1, drv->GetCapabilities().asynchronous_ops); - return CaseTimeout(500) + CaseRepeatAll; - } - callbackStatus = rc; - /* intentional fall-through */ - call_count = 4; - - case 5: - TEST_ASSERT_EQUAL(SIZEOF_LARGE_WRITE, rc); - for (unsigned i = 0; i < SIZEOF_LARGE_WRITE; i++) { - // printf("index %u value %x\n", i, buffer[i]); - TEST_ASSERT_EQUAL((uint8_t)(PATTERN ^ i), buffer[i]); - } - break; - - default: - TEST_ASSERT(false); - break; - } - - return CaseNext; -} - -template -control_t test_readFromInReverse(const size_t call_count) -{ - int32_t rc; - static size_t offset = SIZEOF_LARGE_WRITE; - - //printf("test_readFrom<0x%02x, %" PRIu32 ">: entered with call_count %" PRIu32 "\n", PATTERN, (uint32_t)SIZEOF_READS, (uint32_t)call_count); - - if (call_count == 1) { - FlashJournal_Info_t info; - rc = FlashJournal_getInfo(&journal, &info); - TEST_ASSERT_EQUAL(JOURNAL_STATUS_OK, rc); - TEST_ASSERT_EQUAL(SIZEOF_LARGE_WRITE, info.sizeofJournaledBlob); - TEST_ASSERT(SIZEOF_READS <= info.sizeofJournaledBlob); - - rc = FlashJournal_readFrom(&journal, offset + 1, buffer, SIZEOF_READS); - TEST_ASSERT_EQUAL(JOURNAL_STATUS_EMPTY, rc); - rc = FlashJournal_readFrom(&journal, offset, buffer, SIZEOF_READS); - TEST_ASSERT_EQUAL(JOURNAL_STATUS_EMPTY, rc); - offset -= SIZEOF_READS; - } else { - if (drv->GetCapabilities().asynchronous_ops) { - if (callbackStatus == 0) { - return CaseNext; /* termination condition */ - } - TEST_ASSERT_EQUAL(SIZEOF_READS, callbackStatus); - } - - for (unsigned i = 0; i < SIZEOF_READS; i++) { - // printf("index %u value %x\n", i, buffer[i]); - TEST_ASSERT_EQUAL((uint8_t)(PATTERN ^ (offset + i)), buffer[i]); - } - if (offset == 0) { - return CaseNext; - } - if (offset >= SIZEOF_READS) { - offset -= SIZEOF_READS; - } else { - offset = 0; - } - } - - // printf("test_readFrom: issuing read at offset %lu\n", offset); - while ((rc = FlashJournal_readFrom(&journal, offset, buffer, SIZEOF_READS)) != JOURNAL_STATUS_EMPTY) { - // printf("read returned %" PRId32 "\n", rc); - TEST_ASSERT(rc >= JOURNAL_STATUS_OK); - if (rc == JOURNAL_STATUS_OK) { - TEST_ASSERT_EQUAL(1, drv->GetCapabilities().asynchronous_ops); - return CaseTimeout(500) + CaseRepeatAll; - } - - TEST_ASSERT(rc <= (int32_t)SIZEOF_READS); - for (unsigned i = 0; i < (unsigned)rc; i++) { - // printf("index %u value %x\n", i, buffer[i]); - TEST_ASSERT_EQUAL((uint8_t)(PATTERN ^ (offset + i)), buffer[i]); - } - if (offset == 0) { - return CaseNext; - } - if (offset >= SIZEOF_READS) { - offset -= SIZEOF_READS; - } else { - offset = 0; - } - // printf("test_readFrom: issuing read at offset %lu\n", offset); - }; - - return CaseNext; -} - -template -control_t test_readFromFollowedByReads(size_t call_count) -{ - //printf("test_readFrom<0x%02x, %" PRIu32 ">: entered with call_count %" PRIu32 "\n", PATTERN, (uint32_t)SIZEOF_READS, (uint32_t)call_count); - - int32_t rc; - static size_t offset = SIZEOF_LARGE_WRITE / 2; - - FlashJournal_Info_t info; - switch (call_count) { - case 1: - rc = FlashJournal_getInfo(&journal, &info); - TEST_ASSERT_EQUAL(JOURNAL_STATUS_OK, rc); - TEST_ASSERT_EQUAL(SIZEOF_LARGE_WRITE, info.sizeofJournaledBlob); - TEST_ASSERT(SIZEOF_READS <= (info.sizeofJournaledBlob - offset)); - - rc = FlashJournal_readFrom(&journal, offset, buffer, SIZEOF_READS); - TEST_ASSERT(rc >= JOURNAL_STATUS_OK); - if (rc == JOURNAL_STATUS_OK) { - TEST_ASSERT_EQUAL(1, drv->GetCapabilities().asynchronous_ops); - return CaseTimeout(500) + CaseRepeatAll; - } - callbackStatus = rc; - /* intentional fall-through */ - call_count = 2; - - case 2: - /* verify the previous readFrom */ - TEST_ASSERT_EQUAL(SIZEOF_READS, callbackStatus); - for (unsigned i = 0; i < (unsigned)callbackStatus; i++) { - // printf("index %u value %x\n", i, buffer[i]); - TEST_ASSERT_EQUAL((uint8_t)(PATTERN ^ (offset + i)), buffer[i]); - } - - /* issue a sequential read to follow the previous readFrom */ - rc = FlashJournal_read(&journal, buffer, SIZEOF_READS); - TEST_ASSERT(rc >= JOURNAL_STATUS_OK); - if (rc == JOURNAL_STATUS_OK) { - TEST_ASSERT_EQUAL(1, drv->GetCapabilities().asynchronous_ops); - return CaseTimeout(500) + CaseRepeatAll; - } - callbackStatus = rc; - /* intentional fall-through */ - call_count = 3; - - case 3: - TEST_ASSERT_EQUAL(SIZEOF_READS, callbackStatus); - - for (unsigned i = 0; i < (unsigned)callbackStatus; i++) { - // printf("index %u value %x\n", i, buffer[i]); - TEST_ASSERT_EQUAL((uint8_t)(PATTERN ^ (offset + SIZEOF_READS + i)), buffer[i]); - } - break; - } - - return CaseNext; -} - -template -control_t test_logSeveralOddSizedChunks(size_t call_count) -{ - TEST_ASSERT(N_WRITES >= 1); - - int32_t rc; - - static const uint8_t PATTERN = 0xAA; - static size_t totalDataLogged = 0; - - //printf("test_logSeveralOddSizedChunks<%" PRIu32 ", %" PRIu32 ">: entered with call_count %" PRIu32 "\n", (uint32_t)SIZEOF_ODD_CHUNK, (uint32_t)N_WRITES, (uint32_t)call_count); - TEST_ASSERT(SIZEOF_ODD_CHUNK <= BUFFER_SIZE); - - /* check the status of the previous asynchronous operation */ - if ((call_count > 1) && (call_count <= (N_WRITES + 1))) { - TEST_ASSERT((callbackStatus >= JOURNAL_STATUS_OK) || (callbackStatus == JOURNAL_STATUS_SMALL_LOG_REQUEST)); - if (callbackStatus == JOURNAL_STATUS_SMALL_LOG_REQUEST) { - FlashJournal_Info_t info; - rc = FlashJournal_getInfo(&journal, &info); - TEST_ASSERT_EQUAL(JOURNAL_STATUS_OK, rc); - TEST_ASSERT(SIZEOF_ODD_CHUNK < info.program_unit); - //printf("test_logSeveralOddSizedChunks: RETURNING CaseNext\n"); - return CaseNext; - } - - size_t sizeofLoggedData = callbackStatus; - TEST_ASSERT((size_t)sizeofLoggedData <= SIZEOF_ODD_CHUNK); - if (sizeofLoggedData < SIZEOF_ODD_CHUNK) { - FlashJournal_Info_t info; - rc = FlashJournal_getInfo(&journal, &info); - TEST_ASSERT_EQUAL(JOURNAL_STATUS_OK, rc); - TEST_ASSERT((sizeofLoggedData % info.program_unit) == 0); - } - totalDataLogged += sizeofLoggedData; - } - - while (call_count <= N_WRITES) { - //printf("test_logSeveralOddSizedChunks: iteration with call_count %" PRIu32 "\n", (uint32_t)call_count); - memset(buffer, PATTERN, SIZEOF_ODD_CHUNK); - rc = FlashJournal_log(&journal, buffer, SIZEOF_ODD_CHUNK); - // printf("test_logSeveralOddSizedChunks: called FlashJournal_log(): rc = %" PRId32 "\n", rc); - TEST_ASSERT((rc >= JOURNAL_STATUS_OK) || (rc == JOURNAL_STATUS_SMALL_LOG_REQUEST)); - if (rc == JOURNAL_STATUS_OK) { - TEST_ASSERT_EQUAL(1, drv->GetCapabilities().asynchronous_ops); - return CaseTimeout(500) + CaseRepeatAll; - } - - if (rc == JOURNAL_STATUS_SMALL_LOG_REQUEST) { - FlashJournal_Info_t info; - rc = FlashJournal_getInfo(&journal, &info); - TEST_ASSERT_EQUAL(JOURNAL_STATUS_OK, rc); - TEST_ASSERT(SIZEOF_ODD_CHUNK < info.program_unit); - return CaseNext; - } - - size_t sizeofLoggedData = rc; - TEST_ASSERT(sizeofLoggedData <= SIZEOF_ODD_CHUNK); /* the amount actually written is expected to be less than the original */ - if (sizeofLoggedData < SIZEOF_ODD_CHUNK) { - FlashJournal_Info_t info; - rc = FlashJournal_getInfo(&journal, &info); - TEST_ASSERT_EQUAL(JOURNAL_STATUS_OK, rc); - TEST_ASSERT((sizeofLoggedData % info.program_unit) == 0); - } - - totalDataLogged += sizeofLoggedData; - ++call_count; /* simulate CaseRepeatAll for the synchronous case */ - } - - if (call_count == (N_WRITES + 1)) { - rc = FlashJournal_commit(&journal); - TEST_ASSERT(rc >= JOURNAL_STATUS_OK); - if (rc == JOURNAL_STATUS_OK) { - TEST_ASSERT_EQUAL(1, drv->GetCapabilities().asynchronous_ops); - return CaseTimeout(500) + CaseRepeatAll; - } - - callbackStatus = rc; - } - - TEST_ASSERT_EQUAL(1, callbackStatus); - { - FlashJournal_Info_t info; - rc = FlashJournal_getInfo(&journal, &info); - TEST_ASSERT_EQUAL(JOURNAL_STATUS_OK, rc); - TEST_ASSERT_EQUAL(totalDataLogged, info.sizeofJournaledBlob); - } - - return CaseNext; -} - -control_t test_multipleWritesFollowedByCommitFollowedByMultipleReads(const size_t call_count) -{ - int32_t rc; - - static const uint8_t PATTERN = 0xAA; - static const size_t N_WRITES = 4; - static const size_t N_READS = N_WRITES; - static const size_t SIZEOF_WRITE = BUFFER_SIZE / N_WRITES; - static const size_t SIZEOF_READ = BUFFER_SIZE / N_READS; - - //printf("test_multipleWritesFollowedByCommitFollowedByMultipleReads: entered with call_count %" PRIu32 "\n", (uint32_t)call_count); - - if (call_count <= N_WRITES) { - //printf("writing pattern %02" PRIx8 "\n", (uint8_t)(PATTERN ^ call_count)); - memset(buffer, (PATTERN ^ call_count), SIZEOF_WRITE); - rc = FlashJournal_log(&journal, buffer, SIZEOF_WRITE); - //printf("test_multipleWritesFollowedByCommitFollowedByMultipleReads: log returned %" PRId32 "\n", rc); - TEST_ASSERT(rc >= JOURNAL_STATUS_OK); - if (rc == JOURNAL_STATUS_OK) { - TEST_ASSERT_EQUAL(1, drv->GetCapabilities().asynchronous_ops); - return CaseTimeout(500) + CaseRepeatAll; - } - TEST_ASSERT_EQUAL(SIZEOF_WRITE, rc); - return CaseRepeatAll; - } else if (call_count == (N_WRITES + 1)) { - rc = FlashJournal_commit(&journal); - TEST_ASSERT(rc >= JOURNAL_STATUS_OK); - if (rc == JOURNAL_STATUS_OK) { - TEST_ASSERT_EQUAL(1, drv->GetCapabilities().asynchronous_ops); - return CaseTimeout(500) + CaseRepeatAll; - } - //printf("test_multipleWritesFollowedByCommitFollowedByMultipleReads: commit returned %" PRId32 "\n", rc); - callbackStatus = rc; /* pass forward the return value so that the next iteration can check callbackStatus */ - return CaseRepeatAll; - } else if (call_count < (N_WRITES + 1 + N_READS + 1)) { - unsigned readIteration = call_count - (N_WRITES + 1); - //printf("test_multipleWritesFollowedByCommitFollowedByMultipleReads: read iteration %u\n", readIteration); - if (call_count == (N_WRITES + 1 /* commit */ + 1 /* first iteration after commit */)) { - TEST_ASSERT_EQUAL(1, callbackStatus); - - FlashJournal_Info_t info; - rc = FlashJournal_getInfo(&journal, &info); - TEST_ASSERT_EQUAL(JOURNAL_STATUS_OK, rc); - TEST_ASSERT_EQUAL(BUFFER_SIZE, info.sizeofJournaledBlob); - } else { - TEST_ASSERT_EQUAL(SIZEOF_READ, callbackStatus); - for (unsigned i = 0; i < SIZEOF_READ; i++) { - // printf("test_multipleWritesFollowedByCommitFollowedByMultipleReads: index %u value %x\n", i, buffer[i]); - TEST_ASSERT_EQUAL(PATTERN ^ (readIteration - 1), buffer[i]); - } - } - - while ((rc = FlashJournal_read(&journal, buffer, SIZEOF_READ)) != JOURNAL_STATUS_EMPTY) { - // printf("test_multipleWritesFollowedByCommitFollowedByMultipleReads: read returned %" PRId32 "\n", rc); - TEST_ASSERT((rc == JOURNAL_STATUS_OK) || (rc == SIZEOF_READ)); - if (rc == JOURNAL_STATUS_OK) { - TEST_ASSERT_EQUAL(1, drv->GetCapabilities().asynchronous_ops); - return CaseTimeout(500) + CaseRepeatAll; - } - - TEST_ASSERT_EQUAL(SIZEOF_READ, rc); - //printf("test_multipleWritesFollowedByCommitFollowedByMultipleReads: checking for pattern %02x\n", PATTERN ^ readIteration); - for (unsigned i = 0; i < SIZEOF_READ; i++) { - // printf("index %u value %x\n", i, buffer[i]); - TEST_ASSERT_EQUAL(PATTERN ^ readIteration, buffer[i]); - } - ++readIteration; - }; - TEST_ASSERT_EQUAL(N_READS + 1, readIteration); - } - - return CaseNext; -} - -control_t test_failedSmallWriteFollowedByPaddedWrite(const size_t call_count) -{ - int32_t rc; - - static const uint8_t PATTERN = 0xAA; - - //printf("test_failedSmallWriteFollowedByPaddedWrite: entered with call_count %" PRIu32 "\n", (uint32_t)call_count); - - FlashJournal_Info_t info; - rc = FlashJournal_getInfo(&journal, &info); - TEST_ASSERT_EQUAL(JOURNAL_STATUS_OK, rc); - TEST_ASSERT(info.program_unit >= 1); - if (info.program_unit == 1) { - return CaseNext; - } - - static const size_t SMALL_CONSTANT = 8 * info.program_unit; - static const size_t SIZEOF_WRITE = (info.program_unit - 1) + SMALL_CONSTANT; - TEST_ASSERT(SIZEOF_WRITE <= BUFFER_SIZE); - - memset(buffer, PATTERN, SIZEOF_WRITE); - - if (call_count == 1) { - rc = FlashJournal_log(&journal, buffer, SIZEOF_WRITE); - TEST_ASSERT(rc >= JOURNAL_STATUS_OK); - if (rc == JOURNAL_STATUS_OK) { - TEST_ASSERT_EQUAL(1, drv->GetCapabilities().asynchronous_ops); - return CaseTimeout(500) + CaseRepeatAll; - } - TEST_ASSERT_EQUAL(SMALL_CONSTANT, rc); - callbackStatus = rc; - return CaseRepeatAll; - } else if (call_count == 2) { - TEST_ASSERT_EQUAL(SMALL_CONSTANT, callbackStatus); - rc = FlashJournal_log(&journal, buffer, SIZEOF_WRITE - callbackStatus); - TEST_ASSERT_EQUAL(JOURNAL_STATUS_SMALL_LOG_REQUEST, rc); - - rc = FlashJournal_getInfo(&journal, &info); - TEST_ASSERT_EQUAL(JOURNAL_STATUS_OK, rc); - TEST_ASSERT(info.program_unit >= 1); - TEST_ASSERT(info.program_unit <= BUFFER_SIZE); - - rc = FlashJournal_log(&journal, buffer, info.program_unit); - TEST_ASSERT(rc >= JOURNAL_STATUS_OK); - if (rc == JOURNAL_STATUS_OK) { - TEST_ASSERT_EQUAL(1, drv->GetCapabilities().asynchronous_ops); - return CaseTimeout(500) + CaseRepeatAll; - } - TEST_ASSERT_EQUAL(info.program_unit, rc); - callbackStatus = rc; - return CaseRepeatAll; - } else if (call_count == 3) { - rc = FlashJournal_commit(&journal); - TEST_ASSERT(rc >= JOURNAL_STATUS_OK); - if (rc == JOURNAL_STATUS_OK) { - TEST_ASSERT_EQUAL(1, drv->GetCapabilities().asynchronous_ops); - return CaseTimeout(500) + CaseRepeatAll; - } - TEST_ASSERT_EQUAL(1, rc); - callbackStatus = rc; - return CaseRepeatAll; - } else { - TEST_ASSERT_EQUAL(1, callbackStatus); - - rc = FlashJournal_getInfo(&journal, &info); - TEST_ASSERT_EQUAL(JOURNAL_STATUS_OK, rc); - TEST_ASSERT_EQUAL((SIZEOF_WRITE + 1), info.sizeofJournaledBlob); - } - - return CaseNext; -} - -void test_crc32() -{ - const unsigned char dummyMsg[] = "ahello world"; - flashJournalCrcReset(); TEST_ASSERT_EQUAL(0xe8b7be43, flashJournalCrcCummulative(dummyMsg, 1)); - flashJournalCrcReset(); TEST_ASSERT_EQUAL(0x7e56a173, flashJournalCrcCummulative(dummyMsg, 2)); - flashJournalCrcReset(); TEST_ASSERT_EQUAL(0x26a80c7d, flashJournalCrcCummulative(dummyMsg, 3)); - flashJournalCrcReset(); TEST_ASSERT_EQUAL(0xb8946773, flashJournalCrcCummulative(dummyMsg, 4)); - flashJournalCrcReset(); TEST_ASSERT_EQUAL(0x5fb2761f, flashJournalCrcCummulative(dummyMsg, 5)); - flashJournalCrcReset(); TEST_ASSERT_EQUAL(0x82582cc7, flashJournalCrcCummulative(dummyMsg, 6)); - flashJournalCrcReset(); TEST_ASSERT_EQUAL(0xeceec07a, flashJournalCrcCummulative(dummyMsg, 7)); - flashJournalCrcReset(); TEST_ASSERT_EQUAL(0xac5f7df0, flashJournalCrcCummulative(dummyMsg, 8)); - flashJournalCrcReset(); TEST_ASSERT_EQUAL(0xb21e3e25, flashJournalCrcCummulative(dummyMsg, 9)); - flashJournalCrcReset(); TEST_ASSERT_EQUAL(0x27bf35e4, flashJournalCrcCummulative(dummyMsg, 10)); - flashJournalCrcReset(); TEST_ASSERT_EQUAL(0x31465baa, flashJournalCrcCummulative(dummyMsg, 11)); - flashJournalCrcReset(); TEST_ASSERT_EQUAL(0xaeef4661, flashJournalCrcCummulative(dummyMsg, 12)); - - /* check for composability */ - uint32_t crc; - for (unsigned msgLen = 1; msgLen < strlen((const char *)dummyMsg); msgLen++) { - for (unsigned partitionIndex = 1; partitionIndex < msgLen; partitionIndex++) { - flashJournalCrcReset(); crc = flashJournalCrcCummulative(dummyMsg, partitionIndex); crc = flashJournalCrcCummulative(dummyMsg + partitionIndex, msgLen - partitionIndex); - flashJournalCrcReset(); TEST_ASSERT_EQUAL(flashJournalCrcCummulative(dummyMsg, msgLen), crc); - } - } -} - -#ifndef AVOID_GREENTEA -// Custom setup handler required for proper Greentea support -utest::v1::status_t greentea_setup(const size_t number_of_cases) -{ - GREENTEA_SETUP(60, "default_auto"); - // Call the default reporting function - return greentea_test_setup_handler(number_of_cases); -} -#else -status_t default_setup(const size_t) -{ - return STATUS_CONTINUE; -} -#endif - -// Specify all your test cases here -Case cases[] = { - - Case("initializeBeforeCreate", test_initializeBeforeCreate), - Case("format", test_format), - Case("initialize", test_initialize), - Case("reset and initialize1", test_resetAndInitialize), - - Case("log small item without commit", test_logSmallWithoutCommit), - Case("reset and initialize2", test_resetAndInitialize), - - Case("commit without logs", test_commitWithoutLogs), - Case("initialize", test_initialize), - - /* log small item, and reinitialize */ - Case("log small item and commit1", test_logSmallAndCommit<0xAA>), - Case("initialize after small log and commit1", test_initializeAfterLogSmallAndCommit), - Case("log small item and commit2", test_logSmallAndCommit<0x11>), - Case("initialize after small log and commit2", test_initializeAfterLogSmallAndCommit), - Case("log small item and commit3", test_logSmallAndCommit<0x22>), - Case("initialize after small log and commit3", test_initializeAfterLogSmallAndCommit), - Case("log small item and commit4", test_logSmallAndCommit<0x55>), - Case("initialize after small log and commit4", test_initializeAfterLogSmallAndCommit), - Case("log small item and commit5", test_logSmallAndCommit<0xAB>), - Case("initialize after small log and commit5", test_initializeAfterLogSmallAndCommit), - Case("reset and initialize3", test_resetAndInitialize), - - Case("log large item without commit", test_logLargeWithoutCommit), - - /* initialize, log large item, and reinitialize */ - Case("initialize2", test_initialize), - Case("reset and initialize4", test_resetAndInitialize), - Case("log large item and commit1", test_logLargeAndCommit<0xAA>), - Case("initialize after large log and commit1", test_initializeAfterLogLargeAndCommit), - Case("log large item and commit2", test_logLargeAndCommit<0x55>), - Case("initialize after large log and commit2", test_initializeAfterLogLargeAndCommit), - Case("log large item and commit3", test_logLargeAndCommit<0x11>), - Case("initialize after large log and commit3", test_initializeAfterLogLargeAndCommit), - Case("log large item and commit4", test_logLargeAndCommit<0xAB>), - Case("initialize after large log and commit4", test_initializeAfterLogLargeAndCommit), - Case("log large item and commit5", test_logLargeAndCommit<0x22>), - Case("initialize after large log and commit5", test_initializeAfterLogLargeAndCommit), - Case("reset and initialize5", test_resetAndInitialize), - - Case("log large item and read smaller chunks", test_logLargeAndReadSmallChunks<0xAA>), - Case("read large item in small, odd-sized chunks1", test_readLargeInSmallOddChunks<0xAA, ((BUFFER_SIZE / 2) - 1)>), - Case("read large item in small, odd-sized chunks2", test_readLargeInSmallOddChunks<0xAA, 255>), - Case("read large item in small, odd-sized chunks3", test_readLargeInSmallOddChunks<0xAA, 1021>), - Case("read large item in small, odd-sized chunks4", test_readLargeInSmallOddChunks<0xAA, 2401>), - - Case("log pattern", test_logPattern<0x55>), - Case("readFrom", test_readFromInReverse<0x55, 255>), - Case("readFrom", test_readFromInReverse<0x55, 512>), - Case("readFrom", test_readFromInReverse<0x55, ((BUFFER_SIZE / 2) - 1)>), - Case("readFrom", test_readFromInReverse<0x55, BUFFER_SIZE>), - Case("readFrom followed by sequential reads", test_readFromFollowedByReads<0x55, 255>), - Case("readFrom followed by sequential reads", test_readFromFollowedByReads<0x55, 511>), - Case("readFrom followed by sequential reads", test_readFromFollowedByReads<0x55, 512>), - Case("readFrom followed by sequential reads", test_readFromFollowedByReads<0x55, 513>), - Case("readFrom followed by sequential reads", test_readFromFollowedByReads<0x55, 1024>), - - /* log odd-sized blocks which wouldn't align with program_unit at the tail */ - Case("initialize3", test_initialize), - Case("log odd-sized chunk", test_logSeveralOddSizedChunks<1, 1>), - Case("log odd-sized chunk", test_logSeveralOddSizedChunks<101, 11>), - Case("log odd-sized chunk", test_logSeveralOddSizedChunks<1217, 4>), - Case("log odd-sized chunk", test_logSeveralOddSizedChunks<2402, 5>), - Case("log odd-sized chunk", test_logSeveralOddSizedChunks<4803, 3>), - Case("log odd-sized chunk", test_logSeveralOddSizedChunks<(BUFFER_SIZE-1), 7>), - - Case("initialize4", test_initialize), - Case("multiple writes, commit, multiple reads", test_multipleWritesFollowedByCommitFollowedByMultipleReads), - - Case("failed small write followed by padded write", test_failedSmallWriteFollowedByPaddedWrite), - - Case("reset and initialize6", test_resetAndInitialize), - Case("crc32", test_crc32), - // Case("uninitialize", test_uninitialize), -}; - -// Declare your test specification with a custom setup handler -#ifndef AVOID_GREENTEA -Specification specification(greentea_setup, cases); -#else -Specification specification(default_setup, cases); -#endif - -int main(int argc, char** argv) -{ - // Run the test specification - Harness::run(specification); -} diff --git a/features/storage/FEATURE_STORAGE/TESTS/storage-volume-manager/basicAPI/basicAPI.cpp b/features/storage/FEATURE_STORAGE/TESTS/storage-volume-manager/basicAPI/basicAPI.cpp deleted file mode 100644 index 8200f85..0000000 --- a/features/storage/FEATURE_STORAGE/TESTS/storage-volume-manager/basicAPI/basicAPI.cpp +++ /dev/null @@ -1,1234 +0,0 @@ -/* - * Copyright (c) 2006-2016, ARM Limited, All Rights Reserved - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifdef TARGET_LIKE_POSIX -#define AVOID_GREENTEA -#endif - -#ifndef AVOID_GREENTEA -#include "greentea-client/test_env.h" -#endif -#include "utest/utest.h" -#include "unity/unity.h" - -#include "storage-volume-manager/storage_volume_manager.h" -#include -#include - -using namespace utest::v1; - -/* redefine tr_info() to a printf() equivalent to emit trace */ -#define tr_info(...) ((void) 0) -#define mbed_trace_init(...) ((void) 0) -#define mbed_trace_config_set(...) ((void) 0) - -#ifdef TARGET_LIKE_X86_LINUX_NATIVE -extern ARM_DRIVER_STORAGE ARM_Driver_Storage_MTD_RAM; -ARM_DRIVER_STORAGE *drv = &ARM_Driver_Storage_MTD_RAM; -#elif defined TARGET_LIKE_FRDM_K64F -extern ARM_DRIVER_STORAGE ARM_Driver_Storage_MTD_K64F; -ARM_DRIVER_STORAGE *drv = &ARM_Driver_Storage_MTD_K64F; -#else -extern ARM_DRIVER_STORAGE ARM_Driver_Storage_MTD_K64F; -ARM_DRIVER_STORAGE *drv = &ARM_Driver_Storage_MTD_K64F; -#endif - -/* temporary buffer to hold data for testing. */ -static const unsigned BUFFER_SIZE = 16384; -static uint8_t buffer[BUFFER_SIZE]; - -static int32_t callbackStatus; -static int32_t virtualVolumeCallbackStatus; - -#ifndef AVOID_GREENTEA -// Custom setup handler required for proper Greentea support -utest::v1::status_t greentea_setup(const size_t number_of_cases) -{ - GREENTEA_SETUP(30, "default_auto"); - // Call the default reporting function - return greentea_test_setup_handler(number_of_cases); -} -#endif - -/* used only for the initialization of the volume-manager. */ -void initializeCallbackHandler(int32_t status) -{ - tr_info("in initializeCallbackHandler\r\n"); - Harness::validate_callback(); -} - -/* used only when accessing MTD directly (for verification) */ -void mtdCallbackHandler(int32_t status, ARM_STORAGE_OPERATION operation) -{ - tr_info("in mtdCallbackHandler"); - callbackStatus = status; - Harness::validate_callback(); -} - -/* the normal callback handler for the virtual volume */ -void virtualMTDCallbackHandler(int32_t status, ARM_STORAGE_OPERATION operation) -{ - tr_info("in virtualMTDCallbackHandler"); - virtualVolumeCallbackStatus = status; - Harness::validate_callback(); -} - -control_t test_initialize(const size_t call_count) -{ - tr_info("test_initialize: called with call_count %lu", call_count); - static StorageVolumeManager volumeManager; - - if (call_count == 1) { - int32_t rc = volumeManager.initialize(drv, initializeCallbackHandler); - TEST_ASSERT(rc >= ARM_DRIVER_OK); - if (rc == ARM_DRIVER_OK) { - TEST_ASSERT_EQUAL(1, drv->GetCapabilities().asynchronous_ops); - return CaseTimeout(200) + CaseRepeatAll; - } - - /* synchronous completion */ - TEST_ASSERT(rc == 1); - } - - TEST_ASSERT_EQUAL(true, volumeManager.isInitialized()); - TEST_ASSERT(volumeManager.getStorageInfo().total_storage > 0); - for (size_t index = 0; index < MAX_VOLUMES; index++) { - TEST_ASSERT_EQUAL(false, volumeManager.volumeAtIndex(index)->isAllocated()); - } - - return CaseNext; -} - -template -control_t test_againstSingleVolumeAtOffset(const size_t call_count) -{ - tr_info("test_againstSingleVolumeAtOffset: called with call_count %lu", call_count); - static StorageVolumeManager volumeManager; - static StorageVolume *volumeP = NULL; - static ARM_STORAGE_INFO info; - static size_t sizeofDataOperation; - - const uint8_t PATTERN_FOR_PROGRAM_DATA = 0xAA; - - static enum { - VOLUME_MANAGER_INITIALIZE = 1, - BASIC_SYNCHRONOUS_API_TESTING, - READ_DATA, - ERASE, - READ_AFTER_ERASE, - PROGRAM_DATA, - READ_AFTER_PROGRAM_DATA, - VERIFY_PROGRAM_DATA, - DISCONNECT_VOLUME_MANAGER_CALLBACK, - READ_FROM_DRV_AFTER_PROGRAM_DATA, - VERIFY_PROGRAM_DATA2, - } state = VOLUME_MANAGER_INITIALIZE; - tr_info("came in with state %u", state); - - int32_t rc; - ARM_STORAGE_BLOCK firstBlock; - rc = drv->GetNextBlock(NULL, &firstBlock); - TEST_ASSERT_EQUAL(ARM_DRIVER_OK, rc); - TEST_ASSERT(ARM_STORAGE_VALID_BLOCK(&firstBlock)); - - switch (state) { - case VOLUME_MANAGER_INITIALIZE: - rc = volumeManager.initialize(drv, initializeCallbackHandler); - TEST_ASSERT(rc >= ARM_DRIVER_OK); - if (rc == ARM_DRIVER_OK) { - TEST_ASSERT_EQUAL(1, drv->GetCapabilities().asynchronous_ops); - state = BASIC_SYNCHRONOUS_API_TESTING; - return CaseTimeout(200) + CaseRepeatAll; - } - - /* synchronous completion */ - TEST_ASSERT(rc == 1); - - /* intentional fall-through */ - - case BASIC_SYNCHRONOUS_API_TESTING: - TEST_ASSERT_EQUAL(true, volumeManager.isInitialized()); - - rc = drv->GetInfo(&info); - TEST_ASSERT_EQUAL(ARM_DRIVER_OK, rc); - TEST_ASSERT(info.total_storage > 0); - - { /* add volume */ - rc = volumeManager.addVolume(firstBlock.addr + OFFSET /*addr*/, info.total_storage - OFFSET /*size*/ , &volumeP); - TEST_ASSERT_EQUAL(ARM_DRIVER_OK, rc); - - TEST_ASSERT_EQUAL(true, volumeManager.volumeAtIndex(0)->isAllocated()); - for (size_t index = 1; index < MAX_VOLUMES; index++) { - TEST_ASSERT_EQUAL(false, volumeManager.volumeAtIndex(index)->isAllocated()); - } - } - - { /* GetVersion */ - TEST_ASSERT_EQUAL(drv->GetVersion().api, volumeP->GetVersion().api); - TEST_ASSERT_EQUAL(drv->GetVersion().drv, volumeP->GetVersion().drv); - } - - { /* GetCapabilities */ - TEST_ASSERT_EQUAL(drv->GetCapabilities().asynchronous_ops, volumeP->GetCapabilities().asynchronous_ops); - TEST_ASSERT_EQUAL(drv->GetCapabilities().erase_all, volumeP->GetCapabilities().erase_all); - } - - { /* Initialize */ - rc = volumeP->Initialize(virtualMTDCallbackHandler); - TEST_ASSERT_EQUAL(1, rc); - } - - { /* GetStatus */ - ARM_STORAGE_STATUS status = volumeP->GetStatus(); - TEST_ASSERT_EQUAL(0, status.busy); - TEST_ASSERT_EQUAL(0, status.error); - } - - { /* GetInfo */ - ARM_STORAGE_INFO volumeInfo; - rc = volumeP->GetInfo(&volumeInfo); - TEST_ASSERT_EQUAL(ARM_DRIVER_OK, rc); - - TEST_ASSERT_EQUAL(info.total_storage - OFFSET, volumeInfo.total_storage); - TEST_ASSERT_EQUAL(info.program_unit, volumeInfo.program_unit); - TEST_ASSERT_EQUAL(info.optimal_program_unit, volumeInfo.optimal_program_unit); - TEST_ASSERT_EQUAL(info.program_cycles, volumeInfo.program_cycles); - TEST_ASSERT_EQUAL(info.erased_value, volumeInfo.erased_value); - TEST_ASSERT_EQUAL(info.memory_mapped, volumeInfo.memory_mapped); - TEST_ASSERT_EQUAL(info.programmability, volumeInfo.programmability); - TEST_ASSERT_EQUAL(info.retention_level, volumeInfo.retention_level); - TEST_ASSERT_EQUAL(info.reserved, volumeInfo.reserved); - TEST_ASSERT_EQUAL(0, memcmp(&info.security, &volumeInfo.security, sizeof(ARM_STORAGE_SECURITY_FEATURES))); - } - - { /* resolve address */ - TEST_ASSERT_EQUAL(firstBlock.addr + OFFSET, volumeP->ResolveAddress(0)); - TEST_ASSERT_EQUAL(firstBlock.addr + OFFSET + info.total_storage, volumeP->ResolveAddress(info.total_storage)); - TEST_ASSERT_EQUAL(firstBlock.addr + OFFSET + info.total_storage / 2, volumeP->ResolveAddress(info.total_storage / 2)); - } - - { /* GetNextBlock */ - rc = volumeP->GetNextBlock(NULL, NULL); - TEST_ASSERT_EQUAL(ARM_DRIVER_OK, rc); - ARM_STORAGE_BLOCK block; - rc = volumeP->GetNextBlock(NULL, &block); - TEST_ASSERT_EQUAL(ARM_DRIVER_OK, rc); - TEST_ASSERT_EQUAL(0, block.addr); - TEST_ASSERT_EQUAL(info.total_storage - OFFSET, block.size); - - rc = volumeP->GetNextBlock(&block, NULL); - TEST_ASSERT(rc < ARM_DRIVER_OK); - rc = volumeP->GetNextBlock(&block, &block); - TEST_ASSERT(rc < ARM_DRIVER_OK); - } - - { /* GetBlock */ - ARM_STORAGE_BLOCK block; - rc = volumeP->GetBlock(0, &block); - TEST_ASSERT_EQUAL(ARM_DRIVER_OK, rc); - TEST_ASSERT_EQUAL(0, block.addr); - TEST_ASSERT_EQUAL(info.total_storage - OFFSET, block.size); - - rc = volumeP->GetBlock((info.total_storage / 2), &block); - TEST_ASSERT_EQUAL(ARM_DRIVER_OK, rc); - TEST_ASSERT_EQUAL(0, block.addr); - TEST_ASSERT_EQUAL(info.total_storage - OFFSET, block.size); - - rc = volumeP->GetBlock(info.total_storage, &block); - TEST_ASSERT(rc < ARM_DRIVER_OK); - } - - state = READ_DATA; - /* intentional fallthrough */ - - case READ_DATA: - sizeofDataOperation = ((info.total_storage - OFFSET) > BUFFER_SIZE) ? BUFFER_SIZE : (info.total_storage - OFFSET); - TEST_ASSERT(sizeofDataOperation <= BUFFER_SIZE); - - /* ReadData */ - rc = volumeP->ReadData(0, buffer, sizeofDataOperation); - TEST_ASSERT(rc >= ARM_DRIVER_OK); - if (rc == ARM_DRIVER_OK) { - TEST_ASSERT_EQUAL(1, volumeP->GetCapabilities().asynchronous_ops); - state = ERASE; - return CaseTimeout(200) + CaseRepeatAll; - } - - virtualVolumeCallbackStatus = rc; - /* intentional fallthrough */ - - case ERASE: - TEST_ASSERT_EQUAL(sizeofDataOperation, virtualVolumeCallbackStatus); - - /* Erase */ - rc = volumeP->Erase(0, sizeofDataOperation); - TEST_ASSERT(rc >= ARM_DRIVER_OK); - if (rc == ARM_DRIVER_OK) { - TEST_ASSERT_EQUAL(1, volumeP->GetCapabilities().asynchronous_ops); - state = READ_AFTER_ERASE; - return CaseTimeout(200) + CaseRepeatAll; - } - - virtualVolumeCallbackStatus = rc; - /* intentional fallthrough */ - - case READ_AFTER_ERASE: - TEST_ASSERT_EQUAL(sizeofDataOperation, virtualVolumeCallbackStatus); - - /* Read after Erase */ - rc = volumeP->ReadData(0, buffer, sizeofDataOperation); - TEST_ASSERT(rc >= ARM_DRIVER_OK); - if (rc == ARM_DRIVER_OK) { - TEST_ASSERT_EQUAL(1, volumeP->GetCapabilities().asynchronous_ops); - state = PROGRAM_DATA; - return CaseTimeout(200) + CaseRepeatAll; - } - - virtualVolumeCallbackStatus = rc; - /* intentional fallthrough */ - - case PROGRAM_DATA: - TEST_ASSERT_EQUAL(sizeofDataOperation, virtualVolumeCallbackStatus); - for (size_t index = 0; index < sizeofDataOperation; index++) { - // if (bytePattern != (buffer)[index]) { - // tr_info("%u: expected %x, found %x", index, bytePattern, buffer[index]); - // } - TEST_ASSERT_EQUAL(info.erased_value ? (uint8_t)0xFF : (uint8_t)0, buffer[index]); - } - - /* ProgramData */ - memset(buffer, PATTERN_FOR_PROGRAM_DATA, sizeofDataOperation); - rc = volumeP->ProgramData(0, buffer, sizeofDataOperation); - TEST_ASSERT(rc >= ARM_DRIVER_OK); - if (rc == ARM_DRIVER_OK) { - TEST_ASSERT_EQUAL(1, volumeP->GetCapabilities().asynchronous_ops); - state = READ_AFTER_PROGRAM_DATA; - return CaseTimeout(200) + CaseRepeatAll; - } - - virtualVolumeCallbackStatus = rc; - /* intentional fallthrough */ - - case READ_AFTER_PROGRAM_DATA: - TEST_ASSERT_EQUAL(sizeofDataOperation, virtualVolumeCallbackStatus); - - /* Read after Program */ - rc = volumeP->ReadData(0, buffer, sizeofDataOperation); - TEST_ASSERT(rc >= ARM_DRIVER_OK); - if (rc == ARM_DRIVER_OK) { - TEST_ASSERT_EQUAL(1, volumeP->GetCapabilities().asynchronous_ops); - state = VERIFY_PROGRAM_DATA; - return CaseTimeout(200) + CaseRepeatAll; - } - - virtualVolumeCallbackStatus = rc; - /* intentional fallthrough */ - - case VERIFY_PROGRAM_DATA: - TEST_ASSERT_EQUAL(sizeofDataOperation, virtualVolumeCallbackStatus); - for (uint32_t index = 0; index < sizeofDataOperation; index++) { - if ((buffer)[index] != PATTERN_FOR_PROGRAM_DATA) { - tr_info("%s:%u: %" PRIu32 ": expected 0x%02x, found 0x%02x", __FUNCTION__, __LINE__, index, PATTERN_FOR_PROGRAM_DATA, buffer[index]); - } - TEST_ASSERT_EQUAL(PATTERN_FOR_PROGRAM_DATA, buffer[index]); - } - /* intentional fallthrough */ - - case DISCONNECT_VOLUME_MANAGER_CALLBACK: - rc = drv->Initialize(mtdCallbackHandler); - TEST_ASSERT_EQUAL(1, rc); /* expect synchronous completion */ - /* intentional fallthrough */ - - case READ_FROM_DRV_AFTER_PROGRAM_DATA: - /* Read after Program */ - rc = drv->ReadData(firstBlock.addr + OFFSET, buffer, sizeofDataOperation); - TEST_ASSERT(rc >= ARM_DRIVER_OK); - if (rc == ARM_DRIVER_OK) { - TEST_ASSERT_EQUAL(1, volumeP->GetCapabilities().asynchronous_ops); - state = VERIFY_PROGRAM_DATA2; - return CaseTimeout(200) + CaseRepeatAll; - } - - callbackStatus = rc; - /* intentional fallthrough */ - - case VERIFY_PROGRAM_DATA2: - TEST_ASSERT_EQUAL(sizeofDataOperation, callbackStatus); - for (uint32_t index = 0; index < sizeofDataOperation; index++) { - if ((buffer)[index] != PATTERN_FOR_PROGRAM_DATA) { - tr_info("%s:%u: %" PRIu32 ": expected 0x%02x, found 0x%02x", __FUNCTION__, __LINE__, index, PATTERN_FOR_PROGRAM_DATA, buffer[index]); - } - TEST_ASSERT_EQUAL(PATTERN_FOR_PROGRAM_DATA, buffer[index]); - } - break; - - default: - TEST_ASSERT(false); - } - - return CaseNext; -} - -template -control_t test_againstSingleCStorageAtOffset(const size_t call_count) -{ - tr_info("test_againstSingleCStorageAtOffset: called with call_count %lu", call_count); - static StorageVolumeManager volumeManager; - static _ARM_DRIVER_STORAGE mtd = {}; - static ARM_STORAGE_INFO info; - static size_t sizeofDataOperation; - - const uint8_t PATTERN_FOR_PROGRAM_DATA = 0xAA; - - static enum { - VOLUME_MANAGER_INITIALIZE = 1, - BASIC_SYNCHRONOUS_API_TESTING, - READ_DATA, - ERASE, - READ_AFTER_ERASE, - PROGRAM_DATA, - READ_AFTER_PROGRAM_DATA, - VERIFY_PROGRAM_DATA, - DISCONNECT_VOLUME_MANAGER_CALLBACK, - READ_FROM_DRV_AFTER_PROGRAM_DATA, - VERIFY_PROGRAM_DATA2, - } state = VOLUME_MANAGER_INITIALIZE; - tr_info("came in with state %u", state); - - int32_t rc; - rc = drv->GetNextBlock(NULL, NULL); - TEST_ASSERT_EQUAL(ARM_DRIVER_OK, rc); - ARM_STORAGE_BLOCK firstBlock; - rc = drv->GetNextBlock(NULL, &firstBlock); - TEST_ASSERT_EQUAL(ARM_DRIVER_OK, rc); - TEST_ASSERT(ARM_STORAGE_VALID_BLOCK(&firstBlock)); - - switch (state) { - case VOLUME_MANAGER_INITIALIZE: - rc = volumeManager.initialize(drv, initializeCallbackHandler); - TEST_ASSERT(rc >= ARM_DRIVER_OK); - if (rc == ARM_DRIVER_OK) { - TEST_ASSERT_EQUAL(1, drv->GetCapabilities().asynchronous_ops); - state = BASIC_SYNCHRONOUS_API_TESTING; - return CaseTimeout(200) + CaseRepeatAll; - } - - /* synchronous completion */ - TEST_ASSERT(rc == 1); - - /* intentional fall-through */ - - case BASIC_SYNCHRONOUS_API_TESTING: - TEST_ASSERT_EQUAL(true, volumeManager.isInitialized()); - - rc = drv->GetInfo(&info); - TEST_ASSERT_EQUAL(ARM_DRIVER_OK, rc); - TEST_ASSERT(info.total_storage > 0); - - { /* add volume */ - rc = volumeManager.addVolume_C(firstBlock.addr + OFFSET /*addr*/, info.total_storage - OFFSET /*size*/ , &mtd); - TEST_ASSERT_EQUAL(ARM_DRIVER_OK, rc); - - TEST_ASSERT_EQUAL(true, volumeManager.volumeAtIndex(0)->isAllocated()); - for (size_t index = 1; index < MAX_VOLUMES; index++) { - TEST_ASSERT_EQUAL(false, volumeManager.volumeAtIndex(index)->isAllocated()); - } - } - - { /* GetVersion */ - TEST_ASSERT_EQUAL(drv->GetVersion().api, mtd.GetVersion().api); - TEST_ASSERT_EQUAL(drv->GetVersion().drv, mtd.GetVersion().drv); - } - - { /* GetCapabilities */ - TEST_ASSERT_EQUAL(drv->GetCapabilities().asynchronous_ops, mtd.GetCapabilities().asynchronous_ops); - TEST_ASSERT_EQUAL(drv->GetCapabilities().erase_all, mtd.GetCapabilities().erase_all); - } - - { /* Initialize */ - rc = mtd.Initialize(virtualMTDCallbackHandler); - TEST_ASSERT_EQUAL(1, rc); - } - - { /* GetStatus */ - ARM_STORAGE_STATUS status = mtd.GetStatus(); - TEST_ASSERT_EQUAL(0, status.busy); - TEST_ASSERT_EQUAL(0, status.error); - } - - { /* GetInfo */ - ARM_STORAGE_INFO volumeInfo; - rc = mtd.GetInfo(&volumeInfo); - TEST_ASSERT_EQUAL(ARM_DRIVER_OK, rc); - - TEST_ASSERT_EQUAL(info.total_storage - OFFSET, volumeInfo.total_storage); - TEST_ASSERT_EQUAL(info.program_unit, volumeInfo.program_unit); - TEST_ASSERT_EQUAL(info.optimal_program_unit, volumeInfo.optimal_program_unit); - TEST_ASSERT_EQUAL(info.program_cycles, volumeInfo.program_cycles); - TEST_ASSERT_EQUAL(info.erased_value, volumeInfo.erased_value); - TEST_ASSERT_EQUAL(info.memory_mapped, volumeInfo.memory_mapped); - TEST_ASSERT_EQUAL(info.programmability, volumeInfo.programmability); - TEST_ASSERT_EQUAL(info.retention_level, volumeInfo.retention_level); - TEST_ASSERT_EQUAL(info.reserved, volumeInfo.reserved); - TEST_ASSERT_EQUAL(0, memcmp(&info.security, &volumeInfo.security, sizeof(ARM_STORAGE_SECURITY_FEATURES))); - } - - { /* resolve address */ - TEST_ASSERT_EQUAL(firstBlock.addr + OFFSET, mtd.ResolveAddress(0)); - TEST_ASSERT_EQUAL(firstBlock.addr + OFFSET + info.total_storage, mtd.ResolveAddress(info.total_storage)); - TEST_ASSERT_EQUAL(firstBlock.addr + OFFSET + info.total_storage / 2, mtd.ResolveAddress(info.total_storage / 2)); - } - - { /* GetNextBlock */ - rc = mtd.GetNextBlock(NULL, NULL); - TEST_ASSERT_EQUAL(ARM_DRIVER_OK, rc); - ARM_STORAGE_BLOCK block; - rc = mtd.GetNextBlock(NULL, &block); - TEST_ASSERT_EQUAL(ARM_DRIVER_OK, rc); - TEST_ASSERT_EQUAL(0, block.addr); - TEST_ASSERT_EQUAL(info.total_storage - OFFSET, block.size); - - rc = mtd.GetNextBlock(&block, NULL); - TEST_ASSERT(rc < ARM_DRIVER_OK); - rc = mtd.GetNextBlock(&block, &block); - TEST_ASSERT(rc < ARM_DRIVER_OK); - } - - { /* GetBlock */ - rc = mtd.GetBlock(0, NULL); - TEST_ASSERT_EQUAL(ARM_DRIVER_OK, rc); - ARM_STORAGE_BLOCK block; - rc = mtd.GetBlock(0, &block); - TEST_ASSERT_EQUAL(ARM_DRIVER_OK, rc); - TEST_ASSERT_EQUAL(0, block.addr); - TEST_ASSERT_EQUAL(info.total_storage - OFFSET, block.size); - - rc = mtd.GetBlock((info.total_storage / 2), NULL); - TEST_ASSERT_EQUAL(ARM_DRIVER_OK, rc); - rc = mtd.GetBlock((info.total_storage / 2), &block); - TEST_ASSERT_EQUAL(ARM_DRIVER_OK, rc); - TEST_ASSERT_EQUAL(0, block.addr); - TEST_ASSERT_EQUAL(info.total_storage - OFFSET, block.size); - - rc = mtd.GetBlock(info.total_storage, NULL); - TEST_ASSERT(rc < ARM_DRIVER_OK); - rc = mtd.GetBlock(info.total_storage, &block); - TEST_ASSERT(rc < ARM_DRIVER_OK); - } - - state = READ_DATA; - /* intentional fallthrough */ - - case READ_DATA: - sizeofDataOperation = ((info.total_storage - OFFSET) > BUFFER_SIZE) ? BUFFER_SIZE : (info.total_storage - OFFSET); - TEST_ASSERT(sizeofDataOperation <= BUFFER_SIZE); - - /* ReadData */ - rc = mtd.ReadData(0, buffer, sizeofDataOperation); - TEST_ASSERT(rc >= ARM_DRIVER_OK); - if (rc == ARM_DRIVER_OK) { - TEST_ASSERT_EQUAL(1, mtd.GetCapabilities().asynchronous_ops); - state = ERASE; - return CaseTimeout(200) + CaseRepeatAll; - } - - virtualVolumeCallbackStatus = rc; - /* intentional fallthrough */ - - case ERASE: - TEST_ASSERT_EQUAL(sizeofDataOperation, virtualVolumeCallbackStatus); - - /* Erase */ - rc = mtd.Erase(0, sizeofDataOperation); - TEST_ASSERT(rc >= ARM_DRIVER_OK); - if (rc == ARM_DRIVER_OK) { - TEST_ASSERT_EQUAL(1, mtd.GetCapabilities().asynchronous_ops); - state = READ_AFTER_ERASE; - return CaseTimeout(200) + CaseRepeatAll; - } - - virtualVolumeCallbackStatus = rc; - /* intentional fallthrough */ - - case READ_AFTER_ERASE: - TEST_ASSERT_EQUAL(sizeofDataOperation, virtualVolumeCallbackStatus); - - /* Read after Erase */ - rc = mtd.ReadData(0, buffer, sizeofDataOperation); - TEST_ASSERT(rc >= ARM_DRIVER_OK); - if (rc == ARM_DRIVER_OK) { - TEST_ASSERT_EQUAL(1, mtd.GetCapabilities().asynchronous_ops); - state = PROGRAM_DATA; - return CaseTimeout(200) + CaseRepeatAll; - } - - virtualVolumeCallbackStatus = rc; - /* intentional fallthrough */ - - case PROGRAM_DATA: - TEST_ASSERT_EQUAL(sizeofDataOperation, virtualVolumeCallbackStatus); - for (size_t index = 0; index < sizeofDataOperation; index++) { - // if (bytePattern != (buffer)[index]) { - // tr_info("%u: expected %x, found %x", index, bytePattern, buffer[index]); - // } - TEST_ASSERT_EQUAL(info.erased_value ? (uint8_t)0xFF : (uint8_t)0, buffer[index]); - } - - /* ProgramData */ - memset(buffer, PATTERN_FOR_PROGRAM_DATA, sizeofDataOperation); - rc = mtd.ProgramData(0, buffer, sizeofDataOperation); - TEST_ASSERT(rc >= ARM_DRIVER_OK); - if (rc == ARM_DRIVER_OK) { - TEST_ASSERT_EQUAL(1, mtd.GetCapabilities().asynchronous_ops); - state = READ_AFTER_PROGRAM_DATA; - return CaseTimeout(200) + CaseRepeatAll; - } - - virtualVolumeCallbackStatus = rc; - /* intentional fallthrough */ - - case READ_AFTER_PROGRAM_DATA: - TEST_ASSERT_EQUAL(sizeofDataOperation, virtualVolumeCallbackStatus); - - /* Read after Program */ - rc = mtd.ReadData(0, buffer, sizeofDataOperation); - TEST_ASSERT(rc >= ARM_DRIVER_OK); - if (rc == ARM_DRIVER_OK) { - TEST_ASSERT_EQUAL(1, mtd.GetCapabilities().asynchronous_ops); - state = VERIFY_PROGRAM_DATA; - return CaseTimeout(200) + CaseRepeatAll; - } - - virtualVolumeCallbackStatus = rc; - /* intentional fallthrough */ - - case VERIFY_PROGRAM_DATA: - TEST_ASSERT_EQUAL(sizeofDataOperation, virtualVolumeCallbackStatus); - for (uint32_t index = 0; index < sizeofDataOperation; index++) { - if ((buffer)[index] != PATTERN_FOR_PROGRAM_DATA) { - tr_info("%s:%u: %" PRIu32 ": expected 0x%02x, found 0x%02x", __FUNCTION__, __LINE__, index, PATTERN_FOR_PROGRAM_DATA, buffer[index]); - } - TEST_ASSERT_EQUAL(PATTERN_FOR_PROGRAM_DATA, buffer[index]); - } - /* intentional fallthrough */ - - case DISCONNECT_VOLUME_MANAGER_CALLBACK: - rc = drv->Initialize(mtdCallbackHandler); - TEST_ASSERT_EQUAL(1, rc); /* expect synchronous completion */ - /* intentional fallthrough */ - - case READ_FROM_DRV_AFTER_PROGRAM_DATA: - /* Read after Program */ - rc = drv->ReadData(firstBlock.addr + OFFSET, buffer, sizeofDataOperation); - TEST_ASSERT(rc >= ARM_DRIVER_OK); - if (rc == ARM_DRIVER_OK) { - TEST_ASSERT_EQUAL(1, mtd.GetCapabilities().asynchronous_ops); - state = VERIFY_PROGRAM_DATA2; - return CaseTimeout(200) + CaseRepeatAll; - } - - callbackStatus = rc; - /* intentional fallthrough */ - - case VERIFY_PROGRAM_DATA2: - TEST_ASSERT_EQUAL(sizeofDataOperation, callbackStatus); - for (uint32_t index = 0; index < sizeofDataOperation; index++) { - if ((buffer)[index] != PATTERN_FOR_PROGRAM_DATA) { - tr_info("%s:%u: %" PRIu32 ": expected 0x%02x, found 0x%02x", __FUNCTION__, __LINE__, index, PATTERN_FOR_PROGRAM_DATA, buffer[index]); - } - TEST_ASSERT_EQUAL(PATTERN_FOR_PROGRAM_DATA, buffer[index]); - } - break; - - default: - TEST_ASSERT(false); - } - - return CaseNext; -} - -template -control_t test_concurrentAccessFromTwoVolumes(const size_t call_count) -{ - tr_info("test_concurrentAccessFromTwoVolumes: called with call_count %lu", call_count); - - if (MAX_VOLUMES <= 1) { - return CaseNext; - } - - static StorageVolumeManager volumeManager; - static StorageVolume *volume1P = NULL; - static StorageVolume *volume2P = NULL; - static ARM_STORAGE_INFO info; - static size_t sizeofDataOperation; - - const uint8_t PATTERN_FOR_PROGRAM_DATA = 0xAA; - - static enum { - VOLUME_MANAGER_INITIALIZE = 1, - ADD_VOLUMES, - ERASE1, - PROGRAM_DATA1, - ERASE2, - PROGRAM_DATA2, - DISCONNECT_VOLUME_MANAGER_CALLBACK, - READ_FROM_DRV_AFTER_PROGRAM_DATA1, - VERIFY_PROGRAM_DATA1, - READ_FROM_DRV_AFTER_PROGRAM_DATA2, - VERIFY_PROGRAM_DATA2, - } state = VOLUME_MANAGER_INITIALIZE; - tr_info("came in with state %u", state); - - int32_t rc; - switch (state) { - case VOLUME_MANAGER_INITIALIZE: - rc = volumeManager.initialize(drv, initializeCallbackHandler); - TEST_ASSERT(rc >= ARM_DRIVER_OK); - if (rc == ARM_DRIVER_OK) { - TEST_ASSERT_EQUAL(1, drv->GetCapabilities().asynchronous_ops); - state = ADD_VOLUMES; - return CaseTimeout(200) + CaseRepeatAll; - } - - /* synchronous completion */ - TEST_ASSERT(rc == 1); - - /* intentional fall-through */ - - case ADD_VOLUMES: - TEST_ASSERT_EQUAL(true, volumeManager.isInitialized()); - - rc = drv->GetInfo(&info); - TEST_ASSERT_EQUAL(ARM_DRIVER_OK, rc); - TEST_ASSERT(info.total_storage > 0); - - { /* add volume1 */ - rc = drv->GetBlock(OFFSET1, NULL); - TEST_ASSERT_EQUAL(ARM_DRIVER_OK, rc); - ARM_STORAGE_BLOCK block1; - rc = drv->GetBlock(OFFSET1, &block1); - TEST_ASSERT_EQUAL(ARM_DRIVER_OK, rc); - rc = drv->GetBlock(OFFSET1 + SIZE1 - 1, NULL); - TEST_ASSERT_EQUAL(ARM_DRIVER_OK, rc); - rc = drv->GetBlock(OFFSET1 + SIZE1 - 1, &block1); - TEST_ASSERT_EQUAL(ARM_DRIVER_OK, rc); - - rc = volumeManager.addVolume(OFFSET1 /*addr*/, SIZE1 /*size*/ , &volume1P); - TEST_ASSERT_EQUAL(ARM_DRIVER_OK, rc); - - TEST_ASSERT_EQUAL(true, volumeManager.volumeAtIndex(0)->isAllocated()); - for (size_t index = 1; index < MAX_VOLUMES; index++) { - TEST_ASSERT_EQUAL(false, volumeManager.volumeAtIndex(index)->isAllocated()); - } - - { /* Initialize */ - rc = volume1P->Initialize(virtualMTDCallbackHandler); - TEST_ASSERT_EQUAL(1, rc); - } - } - { /* add volume2 */ - rc = drv->GetBlock(OFFSET2, NULL); - TEST_ASSERT_EQUAL(ARM_DRIVER_OK, rc); - ARM_STORAGE_BLOCK block2; - rc = drv->GetBlock(OFFSET2, &block2); - TEST_ASSERT_EQUAL(ARM_DRIVER_OK, rc); - rc = drv->GetBlock(OFFSET2 + SIZE2 - 2, NULL); - TEST_ASSERT_EQUAL(ARM_DRIVER_OK, rc); - rc = drv->GetBlock(OFFSET2 + SIZE2 - 2, &block2); - TEST_ASSERT_EQUAL(ARM_DRIVER_OK, rc); - - rc = volumeManager.addVolume(OFFSET2 /*addr*/, SIZE2 /*size*/ , &volume2P); - TEST_ASSERT_EQUAL(ARM_DRIVER_OK, rc); - - TEST_ASSERT_EQUAL(true, volumeManager.volumeAtIndex(1)->isAllocated()); - for (size_t index = 2; index < MAX_VOLUMES; index++) { - TEST_ASSERT_EQUAL(false, volumeManager.volumeAtIndex(index)->isAllocated()); - } - - { /* Initialize */ - rc = volume2P->Initialize(virtualMTDCallbackHandler); - TEST_ASSERT_EQUAL(1, rc); - } - } - - sizeofDataOperation = (SIZE1 > BUFFER_SIZE) ? BUFFER_SIZE : SIZE1; - sizeofDataOperation = (SIZE2 > sizeofDataOperation) ? sizeofDataOperation : SIZE2; - TEST_ASSERT((sizeofDataOperation > 0) && (sizeofDataOperation <= BUFFER_SIZE)); - memset(buffer, PATTERN_FOR_PROGRAM_DATA, sizeofDataOperation); - - /* intentional fall-through */ - - case ERASE1: - rc = volume1P->Erase(0, sizeofDataOperation); - TEST_ASSERT(rc >= ARM_DRIVER_OK); - if (rc == ARM_DRIVER_OK) { - TEST_ASSERT_EQUAL(1, volume1P->GetCapabilities().asynchronous_ops); - state = PROGRAM_DATA1; - return CaseTimeout(200) + CaseRepeatAll; - } - - virtualVolumeCallbackStatus = rc; - /* intentional fallthrough */ - - case PROGRAM_DATA1: - TEST_ASSERT_EQUAL(sizeofDataOperation, virtualVolumeCallbackStatus); - - tr_info("PROGRAM_DATA1"); - rc = volume1P->ProgramData(0, buffer, sizeofDataOperation); - TEST_ASSERT(rc >= ARM_DRIVER_OK); - if (rc == ARM_DRIVER_OK) { - TEST_ASSERT_EQUAL(1, volume1P->GetCapabilities().asynchronous_ops); - - ARM_STORAGE_STATUS status; - status = drv->GetStatus(); - TEST_ASSERT_EQUAL(1, status.busy); - TEST_ASSERT_EQUAL(0, status.error); - status = volume1P->GetStatus(); - TEST_ASSERT_EQUAL(1, status.busy); - TEST_ASSERT_EQUAL(0, status.error); - status = volume2P->GetStatus(); - TEST_ASSERT_EQUAL(1, status.busy); - TEST_ASSERT_EQUAL(0, status.error); - - rc = volume2P->ProgramData(0, buffer, sizeofDataOperation); - TEST_ASSERT_EQUAL(ARM_DRIVER_ERROR_BUSY, rc); - rc = volume1P->ProgramData(0, buffer, sizeofDataOperation); - TEST_ASSERT_EQUAL(ARM_DRIVER_ERROR_BUSY, rc); - rc = volume1P->ReadData(0, buffer, sizeofDataOperation); - TEST_ASSERT_EQUAL(ARM_DRIVER_ERROR_BUSY, rc); - rc = volume1P->Erase(0, sizeofDataOperation); - TEST_ASSERT_EQUAL(ARM_DRIVER_ERROR_BUSY, rc); - - state = ERASE2; - return CaseTimeout(200) + CaseRepeatAll; - } - - virtualVolumeCallbackStatus = rc; - /* intentional fallthrough */ - - case ERASE2: - TEST_ASSERT_EQUAL(sizeofDataOperation, virtualVolumeCallbackStatus); - - rc = volume2P->Erase(0, sizeofDataOperation); - TEST_ASSERT(rc >= ARM_DRIVER_OK); - if (rc == ARM_DRIVER_OK) { - TEST_ASSERT_EQUAL(1, volume2P->GetCapabilities().asynchronous_ops); - state = PROGRAM_DATA2; - return CaseTimeout(200) + CaseRepeatAll; - } - - virtualVolumeCallbackStatus = rc; - /* intentional fallthrough */ - - case PROGRAM_DATA2: - TEST_ASSERT_EQUAL(sizeofDataOperation, virtualVolumeCallbackStatus); - - tr_info("PROGRAM_DATA2"); - rc = volume2P->ProgramData(0, buffer, sizeofDataOperation); - TEST_ASSERT(rc >= ARM_DRIVER_OK); - if (rc == ARM_DRIVER_OK) { - TEST_ASSERT_EQUAL(1, volume2P->GetCapabilities().asynchronous_ops); - - ARM_STORAGE_STATUS status; - status = drv->GetStatus(); - TEST_ASSERT_EQUAL(1, status.busy); - TEST_ASSERT_EQUAL(0, status.error); - status = volume2P->GetStatus(); - TEST_ASSERT_EQUAL(1, status.busy); - TEST_ASSERT_EQUAL(0, status.error); - status = volume1P->GetStatus(); - TEST_ASSERT_EQUAL(1, status.busy); - TEST_ASSERT_EQUAL(0, status.error); - - rc = volume1P->ProgramData(0, buffer, sizeofDataOperation); - TEST_ASSERT_EQUAL(ARM_DRIVER_ERROR_BUSY, rc); - rc = volume2P->ProgramData(0, buffer, sizeofDataOperation); - TEST_ASSERT_EQUAL(ARM_DRIVER_ERROR_BUSY, rc); - rc = volume2P->ReadData(0, buffer, sizeofDataOperation); - TEST_ASSERT_EQUAL(ARM_DRIVER_ERROR_BUSY, rc); - rc = volume2P->Erase(0, sizeofDataOperation); - TEST_ASSERT_EQUAL(ARM_DRIVER_ERROR_BUSY, rc); - - state = DISCONNECT_VOLUME_MANAGER_CALLBACK; - return CaseTimeout(200) + CaseRepeatAll; - } - - virtualVolumeCallbackStatus = rc; - /* intentional fallthrough */ - - case DISCONNECT_VOLUME_MANAGER_CALLBACK: - tr_info("DISCONNECT_VOLUME_MANAGER_CALLBACK"); - rc = drv->Initialize(mtdCallbackHandler); - TEST_ASSERT_EQUAL(1, rc); /* expect synchronous completion */ - /* intentional fallthrough */ - - case READ_FROM_DRV_AFTER_PROGRAM_DATA1: - tr_info("verifying state"); - /* Read after Program */ - rc = drv->ReadData(OFFSET1, buffer, sizeofDataOperation); - TEST_ASSERT(rc >= ARM_DRIVER_OK); - if (rc == ARM_DRIVER_OK) { - TEST_ASSERT_EQUAL(1, drv->GetCapabilities().asynchronous_ops); - state = VERIFY_PROGRAM_DATA1; - return CaseTimeout(200) + CaseRepeatAll; - } - - virtualVolumeCallbackStatus = rc; - /* intentional fallthrough */ - - case VERIFY_PROGRAM_DATA1: - TEST_ASSERT_EQUAL(sizeofDataOperation, virtualVolumeCallbackStatus); - - for (uint32_t index = 0; index < sizeofDataOperation; index++) { - if ((buffer)[index] != PATTERN_FOR_PROGRAM_DATA) { - tr_info("%s:%u: %" PRIu32 ": expected 0x%02x, found 0x%02x", __FUNCTION__, __LINE__, index, PATTERN_FOR_PROGRAM_DATA, buffer[index]); - } - TEST_ASSERT_EQUAL(PATTERN_FOR_PROGRAM_DATA, buffer[index]); - } - /* intentional fallthrough */ - - case READ_FROM_DRV_AFTER_PROGRAM_DATA2: - /* Read after Program */ - rc = drv->ReadData(OFFSET2, buffer, sizeofDataOperation); - TEST_ASSERT(rc >= ARM_DRIVER_OK); - if (rc == ARM_DRIVER_OK) { - TEST_ASSERT_EQUAL(1, drv->GetCapabilities().asynchronous_ops); - state = VERIFY_PROGRAM_DATA2; - return CaseTimeout(200) + CaseRepeatAll; - } - - virtualVolumeCallbackStatus = rc; - /* intentional fallthrough */ - - case VERIFY_PROGRAM_DATA2: - TEST_ASSERT_EQUAL(sizeofDataOperation, virtualVolumeCallbackStatus); - - for (uint32_t index = 0; index < sizeofDataOperation; index++) { - if ((buffer)[index] != PATTERN_FOR_PROGRAM_DATA) { - tr_info("%s:%u: %" PRIu32 ": expected 0x%02x, found 0x%02x", __FUNCTION__, __LINE__, index, PATTERN_FOR_PROGRAM_DATA, buffer[index]); - } - TEST_ASSERT_EQUAL(PATTERN_FOR_PROGRAM_DATA, buffer[index]); - } - break; - - default: - TEST_ASSERT(false); - } - - return CaseNext; -} - -template -control_t test_concurrentAccessFromTwoCStorageDevices(const size_t call_count) -{ - tr_info("test_concurrentAccessFromTwoCStorageDevices: called with call_count %lu", call_count); - - if (MAX_VOLUMES <= 1) { - return CaseNext; - } - - static StorageVolumeManager volumeManager; - static _ARM_DRIVER_STORAGE mtd1 = {}; - static _ARM_DRIVER_STORAGE mtd2 = {}; - static ARM_STORAGE_INFO info; - static size_t sizeofDataOperation; - - const uint8_t PATTERN_FOR_PROGRAM_DATA = 0xAA; - - static enum { - VOLUME_MANAGER_INITIALIZE = 1, - ADD_VOLUMES, - ERASE1, - PROGRAM_DATA1, - ERASE2, - PROGRAM_DATA2, - DISCONNECT_VOLUME_MANAGER_CALLBACK, - READ_FROM_DRV_AFTER_PROGRAM_DATA1, - VERIFY_PROGRAM_DATA1, - READ_FROM_DRV_AFTER_PROGRAM_DATA2, - VERIFY_PROGRAM_DATA2, - } state = VOLUME_MANAGER_INITIALIZE; - tr_info("came in with state %u", state); - - int32_t rc; - switch (state) { - case VOLUME_MANAGER_INITIALIZE: - rc = volumeManager.initialize(drv, initializeCallbackHandler); - TEST_ASSERT(rc >= ARM_DRIVER_OK); - if (rc == ARM_DRIVER_OK) { - TEST_ASSERT_EQUAL(1, drv->GetCapabilities().asynchronous_ops); - state = ADD_VOLUMES; - return CaseTimeout(200) + CaseRepeatAll; - } - - /* synchronous completion */ - TEST_ASSERT(rc == 1); - - /* intentional fall-through */ - - case ADD_VOLUMES: - TEST_ASSERT_EQUAL(true, volumeManager.isInitialized()); - - rc = drv->GetInfo(&info); - TEST_ASSERT_EQUAL(ARM_DRIVER_OK, rc); - TEST_ASSERT(info.total_storage > 0); - - { /* add C_Storage device 1 */ - ARM_STORAGE_BLOCK block1; - rc = drv->GetBlock(OFFSET1, &block1); - TEST_ASSERT_EQUAL(ARM_DRIVER_OK, rc); - rc = drv->GetBlock(OFFSET1 + SIZE1 - 1, &block1); - TEST_ASSERT_EQUAL(ARM_DRIVER_OK, rc); - - rc = volumeManager.addVolume_C(OFFSET1 /*addr*/, SIZE1 /*size*/ , &mtd1); - TEST_ASSERT_EQUAL(ARM_DRIVER_OK, rc); - - TEST_ASSERT_EQUAL(true, volumeManager.volumeAtIndex(0)->isAllocated()); - for (size_t index = 1; index < MAX_VOLUMES; index++) { - TEST_ASSERT_EQUAL(false, volumeManager.volumeAtIndex(index)->isAllocated()); - } - - { /* Initialize */ - rc = mtd1.Initialize(virtualMTDCallbackHandler); - TEST_ASSERT_EQUAL(1, rc); - } - } - { /* add C_Storage device 2 */ - ARM_STORAGE_BLOCK block2; - rc = drv->GetBlock(OFFSET2, &block2); - TEST_ASSERT_EQUAL(ARM_DRIVER_OK, rc); - rc = drv->GetBlock(OFFSET2 + SIZE2 - 2, &block2); - TEST_ASSERT_EQUAL(ARM_DRIVER_OK, rc); - - rc = volumeManager.addVolume_C(OFFSET2 /*addr*/, SIZE2 /*size*/ , &mtd2); - TEST_ASSERT_EQUAL(ARM_DRIVER_OK, rc); - - TEST_ASSERT_EQUAL(true, volumeManager.volumeAtIndex(1)->isAllocated()); - for (size_t index = 2; index < MAX_VOLUMES; index++) { - TEST_ASSERT_EQUAL(false, volumeManager.volumeAtIndex(index)->isAllocated()); - } - - { /* Initialize */ - rc = mtd2.Initialize(virtualMTDCallbackHandler); - TEST_ASSERT_EQUAL(1, rc); - } - } - - sizeofDataOperation = (SIZE1 > BUFFER_SIZE) ? BUFFER_SIZE : SIZE1; - sizeofDataOperation = (SIZE2 > sizeofDataOperation) ? sizeofDataOperation : SIZE2; - TEST_ASSERT((sizeofDataOperation > 0) && (sizeofDataOperation <= BUFFER_SIZE)); - memset(buffer, PATTERN_FOR_PROGRAM_DATA, sizeofDataOperation); - - /* intentional fall-through */ - - case ERASE1: - rc = mtd1.Erase(0, sizeofDataOperation); - TEST_ASSERT(rc >= ARM_DRIVER_OK); - if (rc == ARM_DRIVER_OK) { - TEST_ASSERT_EQUAL(1, mtd1.GetCapabilities().asynchronous_ops); - state = PROGRAM_DATA1; - return CaseTimeout(200) + CaseRepeatAll; - } - - virtualVolumeCallbackStatus = rc; - /* intentional fallthrough */ - - case PROGRAM_DATA1: - TEST_ASSERT_EQUAL(sizeofDataOperation, virtualVolumeCallbackStatus); - - tr_info("PROGRAM_DATA1"); - rc = mtd1.ProgramData(0, buffer, sizeofDataOperation); - TEST_ASSERT(rc >= ARM_DRIVER_OK); - if (rc == ARM_DRIVER_OK) { - TEST_ASSERT_EQUAL(1, mtd1.GetCapabilities().asynchronous_ops); - - ARM_STORAGE_STATUS status; - status = drv->GetStatus(); - TEST_ASSERT_EQUAL(1, status.busy); - TEST_ASSERT_EQUAL(0, status.error); - status = mtd1.GetStatus(); - TEST_ASSERT_EQUAL(1, status.busy); - TEST_ASSERT_EQUAL(0, status.error); - status = mtd2.GetStatus(); - TEST_ASSERT_EQUAL(1, status.busy); - TEST_ASSERT_EQUAL(0, status.error); - - rc = mtd2.ProgramData(0, buffer, sizeofDataOperation); - TEST_ASSERT_EQUAL(ARM_DRIVER_ERROR_BUSY, rc); - rc = mtd1.ProgramData(0, buffer, sizeofDataOperation); - TEST_ASSERT_EQUAL(ARM_DRIVER_ERROR_BUSY, rc); - rc = mtd1.ReadData(0, buffer, sizeofDataOperation); - TEST_ASSERT_EQUAL(ARM_DRIVER_ERROR_BUSY, rc); - rc = mtd1.Erase(0, sizeofDataOperation); - TEST_ASSERT_EQUAL(ARM_DRIVER_ERROR_BUSY, rc); - - state = ERASE2; - return CaseTimeout(200) + CaseRepeatAll; - } - - virtualVolumeCallbackStatus = rc; - /* intentional fallthrough */ - - case ERASE2: - TEST_ASSERT_EQUAL(sizeofDataOperation, virtualVolumeCallbackStatus); - - rc = mtd2.Erase(0, sizeofDataOperation); - TEST_ASSERT(rc >= ARM_DRIVER_OK); - if (rc == ARM_DRIVER_OK) { - TEST_ASSERT_EQUAL(1, mtd2.GetCapabilities().asynchronous_ops); - state = PROGRAM_DATA2; - return CaseTimeout(200) + CaseRepeatAll; - } - - virtualVolumeCallbackStatus = rc; - /* intentional fallthrough */ - - case PROGRAM_DATA2: - TEST_ASSERT_EQUAL(sizeofDataOperation, virtualVolumeCallbackStatus); - - tr_info("PROGRAM_DATA2"); - rc = mtd2.ProgramData(0, buffer, sizeofDataOperation); - TEST_ASSERT(rc >= ARM_DRIVER_OK); - if (rc == ARM_DRIVER_OK) { - TEST_ASSERT_EQUAL(1, mtd2.GetCapabilities().asynchronous_ops); - - ARM_STORAGE_STATUS status; - status = drv->GetStatus(); - TEST_ASSERT_EQUAL(1, status.busy); - TEST_ASSERT_EQUAL(0, status.error); - status = mtd2.GetStatus(); - TEST_ASSERT_EQUAL(1, status.busy); - TEST_ASSERT_EQUAL(0, status.error); - status = mtd1.GetStatus(); - TEST_ASSERT_EQUAL(1, status.busy); - TEST_ASSERT_EQUAL(0, status.error); - - rc = mtd1.ProgramData(0, buffer, sizeofDataOperation); - TEST_ASSERT_EQUAL(ARM_DRIVER_ERROR_BUSY, rc); - rc = mtd2.ProgramData(0, buffer, sizeofDataOperation); - TEST_ASSERT_EQUAL(ARM_DRIVER_ERROR_BUSY, rc); - rc = mtd2.ReadData(0, buffer, sizeofDataOperation); - TEST_ASSERT_EQUAL(ARM_DRIVER_ERROR_BUSY, rc); - rc = mtd2.Erase(0, sizeofDataOperation); - TEST_ASSERT_EQUAL(ARM_DRIVER_ERROR_BUSY, rc); - - state = DISCONNECT_VOLUME_MANAGER_CALLBACK; - return CaseTimeout(200) + CaseRepeatAll; - } - - virtualVolumeCallbackStatus = rc; - /* intentional fallthrough */ - - case DISCONNECT_VOLUME_MANAGER_CALLBACK: - tr_info("DISCONNECT_VOLUME_MANAGER_CALLBACK"); - rc = drv->Initialize(mtdCallbackHandler); - TEST_ASSERT_EQUAL(1, rc); /* expect synchronous completion */ - /* intentional fallthrough */ - - case READ_FROM_DRV_AFTER_PROGRAM_DATA1: - tr_info("verifying state"); - /* Read after Program */ - rc = drv->ReadData(OFFSET1, buffer, sizeofDataOperation); - TEST_ASSERT(rc >= ARM_DRIVER_OK); - if (rc == ARM_DRIVER_OK) { - TEST_ASSERT_EQUAL(1, drv->GetCapabilities().asynchronous_ops); - state = VERIFY_PROGRAM_DATA1; - return CaseTimeout(200) + CaseRepeatAll; - } - - virtualVolumeCallbackStatus = rc; - /* intentional fallthrough */ - - case VERIFY_PROGRAM_DATA1: - TEST_ASSERT_EQUAL(sizeofDataOperation, virtualVolumeCallbackStatus); - - for (uint32_t index = 0; index < sizeofDataOperation; index++) { - if ((buffer)[index] != PATTERN_FOR_PROGRAM_DATA) { - tr_info("%s:%u: %" PRIu32 ": expected 0x%02x, found 0x%02x", __FUNCTION__, __LINE__, index, PATTERN_FOR_PROGRAM_DATA, buffer[index]); - } - TEST_ASSERT_EQUAL(PATTERN_FOR_PROGRAM_DATA, buffer[index]); - } - /* intentional fallthrough */ - - case READ_FROM_DRV_AFTER_PROGRAM_DATA2: - /* Read after Program */ - rc = drv->ReadData(OFFSET2, buffer, sizeofDataOperation); - TEST_ASSERT(rc >= ARM_DRIVER_OK); - if (rc == ARM_DRIVER_OK) { - TEST_ASSERT_EQUAL(1, drv->GetCapabilities().asynchronous_ops); - state = VERIFY_PROGRAM_DATA2; - return CaseTimeout(200) + CaseRepeatAll; - } - - virtualVolumeCallbackStatus = rc; - /* intentional fallthrough */ - - case VERIFY_PROGRAM_DATA2: - TEST_ASSERT_EQUAL(sizeofDataOperation, virtualVolumeCallbackStatus); - - for (uint32_t index = 0; index < sizeofDataOperation; index++) { - if ((buffer)[index] != PATTERN_FOR_PROGRAM_DATA) { - tr_info("%s:%u: %" PRIu32 ": expected 0x%02x, found 0x%02x", __FUNCTION__, __LINE__, index, PATTERN_FOR_PROGRAM_DATA, buffer[index]); - } - TEST_ASSERT_EQUAL(PATTERN_FOR_PROGRAM_DATA, buffer[index]); - } - break; - - default: - TEST_ASSERT(false); - } - - return CaseNext; -} - -// Specify all your test cases here -Case cases[] = { - Case("initialize", test_initialize), - Case("Against a single volume at offset", test_againstSingleVolumeAtOffset<0>), - Case("Against a single volume at offset", test_againstSingleVolumeAtOffset<4096>), - Case("Against a single volume at offset", test_againstSingleVolumeAtOffset<8192>), - Case("Against a single volume at offset", test_againstSingleVolumeAtOffset<65536>), - Case("Against a single C_Storage at offset", test_againstSingleCStorageAtOffset<0>), - Case("Against a single C_Storage at offset", test_againstSingleCStorageAtOffset<4096>), - Case("Against a single C_Storage at offset", test_againstSingleCStorageAtOffset<8192>), - Case("Against a single C_Storage at offset", test_againstSingleCStorageAtOffset<65536>), - - /* note: the following tests are unportable in the sense that they require the underlying storage device to support certain address ranges. */ - Case("Concurrent accesss from two volumes", test_concurrentAccessFromTwoVolumes<512*1024, 128*1024, (512+128)*1024, 128*1024>), - Case("Concurrent accesss from two volumes", test_concurrentAccessFromTwoVolumes<512*1024, 128*1024, (512+128)*1024, 128*1024>), - Case("Concurrent accesss from two volumes", test_concurrentAccessFromTwoVolumes<512*1024, 128*1024, (512+256)*1024, 128*1024>), - Case("Concurrent accesss from two volumes", test_concurrentAccessFromTwoVolumes<512*1024, 128*1024, (512+384)*1024, 128*1024>), - Case("Concurrent accesss from two C_Storage devices", test_concurrentAccessFromTwoCStorageDevices<512*1024, 128*1024, (512+128)*1024, 128*1024>), - Case("Concurrent accesss from two C_Storage devices", test_concurrentAccessFromTwoCStorageDevices<512*1024, 128*1024, (512+256)*1024, 128*1024>), - Case("Concurrent accesss from two C_Storage devices", test_concurrentAccessFromTwoCStorageDevices<512*1024, 128*1024, (512+384)*1024, 128*1024>), -}; - -// Declare your test specification with a custom setup handler -#ifndef AVOID_GREENTEA -Specification specification(greentea_setup, cases); -#else -Specification specification([](const size_t) {return STATUS_CONTINUE;}, cases); -#endif - -int main(int argc, char** argv) -{ - mbed_trace_init(); // initialize the trace library - mbed_trace_config_set(TRACE_MODE_COLOR | TRACE_ACTIVE_LEVEL_INFO | TRACE_CARRIAGE_RETURN); - - // Run the test specification - Harness::run(specification); -} diff --git a/features/storage/FEATURE_STORAGE/cfstore/LICENSE b/features/storage/FEATURE_STORAGE/cfstore/LICENSE deleted file mode 100644 index 3ebeebb..0000000 --- a/features/storage/FEATURE_STORAGE/cfstore/LICENSE +++ /dev/null @@ -1,8 +0,0 @@ -Unless specifically indicated otherwise in a file, files are licensed -2 under the Apache 2.0 license, as can be found in: apache-2.0.txt - -Source code in cfstore_fnmatch.c is licensed under the agreements in the -following files: -- berkeley.txt -- chernov.txt -- tatmanjants.txt \ No newline at end of file diff --git a/features/storage/FEATURE_STORAGE/cfstore/Makefile.scripts b/features/storage/FEATURE_STORAGE/cfstore/Makefile.scripts deleted file mode 100644 index 1f18b8e..0000000 --- a/features/storage/FEATURE_STORAGE/cfstore/Makefile.scripts +++ /dev/null @@ -1,63 +0,0 @@ -########################################################################### -# -# Copyright (c) 2013-2015, ARM Limited, All Rights Reserved -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -########################################################################### - -# -# inline debugging/flashing scripts -# -define __SCRIPT_GDB - target remote $(DEBUG_HOST) - monitor endian little - monitor reset - monitor halt - monitor semihosting enable - monitor speed 1000 - monitor loadbin $(TARGET_BIN) 0 - monitor flash device = $(CPU) - load $(TARGET) - file $(TARGET) - b app_start -endef -export __SCRIPT_GDB - -define __SCRIPT_FLASH - r - loadbin $(TARGET_BIN) 0 - r - g - q -endef -export __SCRIPT_FLASH - -define __SCRIPT_ERASE - h - Sleep 100 - unlock kinetis - Sleep 100 - erase - q -endef -export __SCRIPT_ERASE - -define __SCRIPT_RESET - h - r - g - q -endef -export __SCRIPT_RESET diff --git a/features/storage/FEATURE_STORAGE/cfstore/README.md b/features/storage/FEATURE_STORAGE/cfstore/README.md deleted file mode 100644 index 2f645ab..0000000 --- a/features/storage/FEATURE_STORAGE/cfstore/README.md +++ /dev/null @@ -1,103 +0,0 @@ -# Secure Key-Value Storage # - - -## Executive Summary - -The Configuration Store (CFSTORE) is a secure, -associative key-value (KV) store C-Language Hardware Abstraction Layer. -CFSTORE provides the secure and persistent storage for: -- Storing encryption keys data. -- Storing configuration data. -- Storing firmware, firmware updates and incremental firmware blocks for assembling into a firmware update. - -These services are presented to clients with: -- A conceptually simple, file-like interface for storing and managing data using (key, value) pairs in - persistent storage media. -- A simple, hardware-independent API to promote portability across multiple platforms and a low attack surface. -- A very small code/memory footprint so CFSTORE is capable of running on highly-constrained memory systems (~10kB free memory) - where typically available SRAM << NV storage. -- A simple (low complexity) storage capability at the expense of features. For example, CFSTORE only supports the storage of - binary blobs rather than a rich set of data types. - -Current support includes: -- NV-backed support. Integration with Flash Abstraction (Flash Journal Strategy Sequential) for persistent storage on the Freescale FRDM K64F target. -- SRAM backed support. -- More than 60 test cases with >80% test coverage. -- Comprehensive documentation including doxygen generated API and test case documentation. - - -# Configuration-Store Software Architecture - -```C - - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Configuration Store Client | - | e.g. FOTA | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Configuration Store | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Flash Abstraction Layer | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Flash Driver Layer | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - SW - ----------------------------------------------------------------------- - HW - - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | NV Storage Media e.g. Flash | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - Configuration Store Software Architecture - -``` - -The above figure shows the following entities (from top to bottom): -- A Configuration Store client e.g. FOTA. -- Configuration Store, the associative KV pair store. -- Flash Abstraction Layer, portable across the driver layer. -- Flash Driver layer e.g. CMSIS-Driver. -- NV Storage Media. These are the physical storage media. - - -# Providing Feedback - -If you would like to make a contribution to CFSTORE, please provide feedback/designs/comments/code in one of the following ways: -- By logging an issue in the CFSTORE repo. -- By submitting a Pull Request to the CFSTORE repo. -- By sending an email to: --- simon.hughes@arm.com --- milosch.meriac@arm.com - - -# Further Reading - -* The [CFSTORE Getting Started Guide][CFSTORE_GETSTART] including examples. -* The [CFSTORE Engineering Requirements.][CFSTORE_ENGREQ] -* The [CFSTORE High Level Design Document.][CFSTORE_HLD] -* The [CFSTORE Low Level Design Document.][CFSTORE_LLD] -* The [CFSTORE Test Plan.][CFSTORE_TESTPLAN] -* The [CFSTORE Application Note 0001: NXP Freescale Kinetis FRDM-K64F Flash Memory Usage.][CFSTORE_APPNOTE_0001] -* The [CFSTORE Releases][CFSTORE_RELEASE] provides requirements tracking by listing the requirements supported for a CFSTORE version. - - -20160714 - -[CFSTORE_ENGREQ]: doc/design/configuration_store_requirements.md -[CFSTORE_EX1]: ../TESTS/cfstore/example1/example1.cpp -[CFSTORE_EX3]: ../TESTS/cfstore/example3/example3.cpp -[CFSTORE_GETSTART]: doc/design/configuration_store_getting_started.md -[CFSTORE_HLD]: doc/design/configuration_store_hld.md -[CFSTORE_LLD]: doc/design/configuration_store_lld.md -[CFSTORE_TESTPLAN]: doc/design/configuration_store_test_plan.md -[CFSTORE_PROJPLAN]:doc/design/configuration_store_project.md -[CFSTORE_RELEASE]: doc/project/configuration_store_releases.md -[CFSTORE_TERM]: doc/design/configuration_store_terminology.md -[CFSTORE_APPNOTE_0001]: doc/design/configuration_store_app_note_0001.md diff --git a/features/storage/FEATURE_STORAGE/cfstore/VERSION b/features/storage/FEATURE_STORAGE/cfstore/VERSION deleted file mode 100644 index a3c7a02..0000000 --- a/features/storage/FEATURE_STORAGE/cfstore/VERSION +++ /dev/null @@ -1,3 +0,0 @@ -{ - "version": "0.3.3", -} diff --git a/features/storage/FEATURE_STORAGE/cfstore/apache-2.0.txt b/features/storage/FEATURE_STORAGE/cfstore/apache-2.0.txt deleted file mode 100644 index 35750c5..0000000 --- a/features/storage/FEATURE_STORAGE/cfstore/apache-2.0.txt +++ /dev/null @@ -1,13 +0,0 @@ -Copyright (c) 2016 ARM Limited - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. diff --git a/features/storage/FEATURE_STORAGE/cfstore/berkeley.txt b/features/storage/FEATURE_STORAGE/cfstore/berkeley.txt deleted file mode 100644 index 85d6eac..0000000 --- a/features/storage/FEATURE_STORAGE/cfstore/berkeley.txt +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 1989, 1993, 1994 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Guido van Rossum. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ \ No newline at end of file diff --git a/features/storage/FEATURE_STORAGE/cfstore/cfstore.doxyfile b/features/storage/FEATURE_STORAGE/cfstore/cfstore.doxyfile deleted file mode 100644 index cfe73ce..0000000 --- a/features/storage/FEATURE_STORAGE/cfstore/cfstore.doxyfile +++ /dev/null @@ -1,2419 +0,0 @@ -# Doxyfile 1.8.10 - -# This file describes the settings to be used by the documentation system -# doxygen (www.doxygen.org) for a project. -# -# All text after a double hash (##) is considered a comment and is placed in -# front of the TAG it is preceding. -# -# All text after a single hash (#) is considered a comment and will be ignored. -# The format is: -# TAG = value [value, ...] -# For lists, items can also be appended using: -# TAG += value [value, ...] -# Values that contain spaces should be placed between quotes (\" \"). - -#--------------------------------------------------------------------------- -# Project related configuration options -#--------------------------------------------------------------------------- - -# This tag specifies the encoding used for all characters in the config file -# that follow. The default is UTF-8 which is also the encoding used for all text -# before the first occurrence of this tag. Doxygen uses libiconv (or the iconv -# built into libc) for the transcoding. See http://www.gnu.org/software/libiconv -# for the list of possible encodings. -# The default value is: UTF-8. - -DOXYFILE_ENCODING = UTF-8 - -# The PROJECT_NAME tag is a single word (or a sequence of words surrounded by -# double-quotes, unless you are using Doxywizard) that should identify the -# project for which the documentation is generated. This name is used in the -# title of most generated pages and in a few other places. -# The default value is: My Project. - -PROJECT_NAME = "Configuration Store" - -# The PROJECT_NUMBER tag can be used to enter a project or revision number. This -# could be handy for archiving the generated documentation or if some version -# control system is used. - -PROJECT_NUMBER = v0.3.3 - -# Using the PROJECT_BRIEF tag one can provide an optional one line description -# for a project that appears at the top of each page and should give viewer a -# quick idea about the purpose of the project. Keep the description short. - -PROJECT_BRIEF = "Secure Associative Key-Value Store for Persisting Data Attributes to Flash in mbedOS Based Systems ." - -# With the PROJECT_LOGO tag one can specify a logo or an icon that is included -# in the documentation. The maximum height of the logo should not exceed 55 -# pixels and the maximum width should not exceed 200 pixels. Doxygen will copy -# the logo to the output directory. - -PROJECT_LOGO = - -# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) path -# into which the generated documentation will be written. If a relative path is -# entered, it will be relative to the location where doxygen was started. If -# left blank the current directory will be used. - -OUTPUT_DIRECTORY = apidoc/ - -# If the CREATE_SUBDIRS tag is set to YES then doxygen will create 4096 sub- -# directories (in 2 levels) under the output directory of each output format and -# will distribute the generated files over these directories. Enabling this -# option can be useful when feeding doxygen a huge amount of source files, where -# putting all generated files in the same directory would otherwise causes -# performance problems for the file system. -# The default value is: NO. - -CREATE_SUBDIRS = NO - -# If the ALLOW_UNICODE_NAMES tag is set to YES, doxygen will allow non-ASCII -# characters to appear in the names of generated files. If set to NO, non-ASCII -# characters will be escaped, for example _xE3_x81_x84 will be used for Unicode -# U+3044. -# The default value is: NO. - -ALLOW_UNICODE_NAMES = NO - -# The OUTPUT_LANGUAGE tag is used to specify the language in which all -# documentation generated by doxygen is written. Doxygen will use this -# information to generate all constant output in the proper language. -# Possible values are: Afrikaans, Arabic, Armenian, Brazilian, Catalan, Chinese, -# Chinese-Traditional, Croatian, Czech, Danish, Dutch, English (United States), -# Esperanto, Farsi (Persian), Finnish, French, German, Greek, Hungarian, -# Indonesian, Italian, Japanese, Japanese-en (Japanese with English messages), -# Korean, Korean-en (Korean with English messages), Latvian, Lithuanian, -# Macedonian, Norwegian, Persian (Farsi), Polish, Portuguese, Romanian, Russian, -# Serbian, Serbian-Cyrillic, Slovak, Slovene, Spanish, Swedish, Turkish, -# Ukrainian and Vietnamese. -# The default value is: English. - -OUTPUT_LANGUAGE = English - -# If the BRIEF_MEMBER_DESC tag is set to YES, doxygen will include brief member -# descriptions after the members that are listed in the file and class -# documentation (similar to Javadoc). Set to NO to disable this. -# The default value is: YES. - -BRIEF_MEMBER_DESC = YES - -# If the REPEAT_BRIEF tag is set to YES, doxygen will prepend the brief -# description of a member or function before the detailed description -# -# Note: If both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the -# brief descriptions will be completely suppressed. -# The default value is: YES. - -REPEAT_BRIEF = YES - -# This tag implements a quasi-intelligent brief description abbreviator that is -# used to form the text in various listings. Each string in this list, if found -# as the leading text of the brief description, will be stripped from the text -# and the result, after processing the whole list, is used as the annotated -# text. Otherwise, the brief description is used as-is. If left blank, the -# following values are used ($name is automatically replaced with the name of -# the entity):The $name class, The $name widget, The $name file, is, provides, -# specifies, contains, represents, a, an and the. - -ABBREVIATE_BRIEF = "The $name class" \ - "The $name widget" \ - "The $name file" \ - is \ - provides \ - specifies \ - contains \ - represents \ - a \ - an \ - the - -# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then -# doxygen will generate a detailed section even if there is only a brief -# description. -# The default value is: NO. - -ALWAYS_DETAILED_SEC = NO - -# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all -# inherited members of a class in the documentation of that class as if those -# members were ordinary class members. Constructors, destructors and assignment -# operators of the base classes will not be shown. -# The default value is: NO. - -INLINE_INHERITED_MEMB = NO - -# If the FULL_PATH_NAMES tag is set to YES, doxygen will prepend the full path -# before files name in the file list and in the header files. If set to NO the -# shortest path that makes the file name unique will be used -# The default value is: YES. - -FULL_PATH_NAMES = YES - -# The STRIP_FROM_PATH tag can be used to strip a user-defined part of the path. -# Stripping is only done if one of the specified strings matches the left-hand -# part of the path. The tag can be used to show relative paths in the file list. -# If left blank the directory from which doxygen is run is used as the path to -# strip. -# -# Note that you can specify absolute paths here, but also relative paths, which -# will be relative from the directory where doxygen is started. -# This tag requires that the tag FULL_PATH_NAMES is set to YES. - -STRIP_FROM_PATH = - -# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of the -# path mentioned in the documentation of a class, which tells the reader which -# header file to include in order to use a class. If left blank only the name of -# the header file containing the class definition is used. Otherwise one should -# specify the list of include paths that are normally passed to the compiler -# using the -I flag. - -STRIP_FROM_INC_PATH = - -# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter (but -# less readable) file names. This can be useful is your file systems doesn't -# support long names like on DOS, Mac, or CD-ROM. -# The default value is: NO. - -SHORT_NAMES = NO - -# If the JAVADOC_AUTOBRIEF tag is set to YES then doxygen will interpret the -# first line (until the first dot) of a Javadoc-style comment as the brief -# description. If set to NO, the Javadoc-style will behave just like regular Qt- -# style comments (thus requiring an explicit @brief command for a brief -# description.) -# The default value is: NO. - -JAVADOC_AUTOBRIEF = YES - -# If the QT_AUTOBRIEF tag is set to YES then doxygen will interpret the first -# line (until the first dot) of a Qt-style comment as the brief description. If -# set to NO, the Qt-style will behave just like regular Qt-style comments (thus -# requiring an explicit \brief command for a brief description.) -# The default value is: NO. - -QT_AUTOBRIEF = NO - -# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make doxygen treat a -# multi-line C++ special comment block (i.e. a block of //! or /// comments) as -# a brief description. This used to be the default behavior. The new default is -# to treat a multi-line C++ comment block as a detailed description. Set this -# tag to YES if you prefer the old behavior instead. -# -# Note that setting this tag to YES also means that rational rose comments are -# not recognized any more. -# The default value is: NO. - -MULTILINE_CPP_IS_BRIEF = NO - -# If the INHERIT_DOCS tag is set to YES then an undocumented member inherits the -# documentation from any documented member that it re-implements. -# The default value is: YES. - -INHERIT_DOCS = YES - -# If the SEPARATE_MEMBER_PAGES tag is set to YES then doxygen will produce a new -# page for each member. If set to NO, the documentation of a member will be part -# of the file/class/namespace that contains it. -# The default value is: NO. - -SEPARATE_MEMBER_PAGES = NO - -# The TAB_SIZE tag can be used to set the number of spaces in a tab. Doxygen -# uses this value to replace tabs by spaces in code fragments. -# Minimum value: 1, maximum value: 16, default value: 4. - -TAB_SIZE = 4 - -# This tag can be used to specify a number of aliases that act as commands in -# the documentation. An alias has the form: -# name=value -# For example adding -# "sideeffect=@par Side Effects:\n" -# will allow you to put the command \sideeffect (or @sideeffect) in the -# documentation, which will result in a user-defined paragraph with heading -# "Side Effects:". You can put \n's in the value part of an alias to insert -# newlines. - -ALIASES = "experimental=\n
Experimental:
This feature is marked as experimental.
\n" \ - "experimental{1}=\n
Experimental:
\1
\n" - -# This tag can be used to specify a number of word-keyword mappings (TCL only). -# A mapping has the form "name=value". For example adding "class=itcl::class" -# will allow you to use the command class in the itcl::class meaning. - -TCL_SUBST = - -# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C sources -# only. Doxygen will then generate output that is more tailored for C. For -# instance, some of the names that are used will be different. The list of all -# members will be omitted, etc. -# The default value is: NO. - -OPTIMIZE_OUTPUT_FOR_C = YES - -# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java or -# Python sources only. Doxygen will then generate output that is more tailored -# for that language. For instance, namespaces will be presented as packages, -# qualified scopes will look different, etc. -# The default value is: NO. - -OPTIMIZE_OUTPUT_JAVA = NO - -# Set the OPTIMIZE_FOR_FORTRAN tag to YES if your project consists of Fortran -# sources. Doxygen will then generate output that is tailored for Fortran. -# The default value is: NO. - -OPTIMIZE_FOR_FORTRAN = NO - -# Set the OPTIMIZE_OUTPUT_VHDL tag to YES if your project consists of VHDL -# sources. Doxygen will then generate output that is tailored for VHDL. -# The default value is: NO. - -OPTIMIZE_OUTPUT_VHDL = NO - -# Doxygen selects the parser to use depending on the extension of the files it -# parses. With this tag you can assign which parser to use for a given -# extension. Doxygen has a built-in mapping, but you can override or extend it -# using this tag. The format is ext=language, where ext is a file extension, and -# language is one of the parsers supported by doxygen: IDL, Java, Javascript, -# C#, C, C++, D, PHP, Objective-C, Python, Fortran (fixed format Fortran: -# FortranFixed, free formatted Fortran: FortranFree, unknown formatted Fortran: -# Fortran. In the later case the parser tries to guess whether the code is fixed -# or free formatted code, this is the default for Fortran type files), VHDL. For -# instance to make doxygen treat .inc files as Fortran files (default is PHP), -# and .f files as C (default is Fortran), use: inc=Fortran f=C. -# -# Note: For files without extension you can use no_extension as a placeholder. -# -# Note that for custom extensions you also need to set FILE_PATTERNS otherwise -# the files are not read by doxygen. - -EXTENSION_MAPPING = h=C - -# If the MARKDOWN_SUPPORT tag is enabled then doxygen pre-processes all comments -# according to the Markdown format, which allows for more readable -# documentation. See http://daringfireball.net/projects/markdown/ for details. -# The output of markdown processing is further processed by doxygen, so you can -# mix doxygen, HTML, and XML commands with Markdown formatting. Disable only in -# case of backward compatibilities issues. -# The default value is: YES. - -MARKDOWN_SUPPORT = YES - -# When enabled doxygen tries to link words that correspond to documented -# classes, or namespaces to their corresponding documentation. Such a link can -# be prevented in individual cases by putting a % sign in front of the word or -# globally by setting AUTOLINK_SUPPORT to NO. -# The default value is: YES. - -AUTOLINK_SUPPORT = YES - -# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want -# to include (a tag file for) the STL sources as input, then you should set this -# tag to YES in order to let doxygen match functions declarations and -# definitions whose arguments contain STL classes (e.g. func(std::string); -# versus func(std::string) {}). This also make the inheritance and collaboration -# diagrams that involve STL classes more complete and accurate. -# The default value is: NO. - -BUILTIN_STL_SUPPORT = NO - -# If you use Microsoft's C++/CLI language, you should set this option to YES to -# enable parsing support. -# The default value is: NO. - -CPP_CLI_SUPPORT = NO - -# Set the SIP_SUPPORT tag to YES if your project consists of sip (see: -# http://www.riverbankcomputing.co.uk/software/sip/intro) sources only. Doxygen -# will parse them like normal C++ but will assume all classes use public instead -# of private inheritance when no explicit protection keyword is present. -# The default value is: NO. - -SIP_SUPPORT = NO - -# For Microsoft's IDL there are propget and propput attributes to indicate -# getter and setter methods for a property. Setting this option to YES will make -# doxygen to replace the get and set methods by a property in the documentation. -# This will only work if the methods are indeed getting or setting a simple -# type. If this is not the case, or you want to show the methods anyway, you -# should set this option to NO. -# The default value is: YES. - -IDL_PROPERTY_SUPPORT = YES - -# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC -# tag is set to YES then doxygen will reuse the documentation of the first -# member in the group (if any) for the other members of the group. By default -# all members of a group must be documented explicitly. -# The default value is: NO. - -DISTRIBUTE_GROUP_DOC = NO - -# If one adds a struct or class to a group and this option is enabled, then also -# any nested class or struct is added to the same group. By default this option -# is disabled and one has to add nested compounds explicitly via \ingroup. -# The default value is: NO. - -GROUP_NESTED_COMPOUNDS = NO - -# Set the SUBGROUPING tag to YES to allow class member groups of the same type -# (for instance a group of public functions) to be put as a subgroup of that -# type (e.g. under the Public Functions section). Set it to NO to prevent -# subgrouping. Alternatively, this can be done per class using the -# \nosubgrouping command. -# The default value is: YES. - -SUBGROUPING = YES - -# When the INLINE_GROUPED_CLASSES tag is set to YES, classes, structs and unions -# are shown inside the group in which they are included (e.g. using \ingroup) -# instead of on a separate page (for HTML and Man pages) or section (for LaTeX -# and RTF). -# -# Note that this feature does not work in combination with -# SEPARATE_MEMBER_PAGES. -# The default value is: NO. - -INLINE_GROUPED_CLASSES = NO - -# When the INLINE_SIMPLE_STRUCTS tag is set to YES, structs, classes, and unions -# with only public data fields or simple typedef fields will be shown inline in -# the documentation of the scope in which they are defined (i.e. file, -# namespace, or group documentation), provided this scope is documented. If set -# to NO, structs, classes, and unions are shown on a separate page (for HTML and -# Man pages) or section (for LaTeX and RTF). -# The default value is: NO. - -INLINE_SIMPLE_STRUCTS = YES - -# When TYPEDEF_HIDES_STRUCT tag is enabled, a typedef of a struct, union, or -# enum is documented as struct, union, or enum with the name of the typedef. So -# typedef struct TypeS {} TypeT, will appear in the documentation as a struct -# with name TypeT. When disabled the typedef will appear as a member of a file, -# namespace, or class. And the struct will be named TypeS. This can typically be -# useful for C code in case the coding convention dictates that all compound -# types are typedef'ed and only the typedef is referenced, never the tag name. -# The default value is: NO. - -TYPEDEF_HIDES_STRUCT = YES - -# The size of the symbol lookup cache can be set using LOOKUP_CACHE_SIZE. This -# cache is used to resolve symbols given their name and scope. Since this can be -# an expensive process and often the same symbol appears multiple times in the -# code, doxygen keeps a cache of pre-resolved symbols. If the cache is too small -# doxygen will become slower. If the cache is too large, memory is wasted. The -# cache size is given by this formula: 2^(16+LOOKUP_CACHE_SIZE). The valid range -# is 0..9, the default is 0, corresponding to a cache size of 2^16=65536 -# symbols. At the end of a run doxygen will report the cache usage and suggest -# the optimal cache size from a speed point of view. -# Minimum value: 0, maximum value: 9, default value: 0. - -LOOKUP_CACHE_SIZE = 0 - -#--------------------------------------------------------------------------- -# Build related configuration options -#--------------------------------------------------------------------------- - -# If the EXTRACT_ALL tag is set to YES, doxygen will assume all entities in -# documentation are documented, even if no documentation was available. Private -# class members and static file members will be hidden unless the -# EXTRACT_PRIVATE respectively EXTRACT_STATIC tags are set to YES. -# Note: This will also disable the warnings about undocumented members that are -# normally produced when WARNINGS is set to YES. -# The default value is: NO. - -EXTRACT_ALL = NO - -# If the EXTRACT_PRIVATE tag is set to YES, all private members of a class will -# be included in the documentation. -# The default value is: NO. - -EXTRACT_PRIVATE = NO - -# If the EXTRACT_PACKAGE tag is set to YES, all members with package or internal -# scope will be included in the documentation. -# The default value is: NO. - -EXTRACT_PACKAGE = NO - -# If the EXTRACT_STATIC tag is set to YES, all static members of a file will be -# included in the documentation. -# The default value is: NO. - -EXTRACT_STATIC = NO - -# If the EXTRACT_LOCAL_CLASSES tag is set to YES, classes (and structs) defined -# locally in source files will be included in the documentation. If set to NO, -# only classes defined in header files are included. Does not have any effect -# for Java sources. -# The default value is: YES. - -EXTRACT_LOCAL_CLASSES = YES - -# This flag is only useful for Objective-C code. If set to YES, local methods, -# which are defined in the implementation section but not in the interface are -# included in the documentation. If set to NO, only methods in the interface are -# included. -# The default value is: NO. - -EXTRACT_LOCAL_METHODS = NO - -# If this flag is set to YES, the members of anonymous namespaces will be -# extracted and appear in the documentation as a namespace called -# 'anonymous_namespace{file}', where file will be replaced with the base name of -# the file that contains the anonymous namespace. By default anonymous namespace -# are hidden. -# The default value is: NO. - -EXTRACT_ANON_NSPACES = YES - -# If the HIDE_UNDOC_MEMBERS tag is set to YES, doxygen will hide all -# undocumented members inside documented classes or files. If set to NO these -# members will be included in the various overviews, but no documentation -# section is generated. This option has no effect if EXTRACT_ALL is enabled. -# The default value is: NO. - -HIDE_UNDOC_MEMBERS = NO - -# If the HIDE_UNDOC_CLASSES tag is set to YES, doxygen will hide all -# undocumented classes that are normally visible in the class hierarchy. If set -# to NO, these classes will be included in the various overviews. This option -# has no effect if EXTRACT_ALL is enabled. -# The default value is: NO. - -HIDE_UNDOC_CLASSES = NO - -# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, doxygen will hide all friend -# (class|struct|union) declarations. If set to NO, these declarations will be -# included in the documentation. -# The default value is: NO. - -HIDE_FRIEND_COMPOUNDS = NO - -# If the HIDE_IN_BODY_DOCS tag is set to YES, doxygen will hide any -# documentation blocks found inside the body of a function. If set to NO, these -# blocks will be appended to the function's detailed documentation block. -# The default value is: NO. - -HIDE_IN_BODY_DOCS = NO - -# The INTERNAL_DOCS tag determines if documentation that is typed after a -# \internal command is included. If the tag is set to NO then the documentation -# will be excluded. Set it to YES to include the internal documentation. -# The default value is: NO. - -INTERNAL_DOCS = NO - -# If the CASE_SENSE_NAMES tag is set to NO then doxygen will only generate file -# names in lower-case letters. If set to YES, upper-case letters are also -# allowed. This is useful if you have classes or files whose names only differ -# in case and if your file system supports case sensitive file names. Windows -# and Mac users are advised to set this option to NO. -# The default value is: system dependent. - -CASE_SENSE_NAMES = NO - -# If the HIDE_SCOPE_NAMES tag is set to NO then doxygen will show members with -# their full class and namespace scopes in the documentation. If set to YES, the -# scope will be hidden. -# The default value is: NO. - -HIDE_SCOPE_NAMES = NO - -# If the HIDE_COMPOUND_REFERENCE tag is set to NO (default) then doxygen will -# append additional text to a page's title, such as Class Reference. If set to -# YES the compound reference will be hidden. -# The default value is: NO. - -HIDE_COMPOUND_REFERENCE= NO - -# If the SHOW_INCLUDE_FILES tag is set to YES then doxygen will put a list of -# the files that are included by a file in the documentation of that file. -# The default value is: YES. - -SHOW_INCLUDE_FILES = YES - -# If the SHOW_GROUPED_MEMB_INC tag is set to YES then Doxygen will add for each -# grouped member an include statement to the documentation, telling the reader -# which file to include in order to use the member. -# The default value is: NO. - -SHOW_GROUPED_MEMB_INC = NO - -# If the FORCE_LOCAL_INCLUDES tag is set to YES then doxygen will list include -# files with double quotes in the documentation rather than with sharp brackets. -# The default value is: NO. - -FORCE_LOCAL_INCLUDES = NO - -# If the INLINE_INFO tag is set to YES then a tag [inline] is inserted in the -# documentation for inline members. -# The default value is: YES. - -INLINE_INFO = YES - -# If the SORT_MEMBER_DOCS tag is set to YES then doxygen will sort the -# (detailed) documentation of file and class members alphabetically by member -# name. If set to NO, the members will appear in declaration order. -# The default value is: YES. - -SORT_MEMBER_DOCS = YES - -# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the brief -# descriptions of file, namespace and class members alphabetically by member -# name. If set to NO, the members will appear in declaration order. Note that -# this will also influence the order of the classes in the class list. -# The default value is: NO. - -SORT_BRIEF_DOCS = NO - -# If the SORT_MEMBERS_CTORS_1ST tag is set to YES then doxygen will sort the -# (brief and detailed) documentation of class members so that constructors and -# destructors are listed first. If set to NO the constructors will appear in the -# respective orders defined by SORT_BRIEF_DOCS and SORT_MEMBER_DOCS. -# Note: If SORT_BRIEF_DOCS is set to NO this option is ignored for sorting brief -# member documentation. -# Note: If SORT_MEMBER_DOCS is set to NO this option is ignored for sorting -# detailed member documentation. -# The default value is: NO. - -SORT_MEMBERS_CTORS_1ST = YES - -# If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the hierarchy -# of group names into alphabetical order. If set to NO the group names will -# appear in their defined order. -# The default value is: NO. - -SORT_GROUP_NAMES = NO - -# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be sorted by -# fully-qualified names, including namespaces. If set to NO, the class list will -# be sorted only by class name, not including the namespace part. -# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES. -# Note: This option applies only to the class list, not to the alphabetical -# list. -# The default value is: NO. - -SORT_BY_SCOPE_NAME = NO - -# If the STRICT_PROTO_MATCHING option is enabled and doxygen fails to do proper -# type resolution of all parameters of a function it will reject a match between -# the prototype and the implementation of a member function even if there is -# only one candidate or it is obvious which candidate to choose by doing a -# simple string match. By disabling STRICT_PROTO_MATCHING doxygen will still -# accept a match between prototype and implementation in such cases. -# The default value is: NO. - -STRICT_PROTO_MATCHING = NO - -# The GENERATE_TODOLIST tag can be used to enable (YES) or disable (NO) the todo -# list. This list is created by putting \todo commands in the documentation. -# The default value is: YES. - -GENERATE_TODOLIST = YES - -# The GENERATE_TESTLIST tag can be used to enable (YES) or disable (NO) the test -# list. This list is created by putting \test commands in the documentation. -# The default value is: YES. - -GENERATE_TESTLIST = YES - -# The GENERATE_BUGLIST tag can be used to enable (YES) or disable (NO) the bug -# list. This list is created by putting \bug commands in the documentation. -# The default value is: YES. - -GENERATE_BUGLIST = YES - -# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or disable (NO) -# the deprecated list. This list is created by putting \deprecated commands in -# the documentation. -# The default value is: YES. - -GENERATE_DEPRECATEDLIST= YES - -# The ENABLED_SECTIONS tag can be used to enable conditional documentation -# sections, marked by \if ... \endif and \cond -# ... \endcond blocks. - -ENABLED_SECTIONS = - -# The MAX_INITIALIZER_LINES tag determines the maximum number of lines that the -# initial value of a variable or macro / define can have for it to appear in the -# documentation. If the initializer consists of more lines than specified here -# it will be hidden. Use a value of 0 to hide initializers completely. The -# appearance of the value of individual variables and macros / defines can be -# controlled using \showinitializer or \hideinitializer command in the -# documentation regardless of this setting. -# Minimum value: 0, maximum value: 10000, default value: 30. - -MAX_INITIALIZER_LINES = 30 - -# Set the SHOW_USED_FILES tag to NO to disable the list of files generated at -# the bottom of the documentation of classes and structs. If set to YES, the -# list will mention the files that were used to generate the documentation. -# The default value is: YES. - -SHOW_USED_FILES = YES - -# Set the SHOW_FILES tag to NO to disable the generation of the Files page. This -# will remove the Files entry from the Quick Index and from the Folder Tree View -# (if specified). -# The default value is: YES. - -SHOW_FILES = YES - -# Set the SHOW_NAMESPACES tag to NO to disable the generation of the Namespaces -# page. This will remove the Namespaces entry from the Quick Index and from the -# Folder Tree View (if specified). -# The default value is: YES. - -SHOW_NAMESPACES = YES - -# The FILE_VERSION_FILTER tag can be used to specify a program or script that -# doxygen should invoke to get the current version for each file (typically from -# the version control system). Doxygen will invoke the program by executing (via -# popen()) the command command input-file, where command is the value of the -# FILE_VERSION_FILTER tag, and input-file is the name of an input file provided -# by doxygen. Whatever the program writes to standard output is used as the file -# version. For an example see the documentation. - -FILE_VERSION_FILTER = - -# The LAYOUT_FILE tag can be used to specify a layout file which will be parsed -# by doxygen. The layout file controls the global structure of the generated -# output files in an output format independent way. To create the layout file -# that represents doxygen's defaults, run doxygen with the -l option. You can -# optionally specify a file name after the option, if omitted DoxygenLayout.xml -# will be used as the name of the layout file. -# -# Note that if you run doxygen from a directory containing a file called -# DoxygenLayout.xml, doxygen will parse it automatically even if the LAYOUT_FILE -# tag is left empty. - -LAYOUT_FILE = - -# The CITE_BIB_FILES tag can be used to specify one or more bib files containing -# the reference definitions. This must be a list of .bib files. The .bib -# extension is automatically appended if omitted. This requires the bibtex tool -# to be installed. See also http://en.wikipedia.org/wiki/BibTeX for more info. -# For LaTeX the style of the bibliography can be controlled using -# LATEX_BIB_STYLE. To use this feature you need bibtex and perl available in the -# search path. See also \cite for info how to create references. - -CITE_BIB_FILES = - -#--------------------------------------------------------------------------- -# Configuration options related to warning and progress messages -#--------------------------------------------------------------------------- - -# The QUIET tag can be used to turn on/off the messages that are generated to -# standard output by doxygen. If QUIET is set to YES this implies that the -# messages are off. -# The default value is: NO. - -QUIET = NO - -# The WARNINGS tag can be used to turn on/off the warning messages that are -# generated to standard error (stderr) by doxygen. If WARNINGS is set to YES -# this implies that the warnings are on. -# -# Tip: Turn warnings on while writing the documentation. -# The default value is: YES. - -WARNINGS = YES - -# If the WARN_IF_UNDOCUMENTED tag is set to YES then doxygen will generate -# warnings for undocumented members. If EXTRACT_ALL is set to YES then this flag -# will automatically be disabled. -# The default value is: YES. - -WARN_IF_UNDOCUMENTED = YES - -# If the WARN_IF_DOC_ERROR tag is set to YES, doxygen will generate warnings for -# potential errors in the documentation, such as not documenting some parameters -# in a documented function, or documenting parameters that don't exist or using -# markup commands wrongly. -# The default value is: YES. - -WARN_IF_DOC_ERROR = YES - -# This WARN_NO_PARAMDOC option can be enabled to get warnings for functions that -# are documented, but have no documentation for their parameters or return -# value. If set to NO, doxygen will only warn about wrong or incomplete -# parameter documentation, but not about the absence of documentation. -# The default value is: NO. - -WARN_NO_PARAMDOC = YES - -# The WARN_FORMAT tag determines the format of the warning messages that doxygen -# can produce. The string should contain the $file, $line, and $text tags, which -# will be replaced by the file and line number from which the warning originated -# and the warning text. Optionally the format may contain $version, which will -# be replaced by the version of the file (if it could be obtained via -# FILE_VERSION_FILTER) -# The default value is: $file:$line: $text. - -WARN_FORMAT = "$file:$line: $text" - -# The WARN_LOGFILE tag can be used to specify a file to which warning and error -# messages should be written. If left blank the output is written to standard -# error (stderr). - -WARN_LOGFILE = doxygen_warn.log - -#--------------------------------------------------------------------------- -# Configuration options related to the input files -#--------------------------------------------------------------------------- - -# The INPUT tag is used to specify the files and/or directories that contain -# documented source files. You may enter file names like myfile.cpp or -# directories like /usr/src/myproject. Separate the files or directories with -# spaces. See also FILE_PATTERNS and EXTENSION_MAPPING -# Note: If this tag is empty the current directory is searched. - -INPUT = configuration-store README.md doc/design/ doc/project/ ../TESTS/cfstore - -# This tag can be used to specify the character encoding of the source files -# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses -# libiconv (or the iconv built into libc) for the transcoding. See the libiconv -# documentation (see: http://www.gnu.org/software/libiconv) for the list of -# possible encodings. -# The default value is: UTF-8. - -INPUT_ENCODING = UTF-8 - -# If the value of the INPUT tag contains directories, you can use the -# FILE_PATTERNS tag to specify one or more wildcard patterns (like *.cpp and -# *.h) to filter out the source-files in the directories. -# -# Note that for custom extensions or not directly supported extensions you also -# need to set EXTENSION_MAPPING for the extension otherwise the files are not -# read by doxygen. -# -# If left blank the following patterns are tested:*.c, *.cc, *.cxx, *.cpp, -# *.c++, *.java, *.ii, *.ixx, *.ipp, *.i++, *.inl, *.idl, *.ddl, *.odl, *.h, -# *.hh, *.hxx, *.hpp, *.h++, *.cs, *.d, *.php, *.php4, *.php5, *.phtml, *.inc, -# *.m, *.markdown, *.md, *.mm, *.dox, *.py, *.f90, *.f, *.for, *.tcl, *.vhd, -# *.vhdl, *.ucf, *.qsf, *.as and *.js. - -FILE_PATTERNS = *.h \ - *.cpp \ - *.md - -# The RECURSIVE tag can be used to specify whether or not subdirectories should -# be searched for input files as well. -# The default value is: NO. - -RECURSIVE = YES - -# The EXCLUDE tag can be used to specify files and/or directories that should be -# excluded from the INPUT source files. This way you can easily exclude a -# subdirectory from a directory tree whose root is specified with the INPUT tag. -# -# Note that relative paths are relative to the directory from which doxygen is -# run. - -EXCLUDE = configs \ - CONTRIBUTING.md - -# The EXCLUDE_SYMLINKS tag can be used to select whether or not files or -# directories that are symbolic links (a Unix file system feature) are excluded -# from the input. -# The default value is: NO. - -EXCLUDE_SYMLINKS = NO - -# If the value of the INPUT tag contains directories, you can use the -# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude -# certain files from those directories. -# -# Note that the wildcards are matched against the file with absolute path, so to -# exclude all test directories for example use the pattern */test/* - -EXCLUDE_PATTERNS = - -# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names -# (namespaces, classes, functions, etc.) that should be excluded from the -# output. The symbol name can be a fully qualified name, a word, or if the -# wildcard * is used, a substring. Examples: ANamespace, AClass, -# AClass::ANamespace, ANamespace::*Test -# -# Note that the wildcards are matched against the file with absolute path, so to -# exclude all test directories use the pattern */test/* - -EXCLUDE_SYMBOLS = - -# The EXAMPLE_PATH tag can be used to specify one or more files or directories -# that contain example code fragments that are included (see the \include -# command). - -EXAMPLE_PATH = - -# If the value of the EXAMPLE_PATH tag contains directories, you can use the -# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp and -# *.h) to filter out the source-files in the directories. If left blank all -# files are included. - -EXAMPLE_PATTERNS = - -# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be -# searched for input files to be used with the \include or \dontinclude commands -# irrespective of the value of the RECURSIVE tag. -# The default value is: NO. - -EXAMPLE_RECURSIVE = NO - -# The IMAGE_PATH tag can be used to specify one or more files or directories -# that contain images that are to be included in the documentation (see the -# \image command). - -IMAGE_PATH = doc/design/pics - -# The INPUT_FILTER tag can be used to specify a program that doxygen should -# invoke to filter for each input file. Doxygen will invoke the filter program -# by executing (via popen()) the command: -# -# -# -# where is the value of the INPUT_FILTER tag, and is the -# name of an input file. Doxygen will then use the output that the filter -# program writes to standard output. If FILTER_PATTERNS is specified, this tag -# will be ignored. -# -# Note that the filter must not add or remove lines; it is applied before the -# code is scanned, but not when the output code is generated. If lines are added -# or removed, the anchors will not be placed correctly. - -INPUT_FILTER = - -# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern -# basis. Doxygen will compare the file name with each pattern and apply the -# filter if there is a match. The filters are a list of the form: pattern=filter -# (like *.cpp=my_cpp_filter). See INPUT_FILTER for further information on how -# filters are used. If the FILTER_PATTERNS tag is empty or if none of the -# patterns match the file name, INPUT_FILTER is applied. - -FILTER_PATTERNS = - -# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using -# INPUT_FILTER) will also be used to filter the input files that are used for -# producing the source files to browse (i.e. when SOURCE_BROWSER is set to YES). -# The default value is: NO. - -FILTER_SOURCE_FILES = NO - -# The FILTER_SOURCE_PATTERNS tag can be used to specify source filters per file -# pattern. A pattern will override the setting for FILTER_PATTERN (if any) and -# it is also possible to disable source filtering for a specific pattern using -# *.ext= (so without naming a filter). -# This tag requires that the tag FILTER_SOURCE_FILES is set to YES. - -FILTER_SOURCE_PATTERNS = - -# If the USE_MDFILE_AS_MAINPAGE tag refers to the name of a markdown file that -# is part of the input, its contents will be placed on the main page -# (index.html). This can be useful if you have a project on for instance GitHub -# and want to reuse the introduction page also for the doxygen output. - -#USE_MDFILE_AS_MAINPAGE = DOXYGEN_FRONTPAGE.md -USE_MDFILE_AS_MAINPAGE = README.md - -#--------------------------------------------------------------------------- -# Configuration options related to source browsing -#--------------------------------------------------------------------------- - -# If the SOURCE_BROWSER tag is set to YES then a list of source files will be -# generated. Documented entities will be cross-referenced with these sources. -# -# Note: To get rid of all source code in the generated output, make sure that -# also VERBATIM_HEADERS is set to NO. -# The default value is: NO. - -SOURCE_BROWSER = YES - -# Setting the INLINE_SOURCES tag to YES will include the body of functions, -# classes and enums directly into the documentation. -# The default value is: NO. - -INLINE_SOURCES = NO - -# Setting the STRIP_CODE_COMMENTS tag to YES will instruct doxygen to hide any -# special comment blocks from generated source code fragments. Normal C, C++ and -# Fortran comments will always remain visible. -# The default value is: YES. - -STRIP_CODE_COMMENTS = YES - -# If the REFERENCED_BY_RELATION tag is set to YES then for each documented -# function all documented functions referencing it will be listed. -# The default value is: NO. - -REFERENCED_BY_RELATION = YES - -# If the REFERENCES_RELATION tag is set to YES then for each documented function -# all documented entities called/used by that function will be listed. -# The default value is: NO. - -REFERENCES_RELATION = YES - -# If the REFERENCES_LINK_SOURCE tag is set to YES and SOURCE_BROWSER tag is set -# to YES then the hyperlinks from functions in REFERENCES_RELATION and -# REFERENCED_BY_RELATION lists will link to the source code. Otherwise they will -# link to the documentation. -# The default value is: YES. - -REFERENCES_LINK_SOURCE = YES - -# If SOURCE_TOOLTIPS is enabled (the default) then hovering a hyperlink in the -# source code will show a tooltip with additional information such as prototype, -# brief description and links to the definition and documentation. Since this -# will make the HTML file larger and loading of large files a bit slower, you -# can opt to disable this feature. -# The default value is: YES. -# This tag requires that the tag SOURCE_BROWSER is set to YES. - -SOURCE_TOOLTIPS = YES - -# If the USE_HTAGS tag is set to YES then the references to source code will -# point to the HTML generated by the htags(1) tool instead of doxygen built-in -# source browser. The htags tool is part of GNU's global source tagging system -# (see http://www.gnu.org/software/global/global.html). You will need version -# 4.8.6 or higher. -# -# To use it do the following: -# - Install the latest version of global -# - Enable SOURCE_BROWSER and USE_HTAGS in the config file -# - Make sure the INPUT points to the root of the source tree -# - Run doxygen as normal -# -# Doxygen will invoke htags (and that will in turn invoke gtags), so these -# tools must be available from the command line (i.e. in the search path). -# -# The result: instead of the source browser generated by doxygen, the links to -# source code will now point to the output of htags. -# The default value is: NO. -# This tag requires that the tag SOURCE_BROWSER is set to YES. - -USE_HTAGS = NO - -# If the VERBATIM_HEADERS tag is set the YES then doxygen will generate a -# verbatim copy of the header file for each class for which an include is -# specified. Set to NO to disable this. -# See also: Section \class. -# The default value is: YES. - -VERBATIM_HEADERS = YES - -# If the CLANG_ASSISTED_PARSING tag is set to YES then doxygen will use the -# clang parser (see: http://clang.llvm.org/) for more accurate parsing at the -# cost of reduced performance. This can be particularly helpful with template -# rich C++ code for which doxygen's built-in parser lacks the necessary type -# information. -# Note: The availability of this option depends on whether or not doxygen was -# compiled with the --with-libclang option. -# The default value is: NO. - -CLANG_ASSISTED_PARSING = NO - -# If clang assisted parsing is enabled you can provide the compiler with command -# line options that you would normally use when invoking the compiler. Note that -# the include paths will already be set by doxygen for the files and directories -# specified with INPUT and INCLUDE_PATH. -# This tag requires that the tag CLANG_ASSISTED_PARSING is set to YES. - -CLANG_OPTIONS = - -#--------------------------------------------------------------------------- -# Configuration options related to the alphabetical class index -#--------------------------------------------------------------------------- - -# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index of all -# compounds will be generated. Enable this if the project contains a lot of -# classes, structs, unions or interfaces. -# The default value is: YES. - -ALPHABETICAL_INDEX = YES - -# The COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns in -# which the alphabetical index list will be split. -# Minimum value: 1, maximum value: 20, default value: 5. -# This tag requires that the tag ALPHABETICAL_INDEX is set to YES. - -COLS_IN_ALPHA_INDEX = 5 - -# In case all classes in a project start with a common prefix, all classes will -# be put under the same header in the alphabetical index. The IGNORE_PREFIX tag -# can be used to specify a prefix (or a list of prefixes) that should be ignored -# while generating the index headers. -# This tag requires that the tag ALPHABETICAL_INDEX is set to YES. - -IGNORE_PREFIX = - -#--------------------------------------------------------------------------- -# Configuration options related to the HTML output -#--------------------------------------------------------------------------- - -# If the GENERATE_HTML tag is set to YES, doxygen will generate HTML output -# The default value is: YES. - -GENERATE_HTML = YES - -# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. If a -# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of -# it. -# The default directory is: html. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_OUTPUT = . - -# The HTML_FILE_EXTENSION tag can be used to specify the file extension for each -# generated HTML page (for example: .htm, .php, .asp). -# The default value is: .html. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_FILE_EXTENSION = .html - -# The HTML_HEADER tag can be used to specify a user-defined HTML header file for -# each generated HTML page. If the tag is left blank doxygen will generate a -# standard header. -# -# To get valid HTML the header file that includes any scripts and style sheets -# that doxygen needs, which is dependent on the configuration options used (e.g. -# the setting GENERATE_TREEVIEW). It is highly recommended to start with a -# default header using -# doxygen -w html new_header.html new_footer.html new_stylesheet.css -# YourConfigFile -# and then modify the file new_header.html. See also section "Doxygen usage" -# for information on how to generate the default header that doxygen normally -# uses. -# Note: The header is subject to change so you typically have to regenerate the -# default header when upgrading to a newer version of doxygen. For a description -# of the possible markers and block names see the documentation. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_HEADER = - -# The HTML_FOOTER tag can be used to specify a user-defined HTML footer for each -# generated HTML page. If the tag is left blank doxygen will generate a standard -# footer. See HTML_HEADER for more information on how to generate a default -# footer and what special commands can be used inside the footer. See also -# section "Doxygen usage" for information on how to generate the default footer -# that doxygen normally uses. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_FOOTER = - -# The HTML_STYLESHEET tag can be used to specify a user-defined cascading style -# sheet that is used by each HTML page. It can be used to fine-tune the look of -# the HTML output. If left blank doxygen will generate a default style sheet. -# See also section "Doxygen usage" for information on how to generate the style -# sheet that doxygen normally uses. -# Note: It is recommended to use HTML_EXTRA_STYLESHEET instead of this tag, as -# it is more robust and this tag (HTML_STYLESHEET) will in the future become -# obsolete. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_STYLESHEET = - -# The HTML_EXTRA_STYLESHEET tag can be used to specify additional user-defined -# cascading style sheets that are included after the standard style sheets -# created by doxygen. Using this option one can overrule certain style aspects. -# This is preferred over using HTML_STYLESHEET since it does not replace the -# standard style sheet and is therefore more robust against future updates. -# Doxygen will copy the style sheet files to the output directory. -# Note: The order of the extra style sheet files is of importance (e.g. the last -# style sheet in the list overrules the setting of the previous ones in the -# list). For an example see the documentation. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_EXTRA_STYLESHEET = - -# The HTML_EXTRA_FILES tag can be used to specify one or more extra images or -# other source files which should be copied to the HTML output directory. Note -# that these files will be copied to the base HTML output directory. Use the -# $relpath^ marker in the HTML_HEADER and/or HTML_FOOTER files to load these -# files. In the HTML_STYLESHEET file, use the file name only. Also note that the -# files will be copied as-is; there are no commands or markers available. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_EXTRA_FILES = - -# The HTML_COLORSTYLE_HUE tag controls the color of the HTML output. Doxygen -# will adjust the colors in the style sheet and background images according to -# this color. Hue is specified as an angle on a colorwheel, see -# http://en.wikipedia.org/wiki/Hue for more information. For instance the value -# 0 represents red, 60 is yellow, 120 is green, 180 is cyan, 240 is blue, 300 -# purple, and 360 is red again. -# Minimum value: 0, maximum value: 359, default value: 220. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_COLORSTYLE_HUE = 220 - -# The HTML_COLORSTYLE_SAT tag controls the purity (or saturation) of the colors -# in the HTML output. For a value of 0 the output will use grayscales only. A -# value of 255 will produce the most vivid colors. -# Minimum value: 0, maximum value: 255, default value: 100. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_COLORSTYLE_SAT = 100 - -# The HTML_COLORSTYLE_GAMMA tag controls the gamma correction applied to the -# luminance component of the colors in the HTML output. Values below 100 -# gradually make the output lighter, whereas values above 100 make the output -# darker. The value divided by 100 is the actual gamma applied, so 80 represents -# a gamma of 0.8, The value 220 represents a gamma of 2.2, and 100 does not -# change the gamma. -# Minimum value: 40, maximum value: 240, default value: 80. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_COLORSTYLE_GAMMA = 80 - -# If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML -# page will contain the date and time when the page was generated. Setting this -# to YES can help to show when doxygen was last run and thus if the -# documentation is up to date. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_TIMESTAMP = YES - -# If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML -# documentation will contain sections that can be hidden and shown after the -# page has loaded. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_DYNAMIC_SECTIONS = NO - -# With HTML_INDEX_NUM_ENTRIES one can control the preferred number of entries -# shown in the various tree structured indices initially; the user can expand -# and collapse entries dynamically later on. Doxygen will expand the tree to -# such a level that at most the specified number of entries are visible (unless -# a fully collapsed tree already exceeds this amount). So setting the number of -# entries 1 will produce a full collapsed tree by default. 0 is a special value -# representing an infinite number of entries and will result in a full expanded -# tree by default. -# Minimum value: 0, maximum value: 9999, default value: 100. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_INDEX_NUM_ENTRIES = 100 - -# If the GENERATE_DOCSET tag is set to YES, additional index files will be -# generated that can be used as input for Apple's Xcode 3 integrated development -# environment (see: http://developer.apple.com/tools/xcode/), introduced with -# OSX 10.5 (Leopard). To create a documentation set, doxygen will generate a -# Makefile in the HTML output directory. Running make will produce the docset in -# that directory and running make install will install the docset in -# ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find it at -# startup. See http://developer.apple.com/tools/creatingdocsetswithdoxygen.html -# for more information. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -GENERATE_DOCSET = NO - -# This tag determines the name of the docset feed. A documentation feed provides -# an umbrella under which multiple documentation sets from a single provider -# (such as a company or product suite) can be grouped. -# The default value is: Doxygen generated docs. -# This tag requires that the tag GENERATE_DOCSET is set to YES. - -DOCSET_FEEDNAME = "Doxygen generated docs" - -# This tag specifies a string that should uniquely identify the documentation -# set bundle. This should be a reverse domain-name style string, e.g. -# com.mycompany.MyDocSet. Doxygen will append .docset to the name. -# The default value is: org.doxygen.Project. -# This tag requires that the tag GENERATE_DOCSET is set to YES. - -DOCSET_BUNDLE_ID = org.doxygen.Project - -# The DOCSET_PUBLISHER_ID tag specifies a string that should uniquely identify -# the documentation publisher. This should be a reverse domain-name style -# string, e.g. com.mycompany.MyDocSet.documentation. -# The default value is: org.doxygen.Publisher. -# This tag requires that the tag GENERATE_DOCSET is set to YES. - -DOCSET_PUBLISHER_ID = org.doxygen.Publisher - -# The DOCSET_PUBLISHER_NAME tag identifies the documentation publisher. -# The default value is: Publisher. -# This tag requires that the tag GENERATE_DOCSET is set to YES. - -DOCSET_PUBLISHER_NAME = Publisher - -# If the GENERATE_HTMLHELP tag is set to YES then doxygen generates three -# additional HTML index files: index.hhp, index.hhc, and index.hhk. The -# index.hhp is a project file that can be read by Microsoft's HTML Help Workshop -# (see: http://www.microsoft.com/en-us/download/details.aspx?id=21138) on -# Windows. -# -# The HTML Help Workshop contains a compiler that can convert all HTML output -# generated by doxygen into a single compiled HTML file (.chm). Compiled HTML -# files are now used as the Windows 98 help format, and will replace the old -# Windows help format (.hlp) on all Windows platforms in the future. Compressed -# HTML files also contain an index, a table of contents, and you can search for -# words in the documentation. The HTML workshop also contains a viewer for -# compressed HTML files. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -GENERATE_HTMLHELP = NO - -# The CHM_FILE tag can be used to specify the file name of the resulting .chm -# file. You can add a path in front of the file if the result should not be -# written to the html output directory. -# This tag requires that the tag GENERATE_HTMLHELP is set to YES. - -CHM_FILE = - -# The HHC_LOCATION tag can be used to specify the location (absolute path -# including file name) of the HTML help compiler (hhc.exe). If non-empty, -# doxygen will try to run the HTML help compiler on the generated index.hhp. -# The file has to be specified with full path. -# This tag requires that the tag GENERATE_HTMLHELP is set to YES. - -HHC_LOCATION = - -# The GENERATE_CHI flag controls if a separate .chi index file is generated -# (YES) or that it should be included in the master .chm file (NO). -# The default value is: NO. -# This tag requires that the tag GENERATE_HTMLHELP is set to YES. - -GENERATE_CHI = NO - -# The CHM_INDEX_ENCODING is used to encode HtmlHelp index (hhk), content (hhc) -# and project file content. -# This tag requires that the tag GENERATE_HTMLHELP is set to YES. - -CHM_INDEX_ENCODING = - -# The BINARY_TOC flag controls whether a binary table of contents is generated -# (YES) or a normal table of contents (NO) in the .chm file. Furthermore it -# enables the Previous and Next buttons. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTMLHELP is set to YES. - -BINARY_TOC = NO - -# The TOC_EXPAND flag can be set to YES to add extra items for group members to -# the table of contents of the HTML help documentation and to the tree view. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTMLHELP is set to YES. - -TOC_EXPAND = NO - -# If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and -# QHP_VIRTUAL_FOLDER are set, an additional index file will be generated that -# can be used as input for Qt's qhelpgenerator to generate a Qt Compressed Help -# (.qch) of the generated HTML documentation. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -GENERATE_QHP = NO - -# If the QHG_LOCATION tag is specified, the QCH_FILE tag can be used to specify -# the file name of the resulting .qch file. The path specified is relative to -# the HTML output folder. -# This tag requires that the tag GENERATE_QHP is set to YES. - -QCH_FILE = - -# The QHP_NAMESPACE tag specifies the namespace to use when generating Qt Help -# Project output. For more information please see Qt Help Project / Namespace -# (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#namespace). -# The default value is: org.doxygen.Project. -# This tag requires that the tag GENERATE_QHP is set to YES. - -QHP_NAMESPACE = org.doxygen.Project - -# The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating Qt -# Help Project output. For more information please see Qt Help Project / Virtual -# Folders (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#virtual- -# folders). -# The default value is: doc. -# This tag requires that the tag GENERATE_QHP is set to YES. - -QHP_VIRTUAL_FOLDER = doc - -# If the QHP_CUST_FILTER_NAME tag is set, it specifies the name of a custom -# filter to add. For more information please see Qt Help Project / Custom -# Filters (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#custom- -# filters). -# This tag requires that the tag GENERATE_QHP is set to YES. - -QHP_CUST_FILTER_NAME = - -# The QHP_CUST_FILTER_ATTRS tag specifies the list of the attributes of the -# custom filter to add. For more information please see Qt Help Project / Custom -# Filters (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#custom- -# filters). -# This tag requires that the tag GENERATE_QHP is set to YES. - -QHP_CUST_FILTER_ATTRS = - -# The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this -# project's filter section matches. Qt Help Project / Filter Attributes (see: -# http://qt-project.org/doc/qt-4.8/qthelpproject.html#filter-attributes). -# This tag requires that the tag GENERATE_QHP is set to YES. - -QHP_SECT_FILTER_ATTRS = - -# The QHG_LOCATION tag can be used to specify the location of Qt's -# qhelpgenerator. If non-empty doxygen will try to run qhelpgenerator on the -# generated .qhp file. -# This tag requires that the tag GENERATE_QHP is set to YES. - -QHG_LOCATION = - -# If the GENERATE_ECLIPSEHELP tag is set to YES, additional index files will be -# generated, together with the HTML files, they form an Eclipse help plugin. To -# install this plugin and make it available under the help contents menu in -# Eclipse, the contents of the directory containing the HTML and XML files needs -# to be copied into the plugins directory of eclipse. The name of the directory -# within the plugins directory should be the same as the ECLIPSE_DOC_ID value. -# After copying Eclipse needs to be restarted before the help appears. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -GENERATE_ECLIPSEHELP = NO - -# A unique identifier for the Eclipse help plugin. When installing the plugin -# the directory name containing the HTML and XML files should also have this -# name. Each documentation set should have its own identifier. -# The default value is: org.doxygen.Project. -# This tag requires that the tag GENERATE_ECLIPSEHELP is set to YES. - -ECLIPSE_DOC_ID = org.doxygen.Project - -# If you want full control over the layout of the generated HTML pages it might -# be necessary to disable the index and replace it with your own. The -# DISABLE_INDEX tag can be used to turn on/off the condensed index (tabs) at top -# of each HTML page. A value of NO enables the index and the value YES disables -# it. Since the tabs in the index contain the same information as the navigation -# tree, you can set this option to YES if you also set GENERATE_TREEVIEW to YES. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -DISABLE_INDEX = NO - -# The GENERATE_TREEVIEW tag is used to specify whether a tree-like index -# structure should be generated to display hierarchical information. If the tag -# value is set to YES, a side panel will be generated containing a tree-like -# index structure (just like the one that is generated for HTML Help). For this -# to work a browser that supports JavaScript, DHTML, CSS and frames is required -# (i.e. any modern browser). Windows users are probably better off using the -# HTML help feature. Via custom style sheets (see HTML_EXTRA_STYLESHEET) one can -# further fine-tune the look of the index. As an example, the default style -# sheet generated by doxygen has an example that shows how to put an image at -# the root of the tree instead of the PROJECT_NAME. Since the tree basically has -# the same information as the tab index, you could consider setting -# DISABLE_INDEX to YES when enabling this option. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -GENERATE_TREEVIEW = NO - -# The ENUM_VALUES_PER_LINE tag can be used to set the number of enum values that -# doxygen will group on one line in the generated HTML documentation. -# -# Note that a value of 0 will completely suppress the enum values from appearing -# in the overview section. -# Minimum value: 0, maximum value: 20, default value: 4. -# This tag requires that the tag GENERATE_HTML is set to YES. - -ENUM_VALUES_PER_LINE = 4 - -# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be used -# to set the initial width (in pixels) of the frame in which the tree is shown. -# Minimum value: 0, maximum value: 1500, default value: 250. -# This tag requires that the tag GENERATE_HTML is set to YES. - -TREEVIEW_WIDTH = 250 - -# If the EXT_LINKS_IN_WINDOW option is set to YES, doxygen will open links to -# external symbols imported via tag files in a separate window. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -EXT_LINKS_IN_WINDOW = NO - -# Use this tag to change the font size of LaTeX formulas included as images in -# the HTML documentation. When you change the font size after a successful -# doxygen run you need to manually remove any form_*.png images from the HTML -# output directory to force them to be regenerated. -# Minimum value: 8, maximum value: 50, default value: 10. -# This tag requires that the tag GENERATE_HTML is set to YES. - -FORMULA_FONTSIZE = 10 - -# Use the FORMULA_TRANPARENT tag to determine whether or not the images -# generated for formulas are transparent PNGs. Transparent PNGs are not -# supported properly for IE 6.0, but are supported on all modern browsers. -# -# Note that when changing this option you need to delete any form_*.png files in -# the HTML output directory before the changes have effect. -# The default value is: YES. -# This tag requires that the tag GENERATE_HTML is set to YES. - -FORMULA_TRANSPARENT = YES - -# Enable the USE_MATHJAX option to render LaTeX formulas using MathJax (see -# http://www.mathjax.org) which uses client side Javascript for the rendering -# instead of using pre-rendered bitmaps. Use this if you do not have LaTeX -# installed or if you want to formulas look prettier in the HTML output. When -# enabled you may also need to install MathJax separately and configure the path -# to it using the MATHJAX_RELPATH option. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -USE_MATHJAX = NO - -# When MathJax is enabled you can set the default output format to be used for -# the MathJax output. See the MathJax site (see: -# http://docs.mathjax.org/en/latest/output.html) for more details. -# Possible values are: HTML-CSS (which is slower, but has the best -# compatibility), NativeMML (i.e. MathML) and SVG. -# The default value is: HTML-CSS. -# This tag requires that the tag USE_MATHJAX is set to YES. - -MATHJAX_FORMAT = HTML-CSS - -# When MathJax is enabled you need to specify the location relative to the HTML -# output directory using the MATHJAX_RELPATH option. The destination directory -# should contain the MathJax.js script. For instance, if the mathjax directory -# is located at the same level as the HTML output directory, then -# MATHJAX_RELPATH should be ../mathjax. The default value points to the MathJax -# Content Delivery Network so you can quickly see the result without installing -# MathJax. However, it is strongly recommended to install a local copy of -# MathJax from http://www.mathjax.org before deployment. -# The default value is: http://cdn.mathjax.org/mathjax/latest. -# This tag requires that the tag USE_MATHJAX is set to YES. - -MATHJAX_RELPATH = http://cdn.mathjax.org/mathjax/latest - -# The MATHJAX_EXTENSIONS tag can be used to specify one or more MathJax -# extension names that should be enabled during MathJax rendering. For example -# MATHJAX_EXTENSIONS = TeX/AMSmath TeX/AMSsymbols -# This tag requires that the tag USE_MATHJAX is set to YES. - -MATHJAX_EXTENSIONS = - -# The MATHJAX_CODEFILE tag can be used to specify a file with javascript pieces -# of code that will be used on startup of the MathJax code. See the MathJax site -# (see: http://docs.mathjax.org/en/latest/output.html) for more details. For an -# example see the documentation. -# This tag requires that the tag USE_MATHJAX is set to YES. - -MATHJAX_CODEFILE = - -# When the SEARCHENGINE tag is enabled doxygen will generate a search box for -# the HTML output. The underlying search engine uses javascript and DHTML and -# should work on any modern browser. Note that when using HTML help -# (GENERATE_HTMLHELP), Qt help (GENERATE_QHP), or docsets (GENERATE_DOCSET) -# there is already a search function so this one should typically be disabled. -# For large projects the javascript based search engine can be slow, then -# enabling SERVER_BASED_SEARCH may provide a better solution. It is possible to -# search using the keyboard; to jump to the search box use + S -# (what the is depends on the OS and browser, but it is typically -# , /