mirror of
https://git.rtems.org/rtems-libbsd/
synced 2025-05-13 15:19:18 +08:00
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.
This commit is contained in:
parent
45ff774c3c
commit
efd75d2e35
@ -9,11 +9,31 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <rtems/printer.h>
|
#include <rtems/printer.h>
|
||||||
#include <rtems/test-info.h>
|
#include <rtems/test-info.h>
|
||||||
#include <rtems/stackchk.h>
|
#include <rtems/stackchk.h>
|
||||||
#include <rtems/bsd/bsd.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 )
|
static void default_set_self_prio( rtems_task_priority prio )
|
||||||
{
|
{
|
||||||
rtems_status_code sc;
|
rtems_status_code sc;
|
||||||
@ -68,6 +88,15 @@ rtems_task Init(
|
|||||||
sc = rtems_task_wake_after( 2 );
|
sc = rtems_task_wake_after( 2 );
|
||||||
assert(sc == RTEMS_SUCCESSFUL);
|
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();
|
test_main();
|
||||||
/* should not return */
|
/* should not return */
|
||||||
|
|
||||||
|
@ -40,6 +40,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <sysexits.h>
|
#include <sysexits.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <machine/rtems-bsd-commands.h>
|
#include <machine/rtems-bsd-commands.h>
|
||||||
|
|
||||||
@ -175,6 +176,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
|
static void
|
||||||
Init(rtems_task_argument arg)
|
Init(rtems_task_argument arg)
|
||||||
{
|
{
|
||||||
@ -238,6 +258,14 @@ Init(rtems_task_argument arg)
|
|||||||
#endif
|
#endif
|
||||||
default_network_dhcpcd();
|
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();
|
test_main();
|
||||||
|
|
||||||
assert(0);
|
assert(0);
|
||||||
|
@ -46,6 +46,7 @@
|
|||||||
#include <rtems/bsd/test/network-config.h>
|
#include <rtems/bsd/test/network-config.h>
|
||||||
|
|
||||||
#define TEST_NAME "LIBBSD NFS 1"
|
#define TEST_NAME "LIBBSD NFS 1"
|
||||||
|
#define TEST_WAIT_FOR_LINK NET_CFG_INTERFACE_0
|
||||||
#define TEST_STATE_USER_INPUT 1
|
#define TEST_STATE_USER_INPUT 1
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -46,6 +46,7 @@
|
|||||||
#include <rtems/bsd/test/network-config.h>
|
#include <rtems/bsd/test/network-config.h>
|
||||||
|
|
||||||
#define TEST_NAME "LIBBSD PING 1"
|
#define TEST_NAME "LIBBSD PING 1"
|
||||||
|
#define TEST_WAIT_FOR_LINK NET_CFG_INTERFACE_0
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_ping(void)
|
test_ping(void)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user