Verify the main app mostly sleeps
This validates that the main watch app spends at least 99.5% of it's time sleeping in the first 10 seconds.
This commit is contained in:
@@ -102,6 +102,57 @@ def context_factory():
|
||||
return create_context
|
||||
|
||||
|
||||
def measure_frequency(
|
||||
period: float,
|
||||
pin_name: str,
|
||||
executable: str = "sigrok-cli",
|
||||
driver_name: str = "fx2lafw",
|
||||
trigger: str = "r",
|
||||
):
|
||||
|
||||
cmd = [
|
||||
executable,
|
||||
"-C",
|
||||
pin_name,
|
||||
"-d",
|
||||
driver_name,
|
||||
"-c",
|
||||
"samplerate=1M",
|
||||
"--time",
|
||||
"{}ms".format(int(period * 1000)),
|
||||
"-t",
|
||||
"{}={}".format(pin_name, trigger),
|
||||
"-P",
|
||||
"timing:data={}".format(pin_name),
|
||||
"-A",
|
||||
"timing=time",
|
||||
]
|
||||
|
||||
print("sigrok-cli cmd {}".format(cmd))
|
||||
proc = subprocess.run(cmd, capture_output=True, check=True)
|
||||
lines = proc.stdout.decode("utf-8").split("\n")
|
||||
reg = re.compile(".*:\\W(\\d+.\\d+)\\W(\\w+)")
|
||||
periods = []
|
||||
for line in lines:
|
||||
m = reg.match(line)
|
||||
if not m:
|
||||
break
|
||||
num = float(m.groups(1)[0])
|
||||
units = m.groups(1)[1]
|
||||
if units == "s":
|
||||
periods.append(num)
|
||||
elif units == "ms":
|
||||
periods.append(num / 1000)
|
||||
elif units == "μs":
|
||||
periods.append(num / 1000000)
|
||||
else:
|
||||
assert False, "Couldnt find units in line '{}', units were '{}'".format(
|
||||
line, units
|
||||
)
|
||||
|
||||
return periods[::2], periods[1:][::2]
|
||||
|
||||
|
||||
def test_meta_pass(context_factory, logger):
|
||||
serial_dev, jlink = context_factory("Test/Apps/pass.bin")
|
||||
text = serial_dev.read_until(TEST_PASS_TEXT)
|
||||
@@ -252,6 +303,49 @@ def test_wakeup_irq(context_factory, logger):
|
||||
assert abs(delta) < 1000
|
||||
|
||||
|
||||
def test_lptim(context_factory, logger):
|
||||
serial_dev, jlink = context_factory("Test/Apps/lptim.bin")
|
||||
state0_periods, state1_periods = measure_frequency(1, "D0")
|
||||
num_periods = min(len(state0_periods), len(state1_periods))
|
||||
periods = [state0_periods[i] + state1_periods[i] for i in range(num_periods)]
|
||||
freqs = list(map(lambda x: 1 / x, periods))
|
||||
assert (
|
||||
periods
|
||||
), "No LPTIM state changes detected, is the right analyzer being used? Is the device connected?"
|
||||
|
||||
min_f = min(freqs)
|
||||
max_f = max(freqs)
|
||||
avg_f = sum(freqs) / len(freqs)
|
||||
print("min_f:{}, max_f:{}, avg_f:{}".format(min_f, max_f, avg_f))
|
||||
assert abs(avg_f - 50) < 0.25
|
||||
assert min_f > 49
|
||||
assert max_f < 51
|
||||
|
||||
|
||||
def test_app_lowpower(context_factory, logger):
|
||||
serial_dev, jlink = context_factory("Application/main.bin", leave_halted=True)
|
||||
jlink.reset(halt=False)
|
||||
state0_periods, state1_periods = measure_frequency(10, "D1")
|
||||
num_periods = min(len(state0_periods), len(state1_periods))
|
||||
periods = [state0_periods[i] + state1_periods[i] for i in range(num_periods)]
|
||||
freqs = list(map(lambda x: 1 / x, periods))
|
||||
assert (
|
||||
periods
|
||||
), "No debug pin state changes detected, is the right analyzer being used? Is the device connected?"
|
||||
|
||||
min_f = min(freqs)
|
||||
max_f = max(freqs)
|
||||
avg_f = sum(freqs) / len(freqs)
|
||||
pct_sleep = sum(state1_periods) * 100 / sum(state0_periods + state1_periods)
|
||||
print(
|
||||
"min_f:{}, max_f:{}, avg_f:{}, pct_sleep:{}".format(
|
||||
min_f, max_f, avg_f, pct_sleep
|
||||
)
|
||||
)
|
||||
assert len(periods) >= 5
|
||||
assert pct_sleep > 99.95, "Spent too much time awake"
|
||||
|
||||
|
||||
def test_stop(context_factory, logger):
|
||||
serial_dev, jlink = context_factory("Test/Apps/stop.bin")
|
||||
serial_dev.timeout = 70
|
||||
@@ -277,72 +371,6 @@ def test_stop(context_factory, logger):
|
||||
assert abs(delta) < 1000
|
||||
|
||||
|
||||
"sigrok-cli -C D3 -d fx2lafw -c samplerate=1M --time 1s -P timing:data=D3"
|
||||
|
||||
|
||||
def measure_frequency(
|
||||
period: float,
|
||||
pin_name: str,
|
||||
executable: str = "sigrok-cli",
|
||||
driver_name: str = "fx2lafw",
|
||||
):
|
||||
|
||||
cmd = [
|
||||
executable,
|
||||
"-C",
|
||||
pin_name,
|
||||
"-d",
|
||||
driver_name,
|
||||
"-c",
|
||||
"samplerate=1M",
|
||||
"--time",
|
||||
"{}ms".format(int(period * 1000)),
|
||||
"-P",
|
||||
"timing:data={}".format(pin_name),
|
||||
"-A",
|
||||
"timing=time",
|
||||
]
|
||||
|
||||
print("sigrok-cli cmd {}".format(cmd))
|
||||
proc = subprocess.run(cmd, capture_output=True, check=True)
|
||||
lines = proc.stdout.decode("utf-8").split("\n")
|
||||
reg = re.compile(".*:\\W(\\d+.\\d+)\\W(\\w+)")
|
||||
periods = []
|
||||
for line in lines:
|
||||
m = reg.match(line)
|
||||
if not m:
|
||||
break
|
||||
num = float(m.groups(1)[0])
|
||||
units = m.groups(1)[1]
|
||||
if units == "ms":
|
||||
periods.append(num / 1000)
|
||||
elif units == "μs":
|
||||
periods.append(num / 1000000)
|
||||
else:
|
||||
assert False
|
||||
|
||||
return periods[::2], periods[1:][::2]
|
||||
|
||||
|
||||
def test_lptim(context_factory, logger):
|
||||
serial_dev, jlink = context_factory("Test/Apps/lptim.bin")
|
||||
state0_periods, state1_periods = measure_frequency(1, "D0")
|
||||
num_periods = min(len(state0_periods), len(state1_periods))
|
||||
periods = [state0_periods[i] + state1_periods[i] for i in range(num_periods)]
|
||||
freqs = list(map(lambda x: 1 / x, periods))
|
||||
assert (
|
||||
periods
|
||||
), "No LPTIM changes detected, is the right analyzer being used? Is the device connected?"
|
||||
|
||||
min_f = min(freqs)
|
||||
max_f = max(freqs)
|
||||
avg_f = sum(freqs) / len(freqs)
|
||||
print("min:{}, max:{}, avg:{}".format(min_f, max_f, avg_f))
|
||||
assert abs(avg_f - 50) < 0.25
|
||||
assert min_f > 49
|
||||
assert max_f < 51
|
||||
|
||||
|
||||
def main():
|
||||
pytest.main(sys.argv)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user