Sunteți pe pagina 1din 11

Automatic Test Case Generation Of ‘C’ Programs Using CFG

Automatic Test Case Generation of C Program Using


CFG

Sangeeta And Dr. Dharmender Kumar


Guru Jambheshwar University Of Science & Technology, Hisar

and the human involvement in this


Abstract process leads to the involvement of
human biases. Ultimately, the result is
In this modern era, software has become
the generation of ineffective and
an important part of human life. Many
inadequate test cases. Finally, the quality
of the daily activities of human are
of the software is affected.
dependent on the software. Day by day,
There is an urgent need to automate this
human is getting more dependent on
test case generation task. This will
machines or systems. As software is
partially automate the testing activity.
getting more and more complex,
The automatic test case generation will
software quality and reliability have
involve no human biases. As a result of
become an important concern for the
automation, many resources like time,
software industry.
cost, and manpower would be saved.
Software quality and assurance team in
Automatic Test Case Generation Tool
a software company is responsible to
is the answer to all the issues discussed
ensure the quality and reliability in the
earlier. This test case generation tool
software product. An effective testing of
develops test cases for a ‘C’ language
the software is the only way to gain the
program. It automates the unit testing of
customer confidence by removing all
the software by generating test cases for
possible errors. It can be done by
a program / unit. This automatic test case
automatic test case generation.
generation tool use the structural testing
and symbolic testing to generate the test
1. Introduction
cases. The random testing is also be used
in this tool to randomly generate values
In the industry, test cases are generated
manually. This is a very slow process

-1-
Automatic Test Case Generation Of ‘C’ Programs Using CFG

that would be used for identifying the case generation system that
test cases. allows the tester/user to input a
‘C’ program. It will parse
Various problems addressed by this through the program. Based on
automatic test case generation tool are the internal structure of the
as follows: program, CFG (Control Flow
Graph) for the input program is
• Manual generation of test cases generated. This will provide a
leads to the wastage of resources graphical view of the logic of the
like time, money and manpower. program.
• Human biases are involved • The automatic test case
during the manual generation of generation tool will use this CFG
test cases. generated to generate the CFG
• The unavailability of a reliable matrix. Using this CFG matrix,
testing approach leads to the various possible paths through
production of an unreliable the program will be identified.
software product. • First, the automatic test case
• Software providers are losing generation tool will be
their confidence in users. implemented using random

• The overall production cost of testing based technique, then it

software is increased. will allow up to some extent to

• Resources allocated to the get the information about the

software testing process are not feasibility or infeasibility of a

utilized optimally. path / difficulty in solving the

• The ineffective unit testing path.

affects the further level of testing • Finally, this tool will generate the

in the complete software testing test cases for input program.

process • The automatic test case

2. System Process generation tool will develop test

• Automatic test case generation cases based on best available

tool would be an automated test testing criteria that will provide

-2-
Automatic Test Case Generation Of ‘C’ Programs Using CFG

the assurance of complete if(abc<0)


possible testing and also provide {
the information about the In this part, there is no definition of any
termination of the testing variable.
process. }
Unit testing is used for this And the else part does not exist.
research by analysis of all testing From the above discussion, it is analysed
strategies. to use path testing for the test case
generation.
Next issue is left about the most
important that is testing criteria.
A suitable test criteria can be the way to
divide the program input domain into a
path.
(Beizer, 2008, pp 74) Path testing (P∞)
requires that each path through the
By seeing the importance of unit testing
program must be executed by at least
in the software testing activity, the it is
one of the test cases, which is
decided to research for this level of
impractical as infeasible paths are not
testing.
executed by any of the data. This is also
3. Path Testing
called as 100% path coverage. This is
Path Testing is a testing technique in
the strongest criteria in the path testing
which a set of paths are selected from
family.
the domain of all possible paths through
4. Automatic Test Case
the program. The selection of the paths
Generation Tool
is done on the basis of certain criteria.
The test cases for a program of any
Then, these selected paths are executed
programming language can be generated
statically to generate test cases. This
automatically. As far as structured
technique is most applicable for
languages are concerned, they have the
designing the test cases for unit testing
simplest programming structures. So, the
of new software (Beizer, 2008, pp 59).
developer has decided to generate
Consider one example:

-3-
Automatic Test Case Generation Of ‘C’ Programs Using CFG

automatic test cases for the structured Symbolic Execution is performed using
programming language. Finally, the Random Testing Based Automatic Test
developer has selected ‘C’ Language as Data Generation technique, for this
the targeted structured language. Automatic Test Case Generation Tool.
Therefore, this Automatic Test Case 4.1 Working Of Automatic Test Case
Generation Tool will generate test cases Generation Tool based on Random
for a ‘C’ Language program and will use Testing:
the all testing strategies and techniques Step 1: The Automatic Test Case
that are already being decided by the Generation Tool will allow the user to
developer to use after a lot of research parse a ‘C’ Language program.
work done earlier (Refer Fig. 3.3). Step 2: The tool will convert the input
program source code into the
instrumented source code.
Step 3: The tool will generate the CFG
for the instrumented program.
Step 4: From the CFG of the program,
CFG matrix generated.
Step 5: Using the CFG matrix, all
possible paths will be identified as the
testing criteria used in the system is path
testing (all path testing).
Step 6: The tool will statically execute
feasible paths using Symbolic
Execution.
Step 7: Finally, the tool will generate
test cases for the symbolically executed
paths using Random Testing technique.
It is analysed for automatic test case
generation to go for the Computer Based 5. CFG
Testing technique - Symbolic Execution. CFG stands for Control Flow Graph. It
describes the logical structure of the

-4-
Automatic Test Case Generation Of ‘C’ Programs Using CFG

program. It consists of nodes and edges. 19---if((a!=b) && (a!=c) && (b!=c))
Actually it is a directed graph which 20---printf(“scalene”);
shows the all possible ways for the flow 21---else
of control through the program 22---printf(“isosceles”);
beginning from the start node of the 23---}
program to the exit node of the program. 24---else
These various possible flows of control 25--- printf(“not a triangle”);
through the program are the various 26--- printf(“end of program”);
possible paths through the program.
Refer Fig. 3.5 for the CFG of program
Consider one simple example to better
mentioned above.
understand the concept of CFG.

In Fig. 3.5, Node with label 5-9


1---- #include<stdio.h>
represents the accumulation of
2---- void main()
statements no 5, 6, 7, 8, 9 at a single
3---- {
node as they all are sequential. The non-
4---- int a,b,c,flag;
executable statements like variables and
5---- printf("enter three sides of a
type declarations are not considered in
triangle");
CFG.All the decision making statements
6---- scanf("%d%d%d",&a,&b,&c);
and looping statements are shown by
7---- printf(“Side A is : %d”, a);
separate nodes.
8---- printf(“Side B is : %d”, b);
As shown in the figure, labels T & F at
9---- printf(“Side C is : %d”, c);
the decision making nodes outgoing
10---if((a<b+c) && (b<a+c) &&
edges represents the flow control from
(c<a+b))
one node to the other node in the graph
11--- flag=1;
based on the fact whether the condition
12--- else
on decision making node is true or false.
13--- flag=0;
14---if(flag)
5.1 CFG Matrix
15---{
CFG Matrix is the adjacency matrix of
16---if((a==b) && (b==c))
the Control Flow Graph (directed graph).
17---printf(“equilateral triangle”);
What are feasible paths?
18---else

-5-
Automatic Test Case Generation Of ‘C’ Programs Using CFG

Feasible paths are the paths for which the other is Internal Variable. In
some input data is available to execute symbolic execution, the input variables
them and for infeasible paths vice-versa. of a program are assigned symbolic
values. These symbolic values are fixed
and unknown.
Symbolic execution basically
distinguishes between two types of
statements, one is the assignment
statement and the other is decision
making / branching statement.
First, the developer is discussing about
assignment statement. Suppose a
program P is having two input variables
a, b and an internal variable c.
The assignment statement is c = a + b
Other assignment statement is d = c - a

6. Symbolic Execution Then, at the beginning of symbolic


execution of P, symbolic values A & B
Symbolic Execution (Department of
are assigned to input variables a & b. At
Computer Science Clemson University,
the time of symbolic execution of this
1990) is a program analysis method that
assignment statement, c is assigned
represents the program computations as
value as A + B. The symbolic execution
symbolic expressions. This technique
of next assignment statement will
can be used to test a program by
evaluate the value for d as: d = A + B -
computing full symbolic output values
A = B.
or it can also be used to generate test
Now, the developer is discussing about
cases for a program.
the decision making / branching
During the symbolic execution of a
statement.
program, the actual data values are
Refer Fig. 3.6 to have a clear
replaced by symbolic values. Generally,
understanding. At node 1, the condition
a program is having two kinds of
for decision making/ branching is (A>0
variables. One is the Input Variable and

-6-
Automatic Test Case Generation Of ‘C’ Programs Using CFG

& B>0 & C>0). If (A>0 & B>0 & C>0) Suppose if path: Node1-> Node3->
yields true then, the control flow of the Node4 ->Node14 is considered. Then,
program will move from node 1 to node the symbolic evaluation of this path
3 and if (A>0 & B>0 & C>0) yields yields the following path predicate
false then, the control flow of the expression:
program will move from node 1 to node ((A>0 && B>0 && C>0) AND !
2. So, during symbolic execution, the (A<B+C && B<A+C && C<A+B)).
predicate expression for case (when Now, using random testing the symbolic
condition (A>0 & B>0 & C>0) is true) is values are placed by randomly generated
expressed as (A>0 & B>0 & C>0) and in values and the values which will satisfy
other case (when condition (A>0 & B>0 this path predicate expression, means
& C>0) is false), the predicate those set of values can execute the path
expression will be !(A>0 & B>0 & and the set of values is one test data for
C>0). the program.
Similarly, it will be done for each 6.1 Random Testing Technique
decision making / branching statement.
Random Testing Technique is used in
Finally, for a particular path, all the
this automatic test case generation tool
predicates expressions are conjunctively
to select values randomly from the input
joined to form path predicate expression.
domain of the program input variables.
This path predicate expression will
These randomly generated values are
contain the input and internal variables
assigned to the symbolic values and then
in terms of symbolic values.
the predicate expressions for all decision
making nodes in a path are joined using
logical AND to form a conjunctive
clause for that particular path. Then,
randomly generated values are used to
satisfy the conjunctive clause. The
values which will be able to satisfy the
conjunctive clause for a path become the
test data for that path to execute.
7. Problems Identified After Research

-7-
Automatic Test Case Generation Of ‘C’ Programs Using CFG

if(z>20) is the next statement to be


7.1 Internal Value Problem: executed, then in this case z is having
During symbolic execution, all internal constant value which is a contradiction
variables on branch predicates in a
(i.e. All internal variables on branch
program must be evaluated in form of
input variables. predicates in a program must be
Suppose input variables are x, y & z is
evaluated in form of input variables). As
an internal variable.
z is an internal variable and it is given a
Consider these program statements:
constant value but according to symbolic
z = x + y.---1
execution, it must be expressed in terms
if(z>0) ---2
of input variables.
{
7.2 Dynamic Data Structure Problem
statement s1;
}
Dynamic data structure like pointer
Let X & Y be symbolic values for x & y.
value and array whose value of index
Then, for statement 1: z = X + Y
depends on the run time values are still
And for statement 2: if((X + Y)>0)
undecided to be executed by symbolic
{
execution.
statement s1;
The problem mentioned above is still
}
undecidable to be solved using static
Actually, there are two kinds of
testing. So, the developer will not be
assignments: one is predicate base and
solving this problem.
other which is not predicate based.
7.3 Loop Problem:
z = X + Y --- not a predicate based
According to this problem, the loops in
assignment
structured language programs can
if(x>0)
neither be executed by static testing nor
{
by dynamic testing. But different
z=12;---predicate based assignment
researchers proposed different methods
}
to sort out this loop problem while
The problem identified is in case of
executing using static testing.
predicate based assignment., assignment
Suppose one loop is given like this:
is based on symbolic value.
for( i=0; i<10; i++)

-8-
Automatic Test Case Generation Of ‘C’ Programs Using CFG

{ generate test cases. In the testing


Statement s1; framework, this research identify various
} problems and issues and provide
One of the methods proposed was to solutions to overcome the problems and
replace for loop with an if-else in case of to handle the related issues. In the future
static testing while performing using it is possible to remove all errors and
symbolic execution. improve more the quality of software by
Applying this method for the for loop using Genetic algorithm technique to use
mentioned above, the required if-else static technique for test case generation.
selection structure is as follows:
if((i<10)&&(i>=0)) Acknowledgement
{ This work was supported by Dr.
statement s1; Dharmender Kumar. I would like to
} thanks to him for the continual
else encouragement, help and guidance
{ throughout the work.
}
This means that if the condition is true References
then loop will be executed statically one [1] Anastasis A. Sofokleous, “Batch –
time and if condition is false then the Optimistic Test Case Generation Using
loop condition is not matched, like in the Genetic Algorithm”,2007.
case when the loop is bypassed. [2] Anreas S. Andreou, “An Automatic
Conclusion and future work Test Data Generation Scheme Based on
During the Whole life cycle of software Data Flow Criteria and Genetic
project testing plays a important role. Algorithm”2007.
There are various issues related to the [3] Bruce A. Cota , “Control Flow Graph
instrumentation of input program and as Representation Language” IEEE
symbolic testing of the program in the winter simulation conference 1994.
testing framework. Instrumentation of [4] Chao-Jung Hsu, “Integrating path
input program and symbolic execution testing with software reliability
of the program are necessary steps to

-9-
Automatic Test Case Generation Of ‘C’ Programs Using CFG

estimation using control flow graph” [12] M. Prasanna, “A Survey on


IEEE 2008. Automatic Test Case Generation”2005
[5] Chengying Mao, Yansheng Lu , [13] Miller, W.and Spooner,D.L. , “
“Cpp Test : A Prototype Tool For Automatic Gneration Floating –Point
Testing C/C++” IEEE Program Second test data” IEEE transaction on software
International Conference on Availability engineering 1976.
and Security 2007. [14] Ntafos, S.C. “A Comparision of
[6] Carlos Urias Munoz, “An Apporoach Some Structural testing Strategies” IEEE
to Software Product Testing”IEEE transaction on software engineering
Transaction of Software Engineering 1988.
1988. [15] Patricia Mouy, “ Generation of all
[7] Douglas G. Fritz, “An overview of path unit test with function calls”2008.
Hierarchical Control flow graph [16] Preeyavis Pringsulaka, “Coverall
Models” IEEE winter simulation Algorithm for Test case reduction IEEE.
conference 1995. [17] Robert G. Sergent, “Some recent
[8] DeMillo, R.A and Offutt,A.J, advances in the Process World view”
“Constraint Based Automatic Test Data IEEE winter simulation Conference
Generation” IEEE Transaction of 2004
Software Engineering 1991. [18] Weyuker, E. , “Axiomatizing
[9] Fenping Zeng, “Test Case generation Software test data Adequecy”IEEE
based on invariant extaction” IEEE trasaction on Software Engineering
2009. 1986.
[10] Howden, W.E, “Reliability of the [19] W.Eric.Wong, “Effective
Path Analysis testing Strategy” IEEE generation of test Sequences of
transaction on Software Engineering structural testing of concurrent
1976. programs”2005
[11] Jon Evardsson , “A Survey on
automatic Test data Generation” In
proceeding of the Second conference on
Computer science and Engineering in
Linkoping, page 21-28 ECSEL 1999,

-10-
Automatic Test Case Generation Of ‘C’ Programs Using CFG

-11-

S-ar putea să vă placă și