Conditional statement value determination method and apparatus, and storage medium

By setting instrumentation statements in conditional statements and using assembly language analysis, the problem that white-box testing tools cannot obtain the values ​​of conditional statements under bytecode instrumentation is solved, thus improving test coverage and efficiency.

CN116450490BActive Publication Date: 2026-06-26SUZHOU DONGCHAYUN INFORMATION TECH CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
SUZHOU DONGCHAYUN INFORMATION TECH CO LTD
Filing Date
2022-01-07
Publication Date
2026-06-26

Smart Images

  • Figure CN116450490B_ABST
    Figure CN116450490B_ABST
Patent Text Reader

Abstract

Embodiments of the present application provide a conditional statement value determination method and device, and a storage medium. The method comprises: determining at least one conditional statement in source code; setting a plug-in statement before and / or after the conditional statement based on the conditional statement; and determining the value of the conditional statement corresponding to the plug-in statement based on the execution condition of the plug-in statement, wherein the value indicates the execution result of the conditional statement.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of computer technology, and in particular to a method, apparatus and storage medium for determining the value of a conditional statement. Background Technology

[0002] A decision statement often contains several conditional statements. Condition coverage has stronger testing capabilities than decision coverage. Condition coverage can determine the value of each condition in a decision statement, while decision coverage can only judge the overall result of the decision statement, ignoring the value of each condition. In existing technologies, white-box testing techniques can directly instrument the source code to obtain the values ​​of decision statements. However, in the case of bytecode instrumentation, white-box testing tools analyze bytecode, which leads to missing source code information, thus failing to obtain the values ​​of conditional statements in the source code. Summary of the Invention

[0003] This invention provides a method, apparatus, and storage medium for determining the value of a conditional statement.

[0004] The technical solution of this invention is implemented as follows:

[0005] This invention provides a method for determining the value of a conditional statement, the method comprising:

[0006] Identify at least one conditional statement in the source code;

[0007] Based on the conditional statement, instrumentation statements are set before and / or after the conditional statement;

[0008] Based on the execution status of the instrumentation statement, the value of the conditional statement corresponding to the instrumentation statement is determined, and the value indicates the execution result of the conditional statement.

[0009] In the above scheme, determining at least one conditional statement in the source code includes:

[0010] From the statement blocks in the source code, identify the decision statement blocks that contain decision statements; wherein, the statement block includes: multiple consecutively distributed code statements; the code statement includes: an entry statement and an exit statement;

[0011] Based on the block information corresponding to the decision statement block, the condition statement in the decision statement is determined.

[0012] In the above scheme, the block information includes: the position information of the determination statement block;

[0013] The step of determining at least one conditional statement in the decision statement based on the block information corresponding to the decision statement block includes:

[0014] Based on the location information of the decision statement block, the decision statements in the decision statement block are determined from the source code; wherein, the decision statement includes one or more conditional statements;

[0015] The judgment statement is parsed to determine the conditional statements within it.

[0016] In the above scheme, setting instrumentation statements before and / or after the conditional statement includes:

[0017] The conditional statement is analyzed using assembly language (ASM) to generate a test statement; the test statement is logically the same as or the opposite of the conditional statement.

[0018] Based on the test statement, an instrumentation statement containing a first value is set before the test statement;

[0019] And / or,

[0020] Set an instrumentation statement containing a second value after the test statement.

[0021] In the above scheme, determining the value of the conditional statement corresponding to the instrumented statement based on the execution status of the instrumented statement, wherein the value indicates the execution result of the conditional statement, includes:

[0022] Based on the execution status of the instrumentation statement containing the first value and the instrumentation statement containing the second value, the value of the test statement is determined.

[0023] The value of the conditional statement is determined based on the value of the test statement; wherein the value of the conditional statement indicates the execution result of the conditional statement.

[0024] In the above scheme, determining the value of the test statement based on the execution status of the instrumentation statement containing the first value and the instrumentation statement containing the second value includes:

[0025] If both the instrumentation statement containing the first value and the instrumentation statement containing the second value are executed, the value of the test statement is determined to be a true Boolean value.

[0026] And / or,

[0027] If the instrumentation statement containing the first value is executed, and the instrumentation statement containing the second value is not executed, the value of the test statement is determined to be a false Boolean value.

[0028] In the above scheme, determining the value of the conditional statement based on the value of the test statement includes:

[0029] When the test statement and the conditional statement have the same logic, the value of the conditional statement is equal to the value of the test statement.

[0030] And / or,

[0031] When the test statement is logically opposite to the conditional statement, the value of the conditional statement is equal to the value of the inverted test statement.

[0032] This invention also provides a conditional statement value determination device, the device comprising: a first determination module, a setting module, and a second determination module;

[0033] The first determining module is used to determine at least one conditional statement in the source code;

[0034] The setting module is used to set instrumentation statements before and / or after the conditional statements based on the conditional statements.

[0035] The second determining module is used to determine the value of the conditional statement corresponding to the instrumentation statement based on the execution status of the instrumentation statement, wherein the value indicates the execution result of the conditional statement.

[0036] In the above scheme, the first determining module is specifically used for:

[0037] From the statement blocks in the source code, identify the decision statement blocks that contain decision statements; wherein, the statement block includes: multiple consecutively distributed code statements; the code statement includes: an entry statement and an exit statement;

[0038] Based on the block information corresponding to the decision statement block, the condition statement in the decision statement is determined.

[0039] In the above scheme, the block information includes: the position information of the determination statement block;

[0040] The first determining module is specifically used to: determine the determination statement in the determination statement block from the source code based on the position information of the determination statement block; wherein the determination statement includes one or more conditional statements;

[0041] The judgment statement is parsed to determine the conditional statements within it.

[0042] In the above scheme, the setting module is specifically used for:

[0043] The conditional statement is analyzed using assembly language (ASM) to generate a test statement; the test statement is logically the same as or the opposite of the conditional statement.

[0044] Based on the test statement, an instrumentation statement containing a first value is set before the test statement;

[0045] And / or,

[0046] Set an instrumentation statement containing a second value after the test statement.

[0047] In the above scheme, the second determining module is specifically used for:

[0048] Based on the execution status of the instrumentation statement containing the first value and the instrumentation statement containing the second value, the value of the test statement condition statement is determined.

[0049] The value of the conditional statement is determined based on the value of the test statement; wherein the value of the conditional statement indicates the execution result of the conditional statement.

[0050] In the above scheme, the second determining module is specifically used for:

[0051] If both the instrumentation statement containing the first value and the instrumentation statement containing the second value are executed, the value of the test statement is determined to be a true Boolean value.

[0052] And / or,

[0053] If the instrumentation statement containing the first value is executed, and the instrumentation statement containing the second value is not executed, the value of the test statement is determined to be a false Boolean value.

[0054] In the above scheme, the second determining module is specifically used for:

[0055] When the test statement and the conditional statement have the same logic, the value of the conditional statement is equal to the value of the test statement.

[0056] And / or,

[0057] When the test statement is logically opposite to the conditional statement, the value of the conditional statement is equal to the value of the inverted test statement.

[0058] This invention also provides a conditional statement value determination device, the device comprising: a processor and a memory for storing a computer program capable of running on the processor;

[0059] When the processor runs the computer program, it executes the steps of any of the above-described methods for determining the value of a conditional statement.

[0060] This invention also provides a computer storage medium, characterized in that the computer storage medium stores computer-executable instructions; after the computer-executable instructions are executed by a processor, they can implement the steps of the above-described method for determining the value of a conditional statement.

[0061] In this embodiment, at least one conditional statement in the source code is identified, and instrumentation statements are set before and / or after the conditional statement. By observing the execution status of the instrumentation statements, the value of the conditional statement indicating the execution result of the conditional statement is determined. Thus, the execution result of the conditional statement is determined based on the execution status of the instrumentation statements, realizing the acquisition of the execution result, i.e., the value result, of the conditional statement during the instrumentation process. Furthermore, based on the value of the conditional statement, condition coverage statistics can be achieved, thereby supplementing test cases, improving testing efficiency, and making the software test coverage information more comprehensive. Attached Figure Description

[0062] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.

[0063] Figure 1 A flowchart illustrating the method for determining the value of a conditional statement provided by the present invention;

[0064] Figure 2 This is a flowchart illustrating the process of determining statement blocks in the source code in an embodiment of the present invention;

[0065] Figure 3 This is a schematic diagram of the composition structure of statement block information in an embodiment of the present invention;

[0066] Figure 4 This is a flowchart illustrating the process of generating condition blocks in an embodiment of the present invention;

[0067] Figure 5 This is a schematic diagram of the composition structure of condition block information in an embodiment of the present invention;

[0068] Figure 6 This is a schematic diagram of the structure of the conditional statement value determination device provided in the embodiments of the present invention;

[0069] Figure 7 This is a schematic diagram of another conditional statement value determination device provided in an embodiment of the present invention;

[0070] Figure 8 (a)-(i) are example codes in the embodiments of the present invention. Detailed Implementation

[0071] To make the objectives, technical solutions, and advantages of the present invention clearer, the present invention will be further described in detail below with reference to the accompanying drawings. The described embodiments should not be regarded as limitations on the present invention. All other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0072] Unless otherwise specified, the embodiments and features described herein can be combined arbitrarily. The steps illustrated in the flowcharts of the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. Furthermore, although a logical order is shown in the flowcharts, in some cases, the steps shown or described may be performed in a different order than that shown here.

[0073] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention pertains. The terminology used herein is for the purpose of describing embodiments of the invention only and is not intended to limit the invention.

[0074] Before providing a further detailed description of the embodiments of the present invention, the nouns and terms used in communication involved in the embodiments of the present invention will be explained.

[0075] This invention provides a method for determining the value of a conditional statement. For example... Figure 1 As shown, the method includes:

[0076] Step S101: Identify at least one conditional statement in the source code;

[0077] Step S102: Based on the conditional statement, set instrumentation statements before and / or after the conditional statement;

[0078] Step S103: Based on the execution status of the instrumentation statement, determine the value of the conditional statement corresponding to the instrumentation statement, wherein the value indicates the execution result of the conditional statement.

[0079] Specifically, in step S101, the at least one conditional statement can be a statement in the program code. For example, the conditional statement can be a conditional statement in a decision statement included in the source code; here, there can be one or more conditional statements; the conditional statement is an arithmetic expression containing relational operators, such as a == 0, c ! = 1, or d >= 1, etc. Here, relational operators include, but are not limited to: equal to, not equal to, less than, greater than, greater than or equal to, etc.

[0080] Furthermore, in step S101 above, determining at least one conditional statement in the source code includes: determining a decision statement block containing a decision statement from the statement block of the source code.

[0081] The statement block includes: multiple consecutively distributed code statements; the code statement includes: an entry statement and an exit statement; the condition statement in the decision statement is determined according to the block information corresponding to the decision statement block.

[0082] The entry and exit statements here are both statements within a block of code. After the entry statement is executed, at least one other statement in the block will be executed, until the exit statement is reached.

[0083] For example, the statement block may be a code block that executes loop logic guided by a for statement.

[0084] Specifically, the block information is generated based on the determined statement blocks after static analysis of the source code.

[0085] The block information includes at least: the statement block ID, the file ID to which the statement block belongs, the type code of the statement block, the position information of the statement block, and the line number of the entry statement of the statement block; here, the type code of the statement block indicates the type of the statement block, and the statement block containing the decision statement is identified as the decision statement block.

[0086] In this embodiment, the type code of the statement block is an 8-digit hexadecimal value. If it is less than 8 digits, it is padded with 0s before the type code.

[0087] The location information of the statement block is used to determine the location of the statement block from the file to which the statement block belongs.

[0088] The line number of the entry statement in the statement block is used to locate the position of the entry statement.

[0089] Specifically, static analysis is performed on the source code to generate statement blocks.

[0090] The statement block includes multiple consecutively distributed code statements; each statement block includes an entry statement (start statement) and an exit statement (end statement); based on the line number of the entry statement in the current statement block and the line number of the entry statement in the next statement block adjacent to the current statement block, all the code statements included in the current statement block can be determined from the source code.

[0091] The process of determining and generating statement blocks and their corresponding block information in source code is illustrated using a specific example:

[0092] For example, the source code can be like this Figure 8 As shown in (a):

[0093] The statement blocks determined after static analysis of the above source code are as follows: Figure 2 As shown, it should be noted that the comment statement in line 5 is not considered a statement block. C0, C1, C2, C3, C4, C5, C6, and C7 are used as the statement block IDs for the generated statement blocks. Statement blocks C0 to C7 are type-encoded, and corresponding block information is generated.

[0094] like Figure 3 As shown, Figure 3 For this embodiment, block information corresponding to the statement block is generated; the file ID to which the above source code belongs is set to 1; for example: the entry statement of statement block C0 is located on the third line of the source code, therefore, the line number of the entry statement of statement block C0 is 3; the entry statement of statement block C4 is located on the eleventh line of the source code, therefore, the line number of the entry statement of statement block C4 is 11.

[0095] In this embodiment, determining the decision statement block containing the decision statement from the statement block of the source code includes: determining the decision statement block containing the decision statement based on the type encoding in the block information corresponding to the statement block.

[0096] Specifically, whether a statement block is a decision statement block is determined based on whether the number in the first preset position of the type code corresponding to the statement block is 1.

[0097] In this embodiment, the first preset position is the second bit from high to low; the type code is represented by A, and the type code A and 0x0F000000 are ANDed, i.e., A&0x0F000000; if the result of A&0x0F000000 is 0x01000000, it means that the number in the first preset position of the type code of the current statement block is 1, and the current statement block is a decision statement block containing decision statements.

[0098] If the result of A&0x0F000000 is not 0x01000000, it means that the first preset position in the type encoding of the current statement block is not 1, and the current statement block is not a decision statement block containing decision statements.

[0099] For example, such as Figure 3In the block information shown, the type code of statement block C4 is 1100000, which is only a 7-bit hexadecimal value. Padding 0s before 1100000 makes the type code of statement block C4 complete with an 8-bit hexadecimal number 0x01100000. Performing a bitwise AND operation on 0x01100000 and 0x0F000000, the result is 0x01000000, which indicates that statement block C4 is a decision statement block containing decision statements.

[0100] Further, determining at least one conditional statement in the decision statement based on the block information corresponding to the decision statement block includes: determining the decision statement in the decision statement block from the source code based on the position information of the decision statement block; wherein the decision statement includes one or more conditional statements; parsing the decision statement to determine the conditional statements in the decision statement.

[0101] Specifically, the decision statement is parsed to generate a condition block; and the condition statements in the decision statement are determined based on the condition block information corresponding to the condition block.

[0102] The condition block information includes: condition block location index, decision statement block location information, file ID of the decision statement, condition block code, and condition block type identifier; the condition block type identifier can be numbers, letters, or a string composed of numbers and letters, and can be user-defined or a system default value, which is not specifically limited here; the condition block includes: single condition statement block, single condition combination statement block, and decision statement block.

[0103] The condition block position index identifies the order of the condition statements in the condition block from left to right in the decision statement, and is used to determine the position of the condition block in the decision statement; the decision statement block position information is used to determine the position of the statement block from the file to which the statement block belongs; the condition block type identifier is used to represent the type of the condition block through different numbers, that is, whether the condition block is a single condition statement block, a single condition combination statement block, or a decision statement block.

[0104] Specifically, for example Figure 3 In the block information shown, after determining that statement block C4 is a decision statement block containing decision statements based on the type encoding of statement block C4, the location of the statement block is determined from file 1 to which statement block C4 belongs based on the position information in statement block C4, and thus the decision statements are determined. The judgment statement is parsed to generate a condition block.

[0105] like Figure 4As shown; the generated condition blocks are represented by D0, D1, D2, D3, D4, D5, and D6; based on the generated condition blocks, the condition block information corresponding to the condition blocks is determined, such as... Figure 5 As shown; in this embodiment, the condition block type identifier is represented by a 4-digit integer, where 1109 indicates that the condition block is a single condition statement block, 1110 indicates that the condition block is a single condition combination statement block, and 1111 indicates that the condition block is a decision statement block. In this embodiment, among the condition blocks generated by the decision statement, D0, D1, D2, D4, and D5 are all single condition statement blocks, D3 is a single condition combination statement block, and D6 is the decision statement block; based on the condition block position information corresponding to condition blocks D0, D1, D2, D4, and D5, the condition statements corresponding to condition blocks D0, D1, D2, D4, and D5 are determined, that is, the condition statements in the decision statement are determined.

[0106] In step S103, the execution result of the conditional statement is represented by a Boolean value; if the execution result is true, it means that the conditional statement is true after execution; if the execution result is false, it means that the conditional statement is false after execution.

[0107] It should be noted that in this embodiment, at least one conditional statement in the source code is identified, and instrumentation statements are set before and / or after the conditional statement based on the conditional statement. By analyzing the execution status of the instrumentation statements, the value of the conditional statement indicating the execution result of the conditional statement is determined. In this way, the execution result of the conditional statement is determined based on the execution status of the instrumentation statements, realizing the acquisition of the value of the conditional statement indicating the execution result of the conditional statement during the instrumentation process. Furthermore, based on the value of the conditional statement, condition coverage statistics can be achieved, thereby supplementing test cases, improving testing efficiency, and making the software test coverage information more comprehensive.

[0108] Furthermore, after determining the conditional statement in the decision statement, the step of setting instrumentation statements before and / or after the conditional statement includes: performing bytecode analysis on the conditional statement using assembly language (ASM) to generate a test statement; the test statement having the same or opposite logic as the conditional statement; setting an instrumentation statement containing a first value before the test statement based on the test statement; and / or setting an instrumentation statement containing a second value after the test statement.

[0109] Specifically, the method further includes: determining the logical operator corresponding to the conditional statement; and based on the logical operator, performing bytecode analysis on the conditional statement using assembly language (ASM) to generate a test statement; here, the test statement is a conditional statement used for testing.

[0110] Specifically, the logical operator adjacent to the conditional statement is taken as the logical operator corresponding to the conditional statement; the logical operators include, but are not limited to: AND operator (&&), OR operator (||), NOT operator (!), XOR operator (^), etc.

[0111] Specifically, the type of the decision node in the decision statement is determined based on the type encoding in the block information corresponding to the decision statement; and the logical operator corresponding to the last condition statement in the decision statement is determined based on the decision node type.

[0112] The determination node type includes at least one of the following: if node type, while node type, for node type, and do_while node type; the determination node type is determined according to the value at the second preset position in the type code; here, the second preset position can be user-defined or a system default value can be used.

[0113] In this embodiment, if the value at the second preset position is 1, it indicates that the decision node type in the decision statement block is an if node type; if the value at the second preset position is 3, it indicates that the decision node type in the decision statement block is a for node type; if the value at the second preset position is 4, it indicates that the decision node type in the decision statement block is a while node type; if the value at the second preset position is 5, it indicates that the decision node type in the decision statement block is a do-while node type.

[0114] If the decision node type is an if node type, then the logical operator corresponding to the last condition statement in the decision statement is "AND"; if the decision node type is not an if node type, then the logical operator corresponding to the last condition statement in the decision statement is "OR".

[0115] by Figure 3 The block information shown is an example, where the second preset position is the third position from high to low; statement block C4 is a decision statement block, which contains condition statements corresponding to condition blocks D0, D1, D2, D4, and D5; based on the decision statements... It can be seen that the operator corresponding to the conditional statement a == 0 for condition D0 is "||", the operator corresponding to the conditional statement "bbb".equals(b) for condition block D1 is "&&", the operator corresponding to the conditional statement c == 1 for condition block D2 is "||", the operator corresponding to the conditional statement d == 2 for condition block D4 is "&&", and the operator corresponding to the conditional statement "eee" == e for condition block D5 needs to be determined according to the type of the decision node in the decision statement. The type code of decision statement block C4 is 1100000, which is only a 7-bit hexadecimal value. 0s are padded before 1100000 to make the type code of statement block C4 complete as an 8-bit hexadecimal number 0x01100000. The second preset position is 1, which indicates that the node type in decision statement block C4 is an if node, and the logical operator corresponding to the conditional statement in condition statement block D5 is the "&&" operator.

[0116] After determining the logical operator corresponding to the conditional statement, the conditional statement is bytecode analyzed using Assembly Language (ASM) based on the logical operator to generate a test statement. In some embodiments, when the generated test statement is logically identical to the original conditional statement in the decision statement, i.e., the test statement is identical to the conditional statement, the test statement is the conditional statement. In other embodiments, when the generated test statement is logically opposite to the original conditional statement in the decision statement, the test statement is the inverse of the conditional statement. For example, if the original conditional statement in the decision statement is "a!=0", the generated test statement is "a==0", which is logically opposite to the original conditional statement in the decision statement. Similarly, if the original conditional statement in the decision statement is "i>0", the generated test statement is "i<=0", which is logically opposite to the original conditional statement in the decision statement. Furthermore, if the original conditional statement in the decision statement is "i<=10", the generated test statement is "i>10", which is logically opposite to the original conditional statement in the decision statement.

[0117] Furthermore, setting an instrumentation statement before and / or after the conditional statement based on the conditional statement includes: setting an instrumentation statement containing a first value before the test statement based on the test statement; and / or setting an instrumentation statement containing a second value after the test statement.

[0118] Specifically, the instrumentation statement is set with different values ​​according to its position relative to the test statement; the value can be a user-defined value or a system default value, which is not specifically limited here; after the instrumentation statement containing the first value is executed, the first value will be output; after the instrumentation statement containing the second value is executed, the second value will be output.

[0119] The instrumentation statement here can be a code statement that is inserted into execution, and the instrumentation statement is a code statement that is inserted into the instrumentation point in the source code.

[0120] Further, determining the value of the conditional statement corresponding to the instrumentation statement based on the execution status of the instrumentation statement, wherein the value indicates the execution result of the conditional statement, includes: determining the value of the test statement based on the execution status of the instrumentation statement containing a first value and the instrumentation statement containing a second value; determining the value of the conditional statement based on the value of the test statement; wherein the value of the conditional statement indicates the execution result of the conditional statement.

[0121] Specifically, the execution status of the instrumentation statement includes: whether the instrumentation statement is executed and the number of times the instrumentation statement is executed;

[0122] Specifically, based on whether the first value exists in the execution status of the instrumentation statement, it is determined whether the instrumentation statement containing the first value is executed; based on the number of times the first value appears in the execution status, it is determined how many times the instrumentation statement containing the first value is executed.

[0123] Based on whether a second value exists in the execution status of the instrumentation statement, determine whether the instrumentation statement containing the second value is executed; based on the number of times the second value appears in the execution status, determine the number of times the instrumentation statement containing the second value is executed.

[0124] The number of times the instrumentation statement containing the first value is executed is the number of times the test statement is executed, and also the number of times the conditional statement is executed; based on whether the instrumentation statement containing the first value and the instrumentation statement containing the second value are executed, it is determined whether the test statement corresponding to the instrumentation statement is executed and the execution result after execution; based on the execution result of the test statement, the execution result of the conditional statement is determined.

[0125] Further, determining the value of the test statement based on the execution status of the instrumentation statement containing the first value and the instrumentation statement containing the second value includes: if both the instrumentation statement containing the first value and the instrumentation statement containing the second value are executed, determining the value of the test statement as a true Boolean value; and / or, if the instrumentation statement containing the first value is executed and the instrumentation statement containing the second value is not executed, determining the value of the test statement as a false Boolean value.

[0126] Further, determining the value of the conditional statement based on the value of the test statement includes: when the test statement and the conditional statement are logically identical, the value of the conditional statement is equal to the value of the test statement; and / or, when the test statement and the conditional statement are logically opposite, the value of the conditional statement is equal to the inverted value of the test statement.

[0127] Specifically, in one embodiment, if the test statement generated after bytecode analysis of the conditional statement has the same logic as the conditional statement, and if both the instrumentation statement containing the first value and the instrumentation statement containing the second value are executed, and the value of the test statement is true, then the value of the conditional statement is true, indicating that the execution result of the conditional statement is true after it is executed; the number of times the conditional statement is executed is equal to the number of times the instrumentation statement containing the first value is executed.

[0128] If the instrumentation statement containing the first value is executed and the instrumentation statement containing the second value is not executed, the value of the test statement is false, then the value of the conditional statement is false, indicating that after the conditional statement is executed, the execution result of the conditional statement is false; the number of times the conditional statement is executed is equal to the number of times the instrumentation statement containing the first value is executed.

[0129] For example: the source code is Figure 8 As shown in (b):

[0130] The conditional statements are a! = 0 and b! = 0; condition a! = 0 is represented by A, and condition b! = 0 is represented by B; the logical operator corresponding to conditional statement A is "&&", and since the judgment statement is of type if node, the operator corresponding to conditional statement B is also "&&"; after bytecode analysis of the conditional statements using ASM, the generated test statement is logically identical to conditional statements A and B, that is, the generated test statement is conditional statement A and conditional statement B; after setting instrumentation statements before and / or after the conditional statements, the code is as follows. Figure 8 As shown in (c):

[0131] Among them, System.out.printIn(A1) and System.out.printIn(A2) are instrumentation statements for conditional statement A;

[0132] After System.out.printIn(A1) is executed, the first value will be output; after System.out.printIn(A2) is executed, the second value will be output; System.out.printIn(B1) and System.out.printIn(B2) are instrumented statements for conditional statement B. After System.out.printIn(B1) is executed, the first value will be output; after System.out.printIn(B2) is executed, the second value will be output.

[0133] If both System.out.printIn(A1) and System.out.printIn(A2) are executed, the value of conditional statement A is true, indicating that the execution result of conditional statement A is true after it is executed;

[0134] If System.out.printIn(A1) is executed but System.out.printIn(A2) is not executed, then the value of conditional statement A is false, indicating that the execution result of conditional statement A is false after it is executed.

[0135] If both System.out.printIn(B1) and System.out.printIn(B2) are executed, the value of conditional statement B is true, indicating that the execution result of conditional statement B is true after it is executed.

[0136] If System.out.printIn(B1) is executed but System.out.printIn(B2) is not executed, then the value of conditional statement B is false, indicating that the execution result of conditional statement B is false after it is executed.

[0137] For example, the source code is as follows: Figure 8 As shown in (d):

[0138] The conditional statements are i<=10, i>0, and i>1; the conditional statement i<=10 is represented by M, the conditional statement i>0 by N, and the conditional statement i>1 by V; the logical operator corresponding to conditional statement M is "&&", the logical operator corresponding to conditional statement N is "&&", and based on the fact that the judgment statement is of the while node type, the operator corresponding to conditional statement V is "||"; after bytecode analysis of the conditional statements using ASM, the generated test statement is logically identical to conditional statements M, N, and V, that is, the generated test statement is conditional statements M, N, and V; after setting instrumentation statements before and / or after the conditional statements, the code is as follows. Figure 8 As shown in (e):

[0139] Among them, System.out.printIn(M1) and System.out.printIn(M2) are instrumentation statements for the conditional statement M;

[0140] After System.out.printIn(M1) is executed, the first value will be output; after System.out.printIn(M2) is executed, the second value will be output; System.out.printIn(N1) and System.out.printIn(N2) are instrumentation statements for conditional statement N; after System.out.printIn(N1) is executed, the first value will be output; after System.out.printIn(N2) is executed, the second value will be output; after System.out.printIn(V1) and System.out.printIn(V2) are instrumentation statements for conditional statement V; after System.out.printIn(V1) is executed, the first value will be output; after System.out.printIn(V2) is executed, the second value will be output.

[0141] If both System.out.printIn(M1) and System.out.printIn(M2) are executed, the conditional statement M is true, indicating that the execution result of the conditional statement is true after it is executed.

[0142] If System.out.printIn(M1) is executed but System.out.printIn(M2) is not executed, then the conditional statement M is false, indicating that the execution result of the conditional statement M is false after it is executed.

[0143] If both System.out.printIn(N1) and System.out.printIn(N2) are executed, the conditional statement N is true, indicating that after the conditional statement N is executed, the execution result N of the conditional statement is true;

[0144] If System.out.printIn(N1) is executed but System.out.printIn(N2) is not executed, then the value of the conditional statement N is false, indicating that the execution result of the conditional statement N is false after it is executed.

[0145] If both System.out.printIn(V1) and System.out.printIn(V2) are executed, then the conditional statement V is true, indicating that the execution result of the conditional statement V is true after it is executed.

[0146] If System.out.printIn(V1) is executed but System.out.printIn(V2) is not executed, then the value of the conditional statement V is false, indicating that the execution result of the conditional statement V is false after it is executed.

[0147] In another embodiment, if the test statement generated after bytecode analysis of the conditional statement has the opposite logic to the conditional statement, and if both the instrumentation statement containing the first value and the instrumentation statement containing the second value are executed, the value of the test statement is true, and the value of the conditional statement is false, indicating that the execution result of the conditional statement is false after it is executed; the number of times the conditional statement is executed is equal to the number of times the instrumentation statement containing the first value is executed;

[0148] If the instrumentation statement containing the first value is executed, and the instrumentation statement containing the second value is not executed, the value of the test statement is false, and the value of the conditional statement is true, indicating that after the conditional statement is executed, the execution result of the conditional statement is true; the number of times the conditional statement is executed is equal to the number of times the instrumentation statement containing the first value is executed.

[0149] For example, the source code is as follows Figure 8 As shown in (f):

[0150] The conditional statements are c! = 0 and d! = 0; c! = 0 is represented by C, and d! = 0 is represented by D; the logical operator corresponding to conditional statement C is "||", and based on the fact that the judgment statement is of type if node, the operator corresponding to conditional statement B is "&&"; after bytecode analysis of the conditional statements using ASM, the generated test statement is reversed, and is logically opposite to conditional statements A and B, that is, the generated test statement is the result of inverting conditional statements C and D; test statement C' is c == 0; test statement D' is d == 0; although the test statement is logically opposite to the original conditional statement, in order to be equivalent to the original judgment statement, instrumentation statements are set before and / or after the test statement, and the code is as follows. Figure 8 (g):

[0151] Among them, System.out.printIn(C1) and System.out.printIn(C2) are instrumentation statements for test statement C';

[0152] After System.out.printIn(C1) is executed, the first value will be output; after System.out.printIn(C2) is executed, the second value will be output; System.out.printIn(D1) and System.out.printIn(D2) are instrumentation statements for the test statement D'; after System.out.printIn(D1) is executed, the first value will be output; after System.out.printIn(D2) is executed, the second value will be output.

[0153] If both System.out.printIn(C1) and System.out.printIn(C2) are executed, the value of the test statement C' is true, then the value of the conditional statement C is false, indicating that after the conditional statement C is executed, the execution result of the conditional statement C is false;

[0154] If System.out.printIn(C1) is executed but System.out.printIn(C2) is not executed, then the value of the test statement C' is false, and the value of the conditional statement C is true, indicating that after the conditional statement C is executed, the execution result of the conditional statement C is true.

[0155] If both System.out.printIn(B1) and System.out.printIn(B2) are executed, the value of the test statement D' is true, then the value of the conditional statement D is false, indicating that after the conditional statement D is executed, the execution result of the conditional statement D is false;

[0156] If System.out.printIn(D1) is executed but System.out.printIn(D2) is not executed, then the value of the test statement D' is false, and the value of the conditional statement D is true, indicating that after the conditional statement D is executed, the execution result of the conditional statement D is true.

[0157] For example, the source code is as follows: Figure 8 As shown in (h):

[0158] The conditional statements are j<=10, j>0, and j>1; the conditional statement j<=10 is represented by E, the conditional statement j>0 by F, and the conditional statement j>1 by G; the logical operator corresponding to conditional statement E is "||", the logical operator corresponding to conditional statement F is "||", and based on the fact that the judgment statement is of the while node type, the operator corresponding to conditional statement G is "||"; after bytecode analysis of the conditional statements using ASM, the generated test statement E is j<=10, which is logically the same as conditional statement E; conditional statement F' is j<=0, which is logically the opposite of conditional statement F; and conditional statement G' is j<=1, which is logically the opposite of conditional statement G. Although there are test statements that are logically opposite to the original conditional statements, in order to be equivalent to the original judgment statement, instrumentation statements are set before and / or after the test statements, and the code is as follows. Figure 8 As shown in (i):

[0159] System.out.printIn(E1) and System.out.printIn(E2) are instrumentation statements for conditional statement E; after System.out.printIn(E1) is executed, the first value will be output; after System.out.printIn(E2) is executed, the second value will be output.

[0160] System.out.printIn(F1) and System.out.printIn(F2) are instrumentation statements for the test statement F'; after System.out.printIn(F1) is executed, the first value will be output; after System.out.printIn(F2) is executed, the second value will be output.

[0161] System.out.printIn(G1) and System.out.printIn(G2) are instrumentation statements for the test statement G'; after System.out.printIn(G1) is executed, the first value will be output; after System.out.printIn(G2) is executed, the second value will be output.

[0162] If both System.out.printIn(E1) and System.out.printIn(E2) are executed, the conditional statement E is true, indicating that the execution result of the conditional statement is true after it is executed.

[0163] If System.out.printIn(E1) is executed but System.out.printIn(E2) is not executed, then the conditional statement E is false, indicating that the execution result of the conditional statement E is false after it is executed.

[0164] If both System.out.printIn(F1) and System.out.printIn(F2) are executed, the test statement F' is true and the conditional statement F is false, indicating that after the conditional statement N is executed, the execution result F of the conditional statement is false;

[0165] If System.out.printIn(F1) is executed but System.out.printIn(F2) is not executed, then the test statement F' is false and the conditional statement F is true, indicating that the execution result of the conditional statement F is true after it is executed.

[0166] If both System.out.printIn(G1) and System.out.printIn(G2) are executed, then the test statement G' is true and the conditional statement G is false, indicating that after the conditional statement G is executed, the execution result of the conditional statement G is false;

[0167] If System.out.printIn(G1) is executed but System.out.printIn(G2) is not executed, then the conditional statement G' is false and the conditional statement G is true, indicating that the execution result of the conditional statement G is true after it is executed.

[0168] The following is a specific example illustrating the method for determining the value of a conditional statement according to an embodiment of the present invention.

[0169] Step 1: Perform static analysis on the source code to identify at least one statement block;

[0170] The statement block is a sequence of continuously distributed code statements or expressions. Each code statement includes an entry statement and an exit statement. Control can only be transferred from its unique entry statement and only from its unique exit statement. If any statement in the block is executed, all statements can be executed.

[0171] Step 2: Determine the block information of the statement block and store it in the database;

[0172] The block information includes at least: the statement block ID, the file ID to which the statement block belongs, the type code of the statement block, the position information of the statement block, and the line number of the entry statement of the statement block; the statement block is type-coded, and the type code is represented by an 8-digit hexadecimal number.

[0173] Step 3: Determine the decision statement block based on the statement block type encoding;

[0174] Specifically: whether the statement block is a decision statement block is determined by whether the second bit of the type code corresponding to the statement block is 1 from high to low; assuming a type code is A, calculate "A&0x0F000000". If the result is "0x01000000", it means that the basic block contains decision statements; otherwise, it means that the basic block does not contain decision statements. The decision statements include decision statements for branch structures and loop structures.

[0175] Step 4: After identifying the decision statement block, determine the node type of the decision statement block;

[0176] Based on the third position of the type code corresponding to the statement block from high to low, determine the type of the decision node in the decision statement block; convert the type code into an 8-bit hexadecimal number A; calculate A & 0x00F00000. If the result is "0x00100000", it indicates that the node type of the decision statement contained in the basic block is an if node; if the result is "0x00300000", it indicates that the node type of the decision statement contained in the basic block is a for node.

[0177] If the result is "0x00400000", it means that the node type of the decision statement contained in the basic block is a while node; if the result is "0x00400000", it means that the node type of the decision statement contained in the basic block is a do-while node.

[0178] Step 5: After determining the decision statement block, determine the decision statement in the decision statement block according to the file ID to which the statement block belongs, the position information of the statement block, and the code line number of the entry statement of the statement block in the block information corresponding to the decision statement block.

[0179] Specifically, the file containing the decision statement block is determined based on the file ID to which the statement block belongs; the position of the decision statement block in the file is determined based on the position information of the statement block; and the specific line number of the entry statement of the statement block is used to locate the specific line number of the decision statement block in the file, thereby determining the decision statement in the decision statement block.

[0180] Step 6: Parse the judgment statement to generate a condition block; determine the condition statement in the judgment statement based on the condition block information corresponding to the condition block.

[0181] Specifically, the condition block includes: a single condition statement block, a single condition combination statement block, and a decision statement block; the condition block information includes: a condition block position index, a decision statement block position information, the file ID of the decision statement, the condition block code, and a condition block type identifier;

[0182] The condition block position index identifier is the left-to-right sequential encoding of the condition statements in the condition block within the decision statement, used to determine the position of the condition block within the decision statement;

[0183] The determination statement block location information is used to determine the location of the statement block from the file to which the statement block belongs;

[0184] The condition block code refers to the program code corresponding to the single condition, the combination of single conditions, and the decision statement contained in the decision statement.

[0185] The condition block type identifier is used to represent the type of the condition block by different numbers, that is, whether the condition block is a single condition statement block, a single condition combination statement block, or a decision statement block.

[0186] Step 7: Based on the condition block type identifier in the condition block information, determine the decision statement information in the condition block and all single condition statement information contained in the decision statement;

[0187] Specifically, the condition block type identifier is represented by a 4-digit integer. Assuming the condition block type is determined as follows: when the condition block type identifier is 1109, it indicates that the condition block is a single condition statement block; when the condition block type identifier is 1110, it indicates that the condition block is a single condition combined statement block; and when the condition block type identifier is 1111, it indicates that the condition block is a decision statement block.

[0188] Extract the condition block information corresponding to all condition blocks of type 1109 and generate the corresponding JSON file; the condition block position index corresponding to all single condition statements is consistent with the sequential encoding of the single condition statements in the JSON file.

[0189] Step 8: Determine the logical operators corresponding to the conditional statements;

[0190] Extract the logical operator following each single condition statement in the decision statement; and determine the logical operator corresponding to the last condition statement in the decision statement based on the decision node type.

[0191] If the node type of the judgment statement is an if node type, then the logical operator corresponding to the last condition statement is "&&".

[0192] If the node type of the judgment statement is a node type other than the if node type, then the logical operator corresponding to the last condition statement is "||"; store the logical operator corresponding to the condition statement.

[0193] Step 9: Traverse the cache and obtain all functions corresponding to the currently loaded class file.

[0194] Step 10: Access all functions, compare the accessed line number with the line number of the entry statement of the statement block in the source code, if the type of the statement block corresponding to the line number is a decision statement block, mark the line number, and retrieve the condition block information corresponding to the decision statement block and the logical operator corresponding to the condition statement from the cache.

[0195] Step 11: Use ASM to perform bytecode analysis on the condition block information corresponding to the decision statement block marked with the code line number and the logical operator corresponding to the condition block, and generate test statements;

[0196] The test statement can be logically the same as or the opposite of the original conditional statement; the program code composed of the test statement and the corresponding logical operator is equivalent to the operation logic of the decision statement contained in the decision statement block.

[0197] Step 12: Set an instrumentation statement containing a first value before the test statement, and set an instrumentation statement containing a second value after the test statement.

[0198] Step 13: Based on the execution status of the instrumentation statement containing the first value and the instrumentation statement containing the second value, determine the value of the conditional statement;

[0199] The conditional statement can take three values: the conditional statement is executed but the value is unclear, the conditional statement takes a true value, and the conditional statement takes a false value.

[0200] If the test statement generated after bytecode analysis of the conditional statement has the same logic as the conditional statement, and both the instrumentation statement containing the first value and the instrumentation statement containing the second value are executed, the conditional statement is true, indicating that the execution result of the conditional statement is true after execution; the number of times the conditional statement is executed is equal to the number of times the instrumentation statement containing the first value is executed; if the instrumentation statement containing the first value is executed, and the instrumentation statement containing the second value is not executed, the conditional statement is false, indicating that the execution result of the conditional statement is false after execution.

[0201] The number of times the conditional statement is executed is equal to the number of times the instrumentation statement containing the first value is executed.

[0202] If the test statement generated after bytecode analysis of the conditional statement is logically opposite to the conditional statement, and both the instrumentation statement containing the first value and the instrumentation statement containing the second value are executed, the test statement takes the value of true, and the conditional statement takes the value of false, indicating that the execution result of the conditional statement is false after it is executed; the number of times the conditional statement is executed is equal to the number of times the instrumentation statement containing the first value is executed; the number of times the conditional statement takes the value of false is equal to the number of times the instrumentation statement containing the first value is executed.

[0203] If the instrumentation statement containing the first value is executed, and the instrumentation statement containing the second value is not executed, the value of the test statement is false, and the value of the conditional statement is true, indicating that after the conditional statement is executed, the execution result of the conditional statement is true; the number of times the conditional statement is executed is equal to the number of times the instrumentation statement containing the first value is executed; the number of times the conditional statement takes the true value is equal to the number of times the instrumentation statement containing the first value is executed.

[0204] like Figure 6 As shown, Figure 6 A schematic diagram of the structure of the conditional statement value determination device provided in the embodiment of the present invention includes: a first determination module 601, a setting module 602, and a second determination module 603;

[0205] The first determining module 601 is used to determine at least one conditional statement in the source code;

[0206] The setting module 602 is used to set instrumentation statements before and / or after the conditional statements based on the conditional statements.

[0207] The second determining module 603 is used to determine the value of the conditional statement corresponding to the instrumentation statement based on the execution status of the instrumentation statement, wherein the value indicates the execution result of the conditional statement.

[0208] Specifically, the first determining module 601 is specifically used to determine a decision statement block containing a decision statement from the statement block of the source code; wherein, the statement block includes: multiple consecutively distributed code statements; the code statement includes: an entry statement and an exit statement; and to determine the condition statement in the decision statement according to the block information corresponding to the decision statement block.

[0209] Specifically, the block information includes: the position information of the decision statement block; the first determining module 601 is specifically used to determine the decision statement in the decision statement block from the source code according to the position information of the decision statement block; wherein, the decision statement includes one or more conditional statements; the decision statement is parsed to determine the conditional statements in the decision statement.

[0210] Specifically, the setting module 602 is configured to perform bytecode analysis on the conditional statement using assembly language (ASM) to generate a test statement; the test statement is logically the same as or opposite to the conditional statement; based on the test statement, an instrumentation statement containing a first value is set before the test statement; and / or, an instrumentation statement containing a second value is set after the test statement.

[0211] Specifically, the second determining module 603 is specifically used to determine the value of the test statement condition statement based on the execution status of the instrumentation statement containing the first value and the instrumentation statement containing the second value; and to determine the value of the condition statement according to the value of the test statement; wherein the value of the condition statement indicates the execution result of the condition statement.

[0212] Specifically, the second determining module 603 is specifically used to determine that the value of the test statement is a true Boolean value if both the instrumentation statement containing the first value and the instrumentation statement containing the second value are executed; and / or, if the instrumentation statement containing the first value is executed and the instrumentation statement containing the second value is not executed, determine that the value of the test statement is a false Boolean value.

[0213] Specifically, the second determining module 603 is used to determine the value of the condition statement when the test statement and the condition statement are logically the same; and / or, when the test statement and the condition statement are logically opposite, the value of the condition statement is equal to the inverted value of the test statement.

[0214] To implement the method of the embodiments of the present invention, the embodiments of the present invention provide another conditional statement value determination device, specifically, as follows: Figure 7 As shown, the device 70 includes a processor 701 and a memory 702 for storing computer programs that can run on the processor;

[0215] When the processor 701 runs the computer program, it performs the following actions: determining at least one conditional statement in the source code; setting instrumentation statements before and / or after the conditional statements based on the conditional statements; and determining the value of the conditional statement corresponding to the instrumentation statement based on the execution status of the instrumentation statements, wherein the value indicates the execution result of the conditional statements.

[0216] In one embodiment, the processor 701 is further configured to, when running the computer program, perform the following: determining a decision statement block containing decision statements from the statement blocks of the source code; wherein the statement block includes: a plurality of consecutively distributed code statements; the code statements include: an entry statement and an exit statement; and determining conditional statements in the decision statements according to the block information corresponding to the decision statement block.

[0217] In one embodiment, the processor 701 is further configured to, when running the computer program, perform the following: the block information includes: the location information of the decision statement block; based on the location information of the decision statement block, determine the decision statement in the decision statement block from the source code; wherein the decision statement includes one or more conditional statements; parse the decision statement to determine the conditional statements in the decision statement.

[0218] In one embodiment, the processor 701 is further configured to, when running the computer program, perform: bytecode analysis of the conditional statement using assembly language (ASM) to generate a test statement; the test statement being logically the same as or opposite to the conditional statement; based on the test statement, setting an instrumentation statement containing a first value before the test statement; and / or setting an instrumentation statement containing a second value after the test statement.

[0219] In one embodiment, the processor 701 is further configured to, when running the computer program, perform: determining the value of the test statement condition statement based on the execution status of the instrumentation statement containing a first value and the instrumentation statement containing a second value; determining the value of the condition statement according to the value of the test statement; wherein the value of the condition statement indicates the execution result of the condition statement.

[0220] In one embodiment, the processor 701 is further configured to, when running the computer program, execute: if both the instrumentation statement containing the first value and the instrumentation statement containing the second value are executed, determine that the value of the test statement is a true Boolean value; and / or, if the instrumentation statement containing the first value is executed and the instrumentation statement containing the second value is not executed, determine that the value of the test statement is a false Boolean value.

[0221] In one embodiment, the processor 701 is further configured to, when running the computer program, execute: when the test statement and the conditional statement are logically identical, the value of the conditional statement is equal to the value of the test statement; and / or, when the test statement and the conditional statement are logically opposite, the value of the conditional statement is equal to the inverted value of the test statement.

[0222] It should be noted that the condition statement value determination device and the condition statement value determination method provided in the above embodiments belong to the same concept, and their specific implementation process can be found in the method embodiments, which will not be repeated here.

[0223] Of course, in practical applications, such as Figure 7 As shown, the device 70 may further include at least one network interface 703. The various components in the conditional statement value determination device 70 are coupled together via a bus system 704. It is understood that the bus system 704 is used to implement communication between these components. In addition to a data bus, the bus system 704 also includes a power bus, a control bus, and a status signal bus. However, for clarity, in... Figure 7 All buses are labeled as bus system 704. The number of processors 701 can be at least one. Network interface 703 is used for wired or wireless communication between conditional statement value determination device 70 and other devices.

[0224] The memory 702 in this embodiment of the invention is used to store various types of data to support the operation of the conditional statement value determination device 70.

[0225] The methods disclosed in the above embodiments of the present invention can be applied to processor 701, or implemented by processor 701. Processor 701 may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the integrated logic circuit of the hardware in processor 701 or by instructions in the form of software. The processor 7901 mentioned above may be a general-purpose processor, a digital signal processor (DSP), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. Processor 701 can implement or execute the methods, steps and logic block diagrams disclosed in the embodiments of the present invention. The general-purpose processor may be a microprocessor or any conventional processor, etc. The steps of the methods disclosed in the embodiments of the present invention can be directly manifested as being executed by a hardware decoding processor, or being executed by a combination of hardware and software modules in the decoding processor. The software modules may be located in a storage medium, which is located in memory 702. Processor 701 reads the information in memory 702 and combines its hardware to complete the steps of the aforementioned method.

[0226] In an exemplary embodiment, the condition statement value determination device 70 may be implemented by one or more application-specific integrated circuits (ASICs), DSPs, programmable logic devices (PLDs), complex programmable logic devices (CPLDs), field-programmable gate arrays (FPGAs), general-purpose processors, controllers, microcontrollers (MCUs), microprocessors, or other electronic components to perform the aforementioned method.

[0227] In an exemplary embodiment, the present invention also provides a computer-readable storage medium, such as a memory 702 including a computer program, which can be executed by a processor 701 of a conditional statement value determination device 70 to complete the steps described in the aforementioned method.

[0228] Specifically, embodiments of the present invention also provide a computer-readable storage medium storing a computer program thereon. When the computer program is run by a processor, it performs the following: determining at least one conditional statement in the source code; setting instrumentation statements before and / or after the conditional statements based on the conditional statements; and determining the value of the conditional statement corresponding to the instrumentation statement based on the execution status of the instrumentation statements, wherein the value indicates the execution result of the conditional statements.

[0229] In one embodiment, when the computer program is run by the processor, it performs the following: determining a decision statement block containing decision statements from the statement blocks of the source code; wherein the statement block includes: a plurality of consecutively distributed code statements; the code statements include: an entry statement and an exit statement; and determining the condition statement in the decision statement based on the block information corresponding to the decision statement block.

[0230] In one embodiment, when the computer program is run by the processor, it executes the following: the block information includes: the location information of the decision statement block; based on the location information of the decision statement block, the decision statement in the decision statement block is determined from the source code; wherein the decision statement includes one or more conditional statements; the decision statement is parsed to determine the conditional statements in the decision statement.

[0231] In one embodiment, when the computer program is run by the processor, it performs the following: bytecode analysis of the conditional statement using assembly language (ASM) to generate a test statement; the test statement is logically the same as or opposite to the conditional statement; based on the test statement, an instrumentation statement containing a first value is set before the test statement; and / or, an instrumentation statement containing a second value is set after the test statement.

[0232] In one embodiment, when the computer program is run by the processor, it performs the following: determining the value of the test statement conditional statement based on the execution status of the instrumentation statement containing a first value and the instrumentation statement containing a second value; determining the value of the conditional statement according to the value of the test statement; wherein the value of the conditional statement indicates the execution result of the conditional statement.

[0233] In one embodiment, when the computer program is run by the processor, it executes: if both the instrumentation statement containing the first value and the instrumentation statement containing the second value are executed, it determines that the value of the test statement is a true Boolean value; and / or, if the instrumentation statement containing the first value is executed and the instrumentation statement containing the second value is not executed, it determines that the value of the test statement is a false Boolean value.

[0234] In one embodiment, when the computer program is run by the processor, it performs the following: when the test statement and the conditional statement are logically identical, the value of the conditional statement is equal to the value of the test statement; and / or, when the test statement and the conditional statement are logically opposite, the value of the conditional statement is equal to the inverted value of the test statement.

[0235] It should be noted that the computer-readable storage medium provided in the embodiments of the present invention may be a memory such as FRAM, ROM, PROM, EPROM, EEPROM, Flash Memory, magnetic surface memory, optical disk, or CD-ROM; or it may be a device including one or any combination of the above-mentioned memories.

[0236] The above description is merely an embodiment of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, and improvements made within the spirit and scope of the present invention are included within the scope of protection of the present invention.

Claims

1. A method for determining the value of a conditional statement, characterized in that, The method includes: From the statement blocks of the source code, determine the decision statement blocks that contain decision statements; wherein, the statement block includes: multiple consecutively distributed code statements; the code statement includes: an entry statement and an exit statement; The judgment statement is parsed to generate a condition block, condition block information corresponding to the condition block, and logical operators corresponding to the condition block; the condition block includes: a single condition statement block, a single condition combination statement block, and a judgment statement block; the condition block information includes: condition block position index, judgment statement block position information, judgment statement file ID, condition block code, and condition block type identifier. Based on the condition block information corresponding to the condition block, the condition statement in the decision statement is determined; the condition statement is bytecode analyzed using assembly language (ASM) to generate a test statement; the test statement is logically the same as or opposite to the condition statement; based on the test statement, an instrumentation statement containing a first value is set before the test statement; and / or, an instrumentation statement containing a second value is set after the test statement. Based on the execution status of the instrumentation statement containing the first value and the instrumentation statement containing the second value, the value of the test statement is determined; based on the value of the test statement, the value of the conditional statement is determined; wherein, the value of the conditional statement indicates the execution result of the conditional statement.

2. The method for determining the value of a conditional statement according to claim 1, characterized in that, The process of determining the value of the test statement based on the execution status of the instrumentation statement containing the first value and the instrumentation statement containing the second value includes: If both the instrumentation statement containing the first value and the instrumentation statement containing the second value are executed, the value of the test statement is determined to be a true Boolean value. And / or, If the instrumentation statement containing the first value is executed, and the instrumentation statement containing the second value is not executed, the value of the test statement is determined to be a false Boolean value.

3. The method for determining the value of a conditional statement according to claim 1 or 2, characterized in that, Determining the value of the conditional statement based on the value of the test statement includes: When the test statement and the conditional statement have the same logic, the value of the conditional statement is equal to the value of the test statement. And / or, When the test statement is logically opposite to the conditional statement, the value of the conditional statement is equal to the value of the inverted test statement.

4. A device for determining the value of a conditional statement, characterized in that, The device includes: a first determining module, a setting module, and a second determining module; The first determining module is configured to determine, from the statement blocks of the source code, a decision statement block containing a decision statement; wherein, the statement block includes: multiple consecutively distributed code statements; the code statement includes: an entry statement and an exit statement; parse the decision statement to generate a condition block, condition block information corresponding to the condition block, and logical operators corresponding to the condition block; the condition block includes: a single-condition statement block, a single-condition combined statement block, and a decision statement block; the condition block information includes: a condition block position index, decision statement block position information, decision statement file ID, condition block code, and condition block type identifier; and determine the condition statement in the decision statement based on the condition block information corresponding to the condition block. The setting module is used to perform bytecode analysis on the conditional statement using assembly language (ASM) to generate a test statement; the test statement is logically the same as or opposite to the conditional statement; based on the test statement, an instrumentation statement containing a first value is set before the test statement; and / or, an instrumentation statement containing a second value is set after the test statement. The second determining module is used to determine the value of the test statement based on the execution status of the instrumentation statement containing a first value and the instrumentation statement containing a second value; and to determine the value of the condition statement based on the value of the test statement; wherein the value of the condition statement indicates the execution result of the condition statement.

5. The conditional statement value determination device according to claim 4, characterized in that, The second determining module is specifically used for: If both the instrumentation statement containing the first value and the instrumentation statement containing the second value are executed, the value of the test statement is determined to be a true Boolean value. And / or, If the instrumentation statement containing the first value is executed, and the instrumentation statement containing the second value is not executed, the value of the test statement is determined to be a false Boolean value.

6. The conditional statement value determination device according to claim 4 or 5, characterized in that, The second determining module is specifically used for: When the test statement and the conditional statement have the same logic, the value of the conditional statement is equal to the value of the test statement. And / or, When the test statement is logically opposite to the conditional statement, the value of the conditional statement is equal to the value of the inverted test statement.

7. A device for determining the value of a conditional statement, characterized in that, The device includes: a processor and a memory for storing computer programs capable of running on the processor; When the processor is used to run the computer program, it performs the steps of the method according to any one of claims 1 to 3.

8. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 3.