test refractor

This commit is contained in:
hathach 2013-06-29 21:00:33 +07:00
parent 9e607f6dee
commit a943cce991
10 changed files with 80 additions and 179 deletions

View File

@ -76,25 +76,6 @@ typedef ATTR_PACKED_STRUCT(struct)
{
tusb_descriptor_configuration_t configuration;
#if IAD_DESC_REQUIRED
tusb_descriptor_interface_association_t CDC_IAD;
#endif
#if TUSB_CFG_DEVICE_CDC
//CDC - Serial
//CDC Control Interface
tusb_descriptor_interface_t CDC_CCI_Interface;
CDC_HEADER_DESCRIPTOR CDC_Header;
CDC_ABSTRACT_CONTROL_MANAGEMENT_DESCRIPTOR CDC_ACM;
CDC_UNION_1SLAVE_DESCRIPTOR CDC_Union;
tusb_descriptor_endpoint_t CDC_NotificationEndpoint;
//CDC Data Interface
tusb_descriptor_interface_t CDC_DCI_Interface;
tusb_descriptor_endpoint_t CDC_DataOutEndpoint;
tusb_descriptor_endpoint_t CDC_DataInEndpoint;
#endif
//------------- HID Keyboard -------------//
#if TUSB_CFG_DEVICE_HID_KEYBOARD
tusb_descriptor_interface_t keyboard_interface;

View File

@ -103,3 +103,51 @@ void test_usbd_init(void)
//------------- Code Under Test -------------//
TEST_ASSERT_STATUS( usbd_init() );
}
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<manufacturer_len; i++)
{
TEST_ASSERT_EQUAL(TUSB_CFG_DEVICE_STRING_MANUFACTURER[i], app_tusb_desc_strings.manufacturer.unicode_string[i]);
}
//------------- product string descriptor -------------//
uint32_t const product_len = sizeof(TUSB_CFG_DEVICE_STRING_PRODUCT) - 1;
TEST_ASSERT_EQUAL(product_len*2 + 2, app_tusb_desc_strings.product.bLength);
for(uint32_t i=0; i < product_len; i++)
{
TEST_ASSERT_EQUAL(TUSB_CFG_DEVICE_STRING_PRODUCT[i], app_tusb_desc_strings.product.unicode_string[i]);
}
//------------- serial string descriptor -------------//
uint32_t const serial_len = sizeof(TUSB_CFG_DEVICE_STRING_SERIAL) - 1;
TEST_ASSERT_EQUAL(serial_len*2 + 2, app_tusb_desc_strings.serial.bLength);
for(uint32_t i=0; i<serial_len; i++)
{
TEST_ASSERT_EQUAL(TUSB_CFG_DEVICE_STRING_SERIAL[i], app_tusb_desc_strings.serial.unicode_string[i]);
}
}

View File

@ -26,6 +26,10 @@
:paths:
:test:
- +:test/**
:support:
- ../support
:source:
- ../../tinyusb/**
- +:../../demos/bsp/lpc43xx/**
@ -33,9 +37,6 @@
- -:../../demos/
- ../../vendor/freertos/freertos/Source/*
- ../../vendor/freertos/freertos/Source/portable/MSVC-MingW/*
:support:
- ../support
:defines:
# in order to add common defines:

View File

@ -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 <stdlib.h>
#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<manufacturer_len; i++)
{
TEST_ASSERT_EQUAL(TUSB_CFG_DEVICE_STRING_MANUFACTURER[i], app_tusb_desc_strings.manufacturer.unicode_string[i]);
}
//------------- product string descriptor -------------//
uint32_t const product_len = sizeof(TUSB_CFG_DEVICE_STRING_PRODUCT) - 1;
TEST_ASSERT_EQUAL(product_len*2 + 2, app_tusb_desc_strings.product.bLength);
for(uint32_t i=0; i < product_len; i++)
{
TEST_ASSERT_EQUAL(TUSB_CFG_DEVICE_STRING_PRODUCT[i], app_tusb_desc_strings.product.unicode_string[i]);
}
//------------- serial string descriptor -------------//
uint32_t const serial_len = sizeof(TUSB_CFG_DEVICE_STRING_SERIAL) - 1;
TEST_ASSERT_EQUAL(serial_len*2 + 2, app_tusb_desc_strings.serial.bLength);
for(uint32_t i=0; i<serial_len; i++)
{
TEST_ASSERT_EQUAL(TUSB_CFG_DEVICE_STRING_SERIAL[i], app_tusb_desc_strings.serial.unicode_string[i]);
}
}

View File

@ -46,6 +46,7 @@
#include "hal.h"
#include "mock_osal.h"
#include "mock_hid_host.h"
#include "mock_cdc_host.h"
#include "hcd.h"
#include "usbh_hcd.h"

View File

@ -45,10 +45,10 @@
#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 "mock_cdc_host.h"
#include "host_helper.h"
uint8_t dev_addr;

View File

@ -77,7 +77,7 @@ enum {
};
enum {
CDC_COMM_PROTOCOL_ATCOMMAND_ITU_V250 = 0x01 , // ITU-T V2.50
CDC_COMM_PROTOCOL_ATCOMMAND = 0x01 , // ITU-T V2.50
CDC_COMM_PROTOCOL_ATCOMMAND_PCCA_101 ,
CDC_COMM_PROTOCOL_ATCOMMAND_PCCA_101_AND_ANNEXO ,
CDC_COMM_PROTOCOL_ATCOMMAND_GSM_707 ,
@ -217,8 +217,8 @@ typedef ATTR_PACKED_STRUCT(struct) {
uint8_t bLength ; ///< Size of this descriptor in bytes.
uint8_t bDescriptorType ; ///< Descriptor Type, must be Class-Specific
uint8_t bDescriptorSubType ; ///< Descriptor SubType one of above CDC_FUCN_DESC_
uint8_t bControlInterface ; ///< Interface number of Data Interface (zero-based)
uint8_t bSubordinateInterface[0] ; ///< Variable length array
uint8_t bControlInterface ; ///< Interface number of Communication Interface
uint8_t bSubordinateInterface[0] ; ///< Interface number of Data Interface
}tusb_cdc_func_union_t;
typedef ATTR_PACKED_STRUCT(struct) {

View File

@ -79,17 +79,18 @@ typedef enum {
/// USB Descriptor Types (section 9.4 table 9-5)
typedef enum {
TUSB_DESC_TYPE_DEVICE =1 , ///< 1
TUSB_DESC_TYPE_CONFIGURATION , ///< 2
TUSB_DESC_TYPE_STRING , ///< 3
TUSB_DESC_TYPE_INTERFACE , ///< 4
TUSB_DESC_TYPE_ENDPOINT , ///< 5
TUSB_DESC_TYPE_DEVICE_QUALIFIER , ///< 6
TUSB_DESC_TYPE_OTHER_SPEED_CONFIGURATION , ///< 7
TUSB_DESC_TYPE_INTERFACE_POWER , ///< 8
TUSB_DESC_TYPE_OTG , ///< 9
TUSB_DESC_TYPE_DEBUG , ///< 10
TUSB_DESC_TYPE_INTERFACE_ASSOCIATION ///< 11
TUSB_DESC_TYPE_DEVICE = 0x01 ,
TUSB_DESC_TYPE_CONFIGURATION = 0x02 ,
TUSB_DESC_TYPE_STRING = 0x03 ,
TUSB_DESC_TYPE_INTERFACE = 0x04 ,
TUSB_DESC_TYPE_ENDPOINT = 0x05 ,
TUSB_DESC_TYPE_DEVICE_QUALIFIER = 0x06 ,
TUSB_DESC_TYPE_OTHER_SPEED_CONFIGURATION = 0x07 ,
TUSB_DESC_TYPE_INTERFACE_POWER = 0x08 ,
TUSB_DESC_TYPE_OTG = 0x09 ,
TUSB_DESC_TYPE_DEBUG = 0x0A ,
TUSB_DESC_TYPE_INTERFACE_ASSOCIATION = 0x0B ,
TUSB_DESC_TYPE_INTERFACE_CLASS_SPECIFIC = 0x24
}tusb_std_descriptor_type_t;
typedef enum {

View File

@ -160,11 +160,11 @@ void osal_mutex_reset(osal_mutex_handle_t mutex_hdl);
// QUEUE API
//--------------------------------------------------------------------+
typedef struct{
uint32_t * const buffer ; ///< buffer pointer
uint8_t const depth ; ///< buffer size
volatile uint8_t count ; ///< bytes in fifo
volatile uint8_t wr_idx ; ///< write pointer
volatile uint8_t rd_idx ; ///< read pointer
uint32_t * const buffer ; ///< buffer pointer
uint8_t const depth ; ///< buffer size
volatile uint8_t count ; ///< bytes in fifo
volatile uint8_t wr_idx ; ///< write pointer
volatile uint8_t rd_idx ; ///< read pointer
} osal_queue_t;
typedef osal_queue_t * osal_queue_handle_t;

View File

@ -68,7 +68,12 @@
/// define this symbol will make tinyusb look for external configure file
#include "mcu_capacity.h"
#include "tusb_config.h"
#ifdef TUSB_CFG_CONFIG_FILE
#include TUSB_CFG_CONFIG_FILE
#else
#include "tusb_config.h"
#endif
//--------------------------------------------------------------------+
// CONTROLLER