Add nuttx to the system framework, which is 10.1.0

This commit is contained in:
TangYiwen123
2021-06-09 14:33:15 +08:00
parent 06c351e27c
commit 804bd57aa0
5000 changed files with 1488544 additions and 0 deletions
@@ -0,0 +1,134 @@
############################################################################
# apps/examples/elf/tests/Makefile
#
# Copyright (C) 2012, 2014, 2018 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 $(APPDIR)/Make.defs
ALL_SUBDIRS = errno hello helloxx longjmp mutex pthread signal task struct
BUILD_SUBDIRS = errno hello struct signal
ifeq ($(CONFIG_HAVE_CXX),y)
BUILD_SUBDIRS += helloxx
endif
ifeq ($(CONFIG_EXAMPLES_ELF_LONGJMP),y)
BUILD_SUBDIRS += longjmp
endif
ifneq ($(CONFIG_DISABLE_PTHREAD),y)
BUILD_SUBDIRS += mutex pthread
endif
ifneq ($(CONFIG_ARCH_ADDRENV),y)
BUILD_SUBDIRS += task
endif
ELF_DIR = $(APPDIR)/examples/elf
TESTS_DIR = $(ELF_DIR)/tests
DIRLIST_SRC = $(TESTS_DIR)/dirlist.c
SYMTAB_SRC = $(TESTS_DIR)/symtab.c
ifeq ($(CONFIG_EXAMPLES_ELF_ROMFS),y)
FSIMG_SUBDIR = romfs
FSIMG_DIR = $(TESTS_DIR)/$(FSIMG_SUBDIR)
ROMFS_IMG = $(TESTS_DIR)/romfs.img
FSIMG_SRC = $(TESTS_DIR)/romfs.c
else
NXTOOLDIR = $(TOPDIR)/tools
GENCROMFSSRC = gencromfs.c
GENCROMFSEXE = gencromfs$(HOSTEXEEXT)
FSIMG_SUBDIR = cromfs
FSIMG_DIR = $(TESTS_DIR)/$(FSIMG_SUBDIR)
FSIMG_SRC = $(TESTS_DIR)/cromfs.c
endif
define DIR_template
$(1)_$(2):
+$(Q) $(MAKE) -C $(1) $(2) TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)" FSIMG_DIR="$(FSIMG_DIR)" CROSSDEV=$(CROSSDEV)
endef
all: $(FSIMG_SRC) $(DIRLIST_SRC) $(SYMTAB_SRC)
.PHONY: all clean install
$(foreach DIR, $(ALL_SUBDIRS), $(eval $(call DIR_template,$(DIR),clean)))
$(foreach DIR, $(BUILD_SUBDIRS), $(eval $(call DIR_template,$(DIR),install)))
# Install each program in the file system image directory
install: $(foreach DIR, $(BUILD_SUBDIRS), $(DIR)_install)
ifeq ($(CONFIG_EXAMPLES_ELF_ROMFS),y)
# Create the romfs.img file from the populated romfs directory
$(ROMFS_IMG): install
$(Q) genromfs -f $@.tmp -d $(FSIMG_DIR) -V "ELFTEST"
$(Q) $(call TESTANDREPLACEFILE, $@.tmp, $@)
# Create the romfs.c file from the romfs.img file
$(FSIMG_SRC): $(ROMFS_IMG)
$(Q) (cd $(TESTS_DIR); xxd -i romfs.img | sed -e "s/^unsigned/const unsigned/g" >$@)
else
# Make sure that the NuttX gencromfs tool has been built
$(NXTOOLDIR)/$(GENCROMFSEXE): $(NXTOOLDIR)/$(GENCROMFSSRC)
$(Q) $(MAKE) -C $(NXTOOLDIR) -f Makefile.host $(GENCROMFSEXE)
# Create the cromfs.h header file from the populated cromfs directory
$(FSIMG_SRC): install $(NXTOOLDIR)/$(GENCROMFSEXE)
$(Q) $(NXTOOLDIR)/$(GENCROMFSEXE) $(FSIMG_DIR) $@.tmp
$(Q) $(call TESTANDREPLACEFILE, $@.tmp, $@)
endif
# Create the dirlist.h header file from the file system image directory
$(DIRLIST_SRC): install
$(Q) $(TESTS_DIR)/mkdirlist.sh $(FSIMG_DIR) >$@.tmp
$(Q) $(call TESTANDREPLACEFILE, $@.tmp, $@)
# Create the exported symbol table
$(SYMTAB_SRC): install
$(Q) $(APPDIR)$(DELIM)tools$(DELIM)mksymtab.sh $(FSIMG_DIR) g_elf >$@.tmp
$(Q) $(call TESTANDREPLACEFILE, $@.tmp, $@)
# Clean each subdirectory
clean: $(foreach DIR, $(ALL_SUBDIRS), $(DIR)_clean)
$(Q) rm -f $(FSIMG_SRC) $(DIRLIST_SRC) $(ROMFS_IMG) $(SYMTAB_SRC)
$(Q) rm -rf $(FSIMG_DIR)
@@ -0,0 +1,83 @@
############################################################################
# examples/elf/tests/errno/Makefile
#
# Copyright (C) 2012, 2014, 2016 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 $(APPDIR)/Make.defs
ifeq ($(CONFIG_EXAMPLES_ELF_SYSCALL),y)
LDELFFLAGS += -Bstatic
LDLIBPATH += -L $(NUTTXLIB)
else
ifeq ($(CONFIG_EXAMPLES_ELF_LIBC),y)
LDELFFLAGS += -Bstatic
LDLIBPATH += -L $(NUTTXLIB)
endif
endif
ifeq ($(CONFIG_EXAMPLES_ELF_LIBC),y)
LDLIBS += -lc
endif
ifeq ($(CONFIG_EXAMPLES_ELF_SYSCALL),y)
LDLIBS += -lproxies
endif
BIN = errno
SRCS = $(BIN).c
OBJS = $(SRCS:.c=$(OBJEXT))
all: $(BIN)
.PHONY: all clean install
$(OBJS): %$(OBJEXT): %.c
@echo "CC: $<"
$(Q) $(CC) -c $(CELFFLAGS) $< -o $@
$(BIN): $(OBJS)
@echo "LD: $<"
$(Q) $(LD) $(LDELFFLAGS) $(LDLIBPATH) -o $@ $(ARCHCRT0OBJ) $^ $(LDLIBS)
$(FSIMG_DIR)/$(BIN): $(BIN)
$(Q) mkdir -p $(FSIMG_DIR)
$(Q) install $(BIN) $(FSIMG_DIR)/$(BIN)
ifneq ($(CONFIG_DEBUG_SYMBOLS),y)
$(Q) $(STRIP) $(FSIMG_DIR)/$(BIN)
endif
install: $(FSIMG_DIR)/$(BIN)
clean:
$(call DELFILE, $(BIN))
$(call CLEAN)
@@ -0,0 +1,83 @@
/****************************************************************************
* examples/elf/tests/errno/errno.c
*
* Copyright (C) 2012 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 <stdio.h>
#include <stdlib.h>
#include <errno.h>
/****************************************************************************
* Included Files
****************************************************************************/
static const char g_nonexistent[] = "aflav-sautga-ay";
/****************************************************************************
* Public Functions
****************************************************************************/
int main(int argc, char **argv)
{
FILE *test_stream;
/* Try using stdout and stderr explicitly. These are global variables
* exported from the base code.
*/
fprintf(stdout, "Hello, World on stdout\n");
fprintf(stderr, "Hello, World on stderr\n");
/* Try opening a non-existent file using buffered IO. */
test_stream = fopen(g_nonexistent, "r");
if (test_stream)
{
fprintf(stderr, "Hmm... Delete \"%s\" and try this again\n",
g_nonexistent);
exit(1);
}
/* Now print the errno on stderr. Errno is also a global
* variable exported by the base code.
*/
fprintf(stderr, "We failed to open \"%s!\" errno is %d\n",
g_nonexistent, errno);
return 0;
}
@@ -0,0 +1,83 @@
############################################################################
# examples/elf/tests/hello/Makefile
#
# Copyright (C) 2012, 2014, 2016 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 $(APPDIR)/Make.defs
ifeq ($(CONFIG_EXAMPLES_ELF_SYSCALL),y)
LDELFFLAGS += -Bstatic
LDLIBPATH += -L $(NUTTXLIB)
else
ifeq ($(CONFIG_EXAMPLES_ELF_LIBC),y)
LDELFFLAGS += -Bstatic
LDLIBPATH += -L $(NUTTXLIB)
endif
endif
ifeq ($(CONFIG_EXAMPLES_ELF_LIBC),y)
LDLIBS += -lc
endif
ifeq ($(CONFIG_EXAMPLES_ELF_SYSCALL),y)
LDLIBS += -lproxies
endif
BIN = hello
SRCS = $(BIN).c
OBJS = $(SRCS:.c=$(OBJEXT))
all: $(BIN)
.PHONY: all clean install
$(OBJS): %$(OBJEXT): %.c
@echo "CC: $<"
$(Q) $(CC) -c $(CELFFLAGS) $< -o $@
$(BIN): $(OBJS)
@echo "LD: $<"
$(Q) $(LD) $(LDELFFLAGS) $(LDLIBPATH) -o $@ $(ARCHCRT0OBJ) $^ $(LDLIBS)
$(FSIMG_DIR)/$(BIN): $(BIN)
$(Q) mkdir -p $(FSIMG_DIR)
$(Q) install $(BIN) $(FSIMG_DIR)/$(BIN)
ifneq ($(CONFIG_DEBUG_SYMBOLS),y)
$(Q) $(STRIP) $(FSIMG_DIR)/$(BIN)
endif
install: $(FSIMG_DIR)/$(BIN)
clean:
$(call DELFILE, $(BIN))
$(call CLEAN)
@@ -0,0 +1,78 @@
/****************************************************************************
* examples/elf/tests/hello/hello.c
*
* Copyright (C) 2012 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 <stdio.h>
#include <stdlib.h>
/****************************************************************************
* Public Functions
****************************************************************************/
int main(int argc, char **argv)
{
int i;
/* Mandatory "Hello, world!" */
puts("Getting ready to say \"Hello, world\"\n");
printf("Hello, world!\n");
puts("It has been said.\n");
/* Print arguments */
printf("argc\t= %d\n", argc);
printf("argv\t= 0x%p\n", argv);
for (i = 0; i < argc; i++)
{
printf("argv[%d]\t= ", i);
if (argv[i])
{
printf("(0x%p) \"%s\"\n", argv[i], argv[i]);
}
else
{
printf("NULL?\n");
}
}
printf("argv[%d]\t= 0x%p\n", argc, argv[argc]);
printf("Goodbye, world!\n");
return 0;
}
@@ -0,0 +1,188 @@
############################################################################
# examples/elf/tests/helloxx/Makefile
#
# Copyright (C) 2012, 2014-2016 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 $(APPDIR)/Make.defs
ifeq ($(CONFIG_EXAMPLES_ELF_SYSCALL),y)
LDELFFLAGS += -Bstatic
LDLIBPATH += -L $(NUTTXLIB)
else
ifeq ($(CONFIG_EXAMPLES_ELF_LIBC),y)
LDELFFLAGS += -Bstatic
LDLIBPATH += -L $(NUTTXLIB)
endif
endif
ifeq ($(CONFIG_EXAMPLES_ELF_LIBC),y)
LDLIBS += -lc
endif
ifeq ($(CONFIG_EXAMPLES_ELF_SYSCALL),y)
LDLIBS += -lproxies
endif
BIN1 = hello++1
ALL_BIN = $(FSIMG_DIR)/$(BIN1)
BIN2 = hello++2
ALL_BIN += $(FSIMG_DIR)/$(BIN2)
ifeq ($(CONFIG_HAVE_CXXINITIALIZE),y)
BIN3 = hello++3
ALL_BIN += $(FSIMG_DIR)/$(BIN3)
ifeq ($(CONFIG_EXAMPLES_ELF_CXX),y)
BIN4 = hello++4
ALL_BIN += $(FSIMG_DIR)/$(BIN4)
BIN5 = hello++5
ALL_BIN += $(FSIMG_DIR)/$(BIN5)
endif
endif
SRCS1 = $(BIN1).c
OBJS1 = $(SRCS1:.c=$(OBJEXT))
SRCS2 = $(BIN2).c
OBJS2 = $(SRCS2:.c=$(OBJEXT))
ifeq ($(CONFIG_HAVE_CXXINITIALIZE),y)
SRCS3 = $(BIN3).c
OBJS3 = $(SRCS3:.c=$(OBJEXT))
ifeq ($(CONFIG_EXAMPLES_ELF_CXX),y)
SRCS4 = $(BIN4).c
OBJS4 = $(SRCS4:.c=$(OBJEXT))
SRCS5 = $(BIN5).c
OBJS5 = $(SRCS5:.c=$(OBJEXT))
endif
endif
SRCS = $(SRCS1) $(SRCS2) $(SRCS3) $(SRCS4) $(SRCS5)
OBJS = $(OBJS1) $(OBJS2) $(OBJS3) $(OBJS4) $(OBJS5)
LDLIBSTDC_STUBS_DIR = $(TOPDIR)/libxx
LDLIBSTDC_STUBS_LIB = $(LDLIBSTDC_STUBS_DIR)/liblibxx.a
all: $(BIN1) $(BIN2) $(BIN3) $(BIN4) $(BIN5)
.PHONY: all clean install
$(OBJS): %$(OBJEXT): %.cxx
@echo "CC: $<"
$(Q) $(CXX) -c $(CXXELFFLAGS) $< -o $@
# This contains libstdc++ stubs to that you can build C++ code
# without actually having libstdc++
$(LDLIBSTDC_STUBS_LIB):
$(Q) $(MAKE) -C $(LDLIBSTDC_STUBS_DIR) TOPDIR=$(TOPDIR)
# BIN1 and BIN2 link just like C code because they contain no
# static constructors. BIN1 is equivalent to a C hello world;
# BIN2 contains a class that implements hello world, but it is
# not statically initialized.
$(BIN1): $(OBJS1)
@echo "LD: $<"
$(Q) $(LD) $(LDELFFLAGS) $(LDLIBPATH) -o $@ $(ARCHCRT0OBJ) $^ $(LDLIBS)
$(BIN2): $(OBJS2)
@echo "LD: $<"
$(Q) $(LD) $(LDELFFLAGS) $(LDLIBPATH) -o $@ $(ARCHCRT0OBJ) $^ $(LDLIBS)
# BIN3 is equivalent to BIN2 except that is uses static initializers
ifeq ($(CONFIG_HAVE_CXXINITIALIZE),y)
$(BIN3): $(OBJS3)
@echo "LD: $<"
$(Q) $(LD) $(LDELFFLAGS) $(LDLIBPATH) -o $@ $(ARCHCRT0OBJ) $^ $(LDLIBS)
# BIN4 is similar to BIN3 except that it uses the streams code from libstdc++
#
# NOTE: libstdc++ is not available for NuttX as of this writing
#
ifeq ($(CONFIG_EXAMPLES_ELF_CXX),y)
$(BIN4): $(OBJS4)
@echo "LD: $<"
$(Q) $(LD) $(LDELFFLAGS) $(LDLIBPATH) -o $@ $(ARCHCRT0OBJ) $^ $(LDLIBS)
$(BIN5): $(OBJS5)
@echo "LD: $<"
$(Q) $(LD) $(LDELFFLAGS) $(LDLIBPATH) -o $@ $(ARCHCRT0OBJ) $^ $(LDLIBS)
endif
endif
$(FSIMG_DIR)/$(BIN1): $(BIN1)
$(Q) mkdir -p $(FSIMG_DIR)
$(Q) install $(BIN1) $(FSIMG_DIR)/$(BIN1)
ifneq ($(CONFIG_DEBUG_SYMBOLS),y)
$(Q) $(STRIP) $(FSIMG_DIR)/$(BIN1)
endif
$(FSIMG_DIR)/$(BIN2): $(BIN2)
$(Q) mkdir -p $(FSIMG_DIR)
$(Q) install $(BIN2) $(FSIMG_DIR)/$(BIN2)
ifneq ($(CONFIG_DEBUG_SYMBOLS),y)
$(Q) $(STRIP) $(FSIMG_DIR)/$(BIN2)
endif
ifeq ($(CONFIG_HAVE_CXXINITIALIZE),y)
$(FSIMG_DIR)/$(BIN3): $(BIN3)
$(Q) mkdir -p $(FSIMG_DIR)
$(Q) install $(BIN3) $(FSIMG_DIR)/$(BIN3)
ifneq ($(CONFIG_DEBUG_SYMBOLS),y)
$(Q) $(STRIP) $(FSIMG_DIR)/$(BIN3)
endif
ifeq ($(CONFIG_EXAMPLES_ELF_CXX),y)
$(FSIMG_DIR)/$(BIN4): $(BIN4)
$(Q) mkdir -p $(FSIMG_DIR)
$(Q) install $(BIN4) $(FSIMG_DIR)/$(BIN4)
ifneq ($(CONFIG_DEBUG_SYMBOLS),y)
$(Q) $(STRIP) $(FSIMG_DIR)/$(BIN4)
endif
$(FSIMG_DIR)/$(BIN5): $(BIN5)
$(Q) mkdir -p $(FSIMG_DIR)
$(Q) install $(BIN5) $(FSIMG_DIR)/$(BIN5)
ifneq ($(CONFIG_DEBUG_SYMBOLS),y)
$(Q) $(STRIP) $(FSIMG_DIR)/$(BIN5)
endif
endif
endif
install: $(ALL_BIN)
clean:
$(call DELFILE, $(BIN1))
$(call DELFILE, $(BIN2))
$(call DELFILE, $(BIN3))
$(call DELFILE, $(BIN4))
$(call DELFILE, $(BIN5))
$(call CLEAN)
@@ -0,0 +1,60 @@
/////////////////////////////////////////////////////////////////////////////
// apps/examples/elf/tests/helloxx/hello++1.cxx
//
// Copyright (C) 2012 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.
//
/////////////////////////////////////////////////////////////////////////////
//
// This is an trivial version of "Hello, World" program. It illustrates
// that we can build C programs using the C++ compiler.
//
// - Building a C++ program to use the C library
// - No class creation
// - NO Streams
// - NO Static constructor and destructors
//
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Included Files
/////////////////////////////////////////////////////////////////////////////
#include <cstdio>
/////////////////////////////////////////////////////////////////////////////
// Public Functions
/////////////////////////////////////////////////////////////////////////////
int main(int argc, char **argv)
{
printf("Hello, World!\n");
return 0;
}
@@ -0,0 +1,123 @@
/////////////////////////////////////////////////////////////////////////////
// apps/examples/elf/tests/helloxx/hello++2.cxx
//
// Copyright (C) 2012 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.
//
/////////////////////////////////////////////////////////////////////////////
//
// This is an another trivial version of "Hello, World" design. It illustrates
//
// - Building a C++ program to use the C library
// - Basic class creation
// - NO Streams
// - NO Static constructor and destructors
//
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Included Files
/////////////////////////////////////////////////////////////////////////////
#include <cstdio>
/////////////////////////////////////////////////////////////////////////////
// Classes
/////////////////////////////////////////////////////////////////////////////
class CThingSayer
{
const char *szWhatToSay;
public:
CThingSayer(void)
{
printf("CThingSayer::CThingSayer: I am!\n");
szWhatToSay = (const char*)NULL;
}
~CThingSayer(void)
{
printf("CThingSayer::~CThingSayer: I cease to be\n");
if (szWhatToSay)
{
printf("CThingSayer::~CThingSayer: I will never say '%s' again\n",
szWhatToSay);
}
szWhatToSay = (const char*)NULL;
}
void Initialize(const char *czSayThis)
{
printf("CThingSayer::Initialize: When told, I will say '%s'\n",
czSayThis);
szWhatToSay = czSayThis;
}
void SayThing(void)
{
printf("CThingSayer::SayThing: I am now saying '%s'\n", szWhatToSay);
}
};
/////////////////////////////////////////////////////////////////////////////
// Public Functions
/////////////////////////////////////////////////////////////////////////////
int main(int argc, char **argv)
{
CThingSayer *MyThingSayer;
printf("main: Started. Creating MyThingSayer\n");
// Create an instance of the CThingSayer class
// We should see the message from constructor, CThingSayer::CThingSayer(),
MyThingSayer = new CThingSayer;
printf("main: Created MyThingSayer=0x%08lx\n", (long)MyThingSayer);
// Tell MyThingSayer that "Hello, World!" is the string to be said
printf("main: Calling MyThingSayer->Initialize\n");
MyThingSayer->Initialize("Hello, World!");
// Tell MyThingSayer to say the thing we told it to say
printf("main: Calling MyThingSayer->SayThing\n");
MyThingSayer->SayThing();
// We should see the message from the destructor,
// CThingSayer::~CThingSayer(), AFTER we see the following
printf("main: Destroying MyThingSayer\n");
delete MyThingSayer;
printf("main: Returning\n");
return 0;
}
@@ -0,0 +1,132 @@
/////////////////////////////////////////////////////////////////////////////
// apps/examples/elf/tests/helloxx/hello++3.cxx
//
// Copyright (C) 2012 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.
//
/////////////////////////////////////////////////////////////////////////////
//
// This is an another trivial version of "Hello, World" design. It illustrates
//
// - Building a C++ program to use the C library and stdio
// - Basic class creation with virtual methods.
// - Static constructor and destructors (in main program only)
// - NO Streams
//
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Included Files
/////////////////////////////////////////////////////////////////////////////
#include <cstdio>
/////////////////////////////////////////////////////////////////////////////
// Classes
/////////////////////////////////////////////////////////////////////////////
class CThingSayer
{
const char *szWhatToSay;
public:
CThingSayer(void);
virtual ~CThingSayer(void);
virtual void Initialize(const char *czSayThis);
virtual void SayThing(void);
};
// A static instance of the CThingSayer class. This instance MUST
// be constructed by the system BEFORE the program is started at
// main() and must be destructed by the system AFTER the main()
// returns to the system
static CThingSayer MyThingSayer;
// These are implementations of the methods of the CThingSayer class
CThingSayer::CThingSayer(void)
{
printf("CThingSayer::CThingSayer: I am!\n");
szWhatToSay = (const char*)NULL;
}
CThingSayer::~CThingSayer(void)
{
printf("CThingSayer::~CThingSayer: I cease to be\n");
if (szWhatToSay)
{
printf("CThingSayer::~CThingSayer: I will never say '%s' again\n",
szWhatToSay);
}
szWhatToSay = (const char*)NULL;
}
void CThingSayer::Initialize(const char *czSayThis)
{
printf("CThingSayer::Initialize: When told, I will say '%s'\n",
czSayThis);
szWhatToSay = czSayThis;
}
void CThingSayer::SayThing(void)
{
printf("CThingSayer::SayThing: I am now saying '%s'\n", szWhatToSay);
}
/////////////////////////////////////////////////////////////////////////////
// Public Functions
/////////////////////////////////////////////////////////////////////////////
int main(int argc, char **argv)
{
// We should see the message from constructor, CThingSayer::CThingSayer(),
// BEFORE we see the following messages. That is proof that the
// C++ static initializer is working
printf("main: Started. MyThingSayer should already exist\n");
// Tell MyThingSayer that "Hello, World!" is the string to be said
printf("main: Calling MyThingSayer.Initialize\n");
MyThingSayer.Initialize("Hello, World!");
// Tell MyThingSayer to say the thing we told it to say
printf("main: Calling MyThingSayer.SayThing\n");
MyThingSayer.SayThing();
// We are finished, return. We should see the message from the
// destructor, CThingSayer::~CThingSayer(), AFTER we see the following
// message. That is proof that the C++ static destructor logic
// is working
printf("main: Returning. MyThingSayer should be destroyed\n");
return 0;
}
@@ -0,0 +1,150 @@
/////////////////////////////////////////////////////////////////////////////
// apps/examples/elf/tests/helloxx/hello++4.cxx
//
// Copyright (C) 2012 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.
//
/////////////////////////////////////////////////////////////////////////////
//
// This is an excessively complex version of "Hello, World" design to
// illustrate some basic properties of C++:
//
// - Building a C++ program
// - Streams / statically linked libstdc++
// - Static constructor and destructors (in main program only)
//
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Included Files
/////////////////////////////////////////////////////////////////////////////
#include <cstdio>
#include <iostream>
#ifndef NULL
# define NULL ((void*)0L)
#endif
/////////////////////////////////////////////////////////////////////////////
// Classes
/////////////////////////////////////////////////////////////////////////////
using namespace std;
// A hello world sayer class
class CThingSayer
{
const char *szWhatToSay;
public:
CThingSayer(void);
virtual ~CThingSayer(void);
virtual void Initialize(const char *czSayThis);
virtual void SayThing(void);
};
/////////////////////////////////////////////////////////////////////////////
// Private Data
/////////////////////////////////////////////////////////////////////////////
// A static instance of the CThingSayer class. This instance MUST
// be constructed by the system BEFORE the program is started at
// main() and must be destructed by the system AFTER the main()
// returns to the system
static CThingSayer MyThingSayer;
/////////////////////////////////////////////////////////////////////////////
// Method Implementations
/////////////////////////////////////////////////////////////////////////////
// These are implementations of the methods of the CThingSayer class
CThingSayer::CThingSayer(void)
{
cout << "CThingSayer::CThingSayer: I am!" << endl;
szWhatToSay = (const char*)NULL;
}
CThingSayer::~CThingSayer(void)
{
cout << "CThingSayer::~CThingSayer: I cease to be" << endl;
if (szWhatToSay)
{
cout << "CThingSayer::~CThingSayer: I will never say '"
<< szWhatToSay << "' again" << endl;
}
szWhatToSay = (const char*)NULL;
}
void CThingSayer::Initialize(const char *czSayThis)
{
cout << "CThingSayer::Initialize: When told, I will say '"
<< czSayThis << "'" << endl;
szWhatToSay = czSayThis;
}
void CThingSayer::SayThing(void)
{
cout << "CThingSayer::SayThing: I am now saying '"
<< szWhatToSay << "'" << endl;
}
/////////////////////////////////////////////////////////////////////////////
// Public Functions
/////////////////////////////////////////////////////////////////////////////
int main(int argc, char **argv)
{
// We should see the message from constructor, CThingSayer::CThingSayer(),
// BEFORE we see the following messages. That is proof that the
// C++ static initializer is working
cout << "main: Started" << endl;
// Tell MyThingSayer that "Hello, World!" is the string to be said
cout << "main: Calling MyThingSayer.Initialize" << endl;
MyThingSayer.Initialize("Hello, World!");
// Tell MyThingSayer to say the thing we told it to say
cout << "main: Calling MyThingSayer.SayThing" << endl;
MyThingSayer.SayThing();
// We are finished, return. We should see the message from the
// destructor, CThingSayer::~CThingSayer(), AFTER we see the following
// message. That is proof that the C++ static destructor logic
// is working
cout << "main: Returning" << endl;
return 0;
}
@@ -0,0 +1,297 @@
/////////////////////////////////////////////////////////////////////////////
// apps/examples/elf/tests/helloxx/hello++5.cxx
//
// Copyright (C) 2015 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.
//
/////////////////////////////////////////////////////////////////////////////
//
// This is an excessively complex version of "Hello, World" design to
// illustrate some basic properties of C++:
//
// - Building a C++ program
// - Streams / statically linked libstdc++
// - Static constructor and destructors (in main program only)
// - Exception handling
//
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Included Files
/////////////////////////////////////////////////////////////////////////////
#include <cstdio>
#include <iostream>
#include <string>
#ifndef NULL
# define NULL ((void*)0L)
#endif
/////////////////////////////////////////////////////////////////////////////
// Private Classes
/////////////////////////////////////////////////////////////////////////////
using namespace std;
// A hello world sayer class
class CThingSayer
{
const char *szWhatToSay;
public:
CThingSayer(void);
virtual ~CThingSayer(void);
virtual void Initialize(const char *czSayThis);
virtual void SayThing(void);
virtual void ThrowThing(void);
virtual void ThrowMyThing(const char *czSayThis);
};
class MyException: public std::exception
{
std::string reason;
public:
virtual ~MyException() throw();
MyException();
MyException(std::string r);
virtual const char *what() const throw();
};
/////////////////////////////////////////////////////////////////////////////
// Private Data
/////////////////////////////////////////////////////////////////////////////
// A static instance of the CThingSayer class. This instance MUST
// be constructed by the system BEFORE the program is started at
// main() and must be destructed by the system AFTER the main()
// returns to the system
static CThingSayer MyThingSayer;
/////////////////////////////////////////////////////////////////////////////
// MyException Method Implementations
/////////////////////////////////////////////////////////////////////////////
MyException::MyException(std::string r = NULL) : reason(r)
{
if( r.length() > 0 )
{
cout << "MyException(" << r << "): constructing with reason." << endl;
}
else
{
cout << "MyException(): constructing." << endl;
}
}
MyException::~MyException() throw()
{
cout << "~MyException(): destructing." << endl;
}
const char *MyException::what() const throw()
{
return reason.c_str();
}
/////////////////////////////////////////////////////////////////////////////
// CThingSayer Method Implementations
/////////////////////////////////////////////////////////////////////////////
// These are implementations of the methods of the CThingSayer class
CThingSayer::CThingSayer(void)
{
cout << "CThingSayer::CThingSayer: I am!" << endl;
szWhatToSay = (const char*)NULL;
}
CThingSayer::~CThingSayer(void)
{
cout << "CThingSayer::~CThingSayer: I cease to be" << endl;
if (szWhatToSay)
{
cout << "CThingSayer::~CThingSayer: I will never say '"
<< szWhatToSay << "' again" << endl;
}
szWhatToSay = (const char*)NULL;
}
void CThingSayer::Initialize(const char *czSayThis)
{
cout << "CThingSayer::Initialize: When told, I will say '"
<< czSayThis << "'" << endl;
szWhatToSay = czSayThis;
}
void CThingSayer::SayThing(void)
{
cout << "CThingSayer::SayThing: I am now saying '"
<< szWhatToSay << "'" << endl;
}
void CThingSayer::ThrowThing(void)
{
cout << "CThingSayer::ThrowThing: I am now throwing an exception." << endl;
throw exception();
}
void CThingSayer::ThrowMyThing(const char *czSayThis = NULL)
{
cout << "CThingSayer::ThrowMyThing: I am now throwing an MyException (with reason)." << endl;
throw MyException( string(czSayThis) );
}
/////////////////////////////////////////////////////////////////////////////
// Public Functions
/////////////////////////////////////////////////////////////////////////////
int main(int argc, char **argv)
{
// We should see the message from constructor, CThingSayer::CThingSayer(),
// BEFORE we see the following messages. That is proof that the
// C++ static initializer is working
cout << "main: Started" << endl;
// Tell MyThingSayer that "Hello, World!" is the string to be said
cout << "main: Calling MyThingSayer.Initialize" << endl;
MyThingSayer.Initialize("Hello, World!");
// Tell MyThingSayer to say the thing we told it to say
cout << "main: Calling MyThingSayer.SayThing" << endl;
MyThingSayer.SayThing();
// Test Static object throwing std::exception located in flash
try
{
cout << "main: Calling MyThingSayer.ThrowThing (and catching it)" << endl;
MyThingSayer.ThrowThing();
}
catch (const exception& e)
{
cout << "main: Caught exception: " << e.what() << endl;
}
// Test Static object throwing MyException shipped in the ELF and located in RAM.
try
{
cout << "main: Calling MyThingSayer.ThrowMyThing (and catching it)" << endl;
MyThingSayer.ThrowMyThing();
}
catch (const MyException& e)
{
cout << "main: Caught MyException: " << e.what() << endl;
}
// Testing with a local object
CThingSayer localMyThingSayer;
cout << "main: Calling localMyThingSayer.Initialize" << endl;
localMyThingSayer.Initialize("Repeat in heap.");
cout << "main: Calling localMyThingSayer.SayThing" << endl;
localMyThingSayer.SayThing();
// Test local object throwing std::exception located in flash
try
{
cout << "main: Calling localMyThingSayer.ThrowThing (and catching it)" << endl;
localMyThingSayer.ThrowThing();
}
catch (const exception& e)
{
cout << "main: Caught exception: " << e.what() << endl;
}
catch (const MyException& e)
{
cout << "main: Caught MyException: " << e.what() << endl;
}
// Test local object throwing MyException shipped in the ELF and located in RAM.
// Also testing the action record selection logic trying different sorting of the
// catch clauses
try
{
cout << "main: Calling localMyThingSayer.ThrowMyThing (and catching it)" << endl;
localMyThingSayer.ThrowMyThing();
}
catch (const exception& e)
{
cout << "main: Caught exception: " << e.what() << endl;
}
catch (const MyException& e)
{
cout << "main: Caught MyException: " << e.what() << endl;
}
// AGAING: Test local object throwing MyException shipped in the ELF and located in RAM.
// Also testing the action record selection logic trying different sorting of the
// catch clauses
try
{
cout << "main: Calling localMyThingSayer.ThrowMyThing (and catching it)" << endl;
localMyThingSayer.ThrowMyThing("Custom Reason.");
}
catch (const MyException& e)
{
cout << "main: Caught MyException: " << e.what() << endl;
}
catch (const exception& e)
{
cout << "main: Caught exception: " << e.what() << endl;
}
// We are finished, return. We should see the message from the
// destructor, CThingSayer::~CThingSayer(), AFTER we see the following
// message. That is proof that the C++ static destructor logic
// is working
cout << "main: Returning" << endl;
return 0;
}
@@ -0,0 +1,83 @@
############################################################################
# examples/elf/tests/longjmp/Makefile
#
# Copyright (C) 2012, 2014, 2016 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 $(APPDIR)/Make.defs
ifeq ($(CONFIG_EXAMPLES_ELF_SYSCALL),y)
LDELFFLAGS += -Bstatic
LDLIBPATH += -L $(NUTTXLIB)
else
ifeq ($(CONFIG_EXAMPLES_ELF_LIBC),y)
LDELFFLAGS += -Bstatic
LDLIBPATH += -L $(NUTTXLIB)
endif
endif
ifeq ($(CONFIG_EXAMPLES_ELF_LIBC),y)
LDLIBS += -lc
endif
ifeq ($(CONFIG_EXAMPLES_ELF_SYSCALL),y)
LDLIBS += -lproxies
endif
BIN = longjmp
SRCS = $(BIN).c
OBJS = $(SRCS:.c=$(OBJEXT))
all: $(BIN)
.PHONY: all clean install
$(OBJS): %$(OBJEXT): %.c
@echo "CC: $<"
$(Q) $(CC) -c $(CELFFLAGS) $< -o $@
$(BIN): $(OBJS)
@echo "LD: $<"
$(Q) $(LD) $(LDELFFLAGS) $(LDLIBPATH) -o $@ $(ARCHCRT0OBJ) $^ $(LDLIBS)
$(FSIMG_DIR)/$(BIN): $(BIN)
$(Q) mkdir -p $(FSIMG_DIR)
$(Q) install $(BIN) $(FSIMG_DIR)/$(BIN)
ifneq ($(CONFIG_DEBUG_SYMBOLS),y)
$(Q) $(STRIP) $(FSIMG_DIR)/$(BIN)
endif
install: $(FSIMG_DIR)/$(BIN)
clean:
$(call DELFILE, $(BIN))
$(call CLEAN)
@@ -0,0 +1,131 @@
/****************************************************************************
* examples/elf/tests/longjmp/longjmp.c
*
* Copyright (C) 2012 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 <stdio.h>
#include <setjmp.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define MAIN_VAL 47
#define FUNC_VAL 92
#define LEAF_VAL 163
#define FUNCTION_ARG MAIN_VAL
#define LEAF_ARG (FUNCTION_ARG + FUNC_VAL)
#define SETJMP_RETURN (LEAF_ARG + LEAF_VAL)
/****************************************************************************
* Private Data
****************************************************************************/
static jmp_buf env;
/****************************************************************************
* Private Functions
****************************************************************************/
static int leaf(int *some_arg)
{
int some_local_variable = *some_arg + LEAF_VAL;
printf("leaf: received %d\n", *some_arg);
if (*some_arg != LEAF_ARG)
printf("leaf: ERROR: expected %d\n", LEAF_ARG);
printf("leaf: Calling longjmp() with %d\n", some_local_variable);
longjmp(env, some_local_variable);
/* We should not get here */
return -ERROR;
}
static int function(int some_arg)
{
int some_local_variable = some_arg + FUNC_VAL;
int retval;
printf("function: received %d\n", some_arg);
if (some_arg != FUNCTION_ARG)
printf("function: ERROR: expected %d\n", FUNCTION_ARG);
printf("function: Calling leaf() with %d\n", some_local_variable);
retval = leaf(&some_local_variable);
printf("function: ERROR -- leaf returned!\n");
return retval;
}
/****************************************************************************
* Public Functions
****************************************************************************/
int main(int argc, char **argv)
{
int value;
printf("main: Calling setjmp\n");
value = setjmp(env);
printf("main: setjmp returned %d\n", value);
if (value == 0)
{
printf("main: Normal setjmp return\n");
printf("main: Calling function with %d\n", MAIN_VAL);
function(MAIN_VAL);
printf("main: ERROR -- function returned!\n");
return 1;
}
else if (value != SETJMP_RETURN)
{
printf("main: ERROR: Expected %d\n", SETJMP_RETURN);
return 1;
}
else
{
printf("main: SUCCESS: setjmp return from longjmp call\n");
return 0;
}
}
+30
View File
@@ -0,0 +1,30 @@
#!/usr/bin/env bash
usage="Usage: %0 <fsimg-dir-path>"
dir=$1
if [ -z "$dir" ]; then
echo "ERROR: Missing <fsimg-dir-path>"
echo ""
echo $usage
exit 1
fi
if [ ! -d "$dir" ]; then
echo "ERROR: Directory $dir does not exist"
echo ""
echo $usage
exit 1
fi
echo "#include <stddef.h>"
echo ""
echo "const char *dirlist[] ="
echo "{"
for file in `ls $dir`; do
echo " \"$file\","
done
echo " NULL"
echo "};"
@@ -0,0 +1,83 @@
############################################################################
# examples/elf/tests/mutex/Makefile
#
# Copyright (C) 2012, 2014, 2016 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 $(APPDIR)/Make.defs
ifeq ($(CONFIG_EXAMPLES_ELF_SYSCALL),y)
LDELFFLAGS += -Bstatic
LDLIBPATH += -L $(NUTTXLIB)
else
ifeq ($(CONFIG_EXAMPLES_ELF_LIBC),y)
LDELFFLAGS += -Bstatic
LDLIBPATH += -L $(NUTTXLIB)
endif
endif
ifeq ($(CONFIG_EXAMPLES_ELF_LIBC),y)
LDLIBS += -lc
endif
ifeq ($(CONFIG_EXAMPLES_ELF_SYSCALL),y)
LDLIBS += -lproxies
endif
BIN = mutex
SRCS = $(BIN).c
OBJS = $(SRCS:.c=$(OBJEXT))
all: $(BIN)
.PHONY: all clean install
$(OBJS): %$(OBJEXT): %.c
@echo "CC: $<"
$(Q) $(CC) -c $(CELFFLAGS) $< -o $@
$(BIN): $(OBJS)
@echo "LD: $<"
$(Q) $(LD) $(LDELFFLAGS) $(LDLIBPATH) -o $@ $(ARCHCRT0OBJ) $^ $(LDLIBS)
$(FSIMG_DIR)/$(BIN): $(BIN)
$(Q) mkdir -p $(FSIMG_DIR)
$(Q) install $(BIN) $(FSIMG_DIR)/$(BIN)
ifneq ($(CONFIG_DEBUG_SYMBOLS),y)
$(Q) $(STRIP) $(FSIMG_DIR)/$(BIN)
endif
install: $(FSIMG_DIR)/$(BIN)
clean:
$(call DELFILE, $(BIN))
$(call CLEAN)
@@ -0,0 +1,148 @@
/****************************************************************************
* examples/elf/tests/mutex/mutex.c
*
* Copyright (C) 2012 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 <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
/****************************************************************************
* Private Data
****************************************************************************/
static pthread_mutex_t mut;
static volatile int my_mutex = 0;
static unsigned long nloops[2] = {0, 0};
static unsigned long nerrors[2] = {0, 0};
static volatile bool bendoftest;
/****************************************************************************
* Private Functions
****************************************************************************/
/* NOTE: it is necessary for functions that are referred to by function pointers
* pointer to be declared with global scope (at least for ARM). Otherwise,
* a relocation type that is not supported by ELF is generated by GCC.
*/
void thread_func(void *parameter)
{
int my_id = (int)((intptr_t)parameter);
int my_ndx = my_id - 1;
int i;
/* Loop 20 times. There is a 100 MS delay in the loop so this should
* take about 2 seconds. The main thread will stop this thread after
* 2 seconds by setting bendoftest in any event.
*/
for (i = 0; i < 20 && !bendoftest; i++)
{
if ((pthread_mutex_lock(&mut)) != 0)
{
printf("ERROR thread %d: pthread_mutex_lock failed\n", my_id);
}
if (my_mutex == 1)
{
printf("ERROR thread=%d: "
"my_mutex should be zero, instead my_mutex=%d\n",
my_id, my_mutex);
nerrors[my_ndx]++;
}
my_mutex = 1;
usleep(100000);
my_mutex = 0;
if ((pthread_mutex_unlock(&mut)) != 0)
{
printf("ERROR thread %d: pthread_mutex_unlock failed\n", my_id);
}
nloops[my_ndx]++;
}
}
/****************************************************************************
* Public Functions
****************************************************************************/
int main(int argc, char **argv)
{
pthread_t thread1;
pthread_t thread2;
/* Initialize the mutex */
pthread_mutex_init(&mut, NULL);
/* Start two thread instances */
printf("Starting thread 1\n");
bendoftest = false;
if ((pthread_create(&thread1, NULL, (void*)thread_func, (void*)1)) != 0)
{
fprintf(stderr, "Error in thread#1 creation\n");
}
printf("Starting thread 2\n");
if ((pthread_create(&thread2, NULL, (void*)thread_func, (void*)2)) != 0)
{
fprintf(stderr, "Error in thread#2 creation\n");
}
/* Wait a bit for the threads to do their thing. */
sleep(2);
/* Then ask them politely to stop running */
printf("Stopping threads\n");
bendoftest = true;
pthread_join(thread1, NULL);
pthread_join(thread2, NULL);
printf("\tThread1\tThread2\n");
printf("Loops\t%lu\t%lu\n", nloops[0], nloops[1]);
printf("Errors\t%lu\t%lu\n", nerrors[0], nerrors[1]);
return 0;
}
@@ -0,0 +1,83 @@
############################################################################
# examples/elf/tests/pthread/Makefile
#
# Copyright (C) 2012, 2014, 2016 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 $(APPDIR)/Make.defs
ifeq ($(CONFIG_EXAMPLES_ELF_SYSCALL),y)
LDELFFLAGS += -Bstatic
LDLIBPATH += -L $(NUTTXLIB)
else
ifeq ($(CONFIG_EXAMPLES_ELF_LIBC),y)
LDELFFLAGS += -Bstatic
LDLIBPATH += -L $(NUTTXLIB)
endif
endif
ifeq ($(CONFIG_EXAMPLES_ELF_LIBC),y)
LDLIBS += -lc
endif
ifeq ($(CONFIG_EXAMPLES_ELF_SYSCALL),y)
LDLIBS += -lproxies
endif
BIN = pthread
SRCS = $(BIN).c
OBJS = $(SRCS:.c=$(OBJEXT))
all: $(BIN)
.PHONY: all clean install
$(OBJS): %$(OBJEXT): %.c
@echo "CC: $<"
$(Q) $(CC) -c $(CELFFLAGS) $< -o $@
$(BIN): $(OBJS)
@echo "LD: $<"
$(Q) $(LD) $(LDELFFLAGS) $(LDLIBPATH) -o $@ $(ARCHCRT0OBJ) $^ $(LDLIBS)
$(FSIMG_DIR)/$(BIN): $(BIN)
$(Q) mkdir -p $(FSIMG_DIR)
$(Q) install $(BIN) $(FSIMG_DIR)/$(BIN)
ifneq ($(CONFIG_DEBUG_SYMBOLS),y)
$(Q) $(STRIP) $(FSIMG_DIR)/$(BIN)
endif
install: $(FSIMG_DIR)/$(BIN)
clean:
$(call DELFILE, $(BIN))
$(call CLEAN)
@@ -0,0 +1,149 @@
/****************************************************************************
* examples/elf/tests/pthread/pthread.c
*
* Copyright (C) 2012 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 <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define CHILD_ARG ((void*)0x12345678)
#define CHILD_RET ((void*)0x87654321)
/****************************************************************************
* Private Types
****************************************************************************/
enum exit_values_e
{
TESTRESULT_SUCCESS = 0,
TESTRESULT_PTHREAD_ATTR_INIT_FAIL,
TESTRESULT_PTHREAD_CREATE_FAIL,
TESTRESULT_PTHREAD_JOIN_FAIL,
TESTRESULT_CHILD_ARG_FAIL,
TESTRESULT_CHILD_RETVAL_FAIL,
};
/****************************************************************************
* External Functions
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/* NOTE: it is necessary for functions that are referred to by function
* pointers pointer to be declared with global scope (at least for ARM).
* Otherwise, a relocation type that is not supported by ELF is generated
* by GCC.
*/
void *child_start_routine(void *arg)
{
printf("CHILD: started with arg=%d\n", (int)((intptr_t)arg));
if (arg != CHILD_ARG)
{
printf("CHILD: expected arg=%d\n", (int)((intptr_t)CHILD_ARG));
return (void*)TESTRESULT_CHILD_ARG_FAIL;
}
sleep(2);
printf("CHILD: returning %d\n", (int)((intptr_t)CHILD_RET));
pthread_exit(CHILD_RET);
}
/****************************************************************************
* Public Functions
****************************************************************************/
int main(int argc, char **argv)
{
pthread_attr_t attr;
pthread_t thread;
void *retval;
int status;
puts("PARENT: started\n");
status = pthread_attr_init(&attr);
if (status != 0)
{
printf("PARENT: pthread_attr_init() returned %d\n", status);
exit(TESTRESULT_PTHREAD_ATTR_INIT_FAIL);
}
printf("PARENT: calling pthread_start with arg=%d\n",
(int)((intptr_t)CHILD_ARG));
status = pthread_create(&thread, &attr, child_start_routine, CHILD_ARG);
if (status != 0)
{
printf("PARENT: pthread_create() returned %d\n", status);
exit(TESTRESULT_PTHREAD_CREATE_FAIL);
}
status = pthread_join(thread, &retval);
if (status != 0)
{
printf("PARENT pthread_join() returned %d\n", status);
exit(TESTRESULT_PTHREAD_JOIN_FAIL);
}
printf("PARENT child exitted with %d\n", (int)((intptr_t)retval));
if (retval != CHILD_RET)
{
printf("PARENT child thread did not exit with %d\n",
(int)((intptr_t)CHILD_RET));
exit(TESTRESULT_CHILD_RETVAL_FAIL);
}
puts("PARENT returning success\n");
return TESTRESULT_SUCCESS;
}
@@ -0,0 +1,83 @@
############################################################################
# examples/elf/tests/signal/Makefile
#
# Copyright (C) 2012, 2014, 2016 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 $(APPDIR)/Make.defs
ifeq ($(CONFIG_EXAMPLES_ELF_SYSCALL),y)
LDELFFLAGS += -Bstatic
LDLIBPATH += -L $(NUTTXLIB)
else
ifeq ($(CONFIG_EXAMPLES_ELF_LIBC),y)
LDELFFLAGS += -Bstatic
LDLIBPATH += -L $(NUTTXLIB)
endif
endif
ifeq ($(CONFIG_EXAMPLES_ELF_LIBC),y)
LDLIBS += -lc
endif
ifeq ($(CONFIG_EXAMPLES_ELF_SYSCALL),y)
LDLIBS += -lproxies
endif
BIN = signal
SRCS = $(BIN).c
OBJS = $(SRCS:.c=$(OBJEXT))
all: $(BIN)
.PHONY: all clean install
$(OBJS): %$(OBJEXT): %.c
@echo "CC: $<"
$(Q) $(CC) -c $(CELFFLAGS) $< -o $@
$(BIN): $(OBJS)
@echo "LD: $<"
$(Q) $(LD) $(LDELFFLAGS) $(LDLIBPATH) -o $@ $(ARCHCRT0OBJ) $^ $(LDLIBS)
$(FSIMG_DIR)/$(BIN): $(BIN)
$(Q) mkdir -p $(FSIMG_DIR)
$(Q) install $(BIN) $(FSIMG_DIR)/$(BIN)
ifneq ($(CONFIG_DEBUG_SYMBOLS),y)
$(Q) $(STRIP) $(FSIMG_DIR)/$(BIN)
endif
install: $(FSIMG_DIR)/$(BIN)
clean:
$(call DELFILE, $(BIN))
$(call CLEAN)
@@ -0,0 +1,275 @@
/****************************************************************************
* examples/elf/tests/signal/signal.c
*
* Copyright (C) 2012, 2015 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 <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#ifndef USEC_PER_MSEC
# define USEC_PER_MSEC 1000L
#endif
#ifndef MSEC_PER_SEC
# define MSEC_PER_SEC 1000L
#endif
#ifndef USEC_PER_SEC
# define USEC_PER_SEC (USEC_PER_MSEC * MSEC_PER_SEC)
#endif
#define SHORT_DELAY (USEC_PER_SEC / 3)
/****************************************************************************
* Private Data
****************************************************************************/
static int sigusr1_rcvd = 0;
static int sigusr2_rcvd = 0;
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: siguser_action
****************************************************************************/
/* NOTE: it is necessary for functions that are referred to by function pointers
* pointer to be declared with global scope (at least for ARM). Otherwise,
* a relocation type that is not supported by ELF is generated by GCC.
*/
void siguser_action(int signo, siginfo_t *siginfo, void *arg)
{
printf("siguser_action: Received signo=%d siginfo=%p arg=%p\n",
signo, siginfo, arg);
if (signo == SIGUSR1)
{
printf(" SIGUSR1 received\n");
sigusr2_rcvd = 1;
}
else if (signo == SIGUSR2)
{
printf(" SIGUSR2 received\n");
sigusr1_rcvd = 2;
}
else
{
printf(" ERROR: Unexpected signal\n");
}
if (siginfo)
{
printf("siginfo:\n");
printf(" si_signo = %d\n", siginfo->si_signo);
printf(" si_code = %d\n", siginfo->si_code);
printf(" si_errno = %d\n", siginfo->si_errno);
printf(" si_value = %d\n", siginfo->si_value.sival_int);
}
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: main
****************************************************************************/
int main(int argc, char **argv)
{
struct sigaction act;
struct sigaction oact1;
struct sigaction oact2;
pid_t mypid = getpid();
union sigval sigval;
int status;
printf("Setting up signal handlers from pid=%d\n", mypid);
/* Set up so that siguser_action will respond to SIGUSR1 */
memset(&act, 0, sizeof(struct sigaction));
act.sa_sigaction = siguser_action;
act.sa_flags = SA_SIGINFO;
sigemptyset(&act.sa_mask);
status = sigaction(SIGUSR1, &act, &oact1);
if (status != 0)
{
fprintf(stderr, "Failed to install SIGUSR1 handler, errno=%d\n",
errno);
exit(2);
}
printf("Old SIGUSR1 sighandler at %p\n", oact1.sa_handler);
printf("New SIGUSR1 sighandler at %p\n", siguser_action);
/* Set up so that siguser_action will respond to SIGUSR2 */
status = sigaction(SIGUSR2, &act, &oact2);
if (status != 0)
{
fprintf(stderr, "Failed to install SIGUSR2 handler, errno=%d\n",
errno);
exit(2);
}
printf("Old SIGUSR2 sighandler at %p\n", oact2.sa_handler);
printf("New SIGUSR2 sighandler at %p\n", siguser_action);
printf("Raising SIGUSR1 from pid=%d\n", mypid);
fflush(stdout); usleep(SHORT_DELAY);
/* Send SIGUSR1 to ourselves via kill() */
printf("Kill-ing SIGUSR1 from pid=%d\n", mypid);
status = kill(mypid, SIGUSR1);
if (status != 0)
{
fprintf(stderr, "Failed to kill SIGUSR1, errno=%d\n", errno);
exit(3);
}
usleep(SHORT_DELAY);
printf("SIGUSR1 raised from pid=%d\n", mypid);
/* Verify that we received SIGUSR1 */
if (sigusr1_rcvd == 0)
{
fprintf(stderr, "SIGUSR1 not received\n");
exit(4);
}
sigusr1_rcvd = 0;
/* Send SIGUSR2 to ourselves */
printf("sigqueue-ing SIGUSR2 from pid=%d\n", mypid);
fflush(stdout); usleep(SHORT_DELAY);
/* Send SIGUSR2 to ourselves via sigqueue() */
sigval.sival_int = 87;
status = sigqueue(mypid, SIGUSR2, sigval);
if (status != 0)
{
fprintf(stderr, "Failed to queue SIGUSR2, errno=%d\n", errno);
exit(5);
}
usleep(SHORT_DELAY);
printf("SIGUSR2 queued from pid=%d, sigval=87\n", mypid);
/* Verify that SIGUSR2 was received */
if (sigusr2_rcvd == 0)
{
fprintf(stderr, "SIGUSR2 not received\n");
exit(6);
}
sigusr2_rcvd = 0;
/* Remove the siguser_action handler and replace the SIGUSR2
* handler with sigusr2_sighandler.
*/
printf("Resetting SIGUSR2 signal handler from pid=%d\n", mypid);
status = sigaction(SIGUSR2, &oact2, &act);
if (status != 0)
{
fprintf(stderr, "Failed to install SIGUSR1 handler, errno=%d\n",
errno);
exit(2);
}
printf("Old SIGUSR1 sighandler at %p\n", act.sa_handler);
printf("New SIGUSR1 sighandler at %p\n", oact1.sa_handler);
/* Verify that the handler that was removed was siguser_action */
if ((void*)act.sa_handler != (void*)siguser_action)
{
fprintf(stderr,
"Old SIGUSR2 signal handler (%p) is not siguser_action (%p)\n",
act.sa_handler, siguser_action);
exit(8);
}
/* Send SIGUSR2 to ourselves via kill() */
printf("Killing SIGUSR2 from pid=%d\n", mypid);
fflush(stdout); usleep(SHORT_DELAY);
status = kill(mypid, SIGUSR2);
if (status != 0)
{
fprintf(stderr, "Failed to kill SIGUSR2, errno=%d\n", errno);
exit(9);
}
usleep(SHORT_DELAY);
printf("SIGUSR2 killed from pid=%d\n", mypid);
/* Verify that SIGUSR2 was received */
if (sigusr2_rcvd == 0)
{
fprintf(stderr, "SIGUSR2 not received\n");
exit(10);
}
sigusr2_rcvd = 0;
return 0;
}
@@ -0,0 +1,82 @@
############################################################################
# examples/elf/tests/struct/Makefile
#
# Copyright (C) 2012, 2014, 2016 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 $(APPDIR)/Make.defs
ifeq ($(CONFIG_EXAMPLES_ELF_SYSCALL),y)
LDELFFLAGS += -Bstatic
LDLIBPATH += -L $(NUTTXLIB)
else
ifeq ($(CONFIG_EXAMPLES_ELF_LIBC),y)
LDELFFLAGS += -Bstatic
LDLIBPATH += -L $(NUTTXLIB)
endif
endif
ifeq ($(CONFIG_EXAMPLES_ELF_LIBC),y)
LDLIBS += -lc
endif
ifeq ($(CONFIG_EXAMPLES_ELF_SYSCALL),y)
LDLIBS += -lproxies
endif
BIN = struct
SRCS = struct_main.c struct_dummy.c
OBJS = $(SRCS:.c=$(OBJEXT))
all: $(BIN)
.PHONY: all clean install
$(OBJS): %$(OBJEXT): %.c
@echo "CC: $<"
$(Q) $(CC) -c $(CELFFLAGS) $< -o $@
$(BIN): $(OBJS)
@echo "LD: $<"
$(Q) $(LD) $(LDELFFLAGS) $(LDLIBPATH) -o $@ $(ARCHCRT0OBJ) $^ $(LDLIBS)
$(FSIMG_DIR)/$(BIN): $(BIN)
$(Q) mkdir -p $(FSIMG_DIR)
$(Q) install $(BIN) $(FSIMG_DIR)/$(BIN)
ifneq ($(CONFIG_DEBUG_SYMBOLS),y)
$(Q) $(STRIP) $(FSIMG_DIR)/$(BIN)
endif
install: $(FSIMG_DIR)/$(BIN)
clean:
$(call DELFILE, $(BIN))
$(call CLEAN)
@@ -0,0 +1,87 @@
/****************************************************************************
* examples/elf/tests/struct/struct.h
*
* Copyright (C) 2012 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.
*
****************************************************************************/
#ifndef __EXAMPLES_ELF_TESTS_STRUCT_STRUCT_H
#define __EXAMPLES_ELF_TESTS_STRUCT_STRUCT_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <stdio.h>
#include <stdlib.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define DUMMY_SCALAR_VALUE1 42
#define DUMMY_SCALAR_VALUE2 87
#define DUMMY_SCALAR_VALUE3 117
/****************************************************************************
* Public Types
****************************************************************************/
typedef void (*dummy_t)(void);
struct struct_dummy_s
{
int n; /* This is a simple scalar value (DUMMY_SCALAR_VALUE3) */
};
struct struct_s
{
int n; /* This is a simple scalar value (DUMMY_SCALAR_VALUE1) */
const int *pn; /* This is a pointer to a simple scalar value */
const struct struct_dummy_s *ps; /* This is a pointer to a structure */
dummy_t pf; /* This is a pointer to a function */
};
/****************************************************************************
* Public Data
****************************************************************************/
extern int dummy_scalar; /* (DUMMY_SCALAR_VALUE2) */
extern const struct struct_dummy_s dummy_struct;
/****************************************************************************
* Public Functions
****************************************************************************/
extern void dummyfunc(void);
extern const struct struct_s *getstruct(void);
#endif /* __EXAMPLES_ELF_TESTS_STRUCT_STRUCT_H */
@@ -0,0 +1,64 @@
/****************************************************************************
* examples/elf/tests/struct/struct_dummy.c
*
* Copyright (C) 2012 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 <stdio.h>
#include <stdlib.h>
#include "struct.h"
/****************************************************************************
* Public Data
****************************************************************************/
const struct struct_s dummy =
{
DUMMY_SCALAR_VALUE1,
&dummy_scalar,
&dummy_struct,
(dummy_t)dummyfunc
};
/****************************************************************************
* Public Functions
****************************************************************************/
const struct struct_s *getstruct(void)
{
return &dummy;
}
@@ -0,0 +1,107 @@
/****************************************************************************
* examples/elf/tests/struct/struct_main.c
*
* Copyright (C) 2012 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 <stdio.h>
#include <stdlib.h>
#include "struct.h"
/****************************************************************************
* Public Data
****************************************************************************/
const struct struct_dummy_s dummy_struct =
{
DUMMY_SCALAR_VALUE3
};
int dummy_scalar = DUMMY_SCALAR_VALUE2;
/****************************************************************************
* Public Functions
****************************************************************************/
int main(int argc, char **argv)
{
const struct struct_s *mystruct;
printf("Calling getstruct()\n");
mystruct = getstruct();
printf("getstruct returned %p\n", mystruct);
printf(" n = %d (vs %d) %s\n",
mystruct->n, DUMMY_SCALAR_VALUE1,
mystruct->n == DUMMY_SCALAR_VALUE1 ? "PASS" : "FAIL");
printf(" pn = %p (vs %p) %s\n",
mystruct->pn, &dummy_scalar,
mystruct->pn == &dummy_scalar ? "PASS" : "FAIL");
if (mystruct->pn == &dummy_scalar)
{
printf(" *pn = %d (vs %d) %s\n",
*mystruct->pn, DUMMY_SCALAR_VALUE2,
*mystruct->pn == DUMMY_SCALAR_VALUE2 ? "PASS" : "FAIL");
}
printf(" ps = %p (vs %p) %s\n",
mystruct->ps, &dummy_struct,
mystruct->ps == &dummy_struct ? "PASS" : "FAIL");
if (mystruct->ps == &dummy_struct)
{
printf(" ps->n = %d (vs %d) %s\n",
mystruct->ps->n, DUMMY_SCALAR_VALUE3,
mystruct->ps->n == DUMMY_SCALAR_VALUE3 ? "PASS" : "FAIL");
}
printf(" pf = %p (vs %p) %s\n",
mystruct->pf, dummyfunc,
mystruct->pf == dummyfunc ? "PASS" : "FAIL");
if (mystruct->pf == dummyfunc)
{
printf("Calling mystruct->pf()\n");
mystruct->pf();
}
printf("Exit-ing\n");
return 0;
}
void dummyfunc(void)
{
printf("In dummyfunc() -- PASS\n");
}
@@ -0,0 +1,83 @@
############################################################################
# examples/elf/tests/task/Makefile
#
# Copyright (C) 2012, 2014, 2016 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 $(APPDIR)/Make.defs
ifeq ($(CONFIG_EXAMPLES_ELF_SYSCALL),y)
LDELFFLAGS += -Bstatic
LDLIBPATH += -L $(NUTTXLIB)
else
ifeq ($(CONFIG_EXAMPLES_ELF_LIBC),y)
LDELFFLAGS += -Bstatic
LDLIBPATH += -L $(NUTTXLIB)
endif
endif
ifeq ($(CONFIG_EXAMPLES_ELF_LIBC),y)
LDLIBS += -lc
endif
ifeq ($(CONFIG_EXAMPLES_ELF_SYSCALL),y)
LDLIBS += -lproxies
endif
BIN = task
SRCS = $(BIN).c
OBJS = $(SRCS:.c=$(OBJEXT))
all: $(BIN)
.PHONY: all clean install
$(OBJS): %$(OBJEXT): %.c
@echo "CC: $<"
$(Q) $(CC) -c $(CELFFLAGS) $< -o $@
$(BIN): $(OBJS)
@echo "LD: $<"
$(Q) $(LD) $(LDELFFLAGS) $(LDLIBPATH) -o $@ $(ARCHCRT0OBJ) $^ $(LDLIBS)
$(FSIMG_DIR)/$(BIN): $(BIN)
$(Q) mkdir -p $(FSIMG_DIR)
$(Q) install $(BIN) $(FSIMG_DIR)/$(BIN)
ifneq ($(CONFIG_DEBUG_SYMBOLS),y)
$(Q) $(STRIP) $(FSIMG_DIR)/$(BIN)
endif
install: $(FSIMG_DIR)/$(BIN)
clean:
$(call DELFILE, $(BIN))
$(call CLEAN)
@@ -0,0 +1,142 @@
/****************************************************************************
* examples/elf/tests/task/parent.c
*
* Copyright (C) 2012 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 <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sched.h>
#include <semaphore.h>
#include <errno.h>
/****************************************************************************
* Private Data
****************************************************************************/
static char child_name[] = "child";
static char child_arg[] = "Hello from your parent!";
static sem_t g_sem;
#if CONFIG_TASK_NAME_SIZE == 0
static char no_name[] = "<noname>";
#endif
/****************************************************************************
* Privite Functions
****************************************************************************/
/* NOTE: it is necessary for functions that are referred to by function pointers
* pointer to be declared with global scope (at least for ARM). Otherwise,
* a relocation type that is not supported by ELF is generated by GCC.
*/
int child_task(int argc, char **argv)
{
printf("Child: execv was successful!\n");
printf("Child: argc=%d\n", argc);
if (argc != 2)
{
printf("Child: expected argc to be 2\n");
printf("Child: Exit-ting with status=2\n");
exit(2);
}
printf("Child: argv[0]=\"%s\"\n", argv[0]);
#if CONFIG_TASK_NAME_SIZE == 0
if (strcmp(argv[0], no_name) != 0)
{
printf("Child: expected argv[0] to be \"%s\"\n", no_name);
printf("Child: Exit-ting with status=3\n");
exit(3);
}
#else
if (strncmp(argv[0], child_name, CONFIG_TASK_NAME_SIZE) != 0)
{
printf("Child: expected argv[0] to be \"%s\"\n", child_name);
printf("Child: Exit-ting with status=3\n");
exit(3);
}
#endif
printf("Child: argv[1]=\"%s\"\n", argv[1]);
if (strcmp(argv[1], child_arg) != 0)
{
printf("Child: expected argv[1] to be \"%s\"\n", child_arg);
printf("Child: Exit-ting with status=4\n");
exit(4);
}
printf("Child: Exit-ting with status=0\n");
sem_post(&g_sem);
return 0;
}
/****************************************************************************
* Public Functions
****************************************************************************/
int main(int argc, char **argv)
{
pid_t parent_pid = getpid();
char *child_argv[2];
pid_t child_pid;
printf("Parent: Started, pid=%d\n", parent_pid);
sem_init(&g_sem, 0, 0);
printf("Parent: Calling task_create()\n");
child_argv[0] = child_arg;
child_argv[1] = 0;
child_pid = task_create(child_name, 50, 2048, child_task, (FAR char * const *)child_argv);
if (child_pid < 0)
{
printf("Parent: task_create failed: %d\n", errno);
}
printf("Parent: Waiting for child (pid=%d)\n", child_pid);
sem_wait(&g_sem);
printf("Parent: Exit-ing\n");
sem_destroy(&g_sem);
return 0;
}