Beispiel #1
0
    def _main(self):
        """
        Base vunit main function without performing exit
        """
        if self._list_only:
            return self._main_list_only()

        if self._compile_only:
            return self._main_compile_only()

        simulator_if = self._create_simulator_if()
        test_cases = self._create_tests(simulator_if)

        self._compile(simulator_if)

        start_time = ostools.get_time()
        report = TestReport(printer=self._printer)
        try:
            self._run_test(test_cases, report)
            simulator_if.post_process(self._simulator_factory.simulator_output_path)
        except KeyboardInterrupt:
            print()
            LOGGER.debug("_main: Caught Ctrl-C shutting down")
        finally:
            del test_cases
            del simulator_if

        report.set_real_total_time(ostools.get_time() - start_time)
        self._post_process(report)

        return report.all_ok()
Beispiel #2
0
    def _run_test_suite(self, test_suite, num_tests):

        def add_and_print_results(results, runtime):
            time = runtime/len(test_suite.test_cases)
            for test_name in test_suite.test_cases:
                self._report.add_result(test_name,
                                        results[test_name],
                                        time,
                                        output_file_name)
                self._report.print_latest_status(total_tests=num_tests)
            print()

        for test_name in test_suite.test_cases:
            self._print_test_case_banner(test_name)

        start = ostools.get_time()
        old_stdout = sys.stdout
        old_stderr = sys.stderr

        output_path = join(self._output_path, self._encode_path(test_suite.name))
        output_file_name = join(output_path, "output.txt")

        try:
            # If we could not clean output path, fail all tests
            if exists(output_path):
                rmtree(output_path)
            makedirs(output_path)
            output_file = open(output_file_name, "w")
        except:
            traceback.print_exc()
            results = self._fail_suite(test_suite)
            add_and_print_results(results, 0.0)
            return

        try:
            if self._verbose:
                sys.stdout = TeeToFile([old_stderr, output_file])
                sys.stderr = TeeToFile([old_stdout, output_file])
            else:
                sys.stdout = TeeToFile([output_file])
                sys.stderr = TeeToFile([output_file])

            results = test_suite.run(output_path)
        except:
            traceback.print_exc()
            results = self._fail_suite(test_suite)
        finally:
            sys.stdout = old_stdout
            sys.stderr = old_stderr
            output_file.close()

        any_not_passed = any(value != PASSED for value in results.values())
        if (not self._verbose) and any_not_passed:
            with open(output_file_name, "r") as fread:
                for line in fread:
                    print(line, end="")

        runtime = ostools.get_time() - start
        add_and_print_results(results, runtime)
def run_with_compile_errors(ui, args, vhdl_standard):
    def match(name, patterns):
        return reduce(
            lambda found_match, pattern: found_match | fnmatch(name, pattern),
            patterns,
            False,
        )

    # Run all tests in isolation to handle failure to compile
    args.minimal = True
    original_test_patterns = args.test_patterns
    test_report = TestReport()
    n_tests = 0
    testbenches = (ui.library("vhdl_2008").get_test_benches() +
                   ui.library("vhdl_2019").get_test_benches())
    total_start_time = ostools.get_time()
    for tb in testbenches:
        tests = tb.get_tests()
        if not tests:
            test_names = ["all"]
        else:
            test_names = [test.name for test in tests]

        for test_name in test_names:
            full_test_name = "%s.%s.%s" % (tb.library.name, tb.name, test_name)
            if not match(full_test_name, original_test_patterns):
                continue

            test_start_time = ostools.get_time()
            n_tests += 1
            args.test_patterns = [full_test_name]
            ui = VUnit.from_args(args, vhdl_standard=vhdl_standard)
            vhdl_2008 = ui.add_library("vhdl_2008")
            vhdl_2019 = ui.add_library("vhdl_2019")
            vhdl_2008.add_source_files(join(root, "vhdl_2008", "*.vhd"))
            vhdl_2019.add_source_files(join(root, "vhdl_2019", "*.vhd"))

            try:
                ui.main()
            except SystemExit as ex:
                tb_time = ostools.get_time() - test_start_time
                if ex.code == 0:
                    test_report.add_result(full_test_name, PASSED, tb_time,
                                           None)
                else:
                    test_report.add_result(full_test_name, FAILED, tb_time,
                                           None)

    print("\nCompliance test completed:\n")
    test_report.set_expected_num_tests(n_tests)
    test_report.set_real_total_time(ostools.get_time() - total_start_time)
    test_report.print_str()
Beispiel #4
0
    def _run_test_suite(self, test_suite, write_stdout, num_tests, output_path,
                        output_file_name):
        """
        Run the actual test suite
        """
        color_output_file_name = join(output_path, "output_with_color.txt")

        output_file = None
        color_output_file = None

        start_time = ostools.get_time()
        results = self._fail_suite(test_suite)

        try:
            ostools.renew_path(output_path)
            output_file = wrap(open(output_file_name, "w"), use_color=False)

            if write_stdout:
                self._local.output = Tee([self._stdout_ansi, output_file])
            else:
                color_output_file = open(color_output_file_name, "w")
                self._local.output = Tee([color_output_file, output_file])

            results = test_suite.run(output_path)
        except KeyboardInterrupt:
            raise
        except:  # pylint: disable=bare-except
            if self._dont_catch_exceptions:
                raise

            with self._stdout_lock():
                traceback.print_exc()
        finally:
            self._local.output = self._stdout

            for fptr in [output_file, color_output_file]:
                if fptr is None:
                    continue

                fptr.flush()
                fptr.close()

        any_not_passed = any(value != PASSED for value in results.values())

        with self._stdout_lock():

            if (color_output_file is not None) and (
                    any_not_passed or self._is_verbose) and not self._is_quiet:
                self._print_output(color_output_file_name)

            self._add_results(test_suite, results, start_time, num_tests,
                              output_file_name)

            if self._fail_fast and any_not_passed:
                self._abort = True
Beispiel #5
0
    def _run_test_suite(self, test_suite, write_stdout, num_tests):
        """
        Run the actual test suite
        """
        start_time = ostools.get_time()

        output_path = join(self._output_path, test_suite.name)
        output_file_name = join(output_path, "output.txt")

        try:
            # If we could not clean output path, fail all tests
            ostools.renew_path(output_path)
            output_file = open(output_file_name, "w")
        except KeyboardInterrupt:
            raise
        except:  # pylint: disable=bare-except
            results = self._fail_suite(test_suite)
            with self._lock:
                traceback.print_exc()
                self._add_results(test_suite, results, start_time, num_tests)
            return

        try:
            if write_stdout:
                stdout = LogColorOverlay(
                    stream=self._stdout,
                    printer=self._printer,
                    vhdl_report_parser_callback=self.vhdl_report_parser_callback)
                self._local.output = TeeToFile([stdout, output_file])
            else:
                self._local.output = TeeToFile([output_file])

            results = test_suite.run(output_path)
        except KeyboardInterrupt:
            raise
        except:  # pylint: disable=bare-except
            traceback.print_exc()
            results = self._fail_suite(test_suite)
        finally:
            self._local.output = self._stdout
            output_file.flush()
            output_file.close()

        any_not_passed = any(value != PASSED for value in results.values())

        with self._lock:
            if (not write_stdout) and (any_not_passed or self._verbose):
                stdout = LogColorOverlay(
                    stream=sys.stdout,
                    printer=self._printer,
                    vhdl_report_parser_callback=self.vhdl_report_parser_callback)
                self._print_output(output_file_name, stdout)
            self._add_results(test_suite, results, start_time, num_tests)
Beispiel #6
0
    def _add_results(self, test_suite, results, start_time, num_tests,
                     output_file_name):
        """
        Add results to test report
        """
        runtime = ostools.get_time() - start_time
        time_per_test = runtime / len(results)

        for test_name in test_suite.test_names:
            status = results[test_name]
            self._report.add_result(test_name, status, time_per_test,
                                    output_file_name)
            self._report.print_latest_status(total_tests=num_tests)
        print()
Beispiel #7
0
    def _add_results(self, test_suite, results, start_time, num_tests, output_file_name):
        """
        Add results to test report
        """
        runtime = ostools.get_time() - start_time
        time_per_test = runtime / len(results)

        for test_name in test_suite.test_cases:
            status = results[test_name]
            self._report.add_result(test_name,
                                    status,
                                    time_per_test,
                                    output_file_name)
            self._report.print_latest_status(total_tests=num_tests)
        print()
Beispiel #8
0
    def _run_test_suite(self, test_suite, write_stdout, num_tests, output_path,
                        output_file_name):
        """
        Run the actual test suite
        """
        start_time = ostools.get_time()

        try:
            # If we could not clean output path, fail all tests
            ostools.renew_path(output_path)
            output_file = open(output_file_name, "w")
        except KeyboardInterrupt:
            raise
        except:  # pylint: disable=bare-except
            results = self._fail_suite(test_suite)
            with self._lock:  # pylint: disable=not-context-manager
                traceback.print_exc()
                self._add_results(test_suite, results, start_time, num_tests,
                                  output_file_name)
            return

        try:
            if write_stdout:
                self._local.output = TeeToFile([self._stdout, output_file])
            else:
                self._local.output = TeeToFile([output_file])

            results = test_suite.run(output_path)
        except KeyboardInterrupt:
            raise
        except:  # pylint: disable=bare-except
            if self._dont_catch_exceptions:
                raise
            traceback.print_exc()
            results = self._fail_suite(test_suite)
        finally:
            self._local.output = self._stdout
            output_file.flush()
            output_file.close()

        any_not_passed = any(value != PASSED for value in results.values())

        with self._lock:  # pylint: disable=not-context-manager
            if (not write_stdout) and (
                    any_not_passed or self._is_verbose) and not self._is_quiet:
                self._print_output(output_file_name)
            self._add_results(test_suite, results, start_time, num_tests,
                              output_file_name)
Beispiel #9
0
    def _run_test_suite(self,
                        test_suite,
                        write_stdout,
                        num_tests,
                        output_path,
                        output_file_name):
        """
        Run the actual test suite
        """
        color_output_file_name = join(output_path, "output_with_color.txt")

        output_file = None
        color_output_file = None

        start_time = ostools.get_time()
        results = self._fail_suite(test_suite)

        try:
            ostools.renew_path(output_path)
            output_file = wrap(open(output_file_name, "a+"), use_color=False)
            output_file.seek(0)
            output_file.truncate()

            if write_stdout:
                self._local.output = Tee([self._stdout_ansi, output_file])
            else:
                color_output_file = open(color_output_file_name, "w")
                self._local.output = Tee([color_output_file, output_file])

            def read_output():
                """
                Called to read the contents of the output file on demand
                """
                output_file.flush()
                prev = output_file.tell()
                output_file.seek(0)
                contents = output_file.read()
                output_file.seek(prev)
                return contents

            results = test_suite.run(output_path=output_path,
                                     read_output=read_output)
        except KeyboardInterrupt:
            self._add_skipped_tests(test_suite, results, start_time, num_tests, output_file_name)
            raise KeyboardInterrupt
        except:  # pylint: disable=bare-except
            if self._dont_catch_exceptions:
                raise

            with self._stdout_lock():
                traceback.print_exc()
        finally:
            self._local.output = self._stdout

            for fptr in [output_file, color_output_file]:
                if fptr is None:
                    continue

                fptr.flush()
                fptr.close()

        any_not_passed = any(value != PASSED for value in results.values())

        with self._stdout_lock():

            if (color_output_file is not None) and (any_not_passed or self._is_verbose) and not self._is_quiet:
                self._print_output(color_output_file_name)

            self._add_results(test_suite, results, start_time, num_tests, output_file_name)

            if self._fail_fast and any_not_passed:
                self._abort = True
Beispiel #10
0
        lib = f"vhdl_{std}"
        ui.add_library(lib).add_source_files(ROOT / lib / "*.vhd")
    return ui


vhdl_standard = "2019" if SIMULATOR_FACTORY.select_simulator(
).name == "rivierapro" else "2008"
args = VUnitCLI().parse_args()
ui = vunit_from_args(args, vhdl_standard)

# Run all tests in isolation to handle failure to compile
args.minimal = True
original_test_patterns = args.test_patterns
test_report = TestReport()
n_tests = 0
total_start_time = ostools.get_time()
for tb in (ui.library("vhdl_2008").get_test_benches() +
           ui.library("vhdl_2019").get_test_benches()):
    tests = tb.get_tests()
    for test_name in [test.name for test in tests] if tests else ["all"]:
        full_test_name = f"{tb.library.name!s}.{tb.name!s}.{test_name!s}"
        if not reduce(
                lambda found_match, pattern: found_match | fnmatch(
                    full_test_name, pattern),
                original_test_patterns,
                False,
        ):
            continue

        test_start_time = ostools.get_time()
        n_tests += 1