test: format all test scripts

This commit is contained in:
igor.udot
2025-02-24 10:18:03 +08:00
parent 717c18a58e
commit daf2d31008
381 changed files with 6180 additions and 4289 deletions

View File

@@ -1,62 +1,68 @@
# SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
# SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Unlicense OR CC0-1.0
import logging
import os
import pytest
from pytest_embedded import Dut
from pytest_embedded_idf.utils import idf_parametrize
from pytest_embedded_qemu.dut import QemuDut
def basic_efuse_example(dut: Dut) -> None:
dut.expect(r'example: Coding Scheme (3/4)|(NONE)|(REPEAT)|(RS \(Reed-Solomon coding\))', timeout=20)
dut.expect(['example: read efuse fields',
r'example: 1. read MAC address: {}'.format(r':'.join((r'[0-9a-f]{2}',) * 6)),
'example: 2. read secure_version: 0',
'example: 3. read custom fields',
'example: module_version = 0',
'example: device_role = None',
'example: setting_1 = 0',
'example: setting_2 = 0',
'example: custom_secure_version = 0',
'example: This example does not burn any efuse in reality only virtually',
'example: Write operations in efuse fields are performed virtually',
'example: write custom efuse fields',
'efuse: Virtual efuses enabled: Not really burning eFuses',
'example: module_version = 1',
'example: device_role = Slave',
'example: setting_1 = 3',
'example: setting_2 = 4',
'example: custom_secure_version = 5',
'example: Done'], expect_all=True)
dut.expect(
[
'example: read efuse fields',
r'example: 1. read MAC address: {}'.format(r':'.join((r'[0-9a-f]{2}',) * 6)),
'example: 2. read secure_version: 0',
'example: 3. read custom fields',
'example: module_version = 0',
'example: device_role = None',
'example: setting_1 = 0',
'example: setting_2 = 0',
'example: custom_secure_version = 0',
'example: This example does not burn any efuse in reality only virtually',
'example: Write operations in efuse fields are performed virtually',
'example: write custom efuse fields',
'efuse: Virtual efuses enabled: Not really burning eFuses',
'example: module_version = 1',
'example: device_role = Slave',
'example: setting_1 = 3',
'example: setting_2 = 4',
'example: custom_secure_version = 5',
'example: Done',
],
expect_all=True,
)
@pytest.mark.generic
@pytest.mark.esp32
@pytest.mark.esp32c2
@pytest.mark.esp32c3
@idf_parametrize('target', ['esp32', 'esp32c2', 'esp32c3'], indirect=['target'])
def test_examples_efuse(dut: Dut) -> None:
basic_efuse_example(dut)
@pytest.mark.linux
@pytest.mark.host_test
@idf_parametrize('target', ['linux'], indirect=['target'])
def test_examples_efuse_linux(dut: Dut) -> None:
basic_efuse_example(dut)
@pytest.mark.generic
@pytest.mark.esp32
@pytest.mark.esp32c2
@pytest.mark.esp32c3
@pytest.mark.esp32c5
@pytest.mark.esp32c61
@pytest.mark.esp32c6
@pytest.mark.esp32h2
@pytest.mark.esp32s2
@pytest.mark.esp32s3
@pytest.mark.parametrize('config', ['virt_flash_enc',], indirect=True)
@pytest.mark.parametrize(
'config',
[
'virt_flash_enc',
],
indirect=True,
)
@pytest.mark.parametrize('skip_autoflash', ['y'], indirect=True)
@idf_parametrize(
'target',
['esp32', 'esp32c2', 'esp32c3', 'esp32c5', 'esp32c61', 'esp32c6', 'esp32h2', 'esp32s2', 'esp32s3'],
indirect=['target'],
)
def test_examples_efuse_with_virt_flash_enc(dut: Dut) -> None:
# check and log bin size
binary_file = os.path.join(dut.app.binary_path, 'bootloader', 'bootloader.bin')
@@ -106,9 +112,15 @@ def test_examples_efuse_with_virt_flash_enc(dut: Dut) -> None:
@pytest.mark.generic
@pytest.mark.esp32s2
@pytest.mark.parametrize('config', ['virt_flash_enc_aes_256',], indirect=True)
@pytest.mark.parametrize(
'config',
[
'virt_flash_enc_aes_256',
],
indirect=True,
)
@pytest.mark.parametrize('skip_autoflash', ['y'], indirect=True)
@idf_parametrize('target', ['esp32s2'], indirect=['target'])
def test_examples_efuse_with_virt_flash_enc_aes_256(dut: Dut) -> None:
# Only ESP32-S2 has support AES-256 FLASH_ENCRYPTION key
# check and log bin size
@@ -147,19 +159,20 @@ def test_examples_efuse_with_virt_flash_enc_aes_256(dut: Dut) -> None:
@pytest.mark.generic
@pytest.mark.esp32
@pytest.mark.esp32c2
@pytest.mark.esp32c3
@pytest.mark.esp32c5
@pytest.mark.esp32c61
@pytest.mark.esp32c6
@pytest.mark.esp32h2
@pytest.mark.esp32s2
@pytest.mark.esp32s3
@pytest.mark.parametrize('config', ['virt_flash_enc',], indirect=True)
@pytest.mark.parametrize(
'config',
[
'virt_flash_enc',
],
indirect=True,
)
@pytest.mark.parametrize('skip_autoflash', ['y'], indirect=True)
@idf_parametrize(
'target',
['esp32', 'esp32c2', 'esp32c3', 'esp32c5', 'esp32c61', 'esp32c6', 'esp32h2', 'esp32s2', 'esp32s3'],
indirect=['target'],
)
def test_examples_efuse_with_virt_flash_enc_pre_loaded(dut: Dut) -> None:
print(' - Erase flash')
dut.serial.erase_flash()
@@ -216,17 +229,19 @@ def test_examples_efuse_with_virt_flash_enc_pre_loaded(dut: Dut) -> None:
@pytest.mark.generic
@pytest.mark.esp32
@pytest.mark.esp32c2
@pytest.mark.esp32c3
@pytest.mark.esp32c5
@pytest.mark.esp32c61
@pytest.mark.esp32c6
@pytest.mark.esp32h2
@pytest.mark.esp32s2
@pytest.mark.esp32s3
@pytest.mark.parametrize('config', ['virt_flash_enc_release',], indirect=True)
@pytest.mark.parametrize(
'config',
[
'virt_flash_enc_release',
],
indirect=True,
)
@pytest.mark.parametrize('skip_autoflash', ['y'], indirect=True)
@idf_parametrize(
'target',
['esp32', 'esp32c2', 'esp32c3', 'esp32c5', 'esp32c61', 'esp32c6', 'esp32h2', 'esp32s2', 'esp32s3'],
indirect=['target'],
)
def test_examples_efuse_with_virt_flash_enc_release(dut: Dut) -> None:
# check and log bin size
binary_file = os.path.join(dut.app.binary_path, 'bootloader', 'bootloader.bin')
@@ -273,9 +288,15 @@ def test_examples_efuse_with_virt_flash_enc_release(dut: Dut) -> None:
@pytest.mark.generic
@pytest.mark.esp32
@pytest.mark.parametrize('config', ['virt_secure_boot_v1',], indirect=True)
@pytest.mark.parametrize(
'config',
[
'virt_secure_boot_v1',
],
indirect=True,
)
@pytest.mark.parametrize('skip_autoflash', ['y'], indirect=True)
@idf_parametrize('target', ['esp32'], indirect=['target'])
def test_examples_efuse_with_virt_secure_boot_v1(dut: Dut) -> None:
# only for ESP32
# check and log bin size
@@ -321,9 +342,15 @@ def test_examples_efuse_with_virt_secure_boot_v1(dut: Dut) -> None:
@pytest.mark.generic
@pytest.mark.esp32
@pytest.mark.parametrize('config', ['virt_secure_boot_v1',], indirect=True)
@pytest.mark.parametrize(
'config',
[
'virt_secure_boot_v1',
],
indirect=True,
)
@pytest.mark.parametrize('skip_autoflash', ['y'], indirect=True)
@idf_parametrize('target', ['esp32'], indirect=['target'])
def test_examples_efuse_with_virt_secure_boot_v1_pre_loaded(dut: Dut) -> None:
print(' - Erase flash')
dut.serial.erase_flash()
@@ -373,10 +400,16 @@ def test_examples_efuse_with_virt_secure_boot_v1_pre_loaded(dut: Dut) -> None:
dut.expect('example: Done')
@pytest.mark.esp32
@pytest.mark.esp32eco3
@pytest.mark.parametrize('config', [('virt_secure_boot_v2'),], indirect=True)
@pytest.mark.parametrize(
'config',
[
('virt_secure_boot_v2'),
],
indirect=True,
)
@pytest.mark.parametrize('skip_autoflash', ['y'], indirect=True)
@idf_parametrize('target', ['esp32'], indirect=['target'])
def test_examples_efuse_with_virt_secure_boot_v2(dut: Dut) -> None:
# only for ESP32 ECO3
binary_file = os.path.join(dut.app.binary_path, 'bootloader', 'bootloader.bin')
@@ -487,12 +520,17 @@ def test_examples_efuse_with_virt_secure_boot_v2(dut: Dut) -> None:
dut.expect('example: Done')
@pytest.mark.esp32
@pytest.mark.esp32eco3
@pytest.mark.parametrize('config', [('virt_secure_boot_v2'),], indirect=True)
@pytest.mark.parametrize(
'config',
[
('virt_secure_boot_v2'),
],
indirect=True,
)
@pytest.mark.parametrize('skip_autoflash', ['y'], indirect=True)
@idf_parametrize('target', ['esp32'], indirect=['target'])
def test_examples_efuse_with_virt_secure_boot_v2_pre_loaded(dut: Dut) -> None:
print(' - Erase flash')
dut.serial.erase_flash()
print(' - Flash bootloader and app')
@@ -550,18 +588,14 @@ def test_examples_efuse_with_virt_secure_boot_v2_pre_loaded(dut: Dut) -> None:
dut.expect('example: Done')
@pytest.mark.esp32c3
@pytest.mark.esp32c2
@pytest.mark.esp32c5
@pytest.mark.esp32c6
@pytest.mark.esp32c61
@pytest.mark.esp32h2
@pytest.mark.esp32p4
@pytest.mark.esp32s2
@pytest.mark.esp32s3
@pytest.mark.generic
@pytest.mark.parametrize('config', ['virt_secure_boot_v2'], indirect=True)
@pytest.mark.parametrize('skip_autoflash', ['y'], indirect=True)
@idf_parametrize(
'target',
['esp32c3', 'esp32c2', 'esp32c5', 'esp32c6', 'esp32c61', 'esp32h2', 'esp32p4', 'esp32s2', 'esp32s3'],
indirect=['target'],
)
def test_examples_efuse_with_virt_secure_boot_v2_esp32xx(dut: Dut) -> None:
# check and log bin size
binary_file = os.path.join(dut.app.binary_path, 'bootloader', 'bootloader.bin')
@@ -625,18 +659,14 @@ def test_examples_efuse_with_virt_secure_boot_v2_esp32xx(dut: Dut) -> None:
dut.expect('example: Done')
@pytest.mark.esp32c3
@pytest.mark.esp32c2
@pytest.mark.esp32c5
@pytest.mark.esp32c6
@pytest.mark.esp32c61
@pytest.mark.esp32h2
@pytest.mark.esp32p4
@pytest.mark.esp32s2
@pytest.mark.esp32s3
@pytest.mark.generic
@pytest.mark.parametrize('config', ['virt_secure_boot_v2'], indirect=True)
@pytest.mark.parametrize('skip_autoflash', ['y'], indirect=True)
@idf_parametrize(
'target',
['esp32c3', 'esp32c2', 'esp32c5', 'esp32c6', 'esp32c61', 'esp32h2', 'esp32p4', 'esp32s2', 'esp32s3'],
indirect=['target'],
)
def test_example_efuse_with_virt_secure_boot_v2_esp32xx_pre_loaded(dut: Dut) -> None:
print(' - Erase flash')
dut.serial.erase_flash()
@@ -655,7 +685,12 @@ def test_example_efuse_with_virt_secure_boot_v2_esp32xx_pre_loaded(dut: Dut) ->
# Resets eFuse, which enables Secure boot feature
# Resets eFuses, which control digest slots
if dut.app.sdkconfig.get('SOC_EFUSE_REVOKE_BOOT_KEY_DIGESTS'):
dut.serial.erase_field_on_emul_efuse_by_name(['SECURE_BOOT_EN', 'SECURE_BOOT_KEY_REVOKE0', 'SECURE_BOOT_KEY_REVOKE1', 'SECURE_BOOT_KEY_REVOKE2'])
dut.serial.erase_field_on_emul_efuse_by_name([
'SECURE_BOOT_EN',
'SECURE_BOOT_KEY_REVOKE0',
'SECURE_BOOT_KEY_REVOKE1',
'SECURE_BOOT_KEY_REVOKE2',
])
else:
dut.serial.erase_field_on_emul_efuse_by_name(['SECURE_BOOT_EN'])
@@ -701,9 +736,15 @@ def test_example_efuse_with_virt_secure_boot_v2_esp32xx_pre_loaded(dut: Dut) ->
@pytest.mark.generic
@pytest.mark.esp32
@pytest.mark.parametrize('config', ['virt_sb_v1_and_fe',], indirect=True)
@pytest.mark.parametrize(
'config',
[
'virt_sb_v1_and_fe',
],
indirect=True,
)
@pytest.mark.parametrize('skip_autoflash', ['y'], indirect=True)
@idf_parametrize('target', ['esp32'], indirect=['target'])
def test_examples_efuse_with_virt_sb_v1_and_fe(dut: Dut) -> None:
# check and log bin size
binary_file = os.path.join(dut.app.binary_path, 'bootloader', 'bootloader.bin')
@@ -765,10 +806,16 @@ def test_examples_efuse_with_virt_sb_v1_and_fe(dut: Dut) -> None:
dut.expect('example: Done')
@pytest.mark.esp32
@pytest.mark.esp32eco3
@pytest.mark.parametrize('config', ['virt_sb_v2_and_fe',], indirect=True)
@pytest.mark.parametrize(
'config',
[
'virt_sb_v2_and_fe',
],
indirect=True,
)
@pytest.mark.parametrize('skip_autoflash', ['y'], indirect=True)
@idf_parametrize('target', ['esp32'], indirect=['target'])
def test_examples_efuse_with_virt_sb_v2_and_fe(dut: Dut) -> None:
# check and log bin size
binary_file = os.path.join(dut.app.binary_path, 'bootloader', 'bootloader.bin')
@@ -847,10 +894,15 @@ def test_examples_efuse_with_virt_sb_v2_and_fe(dut: Dut) -> None:
dut.expect('example: Done')
@pytest.mark.esp32
@pytest.mark.host_test
@pytest.mark.qemu
@pytest.mark.parametrize('config', ['virt_sb_v2_and_fe.esp32.qemu',], indirect=True)
@pytest.mark.parametrize(
'config',
[
'virt_sb_v2_and_fe.esp32.qemu',
],
indirect=True,
)
@pytest.mark.parametrize(
'qemu_extra_args',
[
@@ -860,6 +912,7 @@ def test_examples_efuse_with_virt_sb_v2_and_fe(dut: Dut) -> None:
],
indirect=True,
)
@idf_parametrize('target', ['esp32'], indirect=['target'])
def test_examples_efuse_with_virt_sb_v2_and_fe_qemu(dut: QemuDut) -> None:
try:
dut.expect('secure_boot_v2: Secure boot V2 is not enabled yet and eFuse digest keys are not set')
@@ -930,17 +983,14 @@ def test_examples_efuse_with_virt_sb_v2_and_fe_qemu(dut: QemuDut) -> None:
efuse_file.write(bytearray.fromhex(esp32eco3_efuses))
@pytest.mark.esp32c3
@pytest.mark.esp32c2
@pytest.mark.esp32c5
@pytest.mark.esp32c61
@pytest.mark.esp32c6
@pytest.mark.esp32h2
@pytest.mark.esp32s2
@pytest.mark.esp32s3
@pytest.mark.generic
@pytest.mark.parametrize('skip_autoflash', ['y'], indirect=True)
@pytest.mark.parametrize('config', ['virt_sb_v2_and_fe'], indirect=True)
@idf_parametrize(
'target',
['esp32c3', 'esp32c2', 'esp32c5', 'esp32c61', 'esp32c6', 'esp32h2', 'esp32s2', 'esp32s3'],
indirect=['target'],
)
def test_examples_efuse_with_virt_sb_v2_and_fe_esp32xx(dut: Dut) -> None:
# check and log bin size
binary_file = os.path.join(dut.app.binary_path, 'bootloader', 'bootloader.bin')