示例#1
0
def just_return_f_params():

    print "[Just Returning the Values]: "
    just_connect_android()
    f_device = MonkeyRunner.waitForConnection()
    adb = AndroidDebugBridge.getBridge()
    f_iDevice = adb.getDevices()[0]
    print "[Connected to] : ", f_iDevice

    f_rec = Receiver()
    return (f_device, f_iDevice, f_rec)
示例#2
0
def run_tests(adb_location, serial_number, package_name, test_runner_name,
              enable_coverage):
    u'''
    Run tests and output result as XML.

    Parameters:
        adb_location : Location of adb.
        serial_number : Serial number of device or emulator. None is OK.
        test_runner_name : Name of test runner. None is OK.
        enable_coverage : Whether coverage measuring is enabled.
    Return:
        ElementTree of result. None if tests did not run.
    '''
    AndroidDebugBridge.init(False)

    connecting_event = DeviceConnectingEvent(serial_number)
    AndroidDebugBridge.addDeviceChangeListener(connecting_event)

    debug_bridge = AndroidDebugBridge.createBridge(adb_location, False)
    connecting_event.wait()

    if not debug_bridge.isConnected():
        print >> sys.stderr, u'bridge is not connected.'
        return None

    device = get_device(serial_number, debug_bridge)

    if not device:
        print >> sys.stderr, u'There is not device.'
        return None

    test_runner = RemoteAndroidTestRunner(package_name, test_runner_name,
                                          device)
    test_runner.setCoverage(enable_coverage)

    formatter = TestResultXmlFormatter(device.getProperties())
    test_runner.run(formatter)

    return formatter.get_result()
def run_tests(adb_location, serial_number,
        package_name, test_runner_name, enable_coverage):
    u'''
    Run tests and output result as XML.

    Parameters:
        adb_location : Location of adb.
        serial_number : Serial number of device or emulator. None is OK.
        test_runner_name : Name of test runner. None is OK.
        enable_coverage : Whether coverage measuring is enabled.
    Return:
        ElementTree of result. None if tests did not run.
    '''
    AndroidDebugBridge.init(False)

    connecting_event = DeviceConnectingEvent(serial_number)
    AndroidDebugBridge.addDeviceChangeListener(connecting_event)

    debug_bridge = AndroidDebugBridge.createBridge(adb_location, False)
    connecting_event.wait()

    if not debug_bridge.isConnected():
        print >>sys.stderr, u'bridge is not connected.'
        return None

    device = get_device(serial_number, debug_bridge)

    if not device:
        print >>sys.stderr, u'There is not device.'
        return None

    test_runner = RemoteAndroidTestRunner(package_name, test_runner_name, device)
    test_runner.setCoverage(enable_coverage)

    formatter = TestResultXmlFormatter(device.getProperties())
    test_runner.run(formatter)

    return formatter.get_result()
def run_tests(adb_location, serial_number,
        package_name, test_runner_name, enable_coverage, coverage_file):
    u'''
    Run tests and output result as XML.

    Parameters:
        adb_location : Location of adb.
        serial_number : Serial number of device or emulator. None is OK.
        package_name : Package name of test application package.
        test_runner_name : Name of test runner. None is OK.
        enable_coverage : Whether coverage measuring is enabled.
        coverage_file : Path of file that will be saved coverage result.
            None is OK.
    Return:
        ElementTree of result. None if tests did not run.
    '''
    AndroidDebugBridge.init(False)

    try:
        # Connect to Android debug bridge.
        connecting_event = DeviceConnectingEvent(serial_number)
        AndroidDebugBridge.addDeviceChangeListener(connecting_event)
        debug_bridge = AndroidDebugBridge.createBridge(adb_location, False)

        # Wait until device is connected.
        connecting_event.wait()
        if not debug_bridge.isConnected():
            print >>sys.stderr, u'bridge is not connected.'
            return None

        # Get the device.
        device = get_device(serial_number, debug_bridge)
        if not device:
            print >>sys.stderr, u'There is not device.'
            return None

        # Run the test runner on the device.
        test_runner = RemoteAndroidTestRunner(
            package_name, test_runner_name, device)
        test_runner.setCoverage(enable_coverage)
        if enable_coverage and coverage_file:
            test_runner.addInstrumentationArg('coverageFile', coverage_file)
        formatter = TestResultXmlFormatter(device.getProperties())
        test_runner.run([formatter])

        return formatter.get_result()
    finally:
        # Disconnect from Android debug bridge.
        AndroidDebugBridge.terminate()
def SetupAndroid():
    RootADB()
    
    # |----------------------------------------------------------------
    # | Connects to the current device returning a MonkeyDevice object
    # | used to simulate screen touches and other events. It may also
    # | be used to issue shell commands using device.shell(cmd).
    # | 
    # |----------------------------------------------------------------
    f_device = MonkeyRunner.waitForConnection()

    # Gets the debug bridge for the device currently connected
    adb = AndroidDebugBridge.getBridge()

    # |----------------------------------------------------------------
    # | Gets an IDevice object used to execute adb shell commands
    # | that may throw a ShellUnresponsiveException.
    # |----------------------------------------------------------------
    f_iDevice = adb.getDevices()[0]
    print "Connected to: ", f_iDevice   

    # Receives output, if any, from commands executed in shell
    f_rec = Receiver()

    # |----------------------------------------------------------------
    # | Preparing Android device for next profiling run
    # |    => Disable EIP randomization
    # |    => Disable Power management
    # |    => Configure to 1P
    # |    => Set constant CPU frequency
    # |    => Install Driver
    # | Comment: Android setup script located in android device
    # |----------------------------------------------------------------
    f_iDevice.executeShellCommand(cd_android_emonx_dir + android_setup_script, f_rec, 0)
    MonkeyRunner.sleep(5.0)

    return (f_device, f_iDevice, f_rec)
示例#6
0
def SetupAndroid():

    print "*****[SETUP ANDROID]*****"

    print "[Kill adb Server before rebooting]"
    subprocess.call(["adb", "kill-server"])

    p = subprocess.Popen("adb devices", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    output = p.communicate()

    try:

        if (
            (output[0] == "List of devices attached \n\n")
            or (
                output[0]
                == "* daemon not running. starting it now on port 5037 *\n* daemon started successfully *\nList of devices attached \n\n"
            )
            or (output[0] == "error: protocol fault (no status)\n")
        ):
            print "[Device wasn't found!]"
            print "[Run serial script]"
            subprocess.call("python" + " /home/intel/workspace/IcyRocks/connect_android.py", shell=True)
        else:
            pass
    except:
        print "[Device was found!]\n" + output[0]

    p = subprocess.Popen("adb devices", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    output = p.communicate()

    try:

        if (
            (output[0] == "List of devices attached \n\n")
            or (
                output[0]
                == "* daemon not running. starting it now on port 5037 *\n* daemon started successfully *\nList of devices attached \n\n"
            )
            or (output[0] == "error: protocol fault (no status)\n")
        ):

            print "[Device wasn't found!]"
            print "[[REBOOT AGAIN]]"

            RebootAndroid()

            print "[Run serial script]"
            subprocess.call("python" + " /home/intel/workspace/IcyRocks/connect_android.py", shell=True)
        else:
            pass
    except:
        print "[Device was found!]\n" + output[0]

    RootADB()

    # |----------------------------------------------------------------
    # | Connects to the current device returning a MonkeyDevice object
    # | used to simulate screen touches and other events. It may also
    # | be used to issue shell commands using device.shell(cmd).
    # |
    # |----------------------------------------------------------------
    f_device = MonkeyRunner.waitForConnection()

    # Gets the debug bridge for the device currently connected
    adb = AndroidDebugBridge.getBridge()

    # |----------------------------------------------------------------
    # | Gets an IDevice object used to execute adb shell commands
    # | that may throw a ShellUnresponsiveException.
    # |----------------------------------------------------------------
    f_iDevice = adb.getDevices()[0]
    print "[Connected to] : ", f_iDevice

    # Receives output, if any, from commands executed in shell
    f_rec = Receiver()

    # |----------------------------------------------------------------
    # | Preparing Android device for next profiling run
    # |    => Disable EIP randomization
    # |    => Disable Power management
    # |    => Configure to 1P
    # |    => Set constant CPU frequency
    # |    => Install Driver
    # | Comment: Android setup script located in android device script dir
    # |----------------------------------------------------------------

    # f_iDevice.executeShellCommand(cd_android_scripts_dir + android_setup_script, f_rec, 0)
    # f_iDevice.executeShellCommand(cd_android_scripts_dir + android_setup_script, f_rec, 0)

    f_iDevice.executeShellCommand(android_setup_script, f_rec, 0)
    MonkeyRunner.sleep(5.0)

    print "[Clear logcat]"
    # Clear logcat

    f_iDevice.executeShellCommand("logcat -c", f_rec, 0)
    MonkeyRunner.sleep(15.0)

    # ClearCache(f_device)
    CheckCPUIdle()

    return (f_device, f_iDevice, f_rec)