Skip to content

Commit

Permalink
ci(esp_usb): Run esp_tinyusb test apps in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-marcisovsky committed Nov 13, 2024
1 parent dd9fca9 commit 340727b
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 41 deletions.
22 changes: 12 additions & 10 deletions .github/workflows/build_and_run_test_app_usb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,28 @@ jobs:
with:
name: usb_test_app_bin_${{ matrix.idf_ver }}
path: |
**/test_app/build_esp*/bootloader/bootloader.bin
**/test_app/build_esp*/partition_table/partition-table.bin
**/test_app/build_esp*/test_app_usb_*.bin
**/test_app/build_esp*/test_app_usb_*.elf
**/test_app/build_esp*/flasher_args.json
**/test_app*/**/build_esp*/bootloader/bootloader.bin
**/test_app*/**/build_esp*/partition_table/partition-table.bin
**/test_app*/**/build_esp*/test_app_*.bin
**/test_app*/**/build_esp*/test_app_*.elf
**/test_app*/**/build_esp*/flasher_args.json
**/test_app*/**/build_esp*/config/sdkconfig.json
if-no-files-found: error

run-target-usb-host:
name: Run USB Host TestApp on target
run-target:
name: Run USB Host and Device TestApps on target
if: ${{ github.repository_owner == 'espressif' }}
needs: build
strategy:
fail-fast: false
matrix:
idf_ver: ["release-v5.0", "release-v5.1", "release-v5.2", "release-v5.3", "latest"]
idf_target: ["esp32s2"]
runs-on: [self-hosted, linux, docker, "${{ matrix.idf_target }}", "usb_host"]
runner_tag: ["usb_host", "usb_device"]
runs-on: [self-hosted, linux, docker, "${{ matrix.idf_target }}", "${{ matrix.runner_tag }}"]
container:
image: python:3.11-bookworm
options: --privileged # Privileged mode has access to serial ports
options: --privileged --device-cgroup-rule="c 188:* rmw" --group-add plugdev
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
Expand All @@ -63,4 +65,4 @@ jobs:
PIP_EXTRA_INDEX_URL: "https://dl.espressif.com/pypi/"
run: pip install --only-binary cryptography pytest-embedded pytest-embedded-serial-esp pytest-embedded-idf pyserial pyusb
- name: Run USB Test App on target
run: pytest --embedded-services esp,idf --target=${{ matrix.idf_target }} -m usb_host --build-dir=build_${{ matrix.idf_target }}
run: pytest --embedded-services esp,idf --target=${{ matrix.idf_target }} -m ${{ matrix.runner_tag }} --build-dir=build_${{ matrix.idf_target }}
68 changes: 39 additions & 29 deletions device/esp_tinyusb/test_apps/cdc_and_usb_device/pytest_cdc.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pytest
from pytest_embedded_idf.dut import IdfDut
from time import sleep
from serial import Serial
from serial import Serial, SerialException
from serial.tools.list_ports import comports


Expand Down Expand Up @@ -32,43 +32,53 @@ def test_usb_device_cdc(dut) -> None:
# Find devices with Espressif TinyUSB VID/PID
s = []
ports = comports()

for port, _, hwid in ports:
if '303A:4002' in hwid:
s.append(port)

if len(s) != 2:
raise Exception('TinyUSB COM port not found')

with Serial(s[0]) as cdc0:
with Serial(s[1]) as cdc1:
# Write dummy string and check for echo
cdc0.write('text\r\n'.encode())
res = cdc0.readline()
assert b'text' in res
if b'novfs' in res:
novfs_cdc = cdc0
vfs_cdc = cdc1
try:
with Serial(s[0]) as cdc0:
with Serial(s[1]) as cdc1:
# Write dummy string and check for echo
cdc0.write('text\r\n'.encode())
res = cdc0.readline()
assert b'text' in res
if b'novfs' in res:
novfs_cdc = cdc0
vfs_cdc = cdc1

cdc1.write('text\r\n'.encode())
res = cdc1.readline()
assert b'text' in res
if b'novfs' in res:
novfs_cdc = cdc1
vfs_cdc = cdc0

# Write more than MPS, check that the transfer is not divided
novfs_cdc.write(bytes(100))
dut.expect_exact("Intf 0, RX 100 bytes")

cdc1.write('text\r\n'.encode())
res = cdc1.readline()
assert b'text' in res
if b'novfs' in res:
novfs_cdc = cdc1
vfs_cdc = cdc0
# Write more than RX buffer, check correct reception
novfs_cdc.write(bytes(600))
transfer_len1 = int(dut.expect(r'Intf 0, RX (\d+) bytes')[1].decode())
transfer_len2 = int(dut.expect(r'Intf 0, RX (\d+) bytes')[1].decode())
assert transfer_len1 + transfer_len2 == 600

# Write more than MPS, check that the transfer is not divided
novfs_cdc.write(bytes(100))
dut.expect_exact("Intf 0, RX 100 bytes")
# The VFS is setup for CRLF RX and LF TX
vfs_cdc.write('text\r\n'.encode())
res = vfs_cdc.readline()
assert b'text\n' in res

# Write more than RX buffer, check correct reception
novfs_cdc.write(bytes(600))
transfer_len1 = int(dut.expect(r'Intf 0, RX (\d+) bytes')[1].decode())
transfer_len2 = int(dut.expect(r'Intf 0, RX (\d+) bytes')[1].decode())
assert transfer_len1 + transfer_len2 == 600
return

# The VFS is setup for CRLF RX and LF TX
vfs_cdc.write('text\r\n'.encode())
res = vfs_cdc.readline()
assert b'text\n' in res
except SerialException as e:
print(f"SerialException occurred: {e}")
raise

return
except Exception as e:
print(f"An unexpected error occurred: {e}")
raise
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
@pytest.mark.esp32s2
@pytest.mark.esp32s3
@pytest.mark.esp32p4
@pytest.mark.usb_device
#@pytest.mark.usb_device Disable in CI: missing tinyusb teardown
def test_usb_device_esp_tinyusb(dut: IdfDut) -> None:
dut.run_all_single_board_cases(group='usb_device')
2 changes: 1 addition & 1 deletion device/esp_tinyusb/test_apps/vendor/pytest_vendor.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def ep_write(buf):
@pytest.mark.esp32s2
@pytest.mark.esp32s3
@pytest.mark.esp32p4
@pytest.mark.usb_device
#@pytest.mark.usb_device Disable in CI, for now, not possible to run this test in Docker container
def test_usb_device_vendor(dut: IdfDut) -> None:
'''
Running the test locally:
Expand Down

0 comments on commit 340727b

Please sign in to comment.