From 43a535c49e1f4f4fa104eadf72093ea5741f6074 Mon Sep 17 00:00:00 2001 From: Roman Leonov Date: Thu, 2 Jan 2025 12:00:25 +0100 Subject: [PATCH] refactor(cdc_and_usb_device): Splitted the tests to cdc and to dconn_detection --- .../CMakeLists.txt | 2 +- .../main/CMakeLists.txt | 0 .../main/idf_component.yml | 0 .../main/test_app_main.c | 0 .../main/test_cdc.c | 0 .../{cdc_and_usb_device => cdc}/pytest_cdc.py | 0 .../sdkconfig.defaults | 0 .../cdc_and_usb_device/main/test_bvalid_sig.h | 18 -- .../main/test_descriptors_config.c | 252 ------------------ .../main/test_descriptors_config.h | 18 -- .../cdc_and_usb_device/main/tud_global_cb.c | 35 --- .../test_apps/dconn_detection/CMakeLists.txt | 9 + .../dconn_detection/main/CMakeLists.txt | 4 + .../dconn_detection/main/idf_component.yml | 5 + .../dconn_detection/main/test_app_main.c | 62 +++++ .../main/test_dconn_detection.c} | 36 ++- .../pytest_dconn_detection.py} | 2 +- .../dconn_detection/sdkconfig.defaults | 18 ++ 18 files changed, 133 insertions(+), 328 deletions(-) rename device/esp_tinyusb/test_apps/{cdc_and_usb_device => cdc}/CMakeLists.txt (89%) rename device/esp_tinyusb/test_apps/{cdc_and_usb_device => cdc}/main/CMakeLists.txt (100%) rename device/esp_tinyusb/test_apps/{cdc_and_usb_device => cdc}/main/idf_component.yml (100%) rename device/esp_tinyusb/test_apps/{cdc_and_usb_device => cdc}/main/test_app_main.c (100%) rename device/esp_tinyusb/test_apps/{cdc_and_usb_device => cdc}/main/test_cdc.c (100%) rename device/esp_tinyusb/test_apps/{cdc_and_usb_device => cdc}/pytest_cdc.py (100%) rename device/esp_tinyusb/test_apps/{cdc_and_usb_device => cdc}/sdkconfig.defaults (100%) delete mode 100644 device/esp_tinyusb/test_apps/cdc_and_usb_device/main/test_bvalid_sig.h delete mode 100644 device/esp_tinyusb/test_apps/cdc_and_usb_device/main/test_descriptors_config.c delete mode 100644 device/esp_tinyusb/test_apps/cdc_and_usb_device/main/test_descriptors_config.h delete mode 100644 device/esp_tinyusb/test_apps/cdc_and_usb_device/main/tud_global_cb.c create mode 100644 device/esp_tinyusb/test_apps/dconn_detection/CMakeLists.txt create mode 100644 device/esp_tinyusb/test_apps/dconn_detection/main/CMakeLists.txt create mode 100644 device/esp_tinyusb/test_apps/dconn_detection/main/idf_component.yml create mode 100644 device/esp_tinyusb/test_apps/dconn_detection/main/test_app_main.c rename device/esp_tinyusb/test_apps/{cdc_and_usb_device/main/test_bvalid_sig.c => dconn_detection/main/test_dconn_detection.c} (69%) rename device/esp_tinyusb/test_apps/{cdc_and_usb_device/pytest_usb_device.py => dconn_detection/pytest_dconn_detection.py} (86%) create mode 100644 device/esp_tinyusb/test_apps/dconn_detection/sdkconfig.defaults diff --git a/device/esp_tinyusb/test_apps/cdc_and_usb_device/CMakeLists.txt b/device/esp_tinyusb/test_apps/cdc/CMakeLists.txt similarity index 89% rename from device/esp_tinyusb/test_apps/cdc_and_usb_device/CMakeLists.txt rename to device/esp_tinyusb/test_apps/cdc/CMakeLists.txt index fdba7348..619c3201 100644 --- a/device/esp_tinyusb/test_apps/cdc_and_usb_device/CMakeLists.txt +++ b/device/esp_tinyusb/test_apps/cdc/CMakeLists.txt @@ -6,4 +6,4 @@ include($ENV{IDF_PATH}/tools/cmake/project.cmake) # "Trim" the build. Include the minimal set of components, main, and anything it depends on. set(COMPONENTS main) -project(test_app_cdc_and_usb_device) +project(test_app_cdc) diff --git a/device/esp_tinyusb/test_apps/cdc_and_usb_device/main/CMakeLists.txt b/device/esp_tinyusb/test_apps/cdc/main/CMakeLists.txt similarity index 100% rename from device/esp_tinyusb/test_apps/cdc_and_usb_device/main/CMakeLists.txt rename to device/esp_tinyusb/test_apps/cdc/main/CMakeLists.txt diff --git a/device/esp_tinyusb/test_apps/cdc_and_usb_device/main/idf_component.yml b/device/esp_tinyusb/test_apps/cdc/main/idf_component.yml similarity index 100% rename from device/esp_tinyusb/test_apps/cdc_and_usb_device/main/idf_component.yml rename to device/esp_tinyusb/test_apps/cdc/main/idf_component.yml diff --git a/device/esp_tinyusb/test_apps/cdc_and_usb_device/main/test_app_main.c b/device/esp_tinyusb/test_apps/cdc/main/test_app_main.c similarity index 100% rename from device/esp_tinyusb/test_apps/cdc_and_usb_device/main/test_app_main.c rename to device/esp_tinyusb/test_apps/cdc/main/test_app_main.c diff --git a/device/esp_tinyusb/test_apps/cdc_and_usb_device/main/test_cdc.c b/device/esp_tinyusb/test_apps/cdc/main/test_cdc.c similarity index 100% rename from device/esp_tinyusb/test_apps/cdc_and_usb_device/main/test_cdc.c rename to device/esp_tinyusb/test_apps/cdc/main/test_cdc.c diff --git a/device/esp_tinyusb/test_apps/cdc_and_usb_device/pytest_cdc.py b/device/esp_tinyusb/test_apps/cdc/pytest_cdc.py similarity index 100% rename from device/esp_tinyusb/test_apps/cdc_and_usb_device/pytest_cdc.py rename to device/esp_tinyusb/test_apps/cdc/pytest_cdc.py diff --git a/device/esp_tinyusb/test_apps/cdc_and_usb_device/sdkconfig.defaults b/device/esp_tinyusb/test_apps/cdc/sdkconfig.defaults similarity index 100% rename from device/esp_tinyusb/test_apps/cdc_and_usb_device/sdkconfig.defaults rename to device/esp_tinyusb/test_apps/cdc/sdkconfig.defaults diff --git a/device/esp_tinyusb/test_apps/cdc_and_usb_device/main/test_bvalid_sig.h b/device/esp_tinyusb/test_apps/cdc_and_usb_device/main/test_bvalid_sig.h deleted file mode 100644 index 82dd31b9..00000000 --- a/device/esp_tinyusb/test_apps/cdc_and_usb_device/main/test_bvalid_sig.h +++ /dev/null @@ -1,18 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -void test_bvalid_sig_mount_cb(void); -void test_bvalid_sig_umount_cb(void); - -#ifdef __cplusplus -} -#endif //__cplusplus diff --git a/device/esp_tinyusb/test_apps/cdc_and_usb_device/main/test_descriptors_config.c b/device/esp_tinyusb/test_apps/cdc_and_usb_device/main/test_descriptors_config.c deleted file mode 100644 index 673761d8..00000000 --- a/device/esp_tinyusb/test_apps/cdc_and_usb_device/main/test_descriptors_config.c +++ /dev/null @@ -1,252 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "soc/soc_caps.h" - -#if SOC_USB_OTG_SUPPORTED - -#include -#include -#include "esp_system.h" -#include "esp_err.h" -#include "freertos/FreeRTOS.h" -#include "freertos/task.h" -#include "freertos/semphr.h" -#include "esp_log.h" -#include "esp_err.h" -#include "driver/gpio.h" -#include "esp_rom_gpio.h" -#include "soc/gpio_sig_map.h" -#include "unity.h" -#include "tinyusb.h" -#include "tusb_tasks.h" - -#define DEVICE_MOUNT_TIMEOUT_MS 5000 - -// ========================= TinyUSB descriptors =============================== - -// Here we need to create dual CDC device, to match the CONFIG_TINYUSB_CDC_COUNT from sdkconfig.defaults -static const uint16_t cdc_desc_config_len = TUD_CONFIG_DESC_LEN + CFG_TUD_CDC * TUD_CDC_DESC_LEN; -static const uint8_t test_fs_configuration_descriptor[] = { - // Config number, interface count, string index, total length, attribute, power in mA - TUD_CONFIG_DESCRIPTOR(1, 0, 0, cdc_desc_config_len, TUSB_DESC_CONFIG_ATT_SELF_POWERED | TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, 100), - TUD_CDC_DESCRIPTOR(0, 4, 0x81, 8, 0x02, 0x82, 64), - TUD_CDC_DESCRIPTOR(2, 4, 0x83, 8, 0x04, 0x84, 64), -}; - -#if (TUD_OPT_HIGH_SPEED) -static const uint8_t test_hs_configuration_descriptor[] = { - // Config number, interface count, string index, total length, attribute, power in mA - TUD_CONFIG_DESCRIPTOR(1, 4, 0, cdc_desc_config_len, TUSB_DESC_CONFIG_ATT_SELF_POWERED | TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, 100), - TUD_CDC_DESCRIPTOR(0, 4, 0x81, 8, 0x02, 0x82, 512), - TUD_CDC_DESCRIPTOR(2, 4, 0x83, 8, 0x04, 0x84, 512), -}; - -static const tusb_desc_device_qualifier_t device_qualifier = { - .bLength = sizeof(tusb_desc_device_qualifier_t), - .bDescriptorType = TUSB_DESC_DEVICE_QUALIFIER, - .bcdUSB = 0x0200, - .bDeviceClass = TUSB_CLASS_MISC, - .bDeviceSubClass = MISC_SUBCLASS_COMMON, - .bDeviceProtocol = MISC_PROTOCOL_IAD, - .bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE, - .bNumConfigurations = 0x01, - .bReserved = 0 -}; - -#endif // TUD_OPT_HIGH_SPEED - -static const tusb_desc_device_t test_device_descriptor = { - .bLength = sizeof(test_device_descriptor), - .bDescriptorType = TUSB_DESC_DEVICE, - .bcdUSB = 0x0200, - .bDeviceClass = TUSB_CLASS_MISC, - .bDeviceSubClass = MISC_SUBCLASS_COMMON, - .bDeviceProtocol = MISC_PROTOCOL_IAD, - .bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE, - .idVendor = 0x303A, // This is Espressif VID. This needs to be changed according to Users / Customers - .idProduct = 0x4002, - .bcdDevice = 0x100, - .iManufacturer = 0x01, - .iProduct = 0x02, - .iSerialNumber = 0x03, - .bNumConfigurations = 0x01 -}; - -// ========================== Private logic ==================================== -SemaphoreHandle_t desc_config_device_mounted = NULL; - -static bool __test_prep(void) -{ - desc_config_device_mounted = xSemaphoreCreateBinary(); - return (desc_config_device_mounted != NULL); -} - -static esp_err_t __test_wait_conn(void) -{ - if (!desc_config_device_mounted) { - return ESP_ERR_INVALID_STATE; - } - - return ( xSemaphoreTake(desc_config_device_mounted, pdMS_TO_TICKS(DEVICE_MOUNT_TIMEOUT_MS)) - ? ESP_OK - : ESP_ERR_TIMEOUT ); -} - -static void __test_conn(void) -{ - if (desc_config_device_mounted) { - xSemaphoreGive(desc_config_device_mounted); - } -} - -static void __test_free(void) -{ - if (desc_config_device_mounted) { - vSemaphoreDelete(desc_config_device_mounted); - } -} - -// ========================== Callbacks ======================================== -// Invoked when device is mounted -void test_descriptors_config_mount_cb(void) -{ - __test_conn(); -} - -void test_descriptors_config_umount_cb(void) -{ - -} - -TEST_CASE("descriptors_config_all_default", "[esp_tinyusb][usb_device]") -{ - TEST_ASSERT_EQUAL(true, __test_prep()); - // Install TinyUSB driver - const tinyusb_config_t tusb_cfg = { - .external_phy = false, - .device_descriptor = NULL, - .configuration_descriptor = NULL, -#if (TUD_OPT_HIGH_SPEED) - .hs_configuration_descriptor = NULL, -#endif // TUD_OPT_HIGH_SPEED - }; - // Install - TEST_ASSERT_EQUAL(ESP_OK, tinyusb_driver_install(&tusb_cfg)); - // Wait for mounted callback - TEST_ASSERT_EQUAL(ESP_OK, __test_wait_conn()); - // Cleanup - TEST_ASSERT_EQUAL(ESP_OK, tinyusb_driver_uninstall()); - __test_free(); -} - -TEST_CASE("descriptors_config_device", "[esp_tinyusb][usb_device]") -{ - TEST_ASSERT_EQUAL(true, __test_prep()); - // Install TinyUSB driver - const tinyusb_config_t tusb_cfg = { - .external_phy = false, - .device_descriptor = &test_device_descriptor, - .configuration_descriptor = NULL, -#if (TUD_OPT_HIGH_SPEED) - .hs_configuration_descriptor = NULL, - .qualifier_descriptor = &device_qualifier, -#endif // TUD_OPT_HIGH_SPEED - }; - // Install - TEST_ASSERT_EQUAL(ESP_OK, tinyusb_driver_install(&tusb_cfg)); - // Wait for mounted callback - TEST_ASSERT_EQUAL(ESP_OK, __test_wait_conn()); - // Cleanup - TEST_ASSERT_EQUAL(ESP_OK, tinyusb_driver_uninstall()); - __test_free(); -} - -TEST_CASE("descriptors_config_device_and_config", "[esp_tinyusb][usb_device]") -{ - TEST_ASSERT_EQUAL(true, __test_prep()); - // Install TinyUSB driver - const tinyusb_config_t tusb_cfg = { - .external_phy = false, - .device_descriptor = &test_device_descriptor, - .configuration_descriptor = test_fs_configuration_descriptor, -#if (TUD_OPT_HIGH_SPEED) - .hs_configuration_descriptor = NULL, - .qualifier_descriptor = &device_qualifier, -#endif // TUD_OPT_HIGH_SPEED - }; - // Install - TEST_ASSERT_EQUAL(ESP_OK, tinyusb_driver_install(&tusb_cfg)); - // Wait for mounted callback - TEST_ASSERT_EQUAL(ESP_OK, __test_wait_conn()); - // Cleanup - TEST_ASSERT_EQUAL(ESP_OK, tinyusb_driver_uninstall()); - __test_free(); -} - -#if (TUD_OPT_HIGH_SPEED) -TEST_CASE("descriptors_config_device_and_fs_config_only", "[esp_tinyusb][usb_device]") -{ - TEST_ASSERT_EQUAL(true, __test_prep()); - // Install TinyUSB driver - const tinyusb_config_t tusb_cfg = { - .external_phy = false, - .device_descriptor = &test_device_descriptor, - .configuration_descriptor = test_fs_configuration_descriptor, - .hs_configuration_descriptor = NULL, - .qualifier_descriptor = &device_qualifier, - }; - // Install - TEST_ASSERT_EQUAL(ESP_OK, tinyusb_driver_install(&tusb_cfg)); - // Wait for mounted callback - TEST_ASSERT_EQUAL(ESP_OK, __test_wait_conn()); - // Cleanup - TEST_ASSERT_EQUAL(ESP_OK, tinyusb_driver_uninstall()); - __test_free(); -} - -TEST_CASE("descriptors_config_device_and_hs_config_only", "[esp_tinyusb][usb_device]") -{ - TEST_ASSERT_EQUAL(true, __test_prep()); - // Install TinyUSB driver - const tinyusb_config_t tusb_cfg = { - .external_phy = false, - .device_descriptor = &test_device_descriptor, - .configuration_descriptor = NULL, - .hs_configuration_descriptor = test_hs_configuration_descriptor, - .qualifier_descriptor = &device_qualifier, - }; - // Install - TEST_ASSERT_EQUAL(ESP_OK, tinyusb_driver_install(&tusb_cfg)); - // Wait for mounted callback - TEST_ASSERT_EQUAL(ESP_OK, __test_wait_conn()); - // Cleanup - TEST_ASSERT_EQUAL(ESP_OK, tinyusb_driver_uninstall()); - __test_free(); -} - -TEST_CASE("descriptors_config_all_configured", "[esp_tinyusb][usb_device]") -{ - TEST_ASSERT_EQUAL(true, __test_prep()); - // Install TinyUSB driver - const tinyusb_config_t tusb_cfg = { - .external_phy = false, - .device_descriptor = &test_device_descriptor, - .fs_configuration_descriptor = test_fs_configuration_descriptor, - .hs_configuration_descriptor = test_hs_configuration_descriptor, - .qualifier_descriptor = &device_qualifier, - }; - // Install - TEST_ASSERT_EQUAL(ESP_OK, tinyusb_driver_install(&tusb_cfg)); - // Wait for mounted callback - TEST_ASSERT_EQUAL(ESP_OK, __test_wait_conn()); - // Cleanup - TEST_ASSERT_EQUAL(ESP_OK, tinyusb_driver_uninstall()); - __test_free(); -} -#endif // TUD_OPT_HIGH_SPEED - -#endif // SOC_USB_OTG_SUPPORTED diff --git a/device/esp_tinyusb/test_apps/cdc_and_usb_device/main/test_descriptors_config.h b/device/esp_tinyusb/test_apps/cdc_and_usb_device/main/test_descriptors_config.h deleted file mode 100644 index 6bdd77b7..00000000 --- a/device/esp_tinyusb/test_apps/cdc_and_usb_device/main/test_descriptors_config.h +++ /dev/null @@ -1,18 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -void test_descriptors_config_mount_cb(void); -void test_descriptors_config_umount_cb(void); - -#ifdef __cplusplus -} -#endif //__cplusplus diff --git a/device/esp_tinyusb/test_apps/cdc_and_usb_device/main/tud_global_cb.c b/device/esp_tinyusb/test_apps/cdc_and_usb_device/main/tud_global_cb.c deleted file mode 100644 index 83dfe374..00000000 --- a/device/esp_tinyusb/test_apps/cdc_and_usb_device/main/tud_global_cb.c +++ /dev/null @@ -1,35 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include "tinyusb.h" -#include "tusb_tasks.h" -#include "test_bvalid_sig.h" -#include "test_descriptors_config.h" - -// Invoked when device is mounted -void tud_mount_cb(void) -{ - /** - * @attention Tests relying on this callback only pass on Linux USB Host! - * - * This callback is issued after SetConfiguration command from USB Host. - * However, Windows issues SetConfiguration only after a USB driver was assigned to the device. - * So in case you are implementing a Vendor Specific class, or your device has 0 interfaces, this callback is not issued on Windows host. - */ - printf("%s\n", __FUNCTION__); - test_bvalid_sig_mount_cb(); - test_descriptors_config_mount_cb(); -} - -// Invoked when device is unmounted -void tud_umount_cb(void) -{ - printf("%s\n", __FUNCTION__); - test_bvalid_sig_umount_cb(); - test_descriptors_config_umount_cb(); -} diff --git a/device/esp_tinyusb/test_apps/dconn_detection/CMakeLists.txt b/device/esp_tinyusb/test_apps/dconn_detection/CMakeLists.txt new file mode 100644 index 00000000..619c3201 --- /dev/null +++ b/device/esp_tinyusb/test_apps/dconn_detection/CMakeLists.txt @@ -0,0 +1,9 @@ +# 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) +include($ENV{IDF_PATH}/tools/cmake/project.cmake) + +# "Trim" the build. Include the minimal set of components, main, and anything it depends on. +set(COMPONENTS main) + +project(test_app_cdc) diff --git a/device/esp_tinyusb/test_apps/dconn_detection/main/CMakeLists.txt b/device/esp_tinyusb/test_apps/dconn_detection/main/CMakeLists.txt new file mode 100644 index 00000000..e81e6278 --- /dev/null +++ b/device/esp_tinyusb/test_apps/dconn_detection/main/CMakeLists.txt @@ -0,0 +1,4 @@ +idf_component_register(SRC_DIRS . + INCLUDE_DIRS . + REQUIRES unity + WHOLE_ARCHIVE) diff --git a/device/esp_tinyusb/test_apps/dconn_detection/main/idf_component.yml b/device/esp_tinyusb/test_apps/dconn_detection/main/idf_component.yml new file mode 100644 index 00000000..b1cb5b54 --- /dev/null +++ b/device/esp_tinyusb/test_apps/dconn_detection/main/idf_component.yml @@ -0,0 +1,5 @@ +## IDF Component Manager Manifest File +dependencies: + espressif/esp_tinyusb: + version: "*" + override_path: "../../../" diff --git a/device/esp_tinyusb/test_apps/dconn_detection/main/test_app_main.c b/device/esp_tinyusb/test_apps/dconn_detection/main/test_app_main.c new file mode 100644 index 00000000..b1321edd --- /dev/null +++ b/device/esp_tinyusb/test_apps/dconn_detection/main/test_app_main.c @@ -0,0 +1,62 @@ +/* + * SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include "unity.h" +#include "unity_test_runner.h" +#include "unity_test_utils_memory.h" + +void app_main(void) +{ + /* + _ _ _ + | | (_) | | + ___ ___ _ __ | |_ _ _ __ _ _ _ _ ___| |__ + / _ \/ __| '_ \| __| | '_ \| | | | | | / __| '_ \ + | __/\__ \ |_) | |_| | | | | |_| | |_| \__ \ |_) | + \___||___/ .__/ \__|_|_| |_|\__, |\__,_|___/_.__/ + | |______ __/ | + |_|______| |___/ + _____ _____ _____ _____ + |_ _| ___/ ___|_ _| + | | | |__ \ `--. | | + | | | __| `--. \ | | + | | | |___/\__/ / | | + \_/ \____/\____/ \_/ + */ + + printf(" _ _ _ \n"); + printf(" | | (_) | | \n"); + printf(" ___ ___ _ __ | |_ _ _ __ _ _ _ _ ___| |__ \n"); + printf(" / _ \\/ __| '_ \\| __| | '_ \\| | | | | | / __| '_ \\ \n"); + printf("| __/\\__ \\ |_) | |_| | | | | |_| | |_| \\__ \\ |_) |\n"); + printf(" \\___||___/ .__/ \\__|_|_| |_|\\__, |\\__,_|___/_.__/ \n"); + printf(" | |______ __/ | \n"); + printf(" |_|______| |___/ \n"); + printf(" _____ _____ _____ _____ \n"); + printf("|_ _| ___/ ___|_ _| \n"); + printf(" | | | |__ \\ `--. | | \n"); + printf(" | | | __| `--. \\ | | \n"); + printf(" | | | |___/\\__/ / | | \n"); + printf(" \\_/ \\____/\\____/ \\_/ \n"); + + unity_utils_setup_heap_record(80); + unity_utils_set_leak_level(128); + unity_run_menu(); +} + +/* setUp runs before every test */ +void setUp(void) +{ + unity_utils_record_free_mem(); +} + +/* tearDown runs after every test */ +void tearDown(void) +{ + unity_utils_evaluate_leaks(); +} diff --git a/device/esp_tinyusb/test_apps/cdc_and_usb_device/main/test_bvalid_sig.c b/device/esp_tinyusb/test_apps/dconn_detection/main/test_dconn_detection.c similarity index 69% rename from device/esp_tinyusb/test_apps/cdc_and_usb_device/main/test_bvalid_sig.c rename to device/esp_tinyusb/test_apps/dconn_detection/main/test_dconn_detection.c index 9bce3811..72496a35 100644 --- a/device/esp_tinyusb/test_apps/cdc_and_usb_device/main/test_bvalid_sig.c +++ b/device/esp_tinyusb/test_apps/dconn_detection/main/test_dconn_detection.c @@ -72,17 +72,47 @@ static const tusb_desc_device_qualifier_t device_qualifier = { }; #endif // TUD_OPT_HIGH_SPEED -void test_bvalid_sig_mount_cb(void) +// Invoked when device is mounted +void tud_mount_cb(void) { + /** + * @attention Tests relying on this callback only pass on Linux USB Host! + * + * This callback is issued after SetConfiguration command from USB Host. + * However, Windows issues SetConfiguration only after a USB driver was assigned to the device. + * So in case you are implementing a Vendor Specific class, or your device has 0 interfaces, this callback is not issued on Windows host. + */ + printf("%s\n", __FUNCTION__); dev_mounted++; } -void test_bvalid_sig_umount_cb(void) +// Invoked when device is unmounted +void tud_umount_cb(void) { + printf("%s\n", __FUNCTION__); dev_umounted++; } -TEST_CASE("bvalid_signal", "[esp_tinyusb][usb_device]") +/** + * @brief TinyUSB Disconnect Detection test case + * + * This is specific artificial test for verifying the disconnection detection event. + * Normally, this event comes as a result of detaching USB device from the port and disappearing the VBUS voltage. + * In this test case, we use GPIO matrix and connect the signal to the ZERO or ONE constant inputs. + * Connection to constant ONE input emulates the attachment to the USB Host port (appearing VBUS). + * Connection to constant ZERO input emulates the detachment from the USB Host port (removing VBUS). + * + * Test logic: + * - Install TinyUSB Device stack without any class + * - In cycle: + * - Emulate the detachment, get the tud_umount_cb(), increase the dev_umounted value + * - Enulate the attachment, get the tud_mount_cb(), increase the dev_mounted value + * - Verify that dev_umounted == dev_mounted + * - Verify that dev_mounted == DEVICE_DETACH_TEST_ROUNDS, where DEVICE_DETACH_TEST_ROUNDS - amount of rounds + * - Uninstall TinyUSB Device stack + * + */ +TEST_CASE("dconn_detection", "[esp_tinyusb]") { unsigned int rounds = DEVICE_DETACH_TEST_ROUNDS; diff --git a/device/esp_tinyusb/test_apps/cdc_and_usb_device/pytest_usb_device.py b/device/esp_tinyusb/test_apps/dconn_detection/pytest_dconn_detection.py similarity index 86% rename from device/esp_tinyusb/test_apps/cdc_and_usb_device/pytest_usb_device.py rename to device/esp_tinyusb/test_apps/dconn_detection/pytest_dconn_detection.py index 24c28465..d23083d0 100644 --- a/device/esp_tinyusb/test_apps/cdc_and_usb_device/pytest_usb_device.py +++ b/device/esp_tinyusb/test_apps/dconn_detection/pytest_dconn_detection.py @@ -9,5 +9,5 @@ @pytest.mark.esp32s3 @pytest.mark.esp32p4 #@pytest.mark.usb_device Disable in CI: missing tinyusb teardown -def test_usb_device_esp_tinyusb(dut: IdfDut) -> None: +def test_usb_device_dconn_detection(dut: IdfDut) -> None: dut.run_all_single_board_cases(group='usb_device') diff --git a/device/esp_tinyusb/test_apps/dconn_detection/sdkconfig.defaults b/device/esp_tinyusb/test_apps/dconn_detection/sdkconfig.defaults new file mode 100644 index 00000000..8092ac2f --- /dev/null +++ b/device/esp_tinyusb/test_apps/dconn_detection/sdkconfig.defaults @@ -0,0 +1,18 @@ +# Configure TinyUSB, it will be used to mock USB devices +CONFIG_TINYUSB_MSC_ENABLED=n +CONFIG_TINYUSB_CDC_ENABLED=y +CONFIG_TINYUSB_CDC_COUNT=2 +CONFIG_TINYUSB_HID_COUNT=0 + +# Disable watchdogs, they'd get triggered during unity interactive menu +CONFIG_ESP_INT_WDT=n +CONFIG_ESP_TASK_WDT=n + +# Run-time checks of Heap and Stack +CONFIG_HEAP_POISONING_COMPREHENSIVE=y +CONFIG_COMPILER_STACK_CHECK_MODE_STRONG=y +CONFIG_COMPILER_STACK_CHECK=y + +CONFIG_UNITY_ENABLE_BACKTRACE_ON_FAIL=y + +CONFIG_COMPILER_CXX_EXCEPTIONS=y