Você está na página 1de 16

Path Testing/Chandra Kumar R

Dated: 07 Jan 2005

Path Testing
Path Testing/Chandra Kumar R
Dated: 07 Jan 2005

CONTENTS

1 Introduction.................................................................................................1
2 Sample Function.........................................................................................1
3 Path Testing................................................................................................3
3.1 Identification of Process Block............................................................3
3.2 Identification of Decision statements..................................................5
3.3 Identification of Junctions and exit statements...................................7
3.4 Control Flow graph..............................................................................9
3.5 List of Decision nodes.......................................................................10
3.6 List of variables that affect the decision............................................10
3.7 Identification of Predicates................................................................10
3.8 Predicate names for truth and false..................................................10
3.9 Control flow graph with named predicates........................................11
3.10 Predicate Descriptions......................................................................12
3.10.1 Predicate: A................................................................................12
3.10.2 Predicate: B................................................................................12
3.10.3 Predicate: C...............................................................................12
3.11 Predicate Interpretation:....................................................................12
3.11.1 Predicate: A................................................................................12
3.11.2 Predicate: B................................................................................12
3.11.3 Predicate: C...............................................................................12
4 Cyclomatic Complexity.............................................................................13
4.1 Independent path list.........................................................................13
5 Proof for Coverage...................................................................................14

i
Path Testing/Chandra Kumar R
Dated: 07 Jan 2005

1 Introduction

This document describes the steps in path testing a function.

2 Sample Function

We are to apply path testing in the following sample function:

void UpdateSegmentInformationForFunctionsInsymbolTable
(
struct symbol_information *psSymbolpointer
)
{

int siNonZeroWhenFunctionIsAnInterruptFunction;

sSegmentInformation * psSegmentInformation;

Assert(psSymbolpointer != NULL);

Assert(!is_in_pragma (psSymbolpointer, INLINE_INDEX));

if (is_symbol_a_function (psSymbolpointer))
{

siNonZeroWhenFunctionIsAnInterruptFunction =
is_in_pragma ( psSymbolpointer, INTERRUPT_INDEX );

if (siNonZeroWhenFunctionIsAnInterruptFunction == 0)
{
siNonZeroWhenFunctionIsAnInterruptFunction =
is_in_pragma ( psSymbolpointer, SWI_INDEX );
};

else
{

if ( siNonZeroWhenFunctionIsAnInterruptFunction )

psSegmentInformation = ( sSegmentInformation *)

1
Path Testing/Chandra Kumar R
Dated: 07 Jan 2005

psGetActiveSegmentInformation
(
ACTIVE_SEG_INDEX_INTERRUPT_FUNCTION
);

psSymbolpointer->spSegmentInformation =
( sSegmentInformation *)psSegmentInformation;
}

else
{

psSegmentInformation = ( sSegmentInformation *)
psGetActiveSegmentInformation
(
ACTIVE_SEG_INDEX_NORMAL_FUNCTION
);

psSymbolpointer->spSegmentInformation =
( sSegmentInformation *) psSegmentInformation;

else
{

3 Path Testing

2
Path Testing/Chandra Kumar R
Dated: 07 Jan 2005

3.1 Identification of Process Block

The process blocks are highlighted and a unique name is assigned to each
process block.

void UpdateSegmentInformationForFunctionsInsymbolTable
(
struct symbol_information *psSymbolpointer
)
{
int siNonZeroWhenFunctionIsAnInterruptFunction;

sSegmentInformation * psSegmentInformation;
P1
Assert(psSymbolpointer != NULL);

Assert( !is_in_pragma (psSymbolpointer, INLINE_INDEX));

if (is_symbol_a_function (psSymbolpointer))
{
siNonZeroWhenFunctionIsAnInterruptFuncion =
is_in_pragma ( psSymbolpointer, INTERRUPT_INDEX ); P2

if( siNonZeroWhenFunctionIsAnInterruptFunction == 0)
{
siNonZeroWhenFunctionIsAnInterruptFunction =
is_in_pragma ( psSymbolpointer, SWI_INDEX ); P3

};

else
{

if( siNonZeroWhenFunctionIsAnInterruptFunction )

psSegmentInformation = ( sSegmentInformation *)
psGetActiveSegmentInformation
(
ACTIVE_SEG_INDEX_INTERRUPT_FUNCTION
} ); P4

psSymbolpointer->spSegmentInformation =
else
( sSegmentInformation *)psSegmentInformation;
3
Path Testing/Chandra Kumar R
Dated: 07 Jan 2005

psSegmentInformation = ( sSegmentInformation *)
psGetActiveSegmentInformation
(
ACTIVE_SEG_INDEX_NORMAL_FUNCTION
); P5

psSymbolpointer->spSegmentInformation =
( sSegmentInformation *) psSegmentInformation;

else
{

3.2 Identification of Decision statements

The decisions of the function are highlighted and a unique name is assigned
to each decision.

4
Path Testing/Chandra Kumar R
Dated: 07 Jan 2005

void UpdateSegmentInformationForFunctionsInsymbolTable
(
struct symbol_information *psSymbolpointer
)
{

int siNonZeroWhenFunctionIsAnInterruptFunction;

sSegmentInformation * psSegmentInformation;

Assert(psSymbolpointer != NULL);

Assert( !is_in_pragma (psSymbolpointer, INLINE_INDEX));


if (is_symbol_a_function (psSymbolpointer)) D1
{

siNonZeroWhenFunctionIsAnInterruptFunction =
is_in_pragma ( psSymbolpointer, INTERRUPT_INDEX );
if( siNonZeroWhenFunctionIsAnInterruptFunction == 0) D2
{
siNonZeroWhenFunctionIsAnInterruptFunction =
is_in_pragma ( psSymbolpointer, SWI_INDEX );
};

else
{

if( siNonZeroWhenFunctionIsAnInterruptFunction ) D3

psSegmentInformation = ( sSegmentInformation *)
psGetActiveSegmentInformation
(
ACTIVE_SEG_INDEX_INTERRUPT_FUNCTION
);

psSymbolpointer->spSegmentInformation =
( sSegmentInformation *)psSegmentInformation;
}

else
{

5
Path Testing/Chandra Kumar R
Dated: 07 Jan 2005

psSegmentInformation = ( sSegmentInformation *)
psGetActiveSegmentInformation
(
ACTIVE_SEG_INDEX_NORMAL_FUNCTION
);

psSymbolpointer->spSegmentInformation =
( sSegmentInformation *) psSegmentInformation;

else
{

3.3 Identification of Junctions and exit statements

The junctions and the exit of the function are highlighted. A unique name is
assigned to each junction.

6
Path Testing/Chandra Kumar R
Dated: 07 Jan 2005

void UpdateSegmentInformationForFunctionsInsymbolTable
(
struct symbol_information *psSymbolpointer
)
{

int siNonZeroWhenFunctionIsAnInterruptFunction;

sSegmentInformation * psSegmentInformation;

Assert(psSymbolpointer != NULL);

Assert( !is_in_pragma (psSymbolpointer, INLINE_INDEX));

if (is_symbol_a_function (psSymbolpointer))
{

siNonZeroWhenFunctionIsAnInterruptFunction =
is_in_pragma ( psSymbolpointer, INTERRUPT_INDEX );

if( siNonZeroWhenFunctionIsAnInterruptFunction == 0)
{
siNonZeroWhenFunctionIsAnInterruptFunction =
is_in_pragma ( psSymbolpointer, SWI_INDEX );
};

else
{

}
J1
if( siNonZeroWhenFunctionIsAnInterruptFunction )

psSegmentInformation = ( sSegmentInformation *)
psGetActiveSegmentInformation
(
ACTIVE_SEG_INDEX_INTERRUPT_FUNCTION
);

psSymbolpointer->spSegmentInformation =
( sSegmentInformation *)psSegmentInformation;
}

else
{

7
Path Testing/Chandra Kumar R
Dated: 07 Jan 2005

psSegmentInformation = ( sSegmentInformation *)
psGetActiveSegmentInformation
(
ACTIVE_SEG_INDEX_NORMAL_FUNCTION
);

psSymbolpointer->spSegmentInformation =
( sSegmentInformation *) psSegmentInformation;

}
Enter
J2
} a

else P1
{
b
}
c
J3F D1
T

}
P2
Exit of the function
d

F T
D2
e
g
P3

f
J1
n JJ1

F T
D2
k i

P5 P4

l j
3.4 Control Flow graph
J2
J2

m
J3
8

Exit
Path Testing/Chandra Kumar R
Dated: 07 Jan 2005

3.5 List of Decision nodes

9
Path Testing/Chandra Kumar R
Dated: 07 Jan 2005

Decision Name Code


DI if (is_symbol_a_function (psSymbolpointer))
D2 if( siNonZeroWhenFunctionIsAnInterruptFuncti
on == 0)
D3 if( siNonZeroWhenFunctionIsAnInterruptFuncti
on )

3.6 List of variables that affect the decision

Decision Name Enter Code


DI psSymbolpointer
D2 siNonZeroWhenFunctionIsAnInterruptFunction
a
D3 siNonZeroWhenFunctionIsAnInterruptFunction
P1

3.7 Identification of Predicates


A’ c A
F T
Decision name D1 Predicate Predicate name
D1 if (is_symbol_a_function P2 A
(psSymbolpointer))
D2 if( siNonZeroWhenFunctionIsAnInterru B
d
ptFunction == 0)
D3 if( siNonZeroWhenFunctionIsAnInterru C
ptFunction F) B’ B T
D2
e
g
P3
3.8 Predicate names for truth and false
f
Predicate name Truth symbol J1 False symbol
n JJ1
A A A’
B B B’ h
C C C’

F C’ C T
3.9 Control flow graph with named predicates D2
k i

P5 P4

l j
J2
J2
10
m
J3

Exit
o
Path Testing/Chandra Kumar R
Dated: 07 Jan 2005

3.10 Predicate Descriptions

3.10.1 Predicate: A
This predicate checks whether the symbol present in the variable
"psSymbolpointer" is a symbol for a function or not. The variable is passed as
an argument to the function "is_symbol_a_function ". The function returns the

11
Path Testing/Chandra Kumar R
Dated: 07 Jan 2005

value 0 if the symbol is not for a function and a non-zero value if the symbol is
for a function.

3.10.2 Predicate: B
This predicate checks whether the variable "siNonZeroWhenFunctionIsAnInte
rruptFunction" is equal to zero or not. This variable will be set only when the
function which symbol pointer is to be updated is a normal interrupt function.
Here it is checked whether the variable is set by the function "is_in_pragma
(psSymbolpointer, INTERRUPT_INDEX)” The function will set the variable
only if the function is a normal interrupt function else resets.

3.10.3 Predicate: C
This predicate checks whether the variable "siNonZeroWhenFunctionIsAnInte
rruptFunction" is set or not. This variable will be set only when the function for
which symbol pointer is to be updated is a normal interrupt function or a SWI
interrupt function. Here it is checked whether the variable is set by the
functions "is_in_pragma (psSymbolpointer, INTERRUPT_INDEX)" or
is_in_pragma (psSymbolpointer, SWI_INDEX)". These functions will set the
variable only if the function is a normal interrupt function or a SWI interrupt
function.

3.11 Predicate Interpretation:

3.11.1 Predicate: A
The predicate A will be true when the symbol passed as argument to the
function is a function symbol. If the symbol is not for a function then the
predicate A will fail.

3.11.2 Predicate: B
The predicate B will be true when the function-symbol passed as argument for
this function is for a normal interrupt function. Else it will be false.

3.11.3 Predicate: C
The predicate C will be true when the function-symbol passed as argument for
this function is for a normal interrupt function or for a SWI interrupt function.
Else it will be false.

4 Cyclomatic Complexity

Now we have to find the number of independent paths (i.e. basis set) to cover
all the control statements.

This can be achieved through Cyclomatic complexity. It gives us the measure


through the following formula,

12
Path Testing/Chandra Kumar R
Dated: 07 Jan 2005

Cyclomatic Complexity = Number of Edges - Number of nodes + 2

Applying the above formula in the control flow graph of our function, we shall
get the Cyclomatic complexity of the function.

Number of Edges = 15
Number of Nodes = 13

Cyclomatic Complexity = Number of Edges - Number of nodes + 2

= 15 - 13 + 2

= 4

Hence the number of independent paths needed to cover all the control
statements is 4.

4.1 Independent path list

Path Predicates
a-b-n-o A’

a-b-c-d-e-f-h-i-j-m-o ABC

a-b-c-d-e-f-h-k-l-m-o ABC’

a-b-c-d-g-h-i-j-m-o AB’C

5 Proof for Coverage

The above path list shows the possible number of independent paths in the
control flow graph. From the following decision table we can assure that
whether we have achieved the complete path coverage or not.

13
Path Testing/Chandra Kumar R
Dated: 07 Jan 2005

DECISIONS PROCESS-LINK
PATHS D1 D2 D3 a b c d e f g h i j k l m n o
a-b-n-o n y y y y

a-b-c-d-e-f-h-i-j-m-o y y y y y y y y y y y y y y

a-b-c-d-e-f-h-k-l-m-o y y n y y y y y y y y y y y

a-b-c-d-g-h-i-j-m-o y n y y y y y y y y y y y

COVERAGE y y y y y y y y y y y y y y y y y y

In the above decision table the following are checked,


1. Check whether every decision has a Yes and No in its column.
2. Check whether every link covered at least once.

As per the decision table every decisions has ‘Yes’ and ‘No’ in its column and
every process-links are covered at least once.

14

Você também pode gostar