Example #1
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_utils.get_statuses(pav_cfg, tests)
                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_utils.get_statuses(pav_cfg, tests)
        fprint('\n', file=self.outfile)
        status_utils.print_status(final_stats, self.outfile)
Example #2
0
    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.tests)
        for test_status in statuses:
            self.assertEqual(correct_statuses[test_status['name']],
                             test_status['state'])
Example #3
0
    def run(self, pav_cfg, args):
        """Gathers and prints the statuses from the specified test runs and/or
        series."""

        try:
            test_ids = cmd_utils.arg_filtered_tests(pav_cfg, args, verbose=self.errfile)
        except ValueError as err:
            output.fprint(err.args[0], color=output.RED, file=self.errfile)
            return errno.EINVAL

        statuses = status_utils.get_statuses(pav_cfg, test_ids)

        if args.summary:
            return self.print_summary(statuses)
        elif args.history:
            if len(test_ids) != 1:
                output.fprint("'--history' flag requires a single test id, "
                              "got: {}"
                              .format(test_ids),
                              file=self.errfile,
                              color=output.RED)
                return 1
            return status_utils.print_status_history(pav_cfg, test_ids[-1],
                                                     self.outfile, args.json)
        else:
            return status_utils.print_status(statuses, self.outfile, args.json)
Example #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.silence()
        run_cmd.run(self.pav_cfg, args)

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

        get_statuses(self.pav_cfg, args.tests)

        cancel_cmd = commands.get_command(args.command_name)
        cancel_cmd.silence()

        self.assertEqual(cancel_cmd.run(self.pav_cfg, args), 0)
Example #5
0
    def run(self, pav_cfg, args):
        """Gathers and prints the statuses from the specified test runs and/or
        series."""

        try:
            test_ids = cmd_utils.arg_filtered_tests(pav_cfg,
                                                    args,
                                                    verbose=self.errfile)
        except ValueError as err:
            output.fprint(err.args[0], color=output.RED, file=self.errfile)
            return errno.EINVAL

        statuses = status_utils.get_statuses(pav_cfg, test_ids)

        if args.summary:
            return self.print_summary(statuses)
        else:
            return status_utils.print_status(statuses, self.outfile, args.json)