Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 97 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ on:

permissions:
contents: read
pull-requests: write

jobs:
build:
strategy:
fail-fast: false
matrix:
os: [ubuntu-24.04, macos-15, windows-2025]
os: [ubuntu-26.04]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
Expand Down Expand Up @@ -48,6 +49,52 @@ jobs:
fi
west twister -T app -v --inline-logs --integration $EXTRA_TWISTER_FLAGS

- name: Run stack analysis
id: stackdiff
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends \
ca-certificates \
git \
jq \
wget \
golang-go \
build-essential \
gcc \
libc6-dev \
unzip
wget https://github.com/capstone-engine/capstone/releases/download/6.0.0-Alpha7/libcapstone-dev_6.0.0-Alpha7_amd64.deb
sudo dpkg -i libcapstone-dev_6.0.0-Alpha7_amd64.deb
git clone https://github.com/paulwuertz/pexplorer
cd pexplorer/selfperf

ls -la /home/runner/work/cannectivity/cannectivity/cannectivity/twister-*/
ls -la /home/runner/work/cannectivity/cannectivity/cannectivity/twister-*/nucleo_h723zg_stm32h723xx
ls -la /home/runner/work/cannectivity/cannectivity/cannectivity/twister-*/nucleo_h723zg_stm32h723xx/zephyr_gnu/cannectivity/app/
ls -la /home/runner/work/cannectivity/cannectivity/cannectivity/twister-*/nucleo_h723zg_stm32h723xx/zephyr_gnu/cannectivity/app/app.cannectivity*

ARGS="";
for ELF in `ls /home/runner/work/cannectivity/cannectivity/cannectivity/twister-out/*/zephyr_gnu/cannectivity/app/app.cannectivity.debug/zephyr/zephyr.elf` ; do
ARGS="$ARGS --elf $ELF";
done

echo $ARGS
echo $ARGS
echo $ARGS

STACKSTATS=$(go run ./cmd/stackcheck_boards/stackcheck_boards.go \
-c /home/runner/work/cannectivity/cannectivity/cannectivity/app/pexplorer-config-usbrxcalls.json \
$ARGS )

cd ../..

{
echo 'STACKSTATS<<EOF'
echo "$STACKSTATS"
echo 'EOF'
} >> "$GITHUB_OUTPUT"
echo "$STACKSTATS"

- name: Run firmware tests
working-directory: cannectivity
if: startsWith(runner.os, 'Linux')
Expand All @@ -69,3 +116,52 @@ jobs:
if: runner.os != 'Windows'
run: |
ccache -s -vv

# pull_request:
# types: [opened, synchronize, reopened]
update-stackuse-comment:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
steps:
- name: Update PR comment
uses: actions/github-script@v8
with:
script: |
const marker = '<!-- my-bot-comment -->';

const body = `${marker}
## Build status

Commit: \`${context.payload.pull_request.head.sha}\`

Updated: ${new Date().toISOString()}

${ steps.step1.outputs }"
`;

const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});

const existing = comments.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes(marker)
);

if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body,
});
}
149 changes: 149 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
stages:
- build
- staticfirmwarestats
- tests

variables:
# Target board (change as needed)
BOARD: "lpcxpresso55s16"
# Zephyr SDK & Toolchain setup
ZEPHYR_SDK_VERSION: "1.0.1"
ZEPHYR_SDK_INSTALL_DIR: "$CI_PROJECT_DIR/.zephyr-sdk"
ZEPHYR_TOOLCHAIN_VARIANT: "zephyr"
WEST_WORKSPACE: "$CI_PROJECT_DIR/../west_workspace"
FF_USE_FASTZIP: "true"
GITLAB_CLIENT_INSECURE_SKIP_TLS_VERIFY: "true"
GLAB_ENABLE_CI_AUTOLOGIN: "true"

# Use lightweight base image (prevents 'no space left on device' image pull error)
image: ubuntu:26.04

# Cache the downloaded ARM toolchain & python packages across pipeline runs
cache:
key: "zephyr-sdk-${ZEPHYR_SDK_VERSION}"
paths:
- .zephyr-sdk/
- .cache/pip/

.setup_zephyr_environment: &setup_zephyr_environment
before_script:
- export DEBIAN_FRONTEND=noninteractive
- export PIP_CACHE_DIR="$CI_PROJECT_DIR/.cache/pip"

- apt-get update && apt-get install -y --no-install-recommends
git cmake ninja-build python3-pip python3-venv python3-setuptools
wget xz-utils device-tree-compiler ccache glab
&& rm -rf /var/lib/apt/lists/*
- python3 -m venv /builds/potwal/zephyr/venv
- source /builds/potwal/zephyr/venv/bin/activate
- pip install west
- export ZEPHYR_SDK_INSTALL_DIR="$ZEPHYR_SDK_INSTALL_DIR"
- mkdir -p "$WEST_WORKSPACE"
- cd "$WEST_WORKSPACE"
- west init -l "$CI_PROJECT_DIR"
- west update --narrow
- pip install jsonschema
- west zephyr-export
- pip install --quiet -r /builds/potwal/zephyr/scripts/requirements-base.txt
- west sdk install -d "$ZEPHYR_SDK_INSTALL_DIR" --gnu-toolchains arm-zephyr-eabi --no-hosttools
- cd "$CI_PROJECT_DIR"

# TODO build a statically linked package of all cmd's in selfperf
.selfperf: &selfperf
before_script:
- export DEBIAN_FRONTEND=noninteractive
- export PIP_CACHE_DIR="$CI_PROJECT_DIR/.cache/pip"
- apt-get update && apt-get install -y --no-install-recommends
ca-certificates git glab jq wget golang-go build-essential gcc libc6-dev
- wget https://github.com/capstone-engine/capstone/releases/download/6.0.0-Alpha7/libcapstone-dev_6.0.0-Alpha7_amd64.deb --no-check-certificate
- dpkg -i libcapstone-dev_6.0.0-Alpha7_amd64.deb
- git clone https://github.com/paulwuertz/pexplorer
- chmod +x .gitlab/update-mr-comment.sh
- glab auth login --token "$GITLAB_TOKEN"

build:firmware:
stage: build
<<: *setup_zephyr_environment
script:
- echo "Building CANnectivity firmware for $BOARD..."
- west build -p auto -b "$BOARD" app/ -- -DCONF_FILE=prj_debug.conf
artifacts:
name: "cannectivity-$BOARD-$CI_COMMIT_SHORT_SHA"
expire_in: 3 days
paths:
- build/zephyr/zephyr.bin
- build/zephyr/zephyr.hex
- build/zephyr/zephyr.elf
rules:
- when: always

staticfirmwarestats:stackdiff:
stage: staticfirmwarestats
before_script:
- export DEBIAN_FRONTEND=noninteractive
- export PIP_CACHE_DIR="$CI_PROJECT_DIR/.cache/pip"
- apt-get update && apt-get install -y --no-install-recommends
ca-certificates git glab jq wget golang-go build-essential gcc libc6-dev unzip
- wget https://github.com/capstone-engine/capstone/releases/download/6.0.0-Alpha7/libcapstone-dev_6.0.0-Alpha7_amd64.deb --no-check-certificate
- dpkg -i libcapstone-dev_6.0.0-Alpha7_amd64.deb
- git clone https://github.com/paulwuertz/pexplorer
- chmod +x .gitlab/update-mr-comment.sh
- glab auth login --token "$GITLAB_TOKEN"
- MRJSON=$(glab api "projects/86584086/merge_requests/2")
- STARTSHA=$(echo $MRJSON | jq -r '.diff_refs.start_sha')
- PIPELINEID=$(glab api "projects/86584086/pipelines?sha=$STARTSHA" | jq '.[0].id')
- cut --help && echo $PIPELINEID
- glab ci get -d -p $PIPELINEID --branch $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME
- JOBID=$(glab ci get -d -p $PIPELINEID --branch $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME | grep build | cut -f1 -w )
- glab api "projects/86584086/jobs/$JOBID/artifacts" > artifacts.zip
- unzip -d ref artifacts.zip build/zephyr/zephyr.elf
script:
# TODO build go binaries atatically linked to allow just install without installin shared libcapstone
- cd pexplorer/selfperf
- STACKSTATS=$(go run ./cmd/stackdiff/stackdiff.go -md -i ../../build/zephyr/zephyr.elf -c ../../app/pexplorer-config-usbrxcalls.json -ref ../../ref/build/zephyr/zephyr.elf)
- cd ../..
- .gitlab/update-mr-comment.sh "$CI_JOB_STAGE" "Stack usage report:" "$STACKSTATS"
after_script:
- >
if [ $CI_JOB_STATUS == 'success' ]; then
echo 'No stack overflows detected :)'
else
# print stack analysis as comment, even when the main script failed
cd pexplorer/selfperf
STACKSTATS=$(go run ./cmd/stackdiff/stackdiff.go -md -i ../../build/zephyr/zephyr.elf -c ../../app/pexplorer-config-usbrxcalls.json -ref ../../ref/build/zephyr/zephyr.elf || echo Overflow detected )
cd ../..
.gitlab/update-mr-comment.sh "$CI_JOB_STAGE" "Stack usage report:" "$STACKSTATS"
fi
dependencies:
- build:firmware
rules:
# Ensure this runs on Merge Request Pipelines to populate $CI_MERGE_REQUEST_IID
- if: $CI_PIPELINE_SOURCE == "merge_request_event"

# TODO show flash diff
# staticfirmwarestats:memorydiff:
# stage: staticfirmwarestats
# <<: *selfperf
# script:
# - ls -la . # build/zephyr/
# dependencies:
# - build:firmware
# rules:
# # Ensure this runs on Merge Request Pipelines to populate $CI_MERGE_REQUEST_IID
# - if: $CI_PIPELINE_SOURCE == "merge_request_event"

tests:firmwaretests:
stage: tests
# <<: *setup_zephyr_environment
script:
- echo west twister -T app -v --inline-logs --platform native_sim/native/64 -j1
rules:
- when: always

# tests:integrationtests:
# stage: tests
# # <<: *setup_zephyr_environment
# script:
# - west twister -T tests -v --inline-logs --integration
# rules:
# - when: always
35 changes: 35 additions & 0 deletions .gitlab/update-mr-comment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env bash
set -e

STAGE_NAME="$1"
TITLE="$2"
BODY="$3"
HEADER_TAG="<!-- ci-stage-status-comment -->"

if [ -z "$CI_MERGE_REQUEST_IID" ]; then
echo "Not running in a Merge Request pipeline. Skipping."
exit 0
fi

glab config set skip_tls_verify true
# 1. Fetch notes safely
NOTES_JSON=$(glab api "projects/:id/merge_requests/${CI_MERGE_REQUEST_IID}/notes?per_page=100" 2>/dev/null || echo "[]")

# 2. Extract ONLY numeric Note IDs matching the header tag
EXISTING_NOTE_ID=$(echo "$NOTES_JSON" | jq -r ".[]? | select(.body? | contains(\"${HEADER_TAG}\")) | .id" | grep -E '^[0-9]+$' | head -n 1 || true)

BODY_CONTENT="${HEADER_TAG}
### ${TITLE}

${BODY}
"

# 3. Create or Update conditionally
if [ -n "$EXISTING_NOTE_ID" ]; then
echo "Updating existing note ID: ${EXISTING_NOTE_ID}"
glab api -X PUT "projects/:id/merge_requests/${CI_MERGE_REQUEST_IID}/notes/${EXISTING_NOTE_ID}" \
-f "body=${BODY_CONTENT}" > /dev/null
else
echo "Creating new comment on MR !${CI_MERGE_REQUEST_IID}"
glab mr note "${CI_MERGE_REQUEST_IID}" -m "${BODY_CONTENT}" > /dev/null
fi
75 changes: 75 additions & 0 deletions app/pexplorer-config-usbrxcalls.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
"threads": [
{
"thread_entry_name": "bg_thread_main",
"size": 1024
},
{
"thread_entry_name": "gs_usb_tx_thread",
"size": 1024
},
{
"thread_entry_name": "gs_usb_rx_thread",
"size": 1024
},
{
"thread_entry_name": "log_process_thread_func",
"size": 768
},
{
"thread_entry_name": "work_queue_main",
"size": 1024
}
],
"dynamic_calls": [
{
"caller": "gs_usb_rx_thread",
"callees": [
"cannectivity_led_event"
]
},
{
"caller": "mpsc_pbuf_alloc",
"callees": [
"z_log_notify_drop"
]
},
{
"caller": "net_buf_unref",
"callees": [
null
]
},
{
"caller": "udc_submit_event",
"callees": [
"usbd_event_carrier"
]
},
{
"caller": "udc_submit_ep_event",
"callees": [
"usbd_event_carrier"
]
},
{
"caller": "udc_ep_enqueue",
"callees": [
"udc_mcux_unlock"
]
},
{
"caller": "udc_mcux_ep_try_feed",
"callees": [
"USB_DeviceLpc3511IpRecv",
"USB_DeviceLpc3511IpSend"
]
},
{
"caller": "udc_mcux_control",
"callees": [
"USB_DeviceLpc3511IpControl"
]
}
]
}
Loading