kopia lustrzana https://github.com/espressif/esp-idf
Merge branch 'bugfix/mqtt_test_publish_less_data' into 'master'
ci: Make the mqtt example test to send only portion of the partition Closes IDFCI-267 See merge request espressif/esp-idf!12160pull/7261/head
commit
942de74a6c
|
@ -17,4 +17,10 @@ menu "Example Configuration"
|
|||
bool
|
||||
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
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "mqtt_client.h"
|
||||
#include "esp_tls.h"
|
||||
#include "esp_ota_ops.h"
|
||||
#include <sys/param.h>
|
||||
|
||||
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");
|
||||
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
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 esp_partition_t* partition = esp_ota_get_running_partition();
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -36,20 +36,19 @@ def on_message(client, userdata, msg):
|
|||
global event_client_received_correct
|
||||
global event_client_received_binary
|
||||
if msg.topic == '/topic/binary':
|
||||
binary = userdata
|
||||
size = os.path.getsize(binary)
|
||||
print('Receiving binary from esp and comparing with {}, size {}...'.format(binary, size))
|
||||
binary, bin_size = userdata
|
||||
print('Receiving binary from esp and comparing with {}, size {}...'.format(binary, bin_size))
|
||||
with open(binary, 'rb') as f:
|
||||
bin = f.read()
|
||||
if bin == msg.payload[:size]:
|
||||
if bin[:bin_size] == msg.payload[:bin_size]:
|
||||
print('...matches!')
|
||||
event_client_received_binary.set()
|
||||
return
|
||||
else:
|
||||
recv_binary = binary + '.received'
|
||||
with open(recv_binary, 'w') as fw:
|
||||
fw.write(msg.payload)
|
||||
raise ValueError('Received binary (saved as: {}) does not match the original file: {}'.format(recv_binary, binary))
|
||||
recv_binary = binary + '.received'
|
||||
with open(recv_binary, 'w') as fw:
|
||||
fw.write(msg.payload)
|
||||
raise ValueError('Received binary (saved as: {}) does not match the original file: {}'.format(recv_binary, binary))
|
||||
|
||||
payload = msg.payload.decode()
|
||||
if not event_client_received_correct.is_set() and payload == 'data':
|
||||
client.subscribe('/topic/binary')
|
||||
|
@ -64,7 +63,7 @@ def test_examples_protocol_mqtt_ssl(env, extra_data):
|
|||
broker_url = ''
|
||||
broker_port = 0
|
||||
"""
|
||||
steps: |
|
||||
steps:
|
||||
1. join AP and connects to ssl broker
|
||||
2. Test connects a client to the same broker
|
||||
3. Test evaluates python client received correct qos0 message
|
||||
|
@ -82,6 +81,7 @@ def test_examples_protocol_mqtt_ssl(env, extra_data):
|
|||
value = re.search(r'\:\/\/([^:]+)\:([0-9]+)', dut1.app.get_sdkconfig()['CONFIG_BROKER_URI'])
|
||||
broker_url = value.group(1)
|
||||
broker_port = int(value.group(2))
|
||||
bin_size = min(int(dut1.app.get_sdkconfig()['CONFIG_BROKER_BIN_SIZE_TO_SEND']), bin_size)
|
||||
except Exception:
|
||||
print('ENV_TEST_FAILURE: Cannot find broker url in sdkconfig')
|
||||
raise
|
||||
|
@ -91,7 +91,7 @@ def test_examples_protocol_mqtt_ssl(env, extra_data):
|
|||
client = mqtt.Client()
|
||||
client.on_connect = on_connect
|
||||
client.on_message = on_message
|
||||
client.user_data_set(binary_file)
|
||||
client.user_data_set((binary_file, bin_size))
|
||||
client.tls_set(None,
|
||||
None,
|
||||
None, cert_reqs=ssl.CERT_NONE, tls_version=ssl.PROTOCOL_TLSv1_2, ciphers=None)
|
||||
|
|
Ładowanie…
Reference in New Issue