From e828026eb5063ace49eda5baf2a6bcbeaf1a8cf6 Mon Sep 17 00:00:00 2001 From: Marius Vikhammer Date: Thu, 21 Jul 2022 10:34:45 +0800 Subject: [PATCH] CI: migrate blink example test to pytest --- examples/get-started/.build-test-rules.yml | 7 ---- examples/get-started/blink/example_test.py | 43 ---------------------- examples/get-started/blink/pytest_blink.py | 37 +++++++++++++++++++ 3 files changed, 37 insertions(+), 50 deletions(-) delete mode 100644 examples/get-started/.build-test-rules.yml delete mode 100644 examples/get-started/blink/example_test.py create mode 100644 examples/get-started/blink/pytest_blink.py diff --git a/examples/get-started/.build-test-rules.yml b/examples/get-started/.build-test-rules.yml deleted file mode 100644 index fa5c407440..0000000000 --- a/examples/get-started/.build-test-rules.yml +++ /dev/null @@ -1,7 +0,0 @@ -# Documentation: .gitlab/ci/README.md#manifest-file-to-control-the-buildtest-apps - -examples/get-started/blink: - disable_test: - - if: IDF_TARGET not in ["esp32", "esp32c3"] - temporary: true - reason: lack of runners diff --git a/examples/get-started/blink/example_test.py b/examples/get-started/blink/example_test.py deleted file mode 100644 index 4cce22f1a6..0000000000 --- a/examples/get-started/blink/example_test.py +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/env python - -from __future__ import division, print_function, unicode_literals - -import hashlib -import os -import re - -import ttfw_idf -from tiny_test_fw import Utility - - -def verify_elf_sha256_embedding(dut): - elf_file = os.path.join(dut.app.binary_path, 'blink.elf') - sha256 = hashlib.sha256() - with open(elf_file, 'rb') as f: - sha256.update(f.read()) - sha256_expected = sha256.hexdigest() - - dut.reset() - sha256_reported = dut.expect(re.compile(r'ELF file SHA256:\s+([a-f0-9]+)'), timeout=5)[0] - - Utility.console_log('ELF file SHA256: %s' % sha256_expected) - Utility.console_log('ELF file SHA256 (reported by the app): %s' % 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') - - -@ttfw_idf.idf_example_test(env_tag='Example_GENERIC', target=['esp32', 'esp32c3']) -def test_examples_blink(env, extra_data): - dut = env.get_dut('blink', 'examples/get-started/blink') - binary_file = os.path.join(dut.app.binary_path, 'blink.bin') - bin_size = os.path.getsize(binary_file) - ttfw_idf.log_performance('blink_bin_size', '{}KB'.format(bin_size // 1024)) - - dut.start_app() - - verify_elf_sha256_embedding(dut) - - -if __name__ == '__main__': - test_examples_blink() diff --git a/examples/get-started/blink/pytest_blink.py b/examples/get-started/blink/pytest_blink.py new file mode 100644 index 0000000000..47d3aaccbd --- /dev/null +++ b/examples/get-started/blink/pytest_blink.py @@ -0,0 +1,37 @@ +# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD +# SPDX-License-Identifier: CC0-1.0 + +import hashlib +import logging +import os + +import pytest +from pytest_embedded_idf.dut import IdfDut + + +def verify_elf_sha256_embedding(bin_path: str, sha256_reported: str) -> None: + elf_file = os.path.join(bin_path, 'blink.elf') + sha256 = hashlib.sha256() + with open(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') + + +@pytest.mark.supported_targets +@pytest.mark.generic +def test_blink(dut: IdfDut) -> None: + # check and log bin size + binary_file = os.path.join(dut.app.binary_path, 'blink.bin') + bin_size = os.path.getsize(binary_file) + logging.info('blink_bin_size : {}KB'.format(bin_size // 1024)) + + sha256_reported = dut.expect(r'ELF file SHA256:\s+([a-f0-9]+)').group(1).decode('utf-8') + + verify_elf_sha256_embedding(dut.app.binary_path, sha256_reported)