Skip to content

Commit 34fb03b

Browse files
committed
Merge branch 'feature/http_example_pytest_migration' into 'master'
http example pytest migration See merge request espressif/esp-idf!18053
2 parents 773715d + 74789ff commit 34fb03b

22 files changed

+812
-867
lines changed

.gitlab-ci.yml

+1
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ before_script:
219219
pytest-rerunfailures
220220
scapy
221221
websocket-client
222+
netifaces
222223
-r tools/esp_prov/requirements.txt
223224
- export EXTRA_CFLAGS=${PEDANTIC_CFLAGS}
224225
- export EXTRA_CXXFLAGS=${PEDANTIC_CXXFLAGS}

.gitlab/ci/build.yml

+6-3
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,17 @@ build_pytest_examples_esp32s2:
4949
extends:
5050
- .build_pytest_template
5151
- .rules:build:example_test-esp32s2
52+
parallel: 2
5253
script:
53-
- run_cmd python tools/ci/build_pytest_apps.py examples --target esp32s2 --size-info $SIZE_INFO_LOCATION -vv
54+
- run_cmd python tools/ci/build_pytest_apps.py examples --target esp32s2 --size-info $SIZE_INFO_LOCATION -vv --parallel-count $CI_NODE_TOTAL --parallel-index $CI_NODE_INDEX
5455

5556
build_pytest_examples_esp32s3:
5657
extends:
5758
- .build_pytest_template
5859
- .rules:build:example_test-esp32s3
60+
parallel: 2
5961
script:
60-
- run_cmd python tools/ci/build_pytest_apps.py examples --target esp32s3 --size-info $SIZE_INFO_LOCATION -vv
62+
- run_cmd python tools/ci/build_pytest_apps.py examples --target esp32s3 --size-info $SIZE_INFO_LOCATION -vv --parallel-count $CI_NODE_TOTAL --parallel-index $CI_NODE_INDEX
6163

6264
build_pytest_examples_esp32c2:
6365
extends:
@@ -70,8 +72,9 @@ build_pytest_examples_esp32c3:
7072
extends:
7173
- .build_pytest_template
7274
- .rules:build:example_test-esp32c3
75+
parallel: 2
7376
script:
74-
- run_cmd python tools/ci/build_pytest_apps.py examples --target esp32c3 --size-info $SIZE_INFO_LOCATION -vv
77+
- run_cmd python tools/ci/build_pytest_apps.py examples --target esp32c3 --size-info $SIZE_INFO_LOCATION -vv --parallel-count $CI_NODE_TOTAL --parallel-index $CI_NODE_INDEX
7578

7679
build_pytest_components_esp32:
7780
extends:

.gitlab/ci/target-test.yml

+10
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,16 @@ example_test_pytest_esp32_wifi:
161161
TARGET: ESP32
162162
ENV_MARKER: wifi
163163

164+
example_test_pytest_esp32_wifi_bt:
165+
extends:
166+
- .pytest_examples_dir_template
167+
- .rules:test:example_test-esp32
168+
needs:
169+
- build_pytest_examples_esp32
170+
variables:
171+
TARGET: ESP32
172+
ENV_MARKER: wifi_bt
173+
164174
example_test_pytest_esp32_ethernet_ip101:
165175
extends:
166176
- .pytest_examples_dir_template

examples/protocols/esp_http_client/esp_http_client_test.py

-99
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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')

examples/protocols/http2_request/example_test.py renamed to examples/protocols/http2_request/pytest_http2_request.py

+16-18
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
# SPDX-License-Identifier: Apache-2.0
55

66
import http.client
7+
import logging
78
import os
89

9-
import tiny_test_fw
10-
import ttfw_idf
11-
from tiny_test_fw import Utility
10+
import pytest
11+
from pytest_embedded import Dut
1212

1313
HTTP_OK = 200
1414
TEST_SERVER = 'http2.github.io'
@@ -22,40 +22,38 @@ def is_test_server_available(): # type: () -> bool
2222
resp = conn.getresponse()
2323
return True if resp.status == HTTP_OK else False
2424
except Exception as msg:
25-
Utility.console_log('Exception occurred when connecting to {}: {}'.format(TEST_SERVER, msg))
25+
logging.info('Exception occurred when connecting to {}: {}'.format(TEST_SERVER, msg))
2626
return False
2727
finally:
2828
conn.close()
2929

3030

31-
@ttfw_idf.idf_example_test(env_tag='Example_EthKitV1')
32-
def test_examples_protocol_http2_request(env, extra_data): # type: (tiny_test_fw.Env.Env, None) -> None # pylint: disable=unused-argument
31+
@pytest.mark.esp32
32+
@pytest.mark.esp32c3
33+
@pytest.mark.esp32s2
34+
@pytest.mark.esp32s3
35+
@pytest.mark.ethernet
36+
def test_examples_protocol_http2_request(dut: Dut) -> None:
3337
"""
3438
steps: |
3539
1. join AP
3640
2. connect to http2.github.io
3741
3. send http2 request
3842
4. send http2 put response
3943
"""
40-
dut1 = env.get_dut('http2_request', 'examples/protocols/http2_request', dut_class=ttfw_idf.ESP32DUT)
4144
# check and log bin size
42-
binary_file = os.path.join(dut1.app.binary_path, 'http2_request.bin')
45+
binary_file = os.path.join(dut.app.binary_path, 'http2_request.bin')
4346
bin_size = os.path.getsize(binary_file)
44-
ttfw_idf.log_performance('http2_request_bin_size', '{}KB'.format(bin_size // 1024))
47+
logging.info('http2_request_bin_size : {}KB'.format(bin_size // 1024))
4548
# start the test
4649
# check if test server is avilable
4750
test_server_available = is_test_server_available()
4851
# Skip the test if the server test server (http2.github.io) is not available at the moment.
4952
if test_server_available:
50-
Utility.console_log('test server \"{}\" is available'.format(TEST_SERVER))
51-
dut1.start_app()
53+
logging.info('test server \"{}\" is available'.format(TEST_SERVER))
5254
# check for connection
53-
dut1.expect('Connection done', timeout=30)
55+
dut.expect('Connection done', timeout=30)
5456
# check for get response
55-
dut1.expect('[get-response] Frame fully received')
57+
dut.expect('Frame fully received')
5658
else:
57-
Utility.console_log('test server \"{0}\" is not available at the moment.\nSkipping the test with status = success.'.format(TEST_SERVER))
58-
59-
60-
if __name__ == '__main__':
61-
test_examples_protocol_http2_request() # pylint: disable=no-value-for-parameter
59+
logging.info('test server \"{0}\" is not available at the moment.\nSkipping the test with status = success.'.format(TEST_SERVER))

examples/protocols/http_request/example_test.py

-41
This file was deleted.

0 commit comments

Comments
 (0)