esp_http_client_test.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import re
  2. import os
  3. import sys
  4. try:
  5. import IDF
  6. except ImportError:
  7. # this is a test case write with tiny-test-fw.
  8. # to run test cases outside tiny-test-fw,
  9. # we need to set environment variable `TEST_FW_PATH`,
  10. # then get and insert `TEST_FW_PATH` to sys path before import FW module
  11. test_fw_path = os.getenv("TEST_FW_PATH")
  12. if test_fw_path and test_fw_path not in sys.path:
  13. sys.path.insert(0, test_fw_path)
  14. import IDF
  15. @IDF.idf_example_test(env_tag="Example_WIFI", ignore=True)
  16. def test_examples_protocol_esp_http_client(env, extra_data):
  17. """
  18. steps: |
  19. 1. join AP
  20. 2. Send HTTP request to httpbin.org
  21. """
  22. dut1 = env.get_dut("esp_http_client", "examples/protocols/esp_http_client")
  23. # check and log bin size
  24. binary_file = os.path.join(dut1.app.binary_path, "esp-http-client-example.bin")
  25. bin_size = os.path.getsize(binary_file)
  26. IDF.log_performance("esp_http_client_bin_size", "{}KB".format(bin_size // 1024))
  27. IDF.check_performance("esp_http_client_bin_size", bin_size // 1024)
  28. # start test
  29. dut1.start_app()
  30. dut1.expect("Connected to AP, begin http example", timeout=30)
  31. dut1.expect(re.compile(r"HTTP GET Status = 200, content_length = (\d)"))
  32. dut1.expect(re.compile(r"HTTP POST Status = 200, content_length = (\d)"))
  33. dut1.expect(re.compile(r"HTTP PUT Status = 200, content_length = (\d)"))
  34. dut1.expect(re.compile(r"HTTP PATCH Status = 200, content_length = (\d)"))
  35. dut1.expect(re.compile(r"HTTP DELETE Status = 200, content_length = (\d)"))
  36. dut1.expect(re.compile(r"HTTP HEAD Status = 200, content_length = (\d)"))
  37. dut1.expect(re.compile(r"HTTP Basic Auth Status = 200, content_length = (\d)"))
  38. dut1.expect(re.compile(r"HTTP Basic Auth redirect Status = 200, content_length = (\d)"))
  39. dut1.expect(re.compile(r"HTTP Digest Auth Status = 200, content_length = (\d)"))
  40. dut1.expect(re.compile(r"HTTP Relative path redirect Status = 200, content_length = (\d)"))
  41. dut1.expect(re.compile(r"HTTP Absolute path redirect Status = 200, content_length = (\d)"))
  42. dut1.expect(re.compile(r"HTTPS Status = 200, content_length = (\d)"))
  43. dut1.expect(re.compile(r"HTTPS Status = 200, content_length = (\d)"))
  44. dut1.expect(re.compile(r"HTTP redirect to HTTPS Status = 200, content_length = (\d)"), timeout=10)
  45. dut1.expect(re.compile(r"HTTP chunk encoding Status = 200, content_length = -1"))
  46. dut1.expect(re.compile(r"HTTP Stream reader Status = 200, content_length = (\d)"))
  47. dut1.expect("Finish http example")
  48. if __name__ == '__main__':
  49. test_examples_protocol_esp_http_client()