example_test.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 os
  17. import re
  18. import tiny_test_fw
  19. import ttfw_idf
  20. @ttfw_idf.idf_example_test(env_tag='Example_EthKitV1')
  21. def test_examples_protocol_http_request(env, extra_data): # type: (tiny_test_fw.Env.Env, None) -> None # pylint: disable=unused-argument
  22. """
  23. steps: |
  24. 1. join AP
  25. 2. connect to example.com
  26. 3. check conneciton success
  27. """
  28. dut1 = env.get_dut('http_request', 'examples/protocols/http_request', dut_class=ttfw_idf.ESP32DUT)
  29. # check and log bin size
  30. binary_file = os.path.join(dut1.app.binary_path, 'http-request.bin')
  31. bin_size = os.path.getsize(binary_file)
  32. ttfw_idf.log_performance('http_request_bin_size', '{}KB'.format(bin_size // 1024))
  33. # start test
  34. dut1.start_app()
  35. dut1.expect(re.compile(r'DNS lookup succeeded.'), timeout=30)
  36. # check if connected or not
  37. dut1.expect(' ... connected', timeout=60)
  38. dut1.expect(' ... socket send success')
  39. dut1.expect(' ... set socket receiving timeout success')
  40. # check server response
  41. dut1.expect(re.compile(r'HTTP/1.0 200 OK'))
  42. # read from the socket completed
  43. dut1.expect('... done reading from socket. Last read return=0 errno=128')
  44. dut1.expect(re.compile(r'(\d)...'))
  45. if __name__ == '__main__':
  46. test_examples_protocol_http_request() # pylint: disable=no-value-for-parameter