constants.py 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. # SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
  2. # SPDX-License-Identifier: Apache-2.0
  3. """
  4. Pytest Related Constants. Don't import third-party packages here.
  5. """
  6. import os
  7. import typing as t
  8. from dataclasses import dataclass
  9. from _pytest.python import Function
  10. from pytest_embedded.utils import to_list
  11. SUPPORTED_TARGETS = ['esp32', 'esp32s2', 'esp32c3', 'esp32s3', 'esp32c2', 'esp32c6', 'esp32h2']
  12. PREVIEW_TARGETS: t.List[str] = [] # this PREVIEW_TARGETS excludes 'linux' target
  13. DEFAULT_SDKCONFIG = 'default'
  14. TARGET_MARKERS = {
  15. 'esp32': 'support esp32 target',
  16. 'esp32s2': 'support esp32s2 target',
  17. 'esp32s3': 'support esp32s3 target',
  18. 'esp32c3': 'support esp32c3 target',
  19. 'esp32c2': 'support esp32c2 target',
  20. 'esp32c6': 'support esp32c6 target',
  21. 'esp32h2': 'support esp32h2 target',
  22. 'esp32p4': 'support esp32p4 target',
  23. 'linux': 'support linux target',
  24. }
  25. SPECIAL_MARKERS = {
  26. 'supported_targets': "support all officially announced supported targets ('esp32', 'esp32s2', 'esp32c3', 'esp32s3', 'esp32c2', 'esp32c6')",
  27. 'preview_targets': "support all preview targets ('none')",
  28. 'all_targets': 'support all targets, including supported ones and preview ones',
  29. 'temp_skip_ci': 'temp skip tests for specified targets only in ci',
  30. 'temp_skip': 'temp skip tests for specified targets both in ci and locally',
  31. 'nightly_run': 'tests should be executed as part of the nightly trigger pipeline',
  32. 'host_test': 'tests which should not be built at the build stage, and instead built in host_test stage',
  33. 'qemu': 'build and test using qemu-system-xtensa, not real target',
  34. }
  35. ENV_MARKERS = {
  36. # single-dut markers
  37. 'generic': 'tests should be run on generic runners',
  38. 'flash_suspend': 'support flash suspend feature',
  39. 'ip101': 'connected via wired 10/100M ethernet',
  40. 'eth_lan8720': 'connected via LAN8720 ethernet transceiver',
  41. 'eth_rtl8201': 'connected via RTL8201 ethernet transceiver',
  42. 'eth_ksz8041': 'connected via KSZ8041 ethernet transceiver',
  43. 'eth_dp83848': 'connected via DP83848 ethernet transceiver',
  44. 'eth_w5500': 'SPI Ethernet module with two W5500',
  45. 'eth_ksz8851snl': 'SPI Ethernet module with two KSZ8851SNL',
  46. 'eth_dm9051': 'SPI Ethernet module with two DM9051',
  47. 'quad_psram': 'runners with quad psram',
  48. 'octal_psram': 'runners with octal psram',
  49. 'usb_host': 'usb host runners',
  50. 'usb_host_flash_disk': 'usb host runners with USB flash disk attached',
  51. 'usb_device': 'usb device runners',
  52. 'ethernet_ota': 'ethernet OTA runners',
  53. 'flash_encryption': 'Flash Encryption runners',
  54. 'flash_encryption_f4r8': 'Flash Encryption runners with 4-line flash and 8-line psram',
  55. 'flash_encryption_f8r8': 'Flash Encryption runners with 8-line flash and 8-line psram',
  56. 'flash_multi': 'Multiple flash chips tests',
  57. 'psram': 'Chip has 4-line psram',
  58. 'ir_transceiver': 'runners with a pair of IR transmitter and receiver',
  59. 'twai_transceiver': 'runners with a TWAI PHY transceiver',
  60. 'flash_encryption_wifi_high_traffic': 'Flash Encryption runners with wifi high traffic support',
  61. 'ethernet': 'ethernet runner',
  62. 'ethernet_flash_8m': 'ethernet runner with 8mb flash',
  63. 'ethernet_router': 'both the runner and dut connect to the same router through ethernet NIC',
  64. 'ethernet_vlan': 'ethernet runner GARM-32-SH-1-R16S5N3',
  65. 'wifi_ap': 'a wifi AP in the environment',
  66. 'wifi_router': 'both the runner and dut connect to the same wifi router',
  67. 'wifi_high_traffic': 'wifi high traffic runners',
  68. 'wifi_wlan': 'wifi runner with a wireless NIC',
  69. 'Example_ShieldBox_Basic': 'basic configuration of the AP and ESP DUT placed in shielded box',
  70. 'Example_ShieldBox': 'multiple shielded APs connected to shielded ESP DUT via RF cable with programmable attenuator',
  71. 'xtal_26mhz': 'runner with 26MHz xtal on board',
  72. 'xtal_40mhz': 'runner with 40MHz xtal on board',
  73. 'external_flash': 'external flash memory connected via VSPI (FSPI)',
  74. 'sdcard_sdmode': 'sdcard running in SD mode',
  75. 'sdcard_spimode': 'sdcard running in SPI mode',
  76. 'emmc': 'eMMC card',
  77. 'MSPI_F8R8': 'runner with Octal Flash and Octal PSRAM',
  78. 'MSPI_F4R8': 'runner with Quad Flash and Octal PSRAM',
  79. 'MSPI_F4R4': 'runner with Quad Flash and Quad PSRAM',
  80. 'jtag': 'runner where the chip is accessible through JTAG as well',
  81. 'usb_serial_jtag': 'runner where the chip is accessible through builtin JTAG as well',
  82. 'adc': 'ADC related tests should run on adc runners',
  83. 'xtal32k': 'Runner with external 32k crystal connected',
  84. 'no32kXtal': 'Runner with no external 32k crystal connected',
  85. 'multi_dut_modbus_rs485': 'a pair of runners connected by RS485 bus',
  86. 'psramv0': 'Runner with PSRAM version 0',
  87. 'esp32eco3': 'Runner with esp32 eco3 connected',
  88. 'ecdsa_efuse': 'Runner with test ECDSA private keys programmed in efuse',
  89. 'ccs811': 'Runner with CCS811 connected',
  90. 'nvs_encr_hmac': 'Runner with test HMAC key programmed in efuse',
  91. 'i2c_oled': 'Runner with ssd1306 I2C oled connected',
  92. 'httpbin': 'runner for tests that need to access the httpbin service',
  93. # multi-dut markers
  94. 'ieee802154': 'ieee802154 related tests should run on ieee802154 runners.',
  95. 'openthread_br': 'tests should be used for openthread border router.',
  96. 'openthread_bbr': 'tests should be used for openthread border router linked to Internet.',
  97. 'openthread_sleep': 'tests should be used for openthread sleepy device.',
  98. 'zigbee_multi_dut': 'zigbee runner which have multiple duts.',
  99. 'wifi_two_dut': 'tests should be run on runners which has two wifi duts connected.',
  100. 'generic_multi_device': 'generic multiple devices whose corresponding gpio pins are connected to each other.',
  101. 'twai_network': 'multiple runners form a TWAI network.',
  102. 'sdio_master_slave': 'Test sdio multi board, esp32+esp32',
  103. 'sdio_multidev_32_c6': 'Test sdio multi board, esp32+esp32c6',
  104. }
  105. @dataclass
  106. class PytestApp:
  107. path: str
  108. target: str
  109. config: str
  110. def __hash__(self) -> int:
  111. return hash((self.path, self.target, self.config))
  112. @dataclass
  113. class PytestCase:
  114. path: str
  115. name: str
  116. apps: t.Set[PytestApp]
  117. target: str
  118. item: Function
  119. def __hash__(self) -> int:
  120. return hash((self.path, self.name, self.apps, self.all_markers))
  121. @property
  122. def all_markers(self) -> t.Set[str]:
  123. return {marker.name for marker in self.item.iter_markers()}
  124. @property
  125. def is_nightly_run(self) -> bool:
  126. return 'nightly_run' in self.all_markers
  127. @property
  128. def target_markers(self) -> t.Set[str]:
  129. return {marker for marker in self.all_markers if marker in TARGET_MARKERS}
  130. @property
  131. def env_markers(self) -> t.Set[str]:
  132. return {marker for marker in self.all_markers if marker in ENV_MARKERS}
  133. @property
  134. def skipped_targets(self) -> t.Set[str]:
  135. def _get_temp_markers_disabled_targets(marker_name: str) -> t.Set[str]:
  136. temp_marker = self.item.get_closest_marker(marker_name)
  137. if not temp_marker:
  138. return set()
  139. # temp markers should always use keyword arguments `targets` and `reason`
  140. if not temp_marker.kwargs.get('targets') or not temp_marker.kwargs.get('reason'):
  141. raise ValueError(
  142. f'`{marker_name}` should always use keyword arguments `targets` and `reason`. '
  143. f'For example: '
  144. f'`@pytest.mark.{marker_name}(targets=["esp32"], reason="IDF-xxxx, will fix it ASAP")`'
  145. )
  146. return set(to_list(temp_marker.kwargs['targets'])) # type: ignore
  147. temp_skip_ci_targets = _get_temp_markers_disabled_targets('temp_skip_ci')
  148. temp_skip_targets = _get_temp_markers_disabled_targets('temp_skip')
  149. # in CI we skip the union of `temp_skip` and `temp_skip_ci`
  150. if os.getenv('CI_JOB_ID'):
  151. skip_targets = temp_skip_ci_targets.union(temp_skip_targets)
  152. else: # we use `temp_skip` locally
  153. skip_targets = temp_skip_targets
  154. return skip_targets