Skip to content

Commit

Permalink
Merge pull request #251 from espressif/fix/linux_dut_with_idf_unity_m…
Browse files Browse the repository at this point in the history
…ixin
  • Loading branch information
hfudev authored Jan 2, 2024
2 parents b57f32b + 464caf5 commit d553e14
Show file tree
Hide file tree
Showing 8 changed files with 1,640 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
- multiboard
- ${{ matrix.arch }}
container:
image: python:${{ matrix.python-version }}-bullseye
image: python:${{ matrix.python-version }}
options: --privileged
steps:
- uses: actions/checkout@v4
Expand Down
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ repos:
args: [ '-f=lf' ]
- id: double-quote-string-fixer
- repo: https://github.com/pycqa/isort
rev: 5.12.0
rev: 5.13.2
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: 23.10.1
rev: 23.12.1
hooks:
- id: black
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: 'v0.1.4'
rev: 'v0.1.9'
hooks:
- id: ruff
args: ['--fix']
- repo: https://github.com/espressif/conventional-precommit-linter
rev: v1.2.1
rev: v1.5.0
hooks:
- id: conventional-precommit-linter
stages: [commit-msg]
Expand Down
8 changes: 8 additions & 0 deletions pytest-embedded-idf/pytest_embedded_idf/linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ def __init__(
self.serial = serial
super().__init__(**kwargs)

self._hard_reset_func = self.serial.hard_reset

def write(self, data: t.AnyStr) -> None:
self.serial.write(data)

Expand All @@ -45,3 +47,9 @@ def __init__(
raise ValueError(f'Targets do not match. App target: {self.app.target}, Cmd target: "linux".')

super().__init__(cmd=[self.app.elf_file], **kwargs)

def hard_reset(self) -> None:
"""
Perform a fake hardware reset
"""
self.write('\n')
26 changes: 26 additions & 0 deletions pytest-embedded-idf/tests/test_idf.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,32 @@ def test_hello_world_linux(dut):

result.assert_outcomes(passed=1)

@pytest.mark.skipif(platform.machine() != 'x86_64', reason='The test is intended to be run on an x86_64 machine.')
def test_unity_tester_with_linux(testdir):
testdir.makepyfile(r"""
def test_unity_tester_with_linux(dut):
dut.run_all_single_board_cases()
"""
)

result = testdir.runpytest(
'-s',
'--embedded-services', 'idf',
'--app-path', f'{os.path.join(testdir.tmpdir, "unit_test_app_linux")}',
'--target', 'linux',
'--junitxml', 'report.xml',
)

result.assert_outcomes(passed=1)

junit_report = ET.parse('report.xml').getroot()[0]

assert junit_report.attrib['errors'] == '0'
assert junit_report.attrib['failures'] == '0'
assert junit_report.attrib['skipped'] == '0'
assert junit_report.attrib['tests'] == '46'


@toolchain_required
def test_check_coredump(testdir, caplog, first_index_of_messages):
Expand Down
32 changes: 15 additions & 17 deletions pytest-embedded/pytest_embedded/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1230,6 +1230,12 @@ def _fixture_classes_and_options(
'test_case_name': test_case_name,
'meta': _meta,
}
if 'idf' in _services and 'esp' not in _services:
# esp,idf will use IdfDut, which based on IdfUnityDutMixin already
from pytest_embedded_idf.unity_tester import IdfUnityDutMixin

mixins[fixture].append(IdfUnityDutMixin)

if 'wokwi' in _services:
from pytest_embedded_wokwi import WokwiDut

Expand All @@ -1241,15 +1247,12 @@ def _fixture_classes_and_options(
)

if 'idf' in _services:
from pytest_embedded_idf.unity_tester import IdfUnityDutMixin
from pytest_embedded_wokwi.idf import IDFFirmwareResolver

kwargs['wokwi'].update({'firmware_resolver': IDFFirmwareResolver()})

mixins[fixture].append(IdfUnityDutMixin)
else:
raise SystemExit('wokwi service should be used together with idf service')
if 'qemu' in _services:
elif 'qemu' in _services:
from pytest_embedded_qemu import QemuDut

classes[fixture] = QemuDut
Expand All @@ -1258,11 +1261,6 @@ def _fixture_classes_and_options(
'qemu': None,
}
)

if 'idf' in _services:
from pytest_embedded_idf.unity_tester import IdfUnityDutMixin

mixins[fixture].append(IdfUnityDutMixin)
elif 'jtag' in _services:
if 'idf' in _services:
from pytest_embedded_idf import IdfDut
Expand Down Expand Up @@ -1411,18 +1409,18 @@ def dut(
A device under test (DUT) object that could gather output from various sources and redirect them to the pexpect
process, and run `expect()` via its pexpect process.
"""
kwargs = _fixture_classes_and_options.kwargs['dut']
mixins = _fixture_classes_and_options.mixins['dut']

# since there's no way to know the target before setup finished
# we have to use the `app.target` to determine the dut class here
if hasattr(app, 'target') and app.target == 'linux':
from pytest_embedded_idf import LinuxDut

cls = LinuxDut
kwargs = _fixture_classes_and_options.kwargs['dut']
kwargs['serial'] = serial

return cls(**kwargs)

cls = _fixture_classes_and_options.classes['dut']
mixins = _fixture_classes_and_options.mixins['dut']
kwargs = _fixture_classes_and_options.kwargs['dut']
kwargs['serial'] = None # replace it later with LinuxSerial
else:
cls = _fixture_classes_and_options.classes['dut']

for k, v in kwargs.items():
if v is None:
Expand Down
177 changes: 177 additions & 0 deletions tests/fixtures/unit_test_app_linux/build/config/sdkconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
{
"APP_BUILD_GENERATE_BINARIES": true,
"APP_BUILD_TYPE_PURE_RAM_APP": false,
"APP_BUILD_TYPE_RAM": true,
"APP_NO_BLOBS": false,
"APP_REPRODUCIBLE_BUILD": false,
"BOOT_ROM_LOG_ALWAYS_OFF": false,
"BOOT_ROM_LOG_ALWAYS_ON": true,
"BOOT_ROM_LOG_ON_GPIO_HIGH": false,
"BOOT_ROM_LOG_ON_GPIO_LOW": false,
"COMPILER_CXX_EXCEPTIONS": false,
"COMPILER_CXX_RTTI": false,
"COMPILER_DISABLE_GCC12_WARNINGS": false,
"COMPILER_DISABLE_GCC13_WARNINGS": false,
"COMPILER_DUMP_RTL_FILES": false,
"COMPILER_FLOAT_LIB_FROM_GCCLIB": true,
"COMPILER_HIDE_PATHS_MACROS": true,
"COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE": false,
"COMPILER_OPTIMIZATION_ASSERTIONS_ENABLE": true,
"COMPILER_OPTIMIZATION_ASSERTIONS_SILENT": false,
"COMPILER_OPTIMIZATION_ASSERTION_LEVEL": 2,
"COMPILER_OPTIMIZATION_CHECKS_SILENT": false,
"COMPILER_OPTIMIZATION_DEBUG": true,
"COMPILER_OPTIMIZATION_NONE": false,
"COMPILER_OPTIMIZATION_PERF": false,
"COMPILER_OPTIMIZATION_SIZE": false,
"COMPILER_RT_LIB_HOST": true,
"COMPILER_RT_LIB_NAME": "",
"COMPILER_STACK_CHECK": true,
"COMPILER_STACK_CHECK_MODE_ALL": false,
"COMPILER_STACK_CHECK_MODE_NONE": false,
"COMPILER_STACK_CHECK_MODE_NORM": false,
"COMPILER_STACK_CHECK_MODE_STRONG": true,
"COMPILER_WARN_WRITE_STRINGS": true,
"ESP_BRINGUP_BYPASS_CPU_CLK_SETTING": true,
"ESP_BRINGUP_BYPASS_RANDOM_SETTING": true,
"ESP_CONSOLE_NONE": false,
"ESP_CONSOLE_UART": true,
"ESP_CONSOLE_UART_BAUDRATE": 115200,
"ESP_CONSOLE_UART_CUSTOM": false,
"ESP_CONSOLE_UART_DEFAULT": true,
"ESP_CONSOLE_UART_NUM": 0,
"ESP_DEBUG_OCDAWARE": true,
"ESP_DEBUG_STUBS_ENABLE": false,
"ESP_ERR_TO_NAME_LOOKUP": true,
"ESP_EVENT_LOOP_PROFILING": false,
"ESP_EVENT_POST_FROM_IRAM_ISR": true,
"ESP_EVENT_POST_FROM_ISR": true,
"ESP_INT_WDT": true,
"ESP_INT_WDT_TIMEOUT_MS": 300,
"ESP_IPC_TASK_STACK_SIZE": 1024,
"ESP_MAC_USE_CUSTOM_MAC_AS_BASE_MAC": false,
"ESP_MAIN_TASK_AFFINITY": 0,
"ESP_MAIN_TASK_AFFINITY_CPU0": true,
"ESP_MAIN_TASK_AFFINITY_NO_AFFINITY": false,
"ESP_MAIN_TASK_STACK_SIZE": 3584,
"ESP_MINIMAL_SHARED_STACK_SIZE": 2048,
"ESP_PANIC_HANDLER_IRAM": false,
"ESP_SLEEP_CACHE_SAFE_ASSERTION": false,
"ESP_SLEEP_DEBUG": false,
"ESP_SLEEP_FLASH_LEAKAGE_WORKAROUND": true,
"ESP_SLEEP_GPIO_ENABLE_INTERNAL_RESISTORS": true,
"ESP_SLEEP_GPIO_RESET_WORKAROUND": false,
"ESP_SLEEP_MSPI_NEED_ALL_IO_PU": false,
"ESP_SLEEP_POWER_DOWN_FLASH": false,
"ESP_SLEEP_WAIT_FLASH_READY_EXTRA_DELAY": 0,
"ESP_SYSTEM_CHECK_INT_LEVEL_4": true,
"ESP_SYSTEM_EVENT_QUEUE_SIZE": 32,
"ESP_SYSTEM_EVENT_TASK_STACK_SIZE": 2304,
"ESP_SYSTEM_PANIC_GDBSTUB": false,
"ESP_SYSTEM_PANIC_PRINT_HALT": false,
"ESP_SYSTEM_PANIC_PRINT_REBOOT": true,
"ESP_SYSTEM_PANIC_REBOOT_DELAY_SECONDS": 0,
"ESP_SYSTEM_PANIC_SILENT_REBOOT": false,
"ESP_SYSTEM_SINGLE_CORE_MODE": true,
"ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0": true,
"ESP_TASK_WDT_EN": true,
"ESP_TASK_WDT_INIT": true,
"ESP_TASK_WDT_PANIC": false,
"ESP_TASK_WDT_TIMEOUT_S": 5,
"FREERTOS_CHECK_MUTEX_GIVEN_BY_OWNER": true,
"FREERTOS_CHECK_PORT_CRITICAL_COMPLIANCE": false,
"FREERTOS_CHECK_STACKOVERFLOW_CANARY": true,
"FREERTOS_CHECK_STACKOVERFLOW_NONE": false,
"FREERTOS_CHECK_STACKOVERFLOW_PTRVAL": false,
"FREERTOS_CORETIMER_SYSTIMER_LVL1": true,
"FREERTOS_CORETIMER_SYSTIMER_LVL3": false,
"FREERTOS_DEBUG_OCDAWARE": true,
"FREERTOS_ENABLE_STATIC_TASK_CLEAN_UP": false,
"FREERTOS_ENABLE_TASK_SNAPSHOT": true,
"FREERTOS_GENERATE_RUN_TIME_STATS": false,
"FREERTOS_HZ": 100,
"FREERTOS_IDLE_TASK_STACKSIZE": 1536,
"FREERTOS_INTERRUPT_BACKTRACE": true,
"FREERTOS_ISR_STACKSIZE": 1536,
"FREERTOS_MAX_TASK_NAME_LEN": 16,
"FREERTOS_NO_AFFINITY": 2147483647,
"FREERTOS_OPTIMIZED_SCHEDULER": true,
"FREERTOS_PLACE_FUNCTIONS_INTO_FLASH": false,
"FREERTOS_PLACE_SNAPSHOT_FUNS_INTO_FLASH": true,
"FREERTOS_PORT": true,
"FREERTOS_QUEUE_REGISTRY_SIZE": 0,
"FREERTOS_SMP": false,
"FREERTOS_SUPPORT_STATIC_ALLOCATION": true,
"FREERTOS_SYSTICK_USES_SYSTIMER": true,
"FREERTOS_TASK_FUNCTION_WRAPPER": true,
"FREERTOS_TASK_NOTIFICATION_ARRAY_ENTRIES": 1,
"FREERTOS_TASK_PRE_DELETION_HOOK": false,
"FREERTOS_THREAD_LOCAL_STORAGE_POINTERS": 1,
"FREERTOS_TICK_SUPPORT_SYSTIMER": true,
"FREERTOS_TIMER_QUEUE_LENGTH": 10,
"FREERTOS_TIMER_SERVICE_TASK_CORE_AFFINITY": 2147483647,
"FREERTOS_TIMER_SERVICE_TASK_NAME": "Tmr Svc",
"FREERTOS_TIMER_TASK_AFFINITY_CPU0": false,
"FREERTOS_TIMER_TASK_NO_AFFINITY": true,
"FREERTOS_TIMER_TASK_PRIORITY": 1,
"FREERTOS_TIMER_TASK_STACK_DEPTH": 2053,
"FREERTOS_TLSP_DELETION_CALLBACKS": true,
"FREERTOS_UNICORE": true,
"FREERTOS_USE_IDLE_HOOK": false,
"FREERTOS_USE_LIST_DATA_INTEGRITY_CHECK_BYTES": true,
"FREERTOS_USE_TICK_HOOK": false,
"FREERTOS_USE_TRACE_FACILITY": false,
"FREERTOS_WATCHPOINT_END_OF_STACK": false,
"HAL_ASSERTION_DISABLE": false,
"HAL_ASSERTION_ENABLE": false,
"HAL_ASSERTION_EQUALS_SYSTEM": true,
"HAL_ASSERTION_SILENT": false,
"HAL_DEFAULT_ASSERTION_LEVEL": 2,
"HEAP_ABORT_WHEN_ALLOCATION_FAILS": false,
"HEAP_PLACE_FUNCTION_INTO_FLASH": false,
"HEAP_POISONING_COMPREHENSIVE": true,
"HEAP_POISONING_DISABLED": false,
"HEAP_POISONING_LIGHT": false,
"HEAP_TASK_TRACKING": false,
"HEAP_TRACING_OFF": true,
"HEAP_TRACING_STANDALONE": false,
"HEAP_TRACING_TOHOST": false,
"HEAP_USE_HOOKS": false,
"IDF_CMAKE": true,
"IDF_EXPERIMENTAL_FEATURES": false,
"IDF_FIRMWARE_CHIP_ID": 65535,
"IDF_INIT_VERSION": "5.3.0",
"IDF_TARGET": "linux",
"IDF_TARGET_LINUX": true,
"IDF_TOOLCHAIN": "gcc",
"LOG_COLORS": true,
"LOG_DEFAULT_LEVEL": 3,
"LOG_DEFAULT_LEVEL_DEBUG": false,
"LOG_DEFAULT_LEVEL_ERROR": false,
"LOG_DEFAULT_LEVEL_INFO": true,
"LOG_DEFAULT_LEVEL_NONE": false,
"LOG_DEFAULT_LEVEL_VERBOSE": false,
"LOG_DEFAULT_LEVEL_WARN": false,
"LOG_MASTER_LEVEL": false,
"LOG_MAXIMUM_EQUALS_DEFAULT": true,
"LOG_MAXIMUM_LEVEL": 3,
"LOG_MAXIMUM_LEVEL_DEBUG": false,
"LOG_MAXIMUM_LEVEL_VERBOSE": false,
"LOG_TIMESTAMP_SOURCE_RTOS": true,
"LOG_TIMESTAMP_SOURCE_SYSTEM": false,
"MMU_PAGE_MODE": "64KB",
"MMU_PAGE_SIZE": 65536,
"MMU_PAGE_SIZE_64KB": true,
"PERIPH_CTRL_FUNC_IN_IRAM": false,
"SOC_GPIO_IN_RANGE_MAX": 65535,
"SOC_GPIO_OUT_RANGE_MAX": 65535,
"SOC_I2C_SUPPORT_10BIT_ADDR": true,
"SOC_I2C_SUPPORT_SLAVE": true,
"UNITY_ENABLE_64BIT": false,
"UNITY_ENABLE_BACKTRACE_ON_FAIL": false,
"UNITY_ENABLE_COLOR": false,
"UNITY_ENABLE_DOUBLE": true,
"UNITY_ENABLE_FIXTURE": false,
"UNITY_ENABLE_FLOAT": true,
"UNITY_ENABLE_IDF_TEST_RUNNER": true
}
Loading

0 comments on commit d553e14

Please sign in to comment.