diff --git a/examples/protocols/esp_http_client/esp_http_client_test.py b/examples/protocols/esp_http_client/esp_http_client_test.py index 49194dd8c..9ca1d6f09 100644 --- a/examples/protocols/esp_http_client/esp_http_client_test.py +++ b/examples/protocols/esp_http_client/esp_http_client_test.py @@ -14,7 +14,7 @@ import TinyFW import IDF -@IDF.idf_example_test(env_tag="Example_WIFI") +@IDF.idf_example_test(env_tag="Example_WIFI", ignore=True) def test_examples_protocol_esp_http_client(env, extra_data): """ steps: | diff --git a/examples/protocols/http_server/advanced_tests/http_server_advanced_test.py b/examples/protocols/http_server/advanced_tests/http_server_advanced_test.py index 0333390da..204471b9c 100644 --- a/examples/protocols/http_server/advanced_tests/http_server_advanced_test.py +++ b/examples/protocols/http_server/advanced_tests/http_server_advanced_test.py @@ -39,7 +39,7 @@ import IDF expath = os.path.dirname(os.path.realpath(__file__)) client = imp.load_source("client", expath + "/scripts/test.py") -@IDF.idf_example_test(env_tag="Example_WIFI") +@IDF.idf_example_test(env_tag="Example_WIFI", ignore=True) def test_examples_protocol_http_server_advanced(env, extra_data): # Acquire DUT dut1 = env.get_dut("http_server", "examples/protocols/http_server/advanced_tests") diff --git a/examples/protocols/http_server/advanced_tests/main/Kconfig.projbuild b/examples/protocols/http_server/advanced_tests/main/Kconfig.projbuild index 1a39b7890..9e2813c69 100644 --- a/examples/protocols/http_server/advanced_tests/main/Kconfig.projbuild +++ b/examples/protocols/http_server/advanced_tests/main/Kconfig.projbuild @@ -8,7 +8,7 @@ config WIFI_SSID config WIFI_PASSWORD string "WiFi Password" - default "mypasswd" + default "mypassword" help WiFi password (WPA or WPA2) for the example to use. Can be left blank if the network has no security set. diff --git a/examples/protocols/http_server/persistent_sockets/main/Kconfig.projbuild b/examples/protocols/http_server/persistent_sockets/main/Kconfig.projbuild index 3174cbd70..9e2813c69 100644 --- a/examples/protocols/http_server/persistent_sockets/main/Kconfig.projbuild +++ b/examples/protocols/http_server/persistent_sockets/main/Kconfig.projbuild @@ -8,7 +8,7 @@ config WIFI_SSID config WIFI_PASSWORD string "WiFi Password" - default "myssid" + default "mypassword" help WiFi password (WPA or WPA2) for the example to use. Can be left blank if the network has no security set. 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 35bbed0c4..e8ae1dee5 100644 --- a/examples/protocols/http_server/simple/http_server_simple_test.py +++ b/examples/protocols/http_server/simple/http_server_simple_test.py @@ -39,7 +39,7 @@ import IDF expath = os.path.dirname(os.path.realpath(__file__)) client = imp.load_source("client", expath + "/scripts/client.py") -@IDF.idf_example_test(env_tag="Example_WIFI") +@IDF.idf_example_test(env_tag="Example_WIFI", ignore=True) def test_examples_protocol_http_server_simple(env, extra_data): # Acquire DUT dut1 = env.get_dut("http_server", "examples/protocols/http_server/simple") diff --git a/examples/protocols/http_server/simple/main/Kconfig.projbuild b/examples/protocols/http_server/simple/main/Kconfig.projbuild index 3174cbd70..9e2813c69 100644 --- a/examples/protocols/http_server/simple/main/Kconfig.projbuild +++ b/examples/protocols/http_server/simple/main/Kconfig.projbuild @@ -8,7 +8,7 @@ config WIFI_SSID config WIFI_PASSWORD string "WiFi Password" - default "myssid" + default "mypassword" help WiFi password (WPA or WPA2) for the example to use. Can be left blank if the network has no security set. diff --git a/examples/protocols/https_request/example_test.py b/examples/protocols/https_request/example_test.py index 169ae6330..e362a2512 100644 --- a/examples/protocols/https_request/example_test.py +++ b/examples/protocols/https_request/example_test.py @@ -14,7 +14,7 @@ import TinyFW import IDF -@IDF.idf_example_test(env_tag="Example_WIFI") +@IDF.idf_example_test(env_tag="Example_WIFI", ignore=True) def test_examples_protocol_https_request(env, extra_data): """ steps: | diff --git a/tools/tiny-test-fw/DUT.py b/tools/tiny-test-fw/DUT.py index 6380c43d6..0193cb6c7 100644 --- a/tools/tiny-test-fw/DUT.py +++ b/tools/tiny-test-fw/DUT.py @@ -645,7 +645,7 @@ class BaseDUT(object): Utility.console_log("DUT debug info for DUT: {}:".format(self.name), color="orange") for failure in self.expect_failures: - Utility.console_log("\t[pattern]: {}\r\n\t[data]: {}\r\n\t[time]: {} - {}\r\n" + Utility.console_log(u"\t[pattern]: {}\r\n\t[data]: {}\r\n\t[time]: {} - {}\r\n" .format(failure["pattern"], failure["data"], self._format_ts(failure["start"]), self._format_ts(failure["end"])), color="orange") diff --git a/tools/tiny-test-fw/IDF/IDFDUT.py b/tools/tiny-test-fw/IDF/IDFDUT.py index 8f870fec8..28ea4867c 100644 --- a/tools/tiny-test-fw/IDF/IDFDUT.py +++ b/tools/tiny-test-fw/IDF/IDFDUT.py @@ -18,7 +18,9 @@ import sys import re import subprocess import functools -import serial +import random +import tempfile + from serial.tools import list_ports import DUT @@ -46,6 +48,8 @@ class IDFDUT(DUT.SerialDUT): # /dev/ttyAMA0 port is listed in Raspberry Pi # /dev/tty.Bluetooth-Incoming-Port port is listed in Mac INVALID_PORT_PATTERN = re.compile(r"AMA|Bluetooth") + # if need to erase NVS partition in start app + ERASE_NVS = True def __init__(self, name, port, log_file, app, **kwargs): self.download_config, self.partition_table = app.process_app_info() @@ -74,24 +78,39 @@ class IDFDUT(DUT.SerialDUT): return cls.get_chip(app, port) is not None @_tool_method - def start_app(self): + def start_app(self, erase_nvs=ERASE_NVS): """ download and start app. + :param: erase_nvs: whether erase NVS partition during flash :return: None """ + if erase_nvs: + address = self.partition_table["nvs"]["offset"] + size = self.partition_table["nvs"]["size"] + nvs_file = tempfile.NamedTemporaryFile() + nvs_file.write(chr(0xFF) * size) + nvs_file.flush() + download_config = self.download_config + [address, nvs_file.name] + else: + download_config = self.download_config + retry_baud_rates = ["921600", "115200"] error = IDFToolError() - for baud_rate in retry_baud_rates: - try: - subprocess.check_output(["python", self.app.esptool, - "--port", self.port, "--baud", baud_rate] - + self.download_config) - break - except subprocess.CalledProcessError as error: - continue - else: - raise error + try: + for baud_rate in retry_baud_rates: + try: + subprocess.check_output(["python", self.app.esptool, + "--port", self.port, "--baud", baud_rate] + + download_config) + break + except subprocess.CalledProcessError as error: + continue + else: + raise error + finally: + if erase_nvs: + nvs_file.close() @_tool_method def reset(self): @@ -102,6 +121,17 @@ class IDFDUT(DUT.SerialDUT): """ subprocess.check_output(["python", self.app.esptool, "--port", self.port, "run"]) + @_tool_method + def erase_partition(self, partition): + """ + :param partition: partition name to erase + :return: None + """ + address = self.partition_table[partition]["offset"] + size = self.partition_table[partition]["size"] + with open(".erase_partition.tmp", "wb") as f: + f.write(chr(0xFF) * size) + @_tool_method def dump_flush(self, output_file, **kwargs): """ diff --git a/tools/tiny-test-fw/IDF/__init__.py b/tools/tiny-test-fw/IDF/__init__.py index fad52f41b..c7480c43f 100644 --- a/tools/tiny-test-fw/IDF/__init__.py +++ b/tools/tiny-test-fw/IDF/__init__.py @@ -20,9 +20,8 @@ from IDF.IDFApp import IDFApp, Example, UT from IDF.IDFDUT import IDFDUT -def idf_example_test(app=Example, dut=IDFDUT, chip="ESP32", - module="examples", execution_time=1, level="example", - **kwargs): +def idf_example_test(app=Example, dut=IDFDUT, chip="ESP32", module="examples", execution_time=1, + level="example", erase_nvs=True, **kwargs): """ decorator for testing idf examples (with default values for some keyword args). @@ -32,10 +31,41 @@ def idf_example_test(app=Example, dut=IDFDUT, chip="ESP32", :param module: module, string :param execution_time: execution time in minutes, int :param level: test level, could be used to filter test cases, string + :param erase_nvs: if need to erase_nvs in DUT.start_app() :param kwargs: other keyword args :return: test method """ - # not use partial function as define as function support auto generating document + try: + # try to config the default behavior of erase nvs + dut.ERASE_NVS = erase_nvs + except AttributeError: + pass + + return TinyFW.test_method(app=app, dut=dut, chip=chip, module=module, + execution_time=execution_time, level=level, **kwargs) + + +def idf_unit_test(app=UT, dut=IDFDUT, chip="ESP32", module="unit-test", execution_time=1, + level="unit", erase_nvs=True, **kwargs): + """ + decorator for testing idf unit tests (with default values for some keyword args). + + :param app: test application class + :param dut: dut class + :param chip: chip supported, string or tuple + :param module: module, string + :param execution_time: execution time in minutes, int + :param level: test level, could be used to filter test cases, string + :param erase_nvs: if need to erase_nvs in DUT.start_app() + :param kwargs: other keyword args + :return: test method + """ + try: + # try to config the default behavior of erase nvs + dut.ERASE_NVS = erase_nvs + except AttributeError: + pass + return TinyFW.test_method(app=app, dut=dut, chip=chip, module=module, execution_time=execution_time, level=level, **kwargs) diff --git a/tools/tiny-test-fw/TinyFW.py b/tools/tiny-test-fw/TinyFW.py index a0314e37b..c475f3824 100644 --- a/tools/tiny-test-fw/TinyFW.py +++ b/tools/tiny-test-fw/TinyFW.py @@ -107,6 +107,7 @@ MANDATORY_INFO = { "execution_time": 1, "env_tag": "default", "category": "function", + "ignore": False, } diff --git a/tools/tiny-test-fw/Utility/CIAssignTest.py b/tools/tiny-test-fw/Utility/CIAssignTest.py index 58c43580b..2df66fe81 100644 --- a/tools/tiny-test-fw/Utility/CIAssignTest.py +++ b/tools/tiny-test-fw/Utility/CIAssignTest.py @@ -125,6 +125,7 @@ class AssignTest(object): # by default we only run function in CI, as other tests could take long time DEFAULT_FILTER = { "category": "function", + "ignore": False, } def __init__(self, test_case_path, ci_config_file, case_group=Group): diff --git a/tools/unit-test-app/unit_test.py b/tools/unit-test-app/unit_test.py index e0e265709..4ce625af3 100644 --- a/tools/unit-test-app/unit_test.py +++ b/tools/unit-test-app/unit_test.py @@ -105,8 +105,7 @@ def format_test_case_config(test_case_data): return case_config -@TinyFW.test_method(app=UT, dut=IDF.IDFDUT, chip="ESP32", module="unit_test", - execution_time=1, env_tag="UT_T1_1") +@IDF.idf_unit_test(env_tag="UT_T1_1") def run_unit_test_cases(env, extra_data): """ extra_data can be three types of value @@ -347,8 +346,7 @@ def case_run(duts, ut_config, env, one_case, failed_cases): Utility.console_log("Failed: " + one_case["name"], color="red") -@TinyFW.test_method(app=UT, dut=IDF.IDFDUT, chip="ESP32", module="master_slave_test_case", execution_time=1, - env_tag="UT_T2_1") +@IDF.idf_unit_test(env_tag="UT_T2_1") def run_multiple_devices_cases(env, extra_data): """ extra_data can be two types of value @@ -385,8 +383,7 @@ def run_multiple_devices_cases(env, extra_data): raise AssertionError("Unit Test Failed") -@TinyFW.test_method(app=UT, dut=IDF.IDFDUT, chip="ESP32", module="unit_test", - execution_time=1, env_tag="UT_T1_1") +@IDF.idf_unit_test(env_tag="UT_T1_1") def run_multiple_stage_cases(env, extra_data): """ extra_data can be 2 types of value