Home | History | Annotate | Download | only in targetprep
      1 /*
      2  * Copyright (C) 2011 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 package com.android.tradefed.targetprep;
     17 
     18 import com.android.tradefed.build.IBuildInfo;
     19 import com.android.tradefed.config.Option;
     20 import com.android.tradefed.device.ITestDevice;
     21 import com.android.tradefed.log.LogUtil.CLog;
     22 import com.android.tradefed.result.ITestInvocationListener;
     23 import com.android.tradefed.testtype.IBuildReceiver;
     24 import com.android.tradefed.testtype.IDeviceTest;
     25 import com.android.tradefed.testtype.IRemoteTest;
     26 
     27 import java.util.HashMap;
     28 import java.util.Map;
     29 
     30 /**
     31 * Long running functional tests for {@link SdkAvdPreparer} that verifies an emulator launch
     32 * is successful many times in sequence
     33 * <p/>
     34 * Requires a SDK Build
     35 */
     36 public class SdkAvdPreparerStressTest implements IBuildReceiver, IDeviceTest, IRemoteTest {
     37 
     38     @Option(name="iterations", description="Number of emulator launch iterations to perform")
     39     private int mIterations = 10;
     40 
     41     @Option(name="launch-attempts", description=
     42         "Number of attempts to launch the emulator for each iteration")
     43     private int mLaunchAttempts = 3;
     44 
     45     private ITestDevice mDevice;
     46 
     47     private IBuildInfo mBuildInfo;
     48 
     49     @Override
     50     public void run(ITestInvocationListener listener) {
     51         SdkAvdPreparer preparer = new SdkAvdPreparer();
     52         int i = 0;
     53         preparer.setLaunchAttempts(mLaunchAttempts);
     54         listener.testRunStarted("stress", 0);
     55         long startTime = System.currentTimeMillis();
     56         try {
     57             for (i = 0; i < mIterations; i++) {
     58                 preparer.setUp(mDevice, mBuildInfo);
     59             }
     60         } catch (Exception e) {
     61             CLog.e(e);
     62         }
     63          finally {
     64             Map<String, String> metrics = new HashMap<String, String>(1);
     65             metrics.put("iterations", Integer.toString(i));
     66             listener.testRunEnded(System.currentTimeMillis()-startTime, metrics);
     67         }
     68     }
     69 
     70     /**
     71      * {@inheritDoc}
     72      */
     73     @Override
     74     public void setDevice(ITestDevice device) {
     75        mDevice = device;
     76     }
     77 
     78     /**
     79      * {@inheritDoc}
     80      */
     81     @Override
     82     public ITestDevice getDevice() {
     83         return mDevice;
     84     }
     85 
     86     /**
     87      * {@inheritDoc}
     88      */
     89     @Override
     90     public void setBuild(IBuildInfo buildInfo) {
     91        mBuildInfo = buildInfo;
     92     }
     93 }
     94