2022-05-18 02:59:34 -04:00
|
|
|
# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
|
|
|
|
# SPDX-License-Identifier: CC0-1.0
|
|
|
|
|
2022-08-26 00:24:27 -04:00
|
|
|
import hashlib
|
|
|
|
import logging
|
2022-05-18 02:59:34 -04:00
|
|
|
from typing import Callable
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
from pytest_embedded_idf.dut import IdfDut
|
2022-08-26 00:24:27 -04:00
|
|
|
from pytest_embedded_qemu.app import QemuApp
|
2022-05-18 02:59:34 -04:00
|
|
|
from pytest_embedded_qemu.dut import QemuDut
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.supported_targets
|
|
|
|
@pytest.mark.generic
|
2022-08-26 00:24:27 -04:00
|
|
|
def test_hello_world(
|
|
|
|
dut: IdfDut, log_minimum_free_heap_size: Callable[..., None]
|
|
|
|
) -> None:
|
2022-05-18 02:59:34 -04:00
|
|
|
dut.expect('Hello world!')
|
|
|
|
log_minimum_free_heap_size()
|
|
|
|
|
|
|
|
|
2022-08-26 00:24:27 -04:00
|
|
|
def verify_elf_sha256_embedding(app: QemuApp, sha256_reported: str) -> None:
|
|
|
|
sha256 = hashlib.sha256()
|
|
|
|
with open(app.elf_file, 'rb') as f:
|
|
|
|
sha256.update(f.read())
|
|
|
|
sha256_expected = sha256.hexdigest()
|
|
|
|
|
|
|
|
logging.info(f'ELF file SHA256: {sha256_expected}')
|
|
|
|
logging.info(f'ELF file SHA256 (reported by the app): {sha256_reported}')
|
|
|
|
|
|
|
|
# the app reports only the first several hex characters of the SHA256, check that they match
|
|
|
|
if not sha256_expected.startswith(sha256_reported):
|
|
|
|
raise ValueError('ELF file SHA256 mismatch')
|
|
|
|
|
|
|
|
|
2022-05-18 02:59:34 -04:00
|
|
|
@pytest.mark.esp32 # we only support qemu on esp32 for now
|
|
|
|
@pytest.mark.host_test
|
|
|
|
@pytest.mark.qemu
|
2022-08-26 00:24:27 -04:00
|
|
|
def test_hello_world_host(app: QemuApp, dut: QemuDut) -> None:
|
|
|
|
sha256_reported = (
|
|
|
|
dut.expect(r'ELF file SHA256:\s+([a-f0-9]+)').group(1).decode('utf-8')
|
|
|
|
)
|
|
|
|
verify_elf_sha256_embedding(app, sha256_reported)
|
|
|
|
|
2022-05-18 02:59:34 -04:00
|
|
|
dut.expect('Hello world!')
|