summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Johns <chrisj@rtems.org>2021-08-08 16:35:02 +1000
committerChris Johns <chrisj@rtems.org>2021-08-27 17:04:30 +1000
commitefd75d2e355b47bff42112322151a679aa615024 (patch)
tree657cd14f3e5bd83e8b2576baff1221dc4e1ced32
parentrtemsbsd: Add interface support routines (diff)
downloadrtems-libbsd-efd75d2e355b47bff42112322151a679aa615024.tar.bz2
testsuite: Wait for the link to be UP
- Wait for a slow PHY to bring the link UP. If the IP address is static the test can start before the link is up and the test fails. - Make 2 tests wait. Others will need to be added.
-rw-r--r--testsuite/include/rtems/bsd/test/default-init.h29
-rw-r--r--testsuite/include/rtems/bsd/test/default-network-init.h28
-rw-r--r--testsuite/nfs01/test_main.c1
-rw-r--r--testsuite/ping01/test_main.c1
4 files changed, 59 insertions, 0 deletions
diff --git a/testsuite/include/rtems/bsd/test/default-init.h b/testsuite/include/rtems/bsd/test/default-init.h
index f8ea3acd..ea502f94 100644
--- a/testsuite/include/rtems/bsd/test/default-init.h
+++ b/testsuite/include/rtems/bsd/test/default-init.h
@@ -9,11 +9,31 @@
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
+#include <unistd.h>
+
#include <rtems/printer.h>
#include <rtems/test-info.h>
#include <rtems/stackchk.h>
#include <rtems/bsd/bsd.h>
+static void default_wait_for_link_up( const char *name )
+{
+ size_t seconds = 0;
+ while ( true ) {
+ bool link_active = false;
+ assert(rtems_bsd_iface_link_state( name, &link_active ) == 0);
+ if (link_active) {
+ return;
+ }
+ sleep( 1 );
+ ++seconds;
+ if (seconds > 10) {
+ printf("error: %s: no active link\n", name);
+ assert(seconds < 10);
+ }
+ }
+}
+
static void default_set_self_prio( rtems_task_priority prio )
{
rtems_status_code sc;
@@ -68,6 +88,15 @@ rtems_task Init(
sc = rtems_task_wake_after( 2 );
assert(sc == RTEMS_SUCCESSFUL);
+#if defined(TEST_WAIT_FOR_LINK)
+ /*
+ * Per test option to wait for the network interface. If the address
+ * is static the PHY may take a while to connect and bring the
+ * interface online.
+ */
+ default_wait_for_link_up( TEST_WAIT_FOR_LINK );
+#endif
+
test_main();
/* should not return */
diff --git a/testsuite/include/rtems/bsd/test/default-network-init.h b/testsuite/include/rtems/bsd/test/default-network-init.h
index ce1fc015..ba995910 100644
--- a/testsuite/include/rtems/bsd/test/default-network-init.h
+++ b/testsuite/include/rtems/bsd/test/default-network-init.h
@@ -40,6 +40,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <sysexits.h>
+#include <unistd.h>
#include <machine/rtems-bsd-commands.h>
@@ -176,6 +177,25 @@ default_network_on_exit(int exit_code, void *arg)
}
static void
+default_wait_for_link_up( const char *name )
+{
+ size_t seconds = 0;
+ while ( true ) {
+ bool link_active = false;
+ assert(rtems_bsd_iface_link_state( name, &link_active ) == 0);
+ if (link_active) {
+ return;
+ }
+ sleep( 1 );
+ ++seconds;
+ if (seconds > 10) {
+ printf("error: %s: no active link\n", name);
+ assert(seconds < 10);
+ }
+ }
+}
+
+static void
Init(rtems_task_argument arg)
{
rtems_status_code sc;
@@ -238,6 +258,14 @@ Init(rtems_task_argument arg)
#endif
default_network_dhcpcd();
+#if defined(TEST_WAIT_FOR_LINK)
+ /*
+ * Per test option to wait for the network interface. If the address
+ * is static the PHY may take a while to connect and bring the
+ * interface online.
+ */
+ default_wait_for_link_up( TEST_WAIT_FOR_LINK );
+#endif
test_main();
assert(0);
diff --git a/testsuite/nfs01/test_main.c b/testsuite/nfs01/test_main.c
index 2312040a..170cd484 100644
--- a/testsuite/nfs01/test_main.c
+++ b/testsuite/nfs01/test_main.c
@@ -46,6 +46,7 @@
#include <rtems/bsd/test/network-config.h>
#define TEST_NAME "LIBBSD NFS 1"
+#define TEST_WAIT_FOR_LINK NET_CFG_INTERFACE_0
#define TEST_STATE_USER_INPUT 1
static void
diff --git a/testsuite/ping01/test_main.c b/testsuite/ping01/test_main.c
index 5702cee2..8b9a42ce 100644
--- a/testsuite/ping01/test_main.c
+++ b/testsuite/ping01/test_main.c
@@ -46,6 +46,7 @@
#include <rtems/bsd/test/network-config.h>
#define TEST_NAME "LIBBSD PING 1"
+#define TEST_WAIT_FOR_LINK NET_CFG_INTERFACE_0
static void
test_ping(void)