Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hwci: move system setup from Actions workflow to script #6

Merged
merged 2 commits into from
Dec 24, 2024
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/treadmill-ci-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ jobs:

# Provide access to the required Treadmill secrets by running in the
# appropriate environment (depending on the on: triggers above)
job-environment: ${{ github.event_name == 'pull_request' && 'treadmill-ci' || 'treadmill-ci-merged' }}
job-environment: ${{ (github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch') && 'treadmill-ci' || 'treadmill-ci-merged' }}


# This workflow tests the tock-hardware-ci scripts itself, so take the
Expand Down
32 changes: 12 additions & 20 deletions .github/workflows/treadmill-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -216,24 +216,17 @@ jobs:
# Avoid overwriting the RUSTFLAGS environment variable
rustflags: ''

- name: Install required system packages
# This is required for the actions/checkout steps to perform a
# proper git clone that also supports checking out submodules:
- name: Install git
run: |
# TODO: currently, the Netboot NBD targets have no access to their
# boot parition (e.g., mounted on /boot/firmware) on a Raspberry Pi OS
# host. This causes certain hooks in response to dpkg / apt commands
# to fail. Thus we ignore errors in these steps until we figure this
# part out.
sudo DEBIAN_FRONTEND=noninteractive apt update || true
sudo DEBIAN_FRONTEND=noninteractive apt install -y \
git cargo openocd python3 python3-pip python3-serial \
python3-pexpect gcc-arm-none-eabi libnewlib-arm-none-eabi \
pkg-config libudev-dev cmake libusb-1.0-0-dev udev make \
gdb-multiarch gcc-arm-none-eabi build-essential jq || true

# Install probe-rs:
curl --proto '=https' --tlsv1.2 -LsSf \
https://github.com/probe-rs/probe-rs/releases/latest/download/probe-rs-tools-installer.sh \
| sh
sudo DEBIAN_FRONTEND=noninteractive apt install -y git

- name: Checkout the Tock Hardware CI scripts
uses: actions/checkout@v4
Expand All @@ -244,33 +237,32 @@ jobs:
- name: Checkout the Tock kernel repository
uses: actions/checkout@v4
with:
path: tock
path: hwci/repos/tock
repository: tock/tock
ref: ${{ inputs.tock-kernel-ref }}

- name: Checkout the libtock-c repository
uses: actions/checkout@v4
with:
path: libtock-c
path: hwci/repos/libtock-c
repository: tock/libtock-c
ref: ${{ inputs.libtock-c-ref }}
fetch-depth: 0
fetch-depth: 0
submodules: false
persist-credentials: true

- name: Create Python virtual environment and install required dependencies
- name: Run setup script
run: |
python3 -m venv ./hwcienv
source ./hwcienv/bin/activate
pip install -r hwci/requirements.txt -c hwci/requirements-frozen.txt
cd ./hwci/
./setup.sh

- name: Run tests
env:
JSON_TEST_ARRAY: ${{ toJSON(fromJSON(needs.test-prepare.outputs.tml-jobs)[matrix.tml-job-id].tests) }}
run: |
source ./hwcienv/bin/activate
cd ./hwci
export PYTHONPATH="$PWD:$PYTHONPATH"
source ./.venv/bin/activate

STEP_FAIL=0

# Generate a summary of all the tests executed:
Expand Down
178 changes: 178 additions & 0 deletions hwci/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
# Ignore local repository checkouts used for the Hardware CI
repos/

# -----------------------------------------------------------------------------
# https://raw.githubusercontent.com/github/gitignore/refs/heads/main/Python.gitignore
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# UV
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
#uv.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
.pdm.toml
.pdm-python
.pdm-build/

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

# PyPI configuration file
.pypirc


12 changes: 6 additions & 6 deletions hwci/boards/nrf52dk.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ class Nrf52dk(TockloaderBoard):
def __init__(self):
super().__init__()
self.arch = "cortex-m4"
self.kernel_path = os.path.join(
self.base_dir, "repos/tock")
self.kernel_board_path = os.path.join(
self.base_dir, "tock/boards/nordic/nrf52840dk"
)
self.kernel_path, "boards/nordic/nrf52840dk")
self.uart_port = self.get_uart_port()
self.uart_baudrate = self.get_uart_baudrate()
self.openocd_board = "nrf52dk"
Expand Down Expand Up @@ -67,10 +68,9 @@ def cleanup(self):

def flash_kernel(self):
logging.info("Flashing the Tock OS kernel")
tock_dir = os.path.join(self.base_dir, "tock")
if not os.path.exists(tock_dir):
logging.error(f"Tock directory {tock_dir} not found")
raise FileNotFoundError(f"Tock directory {tock_dir} not found")
if not os.path.exists(self.kernel_path):
logging.error(f"Tock directory {self.kernel_path} not found")
raise FileNotFoundError(f"Tock directory {self.kernel_path} not found")

# Run make flash-openocd from the board directory
subprocess.run(
Expand Down
6 changes: 2 additions & 4 deletions hwci/boards/tockloader_board.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@ def __init__(self):
super().__init__()
self.board = None # Should be set in subclass
self.arch = None # Should be set in subclass
self.base_dir = os.path.dirname(
os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
)
self.base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

def flash_app(self, app_path):
app_name = os.path.basename(app_path)
logging.info(f"Flashing app: {app_name}")
libtock_c_dir = os.path.join(self.base_dir, "libtock-c")
libtock_c_dir = os.path.join(self.base_dir, "repos", "libtock-c")
if not os.path.exists(libtock_c_dir):
logging.error(f"libtock-c directory {libtock_c_dir} not found")
raise FileNotFoundError(f"libtock-c directory {libtock_c_dir} not found")
Expand Down
6 changes: 5 additions & 1 deletion hwci/core/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import logging
import importlib.util
import sys

from pathlib import Path

def main():
parser = argparse.ArgumentParser(description="Run tests on Tock OS")
Expand All @@ -20,6 +20,10 @@ def main():
format="%(asctime)s - %(levelname)s - %(message)s",
)

# Ensure that imported modules can find the top-level hwci modules
# (appends the hwci root to the PYTHONPATH):
sys.path.append(str(Path(__file__).parent.parent))

# 1. Load board module
board_spec = importlib.util.spec_from_file_location("board_module", args.board)
board_module = importlib.util.module_from_spec(board_spec)
Expand Down
7 changes: 7 additions & 0 deletions hwci/hwci.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Licensed under the Apache License, Version 2.0 or the MIT License.
# SPDX-License-Identifier: Apache-2.0 OR MIT
# Copyright Tock Contributors 2024.

if __name__ == "__main__":
import core
core.main()
Loading
Loading