example_test.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #!/usr/bin/env python
  2. #
  3. # Copyright 2021 Espressif Systems (Shanghai) CO LTD
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. import http.client
  17. import os
  18. import tiny_test_fw
  19. import ttfw_idf
  20. from tiny_test_fw import Utility
  21. HTTP_OK = 200
  22. TEST_SERVER = 'http2.golang.org'
  23. def is_test_server_available(): # type: () -> bool
  24. # 443 - default https port
  25. conn = http.client.HTTPSConnection(TEST_SERVER, 443, timeout=10)
  26. conn.request('GET', '/')
  27. resp = conn.getresponse()
  28. conn.close()
  29. if resp.status == HTTP_OK:
  30. return True
  31. return False
  32. # Disabling the Test in CI as the leaf certificate of http2.golang.org is expired from 8 July.
  33. # There is no timeline when the cert will be updated.
  34. # Disabling this test till an alternative is found for testing the http2 support.
  35. @ttfw_idf.idf_example_test(env_tag='Example_EthKitV1', ignore=True)
  36. def test_examples_protocol_http2_request(env, extra_data): # type: (tiny_test_fw.Env.Env, None) -> None # pylint: disable=unused-argument
  37. """
  38. steps: |
  39. 1. join AP
  40. 2. connect to http2.golang.org
  41. 3. send http2 request
  42. 4. send http2 put response
  43. """
  44. dut1 = env.get_dut('http2_request', 'examples/protocols/http2_request', dut_class=ttfw_idf.ESP32DUT)
  45. # check and log bin size
  46. binary_file = os.path.join(dut1.app.binary_path, 'http2-request.bin')
  47. bin_size = os.path.getsize(binary_file)
  48. ttfw_idf.log_performance('http2_request_bin_size', '{}KB'.format(bin_size // 1024))
  49. # start the test
  50. # check if test server is avilable
  51. test_server_available = is_test_server_available()
  52. # Skip the test if the server test server (http2.golang.org) is not available at the moment.
  53. if test_server_available:
  54. dut1.start_app()
  55. # check for connection
  56. dut1.expect('Connection done', timeout=30)
  57. # check for echo response
  58. dut1.expect('[echo-response] HELLO WORLD', timeout=30)
  59. dut1.expect('[echo-response] Frame fully received')
  60. dut1.expect('[echo-response] Stream Closed')
  61. # check for get response
  62. dut1.expect('[get-response] Frame fully received')
  63. else:
  64. Utility.console_log('test server \"{0}\" is not available at the moment.\nSkipping the test with status = success.'.format(TEST_SERVER))
  65. if __name__ == '__main__':
  66. test_examples_protocol_http2_request() # pylint: disable=no-value-for-parameter