Code coverage rate data exporting method and device, equipment and medium
By establishing a one-way linked list in NVMe devices and using preset instrumented code counts, the problem of code coverage data export in a file system environment is solved, and high-performance, wide-applicability and low-cost data export is achieved, avoiding the Reliance on hardware devices.
Patent Information
- Application Number
- CN202411336815.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-24
- Publication Date
- 2024-12-17
AI Technical Summary
In a file system environment, NVMe devices have difficulty effectively exporting code coverage data. The existing solutions rely on physical interfaces or expensive hardware devices, and lack a general and cost-effective solution.
By establishing a one-way linked list in NVMe device to store code coverage data, and using preset instrumentation code for counting, the data is written into the memory buffer according to the data export command of the target host, and the target host generates a coverage data file, avoiding Reliance on file systems and dedicated hardware.
It realizes high-performance, wide-appropriate code coverage data export without file system support, reduces development costs, avoids dependence on additional hardware interfaces or dedicated hardware devices, and has strong versatility.
Smart Images

Figure CN119149429A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of software testing technology, and in particular to a method, device, equipment and medium for exporting code coverage data. Background Art
[0002] As NVMe (Non Volatile Memory Host Controller Interface Specification) technology continues to mature and become more popular, various NVMe storage devices are emerging rapidly, driving a significant improvement in the overall performance of storage systems. NVMe devices must have high reliability and stability and be able to operate stably for a long time, which requires high-quality software testing as a guarantee. During the test execution, which parts of the code are executed and which parts are not executed, and then the test coverage is evaluated. This evaluation indicator is the code coverage rate.
[0003] Traditional code coverage analysis methods usually rely on inserting special probes into the source code, collecting coverage data while the program is running, and outputting it to a specific file system for analysis tools to process. However, in some embedded system environments, especially those based on NVMe storage devices, due to the lack of file system support, coverage data files cannot be directly generated and saved, which brings challenges to code coverage analysis. For the code coverage analysis problem in a file system-free environment, some existing technical solutions include: (1) Export through physical interface, add a custom coverage tracking mechanism in the firmware code, store the data in memory, and then read it out for analysis through physical interfaces such as serial port, network port, I2C (Inter-Integrated Circuit), etc.; (2) Use hardware debugger, with the help of hardware debugging interfaces such as JTAG (Joint Test Action Group), you can connect to NVMe devices and obtain tracking information during code execution, so as to collect coverage data, but this requires the corresponding hardware debugging equipment; (3) Use simulator or simulation environment. If there is a software simulator or simulation environment for NVMe devices, you can run tests in this environment and use tools such as gcov to collect coverage data; (4) Use commercial tools. Some professional embedded software testing tools may provide code coverage analysis functions suitable for bare metal environments, but this usually requires the purchase of corresponding commercial licenses.
[0004] In summary, existing technical solutions either rely on physical interfaces or require the purchase of expensive dedicated hardware devices or licenses. For NVMe devices that lack physical interfaces such as serial ports and network ports, how to provide a high-performance and more adaptable code coverage data export solution while reducing costs and without the need for file system support is a problem that needs to be solved. Summary of the invention
[0005] In view of this, the purpose of the present invention is to provide a method, device, equipment and medium for exporting code coverage data, which can provide a high-performance and more adaptable code coverage data export solution while reducing costs and without the need for file system support. The specific solution is as follows:
[0006] In a first aspect, the present application discloses a method for exporting code coverage data, which is applied to NVMe devices, including:
[0007] When obtaining a data export command sent by the target host, parsing the data export command to obtain address information and buffer size of a memory buffer previously applied for in the target host;
[0008] Based on the address information and the buffer size, the pre-collected code coverage data is transmitted and written to the memory buffer; the code coverage data is the data obtained by the NVMe device after counting the executed code segments using the preset plug-in code after establishing a one-way linked list for the target data structure for storing code coverage information in each source file and added to the one-way linked list;
[0009] After the code coverage data in the one-way linked list is written, a target command for indicating that the write operation is completed is sent to the target host, so that the target host generates a coverage data file for the acquired code coverage data using a local file system.
[0010] Optionally, the method for exporting code coverage data further includes:
[0011] Polling a preset submission queue to obtain a current latest command entry sent by a target host stored in the preset submission queue, and determining a corresponding command type based on a target field in the current latest command entry;
[0012] If the command type is a data export command sent by the target host based on the extended NVMe protocol, the step of parsing the data export command to obtain the address information and buffer size of the pre-applied memory buffer in the target host is executed.
[0013] Optionally, the one-way linked list includes a head node for storing a preset head node identifier and a version number, and the remaining nodes of the target data structure for storing different source files respectively; wherein the target data structure includes a first field for storing the actual total length of the target data structure, a second field for storing the source file name, a third field for storing the code coverage data and a fourth field for storing a termination string.
[0014] Optionally, transmitting and writing the pre-collected code coverage data to the memory buffer based on the address information and the buffer size includes:
[0015] Based on the address information, the data information stored in the head node is transmitted and written into the memory buffer, and the one-way linked list is traversed to sequentially transmit and write the data information stored in the target data structure in the remaining nodes into the memory buffer;
[0016] Count the total number of bytes of data currently written into the memory buffer;
[0017] If the total number of bytes of the data is not less than the size of the buffer, and there are still target data structures in the one-way linked list that have not been written to the memory buffer, then stop writing the current data, send a preset instruction to the target host so that the target host can send a data export command again, and then transfer and write the data information stored in the remaining target data structures in the one-way linked list to the memory buffer until all the data information in the one-way linked list is transferred and written to the memory buffer; wherein, after obtaining the preset instruction, the target host migrates the data currently in the memory buffer to the target cache for storage;
[0018] If the total number of bytes of the data is less than the size of the buffer, and there are still target data structures in the one-way linked list that have not been written into the memory buffer, then continue to perform the step of traversing the one-way linked list until all data information in the target data structures are transmitted and written into the memory buffer;
[0019] If the total number of bytes of the data is less than the size of the buffer, and the data information in all target data structures in the one-way linked list has been transmitted and written into the memory buffer, it is determined that the data writing operation has been completed.
[0020] Optionally, transmitting and writing the pre-collected code coverage data to the memory buffer based on the address information and the buffer size includes:
[0021] Determine the total amount of data stored in the one-way linked list, and determine whether the total amount of data is less than the buffer size;
[0022] If the total data size is smaller than the buffer size, the data information stored in the head node and the data information stored in the target data structure in the remaining nodes are sequentially transmitted and written to the memory buffer based on the address information;
[0023] If the total data size is not less than the buffer size, the total data size will be sent to the target host so that the target host can reapply for a new memory buffer based on the total data size, and then transfer and write the data information stored in the head node and the data information stored in the target data structure in the remaining nodes to the new memory buffer in turn.
[0024] Optionally, before sending a target command for indicating that the write operation is completed to the target host, the method further includes:
[0025] Counting the actual length of data written into the memory buffer;
[0026] Determine the execution status of the data export command executed this time; the execution status includes a first status for indicating a successful execution and a second status for indicating a failed execution;
[0027] A target command for indicating the completion of the write operation is created based on the actual write length and the execution status, and the target command is submitted as a command entry to a preset completion queue so that the target host obtains the target command from the preset completion queue.
[0028] Optionally, the target host obtains the target command from the preset completion queue, including:
[0029] When the target host polls the preset completion queue, if it monitors that there is a new command entry in the preset completion queue, the target host obtains the target command from the preset completion queue;
[0030] Correspondingly, the target host generates a coverage data file for the acquired code coverage data using a local file system, including:
[0031] The target host parses the target command to obtain the actual write length and the execution status. If the execution status is the first status, code coverage data of corresponding length is obtained from the memory buffer based on the actual write length, and a coverage data file is generated for the code coverage data using a local file system in accordance with a predefined data format.
[0032] In a second aspect, the present application discloses a device for exporting code coverage data, which is applied to an NVMe device, including:
[0033] A command parsing module, used for parsing the data export command sent by the target host to obtain the address information and buffer size of the memory buffer pre-applied in the target host when obtaining the data export command sent by the target host;
[0034] A data transmission module, used for transmitting the pre-collected code coverage data and writing it to the memory buffer based on the address information and the buffer size; the code coverage data is the data obtained by counting the executed code segments using the preset plug-in code after the NVMe device establishes a one-way linked list for the target data structure for storing code coverage information in each source file and is added to the one-way linked list;
[0035] The file generation module is used to send a target command for indicating the completion of the write operation to the target host after the code coverage data in the one-way linked list is written, so that the target host can use the local file system to generate a coverage data file for the acquired code coverage data.
[0036] In a third aspect, the present application discloses an electronic device, comprising:
[0037] Memory, used to store computer programs;
[0038] A processor is used to execute the computer program to implement the steps of the aforementioned disclosed method for deriving code coverage data.
[0039] In a fourth aspect, the present application discloses a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, the steps of the aforementioned disclosed method for exporting code coverage data are implemented.
[0040] It can be seen that in this application, when the NVMe device obtains the data export command sent by the target host, it parses the data export command to obtain the address information and buffer size of the memory buffer pre-applied in the target host; based on the address information and the buffer size, the pre-collected code coverage data is transmitted and written to the memory buffer; the code coverage data is obtained by the NVMe device after establishing a one-way linked list for the target data structure used to store code coverage information in each source file, and counting the executed code segments using the preset plug-in code and adding it to the one-way linked list; after the code coverage data in the one-way linked list is written, a target command for characterizing the completion of the write operation is sent to the target host, so that the target host uses the local file system to generate a coverage data file for the acquired code coverage data.
[0041] Beneficial effect: The NVMe device in this application has already collected the code coverage data and stored it in a one-way linked list. Specifically, the NVMe device will establish a one-way linked list for the target data structure used to store code coverage information in each source file, and then use the preset plug-in code to count the executed code segments to obtain the code coverage data, and store it in the one-way linked list. When it is necessary to export the code coverage data, the target host will apply for a memory buffer in advance and send a data export command to the NVMe device. The data export command includes the address information and buffer size of the memory buffer. Then the NVMe device will transmit and write the collected code coverage data to the memory buffer based on the address information and buffer size. After the code coverage data in the one-way linked list is written, the NVMe device will also send a target command to the target host to characterize the completion of the write operation, so that the target host can use the local file system to generate a coverage data file for the acquired code coverage data. The above solution generates a coverage data file on the target host side, which solves the problem that the NVMe device cannot generate a coverage data file without a file system. It also avoids the shortcomings of existing solutions that rely on additional hardware interfaces or require dedicated hardware devices. This solution has strong versatility and reduces development costs. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.
[0043] Figure 1 A flow chart of a method for exporting code coverage data disclosed in this application;
[0044] Figure 2 A schematic diagram of the structure of a submission queue entry disclosed in this application;
[0045] Figure 3 This is a schematic diagram of an expansion of an Opcode disclosed in this application;
[0046] Figure 4 This is an extended schematic diagram of a CDW10 field disclosed in this application;
[0047] Figure 5 A system architecture diagram between a target host and an NVMe device disclosed in this application;
[0048] Figure 6 A schematic diagram of starting a program disclosed in this application;
[0049] Figure 7 A schematic diagram of constructing a one-way linked list disclosed in this application;
[0050] Figure 8 A schematic diagram of a pile counting method disclosed in this application;
[0051] Fig. 9 A schematic diagram of the structure of a one-way linked list disclosed in this application;
[0052] Fig.10 A flow chart of a method for transmitting code coverage data disclosed in this application;
[0053] Fig.11 A flow chart of another method for transmitting code coverage data disclosed in this application;
[0054] Fig.12 A schematic diagram of the structure of a device for exporting code coverage data disclosed in this application;
[0055] Fig.13 This is a structural diagram of an electronic device disclosed in this application. DETAILED DESCRIPTION
[0056] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.
[0057] In order to solve the problem of code coverage analysis in a file system-free environment, technical solutions either rely on physical interfaces or require the purchase of expensive dedicated hardware devices or licenses. To this end, the embodiments of the present application provide a method, device, equipment and medium for exporting code coverage data. For NVMe devices that lack physical interfaces such as serial ports and network ports, a high-performance and more adaptable code coverage data export solution can be provided without file system support while reducing costs.
[0058] See also Figure 1 As shown, an embodiment of the present application discloses a method for exporting code coverage data, which is applied to NVMe devices. The method includes:
[0059] Step S11: when obtaining a data export command sent by the target host, parsing the data export command to obtain address information and buffer size of a memory buffer previously applied for in the target host.
[0060] In this embodiment, when it is necessary to export code coverage data, the target host will apply for a memory buffer in advance and send a data export command to the NVMe device, and the data export command includes the address information and buffer size of the memory buffer. Therefore, when the NVMe device obtains the data export command sent by the target host, it parses the data export command to obtain the address information and buffer size of the memory buffer.
[0061] In a specific implementation, the above method also includes: polling a preset submission queue to obtain the current latest command entry sent by the target host stored in the preset submission queue, and determining the corresponding command type based on the target field in the current latest command entry; if the command type is a data export command sent by the target host based on the extended NVMe protocol, then executing the step of parsing the data export command to obtain the address information and buffer size of the pre-applied memory buffer in the target host.
[0062] First of all, it should be pointed out that the NVMe protocol defines two types of commands, one is the Admin command and the other is the IO command. Admin commands are mainly used to configure storage devices, and IO commands are mainly used to read and write data in the Flash medium in storage devices. At the same time, two types of queues are also defined, namely the Admin queue and the IO queue. Admin commands can only be submitted to the Admin queue, and IO commands can only be submitted to the IO queue. Among them, the queue is divided into a submission queue (Submission Queue, SQ) and a completion queue (Completion Queue, CQ). The Admin queue has only one set of SQ / CQ, and the IO queue can have multiple sets of SQ / CQ. The submission queue and completion queue in the Admin queue are mainly used in the embodiments of this application. Specifically, the target host submits the export command to the Admin SQ, and the NVMe device responds in the Admin CQ after completing the command. It should also be pointed out that the Submission Queue Entry (SQE) is a command entry stored in the queue, which contains the parameters required for the command, such as the command type, etc. When the host wants to submit a command to the NVMe device, it puts an SQE into the SQ; the Completion Queue Entry (CQE) is a command completion notification stored in the CQ, which contains the command completion status and other related information. When the NVMe device completes a command, a CQE is added to the corresponding CQ.
[0063] Therefore, the NVMe device polls the preset submission queue (i.e., Admin SQ) to obtain the current latest command entry sent by the target host stored in the preset submission queue, and determines the corresponding command type based on the target field in the current latest command entry. If the command type is a data export command sent by the target host based on the extended NVMe protocol, the address information and buffer size of the memory buffer are obtained according to the protocol.
[0064] It should be noted that this application extends the NVMe protocol so that the target host can construct data export commands based on the extended NVMe protocol. First, each command submitted to the SQ is represented by a submission queue entry structure. Each SQE occupies 64 bytes and its structure is as follows: Figure 2 As shown in , Opcode indicates the command type. This application extends the NVMe protocol in two main places. One is the Opcode field. This application sets the value of Opcode to 0xC3 and the command name is Coverage Management. Figure 3 As shown in the figure, b represents binary representation and h represents hexadecimal representation; the second is the CDW10 field, which is as follows Figure 4 As shown, this application uses one of the bytes. When the value is 1, it means that the coverage data is cleared and reset. When the value is 2, it indicates the export command of the coverage data. When the value is 3, it indicates the query status.
[0065] Therefore, the process of sending data export commands based on the extended NVMe protocol on the target host side is mainly as follows:
[0066] (1) Apply for memory: The host applies for a continuous physical memory space of sufficient size in advance as a memory buffer for writing code coverage data on the NVMe device side. The memory needs to meet the alignment and page size requirements of NVMe.
[0067] (2) Fill in the address information of the memory buffer in the SQE: The target host fills the starting physical address of the allocated memory buffer into the PRP Entry 1 field in the SQE. If the size of the buffer exceeds the size of a single physical page (usually 4KB), the PRP Entry 2 field is used to store the starting physical address of the second buffer;
[0068] (3) Fill in the data transmission length of SQE: The host fills in the expected maximum data length in the CDW12 field and the CDW13 field, which is the buffer size of the memory buffer;
[0069] (4) Fill in the Opcode and CDW10 fields;
[0070] (5) The target host submits the command to Admin SQ.
[0071] Step S12: Based on the address information and the buffer size, the pre-collected code coverage data is transmitted and written to the memory buffer; the code coverage data is the data obtained and added to the one-way linked list after the NVMe device establishes a one-way linked list for the target data structure used to store code coverage information in each source file, and the executed code segments are counted using preset plug-in codes.
[0072] First, the system architecture between the target host and the NVMe device in this application is described. Figure 5 As shown in the figure, the target host and NVMe device are connected via the PCIe (peripheral component interconnect express, a high-speed serial computer expansion bus standard) bus. Among them, the host side module is mainly responsible for sending data export commands, triggering the collection of code coverage data, receiving code coverage data transmitted by the NVMe device, and providing coverage data analysis and report generation functions; the device side module is mainly responsible for responding to and processing data export commands, managing the collection and storage of code coverage data, transmitting code coverage data, and providing code coverage data export functions.
[0073] In this embodiment, the NVMe device has already collected the code coverage data and stored it in a one-way linked list. Specifically, the NVMe device will establish a one-way linked list for the target data structure used to store the code coverage information in each source file, and then use the preset plug-in code to count the executed code segments to obtain the code coverage data, and store it in the one-way linked list. After obtaining the data export command sent by the target host and parsing the address information and buffer size of the memory buffer, the collected code coverage data is transmitted and written to the memory buffer based on the address information and buffer size.
[0074] It is understandable that the NVMe device will be responsible for managing the collected code coverage data, specifically organizing the target data structure used to store code coverage information in each source file to establish a one-way linked list, which is convenient for reading and writing when exporting and resetting. Among them, the target data structure specifically refers to the gcov_info structure, which usually contains important information related to code coverage and records the execution status of each code segment in a specific file, such as the number of function calls, branch coverage, etc. In general, if Figure 6As shown in the figure, the startup process of a C language program can be divided into three main parts: startup, main, and exit. The startup function prepares the execution environment for the user program and calls a series of initialization functions. The coverage initialization gcov_init function is one of them. The NVMe device side needs to implement the gcov_init function and organize the incoming gcov_info structure to build a one-way linked list.
[0075] Specifically, this embodiment will first use the GCC (GNU Compiler Collection, GNU compiler suite) compiler to compile the coverage firmware package with the device side module source code and the NVMe device original firmware source code; after the NVMe device is running, the firmware code is executed. In the initialization phase, the gcov_init function implemented by the device side module will be called, and the gcov_info structure corresponding to the source file will be passed in. The device side module saves the address of the gcov_info structure and uses an empty head node to organize it into a linked list, such as Figure 7 As shown, during the run phase, the GCC instrumentation code counts the executed code, and the code coverage data is saved in the gcov_info structure.
[0076] The basic principle of stub counting is as follows: During the compilation phase, stub code is inserted at the appropriate location of the source code, mainly to add counting instructions to count the number of runs. When the stub code is run, the code block will be counted, such as Figure 8 as shown in .
[0077] Step S13: After the code coverage data in the one-way linked list is written, a target command for indicating that the write operation is completed is sent to the target host, so that the target host generates a coverage data file for the acquired code coverage data using the local file system.
[0078] In this embodiment, after the code coverage data in the one-way linked list is written, the NVMe device will also send a target command to the target host to indicate that the write operation is completed, so that the target host can use the local file system to generate a coverage data file for the acquired code coverage data. The above scheme generates a coverage data file on the target host side, which solves the problem that the NVMe device cannot generate a coverage data file without a file system, and also avoids the shortcomings of the existing scheme that relies on additional hardware interfaces or requires dedicated hardware devices. This scheme has strong versatility and reduces development costs.
[0079] In a specific implementation, before sending the target command for characterizing the completion of the write operation to the target host, it also includes: counting the actual write length of the data written in the memory buffer this time; determining the execution status of the data export command executed this time; the execution status includes a first state for characterizing the successful execution and a second state for characterizing the failed execution; creating a target command for characterizing the completion of the write operation based on the actual write length and the execution status, and submitting the target command as a command entry to the preset completion queue so that the target host can obtain the target command from the preset completion queue. That is, after the code coverage data in the one-way linked list is written, the NVMe device will count the actual write length of the data written in the memory buffer this time and determine the execution status of the data export command executed this time, that is, success or failure, and then create a target command for characterizing the completion of the write operation based on the actual write length and the execution status, and submit the target command as a command entry to the preset completion queue to notify the target host that the data export command has been executed. In a specific implementation, the actual write length is written in the Command Specific field in the command entry, and the execution status is written in the Status field.
[0080] Furthermore, the target host obtains the target command from the preset completion queue, including: when the target host polls the preset completion queue, if it monitors that there is a new command entry in the preset completion queue, the target command is obtained from the preset completion queue; accordingly, the target host uses the local file system to generate a coverage data file for the acquired code coverage data, including: the target host parses the target command to obtain the actual write length and the execution status, if the execution status is the first state, then obtains code coverage data of corresponding length from the memory buffer based on the actual write length, and generates a coverage data file for the code coverage data according to a predefined data format using the local file system.
[0081] That is, the target host will periodically poll the preset completion queue (Admin CQ). If it monitors that there is a new command entry (i.e. CQE) in the preset completion queue, it will obtain the target command from the preset completion queue. The target host further parses the target command to obtain the actual write length and execution status. If the execution status is the first state used to characterize successful execution, it will start processing the received code coverage data. Specifically, based on the actual write length, it will obtain the code coverage data of the corresponding length from the memory buffer, and generate a coverage data file for the code coverage data using the local file system in a pre-defined data format for subsequent analysis and reporting.
[0082] It can be seen that in this application, when the NVMe device obtains the data export command sent by the target host, it parses the data export command to obtain the address information and buffer size of the memory buffer pre-applied in the target host; based on the address information and the buffer size, the pre-collected code coverage data is transmitted and written to the memory buffer; the code coverage data is obtained by the NVMe device after establishing a one-way linked list for the target data structure used to store code coverage information in each source file, and counting the executed code segments using the preset plug-in code and adding it to the one-way linked list; after the code coverage data in the one-way linked list is written, a target command for characterizing the completion of the write operation is sent to the target host, so that the target host uses the local file system to generate a coverage data file for the acquired code coverage data.
[0083] Beneficial effect: The NVMe device in this application has already collected the code coverage data and stored it in a one-way linked list. Specifically, the NVMe device will establish a one-way linked list for the target data structure used to store code coverage information in each source file, and then use the preset plug-in code to count the executed code segments to obtain the code coverage data, and store it in the one-way linked list. When it is necessary to export the code coverage data, the target host will apply for a memory buffer in advance and send a data export command to the NVMe device. The data export command includes the address information and buffer size of the memory buffer. Then the NVMe device will transmit and write the collected code coverage data to the memory buffer based on the address information and buffer size. After the code coverage data in the one-way linked list is written, the NVMe device will also send a target command to the target host to characterize the completion of the write operation, so that the target host can use the local file system to generate a coverage data file for the acquired code coverage data. The above solution generates a coverage data file on the target host side, which solves the problem that the NVMe device cannot generate a coverage data file without a file system. It also avoids the shortcomings of existing solutions that rely on additional hardware interfaces or require dedicated hardware devices. This solution has strong versatility and reduces development costs.
[0084] See also Fig. 9 As shown, Fig. 9A structural schematic diagram of a one-way linked list disclosed in the present application, wherein the one-way linked list includes a head node for storing a preset head node identifier and a version number, and the remaining nodes of the target data structure for storing different source files respectively; wherein the target data structure includes a first field for storing the actual total length of the target data structure, a second field for storing the source file name, a third field for storing the code coverage data, and a fourth field for storing a termination string. That is, the one-way linked list includes a head node and the remaining nodes, the head node is mainly used to store the preset head node identifier and the version number, the head node can access the gcov_info structure stored in all the remaining nodes, the gcov_info structure includes a first field for storing the actual total length of the file, a second field for storing the source file name (file name), a third field (i.e., the gcov_info field) for storing the code coverage data, and a fourth field for storing the termination string (file end tag).
[0085] See also Fig.10 As shown, in this embodiment, the above-mentioned transmission and writing of the pre-collected code coverage data to the memory buffer based on the address information and the buffer size may specifically include the following steps:
[0086] Step S21: based on the address information, the data information stored in the head node is transmitted and written to the memory buffer, and the one-way linked list is traversed to sequentially transmit and write the data information stored in the target data structure in the remaining nodes to the memory buffer.
[0087] In this embodiment, the data information stored in the head node is first transmitted and written to the memory buffer determined based on the address information, and the one-way linked list is traversed to sequentially transmit and write the data information stored in the target data structure in the remaining nodes to the memory buffer.
[0088] Step S22: Count the total number of bytes of data currently written into the memory buffer.
[0089] In this embodiment, the total number of bytes of data currently written to the memory buffer is counted in real time. For example, the NVMe device can count the data currently written to the memory buffer at regular intervals.
[0090] Step S23: If the total number of bytes of the data is not less than the buffer size, and there are target data structures in the one-way linked list that have not been written to the memory buffer, stop writing the current data, send a preset instruction to the target host so that the target host can send the data export command again, and then transfer and write the data information stored in the remaining target data structures in the one-way linked list to the memory buffer until all the data information in the one-way linked list is transferred and written to the memory buffer; wherein, after obtaining the preset instruction, the target host migrates the data currently in the memory buffer to the target cache for storage.
[0091] In this embodiment, the total number of data bytes obtained by real-time statistics is compared with the buffer size of the memory buffer. If the total number of data bytes is not less than the buffer size, it means that the current memory buffer is full of data. If there is still unwritten data in the one-way linked list, it is necessary to suspend writing at this time, and send a preset instruction to the target host so that the target host can send the data export command again, and then transfer and write the data information stored in the remaining target data structure in the one-way linked list to the memory buffer until all the data information in the one-way linked list is transferred and written to the memory buffer. It should be pointed out that after the target host obtains the preset instruction, it will first migrate the data in the current memory buffer to the target cache for storage so that the memory buffer can be reused again.
[0092] In addition, after receiving the preset instruction, the target host can also re-apply for a piece of memory space, write the address and size of the re-applied memory space into the data export command, and send it to the NVMe device. The NVMe device then transfers and writes the data information stored in the remaining target data structure in the one-way linked list to the newly applied memory space. It should be pointed out that when the target host sends the data export command again, it needs to carry specific information so that the NVMe device can continue to transmit the remaining data information from the address where the one-way linked list stopped last time. In a specific implementation, the target host can set a counter and accumulate it. When sending a data export command, the current value of the counter will be sent to the NVMe device. For example, when the data export command is sent for the first time, it is initialized to 0, and each time all the data in the one-way linked list is obtained, it is incremented by one. Then, the next time the data export command is sent, it is 1. If the NVMe device fails to complete the transmission of the one-way linked list at one time, a preset instruction is sent to let the target host know the current situation. The target host will keep the current value of the counter at 1 according to the preset instruction, and apply for new memory space or migrate the data in the current memory buffer to the target cache for storage, and then send the data export command again. After receiving the newly sent data export command, the NVMe device still carries 1, so it continues to transmit the remaining data information from the address where the one-way linked list stopped last time.
[0093] Step S24: If the total number of bytes of the data is less than the buffer size, and there are target data structures in the one-way linked list that have not been written to the memory buffer, continue to execute the step of traversing the one-way linked list until the data information in all target data structures is transmitted and written to the memory buffer.
[0094] In this embodiment, if the total number of data bytes obtained by real-time statistics is less than the buffer size, and there are target data structures in the one-way linked list that have not been written to the memory buffer, it means that the memory buffer is not full and the transmission can continue. Therefore, the step of traversing the one-way linked list is continued until the data information in all target data structures is transmitted and written to the memory buffer.
[0095] Step S25: If the total number of bytes of the data is smaller than the buffer size, and the data information in all target data structures in the one-way linked list has been transmitted and written into the memory buffer, it is determined that the data writing operation has been completed.
[0096] In this embodiment, if the total number of data bytes is less than the buffer size, and the data information in all target data structures in the one-way linked list has been transmitted and written to the memory buffer, it means that the memory buffer requested by the target host is larger, and the code coverage data stored in the one-way linked list has been transmitted, so it is determined that the data writing operation has been completed.
[0097] It can be seen that the present application discloses a specific scheme for an NVMe device to transmit and write the pre-collected code coverage data to a memory buffer based on address information and buffer size. During the data transmission process, the NVMe device will count the total number of data bytes currently written to the memory buffer in real time, and compare the total number of data bytes with the buffer size. If the total number of data bytes is not less than the buffer size, and there are still target data structures in the one-way linked list that have not been written to the memory buffer, it means that the current memory buffer is full of data, and it is necessary to pause writing first, and send a preset instruction to the target host so that the target host can send a data export command again, and then transmit and write the data information stored in the remaining target data structures in the one-way linked list to the memory buffer. If the total number of data bytes is less than the buffer size, and there are still target data structures in the one-way linked list that have not been written to the memory buffer, continue to execute the transmission step. In addition, if the total number of data bytes is less than the buffer size, and the data information in all target data structures in the one-way linked list has been transmitted and written to the memory buffer, it means that the data write operation has been completed.
[0098] See also Fig.11 As shown, in this embodiment, the above-mentioned transmission and writing of the pre-collected code coverage data to the memory buffer based on the address information and the buffer size may specifically include the following steps:
[0099] Step S31: Determine the total amount of data stored in the one-way linked list, and determine whether the total amount of data is smaller than the buffer size.
[0100] In this embodiment, after the buffer size of the memory buffer is obtained, it is necessary to first compare the total data size stored in the one-way linked list with the buffer size to determine whether the total data size is smaller than the buffer size.
[0101] Step S32: If the total data size is smaller than the buffer size, the data information stored in the head node and the data information stored in the target data structure in the remaining nodes are transmitted and written to the memory buffer in sequence based on the address information.
[0102] In this embodiment, if the total data size is less than the buffer size, it means that the memory buffer pre-applied by the target host is large enough to store all the data stored in the one-way linked list. Therefore, based on the address information, the data information stored in the head node and the data information stored in the target data structure in the remaining nodes are sequentially transmitted and written to the memory buffer.
[0103] Step S33: If the total data size is not less than the buffer size, the total data size is sent to the target host so that the target host can reapply for a new memory buffer based on the total data size, and then transfer and write the data information stored in the head node and the data information stored in the target data structure in the remaining nodes to the new memory buffer in turn.
[0104] In this embodiment, if the total data size is not less than the buffer size, it means that the memory buffer pre-applied by the target host cannot store all the data stored in the one-way linked list. Therefore, the total data size needs to be sent to the target host so that the target host can re-apply for a new memory buffer based on the total data size. The NVMe device then sequentially transmits and writes the data information stored in the head node and the data information stored in the target data structure in the remaining nodes to the new memory buffer.
[0105] It can be seen that in this embodiment, after the NVMe device obtains the buffer size of the memory buffer, it needs to first compare the total data size stored in the one-way linked list with the buffer size. If the memory buffer pre-applied by the target host is large enough to store all the data stored in the one-way linked list, the sub-execution code coverage data transmission step is performed. On the contrary, if the memory buffer pre-applied by the target host cannot store all the data stored in the one-way linked list, the target host needs to re-apply for a new memory buffer according to the total data size, and then perform the data transmission step.
[0106] See also Fig.12 As shown, an embodiment of the present application discloses a device for exporting code coverage data, which is applied to an NVMe device, and the device includes:
[0107] The command parsing module 11 is used for parsing the data export command sent by the target host to obtain the address information and buffer size of the memory buffer previously applied in the target host;
[0108] The data transmission module 12 is used to transmit and write the pre-collected code coverage data to the memory buffer based on the address information and the buffer size; the code coverage data is the data obtained by counting the executed code segments using the preset plug-in code after the NVMe device establishes a one-way linked list for the target data structure for storing code coverage information in each source file and is added to the one-way linked list;
[0109] The file generation module 13 is used to send a target command for indicating the completion of the write operation to the target host after the code coverage data in the one-way linked list is written, so that the target host can use the local file system to generate a coverage data file for the acquired code coverage data.
[0110] Beneficial effect: The NVMe device in this application has already collected the code coverage data and stored it in a one-way linked list. Specifically, the NVMe device will establish a one-way linked list for the target data structure used to store code coverage information in each source file, and then use the preset plug-in code to count the executed code segments to obtain the code coverage data, and store it in the one-way linked list. When it is necessary to export the code coverage data, the target host will pre-apply for a memory buffer and send a data export command to the NVMe device. The data export command includes the address information and buffer size of the memory buffer. Then the NVMe device will transmit and write the collected code coverage data to the memory buffer based on the address information and buffer size. After the code coverage data in the one-way linked list is written, the NVMe device will also send a target command to the target host to characterize the completion of the write operation, so that the target host can use the local file system to generate a coverage data file for the acquired code coverage data. The above solution generates a coverage data file on the target host side, which solves the problem that the NVMe device cannot generate a coverage data file without a file system. It also avoids the shortcomings of existing solutions that rely on additional hardware interfaces or require dedicated hardware devices. This solution has strong versatility and reduces development costs.
[0111] Since the embodiments of the apparatus part correspond to the embodiments of the method part, the embodiments of the apparatus part refer to the description of the embodiments of the method part, which will not be described here. In addition, the method has the same beneficial effects as the above-mentioned method for deriving code coverage data.
[0112] Fig.13A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. Specifically, it may include: at least one processor 21, at least one memory 22, a power supply 23, a communication interface 24, an input / output interface 25, and a communication bus 26. The memory 22 is used to store a computer program, and the computer program is loaded and executed by the processor 21 to implement the relevant steps in the method for exporting code coverage data performed by the electronic device disclosed in any of the aforementioned embodiments.
[0113] In this embodiment, the power supply 23 is used to provide working voltage for each hardware device on the electronic device 20; the communication interface 24 can create a data transmission channel between the electronic device 20 and the external device, and the communication protocol it follows is any communication protocol that can be applied to the technical solution of the present application, and is not specifically limited here; the input and output interface 25 is used to obtain external input data or output data to the outside world, and its specific interface type can be selected according to specific application needs and is not specifically limited here.
[0114] Among them, the processor 21 may include one or more processing cores, such as a 4-core processor, an 8-core processor, etc. The processor 21 can be implemented in at least one hardware form of DSP (Digital Signal Processing), FPGA (Field-Programmable Gate Array), and PLA (Programmable Logic Array). The processor 21 may also include a main processor and a coprocessor. The main processor is a processor for processing data in the awake state, also known as a CPU (Central Processing Unit); the coprocessor is a low-power processor for processing data in the standby state. In some embodiments, the processor 21 may be integrated with a GPU (Graphics Processing Unit), which is responsible for rendering and drawing the content to be displayed on the display screen. In some embodiments, the processor 21 may also include an AI (Artificial Intelligence) processor, which is used to process computing operations related to machine learning.
[0115] In addition, the memory 22, as a carrier for storing resources, can be a read-only memory, a random access memory, a disk or an optical disk, etc. The resources stored thereon include an operating system 221, a computer program 222 and data 223, etc. The storage method can be temporary storage or permanent storage.
[0116] Among them, the operating system 221 is used to manage and control the hardware devices and computer programs 222 on the electronic device 20, so as to realize the operation and processing of the massive data 223 in the memory 22 by the processor 21, which can be Windows, Unix, Linux, etc. In addition to including a computer program that can be used to complete the method of exporting code coverage data executed by the electronic device 20 disclosed in any of the aforementioned embodiments, the computer program 222 can further include a computer program that can be used to complete other specific tasks. In addition to data transmitted from an external device received by the electronic device, the data 223 can also include data collected by its own input and output interface 25, etc.
[0117] Furthermore, an embodiment of the present application also discloses a computer-readable storage medium, in which a computer program is stored. When the computer program is loaded and executed by a processor, the steps of the method for exporting code coverage data disclosed in any of the aforementioned embodiments are implemented.
[0118] Furthermore, an embodiment of the present application also discloses a computer program product, including a computer program / instruction, which, when executed by a processor, implements the steps of the method for exporting code coverage data disclosed in any of the aforementioned embodiments.
[0119] In this specification, each embodiment is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can be referred to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part.
[0120] Those skilled in the art may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented with electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in terms of function in the above description. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0121] The steps of the method or algorithm described in conjunction with the embodiments disclosed herein may be implemented directly using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable disk, a compact disc read-only memory (CD-ROM), or any other form of storage medium known in the art.
[0122] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0123] The above is a detailed introduction to the code coverage data export method, device, equipment and storage medium provided by the present invention. Specific examples are used in this article to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. At the same time, for those skilled in the art, according to the idea of the present invention, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present invention.
Claims
1. A method for exporting code coverage data, characterized in that: Applicable to NVMe devices, including: When obtaining a data export command sent by the target host, parsing the data export command to obtain address information and buffer size of a memory buffer previously applied for in the target host; Based on the address information and the buffer size, the pre-collected code coverage data is transmitted and written to the memory buffer; the code coverage data is the data obtained by the NVMe device after counting the executed code segments using the preset plug-in code after establishing a one-way linked list for the target data structure for storing code coverage information in each source file and added to the one-way linked list; After the code coverage data in the one-way linked list is written, a target command for indicating that the write operation is completed is sent to the target host, so that the target host generates a coverage data file for the acquired code coverage data using a local file system.
2. The method for deriving code coverage data according to claim 1, characterized in that: Also includes: Polling a preset submission queue to obtain a current latest command entry sent by a target host stored in the preset submission queue, and determining a corresponding command type based on a target field in the current latest command entry; If the command type is a data export command sent by the target host based on the extended NVMe protocol, the step of parsing the data export command to obtain the address information and buffer size of the pre-applied memory buffer in the target host is executed.
3. The method for deriving code coverage data according to claim 1, characterized in that: The one-way linked list includes a head node for storing a preset head node identifier and a version number, and the remaining nodes of the target data structure for storing different source files respectively; wherein the target data structure includes a first field for storing the actual total length of the target data structure, a second field for storing the source file name, a third field for storing the code coverage data and a fourth field for storing a termination string.
4. The method for deriving code coverage data according to claim 3, characterized in that: The method of transmitting and writing the pre-collected code coverage data to the memory buffer based on the address information and the buffer size includes: Based on the address information, the data information stored in the head node is transmitted and written into the memory buffer, and the one-way linked list is traversed to sequentially transmit and write the data information stored in the target data structure in the remaining nodes into the memory buffer; Count the total number of bytes of data currently written into the memory buffer; If the total number of bytes of the data is not less than the size of the buffer, and there are still target data structures in the one-way linked list that have not been written to the memory buffer, then stop writing the current data, send a preset instruction to the target host so that the target host can send a data export command again, and then transfer and write the data information stored in the remaining target data structures in the one-way linked list to the memory buffer until all the data information in the one-way linked list is transferred and written to the memory buffer; wherein, after obtaining the preset instruction, the target host migrates the data currently in the memory buffer to the target cache for storage; If the total number of bytes of the data is less than the size of the buffer, and there are still target data structures in the one-way linked list that have not been written into the memory buffer, then continue to perform the step of traversing the one-way linked list until all data information in the target data structures are transmitted and written into the memory buffer; If the total number of bytes of the data is less than the size of the buffer, and the data information in all target data structures in the one-way linked list has been transmitted and written into the memory buffer, it is determined that the data writing operation has been completed.
5. The method for deriving code coverage data according to claim 3, characterized in that: The method of transmitting and writing the pre-collected code coverage data to the memory buffer based on the address information and the buffer size includes: Determine the total amount of data stored in the one-way linked list, and determine whether the total amount of data is less than the buffer size; If the total data size is smaller than the buffer size, the data information stored in the head node and the data information stored in the target data structure in the remaining nodes are sequentially transmitted and written to the memory buffer based on the address information; If the total data size is not less than the buffer size, the total data size will be sent to the target host so that the target host can reapply for a new memory buffer based on the total data size, and then transfer and write the data information stored in the head node and the data information stored in the target data structure in the remaining nodes to the new memory buffer in turn.
6. The method for deriving code coverage data according to claim 1, characterized in that: Before sending a target command for indicating that the write operation is completed to the target host, the method further includes: Counting the actual length of data written into the memory buffer; Determine the execution status of the data export command executed this time; the execution status includes a first status for indicating a successful execution and a second status for indicating a failed execution; A target command for indicating the completion of the write operation is created based on the actual write length and the execution status, and the target command is submitted as a command entry to a preset completion queue so that the target host obtains the target command from the preset completion queue.
7. The method for deriving code coverage data according to claim 6, characterized in that: The target host obtains the target command from the preset completion queue, including: When the target host polls the preset completion queue, if it monitors that there is a new command entry in the preset completion queue, the target host obtains the target command from the preset completion queue; Correspondingly, the target host generates a coverage data file for the acquired code coverage data using a local file system, including: The target host parses the target command to obtain the actual write length and the execution status. If the execution status is the first status, code coverage data of corresponding length is obtained from the memory buffer based on the actual write length, and a coverage data file is generated for the code coverage data using a local file system in accordance with a predefined data format.
8. A device for exporting code coverage data, characterized in that: Applicable to NVMe devices, including: A command parsing module, used for parsing the data export command sent by the target host to obtain the address information and buffer size of the memory buffer pre-applied in the target host when obtaining the data export command sent by the target host; A data transmission module, used for transmitting the pre-collected code coverage data and writing it to the memory buffer based on the address information and the buffer size; the code coverage data is the data obtained by counting the executed code segments using the preset plug-in code after the NVMe device establishes a one-way linked list for the target data structure for storing code coverage information in each source file and is added to the one-way linked list; The file generation module is used to send a target command for indicating the completion of the write operation to the target host after the code coverage data in the one-way linked list is written, so that the target host can use the local file system to generate a coverage data file for the acquired code coverage data.
9. An electronic device, characterized in that: include: Memory, used to store computer programs; A processor, configured to execute the computer program to implement the steps of the method for deriving code coverage data as described in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: Used to store a computer program; wherein, when the computer program is executed by a processor, the steps of the method for deriving code coverage data according to any one of claims 1 to 7 are implemented.
Citation Information
Cited By
Control data interaction method and device, computer program product, equipment and medium
CN120029963A
Control data interaction method and device, computer program product, equipment and medium
CN120029963B
Fault injection method and device, medium and product
CN120407382A
