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 25, 2024
1 parent d540a61 commit 3e9baa5
Show file tree
Hide file tree
Showing 9 changed files with 73,747 additions and 48 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ jobs:
uses: ./.github/workflows/build.yml

test:
needs: [build]
#needs: [build]
uses: ./.github/workflows/test.yml
37 changes: 25 additions & 12 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ on: [workflow_call]

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

strategy:
matrix:
devices: [{hardware_revision: 5, jlink_device: 760208506}, {hardware_revision: 3, jlink_device: 760208490}, {hardware_revision: 3, jlink_device: 760208484}]

steps:
- uses: actions/checkout@v4

Expand All @@ -20,32 +24,41 @@ jobs:
- name: Install dependencies
continue-on-error: true # JLink install will fail
run: |
arch=$(arch)
echo "Detected arch: ${arch}"
if [ "$arch" == x86_64 ]; then
echo "x64 Architecture"
JLINK_Name=JLink_Linux_V796t_x86_64
NRF_Nam${arch}f-command-line-tools_10.24.2_amd64
elif [ "$arch" == aarch64 ]; then
echo "ARM 64 Architecture"
JLINK_Name=JLink_Linux_V796t_arm
NRF_Name=nrf-command-line-tools_10.24.2_arm64
fi
if [ ! -f "`which JLinkExe`" ]; then
echo "Installing JLink tools..."
wget -q --post-data 'accept_license_agreement=accepted&non_emb_ctr=confirmed&submit=Download+software' https://www.segger.com/downloads/jlink/JLink_Linux_V796t_x86_64.deb
sudo apt -qq update
sudo apt -y install ./JLink_Linux_V796t_x86_64.deb &>/dev/null
wget -q --post-data 'accept_license_agreement=accepted&non_emb_ctr=confirmed&submit=Download+software' https://www.segger.com/downloads/jlink/${JLINK_Name}.deb
sudo apt-get -qq update
sudo apt-get -y install ./${JLINK_Name}.deb &>/dev/null
fi
if [ ! -f "`which nrfjprog`" ]; then
echo "Installing Nordic command line tools..."
wget -q https://nsscprodmedia.blob.core.windows.net/prod/software-and-other-downloads/desktop-software/nrf-command-line-tools/sw/versions-10-x-x/10-24-2/nrf-command-line-tools_10.24.2_amd64.deb
sudo apt -y install ./nrf-command-line-tools_10.24.2_amd64.deb &>/dev/null
wget -q https://nsscprodmedia.blob.core.windows.net/prod/software-and-other-downloads/desktop-software/nrf-command-line-tools/sw/versions-10-x-x/10-24-2/${NRF_Name}.deb
sudo apt-get -y install ./{NRF_Name}.deb &>/dev/null
export PATH=$PATH:/opt
fi
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: Display structure of downloaded files
run: ls
name: zswatch_nrf5340_cpuapp@${{ matrix.devices.hardware_revision }}_debug

- name: Test with pytest
run: |
pip install pytest
pytest app/pytest/
pytest --jlink=${{ matrix.devices.jlink_device }} --hw=${{ matrix.devices.hardware_revision }} app/pytest/
39 changes: 34 additions & 5 deletions app/pytest/conftest.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,44 @@
import pytest
import utils
import pytest
import logging

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")
parser.addoption("--ppk", action="store", default=None, help="Port used by an optional Power Profiling Kit")

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

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

if(ppk != None):
log.info("Using PPK2 on {}".format(ppk))

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

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

@pytest.fixture(autouse=True)
def jlink(request):
'''Serial number of the used J-Link debugger'''
return request.config.getoption("--jlink")

@pytest.fixture(autouse=True)
def hw(request):
'''Hardwawre version used'''
return request.config.getoption("--hw")

@pytest.fixture
def ppk(request):
'''COM port for an optional Power Profiling Kit'''
return request.config.getoption("--ppk")
6 changes: 3 additions & 3 deletions app/pytest/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ psutil
# Artifacts package creation
bz

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

# RTT connection
pylink-square

# Used for PPK integration
ppk2-api
28 changes: 14 additions & 14 deletions app/pytest/test_basic.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import time
import logging
import utils
import pytest
import logging

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)
print("flash")


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)
print("reset")

def test_boot():
search_string = "Enter inactive"
log.info("Booting...")
log.info("Check for \'{}\' string".format(search_string))
assert utils.read_rtt(timeout_ms=60000).find(search_string) != -1
def test_boot(jlink):
#search_string = "Enter inactive"
#log.info("Booting...")
#log.info("Check for \'{}\' string".format(search_string))
#assert utils.read_rtt(serial=jlink, timeout_ms=60000).find(search_string) != -1
print("boot")
9 changes: 9 additions & 0 deletions app/pytest/test_current_consumption.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import utils
import pytest
import logging

log = logging.getLogger()

def test_a(ppk):
if((ppk == None) or (utils.ppk_connected() == 0)):
pytest.skip("No PPK available")
25 changes: 12 additions & 13 deletions app/pytest/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@
import time
import pylink

SERIAL_NUMBER = "760208490"
from ppk2_api.ppk2_api import PPK2_API

log = logging.getLogger()


def current_milli_time():
"""Get times in milliseconds"""
return round(time.time() * 1000)


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


def flash():
def flash(jlink, hw):
"""Flash firmware"""
log.info("Flashing CP_APPLICATION.")
subprocess.run(
Expand All @@ -41,9 +38,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 +57,7 @@ def flash():
"--family",
"nrf53",
"--snr",
SERIAL_NUMBER,
jlink,
"--program",
"./zswatch_nrf5340_CPUNET.hex",
"--coprocessor",
Expand All @@ -75,13 +72,12 @@ def flash():
check=True,
)


def read_rtt(target_device="nRF5340_XXAA", timeout_ms=10000):
def read_rtt(serial, 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=serial)
log.info("Connecting to %s..." % target_device)
jlink.set_tif(pylink.enums.JLinkInterfaces.SWD)
jlink.connect(target_device)
Expand All @@ -103,3 +99,6 @@ def read_rtt(target_device="nRF5340_XXAA", timeout_ms=10000):
log.debug(read_data)

return read_data

def ppk_connected():
return PPK2_API.list_devices()
Loading

0 comments on commit 3e9baa5

Please sign in to comment.