fstest:support fstest can run many times

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
This commit is contained in:
anjiahao 2022-05-31 16:52:04 +08:00 committed by Xiang Xiao
parent 5e3a3dae10
commit 99629e9b5f

View File

@ -99,18 +99,18 @@ struct fstest_filedesc_s
/* Pre-allocated simulated flash */ /* Pre-allocated simulated flash */
static uint8_t g_fileimage[CONFIG_TESTING_FSTEST_MAXFILE]; struct fstest_ctx_s
static struct fstest_filedesc_s g_files[CONFIG_TESTING_FSTEST_MAXOPEN]; {
static char g_mountdir[CONFIG_TESTING_FSTEST_MAXNAME] = uint8_t fileimage[CONFIG_TESTING_FSTEST_MAXFILE];
CONFIG_TESTING_FSTEST_MOUNTPT "/"; struct fstest_filedesc_s files[CONFIG_TESTING_FSTEST_MAXOPEN];
static int g_nfiles; char mountdir[CONFIG_TESTING_FSTEST_MAXNAME];
static int g_ndeleted; int nfiles;
static int g_nfailed; int ndeleted;
int nfailed;
static struct mallinfo g_mmbefore; struct mallinfo mmbefore;
static struct mallinfo g_mmprevious; struct mallinfo mmprevious;
static struct mallinfo g_mmafter; struct mallinfo mmafter;
};
/**************************************************************************** /****************************************************************************
* Private Functions * Private Functions
****************************************************************************/ ****************************************************************************/
@ -140,32 +140,32 @@ static void fstest_showmemusage(struct mallinfo *mmbefore,
* Name: fstest_loopmemusage * Name: fstest_loopmemusage
****************************************************************************/ ****************************************************************************/
static void fstest_loopmemusage(void) static void fstest_loopmemusage(FAR struct fstest_ctx_s *ctx)
{ {
/* Get the current memory usage */ /* Get the current memory usage */
g_mmafter = mallinfo(); ctx->mmafter = mallinfo();
/* Show the change from the previous loop */ /* Show the change from the previous loop */
printf("\nEnd of loop memory usage:\n"); printf("\nEnd of loop memory usage:\n");
fstest_showmemusage(&g_mmprevious, &g_mmafter); fstest_showmemusage(&ctx->mmprevious, &ctx->mmafter);
/* Set up for the next test */ /* Set up for the next test */
g_mmprevious = g_mmafter; ctx->mmprevious = ctx->mmafter;
} }
/**************************************************************************** /****************************************************************************
* Name: fstest_endmemusage * Name: fstest_endmemusage
****************************************************************************/ ****************************************************************************/
static void fstest_endmemusage(void) static void fstest_endmemusage(FAR struct fstest_ctx_s *ctx)
{ {
g_mmafter = mallinfo(); ctx->mmafter = mallinfo();
printf("\nFinal memory usage:\n"); printf("\nFinal memory usage:\n");
fstest_showmemusage(&g_mmbefore, &g_mmafter); fstest_showmemusage(&ctx->mmbefore, &ctx->mmafter);
} }
/**************************************************************************** /****************************************************************************
@ -197,15 +197,16 @@ static inline char fstest_randchar(void)
* Name: fstest_checkexist * Name: fstest_checkexist
****************************************************************************/ ****************************************************************************/
static bool fstest_checkexist(FAR struct fstest_filedesc_s *file) static bool fstest_checkexist(FAR struct fstest_ctx_s *ctx,
FAR struct fstest_filedesc_s *file)
{ {
int i; int i;
bool ret = false; bool ret = false;
for (i = 0; i < CONFIG_TESTING_FSTEST_MAXOPEN; i++) for (i = 0; i < CONFIG_TESTING_FSTEST_MAXOPEN; i++)
{ {
if (&g_files[i] != file && g_files[i].name && if (&ctx->files[i] != file && ctx->files[i].name &&
strcmp(g_files[i].name, file->name) == 0) strcmp(ctx->files[i].name, file->name) == 0)
{ {
ret = true; ret = true;
break; break;
@ -219,7 +220,8 @@ static bool fstest_checkexist(FAR struct fstest_filedesc_s *file)
* Name: fstest_randname * Name: fstest_randname
****************************************************************************/ ****************************************************************************/
static inline void fstest_randname(FAR struct fstest_filedesc_s *file) static inline void fstest_randname(FAR struct fstest_ctx_s *ctx,
FAR struct fstest_filedesc_s *file)
{ {
int dirlen; int dirlen;
int maxname; int maxname;
@ -227,7 +229,7 @@ static inline void fstest_randname(FAR struct fstest_filedesc_s *file)
int alloclen; int alloclen;
int i; int i;
dirlen = strlen(g_mountdir); dirlen = strlen(ctx->mountdir);
/* Force the max filename lengh and also the min name len = 4 */ /* Force the max filename lengh and also the min name len = 4 */
@ -243,7 +245,7 @@ static inline void fstest_randname(FAR struct fstest_filedesc_s *file)
exit(5); exit(5);
} }
memcpy(file->name, g_mountdir, dirlen); memcpy(file->name, ctx->mountdir, dirlen);
do do
{ {
@ -254,24 +256,25 @@ static inline void fstest_randname(FAR struct fstest_filedesc_s *file)
file->name[alloclen] = '\0'; file->name[alloclen] = '\0';
} }
while (fstest_checkexist(file)); while (fstest_checkexist(ctx, file));
} }
/**************************************************************************** /****************************************************************************
* Name: fstest_randfile * Name: fstest_randfile
****************************************************************************/ ****************************************************************************/
static inline void fstest_randfile(FAR struct fstest_filedesc_s *file) static inline void fstest_randfile(FAR struct fstest_ctx_s *ctx,
FAR struct fstest_filedesc_s *file)
{ {
int i; int i;
file->len = (rand() % CONFIG_TESTING_FSTEST_MAXFILE) + 1; file->len = (rand() % CONFIG_TESTING_FSTEST_MAXFILE) + 1;
for (i = 0; i < file->len; i++) for (i = 0; i < file->len; i++)
{ {
g_fileimage[i] = fstest_randchar(); ctx->fileimage[i] = fstest_randchar();
} }
file->crc = crc32(g_fileimage, file->len); file->crc = crc32(ctx->fileimage, file->len);
} }
/**************************************************************************** /****************************************************************************
@ -356,7 +359,7 @@ static int fstest_gc_withfd(int fd, size_t nbytes)
return ret; return ret;
} }
static int fstest_gc(size_t nbytes) static int fstest_gc(FAR struct fstest_ctx_s *ctx, size_t nbytes)
{ {
FAR struct fstest_filedesc_s *file; FAR struct fstest_filedesc_s *file;
int ret = OK; int ret = OK;
@ -367,7 +370,7 @@ static int fstest_gc(size_t nbytes)
for (i = 0; i < CONFIG_TESTING_FSTEST_MAXOPEN; i++) for (i = 0; i < CONFIG_TESTING_FSTEST_MAXOPEN; i++)
{ {
file = &g_files[i]; file = &ctx->files[i];
if (file->name != NULL && !file->deleted) if (file->name != NULL && !file->deleted)
{ {
/* Open the file for reading */ /* Open the file for reading */
@ -401,7 +404,8 @@ static int fstest_gc(size_t nbytes)
* Name: fstest_wrfile * Name: fstest_wrfile
****************************************************************************/ ****************************************************************************/
static inline int fstest_wrfile(FAR struct fstest_filedesc_s *file) static inline int fstest_wrfile(FAR struct fstest_ctx_s *ctx,
FAR struct fstest_filedesc_s *file)
{ {
size_t offset; size_t offset;
int fd; int fd;
@ -409,8 +413,8 @@ static inline int fstest_wrfile(FAR struct fstest_filedesc_s *file)
/* Create a random file */ /* Create a random file */
fstest_randname(file); fstest_randname(ctx, file);
fstest_randfile(file); fstest_randfile(ctx, file);
fd = open(file->name, O_WRONLY | O_CREAT | O_EXCL | O_TRUNC, 0666); fd = open(file->name, O_WRONLY | O_CREAT | O_EXCL | O_TRUNC, 0666);
if (fd < 0) if (fd < 0)
@ -443,7 +447,7 @@ static inline int fstest_wrfile(FAR struct fstest_filedesc_s *file)
nbytestowrite = maxio; nbytestowrite = maxio;
} }
nbyteswritten = write(fd, &g_fileimage[offset], nbytestowrite); nbyteswritten = write(fd, &ctx->fileimage[offset], nbytestowrite);
if (nbyteswritten < 0) if (nbyteswritten < 0)
{ {
int errcode = errno; int errcode = errno;
@ -505,7 +509,7 @@ static inline int fstest_wrfile(FAR struct fstest_filedesc_s *file)
* Name: fstest_fillfs * Name: fstest_fillfs
****************************************************************************/ ****************************************************************************/
static int fstest_fillfs(void) static int fstest_fillfs(FAR struct fstest_ctx_s *ctx)
{ {
FAR struct fstest_filedesc_s *file; FAR struct fstest_filedesc_s *file;
int ret; int ret;
@ -515,10 +519,10 @@ static int fstest_fillfs(void)
for (i = 0; i < CONFIG_TESTING_FSTEST_MAXOPEN; i++) for (i = 0; i < CONFIG_TESTING_FSTEST_MAXOPEN; i++)
{ {
file = &g_files[i]; file = &ctx->files[i];
if (file->name == NULL) if (file->name == NULL)
{ {
ret = fstest_wrfile(file); ret = fstest_wrfile(ctx, file);
if (ret < 0) if (ret < 0)
{ {
#if CONFIG_TESTING_FSTEST_VERBOSE != 0 #if CONFIG_TESTING_FSTEST_VERBOSE != 0
@ -530,7 +534,7 @@ static int fstest_fillfs(void)
#if CONFIG_TESTING_FSTEST_VERBOSE != 0 #if CONFIG_TESTING_FSTEST_VERBOSE != 0
printf(" Created file %s\n", file->name); printf(" Created file %s\n", file->name);
#endif #endif
g_nfiles++; ctx->nfiles++;
} }
} }
@ -541,7 +545,8 @@ static int fstest_fillfs(void)
* Name: fstest_rdblock * Name: fstest_rdblock
****************************************************************************/ ****************************************************************************/
static ssize_t fstest_rdblock(int fd, FAR struct fstest_filedesc_s *file, static ssize_t fstest_rdblock(FAR struct fstest_ctx_s *ctx, int fd,
FAR struct fstest_filedesc_s *file,
size_t offset, size_t len) size_t offset, size_t len)
{ {
size_t maxio = (rand() % CONFIG_TESTING_FSTEST_MAXIO) + 1; size_t maxio = (rand() % CONFIG_TESTING_FSTEST_MAXIO) + 1;
@ -554,7 +559,7 @@ static ssize_t fstest_rdblock(int fd, FAR struct fstest_filedesc_s *file,
for (; ; ) for (; ; )
{ {
nbytesread = read(fd, &g_fileimage[offset], len); nbytesread = read(fd, &ctx->fileimage[offset], len);
if (nbytesread < 0) if (nbytesread < 0)
{ {
int errcode = errno; int errcode = errno;
@ -602,7 +607,8 @@ static ssize_t fstest_rdblock(int fd, FAR struct fstest_filedesc_s *file,
* Name: fstest_rdfile * Name: fstest_rdfile
****************************************************************************/ ****************************************************************************/
static inline int fstest_rdfile(FAR struct fstest_filedesc_s *file) static inline int fstest_rdfile(FAR struct fstest_ctx_s *ctx,
FAR struct fstest_filedesc_s *file)
{ {
size_t ntotalread; size_t ntotalread;
ssize_t nbytesread; ssize_t nbytesread;
@ -630,7 +636,7 @@ static inline int fstest_rdfile(FAR struct fstest_filedesc_s *file)
for (ntotalread = 0; ntotalread < file->len; ) for (ntotalread = 0; ntotalread < file->len; )
{ {
nbytesread = fstest_rdblock(fd, file, ntotalread, nbytesread = fstest_rdblock(ctx, fd, file, ntotalread,
file->len - ntotalread); file->len - ntotalread);
if (nbytesread < 0) if (nbytesread < 0)
{ {
@ -643,7 +649,7 @@ static inline int fstest_rdfile(FAR struct fstest_filedesc_s *file)
/* Verify the file image CRC */ /* Verify the file image CRC */
crc = crc32(g_fileimage, file->len); crc = crc32(ctx->fileimage, file->len);
if (crc != file->crc) if (crc != file->crc)
{ {
printf("ERROR: Bad CRC: %" PRId32 " vs %" PRId32 "\n", crc, file->crc); printf("ERROR: Bad CRC: %" PRId32 " vs %" PRId32 "\n", crc, file->crc);
@ -655,7 +661,7 @@ static inline int fstest_rdfile(FAR struct fstest_filedesc_s *file)
/* Try reading past the end of the file */ /* Try reading past the end of the file */
nbytesread = fstest_rdblock(fd, file, ntotalread, 1024); nbytesread = fstest_rdblock(ctx, fd, file, ntotalread, 1024);
if (nbytesread > 0) if (nbytesread > 0)
{ {
printf("ERROR: Read past the end of file\n"); printf("ERROR: Read past the end of file\n");
@ -675,7 +681,7 @@ static inline int fstest_rdfile(FAR struct fstest_filedesc_s *file)
****************************************************************************/ ****************************************************************************/
#ifdef CONFIG_HAVE_LONG_LONG #ifdef CONFIG_HAVE_LONG_LONG
static unsigned long long fstest_filesize(void) static unsigned long long fstest_filesize(FAR struct fstest_ctx_s *ctx)
{ {
unsigned long long bytes_used; unsigned long long bytes_used;
FAR struct fstest_filedesc_s *file; FAR struct fstest_filedesc_s *file;
@ -685,7 +691,7 @@ static unsigned long long fstest_filesize(void)
for (i = 0; i < CONFIG_TESTING_FSTEST_MAXOPEN; i++) for (i = 0; i < CONFIG_TESTING_FSTEST_MAXOPEN; i++)
{ {
file = &g_files[i]; file = &ctx->files[i];
if (file->name != NULL && !file->deleted) if (file->name != NULL && !file->deleted)
{ {
bytes_used += file->len; bytes_used += file->len;
@ -695,7 +701,7 @@ static unsigned long long fstest_filesize(void)
return bytes_used; return bytes_used;
} }
#else #else
static unsigned long fstest_filesize(void) static unsigned long fstest_filesize(FAR struct fstest_ctx_s *ctx)
{ {
unsigned long bytes_used; unsigned long bytes_used;
FAR struct fstest_filedesc_s *file; FAR struct fstest_filedesc_s *file;
@ -705,7 +711,7 @@ static unsigned long fstest_filesize(void)
for (i = 0; i < CONFIG_TESTING_FSTEST_MAXOPEN; i++) for (i = 0; i < CONFIG_TESTING_FSTEST_MAXOPEN; i++)
{ {
file = &g_files[i]; file = &ctx->files[i];
if (file->name != NULL && !file->deleted) if (file->name != NULL && !file->deleted)
{ {
bytes_used += file->len; bytes_used += file->len;
@ -720,7 +726,7 @@ static unsigned long fstest_filesize(void)
* Name: fstest_verifyfs * Name: fstest_verifyfs
****************************************************************************/ ****************************************************************************/
static int fstest_verifyfs(void) static int fstest_verifyfs(FAR struct fstest_ctx_s *ctx)
{ {
FAR struct fstest_filedesc_s *file; FAR struct fstest_filedesc_s *file;
int ret; int ret;
@ -730,10 +736,10 @@ static int fstest_verifyfs(void)
for (i = 0; i < CONFIG_TESTING_FSTEST_MAXOPEN; i++) for (i = 0; i < CONFIG_TESTING_FSTEST_MAXOPEN; i++)
{ {
file = &g_files[i]; file = &ctx->files[i];
if (file->name != NULL) if (file->name != NULL)
{ {
ret = fstest_rdfile(file); ret = fstest_rdfile(ctx, file);
if (ret < 0) if (ret < 0)
{ {
if (file->deleted) if (file->deleted)
@ -742,8 +748,8 @@ static int fstest_verifyfs(void)
printf("Deleted file %d OK\n", i); printf("Deleted file %d OK\n", i);
#endif #endif
fstest_freefile(file); fstest_freefile(file);
g_ndeleted--; ctx->ndeleted--;
g_nfiles--; ctx->nfiles--;
} }
else else
{ {
@ -763,8 +769,8 @@ static int fstest_verifyfs(void)
printf(" File size: %zd\n", file->len); printf(" File size: %zd\n", file->len);
#endif #endif
fstest_freefile(file); fstest_freefile(file);
g_ndeleted--; ctx->ndeleted--;
g_nfiles--; ctx->nfiles--;
return ERROR; return ERROR;
} }
else else
@ -784,7 +790,7 @@ static int fstest_verifyfs(void)
* Name: fstest_delfiles * Name: fstest_delfiles
****************************************************************************/ ****************************************************************************/
static int fstest_delfiles(void) static int fstest_delfiles(FAR struct fstest_ctx_s *ctx)
{ {
FAR struct fstest_filedesc_s *file; FAR struct fstest_filedesc_s *file;
int ndel; int ndel;
@ -794,7 +800,7 @@ static int fstest_delfiles(void)
/* Are there any files to be deleted? */ /* Are there any files to be deleted? */
int nfiles = g_nfiles - g_ndeleted - g_nfailed; int nfiles = ctx->nfiles - ctx->ndeleted - ctx->nfailed;
if (nfiles <= 1) if (nfiles <= 1)
{ {
return 0; return 0;
@ -810,7 +816,7 @@ static int fstest_delfiles(void)
{ {
/* Guess a file index */ /* Guess a file index */
int ndx = (rand() % (g_nfiles - g_ndeleted)); int ndx = (rand() % (ctx->nfiles - ctx->ndeleted));
/* And delete the next undeleted file after that random index. NOTE /* And delete the next undeleted file after that random index. NOTE
* that the entry at ndx is not checked. * that the entry at ndx is not checked.
@ -825,7 +831,7 @@ static int fstest_delfiles(void)
j = 0; j = 0;
} }
file = &g_files[j]; file = &ctx->files[j];
if (file->name && !file->deleted) if (file->name && !file->deleted)
{ {
ret = unlink(file->name); ret = unlink(file->name);
@ -841,7 +847,7 @@ static int fstest_delfiles(void)
*/ */
file->failed = true; file->failed = true;
g_nfailed++; ctx->nfailed++;
nfiles--; nfiles--;
if (nfiles < 1) if (nfiles < 1)
@ -855,7 +861,7 @@ static int fstest_delfiles(void)
printf(" Deleted file %s\n", file->name); printf(" Deleted file %s\n", file->name);
#endif #endif
file->deleted = true; file->deleted = true;
g_ndeleted++; ctx->ndeleted++;
break; break;
} }
} }
@ -869,7 +875,7 @@ static int fstest_delfiles(void)
* Name: fstest_delallfiles * Name: fstest_delallfiles
****************************************************************************/ ****************************************************************************/
static int fstest_delallfiles(void) static int fstest_delallfiles(FAR struct fstest_ctx_s *ctx)
{ {
FAR struct fstest_filedesc_s *file; FAR struct fstest_filedesc_s *file;
int ret; int ret;
@ -877,7 +883,7 @@ static int fstest_delallfiles(void)
for (i = 0; i < CONFIG_TESTING_FSTEST_MAXOPEN; i++) for (i = 0; i < CONFIG_TESTING_FSTEST_MAXOPEN; i++)
{ {
file = &g_files[i]; file = &ctx->files[i];
if (file->name) if (file->name)
{ {
ret = unlink(file->name); ret = unlink(file->name);
@ -898,9 +904,9 @@ static int fstest_delallfiles(void)
} }
} }
g_nfiles = 0; ctx->nfiles = 0;
g_nfailed = 0; ctx->nfailed = 0;
g_ndeleted = 0; ctx->ndeleted = 0;
return OK; return OK;
} }
@ -908,7 +914,7 @@ static int fstest_delallfiles(void)
* Name: fstest_directory * Name: fstest_directory
****************************************************************************/ ****************************************************************************/
static int fstest_directory(void) static int fstest_directory(FAR struct fstest_ctx_s *ctx)
{ {
DIR *dirp; DIR *dirp;
FAR struct dirent *entryp; FAR struct dirent *entryp;
@ -916,14 +922,14 @@ static int fstest_directory(void)
/* Open the directory */ /* Open the directory */
dirp = opendir(g_mountdir); dirp = opendir(ctx->mountdir);
if (!dirp) if (!dirp)
{ {
/* Failed to open the directory */ /* Failed to open the directory */
printf("ERROR: Failed to open directory '%s': %d\n", printf("ERROR: Failed to open directory '%s': %d\n",
g_mountdir, errno); ctx->mountdir, errno);
return ERROR; return ERROR;
} }
@ -973,17 +979,27 @@ static void show_useage(void)
int main(int argc, FAR char *argv[]) int main(int argc, FAR char *argv[])
{ {
FAR struct fstest_ctx_s *ctx;
struct statfs buf; struct statfs buf;
unsigned int i; unsigned int i;
int ret; int ret;
int loop_num; int loop_num;
int option; int option;
ctx = malloc(sizeof(struct fstest_ctx_s));
if (ctx == NULL)
{
printf("malloc ctx feild,exit!\n");
exit(1);
}
memset(ctx, 0, sizeof(struct fstest_ctx_s));
/* Seed the random number generated */ /* Seed the random number generated */
srand(0x93846); srand(0x93846);
loop_num = CONFIG_TESTING_FSTEST_NLOOPS; loop_num = CONFIG_TESTING_FSTEST_NLOOPS;
strcpy(g_mountdir, CONFIG_TESTING_FSTEST_MOUNTPT); strcpy(ctx->mountdir, CONFIG_TESTING_FSTEST_MOUNTPT);
/* Opt Parse */ /* Opt Parse */
@ -992,32 +1008,35 @@ int main(int argc, FAR char *argv[])
switch (option) switch (option)
{ {
case 'm': case 'm':
strcpy(g_mountdir, optarg); strcpy(ctx->mountdir, optarg);
break; break;
case 'h': case 'h':
show_useage(); show_useage();
free(ctx);
exit(0); exit(0);
case 'n': case 'n':
loop_num = atoi(optarg); loop_num = atoi(optarg);
break; break;
case ':': case ':':
printf("Error: Missing required argument\n"); printf("Error: Missing required argument\n");
free(ctx);
exit(1); exit(1);
case '?': case '?':
printf("Error: Unrecognized option\n"); printf("Error: Unrecognized option\n");
free(ctx);
exit(1); exit(1);
} }
} }
if (g_mountdir[strlen(g_mountdir)-1] != '/') if (ctx->mountdir[strlen(ctx->mountdir)-1] != '/')
{ {
strcat(g_mountdir, "/"); strcat(ctx->mountdir, "/");
} }
/* Set up memory monitoring */ /* Set up memory monitoring */
g_mmbefore = mallinfo(); ctx->mmbefore = mallinfo();
g_mmprevious = g_mmbefore; ctx->mmprevious = ctx->mmbefore;
/* Loop a few times ... file the file system with some random, files, /* Loop a few times ... file the file system with some random, files,
* delete some files randomly, fill the file system with more random file, * delete some files randomly, fill the file system with more random file,
@ -1036,91 +1055,95 @@ int main(int argc, FAR char *argv[])
*/ */
printf("\n=== FILLING %u =============================\n", i); printf("\n=== FILLING %u =============================\n", i);
fstest_fillfs(); fstest_fillfs(ctx);
printf("Filled file system\n"); printf("Filled file system\n");
printf(" Number of files: %d\n", g_nfiles); printf(" Number of files: %d\n", ctx->nfiles);
printf(" Number deleted: %d\n", g_ndeleted); printf(" Number deleted: %d\n", ctx->ndeleted);
/* Directory listing */ /* Directory listing */
fstest_directory(); fstest_directory(ctx);
#ifdef CONFIG_HAVE_LONG_LONG #ifdef CONFIG_HAVE_LONG_LONG
printf("Total file size: %llu\n", fstest_filesize()); printf("Total file size: %llu\n", fstest_filesize(ctx));
#else #else
printf("Total file size: %lu\n", fstest_filesize()); printf("Total file size: %lu\n", fstest_filesize(ctx));
#endif #endif
/* Verify all files written to FLASH */ /* Verify all files written to FLASH */
ret = fstest_verifyfs(); ret = fstest_verifyfs(ctx);
if (ret < 0) if (ret < 0)
{ {
printf("ERROR: Failed to verify files\n"); printf("ERROR: Failed to verify files\n");
printf(" Number of files: %d\n", g_nfiles); printf(" Number of files: %d\n", ctx->nfiles);
printf(" Number deleted: %d\n", g_ndeleted); printf(" Number deleted: %d\n", ctx->ndeleted);
free(ctx);
exit(ret); exit(ret);
} }
else else
{ {
#if CONFIG_TESTING_FSTEST_VERBOSE != 0 #if CONFIG_TESTING_FSTEST_VERBOSE != 0
printf("Verified!\n"); printf("Verified!\n");
printf(" Number of files: %d\n", g_nfiles); printf(" Number of files: %d\n", ctx->nfiles);
printf(" Number deleted: %d\n", g_ndeleted); printf(" Number deleted: %d\n", ctx->ndeleted);
#endif #endif
} }
/* Delete some files */ /* Delete some files */
printf("\n=== DELETING %u ============================\n", i); printf("\n=== DELETING %u ============================\n", i);
ret = fstest_delfiles(); ret = fstest_delfiles(ctx);
if (ret < 0) if (ret < 0)
{ {
printf("ERROR: Failed to delete files\n"); printf("ERROR: Failed to delete files\n");
printf(" Number of files: %d\n", g_nfiles); printf(" Number of files: %d\n", ctx->nfiles);
printf(" Number deleted: %d\n", g_ndeleted); printf(" Number deleted: %d\n", ctx->ndeleted);
free(ctx);
exit(ret); exit(ret);
} }
else else
{ {
printf("Deleted some files\n"); printf("Deleted some files\n");
printf(" Number of files: %d\n", g_nfiles); printf(" Number of files: %d\n", ctx->nfiles);
printf(" Number deleted: %d\n", g_ndeleted); printf(" Number deleted: %d\n", ctx->ndeleted);
} }
/* Directory listing */ /* Directory listing */
fstest_directory(); fstest_directory(ctx);
#ifdef CONFIG_HAVE_LONG_LONG #ifdef CONFIG_HAVE_LONG_LONG
printf("Total file size: %llu\n", fstest_filesize()); printf("Total file size: %llu\n", fstest_filesize(ctx));
#else #else
printf("Total file size: %lu\n", fstest_filesize()); printf("Total file size: %lu\n", fstest_filesize(ctx));
#endif #endif
/* Verify all files written to FLASH */ /* Verify all files written to FLASH */
ret = fstest_verifyfs(); ret = fstest_verifyfs(ctx);
if (ret < 0) if (ret < 0)
{ {
printf("ERROR: Failed to verify files\n"); printf("ERROR: Failed to verify files\n");
printf(" Number of files: %d\n", g_nfiles); printf(" Number of files: %d\n", ctx->nfiles);
printf(" Number deleted: %d\n", g_ndeleted); printf(" Number deleted: %d\n", ctx->ndeleted);
free(ctx);
exit(ret); exit(ret);
} }
else else
{ {
#if CONFIG_TESTING_FSTEST_VERBOSE != 0 #if CONFIG_TESTING_FSTEST_VERBOSE != 0
printf("Verified!\n"); printf("Verified!\n");
printf(" Number of files: %d\n", g_nfiles); printf(" Number of files: %d\n", ctx->nfiles);
printf(" Number deleted: %d\n", g_ndeleted); printf(" Number deleted: %d\n", ctx->ndeleted);
#endif #endif
} }
/* Show file system usage */ /* Show file system usage */
ret = statfs(g_mountdir, &buf); ret = statfs(ctx->mountdir, &buf);
if (ret < 0) if (ret < 0)
{ {
printf("ERROR: statfs failed: %d\n", errno); printf("ERROR: statfs failed: %d\n", errno);
free(ctx);
exit(ret); exit(ret);
} }
else else
@ -1141,14 +1164,15 @@ int main(int argc, FAR char *argv[])
/* Show memory usage */ /* Show memory usage */
fstest_loopmemusage(); fstest_loopmemusage(ctx);
fflush(stdout); fflush(stdout);
} }
/* Delete all files then show memory usage again */ /* Delete all files then show memory usage again */
fstest_delallfiles(); fstest_delallfiles(ctx);
fstest_endmemusage(); fstest_endmemusage(ctx);
fflush(stdout); fflush(stdout);
free(ctx);
return 0; return 0;
} }