examples/cpuhog and serialblaster from Bob Doiron

This commit is contained in:
Gregory Nutt 2014-04-22 07:52:08 -06:00
parent 10e5365132
commit e322fe1543
13 changed files with 550 additions and 13 deletions

View File

@ -891,4 +891,6 @@
* apps/system/sdcard: Remove an STM32 dependency. From Bob Doiron
(2014-4-21).
* apps/nshlib: malloc/free IOBUFFER for 'cat' and 'hexdump' commands
instead of using the stack. From Bob Doiron (2014-4-21).
instead of using the stack. From Bob Doiron (2014-4-21).
* apps/examples/cpuhog and serialblaster: Stress test examples added
by Bob Doiron (2014-4-22).

View File

@ -8,6 +8,7 @@ source "$APPSDIR/examples/buttons/Kconfig"
source "$APPSDIR/examples/can/Kconfig"
source "$APPSDIR/examples/cc3000/Kconfig"
source "$APPSDIR/examples/configdata/Kconfig"
source "$APPSDIR/examples/cpuhog/Kconfig"
source "$APPSDIR/examples/cxxtest/Kconfig"
source "$APPSDIR/examples/dhcpd/Kconfig"
source "$APPSDIR/examples/elf/Kconfig"
@ -49,6 +50,7 @@ source "$APPSDIR/examples/relays/Kconfig"
source "$APPSDIR/examples/rgmp/Kconfig"
source "$APPSDIR/examples/romfs/Kconfig"
source "$APPSDIR/examples/sendmail/Kconfig"
source "$APPSDIR/examples/serialblaster/Kconfig"
source "$APPSDIR/examples/serloop/Kconfig"
source "$APPSDIR/examples/slcd/Kconfig"
source "$APPSDIR/examples/flash_test/Kconfig"

View File

@ -54,6 +54,10 @@ ifeq ($(CONFIG_EXAMPLES_CONFIGDATA),y)
CONFIGURED_APPS += examples/configdata
endif
ifeq ($(CONFIG_EXAMPLES_CPUHOG),y)
CONFIGURED_APPS += examples/cpuhog
endif
ifeq ($(CONFIG_EXAMPLES_CXXTEST),y)
CONFIGURED_APPS += examples/cxxtest
endif
@ -222,6 +226,10 @@ ifeq ($(CONFIG_EXAMPLES_SENDMAIL),y)
CONFIGURED_APPS += examples/sendmail
endif
ifeq ($(CONFIG_EXAMPLES_SERIALBLASTER),y)
CONFIGURED_APPS += examples/serialblaster
endif
ifeq ($(CONFIG_EXAMPLES_SERLOOP),y)
CONFIGURED_APPS += examples/serloop
endif

View File

@ -37,14 +37,15 @@
# Sub-directories
SUBDIRS = adc buttons can cc3000 cxxtest dhcpd discover elf flash_test
SUBDIRS += ftpc ftpd hello helloxx hidkbd igmp i2schar json keypadtest
SUBDIRS += lcdrw mm modbus mount mtdpart nettest nrf24l01_term nsh null nx
SUBDIRS += nxconsole nxffs nxflat nxhello nximage nxlines nxtext ostest
SUBDIRS += pashello pipe poll posix_spawn pwm qencoder random relays rgmp
SUBDIRS += romfs sendmail serloop slcd smart smart_test tcpecho telnetd
SUBDIRS += thttpd tiff touchscreen udp uip usbserial usbterm watchdog
SUBDIRS += wget wgetjson xmlrpc
SUBDIRS = adc buttons can cc3000 cpuhog cxxtest dhcpd discover elf
SUBDIRS += flash_test ftpc ftpd hello helloxx hidkbd igmp i2schar json
SUBDIRS += keypadtest lcdrw mm modbus mount mtdpart nettest nrf24l01_term
SUBDIRS += nsh null nx nxconsole nxffs nxflat nxhello nximage nxlines
SUBDIRS += nxtext ostest pashello pipe poll posix_spawn pwm qencoder random
SUBDIRS += relays rgmp romfs sendmail serialblaster serloop slcd smart
SUBDIRS += smart_test tcpecho telnetd thttpd tiff touchscreen udp uip
SUBDIRS += usbserial usbterm watchdog wget wgetjson xmlrpc
# Sub-directories that might need context setup. Directories may need
# context setup for a variety of reasons, but the most common is because
@ -53,11 +54,11 @@ SUBDIRS += wget wgetjson xmlrpc
CNTXTDIRS = pwm
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
CNTXTDIRS += adc can cc3000 cxxtest dhcpd discover flash_test ftpd
CNTXTDIRS += adc can cc3000 cpuhog cxxtest dhcpd discover flash_test ftpd
CNTXTDIRS += hello helloxx i2schar json keypadtestmodbus lcdrw mtdpart
CNTXTDIRS += nettest nx nxhello nximage nxlines nxtext nrf24l01_term
CNTXTDIRS += ostest random relays qencoder slcd smart_test tcpecho telnetd
CNTXTDIRS += tiff touchscreen usbterm watchdog wgetjson
CNTXTDIRS += ostest random relays qencoder serialblasterslcd smart_test
CNTXTDIRS += tcpecho telnetd tiff touchscreen usbterm watchdog wgetjson
endif
all: nothing

View File

@ -121,11 +121,18 @@ examples/configdata
This is a Unit Test for the MTD configuration data driver
examples/cpuhog
^^^^^^^^^^^^^^^
Attempts to keep the system busy by passing data through a pipe in loop
back mode. This may be useful if you are trying run down other problems
that you think might only occur when the system is very busy.
examples/cxxtest
^^^^^^^^^^^^^^^^
This is a test of the C++ standard library. At present a port of the uClibc++
C++ library is available. Due to licensinging issues, the uClibc++ C++ library
C++ library is available. Due to licensing issues, the uClibc++ C++ library
is not included in the NuttX source tree by default, but must be installed
(see misc/uClibc++/README.txt for installation).
@ -1442,6 +1449,13 @@ examples/sendmail
CONFIG_NETUTILS_UIPLIB=y
CONFIG_NETUTILS_SMTP=y
examples/serialblaster
^^^^^^^^^^^^^^^^^^^^^^
Sends a repeating pattern (the alphabet) out a serial por continuously.
This may be useful if you are trying run down other problems that you
think might only occur when the serial port usage is high.
examples/serloop
^^^^^^^^^^^^^^^^

11
examples/cpuhog/.gitignore vendored Normal file
View File

@ -0,0 +1,11 @@
/Make.dep
/.depend
/.built
/*.asm
/*.obj
/*.rel
/*.lst
/*.sym
/*.adb
/*.lib
/*.src

13
examples/cpuhog/Kconfig Normal file
View File

@ -0,0 +1,13 @@
#
# For a description of the syntax of this configuration file,
# see misc/tools/kconfig-language.txt.
#
config EXAMPLES_CPUHOG
bool "CPU Hog"
default n
---help---
Enable the cpuhog example
if EXAMPLES_CPUHOG
endif

109
examples/cpuhog/Makefile Normal file
View File

@ -0,0 +1,109 @@
############################################################################
# apps/examples/cpuhog/Makefile
#
# Copyright (C) 2014 Gregory Nutt. All rights reserved.
# 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
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name NuttX nor the names of its contributors may be
# used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
############################################################################
-include $(TOPDIR)/.config
-include $(TOPDIR)/Make.defs
include $(APPDIR)/Make.defs
# do nothing loop to use up cpu time
ASRCS =
CSRCS = cpuhog_main.c
AOBJS = $(ASRCS:.S=$(OBJEXT))
COBJS = $(CSRCS:.c=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS)
OBJS = $(AOBJS) $(COBJS)
ifeq ($(CONFIG_WINDOWS_NATIVE),y)
BIN = ..\..\libapps$(LIBEXT)
else
ifeq ($(WINTOOL),y)
BIN = ..\\..\\libapps$(LIBEXT)
else
BIN = ../../libapps$(LIBEXT)
endif
endif
ROOTDEPPATH = --dep-path .
# Built-in application info
APPNAME = cpuhog
PRIORITY = SCHED_PRIORITY_LOW
STACKSIZE = 1024
# Common build
VPATH =
all: .built
.PHONY: clean depend distclean
$(AOBJS): %$(OBJEXT): %.S
$(call ASSEMBLE, $<, $@)
$(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
.built: $(OBJS)
$(call ARCHIVE, $(BIN), $(OBJS))
@touch .built
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat: $(DEPCONFIG) Makefile
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat
else
context:
endif
.depend: Makefile $(SRCS)
@$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
@touch $@
depend: .depend
clean:
$(call DELFILE, .built)
$(call CLEAN)
distclean: clean
$(call DELFILE, Make.dep)
$(call DELFILE, .depend)
-include Make.dep

View File

@ -0,0 +1,163 @@
/****************************************************************************
* examples/cpuhog/cpuhog_main.c
*
* Copyright (C) 2014 Gregory Nutt. All rights reserved.
* 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
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <stdio.h>
#include <unistd.h>
#include <nuttx/clock.h>
#include <nuttx/arch.h>
#include <semaphore.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/stat.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define CPUHOG_FIFO_FNAME "/dev/cpuhogfifo"
/****************************************************************************
* Private Data
****************************************************************************/
static struct state_s
{
volatile bool initialized;
sem_t sem;
int count;
} g_state;
/****************************************************************************
* Public Functions
****************************************************************************/
int cpuhog_main(int argc, char *argv[])
{
int id = -1;
char buf[256];
int fd = -1;
if (!g_state.initialized)
{
sem_init(&g_state.sem, 0, 1);
mkfifo(CPUHOG_FIFO_FNAME, 0666);
g_state.count = 0;
g_state.initialized = true;
printf("cpuhog initialized\n");
}
while(1)
{
/* To test semaphore interaction (debugging system crashes...) */
while (sem_wait(&g_state.sem) != 0)
{
ASSERT(errno == EINTR);
}
/* Burn some inside semlock */
up_udelay(3000);
sem_post(&g_state.sem);
/* Unassigned */
if (id == -1)
{
id = g_state.count++;
printf("cpuhog %d", id);
if (id == 0)
{
printf(": consumer\n");
fd = open(CPUHOG_FIFO_FNAME, O_RDONLY);
}
else if (id == 1)
{
printf(": producer\n");
fd = open(CPUHOG_FIFO_FNAME, O_WRONLY);
}
else
{
printf("\n");
}
}
/* Consumer */
else if (id == 0)
{
if (read(fd, buf, sizeof(buf)) > 0)
{
printf("-");
}
else
{
perror("fifo: ");
}
}
/* Producer */
else if (id == 1)
{
if (write(fd, buf, sizeof(buf)) > 0)
{
printf("+");
}
else
{
perror("fifo: ");
}
}
/* Otherwise just a cpu burner */
else
{
/* Burn some outside semlock */
up_udelay(3000);
}
}
return 0;
}

11
examples/serialblaster/.gitignore vendored Normal file
View File

@ -0,0 +1,11 @@
/Make.dep
/.depend
/.built
/*.asm
/*.obj
/*.rel
/*.lst
/*.sym
/*.adb
/*.lib
/*.src

View File

@ -0,0 +1,13 @@
#
# For a description of the syntax of this configuration file,
# see misc/tools/kconfig-language.txt.
#
config EXAMPLES_SERIALBLASTER
bool "Serial Blaster example"
default n
---help---
Enable the serial blaster example
if EXAMPLES_SERIALBLASTER
endif

View File

@ -0,0 +1,109 @@
############################################################################
# apps/examples/serialblaster/Makefile
#
# Copyright (C) 2014 Gregory Nutt. All rights reserved.
# 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
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name NuttX nor the names of its contributors may be
# used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
############################################################################
-include $(TOPDIR)/.config
-include $(TOPDIR)/Make.defs
include $(APPDIR)/Make.defs
# For testing: Blast canned characters at a designated serial port
ASRCS =
CSRCS = serialblaster_main.c
AOBJS = $(ASRCS:.S=$(OBJEXT))
COBJS = $(CSRCS:.c=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS)
OBJS = $(AOBJS) $(COBJS)
ifeq ($(CONFIG_WINDOWS_NATIVE),y)
BIN = ..\..\libapps$(LIBEXT)
else
ifeq ($(WINTOOL),y)
BIN = ..\\..\\libapps$(LIBEXT)
else
BIN = ../../libapps$(LIBEXT)
endif
endif
ROOTDEPPATH = --dep-path .
# Built-in application info
APPNAME = serialblaster
PRIORITY = SCHED_PRIORITY_DEFAULT
STACKSIZE = 2048
# Common build
VPATH =
all: .built
.PHONY: clean depend distclean
$(AOBJS): %$(OBJEXT): %.S
$(call ASSEMBLE, $<, $@)
$(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
.built: $(OBJS)
$(call ARCHIVE, $(BIN), $(OBJS))
@touch .built
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat: $(DEPCONFIG) Makefile
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat
else
context:
endif
.depend: Makefile $(SRCS)
@$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
@touch $@
depend: .depend
clean:
$(call DELFILE, .built)
$(call CLEAN)
distclean: clean
$(call DELFILE, Make.dep)
$(call DELFILE, .depend)
-include Make.dep

View File

@ -0,0 +1,81 @@
/****************************************************************************
* examples/serialblaster/serialblaster_main.c
*
* Copyright (C) 2014 Gregory Nutt. All rights reserved.
* 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
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <stdio.h>
#include <unistd.h>
#include <nuttx/clock.h>
#include <nuttx/fs/fs.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define BUFFERED_IO
/****************************************************************************
* Private Data
****************************************************************************/
static const char s[] = "abcdefghijklmnopqrstuvwxyz";
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* serloop_main
****************************************************************************/
int serialblaster_main(int argc, char *argv[])
{
while(1)
{
#ifdef BUFFERED_IO
int ret = fputs(s, stdout);
#else
int ret = write(1, s, sizeof(s)-1);
#endif
}
return 0;
}