Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cdc_acm): mock open/close device #87

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

peter-marcisovsky
Copy link
Collaborator

@peter-marcisovsky peter-marcisovsky commented Nov 15, 2024

Description

This MR, as a part of USB Class drivers testing, uses callback functions to some functions from from usb_host.c, used for device opening and closing.

Cmock framework defines callbacks, as user-defined functions which are called whenever a certain mocked function is called, to which a callback function is registered to.

This is useful for us, for example, when we want to "open" a USB device during a class driver host test.

Since the whole USB stack is mocked, usb_host_devcie_open just calls an empty cmock function. But we can register a callback to the usb_host_devcie_open function, which will "open" a mocked USB device. Once the USB device is opened, we can use it for further host testing.

A developer must define USB devices he want's to have "connected" during a test case by himself, at the beginning of a host test case. One can do so by calling usb_host_mock_add_device and passing a device's device and config desc and a desired device address.

Changes

  • Added host tests:
    • Device opening test_device_opening.cpp - We are testing device opening/closing itself
    • Device interfaction test_device_interaction.cpp - We are testing interaction of already opened device with the CDC-ACM driver
  • Test fixtures:
    • CDC-ACM driver mock API for host testing, implements functions
    • mock_cdc_acm_host_install mock_cdc_acm_host_uninstall - Installs/Uninstalls CDC-ACM driver on mocked USB component
    • mock_cdc_acm_host_open mock_cdc_acm_host_close - Opens/Closes mocked CDC device in the CDC-ACM driver
    • mock_cdc_acm_host_data_tx_blocking - Submits mocked transfer to already opened mocked device

Related

  • Blocking change: USB Mock in esp-idf must be updated first
  • IDF-11343 USB class testing: USB Host device list mock

Testing


Checklist

Before submitting a Pull Request, please ensure the following:

  • 🚨 This PR does not introduce breaking changes.
  • All CI checks (GH Actions) pass.
  • Documentation is updated as needed.
  • Tests are updated or added as necessary.
  • Code is well-commented, especially in complex areas.
  • Git history is clean — commits are squashed to the minimum necessary.

@peter-marcisovsky peter-marcisovsky self-assigned this Nov 15, 2024
@peter-marcisovsky peter-marcisovsky added the Status: In Progress Issue is being worked on label Nov 15, 2024
@peter-marcisovsky peter-marcisovsky force-pushed the feat/cdc_acm_mock_open_device branch 2 times, most recently from bf86d96 to 96b95b0 Compare November 26, 2024 12:10
    - Opening and closing mocked USB devices
    - Interaction with mocked USB devices
@peter-marcisovsky peter-marcisovsky marked this pull request as ready for review November 26, 2024 12:51
@peter-marcisovsky peter-marcisovsky added Status: Reviewing Issue is being reviewed and removed Status: In Progress Issue is being worked on labels Nov 26, 2024
@peter-marcisovsky
Copy link
Collaborator Author

There are 2 sub-folders for host tests now:

  • descriptors parsing tests : this tests use USB and Freertos components mocked
  • device itneractions tests : this tests use only mocked USB, Freertos is real component

For this reason, the tests must have been regrouped

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Reviewing Issue is being reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant