Exemplo n.º 1
0
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;
}
Exemplo n.º 2
0
/** @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;
}
Exemplo n.º 3
0
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;
}
Exemplo n.º 4
0
/** @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;
}
Exemplo n.º 5
0
/* @brief  test utility function to delete the cfstore key identified by key_name
 * @note    this function expects cfstore to have been initialised with
 *          a call to ARM_CFSTORE_DRIVER::Initialize()
 */
int32_t cfstore_test_delete(const char* key_name)
{
    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));
    ret = drv->Open(key_name, flags, hkey);
    if(ret < ARM_DRIVER_OK){
        return ret;
    }
    if(hkey != NULL){
        ret = drv->Delete(hkey);
        drv->Close(hkey);
    }
    return ret;
}
Exemplo n.º 6
0
/* @brief   test utility function to check a node appears correctly in the cfstore
 * @note    this function expects cfstore to have been initialised with
 *          a call to ARM_CFSTORE_DRIVER::Initialize()
 */
int32_t cfstore_test_check_node_correct(const cfstore_kv_data_t* node)
{
    char* read_buf;
    int32_t ret = ARM_DRIVER_ERROR;
    ARM_CFSTORE_SIZE len = 0;
    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));

    ret = drv->Open(node->key_name, flags, hkey);
    if(ret < ARM_DRIVER_OK){
        CFSTORE_ERRLOG("%s:Error: failed to open node (key_name=\"%s\", value=\"%s\")(ret=%d)\r\n", __func__, node->key_name, node->value, (int) ret);
        goto out0;
    }
    len = strlen(node->value) + 1;
    read_buf = (char*) malloc(len);
    if(read_buf == NULL) {
        CFSTORE_ERRLOG("%s:Error: failed to allocated read buffer \r\n", __func__);
        goto out1;
    }
    memset(read_buf, 0, len);
    ret = drv->Read(hkey, read_buf, &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);
        goto out2;
    }
    /* check read data is as expected */
    if(strncmp(read_buf, node->value, strlen(node->value)) != 0){
        CFSTORE_ERRLOG("%s:Error: read value data (%s) != KV value data (key_name=\"%s\", value=\"%s\")\r\n", __func__, read_buf, node->key_name, node->value);
        ret = ARM_DRIVER_ERROR;
    }
out2:
    if(read_buf) free(read_buf);
out1:
    drv->Close(hkey);
    hkey = NULL;
out0:
    return ret;
}
Exemplo n.º 7
0
/**
 * @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;
}
Exemplo n.º 8
0
/* @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;
}
Exemplo n.º 9
0
/* @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;
}
Exemplo n.º 10
0
/** @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;
}