esp_http_client_test.py 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import os
  2. import re
  3. import ttfw_idf
  4. @ttfw_idf.idf_example_test(env_tag='Example_EthKitV1')
  5. def test_examples_protocol_esp_http_client(env, extra_data):
  6. """
  7. steps: |
  8. 1. join AP
  9. 2. Send HTTP request to httpbin.org
  10. """
  11. dut1 = env.get_dut('esp_http_client', 'examples/protocols/esp_http_client', dut_class=ttfw_idf.ESP32DUT)
  12. # check and log bin size
  13. binary_file = os.path.join(dut1.app.binary_path, 'esp-http-client-example.bin')
  14. bin_size = os.path.getsize(binary_file)
  15. ttfw_idf.log_performance('esp_http_client_bin_size', '{}KB'.format(bin_size // 1024))
  16. # start test
  17. dut1.start_app()
  18. dut1.expect('Connected to AP, begin http example', timeout=30)
  19. dut1.expect(re.compile(r'HTTP GET Status = 200, content_length = (\d)'))
  20. dut1.expect(re.compile(r'HTTP POST Status = 200, content_length = (\d)'))
  21. dut1.expect(re.compile(r'HTTP PUT Status = 200, content_length = (\d)'))
  22. dut1.expect(re.compile(r'HTTP PATCH Status = 200, content_length = (\d)'))
  23. dut1.expect(re.compile(r'HTTP DELETE Status = 200, content_length = (\d)'))
  24. dut1.expect(re.compile(r'HTTP HEAD Status = 200, content_length = (\d)'))
  25. dut1.expect(re.compile(r'HTTP Basic Auth Status = 200, content_length = (\d)'))
  26. dut1.expect(re.compile(r'HTTP Basic Auth redirect Status = 200, content_length = (\d)'))
  27. dut1.expect(re.compile(r'HTTP Digest Auth Status = 200, content_length = (\d)'))
  28. dut1.expect(re.compile(r'HTTPS Status = 200, content_length = (\d)'))
  29. dut1.expect(re.compile(r'HTTPS Status = 200, content_length = (\d)'))
  30. dut1.expect(re.compile(r'HTTP chunk encoding Status = 200, content_length = (-?\d)'))
  31. # content-len for chunked encoding is typically -1, could be a positive length in some cases
  32. dut1.expect(re.compile(r'HTTP Stream reader Status = 200, content_length = (\d)'))
  33. dut1.expect(re.compile(r'Last esp error code: 0x8001'))
  34. dut1.expect('Finish http example')
  35. # test mbedtls dynamic resource
  36. dut1 = env.get_dut('esp_http_client', 'examples/protocols/esp_http_client', dut_class=ttfw_idf.ESP32DUT, app_config_name='ssldyn')
  37. # check and log bin size
  38. binary_file = os.path.join(dut1.app.binary_path, 'esp-http-client-example.bin')
  39. bin_size = os.path.getsize(binary_file)
  40. ttfw_idf.log_performance('esp_http_client_bin_size', '{}KB'.format(bin_size // 1024))
  41. # start test
  42. dut1.start_app()
  43. dut1.expect('Connected to AP, begin http example', timeout=30)
  44. dut1.expect(re.compile(r'HTTP GET Status = 200, content_length = (\d)'))
  45. dut1.expect(re.compile(r'HTTP POST Status = 200, content_length = (\d)'))
  46. dut1.expect(re.compile(r'HTTP PUT Status = 200, content_length = (\d)'))
  47. dut1.expect(re.compile(r'HTTP PATCH Status = 200, content_length = (\d)'))
  48. dut1.expect(re.compile(r'HTTP DELETE Status = 200, content_length = (\d)'))
  49. dut1.expect(re.compile(r'HTTP HEAD Status = 200, content_length = (\d)'))
  50. dut1.expect(re.compile(r'HTTP Basic Auth Status = 200, content_length = (\d)'))
  51. dut1.expect(re.compile(r'HTTP Basic Auth redirect Status = 200, content_length = (\d)'))
  52. dut1.expect(re.compile(r'HTTP Digest Auth Status = 200, content_length = (\d)'))
  53. dut1.expect(re.compile(r'HTTPS Status = 200, content_length = (\d)'))
  54. dut1.expect(re.compile(r'HTTPS Status = 200, content_length = (\d)'))
  55. dut1.expect(re.compile(r'HTTP chunk encoding Status = 200, content_length = (-?\d)'))
  56. # content-len for chunked encoding is typically -1, could be a positive length in some cases
  57. dut1.expect(re.compile(r'HTTP Stream reader Status = 200, content_length = (\d)'))
  58. dut1.expect(re.compile(r'Last esp error code: 0x8001'))
  59. dut1.expect('Finish http example')
  60. if __name__ == '__main__':
  61. test_examples_protocol_esp_http_client()