tests/periph_timer_periodic: add error tolerance in timings
On a lot of platforms the peripheral timer fires in advance, adding a precision factor of 15% makes the test more reliable
This commit is contained in:
parent
cb87c418f4
commit
ca26a8fe6a
@ -6,19 +6,24 @@
|
|||||||
# 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
|
||||||
# directory for more details.
|
# directory for more details.
|
||||||
|
|
||||||
|
import os
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
from testrunner import run
|
from testrunner import run
|
||||||
|
|
||||||
|
|
||||||
|
PRECISION = float(os.getenv("TEST_PERIPH_TIMER_PERIODIC_PRECISION", "0"))
|
||||||
|
|
||||||
|
|
||||||
def testfunc(child):
|
def testfunc(child):
|
||||||
child.expect_exact('TEST START')
|
child.expect_exact('TEST START')
|
||||||
start = time.time()
|
start = time.time()
|
||||||
child.expect_exact('TEST SUCCEEDED')
|
child.expect_exact('TEST SUCCEEDED')
|
||||||
end = time.time()
|
end = time.time()
|
||||||
# test should run 10 cycles with 25ms each
|
# test should run 10 cycles with 25ms each
|
||||||
assert (end - start) > 0.25
|
elapsed = end - start
|
||||||
assert (end - start) < 0.40
|
assert elapsed > 0.25 * (1 - PRECISION), "=< 0.25s ({})".format(elapsed)
|
||||||
|
assert elapsed < 0.40 * (1 + PRECISION), "=> 0.40s ({})".format(elapsed)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user