IP Library › Granted Patent US 11,151,018
Granted Patent B2
US 11,151,018 · App. 15/953,020 · Granted Oct 19, 2021

Method and apparatus for testing a code file

Inventors: Peng Li (Sunnyvale, CA); Yaohui Chen (Sunnyvale, CA); Tao Wei (Sunnyvale, CA)
Assignee: BAIDU USA LLC
G06F11/3644G06F11/3684G06F11/3688
View Patent ↗
Loading inventors, assignments & file history…
Monitor This Case
Get email alerts when status or documents change.
Order Certified Copies
Most orders are placed with the USPTO same day — all within 24 business hours.
Order via The Patent Place →
Pre-filled with this patent's details
Quick Facts
Patent No.
US 11,151,018
App. No.
15/953,020
Granted
Oct 19, 2021
Kind
B2
Abstract

Embodiments of the present disclosure disclose a method and an apparatus for testing a code file. A preferred embodiment of the method comprises: compiling a to-be-tested code file to obtain an intermediate code file; instrumenting a code block identifier of each code block in the intermediate code file to the intermediate code file; determining an identifier of a jump relationship between two code blocks that have the jump relationship in the intermediate code file; performing dynamic testing to the instrumented intermediate code file based on respective code block identifiers and respective identifiers of jump relationships. This embodiment enhances bug detection capabilities for testing a code file.

Claims (57)

1. A method for testing a code file, comprising:

compiling a to-be-tested code file to obtain an intermediate code file, the intermediate code file comprising at least one code block and a second instrumentation content, wherein the second instrumentation content includes an error detection statement and a location labeled statement for indicating a location of the error detection statement;

instrumenting a first instrumentation content into the intermediate code file, wherein the first instrumentation content includes a code block identifier of each code block in the intermediate code file;

determining an identifier of a jump relationship between two code blocks that have the jump relationship in the intermediate code file based on respective code block identifiers in the intermediate code file, comprising:

parse the intermediate code file, and determine that the two code blocks have the jump relationship in the intermediate code file when there is an execution path for jumping from an execution of a first code block in the two code blocks and a conditional statement to an execution of a second code block in the two code blocks; and

performing dynamic testing to the instrumented intermediate code file based on respective code block identifiers and respective identifiers of jump relationships between code blocks, to generate a testing result of testing the to-be-tested code file, comprising:

compiling the instrumented intermediate code file to obtain an object file corresponding to the instrumented intermediate code file; and

performing grey box fuzz testing to the obtained object file and performing concolic execution to the instrumented intermediate code file to generate the testing result of testing the to-be-tested code file, comprising a second testing operation that comprises:

using a candidate test case used in grey box fuzz testing of the obtained object file as an input for concolic execution of the instrument intermediate code file, the candidate test case comprises a test case in a testing process information, wherein an error access identifier of the testing process information is yes or identifiers of accessed jump relationships of the testing process information are not empty, or the error access identifier of the testing process information is yes and the identifiers of the accessed jump relationships of the testing process information are not empty; performing, using the candidate test case, concolic execution to the instrumented intermediate code file to generate a complementary test case, wherein the error access identifier corresponding to the grey box fuzz testing process characterizes whether the grey box fuzz testing process has accessed the error detection statement; and

using the obtained complementary test case as an input for the grey box fuzz testing of the obtained object file to generate the testing result of testing the to-be-tested code file.

2. The method according to claim 1 , wherein the step of performing dynamic testing to the instrumented intermediate code file based on respective code block identifiers and respective identifiers of jump relationships, to generate a testing result of testing the to-be-tested code file, comprises:

compiling the instrumented intermediate code file to obtain an object file corresponding to the instrumented intermediate code file;

performing grey box fuzz testing to the object file based on respective code block identifiers and respective identifiers of jump relationships, to generate a testing result of testing the to-be-tested code file.

3. The method according to claim 1 , wherein the step of performing dynamic testing to the instrumented intermediate code file based on respective code block identifiers and respective identifiers of jump relationships, to generate a testing result of testing the to-be-tested code file, comprises:

performing concolic execution to the instrumented intermediate code file based on respective code block identifiers and respective identifiers of jump relationships, to generate a testing result of testing the to-be-tested code file.

4. The method according to claim 1 ,

wherein the step of alternately performing grey box fuzz testing to the object file and performing concolic execution to the instrumented intermediate code file based on respective code block identifiers and respective identifiers of jump relationships, to generate a testing result of testing the to-be-tested code file, comprises:

generating a set of test cases, and creating an empty set of testing process information; and executing a first testing operation that comprises:

performing, with a test case in the set of test cases as input, grey box fuzz testing to the object file in response to determining that a preset switch condition is not satisfied;

generating the testing process information, based on the test case used in the grey box fuzz testing process, the identifiers of the jump relationships accessed in the grey box fuzz testing process, and the error access identifier corresponding to the grey box fuzz testing process; and

adding the testing process information as generated to the set of testing process information.

5. The method according to claim 4 , wherein the first testing operation further comprises:

deleting the test case used in the grey box fuzz testing process from the set of test cases.

6. The method according claim 1 , wherein the method further comprises:

in response to determining that a preset switch condition is satisfied, performing the second testing operation, wherein the second testing operation further comprises:

generating a set of candidate test cases using the candidate test case;

performing, using the candidate test case in the set of candidate test cases, concolic execution to the instrumented intermediate code file, to generate the complementary test case that an execution path of the complementary test case is complementary to an execution path of the inputted candidate test case;

adding the complementary test case as generated to the set of candidate test cases; and

continuing to perform the grey box fuzz testing to the obtained object file by using the obtained complementary test case as an input.

7. The method according to claim 6 , wherein, the second testing operation further comprises: before continuing to perform the grey box fuzz testing to the obtained object file by using the obtained complementary test case as an input,

deleting the candidate test case used during the concolic execution from the set of candidate test cases.

8. The method according to claim 1 , wherein the method further comprises:

taking a result of performing grey box fuzz testing to the object file as a testing result of testing the to-be-tested code file in response to determining that a preset end condition is satisfied.

9. The method according to claim 1 , wherein the code block identifier of the each code block is instrumented to a preset location of the each code block.

10. An electronic device, comprising:

an interface;

a memory on which a computer program is stored; and

one or more processors operably coupled to the interface and the memory, wherein the one or more processors function to:

compile a to-be-tested code file to obtain an intermediate code file, the intermediate code file comprising at least one code block and a second instrumentation content, wherein the second instrumentation content includes an error detection statement and a location labeled statement for indicating a location of the error detection statement;

instrument a first instrumentation content into the intermediate code file, wherein the first instrumentation content includes a code block identifier of each code block in the intermediate code file;

determine an identifier of a jump relationship between two code blocks that have the jump relationship in the intermediate code file based on respective code block identifiers in the intermediate code file, comprising:

parse the intermediate code file, and determine that the two code blocks have the jump relationship in the intermediate code file when there is an execution path for jumping from an execution of a first code block in the two code blocks and a conditional statement to an execution of a second code block in the two code blocks; and

perform dynamic testing to the instrumented intermediate code file based on respective code block identifiers and respective identifiers of jump relationships between code blocks, to generate a testing result of testing the to-be-tested code file, comprising:

compiling the instrumented intermediate code file to obtain an object file corresponding to the instrumented intermediate code file; and

performing grey box fuzz testing to the obtained object file and performing concolic execution to the instrumented intermediate code file to generate the testing result of testing the to-be-tested code file, comprising a second testing operation that comprises:

using a candidate test case used in grey box fuzz testing of the obtained object file as an input for concolic execution of the instrument intermediate code file, the candidate test case comprises a test case in a testing process information, wherein an error access identifier of the testing process information is yes or identifiers of accessed jump relationships of the testing process information are not empty, or the error access identifier of the testing process information is yes and the identifiers of the accessed jump relationships of the testing process information are not empty; performing, using the candidate test case, concolic execution to the instrumented intermediate code file to generate a complementary test case, wherein the error access identifier corresponding to the grey box fuzz testing process characterizes whether the grey box fuzz testing process has accessed the error detection statement; and

using the obtained complementary test case as an input for the grey box fuzz testing of the obtained object file to generate the testing result of testing the to-be-tested code file.

11. A non-transitory computer-readable medium on which a computer program is stored, wherein the computer program, when being executed by or more processors, cause the one or more processors to:

compile a to-be-tested code file to obtain an intermediate code file, the intermediate code file comprising at least one code block and a second instrumentation content, wherein the second instrumentation content includes an error detection statement and a location labeled statement for indicating a location of the error detection statement;

instrument a first instrumentation content to the intermediate code file, wherein the first instrumentation content includes a code block identifier of each code block in the intermediate code file;

determine an identifier of a jump relationship between two code blocks that have the jump relationship in the intermediate code file based on respective code block identifiers in the intermediate code file, comprising:

parse the intermediate code file, and determine that the two code blocks have the jump relationship in the intermediate code file when there is an execution path for jumping from an execution of a first code block in the two code blocks and a conditional statement to an execution of a second code block in the two code blocks; and

perform dynamic testing to the instrumented intermediate code file based on respective code block identifiers and respective identifiers of jump relationships between code blocks, to generate a testing result of testing the to-be-tested code file, comprising:

compiling the instrumented intermediate code file to obtain an object file corresponding to the instrumented intermediate code file; and

performing grey box fuzz testing to the obtained object file and performing concolic execution to the instrumented intermediate code file to generate the testing result of testing the to-be-tested code file, comprising a second testing operation that comprises:

using a candidate test case used in grey box fuzz testing of the obtained object file as an input for concolic execution of the instrument intermediate code file, the candidate test case comprises a test case in a testing process information, wherein an error access identifier of the testing process information is yes or identifiers of accessed jump relationships of the testing process information are not empty, or the error access identifier of the testing process information is yes and the identifiers of the accessed jump relationships of the testing process information are not empty; performing, using the candidate test case, concolic execution to the instrumented intermediate code file to generate a complementary test case, wherein the error access identifier corresponding to the grey box fuzz testing process characterizes whether the grey box fuzz testing process has accessed the error detection statement; and

using the obtained complementary test case as an input for the grey box fuzz testing of the obtained object file to generate the testing result of testing the to-be-tested code file.

Assignments (1)
ASSIGNMENT OF ASSIGNOR'S INTEREST Recorded Sep 4, 2020
From: LI, PENG; CHEN, YAOHUI; WEI, TAO
To: BAIDU USA LLC
Reel/Frame 053697/0226 →
Continuity (1)
Related Publication 20190317882A1 · Oct 17, 2019
Cited By (1)
US 12,711,041