Skip to content

Commit

Permalink
tests/test_tools: test to get a command return value
Browse files Browse the repository at this point in the history
Get the output of a one line command without other garbage messages.
  • Loading branch information
cladmi committed Aug 27, 2019
1 parent 4ee820a commit 1d77a23
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tests/test_tools/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/

#include <stdio.h>
#include <string.h>
#include <ctype.h>

#include "shell_commands.h"
#include "shell.h"
Expand Down Expand Up @@ -65,9 +67,40 @@ static int cmd_shellping(int argc, char **argv)
}


/**
* @brief Uppercase the first word
*
* First argument is read, converted to uppercase and printed with a newline.
*
* @param[in] argc Number of arguments
* @param[in] argv Array of arguments
*
* @return 0 on success
*
*/
static int cmd_toupper(int argc, char **argv)
{
if (argc != 2) {
puts("Invalid number of argument");
printf("Usage: %s <word>\n", argv[0]);
return 1;
}

size_t len = strlen(argv[1]);
for (size_t i = 0; i < len; i++) {
char c = toupper(argv[1][i]);
putchar(c);
}
putchar('\n');

return 0;
}


static const shell_command_t shell_commands[] = {
{ "shellping", "Just print 'shellpong'", cmd_shellping },
{ "true", "do nothing, successfully", cmd_true },
{ "toupper", "uppercase first argument", cmd_toupper },
{ NULL, NULL, NULL }
};

Expand Down
11 changes: 11 additions & 0 deletions tests/test_tools/tests/01-run.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,20 @@ def _test_no_local_echo(child):
assert res == 0, "There should have been a timeout and not match stdin"


def _test_clean_output(child):
"""Verify that only what the nodes sends is received."""
child.sendline('toupper lowercase')
retline = child.readline()
assert retline.strip() == 'LOWERCASE'


def testfunc(child):
"""Run some tests to verify the board under test behaves correctly.
It currently tests:
* local echo
* getting some test output without other messages
"""
child.expect_exact("Running 'tests_tools' application")

Expand All @@ -55,6 +63,9 @@ def testfunc(child):
# The node should still answer after the previous one
_shellping(child)

# Check that the output is clean without extra terminal output
_test_clean_output(child)


if __name__ == "__main__":
sys.exit(run(testfunc))

0 comments on commit 1d77a23

Please sign in to comment.