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 2022/11/11 14:27:06 UTC
[incubator-nuttx-apps] branch master updated: mm: add memory stress test
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 b16eaf9d8 mm: add memory stress test
b16eaf9d8 is described below
commit b16eaf9d8ee3bac993d4a29627d92d3c4c00c530
Author: ligd <li...@xiaomi.com>
AuthorDate: Thu Nov 10 23:04:56 2022 +0800
mm: add memory stress test
Signed-off-by: ligd <li...@xiaomi.com>
---
testing/mm/mm_main.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 59 insertions(+)
diff --git a/testing/mm/mm_main.c b/testing/mm/mm_main.c
index bb5ec02f1..6b2839e48 100644
--- a/testing/mm/mm_main.c
+++ b/testing/mm/mm_main.c
@@ -310,6 +310,60 @@ static void do_frees(FAR void **mem, FAR const int *size,
}
}
+static int mm_stress_test(int argc, FAR char *argv[])
+{
+ FAR unsigned char *tmp;
+ int delay = 1;
+ int prio = 0;
+ int size;
+ int i;
+
+ while ((i = getopt(argc, argv, "d:p:")) != ERROR)
+ {
+ if (i == 'd')
+ {
+ delay = atoi(optarg);
+ }
+ else if (i == 'p')
+ {
+ prio = atoi(optarg);
+ }
+ else
+ {
+ printf("Unrecognized option: '%c'\n", i);
+ return -EINVAL;
+ }
+ }
+
+ if (prio != 0)
+ {
+ struct sched_param param;
+
+ sched_getparam(0, ¶m);
+ param.sched_priority = prio;
+ sched_setparam(0, ¶m);
+ }
+
+ while (1)
+ {
+ size = random() % 1024 + 1;
+ tmp = malloc(size);
+ assert(tmp);
+
+ memset(tmp, 0xfe, size);
+ usleep(delay);
+
+ for (i = 0; i < size; i++)
+ {
+ assert(tmp[i] == 0xfe);
+ }
+
+ free(tmp);
+ }
+
+ return 0;
+}
+
/****************************************************************************
* Public Functions
****************************************************************************/
@@ -320,6 +374,11 @@ static void do_frees(FAR void **mem, FAR const int *size,
int main(int argc, FAR char *argv[])
{
+ if (argc > 1)
+ {
+ return mm_stress_test(argc, argv);
+ }
+
mm_showmallinfo();
/* Allocate some memory */