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 9, 2024
1 parent 3ee55c3 commit 16d9650
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 18 deletions.
91 changes: 91 additions & 0 deletions .github/workflows/core-hw.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: Hardware tests

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

jobs:
hardware_device_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' }}
TESTOPTS: "-k 'not authenticate and not recovery'"
TT_UHUB_PORT: 1
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 ${{ matrix.model }} 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*"
# 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"
- run: tail -n50 trezor.log || true
if: failure()
- uses: actions/upload-artifact@v3
with:
name: core-hardware-${{ matrix.model }}
path: trezor.log
retention-days: 7
if: always()

hardware_monero_test:
name: Monero 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
env:
TREZOR_MODEL: ${{ matrix.model == 'T2T1' && 'T' || 'R' }}
PYTEST_TIMEOUT: 1200
PYOPT: 0
DISABLE_OPTIGA: 1
BOOTLOADER_DEVEL: ${{ matrix.model == 'T2B1' && '1' || '0' }}
TT_UHUB_PORT: 1
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 ${{ matrix.model }} 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*"
# 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 --arg fullDeps true --run "cd ../../core/tests && ./run_tests_device_emu_monero.sh $TESTOPTS"
- run: tail -n50 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
24 changes: 13 additions & 11 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()
if model == "T1B1":
# tt.power_off()
path = t1.update_firmware(file)
elif model == "tt":
t1.power_off()
path = tt.update_firmware(file)
elif model == "T2T1":
# 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)
9 changes: 7 additions & 2 deletions ci/hardware_tests/device/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
from subprocess import run


# https://www.uugear.com/product/mega4-4-port-usb-3-ppps-hub-for-raspberry-pi-4b/
# as long as every runner has this hub we don't have to configure a per-runner hub location
HUB_VENDOR = "2109:2817"


class Device:
def __init__(self, uhub_location, device_port):
self.uhub_location = uhub_location
Expand Down Expand Up @@ -39,7 +44,7 @@ def power_on(self):
self.now()
self.log("[hardware/usb] Turning power on...")
run(
f"uhubctl -l {self.uhub_location} -p {self.device_port} -a on",
f"uhubctl --vendor {HUB_VENDOR} -p {self.device_port} -a on",
shell=True,
check=True,
)
Expand All @@ -49,7 +54,7 @@ def power_off(self):
self.now()
self.log("[hardware/usb] Turning power off...")
run(
f"uhubctl -l {self.uhub_location} -p {self.device_port} -r 100 -a off",
f"uhubctl --vendor {HUB_VENDOR} -p {self.device_port} -r 5 -a off",
shell=True,
check=True,
)
Expand Down
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 16d9650

Please sign in to comment.