1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

dist/riotctrl_shell: add suit interactions

This commit is contained in:
Francisco Molina 2022-04-14 08:39:40 +02:00
parent 180be1d6ee
commit 81cbf83478
2 changed files with 52 additions and 1 deletions

View File

@ -10,7 +10,8 @@ sys-related shell interactions
Defines sys-related shell command interactions
"""
from riotctrl.shell import ShellInteraction
import re
from riotctrl.shell import ShellInteraction, ShellInteractionParser
class Help(ShellInteraction):
@ -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_
)

View File

@ -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_sequence_no():
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