Skip to content

Commit dd57b5b

Browse files
committed
Explicitly specify USBPhy used for testing
Add a parameter to the USBPhy class so mock or wrapper USBPhy classes can be used.
1 parent 99124c5 commit dd57b5b

File tree

3 files changed

+22
-16
lines changed

3 files changed

+22
-16
lines changed

TESTS/usb_device/basic/USBTester.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
#define MIN_EP_SIZE 8
3838

3939

40-
USBTester::USBTester(uint16_t vendor_id, uint16_t product_id, uint16_t product_release, bool connect_blocking):
41-
USBDevice(vendor_id, product_id, product_release), reset_count(0), suspend_count(0),
40+
USBTester::USBTester(USBPhy *phy, uint16_t vendor_id, uint16_t product_id, uint16_t product_release, bool connect_blocking):
41+
USBDevice(phy, vendor_id, product_id, product_release), reset_count(0), suspend_count(0),
4242
resume_count(0), interface_set(NONE), configuration_set(NONE)
4343
{
4444

TESTS/usb_device/basic/USBTester.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class USBTester: public USBDevice {
3636
* @param product_release Your preoduct_release
3737
* @param connect_blocking define if the connection must be blocked if USB not plugged in
3838
*/
39-
USBTester(uint16_t vendor_id, uint16_t product_id, uint16_t product_release, bool connect_blocking);
39+
USBTester(USBPhy *phy, uint16_t vendor_id, uint16_t product_id, uint16_t product_release, bool connect_blocking);
4040

4141
~USBTester();
4242

TESTS/usb_device/basic/main.cpp

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "utest/utest.h"
2323

2424
#include "USBTester.h"
25+
#include "usb_phy_api.h"
2526

2627
// If disconnect() + connect() occur too fast the reset event will be dropped.
2728
// At a minimum there should be a 200us delay between disconnect and connect.
@@ -35,6 +36,11 @@
3536

3637
using namespace utest::v1;
3738

39+
static USBPhy *get_phy()
40+
{
41+
return get_usb_phy();
42+
}
43+
3844
void control_basic_test()
3945
{
4046
uint16_t vendor_id = 0x0d28;
@@ -45,7 +51,7 @@ void control_basic_test()
4551
char str[128] = {};
4652

4753
{
48-
USBTester serial(vendor_id, product_id, product_release, true);
54+
USBTester serial(get_phy(), vendor_id, product_id, product_release, true);
4955
sprintf (str, "%s %d %d", serial.get_serial_desc_string(), vendor_id, product_id);
5056
greentea_send_kv("control_basic_test", str);
5157
// Wait for host before terminating
@@ -63,7 +69,7 @@ void control_stall_test()
6369
char _value[128] = {};
6470

6571
{
66-
USBTester serial(vendor_id, product_id, product_release, true);
72+
USBTester serial(get_phy(), vendor_id, product_id, product_release, true);
6773
greentea_send_kv("control_stall_test", serial.get_serial_desc_string());
6874
// Wait for host before terminating
6975
greentea_parse_kv(_key, _value, sizeof(_key), sizeof(_value));
@@ -80,7 +86,7 @@ void control_sizes_test()
8086
char _value[128] = {};
8187

8288
{
83-
USBTester serial(vendor_id, product_id, product_release, true);
89+
USBTester serial(get_phy(), vendor_id, product_id, product_release, true);
8490
greentea_send_kv("control_sizes_test", serial.get_serial_desc_string());
8591
// Wait for host before terminating
8692
greentea_parse_kv(_key, _value, sizeof(_key), sizeof(_value));
@@ -97,7 +103,7 @@ void control_stress_test()
97103
char _value[128] = {};
98104

99105
{
100-
USBTester serial(vendor_id, product_id, product_release, true);
106+
USBTester serial(get_phy(), vendor_id, product_id, product_release, true);
101107
greentea_send_kv("control_stress_test", serial.get_serial_desc_string());
102108
// Wait for host before terminating
103109
greentea_parse_kv(_key, _value, sizeof(_key), sizeof(_value));
@@ -117,7 +123,7 @@ void device_reset_test()
117123
greentea_parse_kv(_key, _value, sizeof(_key), sizeof(_value));
118124
if (strcmp(_value, "false") != 0) {
119125

120-
USBTester serial(vendor_id, product_id, product_release, true);
126+
USBTester serial(get_phy(), vendor_id, product_id, product_release, true);
121127
serial.clear_reset_count();
122128
greentea_send_kv("device_reset_test", serial.get_serial_desc_string());
123129
while(serial.get_reset_count() == 0);
@@ -163,7 +169,7 @@ void device_soft_reconnection_test()
163169
const uint32_t reconnect_try_count = 3;
164170

165171
{
166-
USBTester serial(vendor_id, product_id, product_release, true);
172+
USBTester serial(get_phy(), vendor_id, product_id, product_release, true);
167173

168174
greentea_send_kv("device_soft_reconnection_test", serial.get_serial_desc_string());
169175
// Wait for host before terminating
@@ -205,7 +211,7 @@ void device_suspend_resume_test()
205211
char _value[128] = {};
206212

207213
{
208-
USBTester serial(vendor_id, product_id, product_release, true);
214+
USBTester serial(get_phy(), vendor_id, product_id, product_release, true);
209215
greentea_send_kv("device_suspend_resume_test", serial.get_serial_desc_string());
210216
printf("[1] suspend_count: %d resume_count: %d\n", serial.get_suspend_count(), serial.get_resume_count());
211217
serial.clear_suspend_count();
@@ -228,25 +234,25 @@ void repeated_construction_destruction_test()
228234
char _value[128] = {};
229235

230236
{
231-
USBTester serial(vendor_id, product_id, product_release, true);
237+
USBTester serial(get_phy(), vendor_id, product_id, product_release, true);
232238
TEST_ASSERT_EQUAL(true, serial.configured());
233239
}
234240

235241
wait_us(MIN_DISCONNECT_TIME_US);
236242
{
237-
USBTester serial(vendor_id, product_id, product_release, true);
243+
USBTester serial(get_phy(), vendor_id, product_id, product_release, true);
238244
TEST_ASSERT_EQUAL(true, serial.configured());
239245
}
240246

241247
wait_us(MIN_DISCONNECT_TIME_US);
242248
{
243-
USBTester serial(vendor_id, product_id, product_release, true);
249+
USBTester serial(get_phy(), vendor_id, product_id, product_release, true);
244250
TEST_ASSERT_EQUAL(true, serial.configured());
245251
}
246252

247253
wait_us(MIN_DISCONNECT_TIME_US);
248254
{
249-
USBTester serial(vendor_id, product_id, product_release, true);
255+
USBTester serial(get_phy(), vendor_id, product_id, product_release, true);
250256
TEST_ASSERT_EQUAL(true, serial.configured());
251257
greentea_send_kv("repeated_construction_destruction_test", serial.get_serial_desc_string());
252258
// Wait for host before terminating
@@ -256,7 +262,7 @@ void repeated_construction_destruction_test()
256262

257263
wait_us(MIN_DISCONNECT_TIME_US);
258264
{
259-
USBTester serial(vendor_id, product_id, product_release, true);
265+
USBTester serial(get_phy(), vendor_id, product_id, product_release, true);
260266
TEST_ASSERT_EQUAL(true, serial.configured());
261267
greentea_send_kv("repeated_construction_destruction_test", serial.get_serial_desc_string());
262268
// Wait for host before terminating
@@ -266,7 +272,7 @@ void repeated_construction_destruction_test()
266272

267273
wait_us(MIN_DISCONNECT_TIME_US);
268274
{
269-
USBTester serial(vendor_id, product_id, product_release, true);
275+
USBTester serial(get_phy(), vendor_id, product_id, product_release, true);
270276
TEST_ASSERT_EQUAL(true, serial.configured());
271277
greentea_send_kv("repeated_construction_destruction_test", serial.get_serial_desc_string());
272278
// Wait for host before terminating

0 commit comments

Comments
 (0)