From a7853cdc89a4760ffbd273ec3bd239e576ce894e Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 26 Aug 2015 10:35:40 -0600 Subject: [PATCH] apps/examples/nettest: Extend the test so that it can be down using the local loopback device --- ChangeLog.txt | 2 ++ examples/nettest/Kconfig | 37 ++++++++++++++++++++++---- examples/nettest/Makefile | 44 +++++++++++++++++++------------ examples/nettest/nettest.c | 42 +++++++++++++++++++++++++---- examples/nettest/nettest_client.c | 16 +++++++++++ 5 files changed, 114 insertions(+), 27 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 78c6a7b03..af9eee2e9 100755 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1415,4 +1415,6 @@ * apps/nettest: Add option to suppress network initialization. This is necessary if the nettest is run from NSH which has already initialized the network (2015-08-26). + * apps/nettest: Extend test so that can be performed using the local + loopback device (2015-08-26). diff --git a/examples/nettest/Kconfig b/examples/nettest/Kconfig index 55ba511c5..7f5d8d8b0 100644 --- a/examples/nettest/Kconfig +++ b/examples/nettest/Kconfig @@ -12,19 +12,40 @@ config EXAMPLES_NETTEST if EXAMPLES_NETTEST +config EXAMPLES_NETTEST_LOOPBACK + bool "Loopback test" + default n + depends on NET_LOOPBACK + ---help--- + Perform the test using the local loopback device. In this case, + both the client and the server reside on the target. + +if EXAMPLES_NETTEST_LOOPBACK + +config EXAMPLES_NETTEST_STACKSIZE + int "Server stack size" + default 2048 + +config EXAMPLES_NETTEST_PRIORITY + int "Server priority" + default 100 + +endif # EXAMPLES_NETTEST_LOOPBACK + config EXAMPLES_NETTEST_SERVER bool "Target is server" default n + depends on !EXAMPLES_NETTEST_LOOPBACK ---help--- - Select to use the host as the client side of the test. Default: The - target is the client side of the test + Select to use the host as the client side of the test. Default: The + target is the client side of the test config EXAMPLES_NETTEST_PERFORMANCE bool "Test for Performance" default n ---help--- - Configure the example to test for network performance. Default: Test - is for network functionality. + Configure the example to test for network performance. Default: Test + is for network functionality. choice prompt "IP Domain" @@ -45,7 +66,7 @@ config EXAMPLES_NETTEST_INIT bool "Initialize network" default n if NSH_BUILTIN_APPS default y if !NSH_BUILTIN_APPS - depends on !BUILD_KERNEL + depends on !BUILD_KERNEL && !EXAMPLES_NETTEST_LOOPBACK ---help--- Include logic to initialize the network. This should not be done if the network is already initialized when nettest runs. This is @@ -77,6 +98,8 @@ config EXAMPLES_NETTEST_NETMASK endif # EXAMPLES_NETTEST_INIT +if !EXAMPLES_NETTEST_LOOPBACK + config EXAMPLES_NETTEST_CLIENTIP hex "Client IP Address" default 0x0a000001 if !EXAMPLES_NETTEST_SERVER @@ -89,6 +112,7 @@ config EXAMPLES_NETTEST_CLIENTIP host PC IP address (possibly the gateway address, EXAMPLES_NETTEST_DRIPADDR?). +endif # !EXAMPLES_NETTEST_LOOPBACK endif # EXAMPLES_NETTEST_IPv4 if EXAMPLES_NETTEST_IPv6 @@ -345,6 +369,8 @@ config EXAMPLES_NETTEST_IPv6NETMASK_8 endif # NET_ICMPv6_AUTOCONF endif # EXAMPLES_NETTEST_INIT +if !EXAMPLES_NETTEST_LOOPBACK + comment "Client IPv6 address" config EXAMPLES_NETTEST_CLIENTIPv6ADDR_1 @@ -476,5 +502,6 @@ config EXAMPLES_NETTEST_CLIENTIPv6ADDR_8 values forming the full IP address must be specified individually. This is the last of the 8-values. +endif # !EXAMPLES_NETTEST_LOOPBACK endif # EXAMPLES_NETTEST_IPv6 endif # EXAMPLES_NETTEST diff --git a/examples/nettest/Makefile b/examples/nettest/Makefile index b41eeccf9..fbefe3701 100644 --- a/examples/nettest/Makefile +++ b/examples/nettest/Makefile @@ -43,7 +43,9 @@ TARG_ASRCS = TARG_AOBJS = $(TARG_ASRCS:.S=$(OBJEXT)) TARG_CSRCS = -ifeq ($(CONFIG_EXAMPLES_NETTEST_SERVER),y) +ifeq ($(CONFIG_EXAMPLES_NETTEST_LOOPBACK),y) +TARG_CSRCS += nettest_server.c nettest_client.c +else ifeq ($(CONFIG_EXAMPLES_NETTEST_SERVER),y) TARG_CSRCS += nettest_server.c else TARG_CSRCS += nettest_client.c @@ -70,24 +72,26 @@ else endif endif -HOSTCFLAGS += -DNETTEST_HOST=1 -ifeq ($(CONFIG_EXAMPLES_NETTEST_SERVER),y) -HOSTCFLAGS += -DCONFIG_EXAMPLES_NETTEST_SERVER=1 -DCONFIG_EXAMPLES_NETTEST_CLIENTIP="$(CONFIG_EXAMPLES_NETTEST_CLIENTIP)" -endif -ifeq ($(CONFIG_EXAMPLES_NETTEST_PERFORMANCE),y) -HOSTCFLAGS += -DCONFIG_EXAMPLES_NETTEST_PERFORMANCE=1 -endif +ifneq ($(CONFIG_EXAMPLES_NETTEST_LOOPBACK),y) + HOSTCFLAGS += -DNETTEST_HOST=1 + ifeq ($(CONFIG_EXAMPLES_NETTEST_SERVER),y) + HOSTCFLAGS += -DCONFIG_EXAMPLES_NETTEST_SERVER=1 -DCONFIG_EXAMPLES_NETTEST_CLIENTIP="$(CONFIG_EXAMPLES_NETTEST_CLIENTIP)" + endif + ifeq ($(CONFIG_EXAMPLES_NETTEST_PERFORMANCE),y) + HOSTCFLAGS += -DCONFIG_EXAMPLES_NETTEST_PERFORMANCE=1 + endif -HOST_SRCS = host.c -ifeq ($(CONFIG_EXAMPLES_NETTEST_SERVER),y) -HOST_SRCS += nettest_client.c -else -HOST_SRCS += nettest_server.c -endif + HOST_SRCS = host.c + ifeq ($(CONFIG_EXAMPLES_NETTEST_SERVER),y) + HOST_SRCS += nettest_client.c + else + HOST_SRCS += nettest_server.c + endif -HOSTOBJEXT ?= .hobj -HOST_OBJS = $(HOST_SRCS:.c=$(HOSTOBJEXT)) -HOST_BIN = host + HOSTOBJEXT ?= .hobj + HOST_OBJS = $(HOST_SRCS:.c=$(HOSTOBJEXT)) + HOST_BIN = host +endif ifeq ($(WINTOOL),y) INSTALL_DIR = "${shell cygpath -w $(BIN_DIR)}" @@ -119,17 +123,21 @@ $(TARG_AOBJS): %$(OBJEXT): %.S $(TARG_COBJS) $(TARG_MAINOBJ): %$(OBJEXT): %.c $(call COMPILE, $<, $@) +ifneq ($(CONFIG_EXAMPLES_NETTEST_LOOPBACK),y) $(HOST_OBJS): %$(HOSTOBJEXT): %.c @echo "CC: $<" $(Q) $(HOSTCC) -c $(HOSTCFLAGS) $< -o $@ +endif config.h: $(TOPDIR)/include/nuttx/config.h @echo "CP: $<" $(Q) cp $< $@ +ifneq ($(CONFIG_EXAMPLES_NETTEST_LOOPBACK),y) $(HOST_BIN): config.h $(HOST_OBJS) @echo "LD: $@" $(Q) $(HOSTCC) $(HOSTLDFLAGS) $(HOST_OBJS) -o $@ +endif .built: config.h $(TARG_OBJS) $(call ARCHIVE, $(TARG_BIN), $(TARG_OBJS)) @@ -164,8 +172,10 @@ endif depend: .depend clean: +ifneq ($(CONFIG_EXAMPLES_NETTEST_LOOPBACK),y) $(call DELFILE, *$(HOSTOBJEXT)) $(call DELFILE, $(HOST_BIN)) +endif $(call DELFILE, .built) $(call DELFILE, *.dSYM) $(call DELFILE, config.h) diff --git a/examples/nettest/nettest.c b/examples/nettest/nettest.c index ee2afb615..16e7fcf69 100644 --- a/examples/nettest/nettest.c +++ b/examples/nettest/nettest.c @@ -41,7 +41,10 @@ //#include #include +#include #include +#include +#include #include #include @@ -177,6 +180,14 @@ static void netest_initialize(void) } #endif /*CONFIG_EXAMPLES_NETTEST_INIT */ +#ifdef CONFIG_EXAMPLES_NETTEST_LOOPBACK +static int server_child(int argc, char *argv[]) +{ + recv_server(); + return EXIT_SUCCESS; +} +#endif + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -191,21 +202,42 @@ int main(int argc, FAR char *argv[]) int nettest_main(int argc, char *argv[]) #endif { +#if defined(CONFIG_EXAMPLES_NETTEST_LOOPBACK) + pid_t child; +#endif + #ifdef CONFIG_EXAMPLES_NETTEST_INIT /* Initialize the network */ netest_initialize(); #endif -#ifdef CONFIG_EXAMPLES_NETTEST_SERVER - /* Then perform the server side of the test */ +#if defined(CONFIG_EXAMPLES_NETTEST_LOOPBACK) + /* Then perform the server side of the test on a child task */ + + child = task_create("Nettest Child", CONFIG_EXAMPLES_NETTEST_PRIORITY, + CONFIG_EXAMPLES_NETTEST_STACKSIZE, server_child, + NULL); + if (child < 0) + { + fprintf(stderr, "ERROR: Failed to server daemon\n"); + return EXIT_FAILURE; + } + + usleep(500*10000); + +#elif defined(CONFIG_EXAMPLES_NETTEST_SERVER) + /* Then perform the server side of the test on this thread */ recv_server(); -#else - /* Then perform the client side of the test */ +#endif + +#if !defined(CONFIG_EXAMPLES_NETTEST_SERVER) || \ + defined(CONFIG_EXAMPLES_NETTEST_LOOPBACK) + /* Then perform the client side of the test on this thread */ send_client(); #endif - return 0; + return EXIT_SUCCESS; } diff --git a/examples/nettest/nettest_client.c b/examples/nettest/nettest_client.c index 42699b177..d377a9b3a 100644 --- a/examples/nettest/nettest_client.c +++ b/examples/nettest/nettest_client.c @@ -106,6 +106,16 @@ void send_client(void) myaddr.sin6_family = AF_INET6; myaddr.sin6_port = HTONS(PORTNO); +#ifdef CONFIG_EXAMPLES_NETTEST_LOOPBACK + myaddr.sin6_addr.s6_addr16[0] = 0; + myaddr.sin6_addr.s6_addr16[1] = 0; + myaddr.sin6_addr.s6_addr16[2] = 0; + myaddr.sin6_addr.s6_addr16[3] = 0; + myaddr.sin6_addr.s6_addr16[4] = 0; + myaddr.sin6_addr.s6_addr16[5] = 0; + myaddr.sin6_addr.s6_addr16[6] = 0; + myaddr.sin6_addr.s6_addr16[7] = HTONS(1); +#else myaddr.sin6_addr.s6_addr16[0] = HTONS(CONFIG_EXAMPLES_NETTEST_CLIENTIPv6ADDR_1); myaddr.sin6_addr.s6_addr16[1] = HTONS(CONFIG_EXAMPLES_NETTEST_CLIENTIPv6ADDR_2); myaddr.sin6_addr.s6_addr16[2] = HTONS(CONFIG_EXAMPLES_NETTEST_CLIENTIPv6ADDR_3); @@ -114,12 +124,18 @@ void send_client(void) myaddr.sin6_addr.s6_addr16[5] = HTONS(CONFIG_EXAMPLES_NETTEST_CLIENTIPv6ADDR_6); myaddr.sin6_addr.s6_addr16[6] = HTONS(CONFIG_EXAMPLES_NETTEST_CLIENTIPv6ADDR_7); myaddr.sin6_addr.s6_addr16[7] = HTONS(CONFIG_EXAMPLES_NETTEST_CLIENTIPv6ADDR_8); +#endif addrlen = sizeof(struct sockaddr_in6); #else myaddr.sin_family = AF_INET; myaddr.sin_port = HTONS(PORTNO); + +#ifdef CONFIG_EXAMPLES_NETTEST_LOOPBACK + myaddr.sin_addr.s_addr = HTONL(0x7f000001); +#else myaddr.sin_addr.s_addr = HTONL(CONFIG_EXAMPLES_NETTEST_CLIENTIP); +#endif addrlen = sizeof(struct sockaddr_in); #endif