diff --git a/src/test/params_test.h b/src/test/params_test.h index 43f3012..36a8205 100644 --- a/src/test/params_test.h +++ b/src/test/params_test.h @@ -8,27 +8,52 @@ #ifndef PARAMS_TEST_H_ #define PARAMS_TEST_H_ -// total emulated spi flash size +//////////////// TEST PARAMS //////////////// + +// default test total emulated spi flash size #define PHYS_FLASH_SIZE (16*1024*1024) -// spiffs file system size +// default test spiffs file system size #define SPIFFS_FLASH_SIZE (2*1024*1024) -// spiffs file system offset in emulated spi flash +// default test spiffs file system offset in emulated spi flash #define SPIFFS_PHYS_ADDR (4*1024*1024) +// default test sector size +#define SECTOR_SIZE 65536 +// default test logical block size +#define LOG_BLOCK (SECTOR_SIZE*2) +// default test logical page size +#define LOG_PAGE (SECTOR_SIZE/256) +// default test number of filedescs +#define DEFAULT_NUM_FD 8 +// default test number of cache pages +#define DEFAULT_NUM_CACHE_PAGES 8 + +// When testing, test bench create reference files for comparison on +// the actual hard drive. By default, put these on ram drive for speed. +#define TEST_PATH "/dev/shm/spiffs/test-data/" + +#define ASSERT(c, m) real_assert((c),(m), __FILE__, __LINE__); +void real_assert(int c, const char *n, const char *file, int l); + +/////////// SPIFFS BUILD CONFIG //////////// // test using filesystem magic #define SPIFFS_USE_MAGIC 1 // test using filesystem magic length #define SPIFFS_USE_MAGIC_LENGTH 1 +// test using extra param in callback +#define SPIFFS_HAL_CALLBACK_EXTRA 1 +// test using filehandle offset +#define SPIFFS_FILEHDL_OFFSET 1 +// use this offset +#define TEST_SPIFFS_FILEHDL_OFFSET 0x1000 -#define SECTOR_SIZE 65536 -#define LOG_BLOCK (SECTOR_SIZE*2) -#define LOG_PAGE (SECTOR_SIZE/256) - -#define DEFAULT_NUM_FD 8 -#define DEFAULT_NUM_CACHE_PAGES 8 - -#define ASSERT(c, m) real_assert((c),(m), __FILE__, __LINE__); +// dbg output +#define SPIFFS_DBG(...) //printf(__VA_ARGS__) +#define SPIFFS_GC_DBG(...) //printf(__VA_ARGS__) +#define SPIFFS_CACHE_DBG(...) //printf(__VA_ARGS__) +#define SPIFFS_CHECK_DBG(...) //printf(__VA_ARGS__) +// needed types typedef signed int s32_t; typedef unsigned int u32_t; typedef signed short s16_t; @@ -36,22 +61,4 @@ typedef unsigned short u16_t; typedef signed char s8_t; typedef unsigned char u8_t; -#define SPIFFS_DBG(...) //printf(__VA_ARGS__) -#define SPIFFS_GC_DBG(...) //printf(__VA_ARGS__) -#define SPIFFS_CACHE_DBG(...) //printf(__VA_ARGS__) -#define SPIFFS_CHECK_DBG(...) //printf(__VA_ARGS__) - -#ifndef SPIFFS_HAL_CALLBACK_EXTRA -#define SPIFFS_HAL_CALLBACK_EXTRA 1 -#endif - -#define SPIFFS_FILEHDL_OFFSET 1 -#if SPIFFS_FILEHDL_OFFSET -#define TEST_SPIFFS_FILEHDL_OFFSET 0x1000 -#endif - -// Enable/disable - -void real_assert(int c, const char *n, const char *file, int l); - #endif /* PARAMS_TEST_H_ */ diff --git a/src/test/test_spiffs.c b/src/test/test_spiffs.c index 894c24e..78028a4 100644 --- a/src/test/test_spiffs.c +++ b/src/test/test_spiffs.c @@ -23,6 +23,7 @@ #include #include #include +#include #define AREA(x) _area[(x) - addr_offset] @@ -52,13 +53,75 @@ static u32_t _cache_sz; static int check_valid_flash = 1; -#define TEST_PATH "test_data/" +#ifndef TEST_PATH +#define TEST_PATH "/dev/shm/spiffs/test-data/" +#endif + +// taken from http://stackoverflow.com/questions/675039/how-can-i-create-directory-tree-in-c-linux +// thanks Jonathan Leffler + +static int do_mkdir(const char *path, mode_t mode) +{ + struct stat st; + int status = 0; + + if (stat(path, &st) != 0) { + /* Directory does not exist. EEXIST for race condition */ + if (mkdir(path, mode) != 0 && errno != EEXIST) { + status = -1; + } + } else if (!S_ISDIR(st.st_mode)) { + errno = ENOTDIR; + status = -1; + } + + return status; +} + +/** +** mkpath - ensure all directories in path exist +** Algorithm takes the pessimistic view and works top-down to ensure +** each directory in path exists, rather than optimistically creating +** the last element and working backwards. +*/ +static int mkpath(const char *path, mode_t mode) { + char *pp; + char *sp; + int status; + char *copypath = strdup(path); + + status = 0; + pp = copypath; + while (status == 0 && (sp = strchr(pp, '/')) != 0) { + if (sp != pp) { + /* Neither root nor double slash in path */ + *sp = '\0'; + status = do_mkdir(copypath, mode); + *sp = '/'; + } + pp = sp + 1; + } + if (status == 0) { + status = do_mkdir(path, mode); + } + free(copypath); + return status; +} + +// end take char *make_test_fname(const char *name) { - sprintf(_path, "%s%s", TEST_PATH, name); + sprintf(_path, "%s/%s", TEST_PATH, name); return _path; } +void create_test_path(void) { + if (mkpath(TEST_PATH, 0755)) { + printf("could not create path %s\n", TEST_PATH); + exit(1); + } +} + void clear_test_path() { DIR *dp; struct dirent *ep; @@ -67,7 +130,7 @@ void clear_test_path() { if (dp != NULL) { while ((ep = readdir(dp))) { if (ep->d_name[0] != '.') { - sprintf(_path, "%s%s", TEST_PATH, ep->d_name); + sprintf(_path, "%s/%s", TEST_PATH, ep->d_name); remove(_path); } } @@ -640,6 +703,7 @@ static u32_t cmiss_tot = 0; #endif void _setup_test_only() { + create_test_path(); fs_set_validate_flashing(1); test_init(test_on_stop); }