examples/nettest: Add support for both enpoints on target boards vs. one on a target and one on the host PC.

This commit is contained in:
Gregory Nutt 2017-06-23 18:12:34 -06:00
parent 1c0f237c06
commit a3ac695f17
7 changed files with 149 additions and 33 deletions

View File

@ -36,17 +36,9 @@ config EXAMPLES_NETTEST_LOOPBACK
Perform the test using the local loopback device. In this case, Perform the test using the local loopback device. In this case,
both the client and the server reside on the target. both the client and the server reside on the target.
if EXAMPLES_NETTEST_LOOPBACK # No server if loopback; No second target if loopback
config EXAMPLES_NETTEST_SERVER_STACKSIZE if !EXAMPLES_NETTEST_LOOPBACK
int "Server stack size"
default 2048
config EXAMPLES_NETTEST_SERVER_PRIORITY
int "Server priority"
default 100
endif # EXAMPLES_NETTEST_LOOPBACK
config EXAMPLES_NETTEST_SERVER1 config EXAMPLES_NETTEST_SERVER1
bool "Target1 is server" bool "Target1 is server"
@ -56,6 +48,51 @@ config EXAMPLES_NETTEST_SERVER1
Select to use the host as the client side of the test. Default: The Select to use the host as the client side of the test. Default: The
target is the client side of the test target is the client side of the test
config EXAMPLES_NETTEST_TARGET2
bool "Second endpoint is a target"
default n
---help---
By default, the host PC is configured as the second endpoint of the
NETTEST. If this option is selected, then the second endpoint
will be built into the FLASH image as well. This means that you
can use two target boards to run the test with no host PC
involvement.
if EXAMPLES_NETTEST_TARGET2
config EXAMPLES_NETTEST_PROGNAME2
string "Target2 program name"
default "udpserver" if !EXAMPLES_NETTEST_SERVER2
default "udpclient" if EXAMPLES_NETTEST_SERVER2
depends on BUILD_KERNEL
---help---
This is the name of the Target2 program that will be use when the
NSH ELF program is installed.
config EXAMPLES_NETTEST_PRIORITY2
int "Target2 task priority"
default 100
config EXAMPLES_NETTEST_STACKSIZE2
int "Target2 stack size"
default 2048
endif # EXAMPLES_NETTEST_TARGET2
config EXAMPLES_NETTEST_DAEMON_STACKSIZE
int "Server daemon stack size"
default 2048
config EXAMPLES_NETTEST_DEAMON_PRIORITY
int "Server daemon priority"
default 100
endif # EXAMPLES_NETTEST_LOOPBACK
config EXAMPLES_NETTEST_DEVNAME
string "Network device"
default "eth0"
config EXAMPLES_NETTEST_PERFORMANCE config EXAMPLES_NETTEST_PERFORMANCE
bool "Test for Performance" bool "Test for Performance"
default n default n
@ -78,6 +115,8 @@ config EXAMPLES_NETTEST_IPv6
endchoice # IP Domain endchoice # IP Domain
# No hardware initialization if loopback
config EXAMPLES_NETTEST_INIT config EXAMPLES_NETTEST_INIT
bool "Initialize network" bool "Initialize network"
default n if NSH_BUILTIN_APPS default n if NSH_BUILTIN_APPS
@ -114,6 +153,8 @@ config EXAMPLES_NETTEST_NETMASK
endif # EXAMPLES_NETTEST_INIT endif # EXAMPLES_NETTEST_INIT
# No server if loopback
if !EXAMPLES_NETTEST_LOOPBACK if !EXAMPLES_NETTEST_LOOPBACK
config EXAMPLES_NETTEST_SERVERIP config EXAMPLES_NETTEST_SERVERIP
@ -385,9 +426,11 @@ config EXAMPLES_NETTEST_IPv6NETMASK_8
endif # NET_ICMPv6_AUTOCONF endif # NET_ICMPv6_AUTOCONF
endif # EXAMPLES_NETTEST_INIT endif # EXAMPLES_NETTEST_INIT
# Addresses are well known if loopback is used.
if !EXAMPLES_NETTEST_LOOPBACK || !NET_LOOPBACK if !EXAMPLES_NETTEST_LOOPBACK || !NET_LOOPBACK
comment "Client IPv6 address" comment "Server IPv6 address"
config EXAMPLES_NETTEST_SERVERIPv6ADDR_1 config EXAMPLES_NETTEST_SERVERIPv6ADDR_1
hex "[0]" hex "[0]"

View File

@ -82,12 +82,51 @@ STACKSIZE1 = $(CONFIG_EXAMPLES_NETTEST_STACKSIZE1)
# Target 2 # Target 2
ifeq ($(CONFIG_EXAMPLES_NETTEST_TARGET2),y)
TARG2_CSRCS =
ifeq ($(CONFIG_EXAMPLES_NETTEST_SERVER1),y)
TARG2_CSRCS += nettest_client.c
else
TARG2_CSRCS += nettest_server.c
endif
TARG2_MAINSRC = nettest_target2.c
TARG2_COBJS = $(TARG2_CCRCS:.c=$(OBJEXT))
TARG2_MAINOBJ = $(TARG2_MAINSRC:.c=$(OBJEXT))
# Target 2 Application Info # Target 2 Application Info
# Target common ifeq ($(CONFIG_EXAMPLES_NETTEST_SERVER1),y)
CONFIG_EXAMPLES_NETTEST_PROGNAME2 ?= tcpclient
APPNAME2 = tcpclient
else
CONFIG_EXAMPLES_NETTEST_PROGNAME2 ?= tcpserver
APPNAME2 = tcpserver
endif
CONFIG_EXAMPLES_NETTEST_PRIORITY2 ?= 100
CONFIG_EXAMPLES_NETTEST_STACKSIZE2 ?= 2048
PROGNAME2 = $(CONFIG_EXAMPLES_NETTEST_PROGNAME2)
PRIORITY2 = $(CONFIG_EXAMPLES_NETTEST_PRIORITY2)
STACKSIZE2 = $(CONFIG_EXAMPLES_NETTEST_STACKSIZE2)
endif
# All targets
TARG_SRCS = $(TARG1_CRCS) $(TARG1_MAINSRC) $(TARG2_CSRCS) $(TARG2_MAINSRC) $(TARGCMN_CSRCS)
TARG_OBJS = $(TARG1_COBJS) $(TARG2_COBJS) $(TARGCMN_COBJS)
ifneq ($(CONFIG_BUILD_KERNEL),y) ifneq ($(CONFIG_BUILD_KERNEL),y)
TARG_OBJS += $(TARG1_MAINOBJ) TARG_OBJS += $(TARG1_MAINOBJ) $(TARG2_MAINOBJ)
endif
ifeq ($(CONFIG_EXAMPLES_NETTEST_TARGET2),y)
MAINNAME1 = nettest1_main
MAINNAME2 = nettest2_main
else
MAINNAME1 = nettest_main
endif endif
ifeq ($(CONFIG_WINDOWS_NATIVE),y) ifeq ($(CONFIG_WINDOWS_NATIVE),y)
@ -102,7 +141,9 @@ endif
# Host # Host
ifneq ($(CONFIG_EXAMPLES_NETTEST_TARGET2),y)
ifneq ($(CONFIG_EXAMPLES_NETTEST_LOOPBACK),y) ifneq ($(CONFIG_EXAMPLES_NETTEST_LOOPBACK),y)
HOSTCFLAGS += -DNETTEST_HOST=1 HOSTCFLAGS += -DNETTEST_HOST=1
ifeq ($(CONFIG_EXAMPLES_NETTEST_SERVER),y) ifeq ($(CONFIG_EXAMPLES_NETTEST_SERVER),y)
HOSTCFLAGS += -DCONFIG_EXAMPLES_NETTEST_SERVER=1 -DCONFIG_EXAMPLES_NETTEST_SERVERIP="$(CONFIG_EXAMPLES_NETTEST_SERVERIP)" HOSTCFLAGS += -DCONFIG_EXAMPLES_NETTEST_SERVER=1 -DCONFIG_EXAMPLES_NETTEST_SERVERIP="$(CONFIG_EXAMPLES_NETTEST_SERVERIP)"
@ -122,6 +163,8 @@ ifneq ($(CONFIG_EXAMPLES_NETTEST_LOOPBACK),y)
HOSTOBJEXT ?= hobj HOSTOBJEXT ?= hobj
HOST_OBJS = $(HOST_SRCS:.c=.$(HOSTOBJEXT)) HOST_OBJS = $(HOST_SRCS:.c=.$(HOSTOBJEXT))
endif
endif endif
ifeq ($(WINTOOL),y) ifeq ($(WINTOOL),y)
@ -142,20 +185,28 @@ all: .built $(HOST_BIN)
$(TARG1_COBJS) $(TARG1_MAINOBJ) $(TARGCMN_COBJS) : %$(OBJEXT): %.c $(TARG1_COBJS) $(TARG1_MAINOBJ) $(TARGCMN_COBJS) : %$(OBJEXT): %.c
$(call COMPILE, $<, $@) $(call COMPILE, $<, $@)
ifneq ($(CONFIG_EXAMPLES_UDP_TARGET2),y)
ifneq ($(CONFIG_EXAMPLES_NETTEST_LOOPBACK),y) ifneq ($(CONFIG_EXAMPLES_NETTEST_LOOPBACK),y)
$(HOST_OBJS): %.$(HOSTOBJEXT): %.c $(HOST_OBJS): %.$(HOSTOBJEXT): %.c
@echo "CC: $<" @echo "CC: $<"
$(Q) $(HOSTCC) -c $(HOSTCFLAGS) $< -o $@ $(Q) $(HOSTCC) -c $(HOSTCFLAGS) $< -o $@
endif
endif endif
config.h: $(TOPDIR)/include/nuttx/config.h config.h: $(TOPDIR)/include/nuttx/config.h
@echo "CP: $<" @echo "CP: $<"
$(Q) cp $< $@ $(Q) cp $< $@
ifneq ($(CONFIG_EXAMPLES_UDP_TARGET2),y)
ifneq ($(CONFIG_EXAMPLES_NETTEST_LOOPBACK),y) ifneq ($(CONFIG_EXAMPLES_NETTEST_LOOPBACK),y)
$(HOST_BIN): config.h $(HOST_OBJS) $(HOST_BIN): config.h $(HOST_OBJS)
@echo "LD: $@" @echo "LD: $@"
$(Q) $(HOSTCC) $(HOSTLDFLAGS) $(HOST_OBJS) -o $@ $(Q) $(HOSTCC) $(HOSTLDFLAGS) $(HOST_OBJS) -o $@
endif
endif endif
.built: config.h $(TARG_OBJS) .built: config.h $(TARG_OBJS)
@ -177,9 +228,17 @@ endif
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y) ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME1)_main.bdat: $(DEPCONFIG) Makefile $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME1)_main.bdat: $(DEPCONFIG) Makefile
$(call REGISTER,$(APPNAME1),$(PRIORITY1),$(STACKSIZE1),$(APPNAME1)_main) $(call REGISTER,$(APPNAME1),$(PRIORITY1),$(STACKSIZE1),$(MAINNAME1))
ifeq ($(CONFIG_EXAMPLES_UDP_TARGET2),y)
$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME2)_main.bdat: $(DEPCONFIG) Makefile
$(call REGISTER,$(APPNAME2),$(PRIORITY2),$(STACKSIZE2),$(MAINNAME2))
context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME1)_main.bdat \
$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME2)_main.bdat
else
context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME1)_main.bdat context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME1)_main.bdat
endif
else else
context: context:
endif endif
@ -191,9 +250,11 @@ endif
depend: .depend depend: .depend
clean: clean:
ifneq ($(CONFIG_EXAMPLES_UDP_TARGET2),y)
ifneq ($(CONFIG_EXAMPLES_NETTEST_LOOPBACK),y) ifneq ($(CONFIG_EXAMPLES_NETTEST_LOOPBACK),y)
$(call DELFILE, *.$(HOSTOBJEXT)) $(call DELFILE, *.$(HOSTOBJEXT))
$(call DELFILE, $(HOST_BIN)) $(call DELFILE, $(HOST_BIN))
endif
endif endif
$(call DELFILE, .built) $(call DELFILE, .built)
$(call DELFILE, *.dSYM) $(call DELFILE, *.dSYM)

View File

@ -57,8 +57,10 @@
* nettest_main * nettest_main
****************************************************************************/ ****************************************************************************/
#ifdef CONFIG_BUILD_KERNEL #if defined(CONFIG_BUILD_KERNEL)
int main(int argc, FAR char *argv[]) int main(int argc, FAR char *argv[])
#elif defined(CONFIG_EXAMPLES_NETTEST_TARGET2)
int nettest1_main(int argc, char *argv[])
#else #else
int nettest_main(int argc, char *argv[]) int nettest_main(int argc, char *argv[])
#endif #endif
@ -83,8 +85,8 @@ int nettest_main(int argc, char *argv[])
#if defined(CONFIG_EXAMPLES_NETTEST_LOOPBACK) #if defined(CONFIG_EXAMPLES_NETTEST_LOOPBACK)
/* Then perform the server side of the test on a child task */ /* Then perform the server side of the test on a child task */
child = task_create("Nettest Child", CONFIG_EXAMPLES_NETTEST_SERVER_PRIORITY, child = task_create("Nettest Child", CONFIG_EXAMPLES_NETTEST_DAEMON_PRIORITY,
CONFIG_EXAMPLES_NETTEST_SERVER_STACKSIZE, server_child, CONFIG_EXAMPLES_NETTEST_DAEMON_STACKSIZE, server_child,
NULL); NULL);
if (child < 0) if (child < 0)
{ {

View File

@ -38,7 +38,7 @@
****************************************************************************/ ****************************************************************************/
#include "config.h" #include "config.h"
#include <stdlib.h>
#include "nettest.h" #include "nettest.h"
/**************************************************************************** /****************************************************************************

View File

@ -53,6 +53,16 @@
#ifdef CONFIG_EXAMPLES_NETTEST_INIT #ifdef CONFIG_EXAMPLES_NETTEST_INIT
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#ifdef CONFIG_EXAMPLES_NETTEST_DEVNAME
# define DEVNAME CONFIG_EXAMPLES_NETTEST_DEVNAME
#else
# define DEVNAME "eth0"
#endif
/**************************************************************************** /****************************************************************************
* Private Data * Private Data
****************************************************************************/ ****************************************************************************/
@ -126,37 +136,37 @@ void nettest_initialize(void)
mac[3] = 0xad; mac[3] = 0xad;
mac[4] = 0xbe; mac[4] = 0xbe;
mac[5] = 0xef; mac[5] = 0xef;
netlib_setmacaddr("eth0", mac); netlib_setmacaddr(DEVNAME, mac);
#endif #endif
#ifdef CONFIG_EXAMPLES_NETTEST_IPv6 #ifdef CONFIG_EXAMPLES_NETTEST_IPv6
#ifdef CONFIG_NET_ICMPv6_AUTOCONF #ifdef CONFIG_NET_ICMPv6_AUTOCONF
/* Perform ICMPv6 auto-configuration */ /* Perform ICMPv6 auto-configuration */
netlib_icmpv6_autoconfiguration("eth0"); netlib_icmpv6_autoconfiguration(DEVNAME);
#else /* CONFIG_NET_ICMPv6_AUTOCONF */ #else /* CONFIG_NET_ICMPv6_AUTOCONF */
/* Set up our fixed host address */ /* Set up our fixed host address */
netlib_set_ipv6addr("eth0", netlib_set_ipv6addr(DEVNAME,
(FAR const struct in6_addr *)g_ipv6_hostaddr); (FAR const struct in6_addr *)g_ipv6_hostaddr);
/* Set up the default router address */ /* Set up the default router address */
netlib_set_dripv6addr("eth0", netlib_set_dripv6addr(DEVNAME,
(FAR const struct in6_addr *)g_ipv6_draddr); (FAR const struct in6_addr *)g_ipv6_draddr);
/* Setup the subnet mask */ /* Setup the subnet mask */
netlib_set_ipv6netmask("eth0", netlib_set_ipv6netmask(DEVNAME,
(FAR const struct in6_addr *)g_ipv6_netmask); (FAR const struct in6_addr *)g_ipv6_netmask);
/* New versions of netlib_set_ipvXaddr will not bring the network up, /* New versions of netlib_set_ipvXaddr will not bring the network up,
* So ensure the network is really up at this point. * So ensure the network is really up at this point.
*/ */
netlib_ifup("eth0"); netlib_ifup(DEVNAME);
#endif /* CONFIG_NET_ICMPv6_AUTOCONF */ #endif /* CONFIG_NET_ICMPv6_AUTOCONF */
#else /* CONFIG_EXAMPLES_NETTEST_IPv6 */ #else /* CONFIG_EXAMPLES_NETTEST_IPv6 */
@ -164,17 +174,17 @@ void nettest_initialize(void)
/* Set up our host address */ /* Set up our host address */
addr.s_addr = HTONL(CONFIG_EXAMPLES_NETTEST_IPADDR); addr.s_addr = HTONL(CONFIG_EXAMPLES_NETTEST_IPADDR);
netlib_set_ipv4addr("eth0", &addr); netlib_set_ipv4addr(DEVNAME, &addr);
/* Set up the default router address */ /* Set up the default router address */
addr.s_addr = HTONL(CONFIG_EXAMPLES_NETTEST_DRIPADDR); addr.s_addr = HTONL(CONFIG_EXAMPLES_NETTEST_DRIPADDR);
netlib_set_dripv4addr("eth0", &addr); netlib_set_dripv4addr(DEVNAME, &addr);
/* Setup the subnet mask */ /* Setup the subnet mask */
addr.s_addr = HTONL(CONFIG_EXAMPLES_NETTEST_NETMASK); addr.s_addr = HTONL(CONFIG_EXAMPLES_NETTEST_NETMASK);
netlib_set_ipv4netmask("eth0", &addr); netlib_set_ipv4netmask(DEVNAME, &addr);
#endif /* CONFIG_EXAMPLES_NETTEST_IPv6 */ #endif /* CONFIG_EXAMPLES_NETTEST_IPv6 */
} }

View File

@ -42,7 +42,7 @@ config EXAMPLES_UDP_TARGET2
By default, the host PC is configured as the second endpoint of the By default, the host PC is configured as the second endpoint of the
UDP test. If this option is selected, then the second endpoint UDP test. If this option is selected, then the second endpoint
will be built into the FLASH image as well. This means that you will be built into the FLASH image as well. This means that you
can use two target boards to run the test with not host PC can use two target boards to run the test with no host PC
involvement. involvement.
if EXAMPLES_UDP_TARGET2 if EXAMPLES_UDP_TARGET2

View File

@ -77,15 +77,15 @@ STACKSIZE1 = $(CONFIG_EXAMPLES_UDP_STACKSIZE1)
ifeq ($(CONFIG_EXAMPLES_UDP_TARGET2),y) ifeq ($(CONFIG_EXAMPLES_UDP_TARGET2),y)
TARG2_CRCS = TARG2_CSRCS =
ifeq ($(CONFIG_EXAMPLES_UDP_SERVER1),y) ifeq ($(CONFIG_EXAMPLES_UDP_SERVER1),y)
TARG2_CRCS += udp_client.c TARG2_CSRCS += udp_client.c
else else
TARG2_CRCS += udp_server.c TARG2_CSRCS += udp_server.c
endif endif
TARG2_MAINSRC = udp_target2.c TARG2_MAINSRC = udp_target2.c
TARG2_COBJS = $(TARG2_CRCS:.c=$(OBJEXT)) TARG2_COBJS = $(TARG2_CSRCS:.c=$(OBJEXT))
TARG2_MAINOBJ = $(TARG2_MAINSRC:.c=$(OBJEXT)) TARG2_MAINOBJ = $(TARG2_MAINSRC:.c=$(OBJEXT))
ifeq ($(CONFIG_EXAMPLES_UDP_SERVER1),y) ifeq ($(CONFIG_EXAMPLES_UDP_SERVER1),y)
@ -104,7 +104,7 @@ STACKSIZE2 = $(CONFIG_EXAMPLES_UDP_STACKSIZE2)
endif endif
TARG_SRCS = $(TARG1_CRCS) $(TARG1_MAINSRC) $(TARG2_CRCS) $(TARG2_MAINSRC) $(TARGCMN_CSRCS) TARG_SRCS = $(TARG1_CRCS) $(TARG1_MAINSRC) $(TARG2_CSRCS) $(TARG2_MAINSRC) $(TARGCMN_CSRCS)
TARG_OBJS = $(TARG1_COBJS) $(TARG2_COBJS) $(TARGCMN_COBJS) TARG_OBJS = $(TARG1_COBJS) $(TARG2_COBJS) $(TARGCMN_COBJS)
ifneq ($(CONFIG_BUILD_KERNEL),y) ifneq ($(CONFIG_BUILD_KERNEL),y)