example_test.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. from __future__ import unicode_literals
  2. from pexpect import TIMEOUT
  3. from ttfw_idf import Utility
  4. import os
  5. import ttfw_idf
  6. @ttfw_idf.idf_example_test(env_tag="test_jtag_arm")
  7. def test_examples_gcov(env, extra_data):
  8. rel_project_path = os.path.join('examples', 'system', 'gcov')
  9. dut = env.get_dut('gcov', rel_project_path)
  10. idf_path = dut.app.get_sdk_path()
  11. proj_path = os.path.join(idf_path, rel_project_path)
  12. with ttfw_idf.OCDProcess(os.path.join(proj_path, 'openocd.log')):
  13. with ttfw_idf.TelnetProcess(os.path.join(proj_path, 'telnet.log')) as telnet_p:
  14. dut.start_app()
  15. def expect_counter_output(loop, timeout=10):
  16. dut.expect_all('blink_dummy_func: Counter = {}'.format(loop),
  17. 'some_dummy_func: Counter = {}'.format(loop * 2),
  18. timeout=timeout)
  19. expect_counter_output(0, timeout=20)
  20. dut.expect('Ready to dump GCOV data...', timeout=5)
  21. def dump_coverage():
  22. try:
  23. telnet_p.pexpect_proc.sendline('esp gcov dump')
  24. telnet_p.pexpect_proc.expect_exact('Targets connected.')
  25. telnet_p.pexpect_proc.expect_exact('gcov_example_main.c.gcda')
  26. telnet_p.pexpect_proc.expect_exact('gcov_example_func.c.gcda')
  27. telnet_p.pexpect_proc.expect_exact('some_funcs.c.gcda')
  28. telnet_p.pexpect_proc.expect_exact('Targets disconnected.')
  29. except TIMEOUT:
  30. # Print what is happening with DUT. Limit the size if it is in loop and generating output.
  31. Utility.console_log(dut.read(size=1000))
  32. raise
  33. dump_coverage()
  34. dut.expect('GCOV data have been dumped.', timeout=5)
  35. expect_counter_output(1)
  36. dut.expect('Ready to dump GCOV data...', timeout=5)
  37. dump_coverage()
  38. dut.expect('GCOV data have been dumped.', timeout=5)
  39. for i in range(2, 6):
  40. expect_counter_output(i)
  41. if __name__ == '__main__':
  42. test_examples_gcov()