From 9d854520e2720ba4a734149ccdb3a1666a874a5d Mon Sep 17 00:00:00 2001 From: Giacomo Dematteis Date: Wed, 6 Nov 2024 13:52:10 +0100 Subject: [PATCH] ci: refactor hex handling Move hex files definitions out of workflow files. Remove duplicate constants definitions also. Signed-off-by: Giacomo Dematteis --- .github/workflows/on_target.yml | 11 +----- tests/on_target/tests/test_conn_bridge.py | 36 ++++++------------ tests/on_target/tests/test_serial_dfu.py | 46 +++++++---------------- tests/on_target/utils/flash_tools.py | 10 +++++ tests/on_target/utils/uart.py | 16 ++++++++ 5 files changed, 52 insertions(+), 67 deletions(-) diff --git a/.github/workflows/on_target.yml b/.github/workflows/on_target.yml index 1150bb2e..c51a1ced 100644 --- a/.github/workflows/on_target.yml +++ b/.github/workflows/on_target.yml @@ -184,13 +184,7 @@ jobs: SEGGER_NRF53: ${{ secrets.SEGGER_DUT_2_EXT_DBG }} SEGGER_NRF91: ${{ secrets.SEGGER_DUT_2_NRF91 }} UART_ID: ${{ secrets.UART_DUT_2 }} - NRF53_NET_HEX_FILE: artifacts/connectivity-bridge-${{ inputs.artifact_fw_version }}-thingy91x-nrf53-net.hex - NRF53_APP_HEX_FILE: artifacts/connectivity-bridge-${{ inputs.artifact_fw_version }}-thingy91x-nrf53-app.hex - NRF53_APP_UPDATE_ZIP: artifacts/connectivity-bridge-${{ inputs.artifact_fw_version }}-thingy91x-nrf53-dfu.zip - NRF53_BL_UPDATE_ZIP: artifacts/connectivity-bridge-${{ inputs.artifact_fw_version }}-thingy91x-nrf53-bootloader.zip - NRF91_HEX_FILE: artifacts/nrf91-bl-v2.hex - NRF91_APP_UPDATE_ZIP: artifacts/hello.nrfcloud.com-${{ inputs.artifact_fw_version }}-thingy91x-nrf91-dfu.zip - NRF91_BL_UPDATE_ZIP: artifacts/hello.nrfcloud.com-${{ inputs.artifact_fw_version }}-thingy91x-nrf91-bootloader.zip + LOG_FILENAME: oob_dfu_test_log - name: Run Connectivity Bridge Test @@ -203,9 +197,6 @@ jobs: env: SEGGER_NRF53: ${{ secrets.SEGGER_DUT_2_EXT_DBG }} UART_ID: ${{ secrets.UART_DUT_2 }} - NRF53_NET_HEX_FILE: artifacts/connectivity-bridge-${{ inputs.artifact_fw_version }}-thingy91x-nrf53-net.hex - NRF53_APP_HEX_FILE: artifacts/connectivity-bridge-${{ inputs.artifact_fw_version }}-thingy91x-nrf53-app.hex - NRF91_CUSTOM_APP_ZIP: artifacts/usb_uart_bridge_app.zip LOG_FILENAME: oob_conn_bridge_test_log - name: Run Wi-Fi location tests diff --git a/tests/on_target/tests/test_conn_bridge.py b/tests/on_target/tests/test_conn_bridge.py index bdeb082b..42171b26 100644 --- a/tests/on_target/tests/test_conn_bridge.py +++ b/tests/on_target/tests/test_conn_bridge.py @@ -7,13 +7,19 @@ import time import os import types -from utils.flash_tools import flash_device, reset_device, recover_device, setup_jlink, dfu_device -from utils.uart import Uart +from utils.flash_tools import flash_device, recover_device, dfu_device, get_first_artifact_match +from utils.uart import Uart, wait_until_uart_available from tests.conftest import get_uarts import sys sys.path.append(os.getcwd()) from utils.logger import get_logger +logger = get_logger() + +NRF53_NET_HEX_FILE = get_first_artifact_match("artifacts/connectivity-bridge-*-thingy91x-nrf53-net.hex") +NRF53_APP_HEX_FILE = get_first_artifact_match("artifacts/connectivity-bridge-*-thingy91x-nrf53-app.hex") +NRF91_CUSTOM_APP_ZIP = "artifacts/usb_uart_bridge_app.zip" + UART_TIMEOUT = 60 CB_TIMEOUT = 60 LINE_LEN = 64 @@ -21,23 +27,11 @@ BLE_CONTROL_MESSAGE_RETRIES = 3 MAC_ADDR_FLASH_LOCATION = 0x7A000 -logger = get_logger() +SEGGER_NRF53 = os.getenv('SEGGER_NRF53') +SEGGER_NRF91 = os.getenv('SEGGER_NRF91') +CONNECTIVITY_BRIDGE_UART = "THINGY91X_" + os.getenv('UART_ID') + -def wait_until_uart_available(name, timeout_seconds=60): - base_path = "/dev/serial/by-id" - while timeout_seconds > 0: - try: - serial_paths = [os.path.join(base_path, entry) for entry in os.listdir(base_path)] - for path in sorted(serial_paths): - if name in path: - logger.info(f"UART found: {path}") - return path - except (FileNotFoundError, PermissionError) as e: - logger.info(f"Uart not available yet (error: {e}), retrying...") - time.sleep(1) - timeout_seconds -= 1 - logger.error(f"UART '{name}' not found within {timeout_seconds} seconds") - return None @pytest.fixture(scope="function") def t91x_conn_bridge(): @@ -46,12 +40,6 @@ def t91x_conn_bridge(): First the nRF53 is flashed with connectivity bridge fw. Then dfu is performed on nrf91 with custom test app. ''' - SEGGER_NRF53 = os.getenv('SEGGER_NRF53') - CONNECTIVITY_BRIDGE_UART = "THINGY91X_" + os.getenv('UART_ID') - NRF53_NET_HEX_FILE = os.getenv('NRF53_NET_HEX_FILE') - NRF53_APP_HEX_FILE = os.getenv('NRF53_APP_HEX_FILE') - NRF91_CUSTOM_APP_ZIP = os.getenv('NRF91_CUSTOM_APP_ZIP') - logger.info("Recovering nRF53 network core") recover_device(serial=SEGGER_NRF53, core='Network') logger.info("Recovering nRF53 application core") diff --git a/tests/on_target/tests/test_serial_dfu.py b/tests/on_target/tests/test_serial_dfu.py index 9c1273d4..fe9fa58f 100644 --- a/tests/on_target/tests/test_serial_dfu.py +++ b/tests/on_target/tests/test_serial_dfu.py @@ -7,8 +7,8 @@ import time import os import types -from utils.flash_tools import flash_device, reset_device, recover_device, setup_jlink, dfu_device -from utils.uart import Uart +from utils.flash_tools import flash_device, reset_device, recover_device, setup_jlink, dfu_device, get_first_artifact_match +from utils.uart import Uart, wait_until_uart_available from tests.conftest import get_uarts import sys sys.path.append(os.getcwd()) @@ -16,21 +16,17 @@ logger = get_logger() -def wait_until_uart_available(name, timeout_seconds=60): - base_path = "/dev/serial/by-id" - while timeout_seconds > 0: - try: - serial_paths = [os.path.join(base_path, entry) for entry in os.listdir(base_path)] - for path in sorted(serial_paths): - if name in path: - logger.info(f"UART found: {path}") - return path - except (FileNotFoundError, PermissionError) as e: - logger.info(f"Uart not available yet (error: {e}), retrying...") - time.sleep(1) - timeout_seconds -= 1 - logger.error(f"UART '{name}' not found within {timeout_seconds} seconds") - return None +NRF53_NET_HEX_FILE = get_first_artifact_match("artifacts/connectivity-bridge-*-thingy91x-nrf53-net.hex") +NRF53_APP_HEX_FILE = get_first_artifact_match("artifacts/connectivity-bridge-*-thingy91x-nrf53-app.hex") +NRF53_APP_UPDATE_ZIP = get_first_artifact_match("artifacts/connectivity-bridge-*-thingy91x-nrf53-dfu.zip") +NRF53_BL_UPDATE_ZIP = get_first_artifact_match("artifacts/connectivity-bridge-*-thingy91x-nrf53-bootloader.zip") +NRF91_APP_UPDATE_ZIP = get_first_artifact_match("artifacts/hello.nrfcloud.com-*-thingy91x-nrf91-dfu.zip") +NRF91_BL_UPDATE_ZIP = get_first_artifact_match("artifacts/hello.nrfcloud.com-*-thingy91x-nrf91-bootloader.zip") +NRF91_HEX_FILE = "artifacts/nrf91-bl-v2.hex" + +SEGGER_NRF53 = os.getenv('SEGGER_NRF53') +SEGGER_NRF91 = os.getenv('SEGGER_NRF91') +CONNECTIVITY_BRIDGE_UART = "THINGY91X_" + os.getenv('UART_ID') @pytest.fixture(scope="function") def t91x_dfu(): @@ -39,13 +35,6 @@ def t91x_dfu(): First nRF91 is flashed with oob bootloader fw through segger fw on nRF53. Then nRF53 is flashed with connectivity bridge fw. ''' - SEGGER_NRF53 = os.getenv('SEGGER_NRF53') - SEGGER_NRF91 = os.getenv('SEGGER_NRF91') - CONNECTIVITY_BRIDGE_UART = os.getenv('UART_ID') - NRF53_NET_HEX_FILE = os.getenv('NRF53_NET_HEX_FILE') - NRF53_APP_HEX_FILE = os.getenv('NRF53_APP_HEX_FILE') - NRF91_HEX_FILE = os.getenv('NRF91_HEX_FILE') - logger.info(("Flashing nRF53 with Segger firmware")) setup_jlink(SEGGER_NRF53) @@ -87,15 +76,6 @@ def t91x_dfu(): @pytest.mark.dut2 @pytest.mark.dfu def test_dfu(t91x_dfu): - SEGGER_NRF53 = os.getenv('SEGGER_NRF53') - CONNECTIVITY_BRIDGE_UART = "THINGY91X_" + os.getenv('UART_ID') - - NRF91_APP_UPDATE_ZIP = os.getenv('NRF91_APP_UPDATE_ZIP') - NRF91_BL_UPDATE_ZIP = os.getenv('NRF91_BL_UPDATE_ZIP') - - NRF53_APP_UPDATE_ZIP = os.getenv('NRF53_APP_UPDATE_ZIP') - NRF53_BL_UPDATE_ZIP = os.getenv('NRF53_BL_UPDATE_ZIP') - logger.info("Starting DFU, stopping UART") t91x_dfu.uart.stop() diff --git a/tests/on_target/utils/flash_tools.py b/tests/on_target/utils/flash_tools.py index 20dc7648..401685c9 100644 --- a/tests/on_target/utils/flash_tools.py +++ b/tests/on_target/utils/flash_tools.py @@ -6,6 +6,7 @@ import subprocess import os import sys +import glob sys.path.append(os.getcwd()) from utils.logger import get_logger from utils.thingy91x_dfu import detect_family_from_zip @@ -33,6 +34,8 @@ def reset_device(serial=SEGGER, reset_kind="RESET_SYSTEM"): def flash_device(hexfile, serial=SEGGER, extra_args=[]): # hexfile (str): Full path to file (hex or zip) to be programmed + if not isinstance(hexfile, str): + raise ValueError("hexfile cannot be None") logger.info(f"Flashing device, segger: {serial}, firmware: {hexfile}") try: result = subprocess.run(['nrfutil', 'device', 'program', *extra_args, '--firmware', hexfile, '--serial-number', serial], check=True, text=True, capture_output=True) @@ -118,3 +121,10 @@ def setup_jlink(serial_number): logger.error(f"Standard output:\n{e.stdout}") logger.error(f"Standard error:\n{e.stderr}") raise + +def get_first_artifact_match(pattern): + matches = glob.glob(pattern) + if matches: + return matches[0] + else: + return None diff --git a/tests/on_target/utils/uart.py b/tests/on_target/utils/uart.py index df9b14ed..df13bcec 100644 --- a/tests/on_target/utils/uart.py +++ b/tests/on_target/utils/uart.py @@ -278,3 +278,19 @@ def save_to_file(self, filename: str) -> None: def get_size(self) -> int: return len(self.data) + +def wait_until_uart_available(name, timeout_seconds=60): + base_path = "/dev/serial/by-id" + while timeout_seconds > 0: + try: + serial_paths = [os.path.join(base_path, entry) for entry in os.listdir(base_path)] + for path in sorted(serial_paths): + if name in path: + logger.info(f"UART found: {path}") + return path + except (FileNotFoundError, PermissionError) as e: + logger.info(f"Uart not available yet (error: {e}), retrying...") + time.sleep(1) + timeout_seconds -= 1 + logger.error(f"UART '{name}' not found within {timeout_seconds} seconds") + return None