From d7fc73ff76a44deca3fd9f402f6dd4a244fd5ef3 Mon Sep 17 00:00:00 2001 From: hathach Date: Sat, 29 Jun 2013 16:16:05 +0700 Subject: rename test folder --- tests/lpc18xx_43xx/build/readme.md | 1 + tests/lpc18xx_43xx/project.yml | 91 +++++ tests/lpc18xx_43xx/rakefile.rb | 4 + tests/lpc18xx_43xx/test/device/usbd/test_usbd.c | 136 +++++++ tests/lpc18xx_43xx/test/host/ehci/test_ehci_init.c | 184 +++++++++ tests/lpc18xx_43xx/test/host/ehci/test_ehci_isr.c | 103 +++++ .../test/host/ehci/test_ehci_structure.c | 304 +++++++++++++++ .../host/ehci/test_ehci_usbh_hcd_integration.c | 197 ++++++++++ .../test/host/ehci/test_pipe_bulk_open.c | 178 +++++++++ .../test/host/ehci/test_pipe_bulk_xfer.c | 221 +++++++++++ .../test/host/ehci/test_pipe_control_open.c | 196 ++++++++++ .../test/host/ehci/test_pipe_control_xfer.c | 252 ++++++++++++ .../test/host/ehci/test_pipe_interrupt_open.c | 342 ++++++++++++++++ .../test/host/ehci/test_pipe_interrupt_xfer.c | 236 +++++++++++ .../test/host/ehci/test_pipe_isochronous_open.c | 99 +++++ tests/lpc18xx_43xx/test/host/hid/hidh_callback.h | 71 ++++ tests/lpc18xx_43xx/test/host/hid/test_hid_host.c | 97 +++++ .../test/host/hid/test_hidh_keyboard.c | 224 +++++++++++ tests/lpc18xx_43xx/test/host/hid/test_hidh_mouse.c | 226 +++++++++++ tests/lpc18xx_43xx/test/host/host_helper.h | 77 ++++ tests/lpc18xx_43xx/test/host/hub/test_hub.c | 52 +++ .../integration/test_hidh_keyboard_integrate.c | 132 +++++++ tests/lpc18xx_43xx/test/host/msc/test_msc_host.c | 63 +++ tests/lpc18xx_43xx/test/host/usbh/test_enum_task.c | 290 ++++++++++++++ tests/lpc18xx_43xx/test/host/usbh/test_usbh.c | 206 ++++++++++ tests/lpc18xx_43xx/test/test_assertion.c | 298 ++++++++++++++ tests/lpc18xx_43xx/test/test_binary_const.c | 90 +++++ tests/lpc18xx_43xx/test/test_fifo.c | 98 +++++ tests/lpc18xx_43xx/test/test_osal_freeRTOS.c | 85 ++++ tests/lpc18xx_43xx/test/test_osal_none.c | 434 +++++++++++++++++++++ tests/lpc18xx_43xx/test/test_project_settings.c | 58 +++ tests/test/build/readme.md | 1 - tests/test/project.yml | 91 ----- tests/test/rakefile.rb | 4 - tests/test/test/device/usbd/test_usbd.c | 136 ------- tests/test/test/host/ehci/test_ehci_init.c | 184 --------- tests/test/test/host/ehci/test_ehci_isr.c | 103 ----- tests/test/test/host/ehci/test_ehci_structure.c | 304 --------------- .../host/ehci/test_ehci_usbh_hcd_integration.c | 197 ---------- tests/test/test/host/ehci/test_pipe_bulk_open.c | 178 --------- tests/test/test/host/ehci/test_pipe_bulk_xfer.c | 221 ----------- tests/test/test/host/ehci/test_pipe_control_open.c | 196 ---------- tests/test/test/host/ehci/test_pipe_control_xfer.c | 252 ------------ .../test/test/host/ehci/test_pipe_interrupt_open.c | 342 ---------------- .../test/test/host/ehci/test_pipe_interrupt_xfer.c | 236 ----------- .../test/host/ehci/test_pipe_isochronous_open.c | 99 ----- tests/test/test/host/hid/hidh_callback.h | 71 ---- tests/test/test/host/hid/test_hid_host.c | 97 ----- tests/test/test/host/hid/test_hidh_keyboard.c | 224 ----------- tests/test/test/host/hid/test_hidh_mouse.c | 226 ----------- tests/test/test/host/host_helper.h | 77 ---- tests/test/test/host/hub/test_hub.c | 52 --- .../integration/test_hidh_keyboard_integrate.c | 132 ------- tests/test/test/host/msc/test_msc_host.c | 63 --- tests/test/test/host/usbh/test_enum_task.c | 290 -------------- tests/test/test/host/usbh/test_usbh.c | 206 ---------- tests/test/test/test_assertion.c | 298 -------------- tests/test/test/test_binary_const.c | 90 ----- tests/test/test/test_fifo.c | 98 ----- tests/test/test/test_osal_freeRTOS.c | 85 ---- tests/test/test/test_osal_none.c | 434 --------------------- tests/test/test/test_project_settings.c | 58 --- 62 files changed, 5045 insertions(+), 5045 deletions(-) create mode 100644 tests/lpc18xx_43xx/build/readme.md create mode 100644 tests/lpc18xx_43xx/project.yml create mode 100644 tests/lpc18xx_43xx/rakefile.rb create mode 100644 tests/lpc18xx_43xx/test/device/usbd/test_usbd.c create mode 100644 tests/lpc18xx_43xx/test/host/ehci/test_ehci_init.c create mode 100644 tests/lpc18xx_43xx/test/host/ehci/test_ehci_isr.c create mode 100644 tests/lpc18xx_43xx/test/host/ehci/test_ehci_structure.c create mode 100644 tests/lpc18xx_43xx/test/host/ehci/test_ehci_usbh_hcd_integration.c create mode 100644 tests/lpc18xx_43xx/test/host/ehci/test_pipe_bulk_open.c create mode 100644 tests/lpc18xx_43xx/test/host/ehci/test_pipe_bulk_xfer.c create mode 100644 tests/lpc18xx_43xx/test/host/ehci/test_pipe_control_open.c create mode 100644 tests/lpc18xx_43xx/test/host/ehci/test_pipe_control_xfer.c create mode 100644 tests/lpc18xx_43xx/test/host/ehci/test_pipe_interrupt_open.c create mode 100644 tests/lpc18xx_43xx/test/host/ehci/test_pipe_interrupt_xfer.c create mode 100644 tests/lpc18xx_43xx/test/host/ehci/test_pipe_isochronous_open.c create mode 100644 tests/lpc18xx_43xx/test/host/hid/hidh_callback.h create mode 100644 tests/lpc18xx_43xx/test/host/hid/test_hid_host.c create mode 100644 tests/lpc18xx_43xx/test/host/hid/test_hidh_keyboard.c create mode 100644 tests/lpc18xx_43xx/test/host/hid/test_hidh_mouse.c create mode 100644 tests/lpc18xx_43xx/test/host/host_helper.h create mode 100644 tests/lpc18xx_43xx/test/host/hub/test_hub.c create mode 100644 tests/lpc18xx_43xx/test/host/integration/test_hidh_keyboard_integrate.c create mode 100644 tests/lpc18xx_43xx/test/host/msc/test_msc_host.c create mode 100644 tests/lpc18xx_43xx/test/host/usbh/test_enum_task.c create mode 100644 tests/lpc18xx_43xx/test/host/usbh/test_usbh.c create mode 100644 tests/lpc18xx_43xx/test/test_assertion.c create mode 100644 tests/lpc18xx_43xx/test/test_binary_const.c create mode 100644 tests/lpc18xx_43xx/test/test_fifo.c create mode 100644 tests/lpc18xx_43xx/test/test_osal_freeRTOS.c create mode 100644 tests/lpc18xx_43xx/test/test_osal_none.c create mode 100644 tests/lpc18xx_43xx/test/test_project_settings.c delete mode 100644 tests/test/build/readme.md delete mode 100644 tests/test/project.yml delete mode 100644 tests/test/rakefile.rb delete mode 100644 tests/test/test/device/usbd/test_usbd.c delete mode 100644 tests/test/test/host/ehci/test_ehci_init.c delete mode 100644 tests/test/test/host/ehci/test_ehci_isr.c delete mode 100644 tests/test/test/host/ehci/test_ehci_structure.c delete mode 100644 tests/test/test/host/ehci/test_ehci_usbh_hcd_integration.c delete mode 100644 tests/test/test/host/ehci/test_pipe_bulk_open.c delete mode 100644 tests/test/test/host/ehci/test_pipe_bulk_xfer.c delete mode 100644 tests/test/test/host/ehci/test_pipe_control_open.c delete mode 100644 tests/test/test/host/ehci/test_pipe_control_xfer.c delete mode 100644 tests/test/test/host/ehci/test_pipe_interrupt_open.c delete mode 100644 tests/test/test/host/ehci/test_pipe_interrupt_xfer.c delete mode 100644 tests/test/test/host/ehci/test_pipe_isochronous_open.c delete mode 100644 tests/test/test/host/hid/hidh_callback.h delete mode 100644 tests/test/test/host/hid/test_hid_host.c delete mode 100644 tests/test/test/host/hid/test_hidh_keyboard.c delete mode 100644 tests/test/test/host/hid/test_hidh_mouse.c delete mode 100644 tests/test/test/host/host_helper.h delete mode 100644 tests/test/test/host/hub/test_hub.c delete mode 100644 tests/test/test/host/integration/test_hidh_keyboard_integrate.c delete mode 100644 tests/test/test/host/msc/test_msc_host.c delete mode 100644 tests/test/test/host/usbh/test_enum_task.c delete mode 100644 tests/test/test/host/usbh/test_usbh.c delete mode 100644 tests/test/test/test_assertion.c delete mode 100644 tests/test/test/test_binary_const.c delete mode 100644 tests/test/test/test_fifo.c delete mode 100644 tests/test/test/test_osal_freeRTOS.c delete mode 100644 tests/test/test/test_osal_none.c delete mode 100644 tests/test/test/test_project_settings.c diff --git a/tests/lpc18xx_43xx/build/readme.md b/tests/lpc18xx_43xx/build/readme.md new file mode 100644 index 000000000..f525edb1e --- /dev/null +++ b/tests/lpc18xx_43xx/build/readme.md @@ -0,0 +1 @@ +just a build folder \ No newline at end of file diff --git a/tests/lpc18xx_43xx/project.yml b/tests/lpc18xx_43xx/project.yml new file mode 100644 index 000000000..5cf2c6104 --- /dev/null +++ b/tests/lpc18xx_43xx/project.yml @@ -0,0 +1,91 @@ +--- + +# Notes: +# Sample project C code is not presently written to produce a release artifact. +# As such, release build options are disabled. +# This sample, therefore, only demonstrates running a collection of unit tests. + +:project: + :use_exceptions: TRUE + :use_test_preprocessor: TRUE + :use_auxiliary_dependencies: TRUE + :use_deep_dependencies: TRUE + :build_root: build +# :release_build: TRUE + :test_file_prefix: test_ + +:release_build: + :output: test_tinyusb.exe + :use_assembly: FALSE + +:environment: + +:extension: + :executable: .exe + +:paths: + :test: + - +:test/** + :source: + - ../../tinyusb/** + - +:../../demos/bsp/lpc43xx/** + - +:../../demos/device/keyboard/* + - -:../../demos/ + - ../../vendor/freertos/freertos/Source/* + - ../../vendor/freertos/freertos/Source/portable/MSVC-MingW/* + + :support: + - ../support + +:defines: + # in order to add common defines: + # 1) remove the trailing [] from the :common: section + # 2) add entries to the :common: section (e.g. :test: has TEST defined) + :commmon: &common_defines + - MCU=MCU_LPC43XX -std=gnu99 +# - -mx32 + - CORE_M4 + - __CODE_RED + - _TINY_USB_SOURCE_FILE_ + - _TEST_ + :test: + - *common_defines + :test_preprocess: + - *common_defines +# :release: +# :release_preprocess: + +#:flags: +# :test: +# :compile: +# :dcd_lpc175x_6x.c: +# - -DMCU=MCU_LPC175X_6X + +# Ceedling defaults to using gcc for compiling, linking, etc. +# As [:tools] is blank, gcc will be used (so long as it's in your system path) +# See documentation to configure a given toolchain for use + +:cmock: + :mock_prefix: mock_ + :when_no_prototypes: :warn + :enforce_strict_ordering: TRUE + :plugins: + - :ignore + - :callback + - :array + #:ignore: :args_only + :treat_as: + uint8: HEX8 + uint16: HEX16 + uint32: UINT32 + int8: INT8 + bool: UINT8 + +:plugins: + :load_paths: + - ../vendor/ceedling/plugins + :enabled: + #- stdout_pretty_tests_report + - stdout_ide_tests_report + - module_generator +... diff --git a/tests/lpc18xx_43xx/rakefile.rb b/tests/lpc18xx_43xx/rakefile.rb new file mode 100644 index 000000000..6b217f931 --- /dev/null +++ b/tests/lpc18xx_43xx/rakefile.rb @@ -0,0 +1,4 @@ +PROJECT_CEEDLING_ROOT = "../vendor/ceedling" +load "#{PROJECT_CEEDLING_ROOT}/lib/rakefile.rb" + +task :default => %w[ test:all release ] diff --git a/tests/lpc18xx_43xx/test/device/usbd/test_usbd.c b/tests/lpc18xx_43xx/test/device/usbd/test_usbd.c new file mode 100644 index 000000000..c241fa5a1 --- /dev/null +++ b/tests/lpc18xx_43xx/test/device/usbd/test_usbd.c @@ -0,0 +1,136 @@ +/**************************************************************************/ +/*! + @file test_usbd.c + @author hathach (tinyusb.org) + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2013, hathach (tinyusb.org) + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + This file is part of the tinyusb stack. +*/ +/**************************************************************************/ + +#include +#include "unity.h" +#include "errors.h" +#include "type_helper.h" + +#include "tusb_descriptors.h" + +#include "usbd.h" +#include "mock_dcd.h" +#include "mock_hid_device.h" + +void setUp(void) +{ + +} + +void tearDown(void) +{ +} + +void test_dcd_init_failed(void) +{ + dcd_init_ExpectAndReturn(TUSB_ERROR_FAILED); + + //------------- Code Under Test -------------// + TEST_ASSERT_EQUAL( TUSB_ERROR_FAILED, usbd_init() ); +} + +tusb_error_t stub_hidd_init(tusb_descriptor_interface_t const* p_interface_desc, uint16_t* p_length, int num_call) +{ + printf("hidd_init num_call = %d\n", num_call); + switch(num_call) + { + case 0: + TEST_ASSERT_EQUAL_HEX32(&app_tusb_desc_configuration.keyboard_interface, p_interface_desc); + break; + + case 1: + TEST_ASSERT_EQUAL_HEX32(&app_tusb_desc_configuration.mouse_interface, p_interface_desc); + break; + + case 2: + break; + + default: + return TUSB_ERROR_HIDD_DESCRIPTOR_INTERFACE; + } + + return TUSB_ERROR_NONE; +} + +void test_usbd_init_ok(void) +{ + TEST_IGNORE_MESSAGE("pause device stack"); + dcd_init_ExpectAndReturn(TUSB_ERROR_NONE); + + hidd_init_StubWithCallback(stub_hidd_init); + + dcd_controller_connect_Expect(0); + + //------------- Code Under Test -------------// + TEST_ASSERT_EQUAL( TUSB_ERROR_NONE, usbd_init() ); + +} + +void test_usbd_string_descriptor(void) +{ + dcd_init_IgnoreAndReturn(TUSB_ERROR_FAILED); + + //------------- Code Under Test -------------// + TEST_ASSERT_EQUAL( TUSB_ERROR_FAILED, usbd_init() ); + + + //------------- manufacturer string descriptor -------------// + uint32_t const manufacturer_len = sizeof(TUSB_CFG_DEVICE_STRING_MANUFACTURER) - 1; + TEST_ASSERT_EQUAL(manufacturer_len*2 + 2, app_tusb_desc_strings.manufacturer.bLength); + for(uint32_t i=0; i +#include "unity.h" +#include "type_helper.h" +#include "tusb_option.h" +#include "errors.h" +#include "binary.h" + +#include "hal.h" +#include "hcd.h" +#include "ehci.h" + +#include "ehci_controller_fake.h" +#include "mock_osal.h" +#include "mock_usbh_hcd.h" + +usbh_device_info_t usbh_devices[TUSB_CFG_HOST_DEVICE_MAX+1]; + +static uint8_t hostid; + +//--------------------------------------------------------------------+ +// Setup/Teardown + helper declare +//--------------------------------------------------------------------+ +void setUp(void) +{ + ehci_controller_init(); + TEST_ASSERT_STATUS( hcd_init() ); + + hostid = RANDOM(CONTROLLER_HOST_NUMBER) + TEST_CONTROLLER_HOST_START_INDEX; +} + +void tearDown(void) +{ +} + +//--------------------------------------------------------------------+ +// Initialization +//--------------------------------------------------------------------+ +void test_hcd_init_data(void) +{ + //------------- check memory data -------------// + TEST_ASSERT_MEM_ZERO(&ehci_data.device, sizeof(ehci_data.device)); + TEST_ASSERT_MEM_ZERO(ehci_data.addr0_qtd, sizeof(ehci_qtd_t)*3); +} + +void test_hcd_init_usbint(void) +{ + ehci_registers_t* const regs = get_operational_register(hostid); + + //------------- USB INT Enable-------------// + TEST_ASSERT(regs->usb_int_enable_bit.usb_error); + TEST_ASSERT(regs->usb_int_enable_bit.port_change_detect); + TEST_ASSERT(regs->usb_int_enable_bit.async_advance); + + TEST_ASSERT_FALSE(regs->usb_int_enable_bit.framelist_rollover); + TEST_ASSERT_FALSE(regs->usb_int_enable_bit.pci_host_system_error); + + TEST_ASSERT_FALSE(regs->usb_int_enable_bit.nxp_int_sof); + TEST_ASSERT_FALSE(regs->usb_int_enable_bit.usb); + TEST_ASSERT_TRUE(regs->usb_int_enable_bit.nxp_int_async); + TEST_ASSERT_TRUE(regs->usb_int_enable_bit.nxp_int_period); + + // TODO to be portable use usbint instead of nxp int async/period +} + +void test_hcd_init_async_list(void) +{ + ehci_registers_t * const regs = get_operational_register(hostid); + ehci_qhd_t * const async_head = get_async_head(hostid); + + TEST_ASSERT_EQUAL_HEX(async_head, regs->async_list_base); + + TEST_ASSERT_EQUAL_HEX(async_head, align32( (uint32_t) async_head) ); + TEST_ASSERT_EQUAL(EHCI_QUEUE_ELEMENT_QHD, async_head->next.type); + TEST_ASSERT_FALSE(async_head->next.terminate); + + TEST_ASSERT(async_head->head_list_flag); + TEST_ASSERT(async_head->qtd_overlay.halted); +} + +void check_qhd_endpoint_link(ehci_link_t *p_prev, ehci_qhd_t *p_qhd) +{ + //------------- period list check -------------// + TEST_ASSERT_EQUAL_HEX((uint32_t) p_qhd, align32(p_prev->address)); + TEST_ASSERT_FALSE(p_prev->terminate); + TEST_ASSERT_EQUAL(EHCI_QUEUE_ELEMENT_QHD, p_prev->type); +} + +void test_hcd_init_period_list(void) +{ +#if EHCI_PERIODIC_LIST + ehci_registers_t* const regs = get_operational_register(hostid); + ehci_qhd_t * const period_head_arr = get_period_head(hostid, 1); + ehci_link_t * const framelist = get_period_frame_list(hostid); + + TEST_ASSERT_EQUAL_HEX( (uint32_t) framelist, regs->periodic_list_base); + + check_qhd_endpoint_link( framelist+0, period_head_arr+1); + check_qhd_endpoint_link( framelist+2, period_head_arr+1); + check_qhd_endpoint_link( framelist+4, period_head_arr+1); + check_qhd_endpoint_link( framelist+6, period_head_arr+1); + + check_qhd_endpoint_link( framelist+1, period_head_arr+2); + check_qhd_endpoint_link( framelist+5, period_head_arr+2); + + check_qhd_endpoint_link( framelist+3, period_head_arr+3); + check_qhd_endpoint_link( framelist+7, period_head_arr); + check_qhd_endpoint_link( (ehci_link_t*) (period_head_arr+1), period_head_arr); + check_qhd_endpoint_link( (ehci_link_t*) (period_head_arr+2), period_head_arr); + check_qhd_endpoint_link( (ehci_link_t*) (period_head_arr+3), period_head_arr); + + for(uint32_t i=0; i<4; i++) + { + TEST_ASSERT(period_head_arr[i].interrupt_smask); + TEST_ASSERT(period_head_arr[i].qtd_overlay.halted); + } + + TEST_ASSERT_TRUE(period_head_arr[0].next.terminate); +#endif +} + +void test_hcd_init_tt_control(void) +{ + ehci_registers_t* const regs = get_operational_register(hostid); +} + +void test_hcd_init_usbcmd(void) +{ + ehci_registers_t* const regs = get_operational_register(hostid); + + TEST_ASSERT(regs->usb_cmd_bit.async_enable); + +#if EHCI_PERIODIC_LIST + TEST_ASSERT(regs->usb_cmd_bit.periodic_enable); +#else + TEST_ASSERT_FALSE(regs->usb_cmd_bit.periodic_enable); +#endif + + //------------- Framelist size (NXP specific) -------------// + TEST_ASSERT_BITS(BIN8(11), EHCI_CFG_FRAMELIST_SIZE_BITS, regs->usb_cmd_bit.framelist_size); + TEST_ASSERT_EQUAL(EHCI_CFG_FRAMELIST_SIZE_BITS >> 2, regs->usb_cmd_bit.nxp_framelist_size_msb); +} + +void test_hcd_init_portsc(void) +{ + TEST_IGNORE_MESSAGE("more advance stuff need manipulate this register"); +} diff --git a/tests/lpc18xx_43xx/test/host/ehci/test_ehci_isr.c b/tests/lpc18xx_43xx/test/host/ehci/test_ehci_isr.c new file mode 100644 index 000000000..4f5f040c4 --- /dev/null +++ b/tests/lpc18xx_43xx/test/host/ehci/test_ehci_isr.c @@ -0,0 +1,103 @@ +/**************************************************************************/ +/*! + @file test_ehci_isr.c + @author hathach (tinyusb.org) + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2013, hathach (tinyusb.org) + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + This file is part of the tinyusb stack. +*/ +/**************************************************************************/ + +#include +#include "unity.h" +#include "tusb_option.h" +#include "errors.h" +#include "binary.h" +#include "type_helper.h" + +#include "hal.h" +#include "ehci.h" + +#include "ehci_controller_fake.h" +#include "mock_osal.h" +#include "mock_usbh_hcd.h" + +usbh_device_info_t usbh_devices[TUSB_CFG_HOST_DEVICE_MAX+1]; + +static uint8_t hostid; +static ehci_registers_t * regs; + +void setUp(void) +{ + ehci_controller_init(); + TEST_ASSERT_STATUS( hcd_init()); + + hostid = RANDOM(CONTROLLER_HOST_NUMBER) + TEST_CONTROLLER_HOST_START_INDEX; + regs = get_operational_register(hostid); +} + +void tearDown(void) +{ +} + +void test_isr_device_connect_highspeed(void) +{ + usbh_device_plugged_isr_Expect(hostid); + + //------------- Code Under Test -------------// + ehci_controller_device_plug(hostid, TUSB_SPEED_HIGH); +} + +void test_isr_device_connect_fullspeed(void) +{ + usbh_device_plugged_isr_Expect(hostid); + + //------------- Code Under Test -------------// + ehci_controller_device_plug(hostid, TUSB_SPEED_FULL); +} + +void test_isr_device_connect_slowspeed(void) +{ + usbh_device_plugged_isr_Expect(hostid); + + //------------- Code Under Test -------------// + ehci_controller_device_plug(hostid, TUSB_SPEED_LOW); +} + +void test_isr_device_disconnect(void) +{ + usbh_device_unplugged_isr_Expect(hostid); + + //------------- Code Under Test -------------// + ehci_controller_device_unplug(hostid); + + TEST_ASSERT(regs->usb_cmd_bit.advacne_async); +} diff --git a/tests/lpc18xx_43xx/test/host/ehci/test_ehci_structure.c b/tests/lpc18xx_43xx/test/host/ehci/test_ehci_structure.c new file mode 100644 index 000000000..3ca2f3e45 --- /dev/null +++ b/tests/lpc18xx_43xx/test/host/ehci/test_ehci_structure.c @@ -0,0 +1,304 @@ +/**************************************************************************/ +/*! + @file test_ehci_structure.c + @author hathach (tinyusb.org) + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2013, hathach (tinyusb.org) + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + This file is part of the tinyusb stack. +*/ +/**************************************************************************/ + +#include +#include "unity.h" +#include "tusb_option.h" +#include "errors.h" +#include "binary.h" +#include "type_helper.h" + +#include "hal.h" +#include "hcd.h" +#include "ehci.h" + +#include "ehci_controller_fake.h" +#include "mock_osal.h" +#include "mock_usbh_hcd.h" + +usbh_device_info_t usbh_devices[TUSB_CFG_HOST_DEVICE_MAX+1]; + +//--------------------------------------------------------------------+ +// Setup/Teardown + helper declare +//--------------------------------------------------------------------+ +void setUp(void) +{ + +} + +void tearDown(void) +{ +} + +//--------------------------------------------------------------------+ +// +//--------------------------------------------------------------------+ +void test_struct_alignment(void) +{ + TEST_ASSERT_EQUAL( 32, __alignof__(ehci_qhd_t) ); +// TEST_ASSERT_EQUAL( 32, __alignof__(ehci_qtd_t) ); ehci_qtd_t is used to declare overlay variable in qhd --> cannot declare with ATTR_ALIGNED(32) + + TEST_ASSERT_EQUAL( 32, __alignof__(ehci_itd_t) ); + TEST_ASSERT_EQUAL( 32, __alignof__(ehci_sitd_t) ); + +} + +void test_struct_size(void) +{ + if (4 < sizeof(void*)) // running tests in x64 environment + { + TEST_ASSERT_EQUAL( 64 - 8, offsetof(ehci_qhd_t, p_qtd_list_head) ); // 64 - 2x 32-bit pointer qtds + }else + { + TEST_ASSERT_EQUAL( 64, sizeof(ehci_qhd_t) ); + } + TEST_ASSERT_EQUAL( 32, sizeof(ehci_qtd_t) ); + + TEST_ASSERT_EQUAL( 64, sizeof(ehci_itd_t) ); + TEST_ASSERT_EQUAL( 32, sizeof(ehci_sitd_t) ); + + TEST_ASSERT_EQUAL( 4, sizeof(ehci_link_t) ); +} + +//--------------------------------------------------------------------+ +// EHCI Data Structure +//--------------------------------------------------------------------+ +void test_qtd_structure(void) +{ + TEST_ASSERT_EQUAL( 0, offsetof(ehci_qtd_t, next)); + TEST_ASSERT_EQUAL( 4, offsetof(ehci_qtd_t, alternate)); + TEST_ASSERT_EQUAL( 5, BITFIELD_OFFSET_OF_UINT32(ehci_qtd_t, 1, used)); + + //------------- Word 2 -------------// + TEST_ASSERT_EQUAL( 0, BITFIELD_OFFSET_OF_UINT32(ehci_qtd_t, 2, pingstate_err) ); + TEST_ASSERT_EQUAL( 1, BITFIELD_OFFSET_OF_UINT32(ehci_qtd_t, 2, non_hs_split_state) ); + TEST_ASSERT_EQUAL( 2, BITFIELD_OFFSET_OF_UINT32(ehci_qtd_t, 2, non_hs_period_missed_uframe)); + TEST_ASSERT_EQUAL( 3, BITFIELD_OFFSET_OF_UINT32(ehci_qtd_t, 2, xact_err) ); + TEST_ASSERT_EQUAL( 4, BITFIELD_OFFSET_OF_UINT32(ehci_qtd_t, 2, babble_err) ); + TEST_ASSERT_EQUAL( 5, BITFIELD_OFFSET_OF_UINT32(ehci_qtd_t, 2, buffer_err) ); + TEST_ASSERT_EQUAL( 6, BITFIELD_OFFSET_OF_UINT32(ehci_qtd_t, 2, halted) ); + TEST_ASSERT_EQUAL( 7, BITFIELD_OFFSET_OF_UINT32(ehci_qtd_t, 2, active) ); + TEST_ASSERT_EQUAL( 8, BITFIELD_OFFSET_OF_UINT32(ehci_qtd_t, 2, pid) ); + TEST_ASSERT_EQUAL( 10, BITFIELD_OFFSET_OF_UINT32(ehci_qtd_t, 2, cerr) ); + TEST_ASSERT_EQUAL( 12, BITFIELD_OFFSET_OF_UINT32(ehci_qtd_t, 2, current_page) ); + TEST_ASSERT_EQUAL( 15, BITFIELD_OFFSET_OF_UINT32(ehci_qtd_t, 2, int_on_complete) ); + TEST_ASSERT_EQUAL( 16, BITFIELD_OFFSET_OF_UINT32(ehci_qtd_t, 2, total_bytes) ); + TEST_ASSERT_EQUAL( 31, BITFIELD_OFFSET_OF_UINT32(ehci_qtd_t, 2, data_toggle) ); + + TEST_ASSERT_EQUAL( 12, offsetof(ehci_qtd_t, buffer)); +} + +void test_qhd_structure(void) +{ + TEST_ASSERT_EQUAL( 0, offsetof(ehci_qhd_t, next)); + + //------------- Word 1 -------------// + TEST_ASSERT_EQUAL( 0, BITFIELD_OFFSET_OF_UINT32(ehci_qhd_t, 1, device_address) ); + TEST_ASSERT_EQUAL( 7, BITFIELD_OFFSET_OF_UINT32(ehci_qhd_t, 1, non_hs_period_inactive_next_xact) ); + TEST_ASSERT_EQUAL( 8, BITFIELD_OFFSET_OF_UINT32(ehci_qhd_t, 1, endpoint_number) ); + TEST_ASSERT_EQUAL( 12, BITFIELD_OFFSET_OF_UINT32(ehci_qhd_t, 1, endpoint_speed) ); + TEST_ASSERT_EQUAL( 14, BITFIELD_OFFSET_OF_UINT32(ehci_qhd_t, 1, data_toggle_control) ); + TEST_ASSERT_EQUAL( 15, BITFIELD_OFFSET_OF_UINT32(ehci_qhd_t, 1, head_list_flag) ); + TEST_ASSERT_EQUAL( 16, BITFIELD_OFFSET_OF_UINT32(ehci_qhd_t, 1, max_package_size) ); + TEST_ASSERT_EQUAL( 27, BITFIELD_OFFSET_OF_UINT32(ehci_qhd_t, 1, non_hs_control_endpoint) ); + TEST_ASSERT_EQUAL( 28, BITFIELD_OFFSET_OF_UINT32(ehci_qhd_t, 1, nak_count_reload) ); + + //------------- Word 2 -------------// + TEST_ASSERT_EQUAL( 0, BITFIELD_OFFSET_OF_UINT32(ehci_qhd_t, 2, interrupt_smask) ); + TEST_ASSERT_EQUAL( 8, BITFIELD_OFFSET_OF_UINT32(ehci_qhd_t, 2, non_hs_interrupt_cmask) ); + TEST_ASSERT_EQUAL( 16, BITFIELD_OFFSET_OF_UINT32(ehci_qhd_t, 2, hub_address) ); + TEST_ASSERT_EQUAL( 23, BITFIELD_OFFSET_OF_UINT32(ehci_qhd_t, 2, hub_port) ); + TEST_ASSERT_EQUAL( 30, BITFIELD_OFFSET_OF_UINT32(ehci_qhd_t, 2, mult) ); + + TEST_ASSERT_EQUAL( 3*4, offsetof(ehci_qhd_t, qtd_addr)); + TEST_ASSERT_EQUAL( 4*4, offsetof(ehci_qhd_t, qtd_overlay)); +} + +void test_itd_structure(void) +{ + TEST_ASSERT_EQUAL( 0, offsetof(ehci_itd_t, next)); + + // Each Transaction Word + TEST_ASSERT_EQUAL( 0 , BITFIELD_OFFSET_OF_MEMBER(ehci_itd_t, xact[0], offset) ); + TEST_ASSERT_EQUAL( 12 , BITFIELD_OFFSET_OF_MEMBER(ehci_itd_t, xact[0], page_select) ); + TEST_ASSERT_EQUAL( 15 , BITFIELD_OFFSET_OF_MEMBER(ehci_itd_t, xact[0], int_on_complete) ); + TEST_ASSERT_EQUAL( 16 , BITFIELD_OFFSET_OF_MEMBER(ehci_itd_t, xact[0], length) ); + TEST_ASSERT_EQUAL( 28 , BITFIELD_OFFSET_OF_MEMBER(ehci_itd_t, xact[0], error) ); + TEST_ASSERT_EQUAL( 29 , BITFIELD_OFFSET_OF_MEMBER(ehci_itd_t, xact[0], babble_err) ); + TEST_ASSERT_EQUAL( 30 , BITFIELD_OFFSET_OF_MEMBER(ehci_itd_t, xact[0], buffer_err) ); + TEST_ASSERT_EQUAL( 31 , BITFIELD_OFFSET_OF_MEMBER(ehci_itd_t, xact[0], active) ); + + TEST_ASSERT_EQUAL( 9*4, offsetof(ehci_itd_t, BufferPointer)); +} + +void test_sitd_structure(void) +{ + TEST_ASSERT_EQUAL( 0, offsetof(ehci_sitd_t, next)); + + //------------- Word 1 -------------// + TEST_ASSERT_EQUAL( 0, BITFIELD_OFFSET_OF_UINT32(ehci_sitd_t, 1, device_address) ); + TEST_ASSERT_EQUAL( 8, BITFIELD_OFFSET_OF_UINT32(ehci_sitd_t, 1, endpoint_number) ); + TEST_ASSERT_EQUAL( 16, BITFIELD_OFFSET_OF_UINT32(ehci_sitd_t, 1, hub_address) ); + TEST_ASSERT_EQUAL( 24, BITFIELD_OFFSET_OF_UINT32(ehci_sitd_t, 1, port_number) ); + TEST_ASSERT_EQUAL( 31, BITFIELD_OFFSET_OF_UINT32(ehci_sitd_t, 1, direction) ); + + //------------- Word 2 -------------// + TEST_ASSERT_EQUAL( 4*2, offsetof(ehci_sitd_t, interrupt_smask)); + TEST_ASSERT_EQUAL( 4*2+1, offsetof(ehci_sitd_t, non_hs_interrupt_cmask)); + + //------------- Word 3 -------------// + TEST_ASSERT_EQUAL( 1, BITFIELD_OFFSET_OF_UINT32(ehci_sitd_t, 3, split_state) ); + TEST_ASSERT_EQUAL( 2, BITFIELD_OFFSET_OF_UINT32(ehci_sitd_t, 3, missed_uframe)); + TEST_ASSERT_EQUAL( 3, BITFIELD_OFFSET_OF_UINT32(ehci_sitd_t, 3, xact_err) ); + TEST_ASSERT_EQUAL( 4, BITFIELD_OFFSET_OF_UINT32(ehci_sitd_t, 3, babble_err) ); + TEST_ASSERT_EQUAL( 5, BITFIELD_OFFSET_OF_UINT32(ehci_sitd_t, 3, buffer_err) ); + TEST_ASSERT_EQUAL( 6, BITFIELD_OFFSET_OF_UINT32(ehci_sitd_t, 3, error) ); + TEST_ASSERT_EQUAL( 7, BITFIELD_OFFSET_OF_UINT32(ehci_sitd_t, 3, active) ); + + TEST_ASSERT_EQUAL( 8, BITFIELD_OFFSET_OF_UINT32(ehci_sitd_t, 3, cmask_progress) ); + TEST_ASSERT_EQUAL( 16, BITFIELD_OFFSET_OF_UINT32(ehci_sitd_t, 3, total_bytes) ); + TEST_ASSERT_EQUAL( 30, BITFIELD_OFFSET_OF_UINT32(ehci_sitd_t, 3, page_select) ); + TEST_ASSERT_EQUAL( 31, BITFIELD_OFFSET_OF_UINT32(ehci_sitd_t, 3, int_on_complete) ); + + //------------- Word 4 -------------// + TEST_ASSERT_EQUAL( 4*4, offsetof(ehci_sitd_t, buffer)); + + TEST_ASSERT_EQUAL( 4*6, offsetof(ehci_sitd_t, back)); +} + +//--------------------------------------------------------------------+ +// EHCI Register Interface +//--------------------------------------------------------------------+ +void test_register_offset(void) +{ + TEST_ASSERT_EQUAL( 0x00, offsetof(ehci_registers_t, usb_cmd)); + TEST_ASSERT_EQUAL( 0x04, offsetof(ehci_registers_t, usb_sts)); + TEST_ASSERT_EQUAL( 0x08, offsetof(ehci_registers_t, usb_int_enable)); + TEST_ASSERT_EQUAL( 0x0C, offsetof(ehci_registers_t, frame_index)); + TEST_ASSERT_EQUAL( 0x10, offsetof(ehci_registers_t, ctrl_ds_seg)); + TEST_ASSERT_EQUAL( 0x14, offsetof(ehci_registers_t, periodic_list_base)); + TEST_ASSERT_EQUAL( 0x18, offsetof(ehci_registers_t, async_list_base)); + TEST_ASSERT_EQUAL( 0x1C, offsetof(ehci_registers_t, tt_control)); // NXP specific + TEST_ASSERT_EQUAL( 0x40, offsetof(ehci_registers_t, config_flag)); // NXP not used + TEST_ASSERT_EQUAL( 0x44, offsetof(ehci_registers_t, portsc)); +} + +void test_register_usbcmd(void) +{ + TEST_ASSERT_EQUAL( 0 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_cmd_bit, run_stop) ); + TEST_ASSERT_EQUAL( 1 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_cmd_bit, reset) ); + TEST_ASSERT_EQUAL( 2 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_cmd_bit, framelist_size) ); + TEST_ASSERT_EQUAL( 4 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_cmd_bit, periodic_enable) ); + TEST_ASSERT_EQUAL( 5 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_cmd_bit, async_enable) ); + TEST_ASSERT_EQUAL( 6 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_cmd_bit, advacne_async) ); + TEST_ASSERT_EQUAL( 7 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_cmd_bit, light_reset) ); + TEST_ASSERT_EQUAL( 8 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_cmd_bit, async_park) ); + TEST_ASSERT_EQUAL( 11 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_cmd_bit, async_park_enable) ); + TEST_ASSERT_EQUAL( 15 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_cmd_bit, nxp_framelist_size_msb) ); + TEST_ASSERT_EQUAL( 16 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_cmd_bit, int_threshold) ); +} + +void test_register_usbsts(void) +{ + TEST_ASSERT_EQUAL( 0 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_sts_bit, usb)); + TEST_ASSERT_EQUAL( 1 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_sts_bit, usb_error)); + TEST_ASSERT_EQUAL( 2 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_sts_bit, port_change_detect)); + TEST_ASSERT_EQUAL( 3 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_sts_bit, framelist_rollover)); + TEST_ASSERT_EQUAL( 4 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_sts_bit, pci_host_system_error)); + TEST_ASSERT_EQUAL( 5 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_sts_bit, async_advance)); + TEST_ASSERT_EQUAL( 7 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_sts_bit, nxp_int_sof)); + TEST_ASSERT_EQUAL( 12 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_sts_bit, hc_halted)); + TEST_ASSERT_EQUAL( 13 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_sts_bit, reclamation)); + TEST_ASSERT_EQUAL( 14 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_sts_bit, period_schedule_status)); + TEST_ASSERT_EQUAL( 15 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_sts_bit, async_schedule_status)); + TEST_ASSERT_EQUAL( 18 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_sts_bit, nxp_int_async)); + TEST_ASSERT_EQUAL( 19 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_sts_bit, nxp_int_period)); +} + +void test_register_usbint(void) +{ + TEST_ASSERT_EQUAL( 0 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_int_enable_bit, usb)); + TEST_ASSERT_EQUAL( 1 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_int_enable_bit, usb_error)); + TEST_ASSERT_EQUAL( 2 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_int_enable_bit, port_change_detect)); + TEST_ASSERT_EQUAL( 3 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_int_enable_bit, framelist_rollover)); + TEST_ASSERT_EQUAL( 4 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_int_enable_bit, pci_host_system_error)); + TEST_ASSERT_EQUAL( 5 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_int_enable_bit, async_advance)); + TEST_ASSERT_EQUAL( 7 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_int_enable_bit, nxp_int_sof)); + TEST_ASSERT_EQUAL( 18 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_int_enable_bit, nxp_int_async)); + TEST_ASSERT_EQUAL( 19 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_int_enable_bit, nxp_int_period)); + +} + +void test_register_portsc(void) +{ + TEST_ASSERT_EQUAL( 0 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, portsc_bit, current_connect_status)); + TEST_ASSERT_EQUAL( 1 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, portsc_bit, connect_status_change)); + TEST_ASSERT_EQUAL( 2 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, portsc_bit, port_enable)); + TEST_ASSERT_EQUAL( 3 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, portsc_bit, port_enable_change)); + TEST_ASSERT_EQUAL( 4 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, portsc_bit, over_current_active)); + TEST_ASSERT_EQUAL( 5 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, portsc_bit, over_current_change)); + TEST_ASSERT_EQUAL( 6 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, portsc_bit, force_port_resume)); + TEST_ASSERT_EQUAL( 7 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, portsc_bit, suspend)); + TEST_ASSERT_EQUAL( 8 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, portsc_bit, port_reset)); + TEST_ASSERT_EQUAL( 9 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, portsc_bit, nxp_highspeed_status)); + TEST_ASSERT_EQUAL( 10 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, portsc_bit, line_status)); + TEST_ASSERT_EQUAL( 12 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, portsc_bit, port_power)); + TEST_ASSERT_EQUAL( 13 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, portsc_bit, port_owner)); + TEST_ASSERT_EQUAL( 14 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, portsc_bit, port_indicator_control)); + TEST_ASSERT_EQUAL( 16 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, portsc_bit, port_test_control)); + TEST_ASSERT_EQUAL( 20 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, portsc_bit, wake_on_connect_enable)); + TEST_ASSERT_EQUAL( 21 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, portsc_bit, wake_on_disconnect_enable)); + TEST_ASSERT_EQUAL( 22 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, portsc_bit, wake_on_over_current_enable)); + TEST_ASSERT_EQUAL( 23 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, portsc_bit, nxp_phy_clock_disable)); + TEST_ASSERT_EQUAL( 24 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, portsc_bit, nxp_port_force_fullspeed)); + TEST_ASSERT_EQUAL( 26 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, portsc_bit, nxp_port_speed)); +} + +//--------------------------------------------------------------------+ +// EHCI Data Organization +//--------------------------------------------------------------------+ +void test_ehci_data(void) +{ + for(uint32_t i=0; i +#include "unity.h" +#include "tusb_option.h" +#include "errors.h" +#include "binary.h" +#include "type_helper.h" + +#include "hal.h" +#include "mock_osal.h" +#include "mock_hid_host.h" + +#include "hcd.h" +#include "usbh_hcd.h" +#include "usbh.h" +#include "ehci.h" +#include "ehci_controller_fake.h" +#include "host_helper.h" + +static uint8_t const control_max_packet_size = 64; +static uint8_t hub_addr; +static uint8_t hub_port; +static uint8_t dev_addr; +static uint8_t hostid; + +static ehci_registers_t * regs; +static ehci_qhd_t *async_head; +static ehci_qhd_t *period_head_arr; + + + +void setUp(void) +{ + hub_addr = hub_port = 0; + dev_addr = 1; + hostid = RANDOM(CONTROLLER_HOST_NUMBER) + TEST_CONTROLLER_HOST_START_INDEX; + + ehci_controller_init(); + + helper_usbh_init_expect(); + helper_class_init_expect(); + usbh_init(); + + helper_usbh_device_emulate(dev_addr, hub_addr, hub_port, hostid, TUSB_SPEED_HIGH); + + regs = get_operational_register(hostid); + async_head = get_async_head( hostid ); + period_head_arr = (ehci_qhd_t*) get_period_head( hostid, 1 ); + regs->usb_sts = 0; // hcd_init clear usb_sts by writing 1s +} + +void tearDown(void) +{ +} + +void test_addr0_control_close(void) +{ + dev_addr = 0; + helper_usbh_device_emulate(0, hub_addr, hub_port, hostid, TUSB_SPEED_HIGH); + + TEST_ASSERT_STATUS( hcd_pipe_control_open(dev_addr, control_max_packet_size) ); + + TEST_ASSERT_STATUS( hcd_pipe_control_xfer(dev_addr, + &(tusb_std_request_t) { + .bmRequestType = { .direction = TUSB_DIR_HOST_TO_DEV, .type = TUSB_REQUEST_TYPE_STANDARD, .recipient = TUSB_REQUEST_RECIPIENT_DEVICE }, + .bRequest = TUSB_REQUEST_SET_ADDRESS, + .wValue = 3 }, + NULL) ) ; + + ehci_qhd_t *p_qhd = async_head; + TEST_ASSERT_STATUS( hcd_pipe_control_close(dev_addr) ); + + //------------- Code Under Test -------------// + regs->usb_sts_bit.port_change_detect = 0; // clear port change detect + regs->usb_sts_bit.async_advance = 1; + hcd_isr(hostid); // async advance + + TEST_ASSERT( p_qhd->qtd_overlay.halted ); + TEST_ASSERT_FALSE( p_qhd->is_removing ); + TEST_ASSERT_NULL( p_qhd->p_qtd_list_head ); + TEST_ASSERT_NULL( p_qhd->p_qtd_list_tail ); +} + +void test_isr_disconnect_then_async_advance_control_pipe(void) +{ + TEST_ASSERT_STATUS( hcd_pipe_control_open(dev_addr, control_max_packet_size) ); + + TEST_ASSERT_STATUS( hcd_pipe_control_xfer(dev_addr, + &(tusb_std_request_t) { + .bmRequestType = { .direction = TUSB_DIR_HOST_TO_DEV, .type = TUSB_REQUEST_TYPE_STANDARD, .recipient = TUSB_REQUEST_RECIPIENT_DEVICE }, + .bRequest = TUSB_REQUEST_SET_ADDRESS, + .wValue = 3 }, + NULL) ); + + ehci_qhd_t *p_qhd = get_control_qhd(dev_addr); + ehci_qtd_t *p_qtd_head = p_qhd->p_qtd_list_head; + ehci_qtd_t *p_qtd_tail = p_qhd->p_qtd_list_tail; + + ehci_controller_device_unplug(hostid); + + //------------- Code Under Test -------------// + hcd_isr(hostid); // port change detect + regs->usb_sts_bit.port_change_detect = 0; // clear port change detect + regs->usb_sts_bit.async_advance = 1; + hcd_isr(hostid); // async advance + + TEST_ASSERT_FALSE(p_qhd->used); + TEST_ASSERT_FALSE(p_qhd->is_removing); +// TEST_ASSERT_NULL(p_qhd->p_qtd_list_head); +// TEST_ASSERT_NULL(p_qhd->p_qtd_list_tail); +} + +void test_bulk_pipe_close(void) +{ + tusb_descriptor_endpoint_t const desc_ept_bulk_in = + { + .bLength = sizeof(tusb_descriptor_endpoint_t), + .bDescriptorType = TUSB_DESC_TYPE_ENDPOINT, + .bEndpointAddress = 0x81, + .bmAttributes = { .xfer = TUSB_XFER_BULK }, + .wMaxPacketSize = 512, + .bInterval = 0 + }; + + uint8_t xfer_data[100]; + pipe_handle_t pipe_hdl = hcd_pipe_open(dev_addr, &desc_ept_bulk_in, TUSB_CLASS_MSC); + + TEST_ASSERT_STATUS( hcd_pipe_xfer(pipe_hdl, xfer_data, sizeof(xfer_data), 100) ); + TEST_ASSERT_STATUS( hcd_pipe_xfer(pipe_hdl, xfer_data, sizeof(xfer_data), 50) ); + + ehci_qhd_t *p_qhd = &ehci_data.device[dev_addr-1].qhd[pipe_hdl.index]; + ehci_qtd_t *p_qtd_head = p_qhd->p_qtd_list_head; + ehci_qtd_t *p_qtd_tail = p_qhd->p_qtd_list_tail; + + TEST_ASSERT_STATUS( hcd_pipe_close(pipe_hdl) ); + + //------------- Code Under Test -------------// + regs->usb_sts_bit.async_advance = 1; + get_control_qhd(dev_addr)->is_removing = 1; // mimic unmount + hcd_isr(hostid); // async advance + + TEST_ASSERT_FALSE(p_qhd->used); + TEST_ASSERT_FALSE(p_qhd->is_removing); +// TEST_ASSERT_NULL(p_qhd->p_qtd_list_head); +// TEST_ASSERT_NULL(p_qhd->p_qtd_list_tail); + TEST_ASSERT_FALSE(p_qtd_head->used); + TEST_ASSERT_FALSE(p_qtd_tail->used); +} + +void test_device_unplugged_status(void) +{ + ehci_controller_device_unplug(hostid); + hcd_isr(hostid); + TEST_ASSERT_EQUAL(TUSB_DEVICE_STATE_REMOVING, usbh_devices[dev_addr].state); + + regs->usb_sts_bit.async_advance = 1; + hcd_isr(hostid); // async advance + + TEST_ASSERT_EQUAL(TUSB_DEVICE_STATE_UNPLUG, usbh_devices[dev_addr].state); +} diff --git a/tests/lpc18xx_43xx/test/host/ehci/test_pipe_bulk_open.c b/tests/lpc18xx_43xx/test/host/ehci/test_pipe_bulk_open.c new file mode 100644 index 000000000..4ddc519aa --- /dev/null +++ b/tests/lpc18xx_43xx/test/host/ehci/test_pipe_bulk_open.c @@ -0,0 +1,178 @@ +/**************************************************************************/ +/*! + @file test_pipe_bulk_open.c + @author hathach (tinyusb.org) + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2013, hathach (tinyusb.org) + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + This file is part of the tinyusb stack. +*/ +/**************************************************************************/ + +#include +#include "unity.h" +#include "tusb_option.h" +#include "errors.h" +#include "binary.h" +#include "type_helper.h" + +#include "hal.h" +#include "mock_osal.h" +#include "hcd.h" +#include "mock_usbh_hcd.h" +#include "ehci.h" +#include "ehci_controller_fake.h" +#include "host_helper.h" + +usbh_device_info_t usbh_devices[TUSB_CFG_HOST_DEVICE_MAX+1]; + +static uint8_t const hub_addr = 2; +static uint8_t const hub_port = 2; +static uint8_t dev_addr; +static uint8_t hostid; + +static ehci_qhd_t *async_head; + +//--------------------------------------------------------------------+ +// Setup/Teardown + helper declare +//--------------------------------------------------------------------+ +void setUp(void) +{ + TEST_ASSERT_STATUS( hcd_init() ); + + dev_addr = 1; + hostid = RANDOM(CONTROLLER_HOST_NUMBER) + TEST_CONTROLLER_HOST_START_INDEX; + + memclr_(usbh_devices, sizeof(usbh_device_info_t)*(TUSB_CFG_HOST_DEVICE_MAX+1)); + helper_usbh_device_emulate(dev_addr, hub_addr, hub_port, hostid, TUSB_SPEED_HIGH); + + async_head = get_async_head( hostid ); +} + +void tearDown(void) +{ +} + +void verify_open_qhd(ehci_qhd_t *p_qhd, uint8_t endpoint_addr, uint16_t max_packet_size) +{ + TEST_ASSERT_EQUAL(dev_addr, p_qhd->device_address); + TEST_ASSERT_FALSE(p_qhd->non_hs_period_inactive_next_xact); + TEST_ASSERT_EQUAL(endpoint_addr & 0x0F, p_qhd->endpoint_number); + TEST_ASSERT_EQUAL(usbh_devices[dev_addr].speed, p_qhd->endpoint_speed); + TEST_ASSERT_EQUAL(max_packet_size, p_qhd->max_package_size); + TEST_ASSERT_EQUAL(0, p_qhd->nak_count_reload); // TDD NAK Reload disable + + TEST_ASSERT_EQUAL(hub_addr, p_qhd->hub_address); + TEST_ASSERT_EQUAL(hub_port, p_qhd->hub_port); + TEST_ASSERT_EQUAL(1, p_qhd->mult); // TDD operation model for mult + + TEST_ASSERT_FALSE(p_qhd->qtd_overlay.halted); + TEST_ASSERT(p_qhd->qtd_overlay.next.terminate); + TEST_ASSERT(p_qhd->qtd_overlay.alternate.terminate); + + //------------- HCD -------------// + TEST_ASSERT(p_qhd->used); + TEST_ASSERT_FALSE(p_qhd->is_removing); + TEST_ASSERT_NULL(p_qhd->p_qtd_list_head); + TEST_ASSERT_NULL(p_qhd->p_qtd_list_tail); +} + +//--------------------------------------------------------------------+ +// PIPE OPEN +//--------------------------------------------------------------------+ +tusb_descriptor_endpoint_t const desc_ept_bulk_in = +{ + .bLength = sizeof(tusb_descriptor_endpoint_t), + .bDescriptorType = TUSB_DESC_TYPE_ENDPOINT, + .bEndpointAddress = 0x81, + .bmAttributes = { .xfer = TUSB_XFER_BULK }, + .wMaxPacketSize = 512, + .bInterval = 0 +}; + +void verify_bulk_open_qhd(ehci_qhd_t *p_qhd, tusb_descriptor_endpoint_t const * desc_endpoint, uint8_t class_code) +{ + verify_open_qhd(p_qhd, desc_endpoint->bEndpointAddress, desc_endpoint->wMaxPacketSize.size); + + TEST_ASSERT_FALSE(p_qhd->head_list_flag); + TEST_ASSERT_EQUAL(0, p_qhd->data_toggle_control); + TEST_ASSERT_EQUAL(0, p_qhd->interrupt_smask); + TEST_ASSERT_EQUAL(0, p_qhd->non_hs_interrupt_cmask); + TEST_ASSERT_FALSE(p_qhd->non_hs_control_endpoint); + + // TEST_ASSERT_EQUAL(desc_endpoint->bInterval); TDD highspeed bulk/control OUT + + TEST_ASSERT_EQUAL(desc_endpoint->bEndpointAddress & 0x80 ? EHCI_PID_IN : EHCI_PID_OUT, p_qhd->pid_non_control); + + TEST_ASSERT_EQUAL(class_code, p_qhd->class_code); + //------------- async list check -------------// + TEST_ASSERT_EQUAL_HEX((uint32_t) p_qhd, align32(async_head->next.address)); + TEST_ASSERT_FALSE(async_head->next.terminate); + TEST_ASSERT_EQUAL(EHCI_QUEUE_ELEMENT_QHD, async_head->next.type); +} + +void test_open_bulk_qhd_data(void) +{ + ehci_qhd_t *p_qhd; + pipe_handle_t pipe_hdl; + tusb_descriptor_endpoint_t const * desc_endpoint = &desc_ept_bulk_in; + + //------------- Code Under TEST -------------// + pipe_hdl = hcd_pipe_open(dev_addr, desc_endpoint, TUSB_CLASS_MSC); + + TEST_ASSERT_EQUAL(dev_addr, pipe_hdl.dev_addr); + TEST_ASSERT_EQUAL(TUSB_XFER_BULK, pipe_hdl.xfer_type); + + p_qhd = &ehci_data.device[ pipe_hdl.dev_addr-1 ].qhd[ pipe_hdl.index ]; + verify_bulk_open_qhd(p_qhd, desc_endpoint, TUSB_CLASS_MSC); + + //------------- async list check -------------// + TEST_ASSERT_EQUAL_HEX((uint32_t) p_qhd, align32(async_head->next.address)); + TEST_ASSERT_FALSE(async_head->next.terminate); + TEST_ASSERT_EQUAL(EHCI_QUEUE_ELEMENT_QHD, async_head->next.type); +} + +//--------------------------------------------------------------------+ +// PIPE CLOSE +//--------------------------------------------------------------------+ +void test_bulk_close(void) +{ + tusb_descriptor_endpoint_t const * desc_endpoint = &desc_ept_bulk_in; + pipe_handle_t pipe_hdl = hcd_pipe_open(dev_addr, desc_endpoint, TUSB_CLASS_MSC); + ehci_qhd_t *p_qhd = &ehci_data.device[ pipe_hdl.dev_addr-1].qhd[ pipe_hdl.index ]; + + //------------- Code Under TEST -------------// + hcd_pipe_close(pipe_hdl); + + TEST_ASSERT(p_qhd->is_removing); + TEST_ASSERT( align32(async_head->next.address) != (uint32_t) p_qhd ); + TEST_ASSERT_EQUAL_HEX( (uint32_t) async_head, align32(p_qhd->next.address) ); + TEST_ASSERT_EQUAL(EHCI_QUEUE_ELEMENT_QHD, p_qhd->next.type); +} diff --git a/tests/lpc18xx_43xx/test/host/ehci/test_pipe_bulk_xfer.c b/tests/lpc18xx_43xx/test/host/ehci/test_pipe_bulk_xfer.c new file mode 100644 index 000000000..ccf30d724 --- /dev/null +++ b/tests/lpc18xx_43xx/test/host/ehci/test_pipe_bulk_xfer.c @@ -0,0 +1,221 @@ +/**************************************************************************/ +/*! + @file test_ehci_pipe_bulk_xfer.c + @author hathach (tinyusb.org) + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2013, hathach (tinyusb.org) + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + This file is part of the tinyusb stack. +*/ +/**************************************************************************/ + +#include +#include "unity.h" +#include "tusb_option.h" +#include "errors.h" +#include "binary.h" +#include "type_helper.h" + +#include "hal.h" +#include "mock_osal.h" +#include "hcd.h" +#include "mock_usbh_hcd.h" +#include "ehci.h" +#include "ehci_controller_fake.h" +#include "host_helper.h" + +usbh_device_info_t usbh_devices[TUSB_CFG_HOST_DEVICE_MAX+1]; + +static uint8_t hub_addr = 2; +static uint8_t hub_port = 2; +static uint8_t dev_addr; +static uint8_t hostid; +static uint8_t xfer_data [18000]; // 18K to test buffer pointer list +static uint8_t data2[100]; + +static ehci_qhd_t *async_head; +static ehci_qhd_t *p_qhd_bulk; +static pipe_handle_t pipe_hdl_bulk; + +tusb_descriptor_endpoint_t const desc_ept_bulk_in = +{ + .bLength = sizeof(tusb_descriptor_endpoint_t), + .bDescriptorType = TUSB_DESC_TYPE_ENDPOINT, + .bEndpointAddress = 0x81, + .bmAttributes = { .xfer = TUSB_XFER_BULK }, + .wMaxPacketSize = 512, + .bInterval = 0 +}; + +tusb_descriptor_endpoint_t const desc_ept_bulk_out = +{ + .bLength = sizeof(tusb_descriptor_endpoint_t), + .bDescriptorType = TUSB_DESC_TYPE_ENDPOINT, + .bEndpointAddress = 0x01, + .bmAttributes = { .xfer = TUSB_XFER_BULK }, + .wMaxPacketSize = 512, + .bInterval = 0 +}; + +//--------------------------------------------------------------------+ +// Setup/Teardown + helper declare +//--------------------------------------------------------------------+ +void setUp(void) +{ + ehci_controller_init(); + memclr_(xfer_data, sizeof(xfer_data)); + memclr_(usbh_devices, sizeof(usbh_device_info_t)*(TUSB_CFG_HOST_DEVICE_MAX+1)); + + TEST_ASSERT_STATUS( hcd_init() ); + + dev_addr = 1; + hostid = RANDOM(CONTROLLER_HOST_NUMBER) + TEST_CONTROLLER_HOST_START_INDEX; + helper_usbh_device_emulate(dev_addr, hub_addr, hub_port, hostid, TUSB_SPEED_HIGH); + + async_head = get_async_head( hostid ); + + //------------- pipe open -------------// + pipe_hdl_bulk = hcd_pipe_open(dev_addr, &desc_ept_bulk_in, TUSB_CLASS_MSC); + + TEST_ASSERT_EQUAL(dev_addr, pipe_hdl_bulk.dev_addr); + TEST_ASSERT_EQUAL(TUSB_XFER_BULK, pipe_hdl_bulk.xfer_type); + + p_qhd_bulk = &ehci_data.device[ dev_addr -1].qhd[ pipe_hdl_bulk.index ]; +} + +void tearDown(void) +{ +} +//--------------------------------------------------------------------+ +// BULK TRANSFER +//--------------------------------------------------------------------+ +void verify_qtd(ehci_qtd_t *p_qtd, uint8_t p_data[], uint16_t length) +{ + TEST_ASSERT_TRUE(p_qtd->alternate.terminate); // not used, always invalid + + //------------- status -------------// + TEST_ASSERT_FALSE(p_qtd->pingstate_err); + TEST_ASSERT_FALSE(p_qtd->non_hs_split_state); + TEST_ASSERT_FALSE(p_qtd->non_hs_period_missed_uframe); + TEST_ASSERT_FALSE(p_qtd->xact_err); + TEST_ASSERT_FALSE(p_qtd->babble_err); + TEST_ASSERT_FALSE(p_qtd->buffer_err); + TEST_ASSERT_FALSE(p_qtd->halted); + TEST_ASSERT_TRUE(p_qtd->active); + + TEST_ASSERT_FALSE(p_qtd->data_toggle); + TEST_ASSERT_EQUAL(3, p_qtd->cerr); + TEST_ASSERT_EQUAL(0, p_qtd->current_page); + TEST_ASSERT_EQUAL(length, p_qtd->total_bytes); + TEST_ASSERT_TRUE(p_qtd->used); + + TEST_ASSERT_EQUAL_HEX( p_data, p_qtd->buffer[0] ); + for(uint8_t i=1; i<5; i++) + { + TEST_ASSERT_EQUAL_HEX( align4k((uint32_t) (p_data+4096*i)), align4k(p_qtd->buffer[i]) ); + } +} + +void test_bulk_xfer_hs_ping_out(void) +{ + usbh_devices[dev_addr].speed = TUSB_SPEED_HIGH; + + pipe_handle_t pipe_hdl = hcd_pipe_open(dev_addr, &desc_ept_bulk_out, TUSB_CLASS_MSC); + ehci_qhd_t *p_qhd = qhd_get_from_pipe_handle(pipe_hdl); + + //------------- Code Under Test -------------// + TEST_ASSERT_STATUS( hcd_pipe_xfer(pipe_hdl, xfer_data, sizeof(xfer_data), true) ); + + ehci_qtd_t* p_qtd = p_qhd->p_qtd_list_head; + TEST_ASSERT(p_qtd->pingstate_err); +} + +void test_bulk_xfer(void) +{ + //------------- Code Under Test -------------// + TEST_ASSERT_STATUS( hcd_pipe_xfer(pipe_hdl_bulk, xfer_data, sizeof(xfer_data), true) ); + + ehci_qtd_t* p_qtd = p_qhd_bulk->p_qtd_list_head; + TEST_ASSERT_NOT_NULL(p_qtd); + + verify_qtd( p_qtd, xfer_data, sizeof(xfer_data)); + TEST_ASSERT_EQUAL_HEX(p_qhd_bulk->qtd_overlay.next.address, p_qtd); + TEST_ASSERT_TRUE(p_qtd->next.terminate); + TEST_ASSERT_EQUAL(EHCI_PID_IN, p_qtd->pid); + TEST_ASSERT_TRUE(p_qtd->int_on_complete); +} + +void test_bulk_xfer_double(void) +{ + //------------- Code Under Test -------------// + TEST_ASSERT_STATUS( hcd_pipe_xfer(pipe_hdl_bulk, xfer_data, sizeof(xfer_data), false) ); + + TEST_ASSERT_STATUS( hcd_pipe_xfer(pipe_hdl_bulk, data2, sizeof(data2), true) ); + + ehci_qtd_t* p_head = p_qhd_bulk->p_qtd_list_head; + ehci_qtd_t* p_tail = p_qhd_bulk->p_qtd_list_tail; + + //------------- list head -------------// + TEST_ASSERT_NOT_NULL(p_head); + verify_qtd(p_head, xfer_data, sizeof(xfer_data)); + TEST_ASSERT_EQUAL_HEX(p_qhd_bulk->qtd_overlay.next.address, p_head); + TEST_ASSERT_EQUAL(EHCI_PID_IN, p_head->pid); + TEST_ASSERT_FALSE(p_head->next.terminate); + TEST_ASSERT_FALSE(p_head->int_on_complete); + + //------------- list tail -------------// + TEST_ASSERT_NOT_NULL(p_tail); + verify_qtd(p_tail, data2, sizeof(data2)); + TEST_ASSERT_EQUAL_HEX( align32(p_head->next.address), p_tail); + TEST_ASSERT_EQUAL(EHCI_PID_IN, p_tail->pid); + TEST_ASSERT_TRUE(p_tail->next.terminate); + TEST_ASSERT_TRUE(p_tail->int_on_complete); +} + +void test_bulk_xfer_complete_isr(void) +{ + TEST_ASSERT_STATUS( hcd_pipe_xfer(pipe_hdl_bulk, xfer_data, sizeof(xfer_data), false) ); + + TEST_ASSERT_STATUS( hcd_pipe_xfer(pipe_hdl_bulk, data2, sizeof(data2), true) ); + + ehci_qtd_t* p_head = p_qhd_bulk->p_qtd_list_head; + ehci_qtd_t* p_tail = p_qhd_bulk->p_qtd_list_tail; + + usbh_isr_Expect(pipe_hdl_bulk, TUSB_CLASS_MSC, TUSB_EVENT_XFER_COMPLETE); + + //------------- Code Under Test -------------// + ehci_controller_run(hostid); + + TEST_ASSERT_TRUE(p_qhd_bulk->qtd_overlay.next.terminate); + TEST_ASSERT_FALSE(p_head->used); + TEST_ASSERT_FALSE(p_tail->used); + TEST_ASSERT_NULL(p_qhd_bulk->p_qtd_list_head); + TEST_ASSERT_NULL(p_qhd_bulk->p_qtd_list_tail); +} diff --git a/tests/lpc18xx_43xx/test/host/ehci/test_pipe_control_open.c b/tests/lpc18xx_43xx/test/host/ehci/test_pipe_control_open.c new file mode 100644 index 000000000..7cfdec4bb --- /dev/null +++ b/tests/lpc18xx_43xx/test/host/ehci/test_pipe_control_open.c @@ -0,0 +1,196 @@ +/**************************************************************************/ +/*! + @file test_ehci_pipe.c + @author hathach (tinyusb.org) + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2013, hathach (tinyusb.org) + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + This file is part of the tinyusb stack. +*/ +/**************************************************************************/ + +#include +#include "unity.h" +#include "tusb_option.h" +#include "errors.h" +#include "binary.h" +#include "type_helper.h" + +#include "hal.h" +#include "mock_osal.h" +#include "hcd.h" +#include "mock_usbh_hcd.h" +#include "ehci.h" +#include "ehci_controller_fake.h" +#include "host_helper.h" + +usbh_device_info_t usbh_devices[TUSB_CFG_HOST_DEVICE_MAX+1]; + +static uint8_t const control_max_packet_size = 64; +static uint8_t const hub_addr = 2; +static uint8_t const hub_port = 2; +static uint8_t dev_addr; +static uint8_t hostid; + +static ehci_qhd_t *async_head; +static ehci_qhd_t *p_control_qhd; + +//--------------------------------------------------------------------+ +// Setup/Teardown + helper declare +//--------------------------------------------------------------------+ +void setUp(void) +{ + memclr_(usbh_devices, sizeof(usbh_device_info_t)*(TUSB_CFG_HOST_DEVICE_MAX+1)); + + TEST_ASSERT_STATUS( hcd_init() ); + + dev_addr = 1; + hostid = RANDOM(CONTROLLER_HOST_NUMBER) + TEST_CONTROLLER_HOST_START_INDEX; + + helper_usbh_device_emulate(0, hub_addr, hub_port, hostid, TUSB_SPEED_HIGH); + helper_usbh_device_emulate(dev_addr, hub_addr, hub_port, hostid, TUSB_SPEED_HIGH); + + async_head = get_async_head( hostid ); + p_control_qhd = &ehci_data.device[dev_addr-1].control.qhd; +} + +void tearDown(void) +{ +} + +void verify_open_qhd(ehci_qhd_t *p_qhd, uint8_t endpoint_addr, uint16_t max_packet_size) +{ + TEST_ASSERT_EQUAL(dev_addr, p_qhd->device_address); + TEST_ASSERT_FALSE(p_qhd->non_hs_period_inactive_next_xact); + TEST_ASSERT_EQUAL(endpoint_addr & 0x0F, p_qhd->endpoint_number); + TEST_ASSERT_EQUAL(usbh_devices[dev_addr].speed, p_qhd->endpoint_speed); + TEST_ASSERT_EQUAL(max_packet_size, p_qhd->max_package_size); + TEST_ASSERT_EQUAL(0, p_qhd->nak_count_reload); // TDD NAK Reload disable + + TEST_ASSERT_EQUAL(hub_addr, p_qhd->hub_address); + TEST_ASSERT_EQUAL(hub_port, p_qhd->hub_port); + TEST_ASSERT_EQUAL(1, p_qhd->mult); // TDD operation model for mult + + TEST_ASSERT_FALSE(p_qhd->qtd_overlay.halted); + TEST_ASSERT(p_qhd->qtd_overlay.next.terminate); + TEST_ASSERT(p_qhd->qtd_overlay.alternate.terminate); + + //------------- HCD -------------// + TEST_ASSERT(p_qhd->used); + TEST_ASSERT_FALSE(p_qhd->is_removing); + TEST_ASSERT_NULL(p_qhd->p_qtd_list_head); + TEST_ASSERT_NULL(p_qhd->p_qtd_list_tail); +} + +void verify_control_open_qhd(ehci_qhd_t *p_qhd) +{ + verify_open_qhd(p_qhd, 0, control_max_packet_size); + + TEST_ASSERT_EQUAL(0, p_qhd->class_code); + TEST_ASSERT_EQUAL(1, p_qhd->data_toggle_control); + TEST_ASSERT_EQUAL(0, p_qhd->interrupt_smask); + TEST_ASSERT_EQUAL(0, p_qhd->non_hs_interrupt_cmask); +} + +//--------------------------------------------------------------------+ +// PIPE OPEN +//--------------------------------------------------------------------+ +void test_control_open_addr0_qhd_data(void) +{ + dev_addr = 0; + + //------------- Code Under Test -------------// + TEST_ASSERT_STATUS( hcd_pipe_control_open(dev_addr, control_max_packet_size) ); + + verify_control_open_qhd(async_head); + TEST_ASSERT(async_head->head_list_flag); +} + +void test_control_open_qhd_data(void) +{ + //------------- Code Under TEST -------------// + TEST_ASSERT_STATUS( hcd_pipe_control_open(dev_addr, control_max_packet_size)); + + verify_control_open_qhd(p_control_qhd); + TEST_ASSERT_FALSE(p_control_qhd->head_list_flag); + + //------------- async list check -------------// + TEST_ASSERT_EQUAL_HEX((uint32_t) p_control_qhd, align32(async_head->next.address)); + TEST_ASSERT_FALSE(async_head->next.terminate); + TEST_ASSERT_EQUAL(EHCI_QUEUE_ELEMENT_QHD, async_head->next.type); +} + +void test_control_open_highspeed(void) +{ + usbh_devices[dev_addr].speed = TUSB_SPEED_HIGH; + + //------------- Code Under TEST -------------// + TEST_ASSERT_STATUS( hcd_pipe_control_open(dev_addr, control_max_packet_size) ); + TEST_ASSERT_FALSE(p_control_qhd->non_hs_control_endpoint); +} + +void test_control_open_non_highspeed(void) +{ + usbh_devices[dev_addr].speed = TUSB_SPEED_FULL; + + //------------- Code Under TEST -------------// + TEST_ASSERT_STATUS( hcd_pipe_control_open(dev_addr, control_max_packet_size) ); + + TEST_ASSERT_TRUE(p_control_qhd->non_hs_control_endpoint); +} + +//--------------------------------------------------------------------+ +// PIPE CLOSE +//--------------------------------------------------------------------+ +void test_control_addr0_close(void) +{ + dev_addr = 0; + TEST_ASSERT_STATUS( hcd_pipe_control_open(dev_addr, control_max_packet_size) ); + + //------------- Code Under Test -------------// + TEST_ASSERT_STATUS( hcd_pipe_control_close(dev_addr) ); + + TEST_ASSERT(async_head->head_list_flag); + TEST_ASSERT(async_head->is_removing); +} + +void test_control_close(void) +{ + TEST_ASSERT_STATUS( hcd_pipe_control_open(dev_addr, control_max_packet_size) ); + + //------------- Code Under TEST -------------// + TEST_ASSERT_STATUS( hcd_pipe_control_close(dev_addr) ); + + TEST_ASSERT(p_control_qhd->is_removing); + TEST_ASSERT(p_control_qhd->used); + + TEST_ASSERT( align32(get_async_head(hostid)->next.address) != (uint32_t) p_control_qhd ); + TEST_ASSERT_EQUAL( get_async_head(hostid), align32(p_control_qhd->next.address)); +} diff --git a/tests/lpc18xx_43xx/test/host/ehci/test_pipe_control_xfer.c b/tests/lpc18xx_43xx/test/host/ehci/test_pipe_control_xfer.c new file mode 100644 index 000000000..266cf0ef2 --- /dev/null +++ b/tests/lpc18xx_43xx/test/host/ehci/test_pipe_control_xfer.c @@ -0,0 +1,252 @@ +/**************************************************************************/ +/*! + @file test_ehci_pipe_xfer.c + @author hathach (tinyusb.org) + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2013, hathach (tinyusb.org) + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + This file is part of the tinyusb stack. +*/ +/**************************************************************************/ + +#include +#include "unity.h" +#include "tusb_option.h" +#include "errors.h" +#include "binary.h" +#include "type_helper.h" + +#include "hal.h" +#include "mock_osal.h" +#include "hcd.h" +#include "mock_usbh_hcd.h" +#include "ehci.h" +#include "ehci_controller_fake.h" +#include "host_helper.h" + +usbh_device_info_t usbh_devices[TUSB_CFG_HOST_DEVICE_MAX+1]; + +static uint8_t const control_max_packet_size = 64; +static uint8_t const hub_addr = 2; +static uint8_t const hub_port = 2; +static uint8_t dev_addr; +static uint8_t hostid; +static uint8_t xfer_data [100]; + +static ehci_qhd_t *async_head; +static ehci_qhd_t *p_control_qhd; + +static ehci_qtd_t *p_setup; +static ehci_qtd_t *p_data; +static ehci_qtd_t *p_status; + +//--------------------------------------------------------------------+ +// Setup/Teardown + helper declare +//--------------------------------------------------------------------+ +void setUp(void) +{ + ehci_controller_init(); + + memclr_(usbh_devices, sizeof(usbh_device_info_t)*(TUSB_CFG_HOST_DEVICE_MAX+1)); + memclr_(xfer_data, sizeof(xfer_data)); + + TEST_ASSERT_STATUS( hcd_init() ); + + dev_addr = 1; + hostid = RANDOM(CONTROLLER_HOST_NUMBER) + TEST_CONTROLLER_HOST_START_INDEX; + + helper_usbh_device_emulate(0 , hub_addr, hub_port, hostid, TUSB_SPEED_HIGH); + helper_usbh_device_emulate(dev_addr , hub_addr, hub_port, hostid, TUSB_SPEED_HIGH); + + async_head = get_async_head( hostid ); + + //------------- pipe open -------------// + TEST_ASSERT_STATUS( hcd_pipe_control_open(dev_addr, control_max_packet_size) ); + + p_control_qhd = &ehci_data.device[dev_addr-1].control.qhd; + + p_setup = &ehci_data.device[dev_addr-1].control.qtd[0]; + p_data = &ehci_data.device[dev_addr-1].control.qtd[1]; + p_status = &ehci_data.device[dev_addr-1].control.qtd[2]; +} + +void tearDown(void) +{ +} +//--------------------------------------------------------------------+ +// CONTROL TRANSFER +//--------------------------------------------------------------------+ +tusb_std_request_t request_get_dev_desc = +{ + .bmRequestType = { .direction = TUSB_DIR_DEV_TO_HOST, .type = TUSB_REQUEST_TYPE_STANDARD, .recipient = TUSB_REQUEST_RECIPIENT_DEVICE }, + .bRequest = TUSB_REQUEST_GET_DESCRIPTOR, + .wValue = (TUSB_DESC_TYPE_DEVICE << 8), + .wLength = 18 +}; + +tusb_std_request_t request_set_dev_addr = +{ + .bmRequestType = { .direction = TUSB_DIR_HOST_TO_DEV, .type = TUSB_REQUEST_TYPE_STANDARD, .recipient = TUSB_REQUEST_RECIPIENT_DEVICE }, + .bRequest = TUSB_REQUEST_SET_ADDRESS, + .wValue = 3 +}; + +void verify_qtd(ehci_qtd_t *p_qtd, uint8_t p_data[], uint16_t length) +{ + TEST_ASSERT_TRUE(p_qtd->alternate.terminate); // not used, always invalid + + TEST_ASSERT_FALSE(p_qtd->pingstate_err); + TEST_ASSERT_FALSE(p_qtd->non_hs_split_state); + TEST_ASSERT_FALSE(p_qtd->non_hs_period_missed_uframe); + TEST_ASSERT_FALSE(p_qtd->xact_err); + TEST_ASSERT_FALSE(p_qtd->babble_err); + TEST_ASSERT_FALSE(p_qtd->buffer_err); + TEST_ASSERT_FALSE(p_qtd->halted); + TEST_ASSERT_TRUE(p_qtd->active); + + TEST_ASSERT_EQUAL(3, p_qtd->cerr); + TEST_ASSERT_EQUAL(0, p_qtd->current_page); + TEST_ASSERT_EQUAL(length, p_qtd->total_bytes); + + TEST_ASSERT_EQUAL_HEX(p_data, p_qtd->buffer[0]); +} + +//--------------------------------------------------------------------+ +// Address 0 +//--------------------------------------------------------------------+ +void test_control_addr0_xfer_get_check_qhd_qtd_mapping(void) +{ + dev_addr = 0; + ehci_qhd_t * const p_qhd = async_head; + + TEST_ASSERT_STATUS( hcd_pipe_control_open(dev_addr, control_max_packet_size) ); + + //------------- Code Under TEST -------------// + TEST_ASSERT_STATUS( hcd_pipe_control_xfer(dev_addr, &request_get_dev_desc, xfer_data) ); + + p_setup = &ehci_data.addr0_qtd[0]; + p_data = &ehci_data.addr0_qtd[1]; + p_status = &ehci_data.addr0_qtd[2]; + + TEST_ASSERT_EQUAL_HEX( p_setup, p_qhd->qtd_overlay.next.address ); + TEST_ASSERT_EQUAL_HEX( p_setup , p_qhd->p_qtd_list_head); + TEST_ASSERT_EQUAL_HEX( p_data , p_setup->next.address); + TEST_ASSERT_EQUAL_HEX( p_status , p_data->next.address ); + TEST_ASSERT_TRUE( p_status->next.terminate ); + + verify_qtd(p_setup, (uint8_t*) &request_get_dev_desc, 8); +} + +//--------------------------------------------------------------------+ +// Normal Control +//--------------------------------------------------------------------+ +void test_control_xfer_get(void) +{ + //------------- Code Under TEST -------------// + TEST_ASSERT_STATUS( hcd_pipe_control_xfer(dev_addr, &request_get_dev_desc, xfer_data) ); + + TEST_ASSERT_EQUAL_HEX( p_setup, p_control_qhd->qtd_overlay.next.address ); + TEST_ASSERT_EQUAL_HEX( p_setup , p_control_qhd->p_qtd_list_head); + TEST_ASSERT_EQUAL_HEX( p_data , p_setup->next.address); + TEST_ASSERT_EQUAL_HEX( p_status , p_data->next.address ); + TEST_ASSERT_TRUE( p_status->next.terminate ); + + //------------- SETUP -------------// + verify_qtd(p_setup, (uint8_t*) &request_get_dev_desc, 8); + + TEST_ASSERT_FALSE(p_setup->int_on_complete); + TEST_ASSERT_FALSE(p_setup->data_toggle); + TEST_ASSERT_EQUAL(EHCI_PID_SETUP, p_setup->pid); + + //------------- DATA -------------// + verify_qtd(p_data, xfer_data, request_get_dev_desc.wLength); + TEST_ASSERT_FALSE(p_data->int_on_complete); + TEST_ASSERT_TRUE(p_data->data_toggle); + TEST_ASSERT_EQUAL(EHCI_PID_IN, p_data->pid); + + //------------- STATUS -------------// + verify_qtd(p_status, NULL, 0); + TEST_ASSERT_TRUE(p_status->int_on_complete); + TEST_ASSERT_TRUE(p_status->data_toggle); + TEST_ASSERT_EQUAL(EHCI_PID_OUT, p_status->pid); + TEST_ASSERT_TRUE(p_status->next.terminate); + + TEST_ASSERT_EQUAL_HEX(p_setup, p_control_qhd->p_qtd_list_head); + TEST_ASSERT_EQUAL_HEX(p_status, p_control_qhd->p_qtd_list_tail); +} + +void test_control_xfer_set(void) +{ + //------------- Code Under TEST -------------// + TEST_ASSERT_STATUS( hcd_pipe_control_xfer(dev_addr, &request_set_dev_addr, xfer_data) ); + + TEST_ASSERT_EQUAL_HEX( p_setup, p_control_qhd->qtd_overlay.next.address ); + TEST_ASSERT_EQUAL_HEX( p_setup , p_control_qhd->p_qtd_list_head); + TEST_ASSERT_EQUAL_HEX( p_status , p_setup->next.address ); + TEST_ASSERT_TRUE( p_status->next.terminate ); + + //------------- STATUS -------------// + verify_qtd(p_status, NULL, 0); + TEST_ASSERT_TRUE(p_status->int_on_complete); + TEST_ASSERT_TRUE(p_status->data_toggle); + TEST_ASSERT_EQUAL(EHCI_PID_IN, p_status->pid); + TEST_ASSERT_TRUE(p_status->next.terminate); + + TEST_ASSERT_EQUAL_HEX(p_setup, p_control_qhd->p_qtd_list_head); + TEST_ASSERT_EQUAL_HEX(p_status, p_control_qhd->p_qtd_list_tail); +} + +void test_control_xfer_complete_isr(void) +{ + TEST_ASSERT_STATUS( hcd_pipe_control_xfer(dev_addr, &request_get_dev_desc, xfer_data) ); + + usbh_isr_Expect(((pipe_handle_t){.dev_addr = dev_addr}), 0, TUSB_EVENT_XFER_COMPLETE); + + //------------- Code Under TEST -------------// + ehci_controller_run(hostid); + + TEST_ASSERT_NULL(p_control_qhd->p_qtd_list_head); + TEST_ASSERT_NULL(p_control_qhd->p_qtd_list_tail); + + TEST_ASSERT_FALSE(p_setup->used); + TEST_ASSERT_FALSE(p_data->used); + TEST_ASSERT_FALSE(p_status->used); + +} + +void test_control_xfer_error_isr(void) +{ + TEST_ASSERT_STATUS( hcd_pipe_control_xfer(dev_addr, &request_get_dev_desc, xfer_data) ); + + usbh_isr_Expect(((pipe_handle_t){.dev_addr = dev_addr}), 0, TUSB_EVENT_XFER_ERROR); + + //------------- Code Under TEST -------------// + ehci_controller_run_error(hostid); +} diff --git a/tests/lpc18xx_43xx/test/host/ehci/test_pipe_interrupt_open.c b/tests/lpc18xx_43xx/test/host/ehci/test_pipe_interrupt_open.c new file mode 100644 index 000000000..946d8f0c8 --- /dev/null +++ b/tests/lpc18xx_43xx/test/host/ehci/test_pipe_interrupt_open.c @@ -0,0 +1,342 @@ +/**************************************************************************/ +/*! + @file test_ehci_pipe.c + @author hathach (tinyusb.org) + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2013, hathach (tinyusb.org) + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + This file is part of the tinyusb stack. +*/ +/**************************************************************************/ + +#include "unity.h" +#include "tusb_option.h" +#include "errors.h" +#include "binary.h" +#include "type_helper.h" + +#include "hal.h" +#include "mock_osal.h" +#include "hcd.h" +#include "mock_usbh_hcd.h" +#include "ehci.h" +#include "ehci_controller_fake.h" +#include "host_helper.h" + +usbh_device_info_t usbh_devices[TUSB_CFG_HOST_DEVICE_MAX+1]; + +static uint8_t const hub_addr = 2; +static uint8_t const hub_port = 2; +static uint8_t dev_addr; +static uint8_t hostid; + +static ehci_qhd_t *period_head_arr; + +static ehci_qhd_t *p_int_qhd; +static pipe_handle_t pipe_hdl; + +//--------------------------------------------------------------------+ +// Setup/Teardown + helper declare +//--------------------------------------------------------------------+ +void setUp(void) +{ + memclr_(usbh_devices, sizeof(usbh_device_info_t)*(TUSB_CFG_HOST_DEVICE_MAX+1)); + + hcd_init(); + + dev_addr = 1; + hostid = RANDOM(CONTROLLER_HOST_NUMBER) + TEST_CONTROLLER_HOST_START_INDEX; + + helper_usbh_device_emulate(dev_addr , hub_addr, hub_port, hostid, TUSB_SPEED_HIGH); + + period_head_arr = get_period_head( hostid, 1 ); + p_int_qhd = NULL; + memclr_(&pipe_hdl, sizeof(pipe_handle_t)); +} + +void tearDown(void) +{ +} + +void verify_open_qhd(ehci_qhd_t *p_qhd, uint8_t endpoint_addr, uint16_t max_packet_size) +{ + TEST_ASSERT_EQUAL(dev_addr, p_qhd->device_address); + TEST_ASSERT_FALSE(p_qhd->non_hs_period_inactive_next_xact); + TEST_ASSERT_EQUAL(endpoint_addr & 0x0F, p_qhd->endpoint_number); + TEST_ASSERT_EQUAL(usbh_devices[dev_addr].speed, p_qhd->endpoint_speed); + TEST_ASSERT_EQUAL(max_packet_size, p_qhd->max_package_size); + TEST_ASSERT_EQUAL(0, p_qhd->nak_count_reload); // TDD NAK Reload disable + + TEST_ASSERT_EQUAL(hub_addr, p_qhd->hub_address); + TEST_ASSERT_EQUAL(hub_port, p_qhd->hub_port); + TEST_ASSERT_EQUAL(1, p_qhd->mult); // TDD operation model for mult + + TEST_ASSERT_FALSE(p_qhd->qtd_overlay.halted); + TEST_ASSERT(p_qhd->qtd_overlay.next.terminate); + TEST_ASSERT(p_qhd->qtd_overlay.alternate.terminate); + + //------------- HCD -------------// + TEST_ASSERT(p_qhd->used); + TEST_ASSERT_FALSE(p_qhd->is_removing); + TEST_ASSERT_NULL(p_qhd->p_qtd_list_head); + TEST_ASSERT_NULL(p_qhd->p_qtd_list_tail); +} + + +//--------------------------------------------------------------------+ +// PIPE OPEN +//--------------------------------------------------------------------+ +tusb_descriptor_endpoint_t const desc_ept_interrupt_out = +{ + .bLength = sizeof(tusb_descriptor_endpoint_t), + .bDescriptorType = TUSB_DESC_TYPE_ENDPOINT, + .bEndpointAddress = 0x02, + .bmAttributes = { .xfer = TUSB_XFER_INTERRUPT }, + .wMaxPacketSize = 16, + .bInterval = 4 +}; +void verify_int_qhd(ehci_qhd_t *p_qhd, tusb_descriptor_endpoint_t const * desc_endpoint, uint8_t class_code) +{ + verify_open_qhd(p_qhd, desc_endpoint->bEndpointAddress, desc_endpoint->wMaxPacketSize.size); + + TEST_ASSERT_FALSE(p_qhd->head_list_flag); + TEST_ASSERT_FALSE(p_qhd->data_toggle_control); + TEST_ASSERT_FALSE(p_qhd->non_hs_control_endpoint); + + TEST_ASSERT_EQUAL(desc_endpoint->bEndpointAddress & 0x80 ? EHCI_PID_IN : EHCI_PID_OUT, p_qhd->pid_non_control); +} + +void check_int_endpoint_link(ehci_qhd_t *p_prev, ehci_qhd_t *p_qhd) +{ + //------------- period list check -------------// + TEST_ASSERT_EQUAL_HEX((uint32_t) p_qhd, align32(p_prev->next.address)); + TEST_ASSERT_FALSE(p_prev->next.terminate); + TEST_ASSERT_EQUAL(EHCI_QUEUE_ELEMENT_QHD, p_prev->next.type); +} + +void test_open_interrupt_qhd_hs(void) +{ + //------------- Code Under TEST -------------// + pipe_hdl = hcd_pipe_open(dev_addr, &desc_ept_interrupt_out, TUSB_CLASS_HID); + + TEST_ASSERT_EQUAL(dev_addr, pipe_hdl.dev_addr); + TEST_ASSERT_EQUAL(TUSB_XFER_INTERRUPT, pipe_hdl.xfer_type); + + p_int_qhd = &ehci_data.device[ pipe_hdl.dev_addr-1].qhd[ pipe_hdl.index ]; + + verify_int_qhd(p_int_qhd, &desc_ept_interrupt_out, TUSB_CLASS_HID); + + TEST_ASSERT_EQUAL(0, p_int_qhd->non_hs_interrupt_cmask); +} + +void test_open_interrupt_hs_interval_1(void) +{ + tusb_descriptor_endpoint_t int_edp_interval = desc_ept_interrupt_out; + int_edp_interval.bInterval = 1; + + //------------- Code Under TEST -------------// + pipe_hdl = hcd_pipe_open(dev_addr, &int_edp_interval, TUSB_CLASS_HID); + p_int_qhd = &ehci_data.device[ pipe_hdl.dev_addr-1].qhd[ pipe_hdl.index ]; + + TEST_ASSERT_EQUAL(0 , p_int_qhd->interval_ms); + TEST_ASSERT_EQUAL(BIN8(11111111) , p_int_qhd->interrupt_smask); + + check_int_endpoint_link(period_head_arr, p_int_qhd); +} + +void test_open_interrupt_hs_interval_2(void) +{ + tusb_descriptor_endpoint_t int_edp_interval = desc_ept_interrupt_out; + int_edp_interval.bInterval = 2; + + //------------- Code Under TEST -------------// + pipe_hdl = hcd_pipe_open(dev_addr, &int_edp_interval, TUSB_CLASS_HID); + p_int_qhd = &ehci_data.device[ pipe_hdl.dev_addr-1].qhd[ pipe_hdl.index ]; + + TEST_ASSERT_EQUAL(0 , p_int_qhd->interval_ms); + TEST_ASSERT_EQUAL(4 , cardinality_of(p_int_qhd->interrupt_smask)); // either 10101010 or 01010101 + check_int_endpoint_link(period_head_arr, p_int_qhd); +} + +void test_open_interrupt_hs_interval_3(void) +{ + tusb_descriptor_endpoint_t int_edp_interval = desc_ept_interrupt_out; + int_edp_interval.bInterval = 3; + + //------------- Code Under TEST -------------// + pipe_hdl = hcd_pipe_open(dev_addr, &int_edp_interval, TUSB_CLASS_HID); + p_int_qhd = &ehci_data.device[ pipe_hdl.dev_addr-1].qhd[ pipe_hdl.index ]; + + TEST_ASSERT_EQUAL(0, p_int_qhd->interval_ms); + TEST_ASSERT_EQUAL(2, cardinality_of(p_int_qhd->interrupt_smask) ); + check_int_endpoint_link(period_head_arr, p_int_qhd); +} + +void test_open_interrupt_hs_interval_4(void) +{ + tusb_descriptor_endpoint_t int_edp_interval = desc_ept_interrupt_out; + int_edp_interval.bInterval = 4; + + //------------- Code Under TEST -------------// + pipe_hdl = hcd_pipe_open(dev_addr, &int_edp_interval, TUSB_CLASS_HID); + p_int_qhd = &ehci_data.device[ pipe_hdl.dev_addr-1].qhd[ pipe_hdl.index ]; + + TEST_ASSERT_EQUAL(1, p_int_qhd->interval_ms); + TEST_ASSERT_EQUAL(1, cardinality_of(p_int_qhd->interrupt_smask) ); + check_int_endpoint_link(period_head_arr, p_int_qhd); +} + +void test_open_interrupt_hs_interval_5(void) +{ + tusb_descriptor_endpoint_t int_edp_interval = desc_ept_interrupt_out; + int_edp_interval.bInterval = 5; + + //------------- Code Under TEST -------------// + pipe_hdl = hcd_pipe_open(dev_addr, &int_edp_interval, TUSB_CLASS_HID); + p_int_qhd = &ehci_data.device[ pipe_hdl.dev_addr-1].qhd[ pipe_hdl.index ]; + + TEST_ASSERT_EQUAL(2, p_int_qhd->interval_ms); + TEST_ASSERT_EQUAL(1, cardinality_of(p_int_qhd->interrupt_smask) ); + check_int_endpoint_link( get_period_head(hostid, 2), p_int_qhd ); +} + +void test_open_interrupt_hs_interval_6(void) +{ + tusb_descriptor_endpoint_t int_edp_interval = desc_ept_interrupt_out; + int_edp_interval.bInterval = 6; + + //------------- Code Under TEST -------------// + pipe_hdl = hcd_pipe_open(dev_addr, &int_edp_interval, TUSB_CLASS_HID); + p_int_qhd = &ehci_data.device[ pipe_hdl.dev_addr-1].qhd[ pipe_hdl.index ]; + + TEST_ASSERT_EQUAL(4, p_int_qhd->interval_ms); + TEST_ASSERT_EQUAL(1, cardinality_of(p_int_qhd->interrupt_smask) ); + check_int_endpoint_link( get_period_head(hostid, 4), p_int_qhd); +} + +void test_open_interrupt_hs_interval_7(void) +{ + tusb_descriptor_endpoint_t int_edp_interval = desc_ept_interrupt_out; + int_edp_interval.bInterval = 7; + + //------------- Code Under TEST -------------// + pipe_hdl = hcd_pipe_open(dev_addr, &int_edp_interval, TUSB_CLASS_HID); + p_int_qhd = &ehci_data.device[ pipe_hdl.dev_addr-1].qhd[ pipe_hdl.index ]; + + TEST_ASSERT_EQUAL(8, p_int_qhd->interval_ms); + TEST_ASSERT_EQUAL(1, cardinality_of(p_int_qhd->interrupt_smask) ); + check_int_endpoint_link( get_period_head(hostid, 8), p_int_qhd); +} + +void test_open_interrupt_hs_interval_8(void) +{ + tusb_descriptor_endpoint_t int_edp_interval = desc_ept_interrupt_out; + int_edp_interval.bInterval = 16; + + //------------- Code Under TEST -------------// + pipe_hdl = hcd_pipe_open(dev_addr, &int_edp_interval, TUSB_CLASS_HID); + p_int_qhd = &ehci_data.device[ pipe_hdl.dev_addr-1].qhd[ pipe_hdl.index ]; + + TEST_ASSERT_EQUAL(255, p_int_qhd->interval_ms); + TEST_ASSERT_EQUAL(1, cardinality_of(p_int_qhd->interrupt_smask) ); + check_int_endpoint_link( get_period_head(hostid, 255), p_int_qhd); + check_int_endpoint_link( get_period_head(hostid, 8) , p_int_qhd); +} + +void test_open_interrupt_qhd_non_hs(void) +{ + usbh_devices[dev_addr].speed = TUSB_SPEED_FULL; + + //------------- Code Under TEST -------------// + pipe_hdl = hcd_pipe_open(dev_addr, &desc_ept_interrupt_out, TUSB_CLASS_HID); + + TEST_ASSERT_EQUAL(dev_addr, pipe_hdl.dev_addr); + TEST_ASSERT_EQUAL(TUSB_XFER_INTERRUPT, pipe_hdl.xfer_type); + + p_int_qhd = &ehci_data.device[ pipe_hdl.dev_addr-1].qhd[ pipe_hdl.index ]; + + verify_int_qhd(p_int_qhd, &desc_ept_interrupt_out, TUSB_CLASS_HID); + + TEST_ASSERT_EQUAL(desc_ept_interrupt_out.bInterval, p_int_qhd->interval_ms); + TEST_ASSERT_EQUAL(1, p_int_qhd->interrupt_smask); + TEST_ASSERT_EQUAL(0x1c, p_int_qhd->non_hs_interrupt_cmask); +} + +void test_open_interrupt_qhd_non_hs_9(void) +{ + tusb_descriptor_endpoint_t int_edp_interval = desc_ept_interrupt_out; + int_edp_interval.bInterval = 32; + + usbh_devices[dev_addr].speed = TUSB_SPEED_FULL; + + //------------- Code Under TEST -------------// + pipe_hdl = hcd_pipe_open(dev_addr, &int_edp_interval, TUSB_CLASS_HID); + p_int_qhd = &ehci_data.device[ pipe_hdl.dev_addr-1].qhd[ pipe_hdl.index ]; + + TEST_ASSERT_EQUAL(int_edp_interval.bInterval, p_int_qhd->interval_ms); + check_int_endpoint_link( get_period_head(hostid, 32), p_int_qhd); + check_int_endpoint_link( get_period_head(hostid, 8) , p_int_qhd); +} + +//--------------------------------------------------------------------+ +// PIPE CLOSE +//--------------------------------------------------------------------+ +void test_interrupt_close(void) +{ + pipe_hdl = hcd_pipe_open(dev_addr, &desc_ept_interrupt_out, TUSB_CLASS_HID); + p_int_qhd = qhd_get_from_pipe_handle(pipe_hdl); + + //------------- Code Under TEST -------------// + TEST_ASSERT_EQUAL(TUSB_ERROR_NONE, + hcd_pipe_close(pipe_hdl) ); + + TEST_ASSERT(p_int_qhd->is_removing); + TEST_ASSERT( align32(period_head_arr->next.address) != (uint32_t) p_int_qhd ); + TEST_ASSERT_EQUAL_HEX( (uint32_t) period_head_arr, align32(p_int_qhd->next.address ) ); + TEST_ASSERT_EQUAL(EHCI_QUEUE_ELEMENT_QHD, p_int_qhd->next.type); +} + +void test_interrupt_256ms_close(void) +{ + tusb_descriptor_endpoint_t int_edp_interval = desc_ept_interrupt_out; + int_edp_interval.bInterval = 9; + + pipe_hdl = hcd_pipe_open(dev_addr, &int_edp_interval, TUSB_CLASS_HID); + p_int_qhd = qhd_get_from_pipe_handle(pipe_hdl); + + //------------- Code Under TEST -------------// + TEST_ASSERT_EQUAL(TUSB_ERROR_NONE, + hcd_pipe_close(pipe_hdl) ); + + TEST_ASSERT(p_int_qhd->is_removing); + TEST_ASSERT( align32(get_period_head(hostid, 8)->address) != (uint32_t) p_int_qhd ); + TEST_ASSERT_EQUAL_HEX( (uint32_t) get_period_head(hostid, 8), align32(p_int_qhd->next.address ) ); + TEST_ASSERT_EQUAL(EHCI_QUEUE_ELEMENT_QHD, p_int_qhd->next.type); +} diff --git a/tests/lpc18xx_43xx/test/host/ehci/test_pipe_interrupt_xfer.c b/tests/lpc18xx_43xx/test/host/ehci/test_pipe_interrupt_xfer.c new file mode 100644 index 000000000..f72b5d3ae --- /dev/null +++ b/tests/lpc18xx_43xx/test/host/ehci/test_pipe_interrupt_xfer.c @@ -0,0 +1,236 @@ +/**************************************************************************/ +/*! + @file test_ehci_pipe_bulk_xfer.c + @author hathach (tinyusb.org) + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2013, hathach (tinyusb.org) + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + This file is part of the tinyusb stack. +*/ +/**************************************************************************/ + +#include +#include "unity.h" +#include "tusb_option.h" +#include "errors.h" +#include "binary.h" +#include "type_helper.h" + +#include "hal.h" +#include "mock_osal.h" +#include "hcd.h" +#include "mock_usbh_hcd.h" +#include "ehci.h" +#include "ehci_controller_fake.h" +#include "host_helper.h" + +usbh_device_info_t usbh_devices[TUSB_CFG_HOST_DEVICE_MAX+1]; + +static uint8_t const hub_addr = 2; +static uint8_t const hub_port = 2; +static uint8_t dev_addr; +static uint8_t hostid; +static uint8_t xfer_data [100]; +static uint8_t data2[100]; + +static ehci_qhd_t *period_head_arr; +static ehci_qhd_t *p_qhd_interrupt; +static pipe_handle_t pipe_hdl_interrupt; + +static tusb_descriptor_endpoint_t const desc_ept_interrupt_in = +{ + .bLength = sizeof(tusb_descriptor_endpoint_t), + .bDescriptorType = TUSB_DESC_TYPE_ENDPOINT, + .bEndpointAddress = 0x81, + .bmAttributes = { .xfer = TUSB_XFER_INTERRUPT }, + .wMaxPacketSize = 8, + .bInterval = 2 +}; + +static tusb_descriptor_endpoint_t const desc_ept_interupt_out = +{ + .bLength = sizeof(tusb_descriptor_endpoint_t), + .bDescriptorType = TUSB_DESC_TYPE_ENDPOINT, + .bEndpointAddress = 0x01, + .bmAttributes = { .xfer = TUSB_XFER_INTERRUPT }, + .wMaxPacketSize = 64, + .bInterval = 3 +}; + +//--------------------------------------------------------------------+ +// Setup/Teardown + helper declare +//--------------------------------------------------------------------+ +void setUp(void) +{ + ehci_controller_init(); + + memclr_(usbh_devices, sizeof(usbh_device_info_t)*(TUSB_CFG_HOST_DEVICE_MAX+1)); + memclr_(xfer_data, sizeof(xfer_data)); + + TEST_ASSERT_STATUS( hcd_init() ); + + dev_addr = 1; + hostid = RANDOM(CONTROLLER_HOST_NUMBER) + TEST_CONTROLLER_HOST_START_INDEX; + + helper_usbh_device_emulate(dev_addr , hub_addr, hub_port, hostid, TUSB_SPEED_HIGH); + + period_head_arr = (ehci_qhd_t*) get_period_head( hostid, 1 ); + + //------------- pipe open -------------// + pipe_hdl_interrupt = hcd_pipe_open(dev_addr, &desc_ept_interrupt_in, TUSB_CLASS_HID); + + TEST_ASSERT_EQUAL(dev_addr, pipe_hdl_interrupt.dev_addr); + TEST_ASSERT_EQUAL(TUSB_XFER_INTERRUPT, pipe_hdl_interrupt.xfer_type); + + p_qhd_interrupt = &ehci_data.device[ dev_addr -1].qhd[ pipe_hdl_interrupt.index ]; +} + +void tearDown(void) +{ +} +//--------------------------------------------------------------------+ +// BULK TRANSFER +//--------------------------------------------------------------------+ +void verify_qtd(ehci_qtd_t *p_qtd, uint8_t p_data[], uint16_t length) +{ + TEST_ASSERT_TRUE(p_qtd->alternate.terminate); // not used, always invalid + + //------------- status -------------// + TEST_ASSERT_FALSE(p_qtd->pingstate_err); + TEST_ASSERT_FALSE(p_qtd->non_hs_split_state); + TEST_ASSERT_FALSE(p_qtd->non_hs_period_missed_uframe); + TEST_ASSERT_FALSE(p_qtd->xact_err); + TEST_ASSERT_FALSE(p_qtd->babble_err); + TEST_ASSERT_FALSE(p_qtd->buffer_err); + TEST_ASSERT_FALSE(p_qtd->halted); + TEST_ASSERT_TRUE(p_qtd->active); + + TEST_ASSERT_FALSE(p_qtd->data_toggle); + TEST_ASSERT_EQUAL(3, p_qtd->cerr); + TEST_ASSERT_EQUAL(0, p_qtd->current_page); + TEST_ASSERT_EQUAL(length, p_qtd->total_bytes); + TEST_ASSERT_TRUE(p_qtd->used); + + TEST_ASSERT_EQUAL_HEX( p_data, p_qtd->buffer[0] ); + for(uint8_t i=1; i<5; i++) + { + TEST_ASSERT_EQUAL_HEX( align4k((uint32_t) (p_data+4096*i)), align4k(p_qtd->buffer[i]) ); + } +} + +void test_interrupt_xfer(void) +{ + //------------- Code Under Test -------------// + TEST_ASSERT_STATUS( hcd_pipe_xfer(pipe_hdl_interrupt, xfer_data, sizeof(xfer_data), true) ); + + ehci_qtd_t* p_qtd = p_qhd_interrupt->p_qtd_list_head; + TEST_ASSERT_NOT_NULL(p_qtd); + + verify_qtd( p_qtd, xfer_data, sizeof(xfer_data)); + TEST_ASSERT_EQUAL_HEX(p_qhd_interrupt->qtd_overlay.next.address, p_qtd); + TEST_ASSERT_TRUE(p_qtd->next.terminate); + TEST_ASSERT_EQUAL(EHCI_PID_IN, p_qtd->pid); + TEST_ASSERT_TRUE(p_qtd->int_on_complete); +} + +void test_interrupt_xfer_double(void) +{ + //------------- Code Under Test -------------// + TEST_ASSERT_STATUS( hcd_pipe_xfer(pipe_hdl_interrupt, xfer_data, sizeof(xfer_data), false) ); + + TEST_ASSERT_STATUS( hcd_pipe_xfer(pipe_hdl_interrupt, data2, sizeof(data2), true) ); + + ehci_qtd_t* p_head = p_qhd_interrupt->p_qtd_list_head; + ehci_qtd_t* p_tail = p_qhd_interrupt->p_qtd_list_tail; + + //------------- list head -------------// + TEST_ASSERT_NOT_NULL(p_head); + verify_qtd(p_head, xfer_data, sizeof(xfer_data)); + TEST_ASSERT_EQUAL_HEX(p_qhd_interrupt->qtd_overlay.next.address, p_head); + TEST_ASSERT_EQUAL(EHCI_PID_IN, p_head->pid); + TEST_ASSERT_FALSE(p_head->next.terminate); + TEST_ASSERT_FALSE(p_head->int_on_complete); + + //------------- list tail -------------// + TEST_ASSERT_NOT_NULL(p_tail); + verify_qtd(p_tail, data2, sizeof(data2)); + TEST_ASSERT_EQUAL_HEX( align32(p_head->next.address), p_tail); + TEST_ASSERT_EQUAL(EHCI_PID_IN, p_tail->pid); + TEST_ASSERT_TRUE(p_tail->next.terminate); + TEST_ASSERT_TRUE(p_tail->int_on_complete); +} + +void check_qhd_after_complete(ehci_qhd_t *p_qhd) +{ + TEST_ASSERT_TRUE(p_qhd->qtd_overlay.next.terminate); + TEST_ASSERT_NULL(p_qhd->p_qtd_list_head); + TEST_ASSERT_NULL(p_qhd->p_qtd_list_tail); +} + +void test_interrupt_xfer_complete_isr_interval_less_than_1ms(void) +{ + TEST_ASSERT_STATUS( hcd_pipe_xfer(pipe_hdl_interrupt, xfer_data, sizeof(xfer_data), false) ); + + TEST_ASSERT_STATUS( hcd_pipe_xfer(pipe_hdl_interrupt, data2, sizeof(data2), true) ); + + usbh_isr_Expect(pipe_hdl_interrupt, TUSB_CLASS_HID, TUSB_EVENT_XFER_COMPLETE); + + ehci_qtd_t* p_head = p_qhd_interrupt->p_qtd_list_head; + ehci_qtd_t* p_tail = p_qhd_interrupt->p_qtd_list_tail; + + //------------- Code Under Test -------------// + ehci_controller_run(hostid); + + check_qhd_after_complete(p_qhd_interrupt); + TEST_ASSERT_FALSE(p_head->used); + TEST_ASSERT_FALSE(p_tail->used); +} + +void test_interrupt_xfer_complete_isr_interval_2ms(void) +{ + tusb_descriptor_endpoint_t desc_endpoint_2ms = desc_ept_interrupt_in; + desc_endpoint_2ms.bInterval = 5; + + pipe_handle_t pipe_hdl_2ms = hcd_pipe_open(dev_addr, &desc_endpoint_2ms, TUSB_CLASS_HID); + ehci_qhd_t * p_qhd_2ms = &ehci_data.device[ dev_addr -1].qhd[ pipe_hdl_2ms.index ]; + + TEST_ASSERT_STATUS( hcd_pipe_xfer(pipe_hdl_2ms, xfer_data, sizeof(xfer_data), false) ); + + ehci_qtd_t* p_head = p_qhd_2ms->p_qtd_list_head; + ehci_qtd_t* p_tail = p_qhd_2ms->p_qtd_list_tail; + + //------------- Code Under Test -------------// + ehci_controller_run(hostid); + + check_qhd_after_complete(p_qhd_2ms); + TEST_ASSERT_FALSE(p_head->used); + TEST_ASSERT_FALSE(p_tail->used); + +} diff --git a/tests/lpc18xx_43xx/test/host/ehci/test_pipe_isochronous_open.c b/tests/lpc18xx_43xx/test/host/ehci/test_pipe_isochronous_open.c new file mode 100644 index 000000000..b2ebbf944 --- /dev/null +++ b/tests/lpc18xx_43xx/test/host/ehci/test_pipe_isochronous_open.c @@ -0,0 +1,99 @@ +/**************************************************************************/ +/*! + @file test_ehci_pipe.c + @author hathach (tinyusb.org) + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2013, hathach (tinyusb.org) + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + This file is part of the tinyusb stack. +*/ +/**************************************************************************/ + +#include "unity.h" +#include "tusb_option.h" +#include "errors.h" +#include "binary.h" +#include "type_helper.h" + +#include "hal.h" +#include "mock_osal.h" +#include "hcd.h" +#include "mock_usbh_hcd.h" +#include "ehci.h" +#include "ehci_controller_fake.h" +#include "host_helper.h" + +usbh_device_info_t usbh_devices[TUSB_CFG_HOST_DEVICE_MAX+1]; + +static uint8_t const hub_addr = 2; +static uint8_t const hub_port = 2; +static uint8_t dev_addr; +static uint8_t hostid; + +static ehci_qhd_t *period_head_arr; +//--------------------------------------------------------------------+ +// Setup/Teardown + helper declare +//--------------------------------------------------------------------+ +void setUp(void) +{ + memclr_(usbh_devices, sizeof(usbh_device_info_t)*(TUSB_CFG_HOST_DEVICE_MAX+1)); + + hcd_init(); + + dev_addr = 1; + hostid = RANDOM(CONTROLLER_HOST_NUMBER) + TEST_CONTROLLER_HOST_START_INDEX; + + helper_usbh_device_emulate(dev_addr , hub_addr, hub_port, hostid, TUSB_SPEED_HIGH); + + period_head_arr = get_period_head( hostid, 1 ); +} + +void tearDown(void) +{ +} + +//--------------------------------------------------------------------+ +// TODO ISOCRHONOUS PIPE +//--------------------------------------------------------------------+ +tusb_descriptor_endpoint_t const desc_ept_iso_in = +{ + .bLength = sizeof(tusb_descriptor_endpoint_t), + .bDescriptorType = TUSB_DESC_TYPE_ENDPOINT, + .bEndpointAddress = 0x83, + .bmAttributes = { .xfer = TUSB_XFER_ISOCHRONOUS }, + .wMaxPacketSize = 1024, + .bInterval = 1 +}; + +void test_open_isochronous(void) +{ + pipe_handle_t pipe_hdl = hcd_pipe_open(dev_addr, &desc_ept_iso_in, TUSB_CLASS_AUDIO); + TEST_ASSERT_EQUAL(0, pipe_hdl.dev_addr); +} diff --git a/tests/lpc18xx_43xx/test/host/hid/hidh_callback.h b/tests/lpc18xx_43xx/test/host/hid/hidh_callback.h new file mode 100644 index 000000000..70da64695 --- /dev/null +++ b/tests/lpc18xx_43xx/test/host/hid/hidh_callback.h @@ -0,0 +1,71 @@ +/**************************************************************************/ +/*! + @file tusb_callback.h + @author hathach (tinyusb.org) + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2013, hathach (tinyusb.org) + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + This file is part of the tinyusb stack. +*/ +/**************************************************************************/ + +/** \file + * \brief TBD + * + * \note TBD + */ + +/** \ingroup TBD + * \defgroup TBD + * \brief TBD + * + * @{ + */ + +#ifndef _TUSB_HIDH_CALLBACK_H_ +#define _TUSB_HIDH_CALLBACK_H_ + +#ifdef __cplusplus + extern "C" { +#endif + +#include "common/common.h" + +//------------- hidh -------------// +void tusbh_hid_keyboard_isr(uint8_t dev_addr, tusb_event_t event) ATTR_WEAK; +void tusbh_hid_mouse_isr(uint8_t dev_addr, tusb_event_t event) ATTR_WEAK; + +#ifdef __cplusplus + } +#endif + +#endif /* _TUSB_HIDH_CALLBACK_H_ */ + +/** @} */ diff --git a/tests/lpc18xx_43xx/test/host/hid/test_hid_host.c b/tests/lpc18xx_43xx/test/host/hid/test_hid_host.c new file mode 100644 index 000000000..900319e5e --- /dev/null +++ b/tests/lpc18xx_43xx/test/host/hid/test_hid_host.c @@ -0,0 +1,97 @@ +/**************************************************************************/ +/*! + @file test_host_hid.c + @author hathach (tinyusb.org) + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2013, hathach (tinyusb.org) + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + This file is part of the tinyusb stack. +*/ +/**************************************************************************/ + +#include "stdlib.h" +#include "unity.h" +#include "tusb_option.h" +#include "errors.h" +#include "binary.h" +#include "type_helper.h" + +#include "descriptor_test.h" +#include "mock_osal.h" +#include "mock_hcd.h" +#include "mock_usbh.h" + +#include "hid_host.h" + +uint8_t dev_addr; +pipe_handle_t pipe_hdl; + +extern hidh_interface_info_t keyboard_data[TUSB_CFG_HOST_DEVICE_MAX]; + +tusb_descriptor_interface_t const *p_kbd_interface_desc = &desc_configuration.keyboard_interface; +tusb_hid_descriptor_hid_t const *p_kbh_hid_desc = &desc_configuration.keyboard_hid; +tusb_descriptor_endpoint_t const *p_kdb_endpoint_desc = &desc_configuration.keyboard_endpoint; + +void setUp(void) +{ + dev_addr = RANDOM(TUSB_CFG_HOST_DEVICE_MAX)+1; + pipe_hdl = (pipe_handle_t) {.dev_addr = dev_addr, .xfer_type = TUSB_XFER_INTERRUPT, .index = 2}; +} + +void tearDown(void) +{ +} + +//void test_hidh_open_ok(void) +//{ +// uint16_t length=0; +// +// // TODO expect get HID report descriptor +// hcd_pipe_open_IgnoreAndReturn( pipe_hdl ); +// +// //------------- Code Under TEST -------------// +// TEST_ASSERT_EQUAL(TUSB_ERROR_NONE, hidh_open_subtask(dev_addr, p_kbd_interface_desc, &length) ); +// +// TEST_ASSERT_EQUAL(sizeof(tusb_descriptor_interface_t) + sizeof(tusb_hid_descriptor_hid_t) + sizeof(tusb_descriptor_endpoint_t), +// length); +//} + +void test_hidh_close(void) +{ + keyboard_data[dev_addr-1].pipe_hdl = pipe_hdl; + keyboard_data[dev_addr-1].report_size = 8; + + hcd_pipe_close_ExpectAndReturn(pipe_hdl, TUSB_ERROR_NONE); + + //------------- Code Under TEST -------------// + hidh_close(dev_addr); + + TEST_ASSERT_MEM_ZERO(&keyboard_data[dev_addr-1], sizeof(hidh_interface_info_t)); +} diff --git a/tests/lpc18xx_43xx/test/host/hid/test_hidh_keyboard.c b/tests/lpc18xx_43xx/test/host/hid/test_hidh_keyboard.c new file mode 100644 index 000000000..62bcc8b45 --- /dev/null +++ b/tests/lpc18xx_43xx/test/host/hid/test_hidh_keyboard.c @@ -0,0 +1,224 @@ +/**************************************************************************/ +/*! + @file test_host_hid_keyboard.c + @author hathach (tinyusb.org) + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2013, hathach (tinyusb.org) + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + This file is part of the tinyusb stack. +*/ +/**************************************************************************/ + +#include "stdlib.h" +#include "unity.h" +#include "type_helper.h" +#include "errors.h" +#include "common/common.h" +#include "hid_host.h" +#include "mock_osal.h" +#include "mock_usbh.h" +#include "mock_hcd.h" +#include "mock_hidh_callback.h" +#include "descriptor_test.h" + +extern hidh_interface_info_t keyboard_data[TUSB_CFG_HOST_DEVICE_MAX]; + +tusb_keyboard_report_t sample_key[2] = +{ + { + .modifier = KEYBOARD_MODIFIER_LEFTCTRL, + .keycode = {4}//{KEYBOARD_KEYCODE_a} TODO ascii to key code table + }, + { + .modifier = KEYBOARD_MODIFIER_RIGHTALT, + .keycode = {5}//{KEYBOARD_KEYCODE_z} + } +}; + +uint8_t dev_addr; +hidh_interface_info_t *p_hidh_kbd; + +tusb_keyboard_report_t report; + +tusb_descriptor_interface_t const *p_kbd_interface_desc = &desc_configuration.keyboard_interface; +tusb_descriptor_endpoint_t const *p_kdb_endpoint_desc = &desc_configuration.keyboard_endpoint; + +void setUp(void) +{ + hidh_init(); + memclr_(&report, sizeof(tusb_keyboard_report_t)); + dev_addr = RANDOM(TUSB_CFG_HOST_DEVICE_MAX)+1; + + p_hidh_kbd = &keyboard_data[dev_addr-1]; + + p_hidh_kbd->report_size = sizeof(tusb_keyboard_report_t); + p_hidh_kbd->pipe_hdl = (pipe_handle_t) { + .dev_addr = dev_addr, + .xfer_type = TUSB_XFER_INTERRUPT, + .index = 1 + }; + +} + +void tearDown(void) +{ +} + +void test_keyboard_init(void) +{ + hidh_init(); + + TEST_ASSERT_MEM_ZERO(keyboard_data, sizeof(hidh_interface_info_t)*TUSB_CFG_HOST_DEVICE_MAX); +} + +//------------- is supported -------------// +void test_keyboard_is_supported_fail_unplug(void) +{ + tusbh_device_get_state_IgnoreAndReturn(TUSB_DEVICE_STATE_UNPLUG); + TEST_ASSERT_FALSE( tusbh_hid_keyboard_is_mounted(dev_addr) ); +} + +void test_keyboard_is_supported_fail_not_opened(void) +{ + hidh_init(); + tusbh_device_get_state_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED); + TEST_ASSERT_FALSE( tusbh_hid_keyboard_is_mounted(dev_addr) ); +} + +void test_keyboard_is_supported_ok(void) +{ + tusbh_device_get_state_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED); + TEST_ASSERT_TRUE( tusbh_hid_keyboard_is_mounted(dev_addr) ); +} + +static tusb_error_t stub_set_idle_request(uint8_t address, tusb_std_request_t const* p_request, uint8_t* data, int num_call) +{ + TEST_ASSERT_EQUAL( dev_addr, address); + + //------------- expecting Set Idle with value = 0 -------------// + TEST_ASSERT_NOT_NULL( p_request ); + TEST_ASSERT_EQUAL(TUSB_DIR_HOST_TO_DEV , p_request->bmRequestType.direction); + TEST_ASSERT_EQUAL(TUSB_REQUEST_TYPE_CLASS , p_request->bmRequestType.type); + TEST_ASSERT_EQUAL(TUSB_REQUEST_RECIPIENT_INTERFACE , p_request->bmRequestType.recipient); + TEST_ASSERT_EQUAL(HID_REQUEST_CONTROL_SET_IDLE , p_request->bRequest); + TEST_ASSERT_EQUAL(0 , p_request->wValue); + TEST_ASSERT_EQUAL(p_kbd_interface_desc->bInterfaceNumber , p_request->wIndex); + + TEST_ASSERT_NULL(data); + + return TUSB_ERROR_NONE; +} + +void test_keyboard_open_ok(void) +{ + uint16_t length=0; + pipe_handle_t pipe_hdl = {.dev_addr = dev_addr, .xfer_type = TUSB_XFER_INTERRUPT, .index = 2}; + + hidh_init(); + + usbh_control_xfer_subtask_StubWithCallback(stub_set_idle_request); + hcd_pipe_open_ExpectAndReturn(dev_addr, p_kdb_endpoint_desc, TUSB_CLASS_HID, pipe_hdl); + tusbh_hid_keyboard_isr_Expect(dev_addr, TUSB_EVENT_INTERFACE_OPEN); + + //------------- Code Under TEST -------------// + TEST_ASSERT_EQUAL(TUSB_ERROR_NONE, hidh_open_subtask(dev_addr, p_kbd_interface_desc, &length)); + + TEST_ASSERT_PIPE_HANDLE(pipe_hdl, p_hidh_kbd->pipe_hdl); + TEST_ASSERT_EQUAL(8, p_hidh_kbd->report_size); + TEST_ASSERT_EQUAL(sizeof(tusb_descriptor_interface_t) + sizeof(tusb_hid_descriptor_hid_t) + sizeof(tusb_descriptor_endpoint_t), + length); + TEST_ASSERT_EQUAL(p_kbd_interface_desc->bInterfaceNumber, p_hidh_kbd->interface_number); + + tusbh_device_get_state_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED); + TEST_ASSERT_TRUE( tusbh_hid_keyboard_is_mounted(dev_addr) ); + TEST_ASSERT_EQUAL(TUSB_INTERFACE_STATUS_READY, p_hidh_kbd->status); +} + +//--------------------------------------------------------------------+ +// keyboard_get +//--------------------------------------------------------------------+ +void test_keyboard_get_invalid_address(void) +{ + tusbh_device_get_state_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED); + TEST_ASSERT_EQUAL(TUSB_ERROR_INVALID_PARA, tusbh_hid_keyboard_get_report(0, NULL)); // invalid address +} + +void test_keyboard_get_invalid_buffer(void) +{ + tusbh_device_get_state_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED); + TEST_ASSERT_EQUAL(TUSB_ERROR_INVALID_PARA, tusbh_hid_keyboard_get_report(dev_addr, NULL)); // invalid buffer +} + +void test_keyboard_get_device_not_ready(void) +{ + tusbh_device_get_state_IgnoreAndReturn(TUSB_DEVICE_STATE_UNPLUG); + TEST_ASSERT_EQUAL(TUSB_ERROR_DEVICE_NOT_READY, tusbh_hid_keyboard_get_report(dev_addr, &report)); // device not mounted +} + +void test_keyboard_get_report_xfer_failed() +{ + tusbh_device_get_state_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED); + hcd_pipe_xfer_ExpectAndReturn(p_hidh_kbd->pipe_hdl, (uint8_t*) &report, p_hidh_kbd->report_size, true, TUSB_ERROR_INVALID_PARA); + + //------------- Code Under TEST -------------// + TEST_ASSERT_EQUAL(TUSB_ERROR_INVALID_PARA, tusbh_hid_keyboard_get_report(dev_addr, &report)); +} + +void test_keyboard_get_report_xfer_failed_busy() +{ + tusbh_device_get_state_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED); + p_hidh_kbd->status = TUSB_INTERFACE_STATUS_BUSY; + TEST_ASSERT_EQUAL(TUSB_ERROR_INTERFACE_IS_BUSY, tusbh_hid_keyboard_get_report(dev_addr, &report)); +} + +void test_keyboard_get_ok() +{ + tusbh_device_get_state_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED); + + TEST_ASSERT_EQUAL(TUSB_INTERFACE_STATUS_READY, tusbh_hid_keyboard_status(dev_addr)); + hcd_pipe_xfer_ExpectAndReturn(p_hidh_kbd->pipe_hdl, (uint8_t*) &report, p_hidh_kbd->report_size, true, TUSB_ERROR_NONE); + + //------------- Code Under TEST -------------// + TEST_ASSERT_EQUAL(TUSB_ERROR_NONE, tusbh_hid_keyboard_get_report(dev_addr, &report)); + TEST_ASSERT_EQUAL(TUSB_INTERFACE_STATUS_BUSY, tusbh_hid_keyboard_status(dev_addr)); +} + +void test_keyboard_isr_event_complete(void) +{ + tusbh_hid_keyboard_isr_Expect(dev_addr, TUSB_EVENT_XFER_COMPLETE); + + //------------- Code Under TEST -------------// + hidh_isr(p_hidh_kbd->pipe_hdl, TUSB_EVENT_XFER_COMPLETE); + + tusbh_device_get_state_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED); + TEST_ASSERT_EQUAL(TUSB_INTERFACE_STATUS_COMPLETE, tusbh_hid_keyboard_status(dev_addr)); +} + + diff --git a/tests/lpc18xx_43xx/test/host/hid/test_hidh_mouse.c b/tests/lpc18xx_43xx/test/host/hid/test_hidh_mouse.c new file mode 100644 index 000000000..0156f5a58 --- /dev/null +++ b/tests/lpc18xx_43xx/test/host/hid/test_hidh_mouse.c @@ -0,0 +1,226 @@ +/**************************************************************************/ +/*! + @file test_hidh_mouse.c + @author hathach (tinyusb.org) + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2013, hathach (tinyusb.org) + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + This file is part of the tinyusb stack. +*/ +/**************************************************************************/ + +#include "stdlib.h" +#include "unity.h" +#include "type_helper.h" +#include "errors.h" +#include "common/common.h" + +#include "hid_host.h" +#include "mock_osal.h" +#include "mock_usbh.h" +#include "mock_hcd.h" +#include "mock_hidh_callback.h" +#include "descriptor_test.h" + +extern hidh_interface_info_t mouse_data[TUSB_CFG_HOST_DEVICE_MAX]; +hidh_interface_info_t *p_hidh_mouse; +tusb_mouse_report_t report; + +tusb_descriptor_interface_t const *p_mouse_interface_desc = &desc_configuration.mouse_interface; +tusb_descriptor_endpoint_t const *p_mouse_endpoint_desc = &desc_configuration.mouse_endpoint; + +uint8_t dev_addr; + +void setUp(void) +{ + hidh_init(); + + memclr_(&report, sizeof(tusb_mouse_report_t)); + dev_addr = RANDOM(TUSB_CFG_HOST_DEVICE_MAX)+1; + + p_hidh_mouse = &mouse_data[dev_addr-1]; + + p_hidh_mouse->report_size = sizeof(tusb_mouse_report_t); + p_hidh_mouse->pipe_hdl = (pipe_handle_t) { + .dev_addr = dev_addr, + .xfer_type = TUSB_XFER_INTERRUPT, + .index = 1 + }; +} + +void tearDown(void) +{ + +} + +void test_mouse_init(void) +{ + hidh_init(); + + TEST_ASSERT_MEM_ZERO(mouse_data, sizeof(hidh_interface_info_t)*TUSB_CFG_HOST_DEVICE_MAX); +} + +//------------- is supported -------------// +void test_mouse_is_supported_fail_unplug(void) +{ + tusbh_device_get_state_IgnoreAndReturn(TUSB_DEVICE_STATE_UNPLUG); + TEST_ASSERT_FALSE( tusbh_hid_mouse_is_mounted(dev_addr) ); +} + +void test_mouse_is_supported_fail_not_opened(void) +{ + hidh_init(); + tusbh_device_get_state_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED); + TEST_ASSERT_FALSE( tusbh_hid_mouse_is_mounted(dev_addr) ); +} + +void test_mouse_is_supported_ok(void) +{ + tusbh_device_get_state_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED); + TEST_ASSERT_TRUE( tusbh_hid_mouse_is_mounted(dev_addr) ); +} + +static tusb_error_t stub_set_idle_request(uint8_t address, tusb_std_request_t const* p_request, uint8_t* data, int num_call) +{ + TEST_ASSERT_EQUAL( dev_addr, address); + + //------------- expecting Set Idle with value = 0 -------------// + TEST_ASSERT_NOT_NULL( p_request ); + TEST_ASSERT_EQUAL(TUSB_DIR_HOST_TO_DEV , p_request->bmRequestType.direction); + TEST_ASSERT_EQUAL(TUSB_REQUEST_TYPE_CLASS , p_request->bmRequestType.type); + TEST_ASSERT_EQUAL(TUSB_REQUEST_RECIPIENT_INTERFACE , p_request->bmRequestType.recipient); + TEST_ASSERT_EQUAL(HID_REQUEST_CONTROL_SET_IDLE , p_request->bRequest); + TEST_ASSERT_EQUAL(0 , p_request->wValue); + TEST_ASSERT_EQUAL(p_mouse_interface_desc->bInterfaceNumber , p_request->wIndex); + + TEST_ASSERT_NULL(data); + + return TUSB_ERROR_NONE; +} + +void test_mouse_open_ok(void) +{ + uint16_t length=0; + pipe_handle_t pipe_hdl = {.dev_addr = dev_addr, .xfer_type = TUSB_XFER_INTERRUPT, .index = 2}; + + hidh_init(); + + usbh_control_xfer_subtask_StubWithCallback(stub_set_idle_request); + hcd_pipe_open_ExpectAndReturn(dev_addr, p_mouse_endpoint_desc, TUSB_CLASS_HID, pipe_hdl); + tusbh_hid_mouse_isr_Expect(dev_addr, TUSB_EVENT_INTERFACE_OPEN); + + //------------- Code Under TEST -------------// + TEST_ASSERT_STATUS( hidh_open_subtask(dev_addr, p_mouse_interface_desc, &length)); + + TEST_ASSERT_PIPE_HANDLE(pipe_hdl, p_hidh_mouse->pipe_hdl); + TEST_ASSERT_EQUAL(8, p_hidh_mouse->report_size); + TEST_ASSERT_EQUAL(sizeof(tusb_descriptor_interface_t) + sizeof(tusb_hid_descriptor_hid_t) + sizeof(tusb_descriptor_endpoint_t), + length); + TEST_ASSERT_EQUAL(p_mouse_interface_desc->bInterfaceNumber, p_hidh_mouse->interface_number); + + tusbh_device_get_state_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED); + TEST_ASSERT_TRUE( tusbh_hid_mouse_is_mounted(dev_addr) ); + TEST_ASSERT_EQUAL(TUSB_INTERFACE_STATUS_READY, p_hidh_mouse->status); + +} + +//--------------------------------------------------------------------+ +// mouse_get +//--------------------------------------------------------------------+ +void test_mouse_get_invalid_address(void) +{ + tusbh_device_get_state_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED); + TEST_ASSERT_EQUAL(TUSB_ERROR_INVALID_PARA, tusbh_hid_mouse_get_report(0, NULL)); // invalid address +} + +void test_mouse_get_invalid_buffer(void) +{ + tusbh_device_get_state_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED); + TEST_ASSERT_EQUAL(TUSB_ERROR_INVALID_PARA, tusbh_hid_mouse_get_report(dev_addr, NULL)); // invalid buffer +} + +void test_mouse_get_device_not_ready(void) +{ + tusbh_device_get_state_IgnoreAndReturn(TUSB_DEVICE_STATE_UNPLUG); + TEST_ASSERT_EQUAL(TUSB_ERROR_DEVICE_NOT_READY, tusbh_hid_mouse_get_report(dev_addr, &report)); // device not mounted +} + +void test_mouse_get_report_xfer_failed() +{ + tusbh_device_get_state_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED); + hcd_pipe_xfer_ExpectAndReturn(p_hidh_mouse->pipe_hdl, (uint8_t*) &report, p_hidh_mouse->report_size, true, TUSB_ERROR_INVALID_PARA); + + //------------- Code Under TEST -------------// + TEST_ASSERT_EQUAL(TUSB_ERROR_INVALID_PARA, tusbh_hid_mouse_get_report(dev_addr, &report)); +} + +void test_mouse_get_report_xfer_failed_busy() +{ + tusbh_device_get_state_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED); + p_hidh_mouse->status = TUSB_INTERFACE_STATUS_BUSY; + TEST_ASSERT_EQUAL(TUSB_ERROR_INTERFACE_IS_BUSY, tusbh_hid_mouse_get_report(dev_addr, &report)); +} + +void test_mouse_get_ok() +{ + tusbh_device_get_state_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED); + TEST_ASSERT_EQUAL(TUSB_INTERFACE_STATUS_READY, tusbh_hid_mouse_status(dev_addr)); + hcd_pipe_xfer_ExpectAndReturn(p_hidh_mouse->pipe_hdl, (uint8_t*) &report, p_hidh_mouse->report_size, true, TUSB_ERROR_NONE); + + //------------- Code Under TEST -------------// + TEST_ASSERT_STATUS( tusbh_hid_mouse_get_report(dev_addr, &report)); + + TEST_ASSERT_EQUAL(TUSB_INTERFACE_STATUS_BUSY, tusbh_hid_mouse_status(dev_addr)); +} + +void test_mouse_isr_event_xfer_complete(void) +{ + tusbh_hid_mouse_isr_Expect(dev_addr, TUSB_EVENT_XFER_COMPLETE); + + //------------- Code Under TEST -------------// + hidh_isr(p_hidh_mouse->pipe_hdl, TUSB_EVENT_XFER_COMPLETE); + + tusbh_device_get_state_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED); + TEST_ASSERT_EQUAL(TUSB_INTERFACE_STATUS_COMPLETE, tusbh_hid_mouse_status(dev_addr)); +} + +void test_mouse_isr_event_xfer_error(void) +{ + tusbh_hid_mouse_isr_Expect(dev_addr, TUSB_EVENT_XFER_ERROR); + + //------------- Code Under TEST -------------// + hidh_isr(p_hidh_mouse->pipe_hdl, TUSB_EVENT_XFER_ERROR); + + tusbh_device_get_state_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED); + TEST_ASSERT_EQUAL(TUSB_INTERFACE_STATUS_ERROR, tusbh_hid_mouse_status(dev_addr)); +} + + + diff --git a/tests/lpc18xx_43xx/test/host/host_helper.h b/tests/lpc18xx_43xx/test/host/host_helper.h new file mode 100644 index 000000000..97102c565 --- /dev/null +++ b/tests/lpc18xx_43xx/test/host/host_helper.h @@ -0,0 +1,77 @@ +/* + * host_helper.h + * + * Created on: May 13, 2013 + * Author: hathach + */ + +/* + * Software License Agreement (BSD License) + * Copyright (c) 2012, hathach (tinyusb.org) + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the tiny usb stack. + */ + +#include "common/common.h" +#include "host/usbh.h" +#include "host/usbh_hcd.h" + +static inline void helper_class_init_expect(void) +{ + hidh_init_Expect(); + //TODO update more classes +} + +static inline void helper_class_close_expect(uint8_t dev_addr) +{ + hidh_close_Expect(dev_addr); + //TODO update more classes +} + + + +static inline void helper_usbh_init_expect(void) +{ + osal_semaphore_create_IgnoreAndReturn( (osal_semaphore_handle_t) 0x1234); + osal_task_create_IgnoreAndReturn(TUSB_ERROR_NONE); + osal_queue_create_IgnoreAndReturn( (osal_queue_handle_t) 0x4566 ); + osal_mutex_create_IgnoreAndReturn((osal_mutex_handle_t) 0x789a); +} + +static inline void helper_usbh_device_emulate(uint8_t dev_addr, uint8_t hub_addr, uint8_t hub_port, uint8_t hostid, tusb_speed_t speed) +{ + usbh_devices[dev_addr].core_id = hostid; + usbh_devices[dev_addr].hub_addr = hub_addr; + usbh_devices[dev_addr].hub_port = hub_port; + usbh_devices[dev_addr].speed = speed; + usbh_devices[dev_addr].state = dev_addr ? TUSB_DEVICE_STATE_CONFIGURED : TUSB_DEVICE_STATE_UNPLUG; +} + + + + + + diff --git a/tests/lpc18xx_43xx/test/host/hub/test_hub.c b/tests/lpc18xx_43xx/test/host/hub/test_hub.c new file mode 100644 index 000000000..5aef5dccc --- /dev/null +++ b/tests/lpc18xx_43xx/test/host/hub/test_hub.c @@ -0,0 +1,52 @@ +/**************************************************************************/ +/*! + @file test_hub.c + @author hathach (tinyusb.org) + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2013, hathach (tinyusb.org) + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + This file is part of the tinyusb stack. +*/ +/**************************************************************************/ + +#include "unity.h" + +void setUp(void) +{ +} + +void tearDown(void) +{ +} + +void test_() +{ + // TEST_IGNORE(); +} diff --git a/tests/lpc18xx_43xx/test/host/integration/test_hidh_keyboard_integrate.c b/tests/lpc18xx_43xx/test/host/integration/test_hidh_keyboard_integrate.c new file mode 100644 index 000000000..a9fec44a1 --- /dev/null +++ b/tests/lpc18xx_43xx/test/host/integration/test_hidh_keyboard_integrate.c @@ -0,0 +1,132 @@ +/**************************************************************************/ +/*! + @file test_hidh_keyboard.c + @author hathach (tinyusb.org) + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2013, hathach (tinyusb.org) + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + This file is part of the tinyusb stack. +*/ +/**************************************************************************/ + +//#include "stdlib.h" +//#include "unity.h" +//#include "type_helper.h" +//#include "tusb_option.h" +//#include "errors.h" +// +//#include "mock_osal.h" +//#include "hcd.h" +//#include "usbh.h" +//#include "tusb.h" +//#include "hid_host.h" +////#include "ehci_controller_fake.h" +// +//#include "descriptor_test.h" +// +//uint8_t dev_addr; +//uint8_t hostid; +// +void setUp(void) +{ +// dev_addr = RANDOM(TUSB_CFG_HOST_DEVICE_MAX)+1; +// hostid = RANDOM(CONTROLLER_HOST_NUMBER) + TEST_CONTROLLER_HOST_START_INDEX; +// +//// ehci_controller_init(); +// tusb_init(); +// +} +// +void tearDown(void) +{ +} +// +//osal_semaphore_handle_t sem_create_stub(osal_semaphore_t * const sem, int num_call) +//{ +// (*p_sem) = 0; +// return (osal_semaphore_handle_t) p_sem; +//} +//void sem_wait_stub(osal_semaphore_handle_t const sem_hdl, uint32_t msec, tusb_error_t *p_error, int num_call) +//{ +// +//} +//tusb_error_t sem_post_stub(osal_semaphore_handle_t const sem_hdl, int num_call) +//{ +// (*sem_hdl)++; +// +// return TUSB_ERROR_NONE; +//} +//void sem_reset_stub(osal_semaphore_handle_t const sem_hdl, int num_call) +//{ +// (*sem_hdl) = 0; +//} +// +//osal_queue_handle_t queue_create_stub (osal_queue_t *p_queue, int num_call) +//{ +// p_queue->count = p_queue->wr_idx = p_queue->rd_idx = 0; +// return (osal_queue_handle_t) p_queue; +//} +//void queue_receive_stub (osal_queue_handle_t const queue_hdl, uint32_t *p_data, uint32_t msec, tusb_error_t *p_error, int num_call) +//{ +// +//} +//tusb_error_t queue_send_stub (osal_queue_handle_t const queue_hdl, uint32_t data, int num_call) +//{ +// //TODO mutex lock hal_interrupt_disable +// +// queue_hdl->buffer[queue_hdl->wr_idx] = data; +// queue_hdl->wr_idx = (queue_hdl->wr_idx + 1) % queue_hdl->depth; +// +// if (queue_hdl->depth == queue_hdl->count) // queue is full, 1st rd is overwritten +// { +// queue_hdl->rd_idx = queue_hdl->wr_idx; // keep full state +// }else +// { +// queue_hdl->count++; +// } +// +// //TODO mutex unlock hal_interrupt_enable +// +// return TUSB_ERROR_NONE; +//} +//void queue_flush_stub(osal_queue_handle_t const queue_hdl, int num_call) +//{ +// queue_hdl->count = queue_hdl->rd_idx = queue_hdl->wr_idx = 0; +//} +// +//void test_(void) +//{ +// ehci_controller_device_plug(hostid, TUSB_SPEED_HIGH); +// +// tusb_task_runner(); // get 8-byte descriptor +// ehci_controller_control_xfer_proceed(0, &desc_device); +// +// tusb_task_runner(); // get 8-byte descriptor +//} diff --git a/tests/lpc18xx_43xx/test/host/msc/test_msc_host.c b/tests/lpc18xx_43xx/test/host/msc/test_msc_host.c new file mode 100644 index 000000000..4e42b3023 --- /dev/null +++ b/tests/lpc18xx_43xx/test/host/msc/test_msc_host.c @@ -0,0 +1,63 @@ +/**************************************************************************/ +/*! + @file test_msc_host.c + @author hathach (tinyusb.org) + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2013, hathach (tinyusb.org) + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + This file is part of the tinyusb stack. +*/ +/**************************************************************************/ + +#include "stdlib.h" +#include "unity.h" +#include "tusb_option.h" +#include "errors.h" +#include "binary.h" +#include "type_helper.h" + +//#include "descriptor_test.h" +//#include "msc_host.h" +//#include "usbh.h" +//#include "hcd.h" +//#include "ehci.h" + +void setUp(void) +{ +} + +void tearDown(void) +{ +} + +void test_() +{ + // TEST_IGNORE(); +} diff --git a/tests/lpc18xx_43xx/test/host/usbh/test_enum_task.c b/tests/lpc18xx_43xx/test/host/usbh/test_enum_task.c new file mode 100644 index 000000000..ae3fe34c5 --- /dev/null +++ b/tests/lpc18xx_43xx/test/host/usbh/test_enum_task.c @@ -0,0 +1,290 @@ +/**************************************************************************/ +/*! + @file test_enum_task.c + @author hathach (tinyusb.org) + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2013, hathach (tinyusb.org) + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + This file is part of the tinyusb stack. +*/ +/**************************************************************************/ + +#include "unity.h" +#include "errors.h" +#include "descriptor_test.h" + +#include "mock_osal.h" +#include "usbh.h" +#include "mock_hcd.h" +#include "usbh_hcd.h" + +#include "mock_tusb_callback.h" +#include "mock_hid_host.h" + +extern usbh_device_info_t usbh_devices[TUSB_CFG_HOST_DEVICE_MAX+1]; +extern uint8_t enum_data_buffer[TUSB_CFG_HOST_ENUM_BUFFER_SIZE]; + +usbh_enumerate_t const enum_connect = { + .core_id = 0, + .hub_addr = 0, + .hub_port = 0, +}; + +tusb_speed_t device_speed = TUSB_SPEED_FULL; + +void queue_recv_stub (osal_queue_handle_t const queue_hdl, uint32_t *p_data, uint32_t msec, tusb_error_t *p_error, int num_call); +void semaphore_wait_success_stub(osal_semaphore_handle_t const sem_hdl, uint32_t msec, tusb_error_t *p_error, int num_call); +tusb_error_t control_xfer_stub(uint8_t dev_addr, const tusb_std_request_t * const p_request, uint8_t data[], int num_call); + +void setUp(void) +{ + memclr_(usbh_devices, sizeof(usbh_device_info_t)*(TUSB_CFG_HOST_DEVICE_MAX+1)); + + osal_queue_receive_StubWithCallback(queue_recv_stub); + osal_semaphore_wait_StubWithCallback(semaphore_wait_success_stub); + osal_mutex_wait_StubWithCallback(semaphore_wait_success_stub); + osal_mutex_release_IgnoreAndReturn(TUSB_ERROR_NONE); + hcd_pipe_control_xfer_StubWithCallback(control_xfer_stub); + + hcd_port_connect_status_ExpectAndReturn(enum_connect.core_id, true); + hcd_port_reset_Expect(enum_connect.core_id); + hcd_port_speed_get_ExpectAndReturn(enum_connect.core_id, device_speed); + osal_semaphore_reset_Expect( usbh_devices[0].control.sem_hdl ); + osal_mutex_reset_Expect( usbh_devices[0].control.mutex_hdl ); + hcd_pipe_control_open_ExpectAndReturn(0, 8, TUSB_ERROR_NONE); +} + +void tearDown(void) +{ +} + +//--------------------------------------------------------------------+ +// STUB & HELPER +//--------------------------------------------------------------------+ +void queue_recv_stub (osal_queue_handle_t const queue_hdl, uint32_t *p_data, uint32_t msec, tusb_error_t *p_error, int num_call) +{ + (*p_data) = ( *((uint32_t*) &enum_connect) ); + (*p_error) = TUSB_ERROR_NONE; +} + +void semaphore_wait_success_stub(osal_semaphore_handle_t const sem_hdl, uint32_t msec, tusb_error_t *p_error, int num_call) +{ + (*p_error) = TUSB_ERROR_NONE; +} + +#define semaphore_wait_timeout_stub(n) semaphore_wait_timeout_##n +#define semaphore_wait_timeout(n) \ + void semaphore_wait_timeout_##n(osal_semaphore_handle_t const sem_hdl, uint32_t msec, tusb_error_t *p_error, int num_call) {\ + if (num_call >= n)\ + (*p_error) = TUSB_ERROR_OSAL_TIMEOUT;\ + else \ + (*p_error) = TUSB_ERROR_NONE;\ + } + +semaphore_wait_timeout(0) +semaphore_wait_timeout(1) +semaphore_wait_timeout(2) +semaphore_wait_timeout(3) +semaphore_wait_timeout(4) +semaphore_wait_timeout(5) +semaphore_wait_timeout(6) +semaphore_wait_timeout(7) +semaphore_wait_timeout(8) + +tusb_error_t control_xfer_stub(uint8_t dev_addr, const tusb_std_request_t * const p_request, uint8_t data[], int num_call) +{ + switch (num_call) + { + case 0: // get 8 bytes of device descriptor + TEST_ASSERT_EQUAL(TUSB_REQUEST_GET_DESCRIPTOR, p_request->bRequest); + TEST_ASSERT_EQUAL(TUSB_DESC_TYPE_DEVICE, p_request->wValue >> 8); + TEST_ASSERT_EQUAL(8, p_request->wLength); + memcpy(data, &desc_device, p_request->wLength); + break; + + case 1: // set device address + TEST_ASSERT_EQUAL(TUSB_REQUEST_SET_ADDRESS, p_request->bRequest); + TEST_ASSERT_EQUAL(p_request->wValue, 1); + break; + + case 2: // get full device decriptor for new address + TEST_ASSERT_EQUAL(TUSB_REQUEST_GET_DESCRIPTOR, p_request->bRequest); + TEST_ASSERT_EQUAL(TUSB_DESC_TYPE_DEVICE, p_request->wValue >> 8); + TEST_ASSERT_EQUAL(18, p_request->wLength); + memcpy(data, &desc_device, p_request->wLength); + break; + + case 3: // get 9 bytes of configuration descriptor + TEST_ASSERT_EQUAL(TUSB_REQUEST_GET_DESCRIPTOR, p_request->bRequest); + TEST_ASSERT_EQUAL(TUSB_DESC_TYPE_CONFIGURATION, p_request->wValue >> 8); + TEST_ASSERT_EQUAL(9, p_request->wLength); + memcpy(data, &desc_configuration, p_request->wLength); + break; + + case 4: // get full-length configuration descriptor + TEST_ASSERT_EQUAL(TUSB_REQUEST_GET_DESCRIPTOR, p_request->bRequest); + TEST_ASSERT_EQUAL(TUSB_DESC_TYPE_CONFIGURATION, p_request->wValue >> 8); + TEST_ASSERT_EQUAL(desc_configuration.configuration.wTotalLength, p_request->wLength); + memcpy(data, &desc_configuration, p_request->wLength); + break; + + default: + return TUSB_ERROR_OSAL_TIMEOUT; + } + + return TUSB_ERROR_NONE; +} + +tusb_error_t hidh_install_stub(uint8_t dev_addr, tusb_descriptor_interface_t const *descriptor, uint16_t *p_length, int num_call) +{ + *p_length = sizeof(tusb_descriptor_interface_t) + sizeof(tusb_hid_descriptor_hid_t) + sizeof(tusb_descriptor_endpoint_t); + return TUSB_ERROR_NONE; +} + +//--------------------------------------------------------------------+ +// enumeration +//--------------------------------------------------------------------+ +void test_addr0_failed_dev_desc(void) +{ + osal_semaphore_wait_StubWithCallback(semaphore_wait_timeout_stub(0)); + + tusbh_device_mount_failed_cb_Expect(TUSB_ERROR_USBH_MOUNT_DEVICE_NOT_RESPOND, NULL); + + usbh_enumeration_task(NULL); + + TEST_ASSERT_EQUAL(TUSB_DEVICE_STATE_ADDRESSED, usbh_devices[0].state); + +} + +void test_addr0_failed_set_address(void) +{ + osal_semaphore_wait_StubWithCallback(semaphore_wait_timeout_stub(1)); + hcd_port_reset_Expect( usbh_devices[0].core_id ); + tusbh_device_mount_failed_cb_Expect(TUSB_ERROR_USBH_MOUNT_DEVICE_NOT_RESPOND, NULL); + + usbh_enumeration_task(NULL); + + TEST_ASSERT_EQUAL(TUSB_DEVICE_STATE_ADDRESSED, usbh_devices[0].state); + TEST_ASSERT_EQUAL_MEMORY(&desc_device, enum_data_buffer, 8); +} + +void test_enum_failed_get_full_dev_desc(void) +{ + osal_semaphore_wait_StubWithCallback(semaphore_wait_timeout_stub(2)); + hcd_port_reset_Expect( usbh_devices[0].core_id ); + hcd_pipe_control_close_ExpectAndReturn(0, TUSB_ERROR_NONE); + + osal_semaphore_reset_Expect( usbh_devices[0].control.sem_hdl ); + osal_mutex_reset_Expect( usbh_devices[0].control.mutex_hdl ); + hcd_pipe_control_open_ExpectAndReturn(1, desc_device.bMaxPacketSize0, TUSB_ERROR_NONE); + tusbh_device_mount_failed_cb_Expect(TUSB_ERROR_USBH_MOUNT_DEVICE_NOT_RESPOND, NULL); + + usbh_enumeration_task(NULL); + + TEST_ASSERT_EQUAL(TUSB_DEVICE_STATE_UNPLUG, usbh_devices[0].state); + TEST_ASSERT_EQUAL(TUSB_DEVICE_STATE_ADDRESSED, usbh_devices[1].state); + TEST_ASSERT_EQUAL(TUSB_SPEED_FULL, usbh_devices[1].speed); + TEST_ASSERT_EQUAL(enum_connect.core_id, usbh_devices[1].core_id); + TEST_ASSERT_EQUAL(enum_connect.hub_addr, usbh_devices[1].hub_addr); + TEST_ASSERT_EQUAL(enum_connect.hub_port, usbh_devices[1].hub_port); +} + +void test_enum_failed_get_9byte_config_desc(void) +{ + osal_semaphore_wait_StubWithCallback(semaphore_wait_timeout_stub(3)); + hcd_port_reset_Expect( usbh_devices[0].core_id ); + hcd_pipe_control_close_ExpectAndReturn(0, TUSB_ERROR_NONE); + osal_semaphore_reset_Expect( usbh_devices[0].control.sem_hdl ); + osal_mutex_reset_Expect( usbh_devices[0].control.mutex_hdl ); + + hcd_pipe_control_open_ExpectAndReturn(1, desc_device.bMaxPacketSize0, TUSB_ERROR_NONE); + tusbh_device_attached_cb_ExpectAndReturn((tusb_descriptor_device_t*) enum_data_buffer, 1); + tusbh_device_mount_failed_cb_Expect(TUSB_ERROR_USBH_MOUNT_DEVICE_NOT_RESPOND, NULL); + + usbh_enumeration_task(NULL); + + TEST_ASSERT_EQUAL(desc_device.idVendor, usbh_devices[1].vendor_id); + TEST_ASSERT_EQUAL(desc_device.idProduct, usbh_devices[1].product_id); + TEST_ASSERT_EQUAL(desc_device.bNumConfigurations, usbh_devices[1].configure_count); +} + +void test_enum_failed_get_full_config_desc(void) +{ + osal_semaphore_wait_StubWithCallback(semaphore_wait_timeout_stub(4)); + hcd_port_reset_Expect( usbh_devices[0].core_id ); + hcd_pipe_control_close_ExpectAndReturn(0, TUSB_ERROR_NONE); + osal_semaphore_reset_Expect( usbh_devices[0].control.sem_hdl ); + osal_mutex_reset_Expect( usbh_devices[0].control.mutex_hdl ); + hcd_pipe_control_open_ExpectAndReturn(1, desc_device.bMaxPacketSize0, TUSB_ERROR_NONE); + tusbh_device_attached_cb_ExpectAndReturn((tusb_descriptor_device_t*) enum_data_buffer, 1); + tusbh_device_mount_failed_cb_Expect(TUSB_ERROR_USBH_MOUNT_DEVICE_NOT_RESPOND, NULL); + + usbh_enumeration_task(NULL); +} + +void class_install_expect(void) +{ + hidh_open_subtask_StubWithCallback(hidh_install_stub); +} + +void test_enum_parse_config_desc(void) +{ + osal_semaphore_wait_StubWithCallback(semaphore_wait_timeout_stub(5)); + hcd_port_reset_Expect( usbh_devices[0].core_id ); + hcd_pipe_control_close_ExpectAndReturn(0, TUSB_ERROR_NONE); + osal_semaphore_reset_Expect( usbh_devices[0].control.sem_hdl ); + osal_mutex_reset_Expect( usbh_devices[0].control.mutex_hdl ); + hcd_pipe_control_open_ExpectAndReturn(1, desc_device.bMaxPacketSize0, TUSB_ERROR_NONE); + tusbh_device_attached_cb_ExpectAndReturn((tusb_descriptor_device_t*) enum_data_buffer, 1); + + tusbh_device_mount_failed_cb_Expect(TUSB_ERROR_USBH_MOUNT_DEVICE_NOT_RESPOND, NULL); // fail to set configure + + usbh_enumeration_task(NULL); + + TEST_ASSERT_EQUAL(desc_configuration.configuration.bNumInterfaces, usbh_devices[1].interface_count); +} + +void test_enum_set_configure(void) +{ + osal_semaphore_wait_StubWithCallback(semaphore_wait_timeout_stub(6)); + hcd_port_reset_Expect( usbh_devices[0].core_id ); + hcd_pipe_control_close_ExpectAndReturn(0, TUSB_ERROR_NONE); + osal_semaphore_reset_Expect( usbh_devices[0].control.sem_hdl ); + osal_mutex_reset_Expect( usbh_devices[0].control.mutex_hdl ); + hcd_pipe_control_open_ExpectAndReturn(1, desc_device.bMaxPacketSize0, TUSB_ERROR_NONE); + tusbh_device_attached_cb_ExpectAndReturn((tusb_descriptor_device_t*) enum_data_buffer, 1); + class_install_expect(); + + tusbh_device_mount_succeed_cb_Expect(1); + + usbh_enumeration_task(NULL); + + TEST_ASSERT_EQUAL(TUSB_CLASS_FLAG_HID, usbh_devices[1].flag_supported_class); // TODO change later +} diff --git a/tests/lpc18xx_43xx/test/host/usbh/test_usbh.c b/tests/lpc18xx_43xx/test/host/usbh/test_usbh.c new file mode 100644 index 000000000..30f4a4dfc --- /dev/null +++ b/tests/lpc18xx_43xx/test/host/usbh/test_usbh.c @@ -0,0 +1,206 @@ +/**************************************************************************/ +/*! + @file test_usbd_host.c + @author hathach (tinyusb.org) + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2013, hathach (tinyusb.org) + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + This file is part of the tinyusb stack. +*/ +/**************************************************************************/ + +#include +#include "unity.h" +#include "errors.h" +#include "type_helper.h" + +#include "mock_osal.h" +#include "usbh.h" +#include "usbh_hcd.h" +#include "mock_hcd.h" +#include "usbh_hcd.h" + +#include "mock_tusb_callback.h" +#include "mock_hid_host.h" +#include "host_helper.h" + +uint8_t dev_addr; +void setUp(void) +{ + dev_addr = RANDOM(TUSB_CFG_HOST_DEVICE_MAX)+1; +} + +void tearDown(void) +{ +} + +//--------------------------------------------------------------------+ +// get_status +//--------------------------------------------------------------------+ +void test_usbh_status_get_fail(void) +{ + usbh_devices[dev_addr].state = 0; + + TEST_ASSERT_EQUAL( TUSB_DEVICE_STATE_INVALID_PARAMETER, tusbh_device_get_state(TUSB_CFG_HOST_DEVICE_MAX+1) ); + TEST_ASSERT_EQUAL( TUSB_DEVICE_STATE_UNPLUG, tusbh_device_get_state(dev_addr) ); +} + +void test_usbh_status_get_succeed(void) +{ + usbh_devices[dev_addr].state = TUSB_DEVICE_STATE_CONFIGURED; + TEST_ASSERT_EQUAL( TUSB_DEVICE_STATE_CONFIGURED, tusbh_device_get_state(dev_addr) ); +} + +//--------------------------------------------------------------------+ +// Init +//--------------------------------------------------------------------+ +void test_usbh_init_hcd_failed(void) +{ + hcd_init_IgnoreAndReturn(TUSB_ERROR_HCD_FAILED); + TEST_ASSERT_EQUAL(TUSB_ERROR_HCD_FAILED, usbh_init()); +} + +void test_usbh_init_enum_task_create_failed(void) +{ + hcd_init_ExpectAndReturn(TUSB_ERROR_NONE); + osal_task_create_IgnoreAndReturn(TUSB_ERROR_OSAL_TASK_FAILED); + TEST_ASSERT_EQUAL(TUSB_ERROR_OSAL_TASK_FAILED, usbh_init()); +} + +void test_usbh_init_enum_queue_create_failed(void) +{ + hcd_init_ExpectAndReturn(TUSB_ERROR_NONE); + osal_task_create_IgnoreAndReturn(TUSB_ERROR_NONE); + osal_queue_create_IgnoreAndReturn(NULL); + TEST_ASSERT_EQUAL(TUSB_ERROR_OSAL_QUEUE_FAILED, usbh_init()); +} + +void test_usbh_init_semaphore_create_failed(void) +{ + hcd_init_ExpectAndReturn(TUSB_ERROR_NONE); + osal_task_create_IgnoreAndReturn(TUSB_ERROR_NONE); + osal_queue_create_IgnoreAndReturn((osal_queue_handle_t) 0x1234); + osal_semaphore_create_IgnoreAndReturn(NULL); + TEST_ASSERT_EQUAL(TUSB_ERROR_OSAL_SEMAPHORE_FAILED, usbh_init()); +} + +void test_usbh_init_mutex_create_failed(void) +{ + hcd_init_ExpectAndReturn(TUSB_ERROR_NONE); + osal_task_create_IgnoreAndReturn(TUSB_ERROR_NONE); + osal_queue_create_IgnoreAndReturn((osal_queue_handle_t) 0x1234); + osal_semaphore_create_IgnoreAndReturn((osal_semaphore_handle_t) 0x1234); + osal_mutex_create_IgnoreAndReturn(NULL); + TEST_ASSERT_EQUAL(TUSB_ERROR_OSAL_MUTEX_FAILED, usbh_init()); +} + +void test_usbh_init_ok(void) +{ + hcd_init_ExpectAndReturn(TUSB_ERROR_NONE); + + helper_usbh_init_expect(); + helper_class_init_expect(); + + //------------- code under test -------------// + TEST_ASSERT_EQUAL(TUSB_ERROR_NONE, usbh_init()); + + for (uint8_t i=0; i +#include +#include +#include "unity.h" +#include "CException.h" +#include "binary.h" +#include "common/assertion.h" +#include "errors.h" + +CEXCEPTION_T e; + +void setUp(void) +{ + e = 0; +} + +void tearDown(void) +{ +} + +//--------------------------------------------------------------------+ +// Error Status +//--------------------------------------------------------------------+ +void test_assert_status(void) +{ + Try + { + ASSERT_STATUS(TUSB_ERROR_NONE); + ASSERT_STATUS(TUSB_ERROR_INVALID_PARA); + } + Catch (e) + { + } +} + +//--------------------------------------------------------------------+ +// Logical +//--------------------------------------------------------------------+ +void test_assert_logical_true(void) +{ + Try + { + ASSERT (true , __LINE__); + ASSERT_TRUE (true , __LINE__); + ASSERT_TRUE (false, 0); + } + Catch(e) + { + TEST_ASSERT_EQUAL(0, e); + } +} + +void test_assert_logical_false(void) +{ + Try + { + ASSERT_FALSE (false, __LINE__); + ASSERT_FALSE (true , 0); + } + Catch(e) + { + TEST_ASSERT_EQUAL(0, e); + } +} +//--------------------------------------------------------------------+ +// Pointer +//--------------------------------------------------------------------+ +void test_assert_pointer_not_null(void) +{ + uint32_t n; + + Try + { + ASSERT_PTR_NOT_NULL(&n, __LINE__); + ASSERT_PTR(&n, __LINE__); + ASSERT_PTR(NULL, 0); + } + Catch(e) + { + TEST_ASSERT_EQUAL(0, e); + } +} + +void test_assert_pointer_null(void) +{ + uint32_t n; + + Try + { + ASSERT_PTR_NULL(NULL, __LINE__); + ASSERT_PTR_NULL(&n, 0); + } + Catch(e) + { + TEST_ASSERT_EQUAL(0, e); + } +} + +//--------------------------------------------------------------------+ +// Integer +//--------------------------------------------------------------------+ +void test_assert_int_eqal(void) +{ + Try + { + ASSERT_INT (1, 1, __LINE__); + ASSERT_INT_EQUAL (1, 1, __LINE__); + + // test side effect + uint32_t x = 0; + uint32_t y = 0; + ASSERT_INT (x++, y++, __LINE__); + TEST_ASSERT_EQUAL(1, x); + TEST_ASSERT_EQUAL(1, y); + + ASSERT_INT (1, 0, 0); + } + Catch(e) + { + TEST_ASSERT_EQUAL(0, e); + } +} + +void test_assert_int_within(void) +{ + Try + { + ASSERT_INT_WITHIN (1, 5, 3, __LINE__); + ASSERT_INT_WITHIN (1, 5, 1, __LINE__); + ASSERT_INT_WITHIN (1, 5, 5, __LINE__); + + ASSERT_INT_WITHIN (1, 5, 0, 0); + ASSERT_INT_WITHIN (1, 5, 10, 0); + } + Catch(e) + { + TEST_ASSERT_EQUAL(0, e); + } +} + +void test_assert_int_within_greater(void) +{ + Try + { + ASSERT_INT_WITHIN (1, 5, 10, 0); + } + Catch(e) + { + TEST_ASSERT_EQUAL(0, e); + } + +} + +void test_assert_int_within_less(void) +{ + Try + { + ASSERT_INT_WITHIN (1, 5, 0, 0); + } + Catch(e) + { + TEST_ASSERT_EQUAL(0, e); + } + +} + +//--------------------------------------------------------------------+ +// HEX +//--------------------------------------------------------------------+ +void test_assert_hex_equal(void) +{ + Try + { + ASSERT_HEX (0xffee, 0xffee, __LINE__); + ASSERT_HEX_EQUAL (0xffee, 0xffee, __LINE__); + + // test side effect + uint32_t x = 0xf0f0; + uint32_t y = 0xf0f0; + ASSERT_HEX (x++, y++, __LINE__); + TEST_ASSERT_EQUAL(0xf0f1, x); + TEST_ASSERT_EQUAL(0xf0f1, y); + + ASSERT_HEX(0x1234, 0x4321, 0); + } + Catch(e) + { + TEST_ASSERT_EQUAL(0, e); + } +} + +void test_assert_hex_within(void) +{ + Try + { + ASSERT_HEX_WITHIN (0xff00, 0xffff, 0xff11, __LINE__); + ASSERT_HEX_WITHIN (0xff00, 0xffff, 0xff00, __LINE__); + ASSERT_HEX_WITHIN (0xff00, 0xffff, 0xffff, __LINE__); + } + Catch (e) + { + TEST_ASSERT_EQUAL(0, e); + } +} + +void test_assert_hex_within_less(void) +{ + Try + { + ASSERT_HEX_WITHIN (0xff00, 0xffff, 0xeeee, 0); + } + Catch(e) + { + TEST_ASSERT_EQUAL(0, e); + } +} + +void test_assert_hex_within_greater(void) +{ + Try + { + ASSERT_HEX_WITHIN (0xff00, 0xffff, 0x1eeee, 0); + } + Catch(e) + { + TEST_ASSERT_EQUAL(0, e); + } +} + +//--------------------------------------------------------------------+ +// BIN +//--------------------------------------------------------------------+ +void test_assert_bin_equal(void) +{ + Try + { + ASSERT_BIN8 (BIN8(11110000), BIN8(11110000), __LINE__); + ASSERT_BIN8_EQUAL (BIN8(00001111), BIN8(00001111), __LINE__); + + // test side effect + uint32_t x = BIN8(11001100); + uint32_t y = BIN8(11001100); + ASSERT_BIN8 (x++, y++, __LINE__); + TEST_ASSERT_EQUAL(BIN8(11001101), x); + TEST_ASSERT_EQUAL(BIN8(11001101), y); + + ASSERT_BIN8(BIN8(11001111), BIN8(11111100), 0); + } + Catch(e) + { + TEST_ASSERT_EQUAL(0, e); + } +} + + + + + diff --git a/tests/lpc18xx_43xx/test/test_binary_const.c b/tests/lpc18xx_43xx/test/test_binary_const.c new file mode 100644 index 000000000..5d69c994f --- /dev/null +++ b/tests/lpc18xx_43xx/test/test_binary_const.c @@ -0,0 +1,90 @@ +/**************************************************************************/ +/*! + @file test_binary_const.c + @author hathach (tinyusb.org) + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2013, hathach (tinyusb.org) + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + This file is part of the tinyusb stack. +*/ +/**************************************************************************/ + +#include +#include "unity.h" +#include "common/binary.h" + +void setUp(void) +{ +} + +void tearDown(void) +{ +} + +void test_binary_8() +{ + TEST_ASSERT_EQUAL_HEX8(0x00, BIN8(00000000)); + TEST_ASSERT_EQUAL_HEX8(0x01, BIN8(00000001)); + TEST_ASSERT_EQUAL_HEX8(0x02, BIN8(00000010)); + TEST_ASSERT_EQUAL_HEX8(0x04, BIN8(00000100)); + TEST_ASSERT_EQUAL_HEX8(0x08, BIN8(00001000)); + TEST_ASSERT_EQUAL_HEX8(0x10, BIN8(00010000)); + TEST_ASSERT_EQUAL_HEX8(0x20, BIN8(00100000)); + TEST_ASSERT_EQUAL_HEX8(0x40, BIN8(01000000)); + TEST_ASSERT_EQUAL_HEX8(0x80, BIN8(10000000)); + + TEST_ASSERT_EQUAL_HEX8(0x0f, BIN8(00001111)); + TEST_ASSERT_EQUAL_HEX8(0xf0, BIN8(11110000)); + TEST_ASSERT_EQUAL_HEX8(0xff, BIN8(11111111)); +} + +void test_binary_16() +{ + TEST_ASSERT_EQUAL_HEX16(0x0000, BIN16(00000000, 00000000)); + TEST_ASSERT_EQUAL_HEX16(0x000f, BIN16(00000000, 00001111)); + TEST_ASSERT_EQUAL_HEX16(0x00f0, BIN16(00000000, 11110000)); + TEST_ASSERT_EQUAL_HEX16(0x0f00, BIN16(00001111, 00000000)); + TEST_ASSERT_EQUAL_HEX16(0xf000, BIN16(11110000, 00000000)); + TEST_ASSERT_EQUAL_HEX16(0xffff, BIN16(11111111, 11111111)); +} + +void test_binary_32() +{ + TEST_ASSERT_EQUAL_HEX32(0x00000000, BIN32(00000000, 00000000, 00000000, 00000000)); + TEST_ASSERT_EQUAL_HEX32(0x0000000f, BIN32(00000000, 00000000, 00000000, 00001111)); + TEST_ASSERT_EQUAL_HEX32(0x000000f0, BIN32(00000000, 00000000, 00000000, 11110000)); + TEST_ASSERT_EQUAL_HEX32(0x00000f00, BIN32(00000000, 00000000, 00001111, 00000000)); + TEST_ASSERT_EQUAL_HEX32(0x0000f000, BIN32(00000000, 00000000, 11110000, 00000000)); + TEST_ASSERT_EQUAL_HEX32(0x000f0000, BIN32(00000000, 00001111, 00000000, 00000000)); + TEST_ASSERT_EQUAL_HEX32(0x00f00000, BIN32(00000000, 11110000, 00000000, 00000000)); + TEST_ASSERT_EQUAL_HEX32(0x0f000000, BIN32(00001111, 00000000, 00000000, 00000000)); + TEST_ASSERT_EQUAL_HEX32(0xf0000000, BIN32(11110000, 00000000, 00000000, 00000000)); + TEST_ASSERT_EQUAL_HEX32(0xffffffff, BIN32(11111111, 11111111, 11111111, 11111111)); +} diff --git a/tests/lpc18xx_43xx/test/test_fifo.c b/tests/lpc18xx_43xx/test/test_fifo.c new file mode 100644 index 000000000..f9ae2c59f --- /dev/null +++ b/tests/lpc18xx_43xx/test/test_fifo.c @@ -0,0 +1,98 @@ +/**************************************************************************/ +/*! + @file test_fifo.c + @author hathach (tinyusb.org) + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2013, hathach (tinyusb.org) + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + This file is part of the tinyusb stack. +*/ +/**************************************************************************/ + +#include "unity.h" +#include "fifo.h" + +#define FIFO_SIZE 10 +static fifo_t ff; +static uint8_t buffer[FIFO_SIZE]; + +void setUp(void) +{ + fifo_init(&ff, buffer, FIFO_SIZE, 0); +} + +void tearDown(void) +{ + memset(&ff, 0, sizeof(fifo_t)); +} +void test_create_null(void) +{ + memset(&ff, 0, sizeof(fifo_t)); // clear fifo to test null created + TEST_ASSERT_FALSE( fifo_init(&ff, buffer, 0, 0) ); + TEST_ASSERT_TRUE( fifo_init(&ff, buffer, 1, 0) ); +} + +void test_normal(void) +{ + uint8_t i; + + for(i=0; i < FIFO_SIZE; i++) + { + fifo_write(&ff, i); + } + + for(i=0; i < FIFO_SIZE; i++) + { + uint8_t c; + fifo_read(&ff, &c); + TEST_ASSERT_EQUAL(i, c); + } +} + +void test_is_empty(void) +{ + TEST_ASSERT_TRUE(fifo_is_empty(&ff)); + fifo_write(&ff, 1); + TEST_ASSERT_FALSE(fifo_is_empty(&ff)); +} + +void test_is_full(void) +{ + uint8_t i; + + TEST_ASSERT_FALSE(fifo_is_full(&ff)); + + for(i=0; i < FIFO_SIZE; i++) + { + fifo_write(&ff, i); + } + + TEST_ASSERT_TRUE(fifo_is_full(&ff)); +} diff --git a/tests/lpc18xx_43xx/test/test_osal_freeRTOS.c b/tests/lpc18xx_43xx/test/test_osal_freeRTOS.c new file mode 100644 index 000000000..b22797e55 --- /dev/null +++ b/tests/lpc18xx_43xx/test/test_osal_freeRTOS.c @@ -0,0 +1,85 @@ +/**************************************************************************/ +/*! + @file test_osal_freeRTOS.c + @author hathach (tinyusb.org) + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2013, hathach (tinyusb.org) + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + This file is part of the tinyusb stack. +*/ +/**************************************************************************/ + +#include "unity.h" +#include "errors.h" +//#include "freeRTOS.h" +//#include "osal_freeRTOS.h" +//#include "mock_task.h" +//#include "queue.h" +//#include "mock_portmacro.h" +//#include "mock_portable.h" +//#include "mock_list.h" +// +//#define QUEUE_DEPTH 10 +// +//uint32_t statements[10]; +// +//OSAL_SEM_DEF(sem); +//osal_semaphore_handle_t sem_hdl; +// +//OSAL_QUEUE_DEF(queue, QUEUE_DEPTH, uin32_t); +//osal_queue_handle_t queue_hdl; + +void setUp(void) +{ +// memset(statements, 0, sizeof(statements)); +// sem_hdl = osal_semaphore_create(OSAL_SEM_REF(sem)); +// queue_hdl = osal_queue_create(&queue); +} + +void tearDown(void) +{ + +} + +void test_(void) +{ + tusb_error_t error = TUSB_ERROR_NONE; + uint32_t data; + +// TEST_IGNORE(); +// +// osal_semaphore_post(sem_hdl); +// osal_semaphore_wait(sem_hdl, OSAL_TIMEOUT_WAIT_FOREVER, &error); +// +// uint32_t item = 0x1234; +// osal_queue_send(queue_hdl, &item); +// osal_queue_receive(queue_hdl, &data, OSAL_TIMEOUT_NORMAL, &error); + +} diff --git a/tests/lpc18xx_43xx/test/test_osal_none.c b/tests/lpc18xx_43xx/test/test_osal_none.c new file mode 100644 index 000000000..46e7d090d --- /dev/null +++ b/tests/lpc18xx_43xx/test/test_osal_none.c @@ -0,0 +1,434 @@ +/**************************************************************************/ +/*! + @file test_osal_none.c + @author hathach (tinyusb.org) + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2013, hathach (tinyusb.org) + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + This file is part of the tinyusb stack. +*/ +/**************************************************************************/ + +#ifdef TUSB_CFG_OS +#undef TUSB_CFG_OS +#endif + +#include "unity.h" +#include "errors.h" +#include "osal_none.h" + +#define QUEUE_DEPTH 10 + +uint32_t statements[10]; + +OSAL_SEM_DEF(sem); +osal_semaphore_handle_t sem_hdl; + +OSAL_QUEUE_DEF(queue, QUEUE_DEPTH, uint32_t); +osal_queue_handle_t queue_hdl; + +OSAL_MUTEX_DEF(mutex); +osal_mutex_handle_t mutex_hdl; + +void setUp(void) +{ + memset(statements, 0, sizeof(statements)); + sem_hdl = osal_semaphore_create(OSAL_SEM_REF(sem)); + queue_hdl = osal_queue_create(&queue); + mutex_hdl = osal_mutex_create(OSAL_MUTEX_REF(mutex)); +} + +void tearDown(void) +{ + +} + +//--------------------------------------------------------------------+ +// Semaphore +//--------------------------------------------------------------------+ +void test_semaphore_create(void) +{ + TEST_ASSERT_EQUAL_PTR(&sem, sem_hdl); + TEST_ASSERT_EQUAL(0, sem); +} + +void test_semaphore_post(void) +{ + osal_semaphore_post(sem_hdl); + TEST_ASSERT_EQUAL(1, sem); +} +// blocking service such as semaphore wait need to be invoked within a task's loop + +//--------------------------------------------------------------------+ +// Mutex +//--------------------------------------------------------------------+ +void test_mutex_create(void) +{ + TEST_ASSERT_EQUAL_PTR(&mutex, mutex_hdl); + TEST_ASSERT_EQUAL(1, mutex); +} + +void test_mutex_release(void) +{ + osal_mutex_release(mutex_hdl); + TEST_ASSERT_EQUAL(1, mutex); +} + +//--------------------------------------------------------------------+ +// Queue +//--------------------------------------------------------------------+ +void test_queue_create(void) +{ + TEST_ASSERT_EQUAL_PTR(&queue, queue_hdl); + TEST_ASSERT_EQUAL(QUEUE_DEPTH, queue_hdl->depth); + TEST_ASSERT_EQUAL_PTR(queue_buffer, queue_hdl->buffer); + TEST_ASSERT_EQUAL(0, queue_hdl->count); + TEST_ASSERT_EQUAL(0, queue_hdl->wr_idx); + TEST_ASSERT_EQUAL(0, queue_hdl->rd_idx); +} + +void test_queue_send(void) +{ + uint32_t const item = 0x1234; + osal_queue_send(queue_hdl, &item); + TEST_ASSERT_EQUAL(1, queue_hdl->count); + TEST_ASSERT_EQUAL_MEMORY(&item, queue_hdl->buffer + (queue_hdl->rd_idx * queue_hdl->item_size), 4); +} +// blocking service such as semaphore wait need to be invoked within a task's loop + +//--------------------------------------------------------------------+ +// TASK SEMAPHORE +//--------------------------------------------------------------------+ +tusb_error_t sample_task_semaphore(void) +{ + tusb_error_t error = TUSB_ERROR_NONE; + + OSAL_TASK_LOOP_BEGIN + + statements[0]++; + + osal_semaphore_wait(sem_hdl, OSAL_TIMEOUT_WAIT_FOREVER, &error); + statements[1]++; + + osal_semaphore_wait(sem_hdl, OSAL_TIMEOUT_WAIT_FOREVER, &error); + statements[2]++; + + osal_semaphore_wait(sem_hdl, OSAL_TIMEOUT_WAIT_FOREVER, &error); + statements[3]++; + + osal_semaphore_wait(sem_hdl, OSAL_TIMEOUT_NORMAL, &error); + statements[4]++; + TEST_ASSERT_EQUAL(TUSB_ERROR_OSAL_TIMEOUT, error); + + OSAL_TASK_LOOP_END +} + +void test_task_with_semaphore(void) +{ + // several invoke before sempahore is available + for(uint32_t i=0; i<10; i++) + sample_task_semaphore(); + TEST_ASSERT_EQUAL(1, statements[0]); + + // invoke after posting semaphore + osal_semaphore_post(sem_hdl); + sample_task_semaphore(); + TEST_ASSERT_EQUAL(1, statements[1]); + + // post 2 consecutive times + osal_semaphore_post(sem_hdl); + osal_semaphore_post(sem_hdl); + sample_task_semaphore(); + TEST_ASSERT_EQUAL(1, statements[2]); + TEST_ASSERT_EQUAL(1, statements[3]); + + // timeout + for(uint32_t i=0; i<(OSAL_TIMEOUT_NORMAL*TUSB_CFG_OS_TICKS_PER_SECOND)/1000 ; i++) // not enough time + osal_tick_tock(); + sample_task_semaphore(); + TEST_ASSERT_EQUAL(0, statements[4]); + osal_tick_tock(); + sample_task_semaphore(); + + // reach end of task loop, back to beginning + sample_task_semaphore(); + TEST_ASSERT_EQUAL(2, statements[0]); +} + +//--------------------------------------------------------------------+ +// TASK MUTEX +//--------------------------------------------------------------------+ +tusb_error_t mutex_sample_task1(void) // occupy mutex and not release it +{ + tusb_error_t error = TUSB_ERROR_NONE; + + OSAL_TASK_LOOP_BEGIN + + statements[0]++; + + osal_mutex_wait(mutex_hdl, OSAL_TIMEOUT_WAIT_FOREVER, &error); + statements[2]++; + + OSAL_TASK_LOOP_END +} + +tusb_error_t mutex_sample_task2(void) +{ + tusb_error_t error = TUSB_ERROR_NONE; + + OSAL_TASK_LOOP_BEGIN + + statements[1]++; + + osal_mutex_wait(mutex_hdl, OSAL_TIMEOUT_WAIT_FOREVER, &error); + statements[3]++; + + osal_mutex_wait(mutex_hdl, OSAL_TIMEOUT_NORMAL, &error); + statements[5]++; + + TEST_ASSERT_EQUAL(TUSB_ERROR_OSAL_TIMEOUT, error); + + OSAL_TASK_LOOP_END +} + +void test_task_with_mutex(void) +{ + // several invoke before mutex is available + mutex_sample_task1(); + for(uint32_t i=0; i<10; i++) { + mutex_sample_task2(); + } + + TEST_ASSERT_EQUAL(1, statements[0]); + TEST_ASSERT_EQUAL(1, statements[2]); + + TEST_ASSERT_EQUAL(1, statements[1]); + TEST_ASSERT_EQUAL(0, statements[3]); + + // invoke after posting mutex + osal_mutex_release(mutex_hdl); + for(uint32_t i=0; i<10; i++) { + mutex_sample_task2(); + } + TEST_ASSERT_EQUAL(1, statements[3]); + TEST_ASSERT_EQUAL(0, statements[5]); + + // timeout + for(uint32_t i=0; i<(OSAL_TIMEOUT_NORMAL*TUSB_CFG_OS_TICKS_PER_SECOND)/1000 ; i++){ // one tick less + osal_tick_tock(); + } + mutex_sample_task2(); + TEST_ASSERT_EQUAL(0, statements[5]); + osal_tick_tock(); + + mutex_sample_task2(); + TEST_ASSERT_EQUAL(1, statements[5]); +} + +//--------------------------------------------------------------------+ +// TASK QUEUE +//--------------------------------------------------------------------+ +tusb_error_t sample_task_with_queue(void) +{ + uint32_t data; + tusb_error_t error; + + OSAL_TASK_LOOP_BEGIN + + statements[0]++; + + osal_queue_receive(queue_hdl, &data, OSAL_TIMEOUT_WAIT_FOREVER, &error); + TEST_ASSERT_EQUAL(0x1111, data); + statements[1]++; + + osal_queue_receive(queue_hdl, &data, OSAL_TIMEOUT_WAIT_FOREVER, &error); + TEST_ASSERT_EQUAL(0x2222, data); + statements[2]++; + + osal_queue_receive(queue_hdl, &data, OSAL_TIMEOUT_WAIT_FOREVER, &error); + TEST_ASSERT_EQUAL(0x3333, data); + statements[3]++; + + osal_queue_receive(queue_hdl, &data, OSAL_TIMEOUT_NORMAL, &error); + statements[4]++; + TEST_ASSERT_EQUAL(TUSB_ERROR_OSAL_TIMEOUT, error); + + OSAL_TASK_LOOP_END +} + +void test_task_with_queue(void) +{ + uint32_t i = 0; + uint32_t item; + + sample_task_with_queue(); + // several invoke before queue is available + for(i=0; i<10; i++) + sample_task_with_queue(); + TEST_ASSERT_EQUAL(1, statements[0]); + + // invoke after sending to queue + item = 0x1111; + osal_queue_send(queue_hdl, &item); + sample_task_with_queue(); + TEST_ASSERT_EQUAL(1, statements[1]); + sample_task_with_queue(); + TEST_ASSERT_EQUAL(1, statements[1]); + + item = 0x2222; + osal_queue_send(queue_hdl, &item); + item = 0x3333; + osal_queue_send(queue_hdl, &item); + sample_task_with_queue(); + TEST_ASSERT_EQUAL(1, statements[2]); + TEST_ASSERT_EQUAL(1, statements[3]); + + // timeout + for(uint32_t i=0; i<(OSAL_TIMEOUT_NORMAL*TUSB_CFG_OS_TICKS_PER_SECOND)/1000 ; i++) // not enough time + osal_tick_tock(); + sample_task_with_queue(); + TEST_ASSERT_EQUAL(0, statements[4]); + osal_tick_tock(); + sample_task_with_queue(); + + // reach end of task loop, back to beginning + sample_task_with_queue(); + TEST_ASSERT_EQUAL(2, statements[0]); +} + +//--------------------------------------------------------------------+ +// TASK DELAY +//--------------------------------------------------------------------+ +tusb_error_t sample_task_with_delay(void) +{ + tusb_error_t error; + + OSAL_TASK_LOOP_BEGIN + + osal_task_delay(1000); + + statements[0]++; + + OSAL_TASK_LOOP_END +} + +void test_task_with_delay(void) +{ + sample_task_with_delay(); + TEST_ASSERT_EQUAL(0, statements[0]); + + for(uint32_t i=0; i %w[ test:all release ] diff --git a/tests/test/test/device/usbd/test_usbd.c b/tests/test/test/device/usbd/test_usbd.c deleted file mode 100644 index c241fa5a1..000000000 --- a/tests/test/test/device/usbd/test_usbd.c +++ /dev/null @@ -1,136 +0,0 @@ -/**************************************************************************/ -/*! - @file test_usbd.c - @author hathach (tinyusb.org) - - @section LICENSE - - Software License Agreement (BSD License) - - Copyright (c) 2013, hathach (tinyusb.org) - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - 3. Neither the name of the copyright holders nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY - EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY - DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - This file is part of the tinyusb stack. -*/ -/**************************************************************************/ - -#include -#include "unity.h" -#include "errors.h" -#include "type_helper.h" - -#include "tusb_descriptors.h" - -#include "usbd.h" -#include "mock_dcd.h" -#include "mock_hid_device.h" - -void setUp(void) -{ - -} - -void tearDown(void) -{ -} - -void test_dcd_init_failed(void) -{ - dcd_init_ExpectAndReturn(TUSB_ERROR_FAILED); - - //------------- Code Under Test -------------// - TEST_ASSERT_EQUAL( TUSB_ERROR_FAILED, usbd_init() ); -} - -tusb_error_t stub_hidd_init(tusb_descriptor_interface_t const* p_interface_desc, uint16_t* p_length, int num_call) -{ - printf("hidd_init num_call = %d\n", num_call); - switch(num_call) - { - case 0: - TEST_ASSERT_EQUAL_HEX32(&app_tusb_desc_configuration.keyboard_interface, p_interface_desc); - break; - - case 1: - TEST_ASSERT_EQUAL_HEX32(&app_tusb_desc_configuration.mouse_interface, p_interface_desc); - break; - - case 2: - break; - - default: - return TUSB_ERROR_HIDD_DESCRIPTOR_INTERFACE; - } - - return TUSB_ERROR_NONE; -} - -void test_usbd_init_ok(void) -{ - TEST_IGNORE_MESSAGE("pause device stack"); - dcd_init_ExpectAndReturn(TUSB_ERROR_NONE); - - hidd_init_StubWithCallback(stub_hidd_init); - - dcd_controller_connect_Expect(0); - - //------------- Code Under Test -------------// - TEST_ASSERT_EQUAL( TUSB_ERROR_NONE, usbd_init() ); - -} - -void test_usbd_string_descriptor(void) -{ - dcd_init_IgnoreAndReturn(TUSB_ERROR_FAILED); - - //------------- Code Under Test -------------// - TEST_ASSERT_EQUAL( TUSB_ERROR_FAILED, usbd_init() ); - - - //------------- manufacturer string descriptor -------------// - uint32_t const manufacturer_len = sizeof(TUSB_CFG_DEVICE_STRING_MANUFACTURER) - 1; - TEST_ASSERT_EQUAL(manufacturer_len*2 + 2, app_tusb_desc_strings.manufacturer.bLength); - for(uint32_t i=0; i -#include "unity.h" -#include "type_helper.h" -#include "tusb_option.h" -#include "errors.h" -#include "binary.h" - -#include "hal.h" -#include "hcd.h" -#include "ehci.h" - -#include "ehci_controller_fake.h" -#include "mock_osal.h" -#include "mock_usbh_hcd.h" - -usbh_device_info_t usbh_devices[TUSB_CFG_HOST_DEVICE_MAX+1]; - -static uint8_t hostid; - -//--------------------------------------------------------------------+ -// Setup/Teardown + helper declare -//--------------------------------------------------------------------+ -void setUp(void) -{ - ehci_controller_init(); - TEST_ASSERT_STATUS( hcd_init() ); - - hostid = RANDOM(CONTROLLER_HOST_NUMBER) + TEST_CONTROLLER_HOST_START_INDEX; -} - -void tearDown(void) -{ -} - -//--------------------------------------------------------------------+ -// Initialization -//--------------------------------------------------------------------+ -void test_hcd_init_data(void) -{ - //------------- check memory data -------------// - TEST_ASSERT_MEM_ZERO(&ehci_data.device, sizeof(ehci_data.device)); - TEST_ASSERT_MEM_ZERO(ehci_data.addr0_qtd, sizeof(ehci_qtd_t)*3); -} - -void test_hcd_init_usbint(void) -{ - ehci_registers_t* const regs = get_operational_register(hostid); - - //------------- USB INT Enable-------------// - TEST_ASSERT(regs->usb_int_enable_bit.usb_error); - TEST_ASSERT(regs->usb_int_enable_bit.port_change_detect); - TEST_ASSERT(regs->usb_int_enable_bit.async_advance); - - TEST_ASSERT_FALSE(regs->usb_int_enable_bit.framelist_rollover); - TEST_ASSERT_FALSE(regs->usb_int_enable_bit.pci_host_system_error); - - TEST_ASSERT_FALSE(regs->usb_int_enable_bit.nxp_int_sof); - TEST_ASSERT_FALSE(regs->usb_int_enable_bit.usb); - TEST_ASSERT_TRUE(regs->usb_int_enable_bit.nxp_int_async); - TEST_ASSERT_TRUE(regs->usb_int_enable_bit.nxp_int_period); - - // TODO to be portable use usbint instead of nxp int async/period -} - -void test_hcd_init_async_list(void) -{ - ehci_registers_t * const regs = get_operational_register(hostid); - ehci_qhd_t * const async_head = get_async_head(hostid); - - TEST_ASSERT_EQUAL_HEX(async_head, regs->async_list_base); - - TEST_ASSERT_EQUAL_HEX(async_head, align32( (uint32_t) async_head) ); - TEST_ASSERT_EQUAL(EHCI_QUEUE_ELEMENT_QHD, async_head->next.type); - TEST_ASSERT_FALSE(async_head->next.terminate); - - TEST_ASSERT(async_head->head_list_flag); - TEST_ASSERT(async_head->qtd_overlay.halted); -} - -void check_qhd_endpoint_link(ehci_link_t *p_prev, ehci_qhd_t *p_qhd) -{ - //------------- period list check -------------// - TEST_ASSERT_EQUAL_HEX((uint32_t) p_qhd, align32(p_prev->address)); - TEST_ASSERT_FALSE(p_prev->terminate); - TEST_ASSERT_EQUAL(EHCI_QUEUE_ELEMENT_QHD, p_prev->type); -} - -void test_hcd_init_period_list(void) -{ -#if EHCI_PERIODIC_LIST - ehci_registers_t* const regs = get_operational_register(hostid); - ehci_qhd_t * const period_head_arr = get_period_head(hostid, 1); - ehci_link_t * const framelist = get_period_frame_list(hostid); - - TEST_ASSERT_EQUAL_HEX( (uint32_t) framelist, regs->periodic_list_base); - - check_qhd_endpoint_link( framelist+0, period_head_arr+1); - check_qhd_endpoint_link( framelist+2, period_head_arr+1); - check_qhd_endpoint_link( framelist+4, period_head_arr+1); - check_qhd_endpoint_link( framelist+6, period_head_arr+1); - - check_qhd_endpoint_link( framelist+1, period_head_arr+2); - check_qhd_endpoint_link( framelist+5, period_head_arr+2); - - check_qhd_endpoint_link( framelist+3, period_head_arr+3); - check_qhd_endpoint_link( framelist+7, period_head_arr); - check_qhd_endpoint_link( (ehci_link_t*) (period_head_arr+1), period_head_arr); - check_qhd_endpoint_link( (ehci_link_t*) (period_head_arr+2), period_head_arr); - check_qhd_endpoint_link( (ehci_link_t*) (period_head_arr+3), period_head_arr); - - for(uint32_t i=0; i<4; i++) - { - TEST_ASSERT(period_head_arr[i].interrupt_smask); - TEST_ASSERT(period_head_arr[i].qtd_overlay.halted); - } - - TEST_ASSERT_TRUE(period_head_arr[0].next.terminate); -#endif -} - -void test_hcd_init_tt_control(void) -{ - ehci_registers_t* const regs = get_operational_register(hostid); -} - -void test_hcd_init_usbcmd(void) -{ - ehci_registers_t* const regs = get_operational_register(hostid); - - TEST_ASSERT(regs->usb_cmd_bit.async_enable); - -#if EHCI_PERIODIC_LIST - TEST_ASSERT(regs->usb_cmd_bit.periodic_enable); -#else - TEST_ASSERT_FALSE(regs->usb_cmd_bit.periodic_enable); -#endif - - //------------- Framelist size (NXP specific) -------------// - TEST_ASSERT_BITS(BIN8(11), EHCI_CFG_FRAMELIST_SIZE_BITS, regs->usb_cmd_bit.framelist_size); - TEST_ASSERT_EQUAL(EHCI_CFG_FRAMELIST_SIZE_BITS >> 2, regs->usb_cmd_bit.nxp_framelist_size_msb); -} - -void test_hcd_init_portsc(void) -{ - TEST_IGNORE_MESSAGE("more advance stuff need manipulate this register"); -} diff --git a/tests/test/test/host/ehci/test_ehci_isr.c b/tests/test/test/host/ehci/test_ehci_isr.c deleted file mode 100644 index 4f5f040c4..000000000 --- a/tests/test/test/host/ehci/test_ehci_isr.c +++ /dev/null @@ -1,103 +0,0 @@ -/**************************************************************************/ -/*! - @file test_ehci_isr.c - @author hathach (tinyusb.org) - - @section LICENSE - - Software License Agreement (BSD License) - - Copyright (c) 2013, hathach (tinyusb.org) - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - 3. Neither the name of the copyright holders nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY - EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY - DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND - ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - This file is part of the tinyusb stack. -*/ -/**************************************************************************/ - -#include -#include "unity.h" -#include "tusb_option.h" -#include "errors.h" -#include "binary.h" -#include "type_helper.h" - -#include "hal.h" -#include "ehci.h" - -#include "ehci_controller_fake.h" -#include "mock_osal.h" -#include "mock_usbh_hcd.h" - -usbh_device_info_t usbh_devices[TUSB_CFG_HOST_DEVICE_MAX+1]; - -static uint8_t hostid; -static ehci_registers_t * regs; - -void setUp(void) -{ - ehci_controller_init(); - TEST_ASSERT_STATUS( hcd_init()); - - hostid = RANDOM(CONTROLLER_HOST_NUMBER) + TEST_CONTROLLER_HOST_START_INDEX; - regs = get_operational_register(hostid); -} - -void tearDown(void) -{ -} - -void test_isr_device_connect_highspeed(void) -{ - usbh_device_plugged_isr_Expect(hostid); - - //------------- Code Under Test -------------// - ehci_controller_device_plug(hostid, TUSB_SPEED_HIGH); -} - -void test_isr_device_connect_fullspeed(void) -{ - usbh_device_plugged_isr_Expect(hostid); - - //------------- Code Under Test -------------// - ehci_controller_device_plug(hostid, TUSB_SPEED_FULL); -} - -void test_isr_device_connect_slowspeed(void) -{ - usbh_device_plugged_isr_Expect(hostid); - - //------------- Code Under Test -------------// - ehci_controller_device_plug(hostid, TUSB_SPEED_LOW); -} - -void test_isr_device_disconnect(void) -{ - usbh_device_unplugged_isr_Expect(hostid); - - //------------- Code Under Test -------------// - ehci_controller_device_unplug(hostid); - - TEST_ASSERT(regs->usb_cmd_bit.advacne_async); -} diff --git a/tests/test/test/host/ehci/test_ehci_structure.c b/tests/test/test/host/ehci/test_ehci_structure.c deleted file mode 100644 index 3ca2f3e45..000000000 --- a/tests/test/test/host/ehci/test_ehci_structure.c +++ /dev/null @@ -1,304 +0,0 @@ -/**************************************************************************/ -/*! - @file test_ehci_structure.c - @author hathach (tinyusb.org) - - @section LICENSE - - Software License Agreement (BSD License) - - Copyright (c) 2013, hathach (tinyusb.org) - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - 3. Neither the name of the copyright holders nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY - EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY - DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND - ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - This file is part of the tinyusb stack. -*/ -/**************************************************************************/ - -#include -#include "unity.h" -#include "tusb_option.h" -#include "errors.h" -#include "binary.h" -#include "type_helper.h" - -#include "hal.h" -#include "hcd.h" -#include "ehci.h" - -#include "ehci_controller_fake.h" -#include "mock_osal.h" -#include "mock_usbh_hcd.h" - -usbh_device_info_t usbh_devices[TUSB_CFG_HOST_DEVICE_MAX+1]; - -//--------------------------------------------------------------------+ -// Setup/Teardown + helper declare -//--------------------------------------------------------------------+ -void setUp(void) -{ - -} - -void tearDown(void) -{ -} - -//--------------------------------------------------------------------+ -// -//--------------------------------------------------------------------+ -void test_struct_alignment(void) -{ - TEST_ASSERT_EQUAL( 32, __alignof__(ehci_qhd_t) ); -// TEST_ASSERT_EQUAL( 32, __alignof__(ehci_qtd_t) ); ehci_qtd_t is used to declare overlay variable in qhd --> cannot declare with ATTR_ALIGNED(32) - - TEST_ASSERT_EQUAL( 32, __alignof__(ehci_itd_t) ); - TEST_ASSERT_EQUAL( 32, __alignof__(ehci_sitd_t) ); - -} - -void test_struct_size(void) -{ - if (4 < sizeof(void*)) // running tests in x64 environment - { - TEST_ASSERT_EQUAL( 64 - 8, offsetof(ehci_qhd_t, p_qtd_list_head) ); // 64 - 2x 32-bit pointer qtds - }else - { - TEST_ASSERT_EQUAL( 64, sizeof(ehci_qhd_t) ); - } - TEST_ASSERT_EQUAL( 32, sizeof(ehci_qtd_t) ); - - TEST_ASSERT_EQUAL( 64, sizeof(ehci_itd_t) ); - TEST_ASSERT_EQUAL( 32, sizeof(ehci_sitd_t) ); - - TEST_ASSERT_EQUAL( 4, sizeof(ehci_link_t) ); -} - -//--------------------------------------------------------------------+ -// EHCI Data Structure -//--------------------------------------------------------------------+ -void test_qtd_structure(void) -{ - TEST_ASSERT_EQUAL( 0, offsetof(ehci_qtd_t, next)); - TEST_ASSERT_EQUAL( 4, offsetof(ehci_qtd_t, alternate)); - TEST_ASSERT_EQUAL( 5, BITFIELD_OFFSET_OF_UINT32(ehci_qtd_t, 1, used)); - - //------------- Word 2 -------------// - TEST_ASSERT_EQUAL( 0, BITFIELD_OFFSET_OF_UINT32(ehci_qtd_t, 2, pingstate_err) ); - TEST_ASSERT_EQUAL( 1, BITFIELD_OFFSET_OF_UINT32(ehci_qtd_t, 2, non_hs_split_state) ); - TEST_ASSERT_EQUAL( 2, BITFIELD_OFFSET_OF_UINT32(ehci_qtd_t, 2, non_hs_period_missed_uframe)); - TEST_ASSERT_EQUAL( 3, BITFIELD_OFFSET_OF_UINT32(ehci_qtd_t, 2, xact_err) ); - TEST_ASSERT_EQUAL( 4, BITFIELD_OFFSET_OF_UINT32(ehci_qtd_t, 2, babble_err) ); - TEST_ASSERT_EQUAL( 5, BITFIELD_OFFSET_OF_UINT32(ehci_qtd_t, 2, buffer_err) ); - TEST_ASSERT_EQUAL( 6, BITFIELD_OFFSET_OF_UINT32(ehci_qtd_t, 2, halted) ); - TEST_ASSERT_EQUAL( 7, BITFIELD_OFFSET_OF_UINT32(ehci_qtd_t, 2, active) ); - TEST_ASSERT_EQUAL( 8, BITFIELD_OFFSET_OF_UINT32(ehci_qtd_t, 2, pid) ); - TEST_ASSERT_EQUAL( 10, BITFIELD_OFFSET_OF_UINT32(ehci_qtd_t, 2, cerr) ); - TEST_ASSERT_EQUAL( 12, BITFIELD_OFFSET_OF_UINT32(ehci_qtd_t, 2, current_page) ); - TEST_ASSERT_EQUAL( 15, BITFIELD_OFFSET_OF_UINT32(ehci_qtd_t, 2, int_on_complete) ); - TEST_ASSERT_EQUAL( 16, BITFIELD_OFFSET_OF_UINT32(ehci_qtd_t, 2, total_bytes) ); - TEST_ASSERT_EQUAL( 31, BITFIELD_OFFSET_OF_UINT32(ehci_qtd_t, 2, data_toggle) ); - - TEST_ASSERT_EQUAL( 12, offsetof(ehci_qtd_t, buffer)); -} - -void test_qhd_structure(void) -{ - TEST_ASSERT_EQUAL( 0, offsetof(ehci_qhd_t, next)); - - //------------- Word 1 -------------// - TEST_ASSERT_EQUAL( 0, BITFIELD_OFFSET_OF_UINT32(ehci_qhd_t, 1, device_address) ); - TEST_ASSERT_EQUAL( 7, BITFIELD_OFFSET_OF_UINT32(ehci_qhd_t, 1, non_hs_period_inactive_next_xact) ); - TEST_ASSERT_EQUAL( 8, BITFIELD_OFFSET_OF_UINT32(ehci_qhd_t, 1, endpoint_number) ); - TEST_ASSERT_EQUAL( 12, BITFIELD_OFFSET_OF_UINT32(ehci_qhd_t, 1, endpoint_speed) ); - TEST_ASSERT_EQUAL( 14, BITFIELD_OFFSET_OF_UINT32(ehci_qhd_t, 1, data_toggle_control) ); - TEST_ASSERT_EQUAL( 15, BITFIELD_OFFSET_OF_UINT32(ehci_qhd_t, 1, head_list_flag) ); - TEST_ASSERT_EQUAL( 16, BITFIELD_OFFSET_OF_UINT32(ehci_qhd_t, 1, max_package_size) ); - TEST_ASSERT_EQUAL( 27, BITFIELD_OFFSET_OF_UINT32(ehci_qhd_t, 1, non_hs_control_endpoint) ); - TEST_ASSERT_EQUAL( 28, BITFIELD_OFFSET_OF_UINT32(ehci_qhd_t, 1, nak_count_reload) ); - - //------------- Word 2 -------------// - TEST_ASSERT_EQUAL( 0, BITFIELD_OFFSET_OF_UINT32(ehci_qhd_t, 2, interrupt_smask) ); - TEST_ASSERT_EQUAL( 8, BITFIELD_OFFSET_OF_UINT32(ehci_qhd_t, 2, non_hs_interrupt_cmask) ); - TEST_ASSERT_EQUAL( 16, BITFIELD_OFFSET_OF_UINT32(ehci_qhd_t, 2, hub_address) ); - TEST_ASSERT_EQUAL( 23, BITFIELD_OFFSET_OF_UINT32(ehci_qhd_t, 2, hub_port) ); - TEST_ASSERT_EQUAL( 30, BITFIELD_OFFSET_OF_UINT32(ehci_qhd_t, 2, mult) ); - - TEST_ASSERT_EQUAL( 3*4, offsetof(ehci_qhd_t, qtd_addr)); - TEST_ASSERT_EQUAL( 4*4, offsetof(ehci_qhd_t, qtd_overlay)); -} - -void test_itd_structure(void) -{ - TEST_ASSERT_EQUAL( 0, offsetof(ehci_itd_t, next)); - - // Each Transaction Word - TEST_ASSERT_EQUAL( 0 , BITFIELD_OFFSET_OF_MEMBER(ehci_itd_t, xact[0], offset) ); - TEST_ASSERT_EQUAL( 12 , BITFIELD_OFFSET_OF_MEMBER(ehci_itd_t, xact[0], page_select) ); - TEST_ASSERT_EQUAL( 15 , BITFIELD_OFFSET_OF_MEMBER(ehci_itd_t, xact[0], int_on_complete) ); - TEST_ASSERT_EQUAL( 16 , BITFIELD_OFFSET_OF_MEMBER(ehci_itd_t, xact[0], length) ); - TEST_ASSERT_EQUAL( 28 , BITFIELD_OFFSET_OF_MEMBER(ehci_itd_t, xact[0], error) ); - TEST_ASSERT_EQUAL( 29 , BITFIELD_OFFSET_OF_MEMBER(ehci_itd_t, xact[0], babble_err) ); - TEST_ASSERT_EQUAL( 30 , BITFIELD_OFFSET_OF_MEMBER(ehci_itd_t, xact[0], buffer_err) ); - TEST_ASSERT_EQUAL( 31 , BITFIELD_OFFSET_OF_MEMBER(ehci_itd_t, xact[0], active) ); - - TEST_ASSERT_EQUAL( 9*4, offsetof(ehci_itd_t, BufferPointer)); -} - -void test_sitd_structure(void) -{ - TEST_ASSERT_EQUAL( 0, offsetof(ehci_sitd_t, next)); - - //------------- Word 1 -------------// - TEST_ASSERT_EQUAL( 0, BITFIELD_OFFSET_OF_UINT32(ehci_sitd_t, 1, device_address) ); - TEST_ASSERT_EQUAL( 8, BITFIELD_OFFSET_OF_UINT32(ehci_sitd_t, 1, endpoint_number) ); - TEST_ASSERT_EQUAL( 16, BITFIELD_OFFSET_OF_UINT32(ehci_sitd_t, 1, hub_address) ); - TEST_ASSERT_EQUAL( 24, BITFIELD_OFFSET_OF_UINT32(ehci_sitd_t, 1, port_number) ); - TEST_ASSERT_EQUAL( 31, BITFIELD_OFFSET_OF_UINT32(ehci_sitd_t, 1, direction) ); - - //------------- Word 2 -------------// - TEST_ASSERT_EQUAL( 4*2, offsetof(ehci_sitd_t, interrupt_smask)); - TEST_ASSERT_EQUAL( 4*2+1, offsetof(ehci_sitd_t, non_hs_interrupt_cmask)); - - //------------- Word 3 -------------// - TEST_ASSERT_EQUAL( 1, BITFIELD_OFFSET_OF_UINT32(ehci_sitd_t, 3, split_state) ); - TEST_ASSERT_EQUAL( 2, BITFIELD_OFFSET_OF_UINT32(ehci_sitd_t, 3, missed_uframe)); - TEST_ASSERT_EQUAL( 3, BITFIELD_OFFSET_OF_UINT32(ehci_sitd_t, 3, xact_err) ); - TEST_ASSERT_EQUAL( 4, BITFIELD_OFFSET_OF_UINT32(ehci_sitd_t, 3, babble_err) ); - TEST_ASSERT_EQUAL( 5, BITFIELD_OFFSET_OF_UINT32(ehci_sitd_t, 3, buffer_err) ); - TEST_ASSERT_EQUAL( 6, BITFIELD_OFFSET_OF_UINT32(ehci_sitd_t, 3, error) ); - TEST_ASSERT_EQUAL( 7, BITFIELD_OFFSET_OF_UINT32(ehci_sitd_t, 3, active) ); - - TEST_ASSERT_EQUAL( 8, BITFIELD_OFFSET_OF_UINT32(ehci_sitd_t, 3, cmask_progress) ); - TEST_ASSERT_EQUAL( 16, BITFIELD_OFFSET_OF_UINT32(ehci_sitd_t, 3, total_bytes) ); - TEST_ASSERT_EQUAL( 30, BITFIELD_OFFSET_OF_UINT32(ehci_sitd_t, 3, page_select) ); - TEST_ASSERT_EQUAL( 31, BITFIELD_OFFSET_OF_UINT32(ehci_sitd_t, 3, int_on_complete) ); - - //------------- Word 4 -------------// - TEST_ASSERT_EQUAL( 4*4, offsetof(ehci_sitd_t, buffer)); - - TEST_ASSERT_EQUAL( 4*6, offsetof(ehci_sitd_t, back)); -} - -//--------------------------------------------------------------------+ -// EHCI Register Interface -//--------------------------------------------------------------------+ -void test_register_offset(void) -{ - TEST_ASSERT_EQUAL( 0x00, offsetof(ehci_registers_t, usb_cmd)); - TEST_ASSERT_EQUAL( 0x04, offsetof(ehci_registers_t, usb_sts)); - TEST_ASSERT_EQUAL( 0x08, offsetof(ehci_registers_t, usb_int_enable)); - TEST_ASSERT_EQUAL( 0x0C, offsetof(ehci_registers_t, frame_index)); - TEST_ASSERT_EQUAL( 0x10, offsetof(ehci_registers_t, ctrl_ds_seg)); - TEST_ASSERT_EQUAL( 0x14, offsetof(ehci_registers_t, periodic_list_base)); - TEST_ASSERT_EQUAL( 0x18, offsetof(ehci_registers_t, async_list_base)); - TEST_ASSERT_EQUAL( 0x1C, offsetof(ehci_registers_t, tt_control)); // NXP specific - TEST_ASSERT_EQUAL( 0x40, offsetof(ehci_registers_t, config_flag)); // NXP not used - TEST_ASSERT_EQUAL( 0x44, offsetof(ehci_registers_t, portsc)); -} - -void test_register_usbcmd(void) -{ - TEST_ASSERT_EQUAL( 0 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_cmd_bit, run_stop) ); - TEST_ASSERT_EQUAL( 1 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_cmd_bit, reset) ); - TEST_ASSERT_EQUAL( 2 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_cmd_bit, framelist_size) ); - TEST_ASSERT_EQUAL( 4 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_cmd_bit, periodic_enable) ); - TEST_ASSERT_EQUAL( 5 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_cmd_bit, async_enable) ); - TEST_ASSERT_EQUAL( 6 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_cmd_bit, advacne_async) ); - TEST_ASSERT_EQUAL( 7 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_cmd_bit, light_reset) ); - TEST_ASSERT_EQUAL( 8 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_cmd_bit, async_park) ); - TEST_ASSERT_EQUAL( 11 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_cmd_bit, async_park_enable) ); - TEST_ASSERT_EQUAL( 15 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_cmd_bit, nxp_framelist_size_msb) ); - TEST_ASSERT_EQUAL( 16 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_cmd_bit, int_threshold) ); -} - -void test_register_usbsts(void) -{ - TEST_ASSERT_EQUAL( 0 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_sts_bit, usb)); - TEST_ASSERT_EQUAL( 1 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_sts_bit, usb_error)); - TEST_ASSERT_EQUAL( 2 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_sts_bit, port_change_detect)); - TEST_ASSERT_EQUAL( 3 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_sts_bit, framelist_rollover)); - TEST_ASSERT_EQUAL( 4 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_sts_bit, pci_host_system_error)); - TEST_ASSERT_EQUAL( 5 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_sts_bit, async_advance)); - TEST_ASSERT_EQUAL( 7 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_sts_bit, nxp_int_sof)); - TEST_ASSERT_EQUAL( 12 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_sts_bit, hc_halted)); - TEST_ASSERT_EQUAL( 13 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_sts_bit, reclamation)); - TEST_ASSERT_EQUAL( 14 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_sts_bit, period_schedule_status)); - TEST_ASSERT_EQUAL( 15 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_sts_bit, async_schedule_status)); - TEST_ASSERT_EQUAL( 18 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_sts_bit, nxp_int_async)); - TEST_ASSERT_EQUAL( 19 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_sts_bit, nxp_int_period)); -} - -void test_register_usbint(void) -{ - TEST_ASSERT_EQUAL( 0 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_int_enable_bit, usb)); - TEST_ASSERT_EQUAL( 1 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_int_enable_bit, usb_error)); - TEST_ASSERT_EQUAL( 2 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_int_enable_bit, port_change_detect)); - TEST_ASSERT_EQUAL( 3 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_int_enable_bit, framelist_rollover)); - TEST_ASSERT_EQUAL( 4 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_int_enable_bit, pci_host_system_error)); - TEST_ASSERT_EQUAL( 5 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_int_enable_bit, async_advance)); - TEST_ASSERT_EQUAL( 7 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_int_enable_bit, nxp_int_sof)); - TEST_ASSERT_EQUAL( 18 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_int_enable_bit, nxp_int_async)); - TEST_ASSERT_EQUAL( 19 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, usb_int_enable_bit, nxp_int_period)); - -} - -void test_register_portsc(void) -{ - TEST_ASSERT_EQUAL( 0 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, portsc_bit, current_connect_status)); - TEST_ASSERT_EQUAL( 1 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, portsc_bit, connect_status_change)); - TEST_ASSERT_EQUAL( 2 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, portsc_bit, port_enable)); - TEST_ASSERT_EQUAL( 3 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, portsc_bit, port_enable_change)); - TEST_ASSERT_EQUAL( 4 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, portsc_bit, over_current_active)); - TEST_ASSERT_EQUAL( 5 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, portsc_bit, over_current_change)); - TEST_ASSERT_EQUAL( 6 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, portsc_bit, force_port_resume)); - TEST_ASSERT_EQUAL( 7 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, portsc_bit, suspend)); - TEST_ASSERT_EQUAL( 8 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, portsc_bit, port_reset)); - TEST_ASSERT_EQUAL( 9 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, portsc_bit, nxp_highspeed_status)); - TEST_ASSERT_EQUAL( 10 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, portsc_bit, line_status)); - TEST_ASSERT_EQUAL( 12 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, portsc_bit, port_power)); - TEST_ASSERT_EQUAL( 13 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, portsc_bit, port_owner)); - TEST_ASSERT_EQUAL( 14 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, portsc_bit, port_indicator_control)); - TEST_ASSERT_EQUAL( 16 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, portsc_bit, port_test_control)); - TEST_ASSERT_EQUAL( 20 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, portsc_bit, wake_on_connect_enable)); - TEST_ASSERT_EQUAL( 21 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, portsc_bit, wake_on_disconnect_enable)); - TEST_ASSERT_EQUAL( 22 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, portsc_bit, wake_on_over_current_enable)); - TEST_ASSERT_EQUAL( 23 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, portsc_bit, nxp_phy_clock_disable)); - TEST_ASSERT_EQUAL( 24 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, portsc_bit, nxp_port_force_fullspeed)); - TEST_ASSERT_EQUAL( 26 , BITFIELD_OFFSET_OF_MEMBER(ehci_registers_t, portsc_bit, nxp_port_speed)); -} - -//--------------------------------------------------------------------+ -// EHCI Data Organization -//--------------------------------------------------------------------+ -void test_ehci_data(void) -{ - for(uint32_t i=0; i -#include "unity.h" -#include "tusb_option.h" -#include "errors.h" -#include "binary.h" -#include "type_helper.h" - -#include "hal.h" -#include "mock_osal.h" -#include "mock_hid_host.h" - -#include "hcd.h" -#include "usbh_hcd.h" -#include "usbh.h" -#include "ehci.h" -#include "ehci_controller_fake.h" -#include "host_helper.h" - -static uint8_t const control_max_packet_size = 64; -static uint8_t hub_addr; -static uint8_t hub_port; -static uint8_t dev_addr; -static uint8_t hostid; - -static ehci_registers_t * regs; -static ehci_qhd_t *async_head; -static ehci_qhd_t *period_head_arr; - - - -void setUp(void) -{ - hub_addr = hub_port = 0; - dev_addr = 1; - hostid = RANDOM(CONTROLLER_HOST_NUMBER) + TEST_CONTROLLER_HOST_START_INDEX; - - ehci_controller_init(); - - helper_usbh_init_expect(); - helper_class_init_expect(); - usbh_init(); - - helper_usbh_device_emulate(dev_addr, hub_addr, hub_port, hostid, TUSB_SPEED_HIGH); - - regs = get_operational_register(hostid); - async_head = get_async_head( hostid ); - period_head_arr = (ehci_qhd_t*) get_period_head( hostid, 1 ); - regs->usb_sts = 0; // hcd_init clear usb_sts by writing 1s -} - -void tearDown(void) -{ -} - -void test_addr0_control_close(void) -{ - dev_addr = 0; - helper_usbh_device_emulate(0, hub_addr, hub_port, hostid, TUSB_SPEED_HIGH); - - TEST_ASSERT_STATUS( hcd_pipe_control_open(dev_addr, control_max_packet_size) ); - - TEST_ASSERT_STATUS( hcd_pipe_control_xfer(dev_addr, - &(tusb_std_request_t) { - .bmRequestType = { .direction = TUSB_DIR_HOST_TO_DEV, .type = TUSB_REQUEST_TYPE_STANDARD, .recipient = TUSB_REQUEST_RECIPIENT_DEVICE }, - .bRequest = TUSB_REQUEST_SET_ADDRESS, - .wValue = 3 }, - NULL) ) ; - - ehci_qhd_t *p_qhd = async_head; - TEST_ASSERT_STATUS( hcd_pipe_control_close(dev_addr) ); - - //------------- Code Under Test -------------// - regs->usb_sts_bit.port_change_detect = 0; // clear port change detect - regs->usb_sts_bit.async_advance = 1; - hcd_isr(hostid); // async advance - - TEST_ASSERT( p_qhd->qtd_overlay.halted ); - TEST_ASSERT_FALSE( p_qhd->is_removing ); - TEST_ASSERT_NULL( p_qhd->p_qtd_list_head ); - TEST_ASSERT_NULL( p_qhd->p_qtd_list_tail ); -} - -void test_isr_disconnect_then_async_advance_control_pipe(void) -{ - TEST_ASSERT_STATUS( hcd_pipe_control_open(dev_addr, control_max_packet_size) ); - - TEST_ASSERT_STATUS( hcd_pipe_control_xfer(dev_addr, - &(tusb_std_request_t) { - .bmRequestType = { .direction = TUSB_DIR_HOST_TO_DEV, .type = TUSB_REQUEST_TYPE_STANDARD, .recipient = TUSB_REQUEST_RECIPIENT_DEVICE }, - .bRequest = TUSB_REQUEST_SET_ADDRESS, - .wValue = 3 }, - NULL) ); - - ehci_qhd_t *p_qhd = get_control_qhd(dev_addr); - ehci_qtd_t *p_qtd_head = p_qhd->p_qtd_list_head; - ehci_qtd_t *p_qtd_tail = p_qhd->p_qtd_list_tail; - - ehci_controller_device_unplug(hostid); - - //------------- Code Under Test -------------// - hcd_isr(hostid); // port change detect - regs->usb_sts_bit.port_change_detect = 0; // clear port change detect - regs->usb_sts_bit.async_advance = 1; - hcd_isr(hostid); // async advance - - TEST_ASSERT_FALSE(p_qhd->used); - TEST_ASSERT_FALSE(p_qhd->is_removing); -// TEST_ASSERT_NULL(p_qhd->p_qtd_list_head); -// TEST_ASSERT_NULL(p_qhd->p_qtd_list_tail); -} - -void test_bulk_pipe_close(void) -{ - tusb_descriptor_endpoint_t const desc_ept_bulk_in = - { - .bLength = sizeof(tusb_descriptor_endpoint_t), - .bDescriptorType = TUSB_DESC_TYPE_ENDPOINT, - .bEndpointAddress = 0x81, - .bmAttributes = { .xfer = TUSB_XFER_BULK }, - .wMaxPacketSize = 512, - .bInterval = 0 - }; - - uint8_t xfer_data[100]; - pipe_handle_t pipe_hdl = hcd_pipe_open(dev_addr, &desc_ept_bulk_in, TUSB_CLASS_MSC); - - TEST_ASSERT_STATUS( hcd_pipe_xfer(pipe_hdl, xfer_data, sizeof(xfer_data), 100) ); - TEST_ASSERT_STATUS( hcd_pipe_xfer(pipe_hdl, xfer_data, sizeof(xfer_data), 50) ); - - ehci_qhd_t *p_qhd = &ehci_data.device[dev_addr-1].qhd[pipe_hdl.index]; - ehci_qtd_t *p_qtd_head = p_qhd->p_qtd_list_head; - ehci_qtd_t *p_qtd_tail = p_qhd->p_qtd_list_tail; - - TEST_ASSERT_STATUS( hcd_pipe_close(pipe_hdl) ); - - //------------- Code Under Test -------------// - regs->usb_sts_bit.async_advance = 1; - get_control_qhd(dev_addr)->is_removing = 1; // mimic unmount - hcd_isr(hostid); // async advance - - TEST_ASSERT_FALSE(p_qhd->used); - TEST_ASSERT_FALSE(p_qhd->is_removing); -// TEST_ASSERT_NULL(p_qhd->p_qtd_list_head); -// TEST_ASSERT_NULL(p_qhd->p_qtd_list_tail); - TEST_ASSERT_FALSE(p_qtd_head->used); - TEST_ASSERT_FALSE(p_qtd_tail->used); -} - -void test_device_unplugged_status(void) -{ - ehci_controller_device_unplug(hostid); - hcd_isr(hostid); - TEST_ASSERT_EQUAL(TUSB_DEVICE_STATE_REMOVING, usbh_devices[dev_addr].state); - - regs->usb_sts_bit.async_advance = 1; - hcd_isr(hostid); // async advance - - TEST_ASSERT_EQUAL(TUSB_DEVICE_STATE_UNPLUG, usbh_devices[dev_addr].state); -} diff --git a/tests/test/test/host/ehci/test_pipe_bulk_open.c b/tests/test/test/host/ehci/test_pipe_bulk_open.c deleted file mode 100644 index 4ddc519aa..000000000 --- a/tests/test/test/host/ehci/test_pipe_bulk_open.c +++ /dev/null @@ -1,178 +0,0 @@ -/**************************************************************************/ -/*! - @file test_pipe_bulk_open.c - @author hathach (tinyusb.org) - - @section LICENSE - - Software License Agreement (BSD License) - - Copyright (c) 2013, hathach (tinyusb.org) - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - 3. Neither the name of the copyright holders nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY - EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY - DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND - ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - This file is part of the tinyusb stack. -*/ -/**************************************************************************/ - -#include -#include "unity.h" -#include "tusb_option.h" -#include "errors.h" -#include "binary.h" -#include "type_helper.h" - -#include "hal.h" -#include "mock_osal.h" -#include "hcd.h" -#include "mock_usbh_hcd.h" -#include "ehci.h" -#include "ehci_controller_fake.h" -#include "host_helper.h" - -usbh_device_info_t usbh_devices[TUSB_CFG_HOST_DEVICE_MAX+1]; - -static uint8_t const hub_addr = 2; -static uint8_t const hub_port = 2; -static uint8_t dev_addr; -static uint8_t hostid; - -static ehci_qhd_t *async_head; - -//--------------------------------------------------------------------+ -// Setup/Teardown + helper declare -//--------------------------------------------------------------------+ -void setUp(void) -{ - TEST_ASSERT_STATUS( hcd_init() ); - - dev_addr = 1; - hostid = RANDOM(CONTROLLER_HOST_NUMBER) + TEST_CONTROLLER_HOST_START_INDEX; - - memclr_(usbh_devices, sizeof(usbh_device_info_t)*(TUSB_CFG_HOST_DEVICE_MAX+1)); - helper_usbh_device_emulate(dev_addr, hub_addr, hub_port, hostid, TUSB_SPEED_HIGH); - - async_head = get_async_head( hostid ); -} - -void tearDown(void) -{ -} - -void verify_open_qhd(ehci_qhd_t *p_qhd, uint8_t endpoint_addr, uint16_t max_packet_size) -{ - TEST_ASSERT_EQUAL(dev_addr, p_qhd->device_address); - TEST_ASSERT_FALSE(p_qhd->non_hs_period_inactive_next_xact); - TEST_ASSERT_EQUAL(endpoint_addr & 0x0F, p_qhd->endpoint_number); - TEST_ASSERT_EQUAL(usbh_devices[dev_addr].speed, p_qhd->endpoint_speed); - TEST_ASSERT_EQUAL(max_packet_size, p_qhd->max_package_size); - TEST_ASSERT_EQUAL(0, p_qhd->nak_count_reload); // TDD NAK Reload disable - - TEST_ASSERT_EQUAL(hub_addr, p_qhd->hub_address); - TEST_ASSERT_EQUAL(hub_port, p_qhd->hub_port); - TEST_ASSERT_EQUAL(1, p_qhd->mult); // TDD operation model for mult - - TEST_ASSERT_FALSE(p_qhd->qtd_overlay.halted); - TEST_ASSERT(p_qhd->qtd_overlay.next.terminate); - TEST_ASSERT(p_qhd->qtd_overlay.alternate.terminate); - - //------------- HCD -------------// - TEST_ASSERT(p_qhd->used); - TEST_ASSERT_FALSE(p_qhd->is_removing); - TEST_ASSERT_NULL(p_qhd->p_qtd_list_head); - TEST_ASSERT_NULL(p_qhd->p_qtd_list_tail); -} - -//--------------------------------------------------------------------+ -// PIPE OPEN -//--------------------------------------------------------------------+ -tusb_descriptor_endpoint_t const desc_ept_bulk_in = -{ - .bLength = sizeof(tusb_descriptor_endpoint_t), - .bDescriptorType = TUSB_DESC_TYPE_ENDPOINT, - .bEndpointAddress = 0x81, - .bmAttributes = { .xfer = TUSB_XFER_BULK }, - .wMaxPacketSize = 512, - .bInterval = 0 -}; - -void verify_bulk_open_qhd(ehci_qhd_t *p_qhd, tusb_descriptor_endpoint_t const * desc_endpoint, uint8_t class_code) -{ - verify_open_qhd(p_qhd, desc_endpoint->bEndpointAddress, desc_endpoint->wMaxPacketSize.size); - - TEST_ASSERT_FALSE(p_qhd->head_list_flag); - TEST_ASSERT_EQUAL(0, p_qhd->data_toggle_control); - TEST_ASSERT_EQUAL(0, p_qhd->interrupt_smask); - TEST_ASSERT_EQUAL(0, p_qhd->non_hs_interrupt_cmask); - TEST_ASSERT_FALSE(p_qhd->non_hs_control_endpoint); - - // TEST_ASSERT_EQUAL(desc_endpoint->bInterval); TDD highspeed bulk/control OUT - - TEST_ASSERT_EQUAL(desc_endpoint->bEndpointAddress & 0x80 ? EHCI_PID_IN : EHCI_PID_OUT, p_qhd->pid_non_control); - - TEST_ASSERT_EQUAL(class_code, p_qhd->class_code); - //------------- async list check -------------// - TEST_ASSERT_EQUAL_HEX((uint32_t) p_qhd, align32(async_head->next.address)); - TEST_ASSERT_FALSE(async_head->next.terminate); - TEST_ASSERT_EQUAL(EHCI_QUEUE_ELEMENT_QHD, async_head->next.type); -} - -void test_open_bulk_qhd_data(void) -{ - ehci_qhd_t *p_qhd; - pipe_handle_t pipe_hdl; - tusb_descriptor_endpoint_t const * desc_endpoint = &desc_ept_bulk_in; - - //------------- Code Under TEST -------------// - pipe_hdl = hcd_pipe_open(dev_addr, desc_endpoint, TUSB_CLASS_MSC); - - TEST_ASSERT_EQUAL(dev_addr, pipe_hdl.dev_addr); - TEST_ASSERT_EQUAL(TUSB_XFER_BULK, pipe_hdl.xfer_type); - - p_qhd = &ehci_data.device[ pipe_hdl.dev_addr-1 ].qhd[ pipe_hdl.index ]; - verify_bulk_open_qhd(p_qhd, desc_endpoint, TUSB_CLASS_MSC); - - //------------- async list check -------------// - TEST_ASSERT_EQUAL_HEX((uint32_t) p_qhd, align32(async_head->next.address)); - TEST_ASSERT_FALSE(async_head->next.terminate); - TEST_ASSERT_EQUAL(EHCI_QUEUE_ELEMENT_QHD, async_head->next.type); -} - -//--------------------------------------------------------------------+ -// PIPE CLOSE -//--------------------------------------------------------------------+ -void test_bulk_close(void) -{ - tusb_descriptor_endpoint_t const * desc_endpoint = &desc_ept_bulk_in; - pipe_handle_t pipe_hdl = hcd_pipe_open(dev_addr, desc_endpoint, TUSB_CLASS_MSC); - ehci_qhd_t *p_qhd = &ehci_data.device[ pipe_hdl.dev_addr-1].qhd[ pipe_hdl.index ]; - - //------------- Code Under TEST -------------// - hcd_pipe_close(pipe_hdl); - - TEST_ASSERT(p_qhd->is_removing); - TEST_ASSERT( align32(async_head->next.address) != (uint32_t) p_qhd ); - TEST_ASSERT_EQUAL_HEX( (uint32_t) async_head, align32(p_qhd->next.address) ); - TEST_ASSERT_EQUAL(EHCI_QUEUE_ELEMENT_QHD, p_qhd->next.type); -} diff --git a/tests/test/test/host/ehci/test_pipe_bulk_xfer.c b/tests/test/test/host/ehci/test_pipe_bulk_xfer.c deleted file mode 100644 index ccf30d724..000000000 --- a/tests/test/test/host/ehci/test_pipe_bulk_xfer.c +++ /dev/null @@ -1,221 +0,0 @@ -/**************************************************************************/ -/*! - @file test_ehci_pipe_bulk_xfer.c - @author hathach (tinyusb.org) - - @section LICENSE - - Software License Agreement (BSD License) - - Copyright (c) 2013, hathach (tinyusb.org) - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - 3. Neither the name of the copyright holders nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY - EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY - DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND - ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - This file is part of the tinyusb stack. -*/ -/**************************************************************************/ - -#include -#include "unity.h" -#include "tusb_option.h" -#include "errors.h" -#include "binary.h" -#include "type_helper.h" - -#include "hal.h" -#include "mock_osal.h" -#include "hcd.h" -#include "mock_usbh_hcd.h" -#include "ehci.h" -#include "ehci_controller_fake.h" -#include "host_helper.h" - -usbh_device_info_t usbh_devices[TUSB_CFG_HOST_DEVICE_MAX+1]; - -static uint8_t hub_addr = 2; -static uint8_t hub_port = 2; -static uint8_t dev_addr; -static uint8_t hostid; -static uint8_t xfer_data [18000]; // 18K to test buffer pointer list -static uint8_t data2[100]; - -static ehci_qhd_t *async_head; -static ehci_qhd_t *p_qhd_bulk; -static pipe_handle_t pipe_hdl_bulk; - -tusb_descriptor_endpoint_t const desc_ept_bulk_in = -{ - .bLength = sizeof(tusb_descriptor_endpoint_t), - .bDescriptorType = TUSB_DESC_TYPE_ENDPOINT, - .bEndpointAddress = 0x81, - .bmAttributes = { .xfer = TUSB_XFER_BULK }, - .wMaxPacketSize = 512, - .bInterval = 0 -}; - -tusb_descriptor_endpoint_t const desc_ept_bulk_out = -{ - .bLength = sizeof(tusb_descriptor_endpoint_t), - .bDescriptorType = TUSB_DESC_TYPE_ENDPOINT, - .bEndpointAddress = 0x01, - .bmAttributes = { .xfer = TUSB_XFER_BULK }, - .wMaxPacketSize = 512, - .bInterval = 0 -}; - -//--------------------------------------------------------------------+ -// Setup/Teardown + helper declare -//--------------------------------------------------------------------+ -void setUp(void) -{ - ehci_controller_init(); - memclr_(xfer_data, sizeof(xfer_data)); - memclr_(usbh_devices, sizeof(usbh_device_info_t)*(TUSB_CFG_HOST_DEVICE_MAX+1)); - - TEST_ASSERT_STATUS( hcd_init() ); - - dev_addr = 1; - hostid = RANDOM(CONTROLLER_HOST_NUMBER) + TEST_CONTROLLER_HOST_START_INDEX; - helper_usbh_device_emulate(dev_addr, hub_addr, hub_port, hostid, TUSB_SPEED_HIGH); - - async_head = get_async_head( hostid ); - - //------------- pipe open -------------// - pipe_hdl_bulk = hcd_pipe_open(dev_addr, &desc_ept_bulk_in, TUSB_CLASS_MSC); - - TEST_ASSERT_EQUAL(dev_addr, pipe_hdl_bulk.dev_addr); - TEST_ASSERT_EQUAL(TUSB_XFER_BULK, pipe_hdl_bulk.xfer_type); - - p_qhd_bulk = &ehci_data.device[ dev_addr -1].qhd[ pipe_hdl_bulk.index ]; -} - -void tearDown(void) -{ -} -//--------------------------------------------------------------------+ -// BULK TRANSFER -//--------------------------------------------------------------------+ -void verify_qtd(ehci_qtd_t *p_qtd, uint8_t p_data[], uint16_t length) -{ - TEST_ASSERT_TRUE(p_qtd->alternate.terminate); // not used, always invalid - - //------------- status -------------// - TEST_ASSERT_FALSE(p_qtd->pingstate_err); - TEST_ASSERT_FALSE(p_qtd->non_hs_split_state); - TEST_ASSERT_FALSE(p_qtd->non_hs_period_missed_uframe); - TEST_ASSERT_FALSE(p_qtd->xact_err); - TEST_ASSERT_FALSE(p_qtd->babble_err); - TEST_ASSERT_FALSE(p_qtd->buffer_err); - TEST_ASSERT_FALSE(p_qtd->halted); - TEST_ASSERT_TRUE(p_qtd->active); - - TEST_ASSERT_FALSE(p_qtd->data_toggle); - TEST_ASSERT_EQUAL(3, p_qtd->cerr); - TEST_ASSERT_EQUAL(0, p_qtd->current_page); - TEST_ASSERT_EQUAL(length, p_qtd->total_bytes); - TEST_ASSERT_TRUE(p_qtd->used); - - TEST_ASSERT_EQUAL_HEX( p_data, p_qtd->buffer[0] ); - for(uint8_t i=1; i<5; i++) - { - TEST_ASSERT_EQUAL_HEX( align4k((uint32_t) (p_data+4096*i)), align4k(p_qtd->buffer[i]) ); - } -} - -void test_bulk_xfer_hs_ping_out(void) -{ - usbh_devices[dev_addr].speed = TUSB_SPEED_HIGH; - - pipe_handle_t pipe_hdl = hcd_pipe_open(dev_addr, &desc_ept_bulk_out, TUSB_CLASS_MSC); - ehci_qhd_t *p_qhd = qhd_get_from_pipe_handle(pipe_hdl); - - //------------- Code Under Test -------------// - TEST_ASSERT_STATUS( hcd_pipe_xfer(pipe_hdl, xfer_data, sizeof(xfer_data), true) ); - - ehci_qtd_t* p_qtd = p_qhd->p_qtd_list_head; - TEST_ASSERT(p_qtd->pingstate_err); -} - -void test_bulk_xfer(void) -{ - //------------- Code Under Test -------------// - TEST_ASSERT_STATUS( hcd_pipe_xfer(pipe_hdl_bulk, xfer_data, sizeof(xfer_data), true) ); - - ehci_qtd_t* p_qtd = p_qhd_bulk->p_qtd_list_head; - TEST_ASSERT_NOT_NULL(p_qtd); - - verify_qtd( p_qtd, xfer_data, sizeof(xfer_data)); - TEST_ASSERT_EQUAL_HEX(p_qhd_bulk->qtd_overlay.next.address, p_qtd); - TEST_ASSERT_TRUE(p_qtd->next.terminate); - TEST_ASSERT_EQUAL(EHCI_PID_IN, p_qtd->pid); - TEST_ASSERT_TRUE(p_qtd->int_on_complete); -} - -void test_bulk_xfer_double(void) -{ - //------------- Code Under Test -------------// - TEST_ASSERT_STATUS( hcd_pipe_xfer(pipe_hdl_bulk, xfer_data, sizeof(xfer_data), false) ); - - TEST_ASSERT_STATUS( hcd_pipe_xfer(pipe_hdl_bulk, data2, sizeof(data2), true) ); - - ehci_qtd_t* p_head = p_qhd_bulk->p_qtd_list_head; - ehci_qtd_t* p_tail = p_qhd_bulk->p_qtd_list_tail; - - //------------- list head -------------// - TEST_ASSERT_NOT_NULL(p_head); - verify_qtd(p_head, xfer_data, sizeof(xfer_data)); - TEST_ASSERT_EQUAL_HEX(p_qhd_bulk->qtd_overlay.next.address, p_head); - TEST_ASSERT_EQUAL(EHCI_PID_IN, p_head->pid); - TEST_ASSERT_FALSE(p_head->next.terminate); - TEST_ASSERT_FALSE(p_head->int_on_complete); - - //------------- list tail -------------// - TEST_ASSERT_NOT_NULL(p_tail); - verify_qtd(p_tail, data2, sizeof(data2)); - TEST_ASSERT_EQUAL_HEX( align32(p_head->next.address), p_tail); - TEST_ASSERT_EQUAL(EHCI_PID_IN, p_tail->pid); - TEST_ASSERT_TRUE(p_tail->next.terminate); - TEST_ASSERT_TRUE(p_tail->int_on_complete); -} - -void test_bulk_xfer_complete_isr(void) -{ - TEST_ASSERT_STATUS( hcd_pipe_xfer(pipe_hdl_bulk, xfer_data, sizeof(xfer_data), false) ); - - TEST_ASSERT_STATUS( hcd_pipe_xfer(pipe_hdl_bulk, data2, sizeof(data2), true) ); - - ehci_qtd_t* p_head = p_qhd_bulk->p_qtd_list_head; - ehci_qtd_t* p_tail = p_qhd_bulk->p_qtd_list_tail; - - usbh_isr_Expect(pipe_hdl_bulk, TUSB_CLASS_MSC, TUSB_EVENT_XFER_COMPLETE); - - //------------- Code Under Test -------------// - ehci_controller_run(hostid); - - TEST_ASSERT_TRUE(p_qhd_bulk->qtd_overlay.next.terminate); - TEST_ASSERT_FALSE(p_head->used); - TEST_ASSERT_FALSE(p_tail->used); - TEST_ASSERT_NULL(p_qhd_bulk->p_qtd_list_head); - TEST_ASSERT_NULL(p_qhd_bulk->p_qtd_list_tail); -} diff --git a/tests/test/test/host/ehci/test_pipe_control_open.c b/tests/test/test/host/ehci/test_pipe_control_open.c deleted file mode 100644 index 7cfdec4bb..000000000 --- a/tests/test/test/host/ehci/test_pipe_control_open.c +++ /dev/null @@ -1,196 +0,0 @@ -/**************************************************************************/ -/*! - @file test_ehci_pipe.c - @author hathach (tinyusb.org) - - @section LICENSE - - Software License Agreement (BSD License) - - Copyright (c) 2013, hathach (tinyusb.org) - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - 3. Neither the name of the copyright holders nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY - EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY - DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND - ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - This file is part of the tinyusb stack. -*/ -/**************************************************************************/ - -#include -#include "unity.h" -#include "tusb_option.h" -#include "errors.h" -#include "binary.h" -#include "type_helper.h" - -#include "hal.h" -#include "mock_osal.h" -#include "hcd.h" -#include "mock_usbh_hcd.h" -#include "ehci.h" -#include "ehci_controller_fake.h" -#include "host_helper.h" - -usbh_device_info_t usbh_devices[TUSB_CFG_HOST_DEVICE_MAX+1]; - -static uint8_t const control_max_packet_size = 64; -static uint8_t const hub_addr = 2; -static uint8_t const hub_port = 2; -static uint8_t dev_addr; -static uint8_t hostid; - -static ehci_qhd_t *async_head; -static ehci_qhd_t *p_control_qhd; - -//--------------------------------------------------------------------+ -// Setup/Teardown + helper declare -//--------------------------------------------------------------------+ -void setUp(void) -{ - memclr_(usbh_devices, sizeof(usbh_device_info_t)*(TUSB_CFG_HOST_DEVICE_MAX+1)); - - TEST_ASSERT_STATUS( hcd_init() ); - - dev_addr = 1; - hostid = RANDOM(CONTROLLER_HOST_NUMBER) + TEST_CONTROLLER_HOST_START_INDEX; - - helper_usbh_device_emulate(0, hub_addr, hub_port, hostid, TUSB_SPEED_HIGH); - helper_usbh_device_emulate(dev_addr, hub_addr, hub_port, hostid, TUSB_SPEED_HIGH); - - async_head = get_async_head( hostid ); - p_control_qhd = &ehci_data.device[dev_addr-1].control.qhd; -} - -void tearDown(void) -{ -} - -void verify_open_qhd(ehci_qhd_t *p_qhd, uint8_t endpoint_addr, uint16_t max_packet_size) -{ - TEST_ASSERT_EQUAL(dev_addr, p_qhd->device_address); - TEST_ASSERT_FALSE(p_qhd->non_hs_period_inactive_next_xact); - TEST_ASSERT_EQUAL(endpoint_addr & 0x0F, p_qhd->endpoint_number); - TEST_ASSERT_EQUAL(usbh_devices[dev_addr].speed, p_qhd->endpoint_speed); - TEST_ASSERT_EQUAL(max_packet_size, p_qhd->max_package_size); - TEST_ASSERT_EQUAL(0, p_qhd->nak_count_reload); // TDD NAK Reload disable - - TEST_ASSERT_EQUAL(hub_addr, p_qhd->hub_address); - TEST_ASSERT_EQUAL(hub_port, p_qhd->hub_port); - TEST_ASSERT_EQUAL(1, p_qhd->mult); // TDD operation model for mult - - TEST_ASSERT_FALSE(p_qhd->qtd_overlay.halted); - TEST_ASSERT(p_qhd->qtd_overlay.next.terminate); - TEST_ASSERT(p_qhd->qtd_overlay.alternate.terminate); - - //------------- HCD -------------// - TEST_ASSERT(p_qhd->used); - TEST_ASSERT_FALSE(p_qhd->is_removing); - TEST_ASSERT_NULL(p_qhd->p_qtd_list_head); - TEST_ASSERT_NULL(p_qhd->p_qtd_list_tail); -} - -void verify_control_open_qhd(ehci_qhd_t *p_qhd) -{ - verify_open_qhd(p_qhd, 0, control_max_packet_size); - - TEST_ASSERT_EQUAL(0, p_qhd->class_code); - TEST_ASSERT_EQUAL(1, p_qhd->data_toggle_control); - TEST_ASSERT_EQUAL(0, p_qhd->interrupt_smask); - TEST_ASSERT_EQUAL(0, p_qhd->non_hs_interrupt_cmask); -} - -//--------------------------------------------------------------------+ -// PIPE OPEN -//--------------------------------------------------------------------+ -void test_control_open_addr0_qhd_data(void) -{ - dev_addr = 0; - - //------------- Code Under Test -------------// - TEST_ASSERT_STATUS( hcd_pipe_control_open(dev_addr, control_max_packet_size) ); - - verify_control_open_qhd(async_head); - TEST_ASSERT(async_head->head_list_flag); -} - -void test_control_open_qhd_data(void) -{ - //------------- Code Under TEST -------------// - TEST_ASSERT_STATUS( hcd_pipe_control_open(dev_addr, control_max_packet_size)); - - verify_control_open_qhd(p_control_qhd); - TEST_ASSERT_FALSE(p_control_qhd->head_list_flag); - - //------------- async list check -------------// - TEST_ASSERT_EQUAL_HEX((uint32_t) p_control_qhd, align32(async_head->next.address)); - TEST_ASSERT_FALSE(async_head->next.terminate); - TEST_ASSERT_EQUAL(EHCI_QUEUE_ELEMENT_QHD, async_head->next.type); -} - -void test_control_open_highspeed(void) -{ - usbh_devices[dev_addr].speed = TUSB_SPEED_HIGH; - - //------------- Code Under TEST -------------// - TEST_ASSERT_STATUS( hcd_pipe_control_open(dev_addr, control_max_packet_size) ); - TEST_ASSERT_FALSE(p_control_qhd->non_hs_control_endpoint); -} - -void test_control_open_non_highspeed(void) -{ - usbh_devices[dev_addr].speed = TUSB_SPEED_FULL; - - //------------- Code Under TEST -------------// - TEST_ASSERT_STATUS( hcd_pipe_control_open(dev_addr, control_max_packet_size) ); - - TEST_ASSERT_TRUE(p_control_qhd->non_hs_control_endpoint); -} - -//--------------------------------------------------------------------+ -// PIPE CLOSE -//--------------------------------------------------------------------+ -void test_control_addr0_close(void) -{ - dev_addr = 0; - TEST_ASSERT_STATUS( hcd_pipe_control_open(dev_addr, control_max_packet_size) ); - - //------------- Code Under Test -------------// - TEST_ASSERT_STATUS( hcd_pipe_control_close(dev_addr) ); - - TEST_ASSERT(async_head->head_list_flag); - TEST_ASSERT(async_head->is_removing); -} - -void test_control_close(void) -{ - TEST_ASSERT_STATUS( hcd_pipe_control_open(dev_addr, control_max_packet_size) ); - - //------------- Code Under TEST -------------// - TEST_ASSERT_STATUS( hcd_pipe_control_close(dev_addr) ); - - TEST_ASSERT(p_control_qhd->is_removing); - TEST_ASSERT(p_control_qhd->used); - - TEST_ASSERT( align32(get_async_head(hostid)->next.address) != (uint32_t) p_control_qhd ); - TEST_ASSERT_EQUAL( get_async_head(hostid), align32(p_control_qhd->next.address)); -} diff --git a/tests/test/test/host/ehci/test_pipe_control_xfer.c b/tests/test/test/host/ehci/test_pipe_control_xfer.c deleted file mode 100644 index 266cf0ef2..000000000 --- a/tests/test/test/host/ehci/test_pipe_control_xfer.c +++ /dev/null @@ -1,252 +0,0 @@ -/**************************************************************************/ -/*! - @file test_ehci_pipe_xfer.c - @author hathach (tinyusb.org) - - @section LICENSE - - Software License Agreement (BSD License) - - Copyright (c) 2013, hathach (tinyusb.org) - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - 3. Neither the name of the copyright holders nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY - EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY - DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND - ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - This file is part of the tinyusb stack. -*/ -/**************************************************************************/ - -#include -#include "unity.h" -#include "tusb_option.h" -#include "errors.h" -#include "binary.h" -#include "type_helper.h" - -#include "hal.h" -#include "mock_osal.h" -#include "hcd.h" -#include "mock_usbh_hcd.h" -#include "ehci.h" -#include "ehci_controller_fake.h" -#include "host_helper.h" - -usbh_device_info_t usbh_devices[TUSB_CFG_HOST_DEVICE_MAX+1]; - -static uint8_t const control_max_packet_size = 64; -static uint8_t const hub_addr = 2; -static uint8_t const hub_port = 2; -static uint8_t dev_addr; -static uint8_t hostid; -static uint8_t xfer_data [100]; - -static ehci_qhd_t *async_head; -static ehci_qhd_t *p_control_qhd; - -static ehci_qtd_t *p_setup; -static ehci_qtd_t *p_data; -static ehci_qtd_t *p_status; - -//--------------------------------------------------------------------+ -// Setup/Teardown + helper declare -//--------------------------------------------------------------------+ -void setUp(void) -{ - ehci_controller_init(); - - memclr_(usbh_devices, sizeof(usbh_device_info_t)*(TUSB_CFG_HOST_DEVICE_MAX+1)); - memclr_(xfer_data, sizeof(xfer_data)); - - TEST_ASSERT_STATUS( hcd_init() ); - - dev_addr = 1; - hostid = RANDOM(CONTROLLER_HOST_NUMBER) + TEST_CONTROLLER_HOST_START_INDEX; - - helper_usbh_device_emulate(0 , hub_addr, hub_port, hostid, TUSB_SPEED_HIGH); - helper_usbh_device_emulate(dev_addr , hub_addr, hub_port, hostid, TUSB_SPEED_HIGH); - - async_head = get_async_head( hostid ); - - //------------- pipe open -------------// - TEST_ASSERT_STATUS( hcd_pipe_control_open(dev_addr, control_max_packet_size) ); - - p_control_qhd = &ehci_data.device[dev_addr-1].control.qhd; - - p_setup = &ehci_data.device[dev_addr-1].control.qtd[0]; - p_data = &ehci_data.device[dev_addr-1].control.qtd[1]; - p_status = &ehci_data.device[dev_addr-1].control.qtd[2]; -} - -void tearDown(void) -{ -} -//--------------------------------------------------------------------+ -// CONTROL TRANSFER -//--------------------------------------------------------------------+ -tusb_std_request_t request_get_dev_desc = -{ - .bmRequestType = { .direction = TUSB_DIR_DEV_TO_HOST, .type = TUSB_REQUEST_TYPE_STANDARD, .recipient = TUSB_REQUEST_RECIPIENT_DEVICE }, - .bRequest = TUSB_REQUEST_GET_DESCRIPTOR, - .wValue = (TUSB_DESC_TYPE_DEVICE << 8), - .wLength = 18 -}; - -tusb_std_request_t request_set_dev_addr = -{ - .bmRequestType = { .direction = TUSB_DIR_HOST_TO_DEV, .type = TUSB_REQUEST_TYPE_STANDARD, .recipient = TUSB_REQUEST_RECIPIENT_DEVICE }, - .bRequest = TUSB_REQUEST_SET_ADDRESS, - .wValue = 3 -}; - -void verify_qtd(ehci_qtd_t *p_qtd, uint8_t p_data[], uint16_t length) -{ - TEST_ASSERT_TRUE(p_qtd->alternate.terminate); // not used, always invalid - - TEST_ASSERT_FALSE(p_qtd->pingstate_err); - TEST_ASSERT_FALSE(p_qtd->non_hs_split_state); - TEST_ASSERT_FALSE(p_qtd->non_hs_period_missed_uframe); - TEST_ASSERT_FALSE(p_qtd->xact_err); - TEST_ASSERT_FALSE(p_qtd->babble_err); - TEST_ASSERT_FALSE(p_qtd->buffer_err); - TEST_ASSERT_FALSE(p_qtd->halted); - TEST_ASSERT_TRUE(p_qtd->active); - - TEST_ASSERT_EQUAL(3, p_qtd->cerr); - TEST_ASSERT_EQUAL(0, p_qtd->current_page); - TEST_ASSERT_EQUAL(length, p_qtd->total_bytes); - - TEST_ASSERT_EQUAL_HEX(p_data, p_qtd->buffer[0]); -} - -//--------------------------------------------------------------------+ -// Address 0 -//--------------------------------------------------------------------+ -void test_control_addr0_xfer_get_check_qhd_qtd_mapping(void) -{ - dev_addr = 0; - ehci_qhd_t * const p_qhd = async_head; - - TEST_ASSERT_STATUS( hcd_pipe_control_open(dev_addr, control_max_packet_size) ); - - //------------- Code Under TEST -------------// - TEST_ASSERT_STATUS( hcd_pipe_control_xfer(dev_addr, &request_get_dev_desc, xfer_data) ); - - p_setup = &ehci_data.addr0_qtd[0]; - p_data = &ehci_data.addr0_qtd[1]; - p_status = &ehci_data.addr0_qtd[2]; - - TEST_ASSERT_EQUAL_HEX( p_setup, p_qhd->qtd_overlay.next.address ); - TEST_ASSERT_EQUAL_HEX( p_setup , p_qhd->p_qtd_list_head); - TEST_ASSERT_EQUAL_HEX( p_data , p_setup->next.address); - TEST_ASSERT_EQUAL_HEX( p_status , p_data->next.address ); - TEST_ASSERT_TRUE( p_status->next.terminate ); - - verify_qtd(p_setup, (uint8_t*) &request_get_dev_desc, 8); -} - -//--------------------------------------------------------------------+ -// Normal Control -//--------------------------------------------------------------------+ -void test_control_xfer_get(void) -{ - //------------- Code Under TEST -------------// - TEST_ASSERT_STATUS( hcd_pipe_control_xfer(dev_addr, &request_get_dev_desc, xfer_data) ); - - TEST_ASSERT_EQUAL_HEX( p_setup, p_control_qhd->qtd_overlay.next.address ); - TEST_ASSERT_EQUAL_HEX( p_setup , p_control_qhd->p_qtd_list_head); - TEST_ASSERT_EQUAL_HEX( p_data , p_setup->next.address); - TEST_ASSERT_EQUAL_HEX( p_status , p_data->next.address ); - TEST_ASSERT_TRUE( p_status->next.terminate ); - - //------------- SETUP -------------// - verify_qtd(p_setup, (uint8_t*) &request_get_dev_desc, 8); - - TEST_ASSERT_FALSE(p_setup->int_on_complete); - TEST_ASSERT_FALSE(p_setup->data_toggle); - TEST_ASSERT_EQUAL(EHCI_PID_SETUP, p_setup->pid); - - //------------- DATA -------------// - verify_qtd(p_data, xfer_data, request_get_dev_desc.wLength); - TEST_ASSERT_FALSE(p_data->int_on_complete); - TEST_ASSERT_TRUE(p_data->data_toggle); - TEST_ASSERT_EQUAL(EHCI_PID_IN, p_data->pid); - - //------------- STATUS -------------// - verify_qtd(p_status, NULL, 0); - TEST_ASSERT_TRUE(p_status->int_on_complete); - TEST_ASSERT_TRUE(p_status->data_toggle); - TEST_ASSERT_EQUAL(EHCI_PID_OUT, p_status->pid); - TEST_ASSERT_TRUE(p_status->next.terminate); - - TEST_ASSERT_EQUAL_HEX(p_setup, p_control_qhd->p_qtd_list_head); - TEST_ASSERT_EQUAL_HEX(p_status, p_control_qhd->p_qtd_list_tail); -} - -void test_control_xfer_set(void) -{ - //------------- Code Under TEST -------------// - TEST_ASSERT_STATUS( hcd_pipe_control_xfer(dev_addr, &request_set_dev_addr, xfer_data) ); - - TEST_ASSERT_EQUAL_HEX( p_setup, p_control_qhd->qtd_overlay.next.address ); - TEST_ASSERT_EQUAL_HEX( p_setup , p_control_qhd->p_qtd_list_head); - TEST_ASSERT_EQUAL_HEX( p_status , p_setup->next.address ); - TEST_ASSERT_TRUE( p_status->next.terminate ); - - //------------- STATUS -------------// - verify_qtd(p_status, NULL, 0); - TEST_ASSERT_TRUE(p_status->int_on_complete); - TEST_ASSERT_TRUE(p_status->data_toggle); - TEST_ASSERT_EQUAL(EHCI_PID_IN, p_status->pid); - TEST_ASSERT_TRUE(p_status->next.terminate); - - TEST_ASSERT_EQUAL_HEX(p_setup, p_control_qhd->p_qtd_list_head); - TEST_ASSERT_EQUAL_HEX(p_status, p_control_qhd->p_qtd_list_tail); -} - -void test_control_xfer_complete_isr(void) -{ - TEST_ASSERT_STATUS( hcd_pipe_control_xfer(dev_addr, &request_get_dev_desc, xfer_data) ); - - usbh_isr_Expect(((pipe_handle_t){.dev_addr = dev_addr}), 0, TUSB_EVENT_XFER_COMPLETE); - - //------------- Code Under TEST -------------// - ehci_controller_run(hostid); - - TEST_ASSERT_NULL(p_control_qhd->p_qtd_list_head); - TEST_ASSERT_NULL(p_control_qhd->p_qtd_list_tail); - - TEST_ASSERT_FALSE(p_setup->used); - TEST_ASSERT_FALSE(p_data->used); - TEST_ASSERT_FALSE(p_status->used); - -} - -void test_control_xfer_error_isr(void) -{ - TEST_ASSERT_STATUS( hcd_pipe_control_xfer(dev_addr, &request_get_dev_desc, xfer_data) ); - - usbh_isr_Expect(((pipe_handle_t){.dev_addr = dev_addr}), 0, TUSB_EVENT_XFER_ERROR); - - //------------- Code Under TEST -------------// - ehci_controller_run_error(hostid); -} diff --git a/tests/test/test/host/ehci/test_pipe_interrupt_open.c b/tests/test/test/host/ehci/test_pipe_interrupt_open.c deleted file mode 100644 index 946d8f0c8..000000000 --- a/tests/test/test/host/ehci/test_pipe_interrupt_open.c +++ /dev/null @@ -1,342 +0,0 @@ -/**************************************************************************/ -/*! - @file test_ehci_pipe.c - @author hathach (tinyusb.org) - - @section LICENSE - - Software License Agreement (BSD License) - - Copyright (c) 2013, hathach (tinyusb.org) - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - 3. Neither the name of the copyright holders nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY - EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY - DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND - ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - This file is part of the tinyusb stack. -*/ -/**************************************************************************/ - -#include "unity.h" -#include "tusb_option.h" -#include "errors.h" -#include "binary.h" -#include "type_helper.h" - -#include "hal.h" -#include "mock_osal.h" -#include "hcd.h" -#include "mock_usbh_hcd.h" -#include "ehci.h" -#include "ehci_controller_fake.h" -#include "host_helper.h" - -usbh_device_info_t usbh_devices[TUSB_CFG_HOST_DEVICE_MAX+1]; - -static uint8_t const hub_addr = 2; -static uint8_t const hub_port = 2; -static uint8_t dev_addr; -static uint8_t hostid; - -static ehci_qhd_t *period_head_arr; - -static ehci_qhd_t *p_int_qhd; -static pipe_handle_t pipe_hdl; - -//--------------------------------------------------------------------+ -// Setup/Teardown + helper declare -//--------------------------------------------------------------------+ -void setUp(void) -{ - memclr_(usbh_devices, sizeof(usbh_device_info_t)*(TUSB_CFG_HOST_DEVICE_MAX+1)); - - hcd_init(); - - dev_addr = 1; - hostid = RANDOM(CONTROLLER_HOST_NUMBER) + TEST_CONTROLLER_HOST_START_INDEX; - - helper_usbh_device_emulate(dev_addr , hub_addr, hub_port, hostid, TUSB_SPEED_HIGH); - - period_head_arr = get_period_head( hostid, 1 ); - p_int_qhd = NULL; - memclr_(&pipe_hdl, sizeof(pipe_handle_t)); -} - -void tearDown(void) -{ -} - -void verify_open_qhd(ehci_qhd_t *p_qhd, uint8_t endpoint_addr, uint16_t max_packet_size) -{ - TEST_ASSERT_EQUAL(dev_addr, p_qhd->device_address); - TEST_ASSERT_FALSE(p_qhd->non_hs_period_inactive_next_xact); - TEST_ASSERT_EQUAL(endpoint_addr & 0x0F, p_qhd->endpoint_number); - TEST_ASSERT_EQUAL(usbh_devices[dev_addr].speed, p_qhd->endpoint_speed); - TEST_ASSERT_EQUAL(max_packet_size, p_qhd->max_package_size); - TEST_ASSERT_EQUAL(0, p_qhd->nak_count_reload); // TDD NAK Reload disable - - TEST_ASSERT_EQUAL(hub_addr, p_qhd->hub_address); - TEST_ASSERT_EQUAL(hub_port, p_qhd->hub_port); - TEST_ASSERT_EQUAL(1, p_qhd->mult); // TDD operation model for mult - - TEST_ASSERT_FALSE(p_qhd->qtd_overlay.halted); - TEST_ASSERT(p_qhd->qtd_overlay.next.terminate); - TEST_ASSERT(p_qhd->qtd_overlay.alternate.terminate); - - //------------- HCD -------------// - TEST_ASSERT(p_qhd->used); - TEST_ASSERT_FALSE(p_qhd->is_removing); - TEST_ASSERT_NULL(p_qhd->p_qtd_list_head); - TEST_ASSERT_NULL(p_qhd->p_qtd_list_tail); -} - - -//--------------------------------------------------------------------+ -// PIPE OPEN -//--------------------------------------------------------------------+ -tusb_descriptor_endpoint_t const desc_ept_interrupt_out = -{ - .bLength = sizeof(tusb_descriptor_endpoint_t), - .bDescriptorType = TUSB_DESC_TYPE_ENDPOINT, - .bEndpointAddress = 0x02, - .bmAttributes = { .xfer = TUSB_XFER_INTERRUPT }, - .wMaxPacketSize = 16, - .bInterval = 4 -}; -void verify_int_qhd(ehci_qhd_t *p_qhd, tusb_descriptor_endpoint_t const * desc_endpoint, uint8_t class_code) -{ - verify_open_qhd(p_qhd, desc_endpoint->bEndpointAddress, desc_endpoint->wMaxPacketSize.size); - - TEST_ASSERT_FALSE(p_qhd->head_list_flag); - TEST_ASSERT_FALSE(p_qhd->data_toggle_control); - TEST_ASSERT_FALSE(p_qhd->non_hs_control_endpoint); - - TEST_ASSERT_EQUAL(desc_endpoint->bEndpointAddress & 0x80 ? EHCI_PID_IN : EHCI_PID_OUT, p_qhd->pid_non_control); -} - -void check_int_endpoint_link(ehci_qhd_t *p_prev, ehci_qhd_t *p_qhd) -{ - //------------- period list check -------------// - TEST_ASSERT_EQUAL_HEX((uint32_t) p_qhd, align32(p_prev->next.address)); - TEST_ASSERT_FALSE(p_prev->next.terminate); - TEST_ASSERT_EQUAL(EHCI_QUEUE_ELEMENT_QHD, p_prev->next.type); -} - -void test_open_interrupt_qhd_hs(void) -{ - //------------- Code Under TEST -------------// - pipe_hdl = hcd_pipe_open(dev_addr, &desc_ept_interrupt_out, TUSB_CLASS_HID); - - TEST_ASSERT_EQUAL(dev_addr, pipe_hdl.dev_addr); - TEST_ASSERT_EQUAL(TUSB_XFER_INTERRUPT, pipe_hdl.xfer_type); - - p_int_qhd = &ehci_data.device[ pipe_hdl.dev_addr-1].qhd[ pipe_hdl.index ]; - - verify_int_qhd(p_int_qhd, &desc_ept_interrupt_out, TUSB_CLASS_HID); - - TEST_ASSERT_EQUAL(0, p_int_qhd->non_hs_interrupt_cmask); -} - -void test_open_interrupt_hs_interval_1(void) -{ - tusb_descriptor_endpoint_t int_edp_interval = desc_ept_interrupt_out; - int_edp_interval.bInterval = 1; - - //------------- Code Under TEST -------------// - pipe_hdl = hcd_pipe_open(dev_addr, &int_edp_interval, TUSB_CLASS_HID); - p_int_qhd = &ehci_data.device[ pipe_hdl.dev_addr-1].qhd[ pipe_hdl.index ]; - - TEST_ASSERT_EQUAL(0 , p_int_qhd->interval_ms); - TEST_ASSERT_EQUAL(BIN8(11111111) , p_int_qhd->interrupt_smask); - - check_int_endpoint_link(period_head_arr, p_int_qhd); -} - -void test_open_interrupt_hs_interval_2(void) -{ - tusb_descriptor_endpoint_t int_edp_interval = desc_ept_interrupt_out; - int_edp_interval.bInterval = 2; - - //------------- Code Under TEST -------------// - pipe_hdl = hcd_pipe_open(dev_addr, &int_edp_interval, TUSB_CLASS_HID); - p_int_qhd = &ehci_data.device[ pipe_hdl.dev_addr-1].qhd[ pipe_hdl.index ]; - - TEST_ASSERT_EQUAL(0 , p_int_qhd->interval_ms); - TEST_ASSERT_EQUAL(4 , cardinality_of(p_int_qhd->interrupt_smask)); // either 10101010 or 01010101 - check_int_endpoint_link(period_head_arr, p_int_qhd); -} - -void test_open_interrupt_hs_interval_3(void) -{ - tusb_descriptor_endpoint_t int_edp_interval = desc_ept_interrupt_out; - int_edp_interval.bInterval = 3; - - //------------- Code Under TEST -------------// - pipe_hdl = hcd_pipe_open(dev_addr, &int_edp_interval, TUSB_CLASS_HID); - p_int_qhd = &ehci_data.device[ pipe_hdl.dev_addr-1].qhd[ pipe_hdl.index ]; - - TEST_ASSERT_EQUAL(0, p_int_qhd->interval_ms); - TEST_ASSERT_EQUAL(2, cardinality_of(p_int_qhd->interrupt_smask) ); - check_int_endpoint_link(period_head_arr, p_int_qhd); -} - -void test_open_interrupt_hs_interval_4(void) -{ - tusb_descriptor_endpoint_t int_edp_interval = desc_ept_interrupt_out; - int_edp_interval.bInterval = 4; - - //------------- Code Under TEST -------------// - pipe_hdl = hcd_pipe_open(dev_addr, &int_edp_interval, TUSB_CLASS_HID); - p_int_qhd = &ehci_data.device[ pipe_hdl.dev_addr-1].qhd[ pipe_hdl.index ]; - - TEST_ASSERT_EQUAL(1, p_int_qhd->interval_ms); - TEST_ASSERT_EQUAL(1, cardinality_of(p_int_qhd->interrupt_smask) ); - check_int_endpoint_link(period_head_arr, p_int_qhd); -} - -void test_open_interrupt_hs_interval_5(void) -{ - tusb_descriptor_endpoint_t int_edp_interval = desc_ept_interrupt_out; - int_edp_interval.bInterval = 5; - - //------------- Code Under TEST -------------// - pipe_hdl = hcd_pipe_open(dev_addr, &int_edp_interval, TUSB_CLASS_HID); - p_int_qhd = &ehci_data.device[ pipe_hdl.dev_addr-1].qhd[ pipe_hdl.index ]; - - TEST_ASSERT_EQUAL(2, p_int_qhd->interval_ms); - TEST_ASSERT_EQUAL(1, cardinality_of(p_int_qhd->interrupt_smask) ); - check_int_endpoint_link( get_period_head(hostid, 2), p_int_qhd ); -} - -void test_open_interrupt_hs_interval_6(void) -{ - tusb_descriptor_endpoint_t int_edp_interval = desc_ept_interrupt_out; - int_edp_interval.bInterval = 6; - - //------------- Code Under TEST -------------// - pipe_hdl = hcd_pipe_open(dev_addr, &int_edp_interval, TUSB_CLASS_HID); - p_int_qhd = &ehci_data.device[ pipe_hdl.dev_addr-1].qhd[ pipe_hdl.index ]; - - TEST_ASSERT_EQUAL(4, p_int_qhd->interval_ms); - TEST_ASSERT_EQUAL(1, cardinality_of(p_int_qhd->interrupt_smask) ); - check_int_endpoint_link( get_period_head(hostid, 4), p_int_qhd); -} - -void test_open_interrupt_hs_interval_7(void) -{ - tusb_descriptor_endpoint_t int_edp_interval = desc_ept_interrupt_out; - int_edp_interval.bInterval = 7; - - //------------- Code Under TEST -------------// - pipe_hdl = hcd_pipe_open(dev_addr, &int_edp_interval, TUSB_CLASS_HID); - p_int_qhd = &ehci_data.device[ pipe_hdl.dev_addr-1].qhd[ pipe_hdl.index ]; - - TEST_ASSERT_EQUAL(8, p_int_qhd->interval_ms); - TEST_ASSERT_EQUAL(1, cardinality_of(p_int_qhd->interrupt_smask) ); - check_int_endpoint_link( get_period_head(hostid, 8), p_int_qhd); -} - -void test_open_interrupt_hs_interval_8(void) -{ - tusb_descriptor_endpoint_t int_edp_interval = desc_ept_interrupt_out; - int_edp_interval.bInterval = 16; - - //------------- Code Under TEST -------------// - pipe_hdl = hcd_pipe_open(dev_addr, &int_edp_interval, TUSB_CLASS_HID); - p_int_qhd = &ehci_data.device[ pipe_hdl.dev_addr-1].qhd[ pipe_hdl.index ]; - - TEST_ASSERT_EQUAL(255, p_int_qhd->interval_ms); - TEST_ASSERT_EQUAL(1, cardinality_of(p_int_qhd->interrupt_smask) ); - check_int_endpoint_link( get_period_head(hostid, 255), p_int_qhd); - check_int_endpoint_link( get_period_head(hostid, 8) , p_int_qhd); -} - -void test_open_interrupt_qhd_non_hs(void) -{ - usbh_devices[dev_addr].speed = TUSB_SPEED_FULL; - - //------------- Code Under TEST -------------// - pipe_hdl = hcd_pipe_open(dev_addr, &desc_ept_interrupt_out, TUSB_CLASS_HID); - - TEST_ASSERT_EQUAL(dev_addr, pipe_hdl.dev_addr); - TEST_ASSERT_EQUAL(TUSB_XFER_INTERRUPT, pipe_hdl.xfer_type); - - p_int_qhd = &ehci_data.device[ pipe_hdl.dev_addr-1].qhd[ pipe_hdl.index ]; - - verify_int_qhd(p_int_qhd, &desc_ept_interrupt_out, TUSB_CLASS_HID); - - TEST_ASSERT_EQUAL(desc_ept_interrupt_out.bInterval, p_int_qhd->interval_ms); - TEST_ASSERT_EQUAL(1, p_int_qhd->interrupt_smask); - TEST_ASSERT_EQUAL(0x1c, p_int_qhd->non_hs_interrupt_cmask); -} - -void test_open_interrupt_qhd_non_hs_9(void) -{ - tusb_descriptor_endpoint_t int_edp_interval = desc_ept_interrupt_out; - int_edp_interval.bInterval = 32; - - usbh_devices[dev_addr].speed = TUSB_SPEED_FULL; - - //------------- Code Under TEST -------------// - pipe_hdl = hcd_pipe_open(dev_addr, &int_edp_interval, TUSB_CLASS_HID); - p_int_qhd = &ehci_data.device[ pipe_hdl.dev_addr-1].qhd[ pipe_hdl.index ]; - - TEST_ASSERT_EQUAL(int_edp_interval.bInterval, p_int_qhd->interval_ms); - check_int_endpoint_link( get_period_head(hostid, 32), p_int_qhd); - check_int_endpoint_link( get_period_head(hostid, 8) , p_int_qhd); -} - -//--------------------------------------------------------------------+ -// PIPE CLOSE -//--------------------------------------------------------------------+ -void test_interrupt_close(void) -{ - pipe_hdl = hcd_pipe_open(dev_addr, &desc_ept_interrupt_out, TUSB_CLASS_HID); - p_int_qhd = qhd_get_from_pipe_handle(pipe_hdl); - - //------------- Code Under TEST -------------// - TEST_ASSERT_EQUAL(TUSB_ERROR_NONE, - hcd_pipe_close(pipe_hdl) ); - - TEST_ASSERT(p_int_qhd->is_removing); - TEST_ASSERT( align32(period_head_arr->next.address) != (uint32_t) p_int_qhd ); - TEST_ASSERT_EQUAL_HEX( (uint32_t) period_head_arr, align32(p_int_qhd->next.address ) ); - TEST_ASSERT_EQUAL(EHCI_QUEUE_ELEMENT_QHD, p_int_qhd->next.type); -} - -void test_interrupt_256ms_close(void) -{ - tusb_descriptor_endpoint_t int_edp_interval = desc_ept_interrupt_out; - int_edp_interval.bInterval = 9; - - pipe_hdl = hcd_pipe_open(dev_addr, &int_edp_interval, TUSB_CLASS_HID); - p_int_qhd = qhd_get_from_pipe_handle(pipe_hdl); - - //------------- Code Under TEST -------------// - TEST_ASSERT_EQUAL(TUSB_ERROR_NONE, - hcd_pipe_close(pipe_hdl) ); - - TEST_ASSERT(p_int_qhd->is_removing); - TEST_ASSERT( align32(get_period_head(hostid, 8)->address) != (uint32_t) p_int_qhd ); - TEST_ASSERT_EQUAL_HEX( (uint32_t) get_period_head(hostid, 8), align32(p_int_qhd->next.address ) ); - TEST_ASSERT_EQUAL(EHCI_QUEUE_ELEMENT_QHD, p_int_qhd->next.type); -} diff --git a/tests/test/test/host/ehci/test_pipe_interrupt_xfer.c b/tests/test/test/host/ehci/test_pipe_interrupt_xfer.c deleted file mode 100644 index f72b5d3ae..000000000 --- a/tests/test/test/host/ehci/test_pipe_interrupt_xfer.c +++ /dev/null @@ -1,236 +0,0 @@ -/**************************************************************************/ -/*! - @file test_ehci_pipe_bulk_xfer.c - @author hathach (tinyusb.org) - - @section LICENSE - - Software License Agreement (BSD License) - - Copyright (c) 2013, hathach (tinyusb.org) - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - 3. Neither the name of the copyright holders nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY - EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY - DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND - ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - This file is part of the tinyusb stack. -*/ -/**************************************************************************/ - -#include -#include "unity.h" -#include "tusb_option.h" -#include "errors.h" -#include "binary.h" -#include "type_helper.h" - -#include "hal.h" -#include "mock_osal.h" -#include "hcd.h" -#include "mock_usbh_hcd.h" -#include "ehci.h" -#include "ehci_controller_fake.h" -#include "host_helper.h" - -usbh_device_info_t usbh_devices[TUSB_CFG_HOST_DEVICE_MAX+1]; - -static uint8_t const hub_addr = 2; -static uint8_t const hub_port = 2; -static uint8_t dev_addr; -static uint8_t hostid; -static uint8_t xfer_data [100]; -static uint8_t data2[100]; - -static ehci_qhd_t *period_head_arr; -static ehci_qhd_t *p_qhd_interrupt; -static pipe_handle_t pipe_hdl_interrupt; - -static tusb_descriptor_endpoint_t const desc_ept_interrupt_in = -{ - .bLength = sizeof(tusb_descriptor_endpoint_t), - .bDescriptorType = TUSB_DESC_TYPE_ENDPOINT, - .bEndpointAddress = 0x81, - .bmAttributes = { .xfer = TUSB_XFER_INTERRUPT }, - .wMaxPacketSize = 8, - .bInterval = 2 -}; - -static tusb_descriptor_endpoint_t const desc_ept_interupt_out = -{ - .bLength = sizeof(tusb_descriptor_endpoint_t), - .bDescriptorType = TUSB_DESC_TYPE_ENDPOINT, - .bEndpointAddress = 0x01, - .bmAttributes = { .xfer = TUSB_XFER_INTERRUPT }, - .wMaxPacketSize = 64, - .bInterval = 3 -}; - -//--------------------------------------------------------------------+ -// Setup/Teardown + helper declare -//--------------------------------------------------------------------+ -void setUp(void) -{ - ehci_controller_init(); - - memclr_(usbh_devices, sizeof(usbh_device_info_t)*(TUSB_CFG_HOST_DEVICE_MAX+1)); - memclr_(xfer_data, sizeof(xfer_data)); - - TEST_ASSERT_STATUS( hcd_init() ); - - dev_addr = 1; - hostid = RANDOM(CONTROLLER_HOST_NUMBER) + TEST_CONTROLLER_HOST_START_INDEX; - - helper_usbh_device_emulate(dev_addr , hub_addr, hub_port, hostid, TUSB_SPEED_HIGH); - - period_head_arr = (ehci_qhd_t*) get_period_head( hostid, 1 ); - - //------------- pipe open -------------// - pipe_hdl_interrupt = hcd_pipe_open(dev_addr, &desc_ept_interrupt_in, TUSB_CLASS_HID); - - TEST_ASSERT_EQUAL(dev_addr, pipe_hdl_interrupt.dev_addr); - TEST_ASSERT_EQUAL(TUSB_XFER_INTERRUPT, pipe_hdl_interrupt.xfer_type); - - p_qhd_interrupt = &ehci_data.device[ dev_addr -1].qhd[ pipe_hdl_interrupt.index ]; -} - -void tearDown(void) -{ -} -//--------------------------------------------------------------------+ -// BULK TRANSFER -//--------------------------------------------------------------------+ -void verify_qtd(ehci_qtd_t *p_qtd, uint8_t p_data[], uint16_t length) -{ - TEST_ASSERT_TRUE(p_qtd->alternate.terminate); // not used, always invalid - - //------------- status -------------// - TEST_ASSERT_FALSE(p_qtd->pingstate_err); - TEST_ASSERT_FALSE(p_qtd->non_hs_split_state); - TEST_ASSERT_FALSE(p_qtd->non_hs_period_missed_uframe); - TEST_ASSERT_FALSE(p_qtd->xact_err); - TEST_ASSERT_FALSE(p_qtd->babble_err); - TEST_ASSERT_FALSE(p_qtd->buffer_err); - TEST_ASSERT_FALSE(p_qtd->halted); - TEST_ASSERT_TRUE(p_qtd->active); - - TEST_ASSERT_FALSE(p_qtd->data_toggle); - TEST_ASSERT_EQUAL(3, p_qtd->cerr); - TEST_ASSERT_EQUAL(0, p_qtd->current_page); - TEST_ASSERT_EQUAL(length, p_qtd->total_bytes); - TEST_ASSERT_TRUE(p_qtd->used); - - TEST_ASSERT_EQUAL_HEX( p_data, p_qtd->buffer[0] ); - for(uint8_t i=1; i<5; i++) - { - TEST_ASSERT_EQUAL_HEX( align4k((uint32_t) (p_data+4096*i)), align4k(p_qtd->buffer[i]) ); - } -} - -void test_interrupt_xfer(void) -{ - //------------- Code Under Test -------------// - TEST_ASSERT_STATUS( hcd_pipe_xfer(pipe_hdl_interrupt, xfer_data, sizeof(xfer_data), true) ); - - ehci_qtd_t* p_qtd = p_qhd_interrupt->p_qtd_list_head; - TEST_ASSERT_NOT_NULL(p_qtd); - - verify_qtd( p_qtd, xfer_data, sizeof(xfer_data)); - TEST_ASSERT_EQUAL_HEX(p_qhd_interrupt->qtd_overlay.next.address, p_qtd); - TEST_ASSERT_TRUE(p_qtd->next.terminate); - TEST_ASSERT_EQUAL(EHCI_PID_IN, p_qtd->pid); - TEST_ASSERT_TRUE(p_qtd->int_on_complete); -} - -void test_interrupt_xfer_double(void) -{ - //------------- Code Under Test -------------// - TEST_ASSERT_STATUS( hcd_pipe_xfer(pipe_hdl_interrupt, xfer_data, sizeof(xfer_data), false) ); - - TEST_ASSERT_STATUS( hcd_pipe_xfer(pipe_hdl_interrupt, data2, sizeof(data2), true) ); - - ehci_qtd_t* p_head = p_qhd_interrupt->p_qtd_list_head; - ehci_qtd_t* p_tail = p_qhd_interrupt->p_qtd_list_tail; - - //------------- list head -------------// - TEST_ASSERT_NOT_NULL(p_head); - verify_qtd(p_head, xfer_data, sizeof(xfer_data)); - TEST_ASSERT_EQUAL_HEX(p_qhd_interrupt->qtd_overlay.next.address, p_head); - TEST_ASSERT_EQUAL(EHCI_PID_IN, p_head->pid); - TEST_ASSERT_FALSE(p_head->next.terminate); - TEST_ASSERT_FALSE(p_head->int_on_complete); - - //------------- list tail -------------// - TEST_ASSERT_NOT_NULL(p_tail); - verify_qtd(p_tail, data2, sizeof(data2)); - TEST_ASSERT_EQUAL_HEX( align32(p_head->next.address), p_tail); - TEST_ASSERT_EQUAL(EHCI_PID_IN, p_tail->pid); - TEST_ASSERT_TRUE(p_tail->next.terminate); - TEST_ASSERT_TRUE(p_tail->int_on_complete); -} - -void check_qhd_after_complete(ehci_qhd_t *p_qhd) -{ - TEST_ASSERT_TRUE(p_qhd->qtd_overlay.next.terminate); - TEST_ASSERT_NULL(p_qhd->p_qtd_list_head); - TEST_ASSERT_NULL(p_qhd->p_qtd_list_tail); -} - -void test_interrupt_xfer_complete_isr_interval_less_than_1ms(void) -{ - TEST_ASSERT_STATUS( hcd_pipe_xfer(pipe_hdl_interrupt, xfer_data, sizeof(xfer_data), false) ); - - TEST_ASSERT_STATUS( hcd_pipe_xfer(pipe_hdl_interrupt, data2, sizeof(data2), true) ); - - usbh_isr_Expect(pipe_hdl_interrupt, TUSB_CLASS_HID, TUSB_EVENT_XFER_COMPLETE); - - ehci_qtd_t* p_head = p_qhd_interrupt->p_qtd_list_head; - ehci_qtd_t* p_tail = p_qhd_interrupt->p_qtd_list_tail; - - //------------- Code Under Test -------------// - ehci_controller_run(hostid); - - check_qhd_after_complete(p_qhd_interrupt); - TEST_ASSERT_FALSE(p_head->used); - TEST_ASSERT_FALSE(p_tail->used); -} - -void test_interrupt_xfer_complete_isr_interval_2ms(void) -{ - tusb_descriptor_endpoint_t desc_endpoint_2ms = desc_ept_interrupt_in; - desc_endpoint_2ms.bInterval = 5; - - pipe_handle_t pipe_hdl_2ms = hcd_pipe_open(dev_addr, &desc_endpoint_2ms, TUSB_CLASS_HID); - ehci_qhd_t * p_qhd_2ms = &ehci_data.device[ dev_addr -1].qhd[ pipe_hdl_2ms.index ]; - - TEST_ASSERT_STATUS( hcd_pipe_xfer(pipe_hdl_2ms, xfer_data, sizeof(xfer_data), false) ); - - ehci_qtd_t* p_head = p_qhd_2ms->p_qtd_list_head; - ehci_qtd_t* p_tail = p_qhd_2ms->p_qtd_list_tail; - - //------------- Code Under Test -------------// - ehci_controller_run(hostid); - - check_qhd_after_complete(p_qhd_2ms); - TEST_ASSERT_FALSE(p_head->used); - TEST_ASSERT_FALSE(p_tail->used); - -} diff --git a/tests/test/test/host/ehci/test_pipe_isochronous_open.c b/tests/test/test/host/ehci/test_pipe_isochronous_open.c deleted file mode 100644 index b2ebbf944..000000000 --- a/tests/test/test/host/ehci/test_pipe_isochronous_open.c +++ /dev/null @@ -1,99 +0,0 @@ -/**************************************************************************/ -/*! - @file test_ehci_pipe.c - @author hathach (tinyusb.org) - - @section LICENSE - - Software License Agreement (BSD License) - - Copyright (c) 2013, hathach (tinyusb.org) - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - 3. Neither the name of the copyright holders nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY - EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY - DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND - ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - This file is part of the tinyusb stack. -*/ -/**************************************************************************/ - -#include "unity.h" -#include "tusb_option.h" -#include "errors.h" -#include "binary.h" -#include "type_helper.h" - -#include "hal.h" -#include "mock_osal.h" -#include "hcd.h" -#include "mock_usbh_hcd.h" -#include "ehci.h" -#include "ehci_controller_fake.h" -#include "host_helper.h" - -usbh_device_info_t usbh_devices[TUSB_CFG_HOST_DEVICE_MAX+1]; - -static uint8_t const hub_addr = 2; -static uint8_t const hub_port = 2; -static uint8_t dev_addr; -static uint8_t hostid; - -static ehci_qhd_t *period_head_arr; -//--------------------------------------------------------------------+ -// Setup/Teardown + helper declare -//--------------------------------------------------------------------+ -void setUp(void) -{ - memclr_(usbh_devices, sizeof(usbh_device_info_t)*(TUSB_CFG_HOST_DEVICE_MAX+1)); - - hcd_init(); - - dev_addr = 1; - hostid = RANDOM(CONTROLLER_HOST_NUMBER) + TEST_CONTROLLER_HOST_START_INDEX; - - helper_usbh_device_emulate(dev_addr , hub_addr, hub_port, hostid, TUSB_SPEED_HIGH); - - period_head_arr = get_period_head( hostid, 1 ); -} - -void tearDown(void) -{ -} - -//--------------------------------------------------------------------+ -// TODO ISOCRHONOUS PIPE -//--------------------------------------------------------------------+ -tusb_descriptor_endpoint_t const desc_ept_iso_in = -{ - .bLength = sizeof(tusb_descriptor_endpoint_t), - .bDescriptorType = TUSB_DESC_TYPE_ENDPOINT, - .bEndpointAddress = 0x83, - .bmAttributes = { .xfer = TUSB_XFER_ISOCHRONOUS }, - .wMaxPacketSize = 1024, - .bInterval = 1 -}; - -void test_open_isochronous(void) -{ - pipe_handle_t pipe_hdl = hcd_pipe_open(dev_addr, &desc_ept_iso_in, TUSB_CLASS_AUDIO); - TEST_ASSERT_EQUAL(0, pipe_hdl.dev_addr); -} diff --git a/tests/test/test/host/hid/hidh_callback.h b/tests/test/test/host/hid/hidh_callback.h deleted file mode 100644 index 70da64695..000000000 --- a/tests/test/test/host/hid/hidh_callback.h +++ /dev/null @@ -1,71 +0,0 @@ -/**************************************************************************/ -/*! - @file tusb_callback.h - @author hathach (tinyusb.org) - - @section LICENSE - - Software License Agreement (BSD License) - - Copyright (c) 2013, hathach (tinyusb.org) - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - 3. Neither the name of the copyright holders nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY - EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY - DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND - ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - This file is part of the tinyusb stack. -*/ -/**************************************************************************/ - -/** \file - * \brief TBD - * - * \note TBD - */ - -/** \ingroup TBD - * \defgroup TBD - * \brief TBD - * - * @{ - */ - -#ifndef _TUSB_HIDH_CALLBACK_H_ -#define _TUSB_HIDH_CALLBACK_H_ - -#ifdef __cplusplus - extern "C" { -#endif - -#include "common/common.h" - -//------------- hidh -------------// -void tusbh_hid_keyboard_isr(uint8_t dev_addr, tusb_event_t event) ATTR_WEAK; -void tusbh_hid_mouse_isr(uint8_t dev_addr, tusb_event_t event) ATTR_WEAK; - -#ifdef __cplusplus - } -#endif - -#endif /* _TUSB_HIDH_CALLBACK_H_ */ - -/** @} */ diff --git a/tests/test/test/host/hid/test_hid_host.c b/tests/test/test/host/hid/test_hid_host.c deleted file mode 100644 index 900319e5e..000000000 --- a/tests/test/test/host/hid/test_hid_host.c +++ /dev/null @@ -1,97 +0,0 @@ -/**************************************************************************/ -/*! - @file test_host_hid.c - @author hathach (tinyusb.org) - - @section LICENSE - - Software License Agreement (BSD License) - - Copyright (c) 2013, hathach (tinyusb.org) - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - 3. Neither the name of the copyright holders nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY - EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY - DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND - ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - This file is part of the tinyusb stack. -*/ -/**************************************************************************/ - -#include "stdlib.h" -#include "unity.h" -#include "tusb_option.h" -#include "errors.h" -#include "binary.h" -#include "type_helper.h" - -#include "descriptor_test.h" -#include "mock_osal.h" -#include "mock_hcd.h" -#include "mock_usbh.h" - -#include "hid_host.h" - -uint8_t dev_addr; -pipe_handle_t pipe_hdl; - -extern hidh_interface_info_t keyboard_data[TUSB_CFG_HOST_DEVICE_MAX]; - -tusb_descriptor_interface_t const *p_kbd_interface_desc = &desc_configuration.keyboard_interface; -tusb_hid_descriptor_hid_t const *p_kbh_hid_desc = &desc_configuration.keyboard_hid; -tusb_descriptor_endpoint_t const *p_kdb_endpoint_desc = &desc_configuration.keyboard_endpoint; - -void setUp(void) -{ - dev_addr = RANDOM(TUSB_CFG_HOST_DEVICE_MAX)+1; - pipe_hdl = (pipe_handle_t) {.dev_addr = dev_addr, .xfer_type = TUSB_XFER_INTERRUPT, .index = 2}; -} - -void tearDown(void) -{ -} - -//void test_hidh_open_ok(void) -//{ -// uint16_t length=0; -// -// // TODO expect get HID report descriptor -// hcd_pipe_open_IgnoreAndReturn( pipe_hdl ); -// -// //------------- Code Under TEST -------------// -// TEST_ASSERT_EQUAL(TUSB_ERROR_NONE, hidh_open_subtask(dev_addr, p_kbd_interface_desc, &length) ); -// -// TEST_ASSERT_EQUAL(sizeof(tusb_descriptor_interface_t) + sizeof(tusb_hid_descriptor_hid_t) + sizeof(tusb_descriptor_endpoint_t), -// length); -//} - -void test_hidh_close(void) -{ - keyboard_data[dev_addr-1].pipe_hdl = pipe_hdl; - keyboard_data[dev_addr-1].report_size = 8; - - hcd_pipe_close_ExpectAndReturn(pipe_hdl, TUSB_ERROR_NONE); - - //------------- Code Under TEST -------------// - hidh_close(dev_addr); - - TEST_ASSERT_MEM_ZERO(&keyboard_data[dev_addr-1], sizeof(hidh_interface_info_t)); -} diff --git a/tests/test/test/host/hid/test_hidh_keyboard.c b/tests/test/test/host/hid/test_hidh_keyboard.c deleted file mode 100644 index 62bcc8b45..000000000 --- a/tests/test/test/host/hid/test_hidh_keyboard.c +++ /dev/null @@ -1,224 +0,0 @@ -/**************************************************************************/ -/*! - @file test_host_hid_keyboard.c - @author hathach (tinyusb.org) - - @section LICENSE - - Software License Agreement (BSD License) - - Copyright (c) 2013, hathach (tinyusb.org) - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - 3. Neither the name of the copyright holders nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY - EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY - DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND - ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - This file is part of the tinyusb stack. -*/ -/**************************************************************************/ - -#include "stdlib.h" -#include "unity.h" -#include "type_helper.h" -#include "errors.h" -#include "common/common.h" -#include "hid_host.h" -#include "mock_osal.h" -#include "mock_usbh.h" -#include "mock_hcd.h" -#include "mock_hidh_callback.h" -#include "descriptor_test.h" - -extern hidh_interface_info_t keyboard_data[TUSB_CFG_HOST_DEVICE_MAX]; - -tusb_keyboard_report_t sample_key[2] = -{ - { - .modifier = KEYBOARD_MODIFIER_LEFTCTRL, - .keycode = {4}//{KEYBOARD_KEYCODE_a} TODO ascii to key code table - }, - { - .modifier = KEYBOARD_MODIFIER_RIGHTALT, - .keycode = {5}//{KEYBOARD_KEYCODE_z} - } -}; - -uint8_t dev_addr; -hidh_interface_info_t *p_hidh_kbd; - -tusb_keyboard_report_t report; - -tusb_descriptor_interface_t const *p_kbd_interface_desc = &desc_configuration.keyboard_interface; -tusb_descriptor_endpoint_t const *p_kdb_endpoint_desc = &desc_configuration.keyboard_endpoint; - -void setUp(void) -{ - hidh_init(); - memclr_(&report, sizeof(tusb_keyboard_report_t)); - dev_addr = RANDOM(TUSB_CFG_HOST_DEVICE_MAX)+1; - - p_hidh_kbd = &keyboard_data[dev_addr-1]; - - p_hidh_kbd->report_size = sizeof(tusb_keyboard_report_t); - p_hidh_kbd->pipe_hdl = (pipe_handle_t) { - .dev_addr = dev_addr, - .xfer_type = TUSB_XFER_INTERRUPT, - .index = 1 - }; - -} - -void tearDown(void) -{ -} - -void test_keyboard_init(void) -{ - hidh_init(); - - TEST_ASSERT_MEM_ZERO(keyboard_data, sizeof(hidh_interface_info_t)*TUSB_CFG_HOST_DEVICE_MAX); -} - -//------------- is supported -------------// -void test_keyboard_is_supported_fail_unplug(void) -{ - tusbh_device_get_state_IgnoreAndReturn(TUSB_DEVICE_STATE_UNPLUG); - TEST_ASSERT_FALSE( tusbh_hid_keyboard_is_mounted(dev_addr) ); -} - -void test_keyboard_is_supported_fail_not_opened(void) -{ - hidh_init(); - tusbh_device_get_state_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED); - TEST_ASSERT_FALSE( tusbh_hid_keyboard_is_mounted(dev_addr) ); -} - -void test_keyboard_is_supported_ok(void) -{ - tusbh_device_get_state_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED); - TEST_ASSERT_TRUE( tusbh_hid_keyboard_is_mounted(dev_addr) ); -} - -static tusb_error_t stub_set_idle_request(uint8_t address, tusb_std_request_t const* p_request, uint8_t* data, int num_call) -{ - TEST_ASSERT_EQUAL( dev_addr, address); - - //------------- expecting Set Idle with value = 0 -------------// - TEST_ASSERT_NOT_NULL( p_request ); - TEST_ASSERT_EQUAL(TUSB_DIR_HOST_TO_DEV , p_request->bmRequestType.direction); - TEST_ASSERT_EQUAL(TUSB_REQUEST_TYPE_CLASS , p_request->bmRequestType.type); - TEST_ASSERT_EQUAL(TUSB_REQUEST_RECIPIENT_INTERFACE , p_request->bmRequestType.recipient); - TEST_ASSERT_EQUAL(HID_REQUEST_CONTROL_SET_IDLE , p_request->bRequest); - TEST_ASSERT_EQUAL(0 , p_request->wValue); - TEST_ASSERT_EQUAL(p_kbd_interface_desc->bInterfaceNumber , p_request->wIndex); - - TEST_ASSERT_NULL(data); - - return TUSB_ERROR_NONE; -} - -void test_keyboard_open_ok(void) -{ - uint16_t length=0; - pipe_handle_t pipe_hdl = {.dev_addr = dev_addr, .xfer_type = TUSB_XFER_INTERRUPT, .index = 2}; - - hidh_init(); - - usbh_control_xfer_subtask_StubWithCallback(stub_set_idle_request); - hcd_pipe_open_ExpectAndReturn(dev_addr, p_kdb_endpoint_desc, TUSB_CLASS_HID, pipe_hdl); - tusbh_hid_keyboard_isr_Expect(dev_addr, TUSB_EVENT_INTERFACE_OPEN); - - //------------- Code Under TEST -------------// - TEST_ASSERT_EQUAL(TUSB_ERROR_NONE, hidh_open_subtask(dev_addr, p_kbd_interface_desc, &length)); - - TEST_ASSERT_PIPE_HANDLE(pipe_hdl, p_hidh_kbd->pipe_hdl); - TEST_ASSERT_EQUAL(8, p_hidh_kbd->report_size); - TEST_ASSERT_EQUAL(sizeof(tusb_descriptor_interface_t) + sizeof(tusb_hid_descriptor_hid_t) + sizeof(tusb_descriptor_endpoint_t), - length); - TEST_ASSERT_EQUAL(p_kbd_interface_desc->bInterfaceNumber, p_hidh_kbd->interface_number); - - tusbh_device_get_state_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED); - TEST_ASSERT_TRUE( tusbh_hid_keyboard_is_mounted(dev_addr) ); - TEST_ASSERT_EQUAL(TUSB_INTERFACE_STATUS_READY, p_hidh_kbd->status); -} - -//--------------------------------------------------------------------+ -// keyboard_get -//--------------------------------------------------------------------+ -void test_keyboard_get_invalid_address(void) -{ - tusbh_device_get_state_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED); - TEST_ASSERT_EQUAL(TUSB_ERROR_INVALID_PARA, tusbh_hid_keyboard_get_report(0, NULL)); // invalid address -} - -void test_keyboard_get_invalid_buffer(void) -{ - tusbh_device_get_state_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED); - TEST_ASSERT_EQUAL(TUSB_ERROR_INVALID_PARA, tusbh_hid_keyboard_get_report(dev_addr, NULL)); // invalid buffer -} - -void test_keyboard_get_device_not_ready(void) -{ - tusbh_device_get_state_IgnoreAndReturn(TUSB_DEVICE_STATE_UNPLUG); - TEST_ASSERT_EQUAL(TUSB_ERROR_DEVICE_NOT_READY, tusbh_hid_keyboard_get_report(dev_addr, &report)); // device not mounted -} - -void test_keyboard_get_report_xfer_failed() -{ - tusbh_device_get_state_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED); - hcd_pipe_xfer_ExpectAndReturn(p_hidh_kbd->pipe_hdl, (uint8_t*) &report, p_hidh_kbd->report_size, true, TUSB_ERROR_INVALID_PARA); - - //------------- Code Under TEST -------------// - TEST_ASSERT_EQUAL(TUSB_ERROR_INVALID_PARA, tusbh_hid_keyboard_get_report(dev_addr, &report)); -} - -void test_keyboard_get_report_xfer_failed_busy() -{ - tusbh_device_get_state_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED); - p_hidh_kbd->status = TUSB_INTERFACE_STATUS_BUSY; - TEST_ASSERT_EQUAL(TUSB_ERROR_INTERFACE_IS_BUSY, tusbh_hid_keyboard_get_report(dev_addr, &report)); -} - -void test_keyboard_get_ok() -{ - tusbh_device_get_state_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED); - - TEST_ASSERT_EQUAL(TUSB_INTERFACE_STATUS_READY, tusbh_hid_keyboard_status(dev_addr)); - hcd_pipe_xfer_ExpectAndReturn(p_hidh_kbd->pipe_hdl, (uint8_t*) &report, p_hidh_kbd->report_size, true, TUSB_ERROR_NONE); - - //------------- Code Under TEST -------------// - TEST_ASSERT_EQUAL(TUSB_ERROR_NONE, tusbh_hid_keyboard_get_report(dev_addr, &report)); - TEST_ASSERT_EQUAL(TUSB_INTERFACE_STATUS_BUSY, tusbh_hid_keyboard_status(dev_addr)); -} - -void test_keyboard_isr_event_complete(void) -{ - tusbh_hid_keyboard_isr_Expect(dev_addr, TUSB_EVENT_XFER_COMPLETE); - - //------------- Code Under TEST -------------// - hidh_isr(p_hidh_kbd->pipe_hdl, TUSB_EVENT_XFER_COMPLETE); - - tusbh_device_get_state_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED); - TEST_ASSERT_EQUAL(TUSB_INTERFACE_STATUS_COMPLETE, tusbh_hid_keyboard_status(dev_addr)); -} - - diff --git a/tests/test/test/host/hid/test_hidh_mouse.c b/tests/test/test/host/hid/test_hidh_mouse.c deleted file mode 100644 index 0156f5a58..000000000 --- a/tests/test/test/host/hid/test_hidh_mouse.c +++ /dev/null @@ -1,226 +0,0 @@ -/**************************************************************************/ -/*! - @file test_hidh_mouse.c - @author hathach (tinyusb.org) - - @section LICENSE - - Software License Agreement (BSD License) - - Copyright (c) 2013, hathach (tinyusb.org) - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - 3. Neither the name of the copyright holders nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY - EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY - DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND - ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - This file is part of the tinyusb stack. -*/ -/**************************************************************************/ - -#include "stdlib.h" -#include "unity.h" -#include "type_helper.h" -#include "errors.h" -#include "common/common.h" - -#include "hid_host.h" -#include "mock_osal.h" -#include "mock_usbh.h" -#include "mock_hcd.h" -#include "mock_hidh_callback.h" -#include "descriptor_test.h" - -extern hidh_interface_info_t mouse_data[TUSB_CFG_HOST_DEVICE_MAX]; -hidh_interface_info_t *p_hidh_mouse; -tusb_mouse_report_t report; - -tusb_descriptor_interface_t const *p_mouse_interface_desc = &desc_configuration.mouse_interface; -tusb_descriptor_endpoint_t const *p_mouse_endpoint_desc = &desc_configuration.mouse_endpoint; - -uint8_t dev_addr; - -void setUp(void) -{ - hidh_init(); - - memclr_(&report, sizeof(tusb_mouse_report_t)); - dev_addr = RANDOM(TUSB_CFG_HOST_DEVICE_MAX)+1; - - p_hidh_mouse = &mouse_data[dev_addr-1]; - - p_hidh_mouse->report_size = sizeof(tusb_mouse_report_t); - p_hidh_mouse->pipe_hdl = (pipe_handle_t) { - .dev_addr = dev_addr, - .xfer_type = TUSB_XFER_INTERRUPT, - .index = 1 - }; -} - -void tearDown(void) -{ - -} - -void test_mouse_init(void) -{ - hidh_init(); - - TEST_ASSERT_MEM_ZERO(mouse_data, sizeof(hidh_interface_info_t)*TUSB_CFG_HOST_DEVICE_MAX); -} - -//------------- is supported -------------// -void test_mouse_is_supported_fail_unplug(void) -{ - tusbh_device_get_state_IgnoreAndReturn(TUSB_DEVICE_STATE_UNPLUG); - TEST_ASSERT_FALSE( tusbh_hid_mouse_is_mounted(dev_addr) ); -} - -void test_mouse_is_supported_fail_not_opened(void) -{ - hidh_init(); - tusbh_device_get_state_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED); - TEST_ASSERT_FALSE( tusbh_hid_mouse_is_mounted(dev_addr) ); -} - -void test_mouse_is_supported_ok(void) -{ - tusbh_device_get_state_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED); - TEST_ASSERT_TRUE( tusbh_hid_mouse_is_mounted(dev_addr) ); -} - -static tusb_error_t stub_set_idle_request(uint8_t address, tusb_std_request_t const* p_request, uint8_t* data, int num_call) -{ - TEST_ASSERT_EQUAL( dev_addr, address); - - //------------- expecting Set Idle with value = 0 -------------// - TEST_ASSERT_NOT_NULL( p_request ); - TEST_ASSERT_EQUAL(TUSB_DIR_HOST_TO_DEV , p_request->bmRequestType.direction); - TEST_ASSERT_EQUAL(TUSB_REQUEST_TYPE_CLASS , p_request->bmRequestType.type); - TEST_ASSERT_EQUAL(TUSB_REQUEST_RECIPIENT_INTERFACE , p_request->bmRequestType.recipient); - TEST_ASSERT_EQUAL(HID_REQUEST_CONTROL_SET_IDLE , p_request->bRequest); - TEST_ASSERT_EQUAL(0 , p_request->wValue); - TEST_ASSERT_EQUAL(p_mouse_interface_desc->bInterfaceNumber , p_request->wIndex); - - TEST_ASSERT_NULL(data); - - return TUSB_ERROR_NONE; -} - -void test_mouse_open_ok(void) -{ - uint16_t length=0; - pipe_handle_t pipe_hdl = {.dev_addr = dev_addr, .xfer_type = TUSB_XFER_INTERRUPT, .index = 2}; - - hidh_init(); - - usbh_control_xfer_subtask_StubWithCallback(stub_set_idle_request); - hcd_pipe_open_ExpectAndReturn(dev_addr, p_mouse_endpoint_desc, TUSB_CLASS_HID, pipe_hdl); - tusbh_hid_mouse_isr_Expect(dev_addr, TUSB_EVENT_INTERFACE_OPEN); - - //------------- Code Under TEST -------------// - TEST_ASSERT_STATUS( hidh_open_subtask(dev_addr, p_mouse_interface_desc, &length)); - - TEST_ASSERT_PIPE_HANDLE(pipe_hdl, p_hidh_mouse->pipe_hdl); - TEST_ASSERT_EQUAL(8, p_hidh_mouse->report_size); - TEST_ASSERT_EQUAL(sizeof(tusb_descriptor_interface_t) + sizeof(tusb_hid_descriptor_hid_t) + sizeof(tusb_descriptor_endpoint_t), - length); - TEST_ASSERT_EQUAL(p_mouse_interface_desc->bInterfaceNumber, p_hidh_mouse->interface_number); - - tusbh_device_get_state_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED); - TEST_ASSERT_TRUE( tusbh_hid_mouse_is_mounted(dev_addr) ); - TEST_ASSERT_EQUAL(TUSB_INTERFACE_STATUS_READY, p_hidh_mouse->status); - -} - -//--------------------------------------------------------------------+ -// mouse_get -//--------------------------------------------------------------------+ -void test_mouse_get_invalid_address(void) -{ - tusbh_device_get_state_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED); - TEST_ASSERT_EQUAL(TUSB_ERROR_INVALID_PARA, tusbh_hid_mouse_get_report(0, NULL)); // invalid address -} - -void test_mouse_get_invalid_buffer(void) -{ - tusbh_device_get_state_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED); - TEST_ASSERT_EQUAL(TUSB_ERROR_INVALID_PARA, tusbh_hid_mouse_get_report(dev_addr, NULL)); // invalid buffer -} - -void test_mouse_get_device_not_ready(void) -{ - tusbh_device_get_state_IgnoreAndReturn(TUSB_DEVICE_STATE_UNPLUG); - TEST_ASSERT_EQUAL(TUSB_ERROR_DEVICE_NOT_READY, tusbh_hid_mouse_get_report(dev_addr, &report)); // device not mounted -} - -void test_mouse_get_report_xfer_failed() -{ - tusbh_device_get_state_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED); - hcd_pipe_xfer_ExpectAndReturn(p_hidh_mouse->pipe_hdl, (uint8_t*) &report, p_hidh_mouse->report_size, true, TUSB_ERROR_INVALID_PARA); - - //------------- Code Under TEST -------------// - TEST_ASSERT_EQUAL(TUSB_ERROR_INVALID_PARA, tusbh_hid_mouse_get_report(dev_addr, &report)); -} - -void test_mouse_get_report_xfer_failed_busy() -{ - tusbh_device_get_state_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED); - p_hidh_mouse->status = TUSB_INTERFACE_STATUS_BUSY; - TEST_ASSERT_EQUAL(TUSB_ERROR_INTERFACE_IS_BUSY, tusbh_hid_mouse_get_report(dev_addr, &report)); -} - -void test_mouse_get_ok() -{ - tusbh_device_get_state_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED); - TEST_ASSERT_EQUAL(TUSB_INTERFACE_STATUS_READY, tusbh_hid_mouse_status(dev_addr)); - hcd_pipe_xfer_ExpectAndReturn(p_hidh_mouse->pipe_hdl, (uint8_t*) &report, p_hidh_mouse->report_size, true, TUSB_ERROR_NONE); - - //------------- Code Under TEST -------------// - TEST_ASSERT_STATUS( tusbh_hid_mouse_get_report(dev_addr, &report)); - - TEST_ASSERT_EQUAL(TUSB_INTERFACE_STATUS_BUSY, tusbh_hid_mouse_status(dev_addr)); -} - -void test_mouse_isr_event_xfer_complete(void) -{ - tusbh_hid_mouse_isr_Expect(dev_addr, TUSB_EVENT_XFER_COMPLETE); - - //------------- Code Under TEST -------------// - hidh_isr(p_hidh_mouse->pipe_hdl, TUSB_EVENT_XFER_COMPLETE); - - tusbh_device_get_state_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED); - TEST_ASSERT_EQUAL(TUSB_INTERFACE_STATUS_COMPLETE, tusbh_hid_mouse_status(dev_addr)); -} - -void test_mouse_isr_event_xfer_error(void) -{ - tusbh_hid_mouse_isr_Expect(dev_addr, TUSB_EVENT_XFER_ERROR); - - //------------- Code Under TEST -------------// - hidh_isr(p_hidh_mouse->pipe_hdl, TUSB_EVENT_XFER_ERROR); - - tusbh_device_get_state_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED); - TEST_ASSERT_EQUAL(TUSB_INTERFACE_STATUS_ERROR, tusbh_hid_mouse_status(dev_addr)); -} - - - diff --git a/tests/test/test/host/host_helper.h b/tests/test/test/host/host_helper.h deleted file mode 100644 index 97102c565..000000000 --- a/tests/test/test/host/host_helper.h +++ /dev/null @@ -1,77 +0,0 @@ -/* - * host_helper.h - * - * Created on: May 13, 2013 - * Author: hathach - */ - -/* - * Software License Agreement (BSD License) - * Copyright (c) 2012, hathach (tinyusb.org) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT - * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT - * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING - * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY - * OF SUCH DAMAGE. - * - * This file is part of the tiny usb stack. - */ - -#include "common/common.h" -#include "host/usbh.h" -#include "host/usbh_hcd.h" - -static inline void helper_class_init_expect(void) -{ - hidh_init_Expect(); - //TODO update more classes -} - -static inline void helper_class_close_expect(uint8_t dev_addr) -{ - hidh_close_Expect(dev_addr); - //TODO update more classes -} - - - -static inline void helper_usbh_init_expect(void) -{ - osal_semaphore_create_IgnoreAndReturn( (osal_semaphore_handle_t) 0x1234); - osal_task_create_IgnoreAndReturn(TUSB_ERROR_NONE); - osal_queue_create_IgnoreAndReturn( (osal_queue_handle_t) 0x4566 ); - osal_mutex_create_IgnoreAndReturn((osal_mutex_handle_t) 0x789a); -} - -static inline void helper_usbh_device_emulate(uint8_t dev_addr, uint8_t hub_addr, uint8_t hub_port, uint8_t hostid, tusb_speed_t speed) -{ - usbh_devices[dev_addr].core_id = hostid; - usbh_devices[dev_addr].hub_addr = hub_addr; - usbh_devices[dev_addr].hub_port = hub_port; - usbh_devices[dev_addr].speed = speed; - usbh_devices[dev_addr].state = dev_addr ? TUSB_DEVICE_STATE_CONFIGURED : TUSB_DEVICE_STATE_UNPLUG; -} - - - - - - diff --git a/tests/test/test/host/hub/test_hub.c b/tests/test/test/host/hub/test_hub.c deleted file mode 100644 index 5aef5dccc..000000000 --- a/tests/test/test/host/hub/test_hub.c +++ /dev/null @@ -1,52 +0,0 @@ -/**************************************************************************/ -/*! - @file test_hub.c - @author hathach (tinyusb.org) - - @section LICENSE - - Software License Agreement (BSD License) - - Copyright (c) 2013, hathach (tinyusb.org) - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - 3. Neither the name of the copyright holders nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY - EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY - DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND - ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - This file is part of the tinyusb stack. -*/ -/**************************************************************************/ - -#include "unity.h" - -void setUp(void) -{ -} - -void tearDown(void) -{ -} - -void test_() -{ - // TEST_IGNORE(); -} diff --git a/tests/test/test/host/integration/test_hidh_keyboard_integrate.c b/tests/test/test/host/integration/test_hidh_keyboard_integrate.c deleted file mode 100644 index a9fec44a1..000000000 --- a/tests/test/test/host/integration/test_hidh_keyboard_integrate.c +++ /dev/null @@ -1,132 +0,0 @@ -/**************************************************************************/ -/*! - @file test_hidh_keyboard.c - @author hathach (tinyusb.org) - - @section LICENSE - - Software License Agreement (BSD License) - - Copyright (c) 2013, hathach (tinyusb.org) - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - 3. Neither the name of the copyright holders nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY - EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY - DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND - ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - This file is part of the tinyusb stack. -*/ -/**************************************************************************/ - -//#include "stdlib.h" -//#include "unity.h" -//#include "type_helper.h" -//#include "tusb_option.h" -//#include "errors.h" -// -//#include "mock_osal.h" -//#include "hcd.h" -//#include "usbh.h" -//#include "tusb.h" -//#include "hid_host.h" -////#include "ehci_controller_fake.h" -// -//#include "descriptor_test.h" -// -//uint8_t dev_addr; -//uint8_t hostid; -// -void setUp(void) -{ -// dev_addr = RANDOM(TUSB_CFG_HOST_DEVICE_MAX)+1; -// hostid = RANDOM(CONTROLLER_HOST_NUMBER) + TEST_CONTROLLER_HOST_START_INDEX; -// -//// ehci_controller_init(); -// tusb_init(); -// -} -// -void tearDown(void) -{ -} -// -//osal_semaphore_handle_t sem_create_stub(osal_semaphore_t * const sem, int num_call) -//{ -// (*p_sem) = 0; -// return (osal_semaphore_handle_t) p_sem; -//} -//void sem_wait_stub(osal_semaphore_handle_t const sem_hdl, uint32_t msec, tusb_error_t *p_error, int num_call) -//{ -// -//} -//tusb_error_t sem_post_stub(osal_semaphore_handle_t const sem_hdl, int num_call) -//{ -// (*sem_hdl)++; -// -// return TUSB_ERROR_NONE; -//} -//void sem_reset_stub(osal_semaphore_handle_t const sem_hdl, int num_call) -//{ -// (*sem_hdl) = 0; -//} -// -//osal_queue_handle_t queue_create_stub (osal_queue_t *p_queue, int num_call) -//{ -// p_queue->count = p_queue->wr_idx = p_queue->rd_idx = 0; -// return (osal_queue_handle_t) p_queue; -//} -//void queue_receive_stub (osal_queue_handle_t const queue_hdl, uint32_t *p_data, uint32_t msec, tusb_error_t *p_error, int num_call) -//{ -// -//} -//tusb_error_t queue_send_stub (osal_queue_handle_t const queue_hdl, uint32_t data, int num_call) -//{ -// //TODO mutex lock hal_interrupt_disable -// -// queue_hdl->buffer[queue_hdl->wr_idx] = data; -// queue_hdl->wr_idx = (queue_hdl->wr_idx + 1) % queue_hdl->depth; -// -// if (queue_hdl->depth == queue_hdl->count) // queue is full, 1st rd is overwritten -// { -// queue_hdl->rd_idx = queue_hdl->wr_idx; // keep full state -// }else -// { -// queue_hdl->count++; -// } -// -// //TODO mutex unlock hal_interrupt_enable -// -// return TUSB_ERROR_NONE; -//} -//void queue_flush_stub(osal_queue_handle_t const queue_hdl, int num_call) -//{ -// queue_hdl->count = queue_hdl->rd_idx = queue_hdl->wr_idx = 0; -//} -// -//void test_(void) -//{ -// ehci_controller_device_plug(hostid, TUSB_SPEED_HIGH); -// -// tusb_task_runner(); // get 8-byte descriptor -// ehci_controller_control_xfer_proceed(0, &desc_device); -// -// tusb_task_runner(); // get 8-byte descriptor -//} diff --git a/tests/test/test/host/msc/test_msc_host.c b/tests/test/test/host/msc/test_msc_host.c deleted file mode 100644 index 4e42b3023..000000000 --- a/tests/test/test/host/msc/test_msc_host.c +++ /dev/null @@ -1,63 +0,0 @@ -/**************************************************************************/ -/*! - @file test_msc_host.c - @author hathach (tinyusb.org) - - @section LICENSE - - Software License Agreement (BSD License) - - Copyright (c) 2013, hathach (tinyusb.org) - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - 3. Neither the name of the copyright holders nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY - EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY - DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND - ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - This file is part of the tinyusb stack. -*/ -/**************************************************************************/ - -#include "stdlib.h" -#include "unity.h" -#include "tusb_option.h" -#include "errors.h" -#include "binary.h" -#include "type_helper.h" - -//#include "descriptor_test.h" -//#include "msc_host.h" -//#include "usbh.h" -//#include "hcd.h" -//#include "ehci.h" - -void setUp(void) -{ -} - -void tearDown(void) -{ -} - -void test_() -{ - // TEST_IGNORE(); -} diff --git a/tests/test/test/host/usbh/test_enum_task.c b/tests/test/test/host/usbh/test_enum_task.c deleted file mode 100644 index ae3fe34c5..000000000 --- a/tests/test/test/host/usbh/test_enum_task.c +++ /dev/null @@ -1,290 +0,0 @@ -/**************************************************************************/ -/*! - @file test_enum_task.c - @author hathach (tinyusb.org) - - @section LICENSE - - Software License Agreement (BSD License) - - Copyright (c) 2013, hathach (tinyusb.org) - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - 3. Neither the name of the copyright holders nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY - EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY - DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND - ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - This file is part of the tinyusb stack. -*/ -/**************************************************************************/ - -#include "unity.h" -#include "errors.h" -#include "descriptor_test.h" - -#include "mock_osal.h" -#include "usbh.h" -#include "mock_hcd.h" -#include "usbh_hcd.h" - -#include "mock_tusb_callback.h" -#include "mock_hid_host.h" - -extern usbh_device_info_t usbh_devices[TUSB_CFG_HOST_DEVICE_MAX+1]; -extern uint8_t enum_data_buffer[TUSB_CFG_HOST_ENUM_BUFFER_SIZE]; - -usbh_enumerate_t const enum_connect = { - .core_id = 0, - .hub_addr = 0, - .hub_port = 0, -}; - -tusb_speed_t device_speed = TUSB_SPEED_FULL; - -void queue_recv_stub (osal_queue_handle_t const queue_hdl, uint32_t *p_data, uint32_t msec, tusb_error_t *p_error, int num_call); -void semaphore_wait_success_stub(osal_semaphore_handle_t const sem_hdl, uint32_t msec, tusb_error_t *p_error, int num_call); -tusb_error_t control_xfer_stub(uint8_t dev_addr, const tusb_std_request_t * const p_request, uint8_t data[], int num_call); - -void setUp(void) -{ - memclr_(usbh_devices, sizeof(usbh_device_info_t)*(TUSB_CFG_HOST_DEVICE_MAX+1)); - - osal_queue_receive_StubWithCallback(queue_recv_stub); - osal_semaphore_wait_StubWithCallback(semaphore_wait_success_stub); - osal_mutex_wait_StubWithCallback(semaphore_wait_success_stub); - osal_mutex_release_IgnoreAndReturn(TUSB_ERROR_NONE); - hcd_pipe_control_xfer_StubWithCallback(control_xfer_stub); - - hcd_port_connect_status_ExpectAndReturn(enum_connect.core_id, true); - hcd_port_reset_Expect(enum_connect.core_id); - hcd_port_speed_get_ExpectAndReturn(enum_connect.core_id, device_speed); - osal_semaphore_reset_Expect( usbh_devices[0].control.sem_hdl ); - osal_mutex_reset_Expect( usbh_devices[0].control.mutex_hdl ); - hcd_pipe_control_open_ExpectAndReturn(0, 8, TUSB_ERROR_NONE); -} - -void tearDown(void) -{ -} - -//--------------------------------------------------------------------+ -// STUB & HELPER -//--------------------------------------------------------------------+ -void queue_recv_stub (osal_queue_handle_t const queue_hdl, uint32_t *p_data, uint32_t msec, tusb_error_t *p_error, int num_call) -{ - (*p_data) = ( *((uint32_t*) &enum_connect) ); - (*p_error) = TUSB_ERROR_NONE; -} - -void semaphore_wait_success_stub(osal_semaphore_handle_t const sem_hdl, uint32_t msec, tusb_error_t *p_error, int num_call) -{ - (*p_error) = TUSB_ERROR_NONE; -} - -#define semaphore_wait_timeout_stub(n) semaphore_wait_timeout_##n -#define semaphore_wait_timeout(n) \ - void semaphore_wait_timeout_##n(osal_semaphore_handle_t const sem_hdl, uint32_t msec, tusb_error_t *p_error, int num_call) {\ - if (num_call >= n)\ - (*p_error) = TUSB_ERROR_OSAL_TIMEOUT;\ - else \ - (*p_error) = TUSB_ERROR_NONE;\ - } - -semaphore_wait_timeout(0) -semaphore_wait_timeout(1) -semaphore_wait_timeout(2) -semaphore_wait_timeout(3) -semaphore_wait_timeout(4) -semaphore_wait_timeout(5) -semaphore_wait_timeout(6) -semaphore_wait_timeout(7) -semaphore_wait_timeout(8) - -tusb_error_t control_xfer_stub(uint8_t dev_addr, const tusb_std_request_t * const p_request, uint8_t data[], int num_call) -{ - switch (num_call) - { - case 0: // get 8 bytes of device descriptor - TEST_ASSERT_EQUAL(TUSB_REQUEST_GET_DESCRIPTOR, p_request->bRequest); - TEST_ASSERT_EQUAL(TUSB_DESC_TYPE_DEVICE, p_request->wValue >> 8); - TEST_ASSERT_EQUAL(8, p_request->wLength); - memcpy(data, &desc_device, p_request->wLength); - break; - - case 1: // set device address - TEST_ASSERT_EQUAL(TUSB_REQUEST_SET_ADDRESS, p_request->bRequest); - TEST_ASSERT_EQUAL(p_request->wValue, 1); - break; - - case 2: // get full device decriptor for new address - TEST_ASSERT_EQUAL(TUSB_REQUEST_GET_DESCRIPTOR, p_request->bRequest); - TEST_ASSERT_EQUAL(TUSB_DESC_TYPE_DEVICE, p_request->wValue >> 8); - TEST_ASSERT_EQUAL(18, p_request->wLength); - memcpy(data, &desc_device, p_request->wLength); - break; - - case 3: // get 9 bytes of configuration descriptor - TEST_ASSERT_EQUAL(TUSB_REQUEST_GET_DESCRIPTOR, p_request->bRequest); - TEST_ASSERT_EQUAL(TUSB_DESC_TYPE_CONFIGURATION, p_request->wValue >> 8); - TEST_ASSERT_EQUAL(9, p_request->wLength); - memcpy(data, &desc_configuration, p_request->wLength); - break; - - case 4: // get full-length configuration descriptor - TEST_ASSERT_EQUAL(TUSB_REQUEST_GET_DESCRIPTOR, p_request->bRequest); - TEST_ASSERT_EQUAL(TUSB_DESC_TYPE_CONFIGURATION, p_request->wValue >> 8); - TEST_ASSERT_EQUAL(desc_configuration.configuration.wTotalLength, p_request->wLength); - memcpy(data, &desc_configuration, p_request->wLength); - break; - - default: - return TUSB_ERROR_OSAL_TIMEOUT; - } - - return TUSB_ERROR_NONE; -} - -tusb_error_t hidh_install_stub(uint8_t dev_addr, tusb_descriptor_interface_t const *descriptor, uint16_t *p_length, int num_call) -{ - *p_length = sizeof(tusb_descriptor_interface_t) + sizeof(tusb_hid_descriptor_hid_t) + sizeof(tusb_descriptor_endpoint_t); - return TUSB_ERROR_NONE; -} - -//--------------------------------------------------------------------+ -// enumeration -//--------------------------------------------------------------------+ -void test_addr0_failed_dev_desc(void) -{ - osal_semaphore_wait_StubWithCallback(semaphore_wait_timeout_stub(0)); - - tusbh_device_mount_failed_cb_Expect(TUSB_ERROR_USBH_MOUNT_DEVICE_NOT_RESPOND, NULL); - - usbh_enumeration_task(NULL); - - TEST_ASSERT_EQUAL(TUSB_DEVICE_STATE_ADDRESSED, usbh_devices[0].state); - -} - -void test_addr0_failed_set_address(void) -{ - osal_semaphore_wait_StubWithCallback(semaphore_wait_timeout_stub(1)); - hcd_port_reset_Expect( usbh_devices[0].core_id ); - tusbh_device_mount_failed_cb_Expect(TUSB_ERROR_USBH_MOUNT_DEVICE_NOT_RESPOND, NULL); - - usbh_enumeration_task(NULL); - - TEST_ASSERT_EQUAL(TUSB_DEVICE_STATE_ADDRESSED, usbh_devices[0].state); - TEST_ASSERT_EQUAL_MEMORY(&desc_device, enum_data_buffer, 8); -} - -void test_enum_failed_get_full_dev_desc(void) -{ - osal_semaphore_wait_StubWithCallback(semaphore_wait_timeout_stub(2)); - hcd_port_reset_Expect( usbh_devices[0].core_id ); - hcd_pipe_control_close_ExpectAndReturn(0, TUSB_ERROR_NONE); - - osal_semaphore_reset_Expect( usbh_devices[0].control.sem_hdl ); - osal_mutex_reset_Expect( usbh_devices[0].control.mutex_hdl ); - hcd_pipe_control_open_ExpectAndReturn(1, desc_device.bMaxPacketSize0, TUSB_ERROR_NONE); - tusbh_device_mount_failed_cb_Expect(TUSB_ERROR_USBH_MOUNT_DEVICE_NOT_RESPOND, NULL); - - usbh_enumeration_task(NULL); - - TEST_ASSERT_EQUAL(TUSB_DEVICE_STATE_UNPLUG, usbh_devices[0].state); - TEST_ASSERT_EQUAL(TUSB_DEVICE_STATE_ADDRESSED, usbh_devices[1].state); - TEST_ASSERT_EQUAL(TUSB_SPEED_FULL, usbh_devices[1].speed); - TEST_ASSERT_EQUAL(enum_connect.core_id, usbh_devices[1].core_id); - TEST_ASSERT_EQUAL(enum_connect.hub_addr, usbh_devices[1].hub_addr); - TEST_ASSERT_EQUAL(enum_connect.hub_port, usbh_devices[1].hub_port); -} - -void test_enum_failed_get_9byte_config_desc(void) -{ - osal_semaphore_wait_StubWithCallback(semaphore_wait_timeout_stub(3)); - hcd_port_reset_Expect( usbh_devices[0].core_id ); - hcd_pipe_control_close_ExpectAndReturn(0, TUSB_ERROR_NONE); - osal_semaphore_reset_Expect( usbh_devices[0].control.sem_hdl ); - osal_mutex_reset_Expect( usbh_devices[0].control.mutex_hdl ); - - hcd_pipe_control_open_ExpectAndReturn(1, desc_device.bMaxPacketSize0, TUSB_ERROR_NONE); - tusbh_device_attached_cb_ExpectAndReturn((tusb_descriptor_device_t*) enum_data_buffer, 1); - tusbh_device_mount_failed_cb_Expect(TUSB_ERROR_USBH_MOUNT_DEVICE_NOT_RESPOND, NULL); - - usbh_enumeration_task(NULL); - - TEST_ASSERT_EQUAL(desc_device.idVendor, usbh_devices[1].vendor_id); - TEST_ASSERT_EQUAL(desc_device.idProduct, usbh_devices[1].product_id); - TEST_ASSERT_EQUAL(desc_device.bNumConfigurations, usbh_devices[1].configure_count); -} - -void test_enum_failed_get_full_config_desc(void) -{ - osal_semaphore_wait_StubWithCallback(semaphore_wait_timeout_stub(4)); - hcd_port_reset_Expect( usbh_devices[0].core_id ); - hcd_pipe_control_close_ExpectAndReturn(0, TUSB_ERROR_NONE); - osal_semaphore_reset_Expect( usbh_devices[0].control.sem_hdl ); - osal_mutex_reset_Expect( usbh_devices[0].control.mutex_hdl ); - hcd_pipe_control_open_ExpectAndReturn(1, desc_device.bMaxPacketSize0, TUSB_ERROR_NONE); - tusbh_device_attached_cb_ExpectAndReturn((tusb_descriptor_device_t*) enum_data_buffer, 1); - tusbh_device_mount_failed_cb_Expect(TUSB_ERROR_USBH_MOUNT_DEVICE_NOT_RESPOND, NULL); - - usbh_enumeration_task(NULL); -} - -void class_install_expect(void) -{ - hidh_open_subtask_StubWithCallback(hidh_install_stub); -} - -void test_enum_parse_config_desc(void) -{ - osal_semaphore_wait_StubWithCallback(semaphore_wait_timeout_stub(5)); - hcd_port_reset_Expect( usbh_devices[0].core_id ); - hcd_pipe_control_close_ExpectAndReturn(0, TUSB_ERROR_NONE); - osal_semaphore_reset_Expect( usbh_devices[0].control.sem_hdl ); - osal_mutex_reset_Expect( usbh_devices[0].control.mutex_hdl ); - hcd_pipe_control_open_ExpectAndReturn(1, desc_device.bMaxPacketSize0, TUSB_ERROR_NONE); - tusbh_device_attached_cb_ExpectAndReturn((tusb_descriptor_device_t*) enum_data_buffer, 1); - - tusbh_device_mount_failed_cb_Expect(TUSB_ERROR_USBH_MOUNT_DEVICE_NOT_RESPOND, NULL); // fail to set configure - - usbh_enumeration_task(NULL); - - TEST_ASSERT_EQUAL(desc_configuration.configuration.bNumInterfaces, usbh_devices[1].interface_count); -} - -void test_enum_set_configure(void) -{ - osal_semaphore_wait_StubWithCallback(semaphore_wait_timeout_stub(6)); - hcd_port_reset_Expect( usbh_devices[0].core_id ); - hcd_pipe_control_close_ExpectAndReturn(0, TUSB_ERROR_NONE); - osal_semaphore_reset_Expect( usbh_devices[0].control.sem_hdl ); - osal_mutex_reset_Expect( usbh_devices[0].control.mutex_hdl ); - hcd_pipe_control_open_ExpectAndReturn(1, desc_device.bMaxPacketSize0, TUSB_ERROR_NONE); - tusbh_device_attached_cb_ExpectAndReturn((tusb_descriptor_device_t*) enum_data_buffer, 1); - class_install_expect(); - - tusbh_device_mount_succeed_cb_Expect(1); - - usbh_enumeration_task(NULL); - - TEST_ASSERT_EQUAL(TUSB_CLASS_FLAG_HID, usbh_devices[1].flag_supported_class); // TODO change later -} diff --git a/tests/test/test/host/usbh/test_usbh.c b/tests/test/test/host/usbh/test_usbh.c deleted file mode 100644 index 30f4a4dfc..000000000 --- a/tests/test/test/host/usbh/test_usbh.c +++ /dev/null @@ -1,206 +0,0 @@ -/**************************************************************************/ -/*! - @file test_usbd_host.c - @author hathach (tinyusb.org) - - @section LICENSE - - Software License Agreement (BSD License) - - Copyright (c) 2013, hathach (tinyusb.org) - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - 3. Neither the name of the copyright holders nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY - EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY - DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND - ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - This file is part of the tinyusb stack. -*/ -/**************************************************************************/ - -#include -#include "unity.h" -#include "errors.h" -#include "type_helper.h" - -#include "mock_osal.h" -#include "usbh.h" -#include "usbh_hcd.h" -#include "mock_hcd.h" -#include "usbh_hcd.h" - -#include "mock_tusb_callback.h" -#include "mock_hid_host.h" -#include "host_helper.h" - -uint8_t dev_addr; -void setUp(void) -{ - dev_addr = RANDOM(TUSB_CFG_HOST_DEVICE_MAX)+1; -} - -void tearDown(void) -{ -} - -//--------------------------------------------------------------------+ -// get_status -//--------------------------------------------------------------------+ -void test_usbh_status_get_fail(void) -{ - usbh_devices[dev_addr].state = 0; - - TEST_ASSERT_EQUAL( TUSB_DEVICE_STATE_INVALID_PARAMETER, tusbh_device_get_state(TUSB_CFG_HOST_DEVICE_MAX+1) ); - TEST_ASSERT_EQUAL( TUSB_DEVICE_STATE_UNPLUG, tusbh_device_get_state(dev_addr) ); -} - -void test_usbh_status_get_succeed(void) -{ - usbh_devices[dev_addr].state = TUSB_DEVICE_STATE_CONFIGURED; - TEST_ASSERT_EQUAL( TUSB_DEVICE_STATE_CONFIGURED, tusbh_device_get_state(dev_addr) ); -} - -//--------------------------------------------------------------------+ -// Init -//--------------------------------------------------------------------+ -void test_usbh_init_hcd_failed(void) -{ - hcd_init_IgnoreAndReturn(TUSB_ERROR_HCD_FAILED); - TEST_ASSERT_EQUAL(TUSB_ERROR_HCD_FAILED, usbh_init()); -} - -void test_usbh_init_enum_task_create_failed(void) -{ - hcd_init_ExpectAndReturn(TUSB_ERROR_NONE); - osal_task_create_IgnoreAndReturn(TUSB_ERROR_OSAL_TASK_FAILED); - TEST_ASSERT_EQUAL(TUSB_ERROR_OSAL_TASK_FAILED, usbh_init()); -} - -void test_usbh_init_enum_queue_create_failed(void) -{ - hcd_init_ExpectAndReturn(TUSB_ERROR_NONE); - osal_task_create_IgnoreAndReturn(TUSB_ERROR_NONE); - osal_queue_create_IgnoreAndReturn(NULL); - TEST_ASSERT_EQUAL(TUSB_ERROR_OSAL_QUEUE_FAILED, usbh_init()); -} - -void test_usbh_init_semaphore_create_failed(void) -{ - hcd_init_ExpectAndReturn(TUSB_ERROR_NONE); - osal_task_create_IgnoreAndReturn(TUSB_ERROR_NONE); - osal_queue_create_IgnoreAndReturn((osal_queue_handle_t) 0x1234); - osal_semaphore_create_IgnoreAndReturn(NULL); - TEST_ASSERT_EQUAL(TUSB_ERROR_OSAL_SEMAPHORE_FAILED, usbh_init()); -} - -void test_usbh_init_mutex_create_failed(void) -{ - hcd_init_ExpectAndReturn(TUSB_ERROR_NONE); - osal_task_create_IgnoreAndReturn(TUSB_ERROR_NONE); - osal_queue_create_IgnoreAndReturn((osal_queue_handle_t) 0x1234); - osal_semaphore_create_IgnoreAndReturn((osal_semaphore_handle_t) 0x1234); - osal_mutex_create_IgnoreAndReturn(NULL); - TEST_ASSERT_EQUAL(TUSB_ERROR_OSAL_MUTEX_FAILED, usbh_init()); -} - -void test_usbh_init_ok(void) -{ - hcd_init_ExpectAndReturn(TUSB_ERROR_NONE); - - helper_usbh_init_expect(); - helper_class_init_expect(); - - //------------- code under test -------------// - TEST_ASSERT_EQUAL(TUSB_ERROR_NONE, usbh_init()); - - for (uint8_t i=0; i -#include -#include -#include "unity.h" -#include "CException.h" -#include "binary.h" -#include "common/assertion.h" -#include "errors.h" - -CEXCEPTION_T e; - -void setUp(void) -{ - e = 0; -} - -void tearDown(void) -{ -} - -//--------------------------------------------------------------------+ -// Error Status -//--------------------------------------------------------------------+ -void test_assert_status(void) -{ - Try - { - ASSERT_STATUS(TUSB_ERROR_NONE); - ASSERT_STATUS(TUSB_ERROR_INVALID_PARA); - } - Catch (e) - { - } -} - -//--------------------------------------------------------------------+ -// Logical -//--------------------------------------------------------------------+ -void test_assert_logical_true(void) -{ - Try - { - ASSERT (true , __LINE__); - ASSERT_TRUE (true , __LINE__); - ASSERT_TRUE (false, 0); - } - Catch(e) - { - TEST_ASSERT_EQUAL(0, e); - } -} - -void test_assert_logical_false(void) -{ - Try - { - ASSERT_FALSE (false, __LINE__); - ASSERT_FALSE (true , 0); - } - Catch(e) - { - TEST_ASSERT_EQUAL(0, e); - } -} -//--------------------------------------------------------------------+ -// Pointer -//--------------------------------------------------------------------+ -void test_assert_pointer_not_null(void) -{ - uint32_t n; - - Try - { - ASSERT_PTR_NOT_NULL(&n, __LINE__); - ASSERT_PTR(&n, __LINE__); - ASSERT_PTR(NULL, 0); - } - Catch(e) - { - TEST_ASSERT_EQUAL(0, e); - } -} - -void test_assert_pointer_null(void) -{ - uint32_t n; - - Try - { - ASSERT_PTR_NULL(NULL, __LINE__); - ASSERT_PTR_NULL(&n, 0); - } - Catch(e) - { - TEST_ASSERT_EQUAL(0, e); - } -} - -//--------------------------------------------------------------------+ -// Integer -//--------------------------------------------------------------------+ -void test_assert_int_eqal(void) -{ - Try - { - ASSERT_INT (1, 1, __LINE__); - ASSERT_INT_EQUAL (1, 1, __LINE__); - - // test side effect - uint32_t x = 0; - uint32_t y = 0; - ASSERT_INT (x++, y++, __LINE__); - TEST_ASSERT_EQUAL(1, x); - TEST_ASSERT_EQUAL(1, y); - - ASSERT_INT (1, 0, 0); - } - Catch(e) - { - TEST_ASSERT_EQUAL(0, e); - } -} - -void test_assert_int_within(void) -{ - Try - { - ASSERT_INT_WITHIN (1, 5, 3, __LINE__); - ASSERT_INT_WITHIN (1, 5, 1, __LINE__); - ASSERT_INT_WITHIN (1, 5, 5, __LINE__); - - ASSERT_INT_WITHIN (1, 5, 0, 0); - ASSERT_INT_WITHIN (1, 5, 10, 0); - } - Catch(e) - { - TEST_ASSERT_EQUAL(0, e); - } -} - -void test_assert_int_within_greater(void) -{ - Try - { - ASSERT_INT_WITHIN (1, 5, 10, 0); - } - Catch(e) - { - TEST_ASSERT_EQUAL(0, e); - } - -} - -void test_assert_int_within_less(void) -{ - Try - { - ASSERT_INT_WITHIN (1, 5, 0, 0); - } - Catch(e) - { - TEST_ASSERT_EQUAL(0, e); - } - -} - -//--------------------------------------------------------------------+ -// HEX -//--------------------------------------------------------------------+ -void test_assert_hex_equal(void) -{ - Try - { - ASSERT_HEX (0xffee, 0xffee, __LINE__); - ASSERT_HEX_EQUAL (0xffee, 0xffee, __LINE__); - - // test side effect - uint32_t x = 0xf0f0; - uint32_t y = 0xf0f0; - ASSERT_HEX (x++, y++, __LINE__); - TEST_ASSERT_EQUAL(0xf0f1, x); - TEST_ASSERT_EQUAL(0xf0f1, y); - - ASSERT_HEX(0x1234, 0x4321, 0); - } - Catch(e) - { - TEST_ASSERT_EQUAL(0, e); - } -} - -void test_assert_hex_within(void) -{ - Try - { - ASSERT_HEX_WITHIN (0xff00, 0xffff, 0xff11, __LINE__); - ASSERT_HEX_WITHIN (0xff00, 0xffff, 0xff00, __LINE__); - ASSERT_HEX_WITHIN (0xff00, 0xffff, 0xffff, __LINE__); - } - Catch (e) - { - TEST_ASSERT_EQUAL(0, e); - } -} - -void test_assert_hex_within_less(void) -{ - Try - { - ASSERT_HEX_WITHIN (0xff00, 0xffff, 0xeeee, 0); - } - Catch(e) - { - TEST_ASSERT_EQUAL(0, e); - } -} - -void test_assert_hex_within_greater(void) -{ - Try - { - ASSERT_HEX_WITHIN (0xff00, 0xffff, 0x1eeee, 0); - } - Catch(e) - { - TEST_ASSERT_EQUAL(0, e); - } -} - -//--------------------------------------------------------------------+ -// BIN -//--------------------------------------------------------------------+ -void test_assert_bin_equal(void) -{ - Try - { - ASSERT_BIN8 (BIN8(11110000), BIN8(11110000), __LINE__); - ASSERT_BIN8_EQUAL (BIN8(00001111), BIN8(00001111), __LINE__); - - // test side effect - uint32_t x = BIN8(11001100); - uint32_t y = BIN8(11001100); - ASSERT_BIN8 (x++, y++, __LINE__); - TEST_ASSERT_EQUAL(BIN8(11001101), x); - TEST_ASSERT_EQUAL(BIN8(11001101), y); - - ASSERT_BIN8(BIN8(11001111), BIN8(11111100), 0); - } - Catch(e) - { - TEST_ASSERT_EQUAL(0, e); - } -} - - - - - diff --git a/tests/test/test/test_binary_const.c b/tests/test/test/test_binary_const.c deleted file mode 100644 index 5d69c994f..000000000 --- a/tests/test/test/test_binary_const.c +++ /dev/null @@ -1,90 +0,0 @@ -/**************************************************************************/ -/*! - @file test_binary_const.c - @author hathach (tinyusb.org) - - @section LICENSE - - Software License Agreement (BSD License) - - Copyright (c) 2013, hathach (tinyusb.org) - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - 3. Neither the name of the copyright holders nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY - EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY - DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND - ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - This file is part of the tinyusb stack. -*/ -/**************************************************************************/ - -#include -#include "unity.h" -#include "common/binary.h" - -void setUp(void) -{ -} - -void tearDown(void) -{ -} - -void test_binary_8() -{ - TEST_ASSERT_EQUAL_HEX8(0x00, BIN8(00000000)); - TEST_ASSERT_EQUAL_HEX8(0x01, BIN8(00000001)); - TEST_ASSERT_EQUAL_HEX8(0x02, BIN8(00000010)); - TEST_ASSERT_EQUAL_HEX8(0x04, BIN8(00000100)); - TEST_ASSERT_EQUAL_HEX8(0x08, BIN8(00001000)); - TEST_ASSERT_EQUAL_HEX8(0x10, BIN8(00010000)); - TEST_ASSERT_EQUAL_HEX8(0x20, BIN8(00100000)); - TEST_ASSERT_EQUAL_HEX8(0x40, BIN8(01000000)); - TEST_ASSERT_EQUAL_HEX8(0x80, BIN8(10000000)); - - TEST_ASSERT_EQUAL_HEX8(0x0f, BIN8(00001111)); - TEST_ASSERT_EQUAL_HEX8(0xf0, BIN8(11110000)); - TEST_ASSERT_EQUAL_HEX8(0xff, BIN8(11111111)); -} - -void test_binary_16() -{ - TEST_ASSERT_EQUAL_HEX16(0x0000, BIN16(00000000, 00000000)); - TEST_ASSERT_EQUAL_HEX16(0x000f, BIN16(00000000, 00001111)); - TEST_ASSERT_EQUAL_HEX16(0x00f0, BIN16(00000000, 11110000)); - TEST_ASSERT_EQUAL_HEX16(0x0f00, BIN16(00001111, 00000000)); - TEST_ASSERT_EQUAL_HEX16(0xf000, BIN16(11110000, 00000000)); - TEST_ASSERT_EQUAL_HEX16(0xffff, BIN16(11111111, 11111111)); -} - -void test_binary_32() -{ - TEST_ASSERT_EQUAL_HEX32(0x00000000, BIN32(00000000, 00000000, 00000000, 00000000)); - TEST_ASSERT_EQUAL_HEX32(0x0000000f, BIN32(00000000, 00000000, 00000000, 00001111)); - TEST_ASSERT_EQUAL_HEX32(0x000000f0, BIN32(00000000, 00000000, 00000000, 11110000)); - TEST_ASSERT_EQUAL_HEX32(0x00000f00, BIN32(00000000, 00000000, 00001111, 00000000)); - TEST_ASSERT_EQUAL_HEX32(0x0000f000, BIN32(00000000, 00000000, 11110000, 00000000)); - TEST_ASSERT_EQUAL_HEX32(0x000f0000, BIN32(00000000, 00001111, 00000000, 00000000)); - TEST_ASSERT_EQUAL_HEX32(0x00f00000, BIN32(00000000, 11110000, 00000000, 00000000)); - TEST_ASSERT_EQUAL_HEX32(0x0f000000, BIN32(00001111, 00000000, 00000000, 00000000)); - TEST_ASSERT_EQUAL_HEX32(0xf0000000, BIN32(11110000, 00000000, 00000000, 00000000)); - TEST_ASSERT_EQUAL_HEX32(0xffffffff, BIN32(11111111, 11111111, 11111111, 11111111)); -} diff --git a/tests/test/test/test_fifo.c b/tests/test/test/test_fifo.c deleted file mode 100644 index f9ae2c59f..000000000 --- a/tests/test/test/test_fifo.c +++ /dev/null @@ -1,98 +0,0 @@ -/**************************************************************************/ -/*! - @file test_fifo.c - @author hathach (tinyusb.org) - - @section LICENSE - - Software License Agreement (BSD License) - - Copyright (c) 2013, hathach (tinyusb.org) - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - 3. Neither the name of the copyright holders nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY - EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY - DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND - ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - This file is part of the tinyusb stack. -*/ -/**************************************************************************/ - -#include "unity.h" -#include "fifo.h" - -#define FIFO_SIZE 10 -static fifo_t ff; -static uint8_t buffer[FIFO_SIZE]; - -void setUp(void) -{ - fifo_init(&ff, buffer, FIFO_SIZE, 0); -} - -void tearDown(void) -{ - memset(&ff, 0, sizeof(fifo_t)); -} -void test_create_null(void) -{ - memset(&ff, 0, sizeof(fifo_t)); // clear fifo to test null created - TEST_ASSERT_FALSE( fifo_init(&ff, buffer, 0, 0) ); - TEST_ASSERT_TRUE( fifo_init(&ff, buffer, 1, 0) ); -} - -void test_normal(void) -{ - uint8_t i; - - for(i=0; i < FIFO_SIZE; i++) - { - fifo_write(&ff, i); - } - - for(i=0; i < FIFO_SIZE; i++) - { - uint8_t c; - fifo_read(&ff, &c); - TEST_ASSERT_EQUAL(i, c); - } -} - -void test_is_empty(void) -{ - TEST_ASSERT_TRUE(fifo_is_empty(&ff)); - fifo_write(&ff, 1); - TEST_ASSERT_FALSE(fifo_is_empty(&ff)); -} - -void test_is_full(void) -{ - uint8_t i; - - TEST_ASSERT_FALSE(fifo_is_full(&ff)); - - for(i=0; i < FIFO_SIZE; i++) - { - fifo_write(&ff, i); - } - - TEST_ASSERT_TRUE(fifo_is_full(&ff)); -} diff --git a/tests/test/test/test_osal_freeRTOS.c b/tests/test/test/test_osal_freeRTOS.c deleted file mode 100644 index b22797e55..000000000 --- a/tests/test/test/test_osal_freeRTOS.c +++ /dev/null @@ -1,85 +0,0 @@ -/**************************************************************************/ -/*! - @file test_osal_freeRTOS.c - @author hathach (tinyusb.org) - - @section LICENSE - - Software License Agreement (BSD License) - - Copyright (c) 2013, hathach (tinyusb.org) - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - 3. Neither the name of the copyright holders nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY - EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY - DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND - ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - This file is part of the tinyusb stack. -*/ -/**************************************************************************/ - -#include "unity.h" -#include "errors.h" -//#include "freeRTOS.h" -//#include "osal_freeRTOS.h" -//#include "mock_task.h" -//#include "queue.h" -//#include "mock_portmacro.h" -//#include "mock_portable.h" -//#include "mock_list.h" -// -//#define QUEUE_DEPTH 10 -// -//uint32_t statements[10]; -// -//OSAL_SEM_DEF(sem); -//osal_semaphore_handle_t sem_hdl; -// -//OSAL_QUEUE_DEF(queue, QUEUE_DEPTH, uin32_t); -//osal_queue_handle_t queue_hdl; - -void setUp(void) -{ -// memset(statements, 0, sizeof(statements)); -// sem_hdl = osal_semaphore_create(OSAL_SEM_REF(sem)); -// queue_hdl = osal_queue_create(&queue); -} - -void tearDown(void) -{ - -} - -void test_(void) -{ - tusb_error_t error = TUSB_ERROR_NONE; - uint32_t data; - -// TEST_IGNORE(); -// -// osal_semaphore_post(sem_hdl); -// osal_semaphore_wait(sem_hdl, OSAL_TIMEOUT_WAIT_FOREVER, &error); -// -// uint32_t item = 0x1234; -// osal_queue_send(queue_hdl, &item); -// osal_queue_receive(queue_hdl, &data, OSAL_TIMEOUT_NORMAL, &error); - -} diff --git a/tests/test/test/test_osal_none.c b/tests/test/test/test_osal_none.c deleted file mode 100644 index 46e7d090d..000000000 --- a/tests/test/test/test_osal_none.c +++ /dev/null @@ -1,434 +0,0 @@ -/**************************************************************************/ -/*! - @file test_osal_none.c - @author hathach (tinyusb.org) - - @section LICENSE - - Software License Agreement (BSD License) - - Copyright (c) 2013, hathach (tinyusb.org) - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - 3. Neither the name of the copyright holders nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY - EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY - DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND - ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - This file is part of the tinyusb stack. -*/ -/**************************************************************************/ - -#ifdef TUSB_CFG_OS -#undef TUSB_CFG_OS -#endif - -#include "unity.h" -#include "errors.h" -#include "osal_none.h" - -#define QUEUE_DEPTH 10 - -uint32_t statements[10]; - -OSAL_SEM_DEF(sem); -osal_semaphore_handle_t sem_hdl; - -OSAL_QUEUE_DEF(queue, QUEUE_DEPTH, uint32_t); -osal_queue_handle_t queue_hdl; - -OSAL_MUTEX_DEF(mutex); -osal_mutex_handle_t mutex_hdl; - -void setUp(void) -{ - memset(statements, 0, sizeof(statements)); - sem_hdl = osal_semaphore_create(OSAL_SEM_REF(sem)); - queue_hdl = osal_queue_create(&queue); - mutex_hdl = osal_mutex_create(OSAL_MUTEX_REF(mutex)); -} - -void tearDown(void) -{ - -} - -//--------------------------------------------------------------------+ -// Semaphore -//--------------------------------------------------------------------+ -void test_semaphore_create(void) -{ - TEST_ASSERT_EQUAL_PTR(&sem, sem_hdl); - TEST_ASSERT_EQUAL(0, sem); -} - -void test_semaphore_post(void) -{ - osal_semaphore_post(sem_hdl); - TEST_ASSERT_EQUAL(1, sem); -} -// blocking service such as semaphore wait need to be invoked within a task's loop - -//--------------------------------------------------------------------+ -// Mutex -//--------------------------------------------------------------------+ -void test_mutex_create(void) -{ - TEST_ASSERT_EQUAL_PTR(&mutex, mutex_hdl); - TEST_ASSERT_EQUAL(1, mutex); -} - -void test_mutex_release(void) -{ - osal_mutex_release(mutex_hdl); - TEST_ASSERT_EQUAL(1, mutex); -} - -//--------------------------------------------------------------------+ -// Queue -//--------------------------------------------------------------------+ -void test_queue_create(void) -{ - TEST_ASSERT_EQUAL_PTR(&queue, queue_hdl); - TEST_ASSERT_EQUAL(QUEUE_DEPTH, queue_hdl->depth); - TEST_ASSERT_EQUAL_PTR(queue_buffer, queue_hdl->buffer); - TEST_ASSERT_EQUAL(0, queue_hdl->count); - TEST_ASSERT_EQUAL(0, queue_hdl->wr_idx); - TEST_ASSERT_EQUAL(0, queue_hdl->rd_idx); -} - -void test_queue_send(void) -{ - uint32_t const item = 0x1234; - osal_queue_send(queue_hdl, &item); - TEST_ASSERT_EQUAL(1, queue_hdl->count); - TEST_ASSERT_EQUAL_MEMORY(&item, queue_hdl->buffer + (queue_hdl->rd_idx * queue_hdl->item_size), 4); -} -// blocking service such as semaphore wait need to be invoked within a task's loop - -//--------------------------------------------------------------------+ -// TASK SEMAPHORE -//--------------------------------------------------------------------+ -tusb_error_t sample_task_semaphore(void) -{ - tusb_error_t error = TUSB_ERROR_NONE; - - OSAL_TASK_LOOP_BEGIN - - statements[0]++; - - osal_semaphore_wait(sem_hdl, OSAL_TIMEOUT_WAIT_FOREVER, &error); - statements[1]++; - - osal_semaphore_wait(sem_hdl, OSAL_TIMEOUT_WAIT_FOREVER, &error); - statements[2]++; - - osal_semaphore_wait(sem_hdl, OSAL_TIMEOUT_WAIT_FOREVER, &error); - statements[3]++; - - osal_semaphore_wait(sem_hdl, OSAL_TIMEOUT_NORMAL, &error); - statements[4]++; - TEST_ASSERT_EQUAL(TUSB_ERROR_OSAL_TIMEOUT, error); - - OSAL_TASK_LOOP_END -} - -void test_task_with_semaphore(void) -{ - // several invoke before sempahore is available - for(uint32_t i=0; i<10; i++) - sample_task_semaphore(); - TEST_ASSERT_EQUAL(1, statements[0]); - - // invoke after posting semaphore - osal_semaphore_post(sem_hdl); - sample_task_semaphore(); - TEST_ASSERT_EQUAL(1, statements[1]); - - // post 2 consecutive times - osal_semaphore_post(sem_hdl); - osal_semaphore_post(sem_hdl); - sample_task_semaphore(); - TEST_ASSERT_EQUAL(1, statements[2]); - TEST_ASSERT_EQUAL(1, statements[3]); - - // timeout - for(uint32_t i=0; i<(OSAL_TIMEOUT_NORMAL*TUSB_CFG_OS_TICKS_PER_SECOND)/1000 ; i++) // not enough time - osal_tick_tock(); - sample_task_semaphore(); - TEST_ASSERT_EQUAL(0, statements[4]); - osal_tick_tock(); - sample_task_semaphore(); - - // reach end of task loop, back to beginning - sample_task_semaphore(); - TEST_ASSERT_EQUAL(2, statements[0]); -} - -//--------------------------------------------------------------------+ -// TASK MUTEX -//--------------------------------------------------------------------+ -tusb_error_t mutex_sample_task1(void) // occupy mutex and not release it -{ - tusb_error_t error = TUSB_ERROR_NONE; - - OSAL_TASK_LOOP_BEGIN - - statements[0]++; - - osal_mutex_wait(mutex_hdl, OSAL_TIMEOUT_WAIT_FOREVER, &error); - statements[2]++; - - OSAL_TASK_LOOP_END -} - -tusb_error_t mutex_sample_task2(void) -{ - tusb_error_t error = TUSB_ERROR_NONE; - - OSAL_TASK_LOOP_BEGIN - - statements[1]++; - - osal_mutex_wait(mutex_hdl, OSAL_TIMEOUT_WAIT_FOREVER, &error); - statements[3]++; - - osal_mutex_wait(mutex_hdl, OSAL_TIMEOUT_NORMAL, &error); - statements[5]++; - - TEST_ASSERT_EQUAL(TUSB_ERROR_OSAL_TIMEOUT, error); - - OSAL_TASK_LOOP_END -} - -void test_task_with_mutex(void) -{ - // several invoke before mutex is available - mutex_sample_task1(); - for(uint32_t i=0; i<10; i++) { - mutex_sample_task2(); - } - - TEST_ASSERT_EQUAL(1, statements[0]); - TEST_ASSERT_EQUAL(1, statements[2]); - - TEST_ASSERT_EQUAL(1, statements[1]); - TEST_ASSERT_EQUAL(0, statements[3]); - - // invoke after posting mutex - osal_mutex_release(mutex_hdl); - for(uint32_t i=0; i<10; i++) { - mutex_sample_task2(); - } - TEST_ASSERT_EQUAL(1, statements[3]); - TEST_ASSERT_EQUAL(0, statements[5]); - - // timeout - for(uint32_t i=0; i<(OSAL_TIMEOUT_NORMAL*TUSB_CFG_OS_TICKS_PER_SECOND)/1000 ; i++){ // one tick less - osal_tick_tock(); - } - mutex_sample_task2(); - TEST_ASSERT_EQUAL(0, statements[5]); - osal_tick_tock(); - - mutex_sample_task2(); - TEST_ASSERT_EQUAL(1, statements[5]); -} - -//--------------------------------------------------------------------+ -// TASK QUEUE -//--------------------------------------------------------------------+ -tusb_error_t sample_task_with_queue(void) -{ - uint32_t data; - tusb_error_t error; - - OSAL_TASK_LOOP_BEGIN - - statements[0]++; - - osal_queue_receive(queue_hdl, &data, OSAL_TIMEOUT_WAIT_FOREVER, &error); - TEST_ASSERT_EQUAL(0x1111, data); - statements[1]++; - - osal_queue_receive(queue_hdl, &data, OSAL_TIMEOUT_WAIT_FOREVER, &error); - TEST_ASSERT_EQUAL(0x2222, data); - statements[2]++; - - osal_queue_receive(queue_hdl, &data, OSAL_TIMEOUT_WAIT_FOREVER, &error); - TEST_ASSERT_EQUAL(0x3333, data); - statements[3]++; - - osal_queue_receive(queue_hdl, &data, OSAL_TIMEOUT_NORMAL, &error); - statements[4]++; - TEST_ASSERT_EQUAL(TUSB_ERROR_OSAL_TIMEOUT, error); - - OSAL_TASK_LOOP_END -} - -void test_task_with_queue(void) -{ - uint32_t i = 0; - uint32_t item; - - sample_task_with_queue(); - // several invoke before queue is available - for(i=0; i<10; i++) - sample_task_with_queue(); - TEST_ASSERT_EQUAL(1, statements[0]); - - // invoke after sending to queue - item = 0x1111; - osal_queue_send(queue_hdl, &item); - sample_task_with_queue(); - TEST_ASSERT_EQUAL(1, statements[1]); - sample_task_with_queue(); - TEST_ASSERT_EQUAL(1, statements[1]); - - item = 0x2222; - osal_queue_send(queue_hdl, &item); - item = 0x3333; - osal_queue_send(queue_hdl, &item); - sample_task_with_queue(); - TEST_ASSERT_EQUAL(1, statements[2]); - TEST_ASSERT_EQUAL(1, statements[3]); - - // timeout - for(uint32_t i=0; i<(OSAL_TIMEOUT_NORMAL*TUSB_CFG_OS_TICKS_PER_SECOND)/1000 ; i++) // not enough time - osal_tick_tock(); - sample_task_with_queue(); - TEST_ASSERT_EQUAL(0, statements[4]); - osal_tick_tock(); - sample_task_with_queue(); - - // reach end of task loop, back to beginning - sample_task_with_queue(); - TEST_ASSERT_EQUAL(2, statements[0]); -} - -//--------------------------------------------------------------------+ -// TASK DELAY -//--------------------------------------------------------------------+ -tusb_error_t sample_task_with_delay(void) -{ - tusb_error_t error; - - OSAL_TASK_LOOP_BEGIN - - osal_task_delay(1000); - - statements[0]++; - - OSAL_TASK_LOOP_END -} - -void test_task_with_delay(void) -{ - sample_task_with_delay(); - TEST_ASSERT_EQUAL(0, statements[0]); - - for(uint32_t i=0; i