Skip to content

Commit

Permalink
examples/suit_update: improve test script
Browse files Browse the repository at this point in the history
- Verify smaller image sequence numbers are rejected
- Verify invalid signatures are rejected
  • Loading branch information
fjmolinas committed Oct 21, 2019
1 parent 04712db commit 2fabada
Showing 1 changed file with 51 additions and 16 deletions.
67 changes: 51 additions & 16 deletions examples/suit_update/tests/01-run.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,15 @@ def notify(coap_server, client_url, version=None):
assert not subprocess.call(cmd)


def publish(server_dir, server_url, app_ver, latest_name=None):
def publish(server_dir, server_url, app_ver, keys='default', latest_name=None):
cmd = [
"make",
"suit/publish",
"SUIT_COAP_FSROOT={}".format(server_dir),
"SUIT_COAP_SERVER={}".format(server_url),
"APP_VER={}".format(app_ver),
"RIOTBOOT_SKIP_COMPILE=1",
"SUIT_KEY={}".format(keys),
]
if latest_name is not None:
cmd.append("SUIT_MANIFEST_SIGNED_LATEST={}".format(latest_name))
Expand Down Expand Up @@ -109,25 +110,32 @@ def ping6(client):
return ping_ok


def testfunc(child):
"""For one board test if specified application is updatable"""

# Initial Setup and wait for address configuration
child.expect_exact("main(): This is RIOT!")

def app_version(child):
# get version of currently running image
# "Image Version: 0x00000000"
child.expect(r"Image Version: (?P<app_ver>0x[0-9a-fA-F:]+)")
current_app_ver = int(child.match.group("app_ver"), 16)
app_ver = int(child.match.group("app_ver"), 16)
return app_ver

for version in [current_app_ver + 1, current_app_ver + 2]:
# Get address, if using ethos it will change on each reboot
client_addr = get_ipv6_addr(child)
client = "[{}]".format(client_addr)
# Wait for suit_coap thread to start
# Ping6
ping6(client_addr)
child.expect_exact("suit_coap: started.")

def test_invalid_version(child, client, app_ver):
publish(TMPDIR.name, COAP_HOST, app_ver - 1)
notify(COAP_HOST, client, app_ver - 1)
child.expect_exact("suit_coap: trigger received")
child.expect_exact("suit: verifying manifest signature...")
child.expect_exact("seq_nr <= running image")


def test_invalid_signature(child, client, app_ver):
publish(TMPDIR.name, COAP_HOST, app_ver + 1, 'invalid_keys')
notify(COAP_HOST, client, app_ver + 1)
child.expect_exact("suit_coap: trigger received")
child.expect_exact("suit: verifying manifest signature...")
child.expect_exact("Unable to validate signature")


def test_successful_update(child, client, app_ver):
for version in [app_ver + 1, app_ver + 2]:
# Trigger update process, verify it validates manifest correctly
publish(TMPDIR.name, COAP_HOST, version)
notify(COAP_HOST, client, version)
Expand All @@ -145,6 +153,33 @@ def testfunc(child):
# Verify running slot
child.expect(r"running from slot (\d+)")
assert target_slot == int(child.match.group(1)), "BOOTED FROM SAME SLOT"
# Wait for suit_coap thread to start
child.expect_exact("suit_coap: started.")


def testfunc(child):
# Initial Setup, get client address and current app_ver
child.expect_exact("main(): This is RIOT!")
current_app_ver = app_version(child)
client = get_ipv6_addr(child)
# Wait for suit_coap thread to start
child.expect_exact("suit_coap: started.")
ping6(client)

def run(func):
if child.logfile == sys.stdout:
func(child, "[{}]".format(client), current_app_ver)
else:
try:
func(child, "[{}]".format(client), current_app_ver)
print(".", end="", flush=True)
except Exception as e:
print("FAILED")
raise e

run(test_invalid_signature)
run(test_invalid_version)
run(test_successful_update)

print("TEST PASSED")

Expand Down

0 comments on commit 2fabada

Please sign in to comment.