-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cmock): Enable linux target build to run Cmock tests on class dr…
…ivers - HID, CDC-ACM, UVC class drivers can be build on linux target - Added linux build test and simple Cmock test run in CI
- Loading branch information
1 parent
fbf07ac
commit 8549d81
Showing
20 changed files
with
413 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
host/class/cdc/usb_host_cdc_acm/host_test/main/test_unit_public_api.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
|
||
/* | ||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include <catch2/catch_test_macros.hpp> | ||
|
||
#include "usb/cdc_acm_host.h" | ||
|
||
extern "C" { | ||
#include "Mockusb_host.h" | ||
#include "Mockqueue.h" | ||
#include "Mocktask.h" | ||
#include "Mockidf_additions.h" | ||
#include "Mockportmacro.h" | ||
#include "Mockevent_groups.h" | ||
} | ||
|
||
SCENARIO("CDC-ACM Host install") | ||
{ | ||
// CDC-ACM Host driver config set to nullptr | ||
GIVEN("NO CDC-ACM Host driver config, driver not installed") { | ||
TaskHandle_t task_handle; | ||
int sem; | ||
int event_group; | ||
|
||
// Call cdc_acm_host_install with cdc_acm_host_driver_config set to nullptr, fail to create EventGroup | ||
SECTION("Fail to create EventGroup") { | ||
// Create an EventGroup, return nullptr, so the EventGroup is not created successfully | ||
xEventGroupCreate_ExpectAndReturn(nullptr); | ||
// We should be calling xSemaphoreCreteMutex_ExpectAnyArgsAndRetrun instead of xQueueCreateMutex_ExpectAnyArgsAndReturn | ||
// Because of missing Freertos Mocks | ||
// Create a semaphore, return the semaphore handle (Queue Handle in this scenario), so the semaphore is created successfully | ||
xQueueCreateMutex_ExpectAnyArgsAndReturn(reinterpret_cast<QueueHandle_t>(&sem)); | ||
// Create a task, return pdTRUE, so the task is created successfully | ||
xTaskCreatePinnedToCore_ExpectAnyArgsAndReturn(pdTRUE); | ||
// Return task handle by pointer | ||
xTaskCreatePinnedToCore_ReturnThruPtr_pxCreatedTask(&task_handle); | ||
|
||
// goto err: (xEventGroupCreate returned nullptr), delete the queue and the task | ||
vQueueDelete_Expect(reinterpret_cast<QueueHandle_t>(&sem)); | ||
vTaskDelete_Expect(task_handle); | ||
|
||
// Call the DUT function, expect ESP_ERR_NO_MEM | ||
REQUIRE(ESP_ERR_NO_MEM == cdc_acm_host_install(nullptr)); | ||
} | ||
|
||
// Call cdc_acm_host_install, expect to successfully install the CDC ACM host | ||
SECTION("Successfully install CDC ACM Host") { | ||
// Create an EventGroup, return event group handle, so the EventGroup is created successfully | ||
xEventGroupCreate_ExpectAndReturn(reinterpret_cast<EventGroupHandle_t>(&event_group)); | ||
// We should be calling xSemaphoreCreteMutex_ExpectAnyArgsAndRetrun instead of xQueueCreateMutex_ExpectAnyArgsAndReturn | ||
// Because of missing Freertos Mocks | ||
// Create a semaphore, return the semaphore handle (Queue Handle in this scenario), so the semaphore is created successfully | ||
xQueueCreateMutex_ExpectAnyArgsAndReturn(reinterpret_cast<QueueHandle_t>(&sem)); | ||
// Create a task, return pdTRUE, so the task is created successfully | ||
vPortEnterCritical_Expect(); | ||
vPortExitCritical_Expect(); | ||
xTaskCreatePinnedToCore_ExpectAnyArgsAndReturn(pdTRUE); | ||
// Return task handle by pointer | ||
xTaskCreatePinnedToCore_ReturnThruPtr_pxCreatedTask(&task_handle); | ||
|
||
// Call mocked function from USB Host | ||
// return ESP_OK, so the client si registered successfully | ||
usb_host_client_register_ExpectAnyArgsAndReturn(ESP_OK); | ||
|
||
// Resume the task | ||
vTaskResume_Expect(task_handle); | ||
|
||
// Call the DUT Function, expect ESP_OK | ||
REQUIRE(ESP_OK == cdc_acm_host_install(nullptr)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_hid) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 HID` driver. Namely: | ||
* Simple public API call with mocked USB component to test Linux build and Cmock run for this class driver | ||
|
||
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_hid.elf | ||
``` | ||
|
||
The test executable have some options provided by the test framework. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
idf_component_register(SRC_DIRS . | ||
REQUIRES cmock usb | ||
INCLUDE_DIRS . | ||
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
dependencies: | ||
espressif/catch2: "^3.4.0" | ||
usb_host_hid: | ||
version: "*" | ||
override_path: "../../" |
Oops, something went wrong.