Skip to content

Commit

Permalink
Debug app: cache the latest connection parameters.
Browse files Browse the repository at this point in the history
Fixes showing wrong connection parameters after re-opening the app.
  • Loading branch information
jakkra authored and ldab committed Jul 13, 2024
1 parent a44528e commit 60d2018
Show file tree
Hide file tree
Showing 9 changed files with 238 additions and 7 deletions.
10 changes: 3 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
name: Build

on:
push:
pull_request:
on: [workflow_call]

jobs:
build:
Expand All @@ -26,7 +22,7 @@ jobs:
wget https://sourceforge.net/projects/astyle/files/astyle/astyle%203.4/astyle-3.4.10.tar.bz2/download -O astyle.tar.bz2
tar -xf astyle.tar.bz2
cd astyle-3.4.10
mkdir as-gcc-exe
mkdir -p as-gcc-exe
cd as-gcc-exe
cmake ../
make
Expand All @@ -38,7 +34,7 @@ jobs:
west init -l app
west config manifest.group-filter +bsec2
west update -o=--depth=1 -n
mkdir fw_images
mkdir -p fw_images
- name: Style
working-directory: ZSWatch
Expand Down
11 changes: 11 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
on:
pull_request:
workflow_dispatch:

jobs:
build:
uses: ./.github/workflows/build.yml

test:
needs: [build]
uses: ./.github/workflows/test.yml
51 changes: 51 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
on: [workflow_call]

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

steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'

- name: Install dependencies
continue-on-error: true # JLink install will fail
run: |
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
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
export PATH=$PATH:/opt
fi
python -m pip install --upgrade pip
pip install -r app/pytest/requirements.txt
- name: 'Download image'
uses: actions/download-artifact@v4
with:
name: zswatch_nrf5340_cpuapp@3_debug

- name: Display structure of downloaded files
run: ls

- name: Test with pytest
run: |
pip install pytest
pytest app/pytest/
15 changes: 15 additions & 0 deletions app/pytest/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import pytest
import utils
import logging

logging.basicConfig(level=logging.INFO)


def pytest_configure():
utils.flash()


@pytest.fixture(autouse=True)
def reset():
utils.reset()
yield
3 changes: 3 additions & 0 deletions app/pytest/pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[pytest]
log_cli = True
log_cli_level = INFO
25 changes: 25 additions & 0 deletions app/pytest/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# RUN-TEST: required to do run time tests of zephyr
#
# things used by twister or related in run time testing

# used to flash & debug various boards
pyocd>=0.35.0

# used by twister for board/hardware map
tabulate
natsort

# used by mcuboot
cbor>=1.0.0

# use for twister
psutil

# Artifacts package creation
bz

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

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

log = logging.getLogger()


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


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


def test_boot():
log.info("Wait for boot")
time.sleep(30)
assert utils.read_rtt(timeout_ms=20000).find("Enter inactive") != -1
104 changes: 104 additions & 0 deletions app/pytest/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import subprocess
import logging
import time
import pylink

SERIAL_NUMBER = "760208490"

log = logging.getLogger()


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


def reset():
"""Reset DUT"""
log.info("Reset DUT")
subprocess.run(
[
"nrfjprog",
"--family",
"nrf53",
"--snr",
SERIAL_NUMBER,
"--reset",
],
shell=False,
stderr=subprocess.STDOUT,
text=True,
check=True,
)


def flash():
"""Flash firmware"""
log.info("Flashing CP_APPLICATION.")
subprocess.run(
[
"nrfjprog",
"--family",
"nrf53",
"--snr",
SERIAL_NUMBER,
"--recover",
"--program",
"./zswatch_nrf5340_cpuapp@3_debug.hex",
"--qspichiperase",
"--verify",
],
shell=False,
stderr=subprocess.STDOUT,
text=True,
check=True,
)

log.info("Flashing CP_NETWORK.")
subprocess.run(
[
"nrfjprog",
"--family",
"nrf53",
"--snr",
SERIAL_NUMBER,
"--reset",
"--program",
"./zswatch_nrf5340_CPUNET.hex",
"--coprocessor",
"CP_NETWORK",
"--qspisectorerase",
"--verify",
],
shell=False,
stderr=subprocess.STDOUT,
text=True,
check=True,
)


def read_rtt(target_device="nRF5340_XXAA", timeout_ms=10000):
"""Read Segger RTT output"""
jlink = pylink.JLink()
log.info("Connecting to JLink...")
jlink.open(serial_no=SERIAL_NUMBER)
log.info("Connecting to %s..." % target_device)
jlink.set_tif(pylink.enums.JLinkInterfaces.SWD)
jlink.connect(target_device)
jlink.rtt_start(None)
start_time = current_milli_time()
read_data = ""

while jlink.connected() and start_time + timeout_ms > current_milli_time():
read_bytes = jlink.rtt_read(0, 1024)

if read_bytes and read_bytes != "":
data = "".join(map(chr, read_bytes))
read_data = read_data + data

time.sleep(0.1)

jlink.close()
log.debug(read_data)

return read_data
5 changes: 5 additions & 0 deletions app/src/applications/info/info_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,14 @@ static void timer_callback(lv_timer_t *timer)

static void param_updated(struct bt_conn *conn, uint16_t interval, uint16_t latency, uint16_t timeout)
{
ble_info.connection_interval = interval;
ble_info.connection_latency = latency;
ble_info.connection_timeout = timeout;

if (!running) {
return;
}

LOG_INF("Updated => Interval: %d, latency: %d, timeout: %d", interval, latency, timeout);
info_app_ui_set_conn_params(interval, latency, timeout);
}
Expand Down

0 comments on commit 60d2018

Please sign in to comment.