pytest_http_request.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/usr/bin/env python
  2. #
  3. # SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
  4. # SPDX-License-Identifier: Apache-2.0
  5. import logging
  6. import os
  7. import pytest
  8. from pytest_embedded import Dut
  9. @pytest.mark.esp32
  10. @pytest.mark.esp32c3
  11. @pytest.mark.esp32s2
  12. @pytest.mark.esp32s3
  13. @pytest.mark.ethernet
  14. def test_examples_protocol_http_request(dut: Dut) -> None:
  15. """
  16. steps: |
  17. 1. join AP
  18. 2. connect to example.com
  19. 3. check conneciton success
  20. """
  21. # check and log bin size
  22. binary_file = os.path.join(dut.app.binary_path, 'http_request.bin')
  23. bin_size = os.path.getsize(binary_file)
  24. logging.info('http_request_bin_size : {}KB'.format(bin_size // 1024))
  25. # start test
  26. dut.expect(r'DNS lookup succeeded.', timeout=30)
  27. # check if connected or not
  28. dut.expect(' ... connected', timeout=60)
  29. dut.expect(' ... socket send success')
  30. dut.expect(' ... set socket receiving timeout success')
  31. # check server response
  32. dut.expect(r'HTTP/1.0 200 OK')
  33. # read from the socket completed
  34. dut.expect('... done reading from socket. Last read return=0 errno=128')
  35. dut.expect(r'(\d)...')