Пример #1
0
def stop_at_cts_pattern(command=None, pattern=None, timeout=-1):
    if not command:
        return

    if not pattern:
        response = [pexpect.EOF]
    else:
        response = [pattern, pexpect.EOF]

    result = True
    proc_cts = pexpect.spawn(command, logfile=sys.stdout)
    time.sleep(200)
    try:
        match_id = proc_cts.expect(response, timeout=timeout)
        if match_id == 0:
            time.sleep(5)
    except pexpect.TIMEOUT:
        result = False
    finally:
        proc_cts.sendcontrol('C')
        proc_cts.sendline('')
        target_dir = os.path.join(os.getcwd(),
                                  './android-cts/repository/results/')
        for zip_f in find_files(target_dir, '.zip'):
            ret_code = adb.push(zip_f, '/data/local/tmp/cts-results.zip')[0]
            if ret_code != 0:
                print "Failed to push file %s to device(%s)" % (zip_f,
                                                           adb.get_serial())
        log_target_dir = os.path.join(os.getcwd(),
                                  './android-cts/repository/logs/')
        for zip_f in find_files(log_target_dir, '.zip'):
            base_name = os.path.basename(zip_f)
            if base_name.startswith('device_logcat_'):
                base_name = 'device_logcat.zip'
            if base_name.startswith('host_log_'):
                base_name = 'host_log.zip'

            ret_code = adb.push(zip_f, '/data/local/tmp/%s' % base_name)[0]
            if ret_code != 0:
                print "Failed to push file %s to device(%s)" % (zip_f,
                                                           adb.get_serial())
                with ZipFile(zip_f) as log_fd:
                    print '=========Log file [%s] starts=========>>>>>' % (
                                                                       base_name)
                    f_name = base_name.replace('.zip', '.txt')
                    for line in log_fd.open(f_name).readlines():
                        print line.rstrip()
                    print '<<<<<=========Log file [%s] ends=========' % base_name
    return result
Пример #2
0
def stop_at_cts_pattern(command=None, pattern=None, timeout=-1):
    if not command:
        return

    if not pattern:
        response = [pexpect.EOF]
    else:
        response = [pattern, pexpect.EOF]

    result = True
    proc_cts = pexpect.spawn(command, logfile=sys.stdout)
    time.sleep(200)
    try:
        match_id = proc_cts.expect(response, timeout=timeout)
        if match_id == 0:
            time.sleep(5)
    except pexpect.TIMEOUT:
        result = False
    finally:
        proc_cts.sendcontrol('C')
        proc_cts.sendline('')
        target_dir = os.path.join(os.getcwd(),
                                  './android-cts/repository/results/')
        for zip_f in find_files(target_dir, '.zip'):
            ret_code = adb.push(zip_f, '/data/local/tmp/cts-results.zip')[0]
            if ret_code != 0:
                print "Failed to push file %s to device(%s)" % (
                    zip_f, adb.get_serial())
        log_target_dir = os.path.join(os.getcwd(),
                                      './android-cts/repository/logs/')
        for zip_f in find_files(log_target_dir, '.zip'):
            base_name = os.path.basename(zip_f)
            if base_name.startswith('device_logcat_'):
                base_name = 'device_logcat.zip'
            if base_name.startswith('host_log_'):
                base_name = 'host_log.zip'

            ret_code = adb.push(zip_f, '/data/local/tmp/%s' % base_name)[0]
            if ret_code != 0:
                print "Failed to push file %s to device(%s)" % (
                    zip_f, adb.get_serial())
                with ZipFile(zip_f) as log_fd:
                    print '=========Log file [%s] starts=========>>>>>' % (
                        base_name)
                    f_name = base_name.replace('.zip', '.txt')
                    for line in log_fd.open(f_name).readlines():
                        print line.rstrip()
                    print '<<<<<=========Log file [%s] ends=========' % base_name
    return result
Пример #3
0
 def list_test(self):
     dotext = '.sh'
     mod = self.import_mod("lava_android_test.test_definitions.hostshells")
     sh_files = find_files(mod.curdir, dotext)
     test_list = []
     for f in sh_files:
         ##Assume that the file name only has one '.sh'
         f_name_no_dotext = os.path.basename(f).replace(dotext, '')
         test_list.append('%s-%s' % (self.test_prefix, f_name_no_dotext))
     return test_list
Пример #4
0
 def list_test(self):
     dotext = '.sh'
     mod = self.import_mod("lava_android_test.test_definitions.hostshells")
     sh_files = find_files(mod.curdir, dotext)
     test_list = []
     for f in sh_files:
         ##Assume that the file name only has one '.sh'
         f_name_no_dotext = os.path.basename(f).replace(dotext, '')
         test_list.append('%s-%s' % (self.test_prefix, f_name_no_dotext))
     return test_list
Пример #5
0
    def run_monkeyrunner_test(self, script, serial, test_case_id=None):

        inst = AndroidTestInstaller()
        run = AndroidTestRunner(
            steps_host_pre=['monkeyrunner %s %s' % (script, serial)])
        parser = MonkeyrunnerTestParser()
        parser.monkeyrunner_result = os.path.join(os.path.dirname(script),
                                                  'results.txt')
        test = AndroidTest(testname='monkeyrunner',
                           installer=inst,
                           runner=run,
                           parser=parser)
        test.parser.results = {'test_results': []}
        test.setadb(self.adb)

        ##By calling the install function, we will create the directory
        ##on the target, and the the output file and error file
        ##will be pushed there
        if not self.test_installed(test.testname):
            test.install()

        ##The png files here are generated to the host by the monkeyrunner
        ##monkeyrunner is run on host, not on the target
        bundle = {}
        org_png_file_list = utils.find_files(self.config.tempdir_host,
                                             '.%s' % 'png')
        result_id = test.run(quiet=self.args.quiet)
        if self.args.output:
            cur_all_png_list = utils.find_files(self.config.tempdir_host,
                                                '.%s' % 'png')
            new_png_list = set(cur_all_png_list).difference(org_png_file_list)
            test_id = 'monkeyrunner(%s)' % (test_case_id)
            bundle = generate_bundle(self.args.serial,
                                     result_id,
                                     test=test,
                                     test_id=test_id,
                                     attachments=list(new_png_list))
            utils.delete_files(new_png_list)

        return bundle
Пример #6
0
    def run_monkeyrunner_test(self, script, serial, test_case_id=None):

        inst = AndroidTestInstaller()
        run = AndroidTestRunner(steps_host_pre=[
                                'monkeyrunner %s %s' % (script, serial)])
        parser = MonkeyrunnerTestParser()
        parser.monkeyrunner_result = os.path.join(os.path.dirname(script),
                                                  'results.txt')
        test = AndroidTest(testname='monkeyrunner',
                            installer=inst, runner=run, parser=parser)
        test.parser.results = {'test_results': []}
        test.setadb(self.adb)

        ##By calling the install function, we will create the directory
        ##on the target, and the the output file and error file
        ##will be pushed there
        if not self.test_installed(test.testname):
            test.install()

        ##The png files here are generated to the host by the monkeyrunner
        ##monkeyrunner is run on host, not on the target
        bundle = {}
        org_png_file_list = utils.find_files(self.config.tempdir_host,
                                             '.%s' % 'png')
        result_id = test.run(quiet=self.args.quiet)
        if self.args.output:
            cur_all_png_list = utils.find_files(self.config.tempdir_host,
                                                '.%s' % 'png')
            new_png_list = set(cur_all_png_list).difference(org_png_file_list)
            test_id = 'monkeyrunner(%s)' % (test_case_id)
            bundle = generate_bundle(self.args.serial,
                    result_id, test=test,
                    test_id=test_id,
                    attachments=list(new_png_list))
            utils.delete_files(new_png_list)

        return bundle
Пример #7
0
    def invoke_sub(self):

        if not utils.check_command_exist('monkeyrunner'):
            raise LavaCommandError('The command monkeyrunner can not be found')

        if self.args.repo_type == 'git':
            target_dir = mkdtemp(prefix='git_repo',
                                 dir=self.config.tempdir_host)
            os.chmod(target_dir, 0755)
            GitRepository(self.args.url).checkout(target_dir)
        else:
            raise LavaCommandError("The repository type(%s) is not supported" %
                                   self.args.repo_type)

        script_list = utils.find_files(target_dir, '.py')

        test_id = self.args.url
        if len(test_id) > 40:
            test_id = '%s...' % (test_id[:40])
        test_id = 'monkeyrunner_%s' % test_id

        tip_msg = ("Run monkeyrunner scripts in following url on device(%s):"
                   "\n\turl=%s") % (self.serial, self.args.url)

        self.say_begin(tip_msg)
        bundles = []
        for script in script_list:
            if "monkeycommon.py" == os.path.basename(script):
                continue
            sub_bundle = {}
            from datetime import datetime
            starttime = datetime.utcnow()
            test_case_id = script.replace('%s/' % target_dir, '')
            if len(test_case_id) > 50:
                test_case_id = '%s...' % (test_case_id[:50])
            try:
                sub_bundle = self.run_monkeyrunner_test(
                    script, self.serial, test_case_id)
                test_result = {"test_case_id": test_case_id, "result": 'pass'}
                if sub_bundle:
                    sub_bundle['test_runs'][0]['test_results'].append(
                        test_result)
            except Exception as strerror:
                self.say('Failed to run script(%s) with error:\n%s' %
                         (script, strerror))

                test_result = {"test_case_id": test_case_id, "result": 'fail'}
                TIMEFORMAT = '%Y-%m-%dT%H:%M:%SZ'
                sub_bundle['test_runs'] = [{
                    'test_results': [test_result],
                    'test_id':
                    'monkeyrunner(%s)' % test_case_id,
                    'time_check_performed':
                    False,
                    'analyzer_assigned_uuid':
                    str(uuid4()),
                    'analyzer_assigned_date':
                    starttime.strftime(TIMEFORMAT)
                }]
            if sub_bundle:
                bundles.append(sub_bundle)

        if self.args.output:
            output_dir = os.path.dirname(self.args.output)
            if output_dir and (not os.path.exists(output_dir)):
                os.makedirs(output_dir)
            with open(self.args.output, "wt") as stream:
                DocumentIO.dump(stream, merge_bundles(bundles))

        self.say_end(tip_msg)
Пример #8
0
    def invoke_sub(self):

        if not utils.check_command_exist('monkeyrunner'):
            raise LavaCommandError('The command monkeyrunner can not be found')

        if self.args.repo_type == 'git':
            target_dir = mkdtemp(prefix='git_repo',
                                 dir=self.config.tempdir_host)
            os.chmod(target_dir, 0755)
            GitRepository(self.args.url).checkout(target_dir)
        else:
            raise LavaCommandError("The repository type(%s) is not supported"
                                   % self.args.repo_type)

        script_list = utils.find_files(target_dir, '.py')

        test_id = self.args.url
        if len(test_id) > 40:
            test_id = '%s...' % (test_id[:40])
        test_id = 'monkeyrunner_%s' % test_id

        tip_msg = ("Run monkeyrunner scripts in following url on device(%s):"
                       "\n\turl=%s") % (
                       self.serial,
                       self.args.url)

        self.say_begin(tip_msg)
        bundles = []
        for script in script_list:
            if "monkeycommon.py" == os.path.basename(script):
                continue
            sub_bundle = {}
            from datetime import datetime
            starttime = datetime.utcnow()
            test_case_id = script.replace('%s/' % target_dir, '')
            if len(test_case_id) > 50:
                test_case_id = '%s...' % (test_case_id[:50])
            try:
                sub_bundle = self.run_monkeyrunner_test(script, self.serial,
                                                         test_case_id)
                test_result = {"test_case_id": test_case_id,
                               "result": 'pass'}
                if sub_bundle:
                    sub_bundle['test_runs'][0]['test_results'].append(
                                                            test_result)
            except Exception as strerror:
                self.say('Failed to run script(%s) with error:\n%s' % (
                                                                script,
                                                                strerror))

                test_result = {"test_case_id": test_case_id,
                               "result": 'fail'}
                TIMEFORMAT = '%Y-%m-%dT%H:%M:%SZ'
                sub_bundle['test_runs'] = [{'test_results': [test_result],
                    'test_id': 'monkeyrunner(%s)' % test_case_id,
                    'time_check_performed': False,
                    'analyzer_assigned_uuid': str(uuid4()),
                    'analyzer_assigned_date': starttime.strftime(TIMEFORMAT)}]
            if sub_bundle:
                    bundles.append(sub_bundle)

        if self.args.output:
            output_dir = os.path.dirname(self.args.output)
            if output_dir and (not os.path.exists(output_dir)):
                os.makedirs(output_dir)
            with open(self.args.output, "wt") as stream:
                DocumentIO.dump(stream, merge_bundles(bundles))

        self.say_end(tip_msg)