Skip to content

Commit

Permalink
Move J-Link serial number to command line arguments
Browse files Browse the repository at this point in the history
Add ZSWatch HW revision as variable
  • Loading branch information
Kampi committed Jul 24, 2024
1 parent d540a61 commit e701919
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 27 deletions.
13 changes: 9 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@ on: [workflow_call]

jobs:
test:
runs-on: self-hosted
runs-on: [self-hosted, Linux, X64, ZSWatch]
container:
image: ghcr.io/zephyrproject-rtos/zephyr-build:v0.26.2
volumes:
- /dev/bus/usb/:/dev/bus/usb
options: --privileged

strategy:
matrix:
hardware_revisions: [5]
jlink_devices: [760208506]

steps:
- uses: actions/checkout@v4

Expand Down Expand Up @@ -37,15 +42,15 @@ jobs:
python -m pip install --upgrade pip
pip install -r app/pytest/requirements.txt
- name: 'Download image'
- name: Download debug image
uses: actions/download-artifact@v4
with:
name: zswatch_nrf5340_cpuapp@3_debug
name: zswatch_nrf5340_cpuapp@${{ matrix.hardware_revisions }}_debug

- name: Display structure of downloaded files
run: ls

- name: Test with pytest
run: |
pip install pytest
pytest app/pytest/
pytest --jlink=${{ matrix.jlink_devices }} --hw=${{ matrix.hardware_revisions }} app/pytest/
26 changes: 22 additions & 4 deletions app/pytest/conftest.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,33 @@
import pytest
import utils
import logging
import pytest

logging.basicConfig(level=logging.INFO)

def pytest_addoption(parser):
parser.addoption("--jlink", action="store", help="Serial number of target J-Link")
parser.addoption("--hw", action="store", help="ZSWatch hardware revision")

def pytest_configure(config):
jlink = config.getoption("--jlink")
hw = config.getoption("--hw")

def pytest_configure():
utils.flash()
log = logging.getLogger()
log.info("Using J-Link {}".format(jlink))
log.info("Using ZSWatch revision {}".format(hw))

utils.flash(jlink=jlink, hw=hw)

@pytest.fixture(autouse=True)
def reset():
utils.reset()
def reset(jlink):
utils.reset(jlink=jlink)
yield

@pytest.fixture
def jlink(request):
return request.config.getoption("--jlink")

@pytest.fixture
def hw(request):
return request.config.getoption("--hw")
5 changes: 1 addition & 4 deletions app/pytest/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,5 @@ psutil
# Artifacts package creation
bz

# used for CAN <=> host testing
python-can>=4.3.0

# RTT connection
pylink-square
pylink-square
9 changes: 4 additions & 5 deletions app/pytest/test_basic.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import time
import logging
import utils

log = logging.getLogger()


def test_flash():
def test_flash(jlink, hw):
"""Test flashing, don't need to assert as failing to flash throws exception"""
utils.flash()
utils.flash(jlink=jlink, hw=hw)


def test_reset():
def test_reset(jlink):
"""Test Reset, don't need to assert as failing to reset throws exception"""
utils.reset()
utils.reset(jlink=jlink)


def test_boot():
Expand Down
19 changes: 9 additions & 10 deletions app/pytest/utils.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import os
import subprocess
import logging
import time
import pylink

SERIAL_NUMBER = "760208490"

log = logging.getLogger()


Expand All @@ -13,7 +12,7 @@ def current_milli_time():
return round(time.time() * 1000)


def reset():
def reset(jlink):
"""Reset DUT"""
log.info("Reset DUT")
subprocess.run(
Expand All @@ -22,7 +21,7 @@ def reset():
"--family",
"nrf53",
"--snr",
SERIAL_NUMBER,
jlink,
"--reset",
],
shell=False,
Expand All @@ -32,7 +31,7 @@ def reset():
)


def flash():
def flash(jlink, hw):
"""Flash firmware"""
log.info("Flashing CP_APPLICATION.")
subprocess.run(
Expand All @@ -41,9 +40,9 @@ def flash():
"--family",
"nrf53",
"--snr",
SERIAL_NUMBER,
jlink,
"--program",
"./zswatch_nrf5340_cpuapp@3_debug.hex",
"./zswatch_nrf5340_cpuapp@{}_debug.hex".format(hw),
"--chiperase",
"--verify",
],
Expand All @@ -60,7 +59,7 @@ def flash():
"--family",
"nrf53",
"--snr",
SERIAL_NUMBER,
jlink,
"--program",
"./zswatch_nrf5340_CPUNET.hex",
"--coprocessor",
Expand All @@ -76,12 +75,12 @@ def flash():
)


def read_rtt(target_device="nRF5340_XXAA", timeout_ms=10000):
def read_rtt(jlink, target_device="nRF5340_XXAA", timeout_ms=10000):
"""Read Segger RTT output"""
jlink = pylink.JLink()
logging.getLogger("pylink.jlink").setLevel(logging.WARNING)
log.info("Connecting to JLink...")
jlink.open(serial_no=SERIAL_NUMBER)
jlink.open(serial_no=jlink)
log.info("Connecting to %s..." % target_device)
jlink.set_tif(pylink.enums.JLinkInterfaces.SWD)
jlink.connect(target_device)
Expand Down

0 comments on commit e701919

Please sign in to comment.