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

Merge pull request #15395 from fjmolinas/pr_suit_interactive_test

examples/suit_update: use interactive sync in test
This commit is contained in:
Alexandre Abadie 2020-11-17 13:57:53 +01:00 committed by GitHub
commit 4d8ca6a2e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 69 additions and 24 deletions

View File

@ -51,6 +51,9 @@ FEATURES_OPTIONAL += periph_gpio_irq
# Default COAP manifest resource location when fetched through gpio trigger # Default COAP manifest resource location when fetched through gpio trigger
CFLAGS += -DSUIT_MANIFEST_RESOURCE=\"$(SUIT_COAP_ROOT)/$(SUIT_NOTIFY_MANIFEST)\" CFLAGS += -DSUIT_MANIFEST_RESOURCE=\"$(SUIT_COAP_ROOT)/$(SUIT_NOTIFY_MANIFEST)\"
# Enable test_utils_interactive_sync, only used when running automatic test
DEFAULT_MODULE += test_utils_interactive_sync
# Change this to 0 to not use ethos # Change this to 0 to not use ethos
USE_ETHOS ?= 1 USE_ETHOS ?= 1

View File

@ -465,22 +465,24 @@ displayed during this step:
Once the new image is written, a final validation is performed and, in case of Once the new image is written, a final validation is performed and, in case of
success, the application reboots on the new slot: success, the application reboots on the new slot:
Finalizing payload store
Verifying image digest Verifying image digest
riotboot: verifying digest at 0x1fffbd15 (img at: 0x1000 size: 77448) Starting digest verification against image
Install correct payload
Verifying image digest Verifying image digest
riotboot: verifying digest at 0x1fffbd15 (img at: 0x1000 size: 77448) Starting digest verification against image
suit_parse() success Install correct payload
SUIT policy check OK.
suit_coap: finalizing image flash
riotboot_flashwrite: riotboot flashing completed successfully
Image magic_number: 0x544f4952 Image magic_number: 0x544f4952
Image Version: 0x5e71f662 Image Version: 0x5fa52bcc
Image start address: 0x00001100 Image start address: 0x00201400
Header chksum: 0x745a0376 Header chksum: 0x53bb3d33
suit_coap: rebooting...
main(): This is RIOT! (Version: 2020.04) main(): This is RIOT! (Version: <version xx>))
RIOT SUIT update example application RIOT SUIT update example application
running from slot 1 Running from slot 1
...
The slot number should have changed from after the application reboots. The slot number should have changed from after the application reboots.
You can do the publish-notify sequence several times to verify this. You can do the publish-notify sequence several times to verify this.

View File

@ -68,9 +68,10 @@ static void cb(void *arg)
} }
#endif #endif
int main(void) static int cmd_print_riotboot_hdr(int argc, char **argv)
{ {
puts("RIOT SUIT update example application"); (void)argc;
(void)argv;
int current_slot = riotboot_slot_current(); int current_slot = riotboot_slot_current();
if (current_slot != -1) { if (current_slot != -1) {
@ -78,21 +79,48 @@ int main(void)
* confuses the test script. As a workaround, just disable interrupts * confuses the test script. As a workaround, just disable interrupts
* for a while. * for a while.
*/ */
irq_disable(); unsigned state = irq_disable();
printf("running from slot %d\n", current_slot);
printf("slot start addr = %p\n", (void *)riotboot_slot_get_hdr(current_slot));
riotboot_slot_print_hdr(current_slot); riotboot_slot_print_hdr(current_slot);
irq_enable(); irq_restore(state);
} }
else { else {
printf("[FAILED] You're not running riotboot\n"); printf("[FAILED] You're not running riotboot\n");
} }
return 0;
}
static int cmd_print_current_slot(int argc, char **argv)
{
(void)argc;
(void)argv;
/* Sometimes, udhcp output messes up the following printfs. That
* confuses the test script. As a workaround, just disable interrupts
* for a while.
*/
unsigned state = irq_disable();
printf("Running from slot %d\n", riotboot_slot_current());
irq_restore(state);
return 0;
}
static const shell_command_t shell_commands[] = {
{ "current-slot", "Print current slot number", cmd_print_current_slot },
{ "riotboot-hdr", "Print current slot header", cmd_print_riotboot_hdr },
{ NULL, NULL, NULL }
};
int main(void)
{
puts("RIOT SUIT update example application");
#if defined(MODULE_PERIPH_GPIO_IRQ) && defined(BTN0_PIN) #if defined(MODULE_PERIPH_GPIO_IRQ) && defined(BTN0_PIN)
/* initialize a button to manually trigger an update */ /* initialize a button to manually trigger an update */
gpio_init_int(BTN0_PIN, BTN0_MODE, GPIO_FALLING, cb, NULL); gpio_init_int(BTN0_PIN, BTN0_MODE, GPIO_FALLING, cb, NULL);
#endif #endif
cmd_print_current_slot(0, NULL);
cmd_print_riotboot_hdr(0, NULL);
/* start suit coap updater thread */ /* start suit coap updater thread */
suit_coap_run(); suit_coap_run();
@ -109,7 +137,7 @@ int main(void)
puts("Starting the shell"); puts("Starting the shell");
char line_buf[SHELL_DEFAULT_BUFSIZE]; char line_buf[SHELL_DEFAULT_BUFSIZE];
shell_run(NULL, line_buf, SHELL_DEFAULT_BUFSIZE); shell_run(shell_commands, line_buf, SHELL_DEFAULT_BUFSIZE);
return 0; return 0;
} }

View File

@ -13,6 +13,7 @@ import tempfile
import time import time
from testrunner import run from testrunner import run
from testrunner import utils
# Default test over loopback interface # Default test over loopback interface
COAP_HOST = "[fd00:dead:beef::1]" COAP_HOST = "[fd00:dead:beef::1]"
@ -113,10 +114,7 @@ def ping6(client):
def get_reachable_addr(child): def get_reachable_addr(child):
# Wait for suit_coap thread to start # Give some time for the network interface to be configured
child.expect_exact("suit_coap: started.")
child.expect_exact("Starting the shell")
# give some time for the network interface to be configured
time.sleep(1) time.sleep(1)
# Get address # Get address
client_addr = get_ipv6_addr(child) client_addr = get_ipv6_addr(child)
@ -126,13 +124,25 @@ def get_reachable_addr(child):
def app_version(child): def app_version(child):
utils.test_utils_interactive_sync_shell(child, 5, 1)
# get version of currently running image # get version of currently running image
# "Image Version: 0x00000000" # "Image Version: 0x00000000"
child.sendline('riotboot-hdr')
child.expect(r"Image Version: (?P<app_ver>0x[0-9a-fA-F:]+)\r\n") child.expect(r"Image Version: (?P<app_ver>0x[0-9a-fA-F:]+)\r\n")
app_ver = int(child.match.group("app_ver"), 16) app_ver = int(child.match.group("app_ver"), 16)
return app_ver return app_ver
def running_slot(child):
utils.test_utils_interactive_sync_shell(child, 5, 1)
# get version of currently running image
# "Image Version: 0x00000000"
child.sendline('current-slot')
child.expect(r"Running from slot (\d+)\r\n")
slot = int(child.match.group(1))
return slot
def _test_invalid_version(child, client, app_ver): def _test_invalid_version(child, client, app_ver):
publish(TMPDIR.name, COAP_HOST, app_ver - 1) publish(TMPDIR.name, COAP_HOST, app_ver - 1)
notify(COAP_HOST, client, app_ver - 1) notify(COAP_HOST, client, app_ver - 1)
@ -165,9 +175,11 @@ def _test_successful_update(child, client, app_ver):
while wait_for_update(child) == 0: while wait_for_update(child) == 0:
pass pass
# Wait for reboot
child.expect_exact("suit_coap: rebooting...")
# Verify running slot # Verify running slot
child.expect(r"running from slot (\d+)\r\n") current_slot = running_slot(child)
assert target_slot == int(child.match.group(1)), "BOOTED FROM SAME SLOT" assert target_slot == current_slot, "BOOTED FROM SAME SLOT"
# Verify client is reachable and get address # Verify client is reachable and get address
client = get_reachable_addr(child) client = get_reachable_addr(child)