Lazy symbolization method and system for complex type input variables for symbolic execution

Through lazy symbolization strategy and dynamic mapping relationship management, the problems of low automation and high memory overhead in the symbolization process of complex type input variables are solved, the speed and performance of use case generation are improved, and a more flexible symbolization mechanism is realized.

CN114896145BActive Publication Date: 2024-09-20BEIJING XUANYU INFORMATION TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202210453325.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-04-27
Publication Date
2024-09-20
Estimated Expiration
2042-04-27

AI Technical Summary

Technical Problem

In the process of symbolizing complex type input variables in symbolic execution, the existing technology cannot determine the specific form in advance, resulting in a low degree of automation, cumbersome use, slow generation speed, and high memory overhead.

Method used

Using the lazy symbolization strategy, by generating the mapping relationship between the input driver file and the record variable, actual value, and symbolic value, the symbolic value is dynamically created during the execution process, and only the accessed memory address is symbolized to generate the use case data file.

Benefits of technology

It improves the speed of use case generation, reduces memory overhead, supports a more flexible symbolic mechanism, improves performance, eliminates the storage of useless expressions, and achieves more efficient symbolic execution.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114896145B
    Figure CN114896145B
Patent Text Reader

Abstract

A lazy symbolization method and system for complex type input variables for symbolic execution, including generating an input driver file, specifying input variables and driving a tested function through an entry function; allocating symbolic memory; when executing a statement, interpretive execution and symbolic execution respectively operate on the actual value and symbolic value at the same address; when accessing the memory address during the execution process, interpretive execution directly reads and writes the content of the actual value mapping table; symbolic execution first checks whether there is a symbolic value at the address in the symbolic value mapping table, and directly reads and writes if it exists; if it does not exist, a new symbolic value is created, and a new address and symbolic value mapping is added to the symbolic value mapping table, and then normal reading and writing are performed; after a symbolic execution is completed, the collected constraints are inverted and solved, and finally the mapping relationship between expressions and values ​​is obtained, and a use case data file is generated. The present invention adopts a lazy symbolization strategy for complex type input variables to improve the generation speed of use cases and reduce memory overhead.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to a lazy symbolization method and system for complex type input variables used for symbolic execution, and belongs to the technical field of program testing. Background Art

[0002] At present, symbolic execution technology has been widely used in various test case generation methods and tools due to its automation and precision. Its basic principle is to symbolize the input variables of a tested software or module, and execute the code symbolically according to the logical structure of the tested code. The program state during the execution process is characterized by symbolic expressions of the relevant input variables, collect the constraints of the current execution path, and select a branch point on the path according to a certain strategy. The corresponding constraints in the path constraints are inverted, and then the newly generated path constraints are solved, which can generate a set of solutions for the input variables, that is, a test case that can cover the specified path; through continuous iterative search, test cases with high coverage can be generated.

[0003] In this process, the symbolization of input variables determines the accuracy and complexity of the symbolic expression of constraints in the subsequent symbolic execution. In particular, when the input variables are complex types such as structures and pointers, the symbolization of input variables involves expansion according to the specific actual memory form. For example, an input variable is a structure pointer, which may point to a linked list of length N. The most accurate symbolization is to symbolize the specific data and next members of the N linked list nodes.

[0004] The main problem with the existing technology is that the specific form of the input variable cannot be known before symbolic execution. Therefore, the general method requires the user to specify the specific symbolic input, or to symbolize the variable in advance according to the given expansion depth. The user-specified method has a low degree of automation and is cumbersome to use. Summary of the invention

[0005] The technical problem solved by the present invention is: to overcome the shortcomings of the prior art, to provide a lazy symbolization method and system for complex type input variables for symbolic execution, to adopt a lazy symbolization strategy for complex type input variables, to symbolize the input variables in a targeted manner, thereby improving the generation speed of use cases and reducing memory overhead.

[0006] The technical solution of the present invention is:

[0007] A lazy symbolization method for complex type input variables for symbolic execution, including:

[0008] (1) Generate an input driver file, specify input variables and drive the function under test through the entry function;

[0009] (2) Allocate symbolic memory: Start from the entry function by interpreting and driving symbolic execution. First, allocate memory and record the following three mapping relationships: variable allocation address mapping table var_addr_map, actual value mapping table value_map, and symbol value mapping table sym_map;

[0010] (3) When a statement is executed, interpreted execution and symbolic execution respectively operate on the actual value and symbolic value at the same address; the address of a variable or expression in the actual value mapping table value_map and the symbolic value mapping table sym_map are completely consistent;

[0011] (4) When accessing a memory address during execution, the interpreted execution directly reads and writes the contents of the actual value mapping table value_map; the symbolic execution first checks whether there is a symbol value at the address in the symbol value mapping table sym_map, and if so, directly reads and writes it; if not, a new symbol value is created, and a new address and symbol value mapping is added to the symbol value mapping table sym_map, and then normal read and write operations are performed; when the execution reaches a branch node, the interpreted execution determines the next statement to be executed, and the symbolic execution adds the symbolic value of the branch node judgment statement to the constraint;

[0012] (5) After a symbolic execution is completed, the collected constraints are inverted and solved to obtain the value corresponding to the symbolic value, and then the corresponding relationship between the memory address and the value is obtained, which is then converted into a mapping relationship between the input expression and the value to generate a use case data file;

[0013] (6) The execution process ends.

[0014] Furthermore, when generating the input driver file, the variable as a whole is directly specified as input, and the complex type variable is not expanded into sub-expressions.

[0015] Furthermore, the variable allocation address mapping table var_addr_map includes Var representing the variable or function name and the integer Addr representing the address; the actual value mapping table value_map includes the integer Addr representing the address and the actual value model Value; the symbol value mapping table sym_map includes the integer Addr representing the address and the symbol value model Sym.

[0016] Furthermore, the variable allocation address mapping table var_addr_map and the actual value mapping table value_map are initialized when memory is allocated, and the addresses and values ​​of all variables are recorded therein; the symbol value mapping table sym_map is initialized to empty, and symbol value records are dynamically added during execution.

[0017] Furthermore, the conversion into a mapping relationship between an input expression and a value specifically includes:

[0018] Determine which variable's memory range the address belongs to according to the variable allocation address mapping table var_addr_map. If it is a scalar type, directly determine the variable corresponding to the address. If it is a complex type, recursively expand and binary search to find the input expression corresponding to the address.

[0019] Convert all solution results into a mapping relationship between expressions and values, and generate a use case data file.

[0020] Furthermore, the scalar type refers to: a basic type or a type without members, the basic type includes int type, and the type without members includes enumeration and pointer;

[0021] The complex type refers to: a type containing members; the type containing members includes structures, unions, and arrays.

[0022] Furthermore, the present invention also proposes a complex type input variable lazy symbolization system for symbolic execution, comprising:

[0023] Driver file generation module: generates input driver files, specifies input variables and drives the tested function through entry functions;

[0024] Symbol memory allocation module: starts from the entry function by interpreting and driving symbolic execution, first performs memory allocation, and records the following three mapping relationships: variable allocation address mapping table var_addr_map, actual value mapping table value_map, and symbol value mapping table sym_map;

[0025] Symbolic execution module: When a statement is executed, the interpreted execution and symbolic execution respectively operate on the actual value and symbolic value at the same address; the address of a variable or expression in the actual value mapping table value_map and the symbolic value mapping table sym_map are exactly the same;

[0026] When accessing the memory address during the execution process, the interpreted execution directly reads and writes the contents of the actual value mapping table value_map; the symbolic execution needs to first check whether there is a symbol value at the address in the symbol value mapping table sym_map, and if so, directly read and write; if not, create a new symbol value, add a new address and symbol value mapping in the symbol value mapping table sym_map, and then perform normal read and write operations; when executing to a branch node, the interpreted execution determines the next statement to be executed, and the symbolic execution adds the symbolic value of the branch node judgment statement to the constraint;

[0027] Mapping relationship solving module: After a symbolic execution is completed, the collected constraints are inverted and solved to obtain the value corresponding to the symbolic value, and then the corresponding relationship between the memory address and the value is obtained, which is then converted into a mapping relationship between the input expression and the value to generate a use case data file.

[0028] The beneficial effects of the present invention compared with the prior art are:

[0029] (1) This method is improved on the basis of the existing technology and adopts a lazy symbolization strategy. The currently disclosed patents or technologies do not adopt the lazy symbolization method during the execution process. The present invention targets complex types of input variables and symbolizes the input variables in a targeted manner, thereby improving the generation speed of use cases and reducing memory overhead.

[0030] (2) During the execution of this method, interpreted execution is used to determine the expressions that need to be symbolized, effectively filtering out useless expressions and supporting a symbolic lazy loading mechanism. This method is more flexible and has higher performance than the static specification method. After the solution, the result is mapped to the input expression through the address and binary search, which can eliminate the mapping table information that stores the expression and address.

[0031] (3) This method is based on a self-developed hybrid execution engine and has advantages in embedded feature support, new function expansion, performance optimization, and localization. BRIEF DESCRIPTION OF THE DRAWINGS

[0032] Figure 1 It is a flow chart of the present invention. DETAILED DESCRIPTION

[0033] The specific embodiments of the present invention are further described in detail below with reference to the accompanying drawings.

[0034] The existing methods in the prior art mainly have the following problems

[0035] 1) Recursive expansion results in a large number of input expressions, which causes the generated input driver file to be too large, too many symbolic values, a significant drop in generation speed, high memory usage, and even memory overflow;

[0036] 2) Low symbol efficiency: According to statistics, in the case of complex types, more than 95% of the symbol values ​​will not be accessed in the program, which means that a large amount of symbolic input is worthless;

[0037] 3) The root cause of the above problems is that it is impossible to statically determine which inputs need to be symbolized, so the strategy of symbolizing all of them is adopted, which leads to a series of subsequent problems.

[0038] This method is improved on the basis of the existing technology and adopts a lazy symbolization strategy: at the beginning of symbolic execution, the input variables are not recursively expanded and symbolized, and only the memory start and end addresses of the variable symbols are recorded. During the execution process, if the accessed memory address has no symbolic value, the symbolic value is dynamically created and bound to the address. After the symbolic execution is completed, the solution result is converted into a mapping relationship between the input expression and the value.

[0039] like Figure 1 As shown, the lazy symbolization method for complex type input variables for symbolic execution proposed by the present invention has the following operating steps:

[0040] 1) Generate an input driver file, specify input variables and drive the function under test through the entry function. This method directly specifies the variables as input, and complex type variables are not expanded into sub-expressions;

[0041] 2) Start execution from the entry function by interpreting and driving symbolic execution, first allocate memory, and record the following three mapping relationships:

[0042] Variable allocation address mapping table var_addr_map<Var,Addr> ,

[0043] Actual value mapping table (actual memory) value_map<Addr,Value> ,

[0044] Symbol value mapping table (symbol memory) sym_map<Addr,Sym> ,

[0045] The variable allocation address mapping table var_addr_map includes Var representing the variable or function name and the integer Addr representing the address; the actual value mapping table value_map includes the integer Addr representing the address and the actual value model Value; the symbol value mapping table sym_map includes the integer Addr representing the address and the symbol value model Sym.

[0046] Var represents the variable or function name, Addr is an integer representing the address, Value is the actual value model, which is simulated by char[] internally, and Sym is the symbol value model, which represents a symbol value. In this method, var_addr_map and value_map are initialized when memory is allocated, and the addresses and values ​​of all variables are recorded in them. Sym_map is initialized to empty, and symbol value records are dynamically added during execution;

[0047] 3) The address of a variable or expression in value_map and sym_map is exactly the same. When a statement is executed, interpreted execution and symbolic execution respectively operate on the actual value and symbolic value at the same address;

[0048] 4) When accessing the memory address during execution, the interpreted execution directly reads and writes the contents in value_map; symbolic execution first checks whether there is a symbolic value at the address in sym_map, and if so, directly reads and writes it; if not, a new symbolic value is created, and a new mapping of the address and the symbolic value is added to sym_map, and then normal read and write operations are performed; when the execution reaches a branch node, the interpreted execution determines the next statement to be executed, and the symbolic execution adds the symbolic value of the judgment statement of the branch node to the constraint;

[0049] 5) After a symbolic execution is completed, the collected constraints are inverted and solved to obtain the value corresponding to the symbolic value, and then the corresponding relationship between the memory address and the value is obtained, which is then converted into the relationship between the input expression and the value. The method is as follows:

[0050] According to var_addr_map in 2), the memory range of the variable in which the address is located can be determined. If it is a scalar type, the variable corresponding to the address can be directly determined; if it is a complex type, recursive expansion and binary search are performed to find the input expression corresponding to the address;

[0051] The scalar type refers to: a basic type or a type without members, such as int type, a type without members such as enumeration and pointer;

[0052] The complex type refers to: a type containing members; the type containing members is such as a structure, a union, and an array.

[0053] 6) According to the above method, all the solution results are converted into a mapping relationship between expressions and values, and a use case data file is generated;

[0054] 7) The execution process ends.

[0055] Furthermore, the present invention also proposes a complex type input variable lazy symbolization system for symbolic execution, comprising:

[0056] Driver file generation module: generates input driver files, specifies input variables and drives the tested function through entry functions;

[0057] Symbol memory allocation module: starts from the entry function by interpreting and driving symbolic execution, first performs memory allocation, and records the following three mapping relationships: variable allocation address mapping table var_addr_map, actual value mapping table value_map, and symbol value mapping table sym_map;

[0058] Symbolic execution module: When a statement is executed, the interpreted execution and symbolic execution respectively operate on the actual value and symbolic value at the same address; the address of a variable or expression in the actual value mapping table value_map and the symbolic value mapping table sym_map are exactly the same;

[0059] When accessing the memory address during the execution process, the interpreted execution directly reads and writes the contents of the actual value mapping table value_map; the symbolic execution needs to first check whether there is a symbol value at the address in the symbol value mapping table sym_map, and if so, directly read and write; if not, create a new symbol value, add a new address and symbol value mapping in the symbol value mapping table sym_map, and then perform normal read and write operations; when executing to a branch node, the interpreted execution determines the next statement to be executed, and the symbolic execution adds the symbolic value of the branch node judgment statement to the constraint;

[0060] Mapping relationship solving module: After a symbolic execution is completed, the collected constraints are inverted and solved to obtain the value corresponding to the symbolic value, and then the corresponding relationship between the memory address and the value is obtained, which is then converted into a mapping relationship between the input expression and the value to generate a use case data file.

[0061] This method adopts a lazy symbolization strategy. During the execution process, it uses interpreted execution to determine the expressions that need to be symbolized, effectively filters out useless expressions, and supports a symbolic lazy loading mechanism. It is more flexible and has higher performance than the static specification method. After solving, the result is mapped to the input expression through the address and binary search, which can eliminate the mapping table information that stores the expression and address.

[0062] Example:

[0063] This embodiment takes the program test as an example, and the sample code is as follows.

[0064]

[0065] The specific steps are as follows:

[0066] (1) Generate an input driver file. In the entry function of the driver file, specify the actual parameter a and the global variable bigArray as input: AUnit_Input(&a); AUnit_Input(&bigArray);

[0067] (2) Start symbol execution, allocate memory for variables. The address of variable a recorded in var_addr_map is [0x42000000, 0x42000004) (the square brackets indicate a closed interval, meaning the range includes this address, and the parentheses indicate an open interval, meaning this address is not included, the same below); record the address and actual value of a in value_map: <0x42000000, char[4]> (assuming int occupies 4 bytes). Similarly, the address range of the global variable bigArray is [0x42000004, 0x42020004), and the actual value of bigArray recorded in value_map is <0x42000004, char[0x80000]>;

[0068] (3) When executing to bigArray[0x1000] + a < bigArray[0x10000], the address of bigArray[0x1000] is 0x42001004, and the actual value at this address is 0, without a symbolic value. Then create a symbolic value v0. Since this value is of int type and occupies 4 bytes, v0 represents the symbolic value at the address range [0x42001004, 0x42001008); similarly, the starting memory addresses corresponding to a and bigArray[0x10000] are 0x42000000 and 0x42010004 respectively, and create symbolic values v2 and v3 respectively;

[0069] (4) The constraint collected after the first symbolic execution (default is 0) is!(v0 + v1 < v2). Take the negation of the constraint to become!!(v0 + v1 < v2). Assume the solved values of v0, v1, and v2 are 0, 1, and 9 respectively. Further, the values at the addresses 0x42001004, 0x42000000, and 0x42010004 are 0, 1, and 9 respectively. Then convert to the relationship between the input expression and the value. The operation steps are as follows:

[0070] (5) According to var_addr_map in (2), it can be determined that 0x42000000 belongs to variable a, and 0x42001004 and 0x42010004 belong to variable bitArray. Since a is a basic type, this address is the variable a itself; variable bitArray is a complex type, which needs to be expanded and then binary searched. After calculation, it can be determined that the input expressions corresponding to 0x42001004 and 0x42010004 are bigArray[0x1000] and bigArray[0x10000] respectively; further, the test case inputs are bigArray[0x1000] = 0, a = 1, and bigArray[0x1000] = 9. Save the data for generating test cases to the test case file;

[0071] (6) The symbolic execution process is completed.

[0072] This method has been verified on cases. ① The generation speed of a single 50KB structure variable has been increased from 45 seconds to 1 second, and the number of use cases has increased from 1 to 4, which can cover 100%; ② A single 5000KB structure variable could not be generated before optimization, but after optimization, 4 use cases can be generated within 1 second, which can cover 100%; theoretically, it supports the upper limit of the variable size supported by the compiler. Competitive tools are generally based on open source symbolic execution frameworks, such as KLEE, which have great difficulty in supporting embedded features and custom extensions. This method is based on a self-developed hybrid execution engine, which has advantages in embedded feature support, new function extensions, performance optimization, and localization.

[0073] Parts of the present invention that are not described in detail belong to common knowledge among those skilled in the art.

Claims

1. A lazy symbolization method for complex type input variables for symbolic execution, characterized in that include: Generate input driver files, specify input variables and drive the tested function through entry functions; Allocate symbolic memory: Start from the entry function by interpreting and driving symbolic execution. First, allocate memory and record the following three mapping relationships: variable allocation address mapping table var_addr_map, actual value mapping table value_map, and symbol value mapping table sym_map; When a statement is executed, interpreted execution and symbolic execution respectively operate on the actual value and symbolic value at the same address; The address of a variable or expression in the actual value mapping table value_map and the symbolic value mapping table sym_map is exactly the same; When accessing the memory address during the execution process, the interpreted execution directly reads and writes the contents of the actual value mapping table value_map; the symbolic execution needs to first check whether there is a symbol value at the address in the symbol value mapping table sym_map, and if so, directly read and write; if not, create a new symbol value, add a new address and symbol value mapping in the symbol value mapping table sym_map, and then perform normal read and write operations; when executing to a branch node, the interpreted execution determines the next statement to be executed, and the symbolic execution adds the symbolic value of the branch node judgment statement to the constraint; After a symbolic execution is completed, the collected constraints are inverted and solved to obtain the value corresponding to the symbolic value, and then the corresponding relationship between the memory address and the value is obtained, which is then converted into a mapping relationship between the input expression and the value to generate a use case data file; The execution process ends.

2. The lazy symbolization method for complex type input variables for symbolic execution according to claim 1, characterized in that: When generating an input driver file, directly specify the variable as a whole as input, and complex type variables are not expanded into sub-expressions.

3. The lazy symbolization method for complex type input variables for symbolic execution according to claim 1, characterized in that: The variable allocation address mapping table var_addr_map includes Var representing the variable or function name and the integer Addr representing the address; the actual value mapping table value_map includes the integer Addr representing the address and the actual value model Value; the symbol value mapping table sym_map includes the integer Addr representing the address and the symbol value model Sym.

4. The lazy symbolization method for complex type input variables for symbolic execution according to claim 3, characterized in that: The variable allocation address mapping table var_addr_map and the actual value mapping table value_map are initialized when memory is allocated, and the addresses and values ​​of all variables are recorded in them; The symbol value mapping table sym_map is initialized to empty, and symbol value records are dynamically added during execution.

5. The lazy symbolization method for complex type input variables for symbolic execution according to claim 3, characterized in that: The conversion into a mapping relationship between an input expression and a value specifically includes: Determine which variable's memory range the address belongs to according to the variable allocation address mapping table var_addr_map. If it is a scalar type, directly determine the variable corresponding to the address. If it is a complex type, recursively expand and binary search to find the input expression corresponding to the address. Convert all solution results into a mapping relationship between expressions and values, and generate a use case data file.

6. The lazy symbolization method for complex type input variables for symbolic execution according to claim 5, characterized in that: The scalar type refers to: a basic type or a type without members, a basic type includes an int type, and a type without members includes an enumeration and a pointer; The complex type refers to: a type containing members; the type containing members includes structures, unions, and arrays.

7. A lazy symbolization system for complex type input variables for symbolic execution, characterized by include: Driver file generation module: generates input driver files, specifies input variables and drives the tested function through entry functions; Symbol memory allocation module: starts from the entry function by interpreting and driving symbolic execution, first performs memory allocation, and records the following three mapping relationships: variable allocation address mapping table var_addr_map, actual value mapping table value_map, and symbol value mapping table sym_map; Symbolic execution module: When a statement is executed, the interpreted execution and symbolic execution respectively operate on the actual value and symbolic value at the same address; The address of a variable or expression in the actual value mapping table value_map and the symbolic value mapping table sym_map is exactly the same; When accessing the memory address during the execution process, the interpreted execution directly reads and writes the contents of the actual value mapping table value_map; the symbolic execution needs to first check whether there is a symbol value at the address in the symbol value mapping table sym_map, and if so, directly read and write; if not, create a new symbol value, add a new address and symbol value mapping in the symbol value mapping table sym_map, and then perform normal read and write operations; when executing to a branch node, the interpreted execution determines the next statement to be executed, and the symbolic execution adds the symbolic value of the branch node judgment statement to the constraint; Mapping relationship solving module: After a symbolic execution is completed, the collected constraints are inverted and solved to obtain the value corresponding to the symbolic value, and then the corresponding relationship between the memory address and the value is obtained, which is then converted into a mapping relationship between the input expression and the value to generate a use case data file.

8. A complex type input variable lazy symbolization system for symbolic execution according to claim 7, characterized in that: When generating an input driver file, directly specify the variable as a whole as input, and complex type variables are not expanded into sub-expressions.

9. A complex type input variable lazy symbolization system for symbolic execution according to claim 7, characterized in that: The variable allocation address mapping table var_addr_map includes Var representing the variable or function name and integer Addr representing the address; the actual value mapping table value_map includes integer Addr representing the address and actual value model Value; the symbol value mapping table sym_map includes integer Addr representing the address and symbol value model Sym; The variable allocation address mapping table var_addr_map and the actual value mapping table value_map are initialized when memory is allocated, and the addresses and values ​​of all variables are recorded in them; The symbol value mapping table sym_map is initialized to empty, and symbol value records are dynamically added during execution.

10. A complex type input variable lazy symbolization system for symbolic execution according to claim 9, characterized in that: The conversion into a mapping relationship between an input expression and a value specifically includes: Determine which variable's memory range the address belongs to according to the variable allocation address mapping table var_addr_map. If it is a scalar type, directly determine the variable corresponding to the address. If it is a complex type, recursively expand and binary search to find the input expression corresponding to the address. Convert all solution results into a mapping relationship between expressions and values, and generate a use case data file; The scalar type refers to: a basic type or a type without members, a basic type includes an int type, and a type without members includes an enumeration and a pointer; The complex type refers to: a type containing members; the type containing members includes structures, unions, and arrays.