add test scripts
This commit is contained in:
49
tools/test_srcipts/test_cdc_speed.py
Normal file
49
tools/test_srcipts/test_cdc_speed.py
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
import serial
|
||||||
|
import time
|
||||||
|
try:
|
||||||
|
from serial.tools.list_ports import comports
|
||||||
|
except ImportError:
|
||||||
|
raise serial.serialutil.SerialException
|
||||||
|
|
||||||
|
|
||||||
|
test_comx = 'COM66'
|
||||||
|
test_baudrate = 2000000
|
||||||
|
test_maxsize = 10*1024*1024
|
||||||
|
|
||||||
|
test_data = '0xAA' * 4096
|
||||||
|
|
||||||
|
test_serial = serial.Serial(test_comx, test_baudrate, timeout = 1)
|
||||||
|
|
||||||
|
def test_cdc_out():
|
||||||
|
send_count = 0
|
||||||
|
begin = time.time()
|
||||||
|
|
||||||
|
while True:
|
||||||
|
if send_count < test_maxsize:
|
||||||
|
txdatalen = test_serial.write(test_data.encode("utf-8"))
|
||||||
|
send_count += txdatalen
|
||||||
|
else:
|
||||||
|
print("cdc out speed %f MB/s" %(send_count//1024//1024/(time.time() - begin)))
|
||||||
|
break
|
||||||
|
|
||||||
|
def test_cdc_in():
|
||||||
|
read_count = 0
|
||||||
|
begin = time.time()
|
||||||
|
|
||||||
|
while True:
|
||||||
|
if read_count < test_maxsize:
|
||||||
|
data = test_serial.read(test_maxsize).decode(encoding='utf-8',errors='ignore')
|
||||||
|
read_count += len(data)
|
||||||
|
else:
|
||||||
|
print("cdc in speed %f MB/s" %(read_count//1024//1024/(time.time() - begin)))
|
||||||
|
break
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
print('test cdc out speed')
|
||||||
|
|
||||||
|
test_serial.setDTR(0)
|
||||||
|
test_cdc_out()
|
||||||
|
|
||||||
|
print('test cdc in speed')
|
||||||
|
test_serial.setDTR(1)
|
||||||
|
test_cdc_in()
|
||||||
68
tools/test_srcipts/test_hid_inout.py
Normal file
68
tools/test_srcipts/test_hid_inout.py
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
# Copyright (c) 2021 HPMicro
|
||||||
|
# SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
|
||||||
|
import pywinusb.hid as hid
|
||||||
|
import os
|
||||||
|
import time
|
||||||
|
import sys
|
||||||
|
import operator
|
||||||
|
|
||||||
|
# VID and PID customization changes here...
|
||||||
|
|
||||||
|
VID = 0xFFFF
|
||||||
|
PID = 0xFFFF
|
||||||
|
|
||||||
|
# Send buffer
|
||||||
|
buffer = [0xff]*64
|
||||||
|
|
||||||
|
# Const
|
||||||
|
TIMEOUT = -1
|
||||||
|
PASS = 0
|
||||||
|
FAIL = 1
|
||||||
|
|
||||||
|
# Result
|
||||||
|
result = TIMEOUT
|
||||||
|
|
||||||
|
def search_dev():
|
||||||
|
filter = hid.HidDeviceFilter(vendor_id = VID, product_id = PID)
|
||||||
|
hid_device = filter.get_devices()
|
||||||
|
return hid_device
|
||||||
|
|
||||||
|
def recv_data(data):
|
||||||
|
print("<=================== USB HID Read ========================>")
|
||||||
|
for i in range(0, len(data)):
|
||||||
|
print("0x{0:02x}" .format(data[i]), end=" ")
|
||||||
|
print("\n")
|
||||||
|
|
||||||
|
global result
|
||||||
|
result = (PASS if (operator.eq(data[1:-1], buffer[1:-1]) == True) else FAIL)
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
|
def send_data(report):
|
||||||
|
print("<=================== USB HID Write ========================>")
|
||||||
|
buffer[0] = report[0].report_id
|
||||||
|
print("0x{0:02x}" .format(buffer[0]), end=" ")
|
||||||
|
|
||||||
|
for i in range(1,64):
|
||||||
|
buffer[i] = i % 256
|
||||||
|
print("0x{0:02x}" .format(buffer[i]), end=" ")
|
||||||
|
print("\n")
|
||||||
|
|
||||||
|
report[0].set_raw_data(buffer)
|
||||||
|
report[0].send()
|
||||||
|
return None
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
device = search_dev()[0]
|
||||||
|
device.open()
|
||||||
|
device.set_raw_data_handler(recv_data)
|
||||||
|
send_data(device.find_output_reports())
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
|
if result == PASS:
|
||||||
|
print("USB hid echo passed!")
|
||||||
|
elif result == FAIL:
|
||||||
|
print("USB HID echo failed!")
|
||||||
|
else:
|
||||||
|
print("USB HID echo timed out!")
|
||||||
Reference in New Issue
Block a user