Conditional branch coverage calculation method, device, computer equipment, and storage medium

By obtaining the code type and annotation information of the uncovered conditional branch code lines in the target code and calculating its coverage parameters, the problem of inaccurate conditional branch coverage calculation in the prior art is solved, and a higher precision code test is achieved.

CN117407267BActive Publication Date: 2025-08-15GLENFLY TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202210793302.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-07-07
Publication Date
2025-08-15
Estimated Expiration
2042-07-07

AI Technical Summary

Technical Problem

The existing conditional branch coverage calculation method has low accuracy and cannot meet the code testing needs of high-end projects.

Method used

By obtaining the code type of the conditional branch code line that is not overwritten in the target code, obtaining the corresponding annotation information based on the code type, and calculating the coverage parameters, and finally calculating the conditional branch coverage ratio.

Benefits of technology

It improves the calculation accuracy of conditional branch coverage, can effectively eliminate conditional branch code lines that do not require statistics, and improves the integrity and reliability of code testing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117407267B_ABST
    Figure CN117407267B_ABST
Patent Text Reader

Abstract

The present application relates to a method, apparatus, computer device, storage medium, and computer program product for calculating conditional branch coverage. The method comprises: obtaining the code type of uncovered conditional branch code lines in the target code, and obtaining annotation information corresponding to the uncovered conditional branch code lines based on the code type; obtaining coverage parameters corresponding to the uncovered conditional branch code lines based on the annotation information corresponding to the uncovered conditional branch code lines; and calculating the conditional branch coverage corresponding to the target code based on the coverage parameters corresponding to the uncovered conditional branch code lines and the total number of conditional branch code lines in the target code. This method can eliminate conditional branch code lines that do not need to be counted based on the annotation information corresponding to each conditional branch code line, thereby improving the calculation accuracy of the conditional branch coverage.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a method, apparatus, computer equipment, and storage medium for calculating conditional branch coverage. Background Art

[0002] Generally speaking, in order to ensure project quality, a project needs to undergo several rounds of testing. In addition to common unit testing, integration testing, functional testing, and regression testing, we also need code coverage testing to ensure the integrity and comprehensiveness of code testing. If the code coverage test does not meet the standards, it means that some code has not been fully tested, and these untested codes are likely to contain bugs, resulting in the project quality cannot be guaranteed. This shows the importance of code coverage testing.

[0003] Commonly used statistical metrics for code coverage include function coverage, condition coverage, branch coverage, and statement coverage. Statement coverage and function coverage are calculated by dividing the number of covered statements and functions by the total number of statements and functions, while conditional branch coverage is calculated by dividing the number of covered conditions and branches by the total number of conditions and branches. Conditional branch coverage is generally calculated by dividing the number of conditional branches covered by the code by the total number of conditional branches. However, in some cases, it may be unnecessary or impossible to cover the conditional branches of some code, resulting in inaccurate and unreliable coverage reports that cannot meet the code testing needs of some high-tech projects.

[0004] Currently, the way conditional branch coverage is calculated is not very accurate. Summary of the Invention

[0005] Based on this, it is necessary to provide a conditional branch coverage calculation method, apparatus, computer equipment, computer-readable storage medium and computer program product that can accurately calculate the conditional branch coverage in order to address the above technical problems.

[0006] In a first aspect, the present application provides a method for calculating conditional branch coverage. The method comprises:

[0007] Obtaining code types of uncovered conditional branch code lines in the target code, and obtaining comment information corresponding to the uncovered conditional branch code lines according to the code types;

[0008] Obtaining coverage parameters corresponding to uncovered conditional branch code lines according to comment information corresponding to uncovered conditional branch code lines;

[0009] The conditional branch coverage rate corresponding to the target code is calculated based on the coverage parameters corresponding to the uncovered conditional branch code lines and the total number of conditional branch code lines in the target code.

[0010] In one embodiment, a method for obtaining uncovered conditional branch code lines in the target code includes:

[0011] Get the basic conditional branch coverage of the target code;

[0012] Obtain uncovered conditional branch code lines in the target code based on the base conditional branch coverage of the target code.

[0013] In one embodiment, before obtaining the code type of the uncovered conditional branch code line in the target code and obtaining the comment type corresponding to the uncovered conditional branch code line according to the code type, the method further includes:

[0014] Obtain each conditional branch code line in the target code, and identify the code type of each conditional branch code line in the target code;

[0015] Determine the comment type corresponding to each conditional branch code line according to the code type of each conditional branch code line, and add comment information to each conditional branch code line according to the comment type corresponding to each conditional branch code line in the target code.

[0016] In one embodiment, determining a comment type corresponding to each conditional branch code line according to the code type of each conditional branch code line, and adding comment information to each conditional branch code line according to the comment type corresponding to each conditional branch code line in the target code, includes:

[0017] If the code type of a conditional branch code line is a first code type, determining that the conditional branch code line corresponds to a first comment type, the first comment type includes first comment information, second comment information, third comment information, and fourth comment information, adding one of the first comment information, the second comment information, the third comment information, and the fourth comment information to the conditional branch code line, or not adding any comment information;

[0018] If the code type of a conditional branch code line is the second code type, determining that the conditional branch code line corresponds to the second comment type, the second comment type includes fifth comment information, adding the fifth comment information to the conditional branch code line, or not adding any comment information;

[0019] The first comment information is used to indicate the exclusion of the first part of the corresponding conditional branch code line, the second comment information is used to indicate the exclusion of the second part of the corresponding conditional branch code line, the third comment information is used to indicate the exclusion of the first part or the second part of the corresponding conditional branch code line, the fourth comment information is used to indicate the exclusion of the first part and the second part of the corresponding conditional branch code line, and the fifth comment information is used to indicate the exclusion of the corresponding conditional branch code line.

[0020] In one embodiment, obtaining coverage parameters corresponding to uncovered conditional branch code lines according to annotation information corresponding to uncovered conditional branch code lines includes:

[0021] If the code type of a conditional branch code line is the first code type, obtaining the uncovered type corresponding to the uncovered conditional branch code line, where the uncovered type is divided into first partial coverage, second partial coverage, or complete uncovered;

[0022] If the uncovered conditional branch code line has an uncovered type of coverage of the first partial coverage and the comment information corresponding to the uncovered conditional branch code line is the second comment information, the third comment information, or the fourth comment information, then determining that the coverage parameter corresponding to the uncovered conditional branch code line is 0;

[0023] If the uncovered conditional branch code line corresponds to the uncovered uncovered type of coverage, and the comment information corresponding to the uncovered conditional branch code line is not the second comment information, the third comment information, or the fourth comment information, then determining that the coverage parameter corresponding to the uncovered conditional branch code line is -1;

[0024] If the uncovered conditional branch code line has an uncovered type of coverage of the second partial coverage, and the comment information corresponding to the uncovered conditional branch code line is the first comment information, the third comment information, or the fourth comment information, then determining that the coverage parameter corresponding to the uncovered conditional branch code line is 0;

[0025] If the uncovered conditional branch code line has an uncovered type of coverage of the second partial coverage, and the comment information corresponding to the uncovered conditional branch code line is not the first comment information, the third comment information, or the fourth comment information, then determining that the coverage parameter corresponding to the uncovered conditional branch code line is -1;

[0026] If the uncovered conditional branch code line has an uncovered type of fully uncovered, and the comment information corresponding to the uncovered conditional branch code line is the fourth comment information, determining that the coverage parameter corresponding to the uncovered conditional branch code line is 0;

[0027] If the uncovered conditional branch code line has an uncovered type of fully uncovered, and the comment information corresponding to the uncovered conditional branch code line is the first comment information, the second comment information, or the third comment information, then determining that the coverage parameter corresponding to the uncovered conditional branch code line is -1;

[0028] If the uncovered conditional branch code line corresponds to an uncovered uncovered type, and the comment information corresponding to the uncovered conditional branch code line is not the first comment information, the second comment information, the third comment information, or the fourth comment information, then determining that the coverage parameter corresponding to the uncovered conditional branch code line is -2;

[0029] If the code type of a conditional branch code line is the second code type, and the comment information corresponding to the uncovered conditional branch code line is the fifth comment information, determining that the coverage parameter corresponding to the uncovered conditional branch code line is 0;

[0030] If the code type of a conditional branch code line is the second code type, and the comment information corresponding to the uncovered conditional branch code line is not the fifth comment information, the coverage parameter corresponding to the uncovered conditional branch code line is determined to be -1.

[0031] In one embodiment, calculating the conditional branch coverage of the target code based on the coverage parameters corresponding to the uncovered conditional branch code lines and the total number of conditional branch code lines in the target code includes:

[0032] Calculate the conditional branch coverage number corresponding to the target code by adding the total number of conditional branch code lines in the target code and the coverage parameter corresponding to each uncovered conditional branch code line in the target code;

[0033] The conditional branch coverage rate corresponding to the target code is calculated based on the ratio of the conditional branch coverage number corresponding to the target code and the total number of conditional branch code lines in the target code.

[0034] In a second aspect, the present application further provides a device for calculating conditional branch coverage. The device comprises:

[0035] A comment recognition module is used to obtain the code type of the uncovered conditional branch code line in the target code, and obtain the comment information corresponding to the uncovered conditional branch code line according to the code type;

[0036] A parameter calculation module, configured to obtain coverage parameters corresponding to uncovered conditional branch code lines based on annotation information corresponding to the uncovered conditional branch code lines;

[0037] The coverage calculation module is used to calculate the conditional branch coverage rate corresponding to the target code based on the coverage parameters corresponding to the uncovered conditional branch code lines and the total number of conditional branch code lines in the target code.

[0038] In a third aspect, the present application further provides a computer device. The computer device includes a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the following steps are performed:

[0039] Obtaining code types of uncovered conditional branch code lines in the target code, and obtaining comment information corresponding to the uncovered conditional branch code lines according to the code types;

[0040] Obtaining coverage parameters corresponding to uncovered conditional branch code lines according to comment information corresponding to uncovered conditional branch code lines;

[0041] The conditional branch coverage rate corresponding to the target code is calculated based on the coverage parameters corresponding to the uncovered conditional branch code lines and the total number of conditional branch code lines in the target code.

[0042] In a fourth aspect, the present application further provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the following steps:

[0043] Obtaining code types of uncovered conditional branch code lines in the target code, and obtaining comment information corresponding to the uncovered conditional branch code lines according to the code types;

[0044] Obtaining coverage parameters corresponding to uncovered conditional branch code lines according to comment information corresponding to uncovered conditional branch code lines;

[0045] The conditional branch coverage rate corresponding to the target code is calculated based on the coverage parameters corresponding to the uncovered conditional branch code lines and the total number of conditional branch code lines in the target code.

[0046] In a fifth aspect, the present application further provides a computer program product. The computer program product includes a computer program that, when executed by a processor, implements the following steps:

[0047] Obtaining code types of uncovered conditional branch code lines in the target code, and obtaining comment information corresponding to the uncovered conditional branch code lines according to the code types;

[0048] Obtaining coverage parameters corresponding to uncovered conditional branch code lines according to comment information corresponding to uncovered conditional branch code lines;

[0049] The conditional branch coverage rate corresponding to the target code is calculated based on the coverage parameters corresponding to the uncovered conditional branch code lines and the total number of conditional branch code lines in the target code.

[0050] The above-mentioned conditional branch coverage calculation method, apparatus, computer device, storage medium, and computer program product obtain the code type of uncovered conditional branch code lines in the target code, obtain annotation information corresponding to the uncovered conditional branch code lines based on the code type; obtain coverage parameters corresponding to the uncovered conditional branch code lines based on the annotation information corresponding to the uncovered conditional branch code lines; and calculate the conditional branch coverage corresponding to the target code based on the coverage parameters corresponding to the uncovered conditional branch code lines and the total number of conditional branch code lines in the target code. The method can exclude conditional branch code lines that do not need to be counted based on the annotation information corresponding to each conditional branch code line, thereby improving the calculation accuracy of the conditional branch coverage. BRIEF DESCRIPTION OF THE DRAWINGS

[0051] Figure 1 1 is a flow chart of a method for calculating conditional branch coverage in one embodiment;

[0052] Figure 2 A schematic diagram showing the effect of a method for adding annotation information according to an embodiment;

[0053] Figure 3 A schematic diagram of the effect of a method for adding batch annotation information in one embodiment;

[0054] Figure 4 is a structural block diagram of a device for calculating conditional branch coverage in one embodiment;

[0055] Figure 5 FIG. 1 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION

[0056] In order to make the purpose, technical solutions and advantages of this application more clear, the following further describes this application in detail with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain this application and are not intended to limit this application.

[0057] In one embodiment, Figure 1 As shown, a method for calculating conditional branch coverage is provided. This embodiment uses the method applied to a terminal as an example for illustration. It is understandable that the method can also be applied to a server, or to a system including a terminal and a server, and implemented through interaction between the terminal and the server. In this embodiment, the method includes the following steps:

[0058] Step 102: Obtain the code type of the uncovered conditional branch code line in the target code, and obtain the comment information corresponding to the uncovered conditional branch code line according to the code type.

[0059] The code type refers to the conditional branch statement type of the conditional branch code line, including if statements (condition / decision), switch statements (switch / case), ternary operators, etc. The uncovered conditional branch code lines are obtained by calculating the basic conditional branch coverage of the target code using existing code coverage calculation methods.

[0060] Specifically, based on the test requirements, annotation information is first added to the target code for the code lines that do not need to be covered. The annotation information is used to indicate the exclusion of the corresponding conditional branch code line or the exclusion of a branch of the corresponding conditional branch code line. Then, the target code is subjected to conditional branch coverage calculation using the existing code coverage calculation method. While obtaining the basic conditional branch coverage of the target code, all uncovered conditional branch code lines in the target code can be determined. For example, Bullseye software is used to calculate the conditional branch coverage of the target code. The code type of each uncovered conditional branch code line in the target code is identified, and the annotation information corresponding to each uncovered conditional branch code line is detected and identified based on the code type.

[0061] Step 104 : Obtain coverage parameters corresponding to the uncovered conditional branch code lines according to the annotation information corresponding to the uncovered conditional branch code lines.

[0062] The absolute value of the coverage parameter represents the number of units corresponding to a conditional branch code line when counting code statements. The coverage parameter is usually 0, -1, and -2.

[0063] Specifically, based on the comment information corresponding to an uncovered conditional branch code line, it can be determined whether the uncovered conditional branch code line is excluded. Exclusion means that the excluded part does not need to be calculated into the code coverage. When conditional branch code lines of some code types are excluded, it is also divided into two situations: all code lines are excluded and one branch of the code line is excluded. The comment information corresponding to conditional branch code lines of different code types is different. Therefore, the code type and exclusion situation can be determined based on the comment information of the uncovered conditional branch code line, thereby determining the coverage parameters corresponding to the uncovered conditional branch code line. Similarly, the coverage parameters corresponding to each uncovered conditional branch code line can be determined.

[0064] Step 106 , calculating the conditional branch coverage rate corresponding to the target code based on the coverage parameters corresponding to the uncovered conditional branch code lines and the total number of conditional branch code lines in the target code.

[0065] The total number of conditional branch code lines refers to the number of code lines of the conditional branch type in the target code.

[0066] Specifically, the coverage parameters corresponding to each uncovered conditional branch code line are added to obtain a coverage parameter sum, and then the coverage parameter sum is added to the total number of conditional branch code lines in the target code to obtain the total number of covered conditional branch code lines and excluded conditional branch code lines in the target code. The total number of covered conditional branch code lines and excluded conditional branch code lines in the target code is taken as the conditional branch coverage number corresponding to the target code, and the ratio of the conditional branch coverage number corresponding to the target code to the total number of conditional branch code lines in the target code is taken as the conditional branch coverage rate corresponding to the target code.

[0067] In the above-mentioned conditional branch coverage calculation method, the code type of the uncovered conditional branch code line in the target code is obtained, and the comment information corresponding to the uncovered conditional branch code line is obtained based on the code type; the coverage parameter corresponding to the uncovered conditional branch code line is obtained based on the comment information corresponding to the uncovered conditional branch code line; and the conditional branch coverage corresponding to the target code is calculated based on the coverage parameter corresponding to the uncovered conditional branch code line and the total number of conditional branch code lines in the target code. This method can eliminate conditional branch code lines that do not need to be counted based on the comment information corresponding to each conditional branch code line, thereby improving the calculation accuracy of the conditional branch coverage.

[0068] In one embodiment, a method for obtaining uncovered conditional branch code lines in a target code includes: obtaining a basic conditional branch coverage of the target code; and obtaining uncovered conditional branch code lines in the target code according to the basic conditional branch coverage of the target code.

[0069] Specifically, Bullseye is used to calculate the basic conditional branch coverage of the target code. Bullseye can obtain the total number of conditional branch code lines in the target code and all uncovered conditional branch code lines.

[0070] In one embodiment, before obtaining the code type of the uncovered conditional branch code line in the target code and obtaining the comment type corresponding to the uncovered conditional branch code line according to the code type, it also includes: obtaining each conditional branch code line in the target code and identifying the code type of each conditional branch code line in the target code; determining the comment type corresponding to each conditional branch code line according to the code type of each conditional branch code line, and adding comment information to each conditional branch code line according to the comment type corresponding to each conditional branch code line in the target code.

[0071] Further, determining a comment type corresponding to each conditional branch code line according to the code type of each conditional branch code line, and adding comment information to each conditional branch code line according to the comment type corresponding to each conditional branch code line in the target code, including: if the code type of a conditional branch code line is a first code type, determining that a conditional branch code line corresponds to a first comment type, the first comment type includes first comment information, second comment information, third comment information, and fourth comment information, adding one of the first comment information, second comment information, third comment information, and fourth comment information to the conditional branch code line, or not adding any comment information; If the code type of a conditional branch code line is the second code type, then it is determined that a conditional branch code line corresponds to the second comment type, and the second comment type includes fifth comment information, and the fifth comment information is added to a conditional branch code line, or no comment information is added; the first comment information is used to indicate the exclusion of the first part of the corresponding conditional branch code line, the second comment information is used to indicate the exclusion of the second part of the corresponding conditional branch code line, the third comment information is used to indicate the exclusion of the first part or the second part of the corresponding conditional branch code line, the fourth comment information is used to indicate the exclusion of the first part and the second part of the corresponding conditional branch code line, and the fifth comment information is used to indicate the exclusion of the corresponding conditional branch code line.

[0072] Specifically, first formulate a set of exclusion rules according to the test requirements, and add the comment information covexclude to the corresponding condition / decision / switch code statements that need to be excluded, so that the conditional branch coverage can be recalculated by reading the relevant comments later. There are two methods for adding comment information.

[0073] The first method of adding comment information is line exclusion (also known as line exclusion). Exclusion is completed by adding relevant comments after the code line, realizing single-line exclusion T / F. Another method is batch exclusion T / F. Relevant comments are added before and after the code segment that needs to be excluded T / F. The rules for line-by-line exclusion in the first case are shown in Table 1:

[0074]

[0075] Table 1

[0076] The application example of the first method of adding annotation information is as follows Figure 2 shown.

[0077] The second method of adding annotation information is batch exclusion (also known as batch exclusion). Add comments / **COVEXCLUDE start** / and / **COVEXCLUDE end** / before and after the code segment to be excluded to complete the batch exclusion T / F of this code segment. The rules are shown in Table 2:

[0078]

[0079]

[0080] Table 2

[0081] The application example of the second method of adding annotation information is as follows Figure 3 shown.

[0082] In the above table, condition / decision refers to the first code type, T and F respectively represent a branch of the conditional branch code line, T represents the first part of the conditional branch code line (that is, the true branch of the conditional branch code line), F represents the second part of the conditional branch code line (that is, the false branch of the conditional branch code line), covexcludeT, covexcludeF, covexcludeTorF, and covexcludeTF respectively represent the first annotation information, second annotation information, third annotation information, and fourth annotation information corresponding to the first code type, covexcludeT indicates that the T branch of the corresponding code line is excluded when calculating the coverage, covexcludeF indicates that the F branch of the corresponding code line is excluded when calculating the coverage, covexcludeTorF indicates that the T branch or F branch of the corresponding code line is excluded when calculating the coverage, and covexcludeTF indicates that the T branch and F branch of the corresponding code line are excluded when calculating the coverage. If a condition / decision conditional branch code line does not need to be excluded as a whole, no annotation information is added to the conditional branch code line. Switch / case refers to the second code type. These two statements do not involve partial exclusion when excluding. To exclude, exclude the entire code line. X represents the entire conditional branch code line, covexcludeC represents the fifth comment information corresponding to the second code type, and covexcludeC indicates excluding the corresponding code line. If a switch / case conditional branch code line does not need to be excluded, no comment information is added to the conditional branch code line.

[0083] In this embodiment, each conditional branch code line in the target code is obtained and the code type of each conditional branch code line in the target code is identified; the comment type corresponding to each conditional branch code line is determined based on the code type of each conditional branch code line; and comment information is added to each conditional branch code line based on the comment type corresponding to each conditional branch code line in the target code. Different comment information can be added to code lines according to different test requirements, thereby excluding code lines that do not need to be calculated during the subsequent code coverage calculation process, thereby improving the calculation accuracy of the conditional branch coverage rate.

[0084] In one embodiment, obtaining coverage parameters corresponding to uncovered conditional branch code lines according to comment information corresponding to uncovered conditional branch code lines includes: if the code type of a conditional branch code line is a first code type, obtaining the uncovered type corresponding to the uncovered conditional branch code line, the uncovered type being divided into first partial coverage, second partial coverage, or full uncovered; if the uncovered type corresponding to the uncovered conditional branch code line is first partial coverage, and the comment information corresponding to the uncovered conditional branch code line is second comment information, third comment information, or fourth comment information, determining that the coverage parameter corresponding to the uncovered conditional branch code line is 0; if the code type of the uncovered ... a first code type, the uncovered type being a second code type, the uncovered type being a third code type, or a fourth code type If the corresponding uncovered type is the first partial coverage, and the comment information corresponding to the uncovered conditional branch code line is not the second comment information, the third comment information or the fourth comment information, then the coverage parameter corresponding to the uncovered conditional branch code line is determined to be -1; if the corresponding uncovered type is the second partial coverage, and the comment information corresponding to the uncovered conditional branch code line is the first comment information, the third comment information or the fourth comment information, then the coverage parameter corresponding to the uncovered conditional branch code line is determined to be 0; if the corresponding uncovered type is the second partial coverage, and the comment information corresponding to the uncovered conditional branch code line is not the first comment information , the third comment information or the fourth comment information, then the coverage parameter corresponding to the uncovered conditional branch code line is determined to be -1; if the uncovered type corresponding to the uncovered conditional branch code line is fully uncovered, and the comment information corresponding to the uncovered conditional branch code line is the fourth comment information, then the coverage parameter corresponding to the uncovered conditional branch code line is determined to be 0; if the uncovered type corresponding to the uncovered conditional branch code line is fully uncovered, and the comment information corresponding to the uncovered conditional branch code line is the first comment information, the second comment information or the third comment information, then the coverage parameter corresponding to the uncovered conditional branch code line is determined to be -1; if the uncovered type corresponding to the uncovered conditional branch code line is fully uncovered If the code type is fully uncovered, and the comment information corresponding to the uncovered conditional branch code line is not the first comment information, the second comment information, the third comment information or the fourth comment information, then the coverage parameter corresponding to the uncovered conditional branch code line is determined to be -2; if the code type of a conditional branch code line is the second code type, and the comment information corresponding to the uncovered conditional branch code line is the fifth comment information, then the coverage parameter corresponding to the uncovered conditional branch code line is determined to be 0; if the code type of a conditional branch code line is the second code type, and the comment information corresponding to the uncovered conditional branch code line is not the fifth comment information, then the coverage parameter corresponding to the uncovered conditional branch code line is determined to be -1.

[0085] Specifically, determine the code type. If the code line type is condition / decision, then the code line accounts for 2 in totalcov (also known as the total number of cov or total coverage). Totalcov refers to the total number of conditional branch code lines assuming full coverage of the target code, that is, the total number of conditional branch code lines in the target code. First, set newcov = totalcov, and then see if there is any line or batch comment covexclude information. If so, determine newcov-1 / -0 / -2 according to the corresponding situation in the table below. If not, directly use newcov-2. If the type is switch / case, then it accounts for 1 in the total number of cov. Then see if there is any comment covexclude information. If so, determine newcov-1 / -0. If not, directly use newcov-1.

[0086] As shown in Table 3, conditional / decision code lines that do not cover T, F, or TF are considered uncovered. In actual coverage, coverage of TF and X indicates that the current code line is already covered, so they are not considered uncovered conditional branch code lines and their corresponding coverage parameters are 0.

[0087]

[0088] Table 3

[0089] In one embodiment, the conditional branch coverage rate corresponding to the target code is calculated based on the coverage parameters corresponding to the uncovered conditional branch code lines and the total number of conditional branch code lines in the target code, including: adding the total number of conditional branch code lines in the target code and the coverage parameters corresponding to each uncovered conditional branch code line in the target code to calculate the conditional branch coverage number corresponding to the target code; and calculating the conditional branch coverage rate corresponding to the target code based on the ratio of the conditional branch coverage number corresponding to the target code to the total number of conditional branch code lines in the target code.

[0090] Specifically, by traversing the comment information and code type corresponding to each line of code, newcov-1 / -2 / -0 can be used to repeatedly calculate the conditional branch coverage after excluding some conditional branch code lines. The number of calculations is equal to the number of uncovered conditional branch code lines. Finally, the conditional branch coverage rate is calculated by dividing the final calculated newcov by totalcov.

[0091] In one embodiment, a method for calculating conditional branch coverage includes:

[0092] Obtain each conditional branch code line in the target code and identify the code type of each conditional branch code line in the target code; if the code type of a conditional branch code line is a first code type, determine that the conditional branch code line corresponds to a first comment type, the first comment type includes first comment information, second comment information, third comment information and fourth comment information, and add one of the first comment information, second comment information, third comment information and fourth comment information to the conditional branch code line, or do not add any comment information; if the code type of a conditional branch code line is a second code type, determine that the conditional branch code line corresponds to a second comment type, the second comment type includes fifth comment information, and add the fifth comment information to the conditional branch code line, or do not add any comment information; the first comment information is used to indicate the exclusion of a first part of the corresponding conditional branch code line, the second comment information is used to indicate the exclusion of a second part of the corresponding conditional branch code line, the third comment information is used to indicate the exclusion of the first part or the second part of the corresponding conditional branch code line, the fourth comment information is used to indicate the exclusion of the first part and the second part of the corresponding conditional branch code line, and the fifth comment information is used to indicate the exclusion of the corresponding conditional branch code line.

[0093] Obtain the basic conditional branch coverage of the target code; obtain uncovered conditional branch code lines in the target code based on the basic conditional branch coverage of the target code; obtain the code type of the uncovered conditional branch code lines in the target code, and obtain the annotation information corresponding to the uncovered conditional branch code lines based on the code type.

[0094] If the code type of a conditional branch code line is the first code type, obtain the uncovered type corresponding to the uncovered conditional branch code line, and the uncovered type is divided into the first partial coverage, the second partial coverage or the full uncovered; if the uncovered type corresponding to the uncovered conditional branch code line is the first partial coverage, and the comment information corresponding to the uncovered conditional branch code line is the second comment information, the third comment information or the fourth comment information, then determine that the coverage parameter corresponding to the uncovered conditional branch code line is 0; if the uncovered type corresponding to the uncovered conditional branch code line is the first partial coverage, and the comment information corresponding to the uncovered conditional branch code line is not the second comment information information, the third annotation information or the fourth annotation information, then it is determined that the coverage parameter corresponding to the uncovered conditional branch code line is -1; if the uncovered type corresponding to the uncovered conditional branch code line is the second partial coverage, and the annotation information corresponding to the uncovered conditional branch code line is the first annotation information, the third annotation information or the fourth annotation information, then it is determined that the coverage parameter corresponding to the uncovered conditional branch code line is 0; if the uncovered type corresponding to the uncovered conditional branch code line is the second partial coverage, and the annotation information corresponding to the uncovered conditional branch code line is not the first annotation information, the third annotation information or the fourth annotation information, then it is determined that the uncovered conditional branch The coverage parameter corresponding to the code line is -1; if the uncovered type corresponding to the uncovered conditional branch code line is fully uncovered, and the comment information corresponding to the uncovered conditional branch code line is the fourth comment information, then the coverage parameter corresponding to the uncovered conditional branch code line is determined to be 0; if the uncovered type corresponding to the uncovered conditional branch code line is fully uncovered, and the comment information corresponding to the uncovered conditional branch code line is the first comment information, the second comment information or the third comment information, then the coverage parameter corresponding to the uncovered conditional branch code line is determined to be -1; if the uncovered type corresponding to the uncovered conditional branch code line is fully uncovered, and the uncovered conditional branch code line has the first comment information, the second comment information or the third comment information. If the comment information corresponding to the conditional branch code line is not the first comment information, the second comment information, the third comment information or the fourth comment information, the coverage parameter corresponding to the uncovered conditional branch code line is determined to be -2; if the code type of a conditional branch code line is the second code type, and the comment information corresponding to the uncovered conditional branch code line is the fifth comment information, the coverage parameter corresponding to the uncovered conditional branch code line is determined to be 0; if the code type of a conditional branch code line is the second code type, and the comment information corresponding to the uncovered conditional branch code line is not the fifth comment information, the coverage parameter corresponding to the uncovered conditional branch code line is determined to be -1.

[0095] The conditional branch coverage number corresponding to the target code is calculated by adding the total number of conditional branch code lines in the target code and the coverage parameter corresponding to each uncovered conditional branch code line in the target code; the conditional branch coverage rate corresponding to the target code is calculated based on the ratio of the conditional branch coverage number corresponding to the target code and the total number of conditional branch code lines in the target code.

[0096] It should be understood that, although the various steps in the flowcharts involved in the various embodiments described above are displayed in sequence according to the instructions of the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and these steps can be executed in other orders. Moreover, at least a portion of the steps in the flowcharts involved in the various embodiments described above can include multiple steps or multiple stages, and these steps or stages are not necessarily executed and completed 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 portion of steps or stages in other steps.

[0097] Based on the same inventive concept, embodiments of the present application also provide a conditional branch coverage calculation device for implementing the aforementioned conditional branch coverage calculation method. The solution provided by this device is similar to the solution described in the aforementioned method. Therefore, the specific limitations of one or more of the following conditional branch coverage calculation device embodiments can be found in the aforementioned limitations of the conditional branch coverage calculation method and will not be further elaborated here.

[0098] In one embodiment, Figure 4 As shown, a conditional branch coverage calculation device is provided, including: an annotation recognition module 401, a parameter calculation module 402 and a coverage calculation module 403, wherein:

[0099] An annotation recognition module 401 is used to obtain the code type of the uncovered conditional branch code line in the target code, and obtain the annotation information corresponding to the uncovered conditional branch code line according to the code type;

[0100] A parameter calculation module 402 is configured to obtain a coverage parameter corresponding to the uncovered conditional branch code line according to annotation information corresponding to the uncovered conditional branch code line;

[0101] The coverage calculation module 403 is configured to calculate the conditional branch coverage corresponding to the target code according to the coverage parameters corresponding to the uncovered conditional branch code lines and the total number of conditional branch code lines in the target code.

[0102] In one embodiment, the annotation identification module 401 is further configured to obtain the basic conditional branch coverage of the target code; and obtain uncovered conditional branch code lines in the target code according to the basic conditional branch coverage of the target code.

[0103] In one embodiment, the apparatus further comprises:

[0104] The comment adding module 404 is used to obtain each conditional branch code line in the target code and identify the code type of each conditional branch code line in the target code; determine the comment type corresponding to each conditional branch code line according to the code type of each conditional branch code line, and add comment information to each conditional branch code line according to the comment type corresponding to each conditional branch code line in the target code.

[0105] In one embodiment, the comment adding module 404 is also used to, if the code type of a conditional branch code line is a first code type, determine that a conditional branch code line corresponds to a first comment type, the first comment type includes first comment information, second comment information, third comment information and fourth comment information, add one of the first comment information, second comment information, third comment information and fourth comment information to a conditional branch code line, or add no comment information; if the code type of a conditional branch code line is a second code type, determine that a conditional branch code line corresponds to a second comment type, the second comment type includes fifth comment information, add fifth comment information to a conditional branch code line, or add no comment information; the first comment information is used to indicate the exclusion of the first part of the corresponding conditional branch code line, the second comment information is used to indicate the exclusion of the second part of the corresponding conditional branch code line, the third comment information is used to indicate the exclusion of the first part or the second part of the corresponding conditional branch code line, the fourth comment information is used to indicate the exclusion of the first part and the second part of the corresponding conditional branch code line, and the fifth comment information is used to indicate the exclusion of the corresponding conditional branch code line.

[0106] In one embodiment, the parameter calculation module 402 is further used to obtain the uncovered type corresponding to the uncovered conditional branch code line if the code type of a conditional branch code line is the first code type, and the uncovered type is divided into the first partial coverage, the second partial coverage or the full uncovered; if the uncovered type corresponding to the uncovered conditional branch code line is the first partial coverage, and the comment information corresponding to the uncovered conditional branch code line is the second comment information, the third comment information or the fourth comment information, then determine that the coverage parameter corresponding to the uncovered conditional branch code line is 0; if the uncovered type corresponding to the uncovered conditional branch code line is the first partial coverage, and the uncovered conditional branch code line is the second comment information, the third comment information or the fourth comment information, then determine that the coverage parameter corresponding to the uncovered conditional branch code line is 0; if the uncovered type corresponding to the uncovered conditional branch code line is the first partial coverage, and the uncovered conditional branch code line is the If the comment information corresponding to the code line is not the second comment information, the third comment information or the fourth comment information, then the coverage parameter corresponding to the uncovered conditional branch code line is determined to be -1; if the uncovered type corresponding to the uncovered conditional branch code line is the second partial coverage, and the comment information corresponding to the uncovered conditional branch code line is the first comment information, the third comment information or the fourth comment information, then the coverage parameter corresponding to the uncovered conditional branch code line is determined to be 0; if the uncovered type corresponding to the uncovered conditional branch code line is the second partial coverage, and the comment information corresponding to the uncovered conditional branch code line is not the first comment information, the third comment information or the fourth comment information, then The coverage parameter corresponding to the uncovered conditional branch code line is determined to be -1; if the uncovered type corresponding to the uncovered conditional branch code line is fully uncovered, and the comment information corresponding to the uncovered conditional branch code line is the fourth comment information, then the coverage parameter corresponding to the uncovered conditional branch code line is determined to be 0; if the uncovered type corresponding to the uncovered conditional branch code line is fully uncovered, and the comment information corresponding to the uncovered conditional branch code line is the first comment information, the second comment information or the third comment information, then the coverage parameter corresponding to the uncovered conditional branch code line is determined to be -1; if the uncovered type corresponding to the uncovered conditional branch code line is fully uncovered, and the comment information corresponding to the uncovered conditional branch code line is the first comment information, the second comment information or the third comment information, then the coverage parameter corresponding to the uncovered conditional branch code line is determined to be -1; If the comment information corresponding to the covered conditional branch code line is not the first comment information, the second comment information, the third comment information or the fourth comment information, the coverage parameter corresponding to the uncovered conditional branch code line is determined to be -2; if the code type of a conditional branch code line is the second code type, and the comment information corresponding to the uncovered conditional branch code line is the fifth comment information, the coverage parameter corresponding to the uncovered conditional branch code line is determined to be 0; if the code type of a conditional branch code line is the second code type, and the comment information corresponding to the uncovered conditional branch code line is not the fifth comment information, the coverage parameter corresponding to the uncovered conditional branch code line is determined to be -1.

[0107] In one embodiment, the coverage calculation module 403 is also used to calculate the conditional branch coverage number corresponding to the target code by adding the total number of conditional branch code lines in the target code and the coverage parameters corresponding to each uncovered conditional branch code line in the target code; and calculate the conditional branch coverage rate corresponding to the target code based on the ratio of the conditional branch coverage number corresponding to the target code and the total number of conditional branch code lines in the target code.

[0108] Each module in the above-mentioned conditional branch coverage calculation device can be implemented in whole or in part through 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 the computer device in the form of software, so that the processor can call and execute the corresponding operations of each module.

[0109] In one embodiment, a computer device is provided. The computer device may be a terminal, and its internal structure diagram may be as follows: Figure 5 As 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 via a system bus, and the communication interface, the display unit and the input device are connected to the system bus via 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 conditional branch coverage calculation method is implemented. The display unit of the computer device is used to form a visually visible image, and can be a display screen, a projection device or a virtual reality imaging device. The display screen can be a liquid crystal display screen or an electronic ink display screen. The input device of the computer device can be a touch layer covering the display screen, or a button, trackball or touchpad set on the computer device casing, or an external keyboard, touchpad or mouse, etc.

[0110] Those skilled in the art will understand that Figure 5 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 shown in the figure, or combine certain components, or have a different component arrangement.

[0111] In one embodiment, a computer device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and when the processor executes the computer program, the following steps are implemented:

[0112] Obtaining code types of uncovered conditional branch code lines in the target code, and obtaining comment information corresponding to the uncovered conditional branch code lines according to the code types;

[0113] Obtaining coverage parameters corresponding to uncovered conditional branch code lines according to comment information corresponding to uncovered conditional branch code lines;

[0114] The conditional branch coverage rate corresponding to the target code is calculated based on the coverage parameters corresponding to the uncovered conditional branch code lines and the total number of conditional branch code lines in the target code.

[0115] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:

[0116] Get the basic conditional branch coverage of the target code;

[0117] Obtain uncovered conditional branch code lines in the target code based on the base conditional branch coverage of the target code.

[0118] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:

[0119] Obtain each conditional branch code line in the target code, and identify the code type of each conditional branch code line in the target code;

[0120] Determine the comment type corresponding to each conditional branch code line according to the code type of each conditional branch code line, and add comment information to each conditional branch code line according to the comment type corresponding to each conditional branch code line in the target code.

[0121] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:

[0122] If the code type of a conditional branch code line is a first code type, determining that the conditional branch code line corresponds to a first comment type, the first comment type includes first comment information, second comment information, third comment information, and fourth comment information, adding one of the first comment information, the second comment information, the third comment information, and the fourth comment information to the conditional branch code line, or not adding any comment information;

[0123] If the code type of a conditional branch code line is the second code type, determining that the conditional branch code line corresponds to the second comment type, the second comment type includes fifth comment information, adding the fifth comment information to the conditional branch code line, or not adding any comment information;

[0124] The first comment information is used to indicate the exclusion of the first part of the corresponding conditional branch code line, the second comment information is used to indicate the exclusion of the second part of the corresponding conditional branch code line, the third comment information is used to indicate the exclusion of the first part or the second part of the corresponding conditional branch code line, the fourth comment information is used to indicate the exclusion of the first part and the second part of the corresponding conditional branch code line, and the fifth comment information is used to indicate the exclusion of the corresponding conditional branch code line.

[0125] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:

[0126] If the code type of a conditional branch code line is the first code type, obtaining the uncovered type corresponding to the uncovered conditional branch code line, where the uncovered type is divided into first partial coverage, second partial coverage, or complete uncovered;

[0127] If the uncovered conditional branch code line has an uncovered type of coverage of the first partial coverage and the comment information corresponding to the uncovered conditional branch code line is the second comment information, the third comment information, or the fourth comment information, then determining that the coverage parameter corresponding to the uncovered conditional branch code line is 0;

[0128] If the uncovered conditional branch code line corresponds to the uncovered uncovered type of coverage, and the comment information corresponding to the uncovered conditional branch code line is not the second comment information, the third comment information, or the fourth comment information, then determining that the coverage parameter corresponding to the uncovered conditional branch code line is -1;

[0129] If the uncovered conditional branch code line has an uncovered type of coverage of the second partial coverage, and the comment information corresponding to the uncovered conditional branch code line is the first comment information, the third comment information, or the fourth comment information, then determining that the coverage parameter corresponding to the uncovered conditional branch code line is 0;

[0130] If the uncovered conditional branch code line has an uncovered type of coverage of the second partial coverage, and the comment information corresponding to the uncovered conditional branch code line is not the first comment information, the third comment information, or the fourth comment information, then determining that the coverage parameter corresponding to the uncovered conditional branch code line is -1;

[0131] If the uncovered conditional branch code line has an uncovered type of fully uncovered, and the comment information corresponding to the uncovered conditional branch code line is the fourth comment information, determining that the coverage parameter corresponding to the uncovered conditional branch code line is 0;

[0132] If the uncovered conditional branch code line has an uncovered type of fully uncovered, and the comment information corresponding to the uncovered conditional branch code line is the first comment information, the second comment information, or the third comment information, then determining that the coverage parameter corresponding to the uncovered conditional branch code line is -1;

[0133] If the uncovered conditional branch code line corresponds to an uncovered uncovered type, and the comment information corresponding to the uncovered conditional branch code line is not the first comment information, the second comment information, the third comment information, or the fourth comment information, then determining that the coverage parameter corresponding to the uncovered conditional branch code line is -2;

[0134] If the code type of a conditional branch code line is the second code type, and the comment information corresponding to the uncovered conditional branch code line is the fifth comment information, determining that the coverage parameter corresponding to the uncovered conditional branch code line is 0;

[0135] If the code type of a conditional branch code line is the second code type, and the comment information corresponding to the uncovered conditional branch code line is not the fifth comment information, the coverage parameter corresponding to the uncovered conditional branch code line is determined to be -1.

[0136] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:

[0137] Calculate the conditional branch coverage number corresponding to the target code by adding the total number of conditional branch code lines in the target code and the coverage parameter corresponding to each uncovered conditional branch code line in the target code;

[0138] The conditional branch coverage rate corresponding to the target code is calculated based on the ratio of the conditional branch coverage number corresponding to the target code and the total number of conditional branch code lines in the target code.

[0139] 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 following steps are implemented:

[0140] Obtaining code types of uncovered conditional branch code lines in the target code, and obtaining comment information corresponding to the uncovered conditional branch code lines according to the code types;

[0141] Obtaining coverage parameters corresponding to uncovered conditional branch code lines according to comment information corresponding to uncovered conditional branch code lines;

[0142] The conditional branch coverage rate corresponding to the target code is calculated based on the coverage parameters corresponding to the uncovered conditional branch code lines and the total number of conditional branch code lines in the target code.

[0143] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:

[0144] Get the basic conditional branch coverage of the target code;

[0145] Obtain uncovered conditional branch code lines in the target code based on the base conditional branch coverage of the target code.

[0146] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:

[0147] Obtain each conditional branch code line in the target code, and identify the code type of each conditional branch code line in the target code;

[0148] Determine the comment type corresponding to each conditional branch code line according to the code type of each conditional branch code line, and add comment information to each conditional branch code line according to the comment type corresponding to each conditional branch code line in the target code.

[0149] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:

[0150] If the code type of a conditional branch code line is a first code type, determining that the conditional branch code line corresponds to a first comment type, the first comment type includes first comment information, second comment information, third comment information, and fourth comment information, adding one of the first comment information, the second comment information, the third comment information, and the fourth comment information to the conditional branch code line, or not adding any comment information;

[0151] If the code type of a conditional branch code line is the second code type, determining that the conditional branch code line corresponds to the second comment type, the second comment type includes fifth comment information, adding the fifth comment information to the conditional branch code line, or not adding any comment information;

[0152] The first comment information is used to indicate the exclusion of the first part of the corresponding conditional branch code line, the second comment information is used to indicate the exclusion of the second part of the corresponding conditional branch code line, the third comment information is used to indicate the exclusion of the first part or the second part of the corresponding conditional branch code line, the fourth comment information is used to indicate the exclusion of the first part and the second part of the corresponding conditional branch code line, and the fifth comment information is used to indicate the exclusion of the corresponding conditional branch code line.

[0153] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:

[0154] If the code type of a conditional branch code line is the first code type, obtaining the uncovered type corresponding to the uncovered conditional branch code line, where the uncovered type is divided into first partial coverage, second partial coverage, or complete uncovered;

[0155] If the uncovered conditional branch code line has an uncovered type of coverage of the first partial coverage and the comment information corresponding to the uncovered conditional branch code line is the second comment information, the third comment information, or the fourth comment information, then determining that the coverage parameter corresponding to the uncovered conditional branch code line is 0;

[0156] If the uncovered conditional branch code line corresponds to the uncovered uncovered type of coverage, and the comment information corresponding to the uncovered conditional branch code line is not the second comment information, the third comment information, or the fourth comment information, then determining that the coverage parameter corresponding to the uncovered conditional branch code line is -1;

[0157] If the uncovered conditional branch code line has an uncovered type of coverage of the second partial coverage, and the comment information corresponding to the uncovered conditional branch code line is the first comment information, the third comment information, or the fourth comment information, then determining that the coverage parameter corresponding to the uncovered conditional branch code line is 0;

[0158] If the uncovered conditional branch code line has an uncovered type of coverage of the second partial coverage, and the comment information corresponding to the uncovered conditional branch code line is not the first comment information, the third comment information, or the fourth comment information, then determining that the coverage parameter corresponding to the uncovered conditional branch code line is -1;

[0159] If the uncovered conditional branch code line has an uncovered type of fully uncovered, and the comment information corresponding to the uncovered conditional branch code line is the fourth comment information, determining that the coverage parameter corresponding to the uncovered conditional branch code line is 0;

[0160] If the uncovered conditional branch code line has an uncovered type of fully uncovered, and the comment information corresponding to the uncovered conditional branch code line is the first comment information, the second comment information, or the third comment information, then determining that the coverage parameter corresponding to the uncovered conditional branch code line is -1;

[0161] If the uncovered conditional branch code line corresponds to an uncovered uncovered type, and the comment information corresponding to the uncovered conditional branch code line is not the first comment information, the second comment information, the third comment information, or the fourth comment information, then determining that the coverage parameter corresponding to the uncovered conditional branch code line is -2;

[0162] If the code type of a conditional branch code line is the second code type, and the comment information corresponding to the uncovered conditional branch code line is the fifth comment information, determining that the coverage parameter corresponding to the uncovered conditional branch code line is 0;

[0163] If the code type of a conditional branch code line is the second code type, and the comment information corresponding to the uncovered conditional branch code line is not the fifth comment information, the coverage parameter corresponding to the uncovered conditional branch code line is determined to be -1.

[0164] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:

[0165] Calculate the conditional branch coverage number corresponding to the target code by adding the total number of conditional branch code lines in the target code and the coverage parameter corresponding to each uncovered conditional branch code line in the target code;

[0166] The conditional branch coverage rate corresponding to the target code is calculated based on the ratio of the conditional branch coverage number corresponding to the target code and the total number of conditional branch code lines in the target code.

[0167] In one embodiment, a computer program product is provided, comprising a computer program, which, when executed by a processor, implements the following steps:

[0168] Obtaining code types of uncovered conditional branch code lines in the target code, and obtaining comment information corresponding to the uncovered conditional branch code lines according to the code types;

[0169] Obtaining coverage parameters corresponding to uncovered conditional branch code lines according to comment information corresponding to uncovered conditional branch code lines;

[0170] The conditional branch coverage rate corresponding to the target code is calculated based on the coverage parameters corresponding to the uncovered conditional branch code lines and the total number of conditional branch code lines in the target code.

[0171] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:

[0172] Get the basic conditional branch coverage of the target code;

[0173] Obtain uncovered conditional branch code lines in the target code based on the base conditional branch coverage of the target code.

[0174] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:

[0175] Obtain each conditional branch code line in the target code, and identify the code type of each conditional branch code line in the target code;

[0176] Determine the comment type corresponding to each conditional branch code line according to the code type of each conditional branch code line, and add comment information to each conditional branch code line according to the comment type corresponding to each conditional branch code line in the target code.

[0177] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:

[0178] If the code type of a conditional branch code line is a first code type, determining that the conditional branch code line corresponds to a first comment type, the first comment type includes first comment information, second comment information, third comment information, and fourth comment information, adding one of the first comment information, the second comment information, the third comment information, and the fourth comment information to the conditional branch code line, or not adding any comment information;

[0179] If the code type of a conditional branch code line is the second code type, determining that the conditional branch code line corresponds to the second comment type, the second comment type includes fifth comment information, adding the fifth comment information to the conditional branch code line, or not adding any comment information;

[0180] The first comment information is used to indicate the exclusion of the first part of the corresponding conditional branch code line, the second comment information is used to indicate the exclusion of the second part of the corresponding conditional branch code line, the third comment information is used to indicate the exclusion of the first part or the second part of the corresponding conditional branch code line, the fourth comment information is used to indicate the exclusion of the first part and the second part of the corresponding conditional branch code line, and the fifth comment information is used to indicate the exclusion of the corresponding conditional branch code line.

[0181] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:

[0182] If the code type of a conditional branch code line is the first code type, obtaining the uncovered type corresponding to the uncovered conditional branch code line, where the uncovered type is divided into first partial coverage, second partial coverage, or complete uncovered;

[0183] If the uncovered conditional branch code line has an uncovered type of coverage of the first partial coverage and the comment information corresponding to the uncovered conditional branch code line is the second comment information, the third comment information, or the fourth comment information, then determining that the coverage parameter corresponding to the uncovered conditional branch code line is 0;

[0184] If the uncovered conditional branch code line corresponds to the uncovered uncovered type of coverage, and the comment information corresponding to the uncovered conditional branch code line is not the second comment information, the third comment information, or the fourth comment information, then determining that the coverage parameter corresponding to the uncovered conditional branch code line is -1;

[0185] If the uncovered conditional branch code line has an uncovered type of coverage of the second partial coverage, and the comment information corresponding to the uncovered conditional branch code line is the first comment information, the third comment information, or the fourth comment information, then determining that the coverage parameter corresponding to the uncovered conditional branch code line is 0;

[0186] If the uncovered conditional branch code line has an uncovered type of coverage of the second partial coverage, and the comment information corresponding to the uncovered conditional branch code line is not the first comment information, the third comment information, or the fourth comment information, then determining that the coverage parameter corresponding to the uncovered conditional branch code line is -1;

[0187] If the uncovered conditional branch code line has an uncovered type of fully uncovered, and the comment information corresponding to the uncovered conditional branch code line is the fourth comment information, determining that the coverage parameter corresponding to the uncovered conditional branch code line is 0;

[0188] If the uncovered conditional branch code line has an uncovered type of fully uncovered, and the comment information corresponding to the uncovered conditional branch code line is the first comment information, the second comment information, or the third comment information, then determining that the coverage parameter corresponding to the uncovered conditional branch code line is -1;

[0189] If the uncovered conditional branch code line corresponds to an uncovered uncovered type, and the comment information corresponding to the uncovered conditional branch code line is not the first comment information, the second comment information, the third comment information, or the fourth comment information, then determining that the coverage parameter corresponding to the uncovered conditional branch code line is -2;

[0190] If the code type of a conditional branch code line is the second code type, and the comment information corresponding to the uncovered conditional branch code line is the fifth comment information, determining that the coverage parameter corresponding to the uncovered conditional branch code line is 0;

[0191] If the code type of a conditional branch code line is the second code type, and the comment information corresponding to the uncovered conditional branch code line is not the fifth comment information, the coverage parameter corresponding to the uncovered conditional branch code line is determined to be -1.

[0192] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:

[0193] Calculate the conditional branch coverage number corresponding to the target code by adding the total number of conditional branch code lines in the target code and the coverage parameter corresponding to each uncovered conditional branch code line in the target code;

[0194] The conditional branch coverage rate corresponding to the target code is calculated based on the ratio of the conditional branch coverage number corresponding to the target code and the total number of conditional branch code lines in the target code.

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

[0196] Those skilled in the art will appreciate that all or part of the processes in the above-mentioned embodiment methods can be implemented 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 memory, database or other media used in the embodiments provided in this application may include at least one of non-volatile and volatile memory. Non-volatile memory may include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory may include random access memory (RAM) or external cache memory, etc. By way of 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 the various embodiments provided herein may include at least one of a relational database and a non-relational database. Non-relational databases may include, but are not limited to, distributed databases based on blockchains. The processor involved in the various embodiments provided herein may be, but are not limited to, a general-purpose processor, a central processing unit, a graphics processing unit, a digital signal processor, a programmable logic unit, a data processing logic unit based on quantum computing, and the like.

[0197] The technical features of the above embodiments can 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.

[0198] The above-described embodiments merely represent several implementation methods of the present application. While the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the present application. It should be noted that a person of ordinary skill in the art may make various modifications and improvements without departing from the spirit of the present application, and these modifications and improvements fall within the scope of protection of the present application. Therefore, the scope of protection of the present application shall be determined by the appended claims.

Claims

1. A method for calculating conditional branch coverage, characterized in that: The method comprises: Determining a comment type corresponding to each conditional branch code line according to a code type of each conditional branch code line; the code type includes a first code type and a second code type; the comment type includes a first comment type corresponding to the first code type and a second comment type corresponding to the second code type; In a case where the comment type corresponding to the conditional branch code line is the first comment type, one of first comment information, second comment information, third comment information and fourth comment information is added after the conditional branch code line, or no comment information is added; the conditional branch code line of the first code type includes a first part and a second part, the first comment information is used to indicate exclusion of the first part of the corresponding conditional branch code line, the second comment information is used to indicate exclusion of the second part of the corresponding conditional branch code line, the third comment information is used to indicate exclusion of the first part or the second part of the corresponding conditional branch code line, and the fourth comment information is used to indicate exclusion of the first part and the second part of the corresponding conditional branch code line; When the comment type corresponding to the conditional branch code line is the second comment type, adding fifth comment information before and after the conditional branch code line, or not adding any comment information; the fifth comment information indicates excluding the conditional branch code; Obtaining a code type of an uncovered conditional branch code line in the target code, and obtaining comment information corresponding to the uncovered conditional branch code line based on the code type; the code type refers to a conditional branch statement type of the conditional branch code line; the comment information is used to indicate the exclusion of the corresponding conditional branch code line or the exclusion of a branch of the corresponding conditional branch code line; Obtaining a coverage parameter corresponding to the uncovered conditional branch code line according to the code type, corresponding comment information, and uncovered type of the uncovered conditional branch code line; the uncovered type is divided into first partial coverage, second partial coverage, or complete uncovered; the absolute value of the coverage parameter represents the number of units corresponding to one conditional branch code line when counting code statements, and the coverage parameter includes 0, -1, and -2; Adding the coverage parameters corresponding to each uncovered conditional branch code line to obtain a coverage parameter sum, and adding the coverage parameter sum to the total number of conditional branch code lines in the target code to obtain the total number of covered conditional branch code lines and excluded conditional branch code lines in the target code; The total number of covered conditional branch code lines and excluded conditional branch code lines in the target code is taken as the conditional branch coverage number corresponding to the target code, and the ratio of the conditional branch coverage number corresponding to the target code to the total number of conditional branch code lines in the target code is taken as the conditional branch coverage rate corresponding to the target code.

2. The method according to claim 1, characterized in that A method for obtaining uncovered conditional branch code lines in the target code includes: Obtaining basic conditional branch coverage of the target code; The uncovered conditional branch code lines in the target code are obtained according to the basic conditional branch coverage of the target code.

3. The method according to claim 1, characterized in that Before determining the comment type corresponding to each conditional branch code line according to the code type of each conditional branch code line, and adding comment information to each conditional branch code line according to the comment type corresponding to each conditional branch code line in the target code, the method further includes: Each conditional branch code line in the target code is obtained, and a code type of each conditional branch code line in the target code is identified.

4. The method according to claim 1, wherein The obtaining, according to the annotation information corresponding to the uncovered conditional branch code line, coverage parameters corresponding to the uncovered conditional branch code line includes: If the code type of a conditional branch code line is the first code type, obtaining the uncovered type corresponding to the uncovered conditional branch code line; If the uncovered conditional branch code line corresponds to the uncovered conditional branch code line and the uncovered conditional branch code line has the second annotation information, the third annotation information, or the fourth annotation information, determining that the coverage parameter corresponding to the uncovered conditional branch code line is 0; If the uncovered conditional branch code line corresponds to the uncovered type of coverage is first partial coverage, and the comment information corresponding to the uncovered conditional branch code line is not the second comment information, the third comment information, or the fourth comment information, determining that the coverage parameter corresponding to the uncovered conditional branch code line is -1; If the uncovered conditional branch code line has an uncovered type of coverage of the second partial coverage and the comment information corresponding to the uncovered conditional branch code line is the first comment information, the third comment information, or the fourth comment information, determining that the coverage parameter corresponding to the uncovered conditional branch code line is 0; If the uncovered conditional branch code line corresponds to the uncovered type of coverage is the second partial coverage, and the comment information corresponding to the uncovered conditional branch code line is not the first comment information, the third comment information, or the fourth comment information, determining that the coverage parameter corresponding to the uncovered conditional branch code line is -1; If the uncovered type corresponding to the uncovered conditional branch code line is fully uncovered, and the comment information corresponding to the uncovered conditional branch code line is the fourth comment information, determining that the coverage parameter corresponding to the uncovered conditional branch code line is 0; If the uncovered conditional branch code line corresponds to an uncovered type of code that is completely uncovered, and the comment information corresponding to the uncovered conditional branch code line is the first comment information, the second comment information, or the third comment information, determining that the coverage parameter corresponding to the uncovered conditional branch code line is -1; If the uncovered conditional branch code line corresponds to an uncovered type of code that is not fully uncovered, and the comment information corresponding to the uncovered conditional branch code line is not the first comment information, the second comment information, the third comment information, or the fourth comment information, determining that the coverage parameter corresponding to the uncovered conditional branch code line is -2; If the code type of a conditional branch code line is the second code type, and the comment information corresponding to the uncovered conditional branch code line is the fifth comment information, determining that the coverage parameter corresponding to the uncovered conditional branch code line is 0; If the code type of a conditional branch code line is the second code type, and the comment information corresponding to the uncovered conditional branch code line is not the fifth comment information, the coverage parameter corresponding to the uncovered conditional branch code line is determined to be -1.

5. A conditional branch coverage calculation device, characterized in that: The device comprises: An annotation recognition module is used to determine the annotation type corresponding to each conditional branch code line according to the code type of each conditional branch code line; the code type includes a first code type and a second code type; the annotation type includes a first annotation type corresponding to the first code type, and a second annotation type corresponding to the second code type; when the annotation type corresponding to the conditional branch code line is the first annotation type, one of the first annotation information, the second annotation information, the third annotation information and the fourth annotation information is added after the conditional branch code line, or no annotation information is added; the conditional branch code line of the first code type includes a first part and a second part, the first annotation information is used to indicate the first part of the corresponding conditional branch code line is excluded, and the second annotation information is used to indicate the first part of the corresponding conditional branch code line is excluded. the second part of the conditional branch code line, the third comment information is used to indicate the exclusion of the first part or the second part of the corresponding conditional branch code line, and the fourth comment information is used to indicate the exclusion of the first part and the second part of the corresponding conditional branch code line; when the comment type corresponding to the conditional branch code line is the second comment type, fifth comment information is added before and after the conditional branch code line, or no comment information is added; the fifth comment information indicates the exclusion of the conditional branch code; the code type of the uncovered conditional branch code line in the target code is obtained, and the comment information corresponding to the uncovered conditional branch code line is obtained according to the code type; the code type refers to the conditional branch statement type of the conditional branch code line; the comment information is used to indicate the exclusion of the corresponding conditional branch code line or the exclusion of a branch of the corresponding conditional branch code line; a parameter calculation module, configured to obtain a coverage parameter corresponding to the uncovered conditional branch code line based on the annotation information corresponding to the code type of the uncovered conditional branch code line and the uncovered type; the uncovered type is classified as first partial coverage, second partial coverage, or complete uncovered; the absolute value of the coverage parameter represents the number of units corresponding to one conditional branch code line when counting code statements, and the coverage parameter includes 0, -1, and -2; A coverage calculation module is used to add the coverage parameters corresponding to each uncovered conditional branch code line to obtain a coverage parameter sum, add the coverage parameter sum to the total number of conditional branch code lines in the target code, and obtain the total number of covered conditional branch code lines and excluded conditional branch code lines in the target code; use the total number of covered conditional branch code lines and excluded conditional branch code lines in the target code as the conditional branch coverage number corresponding to the target code, and use the ratio of the conditional branch coverage number corresponding to the target code to the total number of conditional branch code lines in the target code as the conditional branch coverage rate corresponding to the target code.

6. The device according to claim 5, characterized in that The annotation recognition module is further configured to obtain a basic conditional branch coverage rate of the target code; and obtain uncovered conditional branch code lines in the target code according to the basic conditional branch coverage rate of the target code.

7. 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 4 are implemented.

8. 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 4 are implemented.

9. 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 4 are implemented.