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

Merge pull request #17941 from fjmolinas/pr_suit_seq_no_cmd

sys/sc_suit: add seq_no command
This commit is contained in:
benpicco 2022-04-17 23:44:20 +02:00 committed by GitHub
commit 0e5900d597
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 73 additions and 4 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

View File

@ -23,15 +23,33 @@
#include <inttypes.h>
#include "suit/transport/coap.h"
#include "suit/storage.h"
static void _print_usage(char **argv)
{
printf("Usage: %s fetch <manifest url>\n", argv[0]);
printf(" %s seq_no\n", argv[0]);
}
int _suit_handler(int argc, char **argv)
{
if (argc != 2) {
printf("Usage: %s <manifest url>\n", argv[0]);
if (argc < 2) {
_print_usage(argv);
return 1;
}
suit_coap_trigger((uint8_t *)argv[1], strlen(argv[1]));
if (strcmp(argv[1], "fetch") == 0) {
suit_coap_trigger((uint8_t *)argv[2], strlen(argv[2]));
}
else if (strcmp(argv[1], "seq_no") == 0) {
uint32_t seq_no = 0;
suit_storage_get_highest_seq_no(&seq_no);
printf("seq_no: %" PRIu32 "\n", seq_no);
}
else {
_print_usage(argv);
return -1;
}
return 0;
}