Skip to content

Commit

Permalink
ci(test_espefuse): Migrate tests from unittest to pytest
Browse files Browse the repository at this point in the history
  • Loading branch information
radimkarnis committed Oct 25, 2022
1 parent 1d18196 commit 2b42855
Show file tree
Hide file tree
Showing 10 changed files with 1,775 additions and 2,209 deletions.
16 changes: 8 additions & 8 deletions .gitlab-ci.yml
Expand Up @@ -56,14 +56,14 @@ host_tests:
- coverage run --parallel-mode -m pytest ${CI_PROJECT_DIR}/test/test_merge_bin.py
- coverage run --parallel-mode -m pytest ${CI_PROJECT_DIR}/test/test_image_info.py
- coverage run --parallel-mode -m pytest ${CI_PROJECT_DIR}/test/test_modules.py
- coverage run --parallel-mode ${CI_PROJECT_DIR}/test/test_espefuse_host.py esp32
- coverage run --parallel-mode ${CI_PROJECT_DIR}/test/test_espefuse_host.py esp32c2
- coverage run --parallel-mode ${CI_PROJECT_DIR}/test/test_espefuse_host.py esp32c3
- coverage run --parallel-mode ${CI_PROJECT_DIR}/test/test_espefuse_host.py esp32s2
- coverage run --parallel-mode ${CI_PROJECT_DIR}/test/test_espefuse_host.py esp32s3
- coverage run --parallel-mode ${CI_PROJECT_DIR}/test/test_espefuse_host.py esp32s3beta2
- coverage run --parallel-mode ${CI_PROJECT_DIR}/test/test_espefuse_host.py esp32h2beta1
- coverage run --parallel-mode ${CI_PROJECT_DIR}/test/test_espefuse_host.py esp32c6
- coverage run --parallel-mode -m pytest ${CI_PROJECT_DIR}/test/test_espefuse.py --chip esp32
- coverage run --parallel-mode -m pytest ${CI_PROJECT_DIR}/test/test_espefuse.py --chip esp32c2
- coverage run --parallel-mode -m pytest ${CI_PROJECT_DIR}/test/test_espefuse.py --chip esp32c3
- coverage run --parallel-mode -m pytest ${CI_PROJECT_DIR}/test/test_espefuse.py --chip esp32s2
- coverage run --parallel-mode -m pytest ${CI_PROJECT_DIR}/test/test_espefuse.py --chip esp32s3
- coverage run --parallel-mode -m pytest ${CI_PROJECT_DIR}/test/test_espefuse.py --chip esp32s3beta2
- coverage run --parallel-mode -m pytest ${CI_PROJECT_DIR}/test/test_espefuse.py --chip esp32h2beta1
- coverage run --parallel-mode -m pytest ${CI_PROJECT_DIR}/test/test_espefuse.py --chip esp32c6
# some .coverage files in sub-directories are not collected on some runners, move them first
- find . -mindepth 2 -type f -name ".coverage*" -print -exec mv --backup=numbered {} . \;

Expand Down
6 changes: 3 additions & 3 deletions docs/en/espefuse/execute-scripts-cmd.rst
Expand Up @@ -30,7 +30,7 @@ If you want to use other libs in the script you can add them manually.
Inside this script, you can call all commands which are available in CLI, see ``espefuse.py --help``. To run a efuse command you need to call ``espefuse(esp, efuses, args, 'burn_efuse DISABLE_DL_DECRYPT 1')``. This command will not burn eFuses immediately, the burn occurs at the end of all scripts.
If necessary, you can call ``efuses.burn_all()`` which prompts ``Type 'BURN' (all capitals) to continue.``. To skip this check and go without confirmation just add the ``--do-not-confirm`` flag to the ``execute_scripts`` command.

This command supports nesting. This means that one script can be called from another script (see the test case ``test_execute_scripts_nesting`` in ``esptool/test/test_espefuse_host.py``).
This command supports nesting. This means that one script can be called from another script (see the test case ``test_execute_scripts_nesting`` in ``esptool/test/test_espefuse.py``).

.. code-block:: none
Expand Down Expand Up @@ -70,7 +70,7 @@ See how it is done (for ESP32) for ``CODING_SCHEME`` when ``get_meaning()`` is c
After ``efuses.burn_all()``, all needed efuses will be burnt to chip in order ``BLK_MAX`` to ``BLK_0``. This order prevents cases when protection is set before the value goes to a block. Please note this while developing your scripts.
Upon completion, the new eFuses will be read back, and will be done some checks of written eFuses by ``espefuse.py``. In production, you might need to check that all written efuses are set properly, see the example below.

The script `test_efuse_script.py <https://github.com/espressif/esptool/blob/master/test/efuse_scripts/esp32xx/test_efuse_script.py>`__ burns some efuses and checks them after reading back. To check read and write protection, ``is_readable()`` and ``is_writeable()`` are called.
The script `execute_efuse_script.py <https://github.com/espressif/esptool/blob/master/test/efuse_scripts/esp32xx/execute_efuse_script.py>`__ burns some efuses and checks them after reading back. To check read and write protection, ``is_readable()`` and ``is_writeable()`` are called.

Burn Unique Data Per Chip
^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down Expand Up @@ -104,7 +104,7 @@ The example of a script to burn custom_mac address that generated right in the s

.. code:: python
# efuse_script2.py
# efuse_script2.py
step = 4
base_mac = '0xAABBCCDD0000'
Expand Down
23 changes: 17 additions & 6 deletions test/conftest.py
@@ -1,20 +1,31 @@
def pytest_addoption(parser):
# test_esptool.py and test_espefuse.py
parser.addoption(
"--port", action="store", default="/dev/ttyUSB0", help="Serial port"
)
parser.addoption("--chip", action="store", default="esp32", help="Chip type")

# test_esptool.py only
parser.addoption("--baud", action="store", default=115200, help="Baud rate")
parser.addoption("--with-trace", action="store_true", default=False, help="Trace")

# test_espefuse.py only
parser.addoption(
"--with_trace",
action="store_true",
default=False,
help="Trace interactions",
"--reset-port", action="store", default=None, help="FPGA reset port"
)


def pytest_configure(config):
global arg_port, arg_chip, arg_baud, arg_trace
# test_esptool.py and test_espefuse.py
global arg_port, arg_chip
arg_port = config.getoption("--port")
arg_chip = config.getoption("--chip")

# test_esptool.py only
global arg_baud, arg_trace
arg_baud = config.getoption("--baud")
arg_trace = config.getoption("--with_trace")
arg_trace = config.getoption("--with-trace")

# test_espefuse.py only
global arg_reset_port
arg_reset_port = config.getoption("--reset-port")

0 comments on commit 2b42855

Please sign in to comment.