Exemple #1
0
def get_mode_serial():
    """Return the serial dependent on the mode"""

    if get_prop('Client', 'mode') == MODE_USB:
        return get_prop("Info", "serial")
    else:
        return ("%s:%s" %
                (get_prop('Client', 'ip-addr'), get_prop('Client', 'port')))
Exemple #2
0
def test_get_empty_config():
    """Attempts to get a property without a valid config"""

    testutils.deploy_config_raw("")

    with pytest.raises(prop.PropertyError):
        prop.get_prop('info', 'sdk')

    testutils.undeploy()

    return 0
Exemple #3
0
def test_get_property_no_option():
    """Attempt to get property that doesnt exist"""

    contents = ("[Info]\n" "vmtype = arm64")

    testutils.deploy_config_raw(contents)

    with pytest.raises(prop.PropertyError):
        prop.get_prop('info', 'sdk')

    testutils.undeploy()

    return 0
Exemple #4
0
def test_set_property_casing():
    """Set a prop and try to retrieve with casing"""

    sdk = '1'
    testutils.deploy_config_raw("")

    prop.set_prop('INFO', 'sdk', sdk)
    assert prop.get_prop('info', 'sdk') == sdk
    assert prop.get_prop('Info', 'sdk') == sdk
    assert prop.get_prop('INFO', 'sdk') == sdk

    testutils.undeploy()

    return 0
Exemple #5
0
def test_get_property_casing():
    """Get a prop with alternating casing"""

    sdk = '23'
    contents = ("[Info]\n" "sdk = %s" % sdk)

    testutils.deploy_config_raw(contents)

    assert prop.get_prop('info', 'sdk') == sdk
    assert prop.get_prop('Info', 'sdk') == sdk
    assert prop.get_prop('INFO', 'sdk') == sdk

    testutils.undeploy()

    return 0
Exemple #6
0
    def __init__(self, no_serial=False):
        """Object initialization"""

        self.no_serial = no_serial

        if not self.no_serial:
            self.serial = get_prop("Info", "serial")
Exemple #7
0
    def execute(self, args):

        """Main module executor"""

        found = False
        serial = prop.get_prop('Info', 'serial')

        devices = self.adb.get_devices()

        for device in devices:
            if device['serial'] == serial:
                found = True

            break

        print "Status:",

        if found:
            print "Connected"
        else:
            print "Not Connected"

        print "Serial Number: %s" % serial

        return 0
def isAOSPDataInstalled():

    sdk = prop.get_prop("Info", "sdk")

    if isdir(DTF_PACKAGES_DIR + '/' + AOSP_PACKAGE_PREFIX + sdk):
        return True
    else:
        return False
Exemple #9
0
def isAOSPDataInstalled():

    sdk = prop.get_prop("Info", "sdk")

    if isdir(DTF_PACKAGES_DIR + '/' + AOSP_PACKAGE_PREFIX + sdk):
        return True
    else:
        return False
Exemple #10
0
    def __init__(self, no_serial=False):

        """Object initialization"""

        self.no_serial = no_serial

        if not self.no_serial:
            self.serial = get_prop("Info", "serial")
Exemple #11
0
def isAOSPDataInstalled():
    """Determine if AOSP data is installed"""

    sdk = prop.get_prop("Info", "sdk")

    if os.path.isdir(DTF_PACKAGES_DIR + '/' + AOSP_PACKAGE_PREFIX + sdk):
        return True
    else:
        return False
Exemple #12
0
def isAOSPDataInstalled():

    """Determine if AOSP data is installed"""

    sdk = prop.get_prop("Info", "sdk")

    if os.path.isdir(DTF_PACKAGES_DIR + '/' + AOSP_PACKAGE_PREFIX + sdk):
        return True
    else:
        return False
Exemple #13
0
def test_set_new_section_property():
    """Set a property that has no section (yet)"""

    value = '1'
    testutils.deploy_config_raw("")

    prop.set_prop('info', 'sdk', value)
    assert prop.get_prop('info', 'sdk') == value

    testutils.undeploy()

    return 0
Exemple #14
0
def test_set_new_property():
    """Attempt to set a new property (existing section)"""

    value = '1'
    contents = ("[info]\n" "real = not_real")

    testutils.deploy_config_raw(contents)

    prop.set_prop('info', 'sdk', value)
    assert prop.get_prop('info', 'sdk') == value

    testutils.undeploy()
Exemple #15
0
def test_get_property():
    """Attempts to get a valid property"""

    sdk = '23'
    contents = ("[Info]\n" "sdk = %s" % sdk)

    testutils.deploy_config_raw(contents)

    assert prop.get_prop('info', 'sdk') == sdk

    testutils.undeploy()

    return 0
Exemple #16
0
    def get_diff_dir(cls):
        """Determine which diffing db to use"""

        # First check for a property override.
        if prop.test_prop('Local', 'diff-data-dir'):
            diff_dir = prop.get_prop('Local', 'diff-data-dir')

            if not os.path.isdir(diff_dir):
                raise DtfException("Unable to find diffing directory!")
            else:
                return diff_dir

        # Not set
        else:
            sdk = prop.get_prop("Info", "sdk")
            if pm.is_package_installed("aosp-data-%s" % sdk):

                diff_dir = ("%s/aosp-data-%s" % (DTF_PACKAGES_DIR, sdk))

                return diff_dir
            else:
                raise DtfException("AOSP data not installed for this API!")
Exemple #17
0
def test_set_existing_property():
    """Set a property that already exists"""

    value = 'new'

    contents = ("[Info]\n" "sdk = old")

    testutils.deploy_config_raw(contents)

    prop.set_prop('info', 'sdk', value)
    assert prop.get_prop('info', 'sdk') == value

    testutils.undeploy()

    return 0
Exemple #18
0
    def do_create(self, args):
        """Create the archive"""

        zip_name = ""

        if len(args) == 0:
            zip_name = "%s.zip" % prop.get_prop('Info', 'version-string')

        else:
            zip_name = args.pop()

        log.i(self.name, "Archiving to '%s'..." % zip_name)

        rtn = self.make_zip(zip_name)

        if rtn != 0:
            log.e(self.name, "Unable to archive project!")

        return rtn
Exemple #19
0
    def do_get(self, args):
        """Get a property"""

        rtn = 0
        value = ""

        if len(args) != 2:
            log.e(self.name, "A section and property must be specified.")
            rtn = self.usage()

        else:
            section = args[0]
            prop_name = args[1]

            try:
                value = get_prop(section, prop_name)

            except PropertyError:
                rtn = -1

            print value

        return rtn
Exemple #20
0
def __launch_bash_module(module_path, args):
    """Launch a bash module by path"""

    cmd = list()

    # Build the command string
    cmd = [module_path] + args

    # Update the environment
    new_env = os.environ

    # These are used for sourcing
    new_env['DTF_LOG'] = DTF_INCLUDED_DIR + "/dtf_log.sh"
    new_env['DTF_CORE'] = DTF_INCLUDED_DIR + "/dtf_core.sh"

    # We need to be in TOP to get the serial.
    os.chdir(prop.TOP)

    # We want the serial to be already set
    serial = prop.get_prop('Info', 'serial')
    new_env['ANDROID_SERIAL'] = serial

    try:
        popen = subprocess.Popen(cmd, stdout=subprocess.PIPE, env=new_env)
    except OSError:
        log.e(
            TAG, "Unable to execute '%s'. Are the permission flags correct?" %
            module_path)
        return -5

    lines_iterator = iter(popen.stdout.readline, b"")

    for line in lines_iterator:
        sys.stdout.write(line)

    return popen.returncode
Exemple #21
0
def __do_python_prelaunch_checks(mod_inst):
    """Do pre-launch checks"""

    # Make sure requirements are met
    for requirement in mod_inst.requires:

        if utils.which(requirement) is None:
            log.e(TAG, "Unable to execute! Unmet dependency: %s" % requirement)
            return -1

    # Check for a minimum SDK
    try:
        sdk = int(prop.get_prop('Info', 'sdk'))
    except prop.PropertyError:
        log.e(TAG, "Unable to get SDK, is this project corrupt?")
        return -1

    min_sdk = int(mod_inst.min_sdk)

    if min_sdk != 0 and sdk < min_sdk:
        log.e(TAG, "This module requires SDK %d or higher!" % min_sdk)
        return -1

    return 0
Exemple #22
0
def __launch_bash_module(module_path, args):

    """Launch a bash module by path"""

    cmd = list()

    # Build the command string
    cmd = [module_path] + args

    # Update the environment
    new_env = os.environ

    # These are used for sourcing
    new_env['DTF_LOG'] = DTF_INCLUDED_DIR + "/dtf_log.sh"
    new_env['DTF_CORE'] = DTF_INCLUDED_DIR + "/dtf_core.sh"

    # We need to be in TOP to get the serial.
    os.chdir(prop.TOP)

    # We want the serial to be already set
    serial = prop.get_prop('Info', 'serial')
    new_env['ANDROID_SERIAL'] = serial

    try:
        popen = subprocess.Popen(cmd, stdout=subprocess.PIPE, env=new_env)
    except OSError:
        log.e(TAG, "Unable to execute '%s'. Are the permission flags correct?"
            % module_path)
        return -5

    lines_iterator = iter(popen.stdout.readline, b"")

    for line in lines_iterator:
        sys.stdout.write(line)

    return popen.returncode
Exemple #23
0
    def execute(self, args):
        """Main module executor"""

        found = False
        serial = prop.get_prop('Info', 'serial')

        devices = self.adb.get_devices()

        for device in devices:
            if device['serial'] == serial:
                found = True

            break

        print "Status:",

        if found:
            print "Connected"
        else:
            print "Not Connected"

        print "Serial Number: %s" % serial

        return 0
Exemple #24
0
    def do_get(self, args):

        """Get a property"""

        rtn = 0
        value = ""

        if len(args) != 2:
            log.e(self.name, "A section and property must be specified.")
            rtn = self.usage()

        else:
            section = args[0]
            prop_name = args[1]

            try:
                value = get_prop(section, prop_name)

            except PropertyError:
                rtn = -1

            print value

        return rtn
Exemple #25
0
    def busybox(self, cmd):

        """Execute a busybox command on device"""

        busybox = get_prop("Info", "busybox")
        self.shell_command("run-as %s %s %s" % (DTF_CLIENT, busybox, cmd))
Exemple #26
0
    def busybox(self, cmd):
        """Execute a busybox command on device"""

        busybox = get_prop("Info", "busybox")
        self.shell_command("run-as %s %s %s" % (DTF_CLIENT, busybox, cmd))