From abb666bf7375b643dd57355b506d186756be517d Mon Sep 17 00:00:00 2001 From: Marian Buschsieweke Date: Thu, 7 Nov 2024 10:45:50 +0100 Subject: [PATCH] tests/sys/shell_lock: increase robustness of the test Before the test used the `help` command to verify that access to the shell is present. While this does have the benefit of not requiring a custom command, it does have some robustness issues: - When new default commands get added, this test will fail - When the help message of a command gets reworded, the test will fail - When the order of commands in the test will change, the test will fail - Note that with the XFA based `SHELL_COMMAND()` macro, we do not guarantee any particular order. Specifically, the order can change with implementation details. --- tests/sys/shell_lock/main.c | 15 +++++++++++++++ tests/sys/shell_lock/tests/01-run.py | 23 ++++++----------------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/tests/sys/shell_lock/main.c b/tests/sys/shell_lock/main.c index b25911c5b6..e3d2286b77 100644 --- a/tests/sys/shell_lock/main.c +++ b/tests/sys/shell_lock/main.c @@ -20,6 +20,21 @@ #include "test_utils/interactive_sync.h" +/* this command is used by the test automation to check whether commands are + * executed or not (due to the shell being locked). */ +static int _cmd_ping(int argc, char **argv) +{ + if (argc != 1) { + printf("Usage: %s\n", argv[0]); + return 1; + } + + puts("PONG!"); + return 0; +} + +SHELL_COMMAND(ping, "Echo \"PONG!\"", _cmd_ping); + int main(void) { test_utils_interactive_sync(); diff --git a/tests/sys/shell_lock/tests/01-run.py b/tests/sys/shell_lock/tests/01-run.py index 1c60bf1367..cedb31222e 100755 --- a/tests/sys/shell_lock/tests/01-run.py +++ b/tests/sys/shell_lock/tests/01-run.py @@ -22,15 +22,6 @@ PASSWORDS_INCORRECT = [ "_password" ] -EXPECTED_HELP = ( - 'Command Description', - '---------------------------------------', - 'lock Lock the shell', - 'pm interact with layered PM subsystem', - 'reboot Reboot the node', - 'version Prints current RIOT_VERSION', -) - AUTO_LOCK_TIMEOUT_MS = 7000 SHELL_PROMPT = '> ' PASSWORD_PROMPT = 'Password: ' @@ -49,16 +40,15 @@ def testfunc(child): child.expect_exact(SHELL_PROMPT) # check we have access - child.sendline('help') - for line in EXPECTED_HELP: - child.expect_exact(line) + child.sendline('ping') + child.expect_exact("PONG!") # lock child.sendline('lock') child.expect(SHELL_PROMPT) # trigger password prompt - child.sendline('help') + child.sendline('ping') child.expect('The shell is locked. Enter a valid password to unlock.') # test different incorrect passwords @@ -82,16 +72,15 @@ def testfunc(child): child.expect_exact(SHELL_PROMPT) # check we have access - child.sendline('help') - for line in EXPECTED_HELP: - child.expect_exact(line) + child.sendline('ping') + child.expect_exact("PONG!") # wait until auto_lock locks the shell after # CONFIG_SHELL_LOCK_AUTO_LOCK_TIMEOUT_MS (+ 1 second buffer time) time.sleep((AUTO_LOCK_TIMEOUT_MS / 1000.0) + 1) # trigger password prompt - child.sendline('help') + child.sendline('ping') child.expect('The shell is locked. Enter a valid password to unlock.')