2021-01-12 12:47:32 -05:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#
|
2022-01-05 01:56:39 -05:00
|
|
|
# SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
|
2021-09-23 02:31:47 -04:00
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
2021-01-12 12:47:32 -05:00
|
|
|
|
|
|
|
import http.client
|
2022-05-10 02:17:12 -04:00
|
|
|
import logging
|
2021-01-12 12:47:32 -05:00
|
|
|
import os
|
|
|
|
|
2022-05-10 02:17:12 -04:00
|
|
|
import pytest
|
|
|
|
from pytest_embedded import Dut
|
2021-01-12 12:47:32 -05:00
|
|
|
|
|
|
|
HTTP_OK = 200
|
2022-01-05 01:56:39 -05:00
|
|
|
TEST_SERVER = 'http2.github.io'
|
2021-01-12 12:47:32 -05:00
|
|
|
|
|
|
|
|
|
|
|
def is_test_server_available(): # type: () -> bool
|
|
|
|
# 443 - default https port
|
2021-11-04 11:29:07 -04:00
|
|
|
try:
|
|
|
|
conn = http.client.HTTPSConnection(TEST_SERVER, 443, timeout=10)
|
|
|
|
conn.request('GET', '/')
|
|
|
|
resp = conn.getresponse()
|
|
|
|
return True if resp.status == HTTP_OK else False
|
|
|
|
except Exception as msg:
|
2022-05-10 02:17:12 -04:00
|
|
|
logging.info('Exception occurred when connecting to {}: {}'.format(TEST_SERVER, msg))
|
2021-11-04 11:29:07 -04:00
|
|
|
return False
|
|
|
|
finally:
|
|
|
|
conn.close()
|
2021-01-12 12:47:32 -05:00
|
|
|
|
|
|
|
|
2022-05-10 02:17:12 -04:00
|
|
|
@pytest.mark.esp32
|
|
|
|
@pytest.mark.ethernet
|
|
|
|
def test_examples_protocol_http2_request(dut: Dut) -> None:
|
2021-01-12 12:47:32 -05:00
|
|
|
"""
|
|
|
|
steps: |
|
|
|
|
1. join AP
|
2022-01-05 01:56:39 -05:00
|
|
|
2. connect to http2.github.io
|
2021-01-12 12:47:32 -05:00
|
|
|
3. send http2 request
|
|
|
|
4. send http2 put response
|
|
|
|
"""
|
|
|
|
# check and log bin size
|
2022-05-10 02:17:12 -04:00
|
|
|
binary_file = os.path.join(dut.app.binary_path, 'http2_request.bin')
|
2021-01-12 12:47:32 -05:00
|
|
|
bin_size = os.path.getsize(binary_file)
|
2022-05-10 02:17:12 -04:00
|
|
|
logging.info('http2_request_bin_size : {}KB'.format(bin_size // 1024))
|
2021-01-12 12:47:32 -05:00
|
|
|
# start the test
|
|
|
|
# check if test server is avilable
|
|
|
|
test_server_available = is_test_server_available()
|
2022-01-05 01:56:39 -05:00
|
|
|
# Skip the test if the server test server (http2.github.io) is not available at the moment.
|
2021-01-12 12:47:32 -05:00
|
|
|
if test_server_available:
|
2022-05-10 02:17:12 -04:00
|
|
|
logging.info('test server \"{}\" is available'.format(TEST_SERVER))
|
2021-01-12 12:47:32 -05:00
|
|
|
# check for connection
|
2022-05-10 02:17:12 -04:00
|
|
|
dut.expect('Connection done', timeout=30)
|
2021-01-12 12:47:32 -05:00
|
|
|
# check for get response
|
2022-05-10 02:17:12 -04:00
|
|
|
dut.expect('Frame fully received')
|
2021-01-12 12:47:32 -05:00
|
|
|
else:
|
2022-05-10 02:17:12 -04:00
|
|
|
logging.info('test server \"{0}\" is not available at the moment.\nSkipping the test with status = success.'.format(TEST_SERVER))
|