Beftigre Documentation

Current version 1.0. Release date: 2016-12-03

Band Usage Guide

1. Installation

Beftigre's BAND API, is bundled as BeftigreAND.jar, and have been tested on android studio, as it is the recommended/standardised android IDE. To install BeftigreAND.jar:

  • Copy the jar file to the project's libs folder. The final library path would be
    [ProjectName]/app/libs/BeftigreAND.jar

  • Add the file as a dependency (alongside other libraries) in the application's build.gradle file located at [ProjectName]/app/build.gradle as shown in the snippet below.
    ...
    dependencies {
        compile 'com.android.support:support-v4:18.0.0'
        androidTestCompile 'com.jayway.android.robotium:robotium-solo:5.4.1'
        compile files('libs/BeftigreAND.jar')
    }
    
Furthermore, Band API depends on two sets of configuration settings within the application's manifest file located at [ProjectName]/app/src/main/AndroidManifest.xml. The configuration settings are:

  • Set the required Manifest permissions as shown in the snippet below.
    • The power monitoring feature requires location, network, Wi-Fi, internet, phone and boot_ permissions.
    • The data logging feature requires _external storage_ permission.
    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="sample.package">
        <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
        <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
        <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
        <uses-permission android:name="android.permission.INTERNET" />
        <uses-permission android:name="android.permission.READ_PHONE_STATE" />
        <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
        <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
        ...
    

  • Set the required Manifest services as shown in the snippet below.
    Within the application tag UMLoggerService android service is required for power monitoring component. Also the BaseService android service is required for computing the mobile % CPU and memory availability (i.e. actual Given clause), when getBaseStatus() API method is called.
        ...
        <application android:icon="@drawable/icon" android:label="@string/name">
            <service android:name="com.beftigre.band.mon.UMLoggerService" />
            <service android:name="com.beftigre.band.mon.BaseService" />
        </application>
    </manifest>
    

2. Initialise API variables

The first step to using Band in the Test module is initialisation of API variables. (See section 5, for using Band within Application module). The initialisation step is achieved in two folds, as shown below:

  • Instantiating the Band and Marker objects:
    import com.beftigre.band.Band;
    import com.beftigre.band.Marker;
    import com.beftigre.band.annotations.*;
    
    public class SampleTest extends...{
        private Band band;
        private Marker m = new Marker("Label");
    
        public SampleTest(){
            super(SampleActivity.class);
        }
        ...
    

  • Starting power monitoring and registering markers in setUp method:
        ...
        @Override
        protected void setUp() throws Exception {
            super.setUp();
            band = new Band(getActivity(), this);
            band.startPowerMonitoring();
            band.registerMarkers(m);
        }
        ...
    
    Exceptions:
    • DuplicateLabelException is thrown if two or more markers were registered with the same label. Labels are used to create unique identifier for markers, no two markers can have the same label.

3. Write the test logic: Evaluation vs. Comparison

This step involves using annotations on the test method, and using the start and finish markers to specifies the code segments being tested.
Evaluation and Comparison are treated as two different concepts in the Beftigre Framework. Using Band API, both concepts can be achieved depending on the way annotations are specified within the test project

  • Using Band for Evaluation: Evaluation in Beftigre is the process of evaluating an MCA or offloading scheme by itself (otherwise called self-evaluation).
    • An evaluation can be done with different environmental conditions.
    • Evaluation is achieved by setting the attributes of the @Given annotation to 0, and ignoring the @When and @Then annotations.
        ...
        @Given(mobileCPU=0, mobileMemory=0)
        public void testMethod() throws Exception {
            m.start();
            /*do test*/
            m.finish();
        }
        ...
    

  • Using Band for Comparison: Comparison in Beftigre is the process of comparing two different offloading schemes against each other, based on common environmental conditions.
    • The environmental condition used for the expected annotations has to be similar to that of the actual test process.
    • A comparison is accomplished by setting the values of all annotations (@Given, @When and @Then) to the result values of an offloading scheme, being compared against the scheme under test. Where the scheme under test is the offloading scheme currently being evaluated for comparison.
        ...
        @Given(mobileCPU=97, mobileMemory=26)
        @When (bandwidth=4387, latency=31, cloudCPU=42, cloudMemory=20)
        @Then (mElapsedTime=21832, mUsedEnergy=721.3, cUsedCPU=58, cUsedMemory=30)
        public void testMethod() throws Exception {
            m.start();
            /*do test*/
            m.finish();
        }
        ...
    
    Exceptions:
    • DuplicateStartMarkerException is thrown from the Marker class when start() method is called more than once on a registered marker.
    • DuplicateFinishMarkerException is thrown from the Marker class when finish() method is called more than once on a registered marker.
    • UnevenMarkerException is caused if a marker set was incomplete. For example when a marker is started; i.e. start() method called, and not finished. All registered markers must have a complete set. A marker is said to have a complete set if it calls a start() and a finish() method.

4. Finalise the test

This step involves saving the markers, stopping the power monitor and collecting idle resource usage data.

  •     ...
        @Override
        protected void tearDown() throws Exception {
            band.saveMarkers();
            band.stopPowerMonitoring();
            band.getBaseStatus();
            super.tearDown();
        }
    }
    

5. Using Band In Application Code

The snippet below illustrates how to use Band in the application module. (See description above for usage in Test module).

  • import com.beftigre.band.Band;
    import com.beftigre.band.Marker;
    import com.beftigre.band.exceptions.*;
    
    public class SampleActivity extends...{
        private Band band = new Band();
        private Marker m1 = new Marker("Label1");
        private Marker mN = new Marker("LabelN");
    
        @Override
        protected void onCreate(Bundle...)() {
            super.onCreate(savedInstanceState);
            //start power monitor from test class
            try{
                band.registerMarkers(m1, mN);
            }catch(DuplicateLabelException d){...}
            /*app code*/
        }
    
        public void appMethod1() throws Exception {
            m1.start();
            /*app code*/
            m1.finish();
        }
    
        public void appMethodN() throws Exception {
            mN.start();
            /*app code*/
            mN.finish();
        }
    
        //save markers within test class
    }