summaryrefslogtreecommitdiff
path: root/.github/workflows/hil_test.yml
blob: d02f13e05ec2fac6eebe932d7cb15c65bb00bb7c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
name: Hardware Test

on:
  workflow_dispatch:
  pull_request:
    branches: [ master ]
    paths:
      - 'src/**'
      - 'examples/**'
      - 'lib/**'
      - 'hw/**'
      - 'test/hil/**'
      - 'tools/get_deps.py'
      - '.github/actions/**'
      - '.github/workflows/hil_test.yml'
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

env:
  HIL_JSON: test/hil/rpi.json

jobs:
  # ---------------------------------------
  # Build Non Espressif
  # ---------------------------------------
  build:
    if: github.repository_owner == 'hathach'
    runs-on: ubuntu-latest
    outputs:
      BOARDS_LIST: ${{ steps.parse_hil_json.outputs.BOARDS_LIST }}
    steps:
      - name: Checkout TinyUSB
        uses: actions/checkout@v4

      - name: Parse HIL json
        id: parse_hil_json
        run: |
          sudo apt install -y jq

          # Non-Espresif boards
          BOARDS_LIST=$(jq -r '.boards[] | select(.flasher != "esptool") | "-b " + .name' ${{ env.HIL_JSON }} | tr '\n' ' ')
          echo "BOARDS_LIST=$BOARDS_LIST"
          echo "BOARDS_LIST=$BOARDS_LIST" >> $GITHUB_ENV
          echo "BOARDS_LIST=$BOARDS_LIST" >> $GITHUB_OUTPUT

      - name: Setup arm-gcc toolchain
        uses: ./.github/actions/setup_toolchain
        with:
          toolchain: 'arm-gcc'

      - name: Setup risv-gcc toolchain
        uses: ./.github/actions/setup_toolchain
        with:
          toolchain: 'riscv-gcc'

      - name: Get Dependencies
        uses: ./.github/actions/get_deps
        with:
          arg: ${{ env.BOARDS_LIST }}

      - name: Build
        run: python tools/build.py $BOARDS_LIST

      - name: Upload Artifacts for Hardware Testing
        uses: actions/upload-artifact@v4
        with:
          name: hil_rpi
          path: |
            cmake-build/cmake-build-*/*/*/*.elf
            cmake-build/cmake-build-*/*/*/*.bin

  # ---------------------------------------
  # Hardware in the loop (HIL)
  # self-hosted running on an RPI. For attached hardware checkout test/hil/rpi.json
  # ---------------------------------------
  hil-rpi:
    if: github.repository_owner == 'hathach'
    needs:
      - build
    runs-on: [self-hosted, ARM64, rpi, hardware-in-the-loop]
    env:
      BOARDS_LIST: "${{ needs.build-esp.outputs.BOARDS_LIST }} ${{ needs.build.outputs.BOARDS_LIST }}"
    steps:
      - name: Clean workspace
        run: |
          echo "Cleaning up previous run"
          rm -rf "${{ github.workspace }}"
          mkdir -p "${{ github.workspace }}"

        # USB bus on rpi is not stable, reset it before testing
#      - name: Reset USB bus
#        run: |
#          echo "1-2" | sudo tee /sys/bus/usb/drivers/usb/unbind
#          sleep 5
#          echo "1-2" | sudo tee /sys/bus/usb/drivers/usb/bind

      - name: Checkout TinyUSB
        uses: actions/checkout@v4
        with:
          sparse-checkout: test/hil

      - name: Download Artifacts
        uses: actions/download-artifact@v4
        with:
          path: cmake-build
          merge-multiple: true

      - name: Test on actual hardware
        run: |
          echo "BOARDS_LIST=$BOARDS_LIST"
          echo "::group::{cmake-build contents}"
          tree cmake-build
          echo "::endgroup::"
          python3 test/hil/hil_test.py $BOARDS_LIST ${{ env.HIL_JSON }}