example_test.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. from __future__ import unicode_literals
  2. import os
  3. import time
  4. import ttfw_idf
  5. from ttfw_idf import Utility
  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. openocd_cmd_log = os.path.join(proj_path, 'openocd_cmd.log')
  13. with ttfw_idf.OCDBackend(os.path.join(proj_path, 'openocd.log'), dut.app.target) as oocd:
  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(cmd):
  22. try:
  23. response = oocd.cmd_exec(cmd)
  24. with open(openocd_cmd_log, 'a') as f:
  25. f.write(response)
  26. assert all(x in response for x in ['Targets connected.',
  27. 'gcov_example_main.c.gcda',
  28. 'gcov_example_func.c.gcda',
  29. 'some_funcs.c.gcda',
  30. 'Targets disconnected.',
  31. ])
  32. except AssertionError:
  33. # Print what is happening with DUT. Limit the size if it is in loop and generating output.
  34. Utility.console_log(dut.read(size=1000))
  35. raise
  36. # Test two hard-coded dumps
  37. dump_coverage('esp gcov dump')
  38. dut.expect('GCOV data have been dumped.', timeout=5)
  39. expect_counter_output(1)
  40. dut.expect('Ready to dump GCOV data...', timeout=5)
  41. dump_coverage('esp gcov dump')
  42. dut.expect('GCOV data have been dumped.', timeout=5)
  43. for i in range(2, 6):
  44. expect_counter_output(i)
  45. for _ in range(3):
  46. time.sleep(1)
  47. # Test instant run-time dump
  48. dump_coverage('esp gcov')
  49. if __name__ == '__main__':
  50. test_examples_gcov()