add some tests support for msc host

refractor msch buffer for getting inital scsi like inquiry, read capacity
adding support for resovling stall on control pipe
This commit is contained in:
hathach
2013-09-24 15:05:11 +07:00
parent c4fef827b1
commit 63b776f7cf
20 changed files with 449 additions and 134 deletions
@@ -43,21 +43,108 @@
#include "binary.h"
#include "type_helper.h"
//#include "descriptor_test.h"
//#include "msc_host.h"
//#include "usbh.h"
//#include "hcd.h"
//#include "ehci.h"
#include "descriptor_test.h"
#include "mock_osal.h"
#include "mock_hcd.h"
#include "mock_usbh.h"
#include "mock_msch_callback.h"
#include "msc_host.h"
extern msch_interface_t msch_data[TUSB_CFG_HOST_DEVICE_MAX];
static tusb_descriptor_interface_t const *p_msc_interface_desc = &desc_configuration.msc_interface;
static tusb_descriptor_endpoint_t const *p_edp_in = &desc_configuration.msc_endpoint_in;
static tusb_descriptor_endpoint_t const *p_edp_out = &desc_configuration.msc_endpoint_out;
static msch_interface_t* p_msc;
static uint8_t dev_addr;
static pipe_handle_t pipe_in, pipe_out;
static pipe_handle_t const pipe_null = { 0 };
static uint16_t length;
void setUp(void)
{
dev_addr = RANDOM(TUSB_CFG_HOST_DEVICE_MAX)+1;
msch_init();
TEST_ASSERT_MEM_ZERO(msch_data, sizeof(msch_interface_t)*TUSB_CFG_HOST_DEVICE_MAX);
p_msc = &msch_data[dev_addr-1];
pipe_in = (pipe_handle_t) {.dev_addr = dev_addr, .xfer_type = TUSB_XFER_BULK, .index = 1};
pipe_out = (pipe_handle_t) {.dev_addr = dev_addr, .xfer_type = TUSB_XFER_BULK, .index = 2};
}
void tearDown(void)
{
length = 0;
}
void test_()
void test_open_pipe_in_failed(void)
{
// TEST_IGNORE();
hcd_pipe_open_ExpectAndReturn(dev_addr, p_edp_in, TUSB_CLASS_MSC, pipe_null);
TEST_ASSERT_EQUAL(TUSB_ERROR_HCD_OPEN_PIPE_FAILED, msch_open_subtask(dev_addr, p_msc_interface_desc, &length));
}
void test_open_pipe_out_failed(void)
{
hcd_pipe_open_ExpectAndReturn(dev_addr, p_edp_in, TUSB_CLASS_MSC, (pipe_handle_t) {1} );
hcd_pipe_open_ExpectAndReturn(dev_addr, p_edp_out, TUSB_CLASS_MSC, pipe_null);
TEST_ASSERT_EQUAL(TUSB_ERROR_HCD_OPEN_PIPE_FAILED, msch_open_subtask(dev_addr, p_msc_interface_desc, &length));
}
tusb_error_t stub_control_xfer(uint8_t dev_addr, uint8_t bmRequestType, uint8_t bRequest,
uint16_t wValue, uint16_t wIndex, uint16_t wLength, uint8_t* data, int num_call)
{
switch ( num_call )
{
case 0: // get max lun
TEST_ASSERT_EQUAL(bm_request_type(TUSB_DIR_DEV_TO_HOST, TUSB_REQUEST_TYPE_CLASS, TUSB_REQUEST_RECIPIENT_INTERFACE),
bmRequestType);
TEST_ASSERT_EQUAL(MSC_REQUEST_GET_MAX_LUN, bRequest);
TEST_ASSERT_EQUAL(p_msc_interface_desc->bInterfaceNumber, wIndex);
TEST_ASSERT_EQUAL(1, wLength);
*data = 1; // TODO multiple LUN support
break;
default:
TEST_FAIL();
return TUSB_ERROR_FAILED;
}
return TUSB_ERROR_NONE;
}
void test_open_desc_length(void)
{
hcd_pipe_open_ExpectAndReturn(dev_addr, p_edp_in, TUSB_CLASS_MSC, pipe_in);
hcd_pipe_open_ExpectAndReturn(dev_addr, p_edp_out, TUSB_CLASS_MSC, pipe_out);
usbh_control_xfer_subtask_IgnoreAndReturn(TUSB_ERROR_NONE);
hcd_pipe_xfer_IgnoreAndReturn(TUSB_ERROR_NONE);
hcd_pipe_queue_xfer_IgnoreAndReturn(TUSB_ERROR_NONE);
//------------- Code Under Test -------------//
TEST_ASSERT_STATUS( msch_open_subtask(dev_addr, p_msc_interface_desc, &length) );
TEST_ASSERT_EQUAL(sizeof(tusb_descriptor_interface_t) + 2*sizeof(tusb_descriptor_endpoint_t),
length);
}
void test_open_ok(void)
{
hcd_pipe_open_ExpectAndReturn(dev_addr, p_edp_in, TUSB_CLASS_MSC, pipe_in);
hcd_pipe_open_ExpectAndReturn(dev_addr, p_edp_out, TUSB_CLASS_MSC, pipe_out);
//------------- get max lun -------------//
usbh_control_xfer_subtask_StubWithCallback(stub_control_xfer);
//------------- Code Under Test -------------//
TEST_ASSERT_STATUS( msch_open_subtask(dev_addr, p_msc_interface_desc, &length) );
TEST_ASSERT_EQUAL(p_msc_interface_desc->bInterfaceNumber, p_msc->interface_number);
}