From fc1da18cd5627c3e54ff8733fa1c93da85561dfe Mon Sep 17 00:00:00 2001 From: Lars Date: Tue, 22 Dec 2020 13:29:50 +0100 Subject: [PATCH 1/8] add test for radio hal --- 12-ieee802154/test_spec12.py | 37 ++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 12-ieee802154/test_spec12.py diff --git a/12-ieee802154/test_spec12.py b/12-ieee802154/test_spec12.py new file mode 100644 index 00000000..74d02271 --- /dev/null +++ b/12-ieee802154/test_spec12.py @@ -0,0 +1,37 @@ +from time import sleep +import pytest +import riotctrl + + +from riotctrl_shell.ieee802154 import Config_phy, Print_addr, Txtsnd + +APP = 'tests/ieee802154_hal' +pytestmark = pytest.mark.rc_only() + + +class Shell(Config_phy, Print_addr, Txtsnd): + pass + + +@pytest.mark.parametrize('nodes', + [pytest.param(['remote-revb', 'remote-revb'])], + indirect=['nodes']) +def test_task01(riot_ctrl): + print(riotctrl) + sender, receiver = ( + riot_ctrl(0, APP, Shell, port='/dev/ttyUSB0'), + riot_ctrl(1, APP, Shell, port='/dev/ttyUSB1'), + ) + print("--------------------------------------------------------------------------") + sender.tx_mode("direct") + receiver.tx_mode("direct") + receiver_addr = receiver.print_addr() + sender_addr = sender.print_addr() + for i in range(11, 27): + sender.config_phy(i, 0) + receiver.config_phy(i, 0) + sleep(0.2) + sender.txtsnd(receiver_addr) + sleep(0.2) + receiver.check_last_packet(sender_addr, i) + sleep(0.2) From e0fc1a237a39f55700ff0ff6d4ad9701a60b8771 Mon Sep 17 00:00:00 2001 From: Lars Date: Mon, 17 May 2021 12:16:19 +0200 Subject: [PATCH 2/8] add tests for ieee 802.15.4 --- 12-ieee802154/test_spec12.py | 49 ++++++++++++++++++++++++++++-------- conftest.py | 2 ++ requirements.txt | 3 ++- tox.ini | 5 ++-- 4 files changed, 46 insertions(+), 13 deletions(-) diff --git a/12-ieee802154/test_spec12.py b/12-ieee802154/test_spec12.py index 74d02271..b2d6a744 100644 --- a/12-ieee802154/test_spec12.py +++ b/12-ieee802154/test_spec12.py @@ -1,11 +1,11 @@ from time import sleep import pytest -import riotctrl - from riotctrl_shell.ieee802154 import Config_phy, Print_addr, Txtsnd APP = 'tests/ieee802154_hal' +PHY_MODE = 'O-QPSK' +DEFAULT_CHANNEL = 26 pytestmark = pytest.mark.rc_only() @@ -17,21 +17,50 @@ class Shell(Config_phy, Print_addr, Txtsnd): [pytest.param(['remote-revb', 'remote-revb'])], indirect=['nodes']) def test_task01(riot_ctrl): - print(riotctrl) sender, receiver = ( riot_ctrl(0, APP, Shell, port='/dev/ttyUSB0'), riot_ctrl(1, APP, Shell, port='/dev/ttyUSB1'), ) - print("--------------------------------------------------------------------------") sender.tx_mode("direct") receiver.tx_mode("direct") receiver_addr = receiver.print_addr() sender_addr = sender.print_addr() for i in range(11, 27): - sender.config_phy(i, 0) - receiver.config_phy(i, 0) - sleep(0.2) - sender.txtsnd(receiver_addr) - sleep(0.2) + sender.config_phy(PHY_MODE, i, 0) + receiver.config_phy(PHY_MODE, i, 0) + sleep(0.5) + sender.txtsnd(receiver_addr, 1, 0) + sleep(0.5) receiver.check_last_packet(sender_addr, i) - sleep(0.2) + sleep(0.5) + + +@pytest.mark.parametrize('nodes', + [pytest.param(['remote-revb', 'remote-revb'])], + indirect=['nodes']) +def test_task02(riot_ctrl): + sender, receiver = ( + riot_ctrl(0, APP, Shell, port='/dev/ttyUSB0'), + riot_ctrl(1, APP, Shell, port='/dev/ttyUSB1'), + ) + sender.tx_mode("direct") + receiver.tx_mode("direct") + receiver_addr = receiver.print_addr() + sender.txtsnd(receiver_addr, 5, 1000) + + +@pytest.mark.parametrize('nodes', + [pytest.param(['remote-revb', 'remote-revb'])], + indirect=['nodes']) +def test_task03(riot_ctrl): + sender, receiver = ( + riot_ctrl(0, APP, Shell, port='/dev/ttyUSB0'), + riot_ctrl(1, APP, Shell, port='/dev/ttyUSB1'), + ) + sender.tx_mode("direct") + receiver.tx_mode("direct") + receiver_addr = receiver.print_addr() + receiver.reply() + sender.txtsnd(receiver_addr, 1, 0) + sleep(1) + sender.check_last_packet(receiver_addr, DEFAULT_CHANNEL) diff --git a/conftest.py b/conftest.py index 920c1567..d75f64ed 100644 --- a/conftest.py +++ b/conftest.py @@ -277,10 +277,12 @@ def ctrl(nodes_idx, application_dir, shell_interaction_cls, # need to access private member here isn't possible otherwise sadly :( # pylint: disable=W0212 node._application_directory = os.path.join(riotbase, application_dir) + print("-------------------------------------------before flash") node.make_run(['flash'], check=True, stdout=None if log_nodes else subprocess.DEVNULL, stderr=None if log_nodes else subprocess.DEVNULL) termargs = {} + print("-------------------------------------------after flash") if log_nodes: termargs["logfile"] = sys.stdout RUNNING_CTRLS.append(node) diff --git a/requirements.txt b/requirements.txt index 7d8ffe4f..86f79c72 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,5 +3,6 @@ iotlabcli pygithub pytest pytest-cov -riotctrl scapy +pyserial +pexpect diff --git a/tox.ini b/tox.ini index 1a86e4b3..30ff1d24 100644 --- a/tox.ini +++ b/tox.ini @@ -3,7 +3,7 @@ envlist = test,flake8,pylint skipsdist = True [testenv] -basepython = python3 +basepython = python3.6 commands = test: {[testenv:test]commands} flake8: {[testenv:flake8]commands} @@ -50,4 +50,5 @@ commands = 07-multi-hop/ \ 08-interop/ \ 09-coap/ \ - 10-icmpv6-error/ + 10-icmpv6-error/ \ + 12-ieee802154/ From cf3c5f55b9fd88b9eb4cbc0d40c1d2463068c1d2 Mon Sep 17 00:00:00 2001 From: Lars Date: Mon, 17 May 2021 12:53:12 +0200 Subject: [PATCH 3/8] remove comments and revert changes --- conftest.py | 2 -- requirements.txt | 1 + tox.ini | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/conftest.py b/conftest.py index d75f64ed..920c1567 100644 --- a/conftest.py +++ b/conftest.py @@ -277,12 +277,10 @@ def ctrl(nodes_idx, application_dir, shell_interaction_cls, # need to access private member here isn't possible otherwise sadly :( # pylint: disable=W0212 node._application_directory = os.path.join(riotbase, application_dir) - print("-------------------------------------------before flash") node.make_run(['flash'], check=True, stdout=None if log_nodes else subprocess.DEVNULL, stderr=None if log_nodes else subprocess.DEVNULL) termargs = {} - print("-------------------------------------------after flash") if log_nodes: termargs["logfile"] = sys.stdout RUNNING_CTRLS.append(node) diff --git a/requirements.txt b/requirements.txt index 86f79c72..773657bd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,6 +3,7 @@ iotlabcli pygithub pytest pytest-cov +riotctrl scapy pyserial pexpect diff --git a/tox.ini b/tox.ini index 30ff1d24..77de2fc8 100644 --- a/tox.ini +++ b/tox.ini @@ -3,7 +3,7 @@ envlist = test,flake8,pylint skipsdist = True [testenv] -basepython = python3.6 +basepython = python3 commands = test: {[testenv:test]commands} flake8: {[testenv:flake8]commands} From 5596ac0e76826f31f106589123acd093802a56c1 Mon Sep 17 00:00:00 2001 From: Lars Date: Mon, 17 May 2021 13:01:18 +0200 Subject: [PATCH 4/8] remove additonal lines --- requirements.txt | 1 - tox.ini | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/requirements.txt b/requirements.txt index 19c76af8..ed7d2171 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,4 +8,3 @@ scapy pyserial pexpect paho-mqtt - diff --git a/tox.ini b/tox.ini index 6d0e4575..a30f6cb8 100644 --- a/tox.ini +++ b/tox.ini @@ -62,5 +62,4 @@ commands = 09-coap/ \ 10-icmpv6-error/ \ 11-lorawan/ \ - 12-ieee802154/ - + 12-ieee802154/ \ No newline at end of file From 84ecc5f40b46dfee11ffe9edc57e4f5a739a7c4e Mon Sep 17 00:00:00 2001 From: Lars Date: Mon, 17 May 2021 13:03:04 +0200 Subject: [PATCH 5/8] add additional line for tox.ini --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index a30f6cb8..c1805bd8 100644 --- a/tox.ini +++ b/tox.ini @@ -62,4 +62,4 @@ commands = 09-coap/ \ 10-icmpv6-error/ \ 11-lorawan/ \ - 12-ieee802154/ \ No newline at end of file + 12-ieee802154/ From 4f5a8a08adfb32aac959b6c1e7cc765fed034ea0 Mon Sep 17 00:00:00 2001 From: Lars Date: Wed, 9 Jun 2021 13:04:30 +0200 Subject: [PATCH 6/8] 12-ieee802154/test_spec12.py changed function names --- 12-ieee802154/test_spec12.py | 44 ++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/12-ieee802154/test_spec12.py b/12-ieee802154/test_spec12.py index b2d6a744..b999c856 100644 --- a/12-ieee802154/test_spec12.py +++ b/12-ieee802154/test_spec12.py @@ -1,7 +1,7 @@ from time import sleep import pytest -from riotctrl_shell.ieee802154 import Config_phy, Print_addr, Txtsnd +from riotctrl_shell.ieee802154 import IEEE802154Phy APP = 'tests/ieee802154_hal' PHY_MODE = 'O-QPSK' @@ -9,7 +9,7 @@ pytestmark = pytest.mark.rc_only() -class Shell(Config_phy, Print_addr, Txtsnd): +class Shell(IEEE802154Phy): pass @@ -21,17 +21,17 @@ def test_task01(riot_ctrl): riot_ctrl(0, APP, Shell, port='/dev/ttyUSB0'), riot_ctrl(1, APP, Shell, port='/dev/ttyUSB1'), ) - sender.tx_mode("direct") - receiver.tx_mode("direct") - receiver_addr = receiver.print_addr() - sender_addr = sender.print_addr() + sender.ieee802154_tx_mode("direct") + receiver.ieee802154_tx_mode("direct") + receiver_addr = receiver.ieee802154_print_addr() + sender_addr = sender.ieee802154_print_addr() for i in range(11, 27): - sender.config_phy(PHY_MODE, i, 0) - receiver.config_phy(PHY_MODE, i, 0) - sleep(0.5) - sender.txtsnd(receiver_addr, 1, 0) - sleep(0.5) - receiver.check_last_packet(sender_addr, i) + sender.ieee802154_config_phy(PHY_MODE, i, 0) + receiver.ieee802154_config_phy(PHY_MODE, i, 0) + sleep(1) + sender.ieee802154_txtspam(receiver_addr, 1, 0) + sleep(1) + receiver.ieee802154_check_last_packet(sender_addr, i) sleep(0.5) @@ -43,10 +43,10 @@ def test_task02(riot_ctrl): riot_ctrl(0, APP, Shell, port='/dev/ttyUSB0'), riot_ctrl(1, APP, Shell, port='/dev/ttyUSB1'), ) - sender.tx_mode("direct") - receiver.tx_mode("direct") - receiver_addr = receiver.print_addr() - sender.txtsnd(receiver_addr, 5, 1000) + sender.ieee802154_tx_mode("direct") + receiver.ieee802154_tx_mode("direct") + receiver_addr = receiver.ieee802154_print_addr() + sender.ieee802154_txtspam(receiver_addr, 5, 1000) @pytest.mark.parametrize('nodes', @@ -57,10 +57,10 @@ def test_task03(riot_ctrl): riot_ctrl(0, APP, Shell, port='/dev/ttyUSB0'), riot_ctrl(1, APP, Shell, port='/dev/ttyUSB1'), ) - sender.tx_mode("direct") - receiver.tx_mode("direct") - receiver_addr = receiver.print_addr() - receiver.reply() - sender.txtsnd(receiver_addr, 1, 0) + sender.ieee802154_tx_mode("direct") + receiver.ieee802154_tx_mode("direct") + receiver_addr = receiver.ieee802154_print_addr() + receiver.ieee802154_reply() + sender.ieee802154_txtsnd(receiver_addr, 1) sleep(1) - sender.check_last_packet(receiver_addr, DEFAULT_CHANNEL) + sender.ieee802154_check_last_packet(receiver_addr, DEFAULT_CHANNEL) From adf6db76ecc86e84f7dd8527914c345cd6cb7f97 Mon Sep 17 00:00:00 2001 From: Lars Date: Mon, 21 Jun 2021 09:30:49 +0200 Subject: [PATCH 7/8] 12-ieee802154/test_spec12.py adjust function calls --- 12-ieee802154/test_spec12.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/12-ieee802154/test_spec12.py b/12-ieee802154/test_spec12.py index b999c856..7b4fcf2a 100644 --- a/12-ieee802154/test_spec12.py +++ b/12-ieee802154/test_spec12.py @@ -13,6 +13,7 @@ class Shell(IEEE802154Phy): pass +@pytest.mark.local_only @pytest.mark.parametrize('nodes', [pytest.param(['remote-revb', 'remote-revb'])], indirect=['nodes']) @@ -23,18 +24,19 @@ def test_task01(riot_ctrl): ) sender.ieee802154_tx_mode("direct") receiver.ieee802154_tx_mode("direct") - receiver_addr = receiver.ieee802154_print_addr() - sender_addr = sender.ieee802154_print_addr() + receiver_addr = receiver.ieee802154_get_phy() + sender_addr = sender.ieee802154_get_phy() for i in range(11, 27): sender.ieee802154_config_phy(PHY_MODE, i, 0) receiver.ieee802154_config_phy(PHY_MODE, i, 0) sleep(1) - sender.ieee802154_txtspam(receiver_addr, 1, 0) + sender.ieee802154_txtspam(receiver_addr, 10, 1, 0, 0) sleep(1) receiver.ieee802154_check_last_packet(sender_addr, i) sleep(0.5) +@pytest.mark.local_only @pytest.mark.parametrize('nodes', [pytest.param(['remote-revb', 'remote-revb'])], indirect=['nodes']) @@ -45,10 +47,11 @@ def test_task02(riot_ctrl): ) sender.ieee802154_tx_mode("direct") receiver.ieee802154_tx_mode("direct") - receiver_addr = receiver.ieee802154_print_addr() - sender.ieee802154_txtspam(receiver_addr, 5, 1000) + receiver_addr = receiver.ieee802154_get_phy() + sender.ieee802154_txtspam(receiver_addr, 10, 5, 1000, 0) +@pytest.mark.local_only @pytest.mark.parametrize('nodes', [pytest.param(['remote-revb', 'remote-revb'])], indirect=['nodes']) @@ -59,8 +62,8 @@ def test_task03(riot_ctrl): ) sender.ieee802154_tx_mode("direct") receiver.ieee802154_tx_mode("direct") - receiver_addr = receiver.ieee802154_print_addr() - receiver.ieee802154_reply() - sender.ieee802154_txtsnd(receiver_addr, 1) + receiver_addr = receiver.ieee802154_get_phy() + receiver.ieee802154_reply(1) + sender.ieee802154_txtsnd(receiver_addr, 10, 0) sleep(1) sender.ieee802154_check_last_packet(receiver_addr, DEFAULT_CHANNEL) From cb0d3c6a55b1ce0137d1b5fc2488667d5a6fc76d Mon Sep 17 00:00:00 2001 From: Lars Date: Mon, 28 Jun 2021 12:18:46 +0200 Subject: [PATCH 8/8] 12-ieee802154/test_spec12.py refactor function names --- 12-ieee802154/test_spec12.py | 41 +++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/12-ieee802154/test_spec12.py b/12-ieee802154/test_spec12.py index 7b4fcf2a..ed5ae65e 100644 --- a/12-ieee802154/test_spec12.py +++ b/12-ieee802154/test_spec12.py @@ -19,21 +19,21 @@ class Shell(IEEE802154Phy): indirect=['nodes']) def test_task01(riot_ctrl): sender, receiver = ( - riot_ctrl(0, APP, Shell, port='/dev/ttyUSB0'), - riot_ctrl(1, APP, Shell, port='/dev/ttyUSB1'), + riot_ctrl(0, APP, Shell, port='/dev/ttyUSB0', cflags="-DRIOTCTRL"), + riot_ctrl(1, APP, Shell, port='/dev/ttyUSB1', cflags="-DRIOTCTRL"), ) sender.ieee802154_tx_mode("direct") receiver.ieee802154_tx_mode("direct") - receiver_addr = receiver.ieee802154_get_phy() - sender_addr = sender.ieee802154_get_phy() + receiver_addr = receiver.ieee802154_print_info()[0] + sender_addr = sender.ieee802154_print_info()[0] for i in range(11, 27): sender.ieee802154_config_phy(PHY_MODE, i, 0) receiver.ieee802154_config_phy(PHY_MODE, i, 0) - sleep(1) - sender.ieee802154_txtspam(receiver_addr, 10, 1, 0, 0) - sleep(1) + sleep(2) + sender.ieee802154_txtspam(receiver_addr, 10, 4, 100) + sleep(2) receiver.ieee802154_check_last_packet(sender_addr, i) - sleep(0.5) + sleep(1) @pytest.mark.local_only @@ -42,13 +42,16 @@ def test_task01(riot_ctrl): indirect=['nodes']) def test_task02(riot_ctrl): sender, receiver = ( - riot_ctrl(0, APP, Shell, port='/dev/ttyUSB0'), - riot_ctrl(1, APP, Shell, port='/dev/ttyUSB1'), + riot_ctrl(0, APP, Shell, port='/dev/ttyUSB0', cflags="-DRIOTCTRL"), + riot_ctrl(1, APP, Shell, port='/dev/ttyUSB1', cflags="-DRIOTCTRL"), ) sender.ieee802154_tx_mode("direct") receiver.ieee802154_tx_mode("direct") - receiver_addr = receiver.ieee802154_get_phy() - sender.ieee802154_txtspam(receiver_addr, 10, 5, 1000, 0) + receiver_addr = receiver.ieee802154_print_info()[0] + res = sender.ieee802154_txtspam(receiver_addr, 10, 20, 1000) + assert res["tx_packets"] == 20 + if res["percentage_ack"]: + assert res["percentage_ack"] >= 90 @pytest.mark.local_only @@ -57,13 +60,17 @@ def test_task02(riot_ctrl): indirect=['nodes']) def test_task03(riot_ctrl): sender, receiver = ( - riot_ctrl(0, APP, Shell, port='/dev/ttyUSB0'), - riot_ctrl(1, APP, Shell, port='/dev/ttyUSB1'), + riot_ctrl(0, APP, Shell, port='/dev/ttyUSB0', cflags="-DRIOTCTRL"), + riot_ctrl(1, APP, Shell, port='/dev/ttyUSB1', cflags="-DRIOTCTRL"), ) sender.ieee802154_tx_mode("direct") receiver.ieee802154_tx_mode("direct") - receiver_addr = receiver.ieee802154_get_phy() - receiver.ieee802154_reply(1) - sender.ieee802154_txtsnd(receiver_addr, 10, 0) + receiver_addr = receiver.ieee802154_print_info()[0] + receiver.ieee802154_reply_mode_cmd("on") + res = sender.ieee802154_txtspam(receiver_addr, 10, 10, 100) sleep(1) sender.ieee802154_check_last_packet(receiver_addr, DEFAULT_CHANNEL) + assert res["tx_packets"] == 10 + if res["percentage_ack"]: + assert res["percentage_ack"] >= 90 + assert res["percentage_rx"] >= 90