Skip to content

Commit 14e3889

Browse files
committed
Merge branch 'feature/update_mqtt_component' into 'master'
feat(mqtt): update mqtt component and examples from idf See merge request sdk/ESP8266_RTOS_SDK!1587
2 parents b7ed53b + 7d7b70c commit 14e3889

37 files changed

+395
-457
lines changed

components/mqtt/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,3 @@ idf_component_register(SRCS "esp-mqtt/mqtt_client.c"
55
INCLUDE_DIRS esp-mqtt/include
66
PRIV_INCLUDE_DIRS "esp-mqtt/lib/include"
77
REQUIRES lwip http_parser mbedtls tcp_transport)
8-
9-
target_compile_definitions(${COMPONENT_LIB} PUBLIC -DMQTT_SUPPORTED_FEATURE_WS_SUBPROTOCOL -DMQTT_SUPPORTED_FEATURE_TRANSPORT_ERR_REPORTING)

components/mqtt/Kconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,13 @@ menu "ESP-MQTT Configurations"
8686
Default config employs API locks to protect internal structures. It is possible to disable
8787
these locks if the user code doesn't access MQTT API from multiple concurrent tasks
8888

89+
config MQTT_TASK_PRIORITY
90+
int "MQTT task priority"
91+
default 5
92+
depends on MQTT_USE_CUSTOM_CONFIG
93+
help
94+
MQTT task priority. Higher number denotes higher priority.
95+
8996
config MQTT_TASK_CORE_SELECTION_ENABLED
9097
bool "Enable MQTT task core selection"
9198
default false

components/mqtt/component.mk

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,3 @@ COMPONENT_SUBMODULES += esp-mqtt
22
COMPONENT_ADD_INCLUDEDIRS := esp-mqtt/include
33
COMPONENT_SRCDIRS := esp-mqtt esp-mqtt/lib
44
COMPONENT_PRIV_INCLUDEDIRS := esp-mqtt/lib/include
5-
#Due to RTOS version is lower than idf 4.0, so move some define in file mqtt_supported_features.h to here.
6-
CFLAGS += -DMQTT_SUPPORTED_FEATURE_WS_SUBPROTOCOL -DMQTT_SUPPORTED_FEATURE_TRANSPORT_ERR_REPORTING

components/mqtt/test/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
idf_component_register(SRC_DIRS "."
2+
PRIV_REQUIRES unity test_utils mqtt nvs_flash app_update)

components/mqtt/test/component.mk

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#
2+
#Component Makefile
3+
#
4+
COMPONENT_ADD_LDFLAGS = -Wl,--whole-archive -l$(COMPONENT_NAME) -Wl,--no-whole-archive

components/mqtt/test/test_mqtt.c

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#include "test_utils.h"
2+
#include "mqtt_client.h"
3+
#include "unity.h"
4+
#include <sys/time.h>
5+
#include "nvs_flash.h"
6+
#include "esp_ota_ops.h"
7+
8+
static void test_leak_setup(const char * file, long line)
9+
{
10+
uint8_t mac[6];
11+
struct timeval te;
12+
gettimeofday(&te, NULL); // get current time
13+
esp_read_mac(mac, ESP_MAC_WIFI_STA);
14+
printf("%s:%ld: time=%ld.%lds, mac:" MACSTR "\n", file, line, te.tv_sec, te.tv_usec, MAC2STR(mac));
15+
unity_reset_leak_checks();
16+
}
17+
18+
TEST_CASE("mqtt init with invalid url", "[mqtt][leaks=0]")
19+
{
20+
test_leak_setup(__FILE__, __LINE__);
21+
const esp_mqtt_client_config_t mqtt_cfg = {
22+
.uri = "INVALID",
23+
};
24+
esp_mqtt_client_handle_t client = esp_mqtt_client_init(&mqtt_cfg);
25+
TEST_ASSERT_EQUAL(NULL, client );
26+
}
27+
28+
TEST_CASE("mqtt init and deinit", "[mqtt][leaks=0]")
29+
{
30+
test_leak_setup(__FILE__, __LINE__);
31+
const esp_mqtt_client_config_t mqtt_cfg = {
32+
// no connection takes place, but the uri has to be valid for init() to succeed
33+
.uri = "mqtts://localhost:8883",
34+
};
35+
esp_mqtt_client_handle_t client = esp_mqtt_client_init(&mqtt_cfg);
36+
TEST_ASSERT_NOT_EQUAL(NULL, client );
37+
esp_mqtt_client_destroy(client);
38+
}
39+
40+
static const char* this_bin_addr(void)
41+
{
42+
spi_flash_mmap_handle_t out_handle;
43+
const void *binary_address;
44+
const esp_partition_t* partition = esp_ota_get_running_partition();
45+
esp_partition_mmap(partition, 0, partition->size, SPI_FLASH_MMAP_DATA, &binary_address, &out_handle);
46+
return binary_address;
47+
}
48+
49+
TEST_CASE("mqtt enqueue and destroy outbox", "[mqtt][leaks=0]")
50+
{
51+
const char * bin_addr = this_bin_addr();
52+
test_leak_setup(__FILE__, __LINE__);
53+
const int messages = 20;
54+
const int size = 2000;
55+
const esp_mqtt_client_config_t mqtt_cfg = {
56+
// no connection takes place, but the uri has to be valid for init() to succeed
57+
.uri = "mqtts://localhost:8883",
58+
};
59+
esp_mqtt_client_handle_t client = esp_mqtt_client_init(&mqtt_cfg);
60+
TEST_ASSERT_NOT_EQUAL(NULL, client );
61+
int bytes_before = esp_get_free_heap_size();
62+
for (int i=0; i<messages; ++i) {
63+
esp_mqtt_client_publish(client, "test", bin_addr, size, 1, 0);
64+
}
65+
int bytes_after = esp_get_free_heap_size();
66+
// check that outbox allocated all messages on heap
67+
TEST_ASSERT_GREATER_OR_EQUAL(messages*size, bytes_before - bytes_after);
68+
69+
esp_mqtt_client_destroy(client);
70+
}

components/mqtt/weekend_test/mqtt_publish_test.py

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from __future__ import unicode_literals
33
from builtins import str
44
import re
5-
import os
65
import sys
76
import ssl
87
import paho.mqtt.client as mqtt
@@ -11,19 +10,8 @@
1110
import string
1211
import random
1312

14-
try:
15-
import IDF
16-
except ImportError:
17-
# this is a test case write with tiny-test-fw.
18-
# to run test cases outside tiny-test-fw,
19-
# we need to set environment variable `TEST_FW_PATH`,
20-
# then get and insert `TEST_FW_PATH` to sys path before import FW module
21-
test_fw_path = os.getenv("TEST_FW_PATH")
22-
if test_fw_path and test_fw_path not in sys.path:
23-
sys.path.insert(0, test_fw_path)
24-
import IDF
25-
26-
import DUT
13+
from tiny_test_fw import DUT
14+
import ttfw_idf
2715

2816

2917
event_client_connected = Event()
@@ -52,6 +40,8 @@ def mqtt_client_task(client):
5240

5341
def get_host_port_from_dut(dut1, config_option):
5442
value = re.search(r'\:\/\/([^:]+)\:([0-9]+)', dut1.app.get_sdkconfig()[config_option])
43+
if value is None:
44+
return None, None
5545
return value.group(1), int(value.group(2))
5646

5747

@@ -123,7 +113,7 @@ def test_single_config(dut, transport, qos, repeat, published):
123113
event_stop_client.clear()
124114

125115

126-
@IDF.idf_example_test(env_tag="Example_WIFI")
116+
@ttfw_idf.idf_custom_test(env_tag="Example_WIFI")
127117
def test_weekend_mqtt_publish(env, extra_data):
128118
# Using broker url dictionary for different transport
129119
global broker_host
@@ -137,13 +127,7 @@ def test_weekend_mqtt_publish(env, extra_data):
137127
3. Test evaluates python client received correct qos0 message
138128
4. Test ESP32 client received correct qos0 message
139129
"""
140-
dut1 = env.get_dut("mqtt_publish", "examples/protocols/mqtt/publish_test")
141-
# check and log bin size
142-
binary_file = os.path.join(dut1.app.binary_path, "mqtt_publish.bin")
143-
bin_size = os.path.getsize(binary_file)
144-
IDF.log_performance("mqtt_publish_bin_size", "{}KB"
145-
.format(bin_size // 1024))
146-
IDF.check_performance("mqtt_publish_size", bin_size // 1024)
130+
dut1 = env.get_dut("mqtt_publish_connect_test", "tools/test_apps/protocols/mqtt/publish_connect_test")
147131
# Look for host:port in sdkconfig
148132
try:
149133
# python client subscribes to the topic to which esp client publishes and vice versa
@@ -158,13 +142,16 @@ def test_weekend_mqtt_publish(env, extra_data):
158142
raise
159143
dut1.start_app()
160144
try:
161-
ip_address = dut1.expect(re.compile(r" sta ip: ([^,]+),"), timeout=30)
145+
ip_address = dut1.expect(re.compile(r" IPv4 address: ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)"), timeout=30)
162146
print("Connected to AP with IP: {}".format(ip_address))
163147
except DUT.ExpectTimeout:
164148
print('ENV_TEST_FAILURE: Cannot connect to AP')
165149
raise
166150
for qos in [0, 1, 2]:
167151
for transport in ["tcp", "ssl", "ws", "wss"]:
152+
if broker_host[transport] is None:
153+
print('Skipping transport: {}...'.format(transport))
154+
continue
168155
# simple test with empty message
169156
test_single_config(dut1, transport, qos, 0, 5)
170157
# decide on broker what level of test will pass (local broker works the best)
@@ -188,4 +175,4 @@ def test_weekend_mqtt_publish(env, extra_data):
188175

189176

190177
if __name__ == '__main__':
191-
test_weekend_mqtt_publish()
178+
test_weekend_mqtt_publish(dut=ttfw_idf.ESP32QEMUDUT if sys.argv[1:] == ['qemu'] else ttfw_idf.ESP32DUT)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CaseConfig:
2+
- name: test_weekend_mqtt_publish
3+
overwrite:
4+
dut:
5+
class: ESP32QEMUDUT
6+
package: ttfw_idf
7+

examples/protocols/mqtt/publish_test/README.md

Lines changed: 0 additions & 85 deletions
This file was deleted.

examples/protocols/mqtt/publish_test/main/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
This file was deleted.

examples/protocols/mqtt/publish_test/main/Kconfig.projbuild

Lines changed: 0 additions & 50 deletions
This file was deleted.

examples/protocols/mqtt/publish_test/main/component.mk

Lines changed: 0 additions & 1 deletion
This file was deleted.

examples/protocols/mqtt/publish_test/main/mqtt_eclipse_org.pem

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)