From 3e35d4bb8176261e223732dbfa43fa6a9816f4c0 Mon Sep 17 00:00:00 2001 From: Simon Hughes Date: Fri, 10 Feb 2017 15:55:05 +0000 Subject: [PATCH] STORAGE: added test case to write/check n x 25kB files storing ~250kB data. --- features/TESTS/filesystem/fopen/fopen.cpp | 176 +++++++++- features/filesystem/README.md | 66 ++-- features/filesystem/test/fsfat_test.c | 375 ---------------------- features/filesystem/test/fsfat_test.h | 21 +- 4 files changed, 221 insertions(+), 417 deletions(-) diff --git a/features/TESTS/filesystem/fopen/fopen.cpp b/features/TESTS/filesystem/fopen/fopen.cpp index 6c0c869de0..e5210f8e8b 100644 --- a/features/TESTS/filesystem/fopen/fopen.cpp +++ b/features/TESTS/filesystem/fopen/fopen.cpp @@ -71,6 +71,7 @@ static char fsfat_fopen_utest_msg_g[FSFAT_UTEST_MSG_BUF_SIZE]; #define FSFAT_FOPEN_TEST_MOUNT_PT_NAME "sd" #define FSFAT_FOPEN_TEST_MOUNT_PT_PATH "/"FSFAT_FOPEN_TEST_MOUNT_PT_NAME #define FSFAT_FOPEN_TEST_WORK_BUF_SIZE_1 64 +#define FSFAT_FOPEN_TEST_FILEPATH_MAX_DEPTH 20 static const char *sd_badfile_path = "/sd/badfile.txt"; static const char *sd_testfile_path = "/sd/test.txt"; @@ -297,7 +298,7 @@ static int32_t fsfat_filepath_make_dirs(char* filepath, bool do_asserts) char *fpathbuf = NULL; char *buf = NULL; int pos = 0; - char *parts[10]; + char *parts[FSFAT_FOPEN_TEST_FILEPATH_MAX_DEPTH]; FSFAT_DBGLOG("%s:entered\n", __func__); /* find the dirs to create*/ @@ -310,7 +311,7 @@ static int32_t fsfat_filepath_make_dirs(char* filepath, bool do_asserts) } memset(fpathbuf, 0, len+1); memcpy(fpathbuf, filepath, len); - num_parts = fsfat_filepath_split(fpathbuf, parts, 10); + num_parts = fsfat_filepath_split(fpathbuf, parts, FSFAT_FOPEN_TEST_FILEPATH_MAX_DEPTH); FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, "%s:Error: failed to split filepath (filename=\"%s\", num_parts=%d)\n", __func__, filepath, (int) num_parts); TEST_ASSERT_MESSAGE(num_parts > 0, fsfat_fopen_utest_msg_g); @@ -1332,6 +1333,175 @@ control_t fsfat_fopen_test_15(const size_t call_count) } +/* @brief test utility function to create a file of a given size. + * + * A reference data table is used of so that the data file can be later be + * checked with fsfat_test_check_data_file(). + * + * @param filename name of the file including path + * @param data data to store in file + * @param len number of bytes of data present in the data buffer. + */ +int32_t fsfat_test_create_data_file(const char* filename, size_t len) +{ + int32_t ret = -1; + FILE *fp = NULL; + size_t write_len = 0; + size_t written_len = 0; + int32_t exp = 0; + const int32_t exp_max = 8; /* so as not to exceed FSFAT_TEST_BYTE_DATA_TABLE_SIZE/2 */ + + FSFAT_FENTRYLOG("%s:entered (filename=%s, len=%d).\n", __func__, filename, (int) len); + TEST_ASSERT(len % FSFAT_TEST_BYTE_DATA_TABLE_SIZE == 0); + fp = fopen(filename, "a"); + if(fp == NULL){ + return ret; + } + + while(written_len < len) { + /* write fsfat_test_byte_data_table or part thereof, in 9 writes of sizes + * 1, 2, 4, 8, 16, 32, 64, 128, 1, totalling 256 bytes len permitting. */ + for(exp = 0; (exp <= exp_max) && (written_len < len); exp++){ + write_len = 0x1 << (exp % exp_max); + write_len = len - written_len > write_len ? write_len : len - written_len; + ret = fwrite((const void*) &fsfat_test_byte_data_table[written_len % FSFAT_TEST_BYTE_DATA_TABLE_SIZE], write_len, 1, fp); + written_len += write_len; + if(ret != 1){ + FSFAT_DBGLOG("%s:Error: fwrite() failed (ret=%d)\n", __func__, (int) ret); + ret = -1; + goto out0; + } + } + } + if(written_len == len) { + ret = 0; + } else { + ret = -1; + } +out0: + fclose(fp); + return ret; +} + + +/* @brief test utility function to check the data in the specified file is correct. + * + * The data read from the file is check that it agrees with the data written by + * fsfat_test_create_data_file(). + * + * @param filename name of the file including path + * @param data data to store in file + * @param len number of bytes of data present in the data buffer. + */ +int32_t fsfat_test_check_data_file(const char* filename, size_t len) +{ + int32_t ret = -1; + FILE *fp = NULL; + size_t read_len = 0; + uint8_t buf[FSFAT_TEST_BYTE_DATA_TABLE_SIZE]; + + FSFAT_FENTRYLOG("%s:entered (filename=%s, len=%d).\n", __func__, filename, (int) len); + TEST_ASSERT(len % FSFAT_TEST_BYTE_DATA_TABLE_SIZE == 0); + fp = fopen(filename, "r"); + if(fp == NULL){ + return ret; + } + + while(read_len < len) { + ret = fread((void*) buf, FSFAT_TEST_BYTE_DATA_TABLE_SIZE, 1, fp); + read_len += FSFAT_TEST_BYTE_DATA_TABLE_SIZE; + if(ret == 0){ + /* end of read*/ + FSFAT_DBGLOG("%s:unable to read data\n", __func__); + break; + } + if(memcmp(buf, fsfat_test_byte_data_table, FSFAT_TEST_BYTE_DATA_TABLE_SIZE) != 0) { + FSFAT_DBGLOG("%s:Error: read data not as expected (0x%2x, 0x%2x, 0x%2x, 0x%2x, 0x%2x, 0x%2x, 0x%2x, 0x%2x, 0x%2x, 0x%2x, 0x%2x, 0x%2x, 0x%2x, 0x%2x, 0x%2x, 0x%2x\n", __func__, + buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7], buf[8], buf[9], buf[10], buf[11], buf[12], buf[13], buf[14], buf[15]); + ret = -1; + goto out0; + } + } + if(read_len == len) { + ret = 0; + } +out0: + fclose(fp); + return ret; +} + +/* file data for test_16 */ +static fsfat_kv_data_t fsfat_fopen_test_16_kv_data[] = { + { "/sd/tst16_0/testfil0.txt", "dummy_data"}, + { "/sd/tst16_1/subdir0/testfil0.txt", "dummy_data"}, + { "/sd/tst16_2/subdir0/subdir1/testfil0.txt", "dummy_data"}, + { "/sd/tst16_3/subdir0/subdir1/subdir2/subdir3/testfil0.txt", "dummy_data"}, + { "/sd/tst16_4/subdir0/subdir1/subdir2/subdir3/subdir4/testfil0.txt", "dummy_data"}, + { "/sd/tst16_5/subdir0/subdir1/subdir2/subdir3/subdir4/subdir5/testfil0.txt", "dummy_data"}, + { "/sd/tst16_6/subdir0/subdir1/subdir2/subdir3/subdir4/subdir5/subdir6/testfil0.txt", "dummy_data"}, + { "/sd/tst16_7/subdir0/subdir1/subdir2/subdir3/subdir4/subdir5/subdir6/subdir7/testfil0.txt", "dummy_data"}, + { "/sd/tst16_8/subdir0/subdir1/subdir2/subdir3/subdir4/subdir5/subdir6/subdir7/subdir8/testfil0.txt", "dummy_data"}, + { "/sd/tst16_9/subdir0/subdir1/subdir2/subdir3/subdir4/subdir5/subdir6/subdir7/subdir8/subdir9/testfil0.txt", "dummy_data"}, + { NULL, NULL}, +}; + + +/** @brief stress test to write data to fs + * + * @return on success returns CaseNext to continue to next test case, otherwise will assert on errors. + */ +control_t fsfat_fopen_test_16(const size_t call_count) +{ + int32_t ret = 0; + fsfat_kv_data_t *node = fsfat_fopen_test_16_kv_data; + const int32_t num_blocks = 100; /* each file ~25kB */ + + FSFAT_DBGLOG("%s:entered\n", __func__); + (void) call_count; + + /* remove file and directory from a previous failed test run, if present */ + while(node->filename != NULL) { + fsfat_filepath_remove_all((char*) node->filename); + node++; + } + + /* create dirs */ + node = fsfat_fopen_test_16_kv_data; + while(node->filename != NULL) { + ret = fsfat_filepath_make_dirs((char*) node->filename, true); + FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, "%s:Error: failed to create dirs for filename (filename=\"%s\")(ret=%d)\n", __func__, node->filename, (int) ret); + TEST_ASSERT_MESSAGE(ret == 0, fsfat_fopen_utest_msg_g); + node++; + } + + /* create the data files */ + node = fsfat_fopen_test_16_kv_data; + while(node->filename != NULL) { + ret = fsfat_test_create_data_file(node->filename, num_blocks * FSFAT_TEST_BYTE_DATA_TABLE_SIZE); + FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, "%s:Error: failed to create data file (filename=\"%s\")(ret=%d)\n", __func__, node->filename, (int) ret); + TEST_ASSERT_MESSAGE(ret == 0, fsfat_fopen_utest_msg_g); + node++; + } + + /* read the data back and check its as expected */ + node = fsfat_fopen_test_16_kv_data; + while(node->filename != NULL) { + ret = fsfat_test_check_data_file(node->filename, num_blocks * FSFAT_TEST_BYTE_DATA_TABLE_SIZE); + FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, "%s:Error: failed to check data file (filename=\"%s\")(ret=%d)\n", __func__, node->filename, (int) ret); + TEST_ASSERT_MESSAGE(ret == 0, fsfat_fopen_utest_msg_g); + node++; + } + + /* clean up */ + node = fsfat_fopen_test_16_kv_data; + while(node->filename != NULL) { + fsfat_filepath_remove_all((char*) node->filename); + node++; + } + return CaseNext; +} + + #else @@ -1406,7 +1576,7 @@ Case cases[] = { Case("FSFAT_FOPEN_TEST_13: mkdir() test.", FSFAT_FOPEN_TEST_13), Case("FSFAT_FOPEN_TEST_14: stat() test.", FSFAT_FOPEN_TEST_14), Case("FSFAT_FOPEN_TEST_15: format() test.", FSFAT_FOPEN_TEST_15), - + Case("FSFAT_FOPEN_TEST_16: write/check n x 25kB data files.", FSFAT_FOPEN_TEST_16), }; diff --git a/features/filesystem/README.md b/features/filesystem/README.md index 7e6ff2ebb4..1e3719b371 100644 --- a/features/filesystem/README.md +++ b/features/filesystem/README.md @@ -33,6 +33,7 @@ This section describes how to build and run the POSIX file API test case. The fo - [Installing the Tools](#installing-the-tools). This section briefly describes how to setup the mbedos development environment. - [Git Clone the Public mbedOS Repo](#git-clone-the-mbedos-repo). This section describes how to git clone the mbedOS repository containing the FAT32/SDCard and POSIX File API test case of interest. - [Build the mbedOS Test Cases](#build-the-mbedos-test-cases). This section describes how to build the mbedOS test cases. +- [Insert a microSD Card Into the K64F](#insert-sdcard-into-k64f).This section describes how to format (if required) a microSD card prior to running the tests. - [Run the POSIX File Test Case](#run-the-posix-file-test-cases).This section describes how to run the POSIX file test case basic.cpp. ### Installing the Tools @@ -53,7 +54,6 @@ Using a Git Bash terminal, setup mbed-cli in the following way: simhug01@E107851:/d/demo_area/mbed-cli/$ python.exe setup.py install simhug01@E107851:/d/demo_area/mbed-cli/$ popd - Using a Git Bash terminal, setup Greentea in the following way: simhug01@E107851:/d/demo_area$ git clone git@github.com:/armmbed/greentea @@ -101,6 +101,24 @@ Build the test cases for the K64F target using the following commands: The complete [build log][BUILD-TESTS-GCC-20161219-1007] is available for reference. +### Insert SDCard into K64F + +The test cases have been run on a K64F with the following microSDHC cards: + +- Kingston 2GB mircoSDHC card. +- Kingston 8GB mircoSDHC card. +- SanDisk 16GB mircoSDHC ultra card. + +If the card requires formatting then the following procedure is known to work: + +- Insert microSD card into SD adapter in USB stick (or similar) so the microSD card can be insert into windows PC. +- Within file explorer, right click/Format on the USB drive. +- Select FAT32, 4096 cluster size, Quick Format. +- Format the drive. + +The microSD card should then be ready for use in the K64F. + + ### Run the POSIX File Test Case To setup for running the test cases, complete the following steps: @@ -174,11 +192,11 @@ The full [test output log][RUN-TESTS-GCC-20161219-1011] is available for referen mbedOS supports a subset of the POSIX File API, as outlined below: -- clearerr() +- [clearerr()][MAN_CLEARERR]. - STATUS: Basic testing implemented. Working. - [fclose()][MAN_FCLOSE]. - STATUS: Basic testing implemented. Working. -- ferror() +- [ferror()][MAN_CLEARERR]. - STATUS: Basic testing implemented. - STATUS: GCC_ARM: Working. - STATUS: ARMCC: ARMCC has problem with ferror(filep) where filep is NULL. Appears to work for non-NULL pointer. @@ -190,18 +208,20 @@ mbedOS supports a subset of the POSIX File API, as outlined below: - STATUS: Unknown. - [fputs()][MAN_FPUTS]. - STATUS: Basic testing implemented. Working. -- fprintf() +- [fprintf()][MAN_FPRINTF]. - STATUS: Basic testing implemented. Working. -- fopen() +- [fopen()][MAN_FOPEN]. - STATUS: Basic testing implemented. Working. -- freopen() +- [freopen()][MAN_FOPEN]. - STATUS: This is not tested. -- [fread()][MAN_FREAD] +- [fread()][MAN_FREAD]. - STATUS: Basic testing implemented. Working. -- ftell() + - STATUS: n x 25kB stress test working. +- [ftell()][MAN_FTELL]. - STATUS: Basic testing implemented. Working. -- [fwrite()][MAN_FWRITE] +- [fwrite()][MAN_FWRITE]. - STATUS: Basic testing implemented. Working. + - STATUS: n x 25kB stress test working. - [fseek()][MAN_FSEEK] - STATUS: Basic testing implemented. Working. - [getc()][MAN_FGETS]. @@ -214,10 +234,11 @@ mbedOS supports a subset of the POSIX File API, as outlined below: - STATUS: Unknown. - [remove()][MAN_REMOVE] - STATUS: Basic testing implemented. Working. -- rewinddir(). - - STATUS: Implemented. Not tested. -- stat() - - STATUS: Implemented. Not tested. +- [rewind()][MAN_REWIND]. + - STATUS: Basic testing implemented. Working. +- [stat()][MAN_STAT] + - STATUS: Implemented. Working. + - STATUS: Not supported by ARMCC/IAR libc. - tmpfile() - STATUS: Not implemented. - tmpnam() @@ -226,23 +247,23 @@ mbedOS supports a subset of the POSIX File API, as outlined below: Supported directory related operations are as follows: - closedir(). - - STATUS: Implemented. Not tested. + - STATUS: Implemented. Working. - mkdir(). - STATUS: Basic testing implemented. Working. - opendir(). - - STATUS: Implemented. Not tested. + - STATUS: Implemented. Working. - readdir(). - - STATUS: Implemented. Not tested. + - STATUS: Implemented. Working. - [remove()][MAN_REMOVE] - STATUS: Basic testing implemented. Working. - rename() - STATUS: Implemented. Not tested. -- [rewind()][MAN_REWIND]. - - STATUS: Basic testing implemented. Working. +- rewinddir(). + - STATUS: Implemented. Found not to work. Test case not present in repo. - seekdir() - - STATUS: Implemented. Not tested. + - STATUS: Implemented. Found not to work. Test case not present in repo. - telldir(). - - STATUS: Implemented. Not tested. + - STATUS: Implemented. Found not to work. Test case not present in repo. ## errno @@ -276,11 +297,16 @@ The FAT32/SDCard test cases are at following locations in the source code tree: [BUILD-TESTS-GCC-20161219-1007]: https://github.com/ARMmbed/meVo/blob/master/docs/ARM_MBED/TN/ARM_MBED_TN_0017/build_tests_gcc_20161219_1007.txt [RUN-TESTS-GCC-20161219-1011]: https://github.com/ARMmbed/meVo/blob/master/docs/ARM_MBED/TN/ARM_MBED_TN_0017/run_tests_master_gcc_ex_app2_fat_basic_20161219_1011.txt +[MAN_CLEARERR]: https://linux.die.net/man/3/clearerr [MAN_FCLOSE]: https://linux.die.net/man/3/fclose [MAN_FGETS]: https://linux.die.net/man/3/fgets +[MAN_FOPEN]: https://linux.die.net/man/3/fopen +[MAN_FPRINTF]: https://linux.die.net/man/3/fprintf [MAN_FPUTS]: https://linux.die.net/man/3/fputs [MAN_FREAD]: https://linux.die.net/man/3/fread [MAN_FSEEK]: https://linux.die.net/man/3/fseek [MAN_FWRITE]: https://linux.die.net/man/3/fwrite [MAN_REMOVE]: https://linux.die.net/man/3/remove [MAN_REWIND]: https://linux.die.net/man/3/rewind +[MAN_STAT]: https://linux.die.net/man/2/stat +[MAN_FTELL]: https://linux.die.net/man/3/ftell diff --git a/features/filesystem/test/fsfat_test.c b/features/filesystem/test/fsfat_test.c index 148838c64c..9cfad02f25 100644 --- a/features/filesystem/test/fsfat_test.c +++ b/features/filesystem/test/fsfat_test.c @@ -59,41 +59,6 @@ const uint8_t fsfat_test_byte_data_table[FSFAT_TEST_BYTE_DATA_TABLE_SIZE] = { }; -/* @brief set of test data for sequential write tests */ -fsfat_test_rw_data_entry_t fsfat_test_rw_data_table[] = -{ - { 25, 'z' }, - { 00, 'a' }, - { 24, 'y' }, - { 01, 'b' }, - { 23, 'x' }, - { 02, 'c' }, - { 22, 'w' }, - { 03, 'd' }, - { 21, 'v' }, - { 04, 'e' }, - { 20, 'u' }, - { 05, 'f' }, - { 19, 't' }, - { 06, 'g' }, - { 18, 's' }, - { 07, 'h' }, - { 17, 'r' }, - { 8, 'i' }, - { 16, 'q' }, - { 9, 'j' }, - { 15, 'p' }, - { 10, 'k' }, - { 14, 'o' }, - { 11, 'l' }, - { 13, 'n' }, - { 12, 'm' }, - { FSFAT_TEST_RW_TABLE_SENTINEL, '@' }, -}; - - - - /* @brief test utility function to delete the file identified by filename */ int32_t fsfat_test_delete(const char* filename) @@ -102,41 +67,6 @@ int32_t fsfat_test_delete(const char* filename) return remove(filename); } -//todo: delete -#ifdef NOT_DEFINED - -/* @brief test utility function to delete all of the files in the filesystem - */ -int32_t fsfat_test_delete_all(void) -{ - const char* key_name_query = "*"; - char key_name[FSFAT_FILENAME_MAX_LENGTH+1]; - uint8_t len = FSFAT_FILENAME_MAX_LENGTH+1; - int32_t ret = -1; - - FSFAT_FENTRYLOG("%s:entered.\r\n", __func__); - while((ret = drv->Find(key_name_query, prev, next)) == ARM_DRIVER_OK) - { - len = FSFAT_FILENAME_MAX_LENGTH+1; - drv->GetKeyName(next, key_name, &len); - FSFAT_TP(FSFAT_TP_DELETE, "%s:deleting key_name=%s, len=%d\r\n", __func__, key_name, (int) len); - ret = drv->Delete(next); - if(ret < ARM_DRIVER_OK){ - FSFAT_ERRLOG("%s:Error: failed to delete key_name=%s, len=%d\r\n", __func__, key_name, (int) len); - return ret; - } - FSFAT_HANDLE_SWAP(prev, next); - } - if(ret == ARM_FSFAT_DRIVER_ERROR_KEY_NOT_FOUND) { - /* as expected, no more keys have been found by the Find()*/ - ret = ARM_DRIVER_OK; - } - FSFAT_FENTRYLOG("%s:exiting (ret=%d).\r\n", __func__, (int) ret); - return ret; -} - -#endif // NOT_DEFINED - /* @brief test utility function to create a file * @@ -164,221 +94,6 @@ int32_t fsfat_test_create(const char* filename, const char* data, size_t len) } -#ifdef NOT_DEFINED - -/* @brief test utility function to create KVs from the supplied table - * @note this function expects cfstore to have been initialised with - * a call to ARM_FSFAT_DRIVER::Initialize() - */ -int32_t fsfat_test_create_table(const fsfat_kv_data_t* table) -{ - int32_t ret = -1; - ARM_FSFAT_SIZE len = 0; - fsfat_kv_data_t* node = NULL; - ARM_FSFAT_KEYDESC kdesc; - - (void) node; /* suppresses warning when building release */ - FSFAT_FENTRYLOG("%s:entered.\r\n", __func__); - memset(&kdesc, 0, sizeof(kdesc)); - kdesc.drl = ARM_RETENTION_WHILE_DEVICE_ACTIVE; - while(table->key_name != NULL) - { - len = strlen(table->value); - ret = fsfat_test_create(table->key_name, table->value, &len, &kdesc); - if(ret < ARM_DRIVER_OK){ - FSFAT_ERRLOG("%s:Error: failed to create node (key_name=\"%s\", value=\"%s\")\r\n", __func__, node->key_name, node->value); - return ret; - } - table++; - } - return ret; -} - -fsfat_kv_data_t fsfat_test_init_1_data[] = { - FSFAT_INIT_1_TABLE_HEAD, - { "b", "1"}, - { "c", "12"}, - { "d", "123"}, - { "e", "1234"}, - { "g", "12345"}, - { "h", "123456"}, - { "i", "1234567"}, - { "j", "12345678"}, - { "k", "123456789"}, - { "l", "1234567890"}, - { "m", "12345678901"}, - { "n", "123456789012"}, - { "o", "1234567890123"}, - { "p", "12345678901234"}, - { "q", "123456789012345"}, - { "r", "1234567890123456"}, - { "0", "a"}, - { "01", "ab"}, - { "012", "abc"}, - { "0123", "abcd"}, - { "01234", "abcde"}, - { "012345", "abcdef"}, - { "0123456", "abcdefg"}, - { "01234567", "abcdefgh"}, - { "012345678", "abcdefghi"}, - { "0123456789", "abcdefghj"}, - { "0123456789a", "abcdefghjk"}, - { "0123456789ab", "abcdefghjkl"}, - { "0123456789abc", "abcdefghjklm"}, - { "0123456789abcd", "abcdefghjklmn"}, - { "0123456789abcde", "abcdefghjklmno"}, - { "0123456789abcdef", "abcdefghjklmnop"}, - { "0123456789abcdef0", "abcdefghjklmnopq"}, - { "0123456789abcdef01", "abcdefghjklmnopqr"}, - { "0123456789abcdef012", "abcdefghjklmnopqrs"}, - { "0123456789abcdef0123", "abcdefghjklmnopqrst"}, - { "0123456789abcdef01234", "abcdefghjklmnopqrstu"}, - { "0123456789abcdef012345", "abcdefghjklmnopqrstuv"}, - FSFAT_INIT_1_TABLE_MID_NODE, - { "0123456789abcdef01234567", "abcdefghjklmnopqrstuvwx"}, - { "0123456789abcdef012345678", "abcdefghjklmnopqrstuvwxy"}, - { "0123456789abcdef0123456789", "abcdefghjklmnopqrstuvwxyz"}, - { "0123456789abcdef0123456789a", "b"}, - { "0123456789abcdef0123456789ab", "c"}, - { "0123456789abcdef0123456789abc", "d"}, - { "0123456789abcdef0123456789abcd", "e"}, - { "0123456789abcdef0123456789abcde", "f"}, - { "0123456789abcdef0123456789abcdef", "g"}, - { "com.arm.mbed.wifi.accesspoint.essid", ""}, - { "com.arm.mbed.wifi.accesspoint.essid2", ""}, - { "yotta.your-yotta-registry-module-name.module1", ""}, - { "yotta.hello-world.animal{wobbly-dog}{foot}frontLeft", "missing"}, - { "yotta.hello-world.animal{wobbly-dog}{foot}frontRight", "present"}, - { "yotta.hello-world.animal{wobbly-dog}{foot}backLeft", "half present"}, - { "piety.demands.us.to.honour.truth.above.our.friends", "Aristotle"}, - { "basement.medicine.pavement.government.trenchcoat.off.cough.off.kid.did.when.again.alleyway.friend.cap.pen.dollarbills.ten.foot.soot.put.but.anyway.say.May.DA.kid.did.toes.bows.those.hose.nose.clothes.man.blows.well.well", "TheRollingStone" }, - FSFAT_INIT_1_TABLE_TAIL, - { NULL, NULL}, -}; - - -/* @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_FSFAT_DRIVER::Initialize() - */ -int32_t fsfat_test_init_1(void) -{ - char* read_buf = NULL; - const uint8_t key_name_max_len = FSFAT_FILENAME_MAX_LENGTH+1; - uint8_t key_name_len = 0; - char key_name_buf[FSFAT_FILENAME_MAX_LENGTH+1]; - int32_t ret = -1; - ARM_FSFAT_SIZE len = 0; - ARM_FSFAT_SIZE max_len = 0; - ARM_FSFAT_DRIVER* drv = &fsfat_driver; - fsfat_kv_data_t* node = NULL; - ARM_FSFAT_KEYDESC kdesc; - ARM_FSFAT_HANDLE_INIT(hkey); - - FSFAT_FENTRYLOG("%s:entered\r\n", __func__); - memset(&kdesc, 0, sizeof(kdesc)); - memset(key_name_buf, 0, FSFAT_FILENAME_MAX_LENGTH+1); - - /*scan for max length of value blob*/ - node = fsfat_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) { - FSFAT_ERRLOG("%s:Error: failed to allocated read buffer \r\n", __func__); - return ret; - } - kdesc.drl = ARM_RETENTION_WHILE_DEVICE_ACTIVE; - node = fsfat_test_init_1_data; - while(node->key_name != NULL) - { - FSFAT_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){ - FSFAT_ERRLOG("%s:Error: failed to create node (key_name=\"%s\", value=\"%s\")\r\n", __func__, node->key_name, node->value); - return ret; - } - - FSFAT_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){ - FSFAT_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)){ - FSFAT_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 -1; - } - /* 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){ - FSFAT_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)){ - FSFAT_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 -1; - } - 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)){ - FSFAT_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 -1; - } - /* revert FSFAT_LOG for more trace */ - FSFAT_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; -} - -/* @brief test utility function to check a particular KV exists in the - * cfstore using Find() interface - * @note this function expects cfstore to have been initialised with - * a call to ARM_FSFAT_DRIVER::Initialize() - */ -int32_t fsfat_test_kv_is_found(const char* key_name, bool* bfound) -{ - FSFAT_FENTRYLOG("%s:entered.\r\n", __func__); - int32_t ret = -1; - ARM_FSFAT_HANDLE_INIT(prev); - ARM_FSFAT_HANDLE_INIT(next); - ARM_FSFAT_DRIVER* drv = &fsfat_driver; - - FSFAT_ASSERT(bfound != NULL); - FSFAT_ASSERT(key_name != NULL); - *bfound = 0; - - ret = drv->Find(key_name, prev, next); - if(ret == ARM_DRIVER_OK){ - *bfound = 1; - FSFAT_DBGLOG("%s:Found key_name=\"%s\", about to call close.\r\n", __func__, key_name); - drv->Close(next); - } - return ret; -} - -#endif // NOT_DEFINED - /* @brief support function for generating a kv_name * @param name buffer to hold kv name * @param len length of kv name to generate @@ -400,93 +115,3 @@ int32_t fsfat_test_filename_gen(char* name, const size_t len) return 0; } -#ifdef NOT_DEFINED - - -/* @brief test utility function to read the value blob of a specified KV - * @note this function expects cfstore to have been initialised with - * a call to ARM_FSFAT_DRIVER::Initialize() - */ -int32_t fsfat_test_read(const char* key_name, char* data, ARM_FSFAT_SIZE* len) -{ - int32_t ret = -1; - ARM_FSFAT_DRIVER* drv = &fsfat_driver; - ARM_FSFAT_HANDLE_INIT(hkey); - ARM_FSFAT_FMODE flags; - - FSFAT_FENTRYLOG("%s:entered\r\n", __func__); - memset(&flags, 0, sizeof(flags)); - if(key_name == NULL) { - FSFAT_ERRLOG("%s:invalid key_name argument \r\n", __func__); - goto out0; - } - if(data == NULL) { - FSFAT_ERRLOG("%s:invalid data argument \r\n", __func__); - goto out0; - } - if(len == NULL) { - FSFAT_ERRLOG("%s:invalid len argument \r\n", __func__); - goto out0; - } - ret = drv->Open(key_name, flags, hkey); - if(ret < ARM_DRIVER_OK){ - FSFAT_ERRLOG("%s:Error: failed to open node (key_name=\"%s\")(ret=%d)\r\n", __func__, key_name, (int) ret); - goto out1; - } - ret = drv->Read(hkey, data, len); - if(ret < ARM_DRIVER_OK){ - FSFAT_ERRLOG("%s:Error: failed to read key (key_name=\"%s\"\r\n", __func__, key_name); - goto out2; - } -out2: - drv->Close(hkey); -out1: -out0: - return ret; -} - -/* @brief write the value blob of a specified KV - * @note this function expects cfstore to have been initialised with - * a call to ARM_FSFAT_DRIVER::Initialize() - */ -int32_t fsfat_test_write(const char* key_name, const char* data, ARM_FSFAT_SIZE* len) -{ - int32_t ret = -1; - ARM_FSFAT_DRIVER* drv = &fsfat_driver; - ARM_FSFAT_HANDLE_INIT(hkey); - ARM_FSFAT_FMODE flags; - - FSFAT_FENTRYLOG("%s:entered\r\n", __func__); - memset(&flags, 0, sizeof(flags)); - if(key_name == NULL) { - FSFAT_ERRLOG("%s:Error: invalid key_name argument \r\n", __func__); - goto out0; - } - if(data == NULL) { - FSFAT_ERRLOG("%s:Error: invalid data argument \r\n", __func__); - goto out0; - } - if(len == NULL) { - FSFAT_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){ - FSFAT_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){ - FSFAT_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; -} - -#endif // NOT_DEFINED - diff --git a/features/filesystem/test/fsfat_test.h b/features/filesystem/test/fsfat_test.h index c6ca5f105c..a4a6fd12fc 100644 --- a/features/filesystem/test/fsfat_test.h +++ b/features/filesystem/test/fsfat_test.h @@ -28,12 +28,10 @@ extern "C" { #endif -//#include "configuration_store.h" - /* Defines */ -#define FSFAT_INIT_1_TABLE_HEAD { "a", ""} +//#define FSFAT_INIT_1_TABLE_HEAD { "a", ""} #define FSFAT_INIT_1_TABLE_MID_NODE { "/sd/01234567.txt", "abcdefghijklmnopqrstuvwxyz"} -#define FSFAT_INIT_1_TABLE_TAIL { "/sd/fopentst/hello/world/animal/wobbly/dog/foot/backrght.txt", "present"} +//#define FSFAT_INIT_1_TABLE_TAIL { "/sd/fopentst/hello/world/animal/wobbly/dog/foot/backrght.txt", "present"} #define FSFAT_TEST_RW_TABLE_SENTINEL 0xffffffff #define FSFAT_TEST_BYTE_DATA_TABLE_SIZE 256 #define FSFAT_UTEST_MSG_BUF_SIZE 256 @@ -63,27 +61,12 @@ typedef struct fsfat_kv_data_t { const char* value; } fsfat_kv_data_t; -typedef struct fsfat_test_rw_data_entry_t -{ - uint32_t offset; - char rw_char; -} fsfat_test_rw_data_entry_t; - -extern fsfat_kv_data_t fsfat_test_init_1_data[]; -extern fsfat_test_rw_data_entry_t fsfat_test_rw_data_table[]; -extern const char* fsfat_test_opcode_str[]; extern const uint8_t fsfat_test_byte_data_table[FSFAT_TEST_BYTE_DATA_TABLE_SIZE]; int32_t fsfat_test_create(const char* filename, const char* data, size_t len); -int32_t fsfat_test_create_table(const fsfat_kv_data_t* table); int32_t fsfat_test_delete(const char* key_name); -int32_t fsfat_test_delete_all(void); -int32_t fsfat_test_filename_found(const char* key_name, bool* bfound); int32_t fsfat_test_filename_gen(char* name, const size_t len); -int32_t fsfat_test_init_1(void); -int32_t fsfat_test_read(const char* key_name, char* data, size_t* len); -int32_t fsfat_test_write(const char* key_name, const char* data, size_t* len); #ifdef __cplusplus } #endif