Merge branch 'bugfix/mqtt_test_publish_less_data_v4.2' into 'release/v4.2'

ci: Make the mqtt example test to send only portion of the partition (v4.2)

See merge request espressif/esp-idf!14112
This commit is contained in:
Anton Maklakov 2021-06-23 15:18:23 +00:00
commit f4b556fdf9
3 changed files with 25 additions and 16 deletions

View File

@ -17,4 +17,10 @@ menu "Example Configuration"
bool bool
default y if BROKER_CERTIFICATE_OVERRIDE != "" default y if BROKER_CERTIFICATE_OVERRIDE != ""
config BROKER_BIN_SIZE_TO_SEND
# This option is not visible and is used only to set parameters for example tests
# Here we configure the data size to send and to be expected in the python script
int
default 20000
endmenu endmenu

View File

@ -21,6 +21,7 @@
#include "mqtt_client.h" #include "mqtt_client.h"
#include "esp_tls.h" #include "esp_tls.h"
#include "esp_ota_ops.h" #include "esp_ota_ops.h"
#include <sys/param.h>
static const char *TAG = "MQTTS_EXAMPLE"; static const char *TAG = "MQTTS_EXAMPLE";
@ -33,7 +34,7 @@ extern const uint8_t mqtt_eclipse_org_pem_start[] asm("_binary_mqtt_eclipse_or
extern const uint8_t mqtt_eclipse_org_pem_end[] asm("_binary_mqtt_eclipse_org_pem_end"); extern const uint8_t mqtt_eclipse_org_pem_end[] asm("_binary_mqtt_eclipse_org_pem_end");
// //
// Note: this function is for testing purposes only publishing the entire active partition // Note: this function is for testing purposes only publishing part of the active partition
// (to be checked against the original binary) // (to be checked against the original binary)
// //
static void send_binary(esp_mqtt_client_handle_t client) static void send_binary(esp_mqtt_client_handle_t client)
@ -42,7 +43,9 @@ static void send_binary(esp_mqtt_client_handle_t client)
const void *binary_address; const void *binary_address;
const esp_partition_t* partition = esp_ota_get_running_partition(); const esp_partition_t* partition = esp_ota_get_running_partition();
esp_partition_mmap(partition, 0, partition->size, SPI_FLASH_MMAP_DATA, &binary_address, &out_handle); esp_partition_mmap(partition, 0, partition->size, SPI_FLASH_MMAP_DATA, &binary_address, &out_handle);
int msg_id = esp_mqtt_client_publish(client, "/topic/binary", binary_address, partition->size, 0, 0); // sending only the configured portion of the partition (if it's less than the partition size)
int binary_size = MIN(CONFIG_BROKER_BIN_SIZE_TO_SEND,partition->size);
int msg_id = esp_mqtt_client_publish(client, "/topic/binary", binary_address, binary_size, 0, 0);
ESP_LOGI(TAG, "binary sent with msg_id=%d", msg_id); ESP_LOGI(TAG, "binary sent with msg_id=%d", msg_id);
} }

View File

@ -36,21 +36,20 @@ def on_message(client, userdata, msg):
global message_log global message_log
global event_client_received_correct global event_client_received_correct
global event_client_received_binary global event_client_received_binary
if msg.topic == "/topic/binary": if msg.topic == '/topic/binary':
binary = userdata binary, bin_size = userdata
size = os.path.getsize(binary) print('Receiving binary from esp and comparing with {}, size {}...'.format(binary, bin_size))
print("Receiving binary from esp and comparing with {}, size {}...".format(binary, size)) with open(binary, 'rb') as f:
with open(binary, "rb") as f:
bin = f.read() bin = f.read()
if bin == msg.payload[:size]: if bin[:bin_size] == msg.payload[:bin_size]:
print("...matches!") print('...matches!')
event_client_received_binary.set() event_client_received_binary.set()
return return
else: recv_binary = binary + '.received'
recv_binary = binary + ".received" with open(recv_binary, 'w') as fw:
with open(recv_binary, "w") as fw: fw.write(msg.payload)
fw.write(msg.payload) raise ValueError('Received binary (saved as: {}) does not match the original file: {}'.format(recv_binary, binary))
raise ValueError('Received binary (saved as: {}) does not match the original file: {}'.format(recv_binary, binary))
payload = msg.payload.decode() payload = msg.payload.decode()
if not event_client_received_correct.is_set() and payload == "data": if not event_client_received_correct.is_set() and payload == "data":
client.subscribe("/topic/binary") client.subscribe("/topic/binary")
@ -65,7 +64,7 @@ def test_examples_protocol_mqtt_ssl(env, extra_data):
broker_url = "" broker_url = ""
broker_port = 0 broker_port = 0
""" """
steps: | steps:
1. join AP and connects to ssl broker 1. join AP and connects to ssl broker
2. Test connects a client to the same broker 2. Test connects a client to the same broker
3. Test evaluates python client received correct qos0 message 3. Test evaluates python client received correct qos0 message
@ -84,6 +83,7 @@ def test_examples_protocol_mqtt_ssl(env, extra_data):
value = re.search(r'\:\/\/([^:]+)\:([0-9]+)', dut1.app.get_sdkconfig()["CONFIG_BROKER_URI"]) value = re.search(r'\:\/\/([^:]+)\:([0-9]+)', dut1.app.get_sdkconfig()["CONFIG_BROKER_URI"])
broker_url = value.group(1) broker_url = value.group(1)
broker_port = int(value.group(2)) broker_port = int(value.group(2))
bin_size = min(int(dut1.app.get_sdkconfig()['CONFIG_BROKER_BIN_SIZE_TO_SEND']), bin_size)
except Exception: except Exception:
print('ENV_TEST_FAILURE: Cannot find broker url in sdkconfig') print('ENV_TEST_FAILURE: Cannot find broker url in sdkconfig')
raise raise
@ -93,7 +93,7 @@ def test_examples_protocol_mqtt_ssl(env, extra_data):
client = mqtt.Client() client = mqtt.Client()
client.on_connect = on_connect client.on_connect = on_connect
client.on_message = on_message client.on_message = on_message
client.user_data_set(binary_file) client.user_data_set((binary_file, bin_size))
client.tls_set(None, client.tls_set(None,
None, None,
None, cert_reqs=ssl.CERT_NONE, tls_version=ssl.PROTOCOL_TLSv1_2, ciphers=None) None, cert_reqs=ssl.CERT_NONE, tls_version=ssl.PROTOCOL_TLSv1_2, ciphers=None)