Skip to content

Commit

Permalink
dist/riotctrl_shell: add suit interactions
Browse files Browse the repository at this point in the history
  • Loading branch information
fjmolinas committed Apr 14, 2022
1 parent 180be1d commit 2bc93b7
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
32 changes: 31 additions & 1 deletion dist/pythonlibs/riotctrl_shell/sys.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
Defines sys-related shell command interactions
"""

from riotctrl.shell import ShellInteraction
import re
from riotctrl.shell import ShellInteraction, ShellInteractionParser


class Help(ShellInteraction):
Expand Down Expand Up @@ -38,3 +39,32 @@ class Version(ShellInteraction):
def version(self, timeout=-1, async_=False):
"""Sends the reboot command via the terminal"""
return self.cmd("version", timeout, async_)


class SUITSequenceNoParser(ShellInteractionParser):
def __init__(self):
self.c_seq_no = re.compile(r"seq_no: (?P<seq_no>\d+)$")

def parse(self, cmd_output):
for line in cmd_output.splitlines():
m = self.c_seq_no.search(line)
if m is not None:
return int(m.group("seq_no"))
return None


class SUIT(ShellInteraction):
@ShellInteraction.check_term
def suit_cmd(self, args=None, timeout=-1, async_=False):
cmd = "suit"
if args is not None:
cmd += " {args}".format(args=" ".join(str(a) for a in args))
return self.cmd(cmd, timeout=timeout, async_=False)

def suit_sequence_no(self, timeout=-1, async_=False):
return self.suit_cmd(args=("seq_no",), timeout=timeout, async_=async_)

def suit_fetch(self, manifest, timeout=-1, async_=False):
return self.suit_cmd(
args=("fetch", f'"{manifest}"'), timeout=timeout, async_=async_
)
21 changes: 21 additions & 0 deletions dist/pythonlibs/riotctrl_shell/tests/test_sys.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,24 @@ def test_version():
res = si.version()
# mock just returns last input
assert res == "version"


def test_suit_fetch():
rc = init_ctrl()
si = riotctrl_shell.sys.SUIT(rc)
res = si.suit_fetch("coap://[2001:db8::2:1]/manifest")
# mock just returns last input
assert res == "suit fetch coap://[2001:db8::2:1]/manifest"


def test_suit_fetch():
rc = init_ctrl(
output="""
seq_no: 123456789
"""
)
si = riotctrl_shell.sys.SUIT(rc)
res = si.suit_sequence_no()
parser = riotctrl_shell.sys.SUITSequenceNoParser()
# mock just returns last input
assert parser.parse(res) == 123456789

0 comments on commit 2bc93b7

Please sign in to comment.