Code Coverage Determination Method, Device, and Storage Medium
By analyzing and sorting the Go language source code and using post-insert method, the problem of misjudgment and access complexity of Go language coverage tool is solved, and higher test coverage accuracy and adaptability are achieved.
Patent Information
- Application Number
- CN202111223004.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-10-20
- Publication Date
- 2025-07-18
- Estimated Expiration
- 2041-10-20
AI Technical Summary
The existing Go language coverage instrumentation tool has the risk of code not being covered but being misjudged as being covered, the parsing within the function is lost, the branch coverage is incomplete, and the access process requires manual transformation by the user, so it cannot be adapted to multiple compilation methods.
By analyzing the source code, building an abstract syntax tree, determining the code blocks and sorting them, the last code statement is used as the current statement to insert the coverage counter, and the post-insert method is adopted to ensure that the coverage counter is inserted at the end of the code block, reducing the probability of misjudgment.
Effectively reduce the probability that uncovered code statements are misjudged as covered, improve the accuracy of test coverage, adapt to multiple compilation methods, and support white box and black box testing scenarios.
Smart Images

Figure CN113946516B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular, to a method, device, and storage medium for determining code coverage. Background Art
[0002] Existing code coverage instrumentation tools for the Go language all have a significant risk that code that is not covered is misjudged as covered; in the parsing and identification of code statements, there are also situations where parsing within a function is lost and branch coverage is incomplete; moreover, the coverage data has a single dimension and lacks more value for assisting testing; in addition, during the access process, users need to perform a lot of manual modification, and even limited by the structure of the source code, the compilation and deployment methods, it is impossible to implement instrumentation.
[0003] Therefore, it is necessary to provide a method, device, and storage medium for determining code coverage, which can effectively reduce the probability that uncovered code statements are misjudged as covered statements, and greatly improve the accuracy of test coverage. Summary of the Invention
[0004] This application provides a method, device, and storage medium for determining code coverage, which can reduce the probability that uncovered code statements are misjudged as covered statements, and greatly improve the accuracy of test coverage.
[0005] On the one hand, this application provides a method for determining code coverage, and the method includes:
[0006] Obtain the source code of the target application;
[0007] Parse the source code to obtain code blocks; the code blocks include at least two code statements;
[0008] Based on the sorting result, use the code statement at the end of the sorting as the current code statement;
[0009] If the current code statement is a target statement type, insert a coverage counter after the current code statement to obtain the instrumented code;
[0010] Based on the instrumented code, determine the coverage of the source code.
[0011] On the other hand, a device for determining code coverage is provided, and the device includes:
[0012] A source code acquisition module for obtaining the source code of the target application;
[0013] A code parsing module for parsing the source code to obtain code blocks; the code blocks include at least two code statements;
[0014] A sorting result determination module, configured to determine a sorting result of the at least two code statements based on the positions of the at least two code statements in the code block;
[0015] A current code statement determination module, configured to use the code statement at the end of the sorting as the current code statement based on the sorting result;
[0016] A code instrumentation module, configured to insert a coverage counter after the current code statement if the current code statement is a target statement type, to obtain instrumented code;
[0017] A coverage determination module, configured to determine the coverage rate of the source code based on the instrumented code.
[0018] On the other hand, a code coverage determination device is provided. The device includes a processor and a memory. At least one instruction or at least one program segment is stored in the memory. The at least one instruction or the at least one program segment is loaded and executed by the processor to implement the code coverage determination method as described above.
[0019] On the other hand, a computer storage medium is provided. The computer storage medium stores at least one instruction or at least one program segment. The at least one instruction or the at least one program segment is loaded and executed by a processor to implement the code coverage determination method as described above.
[0020] On the other hand, a computer program product or a computer program is provided. The computer program product or the computer program includes computer instructions. The computer instructions are stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes to implement the code coverage determination method as described above.
[0021] The code coverage determination method, device and storage medium provided by this application have the following technical effects:
[0022] This application obtains the source code of a target application; parses the source code to obtain code blocks; the code blocks include at least two code statements; determines a sorting result of the at least two code statements based on the positions of the at least two code statements in the code block; based on the sorting result, uses the code statement at the end of the sorting as the current code statement; if the current code statement is a target statement type, inserts a coverage counter after the current code statement to obtain instrumented code; determines the coverage rate of the source code based on the instrumented code; this application starts from the code statement at the end of the code block and inversely traces backward from the end to find a suitable position for inserting the coverage counter, which can effectively reduce the probability that uncovered code statements are misjudged as covered statements, and greatly improve the accuracy of the test coverage rate. Brief Description of the Drawings
[0023] To more clearly illustrate the technical solutions and advantages in the embodiments of the present application or the prior art, the drawings required for the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings in the following description are only some embodiments of the present application. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.
[0024] Figure 1 It is a schematic diagram of a code coverage determination system provided by an embodiment of the present application;
[0025] Figure 2 It is a schematic flowchart of a code coverage determination method provided by an embodiment of the present application;
[0026] Figure 3 It is a schematic flowchart of a method for obtaining a target code set provided by an embodiment of the present application;
[0027] Figure 4 It is a schematic flowchart of a method for obtaining instrumented code provided by an embodiment of the present application;
[0028] Figure 5 It is a schematic flowchart of a method for instrumenting a coverage counter provided by an embodiment of the present application;
[0029] Figure 6 It is a schematic diagram of the coverage display result of instrumenting a coverage counter at the pre-position of a code block provided by an embodiment of the present application;
[0030] Figure 7 It is a schematic diagram of the parsing result of a code block including an inline function provided by an embodiment of the present application;
[0031] Figure 8 It is a schematic diagram of the instrumentation result of a code statement with only "if" and no "else" provided by an embodiment of the present application;
[0032] Figure 9 It is a schematic flowchart of a coverage instrumentation method provided by an embodiment of the present application;
[0033] Figure 10 It is a schematic diagram of the source code parsing before instrumentation provided by an embodiment of the present application;
[0034] Figure 11 It is provided by an embodiment of the present application Figure 10 Schematic diagram of the instrumentation method of the parsed source code;
[0035] Figure 12 It is provided by an embodiment of the present application Figure 10Schematic diagram of the full-scale instrumentation method for the parsed source code;
[0036] Figure 13 It is a comparison diagram between the code instrumentation method provided by the embodiments of the present application and the existing code instrumentation methods;
[0037] Figure 14 It is a schematic flowchart of the instrumentation method for code statements in a code block provided by the embodiments of the present application;
[0038] Figure 15 It is a schematic flowchart of a method for constructing a set of executable lines in a code block for an embedded function provided by the embodiments of the present application;
[0039] Figure 16 It is a schematic flowchart of a method for uniformly converting the three typical conditional grammars of "if", "else if", and "else" into "if" and "else" provided by the embodiments of the present application;
[0040] Figure 17 It is a schematic flowchart of a comparison diagram of the instrumentation method before and after grammar conversion provided by the embodiments of the present application;
[0041] Figure 18 It is a schematic diagram of the coverage test results of the Griffin coverage platform provided by the embodiments of the present application;
[0042] Figure 19 It is a schematic diagram of the coverage test results of the coverage platform of a music application provided by the embodiments of the present application;
[0043] Figure 20 It is a schematic structural diagram of a code coverage determination device provided by the embodiments of the present application;
[0044] Figure 21 It is a schematic structural diagram of a server provided by the embodiments of the present application. Detailed implementation manners
[0045] The explanations of the professional terms involved in the present application are as follows:
[0046] Instrumentation: Insert some probes (also known as "probes", which are essentially code segments for information collection, and can be assignment statements or function calls for collecting coverage information) into the source code on the basis of ensuring the original logical integrity of the source code under test. By executing the probes, characteristic data of the program running can be obtained. Through the analysis of these data, the control flow and data flow information of the program can be obtained, and then dynamic information such as logical coverage can be obtained.
[0047] Code block: It is a component of a program running logic, and is composed of multiple code statements.
[0048] Coverage counter: A coverage counter refers to a probe added by a testing tool to count the number of executions of a specified code block in the source code under test.
[0049] Next, the technical solutions in the embodiments of the present application will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present application.
[0050] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and do not necessarily need to be used to describe a specific order or sequence. It should be understood that such data can be interchanged under appropriate circumstances so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or server including a series of steps or units does not necessarily have to be limited to those steps or units clearly listed, but may include other steps or units not clearly listed or inherent to these processes, methods, products, or devices.
[0051] Please refer to Figure 1 , Figure 1 which is a schematic diagram of a code coverage determination system provided by an embodiment of the present application. As Figure 1 shown, the code coverage determination system may at least include a server 01 and a client 02.
[0052] Specifically, in the embodiment of the present application, the server 01 may include an independently operating server, or a distributed server, or a server cluster composed of multiple servers, and may also be a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms. The server 01 may include a network communication unit, a processor, a memory, and so on. Specifically, the server 01 may be used to determine the coverage rate of the source code in the application program by performing post-instrumentation on the source code of the application program.
[0053] Specifically, in the embodiments of the present application, the client 02 may include physical devices such as smart phones, desktop computers, tablet computers, laptop computers, digital assistants, smart wearable devices, smart speakers, vehicle-mounted terminals, smart TVs, etc., or may include software running on the physical devices, such as web pages provided by some service providers to users, or may also be applications provided by these service providers to users. Specifically, the client 02 may be used to query the code coverage rate of the source code in the application program online.
[0054] The following introduces a method for determining code coverage rate in the present application. Figure 2 FIG. is a schematic flowchart of a method for determining code coverage rate provided by an embodiment of the present application. This specification provides the method operation steps as described in the embodiment or flowchart, but based on routine or non-creative labor, it may include more or fewer operation steps. The step order listed in the embodiment is only one way among the execution orders of numerous steps, and does not represent the only execution order. When the actual system or server product is executed, it may be executed in the order of the method shown in the embodiment or the accompanying drawings, or executed in parallel (for example, in an environment of parallel processors or multi-threaded processing). Specifically, as Figure 2 shown, the method may include:
[0055] S201: Obtain the source code of the target application program.
[0056] In the embodiments of the present application, the target application program may be an application program in the client, and may include but not be limited to news application programs, music application programs, game application programs, video application programs, etc. The source code may be code in the Go language; the Go (also known as Golang) language is a statically strongly typed, compiled language.
[0057] In the embodiments of the present application, parsing the above source code to obtain code blocks includes:
[0058] Determine the conditional statements in the above source code.
[0059] In the embodiments of the present application, the conditional statement is a statement including special characters "if", "elseif" or "else".
[0060] Determine the preset syntax of the above conditional statement.
[0061] In the embodiments of the present application, the preset syntax of the conditional statement may be determined according to the special characters in the conditional statement. The preset syntax includes target syntax and non-target syntax; if the conditional statement includes "if" and "else", determine that the preset syntax is the target syntax; otherwise, determine it as the non-target syntax; for example, if it only includes "if", "else if" or "else", then determine it as the non-target syntax.
[0062] If the above preset syntax is not the target syntax, convert the above conditional statement into a statement in the target syntax to obtain the source code after syntax conversion.
[0063] In the embodiments of the present application, the three syntaxes of "if", "elseif", and "else" can be uniformly converted into the target syntax logic of "if" and "else".
[0064] Parse the source code after the above syntax conversion to obtain the above code block.
[0065] In the embodiments of the present application, if the preset syntax is the target syntax, directly parse the source code into a code block.
[0066] In the related art, when performing branch statement instrumentation, when the branch statement is a situation with only "if" and no "else", the native Go go test coverage scheme can only instrument the code block within "if", so it can only identify whether the situation where the branch condition is true is covered; the situation where other branch conditions are false cannot be determined; in a specific embodiment, as Figure 8 shown, instrumentation is only performed within the code block where "if(a>b)" is true, and the situation where other branch conditions are false cannot be instrumented. The condition coverage logic table of this example is shown in Table 1:
[0067] Table 1
[0068] Condition Status Coverage Instrumentation(1,2,3...,n) a>b Covered Executed a > b is not covered, a <= b is not covered Not Executed a <= b not covered Not Executed
[0069] It can be seen from Table 1 that such an instrumentation scheme cannot identify whether the state of "a <= b" is executed, and the bottleneck of single-point instrumentation of conditional statements is very obvious, which will cause the loss of branch coverage data.
[0070] In addition, in the manual test scenario of the native Go go test coverage scheme for background services, it is necessary to transform the program's running entry function by wrapping it in a test function, which has a certain learning and access cost, and such a transformation is difficult to adapt to services with a compilation method other than the go build compilation method. In addition, the modified go test scheme needs to close the service process after the service starts to obtain the coverage data product, and it is impossible to obtain the coverage data in real time during the running of the service process, which also contradicts the user's requirement that the coverage tool does not affect the stable operation of the background service.
[0071] In the embodiments of the present application, for statements with only "if" and no "else", a code block structure information for automatically supplementing "else" is uniquely designed and implemented, and a characteristic instrumentation of a coverage counter is performed inside it. Such a two-point instrumentation for branch coverage can provide users with branch coverage information in more dimensions, ensure the integrity of condition coverage, thereby improving the integrity of instrumentation and the accuracy of the determined code coverage rate.
[0072] S203: Parse the above source code to obtain code blocks; the above code blocks include at least two code statements.
[0073] In the embodiments of the present application, the parsing the source code to obtain code blocks includes:
[0074] Based on the source code, construct an abstract syntax tree;
[0075] Based on the abstract syntax tree, determine at least two code blocks, and each code block includes at least two code statements.
[0076] In the embodiments of the present application, the source code can be parsed into an abstract syntax tree, and then based on the abstract syntax tree, code blocks are determined, and each code block is composed of multiple code statements.
[0077] In the embodiments of the present application, the above method further includes:
[0078] Based on the position information of each code block in the abstract syntax tree, sort the at least two code blocks;
[0079] In the embodiments of the present application, according to the position information of the code block in the abstract syntax tree, the code block closer to the root node can be sorted earlier, and the code block closer to the leaf node can be sorted later. The sorting in this embodiment does not disrupt the positions of each code block in the source code.
[0080] Based on the sorting result of the code blocks, perform instrumentation on each code block in sequence.
[0081] In the embodiments of the present application, according to the position information of the code block, starting from the code block with a higher position, perform instrumentation on the code statements of the target type in each code block in sequence. The instrumentation in the embodiments of the present application all refers to instrumenting a coverage counter.
[0082] S205: Based on the positions of the above at least two code statements in the above code block, determine the sorting result of the above at least two code statements.
[0083] In the embodiments of the present application, the code statements can be sorted in sequence according to their positions in the code block. The code statements with a higher position are ranked in the front, and the code statements with a lower position are ranked in the back. The positions of the code statements in the code block are not changed during the sorting process.
[0084] In the embodiments of the present application, there can be at least two code blocks. The sorting results of the respective code statements in each code block can be determined based on the positions of at least two code statements corresponding to each code block in each code block.
[0085] In the embodiments of the present application, when there are multiple code blocks, the code statements of the target type in each code block can be instrumented in sequence according to the position order of the code blocks in the source code, so as to ensure that a coverage counter is instrumented in each code block and improve the accuracy of the determined coverage rate of the source code.
[0086] In the embodiments of the present application, as Figure 3 shown, the above code block includes an embedded function, and the above method further includes:
[0087] S301: Determine the start code line and the end code line of the above code block;
[0088] S303: Determine the start code line and the end code line of the above embedded function;
[0089] In the embodiments of the present application, an embedded function is a function embedded in a code block. The embedded function can include at least one code statement, and the embedded function can be one or multiple.
[0090] In the embodiments of the present application, if there are M above embedded functions, M≥2 and M is a positive integer, the determination of the start code line and the end code line of the above embedded function includes:
[0091] Traverse the embedded functions in the above code block;
[0092] Determine the start code line and the end code line of the first embedded function to the Mth embedded function during the traversal.
[0093] In the embodiments of the present application, the start code line and the end code line of the first embedded function, the second embedded function,..., the Mth embedded function can be determined.
[0094] In the embodiments of the present application, the determination of the start code line and the end code line of the first embedded function to the Mth embedded function during the traversal includes:
[0095] Determine the first target end code line of the first target embedded function; the first target embedded function includes the first embedded function, the (M-1)th embedded function, and the functions between the first embedded function and the (M-1)th embedded function;
[0096] Take the embedded function that is located after the above first target embedded function and adjacent to the above first target embedded function as the second target embedded function;
[0097] Determine the second target starting code line of the above second target embedded function.
[0098] S305: Obtain the code between the starting code line of the above code block and the starting code line of the above embedded function to obtain a first code set;
[0099] In the embodiments of the present application, the above-mentioned obtaining the code between the starting code line of the above code block and the starting code line of the above embedded function to obtain a first code set includes:
[0100] Obtain the code between the starting code line of the above code block and the starting code line of the first embedded function to obtain a first code set.
[0101] In the embodiments of the present application, the code between the starting code line of the above code block and the starting code line of the first starting code line can be combined into a first code set.
[0102] S307: Obtain the code between the ending code line of the above embedded function and the ending code line of the above code block to obtain a second code set;
[0103] In the embodiments of the present application, the above-mentioned obtaining the code between the ending code line of the above embedded function and the ending code line of the above code block to obtain a second code set includes:
[0104] Obtain the code between the ending code line of the Mth embedded function and the ending code line of the above code block to obtain a second code set.
[0105] In the embodiments of the present application, the code between the ending code line of the last embedded function and the ending code line of the above code block can be combined to obtain a second code set.
[0106] S309: Concatenate the above first code set and the above second code set to obtain a target code set.
[0107] In the embodiments of the present application, as Figure 4 shown, the above-mentioned concatenating the above first code set and the above second code set to obtain a target code set includes:
[0108] S3091: Obtain the code between the above first target ending code line and the above second target starting code line to obtain a target embedded code set;
[0109] In the embodiments of the present application, the target embedded code set can be one or more, and the number of target embedded code sets is determined based on the first target embedded function.
[0110] In the embodiments of the present application, when M = 2, the code between the end code line of the first embedded function and the start code line of the second embedded function can be determined as the target embedded code set.
[0111] S3093: Concatenate the above first code set, the above second code set, and the above target embedded code set to obtain the above target code set.
[0112] In a specific embodiment, if there are three embedded functions, the code between the end code line of the first embedded function and the start code line of the second embedded function can be obtained to get the first embedded code set;
[0113] Obtain the code between the end code line of the second embedded function and the start code line of the third embedded function to get the second embedded code set;
[0114] Obtain the code between the end code line of the third embedded function and the start code line of the fourth embedded function to get the third embedded code set;
[0115] The above concatenating the above first code set, the above second code set, and the above target embedded code set to obtain the above target code set may include:
[0116] Concatenate the above first code set, the above second code set, the first embedded code set, the second embedded code set, and the third embedded code set to obtain the above target code set.
[0117] In the embodiments of the present application, the code between all adjacent embedded functions can be obtained to get the embedded code set.
[0118] In the related art, the syntax of the Go language supports passing an embedded function as a parameter to another function. When the native coverage scheme of Go parses the code statement structure of a function and performs coverage instrumentation, if there is another function structure in the function input parameters, it will damage the code statement structure of its context, resulting in incomplete parsing of the code block and causing loss of some code line information. The lost code lines will be classified as non-executable code lines or invalid lines and are not included in the calculation of the numerator and denominator of the coverage rate, thus causing inaccurate coverage rate data. In a specific embodiment, such as Figure 7As shown, within the function input parameters, the inner function code block m is inserted into code block n. When the native Go test coverage scheme parses this code, it can only parse the first half of code block n and the embedded code block m, and cannot recognize the code lines after the embedded code block m. As a result, the second half of code block n truncated by code block m is lost and cannot be recognized as executable code lines for the coverage calculation denominator, thus causing distortion of the coverage data.
[0119] In the embodiment of the present application, when there is an inner function in the code block, it will cause the code statements in the code block to be split, resulting in the situation of lost code lines. At this time, the code statements in the code block except the inner function can be spliced to obtain the target code set, and then instrumentation is performed to improve the accuracy of instrumentation.
[0120] In the embodiment of the present application, the above-mentioned inner function includes at least two first code statements, and the above-mentioned target code set includes at least two second code statements; determining the sorting result of the above-mentioned at least two code statements based on the positions of the above-mentioned at least two code statements in the above-mentioned code block includes:
[0121] Determining the sorting result of the above-mentioned at least two first code statements based on the positions of the above-mentioned at least two first code statements in the above-mentioned inner function;
[0122] Determining the sorting result of the above-mentioned at least two second code statements based on the positions of the above-mentioned at least two second code statements in the above-mentioned target code set.
[0123] S207: Based on the above sorting result, use the code statement at the end of the sorting as the current code statement.
[0124] S209: If the above current code statement is of the target statement type, insert a coverage counter after the above current code statement to obtain the instrumented code.
[0125] In the embodiment of the present application, the target statement type may include expression statements, declaration statements, assignment statements, etc.; different priority levels of code statements of different target statement types can also be set; for example, first determine whether the current code statement is an expression statement; if so, perform instrumentation; if not, continue to determine whether the current code statement is a declaration statement; if so, perform instrumentation; if not, continue to determine whether the current code statement is an assignment statement, if so, perform instrumentation; if not, continue to determine the previous code statement before the current code statement.
[0126] In the embodiment of the present application, starting from the code statement at the end of the code block and searching backwards to find the appropriate position for inserting the coverage counter can effectively reduce the probability that uncovered code statements are misjudged as covered statements.
[0127] In the embodiment of the present application, as Figure 5 shown, after using the last sorted code statement as the current code statement based on the above sorting result, the method further includes:
[0128] S2081: Determine the statement type of the current code statement;
[0129] In the embodiment of the present application, the statement type may include a target statement type and a non-target statement type. The target statement type may include an expression statement, a declaration statement, an assignment statement, etc.; the non-target statement type may include code statements with interruptions or exits such as "continue", "return", "break", etc. at the end.
[0130] S2083: If the current code statement is of the non-target statement type, obtain the previous code statement located before the current code statement, and use the previous code statement as the current code statement again;
[0131] S2085: Repeat the step of determining the statement type of the current code statement.
[0132] In the embodiment of the present application, if there are interruptions or exit statements such as "continue", "return", "break", etc. at the end of a code statement of the target statement type, the coverage counter is accurately instrumented in front of such statements, so that when an interruption or exit statement occurs, the coverage counter cannot be executed, thereby avoiding the risk of significant coverage distortion where uncovered code statements are misjudged as covered.
[0133] In the embodiment of the present application, if the current code statement is of the non-target statement type, continue to judge the previous code statement until a code statement of the target statement type is found.
[0134] S2011: Determine the coverage rate of the source code based on the instrumented code.
[0135] In the related art, the coverage rate scheme of Go's test (go test) only supports white box testing (unit testing) by default. The basic principle is as follows: The source code is first parsed with an abstract syntax tree and divided into several code blocks, and then the native Go go toolcover (terminal display tool) is used to instrument the coverage counter in front of each code block. When the program runs and a code block is executed, the coverage counter will be triggered first, and all the code statements included in the code block after the counter will be determined to have been executed and covered.
[0136] In the scenario of non-white box testing (i.e., black box testing such as interface, system, and manual testing), the current mainstream method for obtaining the code coverage rate of the Go language is to modify the go test coverage scheme. The specific steps are to wrap the program entry function in a test function, implement coverage instrumentation by compiling the binary program with go test, then run the compiled service for testing. After the testing is completed, the service process needs to be shut down to obtain the corresponding coverage products. The native go test coverage scheme in Go uses a scheme of inserting a coverage counter at the front position of the code block. During the process of collecting code coverage during program execution, before executing the code block under test, the pre-positioned counter will be executed first. If the counter is executed, the go test coverage scheme will determine that all statements within the code block under test have been covered, and then execute the code statements within the actual code block under test. In a specific embodiment, as Figure 6 shown, if certain statements encounter exceptions or interruptions when executing the code block under test, the code statements after the exception statements, although not executed, will be determined to have been covered because the coverage counter inserted at the front has been covered. This leads to a significant coverage distortion where uncovered code statements are misjudged as covered.
[0137] In white box testing, if the program encounters code exceptions or interruptions during runtime, the reasons for the abnormal execution of the program can be located and analyzed based on the information of the code under test. However, in black box testing such as interface and system testing, it is difficult to accurately locate the reasons for program abnormal interruptions from the outside, and it is even difficult to detect that the program has encountered abnormal interruptions. Therefore, the misjudgment of the pre-insertion scheme in this scenario of program abnormal interruption will lead to a serious reduction in the reliability of the test coverage rate.
[0138] In the embodiment of this application, the coverage rate of the source code can be determined by running the code with post-insertion. It can avoid the risk of misjudgment of uncovered code in principle, and can effectively and significantly reduce the significant coverage distortion risk that uncovered code statements are misjudged as covered, greatly improving the reliability of the test coverage rate. And only insert the coverage counter for the source code itself, export the coverage data collected in real time after program execution to a cache file, without damaging the source code structure and maintaining the original compilation and deployment methods of the source code. Therefore, it can significantly improve the efficiency of accessing the coverage rate of Go language projects for various frameworks.
[0139] In the embodiment of this application, as Figure 9 shown, Figure 9 is a flowchart of the method for performing coverage instrumentation on a Go service; using the method of this embodiment to perform instrumentation on the source code of a Go service file to obtain the instrumented source code, then compiling the instrumented source code, and then deploying to obtain the instrumented service file, so that the coverage data can be obtained in real time.
[0140] In the embodiments of the present application, when instrumenting the source code, as Figure 10 - 11 shown, Figure 10 - 11 Figure 4-1 is a parsing flow chart before and after instrumenting the source code; the instrumentation tool will insert the instrumentation code of the coverage counter into the source code on the basis of ensuring the integrity of the original logic of the source code to be tested.
[0141] In the embodiments of the present application, as Figure 12 shown, a solution of instrumenting all codes can also be adopted, that is, taking a single line of code as the instrumentation unit, and inserting the coverage counter at the pre-position of each line of code. This solution requires inserting the coverage counter for each line, resulting in a large amount of code and a long overall instrumentation time, with low efficiency; during program operation, the amount of coverage data statistics is large, which affects the performance of reading and analyzing the coverage data.
[0142] In the embodiments of the present application, as Figure 13 shown, Figure 13 Figure 4-2 is a comparison diagram of the code instrumentation method in this embodiment and the existing code instrumentation method; during coverage instrumentation, the traditional pre-position instrumentation within the code block is replaced with a new post-position instrumentation solution. In the present invention, the position of the coverage counter instrumentation is changed from the pre-position to the post-position. If there are statements such as "continue", "return", "break", etc. at the end of the code block, the present invention will accurately instrument the coverage counter before such statements, so that when the interruption or exit statement occurs, the coverage counter cannot be executed, thus avoiding the significant risk of coverage distortion where uncovered code statements are misjudged as covered.
[0143] In the embodiments of the present application, as Figure 14 shown, Figure 14 Figure 4-3 is a schematic flow chart of the instrumentation method for code statements in a code block in this embodiment. The instrumentation strategy is to use the post-position as the starting point, and identify and judge the instrumentation position for each statement one by one from bottom to top in reverse order. The specific steps are as follows:
[0144] S1401: Parse any code block in the source code into n code statements, including code statements 1, 2, 3, 4,..., n - 1, n;
[0145] S1403: According to the reverse order of the code statements, judge the statement type and perform the instrumentation operation on each code statement in turn; take code statement n as the starting statement and judge whether this statement is an expression statement;
[0146] S1405: If it is an expression statement, insert the coverage counter behind code statement n;
[0147] S1407: If it is not an expression statement, continue to judge whether code statement n is a declaration statement;
[0148] S1409: If it is a declaration statement, then insert a coverage counter after code statement n;
[0149] S1411: If it is not a declaration statement, continue to determine whether code statement n is an assignment statement;
[0150] S1413: If it is an assignment statement, then insert a coverage counter after code statement n;
[0151] S1415: If it is not an assignment statement, then assign n - 1 to n in the code statement, and determine whether n is 0 after the assignment;
[0152] S1417: If n is 0 after the assignment and no instrumentation operation has been performed before this, then determine to perform pre-instrumentation before code statement 1;
[0153] S1419: If n is non-zero after the assignment, then repeat the steps from step S1403 where code statement n is used as the starting statement to determine whether the statement is an expression statement to step S1415.
[0154] In the embodiments of the present application, the accuracy of coverage instrumentation and collection can be significantly improved as a whole, and the misjudgment of uncovered code can be reduced.
[0155] In the embodiments of the present application, as Figure 15 shown, for the case where code statements are inserted by other code blocks, resulting in the splitting of code lines, the present invention adopts a parsing strategy of temporarily storing the cut code lines, and then identifying, filtering, and splicing the complete set of code lines corresponding to the code statement.
[0156] The merging strategy includes three parts:
[0157] 1. The set of code lines between the starting line of the code statement and the starting line of the first embedded code block, 2. Multiple embedded code blocks, that is, the merging of the set of code lines between the end line of the previous one and the starting line of the next one, 3. The set of code lines between the end line of the last embedded code block and the end line of the original code statement. By splicing these three temporarily stored sets of code lines, all the code line information included in the entire code statement can be completely reproduced.
[0158] In the embodiments of the present application, as Figure 16 shown, when the present invention parses conditional statements, it will first follow the conditional statement instrumentation logic of gotest, and first uniformly convert the three typical conditional grammars of "if", "else if", and "else" into the logic of "if" and "else", that is, there are only two states of "true" and "false" for the condition.
[0159] In the embodiments of the present application, as Figure 17As shown, after the above splitting is completed, then implement implicit conditional statement instrumentation with only "if" and no "else". Specifically, the method is to add and display the implicit "else".
[0160] In the embodiments of the present application, after supplementing the "else" statement, instrument within the "else"; that is, instrument within both the "true" and "false" of the conditional statement to ensure that it can be accurately determined whether the conditional statement is covered.
[0161] In the embodiments of the present application, Figure 17 in single-point instrumentation, it is only instrumented within the code block where "if(a>b)" is true. The conditional coverage logic of this example is shown in Table 2:
[0162] Table 2
[0163] Condition Status Coverage Instrumentation(1,2,3...,n) a>b Covered Executed a > b is not covered, a <= b is not covered Not Executed a <= b not covered Not Executed
[0164] In the embodiments of the present application, it can be seen that this method cannot identify whether the state of "a<=b" is executed, and the bottleneck of single-point instrumentation of conditional statements is very obvious, which will cause the loss of branch coverage data.
[0165] In the embodiments of the present application, the conditional coverage logic of the example of the solution of the present invention is shown in Table 3:
[0166] Table 3
[0167] Condition Status Coverage Instrumentation(1,2,3...,n) Instrumentation m a>b Covered Executed Not Executed a>b Not Covered Not Executed / a <= b has been covered Not Executed Executed a <= b not covered / Not Executed
[0168] In the embodiments of the present application, the automatic recognition and supplementation of implicit "else" conditional instrumentation solution of the present invention can provide users with more dimensions of branch coverage information in the parsing and instrumentation of branch statements to ensure the integrity of conditional coverage.
[0169] In the embodiments of the present application, the post-instrumentation method of the present application can be applied to the Griffin coverage platform, and the coverage test results of different files are as Figure 18 shown, including the covered lines, statement coverage rate, and branch coverage rate of each file.
[0170] In the embodiments of the present application, the post-instrumentation method of the present application can also be applied to the coverage platform of a music application, and the obtained coverage test results are as Figure 19 shown, which can display version coverage, requirement coverage, branch coverage, commit coverage, coverage tasks, and coverage configuration information, etc.; in this platform, the file path or file name can be set to search for files, so as to view the total number of lines, line coverage rate, and function coverage rate corresponding to each file, and the detailed coverage information of the corresponding file can be displayed only by clicking on the corresponding "operation" identifier.
[0171] In the embodiments of the present application, the testing personnel can find potential missing test cases by analyzing the uncovered code logic, and enhance the confidence of the testing and development personnel in the code quality and test integrity by supplementing the missing test cases.
[0172] This embodiment can also be applied to the fuzz testing scenario. Fuzz testing is a method of discovering software vulnerabilities by providing unexpected inputs to the target system and monitoring abnormal results. Specifically, the testing personnel use different fuzz testing methods as test cases, and then use this embodiment to obtain the coverage rate and view the code coverage, as well as obtain the coverage frequencies of different code statements, so as to evaluate the effectiveness of the fuzz testing algorithm, which can effectively improve the efficiency of fuzz testing.
[0173] As can be seen from the technical solutions provided by the embodiments of the present application above, the embodiments of the present application obtain the source code of the target application program; parse the above source code to obtain code blocks; the above code blocks include at least two code statements; based on the positions of the above at least two code statements in the above code blocks, determine the sorting result of the above at least two code statements; based on the above sorting result, use the code statement at the end of the sorting as the current code statement; if the above current code statement is the target statement type, insert a coverage counter after the above current code statement to obtain the instrumented code; based on the above instrumented code, determine the coverage rate of the above source code; starting from the code statement at the end of the code block, the embodiments of the present application search backwards to find the appropriate position for inserting the coverage counter, which can effectively reduce the probability that uncovered code statements are misjudged as covered statements, and greatly improve the accuracy of the test coverage rate.
[0174] The embodiments of the present application also provide a device for determining the code coverage rate, as Figure 20 shown, the device includes:
[0175] A source code acquisition module 2010, configured to acquire the source code of the target application program;
[0176] A code parsing module 2020, configured to parse the above source code to obtain code blocks; the above code blocks include at least two code statements;
[0177] A sorting result determination module 2030, configured to determine the sorting result of the above at least two code statements based on the positions of the above at least two code statements in the above code blocks;
[0178] A current code statement determination module 2040, configured to use the code statement at the end of the sorting as the current code statement based on the above sorting result;
[0179] The code instrumentation module 2050 is configured to, if the current code statement is of the target statement type, instrument a coverage counter after the current code statement to obtain the instrumented code;
[0180] The coverage determination module 2060 is configured to determine the coverage rate of the source code based on the instrumented code.
[0181] In some embodiments, the apparatus may further include:
[0182] The statement type judgment module is configured to judge the statement type of the current code statement;
[0183] The previous code statement acquisition module is configured to, if the current code statement is not of the target statement type, acquire the previous code statement located before the current code statement, and re-use the previous code statement as the current code statement;
[0184] The repetition module is configured to repeat the step of judging the statement type of the current code statement.
[0185] In some embodiments, the code block includes an embedded function, and the apparatus may further include:
[0186] The code line determination module of the code block is configured to determine the start code line and the end code line of the code block;
[0187] The code line determination module of the embedded function is configured to determine the start code line and the end code line of the embedded function;
[0188] The first code set determination module is configured to obtain the code between the start code line of the code block and the start code line of the embedded function to obtain a first code set;
[0189] The second code set determination module is configured to obtain the code between the end code line of the embedded function and the end code line of the code block to obtain a second code set;
[0190] The target code set determination module is configured to splice the first code set and the second code set to obtain a target code set.
[0191] In some embodiments, the embedded function includes at least two first code statements, and the target code set includes at least two second code statements; the sorting result determination module may include:
[0192] The first sorting result determination unit is configured to determine the sorting result of the at least two first code statements based on the positions of the at least two first code statements in the embedded function;
[0193] A second sorting result determination unit, configured to determine a sorting result of the at least two second code statements based on the positions of the at least two second code statements in the target code set.
[0194] In some embodiments, there are M nested functions, where M≥2 and M is a positive integer. The code line determination module of the nested functions may include:
[0195] A function traversal unit, configured to traverse the nested functions in the code block;
[0196] A code line determination unit of the nested function, configured to determine the start code line and the end code line of the first nested function to the Mth nested function that are traversed.
[0197] In some embodiments, the first code set determination module may include:
[0198] A first code set determination unit, configured to obtain the code between the start code line of the code block and the start code line of the first nested function, to obtain a first code set.
[0199] In some embodiments, the second code set determination module may include:
[0200] A second code set determination unit, configured to obtain the code between the end code line of the Mth nested function and the end code line of the code block, to obtain a second code set.
[0201] In some embodiments, the code line determination unit of the nested function may include:
[0202] A first target end code line determination subunit, configured to determine a first target end code line of a first target nested function; the first target nested function includes the first nested function, the (M - 1)th nested function, and the functions between the first nested function and the (M - 1)th nested function;
[0203] A second target nested function determination subunit, configured to use the nested function that is located after the first target nested function and is adjacent to the first target nested function as the second target nested function;
[0204] A second target start code line determination subunit, configured to determine a second target start code line of the second target nested function.
[0205] In some embodiments, the target code set determination module may include:
[0206] A target nested code set determination unit, configured to obtain the code between the first target end code line and the second target start code line, to obtain a target nested code set;
[0207] A target code set determination unit, configured to splice the above-mentioned first code set, the above-mentioned second code set, and the above-mentioned target embedded code set to obtain the above-mentioned target code set.
[0208] In some embodiments, the code parsing module may include:
[0209] A conditional statement determination unit, configured to determine the conditional statements in the above-mentioned source code;
[0210] A preset syntax determination unit, configured to determine the preset syntax of the above-mentioned conditional statements;
[0211] A statement conversion unit, configured to convert the above-mentioned conditional statements into statements with a target syntax if the above-mentioned preset syntax is not the target syntax, to obtain the source code after syntax conversion;
[0212] A code block determination unit, configured to parse the above-mentioned source code after syntax conversion to obtain the above-mentioned code block.
[0213] The device in the device embodiment and the method embodiment are based on the same inventive concept.
[0214] An embodiment of the present application provides a code coverage determination device, which includes a processor and a memory. At least one instruction or at least one program segment is stored in the memory, and the at least one instruction or at least one program segment is loaded and executed by the processor to implement the code coverage determination method provided in the above-mentioned method embodiment.
[0215] An embodiment of the present application further provides a computer storage medium, which can be set in a terminal to store at least one instruction or at least one program segment related to implementing a code coverage determination method in the method embodiment. The at least one instruction or at least one program segment is loaded and executed by the processor to implement the code coverage determination method provided in the above-mentioned method embodiment.
[0216] An embodiment of the present application further provides a computer program product or a computer program, which includes computer instructions, and the computer instructions are stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes to implement the code coverage determination method provided in the above-mentioned method embodiment.
[0217] Optionally, in the embodiments of the present application, the storage medium may be located in at least one of multiple network servers of a computer network. Optionally, in this embodiment, the above storage medium may include, but is not limited to: various media that can store program codes such as USB flash drives, read-only memories (ROMs), random access memories (RAMs), mobile hard disks, magnetic disks, or optical discs.
[0218] The memory in the embodiments of the present application can be used to store software programs and modules. The processor executes various functional applications and data processing by running the software programs and modules stored in the memory. The memory mainly includes a program storage area and a data storage area. Among them, the program storage area can store an operating system, application programs required for functions, etc.; the data storage area can store data created according to the use of the device, etc. In addition, the memory may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one magnetic disk storage device, a flash memory device, or other non-volatile solid-state storage devices. Correspondingly, the memory may further include a memory controller to provide the processor with access to the memory.
[0219] The method embodiments for determining code coverage provided by the embodiments of the present application can be executed on a mobile terminal, a computer terminal, a server, or a similar computing device. Taking running on a server as an example, Figure 21 is a hardware structure block diagram of a server for the method for determining code coverage provided by the embodiments of the present application. As Figure 21As shown, the server 2100 can vary significantly depending on configuration or performance, and may include one or more central processing units (CPUs) 2110 (the central processing unit 2110 may include, but is not limited to, processing devices such as a microprocessor MCU or a field programmable gate array FPGA), a memory 2130 for storing data, and one or more storage media 2120 for storing application programs 2123 or data 2122 (such as one or more mass storage devices). Among them, the memory 2130 and the storage media 2120 can be transient storage or persistent storage. The programs stored in the storage media 2120 can include one or more modules, and each module can include a series of instruction operations on the server. Further, the central processing unit 2110 can be configured to communicate with the storage media 2120 and execute a series of instruction operations in the storage media 2120 on the server 2100. The server 2100 can also include one or more power supplies 2160, one or more wired or wireless network interfaces 2150, one or more input / output interfaces 2140, and / or one or more operating systems 2121, such as Windows ServerTM, Mac OS XTM, UnixTM, LinuxTM, FreeBSDTM, and so on.
[0220] The input / output interface 2140 can be used to receive or send data via a network. Specific examples of the above-mentioned network can include a wireless network provided by the communication provider of the server 2100. In one example, the input / output interface 2140 includes a network interface controller (NIC), which can be connected to other network devices through a base station and thus communicate with the Internet. In one example, the input / output interface 2140 can be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.
[0221] Those of ordinary skill in the art can understand that Figure 21 the structure shown is only schematic and does not limit the structure of the above-mentioned electronic device. For example, the server 2100 can also include more or fewer components than those Figure 21 shown, or have a different configuration from those Figure 21 shown.
[0222] As can be seen from the embodiments of the code coverage determination method, device, equipment, or storage medium provided by the present application above, the present application obtains the source code of the target application; parses the above source code to obtain code blocks; the above code blocks include at least two code statements; based on the positions of the above at least two code statements in the above code blocks, determines the sorting result of the above at least two code statements; based on the above sorting result, takes the code statement at the end of the sorting as the current code statement; if the above current code statement is of the target statement type, inserts a coverage counter after the above current code statement to obtain the instrumented code; based on the above instrumented code, determines the coverage rate of the above source code; the present application starts from the code statement at the end of the code block and searches backward to find a suitable position to insert the coverage counter, which can effectively reduce the probability that the uncovered code statements are misjudged as covered statements, and greatly improve the accuracy of the test coverage rate.
[0223] It should be noted that: the above sequence of the embodiments of the present application is only for description and does not represent the superiority or inferiority of the embodiments. And the above specific embodiments of this specification have been described. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be executed in a different order from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or sequential order shown to achieve the desired results. In certain embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0224] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between each embodiment can be referred to each other. Each embodiment focuses on the differences from other embodiments. In particular, for the embodiments of the device, equipment, and storage medium, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiments.
[0225] Those of ordinary skill in the art can understand that all or part of the steps to implement the above embodiments can be completed by hardware, or can be completed by a program instructing relevant hardware. The program can be stored in a computer storage medium, and the above-mentioned storage medium can be a read-only memory, a disk, or an optical disc, etc.
[0226] The above are only the preferred embodiments of the present application and are not intended to limit the present application. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.
Claims
1. A method for determining code coverage, characterized in that, The method includes: Obtain the source code of the target application; Parse the source code to obtain code blocks; the code blocks include at least two code statements; The code blocks include nested functions, determine the start code line and end code line of the code blocks; determine the start code line and end code line of the nested functions; Obtain the code located between the start code line of the code block and the start code line of the nested function to obtain a first code set; Obtain the code located between the end code line of the nested function and the end code line of the code block to obtain a second code set; Concatenate the first code set and the second code set to obtain a target code set; The nested functions include at least two first code statements, and the target code set includes at least two second code statements; based on the positions of the at least two first code statements in the nested functions, determine the sorting result of the at least two first code statements; Based on the positions of the at least two second code statements in the target code set, determine the sorting result of the at least two second code statements; Based on the sorting result of the at least two first code statements and the sorting result of the at least two second code statements, use the code statement at the end of the sorting as the current code statement; If the current code statement is of the target statement type, insert a coverage counter after the current code statement to obtain the instrumented code; Based on the instrumented code, determine the coverage rate of the source code.
2. The method according to claim 1, wherein After using the code statement at the end of the sorting as the current code statement based on the sorting result of the at least two first code statements and the sorting result of the at least two second code statements, the method further includes: Judge the statement type of the current code statement; If the current code statement is not of the target statement type, obtain the previous code statement located before the current code statement, and use the previous code statement as the current code statement again; Repeat the step of judging the statement type of the current code statement.
3. The method according to claim 1, wherein There are M nested functions, M≥2 and M is a positive integer. The determination of the start code line and end code line of the nested functions includes: Traverse the nested functions in the code block; Determine the start code line and end code line of the first nested function to the Mth nested function in the traversal; The obtaining of the code located between the start code line of the code block and the start code line of the nested function to obtain a first code set includes: Obtain the code located between the start code line of the code block and the start code line of the first nested function to obtain a first code set; The obtaining of the code located between the end code line of the nested function and the end code line of the code block to obtain a second code set includes: Obtain the code located between the end code line of the Mth nested function and the end code line of the code block to obtain a second code set.
4. The method according to claim 3, characterized in that, The determination of the start code line and end code line of the first nested function to the Mth nested function in the traversal includes: Determine the first target end code line of the first target embedded function; the first target embedded function includes the first embedded function, the (M - 1)th embedded function, and the functions between the first embedded function and the (M - 1)th embedded function; Take the embedded function that is located after the first target embedded function and adjacent to the first target embedded function as the second target embedded function; Determine the second target start code line of the second target embedded function; The splicing of the first code set and the second code set to obtain the target code set includes: Obtain the code between the first target end code line and the second target start code line to get the target embedded code set; Splice the first code set, the second code set, and the target embedded code set to obtain the target code set.
5. The method according to claim 1, wherein The parsing of the source code to obtain code blocks includes: Determine the conditional statements in the source code; Determine the preset syntax of the conditional statements; If the preset syntax is not the target syntax, convert the conditional statements into statements with the target syntax to obtain the source code after syntax conversion; Parse the source code after syntax conversion to obtain the code blocks.
6. A code coverage determination device, characterized in that, The device includes: A source code acquisition module, configured to acquire the source code of the target application; A code parsing module, configured to parse the source code to obtain code blocks; the code blocks include at least two code statements; A sorting result determination module, configured to determine the sorting result of the at least two code statements based on the positions of the at least two code statements in the code blocks; The code block includes embedded functions, and a code line determination module of the code block, configured to determine the start code line and the end code line of the code block; An embedded function code line determination module, configured to determine the start code line and the end code line of the embedded function; A first code set determination module, configured to obtain the code between the start code line of the code block and the start code line of the embedded function to get the first code set; A second code set determination module, configured to obtain the code between the end code line of the embedded function and the end code line of the code block to get the second code set; A target code set determination module, configured to splice the first code set and the second code set to obtain the target code set; The embedded function includes at least two first code statements, and the target code set includes at least two second code statements; the sorting result determination module includes: A first sorting result determination unit, configured to determine the sorting result of the at least two first code statements based on the positions of the at least two first code statements in the embedded function; A second sorting result determination unit, configured to determine the sorting result of the at least two second code statements based on the positions of the at least two second code statements in the target code set; A current code statement determination module, configured to use the code statement at the end of the sorting as the current code statement based on the sorting result of the at least two first code statements and the sorting result of the at least two second code statements; A code instrumentation module, which is used to instrument a coverage counter after the current code statement if the current code statement is of a target statement type, so as to obtain instrumented code; A coverage determination module, which is used to determine the coverage rate of the source code based on the instrumented code; 7. The device according to claim 6, characterized in that, The device further includes: A statement type judgment module, which is used to judge the statement type of the current code statement; A previous code statement acquisition module, which is used to obtain the previous code statement located before the current code statement and re-use the previous code statement as the current code statement if the current code statement is not of a target statement type; A repetition module, which is used to repeat the step of judging the statement type of the current code statement; 8. The device according to claim 6, characterized in that, There are M nested functions, where M≥2 and M is a positive integer. The code line determination module of the nested functions includes: A function traversal unit, which is used to traverse the nested functions in the code block; A code line determination unit for nested functions, which is used to determine the start code line and the end code line of the first to the Mth nested functions in the traversal; The first code set determination module includes: A first code set determination unit, which is used to obtain the code between the start code line of the code block and the start code line of the first nested function to obtain a first code set; The second code set determination module includes: A second code set determination unit, which is used to obtain the code between the end code line of the Mth nested function and the end code line of the code block to obtain a second code set; 9. The device according to claim 8, characterized in that The code line determination unit for nested functions includes: A first target end code line determination subunit, which is used to determine the first target end code line of the first target nested function; the first target nested function includes the first nested function, the (M - 1)th nested function, and the functions between the first nested function and the (M - 1)th nested function; A second target nested function determination subunit, which is used to use the nested function located after the first target nested function and adjacent to the first target nested function as the second target nested function; A second target start code line determination subunit, which is used to determine the second target start code line of the second target nested function; The target code set determination module includes: A target nested code set determination unit, which is used to obtain the code between the first target end code line and the second target start code line to obtain a target nested code set; A target code set determination unit, which is used to splice the first code set, the second code set, and the target nested code set to obtain the target code set; 10. The device according to claim 6, characterized in that, The code parsing module includes: A conditional statement determination unit, which is used to determine the conditional statements in the source code; A preset syntax determination unit, which is used to determine the preset syntax of the conditional statements; A statement conversion unit, which is used to convert the conditional statements into statements of a target syntax if the preset syntax is not the target syntax, so as to obtain a source code after syntax conversion; A code block determination unit, which is used to parse the source code after syntax conversion to obtain the code block; 11. A computer storage medium, characterized in that, At least one instruction or at least one program segment is stored in the computer storage medium, and the at least one instruction or the at least one program segment is loaded and executed by a processor to implement the code coverage determination method according to any one of claims 1-5.
12. A computer program product, characterized in that, The computer program product includes computer instructions, and when the computer instructions are executed by a processor, the code coverage determination method according to any one of claims 1-5 is implemented.
Citation Information
Patent Citations
Method for acquiring statement and branch coverage during execution of C25 assembly language
CN107391375A