realistic context generation for mobile app testing and ... · realistic context generation for...

12
Realistic Context Generation For Mobile App Testing and Performance Evaluation Manoj R. Rege , Vlado Handziski , and Adam Wolisz Technische Universität Berlin Email: [email protected], [email protected], [email protected] Abstract—Mobile app testing and evaluation requires exposing the app to a wide array of real world context conditions viz. location, sensor values, network conditions etc. Such compre- hensive context conditions are difficult to create in a devel- opment environment on a real device, therefore, simulating them in a mobile emulator is a promising alternative. We present ContextMonkey, a framework for context generation in a mobile emulator. ContextMonkey can generate realistic context by leveraging traces in correlated and interdependent way from heterogenous sources: remote trace databases, models, and trace files. It eases the burden on developers to collect correlated traces, convert them to a common format, and feed them to the emulator in an orchestrated manner. We present examples demonstrating the simplicity and potential of ContextMonkey in app testing scenarios. I. I NTRODUCTION The growing popularity of mobile devices like smart-phones, tablets, and wearables has created a highly-competitive mobile app ecosystem where quality of the user experience is crucial for the success of the app. Recent studies [1], [2] have found that 44% users delete their apps immediately if they do not perform as per their expectations. Bad experiences are attributed to heterogeneous factors such as ease of user interfaces as well as poor app performance over networks and across different mobile devices etc. Thus, pre-release app testing and evaluation is critical. The app performance in terms of crashes, response times, energy consumption, network bandwidth consumption, etc. is significantly impacted by the context created by the complex interaction of multiple factors related to the execution envi- ronment. These include mobile device capabilities, the quality of the network connectivity to the backend, the load on the backend servers, the type and frequency of sensor values, and users location among others. Furthermore, these factors are often interrelated, and dependent on each other. The app needs to be exposed to a wide array of realistic combinations of all these parameters in the test phase so as to reduce performance issues post release. Recreating such rich context in the physical reality introduces high overheads in time and cost, and challenges in controllability and repeatability. Thus, realistic trace-driven simulation of such context conditions can be a viable alternative. However, creating trace-driven context simulation is quite laborious. One would have to create and build a library of wide variety of realistic traces and play them in an orchestrated manner. This is not straightforward since the traces for the individual context modalities might have to be collected in a correlated manner and from heterogeneous sources. They can be recorded using mobile devices, leveraged from trace databases, generated using mathematical models etc. All the traces would then have to be converted to a common format. Further, these simulated conditions would need to be made available to the app under test. There are two possible approaches to do this: using either a real device, or a mobile emulator. Linking such a simulation to a real device is operating system (OS) platform dependent, and not transparent. It would require developers to include the simulation as a library in the app source code, and modify it to use the simulation APIs instead of the standard APIs provided by the OS. On the other hand, mobile emulators imitate internal hardware of mobile devices in a software stack, and have the functionality that enables the software stack to communicate with the app without having to make any changes to the app source code. They also have existing APIs exposed to configure the stack appropriately. These APIs can be reused to simplify the linking of a context simulation by feeding traces in an orchestrated manner. Despite being widely used, mobile emulators lack comprehensive capability for context simulation, which is increasingly becoming important with sensor-rich apps. Thus, linking context simulations to emulators can help to bridge the gap between them and real devices, increasing their level of realism. In this paper, we present ContextMonkey, a framework that simulates realistic contextual conditions for app testing and evaluation in a mobile emulator. ContextMonkey enables context simulation by leveraging traces from external trace databases, models, libraries, and trace files in a correlated and interdependent manner. It automates the fetching of traces from these heterogeneous sources, and converts them into emulator specific format, and then orchestrates their feeding to the emulator. Furthermore, it provides a set of APIs using which the developers can define suitable contextual simulations as per the requirements of the app under test. ContextMonkey framework is emulator independent, and can be used for simulating context in multitudes of mobile emulators running on the local workstation as well as those running in the cloud based services. II. CONTEXT MODELING FOR APP TESTING & EVALUATION Many definitions of Context have been proposed in the literature (see [3]). Dey [4] defines context as “any information

Upload: dinhduong

Post on 23-May-2018

223 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Realistic Context Generation For Mobile App Testing and ... · Realistic Context Generation For Mobile App Testing and Performance Evaluation ... imitate internal hardware of mobile

Realistic Context Generation For Mobile AppTesting and Performance Evaluation

Manoj R. Rege⇤, Vlado Handziski†, and Adam Wolisz‡

Technische Universität BerlinEmail: ⇤[email protected], †[email protected], ‡[email protected]

Abstract—Mobile app testing and evaluation requires exposingthe app to a wide array of real world context conditions viz.location, sensor values, network conditions etc. Such compre-hensive context conditions are difficult to create in a devel-opment environment on a real device, therefore, simulatingthem in a mobile emulator is a promising alternative. Wepresent ContextMonkey, a framework for context generation ina mobile emulator. ContextMonkey can generate realistic contextby leveraging traces in correlated and interdependent way fromheterogenous sources: remote trace databases, models, and tracefiles. It eases the burden on developers to collect correlated traces,convert them to a common format, and feed them to the emulatorin an orchestrated manner. We present examples demonstratingthe simplicity and potential of ContextMonkey in app testingscenarios.

I. INTRODUCTION

The growing popularity of mobile devices like smart-phones,tablets, and wearables has created a highly-competitive mobileapp ecosystem where quality of the user experience is crucialfor the success of the app. Recent studies [1], [2] have foundthat 44% users delete their apps immediately if they do notperform as per their expectations. Bad experiences are attributedto heterogeneous factors such as ease of user interfaces as wellas poor app performance over networks and across differentmobile devices etc. Thus, pre-release app testing and evaluationis critical.

The app performance in terms of crashes, response times,energy consumption, network bandwidth consumption, etc. issignificantly impacted by the context created by the complexinteraction of multiple factors related to the execution envi-ronment. These include mobile device capabilities, the qualityof the network connectivity to the backend, the load on thebackend servers, the type and frequency of sensor values,and users location among others. Furthermore, these factorsare often interrelated, and dependent on each other. The appneeds to be exposed to a wide array of realistic combinationsof all these parameters in the test phase so as to reduceperformance issues post release. Recreating such rich contextin the physical reality introduces high overheads in time andcost, and challenges in controllability and repeatability. Thus,realistic trace-driven simulation of such context conditions canbe a viable alternative.

However, creating trace-driven context simulation is quitelaborious. One would have to create and build a library ofwide variety of realistic traces and play them in an orchestratedmanner. This is not straightforward since the traces for the

individual context modalities might have to be collected in acorrelated manner and from heterogeneous sources. They can berecorded using mobile devices, leveraged from trace databases,generated using mathematical models etc. All the traces wouldthen have to be converted to a common format. Further, thesesimulated conditions would need to be made available to theapp under test. There are two possible approaches to do this:using either a real device, or a mobile emulator. Linking sucha simulation to a real device is operating system (OS) platformdependent, and not transparent. It would require developers toinclude the simulation as a library in the app source code, andmodify it to use the simulation APIs instead of the standardAPIs provided by the OS. On the other hand, mobile emulatorsimitate internal hardware of mobile devices in a software stack,and have the functionality that enables the software stack tocommunicate with the app without having to make any changesto the app source code. They also have existing APIs exposedto configure the stack appropriately. These APIs can be reusedto simplify the linking of a context simulation by feeding tracesin an orchestrated manner. Despite being widely used, mobileemulators lack comprehensive capability for context simulation,which is increasingly becoming important with sensor-richapps. Thus, linking context simulations to emulators can helpto bridge the gap between them and real devices, increasingtheir level of realism.

In this paper, we present ContextMonkey, a frameworkthat simulates realistic contextual conditions for app testingand evaluation in a mobile emulator. ContextMonkey enablescontext simulation by leveraging traces from external tracedatabases, models, libraries, and trace files in a correlatedand interdependent manner. It automates the fetching of tracesfrom these heterogeneous sources, and converts them intoemulator specific format, and then orchestrates their feeding tothe emulator. Furthermore, it provides a set of APIs using whichthe developers can define suitable contextual simulations asper the requirements of the app under test. ContextMonkeyframework is emulator independent, and can be used forsimulating context in multitudes of mobile emulators runningon the local workstation as well as those running in the cloudbased services.

II. CONTEXT MODELING FOR APP TESTING &EVALUATION

Many definitions of Context have been proposed in theliterature (see [3]). Dey [4] defines context as “any information

Page 2: Realistic Context Generation For Mobile App Testing and ... · Realistic Context Generation For Mobile App Testing and Performance Evaluation ... imitate internal hardware of mobile

CompassLocation

Network Camera Accele-rometer

Fig. 1: A Directed Acyclic Graph for A Walk at BrandenburgGate context.

that can be used to characterize the situation of an entity. Anentity is a person, place, or object that is considered relevant tothe interaction between a user and an application, including theuser and applications themselves”. Context for mobile apps canbe understood as a set of interrelated factors that can potentiallyimpact the end behavior of the app. We refer to these factorsas modalities further on in this paper. These modalities include:1) Mobile device capabilities - CPU, memory, camera, storage.2) Sensors - temperature, pressure, humidity, light intensity,noise sound level, and change in their values. 3) User state,location, and environment: stationary, mobile, indoors/outdoors,etc. 4) Network type and conditions - 3G, LTE, WiFi - Latency,bandwidth, and packet loss.

These modalities are low-level, often interdependent oneach other, and have values that may vary over time. Thecontext logic in mobile apps consumes these low-level modal-ities, aggregates them, and uses them for context estimation,adapting their behavior over time accordingly. Thus, firstly,ContextMonkey needs a context model which is based on low-level modalities that vary over time, as this would enable thecontext logic in the apps to function seamlessly. Secondly, themodel needs to provide support for defining inter-dependenciesbetween the low-level modalities as observed in the real-world.And finally, the model should be easy to learn and use bydevelopers and at the same time be able to express wide arrayof high-level context definitions. This is due to the fact that inapp testing and evaluation, the appropriate high-level contextdefinition to be used, the relevant modalities associated withthem, and the dependencies among the modalities are largelyapp under test specific, and only best known to the developers.

Context Modeling has been well studied in the literature(see [5], [6], [7]). There are several approaches to modelthe context. Key-value model is the simplest way to rep-resent context information as key-value pairs. However, itcannot model the inter-dependencies and relationships betweenmodalities. Markup based models (ContextML [8], CompositeCapabilities/Preference Profiles (CC/PP) [9], etc.) representcontext data as tags that enable efficient retrieval and validation.Markup based models are highly app dependent and increasein complexity as the information at multiple levels increase,hence, they are not preferable. Logical models use rules,expressions, and facts to represent context. They have high-level of expressibility, however are strongly coupled to theapplication. Ontology based models [10] are the most popularchoice due to its semantic reasoning, application independence,and expressiveness capabilities. However, representation of

Ontology based models can be complex, and they are generallyresource intensive. Graph based models [11], [12] use rela-tionships to represent context. Such a model offers a middleground in terms of variation in representation of low-levelrelationships, richness of expression, and ease of use due to itsintuitive nature. Therefore, for ContextMonkey we have decidedto use graph based models.

In the following we give an example illustrating its use, bymodeling a simple context scenario A Walk at the BrandenburgGate using low-level modalities. Such a context might bedefined by the facts that 1) The mobile device should have thelocation with latitude and longitude values of the BrandenburgGate. 2) The device should experience similar network condi-tions as at the Brandenburg Gate for a given network carrier.3) The camera on the mobile device should capture image ofthe Brandenburg Gate when pointing towards it, and 4) theaccelerometer on the mobile device should have values as inreal walking. The context is represented as a Directed AcyclicGraph (DAG) G =<V,E > (shown in Figure 1), where V isthe vertices set representing all the modalities in the context viz.location, camera, compass, network, and accelerometer. E isthe edge set, where each edge ek

j represents the interdependencebetween two modalities and implies that the modality Vk isdependent on V j. In our example, the camera modality isdependent on both the location and the compass, and thenetwork modality is only dependent on the location. The acyclicnature of the graph prevents circular dependencies betweenthe modalities. The dependencies in the context graph aretransitive by default. The context graph can have disconnectedcomponents that represent modalities independent from others,for example, accelerometer modality. The temporal variationin the modality is specified using the rate of change parameter.Each modality has its own rate of change.

III. CONTEXTMONKEY

A. Design GoalsThe ContextMonkey framework design is based on achieving

three important goals that are discussed in the following.1) Emulator and Data Source Independence: The framework

should be decoupled from both the emulator as well as the datasources used in obtaining the traces for simulation. This ensuresseamless integration of the framework with various emulators(those offering suitable interface to feed the traces) availablefor smart-phones, tablets, wearable devices, and heterogeneousdata sources for traces (those offering interface to obtain traces)such as crowd-sourced databases, models, and trace files.

2) Extensibility: The framework should promote easierintegration of new high-level context scenarios in the future.This implies that it should be possible to add new low-levelmodalities to the framework. These low-level modalities canbe new physical and virtual sensors (functions over physicalsensor values) added on the emulators due to growing mobiledevice capabilities, or any modality that exist on current mobiledevice but not supported by its emulator presently.

3) Fidelity & Seamlessness: The framework should simulatecontext for the app in an emulator-agnostic manner, just as on

Page 3: Realistic Context Generation For Mobile App Testing and ... · Realistic Context Generation For Mobile App Testing and Performance Evaluation ... imitate internal hardware of mobile

a real device. It should capture context at fine-grained level inhigh-fidelity manner; feeding traces of each individual modalityto the emulator at rates observed on a real mobile device.It should also adapt the trace feeding rates of modality asper the rates configured in the app source code. Furthermore,it should provide context simulation to the app seamlessly,without requiring to make any changes in the app source codelike integrating external libraries, and API change.

B. ChallengesOne of the key challenge in the context simulation with

regards to the above design considerations is the potentialinterdependent nature of the modalities. Interdependence re-quires careful orchestration in fetching and feeding traces tothe emulator. This is not easy when the data source types ofmodalities differ. Each data source may have its own methodand APIs to generate traces; the time for fetching traces fromeach data source type may differ widely. Further, the data sourcemay have its own format used to represent the trace. On theother end, the emulator would have its own APIs for feedingtraces, and trace format understood by the emulator mightdiffer from that of the data source. Therefore, the frameworkneeds to understand and execute the respective API calls for theheterogeneous data sources and emulators, and also handle dataformat conversions. These tasks have to be executed respectingthe defined rate of change of the individual modalities so asto maintain high fidelity.

C. ArchitectureThe ContextMonkey architecture has been proposed in the

poster [13]. The architecture is component based and decoupledinto three layers (shown in Figure 2).

1) Trace Layer: The Trace Layer is primarily responsiblefor interacting with heterogeneous trace data sources used insimulation, and orchestrating fetching of traces from them. Itprimarily supports three data source types:

• Trace database services in the cloud such as GoogleStreetView [14], Open Signal [15], Foursquare loca-tion [16], etc. that support fetching traces using APIqueries.

• Models such as BonnMotion [17], SUMO [18], etc. thatprovide highly specialized tools & libraries to generatetraces.

• Trace files that contain individual modality trace datasetscaptured using real mobile devices (such as those availableat Crawdad [19]).

The Trace Layer includes three components:Data Source Manager - The Data Source Manager co-

ordinates all the Trace Layer functionalities associated withobtaining traces from the data sources and processing themfor the simulation. It constructs trace fetching requests. Incase of trace database services this includes API URLs withappropriate query parameters, authorization and authenticationnecessary for using APIs, the HTTP request method, etc. Incase of models, it is the library path details, the appropriatecommands and their corresponding options needed to generate

Data-Source Specific API

Emulator

Data-Source

ContextMonkey

Context Data Queues

Emulator Specific API

Context Manager

Feed API

Context Layer

App

AccelerometerCamera

Trace Layer

GPS

Databases Models Trace Files

Trace API

Feed Layer

Emulator Handler

Feed Format ManagerEmulator Manager

Data-Source Handler

Data-Source Manager

Trace Format Manager

Conte

xtMon

key A

PI

Callback API

Callback API

Context Data Queues

Fig. 2: The ContextMonkey Architecture. The dotted elementsare external to the architecture.

traces, and file paths, headers and their respective formats fortrace files. It also handles the asynchronous Trace API methodsthat are explained further on. Using the data source definitions,the manager maps incoming trace fetching requests to theappropriate data source handler. The manager also handlesprocessing of traces fetched from a data source. The data sourcetrace value units for the modality could be different and need tobe converted. For instance, in case of camera modality imagesmight have different resolution, file compression format whichneed to be processed. The manger filters unwanted attributesfrom the fetched traces. It also handles trace fetching failuresthat can occur due to heterogeneous reasons: unavailability oftraces, exceeded limits on the API calls, service unavailability,network failures, etc. In case of a failure, the manager supportstrace generation based on default values, interpolation, andextrapolation functions. Finally, it sends processed traces to theTrace Format Manager and forwards format converted tracesreceived from the Trace Format Manager to the Context Layer.

Trace Format Manager - A data source might have itsown trace representation format which could be differentfrom the emulator understood trace format. The Trace Layeris emulator-agnostic, therefore the Trace Format Managerfacilitates conversion from the data source specific trace formatsto a common internal representation format of ContextMonkey.

Page 4: Realistic Context Generation For Mobile App Testing and ... · Realistic Context Generation For Mobile App Testing and Performance Evaluation ... imitate internal hardware of mobile

ContextMonkey External API - To the app developers

createContextSimulation - create an instance of ContextMonkey simulation environmentcreateContextGraph - create an instance of Context Graph to be used in the simulationaddModality - include a new modality or modalities in the Context GraphaddDependency - add a modality dependency or dependencies in the Context GraphaddDataSource - associate a data source with the modalityaddEmulator - include a compatible mobile emulator in the simulationrunTime - specify the context simulation run time period in secondsstart - start the context simulation

Fig. 3: ContextMonkey API Description

Data Source Handler - The Data Source Handler containsthe connection logic for fetching traces from the data sources.It multiplexes execution of trace fetching requests from variousdata sources. It executes the queries for fetching trace valuesfrom the database, commands for models, and read operationon trace files and forwards them to the Data source manager.It maintains a local cache of fetched traces, and only fetchesa trace in case of a cache miss.

2) Context Layer: The Context Layer lies at the heart ofContextMonkey managing the control and the execution of thesimulation. It acts as a bridge between fetching traces fromthe data sources, and feeding them to the emulator. It is bothdata source, as well as mobile emulator-agnostic.

Context Data Manager - The Context Data Managerhandles all the functionality of the Context Layer. It maintainsthe context model definition that includes the context graph,the physical, and the virtual modalities, and its dependencies.It computes virtual modality values using these definitions.The manager maintains an individual real clock timer for eachmodality which periodically fires according to its rate of changeparameter, and calls the asynchronous Trace API in orderto request traces. In order to obtain a modality trace that isdependent on another, the manager keeps the knowledge ofthe current value of its predecessor modalities in the contextgraph. Furthermore, it registers, and implements the callbackAPI function to be notified of successful trace requests. Uponreceiving the requested trace, the registered callback functionforwards the trace to the Feed Layer.

Context Data Queue - ContextMonkey also supportsdefining virtual modalities. The virtual modality computationrequires trace values of dependent physical modalities. Asthe physical modalities can have varying amount of timedelay in fetching their trace, the queues store a copy of theirfetched trace value before forwarding it to the Feed Layer. Eachmodality has its own separate queue. Separate queues ensuresequential control logic for individual context modality traces.Computing virtual sensor function requires a synchronousdequeue from dependent modality queues.

3) Feed Layer: The Feed Layer provides the glue whichis necessary to bind ContextMonkey to a compatible mobileemulator. Compatibility implies that a mobile emulator shouldsupport a suitable API for feeding traces, and also make themavailable to the app. The main components of Feed Layer are:

Emulator Manager - The Emulator Manager is the core

component that coordinates activities of the Feed Layer. Itmaintains information necessary for integrating mobile emulatorwith ContextMonkey. This includes emulator specific infor-mation about different supported modalities by the emulator,the emulator API description of a modality for setting andgetting values, their respective formats, the communicationprotocol and configuration parameters to be used in calling theemulator API. Furthermore, it also handles the asynchronousFeed API exposed to the Context Layer to set and get theindividual modality values from the emulator. It forwardsreceived traces to the Feed Format Manager for trace formatconversion. Finally, it maps the modality trace set and getrequests to the appropriate handler for feeding the trace.

Feed Format Manager - The Feed Format Manager dealswith the trace format conversions between the ContextMonkey’sinternal representation format, and the emulator data format.

Emulator Handler - The Emulator Handler is responsiblefor establishing connection to the emulator using the emulatorspecified protocol. It executes requests to set and get themodality values in the emulator by making appropriate APIcalls.

4) API Description: The ContextMonkey API description isgiven in Figure 3. The external APIs are those that are exposedto the app developers to enable them to specify a contextscenario for simulation in the form of graphs, and configure thesimulation related parameters. This includes defining modalitiesand their dependencies, the rate of change, registering datasources and their APIs, the emulator and its APIs, the traceformats, and simulation run period. The internal Trace API andthe Feed API are used for the internal communication betweenthe three layers for fetching the traces and feeding them to theemulator.

IV. DESIGN ALTERNATIVES

During ContextMonkey design, we considered severalalternatives, some were not obvious at the time, however quiteimportant in refining the design goals. We discuss them in thefollowing.

A. System Model AlternativesThere are two possible models to implement the ContextMon-

key architecture. In a local model, the framework runs on thedeveloper’s local workstation that has an app developmentenvironment setup alongside a mobile emulator. For instance,Android SDKs [20] provide toolchains, platform system images,external libraries, and APIs along with emulators for appdevelopment and testing. Alternatively, developers may testtheir apps remotely on a mobile emulator that is runningon a Virtual Machine (VM) in the cloud. CrowdMeter [21],Caiipa [22] are some platforms that offer such cloud basedtesting services. The cloud system model, due to its scalability,offers an additional degree of flexibility by loosely couplingthe ContextMonkey layers among multiple VMs. We limitthe implementation of the architectural layers on to a singlededicated machine. However, we consider both the localworkstation and the cloud VM for the evaluation.

Page 5: Realistic Context Generation For Mobile App Testing and ... · Realistic Context Generation For Mobile App Testing and Performance Evaluation ... imitate internal hardware of mobile

App

Feed LayerContext Layer

Trace Layer

Host Platform

Emulator

Mobile OS

App

Feed LayerContext Layer

Trace LayerHost Platform

Emulator

Mobile OS

App

Feed Layer

Context LayerTrace Layer

Host Platform

Emulator

Mobile OS

App

Feed LayerContext Layer

Trace LayerHost Platform

Emulator

Mobile OS

Fig. 4: Design Alternatives for organization of three layers ofAbstraction

B. Layer OrganizationOne of the most simple ways to realize the ContextMonkey

architecture is to place the ContextMonkey as a mobile appinside the guest mobile OS in the emulator. Besides loosing theemulator and OS platform independence, and seamlessness, itintroduces overhead from having to run the app in an emulatedenvironment where code translation from the guest to the hostsystem is necessary. The other four alternatives (illustrated inFigure 4) stem from the possibilities to structure the layersbetween the emulator and the underlying host platform. The firstalternative places the three layers within the mobile emulator.In case of the second, and in the third alternative, the layersare distributed between the emulator and the host platform.However, these three alternatives fail to achieve completeemulator independence. The fourth alternative is comprisedof placing all the layers on the host platform external to theemulator, and reflects our design goals.

C. Data Trace RepresentationFeeding a trace to an emulator requires format conversion

from a data source format to an intermediate common format,and then to an emulator understood format. XML, JSON, andProtobuf [23] are some of the data formats that can be used forrepresenting traces. Both XML and JSON are human-readable,and offer encoding and decoding without the knowledge ofthe schema in advance. However, compared to XML, JSON iscompact, and less verbose. A binary format like Protobuf needsa predefined schema that needs to be compiled before using itfor encoding and decoding. Being a binary format, Protobufcan seamlessly support encoding and decoding of binary tracemodalities like images. Furthermore, it has a smaller footprintcompared to XML, JSON, and also offers faster data encodingand decoding. The trace feeding rate is an important metric inorder to achieve high fidelity for context simulation. Therefore,we use Protobuf for representing the traces internally withinthe ContextMonkey.

V. IMPLEMENTATION

The ContextMonkey prototype has been implemented inPython. Each architectural layer is organized as a separatePython module, and the components are implemented asseparate classes within the module. The individual componentsin the implementation are shown in Figure 5. At the heart ofContextMonkey implementation lies the Twisted [24] library

that provides support for event driven network programming.ContextMonkey is available as open-source project athttps://github.com/manojrege/contextmonkey.The prototype consists of ⇡ 8K lines of Python code. In thefollowing, we discuss the implementation in detail.

The contextmodel module includes class definitions forthe modality and the Context Graph (DAG) used in expressingcontext within the framework. The ContextModalityabstract class defines an individual context modality andits generic attributes like rate of change, modality depen-dencies, data-source, and trace-processing library. Physi-calContextModality and VirtualContextModal-ity are two subclasses that extend the ContextModalityclass. The PhysicalContextModality class representssensors, location sensors, camera, and network condition modal-ities within the context. The VirtualContextModalityclass represents virtual sensors and has computation attributespecifying the method used to calculate the sensor value. Thedata-source associated with a context modality are definedin the DataSource abstract class and includes attributessuch as datasourcetype, datasourceformat, queryparameterlistassociated with the data-source. The Database, the Model,and the TraceFile classes extend the DataSource classand represent the three types of sources supported by Con-textMonkey. The ContextGraph class represents the DAGfor context specification. The DAG is implemented using thepython NetworkX library. The node attribute in the DAGare of type PhysicalContextModality and Virtu-alContextModality, and the edge attributes define thedependencies among them. It also provides methods for gettingand adding context modalities in the graph, and performs cyclicdependency checks in the context model.

The ContextSimulation class exposes ContextMonkeyAPIs to the developers. It maintains simulation definition,environment, and the associated global variables. The Con-textEngine class includes the event based Twisted reactorloop that coordinates and schedules the events in each layer.It is also responsible for starting and stopping the simulation.The developers need to import the contextmodel and theContextSimulation class to create and run a contextsimulation.

The ContextManager class is responsible for generationof physical modality trace requests based on the modality rateof change. It includes a list of timers for each modality basedon the TimerService utility from the Twisted library. Whenthe modality timer fires a trace request is sent by calling thegetValue method exposed by the Trace Layer.

The DataSourceManager class handles all theTrace Layer functionality. Its executeFetch methoddynamically instantiates and loads a DatasourceHandlerclass instance for trace fetching. This handlerinstance then dynamically maps the request to eitherone of the DatabaseRequestHandler, or theFileRequestHandler, or the ModelRequestHandlerclass instances, based on its modality type. TheDatabaseRequestHandler class is extendable and

Page 6: Realistic Context Generation For Mobile App Testing and ... · Realistic Context Generation For Mobile App Testing and Performance Evaluation ... imitate internal hardware of mobile

uses

= Data Queue

Trace Protobuf Library

ContextSimulationAPI

ContextModel

DataSource Handler

Database RequestHandler

Model RequestHandler

File Request Handler

OpenSignal

Streetview

AccelerometerTraces

LocationTraces

SUMO

BonnMotion

Trace Processing

Stock Android emulator Handler

Emulator Manager

SensorProtocol

Feed Format Converter

AndroidConnection

GPSProtocol

CameraProtocol

Accel.Protocol

Genymotion Handler Genymotion

Client

GenymotionConnection

GPSProtocol

GenymotionTelnet

GenymotionProcessProtocol

Genyshell

encoding

decoding

Trace request

Trace processing& filtering

Decodingdefinition

encodedtrace

encodedtrace

Trace Format Converter

DataSourceHandler

DataSource Manager

Context Manager

StreetView

LocationTrace

OpenSignal

Stock Emulator

Genymotion Emulator

mappinguses

ContextEngine

uses

uses

traceTCP/IP

Feed trace

Feed trace

decodedtrace

Encodingdefinition

Trace Fetching request

HTTP

command

Fileread

Inter ProcessCommunication

decodedtrace

uses

Fig. 5: The component diagram of ContextMonkey implementation

provides a set of methods for fetching traces from remotedatabases. Presently, it supports fetching using HTTP andHTTPS based GET method. It uses the Twisted WebClientthat enables sending specific request methods, settingappropriate headers and also supports error handling based onresponse codes. Similarly, the FileRequestHandler, andthe ModelRequestHandler classes support trace fetchingmethods from the files and the models respectively. Somemodels like BonnMotion provide commands to generate tracesand store them in a file. The ModelRequestHandler thendelegates the trace fetching to FileRequestHandler. Thetrace fetching requests are handled asynchronously by theunderlying Twisted reactor loop.

The TraceProcessing class provides a generic interfacethat provides methods to filter and process trace foreach context modality. As these are data source dependent,the developer can use a separate class to implement thesemethods and enable customized trace processing. Presently, itsupports processing of camera and network modality tracesfrom StreetView and OpenSignal databases respectively. Thesupport for trace format conversion from data source formatto Protobuf is implemented in the TraceFormatManagerclass. The current version supports conversion between thecomma separate value (CSV), JSON and byte formats, andProtobuf.

The ContextDataQueue class provides support for tracebuffering in order to be utilized for the computation of virtualsensor value. The traces from the buffer are dequeued asper the feed rate. The EmulatorManager class exposes

a setModalityValue method for this purpose. The Feed-FormatManager class implements format conversion fromProtobuf to emulator understood format. The EmulatorHan-dler provides a generic Connection interface that containsmethod to establish a connection with the emulator and set thetrace values of individual modality in the emulator using theemulator provided API. We have implemented connection inter-faces for the stock Android [25] (AndroidConnection) andGenymotion [26] (GenymotionConnection) emulators.

The control flow in each layer is implemented using theDeferred design pattern provided by the Twisted framework. Itregisters a sequential callback chain on the deferred objects ineach stage, consisting of trace request generation, datasourcehandler mapping, trace request fetching, trace processing,format conversion, and trace feeding.

VI. EVALUATION

A. Emulator IndependenceIn order to evaluate the emulator independence, we present

examples demonstrating ease of integration of ContextMonkeywith stock Android [25], and Genymotion [26] emulators.

1) Stock Android: The stock Android emulator comesbundled with Android SDK Platform [20], and uses the QuickEMUlator (QEMU) [27] virtualization suite that providesemulation support for several different CPU architectures.The emulator runs Android guest operating system with theGoldfish kernel in QEMU. The emulator supports sensorsimulation stack with a Telnet based command interface.

Page 7: Realistic Context Generation For Mobile App Testing and ... · Realistic Context Generation For Mobile App Testing and Performance Evaluation ... imitate internal hardware of mobile

The command interface enables setting trace values in theAndroid Hardware Abstraction Layer (HAL) that are then madeavailable to the app space in the emulator. We successfullyintegrated the stock Android Emulator with our ContextMonkeyframework. The integration module consists of 338 lines ofcode. The module contains the AndroidConnection classthat implements the interface exposed by the Emulation Handlerfor connection establishment and API call logic. It establishesa Telnet session over a persistent TCP socket connection. Eachmodality is implemented in a separate class that extends fromGeneralSensorProtocol class, and provides method forsetting trace values. We implemented support for 7 sensormodalities with the stock Android emulator.TABLE I: Details of emulator integration with ContextMonkey

Emulator Stock Android Genymotion

Number of Files 10 8Lines of Code 338 399Number of sensors 7 2

2) Genymotion: Genymotion provides a custom GenyShellshell environment to communicate with the emulator. Similarto the stock Android emulator, the connection and the APIcall logic is implemented through Emulator Handler providedinterface in GenymotionConnection. The integrationsource code for Genymotion emulator consists of 399 linesof code. The connection spawns a Telnet server process andthe GenyShell as a separate daemon process. The inter processcommunication between the Telnet server and the GenyShellprocess is carried using the ProcessProtocol provided byTwisted. The API calls to set the trace modality are sent ascommands to the Telnet server that forwards them to GenyShellto set the values in the emulator.

B. Data Source Independence

To demonstrate the data source independence, we integratedmodalities from popular external trace databases such asStreetView [14], OpenSignal [15], and FourSquare [16] withContextMonkey (shown in Table II). We also implementedsupport for location, mobility modality trace generation usingpopular models like BonnMotion [17], and libraries likeSUMO [18]. Furthermore, modality traces from datasetsavailable on CRAWDAD [19], like taxi mobility traces [28],and accelerometer sampled traces collected from Android smart-phones while driving on different vehicles [29] were also added.TABLE II: Description of different data sources integrated withContextMonkey

Modality Source Type

Location FourSquare Database

MobilitySUMO ModelBonnMotionCabSpotting File

Camera Google StreetView DatabaseNetwork OpenSignal DatabaseAccelerometer Mobile Device (driving) File

Fig. 6: MobiCamSim: A location based mobile camera simula-tion with the StreetView in the stock Android emulator.

C. Extensibility: MobiCamSim - A location context drivenmobile camera

We demonstrate the ContextMonkey extensibility usinga MobiCamSim example. MobiCamSim is a trace-drivenlocation context based camera simulation that can be usedfor testing camera sensing based mobile apps. The presentcamera modality in the stock Android emulator serves eitherthe checker-board or the webcam images. We introduce a newcamera modality in the stock Android emulator and implementthe support for feeding image traces to the camera through anAPI. We then use ContextMonkey to define a new contextsimulation that includes location, and compass dependentcamera modality with a predefined field of view parameter.We use the StreetView database to feed location based imagetraces to MobiCamSim (shown in Figure 6).

D. Fidelity

We measure fidelity by comparing the modality vectorreporting rate in an app running on a real mobile deviceto ContextMonkey instrumented stock Android emulator. Theselected modalities include sensors, location, and camera. Weuse only stock Android emulator for our evaluation as theGenymotion emulator has a limited simulated sensor stackAPI support. For our experiments, we use a Moto G phonerunning Android Lollipop 5.1.1. The stock Android emulatorhas an equivalent hardware with respect to ARM CPU, memory,sensors, and OS configuration. We report results from 10 trialruns. We measure the ContextMonkey simulation fidelity on alocal work station (2.3 GHz Intel Core i5 processor with 4GBRAM and Ethernet connectivity), and in our CrowdMeter [30]cloud testbed (t2.medium virtual machine with 2 virtual CPUcores, and 4.0 GB RAM from Amazon Web Services (AWS)Elastic Compute Cloud (EC2) [31]).

Sensors - We use accelerometer, and compass modalitytraces captured on a Moto G phone in a file to measure thesensor simulation fidelity. For the sake of brevity, we onlypresent results for the accelerometer modality. Our analysis isas well applicable to other sensors such as temperature, rotation,gravity, gyroscope, light, etc. present on typical Androiddevices. In the app, we configure four delay settings providedin the Android API for reporting sensor vector value events:FASTEST, GAME, UI, NORMAL, and measure their respectiveaverage reporting rates over a 2 min interval. FASTEST, GAMEUI, NORMAL settings report events at 100 Hz, 50 Hz, 20 Hz,and 5 Hz respectively. We set these values as feeding rates in

Page 8: Realistic Context Generation For Mobile App Testing and ... · Realistic Context Generation For Mobile App Testing and Performance Evaluation ... imitate internal hardware of mobile

0255075

100125

MotoG Workstation Cloud VM(a)

Even

t Rate

(Hz) FASTEST

GAMEUINORMAL

00.020.050.08

0.1

MotoG Workstation Cloud VM(b)

Even

t Rate

(Hz)

GPS

01020304050

MotoG Workstation Cloud VM(c)Ca

pture

Laten

cy (m

s)

Camera

Fig. 7: ContextMonkey Fidelity measurements in the app space. A comparison of (a) Accelerometer reporting rate (b) Locationreporting rate (c) Camera image capture latency measured on a Moto G phone, and on a stock Android emulator instrumentedwith ContextMonkey simulation running on the local work-station and a VM in the cloud testbed.

the ContextMonkey based accelerometer simulation, and thenmeasure the reporting rate in the app within the emulator. Weobserved that the maximum achievable average reporting rate inthe app in case of simulation is 1.20 Hz (local workstation) and1.23 Hz (cloud VM). On further investigation, we found thatalthough ContextMonkey is able to feed values to the simulatedsensor stack within the emulator at the configured rate, thestack only reports events to the app every 800 ms (1.25 Hz). Wemodified the emulator source to change the reporting period asper the FASTEST, GAME UI, NORMAL values measured onthe Moto G phone. Figure 7(a) shows the bar plots comparingthe average event reporting rates (over a 2 min interval) foraccelerometer on a Moto G phone, and in a simulation runningon the local workstation and a VM in the cloud testbed. Postfine-tuning, the average reporting rate in simulation improvedsignificantly to 47.7 Hz (local workstation) and to 47.9 Hz(cloud VM), but fell short of FASTEST value (100 Hz). Ouranalysis suggest that the bottleneck lies in the simulated sensorstack that has to report events to the HAL and then to the appspace, and the time required for it is larger than 10 ms. Also,the binary opcode translation for the ARM CPU did not play abig role, as only a marginal improvement was observed in theaverage reporting rate for the emulator with x86 CPU: 48.5Hz (local workstation) and 48.9 Hz (cloud VM). We plan toaddress this in our future work. However, ContextMonkey wasconsistently feeding traces to the emulator at the desired ratefor sensor simulation.

Location - Location is an important modality for context.We also use trace files generated from a BonnMotion model tomeasure location simulation fidelity. The Android based devicesprovide six different types of location data services to the app:cached GPS, cached network (Cell-id, WiFi), realtime GPS, realtime network, and passive (piggybacked location updates arereceived based on other app’s location requests). The AndroidAPI also provides minTime and minDistance settings that serveas lower bounds to deliver the location updates to the app. Weconfigure the app to use a GPS provider and obtain locationupdates as fast as possible (minTime=0 and minDistance=0).We do not consider other factors such as time to get a locationfix, number of satellites, accuracy, etc. On a Moto G phone,the GPS provider location update events are reported at therate of 0.05 Hz . We use this value to configure the locationsimulation. From the Figure 7(b), one can see that unlike in

TABLE III: Description of context simulation parameters

Modality Frequency(Hz) Data-Source Type

Accelerometer 30 Traces FileLocation 1 BonnMotion FileCamera 0.01 StreetView DatabaseNetwork 0.01 OpenSignal Database

the sensor simulation, in the location simulation (on both thelocal workstation, as well as a VM in the cloud testbed), itis possible to achieve a reporting rate that is equivalent to aMoto G phone.

Camera - We use MobiCamSim to measure the camerasimulation fidelity using capture latency as a metric. The imagecapture latency is defined as the amount of time taken to capturea picture using a camera app. It also includes the time requiredto store the picture of a particular resolution on the device filesystem, or on the internal memory, or the external storage. Weuse a prototyped Android camera app for the measurements.The resolution of the picture is set to 640 x 640 (maximumresolution provided by StreetView). Figure 7(c) illustrates thebar plots for the camera capture latency measured on a MotoG phone and in MobiCamSim on a local workstation and acloud VM. The image capture latency of simulation on thelocal workstation and a cloud VM are 1.14 and 1.04 times thatof real Moto G camera.

Overall, we are encouraged by the fidelity results. In future,we plan to address the sensor stack bottleneck issue, througha new stack design for the stock Android emulator.

E. Microbenchmark - Maximum Achievable Feeding Rate

We instrumented the ContextMonkey code to measure thetime complexity of each individual component in the simulation,and thus, the maximum achievable feeding rate. The maximumachievable feeding rate is measured as the inverse of total timeinterval starting from the trace request generation to the feedingof trace to the emulator by making an API call. We simulatedThe walk around Brandenburg Gate context example using theaccelerometer, the location, and the location dependent cameraand network modalities (details given in Table III).

Table IV shows the component-wise latency breakdownof each modality in the context simulation run on the localworkstation and a cloud VM. The maximum achievablefeeding rate of a modality trace is largely dependent on its

Page 9: Realistic Context Generation For Mobile App Testing and ... · Realistic Context Generation For Mobile App Testing and Performance Evaluation ... imitate internal hardware of mobile

TABLE IV: ContextMonkey components latency break down on the Local Workstation and a Cloud VM. The average, maximum,and minimum statistics are calculated across 100 trial runs

Component Modality - Data-source Local Workstation (ms) Cloud VM (ms)

Avg Max Min Avg Max Min

DataSource Handler

Accelerometer - Trace File (JSON) 0.09 0.12 0.03 0.03 0.05 0.02Location - Model (Text) 0.024 0.028 0.022 0.017 0.03 0.014Camera - StreetView (Binary) 97.88 164.88 67.57 19.62 146.47 10.04Network - OpenSignal (JSON) 867.37 1255.18 778.54 791.23 946.70 739.44

DataSource Manager - Processing StreetView 42.12 53.11 38.11 18.42 29.64 13.49OpenSignal 0.09 0.11 0.08 0.07 0.1 0.5

Trace Format Manager - Encoding

Accelerometer - Trace File 0.00 0.00 0.00 0.00 0.00 0.00Location - Model 0.14 2.8 0.11 0.08 1.0 0.03Camera - StreetView 0.00 0.00 0.00 0.00 0.00 0.00Network - OpenSignal 0.15 0.19 0.14 0.14 0.16 0.11

Feed Format Manager - Decoding

Accelerometer - Trace File 0.00 0.00 0.00 0.00 0.00 0.00Location - Model 0.01 0.04 0.01 0.01 0.03 0.00Camera - StreetView 0.09 0.14 0.09 0.07 0.1 0.06Network - OpenSignal 0.02 0.04 0.02 0.02 0.03 0.01

Emulator Handler (API call)

Accelerometer - Trace File 0.42 1.20 0.33 0.37 1.18 0.31Location - Model 0.40 1.28 0.35 0.39 1.10 0.37Camera - StreetView 8.20 9.23 7.95 3.63 4.85 2.67Network - OpenSignal 0.05 0.06 0.05 0.05 0.05 0.03

Total Time

Accelerometer - Trace File 0.49 2.01 0.49 0.49 1.35 0.49Location - Model 0.50 2.05 0.50 0.49 1.45 0.48Camera - StreetView 152.13 221.13 118.23 45.64 179.34 30.12Network - OpenSignal 867.90 1255.12 778.90 791.99 949.23 739.78

data-source type and the trace format. We discuss the leastmaximum achievable feeding rate observed for different datasources (across 100 trial runs). The least maximum achievablefeeding rate for the accelerometer modality using trace filesis 497 Hz (local workstation) and 740 Hz (cloud VM). Theseresults support our earlier analysis that the bottleneck lies inthe simulated sensor stack of the emulator. In case of thelocation modality using model, the least maximum achievablefeeding rate observed is 489 Hz (local workstation) and 687Hz (cloud VM). The above results clearly demonstrate thatContextMonkey can easily achieve the feeding rates for highfrequency sensors when using trace files, and models. For thecamera and the network modality that use a trace database,the maximum achievable feeding rate varies from 4.5 Hz to8.4 Hz (StreetView) and 0.7 Hz to 1.2 Hz (OpenSignal) on alocal workstation. On a cloud VM, the maximum feeding rateincreases due to the low end-to-end network path latency andfewer number of hops: 5.5 Hz to 33.2 Hz (StreetView) and 1.05Hz to 1.35 Hz (OpenSignal). In case of database, the feedingrate is limited by the end-to-end network path latency, and thebackend response time (accounting for more than 98%).

F. ContextMonkey Case StudiesWe have carried out two case studies using ContextMonkey.

Our goal here is to demonstrate the simplicity, and potentialof ContextMonkey in the mobile app testing and evaluation,and not the novelty of the apps themselves.

1) GeoCrowdSens: GeoCrowdSens is a crowd-sensingbased Android app that uses geofences to trigger collection of

data related to surrounding events using mobile devices [32].The app requests the user to respond to a simple textquery; taking picture, video snaps, etc. Geofence defines ageographical area around a point of interest specified by thefine-grained and coarse-grained radius parameters. The coarse-grained radius triggers an injection, and in-app deployment ofthe geofence over the network, while the fine-grained radiustriggers collection of the data when the user enters the area ofinterest. Reliable triggering of a geofence is dependent on thecoarse-grained radius, the user speed, the network conditions,and the location service provider. We use ContextMonkeyto simulate context for GeoCrowdSens in the stock Androidemulator deployed on a VM in the CrowdMeter testbed. Thetest set-up includes a hermetic server [33] running locally onthe same VM in the testbed. The 3G network is simulatedusing the in-built network simulation support provided by theemulator (leaky bucket with traffic shaping). For the purposeof simulation, we collected location (GPS location provider)and 3G network traces for different context - walking, running,driving, and commuting (train), using a Moto G phone. The 3Gnetwork traces included the end-to-end latency, the bandwidth,and the packet loss between the phone and the GeoCrowdSensbackend service. We used Ping utility and Iperf [34] tool for thenetwork trace collection. The location, and the network traceswere then included in a file, and used in the ContextMonkeysimulation. The simulation consists of 16 lines of code (shownin Appendix A). For the simulation, the rate of change oflocation is set to 20s. We present the results from 30 trial runs

Page 10: Realistic Context Generation For Mobile App Testing and ... · Realistic Context Generation For Mobile App Testing and Performance Evaluation ... imitate internal hardware of mobile

0255075

100

20 50 100 300Radius (m)

Hit %

WalkingRealSim(Hermitic)Sim(NonHermitic) 0

255075

100

20 50 100 300Radius (m)

Hit %

BikingRealSim(Hermitic)Sim(NonHermitic)

0255075

100

20 50 100 300Radius (m)

Hit %

DrivingRealSim(Hermitic)Sim(NonHermitic) 0

255075

100

20 50 100 300Radius (m)

Hit %

TrainRealSim(Hermitic)Sim(NonHermitic)

Fig. 8: A comparison of geofence hit percentage in (hermitic and non-hermitic) simulation with real field for different mobilityscenarios.

0

5

10

15

20

Real Workstation Cloud VM(a)

Resp

onse

Tim

e (s)

0

5

10

15

20

C1 C2 C3 C4(b)

Resp

onse

Tim

e (s)

0

5

10

15

20

Berlin Rome Mumbai(c)

Resp

onse

Tim

e (s)

Fig. 9: Fine-grained CamTour response time analytics on a 3G network using ContextMonkey A comparison of (a) Responsetime estimates for a network carrier using ContextMonkey on a local workstation and a cloud VM. (b) Response time estimatesfor different network carriers in Berlin. (c) Response time estimates at different geographical locations.

for the impact of user speed, and the coarse-grained radius onthe detection (hit) percentage of geofences. The hit percentageis the fraction of geofences that were successfully triggeredfor both the enter and the exit events.

The bar plots in Figure 8 compare the hit percentage in fieldtest and hermetic simulation for the 3G network. As expected,the results show an increasing trend in the hit percentagewith the increase in the coarse-grained radius for differentmobility scenarios. For walking (5km/h), the coarse-grainedradius as small as 20 m can achieve 96.7% hits in hermeticsimulation. For average biking speed (20 km/h), 100% hits areachievable for increased radius of 100 m. In case of driving(40-80 km/h), and commuting (train) (>80km/h) 100% hitsare obtained for radii values greater than 300 m while radiismaller than 100 m fail to trigger even a single geofence. Next,we compare the hermetic simulation results to a small scalefield measurements. The worst case percentage error betweenfield testing and hermitic simulation estimated hit percentagesfor walking, biking, driving and commuting(train) are 0.03%,8.3%, 9.8% and 3.7% respectively. These results demonstratethat it is possible to estimate an appropriate threshold coarse-grained radius value based on user speeds and the network usingContextMonkey simulation. We also carried out non-hermitictest simulation experiments, using the location traces fromBonnMotion model, and the network statistics that have beenreported in the literature [35], [36]. In these experiments, theworst-case percentage error for biking, driving, and commuting(train) increased to 61%, 66%, and 33% respectively while itremained similar in case of walking (0.03%). These test resultshighlight the impact that the test set-up, and the selected tracedata source within ContextMonkey simulation can have on theestimated app performance parameters.

2) CamTour: CamTour is a camera based Android appinspired by Google Glass, and provides information aboutthe landmarks in cities. A user snaps a picture of landmark;CamTour then uses the location coupled with the picture contentto search and deliver landmark related information to theuser. Response time is an important performance metric forCamTour. Developers usually measure response times within alimited scope using real devices. While such measurements arequite valuable, obtaining fine-grained Response time analyticsbased on the real world landmark imagery is desirable forapps such as CamTour. We use ContextMonkey to simulatecontext for CamTour in the stock Android emulator. We definea context based on a location dependent trace driven camerafrom StreetView image traces, and the 3G network conditions(latency, bandwidth, and packet loss) from the OpenSignalnetwork traces. The emulator is deployed on a VM in theCrowdMeter testbed. It is not possible to deploy a hermiticsetup in the CamTour case study due to an external APIdependency [37] for picture content search. Therefore, weuse a non-hermitic setup, with the CamTour backend runningin the production Google App Engine [38] server. The sourcecode for the ContextMonkey simulation consists of 18 linesof code (given in Appendix B). We measure the CamTourResponse time estimates under a given load for 5 differentlandmarks in 3 different cities, and on for 4 different networkcarriers.

The results from 20 trial runs are shown in Figure 9. Wehave labeled the network carriers C1-C4 to mask their identity,and focus on the significance of the results. In Figure 9a, wecompare the response times obtained in the simulation withthe real measurements obtained from a 3G network carrierin Berlin. The mean response time percentage error between

Page 11: Realistic Context Generation For Mobile App Testing and ... · Realistic Context Generation For Mobile App Testing and Performance Evaluation ... imitate internal hardware of mobile

the simulation and the real measurements is 31.8% on a localworkstation and 7.8% in the CrowdMeter cloud testbed. Next,we discuss the response time analytics obtained from thesimulations in the CrowdMeter testbed. The app response timesacross different network carriers in Berlin vary significantly(see Figure 9b). The average 3G latencies on carrier C1 arelower by 73.5% compared to carrier C3. As a result, theaverage response times observed on C1 are 39.4% lower thanC3. Figure 9c illustrates the CamTour estimated response timeson a C1 network carrier, across three different cities aroundthe world. It provides insight into the impact of the CamTourusers geographical location on the response times.

VII. RELATED WORK

Our work builds on the top of previous research efforts incontext modeling, and complements the existing literature incontext enabled testing. Context modeling is well studied in thearea of Pervasive and Ubiquitous computing. SimuContext [39]is a context simulation framework for testing context awareapplications that provides separation between the data sources,and context-aware logic. ContextMonkey, however, is aimed atsimulating mobile app specific contexts within mobile emula-tors. There are a wide array of tools and platforms focusingon different aspects of testing like fault detection, crashes andbugs, UI, functionality etc. For example, AppInsight [40] is ainstrumentation framework that focuses on identifying faultswithin mobile apps. VanarSena [41] utilizes instrumentation tofind bugs in the mobile app. Caiipa [22] is a scalable cloudbased testing service to discover performance bugs and crashes,and hosts a predefined set of contextual trace libraries for blackbox testing. ContextMonkey nicely complements such platformsand services. It can be utilized by app developers, as well asby large-scale cloud based testing services for context enabledtesting. OpenIntents [42] and Samsung Sensor Simulator [43]provide simplified individual sensor simulation capabilitieson mobile emulation platforms. The authors in [44] comeclosest to our goal. They propose a Android based contextsimulator that uses app source instrumentation with speciallibraries. In contrast, ContextMonkey does not require appcode instrumentation. It offers wide range of possibilities as itprovides context simulation support across the emulators usingheterogeneous trace data sources.

VIII. CONCLUSIONS

We presented the ContextMonkey framework for context gen-eration in mobile emulators. The key focus of ContextMonkeyis to promote use of realistic context in testing and evaluationof mobile apps. Accordingly, the ContextMonkey frameworkprovides cross-emulator support for context generation usingtrace-driven simulation. It lessens the burden on the devel-opers by automating interdependent trace generation fromheterogeneous sources and feeding them to the emulator. Ourevaluation of the ContextMonkey framework is based on theperformance comparison for two different mobile apps in thereal field (on a micro scale) with the simulations generatedby the framework in the emulator. In the future, we plan

to extend the ContextMonkey framework to support scalablecontext simulation that can facilitate parallelized and scalabletesting of mobile apps.

ACKNOWLEDGMENTS

The work has been partially supported by Amazon AWSResearch Grant. A special thanks to our shepherd, Antinisca DiMarco, and the anonymous reviewers, for their suggestions inimproving the technical content and presentation of the paper.

REFERENCES

[1] “Why your mobile apps are failing?” http://www.perfectomobile.com/why-mobile-apps-fail, accessed: 25/9/2016.

[2] “Apigee survey: Users reveal top frustrations that lead tobad mobile app reviews,” http://apigee.com/about/press-release/apigee-survey-users-reveal-top-frustrations-lead-bad-mobile-app-reviews.

[3] C. Bettini, O. Brdiczka, K. Henricksen, J. Indulska, D. Nicklas, A. Ran-ganathan, and D. Riboni, “A survey of context modelling and reasoningtechniques,” Pervasive Mob. Comput., vol. 6, no. 2, pp. 161–180, Apr.2010.

[4] G. D. Abowd, A. K. Dey, P. J. Brown, N. Davies, M. Smith, andP. Steggles, “Towards a better understanding of context and context-awareness,” in Proceedings of the 1st International Symposium onHandheld and Ubiquitous Computing, ser. HUC ’99. London, UK, UK:Springer-Verlag, 1999, pp. 304–307.

[5] G. Chen and D. Kotz, “A survey of context-aware mobile computingresearch,” Hanover, NH, USA, Tech. Rep., 2000.

[6] T. Strang and C. Linnhoff-Popien, “A context modeling survey,” in In:Workshop on Advanced Context Modelling, Reasoning and Management,UbiComp 2004 - The Sixth International Conference on UbiquitousComputing, Nottingham/England, 2004.

[7] C. Perera, A. Zaslavsky, P. Christen, and D. Georgakopoulos, “Contextaware computing for the internet of things: A survey,” IEEE Communi-cations Surveys Tutorials, vol. 16, no. 1, pp. 414–454, First 2014.

[8] M. Knappmeyer, S. L. Kiani, C. Frà, B. Moltchanov, and N. Baker, “Con-textml: A light-weight context representation and context managementschema,” in Proceedings of the 5th IEEE International Conference onWireless Pervasive Computing, ser. ISWPC’10, 2010, pp. 367–372.

[9] “Composite Capabilities/Preference Profiles,” https://www.w3.org/Mobile/CCPP/, accessed: 11/01/2017.

[10] D. Ejigu, M. Scuturici, and L. Brunie, “An ontology-based approach tocontext modeling and reasoning in pervasive computing,” in PervasiveComputing and Communications Workshops, March 2007, pp. 14–19.

[11] K. Henricksen, J. Indulska, and A. Rakotonirainy, “Generating contextmanagement infrastructure from high-level context models,” in In4th International Conference on Mobile Data Management (MDM) -Industrial Track, 2003, pp. 1–6.

[12] G. Chen and D. Kotz, “Context aggregation and dissemination inubiquitous computing systems,” in 4th IEEE Workshop on MobileComputing Systems and Applications (WMCSA 2002), 20-21 June 2002,Callicoon, NY, USA, 2002, p. 105.

[13] M. R. Rege, V. Handziski, and A. Wolisz, “Poster: A context simulationharness for realistic mobile app testing,” in Proceedings of the 13thAnnual International Conference on Mobile Systems, Applications, andServices, ser. MobiSys ’15. ACM, 2015, pp. 489–489.

[14] “Google Street View,” https://www.google.com/maps/views/streetview.[15] “OpenSignal Maps,” http://opensignal.com.[16] “Foursquare,” https://developer.foursquare.com/.[17] N. Aschenbruck, R. Ernst, E. Gerhards-Padilla, and M. Schwamborn,

“Bonnmotion: A mobility scenario generation and analysis tool,” inProceedings of the 3rd International ICST Conference on SimulationTools and Techniques, ser. SIMUTools ’10, ICST, Brussels, Belgium,Belgium, 2010, pp. 51:1–51:10.

[18] M. Behrisch, L. Bieker, J. Erdmann, and D. Krajzewicz, “Sumo -simulation of urban mobility: An overview,” in in SIMUL 2011, TheThird International Conference on Advances in System Simulation, 2011,pp. 63–68.

[19] D. Kotz, T. Henderson, I. Abyzov, and J. Yeo, “CRAWDADdataset dartmouth/campus (v. 2009-09-09),” Downloaded fromhttp://crawdad.org/dartmouth/campus/20090909, Sep. 2009.

[20] “Android Studio,” https://developer.android.com/sdk.

Page 12: Realistic Context Generation For Mobile App Testing and ... · Realistic Context Generation For Mobile App Testing and Performance Evaluation ... imitate internal hardware of mobile

[21] M. R. Rege, V. Handziski, and A. Wolisz, “Crowdmeter: An emulationplatform for performance evaluation of crowd-sensing applications,” inProceedings of the 2013 ACM UBICOMP Adjunct Publication. ACM,2013, pp. 1111–1122.

[22] C.-J. M. Liang, N. D. Lane, N. Brouwers, L. Zhang, B. F. Karlsson,H. Liu, Y. Liu, J. Tang, X. Shan, R. Chandra, and F. Zhao, “Caiipa:Automated large-scale mobile app testing through contextual fuzzing,”in Proceedings of the 20th Annual International Conference on MobileComputing and Networking. ACM, 2014, pp. 519–530.

[23] “Protocol Buffers,” https://developers.google.com/protocol-buffers/.

[24] “Twisted,” https://twistedmatrix.com/.

[25] “Android Emulator,” http://developer.android.com/tools/help/emulator.html, accessed: 10/03/2013.

[26] “Genymotion A faster Android emulator,” https://www.genymotion.com.

[27] F. Bellard, “Qemu, a fast and portable dynamic translator,” in Proceedingsof the Annual Conference on USENIX Annual Technical Conference, ser.ATEC ’05. Berkeley, CA, USA: USENIX Association, 2005, pp. 41–41.

[28] M. Piorkowski, N. Sarafijanovic-Djukic, and M. Grossglauser, “CRAW-DAD dataset epfl/mobility (v. 2009-02-24),” Downloaded from http://crawdad.org/epfl/mobility/20090224, Feb. 2009.

[29] M. Jain, A. P. Singh, S. Bali, and S. Kaul, “CRAWDAD datasetjiit/accelerometer (v. 2012-11-03),” Downloaded from http://crawdad.org/jiit/accelerometer/20121103, Nov. 2012.

[30] M. R. Rege, V. Handziski, and A. Wolisz, “Demonstration abstract:Crowdmeter: Predicting performance of crowd-sensing applications usingemulations,” in Proceedings of the 13th International Symposium onInformation Processing in Sensor Networks, ser. IPSN ’14. Piscataway,NJ, USA: IEEE Press, 2014, pp. 311–312.

[31] “Amazon Web Services,” http://aws.amazon.com/, accessed: 10/03/2013.

[32] S. Gaonkar, J. Li, R. R. Choudhury, L. P. Cox, and A. Schmidt, “Micro-blog: sharing and querying content through mobile phones and socialparticipation,” in MobiSys, 2008, pp. 174–186.

[33] “Hermetic servers,” https://testing.googleblog.com/2012/10/hermetic-servers.html.

[34] “Iperf,” http://iperf.sourceforge.net/, accessed: 10/03/2013.

[35] Q. Xiao, K. Xu, D. Wang, L. Li, and Y. Zhong, “TCP performanceover mobile networks in high-speed mobility scenarios,” in 22nd IEEEInternational Conference on Network Protocols, ICNP 2014, Raleigh,NC, USA, October 21-24, 2014, 2014, pp. 281–286.

[36] J. Huang, Q. Xu, B. Tiwana, Z. M. Mao, M. Zhang, and P. Bahl,“Anatomizing application performance differences on smartphones,” inProceedings of the 8th international conference on Mobile systems,applications, and services, ser. MobiSys ’10. ACM, 2010, pp. 165–178.

[37] “Google cloud vision api,” https://cloud.google.com/vision/.

[38] “Google Cloud Platform - App Engine,” https://cloud.google.com/appengine/, accessed: 10/1/2017.

[39] T. Broens and A. van Halteren, “Simucontext: Simply simulate con-text,” in Autonomic and Autonomous Systems, 2006. ICAS ’06. 2006International Conference on, July 2006, pp. 45–45.

[40] L. Ravindranath, J. Padhye, S. Agarwal, R. Mahajan, I. Obermiller, andS. Shayandeh, “Appinsight: mobile app performance monitoring in thewild,” in Proceedings of the 10th USENIX conference on OperatingSystems Design and Implementation, ser. OSDI’12, 2012, pp. 107–120.

[41] L. Ravindranath, S. Nath, J. Padhye, and H. Balakrishnan, “Automatic andscalable fault detection for mobile applications,” in Proceedings of the12th Annual International Conference on Mobile Systems, Applications,and Services, ser. MobiSys ’14. ACM, 2014, pp. 190–203.

[42] “Openintents,” https://code.google.com/p/openintents/.

[43] “Samsung Sensor Simulator,” http://developer.samsung.com/android/tools.

[44] V. Vieira, K. Holl, and M. Hassel, “A context simulator as testing supportfor mobile apps,” in Proceedings of the 30th Annual ACM Symposiumon Applied Computing, ser. SAC ’15. ACM, 2015, pp. 535–541.

APPENDIXCONTEXTMONKEY - CONTEXT SIMULATION CODE

A. Context Simulation: GeoCrowdSens1 i m p o r t con tex tmonkey . ContextMonkeyEngine as e n g i n e2 i m p o r t con tex tmonkey . C o n t e x t S i m u l a t i o n as sim3 from contex tmonkey . c o n t e x t m o d e l . D a t a s o u r c e i m p o r t D a t a b a s e4 from contex tmonkey . c o n t e x t m o d e l . Da taSource i m p o r t T r a c e f i l e5 from contex tmonkey . Con tex tmode l i m p o r t P h y s i c a l C o n t e x t M o d a l i t y6 from contex tmonkey . Emula to r i m p o r t Emula to r78 # M o d a l i t i e s and da t a�s o u r c e s9 d s n e t = T r a c e F i l e ( d a t a s o u r c e i d = 1 , d a t a s o u r c e t y p e = ’ f i l e ’ , d a t a s o u r c e f o r m a t

= ’ t e x t ’ , p a t h = ’ . . / t r a c e f i l e s / n e t w o r k _ d r i v i n g . t x t ’ , h e a d e r = ’ t r u e ’ )10 nwmod = P h y s i c a l C o n t e x t M o d a l i t y ( name = ’ ne twork ’ , s a m p l i n g r a t e = 1 , f e e d r a t e

= 1 , d a t a s o u r c e = d s n e t )1112 d s l o c = T r a c e F i l e ( d a t a s o u r c e i d = 1 , d a t a s o u r c e t y p e = ’ f i l e ’ , d a t a s o u r c e f o r m a t

= ’ t e x t ’ , p a t h = ’ . . / t r a c e f i l e s / l o c a t i o n . t x t ’ , h e a d e r = ’ t r u e ’ )13 locmod = P h y s i c a l C o n t e x t M o d a l i t y ( name = ’ l o c a t i o n ’ , s a m p l i n g r a t e = 0 . 0 5 ,

f e e d r a t e = 0 . 0 5 , d a t a s o u r c e = d s l o c )1415 # C r e a t e C o n t e x t Model16 sim . addModa l i t y ( [ locmod , nwmod ] )17 sim . c r e a t e C o n t e x t G r a p h ( locmod . name , nwmod . name , e0 =( locmod . name , nwmod . name ) )1819 #Add e m u l a t o r20 e m u l a t o r = Emula to r ( ’ Android ’ ,{ ’ add r ’ : ’ 1 2 7 . 0 . 0 . 1 : 5 5 5 4 ’ } )21 sim . addEmula to r ( e m u l a t o r )2223 # S t a r t s i m u l a t i o n24 sim . runTime ( 6 0 0 )25 e n g i n e . s t a r t ( )

Listing 1: GeoCrowdSens

B. Context Simulation: CamTour1 i m p o r t con tex tmonkey . ContextMonkeyEngine as e n g i n e2 i m p o r t con tex tmonkey . C o n t e x t S i m u l a t i o n as sim3 from contex tmonkey . c o n t e x t m o d e l . D a t a s o u r c e i m p o r t D a t a b a s e4 from contex tmonkey . c o n t e x t m o d e l . Da taSource i m p o r t T r a c e f i l e5 from contex tmonkey . Con tex tmode l i m p o r t P h y s i c a l C o n t e x t M o d a l i t y6 from contex tmonkey . Emula to r i m p o r t Emula to r78 # M o d a l i t i e s and da ta�s o u r c e s9 d s n e t = D a t a b a s e ( q u e r y p a r a m e t e r l i s t =[ ’ l a t ’ , ’ l n g ’ , ’ d i s t a n c e ’ , ’ n e t w o r k _ t y p e ’ , ’

a p i k e y ’ ] , keymapping = d i c t ( l a t = ’ l a t i t u d e ’ , l n g = ’ l o n g i t u d e ’ ) ,d a t a s o u r c e f o r m a t = " j s o n " , u r l = ’ h t t p : / / a p i . o p e n s i g n a l . com / v2 /n e t w o r k s t a t s . j s o n ’ , q u e r y p a r a m e t e r s = d i c t ( l a t = " 37 .7907 " , l n g = "�122.4058 " , d i s t a n c e = " 20 " , n e t w o r k _ t y p e = " 3 " , a p i k e y = "@@@@@@@@@" ) ,f e t c h t y p e ="HTTP" )

10 netmod = P h y s i c a l C o n t e x t M o d a l i t y ( name = ’ ne twork ’ , s a m p l i n g r a t e = 0 . 0 1 ,f e e d r a t e = 0 . 0 1 , d a t a s o u r c e = d s n e t , t r a c e p r o c e s s i n g ="OpenSignalNetworkModify " , t r a c e v e c t o r =[ ’ name ’ , ’ r s s i ’ , ’ ave r ageRss iDb ’, ’ downloadSpeed ’ , ’ up loadSpeed ’ , ’ pingTime ’ ] )

1112 t f l o c = T r a c e F i l e ( d a t a s o u r c e t y p e = ’ f i l e ’ , d a t a s o u r c e f o r m a t = ’ t e x t ’ , p a t h =

t r a c e f i l e p a t h , h e a d e r = ’ t r u e ’ , l e n g t h =100)13 locmod = P h y s i c a l C o n t e x t M o d a l i t y ( name = ’ gps ’ , s a m p l i n g r a t e = 0 . 0 1 , f e e d r a t e

= 0 . 0 1 , d a t a s o u r c e = t f l o c , t r a c e v e c t o r =[ ’ a c c u r a c y ’ , ’ a l t i t u d e ’ , ’b e a r i n g ’ , ’ l a t i t u d e ’ , ’ l o n g i t u d e ’ , ’ s t a t u s ’ ] , t r a c e p r o c e s s i n g ="Loca t ionModi fy " )

1415 dbcam = D a t a b a s e ( q u e r y p a r a m e t e r l i s t =[ ’ s i z e ’ , ’ l o c a t i o n ’ , ’ h e a d i n g ’ , ’ p i t c h ’ , ’ key

’ ] , keymapping= d i c t ( s i z e =" 600 x400 " , l o c a t i o n =" l a t i t u d e , l o n g i t u d e " ,h e a d i n g =" 151 .78 " , p i t c h =" �0.76 " ) , d a t a s o u r c e t y p e =" d a t a b a s e " ,d a t a s o u r c e f o r m a t =" b i n a r y " , u r l = ’ h t t p s : / / maps . g o o g l e a p i s . com / maps / a p i /s t r e e t v i e w ’ , q u e r y p a r a m e t e r s = d i c t ( s i z e = " 640 x480 " , l o c a t i o n = "4 6 . 4 1 4 3 8 2 , 1 0 . 0 1 3 9 8 8 " , h e a d i n g = " 151 .78 " , p i t c h = " �0.76 " ) , e x t e n s i o n = ’j p g ’ , f e t c h t y p e ="HTTPS" )

16 cammod= P h y s i c a l C o n t e x t M o d a l i t y ( name= ’ camera ’ , s a m p l i n g r a t e = 0 . 0 1 , f e e d r a t e= 0 . 0 1 , d a t a s o u r c e =dbcam , t r a c e v e c t o r = [ ’ image ’ , ’ o r i g i n a l ’ , ’ encoded ’ , ’camera_ type ’ ] , t r a c e p r o c e s s i n g =" S t r ee tV iewModi fy " )

1718 # C r e a t e C o n t e x t Model19 sim . addModa l i t y ( [ cammod , locmod , nwmod ] )20 sim . c r e a t e C o n t e x t D e p e n d e n c y G r a p h ( locmod . name , netmod . name , cammod . name e0 =(

locmod . name , netmod . name ) , e1 =( locmod . name , camod . name ) )2122 #Add e m u l a t o r23 e m u l a t o r = Emula to r ( ’ Android ’ ,{ ’ add r ’ : ’ 1 2 7 . 0 . 0 . 1 : 5 5 5 4 ’ } )24 sim . addEmula to r ( e m u l a t o r )2526 # S t a r t s i m u l a t i o n27 sim . runTime ( 6 0 0 )28 e n g i n e . s t a r t ( )

Listing 2: CamTour