summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsakumisu <[email protected]>2023-08-15 14:33:54 +0800
committersakumisu <[email protected]>2023-08-15 14:33:54 +0800
commit3792ad4905ae5ebf4cd42cc92e17e91d44f1600f (patch)
tree284ef0f1c20be7cc0dd1f55957b615d68d917372
parent2789633b50d0b9d511a1adf3e7770500dbc31b71 (diff)
add test scripts
-rw-r--r--tools/test_srcipts/test_cdc_speed.py49
-rw-r--r--tools/test_srcipts/test_hid_inout.py68
2 files changed, 117 insertions, 0 deletions
diff --git a/tools/test_srcipts/test_cdc_speed.py b/tools/test_srcipts/test_cdc_speed.py
new file mode 100644
index 00000000..f11b70a4
--- /dev/null
+++ b/tools/test_srcipts/test_cdc_speed.py
@@ -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() \ No newline at end of file
diff --git a/tools/test_srcipts/test_hid_inout.py b/tools/test_srcipts/test_hid_inout.py
new file mode 100644
index 00000000..df512d24
--- /dev/null
+++ b/tools/test_srcipts/test_hid_inout.py
@@ -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!") \ No newline at end of file