From a4c3d7342a49ae2fa64b8bd7a762ea863eb93c7e Mon Sep 17 00:00:00 2001 From: Alexandre Abadie Date: Tue, 26 Nov 2019 15:36:39 +0100 Subject: [PATCH] tests/stdin: refactor test application The test application now prints in a loop the input character. In case stdin is not ready yet after startup this lets the possibility to try to send several time a character before failing. The automatic test is now more robust on platforms where stdin takes time before it gets in a ready state (some AVR, hifive). --- tests/stdin/main.c | 7 +++++-- tests/stdin/tests/01-run.py | 17 +++++++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/tests/stdin/main.c b/tests/stdin/main.c index 7d071685ba..0b44dc2863 100644 --- a/tests/stdin/main.c +++ b/tests/stdin/main.c @@ -18,7 +18,10 @@ int main(void) { - int value = getchar(); - printf("You entered '%c'\n", (char)value); + while (1) { + int value = getchar(); + printf("You entered '%c'\n", (char)value); + } + return 0; } diff --git a/tests/stdin/tests/01-run.py b/tests/stdin/tests/01-run.py index f1d287543b..4acff33846 100755 --- a/tests/stdin/tests/01-run.py +++ b/tests/stdin/tests/01-run.py @@ -7,12 +7,25 @@ # directory for more details. import sys +import pexpect from testrunner import run +TEST_INPUT = 'O' +RETRIES = 5 +TIMEOUT = 3 + + def testfunc(child): - child.sendline('O') - child.expect_exact('You entered \'O\'') + expected_output = 'You entered \'{}\''.format(TEST_INPUT) + for _ in range(0, RETRIES): + child.sendline(TEST_INPUT) + ret = child.expect_exact([expected_output, pexpect.TIMEOUT], + timeout=TIMEOUT) + if ret == 0: + break + else: + child.expect_exact(expected_output) if __name__ == "__main__":