Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests/sys/shell_lock: increase robustness of the test #20962

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions tests/sys/shell_lock/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
23 changes: 6 additions & 17 deletions tests/sys/shell_lock/tests/01-run.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,6 @@
"_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: '
Expand All @@ -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
Expand All @@ -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.')


Expand Down
Loading