2020-04-17 09:51:00 +00:00
|
|
|
from __future__ import unicode_literals
|
2021-01-26 02:49:01 +00:00
|
|
|
|
2020-04-17 09:51:00 +00:00
|
|
|
import os
|
2020-06-30 11:32:22 +00:00
|
|
|
import time
|
|
|
|
|
2020-04-17 09:51:00 +00:00
|
|
|
import ttfw_idf
|
2021-01-26 02:49:01 +00:00
|
|
|
from ttfw_idf import Utility
|
2020-04-17 09:51:00 +00:00
|
|
|
|
|
|
|
|
2021-01-26 02:49:01 +00:00
|
|
|
@ttfw_idf.idf_example_test(env_tag='test_jtag_arm')
|
2020-04-17 09:51:00 +00:00
|
|
|
def test_examples_gcov(env, extra_data):
|
|
|
|
|
|
|
|
rel_project_path = os.path.join('examples', 'system', 'gcov')
|
|
|
|
dut = env.get_dut('gcov', rel_project_path)
|
|
|
|
idf_path = dut.app.get_sdk_path()
|
|
|
|
proj_path = os.path.join(idf_path, rel_project_path)
|
2020-05-19 12:27:31 +00:00
|
|
|
openocd_cmd_log = os.path.join(proj_path, 'openocd_cmd.log')
|
|
|
|
|
|
|
|
with ttfw_idf.OCDBackend(os.path.join(proj_path, 'openocd.log'), dut.app.target) as oocd:
|
|
|
|
dut.start_app()
|
|
|
|
|
|
|
|
def expect_counter_output(loop, timeout=10):
|
|
|
|
dut.expect_all('blink_dummy_func: Counter = {}'.format(loop),
|
|
|
|
'some_dummy_func: Counter = {}'.format(loop * 2),
|
|
|
|
timeout=timeout)
|
|
|
|
|
|
|
|
expect_counter_output(0, timeout=20)
|
|
|
|
dut.expect('Ready to dump GCOV data...', timeout=5)
|
|
|
|
|
2020-06-30 11:32:22 +00:00
|
|
|
def dump_coverage(cmd):
|
2020-05-19 12:27:31 +00:00
|
|
|
try:
|
2020-06-30 11:32:22 +00:00
|
|
|
response = oocd.cmd_exec(cmd)
|
2020-05-19 12:27:31 +00:00
|
|
|
with open(openocd_cmd_log, 'a') as f:
|
|
|
|
f.write(response)
|
|
|
|
|
|
|
|
assert all(x in response for x in ['Targets connected.',
|
|
|
|
'gcov_example_main.c.gcda',
|
|
|
|
'gcov_example_func.c.gcda',
|
|
|
|
'some_funcs.c.gcda',
|
|
|
|
'Targets disconnected.',
|
|
|
|
])
|
|
|
|
|
|
|
|
except AssertionError:
|
|
|
|
# Print what is happening with DUT. Limit the size if it is in loop and generating output.
|
|
|
|
Utility.console_log(dut.read(size=1000))
|
|
|
|
raise
|
|
|
|
|
2020-06-30 11:32:22 +00:00
|
|
|
# Test two hard-coded dumps
|
|
|
|
dump_coverage('esp gcov dump')
|
2020-05-19 12:27:31 +00:00
|
|
|
dut.expect('GCOV data have been dumped.', timeout=5)
|
|
|
|
expect_counter_output(1)
|
|
|
|
dut.expect('Ready to dump GCOV data...', timeout=5)
|
2020-06-30 11:32:22 +00:00
|
|
|
dump_coverage('esp gcov dump')
|
2020-05-19 12:27:31 +00:00
|
|
|
dut.expect('GCOV data have been dumped.', timeout=5)
|
|
|
|
|
|
|
|
for i in range(2, 6):
|
|
|
|
expect_counter_output(i)
|
2020-04-17 09:51:00 +00:00
|
|
|
|
2020-06-30 11:32:22 +00:00
|
|
|
for _ in range(3):
|
|
|
|
time.sleep(1)
|
|
|
|
# Test instant run-time dump
|
|
|
|
dump_coverage('esp gcov')
|
|
|
|
|
2020-04-17 09:51:00 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
test_examples_gcov()
|