apps/testing/mm: Move from apps/examples/mm (#39)

This commit is contained in:
patacongo 2020-01-30 10:07:00 -06:00 committed by GitHub
parent 4e509c8659
commit ba6377078b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 83 additions and 74 deletions

View File

@ -730,11 +730,6 @@ examples/media
ret = bchdev_register(/dev/mtdblock<N>, <path-to-character-driver>,
false);
examples/mm
^^^^^^^^^^^
This is a simple test of the memory manager.
examples/module
^^^^^^^^^^^^^^

View File

@ -65,6 +65,11 @@ testing/fstest
* CONFIG_TESTING_FSTEST_NLOOPS: Number of test loops. default 100
* CONFIG_TESTING_FSTEST_VERBOSE: Verbose output
testing/mm
==========
This is a simple test of the memory manager.
testing/nxffs
=============

View File

@ -3,11 +3,11 @@
# see the file kconfig-language.txt in the NuttX tools repository.
#
config EXAMPLES_MM
tristate "Memory management example"
config TESTING_MM
tristate "Memory management test"
default n
---help---
Enable the memory management example
Enable the memory management test
if EXAMPLES_MM
if TESTING_MM
endif

View File

@ -1,8 +1,8 @@
############################################################################
# apps/examples/mm/Make.defs
# apps/testing/mm/Make.defs
# Adds selected applications to apps/ build
#
# Copyright (C) 2015 Gregory Nutt. All rights reserved.
# Copyright (C) 2015, 2020 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
@ -34,6 +34,6 @@
#
############################################################################
ifneq ($(CONFIG_EXAMPLES_MM),)
CONFIGURED_APPS += $(APPDIR)/examples/mm
ifneq ($(CONFIG_TESTING_MM),)
CONFIGURED_APPS += $(APPDIR)/testing/mm
endif

View File

@ -1,7 +1,7 @@
############################################################################
# apps/examples/mm/Makefile
# apps/testing/mm/Makefile
#
# Copyright (C) 2011-2012, 2017 Gregory Nutt. All rights reserved.
# Copyright (C) 2011-2012, 2017, 2020 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
@ -40,7 +40,7 @@
PROGNAME = mm
PRIORITY = SCHED_PRIORITY_DEFAULT
STACKSIZE = 2048
MODULE = $(CONFIG_EXAMPLES_MM)
MODULE = $(CONFIG_TESTING_MM)
MAINSRC = mm_main.c

View File

@ -1,7 +1,7 @@
/****************************************************************************
* examples/mm/mm_main.c
* apps/testing/mm/mm_main.c
*
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
* Copyright (C) 2011, 2020 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -48,13 +48,14 @@
#define NTEST_ALLOCS 32
/* #define STOP_ON_ERRORS do {} while (0) */
#define STOP_ON_ERRORS exit(1)
/* All other definitions derive from these two */
#define MM_MIN_SHIFT 4 /* 16 bytes */
#define MM_MIN_CHUNK (1 << MM_MIN_SHIFT)
#define MM_GRAN_MASK (MM_MIN_CHUNK-1)
#define MM_GRAN_MASK (MM_MIN_CHUNK - 1)
#define MM_ALIGN_UP(a) (((a) + MM_GRAN_MASK) & ~MM_GRAN_MASK)
#define MM_ALIGN_DOWN(a) ((a) & ~MM_GRAN_MASK)
@ -67,56 +68,57 @@
/****************************************************************************
* Private Data
****************************************************************************/
/* Test allocations */
static const int alloc_sizes[NTEST_ALLOCS] =
static const int g_alloc_sizes[NTEST_ALLOCS] =
{
1024, 12, 962, 5692, 10254, 111, 9932, 601,
222, 2746, 3, 124321, 68, 776, 6750, 852,
4732, 28, 901, 480, 5011, 1536, 2011, 81647,
646, 1646, 69179, 194, 2590, 7, 969, 70
1024, 12, 962, 5692, 10254, 111, 9932, 601,
222, 2746, 3, 124321, 68, 776, 6750, 852,
4732, 28, 901, 480, 5011, 1536, 2011, 81647,
646, 1646, 69179, 194, 2590, 7, 969, 70
};
static const int realloc_sizes[NTEST_ALLOCS] =
static const int g_realloc_sizes[NTEST_ALLOCS] =
{
18, 3088, 963, 123, 511, 11666, 3723, 42,
9374, 1990, 1412, 6, 592, 4088, 11, 5040,
8663, 91255, 28, 4346, 9172, 168, 229, 4734,
59139, 221, 7830, 30421, 1666, 4, 812, 416
18, 3088, 963, 123, 511, 11666, 3723, 42,
9374, 1990, 1412, 6, 592, 4088, 11, 5040,
8663, 91255, 28, 4346, 9172, 168, 229, 4734,
59139, 221, 7830, 30421, 1666, 4, 812, 416
};
static const int random1[NTEST_ALLOCS] =
static const int g_random1[NTEST_ALLOCS] =
{
20, 11, 3, 31, 9, 29, 7, 17,
21, 2, 26, 18, 14, 25, 0, 10,
27, 19, 22, 28, 8, 30, 12, 15,
4, 1, 24, 6, 16, 13, 5, 23
20, 11, 3, 31, 9, 29, 7, 17,
21, 2, 26, 18, 14, 25, 0, 10,
27, 19, 22, 28, 8, 30, 12, 15,
4, 1, 24, 6, 16, 13, 5, 23
};
static const int random2[NTEST_ALLOCS] =
static const int g_random2[NTEST_ALLOCS] =
{
2, 19, 12, 23, 30, 11, 27, 4,
20, 7, 0, 16, 28, 15, 5, 24,
10, 17, 25, 31, 8, 29, 3, 26,
9, 18, 22, 13, 1, 21, 14, 6
2, 19, 12, 23, 30, 11, 27, 4,
20, 7, 0, 16, 28, 15, 5, 24,
10, 17, 25, 31, 8, 29, 3, 26,
9, 18, 22, 13, 1, 21, 14, 6
};
static const int random3[NTEST_ALLOCS] =
static const int g_random3[NTEST_ALLOCS] =
{
8, 17, 3, 18, 26, 23, 30, 11,
12, 22, 4, 20, 25, 10, 27, 1,
29, 14, 19, 21, 0, 31, 7, 24,
9, 15, 2, 28, 16, 6, 13, 5
8, 17, 3, 18, 26, 23, 30, 11,
12, 22, 4, 20, 25, 10, 27, 1,
29, 14, 19, 21, 0, 31, 7, 24,
9, 15, 2, 28, 16, 6, 13, 5
};
static const int alignment[NTEST_ALLOCS/2] =
static const int g_alignment[NTEST_ALLOCS / 2] =
{
128, 2048, 131072, 8192, 32, 32768, 16384 , 262144,
512, 4096, 65536, 8, 64, 1024, 16, 4
};
static void *allocs[NTEST_ALLOCS];
static struct mallinfo alloc_info;
static FAR void *g_allocs[NTEST_ALLOCS];
static struct mallinfo g_alloc_info;
/****************************************************************************
* Private Functions
@ -124,21 +126,22 @@ static struct mallinfo alloc_info;
static void mm_showmallinfo(void)
{
alloc_info = mallinfo();
g_alloc_info = mallinfo();
printf(" mallinfo:\n");
printf(" Total space allocated from system = %lu\n",
(unsigned long)alloc_info.arena);
(unsigned long)g_alloc_info.arena);
printf(" Number of non-inuse chunks = %lu\n",
(unsigned long)alloc_info.ordblks);
(unsigned long)g_alloc_info.ordblks);
printf(" Largest non-inuse chunk = %lu\n",
(unsigned long)alloc_info.mxordblk);
(unsigned long)g_alloc_info.mxordblk);
printf(" Total allocated space = %lu\n",
(unsigned long)alloc_info.uordblks);
(unsigned long)g_alloc_info.uordblks);
printf(" Total non-inuse space = %lu\n",
(unsigned long)alloc_info.fordblks);
(unsigned long)g_alloc_info.fordblks);
}
static void do_mallocs(void **mem, const int *size, const int *seq, int n)
static void do_mallocs(FAR void **mem, FAR const int *size,
FAR const int *seq, int n)
{
int i;
int j;
@ -157,16 +160,18 @@ static void do_mallocs(void **mem, const int *size, const int *seq, int n)
{
int allocsize = MM_ALIGN_UP(size[j] + SIZEOF_MM_ALLOCNODE);
fprintf(stderr, "(%d)malloc failed for allocsize=%d\n", i, allocsize);
if (allocsize > alloc_info.mxordblk)
fprintf(stderr, "(%d)malloc failed for allocsize=%d\n",
i, allocsize);
if (allocsize > g_alloc_info.mxordblk)
{
fprintf(stderr, " Normal, largest free block is only %lu\n",
(unsigned long)alloc_info.mxordblk);
fprintf(stderr, " Normal, largest free block is only %lu\n",
(unsigned long)g_alloc_info.mxordblk);
}
else
{
fprintf(stderr, " ERROR largest free block is %lu\n",
(unsigned long)alloc_info.mxordblk);
(unsigned long)g_alloc_info.mxordblk);
exit(1);
}
}
@ -180,7 +185,8 @@ static void do_mallocs(void **mem, const int *size, const int *seq, int n)
}
}
static void do_reallocs(void **mem, const int *oldsize, const int *newsize, const int *seq, int n)
static void do_reallocs(FAR void **mem, FAR const int *oldsize,
FAR const int *newsize, FAR const int *seq, int n)
{
int i;
int j;
@ -199,15 +205,15 @@ static void do_reallocs(void **mem, const int *oldsize, const int *newsize, cons
int allocsize = MM_ALIGN_UP(newsize[j] + SIZEOF_MM_ALLOCNODE);
fprintf(stderr, "(%d)realloc failed for allocsize=%d\n", i, allocsize);
if (allocsize > alloc_info.mxordblk)
if (allocsize > g_alloc_info.mxordblk)
{
fprintf(stderr, " Normal, largest free block is only %lu\n",
(unsigned long)alloc_info.mxordblk);
(unsigned long)g_alloc_info.mxordblk);
}
else
{
fprintf(stderr, " ERROR largest free block is %lu\n",
(unsigned long)alloc_info.mxordblk);
(unsigned long)g_alloc_info.mxordblk);
exit(1);
}
}
@ -220,7 +226,8 @@ static void do_reallocs(void **mem, const int *oldsize, const int *newsize, cons
}
}
static void do_memaligns(void **mem, const int *size, const int *align, const int *seq, int n)
static void do_memaligns(FAR void **mem, FAR const int *size, FAR const int *align,
FAR const int *seq, int n)
{
int i;
int j;
@ -239,15 +246,15 @@ static void do_memaligns(void **mem, const int *size, const int *align, const in
int allocsize = MM_ALIGN_UP(size[j] + SIZEOF_MM_ALLOCNODE) + 2*align[i];
fprintf(stderr, "(%d)memalign failed for allocsize=%d\n", i, allocsize);
if (allocsize > alloc_info.mxordblk)
if (allocsize > g_alloc_info.mxordblk)
{
fprintf(stderr, " Normal, largest free block is only %lu\n",
(unsigned long)alloc_info.mxordblk);
(unsigned long)g_alloc_info.mxordblk);
}
else
{
fprintf(stderr, " ERROR largest free block is %lu\n",
(unsigned long)alloc_info.mxordblk);
(unsigned long)g_alloc_info.mxordblk);
exit(1);
}
}
@ -260,7 +267,8 @@ static void do_memaligns(void **mem, const int *size, const int *align, const in
}
}
static void do_frees(void **mem, const int *size, const int *seq, int n)
static void do_frees(FAR void **mem, FAR const int *size,
FAR const int *seq, int n)
{
int i;
int j;
@ -293,24 +301,25 @@ int main(int argc, FAR char *argv[])
/* Allocate some memory */
do_mallocs(allocs, alloc_sizes, random1, NTEST_ALLOCS);
do_mallocs(g_allocs, g_alloc_sizes, g_random1, NTEST_ALLOCS);
/* Re-allocate the memory */
do_reallocs(allocs, alloc_sizes, realloc_sizes, random2, NTEST_ALLOCS);
do_reallocs(g_allocs, g_alloc_sizes, g_realloc_sizes, g_random2, NTEST_ALLOCS);
/* Release the memory */
do_frees(allocs, realloc_sizes, random3, NTEST_ALLOCS);
do_frees(g_allocs, g_realloc_sizes, g_random3, NTEST_ALLOCS);
/* Allocate aligned memory */
do_memaligns(allocs, alloc_sizes, alignment, random2, NTEST_ALLOCS/2);
do_memaligns(allocs, alloc_sizes, alignment, &random2[NTEST_ALLOCS/2], NTEST_ALLOCS/2);
do_memaligns(g_allocs, g_alloc_sizes, g_alignment, g_random2, NTEST_ALLOCS / 2);
do_memaligns(g_allocs, g_alloc_sizes, g_alignment, &g_random2[NTEST_ALLOCS / 2],
NTEST_ALLOCS / 2);
/* Release aligned memory */
do_frees(allocs, alloc_sizes, random1, NTEST_ALLOCS);
do_frees(g_allocs, g_alloc_sizes, g_random1, NTEST_ALLOCS);
printf("TEST COMPLETE\n");
return 0;