Skip to content

Commit

Permalink
feat(class/cdc): Add parsing host tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tore-espressif committed Oct 2, 2024
1 parent a4d5193 commit c3ad19d
Show file tree
Hide file tree
Showing 16 changed files with 1,345 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .build-test-rules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ device/esp_tinyusb:
host/class:
enable:
- if: SOC_USB_OTG_SUPPORTED == 1

host/class/cdc/usb_host_cdc_acm/host_test:
enable:
- if: IDF_TARGET in ["linux"] and (IDF_VERSION_MAJOR >= 5 and IDF_VERSION_MINOR >= 4)
29 changes: 29 additions & 0 deletions .github/workflows/build_and_run_host_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Build and Run USB Host test

on:
schedule:
- cron: '0 0 * * SAT' # Saturday midnight
pull_request:
types: [opened, reopened, synchronize]

jobs:
build:
name: Build
strategy:
fail-fast: false
matrix:
idf_ver: ["latest"]
runs-on: ubuntu-20.04
container: espressif/idf:${{ matrix.idf_ver }}
steps:
- uses: actions/checkout@v4
with:
submodules: 'true'
- name: Build USB Test Application
shell: bash
run: |
. ${IDF_PATH}/export.sh
pip install pytest pytest-cpp idf-build-apps==2.4.3 --upgrade
idf-build-apps find --target linux
idf-build-apps build --target linux
pytest host/class/cdc/usb_host_cdc_acm/host_test/build_linux
2 changes: 1 addition & 1 deletion .github/workflows/build_and_run_test_app_usb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,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 --target=${{ matrix.idf_target }} -m usb_host --build-dir=build_${{ matrix.idf_target }}
run: pytest --embedded-services esp,idf --target=${{ matrix.idf_target }} -m usb_host --build-dir=build_${{ matrix.idf_target }}
11 changes: 11 additions & 0 deletions host/class/cdc/usb_host_cdc_acm/host_test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cmake_minimum_required(VERSION 3.16)

include($ENV{IDF_PATH}/tools/cmake/project.cmake)
set(COMPONENTS main)

list(APPEND EXTRA_COMPONENT_DIRS
"$ENV{IDF_PATH}/tools/mocks/usb/"
"$ENV{IDF_PATH}/tools/mocks/freertos/"
)

project(host_test_usb_cdc)
30 changes: 30 additions & 0 deletions host/class/cdc/usb_host_cdc_acm/host_test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
| Supported Targets | Linux |
| ----------------- | ----- |

# Description

This directory contains test code for `USB Host CDC-ACM` driver. Namely:
* Descriptor parsing

Tests are written using [Catch2](https://github.com/catchorg/Catch2) test framework, use CMock, so you must install Ruby on your machine to run them.

# Build

Tests build regularly like an idf project. Currently only working on Linux machines.

```
idf.py --preview set-target linux
idf.py build
```

# Run

The build produces an executable in the build folder.

Just run:

```
./build/host_test_usb_cdc.elf
```

The test executable have some options provided by the test framework.
9 changes: 9 additions & 0 deletions host/class/cdc/usb_host_cdc_acm/host_test/main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
idf_component_register(SRC_DIRS .
REQUIRES cmock usb
INCLUDE_DIRS .
PRIV_INCLUDE_DIRS "../../private_include"
WHOLE_ARCHIVE)

# Currently 'main' for IDF_TARGET=linux is defined in freertos component.
# Since we are using a freertos mock here, need to let Catch2 provide 'main'.
target_link_libraries(${COMPONENT_LIB} PRIVATE Catch2WithMain)
Loading

0 comments on commit c3ad19d

Please sign in to comment.