|
| 1 | +# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD |
| 2 | +# SPDX-License-Identifier: Unlicense OR CC0-1.0 |
| 3 | +import logging |
| 4 | +import os |
| 5 | + |
| 6 | +import pytest |
| 7 | +from pytest_embedded import Dut |
| 8 | + |
| 9 | + |
| 10 | +@pytest.mark.esp32 |
| 11 | +@pytest.mark.esp32c3 |
| 12 | +@pytest.mark.esp32s2 |
| 13 | +@pytest.mark.esp32s3 |
| 14 | +@pytest.mark.ethernet |
| 15 | +def test_examples_protocol_esp_http_client(dut: Dut) -> None: |
| 16 | + """ |
| 17 | + steps: | |
| 18 | + 1. join AP |
| 19 | + 2. Send HTTP request to httpbin.org |
| 20 | + """ |
| 21 | + binary_file = os.path.join(dut.app.binary_path, 'esp_http_client_example.bin') |
| 22 | + bin_size = os.path.getsize(binary_file) |
| 23 | + logging.info('esp_http_client_bin_size : {}KB'.format(bin_size // 1024)) |
| 24 | + # start test |
| 25 | + dut.expect('Connected to AP, begin http example', timeout=30) |
| 26 | + dut.expect(r'HTTP GET Status = 200, content_length = (\d)') |
| 27 | + dut.expect(r'HTTP POST Status = 200, content_length = (\d)') |
| 28 | + dut.expect(r'HTTP PUT Status = 200, content_length = (\d)') |
| 29 | + dut.expect(r'HTTP PATCH Status = 200, content_length = (\d)') |
| 30 | + dut.expect(r'HTTP DELETE Status = 200, content_length = (\d)') |
| 31 | + dut.expect(r'HTTP HEAD Status = 200, content_length = (\d)') |
| 32 | + dut.expect(r'HTTP GET Status = 200, content_length = (\d)') |
| 33 | + dut.expect(r'HTTP POST Status = 200, content_length = (\d)') |
| 34 | + dut.expect(r'HTTP PUT Status = 200, content_length = (\d)') |
| 35 | + dut.expect(r'HTTP PATCH Status = 200, content_length = (\d)') |
| 36 | + dut.expect(r'HTTP DELETE Status = 200, content_length = (\d)') |
| 37 | + dut.expect(r'HTTP HEAD Status = 200, content_length = (\d)') |
| 38 | + dut.expect(r'HTTP Basic Auth Status = 200, content_length = (\d)') |
| 39 | + dut.expect(r'HTTP Basic Auth redirect Status = 200, content_length = (\d)') |
| 40 | + dut.expect(r'HTTP Digest Auth Status = 200, content_length = (\d)') |
| 41 | + dut.expect(r'HTTP Relative path redirect Status = 200, content_length = (\d)') |
| 42 | + dut.expect(r'HTTP Absolute path redirect Status = 200, content_length = (\d)') |
| 43 | + dut.expect(r'HTTP Absolute path redirect \(manual\) Status = 200, content_length = (\d)') |
| 44 | + dut.expect(r'HTTPS Status = 200, content_length = (\d)') |
| 45 | + dut.expect(r'HTTPS Status = 200, content_length = (\d)') |
| 46 | + dut.expect(r'HTTP redirect to HTTPS Status = 200, content_length = (\d)') |
| 47 | + dut.expect(r'HTTP chunk encoding Status = 200, content_length = (-?\d)') |
| 48 | + # content-len for chunked encoding is typically -1, could be a positive length in some cases |
| 49 | + dut.expect(r'HTTP Stream reader Status = 200, content_length = (\d)') |
| 50 | + dut.expect(r'HTTPS Status = 200, content_length = (\d)') |
| 51 | + dut.expect(r'Last esp error code: 0x8001') |
| 52 | + dut.expect(r'HTTP GET Status = 200, content_length = (\d)') |
| 53 | + dut.expect(r'HTTP POST Status = 200, content_length = (\d)') |
| 54 | + dut.expect(r'HTTP Status = 206, content_length = (\d)') |
| 55 | + dut.expect(r'HTTP Status = 206, content_length = 10') |
| 56 | + dut.expect(r'HTTP Status = 206, content_length = 10') |
| 57 | + dut.expect('Finish http example') |
| 58 | + |
| 59 | + |
| 60 | +@pytest.mark.parametrize('config', [pytest.param('ssldyn', marks=[pytest.mark.supported_targets, pytest.mark.ethernet]),], indirect=True) |
| 61 | +def test_examples_protocol_esp_http_client_dynamic_buffer(dut: Dut) -> None: |
| 62 | + # test mbedtls dynamic resource |
| 63 | + # check and log bin size |
| 64 | + binary_file = os.path.join(dut.app.binary_path, 'esp_http_client_example.bin') |
| 65 | + bin_size = os.path.getsize(binary_file) |
| 66 | + logging.info('esp_http_client_bin_size : {}KB'.format(bin_size // 1024)) |
| 67 | + |
| 68 | + dut.expect('Connected to AP, begin http example', timeout=30) |
| 69 | + dut.expect(r'HTTP GET Status = 200, content_length = (\d)') |
| 70 | + dut.expect(r'HTTP POST Status = 200, content_length = (\d)') |
| 71 | + dut.expect(r'HTTP PUT Status = 200, content_length = (\d)') |
| 72 | + dut.expect(r'HTTP PATCH Status = 200, content_length = (\d)') |
| 73 | + dut.expect(r'HTTP DELETE Status = 200, content_length = (\d)') |
| 74 | + dut.expect(r'HTTP HEAD Status = 200, content_length = (\d)') |
| 75 | + dut.expect(r'HTTP GET Status = 200, content_length = (\d)') |
| 76 | + dut.expect(r'HTTP POST Status = 200, content_length = (\d)') |
| 77 | + dut.expect(r'HTTP PUT Status = 200, content_length = (\d)') |
| 78 | + dut.expect(r'HTTP PATCH Status = 200, content_length = (\d)') |
| 79 | + dut.expect(r'HTTP DELETE Status = 200, content_length = (\d)') |
| 80 | + dut.expect(r'HTTP HEAD Status = 200, content_length = (\d)') |
| 81 | + dut.expect(r'HTTP Basic Auth Status = 200, content_length = (\d)') |
| 82 | + dut.expect(r'HTTP Basic Auth redirect Status = 200, content_length = (\d)') |
| 83 | + dut.expect(r'HTTP Relative path redirect Status = 200, content_length = (\d)') |
| 84 | + dut.expect(r'HTTP Absolute path redirect Status = 200, content_length = (\d)') |
| 85 | + dut.expect(r'HTTP Absolute path redirect \(manual\) Status = 200, content_length = (\d)') |
| 86 | + dut.expect(r'HTTPS Status = 200, content_length = (\d)') |
| 87 | + dut.expect(r'HTTPS Status = 200, content_length = (\d)') |
| 88 | + dut.expect(r'HTTP redirect to HTTPS Status = 200, content_length = (\d)') |
| 89 | + dut.expect(r'HTTP chunk encoding Status = 200, content_length = (-?\d)') |
| 90 | + # content-len for chunked encoding is typically -1, could be a positive length in some cases |
| 91 | + dut.expect(r'HTTP Stream reader Status = 200, content_length = (\d)') |
| 92 | + dut.expect(r'HTTPS Status = 200, content_length = (\d)') |
| 93 | + dut.expect(r'Last esp error code: 0x8001') |
| 94 | + dut.expect(r'HTTP GET Status = 200, content_length = (\d)') |
| 95 | + dut.expect(r'HTTP POST Status = 200, content_length = (\d)') |
| 96 | + dut.expect(r'HTTP Status = 206, content_length = (\d)') |
| 97 | + dut.expect(r'HTTP Status = 206, content_length = 10') |
| 98 | + dut.expect(r'HTTP Status = 206, content_length = 10') |
| 99 | + dut.expect('Finish http example') |
0 commit comments