From f7895ef68196e260c55e692a9f623956c60cb0b9 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 29 Sep 2018 11:52:39 -0600 Subject: [PATCH] apps/examples/fstest: Add configuration option to customize stack size. Detect when the media is full and stop writing files. Report total file size. --- examples/fstest/Kconfig | 18 ++++++- examples/fstest/Makefile | 11 ++-- examples/fstest/fstest_main.c | 99 +++++++++++++++++++++++++++-------- 3 files changed, 101 insertions(+), 27 deletions(-) diff --git a/examples/fstest/Kconfig b/examples/fstest/Kconfig index 35a9ac07d..e36668b3e 100644 --- a/examples/fstest/Kconfig +++ b/examples/fstest/Kconfig @@ -12,6 +12,22 @@ config EXAMPLES_FSTEST if EXAMPLES_FSTEST +config EXAMPLES_FSTEST_PROGNAME + string "Program name" + default "fstest" + depends on BUILD_LOADABLE + ---help--- + This is the name of the program that will be use when the NSH ELF + program is installed. + +config EXAMPLES_FSTEST_PRIORITY + int "FS test task priority" + default 100 + +config EXAMPLES_FSTEST_STACKSIZE + int "FS test stack size" + default 2048 + config EXAMPLES_FSTEST_MAXNAME int "Max name size" default 32 @@ -46,7 +62,7 @@ config EXAMPLES_FSTEST_SPIFFS depends on FS_SPIFFS && EXPERIMENTAL ---help--- SPIFFS garbage collection and integrity checking will be performed - after each pass through the test and if a write fails with ENOSPC. + after each pass through the test. If this option is not selected then the SPIFFS FLASH will be be reclaimed on-demand when there is no longer any available FLASH. diff --git a/examples/fstest/Makefile b/examples/fstest/Makefile index 75e57221e..b3803030a 100644 --- a/examples/fstest/Makefile +++ b/examples/fstest/Makefile @@ -37,9 +37,12 @@ # Generic file system stress test application info +CONFIG_EXAMPLES_FSTEST_PRIORITY ?= SCHED_PRIORITY_DEFAULT +CONFIG_EXAMPLES_FSTEST_STACKSIZE ?= 2048 + APPNAME = fstest -PRIORITY = SCHED_PRIORITY_DEFAULT -STACKSIZE = 2048 +PRIORITY = $(CONFIG_EXAMPLES_FSTEST_PRIORITY) +STACKSIZE = $(CONFIG_EXAMPLES_FSTEST_STACKSIZE) # Generic file system stress test @@ -47,8 +50,8 @@ ASRCS = CSRCS = MAINSRC = fstest_main.c -CONFIG_XYZ_PROGNAME ?= fstest$(EXEEXT) -PROGNAME = $(CONFIG_XYZ_PROGNAME) +CONFIG_EXAMPLES_FSTEST_PROGNAME ?= hello$(EXEEXT) +PROGNAME = $(CONFIG_EXAMPLES_FSTEST_PROGNAME) MODULE = CONFIG_EXAMPLES_FSTEST diff --git a/examples/fstest/fstest_main.c b/examples/fstest/fstest_main.c index d3562d1c8..8b739b88e 100644 --- a/examples/fstest/fstest_main.c +++ b/examples/fstest/fstest_main.c @@ -116,6 +116,7 @@ static const char g_mountdir[] = CONFIG_EXAMPLES_FSTEST_MOUNTPT "/"; static int g_nfiles; static int g_ndeleted; static int g_nfailed; +static bool g_media_full; static struct mallinfo g_mmbefore; static struct mallinfo g_mmprevious; @@ -433,34 +434,25 @@ static inline int fstest_wrfile(FAR struct fstest_filedesc_s *file) { int errcode = errno; - /* If the write failed because there is no space on the device, - * then don't complain. + /* If the write failed because an interrupt occurred or because there + * there is no space on the device, then don't complain. */ - if (errcode != ENOSPC) + if (errcode == EINTR) + { + continue; + } + else if (errcode == ENOSPC) + { + g_media_full = true; + } + else { printf("ERROR: Failed to write file: %d\n", errcode); printf(" File name: %s\n", file->name); printf(" File size: %d\n", file->len); printf(" Write offset: %ld\n", (long)offset); printf(" Write size: %ld\n", (long)nbytestowrite); - ret = ERROR; - } - else if (errcode == EINTR) - { - continue; - } - else - { - int ret2; - - /* Try to recover some space on the FLASH */ - - ret2 = fstest_gc_withfd(fd, nbytestowrite); - if (ret2 >= 0) - { - continue; - } } close(fd); @@ -511,6 +503,8 @@ static int fstest_fillfs(void) /* Create a file for each unused file structure */ + g_media_full = false; + for (i = 0; i < CONFIG_EXAMPLES_FSTEST_MAXOPEN; i++) { file = &g_files[i]; @@ -529,6 +523,11 @@ static int fstest_fillfs(void) printf(" Created file %s\n", file->name); #endif g_nfiles++; + + if (g_media_full) + { + break; + } } } @@ -665,6 +664,52 @@ static inline int fstest_rdfile(FAR struct fstest_filedesc_s *file) return OK; } +/**************************************************************************** + * Name: fstest_filesize + ****************************************************************************/ + +#ifdef CONFIG_HAVE_LONG_LONG +static unsigned long long fstest_filesize(void) +{ + unsigned long long bytes_used; + FAR struct fstest_filedesc_s *file; + int i; + + bytes_used = 0; + + for (i = 0; i < CONFIG_EXAMPLES_FSTEST_MAXOPEN; i++) + { + file = &g_files[i]; + if (file->name != NULL && !file->deleted) + { + bytes_used += file->len; + } + } + + return bytes_used; +} +#else +static unsigned long fstest_filesize(void) +{ + unsigned long bytes_used; + FAR struct fstest_filedesc_s *file; + int i; + + bytes_used = 0; + + for (i = 0; i < CONFIG_EXAMPLES_FSTEST_MAXOPEN; i++) + { + file = &g_files[i]; + if (file->name != NULL && !file->deleted) + { + bytes_used += file->len; + } + } + + return bytes_used; +} +#endif + /**************************************************************************** * Name: fstest_verifyfs ****************************************************************************/ @@ -707,7 +752,7 @@ static int fstest_verifyfs(void) if (file->deleted) { #if CONFIG_EXAMPLES_FSTEST_VERBOSE != 0 - printf("Succesffully read a deleted file\n"); + printf("ERROR: Successfully read a deleted file\n"); printf(" File name: %s\n", file->name); printf(" File size: %d\n", file->len); #endif @@ -719,7 +764,7 @@ static int fstest_verifyfs(void) else { #if CONFIG_EXAMPLES_FSTEST_VERBOSE != 0 - printf(" Verifed file %s\n", file->name); + printf(" Verified file %s\n", file->name); #endif } } @@ -955,6 +1000,11 @@ int fstest_main(int argc, char *argv[]) /* Directory listing */ fstest_directory(); +#ifdef CONFIG_HAVE_LONG_LONG + printf("Total file size: %llu\n", fstest_filesize()); +#else + printf("Total file size: %lu\n", fstest_filesize()); +#endif /* Verify all files written to FLASH */ @@ -994,6 +1044,11 @@ int fstest_main(int argc, char *argv[]) /* Directory listing */ fstest_directory(); +#ifdef CONFIG_HAVE_LONG_LONG + printf("Total file size: %llu\n", fstest_filesize()); +#else + printf("Total file size: %lu\n", fstest_filesize()); +#endif /* Verify all files written to FLASH */