In this paper, we propose an approach to automatically generating test data in mobile software testing, concentrate on energy properties.. In this paper, we propose an approach to automa
Trang 1Abstract—In recent years, mobile software has been rapidly
developing The key requirement of mobile software is to ensure
optimum power throughout its run Unlike testing other software
properties, energy testing is usually done on real devices to check
actual energy consumption As such, testers need to have optimal
test data to save time and effort in testing
In this paper, we propose an approach to automatically
generating test data in mobile software testing, concentrate on
energy properties The approach, firstly, builds CFGs (Control
Flow Graph) from the source code of the application We then
propose algorithms to select testable paths from CFG such that
the mobile applications consume more energy Finally, test data
are generated from the testable paths
Index Terms—Power Consumption, Control Flow Graph,
Soft-ware Testing
I INTRODUCTION
In recent years, the number of people using mobile devices
has increased significantly They use mobile phones not only
for connecting people but also for entertainment and working
Mobile applications are becoming more and more popular and
handy
Time spent on mobile devices increases day by day, so the
duration usage of mobile devices requires to be increased
Hardware manufacturers are increasingly expanding the
ca-pacity of their batteries while software makers are trying to
optimize software when applications are in use In software
engineering field, to prepare releasing of an application, one
needs to test energy properties of the software application
There have been many studies on testing the properties of
software systems, such as safety, performance, security, etc
Recently, testing the energy properties of software systems,
particularly mobile software, drawing software experts’
atten-tion Testing energy properties [3] aims to detect errors that
cause of large or unnecessary power consumption It may helps
software developers promptly fix software errors
Unlike other types of testing, most energy properties testing
are performed on real devices and are measured in reality
to evaluate the energy consumption for each test set, which
results in wasting a lot of time and effort Therefore,
optimiz-ing test suites and eliminatoptimiz-ing unhelpful test cases promise a
solution to save much resources in testing mobile applications
The paper [5] has also shown that there are essentially faults
in the source code that cause the device to consume high
amounts of energy In order to find energy bugs, we focus on
finding code snippets that consume more power than allowed
by testing
In this paper, we propose an approach to automatically generating test data concentrating on energy properties The contribution of our paper includes: (1) proposing a CFG (Control Flow Graph) from mobile software’ source code; (2) building algorithms to select the testable paths which the mobile applications consume more power; (3) generating test data from the testable paths
The remain structure of the paper is presented as follows Section II presents an overview of the knowledge and issues that need to be addressed in testing the energy properties
of the application In Section III, we propose a new CFG graph to model the change in power consumption when the statements are executed Section IV introduces the algorithms that optimize the graph and generating the paths on the graph
to generate test data We illustrate the result of the approach using a small case study in Section V The last section offers
a conclusion and some directions for development of the research
II BACKGROUND The techniques we propose in this paper are to create
a new CFG, which can help find test data on the energy characteristics of the application [2] In this section, we discuss some of the issues of testing, energy properties and energy states proposed in previous studies [1]
A The issues of using CFG in testing The input data of the test cases is very important, they decide whether to identify errors in the program or not There are many methods for determining input data for test cases [15], one of which is CFG analysis A Control Flow Graph (CFG) is a directed graph in which the vertices (or nodes) represent basic building blocks and the edges represent control flow paths [11] CFG can be generated automatically from source cod eas exemplified in Figure 1
In CFG, a feasible and complete path is a set of consecutive vertices from the first vertex (v1) to the last vertex (vn):
path = {v1, v2, , vn}
A set of test cases will be generated from a path Finding all the paths will provide a useful set of test data [7]
Trang 2Fig 1 Generating a CFG
Generating test data is most difficult when loops occur in
CFG However, the paper [6] and [16] has solved the above
problems We therefore acknowledge that CFG only includes
complete and independent paths This is an important basis
for creating a new graph to test the energy properties of the
application
B The issues of CFG in generating energy test cases
Several works showing how to create test cases from CFG
[12] [13] [14] When we applied these methods to test the
energy properties of a mobile application, we discovered a
number of issues that needed to be resolved
1) CFG has many useless paths in testing energy
proper-ties: Energy bugs are a major cause of fast energy declines
on mobile devices Energy bugs have different characteristics
than other functional bugs, graphical bugs, wording bugs, or
performance bug For example, with the functional bugs, one
tries to detect all paths in CFG and generate test data from
these paths However, when looking at the paths on CFG, we
find that there are a few paths that have little effect on the
device’s power consumption (unhelpful paths), we focus on
removing unhelpful paths to optimize the number of test cases
2) CFG data is not sufficient for testing energy properties:
Another problem, the test results depend on the testing
envi-ronment in some cases For example, when we download a
file, network speed and file size affect the test results of the
download function Poor network speeds or large file sizes
increase download time, so the device consumes more power
The time affects the energy consumption of mobile device
However, the data generated from CFG has not been able to
check this case To solve this problem, we propose a solution
to mark the nodes on CFG depending on the time, as a basis for the generation of test data in the next step
C Power state of Mobile applications
In the previous study [1], we introduced a concept called the ”Power state of the application” - the power state of the device when it is controlled by the application
Accordingly, when each statement in the application is executed, it can change the device’s power consumption, then the power consumption state changes
In figure 2, when the M ediaP layer.Start() statement is executed, the speaker system of the mobile device is turned
on, which consumes a higher power level, the device switches
to a new state of energy consumption
Fig 2 The device’s power consumption status are changed by control statements
Trang 3give the consumption weight for each state of P CAapp This
will help us know which states consume a large amount of
energy, which is the basis for further research
III OURAPPROACH
It is possible to generate test data for some software
properties from CF G, but it is ineffective when applied to
the energy properties of the software because of the two issues
raised in Part II
We propose a new CF G to solve the problems in Part 2
This approach focuses on assigning two weights (consumption
and execution time) to the CF G to overcome the
disadvan-tages of CF G in energy testing
Figure 3 depicts our approach of generating test data First,
we combined the P CAApp with the CF G to create a new
graph (named CF Gc) The graph CF Gcis the same as CF G
but the energy consumption is an extra weight on the vertices,
which helps to evaluate testable and unhelpful paths Next, we
evaluate the statements in the source code to mark the vertices
that are time-sensitive, we create the new CF Gct
A Assigning energy consumption weight to CF G
The work [8] and many other studies have proposed
algo-rithms that generate CF G from source code automatically We
use the result of this work to generate a CF G from a mobile
software code
The number of branches on CF G will be very large,
we need to eliminate those that have less effect on energy
consumption
To determine how each branch affects the energy
consump-tion, we calculate the weight for each vertex in the CF G using
the energy automaton proposed in the previous studies [1] and
[10]
The new graph is called CF Gc and if v is a vertex (or
node) of CF G, then vc is the new vertex of CF Gc
Where: vc = {v, c} and c is power consumption weight of vc
We perform algorithm 1 to assign the energy weights into
vertices of the CF Gc
Figure 4(a) is the original CF G generated from the source
code of the application After applying algorithm 1, the graph
CF Gchave been built as shown Figure 4(b), in which vertices
are assigned energy consumption weights
weight of state s
6: end for
B Assigning time weight toCF Gc
To solve the second problem, we continue to improve
CF Gc and assign time weights to the vertices The vertices
of the graph are divided into 2 types:
• Time dependent: these vertices are marked with a star (∗)
• Regardless of time: these vertices are left blank
We call the new graph is CF Gct Figure 4(c) shows an example of some vertices depending on execution time
If vc is the vertex of CF Gc, then vct= {vc, blank}|{vc, ∗} where:
• vct = {vc, blank} if vertex v contains a statement, the set of statements is independent of time
• vct= {vc, ∗} indicates that vertex v is time dependent Time-dependent statements are collected from the Android API library [17]
To create the CF Gct, we propose the algorithm 2 Algorithm 2 Assigning the time weights in each vertex Input:
CF Gc
LA - List of Android APIs are time dependent Output:
CF Gct 1: Initialize CF Gct= CF Gc and vct= {vc, blank} ∀ vct
2: for each vertex vc in CF Gc do 3: call s is the statement represented by vertex vc
4: if s ∈ LA then 5: vct= {vc, ∗}
6: else 7: vct= {vc, blank}
8: end if 9: end for
Based on the time-dependent vertex data, the designer can adjust the test environment (network speed, file size, etc) to design more test cases
Trang 4Fig 3 Approach overview of generating test data
Fig 4 An example CF G, CF G c and CF G ct
IV AUTOMATICALLY GENERATE TEST DATA
In order to generate test data for an Android application,
we need to find the paths of the CF Gct, the set of all paths
of CF Gct is called P
p = {vct1, vct2, , vctm}
P = {p1, p2, , pn}
In reality, the number of paths of the CF Gct can be
very large, so we try to select the paths that the application
consumes more power
Let be the allowable energy threshold of a CF Gct’s
vertex, we define a vertex with a high level of energy
con-sumption
Definition 1: A vertex of a CF Gct is called a high energy
consumption vertex if its energy consumption weight (c) is
larger than the
The is set by the test case designer, it depends on the
specific case If is set to be less than zero, all the vertices of
CF Gct are high energy consumption vertices In this study,
we choose as the average consumption of all vertices
The is calculated by the formula:
= (c1+ c2+ + cn)/n Where c1, c2, , cn is power consumption weight of
vct1, vct2, , vctn and n is the number of CF Gct vertices
In this study, we give an average consumption weight
of all the vertices, but the tester can completely adjust the weight to redefine the high energy consumption level, then the number of paths generated can be changed
In energy testing, we are interested in the vertices with high power consumption Thus, all paths passing through these vertices need to be considered
Definition 2:A path of the CF Gct is called a testable path
if it contains at least one high energy consumption vertex Base on the definitions, we propose two steps to optimize the test data set, including:
• Step 1: Finding testable paths
• Step 2: Arranging the paths in order of priority
A Finding testable paths
To find testable paths in the graph, we proceed to browse all paths and mark the paths with high energy consumption vertices The algorithm 3 describes how to find testable paths
Trang 55: if c >= then
6: Pe= Pe∪ p
9: end for
10: end for
B Arranging test data in order of priority
In the next step, we arrange the path in Pe in order of
priority The paths that consume high amounts of energy will
be tested first
Suppose Ciis total energy consumption of the path i in Pe,
then:
Ci =Pk
j=0cj
in which:
• k is the number of vertices in path i
• cj is the energy consumption weight of vertex j in path
i
After calculating total energy consumption of the entire
paths, we have:
C = {C1, C2, Cm}
in which:
• C is the set of energy consumption weight of the paths
in Pe
• m is the number of paths included in Pe
Rearranging set C in descending order, we will get a priority
of the test cases
C Generating automatically test data
Based on the studies of Gupta [9] and Roy [4], we built
a tool that automatically generates CF Gct from source code,
calculates paths of CF Gct, arranges paths according to the
priority order and generates test data automatically
For each path in Pe, our tool generates test data including
specific values of variables and marks * on statements that are
time-dependent The designer can use this data to design the
test-cases
else{
} 8| }
By applying Algorithm 1 and the algorithm 2, we have
CF Gct as shown in Figure 5
Fig 5 CF G ct of the case study
By calculating the weighted average of the vertices, we calculate and get the result as follows:
= (0 + 0 + 0 + 0 + 0 + 0 + 384.62)/7 = 54, 95 Vertex 8 is the ending vertex so we do not calculate this vertex’s weight
Based on the CF Gct, we calculate the set of paths P P consists of 3 paths: p1, p2 and p3
p1= {1, 2, 8}
p2= {1, 3, 4, 8}
p3= {1, 3, 5, 6, 7, 8}
We see that only vertex 7 has a higher weight than , so every testable path on CFG must go through vertex 7 There are several paths that are useless in energy testing To remove them, we apply algorithm 3 and the result returned Pe:
Pe= {p3} The total weight of the path p3 is 384.62 and Pe contains only one path, there is no need to re-order If Pecontains more
Trang 6than one path, we can sort them in descending order to get
priority for the testable paths
Next, we consider the path p3 and the method of
automat-ically generating data from this path
1| !(index < 0)
3| !(index >= 100)
5| index++;
6| mediaPlayer.seekTo(index);
7| *mediaPlayer.start();
8| }
In path p3, there is only one variable, index Based on
index’s constraint conditions in statements 1 and 3, applying
the method proposed in Sub section IV-C, the test data will
be generated automatically
TestData: {index = 0, index = 1, , index = 99}
In addition, the mediaP layer.start() statement is marked
with a star (*), so when designing a test case, the designer
should note that the statement is time-dependent Therefore,
when selecting songs to test for this function, it is necessary
to select songs of different lengths to give more test cases
VI CONCLUSION The paper have presented an approach to automatically
gen-erate data in the power test of Android applications Based on
the previous research results, we proposed to build a Control
Flow Graph that allows to classify useful and unhelpful paths
in energy testing of the graph We also proposed algorithms
to select and optimize testable paths The advantage of our
approach is the ability to remove most of the useless testing
paths on the Control Flow Graph and so that we may save
time and effort in power testing of mobile softwares
We have developed a tool that automatically generates test
data from the source code according to the principle of the
approach This tool, actually, can only generate test data from
simple code snippets In the future, we plan to improve the
approach and the support tool to solve more complex problems
and large softwares
REFERENCES [1] Hong-Anh Le, Anh-Tu Bui, and Ninh-Thuan Truong ”An approach to
modeling and estimating power consumption of mobile applications”.
Mobile networks and Applications, 24(1):124–133, 2019.
[2] Anh-Tu Bui, Hong-Anh Le, and Ninh-Thuan Truong ”Generation of
power state machine for android devices” In ICCASA/ICTCC, 2017.
[3] Jabbarvand, Reyhaneh, and Sam Malek ”Advancing Energy Testing of
Mobile Applications” 2017 IEEE/ACM 39th International Conference
on Software Engineering Companion (ICSE-C) IEEE, 2017.
[4] Pargas, Roy P., Mary Jean Harrold, and Robert R Peck ”Testdata
generation using genetic algorithms” Software testing, verification and
reliability 9.4 (1999): 263-282.
[5] Jabbarvand, Reyhaneh, et al ”Energy-aware test-suite minimization for
android apps” Proceedings of the 25th International Symposium on
Software Testing and Analysis 2016.
[6] Aditya P Mathur ”Foundations of software testing 2E” Pearson
Education India, 2013.
[7] Manish Mishra, Shashi Mishra, and Rabins Porwal ”Basic principle
for test case generation automatically” VSRD International Journal of
Computer Science & Information Technology, 2(9):772–781, 2012.
[8] Flemming Nielson, Hanne R Nielson, and Chris Hankin ”Principles
of program analysis” Springer, 2015.
[9] Gupta, Neelam, Aditya P Mathur, and Mary Lou Soffa ”Generating test data for branch coverage” Proceedings ASE 2000 Fifteenth IEEE International Conference on Automated Software Engineering IEEE, 2000.
[10] Lide Zhang, Robert P Dick, Z Morley Mao, Zhaoguang Wang, and Ann Arbor ”Accurate Online Power Estimation and Automatic Battery Behavior Based Power Model Generation for Smartphones”, 2010 [11] Frances E Allen ”Control flow analysis” ACM Sigplan Notices, 5(7):1–19, 1970.
[12] Tanwer, Sangeeta, and Dharmender Kumar ”Automatic test case generation of C program using CFG” International Journal of Computer Science Issues (IJCSI) 7.4 (2010): 27
[13] Panthi, Vikas, and D P Mohapatra ”Test Scenarios Generation using Path Coverage” International Journal of Computer Science and Informatics 3.2 (2013): 64-68.
[14] Mishra, Deepti Bala, et al ”Test case generation and optimization for critical path testing using genetic algorithm” Soft Computing for Problem Solving Springer, Singapore, 2019 67-80.
[15] Korel, Bogdan ”Automated software test data generation” IEEE Transactions on software engineering 16.8 (1990): 870-879.
[16] Edvardsson, Jon ”A survey on automatic test data generation” Pro-ceedings of the 2nd Conference on Computer Science and Engineering 1999.
[17] Android API https://developer.android.com/guide/index.html.