example_test.py 2.3 KB

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