Skip to content

Commit

Permalink
ci: refactor hex handling
Browse files Browse the repository at this point in the history
Move hex files definitions out of workflow files.
Remove duplicate constants definitions also.

Signed-off-by: Giacomo Dematteis <[email protected]>
  • Loading branch information
DematteisGiacomo committed Nov 20, 2024
1 parent d92fe43 commit 9d85452
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 67 deletions.
11 changes: 1 addition & 10 deletions .github/workflows/on_target.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
36 changes: 12 additions & 24 deletions tests/on_target/tests/test_conn_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,31 @@
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
LINE_COUNT = 64
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():
Expand All @@ -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")
Expand Down
46 changes: 13 additions & 33 deletions tests/on_target/tests/test_serial_dfu.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,26 @@
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())
from utils.logger import get_logger

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():
Expand All @@ -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)

Expand Down Expand Up @@ -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()

Expand Down
10 changes: 10 additions & 0 deletions tests/on_target/utils/flash_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
16 changes: 16 additions & 0 deletions tests/on_target/utils/uart.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 9d85452

Please sign in to comment.