refractor tests

This commit is contained in:
hathach 2013-03-05 15:23:12 +07:00
parent 3ed29f5f3c
commit c0bbc2aded
4 changed files with 145 additions and 60 deletions

View File

@ -0,0 +1,71 @@
/*
* test_ehci.h
*
* Created on: Mar 5, 2013
* Author: hathach
*/
/*
* Software License Agreement (BSD License)
* Copyright (c) 2012, hathach (tinyusb.net)
* 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.
*/
/** \file
* \brief TBD
*
* \note TBD
*/
/** \ingroup TBD
* \defgroup TBD
* \brief TBD
*
* @{
*/
#ifndef _TUSB_TEST_EHCI_H_
#define _TUSB_TEST_EHCI_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdlib.h>
ehci_registers_t* const get_operational_register(uint8_t hostid);
ehci_link_t* const get_period_frame_list(uint8_t list_idx);
ehci_qhd_t* const get_async_head(uint8_t hostid);
ehci_qhd_t* const get_period_head(uint8_t hostid);
#ifdef __cplusplus
}
#endif
#endif /* _TUSB_TEST_EHCI_H_ */
/** @} */

View File

@ -45,6 +45,7 @@
#include "hcd.h"
#include "usbh_hcd.h"
#include "ehci.h"
#include "test_ehci.h"
extern ehci_data_t ehci_data;
usbh_device_info_t usbh_device_info_pool[TUSB_CFG_HOST_DEVICE_MAX+1];
@ -53,9 +54,12 @@ LPC_USB0_Type lpc_usb0;
LPC_USB1_Type lpc_usb1;
uint8_t const max_packet_size = 64;
uint8_t dev_addr = 0;
uint8_t dev_addr;
uint8_t hub_addr;
uint8_t hub_port;
uint8_t hostid;
ehci_qhd_t *async_head;
//--------------------------------------------------------------------+
// Setup/Teardown + helper declare
@ -67,9 +71,22 @@ void setUp(void)
memclr_(usbh_device_info_pool, sizeof(usbh_device_info_t)*(TUSB_CFG_HOST_DEVICE_MAX+1));
dev_addr = 0;
hcd_init();
dev_addr = 1;
hostid = RANDOM(CONTROLLER_HOST_NUMBER) + TEST_CONTROLLER_HOST_START_INDEX;
hub_addr = 2;
hub_port = 2;
for (uint8_t i=0; i<TUSB_CFG_HOST_DEVICE_MAX; i++)
{
usbh_device_info_pool[i].core_id = hostid;
usbh_device_info_pool[i].hub_addr = hub_addr;
usbh_device_info_pool[i].hub_port = hub_port;
}
async_head = get_async_head( hostid );
}
void tearDown(void)
@ -106,86 +123,79 @@ void verify_control_open_qhd(ehci_qhd_t *p_qhd)
void test_control_open_addr0_qhd_data(void)
{
dev_addr = 0;
for (uint8_t i=0; i<CONTROLLER_HOST_NUMBER; i++)
{
uint8_t hostid = i + TEST_CONTROLLER_HOST_START_INDEX;
ehci_qhd_t * const p_qhd = get_async_head( hostid );
usbh_device_info_pool[dev_addr].core_id = hostid;
usbh_device_info_pool[dev_addr].hub_addr = hub_addr;
usbh_device_info_pool[dev_addr].hub_port = hub_port;
ehci_qhd_t * const p_qhd = async_head;
hcd_pipe_control_open(dev_addr, max_packet_size);
hcd_pipe_control_open(dev_addr, max_packet_size);
verify_control_open_qhd(p_qhd);
TEST_ASSERT(p_qhd->head_list_flag);
}
verify_control_open_qhd(p_qhd);
TEST_ASSERT(p_qhd->head_list_flag);
}
void test_control_open_qhd_data(void)
{
dev_addr = 1;
for (uint8_t i=0; i<CONTROLLER_HOST_NUMBER; i++)
{
uint8_t hostid = i + TEST_CONTROLLER_HOST_START_INDEX;
ehci_qhd_t * const async_head = get_async_head( hostid );
ehci_qhd_t * const p_qhd = &ehci_data.device[dev_addr].control.qhd;
ehci_qhd_t * const p_qhd = &ehci_data.device[dev_addr].control.qhd;
hcd_pipe_control_open(dev_addr, max_packet_size);
usbh_device_info_pool[dev_addr].core_id = hostid;
usbh_device_info_pool[dev_addr].hub_addr = hub_addr;
usbh_device_info_pool[dev_addr].hub_port = hub_port;
verify_control_open_qhd(p_qhd);
TEST_ASSERT_FALSE(p_qhd->head_list_flag);
hcd_pipe_control_open(dev_addr, max_packet_size);
verify_control_open_qhd(p_qhd);
TEST_ASSERT_FALSE(p_qhd->head_list_flag);
//------------- 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);
}
//------------- 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_control_open_highspeed(void)
{
dev_addr = 1;
for (uint8_t i=0; i<CONTROLLER_HOST_NUMBER; i++)
{
uint8_t hostid = i + TEST_CONTROLLER_HOST_START_INDEX;
ehci_qhd_t * const p_qhd = &ehci_data.device[dev_addr].control.qhd;
ehci_qhd_t * const p_qhd = &ehci_data.device[dev_addr].control.qhd;
usbh_device_info_pool[dev_addr].core_id = hostid;
usbh_device_info_pool[dev_addr].speed = TUSB_SPEED_HIGH;
usbh_device_info_pool[dev_addr].speed = TUSB_SPEED_HIGH;
hcd_pipe_control_open(dev_addr, max_packet_size);
hcd_pipe_control_open(dev_addr, max_packet_size);
TEST_ASSERT_EQUAL(TUSB_SPEED_HIGH, p_qhd->endpoint_speed);
TEST_ASSERT_FALSE(p_qhd->non_hs_control_endpoint);
}
TEST_ASSERT_EQUAL(TUSB_SPEED_HIGH, p_qhd->endpoint_speed);
TEST_ASSERT_FALSE(p_qhd->non_hs_control_endpoint);
}
void test_control_open_non_highspeed(void)
{
dev_addr = 1;
for (uint8_t i=0; i<CONTROLLER_HOST_NUMBER; i++)
{
uint8_t hostid = i + TEST_CONTROLLER_HOST_START_INDEX;
ehci_qhd_t * const p_qhd = &ehci_data.device[dev_addr].control.qhd;
ehci_qhd_t * const p_qhd = &ehci_data.device[dev_addr].control.qhd;
usbh_device_info_pool[dev_addr].core_id = hostid;
usbh_device_info_pool[dev_addr].speed = TUSB_SPEED_FULL;
usbh_device_info_pool[dev_addr].speed = TUSB_SPEED_FULL;
hcd_pipe_control_open(dev_addr, max_packet_size);
hcd_pipe_control_open(dev_addr, max_packet_size);
TEST_ASSERT_EQUAL(TUSB_SPEED_FULL, p_qhd->endpoint_speed);
TEST_ASSERT_TRUE(p_qhd->non_hs_control_endpoint);
}
TEST_ASSERT_EQUAL(TUSB_SPEED_FULL, p_qhd->endpoint_speed);
TEST_ASSERT_TRUE(p_qhd->non_hs_control_endpoint);
}
void test_control_open_device_not_connected(void)
//--------------------------------------------------------------------+
// BULK PIPE
//--------------------------------------------------------------------+
void test_open_bulk_qhd_data(void)
{
// dev_addr = 1;
// for (uint8_t i=0; i<CONTROLLER_HOST_NUMBER; i++)
// {
// uint8_t hostid = i + TEST_CONTROLLER_HOST_START_INDEX;
// ehci_qhd_t * const async_head = get_async_head( hostid );
// ehci_qhd_t * const p_qhd = &ehci_data.device[dev_addr].control.qhd;
//
// usbh_device_info_pool[dev_addr].core_id = hostid;
// usbh_device_info_pool[dev_addr].hub_addr = hub_addr;
// usbh_device_info_pool[dev_addr].hub_port = hub_port;
//
// hcd_pipe_open(dev_addr, &desc_configuration.keyboard_endpoint);
//
// verify_control_open_qhd(p_qhd);
// TEST_ASSERT_FALSE(p_qhd->head_list_flag);
//
// //------------- 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);
// }
}

View File

@ -103,6 +103,9 @@
}
#endif
#define RANDOM(n) (rand()%(n))
#endif /* _TUSB_TUSB_CONFIG_H_ */
/** @} */

View File

@ -307,9 +307,10 @@ tusb_error_t hcd_pipe_control_open(uint8_t dev_addr, uint8_t max_packet_size)
// return TUSB_ERROR_NONE;
//}
//
//pipe_handle_t hcd_pipe_open(uint8_t dev_addr, tusb_descriptor_endpoint_t const * endpoint_desc)
//{
// return TUSB_ERROR_NONE;
//}
pipe_handle_t hcd_pipe_open(uint8_t dev_addr, tusb_descriptor_endpoint_t const * endpoint_desc)
{
return TUSB_ERROR_NONE;
}
#endif