Skip to content

Commit

Permalink
08-interop: Automate task03
Browse files Browse the repository at this point in the history
  • Loading branch information
MrKevinWeiss committed Nov 2, 2023
1 parent a54547a commit dd8ee94
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 3 deletions.
25 changes: 25 additions & 0 deletions 08-interop/compile_contiki.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

cd /tmp

# Clone Contiki-NG
git clone https://github.com/contiki-ng/contiki-ng.git; cd contiki-ng || \
cd contiki-ng; git pull
git submodule update --init --recursive

# Pull the Contiki-NG Docker image
docker pull contiker/contiki-ng

# Add the `shell` service to the `examples/hello-world` application.
if ! grep -q "MODULES += os/services/shell" examples/hello-world/Makefile; then
sed -i '/all: $(CONTIKI_PROJECT)/a\\nMODULES += os/services/shell\n' examples/hello-world/Makefile
fi


# Compile the `examples/hello-world` application for the nRF52840 platform.
export CNG_PATH=/tmp/contiki-ng
docker run \
--sysctl net.ipv6.conf.all.disable_ipv6=0 \
--mount type=bind,source=$CNG_PATH,destination=/home/user/contiki-ng \
contiker/contiki-ng \
make -C examples/hello-world TARGET=nrf52840 hello-world
41 changes: 41 additions & 0 deletions 08-interop/test_spec08.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import re
import sys
import subprocess

import pexpect.replwrap
import pytest
Expand Down Expand Up @@ -49,6 +50,46 @@ def test_task01(riot_ctrl, log_nodes):
assert res["stats"]["packet_loss"] < 1


@pytest.mark.flaky(reruns=1, reruns_delay=30)
@pytest.mark.iotlab_creds
# nodes passed to riot_ctrl fixture
@pytest.mark.parametrize(
'nodes', [pytest.param(['nrf52840dk', 'nrf52840dk'])], indirect=['nodes']
)
def test_task03(riot_ctrl):
# run `./compile_contiki.sh` relative to this file
subprocess.check_call(["./compile_contiki.sh"], cwd=__file__[: __file__.rfind("/")])

build_path = "build/nrf52840/dk/hello-world.nrf52840"
flashfile = f"/tmp/contiki-ng/examples/hello-world/{build_path}"

gnrc_node, contiki_node = (
riot_ctrl(0, GNRC_APP, Shell),
riot_ctrl(
1,
'examples/hello-world',
riotctrl.shell.ShellInteraction,
extras={"BINFILE": flashfile},
),
)

gnrc_netif, gnrc_addr = lladdr(gnrc_node.ifconfig_list())

# get the address of the contiki node, ie a substring after "-- "
res = contiki_node.cmd("ip-addr")
match = re.search("-- (.+)", res)
assert match
contiki_addr = match[1]

gnrc_node.ifconfig_set(gnrc_netif, "pan_id", "abcd")

res = contiki_node.cmd(f"ping {gnrc_addr}")
assert f"Received ping reply from {gnrc_addr}" in res

res = ping6(gnrc_node, contiki_addr, 3, 12, 1)
assert res['stats']['packet_loss'] < 10


@pytest.mark.flaky(reruns=3, reruns_delay=30)
@pytest.mark.iotlab_creds
# nodes passed to riot_ctrl fixture
Expand Down
14 changes: 11 additions & 3 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,8 @@ def nodes(local, request, boards, iotlab_site):
RUNNING_EXPERIMENTS.remove(exp)


def update_env(node, modules=None, cflags=None, port=None, termflags=None):
def update_env(node, modules=None, cflags=None, port=None, termflags=None, extras=None):
# pylint: disable=too-many-arguments
node.env['QUIETER'] = '1'
if not isinstance(modules, str) and isinstance(modules, Iterable):
node.env['USEMODULE'] = ' '.join(str(m) for m in modules)
Expand All @@ -322,6 +323,8 @@ def update_env(node, modules=None, cflags=None, port=None, termflags=None):
node.env['PORT'] = port
if termflags is not None:
node.env['TERMFLAGS'] = termflags
if extras is not None:
node.env.update(extras)


@pytest.fixture
Expand All @@ -333,6 +336,7 @@ def riot_ctrl(log_nodes, log_file_fmt, nodes, riotbase, request):
factory_ctrls = []

# pylint: disable=R0913
# flake8: noqa: C901
def ctrl(
nodes_idx,
application_dir,
Expand All @@ -342,12 +346,13 @@ def ctrl(
cflags=None,
port=None,
termflags=None,
extras=None,
):
if board_type is not None:
node = next(n for n in nodes if n.board() == board_type)
else:
node = nodes[nodes_idx]
update_env(node, modules, cflags, port, termflags)
update_env(node, modules, cflags, port, termflags, extras)
# if the nodes are not logged, there is no sense in logging to a file
# so check if nodes are logged as well as if they should be logged to a
# file
Expand All @@ -366,8 +371,11 @@ def ctrl(
# need to access private member here isn't possible otherwise sadly :(
# pylint: disable=W0212
node._application_directory = os.path.join(riotbase, application_dir)
flash_cmd = "flash"
if "BINFILE" in node.env:
flash_cmd = "flash-only"
node.make_run(
['flash'],
[flash_cmd],
check=True,
stdout=None if log_nodes else subprocess.DEVNULL,
stderr=None if log_nodes else subprocess.DEVNULL,
Expand Down

0 comments on commit dd8ee94

Please sign in to comment.