3cs510ic24 - Stqa Minor Lect-7
3cs510ic24 - Stqa Minor Lect-7
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:
• 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
• 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.