rename tests to obsolete

This commit is contained in:
hathach
2019-06-06 21:33:55 +07:00
parent dcfaec9efc
commit 481909e704
202 changed files with 0 additions and 0 deletions
@@ -0,0 +1,58 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Ha Thach (tinyusb.org)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* This file is part of the TinyUSB stack.
*/
/** \ingroup TBD
* \defgroup TBD
* \brief TBD
*
* @{
*/
#ifndef _TUSB_CDC_CALLBACK_H_
#define _TUSB_CDC_CALLBACK_H_
#include "common/common.h"
#include "cdc_host.h"
#ifdef __cplusplus
extern "C" {
#endif
void tusbh_cdc_mounted_cb(uint8_t dev_addr);
void tusbh_cdc_unmounted_cb(uint8_t dev_addr);
void tusbh_cdc_xfer_isr(uint8_t dev_addr, xfer_result_t event, cdc_pipeid_t pipe_id, uint32_t xferred_bytes);
void tusbh_cdc_rndis_mounted_cb(uint8_t dev_addr);
void tusbh_cdc_rndis_unmounted_isr(uint8_t dev_addr);
#ifdef __cplusplus
}
#endif
#endif /* _TUSB_CDC_CALLBACK_H_ */
/** @} */
@@ -0,0 +1,276 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Ha Thach (tinyusb.org)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* This file is part of the TinyUSB stack.
*/
#include "tusb_option.h"
#include "descriptor_cdc.h"
//--------------------------------------------------------------------+
// CDC Serials
//--------------------------------------------------------------------+
CFG_TUSB_MEM_SECTION
const cdc_configuration_desc_t cdc_config_descriptor =
{
.configuration =
{
.bLength = sizeof(tusb_desc_configuration_t),
.bDescriptorType = TUSB_DESC_TYPE_CONFIGURATION,
.wTotalLength = sizeof(cdc_configuration_desc_t),
.bNumInterfaces = 2,
.bConfigurationValue = 1,
.iConfiguration = 0x00,
.bmAttributes = TUSB_DESC_CONFIG_ATT_BUS_POWER,
.bMaxPower = TUSB_DESC_CONFIG_POWER_MA(100)
},
// IAD points to CDC Interfaces
.cdc_iad =
{
.bLength = sizeof(tusb_desc_interface_assoc_t),
.bDescriptorType = TUSB_DESC_TYPE_INTERFACE_ASSOCIATION,
.bFirstInterface = 1,
.bInterfaceCount = 2,
.bFunctionClass = TUSB_CLASS_CDC,
.bFunctionSubClass = CDC_COMM_SUBCLASS_ABSTRACT_CONTROL_MODEL,
.bFunctionProtocol = CDC_COMM_PROTOCOL_ATCOMMAND,
.iFunction = 0
},
// USB CDC Serial Interface
//------------- CDC Communication Interface -------------//
.cdc_comm_interface =
{
.bLength = sizeof(tusb_desc_interface_t),
.bDescriptorType = TUSB_DESC_TYPE_INTERFACE,
.bInterfaceNumber = 1,
.bAlternateSetting = 0,
.bNumEndpoints = 1,
.bInterfaceClass = TUSB_CLASS_CDC,
.bInterfaceSubClass = CDC_COMM_SUBCLASS_ABSTRACT_CONTROL_MODEL,
.bInterfaceProtocol = CDC_COMM_PROTOCOL_ATCOMMAND,
.iInterface = 0x00
},
.cdc_header =
{
.bLength = sizeof(cdc_desc_func_header_t),
.bDescriptorType = TUSB_DESC_TYPE_INTERFACE_CLASS_SPECIFIC,
.bDescriptorSubType = CDC_FUNC_DESC_HEADER,
.bcdCDC = 0x0120
},
.cdc_acm =
{
.bLength = sizeof(cdc_desc_func_acm_t),
.bDescriptorType = TUSB_DESC_TYPE_INTERFACE_CLASS_SPECIFIC,
.bDescriptorSubType = CDC_FUNC_DESC_ABSTRACT_CONTROL_MANAGEMENT,
.bmCapabilities = { // 0x06
.support_line_request = 1,
.support_send_break = 1
}
},
.cdc_union =
{
.bLength = sizeof(cdc_desc_func_union_t), // plus number of
.bDescriptorType = TUSB_DESC_TYPE_INTERFACE_CLASS_SPECIFIC,
.bDescriptorSubType = CDC_FUNC_DESC_UNION,
.bControlInterface = 1,
.bSubordinateInterface = 2,
},
.cdc_endpoint_notification =
{
.bLength = sizeof(tusb_desc_endpoint_t),
.bDescriptorType = TUSB_DESC_TYPE_ENDPOINT,
.bEndpointAddress = 0x81,
.bmAttributes = { .xfer = TUSB_XFER_INTERRUPT },
.wMaxPacketSize = 8,
.bInterval = 0x0a // lowest polling rate
},
//------------- CDC Data Interface -------------//
.cdc_data_interface =
{
.bLength = sizeof(tusb_desc_interface_t),
.bDescriptorType = TUSB_DESC_TYPE_INTERFACE,
.bInterfaceNumber = 2,
.bAlternateSetting = 0x00,
.bNumEndpoints = 2,
.bInterfaceClass = TUSB_CLASS_CDC_DATA,
.bInterfaceSubClass = 0,
.bInterfaceProtocol = 0,
.iInterface = 0x00
},
.cdc_endpoint_out =
{
.bLength = sizeof(tusb_desc_endpoint_t),
.bDescriptorType = TUSB_DESC_TYPE_ENDPOINT,
.bEndpointAddress = 2,
.bmAttributes = { .xfer = TUSB_XFER_BULK },
.wMaxPacketSize = 64,
.bInterval = 0
},
.cdc_endpoint_in =
{
.bLength = sizeof(tusb_desc_endpoint_t),
.bDescriptorType = TUSB_DESC_TYPE_ENDPOINT,
.bEndpointAddress = 0x82,
.bmAttributes = { .xfer = TUSB_XFER_BULK },
.wMaxPacketSize = 64,
.bInterval = 0
},
};
//--------------------------------------------------------------------+
// CDC RNSID
//--------------------------------------------------------------------+
CFG_TUSB_MEM_SECTION
const cdc_configuration_desc_t rndis_config_descriptor =
{
.configuration =
{
.bLength = sizeof(tusb_desc_configuration_t),
.bDescriptorType = TUSB_DESC_TYPE_CONFIGURATION,
.wTotalLength = sizeof(cdc_configuration_desc_t),
.bNumInterfaces = 2,
.bConfigurationValue = 1,
.iConfiguration = 0x00,
.bmAttributes = TUSB_DESC_CONFIG_ATT_BUS_POWER,
.bMaxPower = TUSB_DESC_CONFIG_POWER_MA(100)
},
// IAD points to CDC Interfaces
.cdc_iad =
{
.bLength = sizeof(tusb_desc_interface_assoc_t),
.bDescriptorType = TUSB_DESC_TYPE_INTERFACE_ASSOCIATION,
.bFirstInterface = 1,
.bInterfaceCount = 2,
.bFunctionClass = TUSB_CLASS_CDC,
.bFunctionSubClass = CDC_COMM_SUBCLASS_ABSTRACT_CONTROL_MODEL,
.bFunctionProtocol = 0,
.iFunction = 0
},
// USB CDC Serial Interface
//------------- CDC Communication Interface -------------//
.cdc_comm_interface =
{
.bLength = sizeof(tusb_desc_interface_t),
.bDescriptorType = TUSB_DESC_TYPE_INTERFACE,
.bInterfaceNumber = 1,
.bAlternateSetting = 0,
.bNumEndpoints = 1,
.bInterfaceClass = TUSB_CLASS_CDC,
.bInterfaceSubClass = CDC_COMM_SUBCLASS_ABSTRACT_CONTROL_MODEL,
.bInterfaceProtocol = 0xff, // RNDIS is vendor specific protocol
.iInterface = 0x00
},
.cdc_header =
{
.bLength = sizeof(cdc_desc_func_header_t),
.bDescriptorType = TUSB_DESC_TYPE_INTERFACE_CLASS_SPECIFIC,
.bDescriptorSubType = CDC_FUNC_DESC_HEADER,
.bcdCDC = 0x0120
},
.cdc_acm =
{
.bLength = sizeof(cdc_desc_func_acm_t),
.bDescriptorType = TUSB_DESC_TYPE_INTERFACE_CLASS_SPECIFIC,
.bDescriptorSubType = CDC_FUNC_DESC_ABSTRACT_CONTROL_MANAGEMENT,
.bmCapabilities = { 0 }
},
.cdc_union =
{
.bLength = sizeof(cdc_desc_func_union_t), // plus number of
.bDescriptorType = TUSB_DESC_TYPE_INTERFACE_CLASS_SPECIFIC,
.bDescriptorSubType = CDC_FUNC_DESC_UNION,
.bControlInterface = 1,
.bSubordinateInterface = 2,
},
.cdc_endpoint_notification =
{
.bLength = sizeof(tusb_desc_endpoint_t),
.bDescriptorType = TUSB_DESC_TYPE_ENDPOINT,
.bEndpointAddress = 0x81,
.bmAttributes = { .xfer = TUSB_XFER_INTERRUPT },
.wMaxPacketSize = 8,
.bInterval = 0x0a // lowest polling rate
},
//------------- CDC Data Interface -------------//
.cdc_data_interface =
{
.bLength = sizeof(tusb_desc_interface_t),
.bDescriptorType = TUSB_DESC_TYPE_INTERFACE,
.bInterfaceNumber = 2,
.bAlternateSetting = 0x00,
.bNumEndpoints = 2,
.bInterfaceClass = TUSB_CLASS_CDC_DATA,
.bInterfaceSubClass = 0,
.bInterfaceProtocol = 0,
.iInterface = 0x00
},
.cdc_endpoint_out =
{
.bLength = sizeof(tusb_desc_endpoint_t),
.bDescriptorType = TUSB_DESC_TYPE_ENDPOINT,
.bEndpointAddress = 2,
.bmAttributes = { .xfer = TUSB_XFER_BULK },
.wMaxPacketSize = 512,
.bInterval = 0
},
.cdc_endpoint_in =
{
.bLength = sizeof(tusb_desc_endpoint_t),
.bDescriptorType = TUSB_DESC_TYPE_ENDPOINT,
.bEndpointAddress = 0x82,
.bmAttributes = { .xfer = TUSB_XFER_BULK },
.wMaxPacketSize = 512,
.bInterval = 0
},
};
@@ -0,0 +1,73 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Ha Thach (tinyusb.org)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* This file is part of the TinyUSB stack.
*/
/** \ingroup TBD
* \defgroup TBD
* \brief TBD
*
* @{
*/
#ifndef _TUSB_DESCRIPTOR_CDC_H_
#define _TUSB_DESCRIPTOR_CDC_H_
#include "common/common.h"
#include "class/cdc.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct
{
tusb_desc_configuration_t configuration;
tusb_desc_interface_assoc_t cdc_iad;
//CDC Control Interface
tusb_desc_interface_t cdc_comm_interface;
cdc_desc_func_header_t cdc_header;
cdc_desc_func_acm_t cdc_acm;
cdc_desc_func_union_t cdc_union;
tusb_desc_endpoint_t cdc_endpoint_notification;
//CDC Data Interface
tusb_desc_interface_t cdc_data_interface;
tusb_desc_endpoint_t cdc_endpoint_out;
tusb_desc_endpoint_t cdc_endpoint_in;
} cdc_configuration_desc_t;
extern const cdc_configuration_desc_t cdc_config_descriptor;
extern const cdc_configuration_desc_t rndis_config_descriptor;
#ifdef __cplusplus
}
#endif
#endif /* _TUSB_DESCRIPTOR_CDC_H_ */
/** @} */
@@ -0,0 +1,278 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Ha Thach (tinyusb.org)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* This file is part of the TinyUSB stack.
*/
#include "stdlib.h"
#include "unity.h"
#include "tusb_option.h"
#include "tusb_errors.h"
#include "binary.h"
#include "type_helper.h"
#include "mock_osal.h"
#include "mock_hcd.h"
#include "mock_usbh.h"
#include "mock_cdc_callback.h"
#include "descriptor_cdc.h"
#include "cdc_host.h"
#if CFG_TUH_CDC_RNDIS // TODO enable
#include "cdc_rndis_host.h"
#endif
static uint8_t dev_addr;
static uint16_t length;
static tusb_desc_interface_t const * p_comm_interface = &cdc_config_descriptor.cdc_comm_interface;
static tusb_desc_endpoint_t const * p_endpoint_notification = &cdc_config_descriptor.cdc_endpoint_notification;
static tusb_desc_endpoint_t const * p_endpoint_out = &cdc_config_descriptor.cdc_endpoint_out;
static tusb_desc_endpoint_t const * p_endpoint_in = &cdc_config_descriptor.cdc_endpoint_in;
extern cdch_data_t cdch_data[CFG_TUSB_HOST_DEVICE_MAX];
static cdch_data_t * p_cdc = &cdch_data[0];
void setUp(void)
{
length = 0;
dev_addr = 1;
tu_memclr(cdch_data, sizeof(cdch_data_t)*CFG_TUSB_HOST_DEVICE_MAX);
}
void tearDown(void)
{
}
//--------------------------------------------------------------------+
// OPEN
//--------------------------------------------------------------------+
void test_cdch_open_failed_to_open_notification_endpoint(void)
{
pipe_handle_t null_hdl = {0};
hcd_edpt_open_ExpectAndReturn(dev_addr, p_endpoint_notification, TUSB_CLASS_CDC, null_hdl);
//------------- CUT -------------//
TEST_ASSERT_EQUAL(TUSB_ERROR_HCD_OPEN_PIPE_FAILED, cdch_open(dev_addr, p_comm_interface, &length));
}
void test_cdch_open_failed_to_open_data_endpoint_out(void)
{
pipe_handle_t dummy_hld = { .dev_addr = 1 };
pipe_handle_t null_hdl = {0};
hcd_edpt_open_ExpectAndReturn(dev_addr, p_endpoint_notification, TUSB_CLASS_CDC, dummy_hld);
hcd_edpt_open_ExpectAndReturn(dev_addr, p_endpoint_out, TUSB_CLASS_CDC, null_hdl);
//------------- CUT -------------//
TEST_ASSERT_EQUAL(TUSB_ERROR_HCD_OPEN_PIPE_FAILED, cdch_open(dev_addr, p_comm_interface, &length));
}
void test_cdch_open_failed_to_open_data_endpoint_in(void)
{
pipe_handle_t dummy_hld = { .dev_addr = 1 };
pipe_handle_t null_hdl = {0};
hcd_edpt_open_ExpectAndReturn(dev_addr, p_endpoint_notification, TUSB_CLASS_CDC, dummy_hld);
hcd_edpt_open_ExpectAndReturn(dev_addr, p_endpoint_out, TUSB_CLASS_CDC, dummy_hld);
hcd_edpt_open_ExpectAndReturn(dev_addr, p_endpoint_in, TUSB_CLASS_CDC, null_hdl);
//------------- CUT -------------//
TEST_ASSERT_EQUAL(TUSB_ERROR_HCD_OPEN_PIPE_FAILED, cdch_open(dev_addr, p_comm_interface, &length));
}
void test_cdch_open_length_check(void)
{
const uint16_t expected_length =
//------------- Comm Interface -------------//
sizeof(tusb_desc_interface_t) + sizeof(cdc_desc_func_header_t) +
sizeof(cdc_desc_func_acm_t) + sizeof(cdc_desc_func_union_t) +
sizeof(tusb_desc_endpoint_t) +
//------------- Data Interface -------------//
sizeof(tusb_desc_interface_t) + 2*sizeof(tusb_desc_endpoint_t);
pipe_handle_t dummy_hld = { .dev_addr = 1 };
hcd_edpt_open_IgnoreAndReturn(dummy_hld);
tusbh_cdc_mounted_cb_Expect(dev_addr);
//------------- CUT -------------//
TEST_ASSERT_EQUAL( TUSB_ERROR_NONE, cdch_open(dev_addr, p_comm_interface, &length) );
TEST_ASSERT_EQUAL(expected_length, length);
}
void test_cdch_open_interface_number_check(void)
{
pipe_handle_t dummy_hld = { .dev_addr = 1 };
hcd_edpt_open_IgnoreAndReturn(dummy_hld);
tusbh_cdc_mounted_cb_Expect(dev_addr);
//------------- CUT -------------//
TEST_ASSERT_EQUAL( TUSB_ERROR_NONE, cdch_open(dev_addr, p_comm_interface, &length) );
TEST_ASSERT_EQUAL(1, p_cdc->interface_number);
}
void test_cdch_open_protocol_check(void)
{
pipe_handle_t dummy_hld = { .dev_addr = 1 };
hcd_edpt_open_IgnoreAndReturn(dummy_hld);
tusbh_cdc_mounted_cb_Expect(dev_addr);
//------------- CUT -------------//
TEST_ASSERT_EQUAL( TUSB_ERROR_NONE, cdch_open(dev_addr, p_comm_interface, &length) );
TEST_ASSERT_EQUAL(p_comm_interface->bInterfaceProtocol, p_cdc->interface_protocol);
}
void test_cdch_open_acm_capacity_check(void)
{
pipe_handle_t dummy_hld = { .dev_addr = 1 };
hcd_edpt_open_IgnoreAndReturn(dummy_hld);
tusbh_cdc_mounted_cb_Expect(dev_addr);
//------------- CUT -------------//
TEST_ASSERT_EQUAL( TUSB_ERROR_NONE, cdch_open(dev_addr, p_comm_interface, &length) );
TEST_ASSERT_EQUAL_MEMORY(&cdc_config_descriptor.cdc_acm.bmCapabilities, &p_cdc->acm_capability, 1);
}
//--------------------------------------------------------------------+
// CLOSE
//--------------------------------------------------------------------+
void test_cdch_close_device(void)
{
pipe_handle_t pipe_notification = { .dev_addr = 1, .xfer_type = TUSB_XFER_INTERRUPT };
pipe_handle_t pipe_out = { .dev_addr = 1, .xfer_type = TUSB_XFER_BULK, .index = 0 };
pipe_handle_t pipe_int = { .dev_addr = 1, .xfer_type = TUSB_XFER_BULK, .index = 1 };
hcd_edpt_open_ExpectAndReturn(dev_addr, p_endpoint_notification, TUSB_CLASS_CDC, pipe_notification);
hcd_edpt_open_ExpectAndReturn(dev_addr, p_endpoint_out, TUSB_CLASS_CDC, pipe_out);
hcd_edpt_open_ExpectAndReturn(dev_addr, p_endpoint_in, TUSB_CLASS_CDC, pipe_int);
tusbh_cdc_mounted_cb_Expect(dev_addr);
TEST_ASSERT_EQUAL( TUSB_ERROR_NONE, cdch_open(dev_addr, p_comm_interface, &length) );
hcd_pipe_close_ExpectAndReturn(pipe_notification , TUSB_ERROR_NONE);
hcd_pipe_close_ExpectAndReturn(pipe_int , TUSB_ERROR_NONE);
hcd_pipe_close_ExpectAndReturn(pipe_out , TUSB_ERROR_NONE);
tusbh_cdc_unmounted_cb_Expect(dev_addr);
//------------- CUT -------------//
cdch_close(dev_addr);
}
//--------------------------------------------------------------------+
// CHECKING API
//--------------------------------------------------------------------+
void test_cdc_serial_is_mounted_not_configured(void)
{
tusbh_device_get_mounted_class_flag_ExpectAndReturn(dev_addr, 0);
TEST_ASSERT_FALSE( tusbh_cdc_serial_is_mounted(dev_addr) );
}
void test_cdc_serial_is_mounted_protocol_zero(void)
{
tusbh_device_get_mounted_class_flag_ExpectAndReturn(dev_addr, TU_BIT(TUSB_CLASS_CDC) );
cdch_data[0].interface_protocol = 0;
TEST_ASSERT_FALSE( tusbh_cdc_serial_is_mounted(dev_addr) );
}
void test_cdc_serial_is_mounted_protocol_is_vendor(void)
{
tusbh_device_get_mounted_class_flag_ExpectAndReturn(dev_addr, TU_BIT(TUSB_CLASS_CDC) );
cdch_data[0].interface_protocol = 0xff;
TEST_ASSERT_FALSE( tusbh_cdc_serial_is_mounted(dev_addr) );
}
void test_cdc_serial_is_mounted_protocol_is_at_command(void)
{
tusbh_device_get_mounted_class_flag_ExpectAndReturn(dev_addr, TU_BIT(TUSB_CLASS_CDC) );
cdch_data[0].interface_protocol = CDC_COMM_PROTOCOL_ATCOMMAND;
TEST_ASSERT( tusbh_cdc_serial_is_mounted(dev_addr) );
}
//--------------------------------------------------------------------+
// TRANSFER API
//--------------------------------------------------------------------+
void test_cdc_xfer_notification_pipe(void)
{
pipe_handle_t pipe_notification = { .dev_addr = 1, .xfer_type = TUSB_XFER_INTERRUPT };
pipe_handle_t pipe_out = { .dev_addr = 1, .xfer_type = TUSB_XFER_BULK, .index = 0 };
pipe_handle_t pipe_in = { .dev_addr = 1, .xfer_type = TUSB_XFER_BULK, .index = 1 };
cdch_data[dev_addr-1].pipe_notification = pipe_notification;
cdch_data[dev_addr-1].pipe_out = pipe_out;
cdch_data[dev_addr-1].pipe_in = pipe_in;
tusbh_cdc_xfer_isr_Expect(dev_addr, XFER_RESULT_SUCCESS, CDC_PIPE_NOTIFICATION, 10);
//------------- CUT -------------//
cdch_isr(pipe_notification, XFER_RESULT_SUCCESS, 10);
}
void test_cdc_xfer_pipe_out(void)
{
pipe_handle_t pipe_notification = { .dev_addr = 1, .xfer_type = TUSB_XFER_INTERRUPT };
pipe_handle_t pipe_out = { .dev_addr = 1, .xfer_type = TUSB_XFER_BULK, .index = 0 };
pipe_handle_t pipe_in = { .dev_addr = 1, .xfer_type = TUSB_XFER_BULK, .index = 1 };
cdch_data[dev_addr-1].pipe_notification = pipe_notification;
cdch_data[dev_addr-1].pipe_out = pipe_out;
cdch_data[dev_addr-1].pipe_in = pipe_in;
tusbh_cdc_xfer_isr_Expect(dev_addr, XFER_RESULT_FAILED, CDC_PIPE_DATA_OUT, 20);
//------------- CUT -------------//
cdch_isr(pipe_out, XFER_RESULT_FAILED, 20);
}
void test_cdc_xfer_pipe_in(void)
{
pipe_handle_t pipe_notification = { .dev_addr = 1, .xfer_type = TUSB_XFER_INTERRUPT };
pipe_handle_t pipe_out = { .dev_addr = 1, .xfer_type = TUSB_XFER_BULK, .index = 0 };
pipe_handle_t pipe_in = { .dev_addr = 1, .xfer_type = TUSB_XFER_BULK, .index = 1 };
cdch_data[dev_addr-1].pipe_notification = pipe_notification;
cdch_data[dev_addr-1].pipe_out = pipe_out;
cdch_data[dev_addr-1].pipe_in = pipe_in;
tusbh_cdc_xfer_isr_Expect(dev_addr, XFER_RESULT_STALLED, CDC_PIPE_DATA_IN, 0);
//------------- CUT -------------//
cdch_isr(pipe_in, XFER_RESULT_STALLED, 0);
}
@@ -0,0 +1,304 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Ha Thach (tinyusb.org)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* This file is part of the TinyUSB stack.
*/
void setUp(void)
{
}
void tearDown(void)
{
}
#if 0 // TODO enable
#include "stdlib.h"
#include "unity.h"
#include "tusb_option.h"
#include "tusb_errors.h"
#include "binary.h"
#include "type_helper.h"
#include "mock_osal.h"
#include "mock_hcd.h"
#include "mock_usbh.h"
#include "mock_cdc_callback.h"
#include "descriptor_cdc.h"
#include "cdc_host.h"
#include "cdc_rndis_host.h"
static uint8_t dev_addr;
static uint16_t length;
static tusb_desc_interface_t const * p_comm_interface = &rndis_config_descriptor.cdc_comm_interface;
static tusb_desc_endpoint_t const * p_endpoint_notification = &rndis_config_descriptor.cdc_endpoint_notification;
static tusb_desc_endpoint_t const * p_endpoint_out = &rndis_config_descriptor.cdc_endpoint_out;
static tusb_desc_endpoint_t const * p_endpoint_in = &rndis_config_descriptor.cdc_endpoint_in;
static pipe_handle_t pipe_notification = { .dev_addr = 1, .xfer_type = TUSB_XFER_INTERRUPT };
static pipe_handle_t pipe_out = { .dev_addr = 1, .xfer_type = TUSB_XFER_BULK, .index = 0 };
static pipe_handle_t pipe_in = { .dev_addr = 1, .xfer_type = TUSB_XFER_BULK, .index = 1 };
extern cdch_data_t cdch_data[CFG_TUSB_HOST_DEVICE_MAX];
extern rndish_data_t rndish_data[CFG_TUSB_HOST_DEVICE_MAX];
static cdch_data_t * p_cdc = &cdch_data[0];
static rndish_data_t * p_rndis = &rndish_data[0];
enum {
bmrequest_send = 0x21,
bmrequest_get = 0xA1
};
void stub_mutex_wait(osal_mutex_handle_t mutex_hdl, uint32_t msec, tusb_error_t *p_error, int num_call)
{
*p_error = TUSB_ERROR_NONE;
}
void setUp(void)
{
length = 0;
dev_addr = 1;
for (uint8_t i=0; i<CFG_TUSB_HOST_DEVICE_MAX; i++)
{
osal_semaphore_create_ExpectAndReturn( &rndish_data[i].semaphore_notification, &rndish_data[i].semaphore_notification);
}
cdch_init();
osal_mutex_wait_StubWithCallback(stub_mutex_wait);
osal_mutex_release_IgnoreAndReturn(TUSB_ERROR_NONE);
hcd_edpt_open_ExpectAndReturn(dev_addr, p_endpoint_notification, TUSB_CLASS_CDC, pipe_notification);
hcd_edpt_open_ExpectAndReturn(dev_addr, p_endpoint_out, TUSB_CLASS_CDC, pipe_out);
hcd_edpt_open_ExpectAndReturn(dev_addr, p_endpoint_in, TUSB_CLASS_CDC, pipe_in);
}
void tearDown(void)
{
}
static rndis_msg_initialize_t msg_init =
{
.type = RNDIS_MSG_INITIALIZE,
.length = sizeof(rndis_msg_initialize_t),
.request_id = 1, // TODO should use some magic number
.major_version = 1,
.minor_version = 0,
.max_xfer_size = 0x4000 // TODO mimic windows
};
static rndis_msg_initialize_cmplt_t msg_init_cmplt =
{
.type = RNDIS_MSG_INITIALIZE_CMPLT,
.length = sizeof(rndis_msg_initialize_cmplt_t),
.request_id = 1,
.status = RNDIS_STATUS_SUCCESS,
.major_version = 1,
.minor_version = 0,
.device_flags = 0x10,
.medium = 0, // TODO cannot find info on this
.max_packet_per_xfer = 1,
.max_xfer_size = 0x100, // TODO change later
.packet_alignment_factor = 5 // aligment of each RNDIS message (payload) = 2^factor
};
static rndis_msg_query_t msg_query_permanent_addr =
{
.type = RNDIS_MSG_QUERY,
.length = sizeof(rndis_msg_query_t)+6,
.request_id = 1,
.oid = RNDIS_OID_802_3_PERMANENT_ADDRESS,
.buffer_length = 6,
.buffer_offset = 20,
.oid_buffer = {0, 0, 0, 0, 0, 0}
};
static rndis_msg_query_cmplt_t msg_query_permanent_addr_cmplt =
{
.type = RNDIS_MSG_QUERY_CMPLT,
.length = sizeof(rndis_msg_query_cmplt_t)+6,
.request_id = 1,
.status = RNDIS_STATUS_SUCCESS,
.buffer_length = 6,
.buffer_offset = 16,
.oid_buffer = "CAFEBB"
};
static rndis_msg_set_t msg_set_packet_filter =
{
.type = RNDIS_MSG_SET,
.length = sizeof(rndis_msg_set_t)+4,
.request_id = 1,
.oid = RNDIS_OID_GEN_CURRENT_PACKET_FILTER,
.buffer_length = 4,
.buffer_offset = 20,
.oid_buffer = {RNDIS_PACKET_TYPE_DIRECTED | RNDIS_PACKET_TYPE_MULTICAST | RNDIS_PACKET_TYPE_BROADCAST, 0, 0, 0}
};
static rndis_msg_set_cmplt_t msg_set_packet_filter_cmplt =
{
.type = RNDIS_MSG_SET_CMPLT,
.length = sizeof(rndis_msg_set_cmplt_t),
.request_id = 1,
.status = RNDIS_STATUS_SUCCESS
};
static tusb_error_t stub_pipe_notification_xfer(pipe_handle_t pipe_hdl, uint8_t buffer[], uint16_t total_bytes, bool int_on_complete, int num_call)
{
TEST_ASSERT( pipehandle_is_equal(pipe_notification, pipe_hdl) );
TEST_ASSERT_EQUAL( 8, total_bytes );
TEST_ASSERT( int_on_complete );
buffer[0] = 1; // response available
cdch_isr(pipe_hdl, XFER_RESULT_SUCCESS, 8);
return TUSB_ERROR_NONE;
}
void stub_sem_wait_success(osal_semaphore_handle_t const sem_hdl, uint32_t msec, tusb_error_t *p_error, int num_call)
{
TEST_ASSERT_EQUAL_HEX(p_rndis->sem_notification_hdl, sem_hdl);
(*p_error) = TUSB_ERROR_NONE;
}
void stub_sem_wait_timeout(osal_semaphore_handle_t const sem_hdl, uint32_t msec, tusb_error_t *p_error, int num_call)
{
(*p_error) = TUSB_ERROR_OSAL_TIMEOUT;
}
//------------- Test Code -------------//
void test_rndis_send_initalize_failed(void)
{
usbh_control_xfer_subtask_ExpectWithArrayAndReturn(
dev_addr, bmrequest_send, SEND_ENCAPSULATED_COMMAND, 0, p_comm_interface->bInterfaceNumber,
sizeof(rndis_msg_initialize_t), (uint8_t*)&msg_init, sizeof(rndis_msg_initialize_t), TUSB_ERROR_OSAL_TIMEOUT);
tusbh_cdc_mounted_cb_Expect(dev_addr);
//------------- Code Under Test -------------//
TEST_ASSERT_EQUAL( TUSB_ERROR_NONE, cdch_open_subtask(dev_addr, p_comm_interface, &length) );
}
void test_rndis_initialization_notification_timeout(void)
{
usbh_control_xfer_subtask_ExpectWithArrayAndReturn(
dev_addr, bmrequest_send, SEND_ENCAPSULATED_COMMAND, 0, p_comm_interface->bInterfaceNumber,
sizeof(rndis_msg_initialize_t), (uint8_t*)&msg_init, sizeof(rndis_msg_initialize_t), TUSB_ERROR_NONE);
hcd_pipe_xfer_IgnoreAndReturn(TUSB_ERROR_NONE);
osal_semaphore_wait_StubWithCallback(stub_sem_wait_timeout);
tusbh_cdc_mounted_cb_Expect(dev_addr);
//------------- Code Under Test -------------//
TEST_ASSERT_STATUS( cdch_open_subtask(dev_addr, p_comm_interface, &length) );
TEST_ASSERT_FALSE(p_cdc->is_rndis);
}
tusb_error_t stub_control_xfer(uint8_t addr, uint8_t bmRequestType, uint8_t bRequest,
uint16_t wValue, uint16_t wIndex, uint16_t wLength, uint8_t* data, int num_call )
{
TEST_ASSERT_EQUAL(p_comm_interface->bInterfaceNumber, wIndex);
TEST_ASSERT_EQUAL(0, wValue);
TEST_ASSERT_EQUAL(dev_addr, addr);
switch(num_call)
{
//------------- Initialize -------------//
case 0*2+0: // initialize
TEST_ASSERT_EQUAL(bmrequest_send, bmRequestType);
TEST_ASSERT_EQUAL(SEND_ENCAPSULATED_COMMAND, bRequest);
TEST_ASSERT_EQUAL(sizeof(rndis_msg_initialize_t), wLength);
TEST_ASSERT_EQUAL_HEX8_ARRAY(&msg_init, data, wLength);
break;
case 0*2+1: // initialize complete
TEST_ASSERT_EQUAL(bmrequest_get, bmRequestType);
TEST_ASSERT_EQUAL(GET_ENCAPSULATED_RESPONSE, bRequest);
TEST_ASSERT( wLength >= 0x0400 ); // Microsoft Specs
memcpy(data, &msg_init_cmplt, sizeof(rndis_msg_initialize_cmplt_t));
break;
// query for RNDIS_OID_802_3_PERMANENT_ADDRESS
case 1*2+0:
TEST_ASSERT_EQUAL(bmrequest_send, bmRequestType);
TEST_ASSERT_EQUAL(SEND_ENCAPSULATED_COMMAND, bRequest);
TEST_ASSERT_EQUAL(sizeof(rndis_msg_query_t) + 6, wLength); // 6 bytes for MAC address
TEST_ASSERT_EQUAL_HEX8_ARRAY(&msg_query_permanent_addr, data, wLength);
break;
case 1*2+1: // query complete for RNDIS_OID_802_3_PERMANENT_ADDRESS
TEST_ASSERT_EQUAL(bmrequest_get, bmRequestType);
TEST_ASSERT_EQUAL(GET_ENCAPSULATED_RESPONSE, bRequest);
TEST_ASSERT( wLength >= 0x0400 ); // Microsoft Specs
memcpy(data, &msg_query_permanent_addr_cmplt, sizeof(rndis_msg_query_cmplt_t) + 6);
break;
// set RNDIS_OID_GEN_CURRENT_PACKET_FILTER to DIRECTED | MULTICAST | BROADCAST
case 2*2+0:
TEST_ASSERT_EQUAL(bmrequest_send, bmRequestType);
TEST_ASSERT_EQUAL(SEND_ENCAPSULATED_COMMAND, bRequest);
TEST_ASSERT_EQUAL(sizeof(rndis_msg_set_t)+4, wLength);
TEST_ASSERT_EQUAL_HEX8_ARRAY(&msg_set_packet_filter, data, wLength);
break;
case 2*2+1: // query complete for RNDIS_OID_802_3_PERMANENT_ADDRESS
TEST_ASSERT_EQUAL(bmrequest_get, bmRequestType);
TEST_ASSERT_EQUAL(GET_ENCAPSULATED_RESPONSE, bRequest);
TEST_ASSERT( wLength >= 0x0400 ); // Microsoft Specs
memcpy(data, &msg_set_packet_filter_cmplt, sizeof(rndis_msg_set_cmplt_t) );
break;
default:
return TUSB_ERROR_OSAL_TIMEOUT;
}
return TUSB_ERROR_NONE;
}
void test_rndis_initialization_sequence_ok(void)
{
usbh_control_xfer_subtask_StubWithCallback(stub_control_xfer);
hcd_pipe_xfer_StubWithCallback(stub_pipe_notification_xfer);
osal_semaphore_wait_StubWithCallback(stub_sem_wait_success);
osal_semaphore_post_ExpectAndReturn(p_rndis->sem_notification_hdl, TUSB_ERROR_NONE);
osal_semaphore_post_ExpectAndReturn(p_rndis->sem_notification_hdl, TUSB_ERROR_NONE);
osal_semaphore_post_ExpectAndReturn(p_rndis->sem_notification_hdl, TUSB_ERROR_NONE);
tusbh_cdc_rndis_mounted_cb_Expect(dev_addr);
//------------- Code Under Test -------------//
TEST_ASSERT_STATUS( cdch_open_subtask(dev_addr, p_comm_interface, &length) );
TEST_ASSERT(p_cdc->is_rndis);
TEST_ASSERT_EQUAL(msg_init_cmplt.max_xfer_size, p_rndis->max_xfer_size);
TEST_ASSERT_EQUAL_HEX8_ARRAY("CAFEBB", p_rndis->mac_address, 6);
}
#endif