From 9588fab22f61615581754e074b397cbf4690278e Mon Sep 17 00:00:00 2001 From: MrKevinWeiss Date: Mon, 29 Jan 2024 12:09:14 +0100 Subject: [PATCH 1/4] testutils/iotlab.py: Randomize the selected node It seems there have been some failures mainly due to infrastructure. Specifically the samr21-xpro failing to flash will cause many reruns with the same faulty hardware. Previously it would just take the first available node in the list, which is deterministic but doesn't help with flakey test reruns. This may cause an issue with distance to other nodes, but if random selection of nodes becomes a problem we would have to introduce node pairing lists... Which is a bit more work. This is at least a first step. --- testutils/iotlab.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/testutils/iotlab.py b/testutils/iotlab.py index 49d5fdd..8f89317 100644 --- a/testutils/iotlab.py +++ b/testutils/iotlab.py @@ -1,4 +1,5 @@ import logging +import random import re from iotlabcli.auth import get_user_credentials @@ -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 " "..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()) From 6e6db29750599a5cc2c1c85cd1a69f0e220aca35 Mon Sep 17 00:00:00 2001 From: MrKevinWeiss Date: Mon, 29 Jan 2024 12:24:42 +0100 Subject: [PATCH 2/4] testutils: Fix black style --- testutils/github.py | 6 +++--- testutils/tests/test_github.py | 8 +++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/testutils/github.py b/testutils/github.py index d59761c..7d95fc2 100644 --- a/testutils/github.py +++ b/testutils/github.py @@ -210,9 +210,9 @@ def create_comment(github, issue): def _generate_outcome_summary(pytest_report, task): # pylint: disable=C0209 return "{a_open}{outcome}{a_close}".format( - a_open=''.format(task["outcome_url"]) - if "outcome_url" in task - else '', + a_open=( + ''.format(task["outcome_url"]) if "outcome_url" in task else '' + ), outcome=pytest_report.outcome.upper(), a_close='' if "outcome_url" in task else '', ) diff --git a/testutils/tests/test_github.py b/testutils/tests/test_github.py index 824abe2..e3930b3 100644 --- a/testutils/tests/test_github.py +++ b/testutils/tests/test_github.py @@ -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 From 1bb1dbf678538a8dd6c344e8281b3841efc6c0b9 Mon Sep 17 00:00:00 2001 From: MrKevinWeiss Date: Mon, 29 Jan 2024 16:34:39 +0100 Subject: [PATCH 3/4] spec04 and task05: Remove TNT global address Since the default numof addresses is 2 we should remove one assigned so we can add our own global --- 05-single-hop-route/test_spec05.py | 25 +++++++++++++++++++++---- testutils/shell.py | 16 ++++++++++++++++ 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/05-single-hop-route/test_spec05.py b/05-single-hop-route/test_spec05.py index 3211afc..d266c04 100644 --- a/05-single-hop-route/test_spec05.py +++ b/05-single-hop-route/test_spec05.py @@ -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' @@ -42,7 +49,7 @@ 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'] @@ -54,14 +61,24 @@ def test_task02(riot_ctrl): ) 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) diff --git a/testutils/shell.py b/testutils/shell.py index 0aaeee7..e70ca59 100644 --- a/testutils/shell.py +++ b/testutils/shell.py @@ -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) From ccb3c6e84049f0e8b28b2edf2797a67f64ea1b67 Mon Sep 17 00:00:00 2001 From: MrKevinWeiss Date: Mon, 29 Jan 2024 16:35:25 +0100 Subject: [PATCH 4/4] spec04 and task05: change default channel --- 05-single-hop-route/test_spec05.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/05-single-hop-route/test_spec05.py b/05-single-hop-route/test_spec05.py index d266c04..b387f25 100644 --- a/05-single-hop-route/test_spec05.py +++ b/05-single-hop-route/test_spec05.py @@ -56,8 +56,8 @@ def test_task01(riot_ctrl): ) 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())