/** @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; }
/** * @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; }
/** @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 * * 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; }
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; }
/** @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 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; }
/**@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 * * 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; }
/**@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 * * 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 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, 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.\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 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 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; }
/** @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 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; }
/* @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; }
/** @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; }
/** @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; }
/** @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; }