mirror of
https://github.com/espressif/esp-mqtt.git
synced 2026-08-03 20:14:15 +02:00
ci: Adds target tests and move to gitlab components
Ths adopts gitlab components for better maintanance of CI. Adds target tests
This commit is contained in:
@@ -10,8 +10,8 @@ from pytest_embedded import Dut
|
||||
from pytest_embedded_idf.utils import idf_parametrize
|
||||
|
||||
|
||||
@pytest.mark.ethernet
|
||||
@idf_parametrize('target', ['esp32'], indirect=['target'])
|
||||
@pytest.mark.eth_ip101
|
||||
@idf_parametrize("target", ["esp32"], indirect=["target"])
|
||||
def test_examples_protocol_mqtt5(dut: Dut) -> None:
|
||||
"""
|
||||
steps: |
|
||||
@@ -20,46 +20,46 @@ def test_examples_protocol_mqtt5(dut: Dut) -> None:
|
||||
3. check connection success
|
||||
"""
|
||||
# check and log bin size
|
||||
binary_file = os.path.join(dut.app.binary_path, 'mqtt5.bin')
|
||||
binary_file = os.path.join(dut.app.binary_path, "mqtt5.bin")
|
||||
bin_size = os.path.getsize(binary_file)
|
||||
logging.info('mqtt5_bin_size : {}KB'.format(bin_size // 1024))
|
||||
logging.info("mqtt5_bin_size : {}KB".format(bin_size // 1024))
|
||||
# check if connected or not
|
||||
dut.expect_exact('MQTT_EVENT_CONNECTED', timeout=30)
|
||||
dut.expect_exact("MQTT_EVENT_CONNECTED", timeout=30)
|
||||
# check log
|
||||
res = dut.expect(r'sent publish successful, msg_id=(\d+)[^\d]')
|
||||
msgid_pub1 = res.group(1).decode('utf8')
|
||||
res = dut.expect(r'sent subscribe successful, msg_id=(\d+)[^\d]')
|
||||
msgid_sub1 = res.group(1).decode('utf8')
|
||||
res = dut.expect(r'sent subscribe successful, msg_id=(\d+)[^\d]')
|
||||
msgid_sub2 = res.group(1).decode('utf8')
|
||||
res = dut.expect(r'sent unsubscribe successful, msg_id=(\d+)[^\d]')
|
||||
msgid_unsub = res.group(1).decode('utf8')
|
||||
res = dut.expect(r'MQTT_EVENT_PUBLISHED, msg_id=(\d+)[^\d]')
|
||||
msgid_pubd = res.group(1).decode('utf8')
|
||||
res = dut.expect(r"sent publish successful, msg_id=(\d+)[^\d]")
|
||||
msgid_pub1 = res.group(1).decode("utf8")
|
||||
res = dut.expect(r"sent subscribe successful, msg_id=(\d+)[^\d]")
|
||||
msgid_sub1 = res.group(1).decode("utf8")
|
||||
res = dut.expect(r"sent subscribe successful, msg_id=(\d+)[^\d]")
|
||||
msgid_sub2 = res.group(1).decode("utf8")
|
||||
res = dut.expect(r"sent unsubscribe successful, msg_id=(\d+)[^\d]")
|
||||
msgid_unsub = res.group(1).decode("utf8")
|
||||
res = dut.expect(r"MQTT_EVENT_PUBLISHED, msg_id=(\d+)[^\d]")
|
||||
msgid_pubd = res.group(1).decode("utf8")
|
||||
assert msgid_pubd == msgid_pub1
|
||||
|
||||
res = dut.expect(r'MQTT_EVENT_SUBSCRIBED, msg_id=(\d+)[^\d]')
|
||||
msgid_subd = res.group(1).decode('utf8')
|
||||
res = dut.expect(r"MQTT_EVENT_SUBSCRIBED, msg_id=(\d+)[^\d]")
|
||||
msgid_subd = res.group(1).decode("utf8")
|
||||
assert msgid_subd == msgid_sub1
|
||||
|
||||
dut.expect_exact('sent publish successful, msg_id=0')
|
||||
res = dut.expect(r'MQTT_EVENT_SUBSCRIBED, msg_id=(\d+)[^\d]')
|
||||
msgid_subd = res.group(1).decode('utf8')
|
||||
dut.expect_exact("sent publish successful, msg_id=0")
|
||||
res = dut.expect(r"MQTT_EVENT_SUBSCRIBED, msg_id=(\d+)[^\d]")
|
||||
msgid_subd = res.group(1).decode("utf8")
|
||||
assert msgid_subd == msgid_sub2
|
||||
|
||||
dut.expect_exact('sent publish successful, msg_id=0')
|
||||
dut.expect_exact('MQTT_EVENT_DATA')
|
||||
dut.expect_exact('key is board, value is esp32')
|
||||
dut.expect_exact('key is u, value is user')
|
||||
dut.expect_exact('key is p, value is password')
|
||||
dut.expect_exact('payload_format_indicator is 1')
|
||||
dut.expect_exact('response_topic is /topic/test/response')
|
||||
dut.expect_exact('correlation_data is 123456')
|
||||
dut.expect_exact('TOPIC=/topic/qos1')
|
||||
dut.expect_exact('DATA=data_3')
|
||||
res = dut.expect(r'MQTT_EVENT_UNSUBSCRIBED, msg_id=(\d+)[^\d]')
|
||||
msgid_unsubd = res.group(1).decode('utf8')
|
||||
dut.expect_exact("sent publish successful, msg_id=0")
|
||||
dut.expect_exact("MQTT_EVENT_DATA")
|
||||
dut.expect_exact("key is board, value is esp32")
|
||||
dut.expect_exact("key is u, value is user")
|
||||
dut.expect_exact("key is p, value is password")
|
||||
dut.expect_exact("payload_format_indicator is 1")
|
||||
dut.expect_exact("response_topic is /topic/test/response")
|
||||
dut.expect_exact("correlation_data is 123456")
|
||||
dut.expect_exact("TOPIC=/topic/qos1")
|
||||
dut.expect_exact("DATA=data_3")
|
||||
res = dut.expect(r"MQTT_EVENT_UNSUBSCRIBED, msg_id=(\d+)[^\d]")
|
||||
msgid_unsubd = res.group(1).decode("utf8")
|
||||
assert msgid_unsubd == msgid_unsub
|
||||
|
||||
dut.expect_exact('MQTT_EVENT_DISCONNECTED')
|
||||
logging.info('MQTT5 pytest pass')
|
||||
dut.expect_exact("MQTT_EVENT_DISCONNECTED")
|
||||
logging.info("MQTT5 pytest pass")
|
||||
|
||||
@@ -7,4 +7,5 @@ CONFIG_EXAMPLE_ETH_MDIO_GPIO=18
|
||||
CONFIG_EXAMPLE_ETH_PHY_RST_GPIO=5
|
||||
CONFIG_EXAMPLE_ETH_PHY_ADDR=1
|
||||
CONFIG_MQTT_PROTOCOL_5=y
|
||||
CONFIG_BROKER_URL="mqtt://${EXAMPLE_MQTTV5_BROKER_TCP}"
|
||||
CONFIG_BROKER_URL="mqtt://${TEST_BROKER_BRNO_TCP}"
|
||||
CONFIG_LOG_MAXIMUM_LEVEL_DEBUG=y
|
||||
|
||||
@@ -140,7 +140,7 @@ static void mqtt_app_start(void)
|
||||
const esp_mqtt_client_config_t mqtt_cfg = {
|
||||
.broker = {
|
||||
.address.uri = CONFIG_BROKER_URI,
|
||||
.verification.certificate = (const char *)mqtt_eclipseprojects_io_pem_start
|
||||
.verification.certificate = (const char *)mqtt_eclipseprojects_io_pem_start,
|
||||
},
|
||||
};
|
||||
ESP_LOGI(TAG, "[APP] Free memory: %" PRIu32 " bytes", esp_get_free_heap_size());
|
||||
|
||||
@@ -18,15 +18,15 @@ event_client_connected = Event()
|
||||
event_stop_client = Event()
|
||||
event_client_received_correct = Event()
|
||||
event_client_received_binary = Event()
|
||||
message_log = ''
|
||||
message_log = ""
|
||||
|
||||
|
||||
# The callback for when the client receives a CONNACK response from the server.
|
||||
def on_connect(client, userdata, flags, rc): # type: (mqtt.Client, str, bool, str) -> None
|
||||
_ = (userdata, flags)
|
||||
print('Connected with result code ' + str(rc))
|
||||
print("Connected with result code " + str(rc))
|
||||
event_client_connected.set()
|
||||
client.subscribe('/topic/qos0')
|
||||
client.subscribe("/topic/qos0")
|
||||
|
||||
|
||||
def mqtt_client_task(client): # type: (mqtt.Client) -> None
|
||||
@@ -39,35 +39,35 @@ def on_message(client, userdata, msg): # type: (mqtt.Client, tuple, mqtt.client
|
||||
global message_log
|
||||
global event_client_received_correct
|
||||
global event_client_received_binary
|
||||
if msg.topic == '/topic/binary':
|
||||
if msg.topic == "/topic/binary":
|
||||
binary, bin_size = userdata
|
||||
print('Receiving binary from esp and comparing with {}, size {}...'.format(binary, bin_size))
|
||||
with open(binary, 'rb') as f:
|
||||
print("Receiving binary from esp and comparing with {}, size {}...".format(binary, bin_size))
|
||||
with open(binary, "rb") as f:
|
||||
bin = f.read()
|
||||
if bin[:bin_size] == msg.payload[:bin_size]:
|
||||
print('...matches!')
|
||||
print("...matches!")
|
||||
event_client_received_binary.set()
|
||||
return
|
||||
recv_binary = binary + '.received'
|
||||
with open(recv_binary, 'w', encoding='utf-8') as fw:
|
||||
recv_binary = binary + ".received"
|
||||
with open(recv_binary, "w", encoding="utf-8") as fw:
|
||||
fw.write(msg.payload)
|
||||
raise ValueError(
|
||||
'Received binary (saved as: {}) does not match the original file: {}'.format(recv_binary, binary)
|
||||
"Received binary (saved as: {}) does not match the original file: {}".format(recv_binary, binary)
|
||||
)
|
||||
|
||||
payload = msg.payload.decode()
|
||||
if not event_client_received_correct.is_set() and payload == 'data':
|
||||
client.subscribe('/topic/binary')
|
||||
client.publish('/topic/qos0', 'send binary please')
|
||||
if msg.topic == '/topic/qos0' and payload == 'data':
|
||||
if not event_client_received_correct.is_set() and payload == "data":
|
||||
client.subscribe("/topic/binary")
|
||||
client.publish("/topic/qos0", "send binary please")
|
||||
if msg.topic == "/topic/qos0" and payload == "data":
|
||||
event_client_received_correct.set()
|
||||
message_log += 'Received data:' + msg.topic + ' ' + payload + '\n'
|
||||
message_log += "Received data:" + msg.topic + " " + payload + "\n"
|
||||
|
||||
|
||||
@pytest.mark.ethernet
|
||||
@idf_parametrize('target', ['esp32'], indirect=['target'])
|
||||
@pytest.mark.eth_ip101
|
||||
@idf_parametrize("target", ["esp32"], indirect=["target"])
|
||||
def test_examples_protocol_mqtt_ssl(dut): # type: (Dut) -> None
|
||||
broker_url = ''
|
||||
broker_url = ""
|
||||
broker_port = 0
|
||||
"""
|
||||
steps:
|
||||
@@ -77,19 +77,19 @@ def test_examples_protocol_mqtt_ssl(dut): # type: (Dut) -> None
|
||||
4. Test ESP32 client received correct qos0 message
|
||||
5. Test python client receives binary data from running partition and compares it with the binary
|
||||
"""
|
||||
binary_file = os.path.join(dut.app.binary_path, 'mqtt_ssl.bin')
|
||||
binary_file = os.path.join(dut.app.binary_path, "mqtt_ssl.bin")
|
||||
bin_size = os.path.getsize(binary_file)
|
||||
logging.info('[Performance][mqtt_ssl_bin_size]: %s KB', bin_size // 1024)
|
||||
logging.info("[Performance][mqtt_ssl_bin_size]: %s KB", bin_size // 1024)
|
||||
|
||||
# Look for host:port in sdkconfig
|
||||
try:
|
||||
value = re.search(r'\:\/\/([^:]+)\:([0-9]+)', dut.app.sdkconfig.get('BROKER_URI'))
|
||||
value = re.search(r"\:\/\/([^:]+)\:([0-9]+)", dut.app.sdkconfig.get("BROKER_URI"))
|
||||
assert value is not None
|
||||
broker_url = value.group(1)
|
||||
broker_port = int(value.group(2))
|
||||
bin_size = min(int(dut.app.sdkconfig.get('BROKER_BIN_SIZE_TO_SEND')), bin_size)
|
||||
bin_size = min(int(dut.app.sdkconfig.get("BROKER_BIN_SIZE_TO_SEND")), bin_size)
|
||||
except Exception:
|
||||
print('ENV_TEST_FAILURE: Cannot find broker url in sdkconfig')
|
||||
print("ENV_TEST_FAILURE: Cannot find broker url in sdkconfig")
|
||||
raise
|
||||
client = None
|
||||
# 1. Test connects to a broker
|
||||
@@ -100,11 +100,11 @@ def test_examples_protocol_mqtt_ssl(dut): # type: (Dut) -> None
|
||||
client.user_data_set((binary_file, bin_size))
|
||||
client.tls_set(None, None, None, cert_reqs=ssl.CERT_NONE, tls_version=ssl.PROTOCOL_TLSv1_2, ciphers=None)
|
||||
client.tls_insecure_set(True)
|
||||
print('Connecting...')
|
||||
print("Connecting...")
|
||||
client.connect(broker_url, broker_port, 60)
|
||||
except Exception:
|
||||
print(
|
||||
'ENV_TEST_FAILURE: Unexpected error while connecting to broker {}: {}:'.format(
|
||||
"ENV_TEST_FAILURE: Unexpected error while connecting to broker {}: {}:".format(
|
||||
broker_url, sys.exc_info()[0]
|
||||
)
|
||||
)
|
||||
@@ -113,23 +113,23 @@ def test_examples_protocol_mqtt_ssl(dut): # type: (Dut) -> None
|
||||
thread1 = Thread(target=mqtt_client_task, args=(client,))
|
||||
thread1.start()
|
||||
try:
|
||||
print('Connecting py-client to broker {}:{}...'.format(broker_url, broker_port))
|
||||
print("Connecting py-client to broker {}:{}...".format(broker_url, broker_port))
|
||||
if not event_client_connected.wait(timeout=30):
|
||||
raise ValueError('ENV_TEST_FAILURE: Test script cannot connect to broker: {}'.format(broker_url))
|
||||
raise ValueError("ENV_TEST_FAILURE: Test script cannot connect to broker: {}".format(broker_url))
|
||||
try:
|
||||
ip_address = dut.expect(r'IPv4 address: (\d+\.\d+\.\d+\.\d+)[^\d]', timeout=30)[0]
|
||||
print('Connected to AP with IP: {}'.format(ip_address))
|
||||
ip_address = dut.expect(r"IPv4 address: (\d+\.\d+\.\d+\.\d+)[^\d]", timeout=30)[0]
|
||||
print("Connected to AP with IP: {}".format(ip_address))
|
||||
except pexpect.TIMEOUT:
|
||||
print('ENV_TEST_FAILURE: Cannot connect to AP')
|
||||
print("ENV_TEST_FAILURE: Cannot connect to AP")
|
||||
raise
|
||||
print('Checking py-client received msg published from esp...')
|
||||
print("Checking py-client received msg published from esp...")
|
||||
if not event_client_received_correct.wait(timeout=30):
|
||||
raise ValueError('Wrong data received, msg log: {}'.format(message_log))
|
||||
print('Checking esp-client received msg published from py-client...')
|
||||
dut.expect(r'DATA=send binary please', timeout=30)
|
||||
print('Receiving binary data from running partition...')
|
||||
raise ValueError("Wrong data received, msg log: {}".format(message_log))
|
||||
print("Checking esp-client received msg published from py-client...")
|
||||
dut.expect(r"DATA=send binary please", timeout=30)
|
||||
print("Receiving binary data from running partition...")
|
||||
if not event_client_received_binary.wait(timeout=30):
|
||||
raise ValueError('Binary not received within timeout')
|
||||
raise ValueError("Binary not received within timeout")
|
||||
finally:
|
||||
event_stop_client.set()
|
||||
thread1.join()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
CONFIG_BROKER_URI="mqtts://${EXAMPLE_MQTT_BROKER_SSL}"
|
||||
CONFIG_BROKER_URI="mqtts://${TEST_BROKER_BRNO_SSL}"
|
||||
CONFIG_BROKER_CERTIFICATE_OVERRIDE="${EXAMPLE_MQTT_BROKER_CERTIFICATE}"
|
||||
CONFIG_MQTT_USE_CUSTOM_CONFIG=y
|
||||
CONFIG_MQTT_TCP_DEFAULT_PORT=1883
|
||||
@@ -20,3 +20,4 @@ CONFIG_EXAMPLE_ETH_PHY_RST_GPIO=5
|
||||
CONFIG_EXAMPLE_ETH_PHY_ADDR=1
|
||||
CONFIG_EXAMPLE_CONNECT_IPV6=y
|
||||
CONFIG_LWIP_CHECK_THREAD_SAFETY=y
|
||||
CONFIG_LOG_MAXIMUM_LEVEL_DEBUG=y
|
||||
|
||||
@@ -8,7 +8,3 @@ dependencies:
|
||||
version: ">=0.10,<2.0"
|
||||
rules:
|
||||
- if: target in [esp32p4, esp32h2]
|
||||
espressif/esp_hosted:
|
||||
version: "2.5.1"
|
||||
rules:
|
||||
- if: target in [esp32p4, esp32h2]
|
||||
|
||||
@@ -10,8 +10,9 @@ from threading import Thread
|
||||
|
||||
import pexpect
|
||||
import pytest
|
||||
from common_test_methods import get_host_ip4_by_dest_ip
|
||||
from pytest_embedded import Dut
|
||||
|
||||
from conftest import get_host_ip4_by_dest_ip
|
||||
from pytest_embedded_idf.utils import idf_parametrize
|
||||
|
||||
msgid = -1
|
||||
@@ -19,7 +20,7 @@ msgid = -1
|
||||
|
||||
def mqqt_server_sketch(my_ip, port): # type: (str, str) -> None
|
||||
global msgid
|
||||
print('Starting the server on {}'.format(my_ip))
|
||||
logging.info("Starting the server on {}".format(my_ip))
|
||||
s = None
|
||||
try:
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
@@ -28,32 +29,32 @@ def mqqt_server_sketch(my_ip, port): # type: (str, str) -> None
|
||||
s.listen(1)
|
||||
q, addr = s.accept()
|
||||
q.settimeout(30)
|
||||
print('connection accepted')
|
||||
logging.info("connection accepted")
|
||||
except Exception:
|
||||
print(
|
||||
'Local server on {}:{} listening/accepting failure: {}'
|
||||
'Possibly check permissions or firewall settings'
|
||||
'to accept connections on this address'.format(my_ip, port, sys.exc_info()[0])
|
||||
logging.error(
|
||||
"Local server on {}:{} listening/accepting failure: {}"
|
||||
"Possibly check permissions or firewall settings"
|
||||
"to accept connections on this address".format(my_ip, port, sys.exc_info()[0])
|
||||
)
|
||||
raise
|
||||
data = q.recv(1024)
|
||||
# check if received initial empty message
|
||||
print('received from client {!r}'.format(data))
|
||||
logging.info("received from client {!r}".format(data))
|
||||
data = bytearray([0x20, 0x02, 0x00, 0x00])
|
||||
q.send(data)
|
||||
# try to receive qos1
|
||||
data = q.recv(1024)
|
||||
msgid = struct.unpack('>H', data[15:17])[0]
|
||||
print('received from client {!r}, msgid: {}'.format(data, msgid))
|
||||
msgid = struct.unpack(">H", data[15:17])[0]
|
||||
logging.info("received from client {!r}, msgid: {}".format(data, msgid))
|
||||
data = bytearray([0x40, 0x02, data[15], data[16]])
|
||||
q.send(data)
|
||||
time.sleep(5)
|
||||
s.close()
|
||||
print('server closed')
|
||||
logging.info("server closed")
|
||||
|
||||
|
||||
@pytest.mark.ethernet
|
||||
@idf_parametrize('target', ['esp32'], indirect=['target'])
|
||||
@pytest.mark.eth_ip101
|
||||
@idf_parametrize("target", ["esp32"], indirect=["target"])
|
||||
def test_examples_protocol_mqtt_qos1(dut: Dut) -> None:
|
||||
global msgid
|
||||
"""
|
||||
@@ -64,34 +65,34 @@ def test_examples_protocol_mqtt_qos1(dut: Dut) -> None:
|
||||
4. Test the broker received the same message id evaluated in step 3
|
||||
"""
|
||||
# check and log bin size
|
||||
binary_file = os.path.join(dut.app.binary_path, 'mqtt_tcp.bin')
|
||||
binary_file = os.path.join(dut.app.binary_path, "mqtt_tcp.bin")
|
||||
bin_size = os.path.getsize(binary_file)
|
||||
logging.info('[Performance][mqtt_tcp_bin_size]: %s KB', bin_size // 1024)
|
||||
logging.info("[Performance][mqtt_tcp_bin_size]: %s KB", bin_size // 1024)
|
||||
# waiting for getting the IP address
|
||||
try:
|
||||
ip_address = dut.expect(r'IPv4 address: (\d+\.\d+\.\d+\.\d+)', timeout=30).group(1).decode()
|
||||
print('Connected to AP/Ethernet with IP: {}'.format(ip_address))
|
||||
ip_address = dut.expect(r"IPv4 address: (\d+\.\d+\.\d+\.\d+)", timeout=30).group(1).decode()
|
||||
logging.info("Connected to AP/Ethernet with IP: {}".format(ip_address))
|
||||
except pexpect.TIMEOUT:
|
||||
raise ValueError('ENV_TEST_FAILURE: Cannot connect to AP/Ethernet')
|
||||
raise ValueError("ENV_TEST_FAILURE: Cannot connect to AP/Ethernet")
|
||||
|
||||
# 2. start mqtt broker sketch
|
||||
host_ip = get_host_ip4_by_dest_ip(ip_address)
|
||||
thread1 = Thread(target=mqqt_server_sketch, args=(host_ip, 1883))
|
||||
thread1.start()
|
||||
|
||||
data_write = 'mqtt://' + host_ip
|
||||
print('writing to device: {}'.format(data_write))
|
||||
data_write = "mqtt://" + host_ip
|
||||
logging.info("writing to device: {}".format(data_write))
|
||||
dut.write(data_write)
|
||||
thread1.join()
|
||||
print('Message id received from server: {}'.format(msgid))
|
||||
logging.info("Message id received from server: {}".format(msgid))
|
||||
# 3. check the message id was enqueued and then deleted
|
||||
msgid_enqueued = dut.expect(b'outbox: ENQUEUE msgid=([0-9]+)', timeout=30).group(1).decode()
|
||||
msgid_deleted = dut.expect(b'outbox: DELETED msgid=([0-9]+)', timeout=30).group(1).decode()
|
||||
msgid_enqueued = dut.expect(b"outbox: ENQUEUE msgid=([0-9]+)", timeout=30).group(1).decode()
|
||||
msgid_deleted = dut.expect(b"outbox: DELETED msgid=([0-9]+)", timeout=30).group(1).decode()
|
||||
# 4. check the msgid of received data are the same as that of enqueued and deleted from outbox
|
||||
if msgid_enqueued == str(msgid) and msgid_deleted == str(msgid):
|
||||
print('PASS: Received correct msg id')
|
||||
logging.info("PASS: Received correct msg id")
|
||||
else:
|
||||
print('Failure!')
|
||||
logging.error("Failure!")
|
||||
raise ValueError(
|
||||
'Mismatch of msgid: received: {}, enqueued {}, deleted {}'.format(msgid, msgid_enqueued, msgid_deleted)
|
||||
"Mismatch of msgid: received: {}, enqueued {}, deleted {}".format(msgid, msgid_enqueued, msgid_deleted)
|
||||
)
|
||||
thread1.join()
|
||||
|
||||
@@ -11,3 +11,4 @@ CONFIG_EXAMPLE_ETH_PHY_ADDR=1
|
||||
CONFIG_EXAMPLE_CONNECT_IPV6=y
|
||||
CONFIG_LWIP_TCPIP_CORE_LOCKING=y
|
||||
CONFIG_LWIP_CHECK_THREAD_SAFETY=y
|
||||
CONFIG_LOG_MAXIMUM_LEVEL_DEBUG=y
|
||||
|
||||
@@ -3,3 +3,4 @@ CONFIG_EXAMPLE_CONNECT_WIFI=y
|
||||
CONFIG_ESP_WIFI_REMOTE_LIBRARY_EPPP=y
|
||||
CONFIG_ESP_WIFI_REMOTE_EPPP_UART_TX_PIN=17
|
||||
CONFIG_ESP_WIFI_REMOTE_EPPP_UART_RX_PIN=16
|
||||
CONFIG_LOG_MAXIMUM_LEVEL_DEBUG=y
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
CONFIG_IDF_TARGET="esp32p4"
|
||||
CONFIG_EXAMPLE_CONNECT_WIFI=y
|
||||
CONFIG_ESP_WIFI_REMOTE_LIBRARY_HOSTED=y
|
||||
CONFIG_LOG_MAXIMUM_LEVEL_DEBUG=y
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
CONFIG_EXAMPLE_CONNECT_WIFI=n
|
||||
CONFIG_EXAMPLE_CONNECT_PPP=y
|
||||
CONFIG_EXAMPLE_CONNECT_PPP_DEVICE_UART=y
|
||||
CONFIG_LOG_MAXIMUM_LEVEL_DEBUG=y
|
||||
CONFIG_PARTITION_TABLE_SINGLE_APP_LARGE=y
|
||||
|
||||
@@ -17,15 +17,15 @@ from pytest_embedded_idf.utils import idf_parametrize
|
||||
event_client_connected = Event()
|
||||
event_stop_client = Event()
|
||||
event_client_received_correct = Event()
|
||||
message_log = ''
|
||||
message_log = ""
|
||||
|
||||
|
||||
# The callback for when the client receives a CONNACK response from the server.
|
||||
def on_connect(client, userdata, flags, rc): # type: (mqtt.Client, tuple, bool, str) -> None
|
||||
_ = (userdata, flags)
|
||||
print('Connected with result code ' + str(rc))
|
||||
print("Connected with result code " + str(rc))
|
||||
event_client_connected.set()
|
||||
client.subscribe('/topic/qos0')
|
||||
client.subscribe("/topic/qos0")
|
||||
|
||||
|
||||
def mqtt_client_task(client): # type: (mqtt.Client) -> None
|
||||
@@ -38,17 +38,17 @@ def on_message(client, userdata, msg): # type: (mqtt.Client, tuple, mqtt.client
|
||||
_ = userdata
|
||||
global message_log
|
||||
payload = msg.payload.decode()
|
||||
if not event_client_received_correct.is_set() and payload == 'data':
|
||||
client.publish('/topic/qos0', 'data_to_esp32')
|
||||
if msg.topic == '/topic/qos0' and payload == 'data':
|
||||
if not event_client_received_correct.is_set() and payload == "data":
|
||||
client.publish("/topic/qos0", "data_to_esp32")
|
||||
if msg.topic == "/topic/qos0" and payload == "data":
|
||||
event_client_received_correct.set()
|
||||
message_log += 'Received data:' + msg.topic + ' ' + payload + '\n'
|
||||
message_log += "Received data:" + msg.topic + " " + payload + "\n"
|
||||
|
||||
|
||||
@pytest.mark.ethernet
|
||||
@idf_parametrize('target', ['esp32'], indirect=['target'])
|
||||
@pytest.mark.eth_ip101
|
||||
@idf_parametrize("target", ["esp32"], indirect=["target"])
|
||||
def test_examples_protocol_mqtt_ws(dut): # type: (Dut) -> None
|
||||
broker_url = ''
|
||||
broker_url = ""
|
||||
broker_port = 0
|
||||
"""
|
||||
steps: |
|
||||
@@ -58,29 +58,29 @@ def test_examples_protocol_mqtt_ws(dut): # type: (Dut) -> None
|
||||
4. Test ESP32 client received correct qos0 message
|
||||
"""
|
||||
# check and log bin size
|
||||
binary_file = os.path.join(dut.app.binary_path, 'mqtt_websocket.bin')
|
||||
binary_file = os.path.join(dut.app.binary_path, "mqtt_websocket.bin")
|
||||
bin_size = os.path.getsize(binary_file)
|
||||
logging.info('[Performance][mqtt_websocket_bin_size]: %s KB', bin_size // 1024)
|
||||
logging.info("[Performance][mqtt_websocket_bin_size]: %s KB", bin_size // 1024)
|
||||
# Look for host:port in sdkconfig
|
||||
try:
|
||||
value = re.search(r'\:\/\/([^:]+)\:([0-9]+)', dut.app.sdkconfig.get('BROKER_URI'))
|
||||
value = re.search(r"\:\/\/([^:]+)\:([0-9]+)", dut.app.sdkconfig.get("BROKER_URI"))
|
||||
assert value is not None
|
||||
broker_url = value.group(1)
|
||||
broker_port = int(value.group(2))
|
||||
except Exception:
|
||||
print('ENV_TEST_FAILURE: Cannot find broker url in sdkconfig')
|
||||
print("ENV_TEST_FAILURE: Cannot find broker url in sdkconfig")
|
||||
raise
|
||||
client = None
|
||||
# 1. Test connects to a broker
|
||||
try:
|
||||
client = mqtt.Client(transport='websockets')
|
||||
client = mqtt.Client(transport="websockets")
|
||||
client.on_connect = on_connect
|
||||
client.on_message = on_message
|
||||
print('Connecting...')
|
||||
print("Connecting...")
|
||||
client.connect(broker_url, broker_port, 60)
|
||||
except Exception:
|
||||
print(
|
||||
'ENV_TEST_FAILURE: Unexpected error while connecting to broker {}: {}:'.format(
|
||||
"ENV_TEST_FAILURE: Unexpected error while connecting to broker {}: {}:".format(
|
||||
broker_url, sys.exc_info()[0]
|
||||
)
|
||||
)
|
||||
@@ -89,20 +89,20 @@ def test_examples_protocol_mqtt_ws(dut): # type: (Dut) -> None
|
||||
thread1 = Thread(target=mqtt_client_task, args=(client,))
|
||||
thread1.start()
|
||||
try:
|
||||
print('Connecting py-client to broker {}:{}...'.format(broker_url, broker_port))
|
||||
print("Connecting py-client to broker {}:{}...".format(broker_url, broker_port))
|
||||
if not event_client_connected.wait(timeout=30):
|
||||
raise ValueError('ENV_TEST_FAILURE: Test script cannot connect to broker: {}'.format(broker_url))
|
||||
raise ValueError("ENV_TEST_FAILURE: Test script cannot connect to broker: {}".format(broker_url))
|
||||
try:
|
||||
ip_address = dut.expect(r'IPv4 address: (\d+\.\d+\.\d+\.\d+)[^\d]', timeout=30)[0]
|
||||
print('Connected to AP with IP: {}'.format(ip_address))
|
||||
ip_address = dut.expect(r"IPv4 address: (\d+\.\d+\.\d+\.\d+)[^\d]", timeout=30)[0]
|
||||
print("Connected to AP with IP: {}".format(ip_address))
|
||||
except Dut.ExpectTimeout:
|
||||
print('ENV_TEST_FAILURE: Cannot connect to AP')
|
||||
print("ENV_TEST_FAILURE: Cannot connect to AP")
|
||||
raise
|
||||
print('Checking py-client received msg published from esp...')
|
||||
print("Checking py-client received msg published from esp...")
|
||||
if not event_client_received_correct.wait(timeout=30):
|
||||
raise ValueError('Wrong data received, msg log: {}'.format(message_log))
|
||||
print('Checking esp-client received msg published from py-client...')
|
||||
dut.expect(r'DATA=data_to_esp32', timeout=30)
|
||||
raise ValueError("Wrong data received, msg log: {}".format(message_log))
|
||||
print("Checking esp-client received msg published from py-client...")
|
||||
dut.expect(r"DATA=data_to_esp32", timeout=30)
|
||||
finally:
|
||||
event_stop_client.set()
|
||||
thread1.join()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
CONFIG_BROKER_URI="ws://${EXAMPLE_MQTT_BROKER_WS}/ws"
|
||||
CONFIG_BROKER_URI="ws://${TEST_BROKER_BRNO_WS}/ws"
|
||||
CONFIG_EXAMPLE_CONNECT_ETHERNET=y
|
||||
CONFIG_EXAMPLE_CONNECT_WIFI=n
|
||||
CONFIG_EXAMPLE_USE_INTERNAL_ETHERNET=y
|
||||
@@ -9,3 +9,4 @@ CONFIG_EXAMPLE_ETH_PHY_RST_GPIO=5
|
||||
CONFIG_EXAMPLE_ETH_PHY_ADDR=1
|
||||
CONFIG_EXAMPLE_CONNECT_IPV6=y
|
||||
CONFIG_LWIP_CHECK_THREAD_SAFETY=y
|
||||
CONFIG_LOG_MAXIMUM_LEVEL_DEBUG=y
|
||||
|
||||
@@ -19,15 +19,15 @@ from pytest_embedded_idf.utils import idf_parametrize
|
||||
event_client_connected = Event()
|
||||
event_stop_client = Event()
|
||||
event_client_received_correct = Event()
|
||||
message_log = ''
|
||||
message_log = ""
|
||||
|
||||
|
||||
# The callback for when the client receives a CONNACK response from the server.
|
||||
def on_connect(client, userdata, flags, rc): # type: (mqtt.Client, tuple, bool, str) -> None
|
||||
_ = (userdata, flags)
|
||||
print('Connected with result code ' + str(rc))
|
||||
print("Connected with result code " + str(rc))
|
||||
event_client_connected.set()
|
||||
client.subscribe('/topic/qos0')
|
||||
client.subscribe("/topic/qos0")
|
||||
|
||||
|
||||
def mqtt_client_task(client): # type: (mqtt.Client) -> None
|
||||
@@ -40,17 +40,17 @@ def on_message(client, userdata, msg): # type: (mqtt.Client, tuple, mqtt.client
|
||||
_ = userdata
|
||||
global message_log
|
||||
payload = msg.payload.decode()
|
||||
if not event_client_received_correct.is_set() and payload == 'data':
|
||||
client.publish('/topic/qos0', 'data_to_esp32')
|
||||
if msg.topic == '/topic/qos0' and payload == 'data':
|
||||
if not event_client_received_correct.is_set() and payload == "data":
|
||||
client.publish("/topic/qos0", "data_to_esp32")
|
||||
if msg.topic == "/topic/qos0" and payload == "data":
|
||||
event_client_received_correct.set()
|
||||
message_log += 'Received data:' + msg.topic + ' ' + payload + '\n'
|
||||
message_log += "Received data:" + msg.topic + " " + payload + "\n"
|
||||
|
||||
|
||||
@pytest.mark.ethernet
|
||||
@idf_parametrize('target', ['esp32'], indirect=['target'])
|
||||
@pytest.mark.eth_ip101
|
||||
@idf_parametrize("target", ["esp32"], indirect=["target"])
|
||||
def test_examples_protocol_mqtt_wss(dut): # type: (Dut) -> None # type: ignore
|
||||
broker_url = ''
|
||||
broker_url = ""
|
||||
broker_port = 0
|
||||
"""
|
||||
steps: |
|
||||
@@ -60,30 +60,30 @@ def test_examples_protocol_mqtt_wss(dut): # type: (Dut) -> None # type: ignore
|
||||
4. Test ESP32 client received correct qos0 message
|
||||
"""
|
||||
# check and log bin size
|
||||
binary_file = os.path.join(dut.app.binary_path, 'mqtt_websocket_secure.bin')
|
||||
binary_file = os.path.join(dut.app.binary_path, "mqtt_websocket_secure.bin")
|
||||
bin_size = os.path.getsize(binary_file)
|
||||
logging.info('[Performance][mqtt_websocket_secure_bin_size]: %s KB', bin_size // 1024)
|
||||
logging.info("[Performance][mqtt_websocket_secure_bin_size]: %s KB", bin_size // 1024)
|
||||
# Look for host:port in sdkconfig
|
||||
try:
|
||||
value = re.search(r'\:\/\/([^:]+)\:([0-9]+)', dut.app.sdkconfig.get('BROKER_URI'))
|
||||
value = re.search(r"\:\/\/([^:]+)\:([0-9]+)", dut.app.sdkconfig.get("BROKER_URI"))
|
||||
assert value is not None
|
||||
broker_url = value.group(1)
|
||||
broker_port = int(value.group(2))
|
||||
except Exception:
|
||||
print('ENV_TEST_FAILURE: Cannot find broker url in sdkconfig')
|
||||
print("ENV_TEST_FAILURE: Cannot find broker url in sdkconfig")
|
||||
raise
|
||||
client = None
|
||||
# 1. Test connects to a broker
|
||||
try:
|
||||
client = mqtt.Client(transport='websockets')
|
||||
client = mqtt.Client(transport="websockets")
|
||||
client.on_connect = on_connect
|
||||
client.on_message = on_message
|
||||
client.tls_set(None, None, None, cert_reqs=ssl.CERT_NONE, tls_version=ssl.PROTOCOL_TLSv1_2, ciphers=None)
|
||||
print('Connecting...')
|
||||
print("Connecting...")
|
||||
client.connect(broker_url, broker_port, 60)
|
||||
except Exception:
|
||||
print(
|
||||
'ENV_TEST_FAILURE: Unexpected error while connecting to broker {}: {}:'.format(
|
||||
"ENV_TEST_FAILURE: Unexpected error while connecting to broker {}: {}:".format(
|
||||
broker_url, sys.exc_info()[0]
|
||||
)
|
||||
)
|
||||
@@ -92,20 +92,20 @@ def test_examples_protocol_mqtt_wss(dut): # type: (Dut) -> None # type: ignore
|
||||
thread1 = Thread(target=mqtt_client_task, args=(client,))
|
||||
thread1.start()
|
||||
try:
|
||||
print('Connecting py-client to broker {}:{}...'.format(broker_url, broker_port))
|
||||
print("Connecting py-client to broker {}:{}...".format(broker_url, broker_port))
|
||||
if not event_client_connected.wait(timeout=30):
|
||||
raise ValueError('ENV_TEST_FAILURE: Test script cannot connect to broker: {}'.format(broker_url))
|
||||
raise ValueError("ENV_TEST_FAILURE: Test script cannot connect to broker: {}".format(broker_url))
|
||||
try:
|
||||
ip_address = dut.expect(r'IPv4 address: (\d+\.\d+\.\d+\.\d+)[^\d]', timeout=30)[0]
|
||||
print('Connected to AP with IP: {}'.format(ip_address))
|
||||
ip_address = dut.expect(r"IPv4 address: (\d+\.\d+\.\d+\.\d+)[^\d]", timeout=30)[0]
|
||||
print("Connected to AP with IP: {}".format(ip_address))
|
||||
except pexpect.TIMEOUT:
|
||||
print('ENV_TEST_FAILURE: Cannot connect to AP')
|
||||
print("ENV_TEST_FAILURE: Cannot connect to AP")
|
||||
raise
|
||||
print('Checking py-client received msg published from esp...')
|
||||
print("Checking py-client received msg published from esp...")
|
||||
if not event_client_received_correct.wait(timeout=30):
|
||||
raise ValueError('Wrong data received, msg log: {}'.format(message_log))
|
||||
print('Checking esp-client received msg published from py-client...')
|
||||
dut.expect(r'DATA=data_to_esp32', timeout=30)
|
||||
raise ValueError("Wrong data received, msg log: {}".format(message_log))
|
||||
print("Checking esp-client received msg published from py-client...")
|
||||
dut.expect(r"DATA=data_to_esp32", timeout=30)
|
||||
finally:
|
||||
event_stop_client.set()
|
||||
thread1.join()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
CONFIG_BROKER_URI="wss://${EXAMPLE_MQTT_BROKER_WSS}/ws"
|
||||
CONFIG_BROKER_URI="wss://${TEST_BROKER_BRNO_WSS}/ws"
|
||||
CONFIG_BROKER_CERTIFICATE_OVERRIDE="${EXAMPLE_MQTT_BROKER_CERTIFICATE}"
|
||||
CONFIG_EXAMPLE_CONNECT_ETHERNET=y
|
||||
CONFIG_EXAMPLE_CONNECT_WIFI=n
|
||||
@@ -11,3 +11,4 @@ CONFIG_EXAMPLE_ETH_PHY_ADDR=1
|
||||
CONFIG_EXAMPLE_CONNECT_IPV6=y
|
||||
CONFIG_LWIP_TCPIP_CORE_LOCKING=y
|
||||
CONFIG_LWIP_CHECK_THREAD_SAFETY=y
|
||||
CONFIG_LOG_MAXIMUM_LEVEL_DEBUG=y
|
||||
|
||||
Reference in New Issue
Block a user