example_test.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/usr/bin/env python
  2. #
  3. # SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
  4. # SPDX-License-Identifier: Apache-2.0
  5. import http.client
  6. import os
  7. import tiny_test_fw
  8. import ttfw_idf
  9. from tiny_test_fw import Utility
  10. HTTP_OK = 200
  11. TEST_SERVER = 'http2.golang.org'
  12. def is_test_server_available(): # type: () -> bool
  13. # 443 - default https port
  14. conn = http.client.HTTPSConnection(TEST_SERVER, 443, timeout=10)
  15. conn.request('GET', '/')
  16. resp = conn.getresponse()
  17. conn.close()
  18. if resp.status == HTTP_OK:
  19. return True
  20. return False
  21. # Disabling the Test in CI as the leaf certificate of http2.golang.org is expired from 8 July.
  22. # There is no timeline when the cert will be updated.
  23. # Disabling this test till an alternative is found for testing the http2 support.
  24. @ttfw_idf.idf_example_test(env_tag='Example_EthKitV1', ignore=True)
  25. def test_examples_protocol_http2_request(env, extra_data): # type: (tiny_test_fw.Env.Env, None) -> None # pylint: disable=unused-argument
  26. """
  27. steps: |
  28. 1. join AP
  29. 2. connect to http2.golang.org
  30. 3. send http2 request
  31. 4. send http2 put response
  32. """
  33. dut1 = env.get_dut('http2_request', 'examples/protocols/http2_request', dut_class=ttfw_idf.ESP32DUT)
  34. # check and log bin size
  35. binary_file = os.path.join(dut1.app.binary_path, 'http2_request.bin')
  36. bin_size = os.path.getsize(binary_file)
  37. ttfw_idf.log_performance('http2_request_bin_size', '{}KB'.format(bin_size // 1024))
  38. # start the test
  39. # check if test server is avilable
  40. test_server_available = is_test_server_available()
  41. # Skip the test if the server test server (http2.golang.org) is not available at the moment.
  42. if test_server_available:
  43. dut1.start_app()
  44. # check for connection
  45. dut1.expect('Connection done', timeout=30)
  46. # check for echo response
  47. dut1.expect('[echo-response] HELLO WORLD', timeout=30)
  48. dut1.expect('[echo-response] Frame fully received')
  49. dut1.expect('[echo-response] Stream Closed')
  50. # check for get response
  51. dut1.expect('[get-response] Frame fully received')
  52. else:
  53. Utility.console_log('test server \"{0}\" is not available at the moment.\nSkipping the test with status = success.'.format(TEST_SERVER))
  54. if __name__ == '__main__':
  55. test_examples_protocol_http2_request() # pylint: disable=no-value-for-parameter