diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 03686e306d..d141432f9a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -890,6 +890,7 @@ assign_test: CONFIG_FILE_PATH: "${CI_PROJECT_DIR}/examples/test_configs" LOG_PATH: "$CI_PROJECT_DIR/TEST_LOGS" ENV_FILE: "$CI_PROJECT_DIR/ci-test-runner-configs/$CI_RUNNER_DESCRIPTION/EnvConfig.yml" + PYTHON_VER: 3 script: - *define_config_file_name # first test if config file exists, if not exist, exit 0 diff --git a/examples/bluetooth/nimble/bleprph/bleprph_test.py b/examples/bluetooth/nimble/bleprph/bleprph_test.py index 00032d5cbc..ec24c4fdc7 100644 --- a/examples/bluetooth/nimble/bleprph/bleprph_test.py +++ b/examples/bluetooth/nimble/bleprph/bleprph_test.py @@ -109,7 +109,7 @@ def bleprph_client_task(prph_obj, dut, dut_addr): - write 'A' to characteristic with write permission ''' chars_ret_on_write = {} - chars_ret_on_write = ble_client_obj.write_chars('A') + chars_ret_on_write = ble_client_obj.write_chars(b'A') if chars_ret_on_write: Utility.console_log("\nCharacteristics after write operation") for path, props in chars_ret_on_write.items(): diff --git a/examples/protocols/asio/chat_server/asio_chat_server_test.py b/examples/protocols/asio/chat_server/asio_chat_server_test.py index 4f28116aaf..f396f26d5c 100644 --- a/examples/protocols/asio/chat_server/asio_chat_server_test.py +++ b/examples/protocols/asio/chat_server/asio_chat_server_test.py @@ -38,6 +38,7 @@ def test_examples_protocol_asio_chat_server(env, extra_data): # 2. get the server IP address data = dut1.expect(re.compile(r" sta ip: ([^,]+),"), timeout=30) # 3. create tcp client and connect to server + dut1.expect('ASIO engine is up and running', timeout=1) cli = socket.socket(socket.AF_INET, socket.SOCK_STREAM) cli.settimeout(30) cli.connect((data[0],80)) diff --git a/examples/protocols/asio/chat_server/main/chat_server.cpp b/examples/protocols/asio/chat_server/main/chat_server.cpp index 05740f4798..77d76160c9 100644 --- a/examples/protocols/asio/chat_server/main/chat_server.cpp +++ b/examples/protocols/asio/chat_server/main/chat_server.cpp @@ -208,6 +208,8 @@ int asio_main() servers.emplace_back(io_context, endpoint); } + std::cout << "ASIO engine is up and running" << std::endl; + io_context.run(); return 0; diff --git a/examples/protocols/asio/tcp_echo_server/asio_tcp_server_test.py b/examples/protocols/asio/tcp_echo_server/asio_tcp_server_test.py index c29b8ce7b8..2f13e1a481 100644 --- a/examples/protocols/asio/tcp_echo_server/asio_tcp_server_test.py +++ b/examples/protocols/asio/tcp_echo_server/asio_tcp_server_test.py @@ -40,6 +40,7 @@ def test_examples_protocol_asio_tcp_server(env, extra_data): # 2. get the server IP address data = dut1.expect(re.compile(r" sta ip: ([^,]+),"), timeout=30) # 3. create tcp client and connect to server + dut1.expect('ASIO engine is up and running', timeout=1) cli = socket.socket(socket.AF_INET, socket.SOCK_STREAM) cli.settimeout(30) cli.connect((data[0],80)) diff --git a/examples/protocols/asio/tcp_echo_server/main/echo_server.cpp b/examples/protocols/asio/tcp_echo_server/main/echo_server.cpp index 22f171f530..cdfafdb91e 100644 --- a/examples/protocols/asio/tcp_echo_server/main/echo_server.cpp +++ b/examples/protocols/asio/tcp_echo_server/main/echo_server.cpp @@ -86,6 +86,8 @@ void asio_main() server s(io_context, std::atoi(CONFIG_EXAMPLE_PORT)); + std::cout << "ASIO engine is up and running" << std::endl; + io_context.run(); } \ No newline at end of file diff --git a/examples/protocols/asio/udp_echo_server/asio_udp_server_test.py b/examples/protocols/asio/udp_echo_server/asio_udp_server_test.py index d3a01563c1..5249016b15 100644 --- a/examples/protocols/asio/udp_echo_server/asio_udp_server_test.py +++ b/examples/protocols/asio/udp_echo_server/asio_udp_server_test.py @@ -40,6 +40,7 @@ def test_examples_protocol_asio_udp_server(env, extra_data): # 2. get the server IP address data = dut1.expect(re.compile(r" sta ip: ([^,]+),"), timeout=30) # 3. create tcp client and connect to server + dut1.expect('ASIO engine is up and running', timeout=1) cli = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) cli.settimeout(30) cli.connect((data[0], 80)) diff --git a/examples/protocols/asio/udp_echo_server/main/udp_echo_server.cpp b/examples/protocols/asio/udp_echo_server/main/udp_echo_server.cpp index 5b6607d736..c0204e2178 100644 --- a/examples/protocols/asio/udp_echo_server/main/udp_echo_server.cpp +++ b/examples/protocols/asio/udp_echo_server/main/udp_echo_server.cpp @@ -65,5 +65,7 @@ void asio_main() server s(io_context, std::atoi(CONFIG_EXAMPLE_PORT)); + std::cout << "ASIO engine is up and running" << std::endl; + io_context.run(); } diff --git a/examples/protocols/http_server/simple/http_server_simple_test.py b/examples/protocols/http_server/simple/http_server_simple_test.py index 38d8c319e0..72b0b8f3fe 100644 --- a/examples/protocols/http_server/simple/http_server_simple_test.py +++ b/examples/protocols/http_server/simple/http_server_simple_test.py @@ -113,12 +113,6 @@ def test_examples_protocol_http_server_simple(env, extra_data): raise RuntimeError dut1.expect("Found URL query => " + query, timeout=30) - query = "abcd\nyz" - Utility.console_log("Test /hello with invalid query") - if client.test_custom_uri_query(got_ip, got_port, query): - raise RuntimeError - dut1.expect("400 Bad Request - Server unable to understand request due to invalid syntax", timeout=30) - if __name__ == '__main__': test_examples_protocol_http_server_simple() diff --git a/examples/system/ota/advanced_https_ota/example_test.py b/examples/system/ota/advanced_https_ota/example_test.py index c8255ea012..59d8a0774a 100644 --- a/examples/system/ota/advanced_https_ota/example_test.py +++ b/examples/system/ota/advanced_https_ota/example_test.py @@ -1,6 +1,7 @@ import re import os import sys +import struct import socket from threading import Thread import ssl @@ -224,8 +225,8 @@ def test_examples_protocol_advanced_https_ota_example_truncated_bin(env, extra_d truncated_bin_size = 64000 # check and log bin size binary_file = os.path.join(dut1.app.binary_path, bin_name) - f = open(binary_file, "r+") - fo = open(os.path.join(dut1.app.binary_path, truncated_bin_name), "w+") + f = open(binary_file, "rb+") + fo = open(os.path.join(dut1.app.binary_path, truncated_bin_name), "wb+") fo.write(f.read(truncated_bin_size)) fo.close() f.close() @@ -275,8 +276,8 @@ def test_examples_protocol_advanced_https_ota_example_truncated_header(env, extr truncated_bin_size = 180 # check and log bin size binary_file = os.path.join(dut1.app.binary_path, bin_name) - f = open(binary_file, "r+") - fo = open(os.path.join(dut1.app.binary_path, truncated_bin_name), "w+") + f = open(binary_file, "rb+") + fo = open(os.path.join(dut1.app.binary_path, truncated_bin_name), "wb+") fo.write(f.read(truncated_bin_size)) fo.close() f.close() @@ -324,12 +325,12 @@ def test_examples_protocol_advanced_https_ota_example_random(env, extra_data): random_bin_size = 32000 # check and log bin size binary_file = os.path.join(dut1.app.binary_path, random_bin_name) - fo = open(binary_file, "w+") + fo = open(binary_file, "wb+") # First byte of binary file is always set to zero. If first byte is generated randomly, # in some cases it may generate 0xE9 which will result in failure of testcase. - fo.write(str(0)) + fo.write(struct.pack("B", 0)) for i in range(random_bin_size - 1): - fo.write(str(random.randrange(0,255,1))) + fo.write(struct.pack("B", random.randrange(0,255,1))) fo.close() bin_size = os.path.getsize(binary_file) IDF.log_performance("advanced_https_ota_bin_size", "{}KB".format(bin_size // 1024)) diff --git a/examples/system/ota/native_ota_example/example_test.py b/examples/system/ota/native_ota_example/example_test.py index db0e266cfe..bb4e0be4a7 100644 --- a/examples/system/ota/native_ota_example/example_test.py +++ b/examples/system/ota/native_ota_example/example_test.py @@ -1,6 +1,7 @@ import re import os import sys +import struct import socket from threading import Thread import ssl @@ -196,8 +197,8 @@ def test_examples_protocol_native_ota_example_truncated_bin(env, extra_data): truncated_bin_size = 64000 # check and log bin size binary_file = os.path.join(dut1.app.binary_path, bin_name) - f = open(binary_file, "r+") - fo = open(os.path.join(dut1.app.binary_path, truncated_bin_name), "w+") + f = open(binary_file, "rb+") + fo = open(os.path.join(dut1.app.binary_path, truncated_bin_name), "wb+") fo.write(f.read(truncated_bin_size)) fo.close() f.close() @@ -247,8 +248,8 @@ def test_examples_protocol_native_ota_example_truncated_header(env, extra_data): truncated_bin_size = 180 # check and log bin size binary_file = os.path.join(dut1.app.binary_path, bin_name) - f = open(binary_file, "r+") - fo = open(os.path.join(dut1.app.binary_path, truncated_bin_name), "w+") + f = open(binary_file, "rb+") + fo = open(os.path.join(dut1.app.binary_path, truncated_bin_name), "wb+") fo.write(f.read(truncated_bin_size)) fo.close() f.close() @@ -296,12 +297,12 @@ def test_examples_protocol_native_ota_example_random(env, extra_data): random_bin_size = 32000 # check and log bin size binary_file = os.path.join(dut1.app.binary_path, random_bin_name) - fo = open(binary_file, "w+") + fo = open(binary_file, "wb+") # First byte of binary file is always set to zero. If first byte is generated randomly, # in some cases it may generate 0xE9 which will result in failure of testcase. - fo.write(str(0)) + fo.write(struct.pack("B", 0)) for i in range(random_bin_size - 1): - fo.write(str(random.randrange(0,255,1))) + fo.write(struct.pack("B", random.randrange(0,255,1))) fo.close() bin_size = os.path.getsize(binary_file) IDF.log_performance("native_ota_bin_size", "{}KB".format(bin_size // 1024)) diff --git a/examples/wifi/iperf/components/iperf/iperf.c b/examples/wifi/iperf/components/iperf/iperf.c index 5ee304671d..70aca465c5 100644 --- a/examples/wifi/iperf/components/iperf/iperf.c +++ b/examples/wifi/iperf/components/iperf/iperf.c @@ -160,6 +160,7 @@ static esp_err_t IRAM_ATTR iperf_run_tcp_server(void) return ESP_FAIL; } + printf("iperf tcp server create successfully\n"); buffer = s_iperf_ctrl.buffer; want_recv = s_iperf_ctrl.buffer_len; while (!s_iperf_ctrl.finish) { diff --git a/examples/wifi/iperf/iperf_test.py b/examples/wifi/iperf/iperf_test.py index b51eb8fa88..744f102b27 100644 --- a/examples/wifi/iperf/iperf_test.py +++ b/examples/wifi/iperf/iperf_test.py @@ -201,7 +201,7 @@ class TestResult(object): @staticmethod def _convert_to_draw_format(data, label): - keys = data.keys() + keys = list(data.keys()) keys.sort() return { "x-axis": keys, @@ -235,8 +235,8 @@ class TestResult(object): LineChart.draw_line_chart(os.path.join(path, file_name), "Throughput Vs {} ({} {})".format(type_name, self.proto, self.direction), - "Throughput (Mbps)", "{} (dbm)".format(type_name), + "Throughput (Mbps)", data_list) return file_name @@ -324,7 +324,7 @@ class IperfTestUtility(object): except subprocess.CalledProcessError: pass self.dut.write("restart") - self.dut.expect("esp32>") + self.dut.expect_any("iperf>", "esp32>") self.dut.write("scan {}".format(self.ap_ssid)) for _ in range(SCAN_RETRY_COUNT): try: @@ -377,6 +377,12 @@ class IperfTestUtility(object): with open(PC_IPERF_TEMP_LOG_FILE, "w") as f: if proto == "tcp": self.dut.write("iperf -s -i 1 -t {}".format(TEST_TIME)) + # wait until DUT TCP server created + try: + self.dut.expect("iperf tcp server create successfully", timeout=1) + except DUT.ExpectTimeout: + # compatible with old iperf example binary + pass process = subprocess.Popen(["iperf", "-c", dut_ip, "-t", str(TEST_TIME), "-f", "m"], stdout=f, stderr=f) @@ -450,7 +456,7 @@ class IperfTestUtility(object): :return: True or False """ self.dut.write("restart") - self.dut.expect("esp32>") + self.dut.expect_any("iperf>", "esp32>") for _ in range(WAIT_AP_POWER_ON_TIMEOUT // SCAN_TIMEOUT): try: self.dut.write("scan {}".format(self.ap_ssid)) @@ -518,7 +524,7 @@ def test_wifi_throughput_with_different_configs(env, extra_data): # 2. get DUT and download dut = env.get_dut("iperf", "examples/wifi/iperf") dut.start_app() - dut.expect("esp32>") + dut.expect_any("iperf>", "esp32>") # 3. run test for each required att value test_result[config_name] = { @@ -576,7 +582,7 @@ def test_wifi_throughput_vs_rssi(env, extra_data): # 2. get DUT and download dut = env.get_dut("iperf", "examples/wifi/iperf") dut.start_app() - dut.expect("esp32>") + dut.expect_any("iperf>", "esp32>") # 3. run test for each required att value for ap_info in ap_list: @@ -625,7 +631,7 @@ def test_wifi_throughput_basic(env, extra_data): # 2. get DUT dut = env.get_dut("iperf", "examples/wifi/iperf") dut.start_app() - dut.expect("esp32>") + dut.expect_any("iperf>", "esp32>") # 3. preparing test_result = { diff --git a/examples/wifi/iperf/test_report.py b/examples/wifi/iperf/test_report.py index 5d5d792cf8..3da74dcdd3 100644 --- a/examples/wifi/iperf/test_report.py +++ b/examples/wifi/iperf/test_report.py @@ -36,7 +36,7 @@ class ThroughputForConfigsReport(object): self.sdkconfigs[config_name] = self._parse_config_file(sdkconfig_files[config_name]) if not os.path.exists(output_path): os.makedirs(output_path) - self.sort_order = self.sdkconfigs.keys() + self.sort_order = list(self.sdkconfigs.keys()) self.sort_order.sort() @staticmethod @@ -162,7 +162,7 @@ class ThroughputVsRssiReport(object): self.output_path = output_path self.raw_data_path = os.path.join(output_path, "raw_data") self.results = throughput_results - self.throughput_types = self.results.keys() + self.throughput_types = list(self.results.keys()) self.throughput_types.sort() if not os.path.exists(self.raw_data_path): os.makedirs(self.raw_data_path) diff --git a/tools/ci/setup_python.sh b/tools/ci/setup_python.sh index fac76cab4d..72bb249f8d 100644 --- a/tools/ci/setup_python.sh +++ b/tools/ci/setup_python.sh @@ -1,14 +1,7 @@ #! /bin/bash -# Regexp for matching job names which are incompatible with Python 3 -# - UT_009_ - multi-device tests are not compatible -# - UT_014_ - multi-device tests are not compatible -# - UT_017_ - multi-device tests are not compatible -py3_incomp='UT_009_|UT_013_|UT_014_|UT_017_' - -if [ -z ${PYTHON_VER+x} ] || [[ $CI_JOB_NAME =~ $py3_incomp ]]; then - # Use this version of the Python interpreter if it was not defined before or - # the given job is not compatible with Python 3 +if [ -z ${PYTHON_VER+x} ]; then + # Use this version of the Python interpreter if it was not defined before PYTHON_VER=2.7.15 fi diff --git a/tools/esp_prov/esp_prov.py b/tools/esp_prov/esp_prov.py index 3ce67d7003..d306a3a9e4 100644 --- a/tools/esp_prov/esp_prov.py +++ b/tools/esp_prov/esp_prov.py @@ -16,7 +16,7 @@ # from __future__ import print_function -from builtins import input +from builtins import input as binput import argparse import textwrap import time @@ -423,7 +423,7 @@ if __name__ == '__main__': while True: try: - select = int(input("Select AP by number (0 to rescan) : ")) + select = int(binput("Select AP by number (0 to rescan) : ")) if select < 0 or select > len(APs): raise ValueError break diff --git a/tools/esp_prov/security/security1.py b/tools/esp_prov/security/security1.py index 90bffff8a4..be657186c3 100644 --- a/tools/esp_prov/security/security1.py +++ b/tools/esp_prov/security/security1.py @@ -167,7 +167,7 @@ class Security1(Security): return -1 def encrypt_data(self, data): - return self.cipher.update(data) + return self.cipher.update(tobytes(data)) def decrypt_data(self, data): - return self.cipher.update(data) + return self.cipher.update(tobytes(data)) diff --git a/tools/esp_prov/transport/ble_cli.py b/tools/esp_prov/transport/ble_cli.py index ad80bf2ddc..5d88ece806 100644 --- a/tools/esp_prov/transport/ble_cli.py +++ b/tools/esp_prov/transport/ble_cli.py @@ -234,6 +234,8 @@ class BLE_Bluez_Client: try: path.WriteValue([ord(c) for c in data], {}, dbus_interface='org.bluez.GattCharacteristic1') + except TypeError: # python3 compatible + path.WriteValue([c for c in data], {}, dbus_interface='org.bluez.GattCharacteristic1') except dbus.exceptions.DBusException as e: raise RuntimeError("Failed to write value to characteristic " + characteristic_uuid + ": " + str(e)) diff --git a/tools/esp_prov/utils/convenience.py b/tools/esp_prov/utils/convenience.py index 9fec1deac6..42d0febe26 100644 --- a/tools/esp_prov/utils/convenience.py +++ b/tools/esp_prov/utils/convenience.py @@ -14,12 +14,14 @@ # # Convenience functions for commonly used data type conversions +import binascii +from future.utils import tobytes def str_to_hexstr(string): # Form hexstr by appending ASCII codes (in hex) corresponding to # each character in the input string - return ''.join('{:02x}'.format(ord(c)) for c in string) + return binascii.hexlify(tobytes(string)).decode() def hexstr_to_str(hexstr): @@ -28,4 +30,4 @@ def hexstr_to_str(hexstr): hexstr = '0' + hexstr # Interpret consecutive pairs of hex characters as 8 bit ASCII codes # and append characters corresponding to each code to form the string - return ''.join(chr(int(hexstr[2 * i: 2 * i + 2], 16)) for i in range(len(hexstr) // 2)) + return binascii.unhexlify(tobytes(hexstr)).decode()