Skip to content

Commit

Permalink
Run raspberry pi tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
floitsch committed Dec 12, 2024
1 parent 5bd58c8 commit c6e3597
Show file tree
Hide file tree
Showing 10 changed files with 176 additions and 1 deletion.
90 changes: 89 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ env:
DO_RELEASE: ${{ github.event_name == 'release' || startsWith(github.event.inputs.do-release, 'v') }}
DO_MORE_TESTS: ${{ github.event_name == 'schedule' || github.event.inputs.test-more == 'true' }}
ESPTOOL_VERSION: "v4.8.1%2Btoitlang"
TEST_PI_HW: "true"

jobs:
prereqs:
Expand Down Expand Up @@ -111,6 +112,7 @@ jobs:
EXTRA_INCLUDES: ${{ steps.vars.outputs.EXTRA_INCLUDES }}
SHARD_COUNT: ${{ steps.vars.outputs.SHARD_COUNT }}
SHARD_COUNT_LINUX: ${{ steps.vars.outputs.SHARD_COUNT_LINUX }}
TEST_PI_HW: ${{ env.TEST_PI_HW }}

build:
needs: prereqs
Expand Down Expand Up @@ -529,6 +531,49 @@ jobs:
build/firmware-esp32s2.gz
build/firmware-esp32s3.gz
rpi:
runs-on: ubuntu-latest
needs: prereqs
if: needs.prereqs.outputs.TEST_PI_HW == 'true'

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set version
run: |
if [ -z "$TOIT_VERSION" ]; then
TOIT_VERSION=$(cmake -DPRINT_VERSION=1 -P tools/gitversion.cmake)
fi
echo "TOIT_GIT_VERSION=$TOIT_VERSION" >> $GITHUB_ENV
- name: Set up build environment
uses: ./actions/setup-build
with:
toit-dir: .
cache-key-prefix: cross-pi

- name: Make
# Note that the TOIT_GIT_VERSION is set. The make step will thus not
# compute the version from git.
run: |
make raspbian
- name: Pack artifacts
shell: bash
# Note that we use `cp -R` first, since that works on every platform.
run: |
cp -R ./build/raspbian/sdk ./build/raspbian/toit
tar -czf build/rpi.tar.gz -C ./build/raspbian --dereference toit
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: rpi-build
path: |
build/rpi.tar.gz
cross:
runs-on: ubuntu-latest

Expand Down Expand Up @@ -580,10 +625,17 @@ jobs:
run: |
make sdk
make TARGET=win64 sdk
make raspbian
# The raspbian executable is built in the rpi job.
# It is then tested on real hardware.
# If the hardware is unavailable we can reenable this step.
# make raspbian
make aarch64
make arm-linux-gnueabi
- name: Make raspbian
run: |
make raspbian
- name: Build test snapshot
run: |
echo '
Expand Down Expand Up @@ -614,6 +666,7 @@ jobs:
done
- name: Test executables 32-bit
if: ${{ env.TEST_PI_HW != 'true' }}
uses: pguyot/arm-runner-action@v2
with:
cpu: cortex-a7
Expand All @@ -627,6 +680,7 @@ jobs:
build/raspbian/extracted/boot.sh > raspbian_output
- name: Check that the 32-bit run-script worked
if: ${{ env.TEST_PI_HW != 'true' }}
run: |
cat raspbian_output
grep "hello world" raspbian_output
Expand Down Expand Up @@ -1221,3 +1275,37 @@ jobs:
git commit -am "Update to version ${{ env.TOIT_VERSION }}"
git push origin master
popd
serial:
needs: [prereqs, rpi]
if: needs.prereqs.outputs.TEST_PI_HW == 'true'

runs-on: serial

steps:
- name: Clean workspace
run: |
rm -rf ${{ github.workspace }}/*
- uses: actions/checkout@v4

# We need a more recent version of cmake than is installed globally.
- name: Add local bin to PATH
run: |
echo "$HOME/local/bin" >> $GITHUB_PATH
# Download the pi artifact.
- uses: actions/download-artifact@v4
with:
name: rpi-build

- name: Unpack Raspberry Pi
run: |
mkdir -p rpi
tar x -zf rpi.tar.gz -C rpi
- name: Test Raspberry Pi
run: |
# Get the pin configuration from the file in the runner's home.
source $HOME/pi-test.env
make HW_TOIT_EXE=${{ github.workspace }}/rpi/toit/bin/toit test-serial
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,17 @@ install: install-sdk
test:
(cd $(BUILD)/$(HOST) && ninja check_slow check_fuzzer_lib)

.PHONY: test-serial
test-serial:
@if [ -z "$$HW_TOIT_EXE" ]; then \
echo "HW_TOIT_EXE is not set. Set it to the path of the PI executable."; \
exit 1; \
fi
mkdir -p $(BUILD)/serial
(cd $(BUILD)/serial && cmake -DHW_TOIT_EXE=$$HW_TOIT_EXE -G Ninja $(CURDIR)/tests/hw)
$$HW_TOIT_EXE pkg install --project-root tests/hw/pi
(cd $(BUILD)/serial && ninja check_pi)

.PHONY: build-test-assets
build-test-assets: rebuild-cmake
(cd $(BUILD)/$(HOST) && ninja build_test_assets)
Expand Down
28 changes: 28 additions & 0 deletions tests/hw/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright (C) 2024 Toitware ApS.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; version
# 2.1 only.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# The license can be found in the file `LICENSE` in the top level
# directory of this repository.

cmake_minimum_required(VERSION 3.20.0)

project(hw NONE) # No need for compilers.

set(HW_TOIT_EXE "" CACHE FILEPATH "The executable used to run hw tests")

if (NOT HW_TOIT_EXE)
message(FATAL_ERROR "HW_TOIT_EXE not set")
endif()

enable_testing()

add_subdirectory(pi)
35 changes: 35 additions & 0 deletions tests/hw/pi/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright (C) 2024 Toitware ApS.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; version
# 2.1 only.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# The license can be found in the file `LICENSE` in the top level
# directory of this repository.

file(GLOB TOIT_TESTS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*-test.toit")

add_custom_target(
check_pi
COMMAND ${CMAKE_CTEST_COMMAND} -j1 -T test -C pi --output-on-failure
USES_TERMINAL
)

foreach(file ${TOIT_TESTS})
get_filename_component(name ${file} NAME_WE)
set(toit_file ${CMAKE_CURRENT_SOURCE_DIR}/${file})
set(test_name ${name})

add_test(
NAME ${file}
COMMAND ${HW_TOIT_EXE} ${toit_file}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
CONFIGURATIONS pi
)
endforeach()
File renamed without changes.
File renamed without changes.
9 changes: 9 additions & 0 deletions tests/hw/pi/package.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
sdk: ^2.0.0-alpha.144
prefixes:
host: pkg-host
packages:
pkg-host:
url: github.com/toitlang/pkg-host
name: host
version: 1.15.3
hash: 62393e8522b77eafbafe60b9817935266117daf6
4 changes: 4 additions & 0 deletions tests/hw/pi/package.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dependencies:
host:
url: github.com/toitlang/pkg-host
version: ^1.15.3
File renamed without changes.
File renamed without changes.

0 comments on commit c6e3597

Please sign in to comment.