diff --git a/NxWidgets/UnitTests/nxwm/main.cxx b/NxWidgets/UnitTests/nxwm/main.cxx index 068452cff..c202e6443 100644 --- a/NxWidgets/UnitTests/nxwm/main.cxx +++ b/NxWidgets/UnitTests/nxwm/main.cxx @@ -62,6 +62,15 @@ # define MAIN_STRING "user_start: " #endif +#ifdef CONFIG_HAVE_FILENAME +# define showTestStepMemory(msg) \ + _showTestStepMemory((FAR const char*)__FILE__, (int)__LINE__, msg) +# define showTestCaseMemory(msg) \ + _showTestCaseMemory((FAR const char*)__FILE__, (int)__LINE__, msg) +# define showTestMemory(msg) \ + _showTestMemory((FAR const char*)__FILE__, (int)__LINE__, msg) +#endif + ///////////////////////////////////////////////////////////////////////////// // Private Types ///////////////////////////////////////////////////////////////////////////// @@ -70,6 +79,9 @@ struct SNxWmTest { NxWM::CTaskbar *taskbar; // The task bar NxWM::CStartWindow *startwindow; // The start window + unsigned int mmInitial; // Initial memory usage + unsigned int mmStep; // Memory Usage at beginning of test step + unsigned int mmSubStep; // Memory Usage at beginning of test sub-step }; ///////////////////////////////////////////////////////////////////////////// @@ -90,6 +102,118 @@ extern "C" int MAIN_NAME(int argc, char *argv[]); // Public Functions ///////////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////////// +// Name: updateMemoryUsage +///////////////////////////////////////////////////////////////////////////// + +#ifdef CONFIG_HAVE_FILENAME +static void updateMemoryUsage(unsigned int *previous, + FAR const char *file, int line, + FAR const char *msg) +#else +static void updateMemoryUsage(unsigned int *previous, + FAR const char *msg) +#endif +{ + 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 */ + +#ifdef CONFIG_HAVE_FILENAME + printf("File: %s Line: %d : %s\n", file, line, msg); +#else + printf("\n%s:\n", msg); +#endif + 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: showTestCaseMemory +///////////////////////////////////////////////////////////////////////////// + +#ifdef CONFIG_HAVE_FILENAME +static void _showTestCaseMemory(FAR const char *file, int line, FAR const char *msg) +{ + updateMemoryUsage(&g_nxwmtest.mmStep, file, line, msg); + g_nxwmtest.mmSubStep = g_nxwmtest.mmInitial; +} +#else +static void showTestCaseMemory(FAR const char *msg) +{ + updateMemoryUsage(&g_nxwmtest.mmStep, msg); + g_nxwmtest.mmSubStep = g_nxwmtest.mmInitial; +} +#endif + +///////////////////////////////////////////////////////////////////////////// +// Name: showTestMemory +///////////////////////////////////////////////////////////////////////////// + +#ifdef CONFIG_HAVE_FILENAME +static void _showTestMemory(FAR const char *file, int line, FAR const char *msg) +{ + updateMemoryUsage(&g_nxwmtest.mmInitial, file, line, msg); +} +#else +static void showTestMemory(FAR const char *msg) +{ + updateMemoryUsage(&g_nxwmtest.mmInitial, msg); +} +#endif + +///////////////////////////////////////////////////////////////////////////// +// Name: initMemoryUsage +///////////////////////////////////////////////////////////////////////////// + +static void initMemoryUsage(void) +{ + struct mallinfo mmcurrent; + +#ifdef CONFIG_CAN_PASS_STRUCTS + mmcurrent = mallinfo(); +#else + (void)mallinfo(&mmcurrent); +#endif + + g_nxwmtest.mmInitial = mmcurrent.uordblks; + g_nxwmtest.mmStep = mmcurrent.uordblks; + g_nxwmtest.mmSubStep = mmcurrent.uordblks; +} + +///////////////////////////////////////////////////////////////////////////// +// Public Functions +///////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// Name: showTestStepMemory +///////////////////////////////////////////////////////////////////////////// +// Called by ad hoc instrumentation in the NxWM/NxWidgets code + +#ifdef CONFIG_HAVE_FILENAME +void _showTestStepMemory(FAR const char *file, int line, FAR const char *msg) +{ + updateMemoryUsage(&g_nxwmtest.mmSubStep, file, line, msg); +} +#else +void showTestStepMemory(FAR const char *msg) +{ + updateMemoryUsage(&g_nxwmtest.mmSubStep, msg); +} +#endif + ///////////////////////////////////////////////////////////////////////////// // user_start/nxwm_main ///////////////////////////////////////////////////////////////////////////// @@ -102,6 +226,10 @@ int MAIN_NAME(int argc, char *argv[]) up_cxxinitialize(); #endif + // Initialize memory monitor logic + + initMemoryUsage(); + // Create an instance of the Task Bar. // // The general sequence for initializing the task bar is: @@ -120,6 +248,7 @@ int MAIN_NAME(int argc, char *argv[]) printf(MAIN_STRING "ERROR: Failed to instantiate CTaskbar\n"); return EXIT_FAILURE; } + showTestCaseMemory("After create taskbar"); // Connect to the NX server @@ -130,6 +259,7 @@ int MAIN_NAME(int argc, char *argv[]) delete g_nxwmtest.taskbar; return EXIT_FAILURE; } + showTestCaseMemory("After connecting to the server"); // Initialize the task bar // @@ -144,7 +274,8 @@ int MAIN_NAME(int argc, char *argv[]) delete g_nxwmtest.taskbar; return EXIT_FAILURE; } - + showTestCaseMemory("After initializing memory menager"); + // Create the start window. The general sequence for setting up the start window is: // // 1. Call CTaskBar::openApplicationWindow to create a window for the start window, @@ -162,6 +293,7 @@ int MAIN_NAME(int argc, char *argv[]) delete g_nxwmtest.taskbar; return EXIT_FAILURE; } + showTestCaseMemory("After creating start window application window"); printf(MAIN_STRING "Initialize the CApplicationWindow\n"); if (!window->open()) @@ -171,6 +303,7 @@ int MAIN_NAME(int argc, char *argv[]) delete g_nxwmtest.taskbar; return EXIT_FAILURE; } + showTestCaseMemory("After initializing the start window application window"); printf(MAIN_STRING "Creating the start window application\n"); g_nxwmtest.startwindow = new NxWM::CStartWindow(g_nxwmtest.taskbar, window); @@ -181,6 +314,7 @@ int MAIN_NAME(int argc, char *argv[]) delete g_nxwmtest.taskbar; return EXIT_FAILURE; } + showTestCaseMemory("After create the start window application"); // Initialize the NSH library @@ -192,6 +326,7 @@ int MAIN_NAME(int argc, char *argv[]) delete g_nxwmtest.taskbar; return EXIT_FAILURE; } + showTestCaseMemory("After initializing the NSH library"); // Add the NxConsole application to the start window @@ -204,6 +339,7 @@ int MAIN_NAME(int argc, char *argv[]) printf(MAIN_STRING "ERROR: Failed to create CApplicationWindow for the NxConsole\n"); goto noconsole; } + showTestCaseMemory("After creating the NxConsole application window"); printf(MAIN_STRING "Initialize the CApplicationWindow\n"); if (!window->open()) @@ -213,6 +349,7 @@ int MAIN_NAME(int argc, char *argv[]) delete g_nxwmtest.taskbar; return EXIT_FAILURE; } + showTestCaseMemory("After initializing the NxConsole application window"); printf(MAIN_STRING "Creating the NxConsole application\n"); console = new NxWM::CNxConsole(g_nxwmtest.taskbar, window); @@ -222,6 +359,7 @@ int MAIN_NAME(int argc, char *argv[]) delete window; goto noconsole; } + showTestCaseMemory("After creating the NxConsole application"); printf(MAIN_STRING "Adding the NxConsole application to the start window\n"); if (!g_nxwmtest.startwindow->addApplication(console)) @@ -229,6 +367,7 @@ int MAIN_NAME(int argc, char *argv[]) printf(MAIN_STRING "ERROR: Failed to add CNxConsole to the start window\n"); delete window; } + showTestCaseMemory("After adding the NxConsole application"); noconsole: @@ -244,6 +383,7 @@ noconsole: printf(MAIN_STRING "ERROR: Failed to create CApplicationWindow for the calculator\n"); goto nocalculator; } + showTestCaseMemory("After creating the calculator application window"); printf(MAIN_STRING "Initialize the CApplicationWindow\n"); if (!window->open()) @@ -253,6 +393,7 @@ noconsole: delete g_nxwmtest.taskbar; return EXIT_FAILURE; } + showTestCaseMemory("After creating the initializing application window"); printf(MAIN_STRING "Creating the calculator application\n"); calculator = new NxWM::CCalculator(g_nxwmtest.taskbar, window); @@ -262,6 +403,7 @@ noconsole: delete window; goto nocalculator; } + showTestCaseMemory("After creating the calculator application"); printf(MAIN_STRING "Adding the calculator application to the start window\n"); if (!g_nxwmtest.startwindow->addApplication(calculator)) @@ -269,6 +411,7 @@ noconsole: printf(MAIN_STRING "ERROR: Failed to add calculator to the start window\n"); delete window; } + showTestCaseMemory("After adding the calculator application"); nocalculator: #endif @@ -290,6 +433,7 @@ nocalculator: delete g_nxwmtest.startwindow; return EXIT_FAILURE; } + showTestCaseMemory("After starting the start window application"); // Call CTaskBar::startWindowManager to start the display with applications in place. // This method will not return but will enter the task bar's modal loop. @@ -308,22 +452,26 @@ nocalculator: delete g_nxwmtest.startwindow; return EXIT_FAILURE; } + showTestCaseMemory("After starting the window manager"); // Wait a little bit for the display to stabilize. The simulation pressing of // the 'start window' icon in the task bar sleep(2); g_nxwmtest.taskbar->clickIcon(0); + showTestCaseMemory("After clicking the start window icon"); // Wait bit to see the result of the button press. The press the first icon // in the start menu. That should be the NxConsole icon. sleep(2); g_nxwmtest.startwindow->clickIcon(0); + showTestCaseMemory("After clicking the NxConsole icon"); // Wait bit to see the result of the button press. sleep(2); + showTestMemory("Final memory usage"); return EXIT_SUCCESS; } diff --git a/NxWidgets/nxwm/include/capplicationwindow.hxx b/NxWidgets/nxwm/include/capplicationwindow.hxx index 167f51997..924389709 100644 --- a/NxWidgets/nxwm/include/capplicationwindow.hxx +++ b/NxWidgets/nxwm/include/capplicationwindow.hxx @@ -184,6 +184,7 @@ namespace NxWM * used during automated testing of NxWM. */ +#ifdef CONFIG_NXWM_UNITTEST inline void clickMinimizeIcon(int index) { // Get the size and position of the widget @@ -198,12 +199,14 @@ namespace NxWM m_minimizeImage->click(imagePos.x + (imageSize.w >> 1), imagePos.y + (imageSize.h >> 1)); } +#endif /** * Simulate a mouse click on the stop applicaiton icon. This inline method is only * used during automated testing of NxWM. */ +#ifdef CONFIG_NXWM_UNITTEST inline void clickStopIcon(int index) { // Get the size and position of the widget @@ -218,6 +221,7 @@ namespace NxWM m_stopImage->click(imagePos.x + (imageSize.w >> 1), imagePos.y + (imageSize.h >> 1)); } +#endif }; } diff --git a/NxWidgets/nxwm/include/cstartwindow.hxx b/NxWidgets/nxwm/include/cstartwindow.hxx index 5eeb51781..924cc7d05 100644 --- a/NxWidgets/nxwm/include/cstartwindow.hxx +++ b/NxWidgets/nxwm/include/cstartwindow.hxx @@ -209,6 +209,7 @@ namespace NxWM * used during automated testing of NxWM. */ +#ifdef CONFIG_NXWM_UNITTEST inline void clickIcon(int index) { if (index < m_slots.size()) @@ -230,6 +231,7 @@ namespace NxWM image->click(imagePos.x + (imageSize.w >> 1), imagePos.y + (imageSize.h >> 1)); } } +#endif }; } diff --git a/NxWidgets/nxwm/include/ctaskbar.hxx b/NxWidgets/nxwm/include/ctaskbar.hxx index c290cb8ae..4e12fdb2c 100644 --- a/NxWidgets/nxwm/include/ctaskbar.hxx +++ b/NxWidgets/nxwm/include/ctaskbar.hxx @@ -366,6 +366,7 @@ namespace NxWM * used during automated testing of NxWM. */ +#ifdef CONFIG_NXWM_UNITTEST inline void clickIcon(int index) { if (index < m_slots.size()) @@ -387,6 +388,7 @@ namespace NxWM image->click(imagePos.x + (imageSize.w >> 1), imagePos.y + (imageSize.h >> 1)); } } +#endif }; } diff --git a/NxWidgets/nxwm/include/nxwmconfig.hxx b/NxWidgets/nxwm/include/nxwmconfig.hxx index 59ae1e79d..99383fe02 100644 --- a/NxWidgets/nxwm/include/nxwmconfig.hxx +++ b/NxWidgets/nxwm/include/nxwmconfig.hxx @@ -301,4 +301,23 @@ # define CONFIG_NXWM_NXCONSOLE_FONTID CONFIG_NXWM_DEFAULT_FONTID #endif +/**************************************************************************** + * Global Function Prototypes + ****************************************************************************/ +/** + * Hook to support monitoring of memory usage by the NxWM unit test. + */ + +#ifdef CONFIG_NXWM_UNITTEST +# ifdef CONFIG_HAVE_FILENAME +void _showTestStepMemory(FAR const char *file, int line, FAR const char *msg); +# define showTestStepMemory(msg) \ + _showTestStepMemory((FAR const char*)__FILE__, (int)__LINE__, msg) +# else +void showTestStepMemory(FAR const char *msg); +# endif +#else +# define showTestStepMemory(msg) +#endif + #endif // __INCLUDE_NXWMCONFIG_HXX diff --git a/NxWidgets/nxwm/src/cnxconsole.cxx b/NxWidgets/nxwm/src/cnxconsole.cxx index 3cf5e13b9..fb6ca680a 100644 --- a/NxWidgets/nxwm/src/cnxconsole.cxx +++ b/NxWidgets/nxwm/src/cnxconsole.cxx @@ -357,7 +357,9 @@ int CNxConsole::nxconsole(int argc, char *argv[]) } // Now re-direct stdout and stderr so that they use the NX console driver. - // Note that stdin is retained (file descriptor 0, probably the the serial console). + // Notes: (1) stdin is retained (file descriptor 0, probably the the serial + // console). (2) Don't bother trying to put debug instrumentation in the + // following becaue it will end up in the NxConsole window. (void)std::fflush(stdout); (void)std::fflush(stderr); @@ -372,7 +374,7 @@ int CNxConsole::nxconsole(int argc, char *argv[]) std::close(fd); - // Inform the parent thread that we successfully initialize + // Inform the parent thread that we successfully initialized g_nxconvars.result = true; sem_post(&g_nxconvars.sem); diff --git a/NxWidgets/nxwm/src/cstartwindow.cxx b/NxWidgets/nxwm/src/cstartwindow.cxx index 3190f50d9..f25ed8d2b 100644 --- a/NxWidgets/nxwm/src/cstartwindow.cxx +++ b/NxWidgets/nxwm/src/cstartwindow.cxx @@ -457,5 +457,3 @@ void CStartWindow::handleClickEvent(const NXWidgets::CWidgetEventArgs &e) } } - - diff --git a/NxWidgets/nxwm/src/ctaskbar.cxx b/NxWidgets/nxwm/src/ctaskbar.cxx index 2ba0c4b08..2c6bf660b 100644 --- a/NxWidgets/nxwm/src/ctaskbar.cxx +++ b/NxWidgets/nxwm/src/ctaskbar.cxx @@ -706,7 +706,7 @@ bool CTaskbar::createTaskbarWindow(void) * @param pPos The new position of the window. * @return True on success, false on failure. */ - + m_taskbar->setPosition(&pos); m_taskbar->setSize(&size); return true; diff --git a/nuttx/configs/sim/nxwm/defconfig b/nuttx/configs/sim/nxwm/defconfig index 5fead7bb8..2fbeb8fa3 100644 --- a/nuttx/configs/sim/nxwm/defconfig +++ b/nuttx/configs/sim/nxwm/defconfig @@ -32,7 +32,6 @@ # POSSIBILITY OF SUCH DAMAGE. # ############################################################################ -CONFIG_NXWM_TASKBAR_LEFT=y # # Architecture selection # @@ -281,6 +280,14 @@ CONFIG_HAVE_LIBM=y # CONFIG_NAME_MAX - The maximum size of a file name. # CONFIG_STDIO_BUFFER_SIZE - Size of the buffer to allocate # on fopen. (Only if CONFIG_NFILE_STREAMS > 0) +# CONFIG_STDIO_LINEBUFFER - If standard C buffered I/O is enabled +# (CONFIG_STDIO_BUFFER_SIZE > 0), then this option may be added +# to force automatic, line-oriented flushing the output buffer +# for putc(), fputc(), putchar(), puts(), fputs(), printf(), +# fprintf(), and vfprintf(). When a newline is encountered in +# the output string, the output buffer will be flushed. This +# (slightly) increases the NuttX footprint but supports the kind +# of behavior that people expect for printf(). # CONFIG_NUNGET_CHARS - Number of characters that can be # buffered by ungetc() (Only if CONFIG_NFILE_STREAMS > 0) # CONFIG_PREALLOC_MQ_MSGS - The number of pre-allocated message @@ -305,7 +312,8 @@ CONFIG_NPTHREAD_KEYS=4 CONFIG_NFILE_DESCRIPTORS=16 CONFIG_NFILE_STREAMS=16 CONFIG_NAME_MAX=32 -CONFIG_STDIO_BUFFER_SIZE=1024 +CONFIG_STDIO_BUFFER_SIZE=256 +CONFIG_STDIO_LINEBUFFER=y CONFIG_NUNGET_CHARS=2 CONFIG_PREALLOC_MQ_MSGS=32 CONFIG_MQ_MAXMSGSIZE=32 @@ -545,17 +553,23 @@ CONFIG_NX_MXSERVERMSGS=32 CONFIG_NX_MXCLIENTMSGS=16 # -# NxWidgets +# NxWidgets / NxWM # # Use all defaults except # 1. Need an especially big server stack size to work with X # 2. Make the NxWidgets background color match the NxWM back color +# 3. Taskbar on the left +# 4. Bigger stack for NxConsole # CONFIG_NXWIDGETS_SERVERSTACK=16384 CONFIG_NXWIDGETS_LISTENERSTACK=8192 CONFIG_NXWIDGETS_DEFAULT_BACKGROUNDCOLOR=MKRGB(148,189,215) CONFIG_NXWIDGETS_DEFAULT_SELECTEDBACKGROUNDCOLOR=MKRGB(206,227,241) +CONFIG_NXWM_TASKBAR_LEFT=y +CONFIG_NXWM_NXCONSOLE_STACKSIZE=8192 +CONFIG_NXWM_UNITTEST=y + # # NxConsole Configuration Settings: # diff --git a/nuttx/include/cxx/cunistd b/nuttx/include/cxx/cunistd index 2ddc84144..2f0b71270 100755 --- a/nuttx/include/cxx/cunistd +++ b/nuttx/include/cxx/cunistd @@ -41,6 +41,7 @@ //*************************************************************************** #include + //*************************************************************************** // Namespace //*************************************************************************** @@ -49,6 +50,8 @@ namespace std { using ::getpid; using ::_exit; + using ::sleep; + using ::usleep; using ::close; using ::dup; using ::dup2; diff --git a/nuttx/libxx/README.txt b/nuttx/libxx/README.txt index c97dae4ba..6cf066f08 100644 --- a/nuttx/libxx/README.txt +++ b/nuttx/libxx/README.txt @@ -1,36 +1,37 @@ -libxx/README.txt -^^^^^^^^^^^^^^^^ - -This directory contains a fragmentary C++ library that will allow -to build only the simplest of C++ applications. In the deeply -embedded world, that is probably all that is necessary. If you -have a need for more extensive C++ support, the following libraries -are recommended: - - - libstdc++ (part of GCC) - - STLport http://www.stlport.org/ - - uClibc++ http://cxx.uclibc.org/ - -At present, only the following are supported here: - - - void *operator new(std::size_t nbytes); - - void operator delete(void* ptr); - - void operator delete[](void *ptr); - - void __cxa_pure_virtual(void); - - int __aeabi_atexit(void* object, void (*destroyer)(void*), void *dso_handle); - -operator new ------------- - - This operator should take a type of size_t. But size_t has an unknown underlying - type. In the nuttx sys/types.h header file, size_t is typed as uint32_t - (which is determined by architecture-specific logic). But the C++ - compiler may believe that size_t is of a different type resulting in - compilation errors in the operator. Using the underlying integer type - instead of size_t seems to resolve the compilation issues. Need to - REVISIT this. - - Once some C++ compilers, this will cause an error: - - Problem: "'operator new' takes size_t ('...') as first parameter" - Workaround: Add -fpermissive to the compilation flags +libxx/README.txt +^^^^^^^^^^^^^^^^ + +This directory contains a fragmentary C++ library that will allow +to build only the simplest of C++ applications. In the deeply +embedded world, that is probably all that is necessary. If you +have a need for more extensive C++ support, the following libraries +are recommended: + + - libstdc++ (part of GCC) + - STLport http://www.stlport.org/ + - uClibc++ http://cxx.uclibc.org/ + - uSTL http://ustl.sourceforge.net/ + +At present, only the following are supported here: + + - void *operator new(std::size_t nbytes); + - void operator delete(void* ptr); + - void operator delete[](void *ptr); + - void __cxa_pure_virtual(void); + - int __aeabi_atexit(void* object, void (*destroyer)(void*), void *dso_handle); + +operator new +------------ + + This operator should take a type of size_t. But size_t has an unknown underlying + type. In the nuttx sys/types.h header file, size_t is typed as uint32_t + (which is determined by architecture-specific logic). But the C++ + compiler may believe that size_t is of a different type resulting in + compilation errors in the operator. Using the underlying integer type + instead of size_t seems to resolve the compilation issues. Need to + REVISIT this. + + Once some C++ compilers, this will cause an error: + + Problem: "'operator new' takes size_t ('...') as first parameter" + Workaround: Add -fpermissive to the compilation flags