blob: 2b7c33060e1610ebdf20fe3f0bc6c73ddd98bc92 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# Copyright 2011 The ChromiumOS Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
#
# Check timers behavior
#
import time
def one_pass(helper):
helper.wait_output("=== Timer calibration ===")
res = helper.wait_output(
"back-to-back get_time : (?P<lat>[0-9]+) us", use_re=True
)["lat"]
minlat = int(res)
helper.trace("get_time latency %d us\n" % minlat)
helper.wait_output("sleep 1s")
t0 = time.time()
second = helper.wait_output(
"done. delay = (?P<second>[0-9]+) us", use_re=True
)["second"]
t1 = time.time()
secondreal = t1 - t0
secondlat = int(second) - 1000000
helper.trace(
"1s timer latency %d us / real time %f s\n" % (secondlat, secondreal)
)
us = {}
for pow2 in range(7):
delay = 1 << (7 - pow2)
us[delay] = helper.wait_output(
"%d us => (?P<us>[0-9]+) us" % delay, use_re=True
)["us"]
helper.wait_output("Done.")
return minlat, secondlat, secondreal
def test(helper):
one_pass(helper)
helper.ec_command("reboot")
helper.wait_output("--- UART initialized")
# get the timing results on the second pass
# to avoid binary translation overhead
minlat, secondlat, secondreal = one_pass(helper)
# check that the timings somewhat make sense
if minlat > 220 or secondlat > 500 or abs(secondreal - 1.0) > 0.200:
helper.fail(
"imprecise timings "
+ "(get_time %d us sleep %d us / real time %.3f s)"
% (minlat, secondlat, secondreal)
)
return True # PASS !
|