mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-17 05:12:57 +01:00
Merge pull request #7940 from miri64/posix/enh/move-time-to-module
posix: move time functions to their own module
This commit is contained in:
commit
1a0f4940fd
@ -434,6 +434,10 @@ ifneq (,$(filter posix_semaphore,$(USEMODULE)))
|
||||
USEMODULE += xtimer
|
||||
endif
|
||||
|
||||
ifneq (,$(filter posix_time,$(USEMODULE)))
|
||||
USEMODULE += xtimer
|
||||
endif
|
||||
|
||||
ifneq (,$(filter lwip_sixlowpan,$(USEMODULE)))
|
||||
USEMODULE += lwip_ipv6_autoconfig
|
||||
endif
|
||||
|
@ -22,6 +22,7 @@ USEMODULE += gnrc_ipv6_default
|
||||
USEMODULE += gnrc_udp
|
||||
USEMODULE += gnrc_sock_udp
|
||||
USEMODULE += posix_sockets
|
||||
USEMODULE += posix_time
|
||||
# Add also the shell, some shell commands
|
||||
USEMODULE += shell
|
||||
USEMODULE += shell_commands
|
||||
|
3
pkg/umorse/Makefile.dep
Normal file
3
pkg/umorse/Makefile.dep
Normal file
@ -0,0 +1,3 @@
|
||||
ifneq (,$(filter umorse,$(USEPKG)))
|
||||
USEMODULE += posix_time
|
||||
endif
|
@ -7,6 +7,9 @@ endif
|
||||
ifneq (,$(filter posix_sockets,$(USEMODULE)))
|
||||
DIRS += posix/sockets
|
||||
endif
|
||||
ifneq (,$(filter posix_time,$(USEMODULE)))
|
||||
DIRS += posix/time
|
||||
endif
|
||||
ifneq (,$(filter pthread,$(USEMODULE)))
|
||||
DIRS += posix/pthread
|
||||
endif
|
||||
|
3
sys/posix/time/Makefile
Normal file
3
sys/posix/time/Makefile
Normal file
@ -0,0 +1,3 @@
|
||||
MODULE = posix_time
|
||||
|
||||
include $(RIOTBASE)/Makefile.base
|
@ -1,6 +0,0 @@
|
||||
APPLICATION = posix_sleep
|
||||
include ../Makefile.tests_common
|
||||
|
||||
USEMODULE += posix
|
||||
|
||||
include $(RIOTBASE)/Makefile.include
|
9
tests/posix_time/Makefile
Normal file
9
tests/posix_time/Makefile
Normal file
@ -0,0 +1,9 @@
|
||||
APPLICATION = posix_time
|
||||
include ../Makefile.tests_common
|
||||
|
||||
USEMODULE += posix_time
|
||||
|
||||
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
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
@ -14,6 +14,7 @@
|
||||
* @brief Posix sleep test application
|
||||
*
|
||||
* @author Christian Mehlis <mehlis@inf.fu-berlin.de>
|
||||
* @author Martine Lenders <m.lenders@fu-berlin.de>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
@ -23,22 +24,21 @@
|
||||
|
||||
int main(void)
|
||||
{
|
||||
puts("usleep 1 x 1000*1000");
|
||||
for (int i = 0; i < 10; i++) {
|
||||
useconds_t us = i*1000u*1000u;
|
||||
printf("calling usleep(%u)\n", (unsigned int) us);
|
||||
puts("Please hit any key and then ENTER to continue");
|
||||
getchar();
|
||||
puts("5 x usleep(i++ * 500000)");
|
||||
for (unsigned i = 0; i < 5; i++) {
|
||||
useconds_t us = i * 500000u;
|
||||
usleep(us);
|
||||
puts("wake up");
|
||||
}
|
||||
|
||||
puts("sleep 1");
|
||||
for (int i = 0; i < 10; i++) {
|
||||
unsigned int s = i;
|
||||
printf("calling sleep(%u)\n", s);
|
||||
sleep(s);
|
||||
puts("5 x sleep(i++)");
|
||||
for (unsigned i = 0; i < 5; i++) {
|
||||
sleep(i);
|
||||
puts("wake up");
|
||||
}
|
||||
|
||||
puts("done");
|
||||
puts("DONE");
|
||||
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…
Reference in New Issue
Block a user