You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2021/07/31 04:02:47 UTC
[incubator-nuttx-apps] branch master updated:
testing/fstest:Support test fs with parameter
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git
The following commit(s) were added to refs/heads/master by this push:
new 54d94d2 testing/fstest:Support test fs with parameter
54d94d2 is described below
commit 54d94d21b87fc736eceb642babe1cc7e7d2f51d5
Author: anjianjun <an...@xiaomi.com>
AuthorDate: Fri Jul 30 16:58:59 2021 +0800
testing/fstest:Support test fs with parameter
Signed-off-by: anjianjun <an...@xiaomi.com>
---
testing/fstest/README.md | 6 +++++
testing/fstest/fstest_main.c | 55 ++++++++++++++++++++++++++++++++++++++++----
2 files changed, 57 insertions(+), 4 deletions(-)
diff --git a/testing/fstest/README.md b/testing/fstest/README.md
index 458b150..34d03be 100644
--- a/testing/fstest/README.md
+++ b/testing/fstest/README.md
@@ -17,3 +17,9 @@ for the SPIFFS file system.
- `CONFIG_TESTING_FSTEST_MOUNTPT` – Path where the file system is mounted.
- `CONFIG_TESTING_FSTEST_NLOOPS` – Number of test loops. default `100`.
- `CONFIG_TESTING_FSTEST_VERBOSE` – Verbose output.
+
+EXAMPLE
+ fstest -m /mnt -n 10 – Test /mnt 10 times
+ fstest -h – Get help message
+ fstest – Test path define by `CONFIG_TESTING_FSTEST_MOUNTPT`
+ `CONFIG_TESTING_FSTEST_NLOOPS` times
diff --git a/testing/fstest/fstest_main.c b/testing/fstest/fstest_main.c
index 9e7987a..9506900 100644
--- a/testing/fstest/fstest_main.c
+++ b/testing/fstest/fstest_main.c
@@ -102,7 +102,8 @@ struct fstest_filedesc_s
static uint8_t g_fileimage[CONFIG_TESTING_FSTEST_MAXFILE];
static struct fstest_filedesc_s g_files[CONFIG_TESTING_FSTEST_MAXOPEN];
-static const char g_mountdir[] = CONFIG_TESTING_FSTEST_MOUNTPT "/";
+static char g_mountdir[CONFIG_TESTING_FSTEST_MAXNAME] =
+ CONFIG_TESTING_FSTEST_MOUNTPT "/";
static int g_nfiles;
static int g_ndeleted;
static int g_nfailed;
@@ -925,14 +926,14 @@ static int fstest_directory(void)
/* Open the directory */
- dirp = opendir(CONFIG_TESTING_FSTEST_MOUNTPT);
+ dirp = opendir(g_mountdir);
if (!dirp)
{
/* Failed to open the directory */
printf("ERROR: Failed to open directory '%s': %d\n",
- CONFIG_TESTING_FSTEST_MOUNTPT, errno);
+ g_mountdir, errno);
return ERROR;
}
@@ -960,6 +961,19 @@ static int fstest_directory(void)
}
/****************************************************************************
+ * Show help Message
+ ****************************************************************************/
+
+static void show_useage(void)
+{
+ printf("Usage : fstest [OPTION [ARG]] ...\n");
+ printf("-h show this help statement\n");
+ printf("-n num of test loop e.g. [%d]\n", CONFIG_TESTING_FSTEST_NLOOPS);
+ printf("-m mount point tobe test e.g. [%s]\n",
+ CONFIG_TESTING_FSTEST_MOUNTPT);
+}
+
+/****************************************************************************
* Public Functions
****************************************************************************/
@@ -972,10 +986,43 @@ int main(int argc, FAR char *argv[])
struct statfs buf;
unsigned int i;
int ret;
+ int loop_num;
+ int option;
/* Seed the random number generated */
srand(0x93846);
+ loop_num = CONFIG_TESTING_FSTEST_NLOOPS;
+ strcpy(g_mountdir, CONFIG_TESTING_FSTEST_MOUNTPT);
+
+ /* Opt Parse */
+
+ while ((option = getopt(argc, argv, ":m:hn:")) != -1)
+ {
+ switch (option)
+ {
+ case 'm':
+ strcpy(g_mountdir, optarg);
+ break;
+ case 'h':
+ show_useage();
+ exit(0);
+ case 'n':
+ loop_num = atoi(optarg);
+ break;
+ case ':':
+ printf("Error: Missing required argument\n");
+ exit(1);
+ case '?':
+ printf("Error: Unrecognized option\n");
+ exit(1);
+ }
+ }
+
+ if (g_mountdir[strlen(g_mountdir)-1] != '/')
+ {
+ strcat(g_mountdir, "/");
+ }
/* Set up memory monitoring */
@@ -990,7 +1037,7 @@ int main(int argc, FAR char *argv[])
#if CONFIG_TESTING_FSTEST_NLOOPS == 0
for (i = 0; ; i++)
#else
- for (i = 1; i <= CONFIG_TESTING_FSTEST_NLOOPS; i++)
+ for (i = 1; i <= loop_num; i++)
#endif
{
/* Write a files to the file system until either (1) all of the open