Skip to content

Commit

Permalink
feat: add esp-flash-force
Browse files Browse the repository at this point in the history
  • Loading branch information
horw committed Feb 7, 2024
1 parent 53022b9 commit 6ebe641
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 2 deletions.
3 changes: 3 additions & 0 deletions pytest-embedded-arduino/pytest_embedded_arduino/serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ def flash(self) -> None:
flash_settings.append(f'--{k}')
flash_settings.append(v)

if self.app.esp_flash_force:
flash_settings.append('--force')

try:
esptool.main(
['--chip', self.app.target, 'write_flash', *flash_files, *flash_settings],
Expand Down
2 changes: 2 additions & 0 deletions pytest-embedded-idf/pytest_embedded_idf/serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ def load_ram(self) -> None:
)

def _force_flag(self):
if self.app.esp_flash_force:
return ['--force']
config = self.app.sdkconfig
if any((config.get('CONFIG_SECURE_FLASH_ENC_ENABLED', False), config.get('CONFIG_SECURE_BOOT', False))):
return ['--force']
Expand Down
37 changes: 37 additions & 0 deletions pytest-embedded-idf/tests/test_idf.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,43 @@ def test_idf_serial_flash(dut):
result.assert_outcomes(passed=1)


def test_esp_flash_force_flag(testdir):
testdir.makepyfile("""
import pexpect
import pytest
def test_idf_serial_flash(dut):
dut.expect('Hello world!')
assert dut.app.esp_flash_force == True
""")
result = testdir.runpytest(
'-s',
'--embedded-services', 'esp,idf',
'--app-path', os.path.join(testdir.tmpdir, 'hello_world_esp32'),
'--esp-flash-force',
)

result.assert_outcomes(passed=1)


def test_esp_flash_no_force_flag(testdir):
testdir.makepyfile("""
import pexpect
import pytest
def test_idf_serial_flash(dut):
dut.expect('Hello world!')
assert dut.app.esp_flash_force == False
""")
result = testdir.runpytest(
'-s',
'--embedded-services', 'esp,idf',
'--app-path', os.path.join(testdir.tmpdir, 'hello_world_esp32'),
)

result.assert_outcomes(passed=1)


def test_expect_no_matching(testdir):
testdir.makepyfile("""
import pexpect
Expand Down
17 changes: 15 additions & 2 deletions pytest-embedded/pytest_embedded/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,11 @@ def pytest_addoption(parser):
'--port-mac',
help='MAC address of the board. (Default: None)',
)

esp_group.addoption(
'--esp-flash-force',
action='store_true',
help='force mode for esptool',
)
idf_group = parser.getgroup('embedded-idf')
idf_group.addoption(
'--part-tool',
Expand Down Expand Up @@ -765,6 +769,13 @@ def app_path(request: FixtureRequest, test_file_path: str) -> t.Optional[str]:
return _request_param_or_config_option_or_default(request, 'app_path', os.path.dirname(test_file_path))


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


@pytest.fixture
@multi_dut_argument
def build_dir(request: FixtureRequest) -> t.Optional[str]:
Expand Down Expand Up @@ -1024,6 +1035,7 @@ def _fixture_classes_and_options(
skip_autoflash,
erase_all,
esptool_baud,
esp_flash_force,
part_tool,
confirm_target_elf_sha256,
erase_nvs,
Expand Down Expand Up @@ -1074,7 +1086,8 @@ def _fixture_classes_and_options(

for fixture in FIXTURES_SERVICES.keys():
if fixture == 'app':
kwargs['app'] = {'app_path': app_path, 'build_dir': build_dir}
kwargs['app'] = {'app_path': app_path, 'build_dir': build_dir, 'esp_flash_force': esp_flash_force}
print('hero', kwargs)
if 'idf' in _services:
if 'qemu' in _services:
from pytest_embedded_qemu import DEFAULT_IMAGE_FN, QemuApp
Expand Down

0 comments on commit 6ebe641

Please sign in to comment.