apps/examples/nettest: Extend the test so that it can be down using the local loopback device
This commit is contained in:
parent
6cedfcd632
commit
a7853cdc89
@ -1415,4 +1415,6 @@
|
|||||||
* apps/nettest: Add option to suppress network initialization. This
|
* apps/nettest: Add option to suppress network initialization. This
|
||||||
is necessary if the nettest is run from NSH which has already
|
is necessary if the nettest is run from NSH which has already
|
||||||
initialized the network (2015-08-26).
|
initialized the network (2015-08-26).
|
||||||
|
* apps/nettest: Extend test so that can be performed using the local
|
||||||
|
loopback device (2015-08-26).
|
||||||
|
|
||||||
|
@ -12,19 +12,40 @@ config EXAMPLES_NETTEST
|
|||||||
|
|
||||||
if 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
|
config EXAMPLES_NETTEST_SERVER
|
||||||
bool "Target is server"
|
bool "Target is server"
|
||||||
default n
|
default n
|
||||||
|
depends on !EXAMPLES_NETTEST_LOOPBACK
|
||||||
---help---
|
---help---
|
||||||
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_PERFORMANCE
|
config EXAMPLES_NETTEST_PERFORMANCE
|
||||||
bool "Test for Performance"
|
bool "Test for Performance"
|
||||||
default n
|
default n
|
||||||
---help---
|
---help---
|
||||||
Configure the example to test for network performance. Default: Test
|
Configure the example to test for network performance. Default: Test
|
||||||
is for network functionality.
|
is for network functionality.
|
||||||
|
|
||||||
choice
|
choice
|
||||||
prompt "IP Domain"
|
prompt "IP Domain"
|
||||||
@ -45,7 +66,7 @@ config EXAMPLES_NETTEST_INIT
|
|||||||
bool "Initialize network"
|
bool "Initialize network"
|
||||||
default n if NSH_BUILTIN_APPS
|
default n if NSH_BUILTIN_APPS
|
||||||
default y if !NSH_BUILTIN_APPS
|
default y if !NSH_BUILTIN_APPS
|
||||||
depends on !BUILD_KERNEL
|
depends on !BUILD_KERNEL && !EXAMPLES_NETTEST_LOOPBACK
|
||||||
---help---
|
---help---
|
||||||
Include logic to initialize the network. This should not be done if
|
Include logic to initialize the network. This should not be done if
|
||||||
the network is already initialized when nettest runs. This is
|
the network is already initialized when nettest runs. This is
|
||||||
@ -77,6 +98,8 @@ config EXAMPLES_NETTEST_NETMASK
|
|||||||
|
|
||||||
endif # EXAMPLES_NETTEST_INIT
|
endif # EXAMPLES_NETTEST_INIT
|
||||||
|
|
||||||
|
if !EXAMPLES_NETTEST_LOOPBACK
|
||||||
|
|
||||||
config EXAMPLES_NETTEST_CLIENTIP
|
config EXAMPLES_NETTEST_CLIENTIP
|
||||||
hex "Client IP Address"
|
hex "Client IP Address"
|
||||||
default 0x0a000001 if !EXAMPLES_NETTEST_SERVER
|
default 0x0a000001 if !EXAMPLES_NETTEST_SERVER
|
||||||
@ -89,6 +112,7 @@ config EXAMPLES_NETTEST_CLIENTIP
|
|||||||
host PC IP address (possibly the gateway address,
|
host PC IP address (possibly the gateway address,
|
||||||
EXAMPLES_NETTEST_DRIPADDR?).
|
EXAMPLES_NETTEST_DRIPADDR?).
|
||||||
|
|
||||||
|
endif # !EXAMPLES_NETTEST_LOOPBACK
|
||||||
endif # EXAMPLES_NETTEST_IPv4
|
endif # EXAMPLES_NETTEST_IPv4
|
||||||
|
|
||||||
if EXAMPLES_NETTEST_IPv6
|
if EXAMPLES_NETTEST_IPv6
|
||||||
@ -345,6 +369,8 @@ config EXAMPLES_NETTEST_IPv6NETMASK_8
|
|||||||
endif # NET_ICMPv6_AUTOCONF
|
endif # NET_ICMPv6_AUTOCONF
|
||||||
endif # EXAMPLES_NETTEST_INIT
|
endif # EXAMPLES_NETTEST_INIT
|
||||||
|
|
||||||
|
if !EXAMPLES_NETTEST_LOOPBACK
|
||||||
|
|
||||||
comment "Client IPv6 address"
|
comment "Client IPv6 address"
|
||||||
|
|
||||||
config EXAMPLES_NETTEST_CLIENTIPv6ADDR_1
|
config EXAMPLES_NETTEST_CLIENTIPv6ADDR_1
|
||||||
@ -476,5 +502,6 @@ config EXAMPLES_NETTEST_CLIENTIPv6ADDR_8
|
|||||||
values forming the full IP address must be specified individually.
|
values forming the full IP address must be specified individually.
|
||||||
This is the last of the 8-values.
|
This is the last of the 8-values.
|
||||||
|
|
||||||
|
endif # !EXAMPLES_NETTEST_LOOPBACK
|
||||||
endif # EXAMPLES_NETTEST_IPv6
|
endif # EXAMPLES_NETTEST_IPv6
|
||||||
endif # EXAMPLES_NETTEST
|
endif # EXAMPLES_NETTEST
|
||||||
|
@ -43,7 +43,9 @@ TARG_ASRCS =
|
|||||||
TARG_AOBJS = $(TARG_ASRCS:.S=$(OBJEXT))
|
TARG_AOBJS = $(TARG_ASRCS:.S=$(OBJEXT))
|
||||||
|
|
||||||
TARG_CSRCS =
|
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
|
TARG_CSRCS += nettest_server.c
|
||||||
else
|
else
|
||||||
TARG_CSRCS += nettest_client.c
|
TARG_CSRCS += nettest_client.c
|
||||||
@ -70,24 +72,26 @@ else
|
|||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
HOSTCFLAGS += -DNETTEST_HOST=1
|
ifneq ($(CONFIG_EXAMPLES_NETTEST_LOOPBACK),y)
|
||||||
ifeq ($(CONFIG_EXAMPLES_NETTEST_SERVER),y)
|
HOSTCFLAGS += -DNETTEST_HOST=1
|
||||||
HOSTCFLAGS += -DCONFIG_EXAMPLES_NETTEST_SERVER=1 -DCONFIG_EXAMPLES_NETTEST_CLIENTIP="$(CONFIG_EXAMPLES_NETTEST_CLIENTIP)"
|
ifeq ($(CONFIG_EXAMPLES_NETTEST_SERVER),y)
|
||||||
endif
|
HOSTCFLAGS += -DCONFIG_EXAMPLES_NETTEST_SERVER=1 -DCONFIG_EXAMPLES_NETTEST_CLIENTIP="$(CONFIG_EXAMPLES_NETTEST_CLIENTIP)"
|
||||||
ifeq ($(CONFIG_EXAMPLES_NETTEST_PERFORMANCE),y)
|
endif
|
||||||
HOSTCFLAGS += -DCONFIG_EXAMPLES_NETTEST_PERFORMANCE=1
|
ifeq ($(CONFIG_EXAMPLES_NETTEST_PERFORMANCE),y)
|
||||||
endif
|
HOSTCFLAGS += -DCONFIG_EXAMPLES_NETTEST_PERFORMANCE=1
|
||||||
|
endif
|
||||||
|
|
||||||
HOST_SRCS = host.c
|
HOST_SRCS = host.c
|
||||||
ifeq ($(CONFIG_EXAMPLES_NETTEST_SERVER),y)
|
ifeq ($(CONFIG_EXAMPLES_NETTEST_SERVER),y)
|
||||||
HOST_SRCS += nettest_client.c
|
HOST_SRCS += nettest_client.c
|
||||||
else
|
else
|
||||||
HOST_SRCS += nettest_server.c
|
HOST_SRCS += nettest_server.c
|
||||||
endif
|
endif
|
||||||
|
|
||||||
HOSTOBJEXT ?= .hobj
|
HOSTOBJEXT ?= .hobj
|
||||||
HOST_OBJS = $(HOST_SRCS:.c=$(HOSTOBJEXT))
|
HOST_OBJS = $(HOST_SRCS:.c=$(HOSTOBJEXT))
|
||||||
HOST_BIN = host
|
HOST_BIN = host
|
||||||
|
endif
|
||||||
|
|
||||||
ifeq ($(WINTOOL),y)
|
ifeq ($(WINTOOL),y)
|
||||||
INSTALL_DIR = "${shell cygpath -w $(BIN_DIR)}"
|
INSTALL_DIR = "${shell cygpath -w $(BIN_DIR)}"
|
||||||
@ -119,17 +123,21 @@ $(TARG_AOBJS): %$(OBJEXT): %.S
|
|||||||
$(TARG_COBJS) $(TARG_MAINOBJ): %$(OBJEXT): %.c
|
$(TARG_COBJS) $(TARG_MAINOBJ): %$(OBJEXT): %.c
|
||||||
$(call COMPILE, $<, $@)
|
$(call COMPILE, $<, $@)
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
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_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
|
||||||
|
|
||||||
.built: config.h $(TARG_OBJS)
|
.built: config.h $(TARG_OBJS)
|
||||||
$(call ARCHIVE, $(TARG_BIN), $(TARG_OBJS))
|
$(call ARCHIVE, $(TARG_BIN), $(TARG_OBJS))
|
||||||
@ -164,8 +172,10 @@ endif
|
|||||||
depend: .depend
|
depend: .depend
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
|
ifneq ($(CONFIG_EXAMPLES_NETTEST_LOOPBACK),y)
|
||||||
$(call DELFILE, *$(HOSTOBJEXT))
|
$(call DELFILE, *$(HOSTOBJEXT))
|
||||||
$(call DELFILE, $(HOST_BIN))
|
$(call DELFILE, $(HOST_BIN))
|
||||||
|
endif
|
||||||
$(call DELFILE, .built)
|
$(call DELFILE, .built)
|
||||||
$(call DELFILE, *.dSYM)
|
$(call DELFILE, *.dSYM)
|
||||||
$(call DELFILE, config.h)
|
$(call DELFILE, config.h)
|
||||||
|
@ -41,7 +41,10 @@
|
|||||||
//#include <nuttx/config.h>
|
//#include <nuttx/config.h>
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sched.h>
|
||||||
#include <debug.h>
|
#include <debug.h>
|
||||||
|
|
||||||
#include <net/if.h>
|
#include <net/if.h>
|
||||||
@ -177,6 +180,14 @@ static void netest_initialize(void)
|
|||||||
}
|
}
|
||||||
#endif /*CONFIG_EXAMPLES_NETTEST_INIT */
|
#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
|
* Public Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@ -191,21 +202,42 @@ int main(int argc, FAR char *argv[])
|
|||||||
int nettest_main(int argc, char *argv[])
|
int nettest_main(int argc, char *argv[])
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
|
#if defined(CONFIG_EXAMPLES_NETTEST_LOOPBACK)
|
||||||
|
pid_t child;
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_EXAMPLES_NETTEST_INIT
|
#ifdef CONFIG_EXAMPLES_NETTEST_INIT
|
||||||
/* Initialize the network */
|
/* Initialize the network */
|
||||||
|
|
||||||
netest_initialize();
|
netest_initialize();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_EXAMPLES_NETTEST_SERVER
|
#if defined(CONFIG_EXAMPLES_NETTEST_LOOPBACK)
|
||||||
/* Then perform the server side of the test */
|
/* 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();
|
recv_server();
|
||||||
#else
|
#endif
|
||||||
/* Then perform the client side of the test */
|
|
||||||
|
#if !defined(CONFIG_EXAMPLES_NETTEST_SERVER) || \
|
||||||
|
defined(CONFIG_EXAMPLES_NETTEST_LOOPBACK)
|
||||||
|
/* Then perform the client side of the test on this thread */
|
||||||
|
|
||||||
send_client();
|
send_client();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return 0;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -106,6 +106,16 @@ void send_client(void)
|
|||||||
myaddr.sin6_family = AF_INET6;
|
myaddr.sin6_family = AF_INET6;
|
||||||
myaddr.sin6_port = HTONS(PORTNO);
|
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[0] = HTONS(CONFIG_EXAMPLES_NETTEST_CLIENTIPv6ADDR_1);
|
||||||
myaddr.sin6_addr.s6_addr16[1] = HTONS(CONFIG_EXAMPLES_NETTEST_CLIENTIPv6ADDR_2);
|
myaddr.sin6_addr.s6_addr16[1] = HTONS(CONFIG_EXAMPLES_NETTEST_CLIENTIPv6ADDR_2);
|
||||||
myaddr.sin6_addr.s6_addr16[2] = HTONS(CONFIG_EXAMPLES_NETTEST_CLIENTIPv6ADDR_3);
|
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[5] = HTONS(CONFIG_EXAMPLES_NETTEST_CLIENTIPv6ADDR_6);
|
||||||
myaddr.sin6_addr.s6_addr16[6] = HTONS(CONFIG_EXAMPLES_NETTEST_CLIENTIPv6ADDR_7);
|
myaddr.sin6_addr.s6_addr16[6] = HTONS(CONFIG_EXAMPLES_NETTEST_CLIENTIPv6ADDR_7);
|
||||||
myaddr.sin6_addr.s6_addr16[7] = HTONS(CONFIG_EXAMPLES_NETTEST_CLIENTIPv6ADDR_8);
|
myaddr.sin6_addr.s6_addr16[7] = HTONS(CONFIG_EXAMPLES_NETTEST_CLIENTIPv6ADDR_8);
|
||||||
|
#endif
|
||||||
|
|
||||||
addrlen = sizeof(struct sockaddr_in6);
|
addrlen = sizeof(struct sockaddr_in6);
|
||||||
#else
|
#else
|
||||||
myaddr.sin_family = AF_INET;
|
myaddr.sin_family = AF_INET;
|
||||||
myaddr.sin_port = HTONS(PORTNO);
|
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);
|
myaddr.sin_addr.s_addr = HTONL(CONFIG_EXAMPLES_NETTEST_CLIENTIP);
|
||||||
|
#endif
|
||||||
|
|
||||||
addrlen = sizeof(struct sockaddr_in);
|
addrlen = sizeof(struct sockaddr_in);
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user