Skip to content

Commit

Permalink
iot_usbh_cdc: add target ci test
Browse files Browse the repository at this point in the history
  • Loading branch information
leeebo committed Oct 9, 2023
1 parent a416594 commit 12e0896
Show file tree
Hide file tree
Showing 25 changed files with 319 additions and 99 deletions.
22 changes: 22 additions & 0 deletions .gitlab/ci/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,28 @@ build_components_usb_usb_stream_test_apps:
variables:
EXAMPLE_DIR: components/usb/usb_stream/test_apps

build_components_usb_iot_usbh_test_apps:
extends:
- .build_examples_template
- .rules:build:components_usb_iot_usbh_test
parallel:
matrix:
- IMAGE: espressif/idf:release-v4.4
- IMAGE: espressif/idf:release-v5.0
variables:
EXAMPLE_DIR: components/usb/iot_usbh/test_apps

build_components_usb_iot_usbh_cdc_test_apps:
extends:
- .build_examples_template
- .rules:build:components_usb_iot_usbh_cdc_test
parallel:
matrix:
- IMAGE: espressif/idf:release-v4.4
- IMAGE: espressif/idf:release-v5.0
variables:
EXAMPLE_DIR: components/usb/iot_usbh_cdc/test_apps

build_components_display_lcd_esp_lcd_gc9b71_test_apps:
extends:
- .build_examples_template
Expand Down
9 changes: 6 additions & 3 deletions .gitlab/ci/rules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,10 @@
- "components/tools/cmake_utilities/package_manager.cmake"

.patterns-components_usb_iot_usbh_cdc: &patterns-components_usb_iot_usbh_cdc
- "components/usb/iot_usbh/**/*"
- "components/usb/iot_usbh_cdc/**/*"
- "components/tools/cmake_utilities/package_manager.cmake"

.patterns-components_usb_iot_usbh_modem: &patterns-components_usb_iot_usbh_modem
- "components/usb/iot_usbh/**/*"
- "components/usb/iot_usbh_cdc/**/*"
- "components/usb/iot_usbh_modem/**/*"
- "components/tools/cmake_utilities/package_manager.cmake"

Expand Down Expand Up @@ -850,6 +847,10 @@
changes: *patterns-build_system
- <<: *if-dev-push
changes: *patterns-components_led_led_indicator
- <<: *if-dev-push
changes: *patterns-components_usb_iot_usbh
- <<: *if-dev-push
changes: *patterns-components_usb_iot_usbh_cdc
- <<: *if-dev-push
changes: *patterns-components_usb_iot_usbh_modem
- <<: *if-dev-push
Expand Down Expand Up @@ -1301,6 +1302,8 @@
- <<: *if-trigger-job
- <<: *if-dev-push
changes: *patterns-build_system
- <<: *if-dev-push
changes: *patterns-components_usb_iot_usbh
- <<: *if-dev-push
changes: *patterns-components_usb_iot_usbh_cdc

Expand Down
54 changes: 54 additions & 0 deletions .gitlab/ci/target_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,60 @@ components_test_usb_camera:
TEST_FOLDER: components/usb/usb_stream
TEST_ENV: ${ENV_TAG}

components_test_iot_usbh:
extends:
- .pytest_template
- .rules:build:components_usb_iot_usbh_test
needs:
- job: "build_components_usb_iot_usbh_test_apps"
artifacts: true
optional: true
retry:
max: 2
parallel:
matrix:
- IDF_TARGET: esp32s3
IDF_VERSION: "4.4"
ENV_TAG: usb_4g
- IDF_TARGET: esp32s3
IDF_VERSION: "5.0"
ENV_TAG: usb_4g
tags:
- ${IDF_TARGET}
- ${ENV_TAG}
image: $DOCKER_TARGET_TEST_v5_1_ENV_IMAGE
variables:
TEST_TARGET: ${IDF_TARGET}
TEST_FOLDER: components/usb/iot_usbh
TEST_ENV: ${ENV_TAG}

components_test_iot_usbh_cdc:
extends:
- .pytest_template
- .rules:build:components_usb_iot_usbh_cdc_test
needs:
- job: "build_components_usb_iot_usbh_cdc_test_apps"
artifacts: true
optional: true
retry:
max: 2
parallel:
matrix:
- IDF_TARGET: esp32s3
IDF_VERSION: "4.4"
ENV_TAG: usb_4g
- IDF_TARGET: esp32s3
IDF_VERSION: "5.0"
ENV_TAG: usb_4g
tags:
- ${IDF_TARGET}
- ${ENV_TAG}
image: $DOCKER_TARGET_TEST_v5_1_ENV_IMAGE
variables:
TEST_TARGET: ${IDF_TARGET}
TEST_FOLDER: components/usb/iot_usbh_cdc
TEST_ENV: ${ENV_TAG}

components_test_button:
extends:
- .pytest_template
Expand Down
8 changes: 8 additions & 0 deletions components/.build-rules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ components/usb/usb_stream/test_apps:
enable:
- if: IDF_TARGET in ["esp32s2","esp32s3"]

components/usb/iot_usbh/test_apps:
enable:
- if: IDF_TARGET in ["esp32s2","esp32s3"]

components/usb/iot_usbh_cdc/test_apps:
enable:
- if: IDF_TARGET in ["esp32s2","esp32s3"]

components/knob/test_apps:
enable:
- if: INCLUDE_DEFAULT == 1
Expand Down
5 changes: 5 additions & 0 deletions components/usb/iot_usbh/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# ChangeLog

## v0.2.0 - 2023-10-09

* add hardware test
* increase the priority of USB Host to `base+3`

## v0.1.2 - 2023-02-20

* remove unnecessary header files "hal/usbh_ll.h" "hal/usb_hal.h"
Expand Down
10 changes: 6 additions & 4 deletions components/usb/iot_usbh/idf_component.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
version: "0.1.2"
version: "0.2.0"
targets:
- esp32s2
- esp32s3
description: esp-iot-solution USB Host driver
url: https://github.com/espressif/esp-iot-solution
description: Simple USB Host driver maintained in esp-iot-solution
url: https://github.com/espressif/esp-iot-solution/tree/master/components/usb/iot_usbh
repository: https://github.com/espressif/esp-iot-solution/tree/master/components/usb/iot_usbh
issues: https://github.com/espressif/esp-iot-solution/issues
dependencies:
idf: ">=4.4.1"
cmake_utilities: "0.*"
cmake_utilities: "0.*"
2 changes: 1 addition & 1 deletion components/usb/iot_usbh/iot_usbh.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ static const char *TAG = "IOT_USBH";
*/
#define USBH_TASK_BASE_PRIORITY CONFIG_USBH_TASK_BASE_PRIORITY /*! USB Task base priority */
#define USBH_PROC_TASK_NAME "usbh_proc" /*! USB processing task name, task to handle hot-plug */
#define USBH_PROC_TASK_PRIORITY (USBH_TASK_BASE_PRIORITY) /*! USB processing task priority */
#define USBH_PROC_TASK_PRIORITY (USBH_TASK_BASE_PRIORITY + 3) /*! USB processing task priority */
#define USBH_PROC_TASK_STACK_SIZE 3072 /*! USB processing task stack size */
#define USBH_PROC_TASK_CORE CONFIG_USBH_TASK_CORE_ID /*! USB processing task pin to core id */
#define USBH_TASK_KILL_BIT BIT1 /*! Event bit to kill USB processing task */
Expand Down
2 changes: 0 additions & 2 deletions components/usb/iot_usbh/test/CMakeLists.txt

This file was deleted.

36 changes: 0 additions & 36 deletions components/usb/iot_usbh/test/test_iot_usbh.c

This file was deleted.

8 changes: 8 additions & 0 deletions components/usb/iot_usbh/test_apps/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# The following lines of boilerplate have to be in your project's CMakeLists
# in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.16)

set(EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/tools/unit-test-app/components"
"../../iot_usbh")
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(iot_usbh_test)
3 changes: 3 additions & 0 deletions components/usb/iot_usbh/test_apps/main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
idf_component_register(SRC_DIRS "."
INCLUDE_DIRS "."
PRIV_REQUIRES unity test_utils iot_usbh)
68 changes: 68 additions & 0 deletions components/usb/iot_usbh/test_apps/main/test_iot_usbh.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "unity.h"
#include "esp_log.h"
#include "iot_usbh.h"

#define TEST_MEMORY_LEAK_THRESHOLD (-400)

TEST_CASE("iot_usbh init/deinit", "[iot_usbh]")
{
for (size_t i = 0; i < 5; i++) {
usbh_port_config_t config = DEFAULT_USBH_PORT_CONFIG();
usbh_port_handle_t port_hdl = iot_usbh_port_init(&config);
TEST_ASSERT_NOT_NULL(port_hdl);
TEST_ASSERT_EQUAL(ESP_OK, iot_usbh_port_start(port_hdl));
vTaskDelay(pdMS_TO_TICKS(2000));
TEST_ASSERT_EQUAL(ESP_OK, iot_usbh_port_deinit(port_hdl));
}

usbh_port_config_t config = DEFAULT_USBH_PORT_CONFIG();
usbh_port_handle_t port_hdl = iot_usbh_port_init(&config);
TEST_ASSERT_NOT_NULL(port_hdl);
TEST_ASSERT_EQUAL(ESP_OK, iot_usbh_port_start(port_hdl));
vTaskDelay(pdMS_TO_TICKS(1000));
TEST_ASSERT_EQUAL(ESP_OK, iot_usbh_port_stop(port_hdl));
vTaskDelay(pdMS_TO_TICKS(1000));
TEST_ASSERT_EQUAL(ESP_OK, iot_usbh_port_start(port_hdl));
vTaskDelay(pdMS_TO_TICKS(1000));
TEST_ASSERT_EQUAL(ESP_OK, iot_usbh_port_deinit(port_hdl));
vTaskDelay(pdMS_TO_TICKS(1000));
}

static size_t before_free_8bit;
static size_t before_free_32bit;

static void check_leak(size_t before_free, size_t after_free, const char *type)
{
ssize_t delta = after_free - before_free;
printf("MALLOC_CAP_%s: Before %u bytes free, After %u bytes free (delta %d)\n", type, before_free, after_free, delta);
TEST_ASSERT_MESSAGE(delta >= TEST_MEMORY_LEAK_THRESHOLD, "memory leak");
}

void setUp(void)
{
before_free_8bit = heap_caps_get_free_size(MALLOC_CAP_8BIT);
before_free_32bit = heap_caps_get_free_size(MALLOC_CAP_32BIT);
}

void tearDown(void)
{
size_t after_free_8bit = heap_caps_get_free_size(MALLOC_CAP_8BIT);
size_t after_free_32bit = heap_caps_get_free_size(MALLOC_CAP_32BIT);
check_leak(before_free_8bit, after_free_8bit, "8BIT");
check_leak(before_free_32bit, after_free_32bit, "32BIT");
}

void app_main(void)
{
printf("IOT USBH TEST \n");
unity_run_menu();
}
25 changes: 25 additions & 0 deletions components/usb/iot_usbh/test_apps/pytest_iot_usbh.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Apache-2.0

'''
Steps to run these cases:
- Build
- . ${IDF_PATH}/export.sh
- pip install idf_build_apps
- python tools/build_apps.py components/usb/iot_usbh/test_apps -t esp32s3
- Test
- pip install -r tools/requirements/requirement.pytest.txt
- pytest components/usb/iot_usbh/test_apps --target esp32s3
'''

import pytest
from pytest_embedded import Dut

@pytest.mark.target('esp32s2')
@pytest.mark.target('esp32s3')
@pytest.mark.env('usb_4g')
@pytest.mark.timeout(60 * 60)
def test_iot_usbh(dut: Dut)-> None:
dut.expect_exact('Press ENTER to see the list of tests.')
dut.write('*')
dut.expect_unity_test_output(timeout = 1000)
10 changes: 10 additions & 0 deletions components/usb/iot_usbh/test_apps/sdkconfig.defaults
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# For IDF 5.0
CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ_240=y
CONFIG_FREERTOS_HZ=1000
CONFIG_ESP_TASK_WDT_EN=n
CONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH=4096

# For IDF4.4
CONFIG_ESP32S2_DEFAULT_CPU_FREQ_240=y
CONFIG_ESP32S3_DEFAULT_CPU_FREQ_240=y
CONFIG_ESP_TASK_WDT=n
5 changes: 5 additions & 0 deletions components/usb/iot_usbh_cdc/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# ChangeLog

## v0.2.0 - 2023-10-09

* add hardware test
* decrease the stack priority to `usb base` level

## v0.1.3 - 2023-04-17

### Bug Fixes:
Expand Down
10 changes: 6 additions & 4 deletions components/usb/iot_usbh_cdc/idf_component.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
version: "0.1.3"
version: "0.2.0"
targets:
- esp32s2
- esp32s3
description: esp-iot-solution USB Host CDC driver
url: https://github.com/espressif/esp-iot-solution
description: Simple USB Host CDC driver maintained in esp-iot-solution
url: https://github.com/espressif/esp-iot-solution/tree/master/components/usb/iot_usbh_cdc
repository: https://github.com/espressif/esp-iot-solution/tree/master/components/usb/iot_usbh_cdc
issues: https://github.com/espressif/esp-iot-solution/issues
dependencies:
idf: ">=4.4.1"
cmake_utilities: "0.*"
iot_usbh:
version: ">=0.1.2"
version: "0.*"
public: true
override_path: "../iot_usbh"
8 changes: 4 additions & 4 deletions components/usb/iot_usbh_cdc/iot_usbh_cdc.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ static const char *TAG = "USB_HCDC";
#define TIMEOUT_USB_DRIVER_MS 6000 /*! Timeout for driver operate */
#define TIMEOUT_USB_DRIVER_CHECK_MS 10 /*! Timeout check step */
#define CDC_DATA_TASK_NAME "cdc-data" /*! cdc task name */
#define USBH_TASK_BASE_PRIORITY CONFIG_USBH_TASK_BASE_PRIORITY /*! usbh task priority */
#define CDC_DATA_TASK_PRIORITY (USBH_TASK_BASE_PRIORITY+1) /*! cdc task priority, higher to handle event quick */
#define USBH_TASK_BASE_PRIORITY CONFIG_USBH_TASK_BASE_PRIORITY /*! usbh task priority */
#define CDC_DATA_TASK_PRIORITY USBH_TASK_BASE_PRIORITY /*! cdc task priority, higher to handle event quick */
#define CDC_DATA_TASK_STACK_SIZE 4096 /*! cdc task stack size */
#define CDC_DATA_TASK_CORE CONFIG_USBH_TASK_CORE_ID /*! cdc task core id */
#define BULK_OUT_URB_NUM CONFIG_CDC_BULK_OUT_URB_NUM /*! number of out urb enqueued simultaneously */
Expand Down Expand Up @@ -684,7 +684,7 @@ int usbh_cdc_itf_read_bytes(uint8_t itf, uint8_t *buf, size_t length, TickType_t
if (_usb_in_ringbuf_pop(itf, buf + read_sz, length - read_sz, &read_sz, 0) == ESP_OK) {
rx_data_size += read_sz;
}

ESP_LOGD(TAG, "cdc read itf: %u, buf = %p, len = %u, read = %d", itf, buf, length, rx_data_size);
return rx_data_size;
}

Expand All @@ -695,7 +695,7 @@ int usbh_cdc_read_bytes(uint8_t *buf, size_t length, TickType_t ticks_to_wait)

int usbh_cdc_itf_write_bytes(uint8_t itf, const uint8_t *buf, size_t length)
{
ESP_LOGD(TAG, "cdc write itf: %u, p = %p, len=%u", itf, buf, length);
ESP_LOGD(TAG, "cdc write itf: %u, buf = %p, len = %u", itf, buf, length);
ERR_CHECK(buf != NULL && itf < CDC_INTERFACE_NUM_MAX, "invalid args", -1);
int tx_data_size = 0;

Expand Down
2 changes: 0 additions & 2 deletions components/usb/iot_usbh_cdc/test/CMakeLists.txt

This file was deleted.

Loading

0 comments on commit 12e0896

Please sign in to comment.