diff --git a/tools/test_apps/protocols/mqtt/publish_connect_test/app_test.py b/tools/test_apps/protocols/mqtt/publish_connect_test/app_test.py index 580e28568b..738951bd0d 100644 --- a/tools/test_apps/protocols/mqtt/publish_connect_test/app_test.py +++ b/tools/test_apps/protocols/mqtt/publish_connect_test/app_test.py @@ -245,6 +245,9 @@ def connection_tests(dut, cases): set_server_cert_cn(ip) server_port = 2222 + def teardown_connection_suite(): + dut.write('conn teardown 0 0') + def start_connection_case(case, desc): print('Starting {}: {}'.format(case, desc)) case_id = cases[case] @@ -301,6 +304,8 @@ def connection_tests(dut, cases): else: raise Exception('Unexpected negotiated protocol {}'.format(s.get_negotiated_protocol())) + teardown_connection_suite() + @ttfw_idf.idf_custom_test(env_tag='Example_WIFI', group='test-apps') def test_app_protocol_mqtt_publish_connect(env, extra_data): diff --git a/tools/test_apps/protocols/mqtt/publish_connect_test/main/connect_test.c b/tools/test_apps/protocols/mqtt/publish_connect_test/main/connect_test.c index 112c000f59..aa03f1988c 100644 --- a/tools/test_apps/protocols/mqtt/publish_connect_test/main/connect_test.c +++ b/tools/test_apps/protocols/mqtt/publish_connect_test/main/connect_test.c @@ -70,6 +70,17 @@ static void create_client(void) esp_mqtt_client_register_event(client, ESP_EVENT_ANY_ID, mqtt_event_handler, client); mqtt_client = client; esp_mqtt_client_start(client); + ESP_LOGI(TAG, "mqtt client created for connection tests"); +} + +static void destroy_client(void) +{ + if (mqtt_client) { + esp_mqtt_client_stop(mqtt_client); + esp_mqtt_client_destroy(mqtt_client); + mqtt_client = NULL; + ESP_LOGI(TAG, "mqtt client for connection tests destroyed"); + } } static void connect_no_certs(const char *host, const int port) @@ -200,6 +211,9 @@ void connection_test(const char *line) if (mqtt_client == NULL) { create_client(); } + if (strcmp(host, "teardown") == 0) { + destroy_client();; + } ESP_LOGI(TAG, "CASE:%d, connecting to mqtts://%s:%d ", test_case, host, port); running_test_case = test_case; switch (test_case) { diff --git a/tools/test_apps/protocols/mqtt/publish_connect_test/main/publish_test.c b/tools/test_apps/protocols/mqtt/publish_connect_test/main/publish_test.c index 8801a4983f..38cd136273 100644 --- a/tools/test_apps/protocols/mqtt/publish_connect_test/main/publish_test.c +++ b/tools/test_apps/protocols/mqtt/publish_connect_test/main/publish_test.c @@ -159,17 +159,12 @@ static void configure_client(char *transport) if (selected_transport != current_transport) { esp_mqtt_client_config_t config = {0}; - if (selected_transport == SSL || selected_transport == WSS) { - ESP_LOGI(TAG, "Set certificate"); - config.cert_pem = (const char *)mqtt_eclipseprojects_io_pem_start; - esp_mqtt_set_config(mqtt_client, &config); - } switch (selected_transport) { case NONE: break; case TCP: ESP_LOGI(TAG, "[TCP transport] Startup.."); - esp_mqtt_client_set_uri(mqtt_client, CONFIG_EXAMPLE_BROKER_TCP_URI); + config.uri = CONFIG_EXAMPLE_BROKER_TCP_URI; break; case SSL: ESP_LOGI(TAG, "[SSL transport] Startup.."); @@ -177,14 +172,21 @@ static void configure_client(char *transport) break; case WS: ESP_LOGI(TAG, "[WS transport] Startup.."); - esp_mqtt_client_set_uri(mqtt_client, CONFIG_EXAMPLE_BROKER_WS_URI); + config.uri = CONFIG_EXAMPLE_BROKER_WS_URI; break; case WSS: ESP_LOGI(TAG, "[WSS transport] Startup.."); - esp_mqtt_client_set_uri(mqtt_client, CONFIG_EXAMPLE_BROKER_WSS_URI); + config.uri = CONFIG_EXAMPLE_BROKER_WSS_URI; break; } + if (selected_transport == SSL || selected_transport == WSS) { + ESP_LOGI(TAG, "Set certificate"); + config.cert_pem = (const char *)mqtt_eclipseprojects_io_pem_start; + } + esp_mqtt_set_config(mqtt_client, &config); + } + } void publish_test(const char *line) { @@ -193,12 +195,12 @@ void publish_test(const char *line) int repeat = 0; int enqueue = 0; - esp_mqtt_client_stop(mqtt_client); - static bool is_test_init = false; if (!is_test_init) { test_init(); is_test_init = true; + } else { + esp_mqtt_client_stop(mqtt_client); } sscanf(line, "%s %s %d %d %d %d", transport, pattern, &repeat, &expected_published, &qos_test, &enqueue);