Software Testing - White Box Testing: Program Structure Analysis

Program structure analysis

References:
Software Testing Chapter 4 White Box Testing 1

  • Control flow analysis:
    Control flow graph: composed of nodes and lines
    Control flow graph and matrix:
    control flow graph
    control flow graph matrix
    It should be noted that: in the control flow graph, nodes include the confluence point where multiple streamlines intersect at the outlet represented by a diamond.
    The basic requirements of the program structure:
    a. Go to labels that do not exist;
    b. Statement labels that are useless;
    c. Statements that cannot be reached after entering from the program entry;
    d. Statements that cannot reach the stop statement.
    Check for reachability:
    check accessibility
  • Data flow analysis
    If a statement in a program can change the value of a program variable V when it is executed, then V is said to be defined by the statement. A statement is said to refer to a variable V if its execution refers to the value of a variable V in memory.
    Accessibility definition:
    a. The definition of variable V by statement i, expressed as V i V_iVi
    b. If a path in the control flow graph does not define a variable V, then the path is a clear definition of the variable V c.
    If the variable V has a well-defined path from node i to the entry (or exit) of node j, define V i V_iViIt is said that the entry (or exit) of node j has been reached.
    Related definitions:
    si s_isi: Indicates the set of variable definitions reaching the entry of i. (The set of definitions that reach its predecessor exit, that is, the union of the exits of the predecessor node)
    ti t_iti: Indicates the set of variable definitions that reach the exit of i. (remove undefined, add new definition)
    pi p_ipi: is the set ci c_i of all definitions saved by node i
    ci: is the defined set
    ti = ( si ∩ pi ) ∪ ci t_i=(s_i∩p_i)∪c_i generated in node iti=(sipi)ci
    s i = ⋃ j ∈ x i t j s_i=\bigcup\limits_{j∈x_i}t_j si=jxitj
    s i = ⋃ j ∈ x i ( s j ∩ p j ) ∪ d i s_i=\bigcup\limits_{j∈x_i}(s_j∩p_j)∪d_i si=jxi(sjpj)di
    d i = ⋃ j ∈ x i c j d_i=\bigcup\limits_{j∈x_i}c_j di=jxicj
    check accessibility
    References to undefined variables: For each node i, we consider each variable referenced by statement i in turn, and if for any such variable V there is no definition of V up to i, then the program contains an error.
    Unused definition: For each variable define V i V_iVi, we in turn consider V i V_iViFor each program node j reached, if there is no corresponding statement referencing the variable V, the program contains an exception.
  • Information flow analysis
    Find the quotient of M and N, Q is the quotient, and R is the remainder
    Information flow analysis
    Information flow analysis
    Figure a shows the variables used in the input value of each statement when it is executed. Among them, why M and N are used in the execution of statement 4, my idea is that M and N are used in the judgment statement (3) of the loop.
    Figure b shows some statements whose execution may directly or indirectly affect the final value of the output variable. Among them, because the definition of Q does not affect the change of R, so R is not affected by statements 1 and 2, but the value of Q is affected by the value of R.
    Figure c shows which input values ​​may directly or indirectly affect the output variable. (It counts if there is an assignment statement)

Guess you like

Origin blog.csdn.net/Bat_Reality/article/details/123941226