diff options
Diffstat (limited to 'testsuites/ntp01/test_main.c')
-rw-r--r-- | testsuites/ntp01/test_main.c | 103 |
1 files changed, 58 insertions, 45 deletions
diff --git a/testsuites/ntp01/test_main.c b/testsuites/ntp01/test_main.c index ffc656a..734e742 100644 --- a/testsuites/ntp01/test_main.c +++ b/testsuites/ntp01/test_main.c @@ -38,19 +38,67 @@ #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 <tmacros.h> - #include <netstart.h> #include <bsd_compat.h> +#endif + +#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"; @@ -330,19 +378,21 @@ static const char etc_services[] = static void setup_etc(void) { int rv; - + + /* FIXME: no direct IMFS */ + rv = IMFS_make_linearfile("/etc/resolv.conf", S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH, etc_resolv_conf, sizeof(etc_resolv_conf)); assert(rv == 0); - + rv = IMFS_make_linearfile("/etc/ntp.conf", S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH, etc_ntp_conf, sizeof(etc_ntp_conf)); assert(rv == 0); - + rv = IMFS_make_linearfile("/etc/leap-seconds", S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH, etc_leap_seconds, sizeof(etc_leap_seconds)); assert(rv == 0); - + rv = IMFS_make_linearfile("/etc/services", S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH, etc_services, sizeof(etc_services)); assert(rv == 0); @@ -373,47 +423,10 @@ static rtems_task Init( rtems_task_argument argument ) TEST_BEGIN(); - 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; - } + rtems_test_assert( net_start() == 0 ); rtems_shell_init_environment(); - 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); - } - } - run_test(); TEST_END(); |