example_test.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. from __future__ import unicode_literals
  2. import os
  3. import re
  4. import sys
  5. import ttfw_idf
  6. @ttfw_idf.idf_example_test(env_tag='Example_WIFI')
  7. def test_examples_esp_local_ctrl(env, extra_data):
  8. rel_project_path = os.path.join('examples', 'protocols', 'esp_local_ctrl')
  9. dut = env.get_dut('esp_local_ctrl', rel_project_path)
  10. idf_path = dut.app.get_sdk_path()
  11. dut.start_app()
  12. dut_ip = dut.expect(re.compile(r'esp_netif_handlers: sta ip: (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})'))[0]
  13. dut.expect('esp_https_server: Starting server')
  14. dut.expect('esp_https_server: Server listening on port 443')
  15. dut.expect('control: esp_local_ctrl service started with name : my_esp_ctrl_device')
  16. def dut_expect_read():
  17. dut.expect('control: Reading property : timestamp (us)')
  18. dut.expect('control: Reading property : property1')
  19. dut.expect('control: Reading property : property2')
  20. dut.expect('control: Reading property : property3')
  21. # Running mDNS services in docker is not a trivial task. Therefore, the script won't connect to the host name but
  22. # to IP address. However, the certificates were generated for the host name and will be rejected.
  23. cmd = ' '.join([sys.executable, os.path.join(idf_path, rel_project_path, 'scripts/esp_local_ctrl.py'),
  24. '--sec_ver 0',
  25. '--name', dut_ip,
  26. '--dont-check-hostname']) # don't reject the certificate because of the hostname
  27. esp_local_ctrl_log = os.path.join(idf_path, rel_project_path, 'esp_local_ctrl.log')
  28. with ttfw_idf.CustomProcess(cmd, esp_local_ctrl_log) as ctrl_py:
  29. def expect_properties(prop1, prop3):
  30. dut_expect_read()
  31. ctrl_py.pexpect_proc.expect_exact('==== Available Properties ====')
  32. ctrl_py.pexpect_proc.expect(re.compile(r'S.N. Name\s+Type\s+Flags\s+Value'))
  33. ctrl_py.pexpect_proc.expect(re.compile(r'\[ 1\] timestamp \(us\)\s+TIME\(us\)\s+Read-Only\s+\d+'))
  34. ctrl_py.pexpect_proc.expect(re.compile(r'\[ 2\] property1\s+INT32\s+{}'.format(prop1)))
  35. ctrl_py.pexpect_proc.expect(re.compile(r'\[ 3\] property2\s+BOOLEAN\s+Read-Only\s+(True)|(False)'))
  36. ctrl_py.pexpect_proc.expect(re.compile(r'\[ 4\] property3\s+STRING\s+{}'.format(prop3)))
  37. ctrl_py.pexpect_proc.expect_exact('Select properties to set (0 to re-read, \'q\' to quit) :')
  38. property1 = 123456789
  39. property3 = ''
  40. ctrl_py.pexpect_proc.expect_exact('Connecting to {}'.format(dut_ip))
  41. dut.expect('esp_https_server: performing session handshake', timeout=60)
  42. expect_properties(property1, property3)
  43. ctrl_py.pexpect_proc.sendline('1')
  44. ctrl_py.pexpect_proc.expect_exact('Enter value to set for property (timestamp (us)) :')
  45. ctrl_py.pexpect_proc.sendline('2')
  46. ctrl_py.pexpect_proc.expect_exact('Failed to set values!')
  47. dut.expect('control: timestamp (us) is read-only')
  48. expect_properties(property1, property3)
  49. property1 = 638
  50. ctrl_py.pexpect_proc.sendline('2')
  51. ctrl_py.pexpect_proc.expect_exact('Enter value to set for property (property1) :')
  52. ctrl_py.pexpect_proc.sendline(str(property1))
  53. dut.expect('control: Setting property1 value to {}'.format(property1))
  54. expect_properties(property1, property3)
  55. property3 = 'test'
  56. ctrl_py.pexpect_proc.sendline('4')
  57. ctrl_py.pexpect_proc.expect_exact('Enter value to set for property (property3) :')
  58. ctrl_py.pexpect_proc.sendline(property3)
  59. dut.expect('control: Setting property3 value to {}'.format(property3))
  60. expect_properties(property1, property3)
  61. ctrl_py.pexpect_proc.sendline('q')
  62. ctrl_py.pexpect_proc.expect_exact('Quitting...')
  63. if __name__ == '__main__':
  64. test_examples_esp_local_ctrl()