diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/dm/eth.c | 88 | ||||
-rw-r--r-- | test/py/tests/test_net.py | 56 |
2 files changed, 143 insertions, 1 deletions
diff --git a/test/dm/eth.c b/test/dm/eth.c index ebf01d8cf38..d05d2a9abe1 100644 --- a/test/dm/eth.c +++ b/test/dm/eth.c @@ -20,6 +20,7 @@ #include <dm/uclass-internal.h> #include <test/test.h> #include <test/ut.h> +#include <ndisc.h> #define DM_TEST_ETH_NUM 4 @@ -607,3 +608,90 @@ static int dm_test_eth_async_ping_reply(struct unit_test_state *uts) } DM_TEST(dm_test_eth_async_ping_reply, UT_TESTF_SCAN_FDT); + +#if IS_ENABLED(CONFIG_IPV6_ROUTER_DISCOVERY) + +static u8 ip6_ra_buf[] = {0x60, 0xf, 0xc5, 0x4a, 0x0, 0x38, 0x3a, 0xff, 0xfe, + 0x80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x6, 0x85, 0xe6, + 0x29, 0x77, 0xcb, 0xc8, 0x53, 0xff, 0x2, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x1, 0x86, 0x0, 0xdc, 0x90, 0x40, 0x80, 0x15, 0x18, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3, 0x4, + 0x40, 0xc0, 0x0, 0x0, 0x37, 0xdc, 0x0, 0x0, 0x37, + 0x78, 0x0, 0x0, 0x0, 0x0, 0x20, 0x1, 0xca, 0xfe, 0xca, + 0xfe, 0xca, 0xfe, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x1, 0x1, 0x0, 0x15, 0x5d, 0xe2, 0x8a, 0x2}; + +static int dm_test_validate_ra(struct unit_test_state *uts) +{ + struct ip6_hdr *ip6 = (struct ip6_hdr *)ip6_ra_buf; + struct icmp6hdr *icmp = (struct icmp6hdr *)(ip6 + 1); + __be16 temp = 0; + + ut_assert(validate_ra(ip6) == true); + + temp = ip6->payload_len; + ip6->payload_len = 15; + ut_assert(validate_ra(ip6) == false); + ip6->payload_len = temp; + + temp = ip6->saddr.s6_addr16[0]; + ip6->saddr.s6_addr16[0] = 0x2001; + ut_assert(validate_ra(ip6) == false); + ip6->saddr.s6_addr16[0] = temp; + + temp = ip6->hop_limit; + ip6->hop_limit = 15; + ut_assert(validate_ra(ip6) == false); + ip6->hop_limit = temp; + + temp = icmp->icmp6_code; + icmp->icmp6_code = 15; + ut_assert(validate_ra(ip6) == false); + icmp->icmp6_code = temp; + + return 0; +} + +DM_TEST(dm_test_validate_ra, 0); + +static int dm_test_process_ra(struct unit_test_state *uts) +{ + int len = sizeof(ip6_ra_buf); + struct ip6_hdr *ip6 = (struct ip6_hdr *)ip6_ra_buf; + struct icmp6hdr *icmp = (struct icmp6hdr *)(ip6 + 1); + struct ra_msg *msg = (struct ra_msg *)icmp; + unsigned char *option = msg->opt; + struct icmp6_ra_prefix_info *prefix = + (struct icmp6_ra_prefix_info *)option; + __be16 temp = 0; + unsigned char option_len = option[1]; + + ut_assert(process_ra(ip6, len) == 0); + + temp = icmp->icmp6_rt_lifetime; + icmp->icmp6_rt_lifetime = 0; + ut_assert(process_ra(ip6, len) != 0); + icmp->icmp6_rt_lifetime = temp; + + ut_assert(process_ra(ip6, 0) != 0); + + option[1] = 0; + ut_assert(process_ra(ip6, len) != 0); + option[1] = option_len; + + prefix->on_link = false; + ut_assert(process_ra(ip6, len) != 0); + prefix->on_link = true; + + temp = prefix->prefix.s6_addr16[0]; + prefix->prefix.s6_addr16[0] = 0x80fe; + ut_assert(process_ra(ip6, len) != 0); + prefix->prefix.s6_addr16[0] = temp; + + return 0; +} + +DM_TEST(dm_test_process_ra, 0); + +#endif diff --git a/test/py/tests/test_net.py b/test/py/tests/test_net.py index 9ca6743afd9..cd4b4dc53cb 100644 --- a/test/py/tests/test_net.py +++ b/test/py/tests/test_net.py @@ -9,7 +9,7 @@ import u_boot_utils """ Note: This test relies on boardenv_* containing configuration values to define -which the network environment available for testing. Without this, this test +which network environment is available for testing. Without this, this test will be automatically skipped. For example: @@ -29,6 +29,11 @@ env__net_uses_pci = True # set to False. env__net_dhcp_server = True +# True if a DHCPv6 server is attached to the network, and should be tested. +# If DHCPv6 testing is not possible or desired, this variable may be omitted or +# set to False. +env__net_dhcp6_server = True + # A list of environment variables that should be set in order to configure a # static IP. If solely relying on DHCP, this variable may be omitted or set to # an empty list. @@ -55,9 +60,15 @@ env__net_nfs_readable_file = { 'size': 5058624, 'crc32': 'c2244b26', } + +# True if a router advertisement service is connected to the network, and should +# be tested. If router advertisement testing is not possible or desired, this +variable may be omitted or set to False. +env__router_on_net = True """ net_set_up = False +net6_set_up = False def test_net_pre_commands(u_boot_console): """Execute any commands required to enable network hardware. @@ -93,6 +104,25 @@ def test_net_dhcp(u_boot_console): global net_set_up net_set_up = True +@pytest.mark.buildconfigspec('cmd_dhcp6') +def test_net_dhcp6(u_boot_console): + """Test the dhcp6 command. + + The boardenv_* file may be used to enable/disable this test; see the + comment at the beginning of this file. + """ + + test_dhcp6 = u_boot_console.config.env.get('env__net_dhcp6_server', False) + if not test_dhcp6: + pytest.skip('No DHCP6 server available') + + u_boot_console.run_command('setenv autoload no') + output = u_boot_console.run_command('dhcp6') + assert 'DHCP6 client bound to ' in output + + global net6_set_up + net6_set_up = True + @pytest.mark.buildconfigspec('net') def test_net_setup_static(u_boot_console): """Set up a static IP configuration. @@ -126,6 +156,30 @@ def test_net_ping(u_boot_console): output = u_boot_console.run_command('ping $serverip') assert 'is alive' in output +@pytest.mark.buildconfigspec('IPV6_ROUTER_DISCOVERY') +def test_net_network_discovery(u_boot_console): + """Test the network discovery feature of IPv6. + + An IPv6 network command (ping6 in this case) is run to make U-Boot send a + router solicitation packet, receive a router advertisement message, and + parse it. + A router advertisement service needs to be running for this test to succeed. + U-Boot receives the RA, processes it, and if successful, assigns the gateway + IP and prefix length. + The configuration is provided by the boardenv_* file; see the comment at + the beginning of this file. + """ + + router_on_net = u_boot_console.config.env.get('env__router_on_net', False) + if not router_on_net: + pytest.skip('No router on network') + + fake_host_ip = 'fe80::215:5dff:fef6:2ec6' + output = u_boot_console.run_command('ping6 ' + fake_host_ip) + assert 'ROUTER SOLICITATION 1' in output + assert 'Set gatewayip6:' in output + assert '0000:0000:0000:0000:0000:0000:0000:0000' not in output + @pytest.mark.buildconfigspec('cmd_net') def test_net_tftpboot(u_boot_console): """Test the tftpboot command. |