0% found this document useful (0 votes)
16 views21 pages

3cs510ic24 - Stqa Minor Lect-7

Uploaded by

aafadf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views21 pages

3cs510ic24 - Stqa Minor Lect-7

Uploaded by

aafadf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

3CS510IC24- Software Testing & Quality

Assurance
Lecture-7 Odd Sem 24-25
5th Semester – Minor Course
Prof. Daiwat Vyas
Data Flow Testing
• Data Flow Testing focuses on tracking the flow of data through
the control paths of the program, specifically focusing on
definition-use pairs.
• It emphasizes the points where variables are defined and later
used.
Data Flow Testing
• Key terminologies in Data Flow Testing:

• Definition (def): When a variable is assigned a value.


• Usage (use): When a variable's value is utilized, which can be of
two types:
• Computation-use (c-use): Variable used in computations or
operations.
• Predicate-use (p-use): Variable used in decision-making or
branching conditions.
Data Flow Testing
• Data Flow Testing focuses on the points at which variables receive values
(definitions) and the points at which these values are used (uses).

• Key Concepts:
• 1. Definition-Use Chain: Tracks where variables are defined and used.
• 2. Coverage Criteria: Ensures that all variable definitions are tested along
with their corresponding uses.
• 3. Goals: Detect anomalies such as uninitialized variables, unused
variables, and incorrect variable updates.
Data Flow Testing
• Example of Data Flow Testing: Let's consider a simple C program
that calculates the area of a rectangle:
#include <stdio.h> int main()
int calculateArea(int length, int width) {
{
int length = 5; // (5) Definition of 'length'
int area; // (1) Definition of 'area’
area = length * width; // (2) Definition of 'area’ int width = 10; // (6) Definition of 'width'
if (length <= 0 || width <= 0)
{ int result = calculateArea(length, width);
// (3) Usage of 'length', 'width' (p-use) // (7) Usage of 'length' and 'width' (p-use)
printf("Invalid dimensions\n");
printf("The area is: %d\n", result);
return 0;
}
return area; // (4) Usage of 'area' (c-use) return 0;
} }
Data Flow Testing
• Data Flow Test Coverage

• To perform data flow testing, we need to track each variable's definition and its corresponding use.
We'll analyze each variable (length, width, area) based on their definition and usage points.
• Definitions and Uses:

• length:
• Defined at (5)
• Used at (3) and (7) (p-use in decision)
• width:
• Defined at (6)
• Used at (3) and (7) (p-use in decision)
• area:
• Defined at (1) and (2)
• Used at (4) (c-use in return statement)
Data Flow Testing
• Data Flow Test Coverage

• Def-Use Pairs:

• length: (5 → 3), (5 → 7)
• width: (6 → 3), (6 → 7)
• area: (1 → 2), (2 → 4)
Data Flow Testing
• est Paths for Data Flow Testing

• Test Path 1: Valid Dimensions


• Input: length = 5, width = 10
• Execution path:
• Definitions: length at (5), width at (6), area at (2)
• Usages: length at (3), width at (3), area at (4)
• Expected Output: Area = 50
Data Flow Testing
• Test Paths for Data Flow Testing

• Test Path 2: Invalid Dimensions (negative value)

• Input: length = -5, width = 10


• Execution path:
• Definitions: length at (5), width at (6), area at (1)
• Usages: length at (3), width at (3)
• Expected Output: "Invalid dimensions", Area = 0
Data Flow Testing
• Test Paths for Data Flow Testing

• Test Path 3: Invalid Dimensions (zero)

• Input: length = 0, width = 10


• Execution path:
• Definitions: length at (5), width at (6), area at (1)
• Usages: length at (3), width at (3)
• Expected Output: "Invalid dimensions", Area = 0
Data Flow Testing
• Data flow testing ensures that all the variable definitions in the
program have proper uses in computational (c-use) or predicate
(p-use) contexts.

• In the example discussed, we tested three different paths to check


both valid and invalid cases using the definitions and usages of
variables length, width, and area.
Data Flow Anomaly
• In data flow testing, a data flow anomaly occurs when the
sequence of actions on a variable does not follow a correct
pattern, potentially leading to unexpected behavior.
• It highlights errors in the flow of data, such as:

• Variable is used without being defined (Undef).


• Variable is defined but never used (Unused).
• Variable is redefined without being used (Redef).
Data Flow Anomaly
• The common sequence patterns are:

• d (define): A variable is assigned a value.


• u (use): A variable's value is used.
• k (kill): A variable's value is destroyed or becomes unreachable.
Data Flow Anomaly
• Common Anomalous Patterns

• d-d: Redefinition without use (redefinition anomaly).


• d-k: Definition followed by a kill without usage (definition
anomaly).
• u-u: Usage without definition (use anomaly).
Data Flow Anomaly
• Example of Data Flow Anomalies- Consider the following C program
for calculating the sum of two numbers:
Data Flow Anomaly
• Example of Data Flow Anomalies- Consider the following C program
for calculating the sum of two numbers:
Data Flow Anomaly
• Analysis of Anomalies in the Code

• Anomaly 1: Redefinition without Use


• At line (2), result is redefined without being used after its initial
definition at line (1). This results in a potential d-d anomaly since the
first definition is essentially wasted.

• Anomaly 2: Redefinition without Use


• At line (3), result is again redefined without any usage after the
previous redefinition at line (2), causing another d-d anomaly.
Data Flow Anomaly
• Analysis of Anomalies in the Code

• Anomaly 3: Incorrect Use of result

• At line (4), the result is used, but the program prints 0, which isn't
what the programmer likely intended. This is a definition anomaly
(d-u), where the variable was not used correctly between the
redefinition and usage.
Data Flow Anomaly
• Corrected Code Without Data Flow Anomalies
Data Flow Anomaly
• In the corrected version, each variable is properly defined, used, and
no redundant redefinitions occur. This ensures the program behaves
as expected, without data flow anomalies.
Data Flow Graph (already discussed)
• A Data Flow Graph represents the flow of data through a program, focusing
on the definition, usage, and movement of variables.

• Components:
• 1. **Nodes:** Represent statements in the program where variables are
defined or used.
• 2. **Edges:** Represent the flow of data between these statements.

• Example: In a banking system, tracking the flow of 'balance' from deposit


to withdrawal operations.

You might also like