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