mirror of https://github.com/ARMmbed/mbed-os.git
Explicitly specify USBPhy used for testing
Add a parameter to the USBPhy class so mock or wrapper USBPhy classes can be used.feature-hal-spec-usb-device
parent
da46ea2b9c
commit
af5c99d5c1
|
@ -37,8 +37,8 @@
|
||||||
#define MIN_EP_SIZE 8
|
#define MIN_EP_SIZE 8
|
||||||
|
|
||||||
|
|
||||||
USBTester::USBTester(uint16_t vendor_id, uint16_t product_id, uint16_t product_release, bool connect_blocking):
|
USBTester::USBTester(USBPhy *phy, uint16_t vendor_id, uint16_t product_id, uint16_t product_release, bool connect_blocking):
|
||||||
USBDevice(vendor_id, product_id, product_release), reset_count(0), suspend_count(0),
|
USBDevice(phy, vendor_id, product_id, product_release), reset_count(0), suspend_count(0),
|
||||||
resume_count(0), interface_set(NONE), configuration_set(NONE)
|
resume_count(0), interface_set(NONE), configuration_set(NONE)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ public:
|
||||||
* @param product_release Your preoduct_release
|
* @param product_release Your preoduct_release
|
||||||
* @param connect_blocking define if the connection must be blocked if USB not plugged in
|
* @param connect_blocking define if the connection must be blocked if USB not plugged in
|
||||||
*/
|
*/
|
||||||
USBTester(uint16_t vendor_id, uint16_t product_id, uint16_t product_release, bool connect_blocking);
|
USBTester(USBPhy *phy, uint16_t vendor_id, uint16_t product_id, uint16_t product_release, bool connect_blocking);
|
||||||
|
|
||||||
~USBTester();
|
~USBTester();
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include "utest/utest.h"
|
#include "utest/utest.h"
|
||||||
|
|
||||||
#include "USBTester.h"
|
#include "USBTester.h"
|
||||||
|
#include "usb_phy_api.h"
|
||||||
|
|
||||||
// If disconnect() + connect() occur too fast the reset event will be dropped.
|
// If disconnect() + connect() occur too fast the reset event will be dropped.
|
||||||
// At a minimum there should be a 200us delay between disconnect and connect.
|
// At a minimum there should be a 200us delay between disconnect and connect.
|
||||||
|
@ -35,6 +36,11 @@
|
||||||
|
|
||||||
using namespace utest::v1;
|
using namespace utest::v1;
|
||||||
|
|
||||||
|
static USBPhy *get_phy()
|
||||||
|
{
|
||||||
|
return get_usb_phy();
|
||||||
|
}
|
||||||
|
|
||||||
void control_basic_test()
|
void control_basic_test()
|
||||||
{
|
{
|
||||||
uint16_t vendor_id = 0x0d28;
|
uint16_t vendor_id = 0x0d28;
|
||||||
|
@ -45,7 +51,7 @@ void control_basic_test()
|
||||||
char str[128] = {};
|
char str[128] = {};
|
||||||
|
|
||||||
{
|
{
|
||||||
USBTester serial(vendor_id, product_id, product_release, true);
|
USBTester serial(get_phy(), vendor_id, product_id, product_release, true);
|
||||||
sprintf (str, "%s %d %d", serial.get_serial_desc_string(), vendor_id, product_id);
|
sprintf (str, "%s %d %d", serial.get_serial_desc_string(), vendor_id, product_id);
|
||||||
greentea_send_kv("control_basic_test", str);
|
greentea_send_kv("control_basic_test", str);
|
||||||
// Wait for host before terminating
|
// Wait for host before terminating
|
||||||
|
@ -63,7 +69,7 @@ void control_stall_test()
|
||||||
char _value[128] = {};
|
char _value[128] = {};
|
||||||
|
|
||||||
{
|
{
|
||||||
USBTester serial(vendor_id, product_id, product_release, true);
|
USBTester serial(get_phy(), vendor_id, product_id, product_release, true);
|
||||||
greentea_send_kv("control_stall_test", serial.get_serial_desc_string());
|
greentea_send_kv("control_stall_test", serial.get_serial_desc_string());
|
||||||
// Wait for host before terminating
|
// Wait for host before terminating
|
||||||
greentea_parse_kv(_key, _value, sizeof(_key), sizeof(_value));
|
greentea_parse_kv(_key, _value, sizeof(_key), sizeof(_value));
|
||||||
|
@ -80,7 +86,7 @@ void control_sizes_test()
|
||||||
char _value[128] = {};
|
char _value[128] = {};
|
||||||
|
|
||||||
{
|
{
|
||||||
USBTester serial(vendor_id, product_id, product_release, true);
|
USBTester serial(get_phy(), vendor_id, product_id, product_release, true);
|
||||||
greentea_send_kv("control_sizes_test", serial.get_serial_desc_string());
|
greentea_send_kv("control_sizes_test", serial.get_serial_desc_string());
|
||||||
// Wait for host before terminating
|
// Wait for host before terminating
|
||||||
greentea_parse_kv(_key, _value, sizeof(_key), sizeof(_value));
|
greentea_parse_kv(_key, _value, sizeof(_key), sizeof(_value));
|
||||||
|
@ -97,7 +103,7 @@ void control_stress_test()
|
||||||
char _value[128] = {};
|
char _value[128] = {};
|
||||||
|
|
||||||
{
|
{
|
||||||
USBTester serial(vendor_id, product_id, product_release, true);
|
USBTester serial(get_phy(), vendor_id, product_id, product_release, true);
|
||||||
greentea_send_kv("control_stress_test", serial.get_serial_desc_string());
|
greentea_send_kv("control_stress_test", serial.get_serial_desc_string());
|
||||||
// Wait for host before terminating
|
// Wait for host before terminating
|
||||||
greentea_parse_kv(_key, _value, sizeof(_key), sizeof(_value));
|
greentea_parse_kv(_key, _value, sizeof(_key), sizeof(_value));
|
||||||
|
@ -117,7 +123,7 @@ void device_reset_test()
|
||||||
greentea_parse_kv(_key, _value, sizeof(_key), sizeof(_value));
|
greentea_parse_kv(_key, _value, sizeof(_key), sizeof(_value));
|
||||||
if (strcmp(_value, "false") != 0) {
|
if (strcmp(_value, "false") != 0) {
|
||||||
|
|
||||||
USBTester serial(vendor_id, product_id, product_release, true);
|
USBTester serial(get_phy(), vendor_id, product_id, product_release, true);
|
||||||
serial.clear_reset_count();
|
serial.clear_reset_count();
|
||||||
greentea_send_kv("device_reset_test", serial.get_serial_desc_string());
|
greentea_send_kv("device_reset_test", serial.get_serial_desc_string());
|
||||||
while(serial.get_reset_count() == 0);
|
while(serial.get_reset_count() == 0);
|
||||||
|
@ -163,7 +169,7 @@ void device_soft_reconnection_test()
|
||||||
const uint32_t reconnect_try_count = 3;
|
const uint32_t reconnect_try_count = 3;
|
||||||
|
|
||||||
{
|
{
|
||||||
USBTester serial(vendor_id, product_id, product_release, true);
|
USBTester serial(get_phy(), vendor_id, product_id, product_release, true);
|
||||||
|
|
||||||
greentea_send_kv("device_soft_reconnection_test", serial.get_serial_desc_string());
|
greentea_send_kv("device_soft_reconnection_test", serial.get_serial_desc_string());
|
||||||
// Wait for host before terminating
|
// Wait for host before terminating
|
||||||
|
@ -205,7 +211,7 @@ void device_suspend_resume_test()
|
||||||
char _value[128] = {};
|
char _value[128] = {};
|
||||||
|
|
||||||
{
|
{
|
||||||
USBTester serial(vendor_id, product_id, product_release, true);
|
USBTester serial(get_phy(), vendor_id, product_id, product_release, true);
|
||||||
greentea_send_kv("device_suspend_resume_test", serial.get_serial_desc_string());
|
greentea_send_kv("device_suspend_resume_test", serial.get_serial_desc_string());
|
||||||
printf("[1] suspend_count: %d resume_count: %d\n", serial.get_suspend_count(), serial.get_resume_count());
|
printf("[1] suspend_count: %d resume_count: %d\n", serial.get_suspend_count(), serial.get_resume_count());
|
||||||
serial.clear_suspend_count();
|
serial.clear_suspend_count();
|
||||||
|
@ -228,25 +234,25 @@ void repeated_construction_destruction_test()
|
||||||
char _value[128] = {};
|
char _value[128] = {};
|
||||||
|
|
||||||
{
|
{
|
||||||
USBTester serial(vendor_id, product_id, product_release, true);
|
USBTester serial(get_phy(), vendor_id, product_id, product_release, true);
|
||||||
TEST_ASSERT_EQUAL(true, serial.configured());
|
TEST_ASSERT_EQUAL(true, serial.configured());
|
||||||
}
|
}
|
||||||
|
|
||||||
wait_us(MIN_DISCONNECT_TIME_US);
|
wait_us(MIN_DISCONNECT_TIME_US);
|
||||||
{
|
{
|
||||||
USBTester serial(vendor_id, product_id, product_release, true);
|
USBTester serial(get_phy(), vendor_id, product_id, product_release, true);
|
||||||
TEST_ASSERT_EQUAL(true, serial.configured());
|
TEST_ASSERT_EQUAL(true, serial.configured());
|
||||||
}
|
}
|
||||||
|
|
||||||
wait_us(MIN_DISCONNECT_TIME_US);
|
wait_us(MIN_DISCONNECT_TIME_US);
|
||||||
{
|
{
|
||||||
USBTester serial(vendor_id, product_id, product_release, true);
|
USBTester serial(get_phy(), vendor_id, product_id, product_release, true);
|
||||||
TEST_ASSERT_EQUAL(true, serial.configured());
|
TEST_ASSERT_EQUAL(true, serial.configured());
|
||||||
}
|
}
|
||||||
|
|
||||||
wait_us(MIN_DISCONNECT_TIME_US);
|
wait_us(MIN_DISCONNECT_TIME_US);
|
||||||
{
|
{
|
||||||
USBTester serial(vendor_id, product_id, product_release, true);
|
USBTester serial(get_phy(), vendor_id, product_id, product_release, true);
|
||||||
TEST_ASSERT_EQUAL(true, serial.configured());
|
TEST_ASSERT_EQUAL(true, serial.configured());
|
||||||
greentea_send_kv("repeated_construction_destruction_test", serial.get_serial_desc_string());
|
greentea_send_kv("repeated_construction_destruction_test", serial.get_serial_desc_string());
|
||||||
// Wait for host before terminating
|
// Wait for host before terminating
|
||||||
|
@ -256,7 +262,7 @@ void repeated_construction_destruction_test()
|
||||||
|
|
||||||
wait_us(MIN_DISCONNECT_TIME_US);
|
wait_us(MIN_DISCONNECT_TIME_US);
|
||||||
{
|
{
|
||||||
USBTester serial(vendor_id, product_id, product_release, true);
|
USBTester serial(get_phy(), vendor_id, product_id, product_release, true);
|
||||||
TEST_ASSERT_EQUAL(true, serial.configured());
|
TEST_ASSERT_EQUAL(true, serial.configured());
|
||||||
greentea_send_kv("repeated_construction_destruction_test", serial.get_serial_desc_string());
|
greentea_send_kv("repeated_construction_destruction_test", serial.get_serial_desc_string());
|
||||||
// Wait for host before terminating
|
// Wait for host before terminating
|
||||||
|
@ -266,7 +272,7 @@ void repeated_construction_destruction_test()
|
||||||
|
|
||||||
wait_us(MIN_DISCONNECT_TIME_US);
|
wait_us(MIN_DISCONNECT_TIME_US);
|
||||||
{
|
{
|
||||||
USBTester serial(vendor_id, product_id, product_release, true);
|
USBTester serial(get_phy(), vendor_id, product_id, product_release, true);
|
||||||
TEST_ASSERT_EQUAL(true, serial.configured());
|
TEST_ASSERT_EQUAL(true, serial.configured());
|
||||||
greentea_send_kv("repeated_construction_destruction_test", serial.get_serial_desc_string());
|
greentea_send_kv("repeated_construction_destruction_test", serial.get_serial_desc_string());
|
||||||
// Wait for host before terminating
|
// Wait for host before terminating
|
||||||
|
|
Loading…
Reference in New Issue