kopia lustrzana https://github.com/espressif/esp-idf
change: Improve mqtt publish connect tests
- Add random client id on each iteration - Make timeout configuration dependent on more scenario parameterspull/15023/head
rodzic
881bd1bf66
commit
72fbf37648
|
@ -14,6 +14,7 @@
|
|||
#include "freertos/FreeRTOS.h"
|
||||
#include <freertos/event_groups.h>
|
||||
#include "esp_system.h"
|
||||
#include "esp_random.h"
|
||||
|
||||
#include "esp_log.h"
|
||||
#include "mqtt_client.h"
|
||||
|
@ -24,7 +25,7 @@ static const char *TAG = "publish_test";
|
|||
|
||||
static EventGroupHandle_t mqtt_event_group;
|
||||
const static int CONNECTED_BIT = BIT0;
|
||||
|
||||
#define CLIENT_ID_SUFFIX_SIZE 12
|
||||
#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-----";
|
||||
#else
|
||||
|
@ -101,8 +102,6 @@ static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void test_init(void)
|
||||
{
|
||||
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");
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
# SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
|
||||
import contextlib
|
||||
import difflib
|
||||
import logging
|
||||
|
@ -41,7 +42,8 @@ class MqttPublisher(mqtt.Client):
|
|||
self.event_client_connected = Event()
|
||||
self.event_client_got_all = Event()
|
||||
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
|
||||
if self.log_details:
|
||||
|
@ -156,9 +158,14 @@ def get_scenarios() -> List[Dict[str, int]]:
|
|||
|
||||
def get_timeout(test_case: Any) -> int:
|
||||
transport, qos, enqueue, scenario = test_case
|
||||
if transport in ['ws', 'wss'] or qos == 2:
|
||||
return 120
|
||||
return 60
|
||||
timeout = int(scenario['repeat'] * 10)
|
||||
if qos == 1:
|
||||
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:
|
||||
|
@ -172,7 +179,7 @@ def run_publish_test_case(dut: Dut, test_case: Any, publish_cfg: Any) -> None:
|
|||
publish_cfg['transport'] = transport
|
||||
test_timeout = get_timeout(test_case)
|
||||
logging.info(f'Starting Publish test: transport:{transport}, qos:{qos}, nr_of_msgs:{published},'
|
||||
f' msg_size:{repeat*DEFAULT_MSG_SIZE}, enqueue:{enqueue}')
|
||||
f' msg_size:{repeat * DEFAULT_MSG_SIZE}, enqueue:{enqueue}')
|
||||
with MqttPublisher(repeat, published, publish_cfg) as publisher, connected_and_subscribed(dut, transport, publisher.sample_string, scenario['len']):
|
||||
msgs_published: List[mqtt.MQTTMessageInfo] = []
|
||||
dut.write(f'publish {publisher.published} {qos} {enqueue}')
|
||||
|
@ -193,13 +200,13 @@ def run_publish_test_case(dut: Dut, test_case: Any, publish_cfg: Any) -> None:
|
|||
try:
|
||||
dut.expect(re.compile(rb'Correct pattern received exactly x times'), timeout=test_timeout)
|
||||
except pexpect.exceptions.ExceptionPexpect:
|
||||
dut.write(f'publish_report')
|
||||
dut.write('publish_report')
|
||||
dut.expect(re.compile(rb'Test Report'), timeout=30)
|
||||
raise
|
||||
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']
|
||||
qos_cases = [0, 1, 2]
|
||||
enqueue_cases = [0, 1]
|
||||
|
|
Ładowanie…
Reference in New Issue