|
| 1 | +# SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD |
| 2 | +# SPDX-License-Identifier: CC0-1.0 |
| 3 | +import hashlib |
| 4 | +import logging |
| 5 | +from typing import Callable |
| 6 | + |
| 7 | +import pytest |
| 8 | +from pytest_embedded_idf.dut import IdfDut |
| 9 | +from pytest_embedded_idf.utils import idf_parametrize |
| 10 | +from pytest_embedded_qemu.app import QemuApp |
| 11 | +from pytest_embedded_qemu.dut import QemuDut |
| 12 | + |
| 13 | + |
| 14 | +@pytest.mark.generic |
| 15 | +@idf_parametrize('target', ['supported_targets', 'preview_targets'], indirect=['target']) |
| 16 | +def test_hello_world(dut: IdfDut, log_minimum_free_heap_size: Callable[..., None]) -> None: |
| 17 | + dut.expect('Hello world!') |
| 18 | + log_minimum_free_heap_size() |
| 19 | + |
| 20 | + |
| 21 | +@pytest.mark.host_test |
| 22 | +@idf_parametrize('target', ['linux'], indirect=['target']) |
| 23 | +def test_hello_world_linux(dut: IdfDut) -> None: |
| 24 | + dut.expect('Hello world!') |
| 25 | + |
| 26 | + |
| 27 | +@pytest.mark.host_test |
| 28 | +@pytest.mark.macos_shell |
| 29 | +@idf_parametrize('target', ['linux'], indirect=['target']) |
| 30 | +def test_hello_world_macos(dut: IdfDut) -> None: |
| 31 | + dut.expect('Hello world!') |
| 32 | + |
| 33 | + |
| 34 | +def verify_elf_sha256_embedding(app: QemuApp, sha256_reported: str) -> None: |
| 35 | + sha256 = hashlib.sha256() |
| 36 | + with open(app.elf_file, 'rb') as f: |
| 37 | + sha256.update(f.read()) |
| 38 | + sha256_expected = sha256.hexdigest() |
| 39 | + |
| 40 | + logging.info(f'ELF file SHA256: {sha256_expected}') |
| 41 | + logging.info(f'ELF file SHA256 (reported by the app): {sha256_reported}') |
| 42 | + |
| 43 | + # the app reports only the first several hex characters of the SHA256, check that they match |
| 44 | + if not sha256_expected.startswith(sha256_reported): |
| 45 | + raise ValueError('ELF file SHA256 mismatch') |
| 46 | + |
| 47 | + |
| 48 | +@pytest.mark.host_test |
| 49 | +@pytest.mark.qemu |
| 50 | +@idf_parametrize('target', ['esp32', 'esp32c3'], indirect=['target']) |
| 51 | +def test_hello_world_host(app: QemuApp, dut: QemuDut) -> None: |
| 52 | + sha256_reported = dut.expect(r'ELF file SHA256:\s+([a-f0-9]+)').group(1).decode('utf-8') |
| 53 | + verify_elf_sha256_embedding(app, sha256_reported) |
| 54 | + |
| 55 | + dut.expect('Hello world!') |
0 commit comments