example.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # Copyright 2015-2017 Espressif Systems (Shanghai) PTE LTD
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http:#www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. """ example of writing test with TinyTestFW """
  15. import re
  16. import os
  17. import sys
  18. try:
  19. import TinyFW
  20. except ImportError:
  21. # if we want to run test case outside `tiny-test-fw` folder,
  22. # we need to insert tiny-test-fw path into sys path
  23. test_fw_path = os.getenv("TEST_FW_PATH")
  24. if test_fw_path and test_fw_path not in sys.path:
  25. sys.path.insert(0, test_fw_path)
  26. import TinyFW
  27. import IDF
  28. @IDF.idf_example_test(env_tag="Example_WIFI")
  29. def test_examples_protocol_https_request(env, extra_data):
  30. """
  31. steps: |
  32. 1. join AP
  33. 2. connect to www.howsmyssl.com:443
  34. 3. send http request
  35. """
  36. dut1 = env.get_dut("https_request", "examples/protocols/https_request")
  37. dut1.start_app()
  38. dut1.expect(re.compile(r"Connecting to www.howsmyssl.com:443"), timeout=30)
  39. dut1.expect("Performing the SSL/TLS handshake")
  40. dut1.expect("Certificate verified.", timeout=15)
  41. dut1.expect_all(re.compile(r"Cipher suite is TLS-ECDHE-RSA-WITH-AES-128-GCM-SHA256"),
  42. "Reading HTTP response",
  43. timeout=20)
  44. dut1.expect(re.compile(r"Completed (\d) requests"))
  45. if __name__ == '__main__':
  46. TinyFW.set_default_config(env_config_file="EnvConfigTemplate.yml", dut=IDF.IDFDUT)
  47. test_examples_protocol_https_request()