Home | History | Annotate | Download | only in device
      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.device;
     17 
     18 import com.android.ddmlib.Log;
     19 import com.android.tradefed.config.GlobalConfiguration;
     20 import com.android.tradefed.testtype.DeviceTestCase;
     21 
     22 /**
     23  * Functional tests for {@link DeviceManager}
     24  */
     25 public class DeviceManagerFuncTest extends DeviceTestCase {
     26 
     27     private static final String LOG_TAG = "DeviceManagerFuncTest";
     28     private ITestDevice mUsbDevice;
     29 
     30     @Override
     31     protected void setUp() throws Exception {
     32         super.setUp();
     33         mUsbDevice = getDevice();
     34     }
     35 
     36     /**
     37      * Test reconnecting a device to adb over tcp, and back to usb again.
     38      * <p/>
     39      * Note: device under test must have a valid IP, that can be connected to from host machine
     40      * @throws DeviceNotAvailableException
     41      */
     42     public void testReconnectDeviceToTcp_backUsb() throws DeviceNotAvailableException {
     43         Log.i(LOG_TAG, "Starting testReconnectDeviceToTcp_backUsb");
     44 
     45 
     46         IDeviceManager deviceManager = getDeviceManager();
     47         ITestDevice tcpDevice = deviceManager.reconnectDeviceToTcp(mUsbDevice);
     48         assertNotNull(tcpDevice);
     49         try{
     50             assertTrue(tcpDevice.isAdbTcp());
     51 
     52 
     53 
     54             assertTrue(deviceManager.disconnectFromTcpDevice(tcpDevice));
     55             // ensure device is back on usb
     56             mUsbDevice.waitForDeviceAvailable(30 * 1000);
     57         } finally {
     58             deviceManager.disconnectFromTcpDevice(tcpDevice);
     59         }
     60 
     61     }
     62 
     63     private IDeviceManager getDeviceManager() {
     64         return GlobalConfiguration.getDeviceManagerInstance();
     65     }
     66 
     67     /**
     68      * Test reconnecting a device to adb over tcp, and rebooting.
     69      * <p/>
     70      * Done to verify the usb variant device will be detected again if it reboots.
     71      * <p/>
     72      * Note: device under test must have a valid IP, that can be connected to from host machine
     73      *
     74      * @throws DeviceNotAvailableException
     75      */
     76     public void testReconnectDeviceToTcp_reboot() throws DeviceNotAvailableException {
     77         Log.i(LOG_TAG, "Starting testReconnectDeviceToTcp_reboot");
     78 
     79 
     80         IDeviceManager deviceManager = getDeviceManager();
     81         ITestDevice tcpDevice = deviceManager.reconnectDeviceToTcp(mUsbDevice);
     82         assertNotNull(tcpDevice);
     83         try {
     84             try {
     85                 tcpDevice.reboot();
     86                 fail("DeviceNotAvailableException not thrown");
     87             } catch (DeviceNotAvailableException e) {
     88                 // expected
     89             }
     90             // ensure device is back on usb
     91             mUsbDevice.waitForDeviceAvailable();
     92         } finally {
     93             deviceManager.disconnectFromTcpDevice(tcpDevice);
     94         }
     95 
     96     }
     97 }
     98