CN109086215B - Embedded software unit test case generation method and system - Google Patents

Embedded software unit test case generation method and system Download PDF

Info

Publication number
CN109086215B
CN109086215B CN201811216675.4A CN201811216675A CN109086215B CN 109086215 B CN109086215 B CN 109086215B CN 201811216675 A CN201811216675 A CN 201811216675A CN 109086215 B CN109086215 B CN 109086215B
Authority
CN
China
Prior art keywords
solving
function
test case
branch
expression
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201811216675.4A
Other languages
Chinese (zh)
Other versions
CN109086215A (en
Inventor
陈睿
杨帆
江云松
王政
高栋栋
高猛
贾春鹏
陈华南
张璐
孙民
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Sunwise Information Technology Ltd
Original Assignee
Beijing Sunwise Information Technology Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Sunwise Information Technology Ltd filed Critical Beijing Sunwise Information Technology Ltd
Priority to CN201811216675.4A priority Critical patent/CN109086215B/en
Publication of CN109086215A publication Critical patent/CN109086215A/en
Application granted granted Critical
Publication of CN109086215B publication Critical patent/CN109086215B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3684Test management for test design, e.g. generating new test cases

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The invention provides a method and a system for generating a test case of an embedded software unit. The method comprises the following steps: performing static analysis on the embedded software source program file to generate an input drive file; defining a drive function in the input drive file; the driving function is used for appointing and inputting an expression or a pile function to be solved; solving the expression or the stub function according to a combined mode of interpretation execution and symbolic execution; specially encoding IO ports in embedded software into multiple symbols, and solving to obtain a value sequence; and generating a test case based on the solution result and the value sequence. The invention can simplify the operation steps of generating the test case, reduce the performance expense caused by pile insertion, ensure that the automatically generated input drive file can meet most requirements, explain and execute the software of any embedded platform, and greatly reduce the time cost and the labor cost caused by configuring the target environment.

Description

Embedded software unit test case generation method and system
Technical Field
The invention relates to the technical field of software testing, in particular to a method and a system for generating a test case of an embedded software unit.
Background
The quality of the unit is the basis of the quality of the whole software, the later test of the software can be directly influenced by the unit test effect, and finally the quality of the product is influenced to a great extent. According to statistics, many software problems can be discovered in the unit testing stage; if a problem easily found in the unit test is dragged to the later test discovery, the cost is multiplied. Therefore, unit testing is a process essential to ensure software quality.
However, as the software code scale is continuously enlarged, the efficiency of the unit test method relying on the manual design of the test case is not obviously improved, so that more manpower and material resources are required to be invested to meet the test requirement. In the unit test process, most of the time is spent in the test case design stage, so that the automatic generation of the test case is an effective method for improving the unit test efficiency.
The current methods for automatically generating test cases mainly include methods such as fuzzy test, dynamic symbol execution and the like. The fuzzy test has great randomness and is not easy to cover small probability events, boundary values and the like. The principle of generating test cases by dynamic symbolic execution is generally as follows: and running the program, recording the judgment state and the conditional constraint of the branch node in the running process, calculating the conditional constraint of the uncovered path, then performing constraint solving, wherein the solved result is the input of one case, performing next running by taking the result as the input, iterating in the way until all branches are covered, and finally converting the solved result to obtain the test case set.
Patent CN105117341A discloses a distributed automatic test case generation method based on dynamic symbolic execution, in which parameter variables are signed and identified, then code instrumentation is performed to extract branch information and control flow diagram information of a program, and then the branch information and the control flow diagram information are cross-compiled into an executable program of an embedded operating system, and are uploaded to an execution device to run the program, constraints in the running process are extracted, the constraint is formatted into a constraint solver standard format by using an automatic case generation device, a constraint solver is called to obtain a result, and then the next execution is performed until a specified condition is met. The path constraint conditions collected by the method are semantic and accurate according to the program, and are helpful for analyzing complex data structures, but the method mainly has the following problems:
(1) symbolic identification of parameter variables and code instrumentation requires manual assistance to be performed. The parameters of the program need to be symbolized and identified manually, and for complex programs or types, the overhead caused by the operation is possibly higher than that of manual design cases; too much code needs to be inserted into the instrumentation, for a complex program or type, the instrumentation code amount is likely to exceed that of a source program, and the performance reduction is not negligible; the operation steps are too complex and difficult to popularize in engineering application.
(2) Relying too much on the target compiler and the running platform. In the invention, the program is cross compiled and then uploaded to the execution device. However, the embedded platforms are of various types, different platforms have specific compilers and running environments, and the implementation of the method requires the configuration of the corresponding platform environment, which results in increased operation complexity and cost.
(3) And the test case can not be generated aiming at the embedded characteristics of IO port reading and writing, interruption and the like. Many programs in the embedded software relate to IO port access and interrupt triggering, and the existing symbol execution method does not support the situation and has limited improvement on the test efficiency.
Disclosure of Invention
The embodiment of the invention provides a method and a system for generating a test case of an embedded software unit, which aim to solve the problems that the generation of the test case in the prior art needs manual execution, the operation complexity is higher, the cost waste is caused, and the test efficiency of the test case is lower.
In order to solve the technical problem, the invention is realized as follows:
in a first aspect, an embodiment of the present invention provides a method for generating a test case of an embedded software unit, including: performing static analysis on a source program file corresponding to the embedded software unit to generate an input drive file; defining a drive function in the input drive file; the driving function is used for appointing and inputting an expression or a pile function to be solved; solving the expression or the stub function according to the combination of interpretation execution and symbolic execution; the IO port in the embedded software unit is specially coded into multiple symbols to be solved to obtain a value sequence; and generating a test case based on the solution result and the value sequence.
Preferably, the step of performing static analysis on the source program file corresponding to the embedded software unit to generate the input driver file includes: performing static analysis on the source program file; and generating the input drive file according to the function interface information based on the static analysis result.
Preferably, the step of solving the expression or the stub function in a manner of combining the interpretation execution and the symbolic execution includes: symbolizing the expression or the stub function by using an interpretation execution mode; carrying out constraint solving on the symbolized expression or the stake function; collecting branch constraints in the constraint solving process according to the symbolic execution mode; and determining the collected branch constraints as solution results.
Preferably, the step of specially encoding the IO port in the embedded software unit into multiple symbols and solving to obtain a value sequence includes: when the symbols access the IO port, the IO port is coded into new symbols, so that one IO port corresponds to a plurality of symbols; and synthesizing the solving results of the plurality of symbols corresponding to the IO ports into a group of value sequences.
Preferably, the step of generating a test case based on the solution result and the value sequence includes: converting the collected branch constraints and the value sequence into a real use case; and storing the real case to generate the test case.
Preferably, after the step of generating a test case based on the solution result and the value sequence, the method further includes: searching uncovered branches in the expression or the stub function by utilizing a branch search algorithm according to the collected constraints; carrying out constraint solving on the uncovered branch; repeatedly executing the steps; after the search is finished, converting the result of each constraint solving and the value sequence into a real case of one execution path; and storing each real case to generate a test case set.
In a second aspect, an embodiment of the present invention further provides an embedded software unit test case generation system, including: the input drive file generation module is used for performing static analysis on the source program file corresponding to the embedded software unit to generate an input drive file; the drive function definition module is used for defining a drive function in the input drive file; the driving function is used for appointing and inputting an expression or a pile function to be solved; the mixed mode solving module is used for solving the expression or the stub function according to a mode of combining interpretation execution and symbolic execution; the value sequence solving module is used for specially encoding the IO port in the embedded software unit into multiple symbols and solving to obtain a value sequence; and the test case generation module is used for generating a test case based on the solution result and the value sequence.
Preferably, the input driver file generating module includes: the static analysis submodule is used for carrying out static analysis on the source program file; and the input drive file generation submodule is used for generating the input drive file according to the function interface information based on the static analysis result.
Preferably, the mixed-mode solving module includes: the symbolization submodule is used for symbolizing the expression or the stub function by using an interpretation execution mode; the constraint solving submodule is used for carrying out constraint solving on the symbolized expression or the symbolic pile function; the branch constraint collection submodule is used for collecting branch constraints in the constraint solving process according to the symbolic execution mode; and the solution result determining submodule is used for determining the collected branch constraints as solution results.
Preferably, the value sequence solving module includes: the encoding submodule is used for encoding the IO port into a new symbol when the symbol executes to access the IO port, so that one IO port corresponds to a plurality of symbols; and the value sequence solving submodule is used for synthesizing solving results of a plurality of symbols corresponding to the IO port into a group of value sequences.
Preferably, the test case generation module includes: the real case conversion submodule is used for converting the collected branch constraints and the value sequence into a real case; and the test case generation submodule is used for storing the real case to generate the test case.
Preferably, the method further comprises the following steps: an uncovered branch searching module, configured to search uncovered branches in the expression or the stub function by using a branch search algorithm according to the collected constraints; the branch constraint solving module is used for carrying out constraint solving on the uncovered branches; the repeated execution module is used for repeatedly executing the uncovered branch searching module and the branch constraint solving module; the branch real case conversion module is used for converting the result of each constraint solving and the value sequence into a real case of an execution path after the searching is finished; and the test case set generating module is used for storing each real case to generate a test case set.
In the embodiment of the invention, an input drive file is generated by performing static analysis on a source program file corresponding to an embedded software unit, a drive function is defined in the input drive file, the drive function is used for executing an expression or a stub function to be solved, the expression or the stub function is solved according to a mode of combining interpretation execution and symbolic execution, IO ports in embedded software are specially coded into multiple symbols, a value sequence is obtained by solving, and then a test case is generated based on a solving result and the value sequence.
The scheme provided by the embodiment of the invention has the following advantages:
(1) and (4) adopting a mode of inputting a drive file to replace symbol instrumentation. The file can be automatically generated, manual editing and modification are supported, high flexibility is achieved, operation steps are simplified, and performance overhead caused by pile insertion is reduced; in general, the automatically generated input drive file can meet most requirements;
(2) interpreted execution is used instead of a compilation run. The method reduces the overhead brought by compiling, more importantly, the whole process is independent of a target platform and a compiler, no matter which embedded platform software can be interpreted and executed (static analysis is compatible with a platform dialect), and the time cost and the labor cost brought by configuring the target environment are greatly reduced.
Drawings
FIG. 1 is a flowchart illustrating steps of a method for generating test cases of embedded software units according to an embodiment of the present invention;
fig. 2 is a schematic structural diagram of an embedded software unit test case generation system according to an embodiment of the present invention.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, not all, embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
Example one
Referring to fig. 1, a flowchart illustrating steps of a method for generating an embedded software unit test case according to an embodiment of the present invention is shown, where the method for generating an embedded software unit test case specifically includes the following steps:
step 101: and performing static analysis on the source program file corresponding to the embedded software unit to generate an input drive file.
In the embodiment of the present invention, the source program file corresponding to the embedded software unit may be a C language source file in a certain unit of the embedded software, and certainly, may also be another source program file, which is not limited in this embodiment of the present invention.
In the embodiment of the invention, a C language source file is used for detailed description.
After a C language source file in the system is acquired, the C language source file may be preprocessed, and then a syntax analysis front end is used to perform syntax analysis, type and variable extraction, function control flow Chart (CFG) analysis, and function call relation analysis, so that input driver files and function related information may be obtained. The static analysis front end can be compatible with a plurality of C language dialects (such as sfr, inline compilation and the like of C51), and converts programs of all platforms into a uniform model for processing.
In a preferred embodiment of the present invention, the step 101 may include:
substep S1: performing static analysis on the source program file;
substep S2: and generating the input drive file according to the function interface information based on the static analysis result.
In the embodiment of the present invention, taking the tested program test0 as an example, static analysis is performed on the tested program test0, and it can be known that the function has 2 parameters: p and a, 2 global variables are used: g and IO _ PORT, as shown by the following codes:
Figure BDA0001833722290000061
Figure BDA0001833722290000071
as can be seen from the above codes, a global variable and a parameter can be designated as input, the global variable g has a definition and only needs to be designated as input, and the IO _ PORT is a pointer of a volatile type, does not need to be designated as input, and has been initialized, and 0x42002000 needs to be marked as a special address, and the address needs to be encoded into a plurality of symbol values when being accessed. The parameter a is a common type, is directly designated as input after defining the real parameter, and the parameter p is a pointer type, and defines the real parameter p and needs to define a pointed user variable p _ PTRTO and point p to the p _ PTRTO.
Based on the static analysis result, the function interface information can be called to generate an input drive file, and the content of the generated input drive file is as follows:
Figure BDA0001833722290000072
after the input driver file is generated, step 102 is performed.
Step 102: defining a drive function in the input drive file.
In the embodiment of the invention, the driving function can input the expression or the stub function to be solved in English specification.
After the input driver file is generated, a driver function may be defined in the input driver file.
It is to be understood that the above-mentioned driving function may be a function customized by the developer, and how to define the driving function is a well-known technique in the art, and the embodiment of the present invention is not described in detail herein.
In the driving function, an expression requiring solution Input is specified using a special function sunwise _ Input, and a Stub function for generating Input is specified using a special function sunwise _ Stub. The expression of the complex type needs to be decomposed into sub-expressions of scalar type (basic type and enumeration) and then respectively specified as input; the pointer type requires creating and pointing to a user (or user function) variable and then taking the user variable (function) as the solution input. Typically, function parameters, global variables used, and stub functions all need to be specified as inputs. The pile function action can be decomposed into 3 types of return values, global variable modification and pointer type parameter modification, expressions of the actions are designated as solving input respectively, and solving results are recombined to reflect the complex action of the pile function.
After defining a driving function, step 103 is performed.
Step 103: and solving the expression or the stub function according to a combined mode of interpretation execution and symbolic execution.
In the embodiment of the present invention, a hybrid execution manner may be adopted to solve the expression or stub function to be solved, where the hybrid execution manner includes an interpretation execution manner and a symbolic execution manner.
Specifically, the process of solving the expression or stub function in terms of the interpretive and symbolic execution is described in detail in the preferred embodiments below.
In a preferred embodiment of the present invention, the step 103 may include:
substep N1: symbolizing the expression or the stub function by using an interpretation execution mode;
substep N2: carrying out constraint solving on the symbolized expression or the stake function;
substep N3: collecting branch constraints in the constraint solving process according to the symbolic execution mode;
substep N4: and determining the collected branch constraints as solution results.
In the embodiment of the present invention, interpretation and execution may be started from a driver function in an Input driver file, an interpreter memory and a symbolic memory are allocated first, and when a sunside _ Input function is encountered, a corresponding expression is symbolized: g, a, p _ PTRTO [0], … …, p _ PTRTO [7] are encoded as bit vector symbol values of v0, v1, v2, v3, v4 … …, respectively, and stored in a symbol memory at an address that is consistent with its address in the interpreter memory.
The first mixing execution is performed using the default values as inputs. The integer default value is 0, the floating point default value is 0.0, and the pointer default value is a pointer to a user variable or a user function.
Firstly, simulating a function call stack, distributing function local variables p and a to the stack and loading actual parameter values. And then executing downwards in sequence according to the statements on the nodes of the control flow diagram.
In the operation process, the expression or the address in the sentence is read, calculated or stored, and the symbolic value of the expression is updated. When the statement is a statement, only one successor node is provided, and the next node is directly entered for continuous execution; when the statement is a branch statement (if, while, for, switch, etc.), it is necessary to decide the next execution node according to the actual result of the decision node and add the decision symbol value of the node to the constraint, and if the default value is adopted for the first execution and the decision result of if (g ═ p + a) is true, the jump is made to return 0; node and encode the constraint into the Z3 standard format "(═ v0(bvadd v1 v 3)".
5.2 when accessing 0x42002000, a new symbol value is created each time a symbol value is read (e.g. v11, v12) since this address has been previously marked as an IO port, and finally the constraint for this address becomes (and (v 110 x0) (-v 120 x1)), solving for the post-value sequence values 0x0, 0x 1.
And when the node is an exit node, the function is popped, the return value is stored, and one-time mixed execution is finished.
Step 104: and specially encoding the IO port in the embedded software unit into multiple symbols, and solving to obtain a value sequence.
In the embodiment of the present invention, IO ports and interrupt processing may also be adopted, the IO ports in the embedded software are specially encoded into multiple symbols, and a value sequence is obtained by solving, and a specific process is described in detail in the following preferred embodiment.
In a preferred embodiment of the present invention, the step 104 may include:
substep C1: when the symbols access the IO port, the IO port is coded into new symbols, so that one IO port corresponds to a plurality of symbols;
substep C2: and synthesizing the solving results of the plurality of symbols corresponding to the IO ports into a group of value sequences.
When reading an IO port address (such as a serial port or a vertex pointer), a new symbol adding constraint is created each time the memory address is read during symbol execution, and a value sequence can be obtained after solving. The context of the interpretation execution respectively maintains the value sequence (from the solution result of the last iteration) of the addresses and the reading subscript thereof, when the memory address is read each time, a value is read from the value sequence according to the subscript, the reading subscript is incremented by 1, then the read value is written back to the address, and then the value is returned; the actual memory value is read directly when the value sequence read index overflows. The interrupt function generally functions to modify global variables or directly modify memory values via addresses, and similar to IO ports, the interrupt function may change values while reading memory. For the condition of modifying the memory value through the address, the method is directly realized through an IO port mode; for global variables, the variables are decomposed into basic type sub-expressions according to the variable types, each sub-expression is realized in an IO port mode, and finally combination is carried out to obtain the action of the global variable.
After solving the expression or stub function in a combined manner of interpreted execution and symbolic execution, step 105 is performed.
Step 105: and generating a test case based on the solution result and the value sequence.
After the solution result and the value sequence are obtained, the solution result (i.e., the collected branch constraints) and the obtained value sequence may be converted into a real case, and the real case is saved to obtain a test case corresponding to the function to be tested. Specifically, the following preferred embodiments are described in detail.
In a preferred embodiment of the present invention, the step 104 may include:
sub-step M1: converting the collected branch constraints and the value sequence into a real use case;
sub-step M2: and storing the real case to generate the test case.
In the embodiment of the invention, after the branch constraint after the tested function is solved and the solving results of a plurality of symbols corresponding to the IO port are collected, the collected branch constraint and value sequence can be converted into a real case, and the real case is stored, so that the test case corresponding to the tested function is obtained.
In another preferred embodiment of the present invention, after the step 104, the method may further include:
step A1: searching uncovered branches in the expression or the stub function by utilizing a branch search algorithm according to the collected constraints;
step A2: carrying out constraint solving on the uncovered branch;
step A3: repeatedly executing the steps;
step A4: after the search is finished, converting the result of each constraint solving and the value sequence into a real case of one execution path;
step A5: and storing each real case to generate a test case set.
In the embodiment of the invention, according to the collected constraints, uncovered branches are searched by using a branch search algorithm. When not found (indicating that the branch is completely covered, no solution or timeout for solution), the following steps are executed. And when the uncovered branch is found, carrying out constraint solution on the found branch, and if the uncovered branch has a solution, taking the result as input to carry out next mixed execution. For example, the first execution run adopts a default value, the branch path is T, and the constraint is solved after T is changed into F. If not, overtime, skipping and neglecting, and searching uncovered branch again.
And repeating the step A1 to the step A2 until the search is completed.
It should be understood that the above examples are only examples for better understanding of the technical solutions of the embodiments of the present invention, and are not to be taken as the only limitation of the embodiments of the present invention.
And after the search is finished, converting the result and the value sequence of each solving into a case, and finally obtaining a case set. Solving the result that the memory address and the corresponding value thereof are obtained, obtaining the expression corresponding to the address according to the record during symbolization, and further obtaining the corresponding relation between the expression and the input; for an IO port or an address of interrupt modified data, the absolute address is associated with its input as an IO port input. The mixed execution process also records the result of each interpretation execution, including the return value after each execution and the value of the input expression, and takes the values as the expected values of the corresponding test cases.
And screening the generated cases, eliminating the cases without additional coverage contribution by calculating the coverage rate increment of the test cases to obtain a case set without repetition, and finally saving the case set as a test case file (the test case file comprises the test case set).
In the embodiment of the invention, the symbolic execution technology is further improved, and the generation of unit test cases related to IO ports and interrupts in embedded software is supported.
The method for generating the test case of the embedded software unit provided by the embodiment of the invention generates an input drive file by performing static analysis on a source program file corresponding to the embedded software unit, defines a drive function in the input drive file, the drive function is used for executing an expression or a stub function to be solved, solves the expression or the stub function according to a mode of combining interpretation execution and symbolic execution, specially codes IO ports in the embedded software unit into multiple symbols, solves to obtain a value sequence, and further generates the test case based on the solution result and the value sequence. The embodiment of the invention adopts a mode of inputting the drive file to replace symbol instrumentation. The file can be automatically generated, manual editing and modification are supported, high flexibility is achieved, operation steps are simplified, and performance overhead caused by pile insertion is reduced; in general, the automatically generated input drive file can meet most requirements; interpreted execution is used instead of a compilation run. The method reduces the overhead brought by compiling, more importantly, the whole process is independent of a target platform and a compiler, no matter which embedded platform software can be interpreted and executed (static analysis is compatible with a platform dialect), and the time cost and the labor cost brought by configuring the target environment are greatly reduced.
Example two
Referring to fig. 2, a schematic structural diagram of an embedded software unit test case generation system according to an embodiment of the present invention is shown, where the embedded software unit test case generation system specifically includes:
an input driver file generation module 210, configured to perform static analysis on the source program file corresponding to the embedded software unit, and generate an input driver file; a driver function definition module 220, configured to define a driver function in the input driver file; the driving function is used for appointing and inputting an expression or a pile function to be solved; a mixed-mode solving module 230, configured to solve the expression or the stub function according to a combination of interpretive execution and symbolic execution; the value sequence solving module 240 is used for specially encoding the IO port in the embedded software into multiple symbols and solving to obtain a value sequence; and the test case generating module 250 is configured to generate a test case based on the solution result and the value sequence.
Preferably, the input driver file generating module 210 includes: the static analysis submodule is used for carrying out static analysis on the source program file; and the input drive file generation submodule is used for generating the input drive file according to the function interface information based on the static analysis result.
Preferably, the mixed-mode solving module 230 includes: the symbolization submodule is used for symbolizing the expression or the stub function by using an interpretation execution mode; the constraint solving submodule is used for carrying out constraint solving on the symbolized expression or the symbolic pile function; the branch constraint collection submodule is used for collecting branch constraints in the constraint solving process according to the symbolic execution mode; and the solution result determining submodule is used for determining the collected branch constraints as solution results.
Preferably, the value sequence solving module 240 includes: the encoding submodule is used for encoding the IO port into a new symbol when the symbol executes to access the IO port, so that one IO port corresponds to a plurality of symbols; and the value sequence solving submodule is used for synthesizing solving results of a plurality of symbols corresponding to the IO port into a group of value sequences.
Preferably, the test case generating module 250 includes: the real case conversion submodule is used for converting the collected branch constraints and the value sequence into a real case; and the test case generation submodule is used for storing the real case to generate the test case.
Preferably, the system further comprises: an uncovered branch searching module, configured to search uncovered branches in the expression or the stub function by using a branch search algorithm according to the collected constraints; the branch constraint solving module is used for carrying out constraint solving on the uncovered branches; the repeated execution module is used for repeatedly executing the uncovered branch searching module and the branch constraint solving module; the branch real case conversion module is used for converting the result of each constraint solving and the value sequence into a real case of an execution path after the searching is finished; and the test case set generating module is used for storing each real case to generate a test case set.
The embedded software unit test case generation system provided by the embodiment of the invention generates an input drive file by performing static analysis on a source program file corresponding to an embedded software unit, defines a drive function in the input drive file, the drive function is used for executing an expression or a stub function to be solved, solves the expression or the stub function according to a mode of combining interpretation execution and symbolic execution, specially codes an IO port in embedded software into multiple symbols to obtain a value sequence, and generates a test case based on a solution result and the value sequence. The embodiment of the invention adopts a mode of inputting the drive file to replace symbol instrumentation. The file can be automatically generated, manual editing and modification are supported, high flexibility is achieved, operation steps are simplified, and performance overhead caused by pile insertion is reduced; in general, the automatically generated input drive file can meet most requirements; interpreted execution is used instead of a compilation run. The method reduces the overhead brought by compiling, more importantly, the whole process is independent of a target platform and a compiler, no matter which embedded platform software can be interpreted and executed (static analysis is compatible with a platform dialect), and the time cost and the labor cost brought by configuring the target environment are greatly reduced.
The embodiment of the invention also provides a computer-readable storage medium, wherein a computer program is stored on the computer-readable storage medium, and when being executed by a processor, the computer program realizes each process of the embedded software unit test case generation method embodiment, and can achieve the same technical effect, and in order to avoid repetition, the details are not repeated here. The computer-readable storage medium may be a Read-only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk.
It should be noted that, in this document, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or system that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or system. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a process, method, article, or system that comprises the element.
Through the above description of the embodiments, those skilled in the art will clearly understand that the method of the above embodiments can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware, but in many cases, the former is a better implementation manner. Based on such understanding, the technical solutions of the present invention may be embodied in the form of a software product, which is stored in a storage medium (such as ROM/RAM, magnetic disk, optical disk) and includes instructions for enabling a terminal (such as a mobile phone, a computer, a server, an air conditioner, or a network device) to execute the method according to the embodiments of the present invention.
While the present invention has been described with reference to the embodiments shown in the drawings, the present invention is not limited to the embodiments, which are illustrative and not restrictive, and it will be apparent to those skilled in the art that various changes and modifications can be made therein without departing from the spirit and scope of the invention as defined in the appended claims.

Claims (10)

1. A method for generating a test case of an embedded software unit is characterized by comprising the following steps:
performing static analysis on a source program file corresponding to the embedded software unit to generate an input drive file;
defining a drive function in the input drive file; the driving function is used for appointing and inputting an expression or a pile function to be solved;
solving the expression or the stub function according to a combined mode of interpretation execution and symbolic execution;
the IO port in the embedded software unit is specially coded into multiple symbols, and a value sequence is obtained through solving; the method comprises the following steps: when the symbols access the IO port, the IO port is coded into new symbols, so that one IO port corresponds to a plurality of symbols; synthesizing solving results of a plurality of symbols corresponding to the IO ports into a group of value sequences;
and generating a test case based on the solution result and the value sequence.
2. The method according to claim 1, wherein the step of performing static analysis on the source program file corresponding to the embedded software unit to generate the input driver file comprises:
performing static analysis on the source program file;
and generating the input drive file according to the function interface information based on the static analysis result.
3. The method of claim 1, wherein said step of solving said expression or said stub function in a combined interpreted and symbolic way comprises:
symbolizing the expression or the stub function by using an interpretation execution mode;
carrying out constraint solving on the symbolized expression or the stake function;
collecting branch constraints in the constraint solving process according to the symbolic execution mode;
and determining the collected branch constraints as solution results.
4. The method of claim 3, wherein the step of generating test cases based on the solution results and the sequence of values comprises:
converting the collected branch constraints and the value sequence into a real use case;
and storing the real case to generate the test case.
5. The method of claim 1, further comprising, after the step of generating test cases based on the solution results and the sequence of values:
searching uncovered branches in the expression or the stub function by utilizing a branch search algorithm according to the collected constraints;
carrying out constraint solving on the uncovered branch;
repeatedly executing the steps;
after the search is finished, converting the result of each constraint solving and the value sequence into a real case of one execution path;
and storing each real case to generate a test case set.
6. An embedded software unit test case generation system, comprising:
the input drive file generation module is used for performing static analysis on the source program file corresponding to the embedded software unit to generate an input drive file;
the drive function definition module is used for defining a drive function in the input drive file; the driving function is used for appointing and inputting an expression or a pile function to be solved;
the mixed mode solving module is used for solving the expression or the stub function according to a mode of combining interpretation execution and symbolic execution;
the value sequence solving module is used for specially encoding the IO port in the embedded software unit into multiple symbols and solving to obtain a value sequence; the value sequence solving module comprises:
the encoding submodule is used for encoding the IO port into a new symbol when the symbol executes to access the IO port, so that one IO port corresponds to a plurality of symbols;
the value sequence solving submodule is used for synthesizing solving results of a plurality of symbols corresponding to the IO port into a group of value sequences;
and the test case generation module is used for generating a test case based on the solution result and the value sequence.
7. The system of claim 6, wherein the input driver file generation module comprises:
the static analysis submodule is used for carrying out static analysis on the source program file;
and the input drive file generation submodule is used for generating the input drive file according to the function interface information based on the static analysis result.
8. The system of claim 6, wherein the mixed-mode solution module comprises:
the symbolization submodule is used for symbolizing the expression or the stub function by using an interpretation execution mode;
the constraint solving submodule is used for carrying out constraint solving on the symbolized expression or the symbolic pile function;
the branch constraint collection submodule is used for collecting branch constraints in the constraint solving process according to the symbolic execution mode;
and the solution result determining submodule is used for determining the collected branch constraints as solution results.
9. The system of claim 8, wherein the test case generation module comprises:
the real case conversion submodule is used for converting the collected branch constraints into real cases;
and the test case generation submodule is used for storing the real case to generate the test case.
10. The system of claim 6, further comprising:
an uncovered branch searching module, configured to search uncovered branches in the expression or the stub function by using a branch search algorithm according to the collected constraints;
the branch constraint solving module is used for carrying out constraint solving on the uncovered branches;
the repeated execution module is used for repeatedly executing the uncovered branch searching module and the branch constraint solving module;
the branch real case conversion module is used for converting the result of each constraint solving and the value sequence into a real case of an execution path after the searching is finished;
and the test case set generating module is used for storing each real case to generate a test case set.
CN201811216675.4A 2018-10-18 2018-10-18 Embedded software unit test case generation method and system Active CN109086215B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201811216675.4A CN109086215B (en) 2018-10-18 2018-10-18 Embedded software unit test case generation method and system

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201811216675.4A CN109086215B (en) 2018-10-18 2018-10-18 Embedded software unit test case generation method and system

Publications (2)

Publication Number Publication Date
CN109086215A CN109086215A (en) 2018-12-25
CN109086215B true CN109086215B (en) 2021-11-16

Family

ID=64843750

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201811216675.4A Active CN109086215B (en) 2018-10-18 2018-10-18 Embedded software unit test case generation method and system

Country Status (1)

Country Link
CN (1) CN109086215B (en)

Families Citing this family (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111176994B (en) * 2019-12-24 2023-03-31 北京轩宇信息技术有限公司 Unit test case generation method and device for embedded software IO port
CN112363922B (en) * 2020-11-09 2024-08-06 中国农业银行股份有限公司 Test case generation method and related equipment thereof
CN112506793B (en) * 2020-12-18 2024-05-28 航天信息股份有限公司 Method and system for testing embedded software unit, readable medium and electronic equipment
CN113220307B (en) * 2021-06-08 2022-02-22 中航机载系统共性技术有限公司 Optimization method and device for code coverage analysis and electronic equipment
CN115033472B (en) * 2022-04-18 2024-03-22 大连理工大学 Interrupt driver model detection method based on thread cyclic scheduling serialization
CN114896145B (en) * 2022-04-27 2024-09-20 北京轩宇信息技术有限公司 Lazy symbolization method and system for complex type input variables for symbol execution
CN116578498B (en) * 2023-07-12 2023-09-29 西南交通大学 Automatic generation method and system for unit test cases
CN116594915B (en) * 2023-07-17 2023-09-29 西南交通大学 Automatic generation method, device, equipment and medium for integrated test cases
CN117171053B (en) * 2023-11-01 2024-02-20 睿思芯科(深圳)技术有限公司 Test method, system and related equipment for vectorized programming

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102289362A (en) * 2011-08-26 2011-12-21 北京邮电大学 Segmented symbolic execution device and working method thereof
CN102799529A (en) * 2012-07-13 2012-11-28 北京航空航天大学 Generation method of dynamic binary code test case
CN104063325A (en) * 2014-07-11 2014-09-24 电子科技大学 Automatic generation device and method for test cases of embedded software

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102289362A (en) * 2011-08-26 2011-12-21 北京邮电大学 Segmented symbolic execution device and working method thereof
CN102799529A (en) * 2012-07-13 2012-11-28 北京航空航天大学 Generation method of dynamic binary code test case
CN104063325A (en) * 2014-07-11 2014-09-24 电子科技大学 Automatic generation device and method for test cases of embedded software

Also Published As

Publication number Publication date
CN109086215A (en) 2018-12-25

Similar Documents

Publication Publication Date Title
CN109086215B (en) Embedded software unit test case generation method and system
CN110502227B (en) Code complement method and device, storage medium and electronic equipment
CN110149800B (en) Apparatus for processing abstract syntax tree associated with source code of source program
US11579856B2 (en) Multi-chip compatible compiling method and device
CN111736840B (en) Method for compiling applet application, method for running applet application, storage medium and electronic device
CN108595334B (en) Method and device for calculating dynamic slices of Java program and readable storage medium
CN102696012A (en) Creating inferred symbols from code usage
US20070250827A1 (en) Apparatus for supporting program development, and operation method for the apparatus
US20100199269A1 (en) Program optimization device and program optimization method
JP4638484B2 (en) Data integrity in data processing equipment
CN110727429B (en) Front-end page generation method, device and equipment
CN111143228B (en) Test code generation method and device based on decision table method
CN112379917A (en) Browser compatibility improving method, device, equipment and storage medium
US6519768B1 (en) Instruction translation method
CN110737431B (en) Software development method, development platform, terminal device and storage medium
US10642714B2 (en) Mapping dynamic analysis data to source code
CN118312154A (en) Compiler generating method, compiler, and storage medium
CN114791808A (en) Data flow graph generation method and device
CN108563561B (en) Program implicit constraint extraction method and system
Benzinger Automated complexity analysis of Nuprl extracted programs
CN116595967A (en) Natural language rule writing method based on text and related device
CN114594943B (en) Data modeling method, device, equipment and storage medium
CN111061466A (en) Automatic conversion method, system, terminal and medium of behavior control scripting language
CN113961238A (en) Object conversion method and device, electronic equipment and storage medium
CN107562430B (en) Compiling method for file processing function of mobile pi-calculus language

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant