pytest_hello_world.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # SPDX-FileCopyrightText: 2022-2023 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. @pytest.mark.linux
  19. @pytest.mark.host_test
  20. def test_hello_world_linux(dut: IdfDut) -> None:
  21. dut.expect('Hello world!')
  22. def verify_elf_sha256_embedding(app: QemuApp, sha256_reported: str) -> None:
  23. sha256 = hashlib.sha256()
  24. with open(app.elf_file, 'rb') as f:
  25. sha256.update(f.read())
  26. sha256_expected = sha256.hexdigest()
  27. logging.info(f'ELF file SHA256: {sha256_expected}')
  28. logging.info(f'ELF file SHA256 (reported by the app): {sha256_reported}')
  29. # the app reports only the first several hex characters of the SHA256, check that they match
  30. if not sha256_expected.startswith(sha256_reported):
  31. raise ValueError('ELF file SHA256 mismatch')
  32. @pytest.mark.esp32 # we only support qemu on esp32 for now
  33. @pytest.mark.host_test
  34. @pytest.mark.qemu
  35. def test_hello_world_host(app: QemuApp, dut: QemuDut) -> None:
  36. sha256_reported = (
  37. dut.expect(r'ELF file SHA256:\s+([a-f0-9]+)').group(1).decode('utf-8')
  38. )
  39. verify_elf_sha256_embedding(app, sha256_reported)
  40. dut.expect('Hello world!')