summaryrefslogtreecommitdiff
path: root/.github/workflows/hil_test.yml
blob: 39a9060a2777b6e41aba09beac88596504a32b7b (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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
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

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' test/hil/pi4.json | tr '\n' ' ')
          echo "BOARDS_LIST=$BOARDS_LIST"
          echo "BOARDS_LIST=$BOARDS_LIST" >> $GITHUB_ENV
          echo "BOARDS_LIST=$BOARDS_LIST" >> $GITHUB_OUTPUT

      - name: Setup Toolchain
        uses: ./.github/actions/setup_toolchain
        with:
          toolchain: 'arm-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_pi4
          path: |
            cmake-build/cmake-build-*/*/*/*.elf
            cmake-build/cmake-build-*/*/*/*.bin

  # ---------------------------------------
  # Build Espressif
  # ---------------------------------------
  build-esp:
    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
          # Espressif boards
          BOARDS_LIST=$(jq -r '.boards[] | select(.flasher == "esptool") | "-b " + .name' test/hil/pi4.json | tr '\n' ' ')
          echo "BOARDS_LIST=$BOARDS_LIST"
          echo "BOARDS_LIST=$BOARDS_LIST" >> $GITHUB_ENV
          echo "BOARDS_LIST=$BOARDS_LIST" >> $GITHUB_OUTPUT

      - name: Setup ESP-IDF
        if: env.BOARDS_LIST != ''
        uses: ./.github/actions/setup_toolchain
        with:
          toolchain: 'esp-idf'
          toolchain_url: 'v5.1.1'

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

      - name: Build Espressif
        if: env.BOARDS_LIST != ''
        run: docker run --rm -v $PWD:/project -w /project espressif/idf:v5.1.1 python3 tools/build.py $BOARDS_LIST

      - name: Upload Artifacts for Hardware Testing
        uses: actions/upload-artifact@v4
        with:
          name: hil_pi4_esp
          path: |
            cmake-build/cmake-build-*/*/*/*.bin
            cmake-build/cmake-build-*/*/*/bootloader/bootloader.bin
            cmake-build/cmake-build-*/*/*/partition_table/partition-table.bin
            cmake-build/cmake-build-*/*/*/config.env
            cmake-build/cmake-build-*/*/*/flash_args

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

        # USB bus on rpi4 is not stable, reset it before testing
      - name: Reset USB bus
        run: |
          # lsusb -t
          # reset VIA Labs 2.0 hub
          sudo usbreset 001/002

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

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

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

      - 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 pi4.json