examples/fstest: For SPIFFS, add garbage collection and file system integrity IOCTL calls. This was to avoid running out of FLASH space while running the fstest (ENOSPC=28). However, it does not work.. still runs out of memory.
This commit is contained in:
parent
4bbfdbb9fa
commit
3ba19b0d9a
@ -40,6 +40,18 @@ config EXAMPLES_FSTEST_NLOOPS
|
|||||||
int "Number of test loops"
|
int "Number of test loops"
|
||||||
default 100
|
default 100
|
||||||
|
|
||||||
|
config EXAMPLES_FSTEST_SPIFFS
|
||||||
|
bool "Enable SPIFFS testing"
|
||||||
|
default n
|
||||||
|
depends on FS_SPIFFS
|
||||||
|
---help---
|
||||||
|
SPIFFS garbage collection and integrity checking will be performed
|
||||||
|
after a write fails with ENOSPC.
|
||||||
|
|
||||||
|
If this option is not selected then the SPIFFS FLASH will likely
|
||||||
|
become full before you finish the test.
|
||||||
|
|
||||||
|
|
||||||
config EXAMPLES_FSTEST_VERBOSE
|
config EXAMPLES_FSTEST_VERBOSE
|
||||||
bool "Verbose output"
|
bool "Verbose output"
|
||||||
default n
|
default n
|
||||||
|
@ -40,6 +40,7 @@
|
|||||||
#include <nuttx/config.h>
|
#include <nuttx/config.h>
|
||||||
|
|
||||||
#include <sys/mount.h>
|
#include <sys/mount.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@ -270,6 +271,52 @@ static void fstest_freefile(FAR struct fstest_filedesc_s *file)
|
|||||||
memset(file, 0, sizeof(struct fstest_filedesc_s));
|
memset(file, 0, sizeof(struct fstest_filedesc_s));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: fstest_gc
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifdef CONFIG_EXAMPLES_FSTEST_SPIFFS
|
||||||
|
static int fstest_gc(int fd, size_t nbytes)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
/* Perform SPIFFS garbage collection */
|
||||||
|
|
||||||
|
printf("SPIFFS Garbage Collection: %lu bytes\n", (unsigned long)nbytes);
|
||||||
|
|
||||||
|
ret = ioctl(fd, FIOC_OPTIMIZE, (unsigned long)nbytes);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
int ret2;
|
||||||
|
|
||||||
|
printf("ERROR: ioctl(FIOC_OPTIMIZE) failed: %d\n", errno);
|
||||||
|
printf("SPIFFS Integrity Test\n");
|
||||||
|
|
||||||
|
ret2 = ioctl(fd, FIOC_INTEGRITY, 0);
|
||||||
|
if (ret2 < 0)
|
||||||
|
{
|
||||||
|
printf("ERROR: ioctl(FIOC_INTEGRITY) failed: %d\n", errno);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Check the integrity of the SPIFFS file system */
|
||||||
|
|
||||||
|
printf("SPIFFS Integrity Test\n");
|
||||||
|
|
||||||
|
ret = ioctl(fd, FIOC_INTEGRITY, 0);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
printf("ERROR: ioctl(FIOC_INTEGRITY) failed: %d\n", errno);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
# define fstest_gc(f,n) (-ENOSYS)
|
||||||
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: fstest_wrfile
|
* Name: fstest_wrfile
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@ -284,6 +331,7 @@ static inline int fstest_wrfile(FAR struct fstest_filedesc_s *file)
|
|||||||
|
|
||||||
fstest_randname(file);
|
fstest_randname(file);
|
||||||
fstest_randfile(file);
|
fstest_randfile(file);
|
||||||
|
|
||||||
fd = open(file->name, O_WRONLY | O_CREAT | O_EXCL, 0666);
|
fd = open(file->name, O_WRONLY | O_CREAT | O_EXCL, 0666);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
{
|
{
|
||||||
@ -333,6 +381,18 @@ static inline int fstest_wrfile(FAR struct fstest_filedesc_s *file)
|
|||||||
printf(" Write size: %ld\n", (long)nbytestowrite);
|
printf(" Write size: %ld\n", (long)nbytestowrite);
|
||||||
ret = ERROR;
|
ret = ERROR;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int ret2;
|
||||||
|
|
||||||
|
/* Try to recover some space on the FLASH */
|
||||||
|
|
||||||
|
ret2 = fstest_gc(fd, nbytestowrite);
|
||||||
|
if (ret2 >= 0)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
@ -366,6 +426,11 @@ static inline int fstest_wrfile(FAR struct fstest_filedesc_s *file)
|
|||||||
offset += nbyteswritten;
|
offset += nbyteswritten;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Try to recover some space on the FLASH to write another file of this
|
||||||
|
* size.
|
||||||
|
*/
|
||||||
|
|
||||||
|
(void)fstest_gc(fd, file->len);
|
||||||
close(fd);
|
close(fd);
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user