tests: update posix_time tests for running with pexpect script
This commit is contained in:
parent
0a0bb86f4a
commit
f3f5489b4e
@ -4,3 +4,6 @@ include ../Makefile.tests_common
|
|||||||
USEMODULE += posix_time
|
USEMODULE += posix_time
|
||||||
|
|
||||||
include $(RIOTBASE)/Makefile.include
|
include $(RIOTBASE)/Makefile.include
|
||||||
|
|
||||||
|
test:
|
||||||
|
./tests/01-run.py
|
||||||
|
|||||||
10
tests/posix_time/README.md
Normal file
10
tests/posix_time/README.md
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
# posix_time test application
|
||||||
|
|
||||||
|
This test tests POSIX' `sleep()` and `usleep()`.
|
||||||
|
The test script also checks the sanity of the timings by comparing the overall
|
||||||
|
run time of the test with the host's time with an expected jitter of 15%.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
```
|
||||||
|
make flash test
|
||||||
|
```
|
||||||
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2014 Freie Universität Berlin
|
* Copyright (C) 2014-17 Freie Universität Berlin
|
||||||
*
|
*
|
||||||
* This file is subject to the terms and conditions of the GNU Lesser
|
* This file is subject to the terms and conditions of the GNU Lesser
|
||||||
* General Public License v2.1. See the file LICENSE in the top level
|
* General Public License v2.1. See the file LICENSE in the top level
|
||||||
@ -14,6 +14,7 @@
|
|||||||
* @brief Posix sleep test application
|
* @brief Posix sleep test application
|
||||||
*
|
*
|
||||||
* @author Christian Mehlis <mehlis@inf.fu-berlin.de>
|
* @author Christian Mehlis <mehlis@inf.fu-berlin.de>
|
||||||
|
* @author Martine Lenders <m.lenders@fu-berlin.de>
|
||||||
*
|
*
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
@ -23,22 +24,21 @@
|
|||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
puts("usleep 1 x 1000*1000");
|
puts("Please hit any key and then ENTER to continue");
|
||||||
for (int i = 0; i < 10; i++) {
|
getchar();
|
||||||
useconds_t us = i*1000u*1000u;
|
puts("5 x usleep(i++ * 500000)");
|
||||||
printf("calling usleep(%u)\n", (unsigned int) us);
|
for (unsigned i = 0; i < 5; i++) {
|
||||||
|
useconds_t us = i * 500000u;
|
||||||
usleep(us);
|
usleep(us);
|
||||||
puts("wake up");
|
puts("wake up");
|
||||||
}
|
}
|
||||||
|
|
||||||
puts("sleep 1");
|
puts("5 x sleep(i++)");
|
||||||
for (int i = 0; i < 10; i++) {
|
for (unsigned i = 0; i < 5; i++) {
|
||||||
unsigned int s = i;
|
sleep(i);
|
||||||
printf("calling sleep(%u)\n", s);
|
|
||||||
sleep(s);
|
|
||||||
puts("wake up");
|
puts("wake up");
|
||||||
}
|
}
|
||||||
|
|
||||||
puts("done");
|
puts("DONE");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
49
tests/posix_time/tests/01-run.py
Executable file
49
tests/posix_time/tests/01-run.py
Executable file
@ -0,0 +1,49 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# vim:fenc=utf-8
|
||||||
|
|
||||||
|
# Copyright (C) 2017 Freie Universität Berlin
|
||||||
|
#
|
||||||
|
# This file is subject to the terms and conditions of the GNU Lesser
|
||||||
|
# General Public License v2.1. See the file LICENSE in the top level
|
||||||
|
# directory for more details.
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
|
||||||
|
sys.path.append(os.path.join(os.environ['RIOTBASE'], 'dist/tools/testrunner'))
|
||||||
|
import testrunner
|
||||||
|
|
||||||
|
US_PER_SEC = 1000000
|
||||||
|
EXTERNAL_JITTER = 0.15
|
||||||
|
|
||||||
|
class InvalidTimeout(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def testfunc(child):
|
||||||
|
try:
|
||||||
|
child.expect_exact("Please hit any key and then ENTER to continue")
|
||||||
|
child.sendline("a")
|
||||||
|
start_test = time.time()
|
||||||
|
child.expect_exact("5 x usleep(i++ * 500000)")
|
||||||
|
for i in range(5):
|
||||||
|
child.expect_exact("wake up")
|
||||||
|
child.expect_exact("5 x sleep(i++)")
|
||||||
|
for i in range(5):
|
||||||
|
child.expect_exact("wake up")
|
||||||
|
child.expect_exact("DONE")
|
||||||
|
testtime = (time.time() - start_test) * US_PER_SEC
|
||||||
|
exp = sum(i * 500000 for i in range(5)) + \
|
||||||
|
sum(i * US_PER_SEC for i in range(5))
|
||||||
|
lower_bound = exp - (exp * EXTERNAL_JITTER)
|
||||||
|
upper_bound = exp + (exp * EXTERNAL_JITTER)
|
||||||
|
if not (lower_bound < testtime < upper_bound):
|
||||||
|
raise InvalidTimeout("Host timer measured %d us (client measured %d us)" % \
|
||||||
|
(testtime, exp));
|
||||||
|
except InvalidTimeout as e:
|
||||||
|
print(e)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
sys.exit(testrunner.run(testfunc, echo=True))
|
||||||
Loading…
x
Reference in New Issue
Block a user