# US 2019/0317882 A1 · Method and apparatus for testing a code file

> Agents: this data is available as JSON from the patentgrep API and MCP server — see https://patentgrep.com/llms.txt

- Number: US 2019/0317882 A1
- Document ID: US20190317882A1
- Status: Published application
- Kind: A1
- Application number: 15/953,020
- Filed: 2018-04-13
- Published: 2019-10-17
- Earliest claimed: 2018-04-13
- Assignees: Baidu USA LLC
- Applicants: Baidu USA LLC
- Inventors: Peng LI; Yaohui CHEN; Tao WEI
- Web page: https://patentgrep.com/patent/US20190317882A1

## CPC

- G06F 11/3644: {by instrumenting at runtime}
- G06F 11/3684: {for test design, e.g. generating new test cases}
- G06F 11/3688: {for test execution, e.g. scheduling of test suites}
- Y02D 10/00: Energy efficient computing, e.g. low power processors, power management or thermal management
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)
- Y02D: CLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE

## 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

### Claim 1

A method for testing a code file, comprising:
compiling a to-be-tested code file to obtain an intermediate code file;
instrumenting 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;
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; and
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.

### Claim 2 (depends on 1)

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;
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.

### Claim 3 (depends on 1)

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.

### Claim 4 (depends on 1)

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.

### Claim 5 (depends on 2)

The method according to claim 2, wherein the step of compiling a to-be-tested code file to obtain an intermediate code file, comprises:
compiling a to-be-tested code file to obtain an intermediate code file including 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.

### Claim 6 (depends on 5)

The method according to claim 5, 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 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, wherein the error access identifier corresponding to the grey box fuzz testing process is configured for characterizing whether the grey box fuzz testing process has accessed the error detection statement; and adding the testing process information as generated to the set of testing process information.

### Claim 7 (depends on 6)

The method according to claim 6, 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.

### Claim 8 (depends on 7)

The method according to claim 7, wherein the first testing operation further comprises:
in response to determining that the preset switch condition is satisfied, performing a second testing operation that comprises: generating a set of candidate test cases using a candidate test case, wherein the candidate test case refers to a test case in a testing process information in the set of testing process information, wherein, the error access identifier of the testing process information is yes and/or the identifiers of the jump relationships accessed of the testing process information is not empty; performing, using the candidate test case in the set of candidate test cases, concolic execution to the instrumented intermediate code file, to generate a 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 test cases; and continuing executing the first testing operation.

### Claim 9 (depends on 8)

The method according to claim 8, wherein the first testing operation 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.

### Claim 10 (depends on 9)

The method according to claim 9, wherein, the second testing operation further comprises: before continuing executing the first testing operation, deleting the candidate test case used during the concolic execution from the set of candidate test cases.

### Claim 11

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;
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; and
perform 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.

### Claim 12

A 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;
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; and
perform 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.
