Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create sim_if and test submodules #582

Merged
merged 5 commits into from
Nov 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/cli.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

Command Line Interface
======================
A :class:`VUnit <vunit.ui.vunit.VUnit>` object can be created from command
A :class:`VUnit <vunit.ui.VUnit>` object can be created from command
line arguments by using the :meth:`from_argv
<vunit.ui.vunit.VUnit.from_argv>` method effectively creating a custom
<vunit.ui.VUnit.from_argv>` method effectively creating a custom
command line tool for running tests in the user project. Source files
and libraries are added to the project by using methods on the VUnit
object. The configuration is followed by a call to the :meth:`main
<vunit.ui.vunit.VUnit.main>` method which will execute the function
<vunit.ui.VUnit.main>` method which will execute the function
specified by the command line arguments and exit the script. The added
source files are automatically scanned for test cases.

Expand Down
2 changes: 1 addition & 1 deletion docs/installing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Start by cloning our `GIT repository on GitHub <https://github.com/vunit/vunit/>

The ``--recursive`` option initializes `OSVVM <https://github.com/JimLewis/OSVVM>`__ which is included as a submodule in the VUnit repository.

To be able to import :class:`VUnit <vunit.ui.vunit.VUnit>` in your ``run.py`` script
To be able to import :class:`VUnit <vunit.ui.VUnit>` in your ``run.py`` script
you need to make it visible to Python or else the following error
occurs.

Expand Down
2 changes: 1 addition & 1 deletion docs/py/ui.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Python Interface
================
The Python interface of VUnit is exposed through the :class:`VUnit
class <vunit.ui.vunit.VUnit>` that can be imported directly. See the
class <vunit.ui.VUnit>` that can be imported directly. See the
:ref:`User Guide <user_guide>` for a quick introduction. The
following list provides detailed references of the Python API and
about how to set compilation and simulation options.
Expand Down
4 changes: 2 additions & 2 deletions docs/py/vunit.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
vunit.ui.vunit
vunit.ui
==============

.. autoclass:: vunit.ui.vunit.VUnit()
.. autoclass:: vunit.ui.VUnit()
:exclude-members: add_preprocessor,
add_builtins

Expand Down
8 changes: 5 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,16 @@ def find_all_files(directory, endings=None):
name="vunit_hdl",
version=version(),
packages=[
"tests",
"tests.lint",
"tests.unit",
"tests.acceptance",
"vunit",
"vunit.com",
"vunit.parsing",
"vunit.parsing.verilog",
"vunit.sim_if",
"vunit.test",
"vunit.test.lint",
"vunit.test.unit",
"vunit.test.acceptance",
"vunit.ui",
"vunit.vivado",
],
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ begin
end procedure;
begin
test_runner_setup(runner, runner_cfg);
check_has_suffix(tb_path, "/vunit/test/acceptance/artificial/vhdl/");
check_has_suffix(vunit_lib.run_pkg.tb_path(runner_cfg), "/vunit/test/acceptance/artificial/vhdl/");
check_has_suffix(tb_path, "/tests/acceptance/artificial/vhdl/");
check_has_suffix(vunit_lib.run_pkg.tb_path(runner_cfg), "/tests/acceptance/artificial/vhdl/");
test_runner_cleanup(runner);
wait;
end process;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
Acceptance test of VUnit end to end functionality
"""


import unittest
from os.path import join, dirname
from os import environ
from subprocess import call
import sys
from vunit.test.common import has_simulator, check_report, simulator_is
from tests.common import check_report
from vunit.sim_if.common import has_simulator, simulator_is


@unittest.skipUnless(has_simulator(), "Requires simulator")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
Verify that all external run scripts work correctly
"""


import unittest
from os import environ
from os.path import join, dirname
from subprocess import call
import sys
from tests.common import check_report
from vunit import ROOT
from vunit.builtins import VHDL_PATH
from vunit.test.common import has_simulator, check_report, simulator_is, simulator_check
from vunit.sim_if.common import has_simulator, simulator_is, simulator_check


def simulator_supports_verilog():
Expand Down
26 changes: 0 additions & 26 deletions vunit/test/common.py → tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,12 @@
Common functions re-used between test cases
"""


from xml.etree import ElementTree
import contextlib
import functools
import os
import shutil
import random
from vunit.simulator_factory import SIMULATOR_FACTORY


def has_simulator():
return SIMULATOR_FACTORY.has_simulator


def simulator_is(*names):
"""
Check that current simulator is any of names
"""
supported_names = [sim.name for sim in SIMULATOR_FACTORY.supported_simulators()]
for name in names:
assert name in supported_names
return SIMULATOR_FACTORY.select_simulator().name in names


def simulator_check(func):
"""
Check some method of the selected simulator
"""
simif = SIMULATOR_FACTORY.select_simulator()
if simif is None:
return False
return func(simif)


def check_report(report_file, tests=None):
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from subprocess import check_call
from os.path import join, dirname
import sys
from vunit.test.lint.test_pycodestyle import get_files_and_folders
from tests.lint.test_pycodestyle import get_files_and_folders


class TestPylint(unittest.TestCase):
Expand Down
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions tests/unit/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
#
# Copyright (c) 2014-2019, Lars Asplund [email protected]
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
from os.path import join, dirname, exists
import os
from shutil import rmtree
from vunit.activehdl_interface import ActiveHDLInterface
from vunit.test.mock_2or3 import mock
from tests.mock_2or3 import mock
from vunit.sim_if.activehdl import ActiveHDLInterface
from vunit.project import Project
from vunit.ostools import renew_path, write_file
from vunit.vhdl_standard import VHDL
Expand All @@ -25,10 +25,8 @@ class TestActiveHDLInterface(unittest.TestCase):
Test the ActiveHDL interface
"""

@mock.patch(
"vunit.simulator_interface.check_output", autospec=True, return_value=""
)
@mock.patch("vunit.activehdl_interface.Process", autospec=True)
@mock.patch("vunit.sim_if.check_output", autospec=True, return_value="")
@mock.patch("vunit.sim_if.activehdl.Process", autospec=True)
def test_compile_project_vhdl_2008(self, process, check_output):
simif = ActiveHDLInterface(prefix="prefix", output_path=self.output_path)
project = Project()
Expand Down Expand Up @@ -62,10 +60,8 @@ def test_compile_project_vhdl_2008(self, process, check_output):
env=simif.get_env(),
)

@mock.patch(
"vunit.simulator_interface.check_output", autospec=True, return_value=""
)
@mock.patch("vunit.activehdl_interface.Process", autospec=True)
@mock.patch("vunit.sim_if.check_output", autospec=True, return_value="")
@mock.patch("vunit.sim_if.activehdl.Process", autospec=True)
def test_compile_project_vhdl_2002(self, process, check_output):
simif = ActiveHDLInterface(prefix="prefix", output_path=self.output_path)
project = Project()
Expand Down Expand Up @@ -99,10 +95,8 @@ def test_compile_project_vhdl_2002(self, process, check_output):
env=simif.get_env(),
)

@mock.patch(
"vunit.simulator_interface.check_output", autospec=True, return_value=""
)
@mock.patch("vunit.activehdl_interface.Process", autospec=True)
@mock.patch("vunit.sim_if.check_output", autospec=True, return_value="")
@mock.patch("vunit.sim_if.activehdl.Process", autospec=True)
def test_compile_project_vhdl_93(self, process, check_output):
simif = ActiveHDLInterface(prefix="prefix", output_path=self.output_path)
project = Project()
Expand Down Expand Up @@ -136,10 +130,8 @@ def test_compile_project_vhdl_93(self, process, check_output):
env=simif.get_env(),
)

@mock.patch(
"vunit.simulator_interface.check_output", autospec=True, return_value=""
)
@mock.patch("vunit.activehdl_interface.Process", autospec=True)
@mock.patch("vunit.sim_if.check_output", autospec=True, return_value="")
@mock.patch("vunit.sim_if.activehdl.Process", autospec=True)
def test_compile_project_vhdl_extra_flags(self, process, check_output):
simif = ActiveHDLInterface(prefix="prefix", output_path=self.output_path)
project = Project()
Expand Down Expand Up @@ -174,10 +166,8 @@ def test_compile_project_vhdl_extra_flags(self, process, check_output):
env=simif.get_env(),
)

@mock.patch(
"vunit.simulator_interface.check_output", autospec=True, return_value=""
)
@mock.patch("vunit.activehdl_interface.Process", autospec=True)
@mock.patch("vunit.sim_if.check_output", autospec=True, return_value="")
@mock.patch("vunit.sim_if.activehdl.Process", autospec=True)
def test_compile_project_verilog(self, process, check_output):
library_cfg = join(self.output_path, "library.cfg")
simif = ActiveHDLInterface(prefix="prefix", output_path=self.output_path)
Expand Down Expand Up @@ -211,10 +201,8 @@ def test_compile_project_verilog(self, process, check_output):
env=simif.get_env(),
)

@mock.patch(
"vunit.simulator_interface.check_output", autospec=True, return_value=""
)
@mock.patch("vunit.activehdl_interface.Process", autospec=True)
@mock.patch("vunit.sim_if.check_output", autospec=True, return_value="")
@mock.patch("vunit.sim_if.activehdl.Process", autospec=True)
def test_compile_project_system_verilog(self, process, check_output):
library_cfg = join(self.output_path, "library.cfg")
simif = ActiveHDLInterface(prefix="prefix", output_path=self.output_path)
Expand Down Expand Up @@ -248,10 +236,8 @@ def test_compile_project_system_verilog(self, process, check_output):
env=simif.get_env(),
)

@mock.patch(
"vunit.simulator_interface.check_output", autospec=True, return_value=""
)
@mock.patch("vunit.activehdl_interface.Process", autospec=True)
@mock.patch("vunit.sim_if.check_output", autospec=True, return_value="")
@mock.patch("vunit.sim_if.activehdl.Process", autospec=True)
def test_compile_project_verilog_extra_flags(self, process, check_output):
library_cfg = join(self.output_path, "library.cfg")
simif = ActiveHDLInterface(prefix="prefix", output_path=self.output_path)
Expand Down Expand Up @@ -288,10 +274,8 @@ def test_compile_project_verilog_extra_flags(self, process, check_output):
env=simif.get_env(),
)

@mock.patch(
"vunit.simulator_interface.check_output", autospec=True, return_value=""
)
@mock.patch("vunit.activehdl_interface.Process", autospec=True)
@mock.patch("vunit.sim_if.check_output", autospec=True, return_value="")
@mock.patch("vunit.sim_if.activehdl.Process", autospec=True)
def test_compile_project_verilog_include(self, process, check_output):
library_cfg = join(self.output_path, "library.cfg")
simif = ActiveHDLInterface(prefix="prefix", output_path=self.output_path)
Expand Down Expand Up @@ -328,10 +312,8 @@ def test_compile_project_verilog_include(self, process, check_output):
env=simif.get_env(),
)

@mock.patch(
"vunit.simulator_interface.check_output", autospec=True, return_value=""
)
@mock.patch("vunit.activehdl_interface.Process", autospec=True)
@mock.patch("vunit.sim_if.check_output", autospec=True, return_value="")
@mock.patch("vunit.sim_if.activehdl.Process", autospec=True)
def test_compile_project_verilog_define(self, process, check_output):
library_cfg = join(self.output_path, "library.cfg")
simif = ActiveHDLInterface(prefix="prefix", output_path=self.output_path)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"""

import unittest
from vunit.test.mock_2or3 import mock
from tests.mock_2or3 import mock
from vunit.builtins import BuiltinsAdder


Expand Down
10 changes: 6 additions & 4 deletions vunit/test/unit/test_cds_file.py → tests/unit/test_cds_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"""

import unittest
from vunit.test.mock_2or3 import mock
from vunit.cds_file import CDSFile
from tests.mock_2or3 import mock
from vunit.sim_if.cds_file import CDSFile


class TestCDSFile(unittest.TestCase):
Expand Down Expand Up @@ -90,15 +90,17 @@ def _create_cds_file(contents):
"""
Create a CDSFile object with 'contents'
"""
with mock.patch("vunit.cds_file.read_file", autospec=True) as read_file:
with mock.patch("vunit.sim_if.cds_file.read_file", autospec=True) as read_file:
read_file.return_value = contents
return CDSFile.parse("file_name")

def _check_written_as(self, cds, contents):
"""
Check that the CDSFile object writes the 'contents to the file
"""
with mock.patch("vunit.cds_file.write_file", autospec=True) as write_file:
with mock.patch(
"vunit.sim_if.cds_file.write_file", autospec=True
) as write_file:
cds.write("filename")
self.assertEqual(len(write_file.mock_calls), 1)
args = write_file.mock_calls[0][1]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
import unittest
import contextlib
from os.path import join
from tests.mock_2or3 import mock
from tests.common import with_tempdir, create_tempdir
from tests.unit.test_test_bench import Entity
from vunit.configuration import Configuration, AttributeException
from vunit.test.mock_2or3 import mock
from vunit.test.common import with_tempdir, create_tempdir
from vunit.test.unit.test_test_bench import Entity


class TestConfiguration(unittest.TestCase):
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

import unittest
from os.path import join
from tests.common import with_tempdir
from vunit.database import DataBase, PickledDataBase
from vunit.test.common import with_tempdir


class TestDataBase(unittest.TestCase):
Expand Down
Loading