app/fstest: config the number of open file and the maximum size of file

adjust resource using on resource-constrained systems

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
This commit is contained in:
dongjiuzhu1 2022-12-12 19:58:47 +08:00 committed by Xiang Xiao
parent 30efeb7424
commit 2e0c1c1ddb

View File

@ -77,12 +77,14 @@ struct fstest_filedesc_s
struct fstest_ctx_s
{
uint8_t fileimage[CONFIG_TESTING_FSTEST_MAXFILE];
struct fstest_filedesc_s files[CONFIG_TESTING_FSTEST_MAXOPEN];
FAR uint8_t *fileimage;
FAR struct fstest_filedesc_s *files;
char mountdir[CONFIG_TESTING_FSTEST_MAXNAME];
int nfiles;
int ndeleted;
int nfailed;
int max_file;
int max_open;
struct mallinfo mmbefore;
struct mallinfo mmprevious;
struct mallinfo mmafter;
@ -179,7 +181,7 @@ static bool fstest_checkexist(FAR struct fstest_ctx_s *ctx,
int i;
bool ret = false;
for (i = 0; i < CONFIG_TESTING_FSTEST_MAXOPEN; i++)
for (i = 0; i < ctx->max_open; i++)
{
if (&ctx->files[i] != file && ctx->files[i].name &&
strcmp(ctx->files[i].name, file->name) == 0)
@ -244,7 +246,7 @@ static inline void fstest_randfile(FAR struct fstest_ctx_s *ctx,
{
int i;
file->len = (rand() % CONFIG_TESTING_FSTEST_MAXFILE) + 1;
file->len = (rand() % ctx->max_file) + 1;
for (i = 0; i < file->len; i++)
{
ctx->fileimage[i] = fstest_randchar();
@ -344,7 +346,7 @@ static int fstest_gc(FAR struct fstest_ctx_s *ctx, size_t nbytes)
/* Find the first valid file */
for (i = 0; i < CONFIG_TESTING_FSTEST_MAXOPEN; i++)
for (i = 0; i < ctx->max_open; i++)
{
file = &ctx->files[i];
if (file->name != NULL && !file->deleted)
@ -493,7 +495,7 @@ static int fstest_fillfs(FAR struct fstest_ctx_s *ctx)
/* Create a file for each unused file structure */
for (i = 0; i < CONFIG_TESTING_FSTEST_MAXOPEN; i++)
for (i = 0; i < ctx->max_open; i++)
{
file = &ctx->files[i];
if (file->name == NULL)
@ -665,7 +667,7 @@ static unsigned long long fstest_filesize(FAR struct fstest_ctx_s *ctx)
bytes_used = 0;
for (i = 0; i < CONFIG_TESTING_FSTEST_MAXOPEN; i++)
for (i = 0; i < ctx->max_open; i++)
{
file = &ctx->files[i];
if (file->name != NULL && !file->deleted)
@ -685,7 +687,7 @@ static unsigned long fstest_filesize(FAR struct fstest_ctx_s *ctx)
bytes_used = 0;
for (i = 0; i < CONFIG_TESTING_FSTEST_MAXOPEN; i++)
for (i = 0; i < ctx->max_open; i++)
{
file = &ctx->files[i];
if (file->name != NULL && !file->deleted)
@ -710,7 +712,7 @@ static int fstest_verifyfs(FAR struct fstest_ctx_s *ctx)
/* Create a file for each unused file structure */
for (i = 0; i < CONFIG_TESTING_FSTEST_MAXOPEN; i++)
for (i = 0; i < ctx->max_open; i++)
{
file = &ctx->files[i];
if (file->name != NULL)
@ -802,7 +804,7 @@ static int fstest_delfiles(FAR struct fstest_ctx_s *ctx)
{
/* Test for wrap-around */
if (j >= CONFIG_TESTING_FSTEST_MAXOPEN)
if (j >= ctx->max_open)
{
j = 0;
}
@ -857,7 +859,7 @@ static int fstest_delallfiles(FAR struct fstest_ctx_s *ctx)
int ret;
int i;
for (i = 0; i < CONFIG_TESTING_FSTEST_MAXOPEN; i++)
for (i = 0; i < ctx->max_open; i++)
{
file = &ctx->files[i];
if (file->name)
@ -943,6 +945,10 @@ static void show_useage(void)
printf("-n num of test loop e.g. [%d]\n", CONFIG_TESTING_FSTEST_NLOOPS);
printf("-m mount point to be tested e.g. [%s]\n",
CONFIG_TESTING_FSTEST_MOUNTPT);
printf("-o num of open file e.g. [%d]\n",
CONFIG_TESTING_FSTEST_MAXOPEN);
printf("-s size of every file e.g. [%d]\n",
CONFIG_TESTING_FSTEST_MAXFILE);
}
/****************************************************************************
@ -975,11 +981,13 @@ int main(int argc, FAR char *argv[])
srand(0x93846);
loop_num = CONFIG_TESTING_FSTEST_NLOOPS;
ctx->max_file = CONFIG_TESTING_FSTEST_MAXFILE;
ctx->max_open = CONFIG_TESTING_FSTEST_MAXOPEN;
strcpy(ctx->mountdir, CONFIG_TESTING_FSTEST_MOUNTPT);
/* Opt Parse */
while ((option = getopt(argc, argv, ":m:hn:")) != -1)
while ((option = getopt(argc, argv, ":m:hn:o:s:")) != -1)
{
switch (option)
{
@ -993,6 +1001,12 @@ int main(int argc, FAR char *argv[])
case 'n':
loop_num = atoi(optarg);
break;
case 'o':
ctx->max_open = atoi(optarg);
break;
case 's':
ctx->max_file = atoi(optarg);
break;
case ':':
printf("Error: Missing required argument\n");
free(ctx);
@ -1009,6 +1023,21 @@ int main(int argc, FAR char *argv[])
strcat(ctx->mountdir, "/");
}
ctx->fileimage = calloc(ctx->max_file, 1);
if (ctx->fileimage == NULL)
{
free(ctx);
exit(1);
}
ctx->files = calloc(sizeof(struct fstest_filedesc_s), ctx->max_open);
if (ctx->files == NULL)
{
free(ctx->fileimage);
free(ctx);
exit(1);
}
/* Set up memory monitoring */
ctx->mmbefore = mallinfo();
@ -1149,6 +1178,8 @@ int main(int argc, FAR char *argv[])
fstest_delallfiles(ctx);
fstest_endmemusage(ctx);
fflush(stdout);
free(ctx->fileimage);
free(ctx->files);
free(ctx);
#ifdef CONFIG_TESTING_FSTEST_POWEROFF