Beispiel #1
0
def run_device_test(out_dir, test_dir, build_flags, abi, platform):
    test_name = os.path.basename(test_dir)
    build_dir = os.path.join(out_dir, test_name)
    build_result = run_ndk_build_test(test_name, build_dir, test_dir,
                                      build_flags, abi, platform)
    if not build_result.passed:
        return [build_result]

    device_dir = os.path.join('/data/local/tmp/ndk-tests', test_name)

    result, out = adb.shell('mkdir -p {}'.format(device_dir))
    if result != 0:
        raise RuntimeError('mkdir failed:\n' + '\n'.join(out))

    results = []
    try:
        test_cases = copy_test_to_device(build_dir, device_dir, abi)
        for case in test_cases:
            case_name = '.'.join([test_name, case])
            if run_is_disabled(case, test_dir):
                results.append(Skipped(case_name, 'run disabled'))
                continue

            cmd = 'cd {} && LD_LIBRARY_PATH={} ./{}'.format(
                device_dir, device_dir, case)
            result, out = adb.shell(cmd)
            if result == 0:
                results.append(Success(case_name))
            else:
                results.append(Failure(case_name, '\n'.join(out)))
        return results
    finally:
        adb.shell('rm -rf {}'.format(device_dir))
Beispiel #2
0
def run_device_test(out_dir, test_dir, build_flags, abi, platform):
    test_name = os.path.basename(test_dir)
    build_dir = os.path.join(out_dir, test_name)
    build_result = run_ndk_build_test(test_name, build_dir, test_dir,
                                      build_flags, abi, platform)
    if not build_result.passed:
        return [build_result]

    device_dir = os.path.join('/data/local/tmp/ndk-tests', test_name)

    result, out = adb.shell('mkdir -p {}'.format(device_dir))
    if result != 0:
        raise RuntimeError('mkdir failed:\n' + '\n'.join(out))

    results = []
    try:
        test_cases = copy_test_to_device(build_dir, device_dir, abi)
        for case in test_cases:
            case_name = '.'.join([test_name, case])
            if run_is_disabled(case, test_dir):
                results.append(Skipped(case_name, 'run disabled'))
                continue

            cmd = 'cd {} && LD_LIBRARY_PATH={} ./{}'.format(
                device_dir, device_dir, case)
            result, out = adb.shell(cmd)
            if result == 0:
                results.append(Success(case_name))
            else:
                results.append(Failure(case_name, '\n'.join(out)))
        return results
Beispiel #3
0
    def run(self, out_dir, test_filters):
        print('Running device test: {}'.format(self.name))
        build_dir = os.path.join(out_dir, self.name)
        build_result = _run_ndk_build_test(self.name, build_dir, self.test_dir,
                                           self.build_flags, self.abi,
                                           self.platform)
        if not build_result.passed():
            return [build_result]

        device_dir = os.path.join('/data/local/tmp/ndk-tests', self.name)

        result, out = adb.shell('mkdir -p {}'.format(device_dir))
        if result != 0:
            raise RuntimeError('mkdir failed:\n' + '\n'.join(out))

        results = []
        try:
            test_cases = _copy_test_to_device(build_dir, device_dir, self.abi)
            for case in test_cases:
                case_name = _make_subtest_name(self.name, case)
                if not test_filters.filter(case_name):
                    results.append(Skipped(case_name, 'filtered'))
                    continue
                if _run_is_disabled(case, self.test_dir):
                    results.append(Skipped(case_name, 'run disabled'))
                    continue

                cmd = 'cd {} && LD_LIBRARY_PATH={} ./{}'.format(
                    device_dir, device_dir, case)
                result, out = adb.shell(cmd)
                if result == 0:
                    results.append(Success(case_name))
                else:
                    results.append(Failure(case_name, '\n'.join(out)))
            return results
Beispiel #4
0
    def keyevent(self,keycode):
        """
        send keyevent

        :Args:
            - keycode: keyevent code
              http://developer.android.com/reference/android/view/KeyEvent.html
        """
        cmd = "input keyevent %s" % keycode
        adb.shell(cmd)
Beispiel #5
0
    def tap(self,xcoord,ycoord):
        """
        Tap at given coordinates

        :Args:
            - xcoord: X Coordinate to tap
            - ycoord: Y Coordinate to tap
        """
        self._assertCoord(xcoord,ycoord)
        cmd = "input tap %s %s" % (xcoord,ycoord)
        adb.shell(cmd)
Beispiel #6
0
    def run(self, out_dir, test_filters):
        print('Running device test: {}'.format(self.name))
        build_dir = os.path.join(out_dir, self.name)
        build_result = _run_ndk_build_test(self.name, build_dir, self.test_dir,
                                           self.build_flags, self.abi,
                                           self.platform, self.toolchain)
        if not build_result.passed():
            return [build_result]

        device_dir = posixpath.join('/data/local/tmp/ndk-tests', self.name)

        # We have to use `ls foo || mkdir foo` because Gingerbread was lacking
        # `mkdir -p`, the -d check for directory existence, stat, dirname, and
        # every other thing I could think of to implement this aside from ls.
        result, out = adb.shell('ls {0} || mkdir {0}'.format(device_dir))
        if result != 0:
            raise RuntimeError('mkdir failed:\n' + '\n'.join(out))

        results = []
        try:
            test_cases = _copy_test_to_device(build_dir, device_dir, self.abi,
                                              test_filters, self.name)
            for case in test_cases:
                case_name = _make_subtest_name(self.name, case)
                if not test_filters.filter(case_name):
                    continue

                config = self.check_subtest_unsupported(case)
                if config is not None:
                    message = 'test unsupported for {}'.format(config)
                    results.append(Skipped(case_name, message))
                    continue

                cmd = 'cd {} && LD_LIBRARY_PATH={} ./{}'.format(
                    device_dir, device_dir, case)
                print('\tExecuting {}...'.format(case_name))
                result, out = adb.shell(cmd)

                config, bug = self.check_subtest_broken(case)
                if config is None:
                    if result == 0:
                        results.append(Success(case_name))
                    else:
                        results.append(Failure(case_name, '\n'.join(out)))
                else:
                    if result == 0:
                        results.append(
                            UnexpectedSuccess(case_name, config, bug))
                    else:
                        results.append(ExpectedFailure(case_name, config, bug))
            return results
        finally:
            adb.shell('rm -r {}'.format(device_dir))
Beispiel #7
0
    def swipe(self,xstart,ystart,xend,yend,duration=None):
        """
        Swipe

        :Args:
            - xstart: X start coordinate
            - ystart: Y start coordinate
            - xend: X end coordinate
            - yend: Y end coordinate
            - duration: android >= 4.4 can use opt duration(ms)
        """
        self._assertCoord(xstart,ystart)
        self._assertCoord(xend,yend)
        if duration:
            duration = int(duration)
        else:
            duration = ""
        cmd = "input swipe %s %s %s %s %s" % (xstart,ystart,xend,yend,duration)
        adb.shell(cmd)
Beispiel #8
0
def _copy_test_to_device(build_dir, device_dir, abi, test_filters, test_name):
    abi_dir = os.path.join(build_dir, 'libs', abi)
    if not os.path.isdir(abi_dir):
        raise RuntimeError('No libraries for {}'.format(abi))

    test_cases = []
    for test_file in os.listdir(abi_dir):
        if test_file in ('gdbserver', 'gdb.setup'):
            continue

        file_is_lib = False
        if not test_file.endswith('.so'):
            file_is_lib = True
            case_name = _make_subtest_name(test_name, test_file)
            if not test_filters.filter(case_name):
                continue
            test_cases.append(test_file)

        # TODO(danalbert): Libs with the same name will clobber each other.
        # This was the case with the old shell based script too. I'm trying not
        # to change too much in the translation.
        lib_path = os.path.join(abi_dir, test_file)
        print('\tPushing {} to {}...'.format(lib_path, device_dir))
        adb.push(lib_path, device_dir)

        # Binaries pushed from Windows may not have execute permissions.
        if not file_is_lib:
            file_path = posixpath.join(device_dir, test_file)
            adb.shell('chmod +x ' + file_path)

        # TODO(danalbert): Sync data.
        # The libc++ tests contain a DATA file that lists test names and their
        # dependencies on file system data. These files need to be copied to
        # the device.

    if len(test_cases) == 0:
        raise RuntimeError('Could not find any test executables.')

    return test_cases
Beispiel #9
0
    def run(self, out_dir, test_filters):
        print('Running device test: {}'.format(self.name))
        build_dir = os.path.join(out_dir, self.name)
        build_result = _run_ndk_build_test(self.name, build_dir, self.test_dir,
                                           self.build_flags, self.abi,
                                           self.platform)
        if not build_result.passed():
            return [build_result]

        device_dir = os.path.join('/data/local/tmp/ndk-tests', self.name)

        result, out = adb.shell('mkdir -p {}'.format(device_dir))
        if result != 0:
            raise RuntimeError('mkdir failed:\n' + '\n'.join(out))

        results = []
        try:
            test_cases = _copy_test_to_device(build_dir, device_dir, self.abi)
            for case in test_cases:
                case_name = _make_subtest_name(self.name, case)
                if not test_filters.filter(case_name):
                    results.append(Skipped(case_name, 'filtered'))
                    continue
                if _run_is_disabled(case, self.test_dir):
                    results.append(Skipped(case_name, 'run disabled'))
                    continue

                cmd = 'cd {} && LD_LIBRARY_PATH={} ./{}'.format(
                    device_dir, device_dir, case)
                result, out = adb.shell(cmd)
                if result == 0:
                    results.append(Success(case_name))
                else:
                    results.append(Failure(case_name, '\n'.join(out)))
            return results
        finally:
            adb.shell('rm -rf {}'.format(device_dir))
Beispiel #10
0
 def sendText(self,text):
     cmd = "input text \"%s\"" % text
     adb.shell(cmd)
Beispiel #11
0
        for case in test_cases:
            case_name = '.'.join([test_name, case])
            if run_is_disabled(case, test_dir):
                results.append(Skipped(case_name, 'run disabled'))
                continue

            cmd = 'cd {} && LD_LIBRARY_PATH={} ./{}'.format(
                device_dir, device_dir, case)
            result, out = adb.shell(cmd)
            if result == 0:
                results.append(Success(case_name))
            else:
                results.append(Failure(case_name, '\n'.join(out)))
        return results
    finally:
        adb.shell('rm -rf {}'.format(device_dir))


def run_tests(out_dir, test_dir, test_func):
    results = []
    for dentry in os.listdir(test_dir):
        path = os.path.join(test_dir, dentry)
        if os.path.isdir(path):
            try:
                results.extend(test_func(out_dir, path))
            except RuntimeError as ex:
                results.append(Failure(os.path.basename(dentry), ex))
    return results


def get_test_device():
Beispiel #12
0
 def test_shell_n_misspelled(self):
     result = adb.shell('misspelled')
     self.assertRegexpMatches(result[1], 'not found')
Beispiel #13
0
 def test_shell_p_w_option(self):
     result = adb.shell('ls -l')
     #search for time attribute which is for sure present in "-l" option
     self.assertRegexpMatches(result[1], '[0-2][0-9]:[0-5][0-9]')
Beispiel #14
0
 def test_shell_p(self):
     result = adb.shell('ls')
     #search for folders which will be for sure on Adnroid OS
     self.assertRegexpMatches(result[1], '(\\r\\nroot|\\r\\nsys|\\r\\nsystem)')
Beispiel #15
0
def main():
    orig_cwd = os.getcwd()
    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
    if '_NDK_TESTING_ALL_' not in os.environ:
        os.environ['_NDK_TESTING_ALL_'] = 'all'

    if 'NDK' not in os.environ:
        os.environ['NDK'] = os.path.dirname(os.getcwd())

    args = ArgParser().parse_args()
    ndk_build_flags = []
    if args.abi is not None:
        ndk_build_flags.append('APP_ABI={}'.format(args.abi))
    if args.platform is not None:
        ndk_build_flags.append('APP_PLATFORM={}'.format(args.platform))
    if args.show_commands:
        ndk_build_flags.append('V=1')

    if not os.path.exists(os.path.join('../build/tools/prebuilt-common.sh')):
        sys.exit('Error: Not run from a valid NDK.')

    out_dir = args.out_dir
    if out_dir is not None:
        if not os.path.isabs(out_dir):
            out_dir = os.path.join(orig_cwd, out_dir)
        if os.path.exists(out_dir):
            shutil.rmtree(out_dir)
        os.makedirs(out_dir)
    else:
        out_dir = tempfile.mkdtemp()
        atexit.register(lambda: shutil.rmtree(out_dir))

    suites = ['awk', 'build', 'device']
    if args.suite:
        suites = [args.suite]

    # Do this early so we find any device issues now rather than after we've
    # run all the build tests.
    if 'device' in suites:
        check_adb_works_or_die(args.abi)
        api_level = int(adb.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 api_level >= 21:
            ndk_build_flags.append('APP_PIE=true')

        os.environ['ANDROID_SERIAL'] = get_test_device()

        if can_use_asan(args.abi, api_level, args.toolchain):
            asan_device_setup()

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

    runner = tests.TestRunner()
    if 'awk' in suites:
        runner.add_suite('awk', 'awk', AwkTest)
    if 'build' in suites:
        runner.add_suite('build', 'build', BuildTest, args.abi, args.platform,
                         args.toolchain, ndk_build_flags)
    if 'device' in suites:
        runner.add_suite('device', 'device', DeviceTest, args.abi,
                         args.platform, api_level, args.toolchain,
                         ndk_build_flags)

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

    stats = ResultStats(suites, results)

    use_color = sys.stdin.isatty() and os.name != 'nt'
    printer = printers.StdoutPrinter(use_color=use_color,
                                     show_all=args.show_all)
    printer.print_results(results, stats)
    sys.exit(stats.global_stats['fail'] > 0)
Beispiel #16
0
 def test_shell_n_misspelled(self):
     result = adb.shell('misspelled')
     self.assertRegexpMatches(result[1], 'not found')
Beispiel #17
0
 def test_shell_p_w_option(self):
     result = adb.shell('ls -l')
     #search for time attribute which is for sure present in "-l" option
     self.assertRegexpMatches(result[1], '[0-2][0-9]:[0-5][0-9]')
Beispiel #18
0
 def test_shell_p(self):
     result = adb.shell('ls')
     #search for folders which will be for sure on Adnroid OS
     self.assertRegexpMatches(result[1],
                              '(\\r\\nroot|\\r\\nsys|\\r\\nsystem)')