Row coverage rate determination method and device, computer equipment and storage medium
During the test process of the program to be tested, the execution array and reference array of the target time period are obtained, the newly executed bytecode instructions and source code lines are determined, and the line coverage rate is calculated, which solves the problem of low timeline determination of row coverage in traditional technology, and more efficient test case adjustment and testing efficiency improvement are achieved.
Patent Information
- Application Number
- CN202411976719.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-26
- Publication Date
- 2025-03-25
- Estimated Expiration
- 2044-12-26
AI Technical Summary
In traditional technology, the determination of line coverage is low in time, and the code execution cannot be reflected in time during the test process of the program to be tested, which affects the adjustment of test cases and the testing efficiency.
By obtaining the execution array and reference array of the target time period, the target index of the newly executed bytecode instruction is determined during that time period, combined with the index table, the target line identification of the newly executed source code line is determined, and the row coverage ratio of the program to be tested is finally calculated.
It realizes determining the current line coverage ratio of the program to be tested at the end of each time period, improving the timeliness determination of line coverage ratio, conveniently adjusting test cases in a timely manner, and improving testing efficiency.
Smart Images

Figure CN119690850A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a method, apparatus, computer device and storage medium for determining row coverage. Background Art
[0002] Line coverage is an indicator used in software testing to measure the execution of code in the program to be tested. Line coverage refers to the ratio of the number of source code lines executed in the program to be tested to the total number of source code lines. The higher the line coverage, the more comprehensive the test cases for the program to be tested are, and the better it can reveal potential errors and defects in the program to be tested.
[0003] In the conventional technology, after the test of the program to be tested is completed, the line coverage is calculated by collecting the executed source code line identifiers, which results in low timeliness in determining the line coverage. Summary of the invention
[0004] Based on this, it is necessary to provide a row coverage determination method, apparatus, computer equipment, computer-readable storage medium and computer program product that can improve the timeliness of row coverage in response to the above technical problems.
[0005] In a first aspect, the present application provides a method for determining row coverage. The method comprises:
[0006] Obtaining an execution array and a reference array corresponding to a target time period; the reference array is the same as the execution array corresponding to a time period immediately before the target time period, and the elements in the execution array represent the execution status of the bytecode instruction corresponding to the index of the element;
[0007] Determining, based on the execution array and the reference array, a target index corresponding to the bytecode instruction newly executed within the target time period;
[0008] Determine, based on the index table corresponding to the program to be tested and the target index, a target line identifier corresponding to a target source code line newly executed within the target time period;
[0009] Based on the target row identifier, the row coverage corresponding to the program to be tested is determined.
[0010] In one embodiment, determining the target index corresponding to the bytecode instruction newly executed within the target time period based on the execution array and the reference array includes:
[0011] Performing a bitwise inversion operation on the reference array to obtain an updated reference array;
[0012] Performing a bitwise AND operation on the execution array and the updated reference array to obtain a newly added array;
[0013] The index corresponding to the element with the first identifier in the newly added array is determined as the target index; the first identifier represents that the bytecode instruction corresponding to the index of the first identifier is executed within the target time period.
[0014] In one embodiment, determining the target line identifier corresponding to the target source code line newly executed within the target time period based on the index table corresponding to the program to be tested and the target index includes:
[0015] For each of the target indexes, the source code line identifier corresponding to the target index in the index table is determined as the target line identifier corresponding to the target index; the index table includes a correspondence between indexes and source code line identifiers, the index is a bytecode instruction identifier of a bytecode instruction in a bytecode file corresponding to the program to be tested, and the source code line identifier is an identifier of a source code line in the program to be tested.
[0016] In one embodiment, determining the line coverage corresponding to the program to be tested based on the target line identifier includes:
[0017] Counting the target row identifiers corresponding to the target time period to obtain the total number of newly added executions corresponding to the target time period;
[0018] Counting the total number of historical executions and the total number of newly added executions to obtain the current total number of executions;
[0019] Based on the current execution total number and the total number of code lines corresponding to the program to be tested, the line coverage corresponding to the program to be tested is determined.
[0020] In one embodiment, the step of obtaining the execution array and the reference array corresponding to the target time period includes:
[0021] Obtaining an execution array and a reference array corresponding to a previous adjacent time period of the target time period;
[0022] Performing a bitwise OR operation on the execution array and the reference array corresponding to the previous adjacent time period to obtain a reference array corresponding to the target time period;
[0023] Based on the bytecode instruction identifier corresponding to the bytecode instruction executed in the target time period, the execution array corresponding to the previous adjacent time period is updated to obtain the execution array corresponding to the target time period.
[0024] In one embodiment, before acquiring the execution array and the reference array corresponding to the target time period, the method further includes:
[0025] Compile the program to be tested to obtain a bytecode file corresponding to the program to be tested;
[0026] Determine a mapping relationship between source code line identifiers of source code lines in the program to be tested and bytecode instruction identifiers of bytecode instructions in the bytecode file;
[0027] Based on the mapping relationship, an index table corresponding to the program to be tested is determined.
[0028] In a second aspect, the present application further provides a row coverage determination device. The device comprises:
[0029] An acquisition module, used to acquire an execution array and a reference array corresponding to a target time period; the reference array is the same as the execution array corresponding to a previous adjacent time period of the target time period, and the elements in the execution array represent the execution status of the bytecode instruction corresponding to the index of the element;
[0030] An index determination module, configured to determine, based on the execution array and the reference array, a target index corresponding to the bytecode instruction newly executed within the target time period;
[0031] A line identifier determination module, used to determine a target line identifier corresponding to a target source code line newly executed within the target time period based on an index table corresponding to the program to be tested and the target index;
[0032] A line coverage determination module is used to determine the line coverage corresponding to the program to be tested based on the target line identifier.
[0033] In a third aspect, the present application further provides a computer device, comprising a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of any one of the methods described in the first aspect when executing the computer program.
[0034] In a fourth aspect, the present application further provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the steps of any one of the methods described in the first aspect.
[0035] In a fifth aspect, the present application further provides a computer program product, comprising a computer program, which, when executed by a processor, implements the steps of any one of the methods described in the first aspect.
[0036] The above-mentioned line coverage determination method, device, computer equipment, storage medium and computer program product obtain an execution array corresponding to a target time period and reference data identical to the execution array corresponding to a time period immediately before the target time period, and determine a target index corresponding to the bytecode instruction newly executed in the target time period according to the execution array and the reference array. Since the index table includes the bytecode instruction identifiers of each bytecode instruction in the bytecode file corresponding to the program to be tested and the corresponding relationship between the source code line identifiers of the source code lines in the program to be tested, the target line identifier corresponding to the target source code line newly executed in the target time period can be determined according to the index table and the target index, and the total number of newly executed operations corresponding to the target time period can be determined according to the target line identifier. Similarly, the total number of historical executions corresponding to each historical time period before the target time period is determined based on the above-mentioned method, and the line coverage corresponding to the program to be tested at the end time of the target time period can be determined according to the total number of newly executed operations and each total number of historical executions. It can be understood that the current line coverage of the program to be tested can be determined once at the end time of each time period, which improves the timeliness of line coverage determination compared to determining the line coverage at the end time of the program to be tested. Moreover, during the testing process, the line coverage of the program to be tested is calculated, so that the test cases of the program to be tested can be adjusted in time to improve the testing efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] Figure 1 A diagram of an application environment of a method for determining a row coverage ratio according to an embodiment;
[0038] Figure 2 A schematic diagram of a flow chart of a method for determining a bank coverage rate according to an embodiment;
[0039] Figure 3 A schematic diagram of an execution array in one embodiment;
[0040] Figure 4 is a schematic diagram of an index table in one embodiment;
[0041] Figure 5 A schematic diagram of a process for determining newly added data in an embodiment;
[0042] Figure 6 A schematic diagram of a process after determining a newly added array in one embodiment;
[0043] Figure 7 A schematic diagram of a process of determining a reference array corresponding to a target time period in an embodiment;
[0044] Figure 8 A schematic diagram of an execution array corresponding to a target time period in an embodiment;
[0045] Fig. 9A schematic diagram of a process for determining a bank coverage rate according to an embodiment;
[0046] Fig.10 is a structural block diagram of a device for determining a row coverage rate according to an embodiment;
[0047] Fig.11 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0048] 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.
[0049] The row coverage determination 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 server 104 through the network. The data storage system can store data that the server 104 needs to process. The data storage system can be integrated on the server 104, or it can be placed on the cloud or other network servers. Both the terminal and the server can be used alone to execute the line coverage determination method provided in the embodiment of the present application. The terminal and the server can also be used in collaboration to execute the line coverage determination method provided in the embodiment of the present application. For example, the terminal 102 obtains the execution array and the reference array corresponding to the target time period; the reference array is the same as the execution array corresponding to the previous adjacent time period of the target time period, and the elements in the execution array represent the execution status of the bytecode instructions corresponding to the index of the element; based on the execution array and the reference array, the target index corresponding to the bytecode instructions newly executed in the target time period is determined; based on the index table and the target index corresponding to the program to be tested, the target line identifier corresponding to the target source code line newly executed in the target time period is determined; based on the target line identifier, the line coverage corresponding to the program to be tested is determined. The terminal 102 may be, but is not limited to, various personal computers, laptops, smart phones, tablet computers, IoT devices, and portable wearable devices. The IoT devices may be smart speakers, smart TVs, smart air conditioners, smart car-mounted devices, etc. The portable wearable devices may be smart watches, smart bracelets, head-mounted devices, etc. The server 104 may be implemented as an independent server or a server cluster consisting of multiple servers.
[0050] In one embodiment, Figure 2 As shown, a method for determining a row coverage is provided. This embodiment is described by taking the method applied to a computer device as an example, and includes steps 202 to 208.
[0051] Step 202, obtain the execution array and reference array corresponding to the target time period; the reference array is the same as the execution array corresponding to the previous adjacent time period of the target time period, and the elements in the execution array represent the execution status of the bytecode instructions corresponding to the index of the element.
[0052] Among them, the time period refers to a period of time during the test process of the program to be tested, which can be understood as dividing the test time of the program to be tested into multiple time periods. For example, the first second in the test process of the program to be tested is a time period, and the second second is a time period. The length of the time period can be set according to actual needs and is not limited here. The target time period refers to the current time period. The execution array refers to an array that stores the execution status of the bytecode. The execution array includes multiple elements, each element corresponds to an index, and the index is the bytecode instruction identifier of the bytecode instruction. The elements in the execution array can be a first identifier or a second identifier. The first identifier indicates that the bytecode instruction corresponding to the index of the element is executed, and the second identifier indicates that the bytecode instruction corresponding to the index of the element is not executed. The first identifier can be 1, and the second identifier can be 0. For example, the schematic diagram of the execution array is as follows Figure 3 As shown, 0 in the execution array is an element in the execution array, and index 1, index 2, and index 3 in the execution array are indexes of the elements in the execution array, and the elements and indexes in the execution array correspond one to one. The reference array refers to an array used to record the execution array of the previous adjacent time, that is, the reference element group corresponding to the target time period is the same as the execution array corresponding to the previous adjacent time period of the target time period.
[0053] An element refers to a value stored in an array, and an element in an execution array refers to a value stored in an execution array. An index refers to the position identifier of an element, and an index can be a bytecode instruction identifier of a bytecode instruction. A bytecode instruction refers to an intermediate representation generated after the program source code is compiled. It is a machine-independent instruction for a virtual machine to interpret or compile and execute, and usually represents the operation and flow of the program in a concise form. A bytecode file consists of multiple bytecode instructions, and bytecode instructions correspond to bytecode instruction identifiers one by one. The execution status of a bytecode instruction refers to whether the bytecode instruction is interpreted or compiled and executed. The execution status of a bytecode instruction can be divided into being executed or not executed.
[0054] Exemplarily, at the end of the target time period, the computer device acquires the current execution array and reference array to obtain the execution array and reference array corresponding to the target time period.
[0055] Step 204: Determine the target index corresponding to the bytecode instruction newly executed within the target time period based on the execution array and the reference array.
[0056] The target index refers to the bytecode identifier corresponding to the bytecode instruction executed in the target time period.
[0057] Exemplarily, the computer device performs a logical operation on the execution data and the reference array to obtain a newly added array, and based on the newly added array, determines a target index corresponding to the bytecode instruction newly executed within a target time period.
[0058] Step 206 : determining the target line identifier corresponding to the target source code line newly executed within the target time period based on the index table corresponding to the program to be tested and the target index.
[0059] Among them, the program to be tested refers to the program to be tested, and the program to be tested may be composed of multiple source code lines in one program file, or may be composed of multiple source code lines in multiple program files. The index table corresponding to the program to be tested refers to the index table generated according to the program to be tested. The index table is an array of key-value pair structures, and the index table may be a hash table. The index table includes indexes and source code line identifiers, and the index in the index table is the bytecode instruction identifier of the bytecode instruction in the bytecode file corresponding to the program to be tested, and the bytecode instruction identifier may be the identifier of the position of the bytecode instruction in the bytecode file; the source code line identifier refers to the identifier of the source code line in the program to be tested, and the source code line identifier may be the position identifier of the source code line in the program to be tested, or may be composed of the file identifier of the file where the source code line is located and the position identifier in the file where it is located. For example, the schematic diagram of the index table is as follows: Figure 4 As shown, index 1, index 2, and index 3 are indexes in the index table. Index 1 corresponds to two source code line identifiers, namely "file 1 + line number 1" and "file 4 + line number 8". "File 1 + line number 1" represents the first line of source code in file 1 that constitutes the program to be tested, and "file 4 + line number 8" represents the eighth line of source code in file 4 that constitutes the program to be tested, that is, the bytecode instruction corresponding to index 1 is associated with the first line of source code in file 1 and the eighth line of source code in file 4. The target line identifier refers to the identifier of the source code line executed in the target time period.
[0060] Exemplarily, the computer device obtains an index table corresponding to the program to be tested, and determines a target line identifier corresponding to a target source code line newly executed within a target time period based on the index table and the target index.
[0061] Step 208: Determine the line coverage corresponding to the program to be tested based on the target line identifier.
[0062] The line coverage refers to the ratio of the number of source code lines executed in the program to be tested to the total number of code lines in the program to be tested at the end of the target time period.
[0063] Exemplarily, the computer device counts the target row identifiers corresponding to the target time period to obtain the total number of newly added executions corresponding to the target time period, and determines the row coverage of the program to be tested corresponding to the target time period based on the total number of newly added executions corresponding to the target time period and the total number of historical executions corresponding to each historical time period. The historical time period refers to the time period before the target time period during the testing of the program to be tested. For example, if the target time period is the fifth time period, the first time period, the second time period, the third time period, and the fourth time period are all historical time periods.
[0064] In this embodiment, an execution array corresponding to the target time period and reference data identical to the execution array corresponding to the previous adjacent time period of the target time period are obtained, and a target index corresponding to the bytecode instruction newly executed in the target time period is determined according to the execution array and the reference array. Since the index table includes the bytecode instruction identifiers of each bytecode instruction in the bytecode file corresponding to the program to be tested and the corresponding relationship between the source code line identifiers of the source code lines in the program to be tested, the target line identifier corresponding to the target source code line newly executed in the target time period can be determined according to the index table and the target index, and the total number of newly executed operations corresponding to the target time period can be determined according to the target line identifier. Similarly, the total number of historical executions corresponding to each historical time period before the target time period is determined based on the above method, and the line coverage rate corresponding to the program to be tested at the end time of the target time period can be determined according to the total number of newly executed operations and each total number of historical executions. It can be understood that the current line coverage rate of the program to be tested can be determined once at the end time of each time period, which improves the timeliness of line coverage rate determination compared to determining the line coverage rate at the end time of the program to be tested. Moreover, calculating the line coverage rate of the program to be tested during the test process facilitates timely adjustment of the test cases of the program to be tested to improve the efficiency of the test.
[0065] In one embodiment, determining a target index corresponding to a bytecode instruction newly executed within a target time period based on an execution array and a reference array includes:
[0066] Perform a bitwise inversion operation on the reference array to obtain an updated reference array; perform a bitwise AND operation on the execution array and the updated reference array to obtain a newly added array; determine the index corresponding to the element with the first identifier in the newly added array as the target index; the first identifier indicates that the bytecode instruction corresponding to the index of the first identifier is executed within the target time period.
[0067] The bitwise negation operation refers to the negation operation of each element in the reference array. For example, if the reference array is 001010, the reference array is negated, and the updated reference array is 110101. The bitwise AND operation refers to the AND operation of the elements at the same position in the two arrays. For example, if the execution array is 000011 and the updated reference array is 110101, the execution array and the updated reference array are bitwise ANDed, and the newly added array is 000001.
[0068] Exemplarily, the computer device performs a bitwise inversion operation on the reference array to obtain an updated reference array, and then performs a bitwise AND operation on the execution array and the updated reference array to obtain a newly added array, and determines the index corresponding to the element with the first identifier in the newly added array as the target index. For example, a schematic diagram of the newly added data determination process is shown in FIG. Figure 5 As shown, LineBitOrigin is the execution array, LineBitTemp is the reference array, and LineBitDiff is the newly added array. The newly added array can be obtained by performing bitwise AND-NOT operations on the elements corresponding to the same index in the execution array and the reference array.
[0069] In one embodiment, the flowchart after determining the newly added array is as follows: Figure 6 As shown, it includes: the computer device determines the index corresponding to the element with the first identifier in the newly added array as the target index; determines the source code line identifier corresponding to the target index in the index table as the target line identifier corresponding to the target index; and sends the target line identifier corresponding to the target time period to the server. The server counts the target line identifier corresponding to the target time period to obtain the total number of newly added executions corresponding to the target time period; counts each historical execution total number and the total number of newly added executions to obtain the current execution total number; determines the line coverage rate corresponding to the program to be tested at the end of the target time period based on the current execution total number and the total number of code lines corresponding to the program to be tested, and generates a line coverage rate report based on the line coverage rate corresponding to the end of the target time period, and the line coverage rate report is used for the tester to view. Among them, the computer device sends the target line identifier corresponding to the target time period to the server, including but not limited to using GRPC (Google Remote Procedure Call, Google Remote Procedure Call Protocol), HTTP (Hyper Text Transfer Protocol, Hypertext Transfer Protocol) and RPC (Remote Procedure Call, Remote Procedure Call) and other network transmission methods.
[0070] In this embodiment, a newly added array is obtained by performing a bitwise AND operation on the execution array and the updated reference array, and the index corresponding to the element with the first identifier in the newly added array is the bytecode instruction identifier of the bytecode instruction executed in the target time period, so the index corresponding to the element with the first identifier in the newly added array can be determined as the target index, providing accurate basic data for the subsequent determination of the target row identifier. Moreover, the process of determining the target index only includes bitwise inversion operations and bitwise AND operations, and the entire process has a small amount of operations and a fast operation speed, thereby improving the efficiency of determining the target index.
[0071] In one embodiment, based on the index table and the target index corresponding to the program to be tested, determining the target line identifier corresponding to the target source code line newly executed within the target time period includes:
[0072] For each target index, the source code line identifier corresponding to the target index in the index table is determined as the target line identifier corresponding to the target index; the index table includes a correspondence between the index and the source code line identifier, the index is the bytecode instruction identifier of the bytecode instruction in the bytecode file corresponding to the program to be tested, and the source code line identifier is the identifier of the source code line in the program to be tested.
[0073] Among them, the number of indexes in the index table is the same as the number of bytecode instructions in the bytecode file corresponding to the program to be tested. The index is the bytecode instruction identifier of the bytecode instruction, and the index corresponds to the bytecode instruction one by one. For example, the bytecode file corresponding to the program to be tested contains 100 bytecode instructions, then there are 100 indexes in the index table corresponding to the program to be tested.
[0074] Exemplarily, after determining the target index, the computer device obtains an index table corresponding to the program to be tested, and for each target index, determines the source code line identifier corresponding to the target index in the index table as the target line identifier corresponding to the target index.
[0075] In this embodiment, since the index table includes the bytecode instruction identifiers of each bytecode instruction in the bytecode file corresponding to the program to be tested and the corresponding source code line identifiers of the source code lines in the program to be tested, the target line identifier corresponding to the target source code line newly executed in the target time period can be determined based on the index table and the target index.
[0076] In one embodiment, determining the line coverage corresponding to the program to be tested based on the target line identifier includes:
[0077] The target line identifiers corresponding to the target time period are counted to obtain the total number of new executions corresponding to the target time period; the historical total number of executions and the total number of new executions are counted to obtain the current total number of executions; based on the current total number of executions and the total number of code lines corresponding to the program to be tested, the line coverage corresponding to the program to be tested is determined.
[0078] The total number of newly added executions refers to the total number of source code lines executed in the target time period. The total number of historical executions refers to the total number of source code lines executed in the historical time period. The historical time period refers to the time period before the target time period during the test of the program to be tested. The length of the historical time period can be equal to the length of the target time period. The total number of current executions refers to the total number of source code lines executed up to the end of the target time period. The total number of code lines refers to the total number of source code lines included in the program to be tested.
[0079] Exemplarily, the computer device counts the target line identifiers corresponding to the target time period, obtains the total number of new executions corresponding to the target time period, obtains the total number of historical executions corresponding to each historical time period, counts each historical execution total and the total number of new executions, obtains the current execution total, divides the current execution total by the total number of code lines corresponding to the program to be tested, and obtains the line coverage corresponding to the program to be tested at the end of the target time period.
[0080] In this embodiment, the current total number of executions is obtained by counting the total number of historical executions and the total number of new executions. Based on the current total number of executions and the total number of code lines corresponding to the program to be tested, the line coverage rate of the program to be tested at the end of the target time period can be determined. It can be understood that the current line coverage rate of the program to be tested can be determined once at the end of each time period, which improves the timeliness of the line coverage rate determination compared to determining the line coverage rate at the end of the test of the program to be tested.
[0081] In one embodiment, obtaining the execution array and the reference array corresponding to the target time period includes:
[0082] Obtain an execution array and a reference array corresponding to the previous adjacent time period of the target time period; perform a bitwise OR operation on the execution array and the reference array corresponding to the previous adjacent time period to obtain a reference array corresponding to the target time period; based on the bytecode instruction identifier corresponding to the bytecode instruction executed in the target time period, update the execution array corresponding to the previous adjacent time period to obtain an execution array corresponding to the target time period.
[0083] The bitwise OR operation refers to performing an OR operation on the elements at the same position in the two arrays.
[0084] Exemplarily, the computer device determines the execution array and reference array corresponding to the previous adjacent time period in the previous adjacent time period of the target time period, and after determining the newly added array corresponding to the previous adjacent time period based on the execution array and reference array corresponding to the previous adjacent time period, performs a bitwise OR operation on the execution array and reference array corresponding to the previous adjacent time period, and uses the obtained array as the reference array corresponding to the target time period. For example, a schematic diagram of the determination process of the reference array corresponding to the target time period is shown in FIG. Figure 7 As shown, a bitwise OR operation is performed on the execution array LineBitOrigin corresponding to the previous adjacent time period and the reference array LineBitTemp corresponding to the previous adjacent time period to obtain the reference array LineBitTemp corresponding to the target time period.
[0085] Based on the bytecode instruction identifier corresponding to the bytecode instruction executed in the target time period, the computer device assigns the element value of the same index as the bytecode instruction identifier in the execution array corresponding to the previous adjacent time period as the first identifier to obtain the execution array corresponding to the target time period. For example, the schematic diagram of the execution array corresponding to the target time period is as follows: Figure 8 As shown, the bytecode instruction corresponding to index 4 and the bytecode instruction corresponding to index 7 are executed within the target time period, and the elements corresponding to index 4 and index 7 are assigned values of 1 respectively.
[0086] In this embodiment, the reference array corresponding to the target time period is obtained by performing a bitwise OR operation on the execution array and the reference array corresponding to the previous adjacent time period. The indexes corresponding to all the elements with the first identifier in the reference array corresponding to the target time period represent all the bytecode instructions executed between the target time periods, providing accurate basic data for the subsequent determination of the newly added array corresponding to the target time period; the execution array corresponding to the previous adjacent time period is updated by the bytecode instruction identifier corresponding to the bytecode instruction executed in the target time period, obtaining the execution array corresponding to the target time period. The indexes corresponding to all the elements with the first identifier in the execution array corresponding to the target time period represent all the bytecode instructions executed before and during the target time period, providing accurate basic data for the subsequent determination of the newly added array corresponding to the target time period. Moreover, the information of the bytecode instructions executed by the execution data cup is stored, which occupies less storage space and improves resource utilization.
[0087] In one embodiment, before acquiring the execution array and the reference array corresponding to the target time period, the method further includes:
[0088] Compile the program to be tested to obtain a bytecode file corresponding to the program to be tested; determine the mapping relationship between the source code line identifier of the source code line in the program to be tested and the bytecode instruction identifier of the bytecode instruction in the bytecode file; based on the mapping relationship, determine the index table corresponding to the program to be tested.
[0089] The mapping relationship refers to the corresponding relationship between the bytecode instruction identifier and the source code line identifier.
[0090] Exemplarily, a computer device compiles the program to be tested, obtains a bytecode file corresponding to the program to be tested, determines a mapping relationship between source code line identifiers of source code lines in the program to be tested and bytecode instruction identifiers of bytecode instructions in the bytecode file, and determines an index table corresponding to the program to be tested based on all mapping relationships.
[0091] In one embodiment, before compiling the program to be tested, the method further includes: embedding a line coverage collection program into the program to be tested. The embedding method may be an instrumentation method. The line coverage collection program is used to collect running information of the program to be tested, including but not limited to execution paths and variable values, etc., to support software testing, performance analysis or behavior monitoring.
[0092] In one embodiment, after compiling the program to be tested and obtaining the bytecode file corresponding to the program to be tested, the method further includes: generating an initial execution array based on the bytecode instruction identifier of the bytecode instruction in the bytecode file; the elements in the execution array are all second identifiers, the number of elements in the execution array is the same as the number of bytecode instructions in the bytecode file, and the index of the elements in the execution array is the bytecode instruction identifier of the bytecode instruction in the bytecode file. The second identifier indicates that the bytecode instruction indexed by the second identifier is not executed, and the second identifier can be 0.
[0093] In this embodiment, an index table corresponding to the program to be tested is determined through a mapping relationship between source code line identifiers of source code lines in the program to be tested and bytecode instruction identifiers of bytecode instructions in a bytecode file. The index table includes a corresponding relationship between bytecode instruction identifiers of each bytecode instruction in the bytecode file corresponding to the program to be tested and source code line identifiers of source code lines in the program to be tested, thereby laying a foundation for subsequently determining a target line identifier according to a target index.
[0094] In an exemplary embodiment, the row coverage determination process diagram is as follows: Fig. 9 As shown, including:
[0095] (1) The computer device embeds the line coverage collection program into the program to be tested through the instrumentation method.
[0096] (2) After the program to be tested is started, the program to be tested is compiled to obtain the bytecode file corresponding to the program to be tested, and the mapping relationship between the source code line identifier of the source code line in the program to be tested and the bytecode instruction identifier of the bytecode instruction in the bytecode file is determined. Based on all the mapping relationships, the index table CodeMap corresponding to the program to be tested is determined. Based on the bytecode instruction identifier of the bytecode instruction in the bytecode file, the initial execution array LineBitOrigin is generated, and all elements in the execution array LineBitOrigin are 0.
[0097] (3) The program to be tested starts testing, and the line coverage collection program collects the bytecode instructions that are running, and assigns the element value of the execution array LineBitTemp with the same index as the bytecode instruction identifier to 1.
[0098] (4) Periodically calculate row coverage, including:
[0099] At the end of the first test period, an initial reference array LineBitTemp is created, and all elements in the reference array LineBitTemp are 0.
[0100] For each target time period, perform a bitwise inversion operation on the reference array LineBitTemp corresponding to the target time period to obtain an updated reference array LineBitTemp, then perform a bitwise AND operation on the execution array LineBitOrigin corresponding to the target time period and the updated reference array LineBitTemp to obtain a newly added array LineBitDiff corresponding to the target time period, and determine the index corresponding to the element 1 in the newly added array as the target index. For each target index, determine the source code line identifier corresponding to the target index in the index table as the target line identifier corresponding to the target index.
[0101] A bitwise OR operation is performed on the execution array LineBitOrigin corresponding to the target time period and the reference array LineBitTemp to obtain the reference array LineBitTemp corresponding to the next time period.
[0102] (5) Based on the preset sending interval, the determined target line identifier is sent to the server. The server counts the received target line identifiers to obtain the total number of newly added executions; the total number of historical executions and the total number of newly added executions are counted to obtain the current total number of executions; the current total number of executions is divided by the total number of code lines corresponding to the program to be tested to obtain the current line coverage of the program to be tested, and the line coverage report is updated based on the current corresponding line coverage. The line coverage report is used for testers to view. The preset sending interval can be equal to the length of the target time period, or it can be a multiple of the length of the target time period.
[0103] In this embodiment, an execution array corresponding to the target time period and reference data identical to the execution array corresponding to the previous adjacent time period of the target time period are obtained, and a target index corresponding to the bytecode instruction newly executed in the target time period is determined according to the execution array and the reference array. Since the index table includes the bytecode instruction identifiers of each bytecode instruction in the bytecode file corresponding to the program to be tested and the corresponding relationship between the source code line identifiers of the source code lines in the program to be tested, the target line identifier corresponding to the target source code line newly executed in the target time period can be determined according to the index table and the target index, and the total number of newly executed operations corresponding to the target time period can be determined according to the target line identifier. Similarly, the total number of historical executions corresponding to each historical time period before the target time period is determined based on the above method, and the line coverage rate corresponding to the program to be tested at the end time of the target time period can be determined according to the total number of newly executed operations and each total number of historical executions. It can be understood that the current line coverage rate of the program to be tested can be determined once at the end time of each time period, which improves the timeliness of line coverage rate determination compared to determining the line coverage rate at the end time of the program to be tested. Moreover, calculating the line coverage rate of the program to be tested during the test process facilitates timely adjustment of the test cases of the program to be tested to improve the efficiency of the test.
[0104] It should be understood that, although the various steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps does not have a strict order restriction, 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 can 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.
[0105] Based on the same inventive concept, the embodiment of the present application also provides a row coverage determination device for implementing the row coverage determination method involved above. 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 limitations in one or more embodiments of the row coverage determination device provided below can refer to the limitations of the row coverage determination method above, and will not be repeated here.
[0106] In one embodiment, Fig.10As shown, a row coverage determination device is provided, comprising: an acquisition module 1002, an index determination module 1004, a row identification determination module 1006 and a row coverage determination module 1008, wherein:
[0107] The acquisition module 1002 is used to acquire an execution array and a reference array corresponding to a target time period; the reference array is the same as the execution array corresponding to a time period immediately before the target time period, and the elements in the execution array represent the execution status of the bytecode instruction corresponding to the index of the element;
[0108] An index determination module 1004, configured to determine a target index corresponding to a bytecode instruction newly executed within the target time period based on the execution array and the reference array;
[0109] A row identifier determination module 1006 is used to determine a target row identifier corresponding to a target source code row newly executed within the target time period based on the index table corresponding to the program to be tested and the target index;
[0110] The line coverage determination module 1008 is used to determine the line coverage corresponding to the program to be tested based on the target line identifier.
[0111] In one embodiment, the index determination module 1004 is also used to: perform a bitwise inversion operation on the reference array to obtain an updated reference array; perform a bitwise AND operation on the execution array and the updated reference array to obtain a newly added array; determine the index corresponding to the element with the first identifier in the newly added array as the target index; the first identifier represents that the bytecode instruction corresponding to the index of the first identifier is executed within the target time period.
[0112] In one embodiment, the line identifier determination module 1006 is further used to: for each target index, determine the source code line identifier corresponding to the target index in the index table as the target line identifier corresponding to the target index; the index table includes a correspondence between an index and a source code line identifier, the index is a bytecode instruction identifier of a bytecode instruction in a bytecode file corresponding to the program to be tested, and the source code line identifier is an identifier of a source code line in the program to be tested.
[0113] In one embodiment, the line coverage determination module 1008 is also used to: count the target line identifiers corresponding to the target time period to obtain the total number of new executions corresponding to the target time period; count the total number of historical executions and the total number of new executions to obtain the current total number of executions; and determine the line coverage corresponding to the program to be tested based on the current total number of executions and the total number of code lines corresponding to the program to be tested.
[0114] In one embodiment, the acquisition module 1002 is also used to: obtain an execution array and a reference array corresponding to the previous adjacent time period of the target time period; perform a bitwise OR operation on the execution array and the reference array corresponding to the previous adjacent time period to obtain a reference array corresponding to the target time period; and update the execution array corresponding to the previous adjacent time period based on the bytecode instruction identifier corresponding to the bytecode instruction executed in the target time period to obtain an execution array corresponding to the target time period.
[0115] In one embodiment, the acquisition module 1002 is also used to: compile the program to be tested to obtain a bytecode file corresponding to the program to be tested; determine the mapping relationship between the source code line identifier of the source code line in the program to be tested and the bytecode instruction identifier of the bytecode instruction in the bytecode file; and determine the index table corresponding to the program to be tested based on the mapping relationship.
[0116] Each module in the above-mentioned line coverage determination device can be implemented in whole or in part by software, hardware or a combination thereof. Each module 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 the operations corresponding to each module.
[0117] In one embodiment, a computer device is provided. The computer device may be a terminal, and its internal structure diagram may be as follows: Fig.11As shown. The computer device includes a processor, a memory, an input / output interface, a communication interface, a display unit and an input device. 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. 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 an 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, a method for determining a row coverage is 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, and 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.
[0118] Those skilled in the art will understand that Fig.11 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.
[0119] In one embodiment, a computer device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the steps in the above-mentioned method embodiments when executing the computer program.
[0120] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments are implemented.
[0121] In one embodiment, a computer program product is provided, including a computer program, which implements the steps in the above method embodiments when executed by a processor.
[0122] 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.
[0123] 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.
[0124] The technical features of the above embodiments may be combined arbitrarily. 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.
[0125] 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 understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations 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 determining row coverage, characterized in that: The method comprises: Obtaining an execution array and a reference array corresponding to a target time period; the reference array is the same as the execution array corresponding to a time period immediately before the target time period, and the elements in the execution array represent the execution status of the bytecode instruction corresponding to the index of the element; Determining, based on the execution array and the reference array, a target index corresponding to the bytecode instruction newly executed within the target time period; Determine, based on the index table corresponding to the program to be tested and the target index, a target line identifier corresponding to a target source code line newly executed within the target time period; Based on the target row identifier, the row coverage corresponding to the program to be tested is determined.
2. The method according to claim 1, characterized in that: The determining, based on the execution array and the reference array, a target index corresponding to the bytecode instruction newly executed within the target time period includes: Performing a bitwise inversion operation on the reference array to obtain an updated reference array; Performing a bitwise AND operation on the execution array and the updated reference array to obtain a newly added array; The index corresponding to the element with the first identifier in the newly added array is determined as the target index; the first identifier represents that the bytecode instruction corresponding to the index of the first identifier is executed within the target time period.
3. The method according to claim 1, characterized in that The step of determining, based on the index table corresponding to the program to be tested and the target index, a target line identifier corresponding to a target source code line newly executed within the target time period includes: For each of the target indexes, the source code line identifier corresponding to the target index in the index table is determined as the target line identifier corresponding to the target index; the index table includes a correspondence between indexes and source code line identifiers, the index is a bytecode instruction identifier of a bytecode instruction in a bytecode file corresponding to the program to be tested, and the source code line identifier is an identifier of a source code line in the program to be tested.
4. The method according to claim 1, characterized in that: The determining, based on the target row identifier, the row coverage corresponding to the program to be tested includes: Counting the target row identifiers corresponding to the target time period to obtain the total number of newly added executions corresponding to the target time period; Counting the total number of historical executions and the total number of newly added executions to obtain the current total number of executions; Based on the current total number of executions and the total number of code lines corresponding to the program to be tested, a line coverage rate corresponding to the program to be tested is determined.
5. The method according to claim 1, characterized in that: The step of obtaining the execution array and the reference array corresponding to the target time period includes: Obtaining an execution array and a reference array corresponding to a previous adjacent time period of the target time period; Performing a bitwise OR operation on the execution array and the reference array corresponding to the previous adjacent time period to obtain a reference array corresponding to the target time period; Based on the bytecode instruction identifier corresponding to the bytecode instruction executed in the target time period, the execution array corresponding to the previous adjacent time period is updated to obtain the execution array corresponding to the target time period.
6. The method according to claim 1, characterized in that Before obtaining the execution array and the reference array corresponding to the target time period, the method further includes: Compile the program to be tested to obtain a bytecode file corresponding to the program to be tested; Determine a mapping relationship between source code line identifiers of source code lines in the program to be tested and bytecode instruction identifiers of bytecode instructions in the bytecode file; Based on the mapping relationship, an index table corresponding to the program to be tested is determined.
7. A row coverage determination device, characterized in that: The device comprises: An acquisition module, used to acquire an execution array and a reference array corresponding to a target time period; the reference array is the same as the execution array corresponding to a previous adjacent time period of the target time period, and the elements in the execution array represent the execution status of the bytecode instruction corresponding to the index of the element; An index determination module, configured to determine, based on the execution array and the reference array, a target index corresponding to the bytecode instruction newly executed within the target time period; A line identifier determination module, used to determine a target line identifier corresponding to a target source code line newly executed within the target time period based on an index table corresponding to the program to be tested and the target index; A line coverage determination module is used to determine the line coverage corresponding to the program to be tested based on the target line identifier.
8. 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 6 are implemented.
9. 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 6 are implemented.
10. A computer program product, comprising a computer program, 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 6 are implemented.
Citation Information
Patent Citations
Code coverage rate processing method and device, server and storage medium
CN111290943A
Code coverage rate detection method and device
CN113836006A
Method and device for storing unique index of distributed native graph database
CN117633303A
Method, device, system, and computer program for coverage-guided software fuzzing
US20240012742A1