def list_tests():
        test_dir = Paths.join(Paths.flow123d_root(), 'tests')
        tests = Paths.walk(test_dir, [
            PathFilters.filter_type_is_file(),
            PathFilters.filter_endswith('.yaml'),
            PathFilters.filter_not(PathFilters.filter_name('config.yaml')),
        ])
        result = dict()
        for r in tests:
            dirname = Paths.dirname(r)
            basename = Paths.basename(r)
            if Paths.dirname(dirname) != test_dir:
                continue

            if dirname not in result:
                result[dirname] = list()
            result[dirname].append(basename)
        keys = sorted(result.keys())

        for dirname in keys:
            printf.warning(Paths.relpath(dirname, test_dir))
            with printf:
                paths = list()
                wrap = 2
                for basename in result[dirname]:
                    paths.append(basename)
                for i in range(0, len(paths), wrap):
                    printf.out('  '.join(
                        ['{:<40s}'.format(x) for x in paths[i:i + wrap]]))
            printf.sep()
Beispiel #2
0
    def get_result(self):
        if self.clean.returncode != 0:
            printf.out("{} Could not clean directory '{c[dir]}': {c[error]}",
                       self.get_status_line(self.clean),
                       c=self.clean)
            return

        if self.pypy.returncode != 0:
            printf.out("{} Run error, case: {p[name]}",
                       self.get_status_line(self.pypy),
                       p=self.pypy)
            self.print_log_file(self.pypy.log, self.n_lines)
            return
        elif self.batch:
            self.print_log_file(self.pypy.log, self.n_lines)

        if self.comp.returncode not in (0, None):
            printf.out("{} Compare error, case: {p[name]}, Details: ",
                       self.get_status_line(self.comp),
                       p=self.pypy)
            self.print_log_file(self.pypy.log, self.n_lines)
            with printf:
                with printf:
                    for c in self.comp.tests:
                        rc = c.returncode
                        if rc == 0:
                            printf.out('[{:^6}]: {}', 'OK', c.name)
                        else:
                            printf.out('[{:^6}]: {}', 'FAILED', c.name)
            return
        elif self.batch:
            self.print_log_file(self.comp.log, self.n_lines)
Beispiel #3
0
    def print_log_file(cls, f, n_lines):
        log_file = IO.read(f)
        if log_file:
            if n_lines == 0:
                printf.out('Full log from file {}:', f)
            else:
                printf.out('Last {} lines from file {}:', abs(n_lines), f)

            printf.stream(format_n_lines(log_file.rstrip(), -n_lines))
Beispiel #4
0
 def get_result(self):
     if self.returncode != 0:
         if self.returncode != 0:
             printf.out("{} Run error, case: {p.name}",
                        RuntestParser.get_status_line(self),
                        p=self)
             RuntestParser.print_log_file(self.log, self.n_lines)
             return
     elif self.batch:
         RuntestParser.print_log_file(self.log, self.n_lines)
    def _run(self):
        """
        Run method for this module
        """

        printf.important('configuration:').sep()
        with printf:
            overrides = ('memory_limit', 'time_limit', 'cpu')
            global_changes = {
                k: self.arg_options.get(k)
                for k in overrides if self.arg_options.get(k)
            }
            for k, v in global_changes.items():
                printf.important('{:16s} {:10s} (global override)', str(k),
                                 str(v))

            # ---------------------------------------------

            if self.arg_options.random_output_dir:
                import scripts.yamlc as yamlc
                yamlc.TEST_RESULTS = 'test_results-{}'.format(
                    self.arg_options.random_output_dir)

            # ---------------------------------------------

            self.all_yamls = self._walk_files()
            printf.important("{:16s} {}", 'yaml files', len(self.all_yamls))
            if not self.all_yamls:
                printf.warning('No yaml files found in following locations:')
                with printf:
                    printf.opt(default='IMPORTANT').stream(
                        self.arg_options.args)
                sys.exit(0)

            # ---------------------------------------------

            self.configs = self.read_configs(self.all_yamls)
            self.configs.update(
                proc=self.arg_options.cpu,
                time_limit=self.arg_options.time_limit,
                memory_limit=self.arg_options.memory_limit,
            )

            # filter tags for includes and excludes
            self.configs.filter_tags(include=self.include,
                                     exclude=self.exclude)

        if self.arg_options.queue:
            if printf.verbosity() is printf.OutputVerbosity.FULL:
                printf.out('Running in PBS mode')
            return self.run_pbs_mode()
        else:
            if printf.verbosity() is printf.OutputVerbosity.FULL:
                printf.out('Running in LOCAL mode')
            return self.run_local_mode()
Beispiel #6
0
    def on_update(self, pypy=None):
        self._check_limits()

        if self.terminated:
            return

        for fmt in ensure_iterable(self.update_format):
            if printf.tty():
                printf.rewrite(fmt, monitor=self)
            else:
                printf.out(fmt, monitor=self)
Beispiel #7
0
def massif_hook(pypy):
    """
    Function will initialize ValgrindMassif and print result on success
    :type pypy: scripts.core.pypy.PyPy
    """
    vm = ValgrindMassif(pypy.case.fs.valgrind_out)
    vm.output = OutputMode.variable_output()
    vm.start()
    vm.join()

    # if ms_print ended successfully we print first 32 lines (where graph is)
    if vm.returncode == 0:
        output = vm.output.read()
        lines = str(output).splitlines()[0:32]
        printf.out('\n    '.join(lines))
def do_work(arg_options=None, debug=False):
    """
    Main method which invokes ModuleRuntest
    :rtype: ParallelThreads
    :type debug: bool
    :type arg_options: utils.argparser.RuntestArgs
    """
    module = ModuleRuntest(arg_options)
    result = module.run(debug)  # type: ParallelThreads

    if not arg_options.queue:
        printf.sep()
        if arg_options.save_to_db:
            from scripts.artifacts.collect.loader import load_data, save_to_database
            from scripts.artifacts.collect.modules.flow123d_profiler import Flow123dProfiler

            for t in result.threads:
                thread = t  # type: RuntestMultiThread
                with printf:
                    printf.out('Processing %s' % thread.pypy.case.fs.output)
                    data = load_data(thread.pypy.case.fs.output,
                                     Flow123dProfiler())

                    if data:
                        with printf:
                            printf.out(' - found %d file(s)' % len(data))
                            with printf:
                                for item in data:
                                    printf.out(' %d element(s)' %
                                               len(item.items))
                    else:
                        printf.error('No profiler data found')
                    save_to_database(data)

    # pickle out result on demand
    if arg_options.dump:
        try:
            import pickle
            pickle.dump(result.dump(), open(arg_options.dump, 'wb'))
        except:
            pass

    return result.returncode, result
Beispiel #9
0
    def print_test_result(cls, thread, formatter=TestPrinterStatus):
        """
        :type formatter: TestPrinterStatus
        :type thread: scripts.core.threads.RuntestMultiThread
        """
        status_name = '[ {} ]'.format(formatter.get(str(
            thread.returncode))).upper()
        case_name = thread.pypy.case.as_string

        detail = ''
        thread_names = ['clean', 'pypy', 'comp']
        thread_rcs = dict()
        thread_msg = dict()

        for ti in thread_names:
            subthread = getattr(thread, ti)
            thread_rcs[ti] = subthread.returncode
            thread_msg[ti] = getattr(formatter, 'detail_{}'.format(ti))(thread)

        # first non zero rc will be formatted
        # otherwise first non empty detail
        for ti in thread_names:
            subthread = getattr(thread, ti)
            if subthread.returncode.failed:
                sub_detail = thread_msg[ti]
                detail = formatter.errors[ti].format(**locals())
                printf.error(formatter.template.format(**locals()))
                return

        # first non empty detail
        for ti in thread_names:
            subthread = getattr(thread, ti)
            sub_detail = thread_msg[ti]
            if sub_detail:
                detail = formatter.errors[ti].format(**locals())
                printf.out(formatter.template.format(**locals()))
                return

        if str(thread.returncode).upper() == 'NONE':
            printf.warning(formatter.template.format(**locals()))
        else:
            printf.success(formatter.template.format(**locals()))
Beispiel #10
0
    def on_complete(self, pypy=None):

        if self.log_file:
            IO.write(self.log_file, self.content)

        # finish after update
        if self.update_format and (not self.complete_format
                                   and not self.color_complete_format):
            printf.finish_rewrite()

        # print regular messages
        for fmt in ensure_iterable(self.complete_format):
            printf.out(fmt, monitor=self)

        # print messages if error
        if self.pypy.with_error():
            for fmt in ensure_iterable(self.error_complete_format):
                printf.error(fmt, monitor=self)

        # print regular color messages based on result
        for fmt in ensure_iterable(self.color_complete_format):
            if self.pypy.returncode() == 0:
                printf.success(fmt, monitor=self)
            elif self.pypy.returncode() is None:
                printf.warning(fmt, monitor=self)
            else:
                printf.error(fmt, monitor=self)

        with printf:
            if printf.verbosity() is printf.OutputVerbosity.FULL:
                printf.sep()
                printf.out('Output from file {self.pypy.full_output}'.format(
                    **locals()))
                printf.opt(raw=True).stream(
                    format_n_lines(self.content, pypy.was_successful()))
            elif printf.verbosity(
            ) is printf.OutputVerbosity.SMART and pypy.with_error():
                printf.sep()
                printf.out(
                    'Last 50 lines from file {self.pypy.full_output}'.format(
                        **locals()))
                printf.opt(raw=True).stream(
                    format_n_lines(self.content, success=False, n_lines=-50))
            elif printf.verbosity(
            ) is printf.OutputVerbosity.MINIMAL and pypy.with_error():
                printf.sep()
                printf.out(
                    'Last 50 lines from file {self.pypy.full_output}'.format(
                        **locals()))
                printf.opt(raw=True).stream(
                    format_n_lines(self.content, success=False, n_lines=-50))
Beispiel #11
0
    def run_local_mode(self):
        """
        Runs this module in local mode.
        At this point all configuration files has been loaded what is left
        to do is to prepare execution arguments start whole process
        """
        with printf:
            runner = ParallelThreads(self.arg_options.parallel)
            runner.stop_on_error = not self.arg_options.keep_going
            pypy_index = 1

            for yaml_file, yaml_config in list(self.configs.files.items()):
                for case in yaml_config.get_one(yaml_file):
                    if printf.verbosity() is printf.OutputVerbosity.FULL:
                        printf.out(' - found case {} in {}', case, yaml_file)
                    # create main process which first clean output dir
                    # and then execute test following with comparisons
                    multi_process = self.create_process_from_case(case)
                    multi_process.pypy.extra['runner'] = runner
                    multi_process.pypy.extra['index'] = pypy_index
                    pypy_index += 1
                    runner.add(multi_process)

            printf.important('{:16s} {}', 'total cases', runner.total)
            if printf.verbosity() is printf.OutputVerbosity.FULL:
                printf.out(' - {:16s} {}', 'includes', self.include)
                printf.out(' - {:16s} {}', 'excludes', self.exclude)

                printf.important('cases')
                with printf:
                    for thread in runner.threads:
                        try:
                            printf.out(' - {}', thread.pypy.case)
                        except:
                            printf.out(' - {}', thread)

        printf.sep().important('execution:')
        with printf:

            # run!
            runner.start()
            while runner.is_running():
                time.sleep(1)

        printf.sep().important('SUMMARY ').sep()

        with printf:
            for thread in runner.threads:
                multithread = thread  # type: RuntestMultiThread
                StatusPrinter.print_test_result(multithread)
            printf.sep()
            StatusPrinter.print_runner_stat(runner)

        # exit with runner's exit code
        GlobalResult.returncode = runner.returncode
        return runner
Beispiel #12
0
    def on_start(self, pypy=None):
        self.process = self.pypy.executor.process

        for fmt in ensure_iterable(self.start_format):
            printf.out(fmt, monitor=self)