Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add erase-flash option to erase the flash before programming. (RDT-234) #98

Merged
merged 1 commit into from
Jul 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion pytest-embedded-arduino/pytest_embedded_arduino/serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ def __init__(
baud: int = EspSerial.DEFAULT_BAUDRATE,
target: Optional[str] = None,
skip_autoflash: bool = False,
erase_flash: bool = False,
**kwargs,
) -> None:
self.app = app
super().__init__(pexpect_proc, target or self.app.target, port, baud, skip_autoflash, **kwargs)
super().__init__(pexpect_proc, target or self.app.target, port, baud, skip_autoflash, erase_flash, **kwargs)

def _start(self):
if self.skip_autoflash:
Expand Down Expand Up @@ -68,6 +69,9 @@ def __init__(self, attributes):
default_kwargs['force'] = False
default_kwargs['chip'] = self.app.target

if self.erase_flash:
default_kwargs['erase_all'] = True
hfudev marked this conversation as resolved.
Show resolved Hide resolved

default_kwargs.update(self.app.flash_settings)
flash_args = FlashArgs(default_kwargs)

Expand Down
6 changes: 5 additions & 1 deletion pytest-embedded-idf/pytest_embedded_idf/serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def __init__(
port: Optional[str] = None,
baud: int = EspSerial.DEFAULT_BAUDRATE,
skip_autoflash: bool = False,
erase_flash: bool = False,
port_app_cache: Dict[str, str] = None,
confirm_target_elf_sha256: bool = False,
erase_nvs: bool = False,
Expand All @@ -45,7 +46,7 @@ def __init__(
if target and self.app.target and self.app.target != target:
raise ValueError(f'Targets do not match. App target: {self.app.target}, Cmd target: {target}.')

super().__init__(pexpect_proc, target or app.target, port, baud, skip_autoflash, **kwargs)
super().__init__(pexpect_proc, target or app.target, port, baud, skip_autoflash, erase_flash, **kwargs)

def _post_init(self):
if self.esp.serial_port in self._port_app_cache:
Expand Down Expand Up @@ -129,6 +130,9 @@ def __init__(self, attributes):
if self.ESPTOOL_VERSION == EsptoolVersion.V4:
default_kwargs['force'] = False

if self.erase_flash:
default_kwargs['erase_all'] = True

default_kwargs.update(self.app.flash_settings)
default_kwargs.update(self.app.flash_args.get('extra_esptool_args', {}))
args = FlashArgs(default_kwargs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def __init__(
port: Optional[str] = None,
baud: int = DEFAULT_BAUDRATE,
skip_autoflash: bool = False,
erase_flash: bool = False,
port_target_cache: Dict[str, str] = None,
**kwargs,
) -> None:
Expand Down Expand Up @@ -87,6 +88,7 @@ def __init__(
self.target = target

self.skip_autoflash = skip_autoflash
self.erase_flash = erase_flash
super().__init__(pexpect_proc, port=self.esp._port, **kwargs)

def _post_init(self):
Expand Down
14 changes: 14 additions & 0 deletions pytest-embedded/pytest_embedded/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ def pytest_addoption(parser):
'--skip-autoflash',
help='y/yes/true for True and n/no/false for False. Set to True to disable auto flash. (Default: False)',
)
esp_group.addoption(
'--erase-flash',
help='y/yes/true for True and n/no/false for False. Set to True to erase flash before programming. '
'(Default: False)',
)

idf_group = parser.getgroup('embedded-idf')
idf_group.addoption(
Expand Down Expand Up @@ -566,6 +571,13 @@ def skip_autoflash(request: FixtureRequest) -> Optional[bool]:
return _request_param_or_config_option_or_default(request, 'skip_autoflash', None)


@pytest.fixture
@multi_dut_argument
def erase_flash(request: FixtureRequest) -> Optional[bool]:
"""Enable parametrization for the same cli option"""
return _request_param_or_config_option_or_default(request, 'erase_flash', None)


#######
# idf #
#######
Expand Down Expand Up @@ -704,6 +716,7 @@ def _fixture_classes_and_options(
target,
baud,
skip_autoflash,
erase_flash,
part_tool,
confirm_target_elf_sha256,
erase_nvs,
Expand Down Expand Up @@ -792,6 +805,7 @@ def _fixture_classes_and_options(
'port': os.getenv('ESPPORT') or port,
'baud': int(os.getenv('ESPBAUD') or baud or EspSerial.DEFAULT_BAUDRATE),
'skip_autoflash': skip_autoflash,
'erase_flash': erase_flash,
}
if 'idf' in _services:
from pytest_embedded_idf.serial import IdfSerial
Expand Down