From 9e45144d3ad1420908cfdf84306c76f637829023 Mon Sep 17 00:00:00 2001 From: patacongo Date: Mon, 29 Oct 2012 19:32:05 +0000 Subject: 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 --- apps/examples/elf/elf_main.c | 80 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 75 insertions(+), 5 deletions(-) (limited to 'apps/examples/elf/elf_main.c') 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 #include + #include #include #include @@ -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[] = "****************************************************************************"; @@ -145,6 +149,53 @@ extern const int nexports; * Private Functions ****************************************************************************/ +/**************************************************************************** + * 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; } -- cgit v1.2.3