mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
tests/riotboot: migrate to full python test script
This commit is contained in:
parent
dbbdd703ea
commit
12761934bc
@ -13,13 +13,9 @@ BINDIR_APP = $(BINDIR)/$(APPLICATION)
|
|||||||
#
|
#
|
||||||
export SLOT0_OFFSET SLOT0_LEN SLOT1_OFFSET SLOT1_LEN
|
export SLOT0_OFFSET SLOT0_LEN SLOT1_OFFSET SLOT1_LEN
|
||||||
|
|
||||||
# Mandatory APP_VER, set to epoch by default, or "0" for CI build
|
# Mandatory APP_VER, set to epoch by default
|
||||||
ifeq (1, RIOT_CI_BUILD)
|
EPOCH := $(shell date +%s)
|
||||||
APP_VER ?= 0
|
APP_VER ?= $(EPOCH)
|
||||||
else
|
|
||||||
EPOCH := $(shell date +%s)
|
|
||||||
APP_VER ?= $(EPOCH)
|
|
||||||
endif
|
|
||||||
|
|
||||||
# Final target for slot 0 with riot_hdr
|
# Final target for slot 0 with riot_hdr
|
||||||
SLOT0_RIOT_BIN = $(BINDIR_APP)-slot0.$(APP_VER).riot.bin
|
SLOT0_RIOT_BIN = $(BINDIR_APP)-slot0.$(APP_VER).riot.bin
|
||||||
|
@ -16,11 +16,6 @@ DEVELHELP ?= 1
|
|||||||
# Change this to 0 show compiler invocation lines by default:
|
# Change this to 0 show compiler invocation lines by default:
|
||||||
QUIET ?= 1
|
QUIET ?= 1
|
||||||
|
|
||||||
# The test script assumes initially version "0" is flashed,
|
|
||||||
# as done by the CI.
|
|
||||||
# Thus default to that (instead of epoch set by makefiles/boot/riotboot.inc.mk).
|
|
||||||
APP_VER?=0
|
|
||||||
|
|
||||||
# Ensure both slot bin files are always generated and linked to avoid compiling
|
# Ensure both slot bin files are always generated and linked to avoid compiling
|
||||||
# during the test. This ensures that "BUILD_IN_DOCKER=1 make test"
|
# during the test. This ensures that "BUILD_IN_DOCKER=1 make test"
|
||||||
# can rely on them being present without having to trigger re-compilation.
|
# can rely on them being present without having to trigger re-compilation.
|
||||||
|
@ -27,14 +27,14 @@ functionality:
|
|||||||
|
|
||||||
This will:
|
This will:
|
||||||
|
|
||||||
1. flash bootloader and slot0 with APP_VER=0, invalidate slot1
|
1. flash bootloader and slot0, invalidate slot1
|
||||||
2. verify slot0 has been booted and has APP_VER set to 0
|
2. get the running slot and current APP_VER
|
||||||
|
|
||||||
3. flash slot1 with APP_VER set to 1
|
3. flash slot1 with APP_VER + 1
|
||||||
4. verify slot1 has booted and shows APP_VER==1
|
4. verify slot1 has booted and shows version = APP_VER + 1
|
||||||
|
|
||||||
5. flash slot0 with APP_VER set to 2
|
5. flash slot0 with APP_VER + 2
|
||||||
6. verify slot0 has booted and shows APP_VER==2
|
4. verify slot0 has booted and shows version = APP_VER + 2
|
||||||
|
|
||||||
If this test runs correctly, it shows that riotboot's basic functions and are
|
If this test runs correctly, it shows that riotboot's basic functions are
|
||||||
working properly on the target board.
|
working properly on the target board.
|
||||||
|
79
tests/riotboot/tests/01-run.py
Executable file
79
tests/riotboot/tests/01-run.py
Executable file
@ -0,0 +1,79 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
# Copyright (C) 2018 Federico Pellegrin <fede@evolware.org>
|
||||||
|
# Copyright (C) 2019 Francisco Molina <francois-xavier.molina@inria.fr>
|
||||||
|
#
|
||||||
|
# This file is subject to the terms and conditions of the GNU Lesser
|
||||||
|
# General Public License v2.1. See the file LICENSE in the top level
|
||||||
|
# directory for more details.
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import subprocess
|
||||||
|
from testrunner import run
|
||||||
|
|
||||||
|
|
||||||
|
def flash_slot(slotnum, version):
|
||||||
|
cmd = [
|
||||||
|
"make",
|
||||||
|
"RIOTBOOT_SKIP_COMPILE=1",
|
||||||
|
"riotboot/flash-slot{}".format(slotnum),
|
||||||
|
"APP_VER={}".format(version),
|
||||||
|
]
|
||||||
|
assert subprocess.call(cmd) == 0
|
||||||
|
|
||||||
|
|
||||||
|
def assert_check_slot(child, slotnum, version):
|
||||||
|
# Check if it's running on the expected slot
|
||||||
|
child.expect_exact('>')
|
||||||
|
child.sendline("curslotnr")
|
||||||
|
child.expect_exact("Current slot={}".format(slotnum))
|
||||||
|
|
||||||
|
# Ask for current slot header info and check for basic output integrity
|
||||||
|
child.expect_exact('>')
|
||||||
|
child.sendline("curslothdr")
|
||||||
|
# Magic number is "RIOT" (always in little endian)
|
||||||
|
child.expect_exact("Image magic_number: 0x544f4952")
|
||||||
|
# Other info is hardware/app dependent so we just check basic compliance
|
||||||
|
child.expect_exact("Image Version: {0:#0{1}x}".format(version, 10))
|
||||||
|
child.expect(r"Image start address: 0x[0-9a-fA-F]{8}\r\n")
|
||||||
|
child.expect(r"Header chksum: 0x[0-9a-fA-F]{8}\r\n")
|
||||||
|
|
||||||
|
# Ask for address of slot 0
|
||||||
|
child.expect_exact('>')
|
||||||
|
child.sendline("getslotaddr 0")
|
||||||
|
child.expect(r"Slot 0 address=0x[0-9a-fA-F]{8}\r\n")
|
||||||
|
|
||||||
|
# Ask for data of all slots
|
||||||
|
child.expect_exact('>')
|
||||||
|
child.sendline("dumpaddrs")
|
||||||
|
child.expect(r"slot 0: metadata: 0x[0-9a-fA-F]{1,8} "
|
||||||
|
r"image: 0x[0-9a-fA-F]{8}\r\n")
|
||||||
|
child.expect(r"slot 1: metadata: 0x[0-9a-fA-F]{1,8} "
|
||||||
|
r"image: 0x[0-9a-fA-F]{8}\r\n")
|
||||||
|
child.expect_exact('>')
|
||||||
|
|
||||||
|
|
||||||
|
def testfunc(child):
|
||||||
|
# Ask for current slot, should be 0 or 1
|
||||||
|
child.expect_exact('>')
|
||||||
|
child.sendline("curslotnr")
|
||||||
|
child.expect(r"Current slot=([0-1])")
|
||||||
|
slotnum = int(child.match.group(1))
|
||||||
|
|
||||||
|
# Ask for current APP_VER
|
||||||
|
child.expect_exact('>')
|
||||||
|
child.sendline("curslothdr")
|
||||||
|
child.expect(r"Image Version: (?P<app_ver>0x[0-9a-fA-F]{8})\r\n")
|
||||||
|
current_app_ver = int(child.match.group("app_ver"), 16)
|
||||||
|
|
||||||
|
# Flash to both slots and verify basic functions
|
||||||
|
for version in [current_app_ver + 1, current_app_ver + 2]:
|
||||||
|
slotnum = slotnum ^ 1
|
||||||
|
flash_slot(slotnum, version)
|
||||||
|
assert_check_slot(child, slotnum, version)
|
||||||
|
|
||||||
|
print("TEST PASSED")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
sys.exit(run(testfunc))
|
@ -1,14 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
export RIOTBOOT_SKIP_COMPILE=1
|
|
||||||
set -e
|
|
||||||
|
|
||||||
${APPDIR}/tests/common/assert_slotnum.py 0 0
|
|
||||||
|
|
||||||
APP_VER=1 make -C${APPDIR} riotboot/flash-slot1
|
|
||||||
${APPDIR}/tests/common/assert_slotnum.py 1 1
|
|
||||||
|
|
||||||
APP_VER=2 make -C${APPDIR} riotboot/flash-slot0
|
|
||||||
${APPDIR}/tests/common/assert_slotnum.py 0 2
|
|
||||||
|
|
||||||
echo "[TEST PASSED]"
|
|
@ -1,48 +0,0 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
|
|
||||||
# Copyright (C) 2018 Federico Pellegrin <fede@evolware.org>
|
|
||||||
#
|
|
||||||
# This file is subject to the terms and conditions of the GNU Lesser
|
|
||||||
# General Public License v2.1. See the file LICENSE in the top level
|
|
||||||
# directory for more details.
|
|
||||||
|
|
||||||
import sys
|
|
||||||
from testrunner import run
|
|
||||||
|
|
||||||
slotnum = int(sys.argv[1])
|
|
||||||
app_ver = int(sys.argv[2])
|
|
||||||
print("expecting slot number %s, app_ver %s" % (slotnum, app_ver))
|
|
||||||
|
|
||||||
|
|
||||||
def testfunc(child):
|
|
||||||
global slotnum
|
|
||||||
global app_ver
|
|
||||||
|
|
||||||
# Ask for current slot, should be 0 or 1
|
|
||||||
child.sendline("curslotnr")
|
|
||||||
child.expect("Current slot=%s" % (slotnum))
|
|
||||||
child.expect('>')
|
|
||||||
|
|
||||||
# Ask for current slot header info and checks for basic output integrity
|
|
||||||
child.sendline("curslothdr")
|
|
||||||
# Magic number is "RIOT" (always in little endian)
|
|
||||||
child.expect_exact("Image magic_number: 0x544f4952")
|
|
||||||
# Other info is hardware/app dependent so we just check basic compliance
|
|
||||||
child.expect("Image Version: %s" % ("{0:#0{1}x}".format(app_ver, 10)))
|
|
||||||
child.expect("Image start address: 0x[0-9a-fA-F]{8}")
|
|
||||||
child.expect("Header chksum: 0x[0-9a-fA-F]{8}")
|
|
||||||
child.expect('>')
|
|
||||||
|
|
||||||
# Ask for address of slot 0
|
|
||||||
child.sendline("getslotaddr 0")
|
|
||||||
child.expect("Slot 0 address=0x[0-9a-fA-F]{8}")
|
|
||||||
child.expect('>')
|
|
||||||
|
|
||||||
# Ask for data of all slots
|
|
||||||
child.sendline("dumpaddrs")
|
|
||||||
child.expect("slot 0: metadata: 0x[0-9a-fA-F]{1,8} image: 0x[0-9a-fA-F]{8}")
|
|
||||||
child.expect('>')
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
sys.exit(run(testfunc))
|
|
Loading…
Reference in New Issue
Block a user