example_test.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. @ttfw_idf.idf_example_test(env_tag='Example_EthKitV1')
  33. def test_examples_protocol_http2_request(env, extra_data): # type: (tiny_test_fw.Env.Env, None) -> None # pylint: disable=unused-argument
  34. """
  35. steps: |
  36. 1. join AP
  37. 2. connect to http2.golang.org
  38. 3. send http2 request
  39. 4. send http2 put response
  40. """
  41. dut1 = env.get_dut('http2_request', 'examples/protocols/http2_request', dut_class=ttfw_idf.ESP32DUT)
  42. # check and log bin size
  43. binary_file = os.path.join(dut1.app.binary_path, 'http2-request.bin')
  44. bin_size = os.path.getsize(binary_file)
  45. ttfw_idf.log_performance('http2_request_bin_size', '{}KB'.format(bin_size // 1024))
  46. # start the test
  47. # check if test server is avilable
  48. test_server_available = is_test_server_available()
  49. # Skip the test if the server test server (http2.golang.org) is not available at the moment.
  50. if test_server_available:
  51. dut1.start_app()
  52. # check for connection
  53. dut1.expect('Connection done', timeout=30)
  54. # check for echo response
  55. dut1.expect('[echo-response] HELLO WORLD', timeout=30)
  56. dut1.expect('[echo-response] Frame fully received')
  57. dut1.expect('[echo-response] Stream Closed')
  58. # check for get response
  59. dut1.expect('[get-response] Frame fully received')
  60. else:
  61. Utility.console_log('test server \"{0}\" is not available at the moment.\nSkipping the test with status = success.'.format(TEST_SERVER))
  62. if __name__ == '__main__':
  63. test_examples_protocol_http2_request() # pylint: disable=no-value-for-parameter