From b148433fbd39baf229902182e28568cc35b40d93 Mon Sep 17 00:00:00 2001 From: Shubham Kulkarni Date: Tue, 30 Mar 2021 12:46:24 +0530 Subject: [PATCH 1/2] esp_http_client_read: Add check for esp_http_client_is_complete_data_received before returning ESP_FAIL Closes: https://github.com/espressif/esp-idf/issues/6772 --- components/esp_http_client/esp_http_client.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/esp_http_client/esp_http_client.c b/components/esp_http_client/esp_http_client.c index 5f1154cccf..aa3c81242e 100644 --- a/components/esp_http_client/esp_http_client.c +++ b/components/esp_http_client/esp_http_client.c @@ -991,7 +991,7 @@ int esp_http_client_read(esp_http_client_handle_t client, char *buffer, int len) } ESP_LOG_LEVEL(sev, TAG, "esp_transport_read returned:%d and errno:%d ", rlen, errno); } - if (rlen < 0 && ridx == 0) { + if (rlen < 0 && ridx == 0 && !esp_http_client_is_complete_data_received(client)) { return ESP_FAIL; } else { return ridx; From 691e30e659ce77f059d131db5ee9354872f39f88 Mon Sep 17 00:00:00 2001 From: Shubham Kulkarni Date: Mon, 19 Apr 2021 12:47:06 +0530 Subject: [PATCH 2/2] advanced_https_ota: Add example test for OTA with OpenSSL server with binary file aligned to 289 byte boundary --- .gitlab/ci/target-test.yml | 1 + .../ota/advanced_https_ota/example_test.py | 50 +++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/.gitlab/ci/target-test.yml b/.gitlab/ci/target-test.yml index ee8e0bd7ce..d0e33adc65 100644 --- a/.gitlab/ci/target-test.yml +++ b/.gitlab/ci/target-test.yml @@ -121,6 +121,7 @@ example_test_001D: example_test_OTA: extends: .example_test_esp32_template + parallel: 2 tags: - ESP32 - Example_WIFI_OTA diff --git a/examples/system/ota/advanced_https_ota/example_test.py b/examples/system/ota/advanced_https_ota/example_test.py index c98e029032..d3adfe7637 100644 --- a/examples/system/ota/advanced_https_ota/example_test.py +++ b/examples/system/ota/advanced_https_ota/example_test.py @@ -641,6 +641,55 @@ def test_examples_protocol_advanced_https_ota_example_bluedroid_gatts(env, extra dut1.reset() +@ttfw_idf.idf_example_test(env_tag='Example_WIFI_OTA') +def test_examples_protocol_advanced_https_ota_example_openssl_aligned_bin(env, extra_data): + """ + This is a test case for esp_http_client_read with binary size multiple of 289 bytes + steps: | + 1. join AP + 2. Fetch OTA image over HTTPS + 3. Reboot with the new OTA image + """ + dut1 = env.get_dut('advanced_https_ota_example', 'examples/system/ota/advanced_https_ota', dut_class=ttfw_idf.ESP32DUT) + # Original binary file generated after compilation + bin_name = 'advanced_https_ota.bin' + # Binary file aligned to DEFAULT_OTA_BUF_SIZE(289 bytes) boundary + aligned_bin_name = 'aligned.bin' + # check and log bin size + binary_file = os.path.join(dut1.app.binary_path, bin_name) + # Original binary size + bin_size = os.path.getsize(binary_file) + # Dummy data required to align binary size to 289 bytes boundary + dummy_data_size = 289 - (bin_size % 289) + f = open(binary_file, 'rb+') + fo = open(os.path.join(dut1.app.binary_path, aligned_bin_name), 'wb+') + fo.write(f.read(bin_size)) + for _ in range(dummy_data_size): + fo.write(struct.pack('B', random.randrange(0,255,1))) + fo.close() + f.close() + # start test + host_ip = get_my_ip() + chunked_server = start_chunked_server(dut1.app.binary_path, 8070) + dut1.start_app() + dut1.expect('Loaded app from partition at offset', timeout=30) + try: + ip_address = dut1.expect(re.compile(r' sta ip: ([^,]+),'), timeout=30) + print('Connected to AP with IP: {}'.format(ip_address)) + except DUT.ExpectTimeout: + raise ValueError('ENV_TEST_FAILURE: Cannot connect to AP') + dut1.expect('Starting Advanced OTA example', timeout=30) + + print('writing to device: {}'.format('https://' + host_ip + ':8070/' + aligned_bin_name)) + dut1.write('https://' + host_ip + ':8070/' + aligned_bin_name) + dut1.expect('Loaded app from partition at offset', timeout=60) + dut1.expect('Starting Advanced OTA example', timeout=30) + chunked_server.kill() + os.remove(os.path.join(dut1.app.binary_path, 'server_cert.pem')) + os.remove(os.path.join(dut1.app.binary_path, 'server_key.pem')) + os.remove(aligned_bin_name) + + if __name__ == '__main__': test_examples_protocol_advanced_https_ota_example() test_examples_protocol_advanced_https_ota_example_chunked() @@ -652,3 +701,4 @@ if __name__ == '__main__': test_examples_protocol_advanced_https_ota_example_partial_request() test_examples_protocol_advanced_https_ota_example_nimble_gatts() test_examples_protocol_advanced_https_ota_example_bluedroid_gatts() + test_examples_protocol_advanced_https_ota_example_openssl_aligned_bin()