本文整理汇总了C++中ARM_CFSTORE_DRIVER::Write方法的典型用法代码示例。如果您正苦于以下问题:C++ ARM_CFSTORE_DRIVER::Write方法的具体用法?C++ ARM_CFSTORE_DRIVER::Write怎么用?C++ ARM_CFSTORE_DRIVER::Write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ARM_CFSTORE_DRIVER
的用法示例。
在下文中一共展示了ARM_CFSTORE_DRIVER::Write方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: cfstore_test_create
/* @brief test utility function to create a KV in the cfstore
* @note this function expects cfstore to have been initialised with
* a call to ARM_CFSTORE_DRIVER::Initialize()
*/
int32_t cfstore_test_create(const char* key_name, const char* data, ARM_CFSTORE_SIZE* len, ARM_CFSTORE_KEYDESC* kdesc)
{
int32_t ret = ARM_DRIVER_ERROR;
ARM_CFSTORE_SIZE value_len = 0;
ARM_CFSTORE_DRIVER* drv = &cfstore_driver;
ARM_CFSTORE_HANDLE_INIT(hkey);
CFSTORE_FENTRYLOG("%s:entered.\r\n", __func__);
value_len = *len;
kdesc->drl = ARM_RETENTION_WHILE_DEVICE_ACTIVE;
ret = drv->Create(key_name, value_len, kdesc, hkey);
if(ret < ARM_DRIVER_OK){
return ret;
}
value_len = *len;
ret = drv->Write(hkey, data, &value_len);
if(ret < ARM_DRIVER_OK){
drv->Close(hkey);
return ret;
}
if(value_len != *len){
drv->Close(hkey);
return ARM_DRIVER_ERROR;
}
drv->Close(hkey);
return ret;
}
示例2: memset
/** @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;
}
示例3: memset
/* @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;
}
示例4: memset
/**
* @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;
}
示例5: cfstore_test_write
/* @brief write the value blob of a specified KV
* @note this function expects cfstore to have been initialised with
* a call to ARM_CFSTORE_DRIVER::Initialize()
*/
int32_t cfstore_test_write(const char* key_name, const char* data, ARM_CFSTORE_SIZE* len)
{
int32_t ret = ARM_DRIVER_ERROR;
ARM_CFSTORE_DRIVER* drv = &cfstore_driver;
ARM_CFSTORE_HANDLE_INIT(hkey);
ARM_CFSTORE_FMODE flags;
CFSTORE_FENTRYLOG("%s:entered\r\n", __func__);
memset(&flags, 0, sizeof(flags));
if(key_name == NULL) {
CFSTORE_ERRLOG("%s:Error: invalid key_name argument \r\n", __func__);
goto out0;
}
if(data == NULL) {
CFSTORE_ERRLOG("%s:Error: invalid data argument \r\n", __func__);
goto out0;
}
if(len == NULL) {
CFSTORE_ERRLOG("%s:Error: invalid len argument \r\n", __func__);
goto out0;
}
flags.write = 1;
ret = drv->Open(key_name, flags, hkey);
if(ret < ARM_DRIVER_OK){
CFSTORE_ERRLOG("%s:Error: failed to open node (key_name=\"%s\")(ret=%d)\r\n", __func__, key_name, (int) ret);
goto out1;
}
ret = drv->Write(hkey, data, len);
if(ret < ARM_DRIVER_OK){
CFSTORE_ERRLOG("%s:Error: failed to write key (key_name=\"%s\")\r\n", __func__, key_name);
goto out2;
}
out2:
drv->Close(hkey);
out1:
out0:
return ret;
}
示例6: strlen
/* @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;
}
示例7: deleting
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;
}
示例8: sizeof
/** @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;
}
示例9: memset
/* @brief utility test function to initialise cfstore sram area with some
* KV's to manipulate
* @note this function expects cfstore to have been initialised with
* a call to ARM_CFSTORE_DRIVER::Initialize()
*/
int32_t cfstore_test_init_1(void)
{
char* read_buf = NULL;
const uint8_t key_name_max_len = CFSTORE_KEY_NAME_MAX_LENGTH+1;
uint8_t key_name_len = 0;
char key_name_buf[CFSTORE_KEY_NAME_MAX_LENGTH+1];
int32_t ret = ARM_DRIVER_ERROR;
ARM_CFSTORE_SIZE len = 0;
ARM_CFSTORE_SIZE max_len = 0;
ARM_CFSTORE_DRIVER* drv = &cfstore_driver;
cfstore_kv_data_t* node = NULL;
ARM_CFSTORE_KEYDESC kdesc;
ARM_CFSTORE_HANDLE_INIT(hkey);
CFSTORE_FENTRYLOG("%s:entered\r\n", __func__);
memset(&kdesc, 0, sizeof(kdesc));
memset(key_name_buf, 0, CFSTORE_KEY_NAME_MAX_LENGTH+1);
/*scan for max length of value blob*/
node = cfstore_test_init_1_data;
while(node->key_name != NULL)
{
len = strlen(node->value);
if(len > max_len){
max_len = len;
max_len++;
}
node++;
}
read_buf = (char*) malloc(max_len);
if(read_buf == NULL) {
CFSTORE_ERRLOG("%s:Error: failed to allocated read buffer \r\n", __func__);
return ret;
}
kdesc.drl = ARM_RETENTION_WHILE_DEVICE_ACTIVE;
node = cfstore_test_init_1_data;
while(node->key_name != NULL)
{
CFSTORE_DBGLOG("%s:About to create new node (key_name=\"%s\", value=\"%s\")\r\n", __func__, node->key_name, node->value);
ret = drv->Create(node->key_name, strlen(node->value), &kdesc, hkey);
if(ret < ARM_DRIVER_OK){
CFSTORE_ERRLOG("%s:Error: failed to create node (key_name=\"%s\", value=\"%s\")\r\n", __func__, node->key_name, node->value);
return ret;
}
CFSTORE_DBGLOG("%s:length of KV=%d (key_name=\"%s\", value=\"%s\")\r\n", __func__, (int) len, node->key_name, node->value);
len = strlen(node->value);
ret = drv->Write(hkey, (char*) node->value, &len);
if(ret < ARM_DRIVER_OK){
CFSTORE_ERRLOG("%s:Error: failed to write key (key_name=\"%s\", value=\"%s\")\r\n", __func__, node->key_name, node->value);
drv->Close(hkey);
return ret;
}
if(len != strlen(node->value)){
CFSTORE_ERRLOG("%s:Error: failed to write full value data (key_name=\"%s\", value=\"%s\"), len=%d\r\n", __func__, node->key_name, node->value, (int) len);
drv->Close(hkey);
return ARM_DRIVER_ERROR;
}
/* read the data back*/
len = strlen(node->value);
memset(read_buf, 0, max_len);
ret = drv->Read(hkey, read_buf, &len);
if(ret < ARM_DRIVER_OK){
CFSTORE_ERRLOG("%s:Error: failed to read key (key_name=\"%s\", value=\"%s\")\r\n", __func__, node->key_name, node->value);
drv->Close(hkey);
return ret;
}
if(len != strlen(node->value)){
CFSTORE_ERRLOG("%s:Error: failed to read full value data (key_name=\"%s\", value=\"%s\"), len=%d, ret=%d\r\n", __func__, node->key_name, node->value, (int) len, (int) ret);
drv->Close(hkey);
return ARM_DRIVER_ERROR;
}
key_name_len = key_name_max_len;
memset(key_name_buf, 0, key_name_len);
drv->GetKeyName(hkey, key_name_buf, &key_name_len);
if(len != strlen(node->value)){
CFSTORE_ERRLOG("%s:Error: failed to GetKeyName() (key_name=\"%s\", value=\"%s\"), len=%d\r\n", __func__, node->key_name, node->value, (int) len);
drv->Close(hkey);
return ARM_DRIVER_ERROR;
}
/* revert CFSTORE_LOG for more trace */
CFSTORE_DBGLOG("Created KV successfully (key_name=\"%s\", value=\"%s\")\r\n", key_name_buf, read_buf);
drv->Close(hkey);
node++;
}
free(read_buf);
return ret;
}