Skip to content

Commit

Permalink
ci: move hardware tests over to github actions
Browse files Browse the repository at this point in the history
[skip_ci]
  • Loading branch information
mmilata committed Feb 8, 2024
1 parent 3ee55c3 commit 069b642
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 14 deletions.
79 changes: 79 additions & 0 deletions .github/workflows/core-hw.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: Core hardware

on:
schedule:
- cron: '15 23 * * *' # every day @ 23:15
workflow_dispatch:
pull_request: # TODO remove

jobs:
# core_hardware_test:
# name: Selfhosted runner test
# runs-on: runner5
# env:
# TREZOR_MODEL: T
# PYOPT: 0
# # BOOTLOADER_DEVEL: 1
# DISABLE_OPTIGA: 1
# PYTEST_TIMEOUT: 300
# TREZOR_PYTEST_SKIP_ALTCOINS: 1
# TT_UHUB_LOCATION: "1-3"
# TT_UHUB_PORT: "1"
# # NIX_PATH: "nixpkgs=channel:nixos-23.11"
# steps:
# - uses: actions/checkout@v4
# with:
# submodules: recursive
# - uses: ./.github/actions/environment
# - run: nix-shell --arg hardwareTest true --run uhubctl
# - run: nix-shell --run "poetry run make -C core build_firmware"
# - run: nix-shell --arg hardwareTest true --run "poetry run python ci/hardware_tests/bootstrap.py tt core/build/firmware/firmware.bin"
# - run: nix-shell --run "poetry run trezorctl list"
# - run: nix-shell --run "poetry run trezorctl get-features"
# - run: |
# nix-shell --arg hardwareTest true --run "ls -l /dev/tty*"
# # TODO explain
# nix-shell --arg hardwareTest true --run "sleep 8h | tio --no-autoconnect /dev/ttyTREZOR &> trezor.log" &
# nix-shell --run "poetry run pytest -v tests/device_tests -k 'not authenticate and not recovery'"
# - run: cat trezor.log
# if: always()

core_hardware_test:
name: Device tests
runs-on: [self-hosted, ${{ matrix.model == 'T2B1' && 'hw-t2b1' || 'runner5' }}] # FIXME use hw-t2t1 after it's removed from runner0
strategy:
fail-fast: false
matrix:
model: [T2T1, T2B1] # FIXME t1b1
coins: [universal, btconly]
env:
TREZOR_MODEL: ${{ matrix.model == 'T2T1' && 'T' || 'R' }}
TREZOR_PYTEST_SKIP_ALTCOINS: ${{ matrix.coins == 'btconly' && '1' || '0' }}
PYTEST_TIMEOUT: 1200
PYOPT: 0
DISABLE_OPTIGA: 1
BOOTLOADER_DEVEL: ${{ matrix.model == 'T2B1' && '1' || '0' }}
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- uses: ./.github/actions/environment
- run: nix-shell --arg hardwareTest true --run uhubctl
- run: nix-shell --run "poetry run make -C core build_firmware"
- run: nix-shell --arg hardwareTest true --run "poetry run python ci/hardware_tests/bootstrap.py tt core/build/firmware/firmware.bin"
- run: nix-shell --run "poetry run trezorctl list"
- run: nix-shell --run "poetry run trezorctl get-features"
- run: |
nix-shell --arg hardwareTest true --run "ls -l /dev/tty*"
echo $TT_UHUB_PORT/$TT_UHUB_LOCATION
# log serial console to file; sleep is used because tio needs stdin that is not /dev/null
nix-shell --arg hardwareTest true --run "sleep 8h | tio --no-autoconnect /dev/ttyTREZOR &> trezor.log" &
nix-shell --run "poetry run pytest -v tests/device_tests -k 'not authenticate and not recovery'"
- run: tail -n50 tests/trezor.log || true
if: failure()
- uses: actions/upload-artifact@v3
with:
name: core-hardware-${{ matrix.model }}
path: trezor.log
retention-days: 7
if: always()
1 change: 0 additions & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,5 @@ include:
- ci/prebuild.yml
- ci/build.yml
- ci/test.yml
- ci/test-hw.yml
- ci/posttest.yml
- ci/deploy.yml
20 changes: 11 additions & 9 deletions ci/hardware_tests/bootstrap.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
import os
import sys

from device.t1 import TrezorOne
from device.tt import TrezorT
from device.legacy import TrezorOne
from device.core import TrezorCore


def main(model: str, file: str = None):
t1 = TrezorOne(
os.environ["T1_UHUB_LOCATION"],
os.environ["T1_ARDUINO_SERIAL"],
os.environ["T1_UHUB_PORT"],
os.getenv("T1_UHUB_LOCATION"),
os.getenv("T1_ARDUINO_SERIAL"),
os.getenv("T1_UHUB_PORT"),
)
tt = TrezorT(os.environ["TT_UHUB_LOCATION"], os.environ["TT_UHUB_PORT"])
tt = TrezorCore(os.getenv("TT_UHUB_LOCATION"), os.getenv("TT_UHUB_PORT"))

if model == "t1":
tt.power_off()
# tt.power_off()
path = t1.update_firmware(file)
elif model == "tt":
t1.power_off()
path = tt.update_firmware(file)
# t1.power_off()
path = tt.update_firmware(file, "Trezor T")
elif model == "t2b1":
path = tt.update_firmware(file, "Safe 3")
else:
raise ValueError("Unknown Trezor model.")

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
from .device import Device


class TrezorT(Device):
def update_firmware(self, file=None):
class TrezorCore(Device):
def update_firmware(self, file=None, model_name="Trezor T"):
if not file:
raise ValueError(
"Uploading production firmware will replace the bootloader, it is not allowed!"
)

# reset to enter bootloader again
self.power_off()
self.wait(5)
self.power_on()

self.wait(5)
self.check_model("Trezor T bootloader")
self.check_model("bootloader")

self.run_trezorctl("device wipe --bootloader || true")
self.wait(5)
Expand All @@ -26,4 +27,4 @@ def update_firmware(self, file=None):

# after firmware-update finishes wait for reboot
self.wait(15)
return self.check_model("Trezor T")
return self.check_model(model_name)
File renamed without changes.
1 change: 1 addition & 0 deletions ci/shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ stdenvNoCC.mkDerivation ({
libiconv
] ++ lib.optionals hardwareTest [
uhubctl
tio
ffmpeg
dejavu_fonts
] ++ lib.optionals devTools [
Expand Down

0 comments on commit 069b642

Please sign in to comment.