2023-12-18 09:29:58 -05:00
|
|
|
# SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
|
2023-07-31 00:49:08 -04:00
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
|
|
|
"""
|
|
|
|
Pytest Related Constants. Don't import third-party packages here.
|
|
|
|
"""
|
2023-06-13 05:12:55 -04:00
|
|
|
import os
|
2023-07-31 00:49:08 -04:00
|
|
|
import typing as t
|
|
|
|
from dataclasses import dataclass
|
2023-11-28 08:38:47 -05:00
|
|
|
from enum import Enum
|
|
|
|
from functools import cached_property
|
2023-12-18 09:29:58 -05:00
|
|
|
from pathlib import Path
|
2023-07-31 00:49:08 -04:00
|
|
|
|
2023-06-13 05:12:55 -04:00
|
|
|
from _pytest.python import Function
|
2023-12-18 09:29:58 -05:00
|
|
|
from idf_ci_utils import IDF_PATH
|
2023-06-13 05:12:55 -04:00
|
|
|
from pytest_embedded.utils import to_list
|
|
|
|
|
2024-01-01 21:21:45 -05:00
|
|
|
SUPPORTED_TARGETS = ['esp32', 'esp32s2', 'esp32c3', 'esp32s3', 'esp32c2', 'esp32c6', 'esp32h2', 'esp32p4']
|
2023-07-31 00:49:08 -04:00
|
|
|
PREVIEW_TARGETS: t.List[str] = [] # this PREVIEW_TARGETS excludes 'linux' target
|
|
|
|
DEFAULT_SDKCONFIG = 'default'
|
|
|
|
|
|
|
|
TARGET_MARKERS = {
|
|
|
|
'esp32': 'support esp32 target',
|
|
|
|
'esp32s2': 'support esp32s2 target',
|
|
|
|
'esp32s3': 'support esp32s3 target',
|
|
|
|
'esp32c3': 'support esp32c3 target',
|
|
|
|
'esp32c2': 'support esp32c2 target',
|
|
|
|
'esp32c6': 'support esp32c6 target',
|
|
|
|
'esp32h2': 'support esp32h2 target',
|
2023-08-18 00:05:16 -04:00
|
|
|
'esp32p4': 'support esp32p4 target',
|
2023-07-31 00:49:08 -04:00
|
|
|
'linux': 'support linux target',
|
|
|
|
}
|
|
|
|
|
|
|
|
SPECIAL_MARKERS = {
|
|
|
|
'supported_targets': "support all officially announced supported targets ('esp32', 'esp32s2', 'esp32c3', 'esp32s3', 'esp32c2', 'esp32c6')",
|
|
|
|
'preview_targets': "support all preview targets ('none')",
|
|
|
|
'all_targets': 'support all targets, including supported ones and preview ones',
|
|
|
|
'temp_skip_ci': 'temp skip tests for specified targets only in ci',
|
|
|
|
'temp_skip': 'temp skip tests for specified targets both in ci and locally',
|
|
|
|
'nightly_run': 'tests should be executed as part of the nightly trigger pipeline',
|
|
|
|
'host_test': 'tests which should not be built at the build stage, and instead built in host_test stage',
|
|
|
|
}
|
|
|
|
|
|
|
|
ENV_MARKERS = {
|
2023-11-28 08:38:47 -05:00
|
|
|
# special markers
|
|
|
|
'qemu': 'build and test using qemu, not real target',
|
2023-07-31 00:49:08 -04:00
|
|
|
# single-dut markers
|
|
|
|
'generic': 'tests should be run on generic runners',
|
|
|
|
'flash_suspend': 'support flash suspend feature',
|
|
|
|
'ip101': 'connected via wired 10/100M ethernet',
|
2023-10-09 05:47:32 -04:00
|
|
|
'eth_lan8720': 'connected via LAN8720 ethernet transceiver',
|
|
|
|
'eth_rtl8201': 'connected via RTL8201 ethernet transceiver',
|
|
|
|
'eth_ksz8041': 'connected via KSZ8041 ethernet transceiver',
|
|
|
|
'eth_dp83848': 'connected via DP83848 ethernet transceiver',
|
|
|
|
'eth_w5500': 'SPI Ethernet module with two W5500',
|
|
|
|
'eth_ksz8851snl': 'SPI Ethernet module with two KSZ8851SNL',
|
|
|
|
'eth_dm9051': 'SPI Ethernet module with two DM9051',
|
2023-07-31 00:49:08 -04:00
|
|
|
'quad_psram': 'runners with quad psram',
|
|
|
|
'octal_psram': 'runners with octal psram',
|
|
|
|
'usb_host': 'usb host runners',
|
|
|
|
'usb_host_flash_disk': 'usb host runners with USB flash disk attached',
|
|
|
|
'usb_device': 'usb device runners',
|
|
|
|
'ethernet_ota': 'ethernet OTA runners',
|
|
|
|
'flash_encryption': 'Flash Encryption runners',
|
|
|
|
'flash_encryption_f4r8': 'Flash Encryption runners with 4-line flash and 8-line psram',
|
|
|
|
'flash_encryption_f8r8': 'Flash Encryption runners with 8-line flash and 8-line psram',
|
|
|
|
'flash_multi': 'Multiple flash chips tests',
|
|
|
|
'psram': 'Chip has 4-line psram',
|
|
|
|
'ir_transceiver': 'runners with a pair of IR transmitter and receiver',
|
|
|
|
'twai_transceiver': 'runners with a TWAI PHY transceiver',
|
|
|
|
'flash_encryption_wifi_high_traffic': 'Flash Encryption runners with wifi high traffic support',
|
|
|
|
'ethernet': 'ethernet runner',
|
|
|
|
'ethernet_flash_8m': 'ethernet runner with 8mb flash',
|
|
|
|
'ethernet_router': 'both the runner and dut connect to the same router through ethernet NIC',
|
|
|
|
'ethernet_vlan': 'ethernet runner GARM-32-SH-1-R16S5N3',
|
|
|
|
'wifi_ap': 'a wifi AP in the environment',
|
|
|
|
'wifi_router': 'both the runner and dut connect to the same wifi router',
|
|
|
|
'wifi_high_traffic': 'wifi high traffic runners',
|
|
|
|
'wifi_wlan': 'wifi runner with a wireless NIC',
|
|
|
|
'Example_ShieldBox_Basic': 'basic configuration of the AP and ESP DUT placed in shielded box',
|
|
|
|
'Example_ShieldBox': 'multiple shielded APs connected to shielded ESP DUT via RF cable with programmable attenuator',
|
|
|
|
'xtal_26mhz': 'runner with 26MHz xtal on board',
|
|
|
|
'xtal_40mhz': 'runner with 40MHz xtal on board',
|
|
|
|
'external_flash': 'external flash memory connected via VSPI (FSPI)',
|
2023-11-27 06:55:53 -05:00
|
|
|
'sdcard_sdmode': 'sdcard running in SD mode, to be removed after test migration',
|
2023-07-31 00:49:08 -04:00
|
|
|
'sdcard_spimode': 'sdcard running in SPI mode',
|
|
|
|
'emmc': 'eMMC card',
|
2023-11-27 06:55:53 -05:00
|
|
|
'sdcard': 'sdcard runner',
|
2023-07-31 00:49:08 -04:00
|
|
|
'MSPI_F8R8': 'runner with Octal Flash and Octal PSRAM',
|
|
|
|
'MSPI_F4R8': 'runner with Quad Flash and Octal PSRAM',
|
|
|
|
'MSPI_F4R4': 'runner with Quad Flash and Quad PSRAM',
|
|
|
|
'jtag': 'runner where the chip is accessible through JTAG as well',
|
|
|
|
'usb_serial_jtag': 'runner where the chip is accessible through builtin JTAG as well',
|
|
|
|
'adc': 'ADC related tests should run on adc runners',
|
|
|
|
'xtal32k': 'Runner with external 32k crystal connected',
|
|
|
|
'no32kXtal': 'Runner with no external 32k crystal connected',
|
|
|
|
'psramv0': 'Runner with PSRAM version 0',
|
|
|
|
'esp32eco3': 'Runner with esp32 eco3 connected',
|
|
|
|
'ecdsa_efuse': 'Runner with test ECDSA private keys programmed in efuse',
|
|
|
|
'ccs811': 'Runner with CCS811 connected',
|
|
|
|
'nvs_encr_hmac': 'Runner with test HMAC key programmed in efuse',
|
|
|
|
'i2c_oled': 'Runner with ssd1306 I2C oled connected',
|
|
|
|
'httpbin': 'runner for tests that need to access the httpbin service',
|
|
|
|
# multi-dut markers
|
2023-11-28 08:38:47 -05:00
|
|
|
'multi_dut_modbus_rs485': 'a pair of runners connected by RS485 bus',
|
2023-07-31 00:49:08 -04:00
|
|
|
'ieee802154': 'ieee802154 related tests should run on ieee802154 runners.',
|
|
|
|
'openthread_br': 'tests should be used for openthread border router.',
|
2023-09-05 22:54:19 -04:00
|
|
|
'openthread_bbr': 'tests should be used for openthread border router linked to Internet.',
|
2023-07-31 00:49:08 -04:00
|
|
|
'openthread_sleep': 'tests should be used for openthread sleepy device.',
|
|
|
|
'zigbee_multi_dut': 'zigbee runner which have multiple duts.',
|
|
|
|
'wifi_two_dut': 'tests should be run on runners which has two wifi duts connected.',
|
|
|
|
'generic_multi_device': 'generic multiple devices whose corresponding gpio pins are connected to each other.',
|
|
|
|
'twai_network': 'multiple runners form a TWAI network.',
|
2023-10-26 06:46:56 -04:00
|
|
|
'sdio_master_slave': 'Test sdio multi board, esp32+esp32',
|
|
|
|
'sdio_multidev_32_c6': 'Test sdio multi board, esp32+esp32c6',
|
2023-12-25 21:38:06 -05:00
|
|
|
'usj_device': 'Test usb_serial_jtag and usb_serial_jtag is used as serial only (not console)',
|
2023-12-18 09:29:58 -05:00
|
|
|
'twai_std': 'twai runner with all twai supported targets connect to usb-can adapter',
|
2023-07-31 00:49:08 -04:00
|
|
|
}
|
|
|
|
|
2023-12-18 09:29:58 -05:00
|
|
|
DEFAULT_CONFIG_RULES_STR = ['sdkconfig.ci=default', 'sdkconfig.ci.*=', '=default']
|
|
|
|
DEFAULT_IGNORE_WARNING_FILEPATH = os.path.join(IDF_PATH, 'tools', 'ci', 'ignore_build_warnings.txt')
|
|
|
|
DEFAULT_BUILD_TEST_RULES_FILEPATH = os.path.join(IDF_PATH, '.gitlab', 'ci', 'default-build-test-rules.yml')
|
|
|
|
DEFAULT_FULL_BUILD_TEST_FILEPATTERNS = [
|
|
|
|
# tools
|
|
|
|
'tools/cmake/**/*',
|
|
|
|
'tools/tools.json',
|
|
|
|
# components
|
|
|
|
'components/cxx/**/*',
|
|
|
|
'components/esp_common/**/*',
|
|
|
|
'components/esp_hw_support/**/*',
|
|
|
|
'components/esp_rom/**/*',
|
|
|
|
'components/esp_system/**/*',
|
|
|
|
'components/esp_timer/**/*',
|
|
|
|
'components/freertos/**/*',
|
|
|
|
'components/hal/**/*',
|
|
|
|
'components/heap/**/*',
|
|
|
|
'components/log/**/*',
|
|
|
|
'components/newlib/**/*',
|
|
|
|
'components/riscv/**/*',
|
|
|
|
'components/soc/**/*',
|
|
|
|
'components/xtensa/**/*',
|
|
|
|
]
|
|
|
|
DEFAULT_BUILD_LOG_FILENAME = 'build_log.txt'
|
|
|
|
|
2023-07-31 00:49:08 -04:00
|
|
|
|
2023-11-28 08:38:47 -05:00
|
|
|
class CollectMode(str, Enum):
|
|
|
|
SINGLE_SPECIFIC = 'single_specific'
|
|
|
|
MULTI_SPECIFIC = 'multi_specific'
|
|
|
|
MULTI_ALL_WITH_PARAM = 'multi_all_with_param'
|
|
|
|
ALL = 'all'
|
|
|
|
|
|
|
|
|
2023-07-31 00:49:08 -04:00
|
|
|
@dataclass
|
|
|
|
class PytestApp:
|
|
|
|
path: str
|
|
|
|
target: str
|
|
|
|
config: str
|
|
|
|
|
|
|
|
def __hash__(self) -> int:
|
|
|
|
return hash((self.path, self.target, self.config))
|
|
|
|
|
2023-11-28 08:38:47 -05:00
|
|
|
@cached_property
|
|
|
|
def build_dir(self) -> str:
|
|
|
|
return os.path.join(self.path, f'build_{self.target}_{self.config}')
|
|
|
|
|
2023-07-31 00:49:08 -04:00
|
|
|
|
|
|
|
@dataclass
|
|
|
|
class PytestCase:
|
2023-11-28 08:38:47 -05:00
|
|
|
apps: t.List[PytestApp]
|
2023-07-31 00:49:08 -04:00
|
|
|
|
2023-06-13 05:12:55 -04:00
|
|
|
item: Function
|
2023-07-31 00:49:08 -04:00
|
|
|
|
|
|
|
def __hash__(self) -> int:
|
2023-06-13 05:12:55 -04:00
|
|
|
return hash((self.path, self.name, self.apps, self.all_markers))
|
|
|
|
|
2023-11-28 08:38:47 -05:00
|
|
|
@cached_property
|
|
|
|
def path(self) -> str:
|
|
|
|
return str(self.item.path)
|
2023-06-13 05:12:55 -04:00
|
|
|
|
2023-11-28 08:38:47 -05:00
|
|
|
@cached_property
|
|
|
|
def name(self) -> str:
|
|
|
|
return self.item.originalname # type: ignore
|
2023-06-13 05:12:55 -04:00
|
|
|
|
2023-11-28 08:38:47 -05:00
|
|
|
@cached_property
|
|
|
|
def targets(self) -> t.List[str]:
|
|
|
|
return [app.target for app in self.apps]
|
|
|
|
|
|
|
|
@cached_property
|
|
|
|
def is_single_dut_test_case(self) -> bool:
|
|
|
|
return True if len(self.apps) == 1 else False
|
2023-06-13 05:12:55 -04:00
|
|
|
|
2023-12-18 09:29:58 -05:00
|
|
|
@cached_property
|
|
|
|
def is_host_test(self) -> bool:
|
|
|
|
return 'host_test' in self.all_markers or 'linux' in self.targets
|
|
|
|
|
2023-11-28 08:38:47 -05:00
|
|
|
# the following markers could be changed dynamically, don't use cached_property
|
2023-06-13 05:12:55 -04:00
|
|
|
@property
|
2023-11-28 08:38:47 -05:00
|
|
|
def all_markers(self) -> t.Set[str]:
|
|
|
|
return {marker.name for marker in self.item.iter_markers()}
|
2023-06-13 05:12:55 -04:00
|
|
|
|
|
|
|
@property
|
2023-11-28 08:38:47 -05:00
|
|
|
def target_markers(self) -> t.Set[str]:
|
2023-06-13 05:12:55 -04:00
|
|
|
def _get_temp_markers_disabled_targets(marker_name: str) -> t.Set[str]:
|
|
|
|
temp_marker = self.item.get_closest_marker(marker_name)
|
|
|
|
|
|
|
|
if not temp_marker:
|
|
|
|
return set()
|
|
|
|
|
|
|
|
# temp markers should always use keyword arguments `targets` and `reason`
|
|
|
|
if not temp_marker.kwargs.get('targets') or not temp_marker.kwargs.get('reason'):
|
|
|
|
raise ValueError(
|
|
|
|
f'`{marker_name}` should always use keyword arguments `targets` and `reason`. '
|
|
|
|
f'For example: '
|
|
|
|
f'`@pytest.mark.{marker_name}(targets=["esp32"], reason="IDF-xxxx, will fix it ASAP")`'
|
|
|
|
)
|
|
|
|
|
|
|
|
return set(to_list(temp_marker.kwargs['targets'])) # type: ignore
|
|
|
|
|
|
|
|
temp_skip_ci_targets = _get_temp_markers_disabled_targets('temp_skip_ci')
|
|
|
|
temp_skip_targets = _get_temp_markers_disabled_targets('temp_skip')
|
|
|
|
|
|
|
|
# in CI we skip the union of `temp_skip` and `temp_skip_ci`
|
|
|
|
if os.getenv('CI_JOB_ID'):
|
|
|
|
skip_targets = temp_skip_ci_targets.union(temp_skip_targets)
|
|
|
|
else: # we use `temp_skip` locally
|
|
|
|
skip_targets = temp_skip_targets
|
|
|
|
|
2023-11-28 08:38:47 -05:00
|
|
|
return {marker for marker in self.all_markers if marker in TARGET_MARKERS} - skip_targets
|
|
|
|
|
|
|
|
@property
|
|
|
|
def env_markers(self) -> t.Set[str]:
|
|
|
|
return {marker for marker in self.all_markers if marker in ENV_MARKERS}
|
|
|
|
|
|
|
|
@property
|
2023-12-18 09:29:58 -05:00
|
|
|
def target_selector(self) -> str:
|
|
|
|
return ','.join(app.target for app in self.apps)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def requires_elf_or_map(self) -> bool:
|
|
|
|
"""
|
|
|
|
This property determines whether the test case requires elf or map file. By default, one app in the test case
|
|
|
|
only requires .bin files.
|
|
|
|
|
|
|
|
:return: True if the test case requires elf or map file, False otherwise
|
|
|
|
"""
|
|
|
|
if 'jtag' in self.env_markers or 'usb_serial_jtag' in self.env_markers:
|
|
|
|
return True
|
2023-11-28 08:38:47 -05:00
|
|
|
|
2023-12-18 09:29:58 -05:00
|
|
|
if any('panic' in Path(app.path).parts for app in self.apps):
|
|
|
|
return True
|
|
|
|
|
|
|
|
return False
|
2023-11-28 08:38:47 -05:00
|
|
|
|
2023-12-18 09:29:58 -05:00
|
|
|
def all_built_in_app_lists(self, app_lists: t.Optional[t.List[str]] = None) -> t.Optional[str]:
|
|
|
|
"""
|
|
|
|
Check if all binaries of the test case are built in the app lists.
|
2023-11-28 08:38:47 -05:00
|
|
|
|
2023-12-18 09:29:58 -05:00
|
|
|
:param app_lists: app lists to check
|
|
|
|
:return: debug string if not all binaries are built in the app lists, None otherwise
|
|
|
|
"""
|
2023-11-28 08:38:47 -05:00
|
|
|
if app_lists is None:
|
|
|
|
# ignore this feature
|
2023-12-18 09:29:58 -05:00
|
|
|
return None
|
2023-11-28 08:38:47 -05:00
|
|
|
|
|
|
|
bin_found = [0] * len(self.apps)
|
|
|
|
for i, app in enumerate(self.apps):
|
|
|
|
if app.build_dir in app_lists:
|
|
|
|
bin_found[i] = 1
|
|
|
|
|
|
|
|
if sum(bin_found) == 0:
|
|
|
|
msg = f'Skip test case {self.name} because all following binaries are not listed in the app lists: '
|
|
|
|
for app in self.apps:
|
|
|
|
msg += f'\n - {app.build_dir}'
|
|
|
|
|
|
|
|
print(msg)
|
2023-12-18 09:29:58 -05:00
|
|
|
return msg
|
2023-11-28 08:38:47 -05:00
|
|
|
|
|
|
|
if sum(bin_found) == len(self.apps):
|
2023-12-18 09:29:58 -05:00
|
|
|
return None
|
2023-11-28 08:38:47 -05:00
|
|
|
|
|
|
|
# some found, some not, looks suspicious
|
|
|
|
msg = f'Found some binaries of test case {self.name} are not listed in the app lists.'
|
|
|
|
for i, app in enumerate(self.apps):
|
|
|
|
if bin_found[i] == 0:
|
|
|
|
msg += f'\n - {app.build_dir}'
|
|
|
|
|
|
|
|
msg += '\nMight be a issue of .build-test-rules.yml files'
|
2023-12-18 09:29:58 -05:00
|
|
|
print(msg)
|
|
|
|
return msg
|