test(parlio,rmt,lcd): add virtual flash encryption test

This commit is contained in:
Chen Jichang
2026-02-05 11:42:08 +08:00
committed by Chen Ji Chang
parent a483acbf8f
commit 0ac402217c
45 changed files with 643 additions and 30 deletions
@@ -0,0 +1,35 @@
# SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Apache-2.0
import pytest
from _pytest.fixtures import FixtureRequest
from _pytest.monkeypatch import MonkeyPatch
from pytest_embedded_idf.serial import IdfSerial
# This is a custom IdfSerial class to support custom functionality
# which is required only for this test
class EfuseFlashEncSerial(IdfSerial):
@IdfSerial.use_esptool()
def write_flash_no_enc(self) -> None:
self.app.flash_settings['encrypt'] = False
flash_files = []
for file in self.app.flash_files:
# Set encrypted flag to false for each file.
flash_files.append(file._replace(encrypted=False))
# Replace the original tuple with modified tuple with all the files marked as unencrypted.
self.app.flash_files = tuple(flash_files)
# Now flash the files
self.flash()
@pytest.fixture(scope='module')
def monkeypatch_module(request: FixtureRequest) -> MonkeyPatch:
mp = MonkeyPatch()
request.addfinalizer(mp.undo)
return mp
@pytest.fixture(scope='module', autouse=True)
def replace_dut_class(monkeypatch_module: MonkeyPatch) -> None:
monkeypatch_module.setattr('pytest_embedded_idf.IdfSerial', EfuseFlashEncSerial)
@@ -25,7 +25,7 @@
#define TEST_IMG_SIZE (100 * 100 * sizeof(uint16_t))
static void lcd_parlio_panel_with_st7789_interface(esp_lcd_panel_io_handle_t io_handle)
{
uint8_t *img = heap_caps_malloc(TEST_IMG_SIZE, MALLOC_CAP_DMA);
uint8_t *img = heap_caps_calloc(1, TEST_IMG_SIZE, MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL);
TEST_ASSERT_NOT_NULL(img);
gpio_config_t bk_gpio_config = {
@@ -148,7 +148,7 @@ static void lcd_parlio_send_colors_to_fixed_region(size_t data_width)
int x_end = 200;
int y_end = 200;
size_t color_size = (x_end - x_start) * (y_end - y_start) * 2;
void *color_data = malloc(color_size);
void *color_data = heap_caps_calloc(1, color_size, MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL);
TEST_ASSERT_NOT_NULL(color_data);
uint8_t color_byte = esp_random() & 0xFF;
memset(color_data, color_byte, color_size);
@@ -0,0 +1,7 @@
# Name, Type, SubType, Offset, Size, Flags
bootloader, bootloader, primary, N/A, N/A,
partition_table, partition_table, primary, N/A, N/A,
nvs, data, nvs, , 0x4000,
phy_init, data, phy, , 0x1000,
emul_efuse, data, efuse, , 0x2000,
factory, app, factory, , 1M,
1 # Name Type SubType Offset Size Flags
2 bootloader bootloader primary N/A N/A
3 partition_table partition_table primary N/A N/A
4 nvs data nvs 0x4000
5 phy_init data phy 0x1000
6 emul_efuse data efuse 0x2000
7 factory app factory 1M
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
# SPDX-FileCopyrightText: 2024-2026 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: CC0-1.0
import pytest
from pytest_embedded import Dut
@@ -16,3 +16,25 @@ from pytest_embedded_idf.utils import idf_parametrize
@idf_parametrize('target', ['esp32p4', 'esp32h2', 'esp32c5'], indirect=['target'])
def test_parlio_lcd(dut: Dut) -> None:
dut.run_all_single_board_cases()
@pytest.mark.generic
@pytest.mark.parametrize(
'config, skip_autoflash',
[
('virt_flash_enc', 'y'),
],
indirect=True,
)
@idf_parametrize('target', ['esp32p4', 'esp32h2', 'esp32c5'], indirect=['target'])
def test_parlio_lcd_with_virt_flash_enc(dut: Dut) -> None:
print(' - Erase flash')
dut.serial.erase_flash()
print(' - Start app (flash partition_table and app)')
dut.serial.write_flash_no_enc()
dut.expect('Loading virtual efuse blocks from real efuses')
dut.expect('Checking flash encryption...')
dut.expect('Generating new flash encryption key...')
dut.run_all_single_board_cases()
@@ -0,0 +1,12 @@
# FLASH_ENCRYPTION with EFUSE_VIRTUAL_KEEP_IN_FLASH
CONFIG_PARTITION_TABLE_OFFSET=0xC000
CONFIG_PARTITION_TABLE_CUSTOM=y
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions_efuse_emul.csv"
CONFIG_SECURE_FLASH_ENC_ENABLED=y
# Virtual eFuse mode is enough for driver behaviour test.
# Real encryption tests are guaranteed by DMA tests
CONFIG_EFUSE_VIRTUAL=y
CONFIG_EFUSE_VIRTUAL_KEEP_IN_FLASH=y