Skip to content

Commit

Permalink
tests: Create custom host_test marker for tests without real chip c…
Browse files Browse the repository at this point in the history
…onnected

Closes #838
  • Loading branch information
radimkarnis committed Feb 20, 2023
1 parent 090c099 commit 9c8c1f1
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ The following tests run automatically by GitHub Actions for each Pull Request. Y
* ``test_mergebin.py`` tests the ``merge_bin`` command
* ``test_modules.py`` tests the modules used by ``esptool.py`` for regressions
* ``test_espsecure.py`` tests ``espsecure.py`` functionality
* ``test_espsecure_hsm.py`` tests support of extarnal HSM signing in ``espsecure.py``. These tests require additional prerequisites, see ``SoftHSM2 setup`` in the `tests workflow definition <https://github.com/espressif/esptool/blob/master/.github/workflows/test_esptool.yml>`_ for more information.

The following tests are not run automatically by GitHub Actions, because they need real connected hardware. Therefore, they need to be run locally in a command line:

Expand Down Expand Up @@ -146,7 +147,7 @@ The following tests are not run automatically by GitHub Actions, but can be run

Do not attempt to run these tests on real hardware! You risk damaging or destroying the ESP chip!

The whole test suite (without the tests needing an actual hardware) can be easily run with the following command in the esptool root folder: ``pytest --ignore=test/test_esptool.py``
The whole test suite (without the tests needing an actual hardware or installation of additional prerequisites) can be easily run with the following command in the esptool root folder: ``pytest -m host_test``


Pull Request Process
Expand Down
2 changes: 1 addition & 1 deletion docs/en/esptool/basic-commands.rst
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ Example output:
Device: 4016
Detected flash size: 4MB

Refer to `flashrom source code <https://review.coreboot.org/plugins/gitiles/flashrom/+/refs/heads/master/flashchips.h>`__ for flash chip manufacturer name and part number.
Refer to `flashrom source code <https://github.com/flashrom/flashrom/blob/master/include/flashchips.h>`__ for flash chip manufacturer name and part number.

.. _elf-2-image:

Expand Down
7 changes: 7 additions & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ def pytest_configure(config):
global arg_reset_port
arg_reset_port = config.getoption("--reset-port")

# register custom markers
config.addinivalue_line(
"markers",
"host_test: mark esptool tests that run on the host machine only "
"(don't require a real chip connected).",
)


def need_to_install_package_err():
pytest.exit(
Expand Down
1 change: 1 addition & 0 deletions test/test_espefuse.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
print("Running espefuse.py tests...")


@pytest.mark.host_test
class EfuseTestCase:
def setup_method(self):
if reset_port is None:
Expand Down
1 change: 1 addition & 0 deletions test/test_espsecure.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
TEST_DIR = os.path.abspath(os.path.dirname(__file__))


@pytest.mark.host_test
class EspSecureTestCase:
def run_espsecure(self, args):
"""
Expand Down
6 changes: 6 additions & 0 deletions test/test_esptool.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,18 +465,21 @@ def test_length_not_aligned_4bytes(self):
def test_length_not_aligned_4bytes_no_compression(self):
self.run_esptool("write_flash -u 0x0 images/not_4_byte_aligned.bin")

@pytest.mark.host_test
def test_write_overlap(self):
output = self.run_esptool_error(
"write_flash 0x0 images/bootloader_esp32.bin 0x1000 images/one_kb.bin"
)
assert "Detected overlap at address: 0x1000 " in output

@pytest.mark.host_test
def test_repeated_address(self):
output = self.run_esptool_error(
"write_flash 0x0 images/one_kb.bin 0x0 images/one_kb.bin"
)
assert "Detected overlap at address: 0x0 " in output

@pytest.mark.host_test
def test_write_sector_overlap(self):
# These two 1KB files don't overlap,
# but they do both touch sector at 0x1000 so should fail
Expand Down Expand Up @@ -613,6 +616,7 @@ def test_large_no_compression(self):
self.run_esptool("write_flash -u -fs 4MB 0x280000 images/one_mb.bin")
self.verify_readback(0x280000, 0x100000, "images/one_mb.bin")

@pytest.mark.host_test
def test_invalid_size_arg(self):
self.run_esptool_error("write_flash -fs 10MB 0x6000 images/one_kb.bin")

Expand Down Expand Up @@ -1134,6 +1138,7 @@ def __exit__(self, exc_type, exc_value, exc_tb):
"serial_write_timeout = 12"
)

@pytest.mark.host_test
def test_load_config_file(self):
# Test a valid file is loaded
config_file_path = os.path.join(os.getcwd(), "esptool.cfg")
Expand Down Expand Up @@ -1171,6 +1176,7 @@ def test_load_config_file(self):
output = self.run_esptool("version")
assert f"Loaded custom configuration from {config_file_path}" in output

@pytest.mark.host_test
def test_load_config_file_with_env_var(self):
config_file_path = os.path.join(TEST_DIR, "custom_file.ini")
with self.ConfigFile(config_file_path, self.dummy_config):
Expand Down
1 change: 1 addition & 0 deletions test/test_image_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def read_image(filename):
return f.read()


@pytest.mark.host_test
class TestImageInfo:
def run_image_info(self, chip, file, version=None):
"""Runs image_info on a binary file.
Expand Down
1 change: 1 addition & 0 deletions test/test_imagegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def segment_matches_section(segment, section):
return section.header.sh_addr == segment.addr and sh_size == len(segment.data)


@pytest.mark.host_test
class BaseTestCase:
@classmethod
def setup_class(self):
Expand Down
1 change: 1 addition & 0 deletions test/test_merge_bin.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def read_image(filename):
return f.read()


@pytest.mark.host_test
class TestMergeBin:
def run_merge_bin(self, chip, offsets_names, options=[]):
"""Run merge_bin on a list of (offset, filename) tuples
Expand Down
3 changes: 3 additions & 0 deletions test/test_modules.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# Tests for regressions in python modules
# used by esptool.py, espefuse.py, and espsecure.py

import pytest

import reedsolo


@pytest.mark.host_test
def test_reed_solomon_encoding():
# fmt: off
pairs = [("a0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebf", "0404992ae0b12cb0ef0d4fd3"),
Expand Down

0 comments on commit 9c8c1f1

Please sign in to comment.