def parse_args(self, args=None, namespace=None):
        result = super(ArgumentParser, self).parse_args(args, namespace)

        adb_path = result.adb_path or "adb"

        # Try to run the specified adb command
        try:
            subprocess.check_output([adb_path, "version"],
                                    stderr=subprocess.STDOUT)
        except (OSError, subprocess.CalledProcessError):
            msg = "ERROR: Unable to run adb executable (tried '{}')."
            if not result.adb_path:
                msg += "\n       Try specifying its location with --adb."
            sys.exit(msg.format(adb_path))

        try:
            if result.device == "-a":
                result.device = adb.get_device(adb_path=adb_path)
            elif result.device == "-d":
                result.device = adb.get_usb_device(adb_path=adb_path)
            elif result.device == "-e":
                result.device = adb.get_emulator_device(adb_path=adb_path)
            else:
                result.device = adb.get_device(result.serial, adb_path=adb_path)
        except (adb.DeviceNotFoundError, adb.NoUniqueDeviceError, RuntimeError):
            # Don't error out if we can't find a device.
            result.device = None

        return result
Esempio n. 2
0
    def parse_args(self, args=None, namespace=None):
        result = super(ArgumentParser, self).parse_args(args, namespace)

        adb_path = result.adb_path or "adb"

        # Try to run the specified adb command
        try:
            subprocess.check_output([adb_path, "version"],
                                    stderr=subprocess.STDOUT)
        except (OSError, subprocess.CalledProcessError):
            msg = "ERROR: Unable to run adb executable (tried '{}')."
            if not result.adb_path:
                msg += "\n       Try specifying its location with --adb."
            sys.exit(msg.format(adb_path))

        try:
            if result.device == "-a":
                result.device = adb.get_device(adb_path=adb_path)
            elif result.device == "-d":
                result.device = adb.get_usb_device(adb_path=adb_path)
            elif result.device == "-e":
                result.device = adb.get_emulator_device(adb_path=adb_path)
            else:
                result.device = adb.get_device(result.serial, adb_path=adb_path)
        except (adb.DeviceNotFoundError, adb.NoUniqueDeviceError, RuntimeError):
            # Don't error out if we can't find a device.
            result.device = None

        return result
    def test_sync(self):
        """Sync a randomly generated directory of files to specified device."""
        base_dir = tempfile.mkdtemp()

        # Create mirror device directory hierarchy within base_dir.
        full_dir_path = base_dir + self.DEVICE_TEMP_DIR
        os.makedirs(full_dir_path)

        # Create 32 random files within the host mirror.
        temp_files = make_random_host_files(in_dir=full_dir_path, num_files=32)

        # Clean up any trash on the device.
        device = adb.get_device(product=base_dir)
        device.shell(['rm', '-rf', self.DEVICE_TEMP_DIR])

        device.sync('data')

        # Confirm that every file on the device mirrors that on the host.
        for temp_file in temp_files:
            device_full_path = posixpath.join(self.DEVICE_TEMP_DIR,
                                              temp_file.base_name)
            dev_md5, _ = device.shell(
                [get_md5_prog(self.device), device_full_path]).split()
            self.assertEqual(temp_file.checksum, dev_md5)

        self.device.shell(['rm', '-rf', self.DEVICE_TEMP_DIR])
        shutil.rmtree(base_dir + self.DEVICE_TEMP_DIR)
    def test_sync(self):
        """Sync a randomly generated directory of files to specified device."""
        base_dir = tempfile.mkdtemp()

        # Create mirror device directory hierarchy within base_dir.
        full_dir_path = base_dir + self.DEVICE_TEMP_DIR
        os.makedirs(full_dir_path)

        # Create 32 random files within the host mirror.
        temp_files = make_random_host_files(in_dir=full_dir_path, num_files=32)

        # Clean up any trash on the device.
        device = adb.get_device(product=base_dir)
        device.shell(['rm', '-rf', self.DEVICE_TEMP_DIR])

        device.sync('data')

        # Confirm that every file on the device mirrors that on the host.
        for temp_file in temp_files:
            device_full_path = posixpath.join(self.DEVICE_TEMP_DIR,
                                              temp_file.base_name)
            dev_md5, _ = device.shell(
                [get_md5_prog(self.device), device_full_path])[0].split()
            self.assertEqual(temp_file.checksum, dev_md5)

        self.device.shell(['rm', '-rf', self.DEVICE_TEMP_DIR])
        if base_dir is not None:
            shutil.rmtree(base_dir)
Esempio n. 5
0
def get_device_details(serial):
    import adb  # pylint: disable=import-error
    props = adb.get_device(serial).get_props()
    name = props['ro.product.name']
    version = int(props['ro.build.version.sdk'])
    supported_abis = get_device_abis(props)
    return Device(serial, name, version, supported_abis)
Esempio n. 6
0
def get_device_details(serial):
    import adb  # pylint: disable=import-error
    props = adb.get_device(serial).get_props()
    name = props['ro.product.name']
    version = int(props['ro.build.version.sdk'])
    supported_abis = get_device_abis(props)
    return Device(serial, name, version, supported_abis)
def main():
    args = parse_args()
    if args.verbose:
        logging.getLogger().setLevel(logging.INFO)

    device = adb.get_device(args.serial)

    if not args.output:
        device.wait()
        args.output = 'perf-%s-%s.tsv' % (
            device.get_prop('ro.build.flavor'),
            device.get_prop('ro.build.version.incremental'))
    check_dm_verity_settings(device)

    if args.apk_dir:
        install_apks(device, args.apk_dir)

    record_list = []
    event_tags = filter_event_tags(read_event_tags(args.tags), device)
    init_perf(device, args.output, record_list, event_tags)
    interval_adjuster = IntervalAdjuster(args.interval, device)
    event_tags_re = make_event_tags_re(event_tags)
    end_tag = event_tags[-1]
    for i in range(args.iterations):
        print 'Run #%d ' % i
        record = do_iteration(
            device, interval_adjuster, event_tags_re, end_tag)
        record_list.append(record)
Esempio n. 8
0
    def test_sync(self):
        """Sync a host directory to the data partition."""

        try:
            base_dir = tempfile.mkdtemp()

            # Create mirror device directory hierarchy within base_dir.
            full_dir_path = base_dir + self.DEVICE_TEMP_DIR
            os.makedirs(full_dir_path)

            # Create 32 random files within the host mirror.
            temp_files = make_random_host_files(
                in_dir=full_dir_path, num_files=32)

            # Clean up any stale files on the device.
            device = adb.get_device()  # pylint: disable=no-member
            device.shell(['rm', '-rf', self.DEVICE_TEMP_DIR])

            old_product_out = os.environ.get('ANDROID_PRODUCT_OUT')
            os.environ['ANDROID_PRODUCT_OUT'] = base_dir
            device.sync('data')
            if old_product_out is None:
                del os.environ['ANDROID_PRODUCT_OUT']
            else:
                os.environ['ANDROID_PRODUCT_OUT'] = old_product_out

            self.verify_sync(device, temp_files, self.DEVICE_TEMP_DIR)

            #self.device.shell(['rm', '-rf', self.DEVICE_TEMP_DIR])
        finally:
            if base_dir is not None:
                shutil.rmtree(base_dir)
Esempio n. 9
0
def main():
    device = adb.get_device()
    unlock(device)
    benchmark_sink(device)
    benchmark_source(device)
    benchmark_push(device)
    benchmark_pull(device)
Esempio n. 10
0
def start_jdb_only(args, pid):
    adb_path = args.device.adb_path
    serial = args.device.serial
    jdb_cmd = args.jdb_cmd
    verbose = bool(args.verbose)
    device = adb.get_device(serial, adb_path=adb_path)

    if verbose == "True":
        enable_verbose_logging()

    log("Starting jdb...")

    jdb_port = 65534
    device.forward("tcp:{}".format(jdb_port), "jdwp:{}".format(pid))
    jdb_cmd = [
        jdb_cmd, "-connect",
        "com.sun.jdi.SocketAttach:hostname=localhost,port={}".format(jdb_port)
    ]

    jdb = subprocess.Popen(jdb_cmd)
    while jdb.returncode is None:
        try:
            jdb.communicate()
        except KeyboardInterrupt:
            jdb.kill()
            exit(0)
def main():
    device = adb.get_device()
    unlock(device)
    benchmark_sink(device)
    benchmark_source(device)
    benchmark_push(device)
    benchmark_pull(device)
Esempio n. 12
0
def main():
    args = parse_args()
    if args.verbose:
        logging.getLogger().setLevel(logging.INFO)

    device = adb.get_device(args.serial)

    if not args.output:
        device.wait()
        args.output = 'perf-%s-%s.tsv' % (
            device.get_prop('ro.build.flavor'),
            device.get_prop('ro.build.version.incremental'))
    check_dm_verity_settings(device)

    if args.apk_dir:
        install_apks(device, args.apk_dir)

    record_list = []
    event_tags = filter_event_tags(read_event_tags(args.tags), device)
    end_tag = args.end_tag or event_tags[-1]
    if end_tag not in event_tags:
        sys.exit('%s is not a valid tag.' % end_tag)
    event_tags = event_tags[0:event_tags.index(end_tag) + 1]
    init_perf(device, args.output, record_list, event_tags)
    interval_adjuster = IntervalAdjuster(args.interval, device)
    event_tags_re = make_event_tags_re(event_tags)

    for i in range(args.iterations):
        print 'Run #%d ' % i
        record = do_iteration(device, interval_adjuster, event_tags_re,
                              end_tag)
        record_list.append(record)
Esempio n. 13
0
 def __init__(self):
     self.pid = 0
     self.dev = 0
     self.ino = 0
     self.file_name = ""
     self.off = 0
     self.files = {}  # k: ino, v: [] of file ofs
     self.device = adb.get_device()
Esempio n. 14
0
def get_device_details(serial):
    import adb  # pylint: disable=import-error
    props = adb.get_device(serial).get_props()
    name = props['ro.product.name']
    version = int(props['ro.build.version.sdk'])
    supported_abis = get_device_abis(props)
    build_id = props['ro.build.id']
    is_emulator = props.get('ro.build.characteristics') == 'emulator'
    return Device(serial, name, version, build_id, supported_abis, is_emulator)
Esempio n. 15
0
def benchmark_shell(device=None, file_size_mb=100):
    if device == None:
        device = adb.get_device()

    speeds = list()
    for _ in range(0, 10):
        begin = time.time()
        device.shell(
            ["dd", "if=/dev/zero", "bs=1m", "count=" + str(file_size_mb)])
        end = time.time()
        speeds.append(file_size_mb / float(end - begin))

    analyze("shell %dMiB" % file_size_mb, speeds)
def benchmark_shell(device=None, file_size_mb=100):
    if device == None:
        device = adb.get_device()

    speeds = list()
    for _ in range(0, 10):
        begin = time.time()
        device.shell(["dd", "if=/dev/zero", "bs=1m",
                      "count=" + str(file_size_mb)])
        end = time.time()
        speeds.append(file_size_mb / float(end - begin))

    analyze("shell %dMiB" % file_size_mb, speeds)
Esempio n. 17
0
 def __call__(self, parser, namespace, values, option_string=None):
     if option_string is None:
         raise RuntimeError("DeviceAction called without option_string")
     elif option_string == "-a":
         # Handled in parse_args
         return
     elif option_string == "-d":
         namespace.device = adb.get_usb_device()
     elif option_string == "-e":
         namespace.device = adb.get_emulator_device()
     elif option_string == "-s":
         namespace.device = adb.get_device(values[0])
     else:
         raise RuntimeError("Unexpected flag {}".format(option_string))
Esempio n. 18
0
 def __call__(self, parser, namespace, values, option_string=None):
     if option_string is None:
         raise RuntimeError("DeviceAction called without option_string")
     elif option_string == "-a":
         # Handled in parse_args
         return
     elif option_string == "-d":
         namespace.device = adb.get_usb_device()
     elif option_string == "-e":
         namespace.device = adb.get_emulator_device()
     elif option_string == "-s":
         namespace.device = adb.get_device(values[0])
     else:
         raise RuntimeError("Unexpected flag {}".format(option_string))
def benchmark_source(device=None, size_mb=100):
    if device == None:
        device = adb.get_device()

    speeds = list()
    cmd = device.adb_cmd + ["raw", "source:%d" % (size_mb * 1024 * 1024)]

    with open(os.devnull, 'w') as devnull:
        for _ in range(0, 10):
            begin = time.time()
            subprocess.check_call(cmd, stdout=devnull)
            end = time.time()
            speeds.append(size_mb / float(end - begin))

    analyze("source %dMiB" % size_mb, speeds)
Esempio n. 20
0
def benchmark_source(device=None, size_mb=100):
    if device == None:
        device = adb.get_device()

    speeds = list()
    cmd = device.adb_cmd + ["raw", "source:%d" % (size_mb * 1024 * 1024)]

    with open(os.devnull, 'w') as devnull:
        for _ in range(0, 10):
            begin = time.time()
            subprocess.check_call(cmd, stdout=devnull)
            end = time.time()
            speeds.append(size_mb / float(end - begin))

    analyze("source %dMiB" % size_mb, speeds)
Esempio n. 21
0
def start_jdb(adb_path, serial, jdb_cmd, pid, verbose):
    pid = int(pid)
    device = adb.get_device(serial, adb_path=adb_path)
    if verbose == "True":
        enable_verbose_logging()

    log("Starting jdb to unblock application.")

    # Do setup stuff to keep ^C in the parent from killing us.
    signal.signal(signal.SIGINT, signal.SIG_IGN)
    windows = sys.platform.startswith("win")
    if not windows:
        os.setpgrp()

    jdb_port = 65534
    device.forward("tcp:{}".format(jdb_port), "jdwp:{}".format(pid))
    jdb_cmd = [
        jdb_cmd, "-connect",
        "com.sun.jdi.SocketAttach:hostname=localhost,port={}".format(jdb_port)
    ]

    flags = subprocess.CREATE_NEW_PROCESS_GROUP if windows else 0
    jdb = subprocess.Popen(jdb_cmd,
                           stdin=subprocess.PIPE,
                           stdout=subprocess.PIPE,
                           stderr=subprocess.STDOUT,
                           creationflags=flags)

    # Wait until jdb can communicate with the app. Once it can, the app will
    # start polling for a Java debugger (e.g. every 200ms). We need to wait
    # a while longer then so that the app notices jdb.
    jdb_magic = "__verify_jdb_has_started__"
    jdb.stdin.write('print "{}"\n'.format(jdb_magic))
    saw_magic_str = False
    while True:
        line = jdb.stdout.readline()
        if line == "":
            break
        log("jdb output: " + line.rstrip())
        if jdb_magic in line and not saw_magic_str:
            saw_magic_str = True
            time.sleep(0.3)
            jdb.stdin.write("exit\n")
    jdb.wait()
    if saw_magic_str:
        log("JDB finished unblocking application.")
    else:
        log("error: did not find magic string in JDB output.")
Esempio n. 22
0
def start_jdb(adb_path, serial, jdb_cmd, pid, verbose):
    pid = int(pid)
    device = adb.get_device(serial, adb_path=adb_path)
    if verbose == "True":
        enable_verbose_logging()

    log("Starting jdb to unblock application.")

    # Do setup stuff to keep ^C in the parent from killing us.
    signal.signal(signal.SIGINT, signal.SIG_IGN)
    windows = sys.platform.startswith("win")
    if not windows:
        os.setpgrp()

    jdb_port = 65534
    device.forward("tcp:{}".format(jdb_port), "jdwp:{}".format(pid))
    jdb_cmd = [jdb_cmd, "-connect",
               "com.sun.jdi.SocketAttach:hostname=localhost,port={}".format(jdb_port)]

    flags = subprocess.CREATE_NEW_PROCESS_GROUP if windows else 0
    jdb = subprocess.Popen(jdb_cmd,
                           stdin=subprocess.PIPE,
                           stdout=subprocess.PIPE,
                           stderr=subprocess.STDOUT,
                           creationflags=flags)

    # Wait until jdb can communicate with the app. Once it can, the app will
    # start polling for a Java debugger (e.g. every 200ms). We need to wait
    # a while longer then so that the app notices jdb.
    jdb_magic = "__verify_jdb_has_started__"
    jdb.stdin.write('print "{}"\n'.format(jdb_magic))
    saw_magic_str = False
    while True:
        line = jdb.stdout.readline()
        if line == "":
            break
        log("jdb output: " + line.rstrip())
        if jdb_magic in line and not saw_magic_str:
            saw_magic_str = True
            time.sleep(0.3)
            jdb.stdin.write("exit\n")
    jdb.wait()
    if saw_magic_str:
        log("JDB finished unblocking application.")
    else:
        log("error: did not find magic string in JDB output.")
def benchmark_pull(device=None, file_size_mb=100):
    if device == None:
        device = adb.get_device()

    remote_path = "/data/local/tmp/adb_benchmark_temp"
    local_path = "/tmp/adb_benchmark_temp"

    device.shell(["dd", "if=/dev/zero", "of=" + remote_path, "bs=1m",
                  "count=" + str(file_size_mb)])
    speeds = list()
    for _ in range(0, 10):
        begin = time.time()
        device.pull(remote=remote_path, local=local_path)
        end = time.time()
        speeds.append(file_size_mb / float(end - begin))

    analyze("pull %dMiB" % file_size_mb, speeds)
Esempio n. 24
0
def benchmark_sink(device=None, size_mb=100):
    if device == None:
        device = adb.get_device()

    speeds = list()
    cmd = device.adb_cmd + ["raw", "sink:%d" % (size_mb * 1024 * 1024)]

    with tempfile.TemporaryFile() as tmpfile:
        tmpfile.truncate(size_mb * 1024 * 1024)

        for _ in range(0, 10):
            tmpfile.seek(0)
            begin = time.time()
            subprocess.check_call(cmd, stdin=tmpfile)
            end = time.time()
            speeds.append(size_mb / float(end - begin))

    analyze("sink %dMiB" % size_mb, speeds)
def benchmark_push(device=None, file_size_mb=100):
    if device == None:
        device = adb.get_device()

    remote_path = "/dev/null"
    local_path = "/tmp/adb_benchmark_temp"

    with open(local_path, "wb") as f:
        f.truncate(file_size_mb * 1024 * 1024)

    speeds = list()
    for _ in range(0, 10):
        begin = time.time()
        device.push(local=local_path, remote=remote_path)
        end = time.time()
        speeds.append(file_size_mb / float(end - begin))

    analyze("push %dMiB" % file_size_mb, speeds)
Esempio n. 26
0
def benchmark_push(device=None, file_size_mb=100):
    if device == None:
        device = adb.get_device()

    remote_path = "/dev/null"
    local_path = "/tmp/adb_benchmark_temp"

    with open(local_path, "wb") as f:
        f.truncate(file_size_mb * 1024 * 1024)

    speeds = list()
    for _ in range(0, 10):
        begin = time.time()
        device.push(local=local_path, remote=remote_path)
        end = time.time()
        speeds.append(file_size_mb / float(end - begin))

    analyze("push %dMiB" % file_size_mb, speeds)
def benchmark_sink(device=None, size_mb=100):
    if device == None:
        device = adb.get_device()

    speeds = list()
    cmd = device.adb_cmd + ["raw", "sink:%d" % (size_mb * 1024 * 1024)]

    with tempfile.TemporaryFile() as tmpfile:
        tmpfile.truncate(size_mb * 1024 * 1024)

        for _ in range(0, 10):
            tmpfile.seek(0)
            begin = time.time()
            subprocess.check_call(cmd, stdin=tmpfile)
            end = time.time()
            speeds.append(size_mb / float(end - begin))

    analyze("sink %dMiB" % size_mb, speeds)
Esempio n. 28
0
def benchmark_pull(device=None, file_size_mb=100):
    if device == None:
        device = adb.get_device()

    remote_path = "/data/local/tmp/adb_benchmark_temp"
    local_path = "/tmp/adb_benchmark_temp"

    device.shell([
        "dd", "if=/dev/zero", "of=" + remote_path, "bs=1m",
        "count=" + str(file_size_mb)
    ])
    speeds = list()
    for _ in range(0, 10):
        begin = time.time()
        device.pull(remote=remote_path, local=local_path)
        end = time.time()
        speeds.append(file_size_mb / float(end - begin))

    analyze("pull %dMiB" % file_size_mb, speeds)
Esempio n. 29
0
    def test_push_sync(self):
        """Sync a host directory to a specific path."""

        try:
            temp_dir = tempfile.mkdtemp()
            temp_files = make_random_host_files(in_dir=temp_dir, num_files=32)

            device_dir = posixpath.join(self.DEVICE_TEMP_DIR, 'sync_src_dst')

            # Clean up any stale files on the device.
            device = adb.get_device()  # pylint: disable=no-member
            device.shell(['rm', '-rf', device_dir])

            device.push(temp_dir, device_dir, sync=True)

            self.verify_sync(device, temp_files, device_dir)

            self.device.shell(['rm', '-rf', self.DEVICE_TEMP_DIR])
        finally:
            if temp_dir is not None:
                shutil.rmtree(temp_dir)
 def test_unique_device(self, mock_get_devices):
     mock_get_devices.return_value = ['foo']
     device = adb.get_device()
     self.assertEqual(device.serial, 'foo')
 def test_arg_beats_env(self, mock_get_devices):
     mock_get_devices.return_value = ['foo', 'bar']
     os.environ['ANDROID_SERIAL'] = 'bar'
     device = adb.get_device('foo')
     self.assertEqual(device.serial, 'foo')
 def test_explicit(self, mock_get_devices):
     mock_get_devices.return_value = ['foo', 'bar']
     device = adb.get_device('foo')
     self.assertEqual(device.serial, 'foo')
Esempio n. 33
0
def run_single_configuration(ndk_path,
                             out_dir,
                             printer,
                             abi,
                             toolchain,
                             build_api_level=None,
                             verbose_build=False,
                             suites=None,
                             test_filter=None,
                             device_serial=None,
                             skip_run=False,
                             force_deprecated_headers=False):
    """Runs all the tests for the given configuration.

    Sets up the necessary build flags and environment, checks that the device
    under test is in working order and performs device setup (if running device
    tests), and finally runs the tests for the selected suites.

    Args:
        ndk_path: Absolute path the the NDK being tested.
        out_dir: Directory to use when building tests.
        printer: Instance of printers.Printer that will be used to print test
            results.
        abi: ABI to test against.
        toolchain: Toolchain to build with.
        build_api_level: API level to build against. If None, will default to
            the value set in the test's Application.mk, or ndk-build's default.
        verbose_build: Show verbose output from ndk-build and cmake.
        suites: Set of strings denoting which test suites to run. Possible
            values are 'build' and 'device'. If None, will run all suites.
        test_filter: Filter string for selecting a subset of tests.
        device_serial: Serial number of the device to use for device tests. If
            none, will try to find a device from ANDROID_SERIAL or a unique
            attached device.
        skip_run: Skip running the tests; just build. Useful for post-build
            steps if CI doesn't have the device available.
        force_deprecated_headers: Set `APP_DEPRECATED_HEADERS=true` for every
            build.

    Returns:
        ndk.test.Report describing the test results.
    """
    if suites is None:
        suites = tests.testlib.ALL_SUITES

    os.chdir(os.path.dirname(os.path.realpath(__file__)))

    os.environ['NDK'] = ndk_path

    if verbose_build:
        # Don't decrease our log level.
        root_logger = logging.getLogger()
        if root_logger.getEffectiveLevel() != logging.DEBUG:
            root_logger.setLevel(logging.INFO)

    force_pie = False

    # Do this early so we find any device issues now rather than after we've
    # run all the build tests.
    have_device_suites = 'device' in suites or 'libc++' in suites
    if have_device_suites and not skip_run:
        device = adb.get_device(device_serial)
        check_adb_works_or_die(device, abi)
        device_api_level = int(device.get_prop('ro.build.version.sdk'))

        # PIE is required in L. All of the device tests are written toward the
        # ndk-build defaults, so we need to inform the build that we need PIE
        # if we're running on a newer device.
        if device_api_level >= 21:
            force_pie = True

        os.environ['ANDROID_SERIAL'] = device.serial

        if can_use_asan(device, abi, device_api_level, toolchain):
            asan_device_setup()

        # Do this as part of initialization rather than with a `mkdir -p` later
        # because Gingerbread didn't actually support -p :(
        device.shell_nocheck(['rm -r /data/local/tmp/ndk-tests 2>&1'])
        device.shell(['mkdir /data/local/tmp/ndk-tests 2>&1'])
        device.shell_nocheck(['rm -r /data/local/tmp/cmake-tests 2>&1'])
        device.shell(['mkdir /data/local/tmp/cmake-tests 2>&1'])
    elif skip_run:
        # We need to fake these if we're skipping running the tests. Set device
        # to None so any attempt to interact with it will raise an error, and
        # set the API level to the minimum supported by the ABI so
        # test_config.py checks still behave as expected.
        device = None
        device_api_level = build.lib.build_support.minimum_platform_level(abi)

    runner = tests.testlib.TestRunner(printer)
    if 'build' in suites:
        build_scanner = tests.testlib.BuildTestScanner()
        build_scanner.add_build_configuration(abi, build_api_level, toolchain,
                                              force_pie, verbose_build,
                                              force_deprecated_headers)
        runner.add_suite('build', 'build', build_scanner)
    if 'device' in suites:
        device_scanner = tests.testlib.DeviceTestScanner()
        device_scanner.add_device_configuration(
            abi, build_api_level, toolchain, force_pie, verbose_build,
            force_deprecated_headers, device, device_api_level, skip_run)
        runner.add_suite('device', 'device', device_scanner)
    if 'libc++' in suites:
        libcxx_scanner = tests.testlib.LibcxxTestScanner()
        libcxx_scanner.add_device_configuration(
            abi, build_api_level, toolchain, force_pie, verbose_build,
            force_deprecated_headers, device, device_api_level, skip_run)
        runner.add_suite('libc++', 'libc++', libcxx_scanner)

    test_filters = tests.filters.TestFilter.from_string(test_filter)
    report = runner.run(out_dir, test_filters)
    return report
 def setUp(self):
     self.device = adb.get_device()
Esempio n. 35
0
 def parse_args(self, args=None, namespace=None):
     result = super(ArgumentParser, self).parse_args(args, namespace)
     # Default to -a behavior if no flags are given.
     if "device" not in result:
         result.device = adb.get_device()
     return result
Esempio n. 36
0
 def test_unique_device(self, mock_get_devices):
     mock_get_devices.return_value = ['foo']
     device = adb.get_device()
     self.assertEqual(device.serial, 'foo')
Esempio n. 37
0
 def test_explicit(self, mock_get_devices):
     mock_get_devices.return_value = ['foo', 'bar']
     device = adb.get_device('foo')
     self.assertEqual(device.serial, 'foo')
Esempio n. 38
0
 def setUp(self):
     self.device = adb.get_device()
Esempio n. 39
0
def main():
    args, extra_args = parse_args()

    if args.ndk is None:
        args.ndk = ndk.paths.get_install_path()

    libcxx_dir = os.path.join(args.ndk, 'sources/cxx-stl/llvm-libc++')
    device_dir = '/data/local/tmp/libcxx'
    use_pie = True
    if not args.build_only:
        # We need to do this here rather than at the top because we load the
        # module from a path that is given on the command line. We load it from
        # the NDK given on the command line so this script can be run even
        # without a full platform checkout.
        site.addsitedir(os.path.join(args.ndk, 'python-packages'))
        import adb  # pylint: disable=import-error
        device = adb.get_device()
        prep_device(device, libcxx_dir, device_dir, args.abi)
        device_api_level = int(device.get_prop('ro.build.version.sdk'))
        if device_api_level < 16:
            use_pie = False

    arch = build.lib.build_support.abi_to_arch(args.abi)
    host_tag = find_host_tag(args.ndk)
    triple = build.lib.build_support.arch_to_triple(arch)
    toolchain = build.lib.build_support.arch_to_toolchain(arch)

    lit_path = build.lib.build_support.android_path(
        'external/llvm/utils/lit/lit.py')

    replacements = [
        ('ABI', args.abi),
        ('API', args.platform),
        ('ARCH', arch),
        ('HOST_TAG', host_tag),
        ('TOOLCHAIN', toolchain),
        ('TRIPLE', triple),
        ('USE_PIE', use_pie),
    ]
    sed_args = ['sed']
    for key, repl in replacements:
        sed_args.extend(['-e', 's:%{}%:{}:g'.format(key, repl)])
    sed_args.append(os.path.join(libcxx_dir, 'test/lit.ndk.cfg.in'))
    with open(os.path.join(libcxx_dir, 'test/lit.site.cfg'), 'w') as cfg_file:
        subprocess.check_call(sed_args, stdout=cfg_file)

    default_test_path = os.path.join(libcxx_dir, 'test')
    have_filter_args = False
    for arg in extra_args:
        # If the argument is a valid path with default_test_path, it is a
        # test filter.
        real_path = os.path.realpath(arg)
        if not real_path.startswith(default_test_path):
            continue
        if not os.path.exists(real_path):
            continue

        have_filter_args = True
        break  # No need to keep scanning.

    lit_args = [
        lit_path,
        '-sv',
        '--param=device_dir=' + device_dir,
        '--param=unified_headers={}'.format(not args.deprecated_headers),
    ] + extra_args

    if args.build_only:
        lit_args.append('--param=build_only=True')
    else:
        lit_args.append('--timeout={}'.format(args.timeout))

    if not have_filter_args:
        lit_args.append(default_test_path)
    env = dict(os.environ)
    env['NDK'] = args.ndk
    subprocess.check_call(lit_args, env=env)
Esempio n. 40
0
 def test_from_env(self, mock_get_devices):
     mock_get_devices.return_value = ["foo", "bar"]
     os.environ["ANDROID_SERIAL"] = "foo"
     device = adb.get_device()
     self.assertEqual(device.serial, "foo")
Esempio n. 41
0
 def test_explicit(self, mock_get_devices):
     mock_get_devices.return_value = ["foo", "bar"]
     device = adb.get_device("foo")
     self.assertEqual(device.serial, "foo")
Esempio n. 42
0
def run_single_configuration(ndk_path,
                             out_dir,
                             printer,
                             abi,
                             toolchain,
                             build_api_level=None,
                             verbose_ndk_build=False,
                             suites=None,
                             test_filter=None,
                             device_serial=None):
    """Runs all the tests for the given configuration.

    Sets up the necessary build flags and environment, checks that the device
    under test is in working order and performs device setup (if running device
    tests), and finally runs the tests for the selected suites.

    Args:
        ndk_path: Absolute path the the NDK being tested.
        out_dir: Directory to use when building tests.
        printer: Instance of printers.Printer that will be used to print test
            results.
        abi: ABI to test against.
        toolchain: Toolchain to build with.
        build_api_level: API level to build against. If None, will default to
            the value set in the test's Application.mk, or ndk-build's default.
        verbose_ndk_build: Show verbose output from ndk-build.
        suites: Set of strings denoting which test suites to run. Possible
            values are 'awk', 'build', and 'device'. If None, will run all
            suites.
        test_filter: Filter string for selecting a subset of tests.
        device_serial: Serial number of the device to use for device tests. If
            none, will try to find a device from ANDROID_SERIAL or a unique
            attached device.

    Returns:
        True if all tests completed successfully, False if there were failures.
    """
    if suites is None:
        suites = ('awk', 'build', 'device')

    os.chdir(os.path.dirname(os.path.realpath(__file__)))

    # Defining _NDK_TESTING_ALL_=yes to put armeabi-v7a-hard in its own
    # libs/armeabi-v7a-hard directory and tested separately from armeabi-v7a.
    # Some tests are now compiled with both APP_ABI=armeabi-v7a and
    # APP_ABI=armeabi-v7a-hard. Without _NDK_TESTING_ALL_=yes, tests may fail
    # to install due to race condition on the same libs/armeabi-v7a
    os.environ['_NDK_TESTING_ALL_'] = 'all'

    os.environ['NDK'] = ndk_path

    # For some reason we handle NDK_TOOLCHAIN_VERSION in _run_ndk_build_test...
    # We also handle APP_ABI there (as well as here). This merits some cleanup.
    ndk_build_flags = ['APP_ABI={}'.format(abi)]
    if build_api_level is not None:
        ndk_build_flags.append('APP_PLATFORM={}'.format(build_api_level))
    if verbose_ndk_build:
        ndk_build_flags.append('V=1')

    # Do this early so we find any device issues now rather than after we've
    # run all the build tests.
    if 'device' in suites:
        device = adb.get_device(device_serial)
        check_adb_works_or_die(device, abi)
        device_api_level = int(device.get_prop('ro.build.version.sdk'))

        # PIE is required in L. All of the device tests are written toward the
        # ndk-build defaults, so we need to inform the build that we need PIE
        # if we're running on a newer device.
        if device_api_level >= 21:
            ndk_build_flags.append('APP_PIE=true')

        os.environ['ANDROID_SERIAL'] = device.serial

        if can_use_asan(device, abi, device_api_level, toolchain):
            asan_device_setup()

        # Do this as part of initialization rather than with a `mkdir -p` later
        # because Gingerbread didn't actually support -p :(
        device.shell_nocheck(['rm -r /data/local/tmp/ndk-tests 2>&1'])
        device.shell(['mkdir /data/local/tmp/ndk-tests 2>&1'])

    runner = tests.TestRunner(printer)
    if 'awk' in suites:
        runner.add_suite('awk', 'awk', AwkTest)
    if 'build' in suites:
        runner.add_suite('build', 'build', BuildTest, abi, build_api_level,
                         toolchain, ndk_build_flags)
    if 'device' in suites:
        runner.add_suite('device', 'device', DeviceTest, abi, build_api_level,
                         device, device_api_level, toolchain, ndk_build_flags)

    test_filters = filters.TestFilter.from_string(test_filter)
    results = runner.run(out_dir, test_filters)

    stats = ResultStats(suites, results)

    printer.print_summary(results, stats)
    return stats.global_stats['fail'] == 0, results
Esempio n. 43
0
def run_single_configuration(
    ndk_path,
    out_dir,
    printer,
    abi,
    toolchain,
    build_api_level=None,
    verbose_ndk_build=False,
    suites=None,
    test_filter=None,
    device_serial=None,
):
    """Runs all the tests for the given configuration.

    Sets up the necessary build flags and environment, checks that the device
    under test is in working order and performs device setup (if running device
    tests), and finally runs the tests for the selected suites.

    Args:
        ndk_path: Absolute path the the NDK being tested.
        out_dir: Directory to use when building tests.
        printer: Instance of printers.Printer that will be used to print test
            results.
        abi: ABI to test against.
        toolchain: Toolchain to build with.
        build_api_level: API level to build against. If None, will default to
            the value set in the test's Application.mk, or ndk-build's default.
        verbose_ndk_build: Show verbose output from ndk-build.
        suites: Set of strings denoting which test suites to run. Possible
            values are 'awk', 'build', and 'device'. If None, will run all
            suites.
        test_filter: Filter string for selecting a subset of tests.
        device_serial: Serial number of the device to use for device tests. If
            none, will try to find a device from ANDROID_SERIAL or a unique
            attached device.

    Returns:
        True if all tests completed successfully, False if there were failures.
    """
    if suites is None:
        suites = ("awk", "build", "device")

    os.chdir(os.path.dirname(os.path.realpath(__file__)))

    # Defining _NDK_TESTING_ALL_=yes to put armeabi-v7a-hard in its own
    # libs/armeabi-v7a-hard directory and tested separately from armeabi-v7a.
    # Some tests are now compiled with both APP_ABI=armeabi-v7a and
    # APP_ABI=armeabi-v7a-hard. Without _NDK_TESTING_ALL_=yes, tests may fail
    # to install due to race condition on the same libs/armeabi-v7a
    os.environ["_NDK_TESTING_ALL_"] = "all"

    os.environ["NDK"] = ndk_path

    # For some reason we handle NDK_TOOLCHAIN_VERSION in _run_ndk_build_test...
    # We also handle APP_ABI there (as well as here). This merits some cleanup.
    ndk_build_flags = ["APP_ABI={}".format(abi)]
    if build_api_level is not None:
        ndk_build_flags.append("APP_PLATFORM={}".format(build_api_level))
    if verbose_ndk_build:
        ndk_build_flags.append("V=1")

    # Do this early so we find any device issues now rather than after we've
    # run all the build tests.
    if "device" in suites:
        device = adb.get_device(device_serial)
        check_adb_works_or_die(device, abi)
        device_api_level = int(device.get_prop("ro.build.version.sdk"))

        # PIE is required in L. All of the device tests are written toward the
        # ndk-build defaults, so we need to inform the build that we need PIE
        # if we're running on a newer device.
        if device_api_level >= 21:
            ndk_build_flags.append("APP_PIE=true")

        os.environ["ANDROID_SERIAL"] = device.serial

        if can_use_asan(device, abi, device_api_level, toolchain):
            asan_device_setup()

        # Do this as part of initialization rather than with a `mkdir -p` later
        # because Gingerbread didn't actually support -p :(
        device.shell_nocheck(["rm -r /data/local/tmp/ndk-tests 2>&1"])
        device.shell(["mkdir /data/local/tmp/ndk-tests 2>&1"])

    runner = tests.TestRunner(printer)
    if "awk" in suites:
        runner.add_suite("awk", "awk", AwkTest)
    if "build" in suites:
        runner.add_suite("build", "build", BuildTest, abi, build_api_level, toolchain, ndk_build_flags)
    if "device" in suites:
        runner.add_suite(
            "device", "device", DeviceTest, abi, build_api_level, device, device_api_level, toolchain, ndk_build_flags
        )

    test_filters = filters.TestFilter.from_string(test_filter)
    results = runner.run(out_dir, test_filters)

    stats = ResultStats(suites, results)

    printer.print_summary(results, stats)
    return stats.global_stats["fail"] == 0, results
Esempio n. 44
0
 def test_arg_beats_env(self, mock_get_devices):
     mock_get_devices.return_value = ['foo', 'bar']
     os.environ['ANDROID_SERIAL'] = 'bar'
     device = adb.get_device('foo')
     self.assertEqual(device.serial, 'foo')
Esempio n. 45
0
 def parse_args(self, args=None, namespace=None):
     result = super(ArgumentParser, self).parse_args(args, namespace)
     # Default to -a behavior if no flags are given.
     if "device" not in result:
         result.device = adb.get_device()
     return result
Esempio n. 46
0
 def __init__(self, *args, **kwargs):
     super(ShellTest, self).__init__(*args, **kwargs)
     self.device = adb.get_device(os.getenv("BOOTLOADER_TEST_SERIAL"));
Esempio n. 47
0
 def __init__(self, *args, **kwargs):
   super(ShellTest, self).__init__(*args, **kwargs)
   self.device = adb.get_device(os.getenv("IO_TEST_SERIAL"))