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:
parent
180be1d6ee
commit
81cbf83478
32
dist/pythonlibs/riotctrl_shell/sys.py
vendored
32
dist/pythonlibs/riotctrl_shell/sys.py
vendored
@ -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_
|
||||
)
|
||||
|
21
dist/pythonlibs/riotctrl_shell/tests/test_sys.py
vendored
21
dist/pythonlibs/riotctrl_shell/tests/test_sys.py
vendored
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user