Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix failing spec05 and task02 test #299

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions 05-single-hop-route/test_spec05.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import pytest
import random

from riotctrl_shell.gnrc import GNRCICMPv6Echo, GNRCIPv6NIB, GNRCPktbufStats
from riotctrl_shell.netif import Ifconfig

from testutils.native import bridged
from testutils.shell import ping6, lladdr, check_pktbuf
from testutils.shell import (
ping6,
lladdr,
check_pktbuf,
has_global_addr,
try_to_remove_global_addr,
)


APP = 'examples/gnrc_networking'
Expand Down Expand Up @@ -42,26 +49,36 @@ def test_task01(riot_ctrl):
check_pktbuf(pinged, pinger)


@pytest.mark.flaky(reruns=3, reruns_delay=30)
@pytest.mark.flaky(reruns=0, reruns_delay=30)
@pytest.mark.iotlab_creds
@pytest.mark.parametrize(
'nodes', [pytest.param(['iotlab-m3', 'iotlab-m3'])], indirect=['nodes']
)
def test_task02(riot_ctrl):
pinger, pinged = (
riot_ctrl(0, APP, Shell, modules=["shell_cmd_gnrc_pktbuf"]),
riot_ctrl(1, APP, Shell, modules=["shell_cmd_gnrc_pktbuf"]),
riot_ctrl(0, APP, Shell, modules=["shell_cmd_gnrc_pktbuf"], cflags="-DCONFIG_IEEE802154_DEFAULT_CHANNEL=13"),
riot_ctrl(1, APP, Shell, modules=["shell_cmd_gnrc_pktbuf"], cflags="-DCONFIG_IEEE802154_DEFAULT_CHANNEL=13"),
)

pinged_netif, pinged_lladdr = lladdr(pinged.ifconfig_list())
pinged.ifconfig_add(pinged_netif, "beef::1/64")
pinger_netif, pinger_lladdr = lladdr(pinger.ifconfig_list())

if has_global_addr(pinged) or has_global_addr(pinger):
pan_id = format(random.randint(0x1000, 0xFFFF), "x")
pinged.ifconfig_set(pinged_netif, "pan_id", pan_id)
pinger.ifconfig_set(pinger_netif, "pan_id", pan_id)
pinged.ifconfig_set(pinged_netif, "chan", "12")
pinger.ifconfig_set(pinger_netif, "chan", "12")
try_to_remove_global_addr(pinged)
try_to_remove_global_addr(pinger)

pinged.ifconfig_add(pinged_netif, "beef::1/64")
pinger.ifconfig_add(pinger_netif, "affe::1/120")

pinged.nib_route_add(pinged_netif, "::", pinger_lladdr)
pinger.nib_route_add(pinger_netif, "::", pinged_lladdr)

res = ping6(pinger, "beef::1", count=100, interval=300, packet_size=1024)
res = ping6(pinger, f"beef::1", count=100, interval=300, packet_size=1024)
assert res['stats']['packet_loss'] < 10

check_pktbuf(pinged, pinger)
Expand Down
6 changes: 3 additions & 3 deletions testutils/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,9 @@ def create_comment(github, issue):
def _generate_outcome_summary(pytest_report, task):
# pylint: disable=C0209
return "<strong>{a_open}{outcome}{a_close}</strong>".format(
a_open='<a href="{}">'.format(task["outcome_url"])
if "outcome_url" in task
else '',
a_open=(
'<a href="{}">'.format(task["outcome_url"]) if "outcome_url" in task else ''
),
outcome=pytest_report.outcome.upper(),
a_close='</a>' if "outcome_url" in task else '',
)
Expand Down
7 changes: 4 additions & 3 deletions testutils/iotlab.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import random
import re

from iotlabcli.auth import get_user_credentials
Expand Down Expand Up @@ -55,14 +56,14 @@ def __init__(self, name, ctrls, site=DEFAULT_SITE):
def board_from_iotlab_node(iotlab_node):
"""Return BOARD matching iotlab_node"""
reg = r'([0-9a-zA-Z\-]+)-\d+\.[a-z]+\.iot-lab\.info'
match = re.search(reg, iotlab_node)
if match is None:
matches = re.findall(reg, iotlab_node)
if not matches:
raise ValueError(
f"Unable to parse {iotlab_node} as IoT-LAB node "
"name of format "
"<node-name>.<site-name>.iot-lab.info"
)
iotlab_node_name = match.group(1)
iotlab_node_name = random.choice(matches)
dict_values = IoTLABExperiment.BOARD_ARCHI_MAP.values()
dict_names = [value['name'] for value in dict_values]
dict_keys = list(IoTLABExperiment.BOARD_ARCHI_MAP.keys())
Expand Down
16 changes: 16 additions & 0 deletions testutils/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,22 @@ def global_addr(ifconfig_out):
return first_netif_and_addr_by_scope(ifconfig_out, "global")


def has_global_addr(node):
"""Check if node has a global address."""
try:
global_addr(node.ifconfig_list())
except (RuntimeError, IndexError):
return False
return True


def try_to_remove_global_addr(node):
"""Try to remove global address from node."""
if has_global_addr(node):
netif, addr = global_addr(node.ifconfig_list())
node.cmd(f"ifconfig {netif} del {addr}")


def check_pktbuf(*nodes, wait=10):
if wait:
time.sleep(wait)
Expand Down
8 changes: 5 additions & 3 deletions testutils/tests/test_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -983,9 +983,11 @@ def test_upload_results(
monkeypatch.setattr(
testutils.github,
"get_results_gist",
lambda *args, **kwargs: (testutils.github.Git('.'), "", "the_gist_id")
if gist_created
else (None, None, None),
lambda *args, **kwargs: (
(testutils.github.Git('.'), "", "the_gist_id")
if gist_created
else (None, None, None)
),
)
monkeypatch.setattr(
testutils.github, "upload_result_content", lambda *args, **kwargs: head
Expand Down
Loading