Code Monkey home page Code Monkey logo

async-droid's Introduction

Android App Schedule Enumerator

A tool for concurrency testing of Android apps.

Requirements

  • Android SDK: http://developer.android.com/sdk/index.html

    • Android SDK Tools
    • Android SDK Platform-tools
    • Android SDK Platform (we use Android 4.4.2 / API 19)
    • Android system image for the emulator
    • (Optional) Eclipse + ADT plugin
  • (Optional) Alternative Android Virtual Devices:

  • Java (SE 7)

  • Apache Ant (1.9.4)

  • Python (2.7.5)

Usage

Ensure the ANDROID_HOME environment variable points to a valid Android platform SDK containing an Android platform library, e.g., $ANDROID_HOME/platforms/android-19/android.jar. Also, be sure you have created and started an Android Virtual Device (AVD).

Instrument your application .apk file for testing. For instance, try the example app in example/HelloWorldApk.apk:

ant -Dapk=example/HelloWorldApp.apk

(Note that the original .apk file will remain unmodified.)

Then, test the instrumented application by:

Recording a set of user events (this overwrites the previously recorded events):

python bin/aase.py --record build/HelloWorldApp.apk

Then replaying them for schedules with/without a delay bound.

python bin/aase.py --replay --delays 1 build/HelloWorldApp.apk

Running the sample application

To demonstrate the detection of a sample concurrency bug, we provide a previous version of vlilleChecker Android App (built from commit 86b22a7).

Instrument the application .apk file for testing:

ant -Dapk=example/sample_vlillechecker.apk -Dandroid.api.version=19

You can replay the user events that trigger the bug (with particular thread interleavings) by running:

python bin/aase.py --replay --delays 1 --events events.trc build/sample_vlillechecker.apk

(Optional) You can also record your own a set of user events with the command below and then replay them:

python bin/aase.py --record build/sample_vlillechecker.apk     

async-droid's People

Contributors

burcuku avatar michael-emmi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Forkers

burcuku

async-droid's Issues

Scheduled onPostExecute is not overwriten, hence does not notify

We schedule the main thread iff:

  • It has an input or
  • It has an AsyncTask result/progress
    in its main queue.

When an AsyncTask onPostExecute is not overwritten, it is not instrumented. Hence, though the main thread is scheduled and the scheduler waits for notification, main thread does not notify. In that case, the test is deadlocked.

As a temporary solution, we schedule main thread only if it is waiting.
(This causes not to schedule the main thread although it has an event handler in its queue, to be scheduled when it is its turn. How can we handle that situation?)

ActionBar events

To check if the action bar is created or not, we used to check Activity.getActionBar.
However, that causes the action bar to be created if it is null (probably before setting up the necessary structures by UI thread).
Now, we read mActionBar of android.app.Activity or android.support.v7.app.ActionBarActivityDelegate to check whether the action bar is initialized or not.

Input Injection

Enable InputRepeater to be scheduled only if the next event is available (its view is created, etc..)
Currently it gets scheduled but does not inject the event if it is not available.

ReflectionUtils for different libraries

android.app.Fragment does not exist in earlier versions. Support libraries have the class e.g. (android.support.v4.app.Fragment) that is not included in the compilation of our Ase library.
Get FragmentManager, Fragments, etc seperately using the runtime class information.

Keep the fragment in which view is inflated in

Problem:

  • Two fragments view list items that use the same layout file for an item, hence same id for the views in the item view
  • Replayed events: (1) move to fragment 0 from 1 (2) click on an item's checkbox
  • Event might be replayed in fragment 0. Because, the fragment lifecycle events are asynchronous and an event may be repeated before inflating the selected fragment's view. The view exists on the current view hierarchy (inflated the same item view layout), and event is replayed.

Solution:

  • Keep the fragment in which the view is inflated and check whether that fragment is visible before replaying the input

How:

  • The fragments may not have unique ids, may not have tags. We use the class names as identifiers.
  • We already instrument a view (with a recording event handler) in a fragment's layout in onCreateView of a fragment
  • Record the name of the fragment inside the recorded event
  • Before replaying an event:
    • Get all currently visible fragments and check if the event view's fragment matches with any of them

Traverse each view in ListView (e.g. to instrument checkbox)

Currently, we traverse and instrument views in activity and fragment layouts, i.e. when an activity is created or a fragment view is created.
In ListView, views are inflated dynamically. Hence, we could not traverse inside each view.
We should instrument "getView()" method and traverse the views inside the item view. So, we can instrument each of these children views (e.g. CheckBox in an item's view in ListView)

Tasks from previous test in AsyncTask

Before finishing a test, we check whether there is a thread which is okToSchedule.
An AsyncTask is okToSchedule if it is waiting for the Scheduler to schedule it.

Problem:
The AsyncTask thread has not executed when I check it for scheduling. I finish a test when none of the threads are okToSchedule.
After the new test starts, AsyncTask waits for the Scheduler and the task of a previous test gets scheduled in the second test.

Solution:
Read the private field sPoolWorkQueue of an AsyncTask class and set okToSchedule accordingly.
Note: The name of the field in sWorkQueue in Android version < 4.0.1

Full path to a view

We can keep the full path from root view to a particular view and check the existence of these views while repeating the inputs.

Most views do not have ids, for now, I keep Activity, Fragment, ListView ids and position in a listview.

onCancelled

Instrument and control onCancelled() of an AsyncTask.
(Runs on the UI thread after cancel(boolean) is invoked and doInBackground(Object[]) has finished.)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.