forked from espressif/esp-idf
change: Improve mqtt publish connect tests
- Add random client id on each iteration - Make timeout configuration dependent on more scenario parameters
This commit is contained in:
@@ -14,6 +14,7 @@
|
|||||||
#include "freertos/FreeRTOS.h"
|
#include "freertos/FreeRTOS.h"
|
||||||
#include <freertos/event_groups.h>
|
#include <freertos/event_groups.h>
|
||||||
#include "esp_system.h"
|
#include "esp_system.h"
|
||||||
|
#include "esp_random.h"
|
||||||
|
|
||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
#include "mqtt_client.h"
|
#include "mqtt_client.h"
|
||||||
@@ -24,7 +25,7 @@ static const char *TAG = "publish_test";
|
|||||||
|
|
||||||
static EventGroupHandle_t mqtt_event_group;
|
static EventGroupHandle_t mqtt_event_group;
|
||||||
const static int CONNECTED_BIT = BIT0;
|
const static int CONNECTED_BIT = BIT0;
|
||||||
|
#define CLIENT_ID_SUFFIX_SIZE 12
|
||||||
#if CONFIG_EXAMPLE_BROKER_CERTIFICATE_OVERRIDDEN == 1
|
#if CONFIG_EXAMPLE_BROKER_CERTIFICATE_OVERRIDDEN == 1
|
||||||
static const uint8_t mqtt_eclipseprojects_io_pem_start[] = "-----BEGIN CERTIFICATE-----\n" CONFIG_EXAMPLE_BROKER_CERTIFICATE_OVERRIDE "\n-----END CERTIFICATE-----";
|
static const uint8_t mqtt_eclipseprojects_io_pem_start[] = "-----BEGIN CERTIFICATE-----\n" CONFIG_EXAMPLE_BROKER_CERTIFICATE_OVERRIDE "\n-----END CERTIFICATE-----";
|
||||||
#else
|
#else
|
||||||
@@ -101,8 +102,6 @@ static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void test_init(void)
|
void test_init(void)
|
||||||
{
|
{
|
||||||
ESP_LOGI(TAG, "[APP] Free memory: %d bytes", esp_get_free_heap_size());
|
ESP_LOGI(TAG, "[APP] Free memory: %d bytes", esp_get_free_heap_size());
|
||||||
@@ -169,6 +168,10 @@ static void configure_client(command_context_t * ctx, const char *transport)
|
|||||||
ESP_LOGI(TAG, "Set certificate");
|
ESP_LOGI(TAG, "Set certificate");
|
||||||
config.broker.verification.certificate = (const char *)mqtt_eclipseprojects_io_pem_start;
|
config.broker.verification.certificate = (const char *)mqtt_eclipseprojects_io_pem_start;
|
||||||
}
|
}
|
||||||
|
// Generate a random client id for each iteration
|
||||||
|
char client_id[CLIENT_ID_SUFFIX_SIZE] = {0};
|
||||||
|
snprintf(client_id, sizeof(client_id), "esp32-%08X", esp_random());
|
||||||
|
config.credentials.client_id = client_id;
|
||||||
esp_mqtt_set_config(ctx->mqtt_client, &config);
|
esp_mqtt_set_config(ctx->mqtt_client, &config);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
# SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
|
# SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
|
||||||
# SPDX-License-Identifier: Unlicense OR CC0-1.0
|
# SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||||
|
|
||||||
import contextlib
|
import contextlib
|
||||||
import difflib
|
import difflib
|
||||||
import logging
|
import logging
|
||||||
@@ -41,7 +42,8 @@ class MqttPublisher(mqtt.Client):
|
|||||||
self.event_client_connected = Event()
|
self.event_client_connected = Event()
|
||||||
self.event_client_got_all = Event()
|
self.event_client_got_all = Event()
|
||||||
transport = 'websockets' if self.publish_cfg['transport'] in ['ws', 'wss'] else 'tcp'
|
transport = 'websockets' if self.publish_cfg['transport'] in ['ws', 'wss'] else 'tcp'
|
||||||
super().__init__('MqttTestRunner', userdata=0, transport=transport)
|
client_id = 'MqttTestRunner' + ''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase) for _ in range(5))
|
||||||
|
super().__init__(client_id, userdata=0, transport=transport)
|
||||||
|
|
||||||
def print_details(self, text): # type: (str) -> None
|
def print_details(self, text): # type: (str) -> None
|
||||||
if self.log_details:
|
if self.log_details:
|
||||||
@@ -156,9 +158,14 @@ def get_scenarios() -> List[Dict[str, int]]:
|
|||||||
|
|
||||||
def get_timeout(test_case: Any) -> int:
|
def get_timeout(test_case: Any) -> int:
|
||||||
transport, qos, enqueue, scenario = test_case
|
transport, qos, enqueue, scenario = test_case
|
||||||
if transport in ['ws', 'wss'] or qos == 2:
|
timeout = int(scenario['repeat'] * 10)
|
||||||
return 120
|
if qos == 1:
|
||||||
return 60
|
timeout += 30
|
||||||
|
if qos == 2:
|
||||||
|
timeout += 45
|
||||||
|
if transport in ['ws', 'wss']:
|
||||||
|
timeout += 30
|
||||||
|
return timeout
|
||||||
|
|
||||||
|
|
||||||
def run_publish_test_case(dut: Dut, test_case: Any, publish_cfg: Any) -> None:
|
def run_publish_test_case(dut: Dut, test_case: Any, publish_cfg: Any) -> None:
|
||||||
@@ -193,13 +200,13 @@ def run_publish_test_case(dut: Dut, test_case: Any, publish_cfg: Any) -> None:
|
|||||||
try:
|
try:
|
||||||
dut.expect(re.compile(rb'Correct pattern received exactly x times'), timeout=test_timeout)
|
dut.expect(re.compile(rb'Correct pattern received exactly x times'), timeout=test_timeout)
|
||||||
except pexpect.exceptions.ExceptionPexpect:
|
except pexpect.exceptions.ExceptionPexpect:
|
||||||
dut.write(f'publish_report')
|
dut.write('publish_report')
|
||||||
dut.expect(re.compile(rb'Test Report'), timeout=30)
|
dut.expect(re.compile(rb'Test Report'), timeout=30)
|
||||||
raise
|
raise
|
||||||
logging.info('ESP32 received all data from runner')
|
logging.info('ESP32 received all data from runner')
|
||||||
|
|
||||||
|
|
||||||
stress_scenarios = [{'len':20, 'repeat':50}] # many medium sized
|
stress_scenarios = [{'len':20, 'repeat':30}] # many medium sized
|
||||||
transport_cases = ['tcp', 'ws', 'wss', 'ssl']
|
transport_cases = ['tcp', 'ws', 'wss', 'ssl']
|
||||||
qos_cases = [0, 1, 2]
|
qos_cases = [0, 1, 2]
|
||||||
enqueue_cases = [0, 1]
|
enqueue_cases = [0, 1]
|
||||||
|
Reference in New Issue
Block a user