diff --git a/examples/nxflat/nxflat_main.c b/examples/nxflat/nxflat_main.c index 3eddcb4a23..e792fa1b75 100644 --- a/examples/nxflat/nxflat_main.c +++ b/examples/nxflat/nxflat_main.c @@ -40,10 +40,18 @@ #include #include +#include +#include +#include +#include +#include #include +#include +#include #include "tests/romfs.h" #include "tests/dirlist.h" +#include "tests/symtab.h" /**************************************************************************** * Definitions @@ -57,10 +65,22 @@ * Private Data ****************************************************************************/ +static const char delimiter[] = + "****************************************************************************"; + /**************************************************************************** * Private Functions ****************************************************************************/ +/**************************************************************************** + * Name: testheader + ****************************************************************************/ + +static inline void testheader(FAR const char *progname) +{ + printf("\n%s\n* Executing %s\n%s\n\n", delimiter, progname, delimiter); +} + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -79,5 +99,32 @@ void user_initialize(void) int user_start(int argc, char *argv[]) { + struct binary_s bin; + int ret; + int i; + + for (i = 0; dirlist[i]; i++) + { + testheader(dirlist[i]); + + memset(&bin, 0, sizeof(struct binary_s)); + bin.filename = dirlist[i]; + bin.exports = exports; + bin.nexports = NEXPORTS; + + ret = load_module(&bin); + if (ret < 0) + { + fprintf(stderr, "ERROR: Failed to load program '%s'\n", dirlist[i]); + exit(1); + } + + ret = exec_module(&bin, 50); + if (ret < 0) + { + fprintf(stderr, "ERROR: Failed to execute program '%s'\n", dirlist[i]); + unload_module(&bin); + } + } return 0; } diff --git a/examples/nxflat/tests/Makefile b/examples/nxflat/tests/Makefile index 6420e4773f..c327e71b4a 100644 --- a/examples/nxflat/tests/Makefile +++ b/examples/nxflat/tests/Makefile @@ -43,13 +43,14 @@ ROMFS_DIR = $(TESTS_DIR)/romfs ROMFS_IMG = $(TESTS_DIR)/romfs.img ROMFS_HDR = $(TESTS_DIR)/romfs.h ROMFS_DIRLIST = $(TESTS_DIR)/dirlist.h +SYMTAB = $(TESTS_DIR)/symtab.h define DIR_template $(1)_$(2): @$(MAKE) -C $(1) $(3) TOPDIR=$(TOPDIR) ROMFS_DIR=$(ROMFS_DIR) CROSSDEV=$(CROSSDEV) endef -all: $(ROMFS_HDR) $(ROMFS_DIRLIST) +all: $(ROMFS_HDR) $(ROMFS_DIRLIST) $(SYMTAB) .PHONY: all build clean install populate $(foreach DIR, $(SUBDIRS), $(eval $(call DIR_template,$(DIR),build, all))) @@ -83,25 +84,20 @@ $(ROMFS_IMG): populate $(ROMFS_HDR) : $(ROMFS_IMG) @xxd -i $^ >$@ +# Create the dirlist.h header file from the romfs directory + $(ROMFS_DIRLIST) : populate - @echo "#ifndef __EXAMPLES_NXFLAT_TESTS_DIRLIST_H" >$(ROMFS_DIRLIST) - @echo "#define __EXAMPLES_NXFLAT_TESTS_DIRLIST_H" >>$(ROMFS_DIRLIST) - @echo "" >>$(ROMFS_DIRLIST) - @echo "static const char *dirlist[] =" >>$(ROMFS_DIRLIST) - @echo "{" >>$(ROMFS_DIRLIST) - @(\ - for file in `ls $(ROMFS_DIR)`; do \ - echo " \"$$file\"," >>$(ROMFS_DIRLIST); \ - done; \ - ) - @echo "};" >>$(ROMFS_DIRLIST) - @echo "" >>$(ROMFS_DIRLIST) - @echo "#endif /* __EXAMPLES_NXFLAT_TESTS_DIRLIST_H */" >>$(ROMFS_DIRLIST) + @$(TESTS_DIR)/mkdirlist.sh $(ROMFS_DIR) >$@ + +# Create the exported symbol table list from the derived *-thunk.S files + +$(SYMTAB): build + @$(TESTS_DIR)/mksymtab.sh $(TESTS_DIR) >$@ # Clean each subdirectory clean: $(foreach DIR, $(SUBDIRS), $(DIR)_clean) - @rm -f $(ROMFS_HDR) $(ROMFS_IMG) + @rm -f $(ROMFS_HDR) $(ROMFS_IMG) $(SYMTAB) @rm -rf $(ROMFS_DIR) diff --git a/examples/nxflat/tests/mkdirlist.sh b/examples/nxflat/tests/mkdirlist.sh new file mode 100755 index 0000000000..cc55ac0b56 --- /dev/null +++ b/examples/nxflat/tests/mkdirlist.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +usage="Usage: %0 " + +dir=$1 +if [ -z "$dir" ]; then + echo "ERROR: Missing " + echo "" + echo $usage + exit 1 +fi + +if [ ! -d "$dir" ]; then + echo "ERROR: Directory $dir does not exist" + echo "" + echo $usage + exit 1 +fi + +echo "#ifndef __EXAMPLES_NXFLAT_TESTS_DIRLIST_H" +echo "#define __EXAMPLES_NXFLAT_TESTS_DIRLIST_H" +echo "" +echo "static const char *dirlist[] =" +echo "{" + +for file in `ls $dir`; do + echo " \"$file\"," +done + +echo " NULL" +echo "};" +echo "" +echo "#endif /* __EXAMPLES_NXFLAT_TESTS_DIRLIST_H */" + + diff --git a/examples/nxflat/tests/mksymtab.sh b/examples/nxflat/tests/mksymtab.sh new file mode 100755 index 0000000000..a5161ae734 --- /dev/null +++ b/examples/nxflat/tests/mksymtab.sh @@ -0,0 +1,38 @@ +#!/bin/bash + +usage="Usage: %0 " + +dir=$1 +if [ -z "$dir" ]; then + echo "ERROR: Missing " + echo "" + echo $usage + exit 1 +fi + +if [ ! -d "$dir" ]; then + echo "ERROR: Directory $dir does not exist" + echo "" + echo $usage + exit 1 +fi + +varlist=`find $dir -name "*-thunk.S"| xargs grep -h asciz | cut -f3 | sort | uniq` + +echo "#ifndef __EXAMPLES_NXFLAT_TESTS_SYMTAB_H" +echo "#define __EXAMPLES_NXFLAT_TESTS_SYMTAB_H" +echo "" +echo "#include " +echo "" +echo "static const struct symtab_s exports[] = " +echo "{" +for string in $varlist; do + var=`echo $string | sed -e "s/\"//g"` + echo " {$string, $var}," +done + +echo "};" +echo "#define NEXPORTS (sizeof(exports)/sizeof(struct symtab_s))" +echo "" +echo "#endif /* __EXAMPLES_NXFLAT_TESTS_SYMTAB_H */" +