Exemple #1
0
    def run(self, pav_cfg, args):

        # get start time
        start_time = time.time()

        tests = status.get_tests(pav_cfg, args, self.errfile)

        # determine timeout time, if there is one
        end_time = None
        if args.timeout is not None:
            end_time = start_time + float(args.timeout)

        periodic_status_count = 0
        while (len(tests) != 0) and (end_time is None or
                                     time.time() < end_time):
            # Check which tests have completed or failed and move them to the
            # final list.
            temp_tests = copy.deepcopy(tests)
            for test_id in temp_tests:
                test_obj = TestRun.load(pav_cfg, test_id)
                run_complete_file = test_obj.path/'RUN_COMPLETE'
                if run_complete_file.exists():
                    tests.remove(test_id)

            # print status every 5 seconds
            if not args.silent:
                if time.time() > (start_time + 5*periodic_status_count):
                    stats = status.get_statuses(pav_cfg, args, self.errfile)
                    stats_out = []

                    if not args.oneline:
                        for test in stats:
                            stat = [str(time.ctime(time.time())), ':',
                                    'test #',
                                    str(test['test_id']),
                                    test['name'],
                                    test['state'],
                                    test['note'],
                                    "\n"]
                            stats_out.append(' '.join(stat))
                        fprint(''.join(map(str, stats_out)),
                               file=self.outfile, width=None)
                    else:
                        stats_out.extend([
                            str(time.ctime(time.time())), ': '
                        ])
                        for test in stats:
                            stat = [str(test['test_id']),
                                    '(', test['name'], ') ',
                                    test['state'], ' | ']
                            stats_out.append(''.join(stat))
                        fprint(''.join(map(str, stats_out)), end='\r',
                               file=self.outfile, width=None)

                    periodic_status_count += 1

        final_stats = status.get_statuses(pav_cfg, args, self.errfile)
        fprint('\n', file=self.outfile)
        return status.print_status(final_stats, self.outfile, args.json)
Exemple #2
0
    def wait(self, pav_cfg, tests: List[int], end_time: float,
             out_mode: str) -> None:
        """Wait on each of the given tests to complete, printing a status
        message """

        status_time = time.time() + self.STATUS_UPDATE_PERIOD
        while (len(tests) != 0) and (end_time is None
                                     or time.time() < end_time):

            # Check which tests have completed or failed and move them to the
            # final list.
            temp_tests = copy.deepcopy(tests)
            for test_id in temp_tests:
                test_obj = TestRun.load(pav_cfg, test_id)
                run_complete_file = test_obj.path / 'RUN_COMPLETE'
                if run_complete_file.exists():
                    tests.remove(test_id)

            # print status every 5 seconds
            if time.time() > status_time:
                status_time = time.time() + self.STATUS_UPDATE_PERIOD

                stats = status.get_statuses(pav_cfg, tests, self.errfile)
                stats_out = []

                if out_mode == self.OUT_SILENT:
                    pass
                elif out_mode == self.OUT_SUMMARY:
                    states = {}
                    for test in stats:
                        if test['state'] not in states.keys():
                            states[test['state']] = 1
                        else:
                            states[test['state']] += 1
                    status_counts = []
                    for state, count in states.items():
                        status_counts.append(state + ': ' + str(count))
                    fprint(' | '.join(status_counts),
                           file=self.outfile,
                           end='\r',
                           width=None)
                else:
                    for test in stats:
                        stat = [
                            str(time.ctime(time.time())), ':', 'test #',
                            str(test['test_id']), test['name'], test['state'],
                            test['note'], "\n"
                        ]
                        stats_out.append(' '.join(stat))
                    fprint(''.join(map(str, stats_out)),
                           file=self.outfile,
                           width=None)

        final_stats = status.get_statuses(pav_cfg, tests, self.errfile)
        fprint('\n', file=self.outfile)
        status.print_status(final_stats, self.outfile)
    def test_run_timeouts(self):
        """Make sure run timeout file works as expected."""

        run_cmd = commands.get_command('run')
        run_cmd.silence()

        arg_parser = arguments.get_parser()

        # All test follow the same pattern seen above, but we can run them all
        # at once, since a run timeout doesn't effect the others.
        args = arg_parser.parse_args(['run', 'timeout_run_tests'])
        self.assertEqual(run_cmd.run(self.pav_cfg, args), 0)

        time.sleep(35)

        correct_statuses = {
            'timeout_run_tests.GoodRun': 'COMPLETE',
            'timeout_run_tests.GoodRun2': 'COMPLETE',
            'timeout_run_tests.GoodRun3': 'COMPLETE',
            'timeout_run_tests.BadRun': 'RUN_TIMEOUT',
            'timeout_run_tests.BadRun2': 'RUN_TIMEOUT',
            'timeout_run_tests.BadRun3': 'RUN_TIMEOUT'
        }

        status_args = arg_parser.parse_args(['status'])

        statuses = get_statuses(self.pav_cfg, status_args, io.StringIO())
        for test_status in statuses:
            self.assertEqual(correct_statuses[test_status['name']],
                             test_status['state'])
Exemple #4
0
    def test_cancel(self):
        """Test cancel command with no arguments."""

        arg_parser = arguments.get_parser()

        args = arg_parser.parse_args(['run', '-H', 'this', 'cancel_test'])
        run_cmd = commands.get_command(args.command_name)
        run_cmd.outfile = run_cmd.errfile = StringIO()
        run_cmd.run(self.pav_cfg, args)

        args = arg_parser.parse_args(['cancel'])

        get_statuses(self.pav_cfg, args, StringIO())

        cancel_cmd = commands.get_command(args.command_name)
        cancel_cmd.outfile = cancel_cmd.errfile = StringIO()

        self.assertEqual(cancel_cmd.run(self.pav_cfg, args), 0)
    def test_cancel_cancelled_test(self):
        """Test cancelling a previously cancelled test."""

        arg_parser = arguments.get_parser()

        args = arg_parser.parse_args(['run', '-H', 'this', 'hello_world'])
        run_cmd = commands.get_command(args.command_name)
        run_cmd.outfile = StringIO()
        run_cmd.run(self.pav_cfg, args)

        args = arg_parser.parse_args(['cancel'])

        get_statuses(self.pav_cfg, args, StringIO())

        cancel_cmd = commands.get_command(args.command_name)
        cancel_cmd.outfile = StringIO()
        cancel_cmd.errfile = StringIO()

        cancel_cmd.run(self.pav_cfg, args)
        self.assertEqual(cancel_cmd.run(self.pav_cfg, args), 0)
    def test_wait_cancel(self):
        """Test cancel command after waiting for tests to start."""

        arg_parser = arguments.get_parser()

        args = arg_parser.parse_args(['run', '-H', 'this', 'hello_world'])
        run_cmd = commands.get_command(args.command_name)
        run_cmd.outfile = StringIO()
        run_cmd.run(self.pav_cfg, args)

        args = arg_parser.parse_args(['cancel'])

        time.sleep(5)
        get_statuses(self.pav_cfg, args, StringIO())

        cancel_cmd = commands.get_command(args.command_name)
        cancel_cmd.outfile = StringIO()
        cancel_cmd.errfile = StringIO()

        self.assertEqual(cancel_cmd.run(self.pav_cfg, args), 0)
Exemple #7
0
    def run(self, pav_cfg, args):
        # Store the initial time for timeout functionality.
        start_time = time.time()

        tmp_statuses = status.get_statuses(pav_cfg, args, self.errfile)

        final_statuses = 0

        while (final_statuses < len(tmp_statuses)) and \
              ((time.time() - start_time) < float(args.timeout)):
            # Check which tests have completed or failed and move them to the
            # final list.
            final_statuses = 0
            for test in tmp_statuses:
                if test['state'] in self.comp_list:
                    final_statuses += 1

            tmp_statuses = status.get_statuses(pav_cfg, args, self.errfile)

        ret_val = status.print_status(tmp_statuses, self.outfile, args.json)

        return ret_val