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).
This commit is contained in:
parent
f5252bf482
commit
a4c3d7342a
@ -18,7 +18,10 @@
|
|||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
|
while (1) {
|
||||||
int value = getchar();
|
int value = getchar();
|
||||||
printf("You entered '%c'\n", (char)value);
|
printf("You entered '%c'\n", (char)value);
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,12 +7,25 @@
|
|||||||
# directory for more details.
|
# directory for more details.
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
import pexpect
|
||||||
from testrunner import run
|
from testrunner import run
|
||||||
|
|
||||||
|
|
||||||
|
TEST_INPUT = 'O'
|
||||||
|
RETRIES = 5
|
||||||
|
TIMEOUT = 3
|
||||||
|
|
||||||
|
|
||||||
def testfunc(child):
|
def testfunc(child):
|
||||||
child.sendline('O')
|
expected_output = 'You entered \'{}\''.format(TEST_INPUT)
|
||||||
child.expect_exact('You entered \'O\'')
|
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__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user