aboutsummaryrefslogtreecommitdiff
path: root/nuttx/mm/mm_test.c
diff options
context:
space:
mode:
authorpatacongo <patacongo@7fd9a85b-ad96-42d3-883c-3090e2eb8679>2012-07-14 23:31:12 +0000
committerpatacongo <patacongo@7fd9a85b-ad96-42d3-883c-3090e2eb8679>2012-07-14 23:31:12 +0000
commit183aa2858c3bdabafb09943b00760c4831f588e1 (patch)
tree27bc6c7bda8a5889685481fab926aa45950651ea /nuttx/mm/mm_test.c
parent7c6185ae4bfefb70c17e75219db7269c03c7fd79 (diff)
downloadpx4-firmware-183aa2858c3bdabafb09943b00760c4831f588e1.tar.gz
px4-firmware-183aa2858c3bdabafb09943b00760c4831f588e1.tar.bz2
px4-firmware-183aa2858c3bdabafb09943b00760c4831f588e1.zip
mm/ file clean-up
git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@4943 7fd9a85b-ad96-42d3-883c-3090e2eb8679
Diffstat (limited to 'nuttx/mm/mm_test.c')
-rw-r--r--nuttx/mm/mm_test.c100
1 files changed, 81 insertions, 19 deletions
diff --git a/nuttx/mm/mm_test.c b/nuttx/mm/mm_test.c
index e7a44dec7..b25a24095 100644
--- a/nuttx/mm/mm_test.c
+++ b/nuttx/mm/mm_test.c
@@ -2,7 +2,7 @@
* mm/mm_test.c
*
* Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved.
- * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
+ * Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -33,10 +33,18 @@
*
************************************************************************/
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+/************************************************************************
+ * Pre-processor Definitions
+ ************************************************************************/
+
/* Fake NuttX dependencies */
#define FAR
@@ -56,6 +64,10 @@
/* #define STOP_ON_ERRORS do{}while(0) */
#define STOP_ON_ERRORS exit(1)
+/************************************************************************
+ * Private Data
+ ************************************************************************/
+
/* Test allocations */
static const int alloc_sizes[NTEST_ALLOCS] =
@@ -65,6 +77,7 @@ static const int alloc_sizes[NTEST_ALLOCS] =
4732, 28, 901, 480, 5011, 1536, 2011, 81647,
646, 1646, 69179, 194, 2590, 7, 969, 70
};
+
static const int realloc_sizes[NTEST_ALLOCS] =
{
18, 3088, 963, 123, 511, 11666, 3723, 42,
@@ -72,6 +85,7 @@ static const int realloc_sizes[NTEST_ALLOCS] =
8663, 91255, 28, 4346, 9172, 168, 229, 4734,
59139, 221, 7830, 30421, 1666, 4, 812, 416
};
+
static const int random1[NTEST_ALLOCS] =
{
20, 11, 3, 31, 9, 29, 7, 17,
@@ -79,6 +93,7 @@ static const int random1[NTEST_ALLOCS] =
27, 19, 22, 28, 8, 30, 12, 15,
4, 1, 24, 6, 16, 13, 5, 23
};
+
static const int random2[NTEST_ALLOCS] =
{
2, 19, 12, 23, 30, 11, 27, 4,
@@ -86,6 +101,7 @@ static const int random2[NTEST_ALLOCS] =
10, 17, 25, 31, 8, 29, 3, 26,
9, 18, 22, 13, 1, 21, 14, 6
};
+
static const int random3[NTEST_ALLOCS] =
{
8, 17, 3, 18, 26, 23, 30, 11,
@@ -93,18 +109,24 @@ static const int random3[NTEST_ALLOCS] =
29, 14, 19, 21, 0, 31, 7, 24,
9, 15, 2, 28, 16, 6, 13, 5
};
+
static const int 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 unsigned int g_reportedheapsize = 0;
static unsigned int g_actualheapsize = 0;
/************************************************************************
- * mm_showchunkinfo
+ * Private Functions
+ ************************************************************************/
+
+/************************************************************************
+ * Name: mm_findinfreelist
************************************************************************/
static int mm_findinfreelist(struct mm_freenode_s *node)
@@ -120,9 +142,14 @@ static int mm_findinfreelist(struct mm_freenode_s *node)
return 1;
}
}
+
return 0;
}
+/************************************************************************
+ * Name: mm_showchunkinfo
+ ************************************************************************/
+
static void mm_showchunkinfo(void)
{
struct mm_allocnode_s *node;
@@ -146,8 +173,8 @@ static void mm_showchunkinfo(void)
for (node = g_heapstart[region];
node < g_heapend[region];
node = (struct mm_allocnode_s *)((char*)node + node->size))
- {
- printf(" %p 0x%08x 0x%08x %s",
+ {
+ printf(" %p 0x%08x 0x%08x %s",
node, node->size, node->preceding & ~MM_ALLOC_BIT,
node->preceding & MM_ALLOC_BIT ? "Allocated" : "Free ");
found = mm_findinfreelist((struct mm_freenode_s *)node);
@@ -168,6 +195,10 @@ static void mm_showchunkinfo(void)
#undef region
}
+/************************************************************************
+ * Name: mm_showfreelist
+ ************************************************************************/
+
static void mm_showfreelist(void)
{
struct mm_freenode_s *prev;
@@ -204,6 +235,10 @@ static void mm_showfreelist(void)
}
}
+/************************************************************************
+ * Name: mm_showmallinfo
+ ************************************************************************/
+
static void mm_showmallinfo(void)
{
int sval;
@@ -213,15 +248,15 @@ static void mm_showmallinfo(void)
alloc_info = mallinfo();
printf(" mallinfo:\n");
printf(" Total space allocated from system = %ld\n",
- alloc_info.arena);
+ alloc_info.arena);
printf(" Number of non-inuse chunks = %ld\n",
- alloc_info.ordblks);
+ alloc_info.ordblks);
printf(" Largest non-inuse chunk = %ld\n",
- alloc_info.mxordblk);
+ alloc_info.mxordblk);
printf(" Total allocated space = %ld\n",
- alloc_info.uordblks);
+ alloc_info.uordblks);
printf(" Total non-inuse space = %ld\n",
- alloc_info.fordblks);
+ alloc_info.fordblks);
sval = mm_getsemaphore();
if (sval != 1)
@@ -249,7 +284,12 @@ static void mm_showmallinfo(void)
}
}
-static void do_mallocs(void **mem, const int *size, const int *rand, int n)
+/************************************************************************
+ * Name: do_mallocs
+ ************************************************************************/
+
+static void do_mallocs(void **mem, const int *size, const int *rand,
+ int n)
{
int sval;
int i;
@@ -294,7 +334,12 @@ static void do_mallocs(void **mem, const int *size, const int *rand, int n)
}
}
-static void do_reallocs(void **mem, const int *oldsize, const int *newsize, const int *rand, int n)
+/************************************************************************
+ * Name: do_reallocs
+ ************************************************************************/
+
+static void do_reallocs(void **mem, const int *oldsize,
+ const int *newsize, const int *rand, int n)
{
int sval;
int i;
@@ -304,11 +349,11 @@ static void do_reallocs(void **mem, const int *oldsize, const int *newsize, cons
{
j = rand[i];
printf("(%d)Re-allocating at %p from %d to %d bytes\n",
- i, mem[j], oldsize[j], newsize[j]);
+ i, mem[j], oldsize[j], newsize[j]);
mem[j] = mm_realloc(mem[j], newsize[j]);
printf("(%d)Memory re-allocated at %p\n", i, mem[j]);
if (mem[j] == NULL)
- {
+ {
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)
@@ -320,7 +365,7 @@ static void do_reallocs(void **mem, const int *oldsize, const int *newsize, cons
fprintf(stderr, " ERROR largest free block is %ld\n", alloc_info.mxordblk);
exit(1);
}
- }
+ }
else
{
memset(mem[j], 0x55, newsize[j]);
@@ -337,7 +382,12 @@ 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 *rand, int n)
+/************************************************************************
+ * Name: do_memaligns
+ ************************************************************************/
+
+static void do_memaligns(void **mem, const int *size, const int *align,
+ const int *rand, int n)
{
int sval;
int i;
@@ -347,11 +397,11 @@ static void do_memaligns(void **mem, const int *size, const int *align, const in
{
j = rand[i];
printf("(%d)Allocating %d bytes aligned to 0x%08x\n",
- i, size[j], align[i]);
+ i, size[j], align[i]);
mem[j] = mm_memalign(align[i], size[j]);
printf("(%d)Memory allocated at %p\n", i, mem[j]);
if (mem[j] == NULL)
- {
+ {
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)
@@ -363,7 +413,7 @@ static void do_memaligns(void **mem, const int *size, const int *align, const in
fprintf(stderr, " ERROR largest free block is %ld\n", alloc_info.mxordblk);
exit(1);
}
- }
+ }
else
{
memset(mem[j], 0x33, size[j]);
@@ -380,6 +430,10 @@ static void do_memaligns(void **mem, const int *size, const int *align, const in
}
}
+/************************************************************************
+ * Name: do_frees
+ ************************************************************************/
+
static void do_frees(void **mem, const int *size, const int *rand, int n)
{
int sval;
@@ -390,7 +444,7 @@ static void do_frees(void **mem, const int *size, const int *rand, int n)
{
j = rand[i];
printf("(%d)Releasing memory at %p (size=%d bytes)\n",
- i, mem[j], size[j]);
+ i, mem[j], size[j]);
mm_free(mem[j]);
mem[j] = NULL;
@@ -405,6 +459,14 @@ static void do_frees(void **mem, const int *size, const int *rand, int n)
}
}
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+/************************************************************************
+ * Name: main
+ ************************************************************************/
+
int main(int argc, char **argv, char **envp)
{
void *heap1_base;