pytest_hello_world.py 1.4 KB

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