diff options
author | Kinsey Moore <kinsey.moore@oarcorp.com> | 2023-04-18 13:52:35 -0500 |
---|---|---|
committer | Kinsey Moore <kinsey.moore@oarcorp.com> | 2023-04-18 13:54:48 -0500 |
commit | 5ccb5955c1f12143956e85cedc363d87c6a7aca9 (patch) | |
tree | b754809d499ef2318738d91290bf5cc8d0399742 | |
parent | legacy: Fixes for the legacy network stack (diff) | |
download | rtems-net-services-5ccb5955c1f12143956e85cedc363d87c6a7aca9.tar.bz2 |
lwip: Restore build and break out adapter source
This fixes the build for tests that use libraries from the installed BSP
and breaks out the common adapter code for reuse.
-rw-r--r-- | netservices.py | 38 | ||||
-rw-r--r-- | stack/common/include/net_adapter.h | 41 | ||||
-rw-r--r-- | stack/lwip/net_adapter.c | 87 | ||||
-rw-r--r-- | testsuites/ntp01/test_main.c | 59 | ||||
-rw-r--r-- | testsuites/telnetd01/init.c | 72 | ||||
-rw-r--r-- | testsuites/ttcpshell01/test_main.c | 38 |
6 files changed, 155 insertions, 180 deletions
diff --git a/netservices.py b/netservices.py index 5922b22..27154e9 100644 --- a/netservices.py +++ b/netservices.py @@ -81,12 +81,15 @@ def build(bld): stack_name = bld.env.STACK_NAME stack_def = 'RTEMS_NET_' + stack_name.upper() - stack_inc = str(bld.path.find_node('stack/' + stack_name + '/include')) + stack_root = 'stack/' + stack_name + stack_inc = str(bld.path.find_node(stack_root + '/include')) + stack_common_inc = 'stack/common/include' + stack_adapter_source = stack_root + '/net_adapter.c' ns_cflags = ['-g', '-Wall', bld.env.OPTIMIZATION] ntp_source_files = [] - ntp_incl = [stack_inc] + ntp_incl = [stack_inc, stack_common_inc] arch_lib_path = rtems.arch_bsp_lib_path(bld.env.RTEMS_VERSION, bld.env.RTEMS_ARCH_BSP) @@ -107,7 +110,7 @@ def build(bld): use=[stack_name]) bld.install_files("${PREFIX}/" + arch_lib_path, ["libntp.a"]) - ttcp_incl = [stack_inc, 'ttcp/include'] + ttcp_incl = [stack_inc, stack_common_inc, 'ttcp/include'] ttcp_source_files = ['ttcp/ttcp.c'] @@ -138,42 +141,49 @@ def build(bld): [install_headers(path) for path in ntp_incl] - #lib_path = os.path.join(bld.env.PREFIX, arch_lib_path) - #bld.read_stlib('lwip', paths=[lib_path]) - #bld.read_stlib('rtemstest', paths=[lib_path]) - #bld.read_stlib('telnetd', paths=[lib_path]) + # bring in knowledge of libraries from the installed BSP + lib_path = os.path.join(bld.env.PREFIX, arch_lib_path) + bld.read_stlib(stack_name, paths=[lib_path]) + bld.read_stlib('rtemstest', paths=[lib_path]) + bld.read_stlib('telnetd', paths=[lib_path]) libs = ['m', 'rtemstest'] - ntp_test_incl = ntp_incl + ['testsuites'] + ntp_test_incl = ntp_incl + ['testsuites', stack_common_inc] + ntp_test_sources = ['testsuites/ntp01/test_main.c'] + ntp_test_sources += [stack_adapter_source] bld.program(features='c', target='ntp01.exe', - source='testsuites/ntp01/test_main.c', + source=' '.join(ntp_test_sources), cflags=ns_cflags, includes=ntp_test_incl, defines=[stack_def], lib=libs, use=['ntp', stack_name]) - ttcp_test_incl = ttcp_incl + ['testsuites'] + ttcp_test_incl = ttcp_incl + ['testsuites', stack_common_inc] + ttcp_test_sources = ['testsuites/ttcpshell01/test_main.c'] + ttcp_test_sources += [stack_adapter_source] bld.program(features='c', target='ttcpshell01.exe', - source='testsuites/ttcpshell01/test_main.c', + source=' '.join(ttcp_test_sources), cflags=ns_cflags, defines=[stack_def], includes=ttcp_test_incl, lib=libs, use=['ttcp', stack_name]) - test_app_incl = [stack_inc, 'testsuites'] + tlnt_test_incl = [stack_inc, stack_common_inc, 'testsuites'] + tlnt_test_sources = ['testsuites/telnetd01/init.c'] + tlnt_test_sources += [stack_adapter_source] bld.program(features='c', target='telnetd01.exe', - source='testsuites/telnetd01/init.c', + source=' '.join(tlnt_test_sources), cflags=ns_cflags, defines=[stack_def], - includes=test_app_incl, + includes=tlnt_test_incl, lib=libs, use=['telnetd', stack_name]) diff --git a/stack/common/include/net_adapter.h b/stack/common/include/net_adapter.h new file mode 100644 index 0000000..340d7dd --- /dev/null +++ b/stack/common/include/net_adapter.h @@ -0,0 +1,41 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/** + * @file + * + * @brief This file contains the prototypes for network adapters necessary for + * network services tests to run on lwIP. + */ + +/* + * COPYRIGHT (c) 2023. On-Line Applications Research Corporation (OAR). + * All rights reserved. + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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 NET_ADAPTER_H +#define NET_ADAPTER_H + +int net_start(void); + +#endif /* NET_ADAPTER_H */ diff --git a/stack/lwip/net_adapter.c b/stack/lwip/net_adapter.c new file mode 100644 index 0000000..09f50bb --- /dev/null +++ b/stack/lwip/net_adapter.c @@ -0,0 +1,87 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/** + * @file + * + * @brief This file contains the adapter necessary for network services tests to + * run on lwIP. + */ + +/* + * COPYRIGHT (c) 2023. On-Line Applications Research Corporation (OAR). + * All rights reserved. + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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 <lwip/dhcp.h> +#include <lwip/prot/dhcp.h> +#include <arch/sys_arch.h> + +#include <netstart.h> +#include <bsd_compat.h> +#include <net_adapter.h> + +struct netif net_interface; + +int net_start() +{ + ip_addr_t ipaddr, netmask, gw; + + IP_ADDR4( &ipaddr, 10, 0, 2, 14 ); + IP_ADDR4( &netmask, 255, 255, 255, 0 ); + IP_ADDR4( &gw, 10, 0, 2, 3 ); + unsigned char mac_ethernet_address[] = { 0x00, 0x0a, 0x35, 0x00, 0x22, 0x01 }; + + rtems_bsd_compat_initialize(); + + int ret = start_networking( + &net_interface, + &ipaddr, + &netmask, + &gw, + mac_ethernet_address + ); + + if ( ret != 0 ) { + return ret; + } + + dhcp_start( &net_interface ); + + /* + * Wait for DHCP bind to start NTP. lwIP does automatic address updating in + * the backend that NTP isn't prepared for which causes socket conflicts when + * the socket for the old address gets updated to the new address and NTP's + * address information for the old socket is stale. NTP tries to create a new + * socket for the new address before deleting the old one and gets an error + * because it can't bind twice to the same address. This causes NTP + * acquisition to be delayed by minutes in the worst case. + */ + volatile struct dhcp *dhcp_state = netif_dhcp_data(&net_interface); + if ( dhcp_state != NULL ) { + while (dhcp_state->state != DHCP_STATE_BOUND) { + sleep(1); + } + } + return 0; +} diff --git a/testsuites/ntp01/test_main.c b/testsuites/ntp01/test_main.c index 734e742..229a013 100644 --- a/testsuites/ntp01/test_main.c +++ b/testsuites/ntp01/test_main.c @@ -38,67 +38,12 @@ #include <rtems/ntpd.h> #include <rtems/shell.h> -#if RTEMS_NET_LWIP -#include <lwip/dhcp.h> -#include <lwip/prot/dhcp.h> -#include <arch/sys_arch.h> -#include <netstart.h> -#include <bsd_compat.h> -#endif +#include <net_adapter.h> #include <tmacros.h> const char rtems_test_name[] = "NTP 1"; -static int net_start(void); - -#if RTEMS_NET_LWIP -struct netif net_interface; - -static int net_start(void) { - ip_addr_t ipaddr, netmask, gw; - - IP_ADDR4( &ipaddr, 10, 0, 2, 14 ); - IP_ADDR4( &netmask, 255, 255, 255, 0 ); - IP_ADDR4( &gw, 10, 0, 2, 3 ); - unsigned char mac_ethernet_address[] = { 0x00, 0x0a, 0x35, 0x00, 0x22, 0x01 }; - - rtems_bsd_compat_initialize(); - - ret = start_networking( - &net_interface, - &ipaddr, - &netmask, - &gw, - mac_ethernet_address - ); - - if ( ret != 0 ) { - return 1; - } - - dhcp_start( &net_interface ); - - /* - * Wait for DHCP bind to start NTP. lwIP does automatic address updating in - * the backend that NTP isn't prepared for which causes socket conflicts when - * the socket for the old address gets updated to the new address and NTP's - * address information for the old socket is stale. NTP tries to create a new - * socket for the new address before deleting the old one and gets an error - * because it can't bind twice to the same address. This causes NTP - * acquisition to be delayed by minutes in the worst case. - */ - volatile struct dhcp *dhcp_state = netif_dhcp_data(&net_interface); - if ( dhcp_state != NULL ) { - while (dhcp_state->state != DHCP_STATE_BOUND) { - sleep(1); - } - } - - return 0; -} -#endif - static const char etc_resolv_conf[] = "nameserver 8.8.8.8\n"; @@ -419,8 +364,6 @@ static void run_test(void) static rtems_task Init( rtems_task_argument argument ) { - int ret; - TEST_BEGIN(); rtems_test_assert( net_start() == 0 ); diff --git a/testsuites/telnetd01/init.c b/testsuites/telnetd01/init.c index 9d78fd1..03edfa3 100644 --- a/testsuites/telnetd01/init.c +++ b/testsuites/telnetd01/init.c @@ -28,18 +28,12 @@ #include <rtems/telnetd.h> -#if RTEMS_NET_LWIP -#include <lwip/dhcp.h> -#include <arch/sys_arch.h> -#include <netstart.h> -#endif +#include <net_adapter.h> #include <tmacros.h> const char rtems_test_name[] = "TELNETD 1"; -static int net_start(void); - rtems_shell_env_t env; static void telnet_shell( char *name, void *arg ) @@ -57,71 +51,9 @@ rtems_telnetd_config_table rtems_telnetd_config = { .stack_size = 8 * RTEMS_MINIMUM_STACK_SIZE, }; -#if RTEMS_NET_LWIP -struct netif net_interface; - -#define print_ip( tag, ip ) \ - printf( \ - "%s: %" PRId32 ".%" PRId32 ".%" PRId32 ".%" PRId32 "\n", \ - tag, \ - ( ntohl( ip.addr ) >> 24 ) & 0xff, \ - ( ntohl( ip.addr ) >> 16 ) & 0xff, \ - ( ntohl( ip.addr ) >> 8 ) & 0xff, \ - ntohl( ip.addr ) & 0xff \ - ); - -static int shell_main_netinfo( - int argc, - char **argv -) -{ - print_ip( "IP", net_interface.ip_addr.u_addr.ip4 ); - print_ip( "Mask", net_interface.netmask.u_addr.ip4 ); - print_ip( "GW", net_interface.gw.u_addr.ip4 ); - return 0; -} - -rtems_shell_cmd_t shell_NETINFO_Command = { - "netinfo", /* name */ - "netinfo - shows basic network info, no arguments", /* usage */ - "net", /* topic */ - shell_main_netinfo, /* command */ - NULL, /* alias */ - NULL /* next */ -}; - -static int net_start(void) { - ip_addr_t ipaddr, netmask, gw; - - IP_ADDR4( &ipaddr, 10, 0, 2, 14 ); - IP_ADDR4( &netmask, 255, 255, 255, 0 ); - IP_ADDR4( &gw, 10, 0, 2, 3 ); - unsigned char mac_ethernet_address[] = { 0x00, 0x0a, 0x35, 0x00, 0x22, 0x01 }; - - rtems_shell_init_environment(); - - ret = start_networking( - &net_interface, - &ipaddr, - &netmask, - &gw, - mac_ethernet_address - ); - - if ( ret != 0 ) { - return 1; - } - - dhcp_start( &net_interface ); - - return 0; -} -#endif - static rtems_task Init( rtems_task_argument argument ) { rtems_status_code sc; - int ret; TEST_BEGIN(); @@ -141,7 +73,6 @@ static rtems_task Init( rtems_task_argument argument ) use NULL to disable a login check */ ); rtems_test_assert( sc == RTEMS_SUCCESSFUL ); - sys_arch_delay( 300000 ); TEST_END(); rtems_test_exit( 0 ); @@ -159,7 +90,6 @@ static rtems_task Init( rtems_task_argument argument ) #define CONFIGURE_SHELL_COMMANDS_INIT #define CONFIGURE_SHELL_COMMANDS_ALL -#define CONFIGURE_SHELL_USER_COMMANDS &shell_NETINFO_Command #define CONFIGURE_MAXIMUM_TASKS 12 diff --git a/testsuites/ttcpshell01/test_main.c b/testsuites/ttcpshell01/test_main.c index b3e626c..c84a788 100644 --- a/testsuites/ttcpshell01/test_main.c +++ b/testsuites/ttcpshell01/test_main.c @@ -37,21 +37,12 @@ #include <rtems/console.h> #include <ttcp.h> -#if RTEMS_NET_LWIP -#include <lwip/dhcp.h> -#include <arch/sys_arch.h> -#include <netstart.h> -#endif +#include <net_adapter.h> #include <tmacros.h> const char rtems_test_name[] = "lwIP TTCP 1"; -static int net_start(void); - -#if RTEMS_NET_LWIP -struct netif net_interface; - rtems_shell_cmd_t shell_TTCP_Command = { "ttcp", /* name */ "ttcp -h # to get help", /* usage */ @@ -61,35 +52,9 @@ rtems_shell_cmd_t shell_TTCP_Command = { NULL /* next */ }; -static int net_start(void) { - ip_addr_t ipaddr, netmask, gw; - - IP_ADDR4( &ipaddr, 10, 0, 2, 14 ); - IP_ADDR4( &netmask, 255, 255, 255, 0 ); - IP_ADDR4( &gw, 10, 0, 2, 3 ); - unsigned char mac_ethernet_address[] = { 0x00, 0x0a, 0x35, 0x00, 0x22, 0x01 }; - - ret = start_networking( - &net_interface, - &ipaddr, - &netmask, - &gw, - mac_ethernet_address - ); - - if ( ret != 0 ) { - return 1; - } - - dhcp_start( &net_interface ); - - return 0; -} - static rtems_task Init( rtems_task_argument argument ) { rtems_status_code sc; - int ret; TEST_BEGIN(); @@ -108,7 +73,6 @@ static rtems_task Init( rtems_task_argument argument ) use NULL to disable a login check */ ); rtems_test_assert( sc == RTEMS_SUCCESSFUL ); - sys_arch_delay( 300000 ); TEST_END(); rtems_test_exit( 0 ); |