Test method, device and equipment of USB equipment and readable storage medium

By obtaining the connection information of the USB device and identifying the target protocol, the test program is automatically obtained, which solves the problem of large workload and low efficiency of USB device testing in the prior art, and realizes efficient automated testing of a variety of USB devices.

CN119718796APending Publication Date: 2025-03-28BEIJING SMARTMORE INTELLIGENT TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411741659.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-29
Publication Date
2025-03-28

AI Technical Summary

Technical Problem

In the prior art, the testing workload of USB devices is large and the testing efficiency is low, and it requires manual writing of test programs.

Method used

By obtaining the connection information sent by the USB device, determining the device descriptor, and identifying the target protocol based on the descriptor, the corresponding target test program is determined in the preset test program library, and automated testing of the USB device is realized.

Benefits of technology

Reduces the steps of USB device testing, improves testing efficiency, and enables automated testing of multiple types of USB devices.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119718796A_ABST
    Figure CN119718796A_ABST
Patent Text Reader

Abstract

The invention relates to a USB equipment testing method and device, equipment and a readable storage medium. The method comprises the following steps: acquiring connection information sent by a USB device, wherein the USB device is connected with the terminal through a port of the terminal; determining a device descriptor of the USB device based on the connection information; identifying a target protocol used by the connection information based on the device descriptor; based on the device descriptor and the target protocol, determining a target test program corresponding to the device descriptor and the target protocol in a preset test program library; and testing the USB device based on the target test program to obtain a test result related to the USB device. By adopting the method and the device, the automatic test of the USB equipment can be realized, so that the test efficiency of the USB equipment is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of device testing, and in particular to a method and apparatus for testing a USB device, a computer device, and a computer-readable storage medium. Background Art

[0002] With the rapid development of computers, USB (Universal Serial Bus) interface has been widely used due to its plug-and-play advantage. USB technology has become an indispensable part of modern electronic devices. In the process of USB technology development, the complexity and importance of USB testing are also increasing.

[0003] Currently, device manufacturers usually manually write a test program for each USB device protocol to perform testing, which results in a large workload and low testing efficiency for USB devices. Summary of the invention

[0004] Based on this, it is necessary to provide a USB device testing method, apparatus, computer equipment, computer readable storage medium and computer program product to address the above technical problems, which can reduce the steps of USB device testing and thus improve the testing efficiency of USB devices.

[0005] In a first aspect, the present application provides a method for testing a USB device, comprising:

[0006] Acquire connection information sent by a USB device, wherein the USB device is connected to the terminal through a port of the terminal;

[0007] Determine a device descriptor of the USB device based on the connection information;

[0008] identifying a target protocol used by the connection information based on the device descriptor;

[0009] Based on the device descriptor and the protocol, determining a target test program corresponding to the device descriptor and the protocol in a preset test program library;

[0010] The USB device is tested based on the target test program to obtain a test result related to the USB device.

[0011] In a second aspect, the present application provides a testing device for a USB device, comprising:

[0012] A connection information acquisition module, used to acquire connection information sent by a USB device, wherein the USB device is connected to the terminal through a port of the terminal;

[0013] A determination module, configured to determine a device descriptor of the USB device based on the connection information;

[0014] A protocol acquisition module, used for acquiring the protocol used by the connection information based on the device descriptor;

[0015] A test program acquisition module, used to determine a target test program corresponding to the device descriptor and the protocol in a preset test program library based on the device descriptor and the protocol;

[0016] The test program running module is used to test the USB device based on the target test program to obtain the test result related to the USB device.

[0017] In a third aspect, the present application provides a computer device, the computer device comprising a memory and a processor, the memory storing a computer program, and the processor implementing the steps in the above method when executing the computer program.

[0018] In a fourth aspect, the present application provides a computer-readable storage medium having a computer program stored thereon, which implements the steps in the above method when executed by a processor.

[0019] In a fifth aspect, the present application provides a computer program product, which includes a computer program, and the computer program implements the steps in the above method when executed by a processor.

[0020] The above-mentioned USB device testing method, apparatus, computer equipment, computer-readable storage medium and computer program product obtain connection information sent by a USB device connected to a terminal, determine a device descriptor of the USB device based on the connection information, and then identify the target protocol used by the connection information based on the device descriptor. In this way, a target test program corresponding to the device descriptor and the target protocol can be determined in a preset test program library based on the device descriptor and the target protocol. After that, the USB device can be tested with the test program corresponding to the target protocol communicated by the USB device. Compared with the test personnel manually writing the corresponding test script, it can realize automated testing of USB devices. The terminal can identify and test various types of USB devices, thereby improving the testing efficiency of USB devices. BRIEF DESCRIPTION OF THE DRAWINGS

[0021] Figure 1 An application environment diagram of a USB device testing method provided in an embodiment of the present application;

[0022] Figure 2 A flowchart of a method for testing a USB device provided in an embodiment of the present application;

[0023] Figure 3 A schematic diagram of a process for obtaining a target driver according to an embodiment of the present application;

[0024] Figure 4 A schematic diagram of a process for obtaining a target driver according to another embodiment of the present application;

[0025] Figure 5 A system schematic diagram of a test system provided in an embodiment of the present application;

[0026] Figure 6 A structural block diagram of a USB device testing device provided in an embodiment of the present application;

[0027] Figure 7 An internal structure diagram of a computer device provided in an embodiment of the present application;

[0028] Figure 8 An internal structure diagram of a computer-readable storage medium provided in an embodiment of the present application. DETAILED DESCRIPTION

[0029] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0030] The USB device testing method provided in the embodiment of the present application can be applied to Figure 1 In the application environment shown. Among them, the terminal 102 communicates with the device under test 104 through a physical medium connection. The device under test can be a USB device. The data storage system can store data that the terminal 102 needs to process. For example, the connection information sent by the device under test 104, the preset test program library, etc. are used to implement the program for testing the device under test. The data storage system can be integrated on the terminal 102, and can also be placed on the cloud or other network servers. Among them, the terminal 102 can be, but is not limited to, various personal computers, laptops, smart phones, and tablet computers.

[0031] like Figure 2 As shown, the present application embodiment provides a method for testing a USB device, which is applied to Figure 1 The terminal 102 in the example is used for explanation. It is understandable that the computer device may include at least one of a terminal and a server. The method comprises the following steps:

[0032] S202: Acquire connection information sent by the USB device.

[0033] Among them, the USB device is connected to the terminal through the port of the terminal. USB (Universal Serial Bus) devices are a type of hardware that is connected to a computer or other device through a USB interface. USB devices can be, for example, large-capacity storage devices, human-machine interface devices, communication devices, printers, audio devices, and other devices. Communication devices can also include virtual network card devices, serial port devices, etc. The port is used to access the USB device so that the USB device is connected to the terminal.

[0034] Exemplarily, after the USB device is connected to the terminal through the port of the terminal, the USB device may send connection information to the terminal, wherein the connection information is used to represent the overall information of the USB device, and the overall information may include device information and the communication protocol used by the USB device.

[0035] Optionally, before obtaining the connection information sent by the USB device, the terminal needs to initiate an enumeration process. During the enumeration process, the terminal sends a request message to the connected USB device to trigger the USB device to send the connection information.

[0036] S204: Determine a device descriptor of the USB device based on the connection information.

[0037] The device descriptor is a set of standard information provided by a USB device when it is connected to a terminal. The standard information includes the basic properties and functions of the device, so that the operating system of the subsequent terminal can identify the USB device and obtain a way to communicate with the device.

[0038] Exemplarily, the terminal removes some meaningless information in the connection information to extract the device descriptor from the connection information. The device descriptor is usually represented in the form of a C language structure in the firmware of the USB device. For example, the device descriptor is represented in the following form:

[0039] typedef struct {

[0040] uint8_t bLength; / / Descriptor size (18 bytes)

[0041] uint8_t bDescriptorType; / / Descriptor type (device descriptor is 0x01)

[0042] uint16_t bcdUSB; / / USB specification version number (BCD format)

[0043] uint8_t bDeviceClass; / / Device class

[0044] uint8_t bDeviceSubClass; / / Device subclass

[0045] uint8_t bDeviceProtocol; / / Device protocol

[0046] uint8_t bMaxPacketSize0; / / Maximum packet size of endpoint 0

[0047] uint16_t idVendor; / / Vendor ID (VID)

[0048] uint16_t idProduct; / / Product ID (PID)

[0049] uint16_t bcdDevice; / / Device release number (BCD format)

[0050] uint8_t iManufacturer; / / Manufacturer string index

[0051] uint8_t iProduct; / / Product string index

[0052] uint8_t iSerialNumber; / / Serial number string index

[0053] uint8_t bNumConfigurations; / / Configuration quantity

[0054] }USB_Device_Descriptor;

[0055] S206, identifying the target protocol used by the connection information based on the device descriptor.

[0056] The device descriptor includes device class information, device subclass information, and device protocol code. The device class information defines the USB class code of the device. For example, 0x00 indicates that the device belongs to the class defined by the interface descriptor in the device descriptor, while 0x09 indicates the Hub class. The device subclass information defines the USB subclass code of the device. The specific meaning of this field depends on the value of the device class information. For example, if the device class information is 0x02, it means that the device belongs to the Communication Device Class (CDC). The device subclass information is used to determine which type of communication device class the device belongs to. For example, if the device subclass information is 0x00, it may indicate a subclass for a virtual COM port. If the device subclass information is 0x01, it means that the device is an Ethernet network control model subclass in the communication device, which is usually used to provide network connections. The device protocol code defines the USB protocol code of the device. Referring to the above example, the device protocol code can be represented by the bDeviceProtocol field. The interpretation of this field also depends on the device class information and the device subclass information. For example, for a USB device, its device class information is 0x02, indicating that the USB device belongs to the communication device class. The device subclass information is 0x00, indicating that the device belongs to the abstract control model. The interpretation of the device protocol code matches the abstract control model. If the device protocol code is 0x01, it means that the USB device uses the AT command set (Attention command set) to communicate. In this way, it can be inferred that the USB device may be a USB modem, which is controlled by sending and receiving AT commands.

[0057] Based on the device descriptor, the protocol type used by the USB device can be determined. Then, the target protocol can be determined based on other information. The target protocol includes the protocol type and detailed information of the protocol. Other information can be, for example, a pre-stored protocol library or an interface descriptor.

[0058] Optionally, if the target protocol used by the connection information cannot be identified based on the device descriptor, a prompt is displayed on the terminal through the browser to add the target protocol identification reference information corresponding to the device descriptor; the target protocol identification reference information is obtained based on the prompt, and the target protocol used by the connection information is identified based on the target protocol identification reference information and the device descriptor. If the terminal can identify the target protocol used by the USB device, it means that the driver corresponding to the USB device is stored in the terminal.

[0059] S208, based on the device descriptor and the target protocol, determining a target test program corresponding to the device descriptor and the target protocol in a preset test program library.

[0060] Among them, a variety of test programs are stored in the preset test program library, and these test programs can be used to test USB devices. The test program can correspond to a program description. The program description is used to indicate the protocol and device type that the test program can test. Therefore, after obtaining the device descriptor and the target protocol, the terminal can determine the corresponding target test program in the preset test program library. The target test program can be, for example, a test script.

[0061] S210, testing the USB device based on the target test program to obtain test results related to the USB device.

[0062] Exemplarily, after the terminal obtains the corresponding target test program, the USB device is tested based on the target test program. For example, when the USB code reader is identified as CDC communication based on the device descriptor and the target protocol, the baud rate, parity, data bit, end bit and other functions of the serial communication will be tested. When the USB device is identified as a virtual network card based on the device descriptor and the target protocol, the network card IP and the code reader IP will be tested for ping test and bandwidth test and data transmission, etc. When the USB device is identified as a USB flash drive based on the device descriptor and the target protocol, the target test program is used to test the transmission speed and other functions of the USB device.

[0063] It can be seen that in the embodiment of the present application, by obtaining the connection information sent by the USB device connected to the terminal, the device descriptor of the USB device is determined based on the connection information, and then the target protocol used by the connection information can be identified based on the device descriptor. In this way, the target test program corresponding to the device descriptor and the target protocol can be determined in the preset test program library based on the device descriptor and the target protocol, and then the USB device can be tested for the test program corresponding to the target protocol communicated by the USB device. Compared with the test personnel manually writing the corresponding test script, the automatic test of the USB device can be realized, and the terminal can identify and test various types of USB devices, thereby improving the test efficiency of the USB device. In addition, for devices that support multiple protocols, the protocols used by them can also be specifically analyzed to test the device.

[0064] When the terminal tests the USB device, it needs to communicate and interact with the USB device. Then the USB device is tested based on the information sent and received during the interaction. In some embodiments, Figure 3 As shown, in order to realize the interaction between the terminal and the USB device, some drivers can be pre-stored in the terminal. Therefore, a preset driver library is stored in the terminal. In the preset driver library, drivers corresponding to different types of devices are stored, such as general programs and some device-specific drivers. In this way, the USB device can be tested based on the target test program. For details, please refer to the following steps:

[0065] S302: If a target driver corresponding to the device descriptor exists in the preset driver library, the target driver is obtained.

[0066] The preset driver library may store general drivers and special drivers. The special drivers may be used to communicate with some special types of USB devices, for example.

[0067] Exemplarily, the terminal can determine the target driver corresponding to the device descriptor from the preset driver library based on the device descriptor. The terminal can obtain the PID (product identifier) ​​and VID (vendor identifier) ​​in the device descriptor, and then match the driver list in the preset driver library according to the above two identifiers. If there is a matching driver in the list, then the driver will be loaded. If there is no matching driver, you can try to load a universal driver. Universal drivers include universal drivers for various protocols. For example, HID (Human Interface Device) protocol universal driver, USB Mass Storage protocol universal driver, USB Audio protocol universal driver, USB Printer protocol universal driver, USB Video protocol universal driver, USB Communication Device Class (CDC) protocol universal driver, USB Smart Card protocol universal driver, USB Diagnostic Device Class protocol universal driver. The universal driver can adapt all USB devices according to the device descriptor returned by the device. Therefore, if the server does not find a dedicated driver adapted to the USB device from the preset driver library, it can also obtain a universal driver that conforms to the target protocol.

[0068] S304, running the target test program based on the target protocol and the target driver to obtain the test result of the USB device.

[0069] The target protocol includes the communication rules that the terminal needs to follow when interacting with the USB device, that is, the detailed information of the aforementioned protocol. Exemplarily, after the terminal determines the target protocol of the USB device, it can obtain the protocol detailed information corresponding to the target protocol, and then run the corresponding target test program based on the protocol detailed information and the target driver, so as to obtain the corresponding test result after executing the target test program on the USB device.

[0070] It can be seen that in this embodiment, the terminal determines the target driver corresponding to the device descriptor from the preset driver library, obtains the protocol details corresponding to the target protocol, and runs the target test program based on the protocol details and the target driver to obtain the test results of the USB device, thereby realizing communication between the terminal and the USB device, and further realizing automatic testing of multiple devices.

[0071] In another embodiment, if Figure 4 As shown, the preset driver library may not have pre-stored the dedicated driver corresponding to the USB device to be tested, and the current preset driver library does not have a dedicated driver that can match the USB device. To improve the test quality, you can download the corresponding dedicated driver and then test the USB device based on the dedicated driver. The details are as follows:

[0072] S402: If the target driver corresponding to the device descriptor does not exist in the preset driver library, a dedicated driver is downloaded based on the device descriptor, and the dedicated driver is added to the preset driver library.

[0073] Among them, the dedicated driver can be downloaded by the terminal from the Internet based on the device descriptor. For example, after the terminal extracts the PID and VID, it searches for the corresponding dedicated driver on the Internet. There can be multiple downloaded dedicated drivers. The terminal can try to pair the downloaded multiple dedicated drivers with the USB device. If they match, the matched dedicated driver is added to the preset driver library. Compared with the general driver, the dedicated driver is more compatible with the USB device, which can improve the test accuracy of the USB device.

[0074] S404, running the target test program based on the target protocol and the dedicated driver to obtain the test result of the USB device.

[0075] It can be seen that in this embodiment, the terminal can also download a dedicated driver based on the device descriptor, and then run the target test program based on the downloaded dedicated driver and the target protocol to obtain the test results of the USB device, thereby improving the matching degree between the driver and the USB device, and then improving the accuracy and correctness of the test results.

[0076] In other embodiments, in order to obtain a driver that is not stored in a preset driver library or a protocol that is not pre-stored in the terminal, a test system with a USB device can be deployed on the terminal. The test system includes an interactive module, which communicates with a browser to obtain target protocol identification reference information. In this way, the tester can upload the target protocol identification reference information through the browser and the interactive module to solve the problem of being unable to identify the connected USB device. Specifically, if the terminal fails to identify the target protocol used by the connection information based on the device descriptor, a prompt for adding the target protocol identification reference information corresponding to the device descriptor is displayed on the terminal through the browser; then the target protocol identification reference information is obtained based on the prompt, and the target protocol used by the connection information is identified based on the target protocol identification reference information and the device descriptor. Among them, the target protocol reference information can be protocol-related information or corresponding driver-related information. The target protocol identification reference information is used to identify the target protocol used by the connection information. The prompt can, for example, prompt the tester to upload the protocol required to be tested for the connected USB device and the information of the driver corresponding to the USB device. For example, the tester can upload the driver corresponding to the USB device to the test system through the browser. In this way, the terminal can identify the connected USB device and test the USB device. The acquired target protocol identification reference information can be stored in the terminal, so that the terminal can successfully identify the USB device of this type when encountering the USB device of this type again in the future.

[0077] It can be seen that in this embodiment, a prompt for adding the target protocol identification reference information corresponding to the device descriptor is displayed on the terminal through the browser, and then the target protocol identification reference information is obtained based on the prompt. After that, the target protocol used for the connection information can be identified based on the target protocol identification reference information and the device descriptor. In this way, the protocols and USB devices that can be tested can be expanded to achieve self-iteration.

[0078] After the corresponding device descriptor and target protocol are identified through the connection information sent by the USB, and the corresponding test program is obtained, the target test program can be run to obtain the test result of the USB device. In some embodiments, the target test program may include multiple test cases. Each test case corresponds to a test information. The test information may be a test of a certain function of the USB device. For example, for a serial port device, the test information may be a transmission baud rate for testing the serial port device. Each test case may correspond to a different transmission baud rate. When a test case runs successfully, the value corresponding to the transmission baud rate in the test case is determined as the specific value of the transmission baud rate of the tested serial port device. That is to say, in the process of running the target test program to obtain the test result of the USB device, the terminal will run multiple test cases in the target test program, and then obtain the running result of each test case. If the running result of the test case is successful, the test result of the corresponding USB device is determined based on the device information in the test case with a successful running result.

[0079] For example, when a USB device is identified as a serial port, the terminal obtains a test program related to the serial port to perform related tests on the serial port. When the terminal interacts with the USB device, the normal data transmitted by the USB device can be received only when the baud rates of the two are set to be consistent. Therefore, when the USB device is identified as a serial port, the terminal executes different test cases in the test program to try to receive data sent by the USB device at different baud rates. When the data is received, the current transmission baud rate used by the USB device can be confirmed (for example, when the transmission baud rate of the USB device is 9600 baud, the system cannot perceive the transmission baud rate used by the device. The terminal patrols the test cases corresponding to 1200 baud, 2400 baud, 4800 baud, 9600 baud, and 115200 baud to receive data. When the data is received, the baud rate used by the USB device can be confirmed).

[0080] It can be seen that in this embodiment, by obtaining a corresponding test program and running multiple test cases in the test program, the test results of the USB device can be obtained. In this way, the automated test of the USB device can be realized, and the USB device can be tested in batches without manual execution. Moreover, the test cases in the test program stored in the terminal can be customized and deleted, thereby improving the flexibility of the test.

[0081] As mentioned above, the terminal can identify the target protocol used by the connection information based on the device descriptor. In some embodiments, the device descriptor may include the device class information of the USB device and the protocol code corresponding to the connection information. The terminal can analyze the device class information and the protocol code, so as to identify the protocol list corresponding to the device class information from the preset protocol library. Since some devices can send connection information of multiple protocols, the protocol list may include information of multiple protocols. And because the connection information sent by the USB device is based on a certain protocol. Therefore, in order to determine the target protocol used by the USB device, the device descriptor can be parsed to obtain the protocol code. Then the target protocol is identified from the protocol list based on the protocol code. The preset protocol library can be used to store information of multiple protocols in advance in the terminal, and the information may include protocols corresponding to different devices and detailed information corresponding to each protocol. Then, the subsequent terminal can test the device based on the target protocol after obtaining the target protocol. That is, the step of identifying the target protocol used by the connection information based on the device descriptor includes: parsing the device descriptor to obtain the device class information and the protocol code of the USB device; obtaining the protocol list corresponding to the device class information from the preset protocol library based on the device class information; and identifying the target protocol from the protocol list based on the protocol code.

[0082] It can be seen that in this embodiment, by analyzing the connection information, the protocol used by the connected USB device can be identified, and then the USB device can be tested based on the protocol. A variety of communication protocols are pre-stored in the terminal, which is convenient for the terminal to automatically identify the USB device and test it. And the preset protocol library is changeable. When the terminal cannot identify the USB device, the protocol used by the USB device can be identified based on the input of the tester or by downloading the corresponding driver by itself. And the identifiable protocol is added to the preset protocol library. In this way, multiple USB devices can be tested and the test scope can be expanded.

[0083] Before the USB device sends connection information to the terminal, the terminal may first send request information to the USB device. In some embodiments, the terminal may monitor the voltage signal of the port of the terminal. The port is used to physically connect the USB device and the terminal. When the voltage information changes, the terminal may send a request message to the USB device connected to the port to trigger the USB device to send the connection information to the terminal. It can be seen that in this embodiment, by monitoring the voltage signal of the terminal port, the connected USB device can be discovered in time, thereby improving the testing efficiency of the USB device.

[0084] In an exemplary embodiment, in order to improve the testing efficiency of USB devices, the terminal can be connected to multiple USB devices through physical media for communication. Figure 5As shown, the terminal can be deployed with a test system. For example, the USB device will be connected to the test system by means of a USB cable. The test system may include a driver module, an interaction module, a data identification module and a test module. The driver module can obtain a driver that matches the currently connected USB device from a preset driver library, and run the driver to realize the interaction between the USB device and the terminal. The interaction module can be connected to the display module of the terminal, and the display module can be, for example, a display. The tester can communicate with the interaction module through a browser displayed on the display. The data identification module can identify the protocol for communication between the USB device and the terminal. The test module is used to read the test program in the preset test program library to test the USB device.

[0085] When the terminal is running, the terminal monitors the voltage signal of the port. When the tester connects the USB device to be tested to the terminal through a physical medium, for example, when the USB device is inserted into the port of the terminal, the voltage signal of the port will change. When the terminal monitors the voltage change of the port, the terminal sends a request message to the USB device connected to the port. After receiving the request message, the USB device processes the request message and sends the connection information to the terminal. Among them, the connection information carries a device identifier, and the device identifier includes device class information and a protocol code.

[0086] After receiving the connection information, the terminal determines the device descriptor of the USB device based on the connection information. Then, based on the device descriptor, the target driver corresponding to the device descriptor is identified from the preset driver library. In addition, the device descriptor is parsed to obtain the device class information and protocol code of the USB device; based on the device class information, the protocol list corresponding to the device class information is obtained from the preset protocol library; based on the protocol code, the target protocol is identified from the protocol list. After that, the target test program can be run based on the target protocol and the driver to obtain the test result of the USB device. For example, after receiving the connection request, the patrol data identification module will be determined according to the content of the request to determine whether the request is a normal request, and the corresponding test protocol will be found after the determination is passed. The corresponding driver is assigned to the USB device, and the protocol is tested autonomously and then the test result is output. Optionally, when running the target test program, the following steps may be included: running multiple test cases of the target test program to obtain the running result of each test case; if the running result of the test case is successful, the test result of the USB device is determined based on the device information in the test case with the successful running result.

[0087] When the terminal cannot identify the target driver corresponding to the device descriptor from the preset driver library, the terminal can download a dedicated driver based on the device descriptor and add the dedicated driver to the preset driver library. Then, similarly, based on the target protocol dedicated driver, run the target test program to obtain the test result of the USB device.

[0088] Optionally, the terminal can also display a prompt for adding the target protocol identification reference information corresponding to the device descriptor on the terminal through the browser; obtain the target protocol identification reference information based on the prompt, and identify the target protocol used by the device descriptor identification connection information based on the target protocol identification reference information. For example, when the USB device is connected to the test system and the system cannot recognize the device, the tester can upload or select the corresponding target test protocol and target driver through the prompt on the browser. That is, the browser can send the test system what protocol the current device needs to test and which driver to use for testing to the test system. The tester can load the USB device-specific driver into the system through the browser and the interactive module, and the data identification module will also iterate itself according to the newly loaded driver.

[0089] In addition, the test system will record and transmit the test results to the browser in real time during the real-time test, so that the tester can follow up the test process.

[0090] Through the above steps, the automated test of USB devices can be realized, and because multiple protocol libraries or driver libraries are pre-stored, multiple devices can be identified and tested, thereby increasing the types of test devices. In addition, when there is no matching protocol or driver in the protocol library or driver library, this embodiment also provides a corresponding solution, thereby improving the robustness of the test system.

[0091] It should be understood that, although the steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the indications of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear description in this article, there is no strict order restriction on the execution of these steps, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-mentioned embodiments may include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.

[0092] Based on the same inventive concept, the embodiment of the present application also provides a test device for a USB device. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above method, so the specific definition of the test device embodiment of one or more USB devices provided below can refer to the definition of the test method for USB devices above, and will not be repeated here.

[0093] like Figure 6 As shown, the embodiment of the present application provides a testing device 600, including:

[0094] The connection information acquisition module 602 is used to acquire the connection information sent by the USB device, and the USB device is connected to the terminal through the port of the terminal;

[0095] A determination module 604 is used to determine a device descriptor of the USB device based on the connection information;

[0096] A protocol identification module 606, for identifying a target protocol used by the connection information based on the device descriptor;

[0097] A test program acquisition module 608 is used to determine a target test program corresponding to the device descriptor and the target protocol in a preset test program library based on the device descriptor and the target protocol;

[0098] The test program running module 610 is used to test the USB device based on the target test program to obtain the test results related to the USB device.

[0099] In some embodiments, the test program running module 610 is specifically used to: determine the target driver corresponding to the device descriptor from a preset driver library; and run the target test program based on the target protocol and the target driver to obtain the test result of the USB device.

[0100] In some embodiments, the test program running module 610 is specifically used to: download a dedicated driver based on the device descriptor and add the dedicated driver to a preset driver library; run a target test program based on a target protocol dedicated driver to obtain a test result of the USB device.

[0101] In some embodiments, the test program running module 610 is specifically used to: run multiple test cases of the target test program to obtain the running result of each test case; if the running result of the test case is successful, determine the test result of the USB device based on the device information in the test case with a successful running result.

[0102] In some embodiments, the protocol identification module 606 is specifically used to: parse the device descriptor to obtain the device class information and protocol code of the USB device; based on the device class information, obtain the protocol list corresponding to the device class information from the preset protocol library; and identify the target protocol from the protocol list based on the protocol code.

[0103] In some embodiments, the protocol identification module 606 is also used for: if the target protocol used for the connection information cannot be identified based on the device descriptor, a prompt is displayed on the terminal through the browser to add the target protocol identification reference information corresponding to the device descriptor; based on the prompt, the target protocol identification reference information is obtained, and the target protocol used for the connection information is identified based on the target protocol identification reference information and the device descriptor.

[0104] In some embodiments, the testing device further includes a monitoring module, which is used to monitor the voltage signal of the port; when the voltage signal changes, a request message is sent to a USB device connected to the port, and the request message is used to enable the USB device to send connection information.

[0105] Each module in the above-mentioned USB device test device can be implemented in whole or in part by software, hardware or a combination thereof. Each of the above-mentioned modules can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute operations corresponding to each of the above modules.

[0106] In some embodiments, a computer device is provided. The computer device may be a terminal, and its internal structure diagram may be as follows: Figure 7As shown. The computer device includes a processor, a memory, an input / output interface, a communication interface, a display unit and an input device. Among them, the processor, the memory and the input / output interface are connected through a system bus, and the communication interface, the display unit and the input device are connected to the system bus through the input / output interface. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The input / output interface of the computer device is used to exchange information between the processor and the external device. The communication interface of the computer device is used to communicate with an external terminal in a wired or wireless manner, and the wireless manner can be implemented through WIFI, a mobile cellular network, NFC (near field communication) or other technologies. When the computer program is executed by the processor, the steps in the above-mentioned USB device testing method are implemented. The display unit of the computer device is used to form a visually visible picture, which can be a display screen, a projection device or a virtual reality imaging device. The display screen can be a liquid crystal display screen or an electronic ink display screen; the input device of the computer device can be a touch layer covering the display screen, or a button, trackball or touchpad set on the computer device shell, or an external keyboard, touchpad or mouse.

[0107] Those skilled in the art will understand that Figure 7 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.

[0108] In some embodiments, a computer device is provided. The computer device includes a memory and a processor. The memory stores a computer program. When the processor executes the computer program, the steps in the above method embodiments are implemented.

[0109] In some embodiments, Figure 8 The figure shows an internal structure diagram of a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments are implemented.

[0110] In some embodiments, a computer program product is provided. The computer program product includes a computer program. When the computer program is executed by a processor, the steps in the above method embodiments are implemented.

[0111] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant laws, regulations and standards of relevant countries and regions.

[0112] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but are not limited to this.

[0113] The technical features of the above embodiments may be arbitrarily combined. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0114] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be construed as limiting the scope of the present application. It should be noted that, for a person of ordinary skill in the art, several modifications and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.

Claims

1. A method for testing a USB device, applied to a terminal, characterized in that: include: Acquire connection information sent by a USB device, wherein the USB device is connected to the terminal through a port of the terminal; Determine a device descriptor of the USB device based on the connection information; identifying a target protocol used by the connection information based on the device descriptor; Based on the device descriptor and the target protocol, determining a target test program corresponding to the device descriptor and the target protocol in a preset test program library; The USB device is tested based on the target test program to obtain a test result related to the USB device.

2. The method according to claim 1, characterized in that The testing of the USB device based on the target test program to obtain a test result related to the USB device includes: If a target driver corresponding to the device descriptor exists in the preset driver library, obtaining the target driver; Based on the target protocol and the target driver, the target test program is run to obtain the test result of the USB device.

3. The method according to claim 2, characterized in that The testing of the USB device based on the target test program to obtain a test result related to the USB device includes: If the target driver corresponding to the device descriptor does not exist in the preset driver library, based on the device descriptor, obtaining a dedicated driver corresponding to the device descriptor, and adding the dedicated driver to the preset driver library; Based on the target protocol and the dedicated driver, the target test program is run to obtain the test result of the USB device.

4. The method according to claim 2 or 3, characterized in that: The target test program includes a plurality of test cases, and the test cases include device information. The step of running the target test program to obtain a test result of the USB device includes: Running the plurality of test cases of the target test program to obtain a running result of each test case; If the running result of the test case is successful, the test result of the USB device is determined based on the device information in the test case with the successful running result.

5. The method according to claim 1, characterized in that: The identifying a target protocol used by the connection information based on the device descriptor comprises: Parsing the device descriptor to obtain device class information and protocol code of the USB device; Based on the device class information, obtaining a protocol list corresponding to the device class information from a preset protocol library; The target protocol is identified from the protocol list based on the protocol code.

6. The testing method according to claim 1, characterized in that: Before obtaining the connection information sent by the USB device, the method includes: monitoring a voltage signal of the port; When the voltage signal changes, a request message is sent to the USB device connected to the port, wherein the request message is used to enable the USB device to send the connection information.

7. The testing method according to claim 1, characterized in that: The method further comprises: If the target protocol used by the connection information cannot be identified based on the device descriptor, displaying a prompt to add target protocol identification reference information corresponding to the device descriptor on the terminal through a browser; The target protocol identification reference information is acquired based on the prompt, and a target protocol used by the connection information is identified based on the target protocol identification reference information and the device descriptor.

8. A testing device for a USB device, characterized in that: include: A connection information acquisition module, used to acquire connection information sent by a USB device, wherein the USB device is connected to the terminal through a port of the terminal; A determination module, configured to determine a device descriptor of the USB device based on the connection information; A protocol identification module, used to identify a target protocol used by the connection information based on the device descriptor; A test program acquisition module, used to determine a target test program corresponding to the device descriptor and the target protocol in a preset test program library based on the device descriptor and the target protocol; The test program running module is used to test the USB device based on the target test program to obtain the test result related to the USB device.

9. A computer device, comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.