• No se han encontrado resultados

TABLE 5.2 Predicates and p-use() Set of Edges in Figure 5.4

Edges (i, j) predicate(i, j) p-use(i, j)

(1, 2) True {}

(2, 3) True {}

(3, 4) (ti<AS) && (value[i] != −999) {i, ti, AS, value}

(4, 5) (value[i]<=MIN) && (value[i]>=MAX) {i, MIN, MAX, value}

(4, 6) ∼((value[i]<=MIN) && (value[i]>=MAX)) {i, MIN, MAX, value}

(5, 6) True {}

(6, 3) True {}

(3, 7) ∼((ti<AS) && (value[i] != −999)) {i, ti, AS, value}

(7, 8) ∼(tv>0) {tv}

(7, 9) (tv>0) {tv}

(8, 10) True {}

(9, 10) True {}

Example: Paths2-3-4-5and3-4-6-3are simple paths (Figure 5.4).

Loop-Free Path: A loop-free path is a path in whichall nodes are distinct.

Complete Path: A complete path is a path from the entry node to the exit node.

Du-path: A path (n1−n2− · · · −njnk) is a definition-use path (du-path) with respect to (w.r.t) variable x if node n1 has a global definition of x andeither

• node nk has a global c-use of x and (n1−n2− · · · −njnk) is a def-clear simple path w.r.t.x or

• edge (nj,nk) has a p-use of x and (n1−n2− · · · −nj) is a def-clear, loop-free path w.r.t.x.

Example: Considering the global definition and global c-use of variable tv in nodes2 and5, respectively,2-3-4-5is a du-path.

Example: Considering the global definition and p-use of variable tv in nodes2

and on edge(7, 9), respectively,2-3-7-9is a du-path.

5.6 DATA FLOW TESTING CRITERIA

In this section, we explain seven types of data flow testing criteria. These criteria are based on two fundamental concepts, namely, definitions and uses —both c-uses and p-uses —of variables.

All-defs: For each variable x and for each node i such that x has a global definition in nodei, select a complete path which includes a def-clear path from nodei to

• nodej having a global c-use ofx or • edge (j,k) having a p-use ofx.

Example: Consider the variable tv, which has global definitions in nodes2 and

5 (Figure 5.4 and Tables 5.1 and 5.2). First, we consider its global definition in node2. We find a global c-use of tv in node5, and there exists a def-clear path

2-3-4-5from node 2 to node5. We choose a complete path1-2-3-4-5-6-3-7-9-10

that includes the def-clear path 2-3-4-5 to satisfy the all-defs criterion. We also find p-uses of variable tv on edge(7, 8), and there exists a def-clear path2-3-7-8

from node2to edge(7, 8). We choose a complete path1-2-3-7-8-10that includes the def-clear path 2-3-7-8 to satisfy the all-defs criterion. Now we consider the definition of tv in node 5. In node 9 there is a global c-use of tv, and in edges

(7, 8) and(7, 9) there are p-uses of tv. There is a def-clear path 5-6-3-7-9 from node 5 to node 9. Thus, we choose a complete path 1-2-3-4-5-6-3-7-9-10 that includes the def-clear path 5-6-3-7-9 to satisfy the all-defs criterion. The reader may note that the complete path1-2-3-4-5-6-3-7-9-10covers the all-defs criterion for variable tv defined in nodes 2 and5. To satisfy the all-defs criterion, similar paths must be obtained for variablesi, ti, and sum.

All-c-uses: For each variablexand for each nodei, such thatx has a global definition in node i, select complete paths which include def-clear paths from nodei toall nodesj such that there is a global c-use ofx inj.

Example: Let us obtain paths to satisfy the all-c-uses criterion with respect to variable ti. We find two global definitions of ti in nodes 2 and4. Corresponding to the global definition in node2, there is a global c-use of ti in node4. However, corresponding to the global definition in node4, there is no global c-use of ti. From the global definition in node2, there is a def-clear path to the global c-use in node

4in the form of2-3-4. The reader may note that there arefourcomplete paths that include the def-clear path2-3-4as follows:

1-2-3-4-5-6-3-7-8-10,

1-2-3-4-5-6-3-7-9-10,

1-2-3-4-6-3-7-8-10, and

1-2-3-4-6-3-7-9-10.

One may choose one or more paths from among the four paths above to satisfy the all-c-uses criterion with respect to variable ti.

All-p-uses: For each variablex and for each nodei such thatx has a global definition in node i, select complete paths which include def-clear paths from nodei toall edges (j,k) such that there is a p-use ofx on edge (j,k).

Example: Let us obtain paths to satisfy the all-p-uses criterion with respect to variable tv. We find two global definitions of tv in nodes2 and5. Corresponding to the global definition in node2, there is a p-use of tv on edges(7, 8)and(7, 9). There are def-clear paths from node2 to edges (7, 8)and(7, 9), namely 2-3-7-8

5.6 DATA FLOW TESTING CRITERIA 123 (7, 8)and(7, 9), namely,5-6-3-7-8 and5-6-3-7-9, respectively. In the following, we identifyfour complete paths that include the above four def-clear paths:

1-2-3-7-8-10,

1-2-3-7-9-10,

1-2-3-4-5-6-3-7-8-10, and

1-2-3-4-5-6-3-7-9-10.

All-p-uses/Some-c-uses: This criterion is identical to the all-p-uses criterion except when a variablexhas no p-use. Ifxhas no p-use, then this criterion reduces to the some-c-uses criterion explained below.

Some-c-uses: For each variablex and for each nodei such thatx has a global definition in node i, select complete paths which include def-clear paths from node i to some nodes j such that there is a global c-use ofx in nodej.

Example: Let us obtain paths to satisfy the all-p-uses/some-c-uses criterion with respect to variablei. We find two global definitions ofiin nodes2and6. There is no p-use ofiin Figure 5.4. Thus, we consider some c-uses of variablei. Corresponding to the global definition of variablei in node2, there is a global c-use ofi in node

6, and there is a def-clear path from node2 to node 6 in the form of2-3-4-5-6. Therefore, to satisfy the all-p-uses/some-c-uses criterion with respect to variablei, we select the complete path 1-2-3-4-5-6-3-7-9-10 that includes the def-clear path

2-3-4-5-6.

All-c-uses/Some-p-uses: This criterion is identical to the all-c-uses criterion except when a variable x has no global c-use. If x has no global c-use, then this criterion reduces to the some-p-uses criterion explained below.

Some-p-uses: For each variablex and for each nodei such thatx has a global definition in node i, select complete paths which include def-clear paths from nodei tosomeedges (j,k) such that there is a p-use ofx on edge (j,k).

Example: Let us obtain paths to satisfy the all-c-uses/some-p-uses criterion with respect to variable AS. We find just one global definition of AS in node1. There is no global c-use of AS in Figure 5.4. Thus, we consider some p-uses of AS. Corresponding to the global definition of AS in node 1, there are p-uses of AS on edges (3, 7) and (3, 4), and there are def-clear paths from node 1 to those two edges, namely, 1-2-3-7 and 1-2-3-4, respectively. There are many complete paths that include those two def-clear paths. One such example path is given as

1-2-3-4-5-6-3-7-9-10.

All-uses: This criterion is the conjunction of the all-p-uses criterion and the all-c-uses criterion discussed above.

All-du-paths: For each variablexand for each nodeisuch thatxhas a global definition in nodei, select complete paths which includealldu-paths from nodei

• toall nodesj such that there is a global c-use ofx inj and • toall edges (j,k) such that there is a p-use ofx on (j,k).

In Chapter 4, we explained a procedure to generate a test input from an entry–exit program path. There is much similarity between the control flow–based testing and the data flow–based testing. Their difference lies in the ways the two techniques select program paths.

5.7 COMPARISON OF DATA FLOW TEST SELECTION