Skip to content

Commit

Permalink
workflow: on_target: Reuse build workflow to build firmware
Browse files Browse the repository at this point in the history
Previously the on_target workflow was re-doing the steps done by the
build workflow. But since now the build workflow uploads the built
firmware as artifacts, we now have the possibility to re-use it. The
on_target workflow now calls the build worfklow and downloads its
artifaacts to perform the tests.

The test fraemwork code was modified to accept new input argument
firmware-hex that points to the hex file to test.
Also renamed the python file to have the test_ prefix so that it can be
invoked by pytest without having to specify the -s option.

Signed-off-by: Balaji Srinivasan <[email protected]>
  • Loading branch information
Balaji Srinivasan committed Jun 11, 2024
1 parent 3b062c4 commit cb9ea64
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 58 deletions.
65 changes: 18 additions & 47 deletions .github/workflows/on_target.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,57 +3,14 @@ name: Target tests
on:
workflow_call:
workflow_dispatch:
inputs:
run_test:
description: 'Run test stage'
required: false
default: 'yes'
type: choice
options:
- 'yes'
- 'no'
schedule:
- cron: "0 0 * * *"

jobs:
build:
name: Build
runs-on: ubuntu-22.04
container: ghcr.io/zephyrproject-rtos/ci:v0.26.13
env:
CMAKE_PREFIX_PATH: /opt/toolchains
steps:
- name: Checkout
uses: actions/checkout@v4
with:
path: thingy91x-oob

- name: Initialize
working-directory: thingy91x-oob
run: |
west init -l .
west config manifest.group-filter +bsec
west config build.sysbuild True
west update -o=--depth=1 -n
- name: Install dependencies
run: |
pip install -r nrf/scripts/requirements-build.txt
- name: Build firmware
working-directory: thingy91x-oob
run: |
west build -b thingy91x/nrf9151/ns app -p
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: oob-t91x-hex
if-no-files-found: error
path: thingy91x-oob/build/merged.hex
uses: ./.github/workflows/build.yml

test:
if: github.event.inputs.run_test == 'yes' || github.event.inputs.run_test == '' || github.event.inputs.run_test == null
name: Test
needs: build
runs-on: self-hosted
Expand All @@ -72,15 +29,29 @@ jobs:
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: oob-t91x-hex
name: firmware
path: thingy91x-oob/tests/on_target/artifacts

- name: Set version
shell: bash
run: |
if [[ "${{ startsWith(github.ref, 'refs/tags/') }}" == "true" ]]; then
echo "VERSION=${{ github.ref_name }}" >> $GITHUB_ENV
else
echo "VERSION=${{ github.sha }}" >> $GITHUB_ENV
fi
- name: Verify artifact path
working-directory: thingy91x-oob
run: |
ls -l tests/on_target/artifacts
- name: Install dependencies
working-directory: thingy91x-oob/tests/on_target
run: |
pip install -r requirements.txt --break-system-packages
- name: Run tests
working-directory: thingy91x-oob
working-directory: thingy91x-oob/tests/on_target
run: |
./tests/on_target/run-tests.sh
pytest -v --firmware-hex artifacts/hello.nrfcloud.com-${{ env.VERSION }}-thingy91x-debug-app.hex
7 changes: 0 additions & 7 deletions tests/on_target/run-tests.sh

This file was deleted.

17 changes: 17 additions & 0 deletions tests/on_target/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ def get_uarts():
def t91x_board():
all_uarts = get_uarts()
logger.info(f"All uarts discovered: {all_uarts}")
if not all_uarts:
pytest.fail("No UARTs found")
log_uart_string = all_uarts[0]
logger.info(f"Log UART: {log_uart_string}")

Expand All @@ -51,3 +53,18 @@ def t91x_board():
)

uart.stop()


@pytest.fixture(scope="module")
def hex_file(request):
return request.config.getoption("--firmware-hex")


# Add support for input arguments
def pytest_addoption(parser):
parser.addoption(
"--firmware-hex",
action="store",
default="artifacts/merged.hex",
help="Path to the firmware hex file",
)
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@

TEST_TIMEOUT = 1 * 60

TOP_DIR = os.getenv("TOP_DIR", "tests/on_target")
HEX_FILE = os.path.abspath(os.path.join(TOP_DIR, "artifacts/merged.hex"))

def test_program_board_and_check_uart(t91x_board):
flash_device(HEX_FILE)
def test_program_board_and_check_uart(t91x_board, hex_file):
flash_device(os.path.abspath(hex_file))

expected_lines = ["Network connectivity established", "Connected to Cloud"]

Expand Down

0 comments on commit cb9ea64

Please sign in to comment.