summaryrefslogtreecommitdiff
path: root/apps/examples/elf/elf_main.c
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-10-29 19:32:05 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-10-29 19:32:05 +0000
commit9e45144d3ad1420908cfdf84306c76f637829023 (patch)
tree63a4ac04f182a282aac2d649973c99285b12cad5 /apps/examples/elf/elf_main.c
parentade5fb42679b7e890f29487ca850c65f9944fa1e (diff)
downloadnuttx-9e45144d3ad1420908cfdf84306c76f637829023.tar.gz
nuttx-9e45144d3ad1420908cfdf84306c76f637829023.tar.bz2
nuttx-9e45144d3ad1420908cfdf84306c76f637829023.zip
C++ constructors work with ELF load now
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5273 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'apps/examples/elf/elf_main.c')
-rw-r--r--apps/examples/elf/elf_main.c80
1 files changed, 75 insertions, 5 deletions
diff --git a/apps/examples/elf/elf_main.c b/apps/examples/elf/elf_main.c
index 23a6b2d21..669de430d 100644
--- a/apps/examples/elf/elf_main.c
+++ b/apps/examples/elf/elf_main.c
@@ -41,6 +41,7 @@
#include <nuttx/compiler.h>
#include <sys/mount.h>
+
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@@ -129,6 +130,9 @@
* Private Data
****************************************************************************/
+static unsigned int g_mminitial; /* Initial memory usage */
+static unsigned int g_mmstep; /* Memory Usage at beginning of test step */
+
static const char delimiter[] =
"****************************************************************************";
@@ -146,6 +150,53 @@ extern const int nexports;
****************************************************************************/
/****************************************************************************
+ * Name: mm_update
+ ****************************************************************************/
+
+static void mm_update(FAR unsigned int *previous, FAR const char *msg)
+{
+ struct mallinfo mmcurrent;
+
+ /* Get the current memory usage */
+
+#ifdef CONFIG_CAN_PASS_STRUCTS
+ mmcurrent = mallinfo();
+#else
+ (void)mallinfo(&mmcurrent);
+#endif
+
+ /* Show the change from the previous time */
+
+ printf("\nMemory Usage %s:\n", msg);
+ printf(" Before: %8u After: %8u Change: %8d\n",
+ *previous, mmcurrent.uordblks, (int)mmcurrent.uordblks - (int)*previous);
+
+ /* Set up for the next test */
+
+ *previous = mmcurrent.uordblks;
+}
+
+/****************************************************************************
+ * Name: mm_initmonitor
+ ****************************************************************************/
+
+static void mm_initmonitor(void)
+{
+ struct mallinfo mmcurrent;
+
+#ifdef CONFIG_CAN_PASS_STRUCTS
+ mmcurrent = mallinfo();
+#else
+ (void)mallinfo(&mmcurrent);
+#endif
+
+ g_mminitial = mmcurrent.uordblks;
+ g_mmstep = mmcurrent.uordblks;
+
+ printf("Initial memory usage: %d\n", mmcurrent.uordblks);
+}
+
+/****************************************************************************
* Name: testheader
****************************************************************************/
@@ -168,6 +219,10 @@ int elf_main(int argc, char *argv[])
int ret;
int i;
+ /* Initialize the memory monitor */
+
+ mm_initmonitor();
+
/* Initialize the ELF binary loader */
message("Initializing the ELF binary loader\n");
@@ -178,6 +233,8 @@ int elf_main(int argc, char *argv[])
exit(1);
}
+ mm_update(&g_mmstep, "after elf_initialize");
+
/* Create a ROM disk for the ROMFS filesystem */
message("Registering romdisk at /dev/ram%d\n", CONFIG_EXAMPLES_ELF_DEVMINOR);
@@ -190,6 +247,8 @@ int elf_main(int argc, char *argv[])
exit(1);
}
+ mm_update(&g_mmstep, "after romdisk_register");
+
/* Mount the file system */
message("Mounting ROMFS filesystem at target=%s with source=%s\n",
@@ -203,7 +262,9 @@ int elf_main(int argc, char *argv[])
elf_uninitialize();
}
- /* Now excercise every progrm in the ROMFS file system */
+ mm_update(&g_mmstep, "after mount");
+
+ /* Now excercise every program in the ROMFS file system */
for (i = 0; dirlist[i]; i++)
{
@@ -223,17 +284,26 @@ int elf_main(int argc, char *argv[])
exit(1);
}
+ mm_update(&g_mmstep, "after load_module");
+
ret = exec_module(&bin, 50);
+
+ mm_update(&g_mmstep, "after exec_module");
+
if (ret < 0)
{
err("ERROR: Failed to execute program '%s'\n", dirlist[i]);
- unload_module(&bin);
+ }
+ else
+ {
+ message("Wait a bit for test completion\n");
+ sleep(4);
}
- message("Wait a bit for test completion\n");
- sleep(4);
+ unload_module(&bin);
+ mm_update(&g_mmstep, "after unload_module");
}
- message("End-of-Test.. Exiting\n");
+ mm_update(&g_mmstep, "End-of-Test");
return 0;
}