[rtems-libbsd commit] testsuite: Wait for the link to be UP

Chris Johns chrisj at rtems.org
Thu Sep 2 02:43:00 UTC 2021


Module:    rtems-libbsd
Branch:    6-freebsd-12
Commit:    efd75d2e355b47bff42112322151a679aa615024
Changeset: http://git.rtems.org/rtems-libbsd/commit/?id=efd75d2e355b47bff42112322151a679aa615024

Author:    Chris Johns <chrisj at rtems.org>
Date:      Sun Aug  8 16:35:02 2021 +1000

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.

---

 testsuite/include/rtems/bsd/test/default-init.h    | 29 ++++++++++++++++++++++
 .../include/rtems/bsd/test/default-network-init.h  | 28 +++++++++++++++++++++
 testsuite/nfs01/test_main.c                        |  1 +
 testsuite/ping01/test_main.c                       |  1 +
 4 files changed, 59 insertions(+)

diff --git a/testsuite/include/rtems/bsd/test/default-init.h b/testsuite/include/rtems/bsd/test/default-init.h
index f8ea3ac..ea502f9 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 ce1fc01..ba99591 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 2312040..170cd48 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 5702cee..8b9a42c 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)



More information about the vc mailing list