From c4426fcb59e5dd1faef2900581966a199a592bf1 Mon Sep 17 00:00:00 2001 From: Patrick Lehmann Date: Sun, 27 Dec 2020 23:52:09 +0100 Subject: Added structure for unit tests for Python code. --- testsuite/pyunit/dom/Instantiate.py | 24 ++++++++++++++++++++++++ testsuite/pyunit/libghdl/Initialize.py | 20 ++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 testsuite/pyunit/dom/Instantiate.py create mode 100644 testsuite/pyunit/libghdl/Initialize.py (limited to 'testsuite/pyunit') diff --git a/testsuite/pyunit/dom/Instantiate.py b/testsuite/pyunit/dom/Instantiate.py new file mode 100644 index 000000000..c3509e39b --- /dev/null +++ b/testsuite/pyunit/dom/Instantiate.py @@ -0,0 +1,24 @@ +from pathlib import Path +from unittest import TestCase + +from pyVHDLModel.VHDLModel import Design, Library, Document, Entity + + +if __name__ == "__main__": + print("ERROR: you called a testcase declaration file as an executable module.") + print("Use: 'python -m unitest '") + exit(1) + +class Instantiate(TestCase): + def test_Design(self): + design = Design() + + def test_Library(self): + library = Library() + + def test_Document(self): + path = Path("tests.vhdl") + document = Document(path) + + def test_Entity(self): + entity = Entity("entity_1") diff --git a/testsuite/pyunit/libghdl/Initialize.py b/testsuite/pyunit/libghdl/Initialize.py new file mode 100644 index 000000000..b7e370650 --- /dev/null +++ b/testsuite/pyunit/libghdl/Initialize.py @@ -0,0 +1,20 @@ +from unittest import TestCase + + +if __name__ == "__main__": + print("ERROR: you called a testcase declaration file as an executable module.") + print("Use: 'python -m unitest '") + exit(1) + +class Instantiate(TestCase): + def test_InitializeGHDL(self): + pass + + def test_ReadSourceFile(self): + pass + + def test_ParseFile(self): + pass + + def test_ListDesignUnits(self): + pass -- cgit v1.2.3 From 0235203f927367e96e9486fff5d2cf4ed089223c Mon Sep 17 00:00:00 2001 From: Patrick Lehmann Date: Mon, 28 Dec 2020 00:01:42 +0100 Subject: Added requirements for Python test. --- testsuite/pyunit/dom/Instantiate.py | 1 + 1 file changed, 1 insertion(+) (limited to 'testsuite/pyunit') diff --git a/testsuite/pyunit/dom/Instantiate.py b/testsuite/pyunit/dom/Instantiate.py index c3509e39b..429c1a5a8 100644 --- a/testsuite/pyunit/dom/Instantiate.py +++ b/testsuite/pyunit/dom/Instantiate.py @@ -9,6 +9,7 @@ if __name__ == "__main__": print("Use: 'python -m unitest '") exit(1) + class Instantiate(TestCase): def test_Design(self): design = Design() -- cgit v1.2.3 From 713389ad5d939b8342da0119804a3dfeeb8c49de Mon Sep 17 00:00:00 2001 From: Patrick Lehmann Date: Mon, 28 Dec 2020 11:57:02 +0100 Subject: Translatest `python/units01` test to a unit test in Python. --- testsuite/pyunit/libghdl/Initialize.py | 77 ++++++++++++++++++++++++++---- testsuite/pyunit/libghdl/simpleEntity.vhdl | 26 ++++++++++ 2 files changed, 95 insertions(+), 8 deletions(-) create mode 100644 testsuite/pyunit/libghdl/simpleEntity.vhdl (limited to 'testsuite/pyunit') diff --git a/testsuite/pyunit/libghdl/Initialize.py b/testsuite/pyunit/libghdl/Initialize.py index b7e370650..7392f1efc 100644 --- a/testsuite/pyunit/libghdl/Initialize.py +++ b/testsuite/pyunit/libghdl/Initialize.py @@ -1,20 +1,81 @@ +from pathlib import Path +from typing import Any, NoReturn from unittest import TestCase +import libghdl +from libghdl.thin import name_table +from libghdl.thin import files_map +from libghdl.thin.vhdl import nodes +from libghdl.thin.vhdl import sem_lib +from libghdl.thin import errorout_console + if __name__ == "__main__": print("ERROR: you called a testcase declaration file as an executable module.") print("Use: 'python -m unitest '") exit(1) + class Instantiate(TestCase): - def test_InitializeGHDL(self): - pass + _filename : Path = Path("simpleEntity.vhdl") + _sfe: Any + _file: Any + + _continueTesting = True + + @staticmethod + def getIdentifier(node): + """Return the Python string from node :param:`node` identifier""" + return name_table.Get_Name_Ptr(nodes.Get_Identifier(node)).decode("utf-8") + + def setUp(self) -> None: + """Check for every test, if tests should continue.""" + if not self.__class__._continueTesting: + self.skipTest("No reason to go on.") + + def fail(self, msg: Any = ...) -> NoReturn: + self.__class__._continueTesting = False + super().fail(msg) + + def test_InitializeGHDL(self) -> None: + """Initialization: set options and then load libaries""" + + # Print error messages on the console. + errorout_console.Install_Handler() + + # Set options. This must be done before analyze_init() + libghdl.set_option(b"--std=08") + + # Finish initialization. This will load the standard package. + if libghdl.analyze_init_status() != 0: + self.fail("libghdl initialization error") + + def test_ReadSourceFile(self) -> None: + # Load the file + file_id = name_table.Get_Identifier(str(self._filename).encode("utf_8")) + self._sfe = files_map.Read_Source_File(name_table.Null_Identifier, file_id) + if self._sfe == files_map.No_Source_File_Entry: + self.fail("Cannot read file '{!s}'".format(self._filename)) + + def test_ParseFile(self) -> None: + # Parse + self._file = sem_lib.Load_File(self._sfe) + + def test_ListDesignUnits_WhileLoop(self) -> None: + # Display all design units + designUnit = nodes.Get_First_Design_Unit(self._file) + while designUnit != nodes.Null_Iir: + libraryUnit = nodes.Get_Library_Unit(designUnit) + + if nodes.Get_Kind(libraryUnit) == nodes.Iir_Kind.Entity_Declaration: + entityName = self.getIdentifier(libraryUnit) + self.assertTrue(entityName == "e1") - def test_ReadSourceFile(self): - pass + elif nodes.Get_Kind(libraryUnit) == nodes.Iir_Kind.Architecture_Body: + architectureName = self.getIdentifier(libraryUnit) + self.assertTrue(architectureName == "arch") - def test_ParseFile(self): - pass + else: + self.fail("Unknown unit.") - def test_ListDesignUnits(self): - pass + designUnit = nodes.Get_Chain(designUnit) diff --git a/testsuite/pyunit/libghdl/simpleEntity.vhdl b/testsuite/pyunit/libghdl/simpleEntity.vhdl new file mode 100644 index 000000000..bfcb0aceb --- /dev/null +++ b/testsuite/pyunit/libghdl/simpleEntity.vhdl @@ -0,0 +1,26 @@ +library ieee; +use ieee.numeric_std.all; + +entity e1 is + generic ( + BITS : positive = 8 + port ( + Clock: in std_logic; + Reset: in std_logic; + Q: out std_logic_vector(BITS - 1 downto 0) + ); +end entity e1; + +architecture behav of e1 is +begin + process(Clock) + begin + if rising_edge(Clock) then + if Reset = '1' then + Q <= (others => '0'); + else + Q <= std_logic_vector(unsigned(Q) + 1); + end if; + end if; + end process; +end architecture behav; -- cgit v1.2.3 From 77db544ae08ad40a307b6e9c76ff62cafdb21809 Mon Sep 17 00:00:00 2001 From: Patrick Lehmann Date: Mon, 28 Dec 2020 12:57:32 +0100 Subject: Merge sub tests into one test due to test case ordering and possible parallel execution. --- testsuite/pyunit/libghdl/Initialize.py | 31 +++++++----------------------- testsuite/pyunit/libghdl/simpleEntity.vhdl | 3 ++- 2 files changed, 9 insertions(+), 25 deletions(-) (limited to 'testsuite/pyunit') diff --git a/testsuite/pyunit/libghdl/Initialize.py b/testsuite/pyunit/libghdl/Initialize.py index 7392f1efc..1db2eed18 100644 --- a/testsuite/pyunit/libghdl/Initialize.py +++ b/testsuite/pyunit/libghdl/Initialize.py @@ -1,5 +1,4 @@ from pathlib import Path -from typing import Any, NoReturn from unittest import TestCase import libghdl @@ -17,26 +16,13 @@ if __name__ == "__main__": class Instantiate(TestCase): - _filename : Path = Path("simpleEntity.vhdl") - _sfe: Any - _file: Any - - _continueTesting = True + _filename : Path = Path("testsuite/pyunit/libghdl/simpleEntity.vhdl") @staticmethod def getIdentifier(node): """Return the Python string from node :param:`node` identifier""" return name_table.Get_Name_Ptr(nodes.Get_Identifier(node)).decode("utf-8") - def setUp(self) -> None: - """Check for every test, if tests should continue.""" - if not self.__class__._continueTesting: - self.skipTest("No reason to go on.") - - def fail(self, msg: Any = ...) -> NoReturn: - self.__class__._continueTesting = False - super().fail(msg) - def test_InitializeGHDL(self) -> None: """Initialization: set options and then load libaries""" @@ -50,30 +36,27 @@ class Instantiate(TestCase): if libghdl.analyze_init_status() != 0: self.fail("libghdl initialization error") - def test_ReadSourceFile(self) -> None: # Load the file file_id = name_table.Get_Identifier(str(self._filename).encode("utf_8")) - self._sfe = files_map.Read_Source_File(name_table.Null_Identifier, file_id) - if self._sfe == files_map.No_Source_File_Entry: + sfe = files_map.Read_Source_File(name_table.Null_Identifier, file_id) + if sfe == files_map.No_Source_File_Entry: self.fail("Cannot read file '{!s}'".format(self._filename)) - def test_ParseFile(self) -> None: # Parse - self._file = sem_lib.Load_File(self._sfe) + file = sem_lib.Load_File(sfe) - def test_ListDesignUnits_WhileLoop(self) -> None: # Display all design units - designUnit = nodes.Get_First_Design_Unit(self._file) + designUnit = nodes.Get_First_Design_Unit(file) while designUnit != nodes.Null_Iir: libraryUnit = nodes.Get_Library_Unit(designUnit) if nodes.Get_Kind(libraryUnit) == nodes.Iir_Kind.Entity_Declaration: entityName = self.getIdentifier(libraryUnit) - self.assertTrue(entityName == "e1") + self.assertEqual(entityName, "e1", "expected entity name 'e1', got '{}'".format(entityName)) elif nodes.Get_Kind(libraryUnit) == nodes.Iir_Kind.Architecture_Body: architectureName = self.getIdentifier(libraryUnit) - self.assertTrue(architectureName == "arch") + self.assertEqual(architectureName, "behav", "expected architecture name 'behav', got '{}'".format(architectureName)) else: self.fail("Unknown unit.") diff --git a/testsuite/pyunit/libghdl/simpleEntity.vhdl b/testsuite/pyunit/libghdl/simpleEntity.vhdl index bfcb0aceb..a26a6357c 100644 --- a/testsuite/pyunit/libghdl/simpleEntity.vhdl +++ b/testsuite/pyunit/libghdl/simpleEntity.vhdl @@ -3,7 +3,8 @@ use ieee.numeric_std.all; entity e1 is generic ( - BITS : positive = 8 + BITS : positive := 8 + ); port ( Clock: in std_logic; Reset: in std_logic; -- cgit v1.2.3 From 7f703bfbb31f24c84d0b224aeb3613692bddf214 Mon Sep 17 00:00:00 2001 From: Patrick Lehmann Date: Mon, 28 Dec 2020 18:15:03 +0100 Subject: Renamed testcase to SimpleEntity. --- testsuite/pyunit/SimpleEntity.vhdl | 27 +++++++++++++++++++++++++++ testsuite/pyunit/dom/Instantiate.py | 25 ------------------------- testsuite/pyunit/dom/SimpleEntity.py | 25 +++++++++++++++++++++++++ testsuite/pyunit/libghdl/simpleEntity.vhdl | 27 --------------------------- 4 files changed, 52 insertions(+), 52 deletions(-) create mode 100644 testsuite/pyunit/SimpleEntity.vhdl delete mode 100644 testsuite/pyunit/dom/Instantiate.py create mode 100644 testsuite/pyunit/dom/SimpleEntity.py delete mode 100644 testsuite/pyunit/libghdl/simpleEntity.vhdl (limited to 'testsuite/pyunit') diff --git a/testsuite/pyunit/SimpleEntity.vhdl b/testsuite/pyunit/SimpleEntity.vhdl new file mode 100644 index 000000000..a26a6357c --- /dev/null +++ b/testsuite/pyunit/SimpleEntity.vhdl @@ -0,0 +1,27 @@ +library ieee; +use ieee.numeric_std.all; + +entity e1 is + generic ( + BITS : positive := 8 + ); + port ( + Clock: in std_logic; + Reset: in std_logic; + Q: out std_logic_vector(BITS - 1 downto 0) + ); +end entity e1; + +architecture behav of e1 is +begin + process(Clock) + begin + if rising_edge(Clock) then + if Reset = '1' then + Q <= (others => '0'); + else + Q <= std_logic_vector(unsigned(Q) + 1); + end if; + end if; + end process; +end architecture behav; diff --git a/testsuite/pyunit/dom/Instantiate.py b/testsuite/pyunit/dom/Instantiate.py deleted file mode 100644 index 429c1a5a8..000000000 --- a/testsuite/pyunit/dom/Instantiate.py +++ /dev/null @@ -1,25 +0,0 @@ -from pathlib import Path -from unittest import TestCase - -from pyVHDLModel.VHDLModel import Design, Library, Document, Entity - - -if __name__ == "__main__": - print("ERROR: you called a testcase declaration file as an executable module.") - print("Use: 'python -m unitest '") - exit(1) - - -class Instantiate(TestCase): - def test_Design(self): - design = Design() - - def test_Library(self): - library = Library() - - def test_Document(self): - path = Path("tests.vhdl") - document = Document(path) - - def test_Entity(self): - entity = Entity("entity_1") diff --git a/testsuite/pyunit/dom/SimpleEntity.py b/testsuite/pyunit/dom/SimpleEntity.py new file mode 100644 index 000000000..429c1a5a8 --- /dev/null +++ b/testsuite/pyunit/dom/SimpleEntity.py @@ -0,0 +1,25 @@ +from pathlib import Path +from unittest import TestCase + +from pyVHDLModel.VHDLModel import Design, Library, Document, Entity + + +if __name__ == "__main__": + print("ERROR: you called a testcase declaration file as an executable module.") + print("Use: 'python -m unitest '") + exit(1) + + +class Instantiate(TestCase): + def test_Design(self): + design = Design() + + def test_Library(self): + library = Library() + + def test_Document(self): + path = Path("tests.vhdl") + document = Document(path) + + def test_Entity(self): + entity = Entity("entity_1") diff --git a/testsuite/pyunit/libghdl/simpleEntity.vhdl b/testsuite/pyunit/libghdl/simpleEntity.vhdl deleted file mode 100644 index a26a6357c..000000000 --- a/testsuite/pyunit/libghdl/simpleEntity.vhdl +++ /dev/null @@ -1,27 +0,0 @@ -library ieee; -use ieee.numeric_std.all; - -entity e1 is - generic ( - BITS : positive := 8 - ); - port ( - Clock: in std_logic; - Reset: in std_logic; - Q: out std_logic_vector(BITS - 1 downto 0) - ); -end entity e1; - -architecture behav of e1 is -begin - process(Clock) - begin - if rising_edge(Clock) then - if Reset = '1' then - Q <= (others => '0'); - else - Q <= std_logic_vector(unsigned(Q) + 1); - end if; - end if; - end process; -end architecture behav; -- cgit v1.2.3 From 1c912a59c73a1ecb4c8b4d5d16bfc097d63d8546 Mon Sep 17 00:00:00 2001 From: Patrick Lehmann Date: Mon, 28 Dec 2020 18:17:24 +0100 Subject: Improved testcase ' SimpleEntity' for pyGHDL.dom. --- testsuite/pyunit/dom/SimpleEntity.py | 28 +++++++++++++++++++++------- testsuite/pyunit/libghdl/Initialize.py | 2 +- 2 files changed, 22 insertions(+), 8 deletions(-) (limited to 'testsuite/pyunit') diff --git a/testsuite/pyunit/dom/SimpleEntity.py b/testsuite/pyunit/dom/SimpleEntity.py index 429c1a5a8..046d5ceff 100644 --- a/testsuite/pyunit/dom/SimpleEntity.py +++ b/testsuite/pyunit/dom/SimpleEntity.py @@ -1,7 +1,8 @@ from pathlib import Path from unittest import TestCase -from pyVHDLModel.VHDLModel import Design, Library, Document, Entity +from pyGHDL.dom.Misc import Design, Library, Document +from pyGHDL.dom.DesignUnit import Entity, Architecture if __name__ == "__main__": @@ -10,16 +11,29 @@ if __name__ == "__main__": exit(1) -class Instantiate(TestCase): +class SimpleEntity(TestCase): + _path: Path = Path("testsuite/pyunit/SimpleEntity.vhdl") + def test_Design(self): design = Design() - def test_Library(self): - library = Library() + self.assertIsNotNone(design) + + # def test_Library(self): + # library = Library() def test_Document(self): - path = Path("tests.vhdl") - document = Document(path) + design = Design() + document = Document(self._path) + design.Documents.append(document) + + self.assertTrue(len(design.Documents) == 1) def test_Entity(self): - entity = Entity("entity_1") + design = Design() + document = Document(self._path) + design.Documents.append(document) + + self.assertEqual(len(design.Documents[0].Entities), 1) + self.assertTrue(design.Documents[0].Entities[0].Name == "e1") + diff --git a/testsuite/pyunit/libghdl/Initialize.py b/testsuite/pyunit/libghdl/Initialize.py index 1db2eed18..8bbc0e954 100644 --- a/testsuite/pyunit/libghdl/Initialize.py +++ b/testsuite/pyunit/libghdl/Initialize.py @@ -16,7 +16,7 @@ if __name__ == "__main__": class Instantiate(TestCase): - _filename : Path = Path("testsuite/pyunit/libghdl/simpleEntity.vhdl") + _filename : Path = Path("testsuite/pyunit/SimpleEntity.vhdl") @staticmethod def getIdentifier(node): -- cgit v1.2.3 From 42a1c81bbd4759dc50dfec089be35cb69c2ab088 Mon Sep 17 00:00:00 2001 From: Patrick Lehmann Date: Mon, 28 Dec 2020 18:24:47 +0100 Subject: Added testsuites so all Python unit tests can be run with a single command. --- testsuite/pyunit/__init__.py | 12 ++++++++++++ testsuite/pyunit/dom/__init__.py | 10 ++++++++++ testsuite/pyunit/libghdl/__init__.py | 10 ++++++++++ 3 files changed, 32 insertions(+) create mode 100644 testsuite/pyunit/__init__.py create mode 100644 testsuite/pyunit/dom/__init__.py create mode 100644 testsuite/pyunit/libghdl/__init__.py (limited to 'testsuite/pyunit') diff --git a/testsuite/pyunit/__init__.py b/testsuite/pyunit/__init__.py new file mode 100644 index 000000000..b73f051d4 --- /dev/null +++ b/testsuite/pyunit/__init__.py @@ -0,0 +1,12 @@ +from unittest import TestSuite + +from testsuite.pyunit import libghdl, dom + + +def load_tests(loader, testCases, pattern): + suite = TestSuite() + + suite.addTests(loader.loadTestsFromModule(libghdl)) + suite.addTests(loader.loadTestsFromModule(dom)) + + return suite diff --git a/testsuite/pyunit/dom/__init__.py b/testsuite/pyunit/dom/__init__.py new file mode 100644 index 000000000..768810d72 --- /dev/null +++ b/testsuite/pyunit/dom/__init__.py @@ -0,0 +1,10 @@ +from unittest import TestSuite + +from testsuite.pyunit.dom import SimpleEntity + +def load_tests(loader, testCases, pattern): + suite = TestSuite() + + suite.addTests(loader.loadTestsFromModule(SimpleEntity)) + + return suite diff --git a/testsuite/pyunit/libghdl/__init__.py b/testsuite/pyunit/libghdl/__init__.py new file mode 100644 index 000000000..24ce9e704 --- /dev/null +++ b/testsuite/pyunit/libghdl/__init__.py @@ -0,0 +1,10 @@ +from unittest import TestSuite + +from testsuite.pyunit.libghdl import Initialize + +def load_tests(loader, testCases, pattern): + suite = TestSuite() + + suite.addTests(loader.loadTestsFromModule(Initialize)) + + return suite -- cgit v1.2.3 From e5db6a80cf34db4b5ec84d8bd159fef837184e78 Mon Sep 17 00:00:00 2001 From: Patrick Lehmann Date: Mon, 28 Dec 2020 19:03:39 +0100 Subject: Added a test for Architectures. --- testsuite/pyunit/dom/SimpleEntity.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'testsuite/pyunit') diff --git a/testsuite/pyunit/dom/SimpleEntity.py b/testsuite/pyunit/dom/SimpleEntity.py index 046d5ceff..a8caf9e6f 100644 --- a/testsuite/pyunit/dom/SimpleEntity.py +++ b/testsuite/pyunit/dom/SimpleEntity.py @@ -2,7 +2,6 @@ from pathlib import Path from unittest import TestCase from pyGHDL.dom.Misc import Design, Library, Document -from pyGHDL.dom.DesignUnit import Entity, Architecture if __name__ == "__main__": @@ -37,3 +36,10 @@ class SimpleEntity(TestCase): self.assertEqual(len(design.Documents[0].Entities), 1) self.assertTrue(design.Documents[0].Entities[0].Name == "e1") + def test_Architecture(self): + design = Design() + document = Document(self._path) + design.Documents.append(document) + + self.assertEqual(len(design.Documents[0].Architectures), 1) + self.assertTrue(design.Documents[0].Architectures[0].Name == "behav") -- cgit v1.2.3 From f35dee7cd0c8e1a8a5dc856e502a92cab4640964 Mon Sep 17 00:00:00 2001 From: Patrick Lehmann Date: Mon, 28 Dec 2020 21:50:49 +0100 Subject: Removed outdated files. --- testsuite/pyunit/SimplePackage.vhdl | 21 +++++++++++++++ testsuite/pyunit/testsuite.sh | 53 +++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 testsuite/pyunit/SimplePackage.vhdl create mode 100644 testsuite/pyunit/testsuite.sh (limited to 'testsuite/pyunit') diff --git a/testsuite/pyunit/SimplePackage.vhdl b/testsuite/pyunit/SimplePackage.vhdl new file mode 100644 index 000000000..f06cc32fa --- /dev/null +++ b/testsuite/pyunit/SimplePackage.vhdl @@ -0,0 +1,21 @@ +library ieee; +use ieee.numeric_std.all + +package pack_1 is + constant const_1 : boolean; + + type matrix is array(natural range <>, natural range <>) of std_logic; + + subtype matrix8x8 is matrix(7 downto 0, 7 downto 0); + + function func1(value : unsigned) return natural; +end package; + +package body pack_1 is + constant const_1 : boolean := true; + + function func1(value : unsigned) return natural is + begin + return to_integer(value); + end function; +end package body; diff --git a/testsuite/pyunit/testsuite.sh b/testsuite/pyunit/testsuite.sh new file mode 100644 index 000000000..12b367f2c --- /dev/null +++ b/testsuite/pyunit/testsuite.sh @@ -0,0 +1,53 @@ +#! /bin/sh + +# Driver for a testsuite. + +set -e + +# This is the only place where test dirs are specified. Do not duplicate this +# line +dirs="*[0-9]" + +failures="" +full=n + +for opt; do + case "$opt" in + -k | --keep-going) full=y ;; + --dir=*) dirs=`echo $opt | sed -e 's/--dir=//'` ;; + --skip=*) d=`echo $opt | sed -e 's/--skip=//'` + dirs=`echo "" $dirs | sed -e "s/ $d//"` ;; + --start-at=*) d=`echo $opt | sed -e 's/--start-at=//'` + dirs=`echo "" $dirs | sed -e "s/^.* $d//"` + dirs="$d $dirs" ;; + --list-tests) echo $dirs; exit 0;; + *) echo "Unknown option $opt" + exit 2 + ;; + esac +done + +singlerun() { + echo "" + echo "dir $1:" + cd $1 + if ! ./testsuite.sh; then + echo "#################################################################" + echo "######### FAILURE: $1" + echo "#################################################################" + if [ $2 = "y" ]; then + failures="$failures $1" + else + exit 1; + fi + fi + cd .. +} + +for i in $dirs; do singlerun $i $full; done + +if [ x"$failures" = x"" ]; then + echo "tests are successful" && exit 0 +else + echo "test failed ($failures)" && exit 1 +fi -- cgit v1.2.3 From f940ff13f5aad6b2253017413182f80544546218 Mon Sep 17 00:00:00 2001 From: umarcor Date: Mon, 28 Dec 2020 20:49:18 +0100 Subject: merge testsuite/python into testsuite/pyunit --- testsuite/pyunit/testsuite.sh | 57 +++++++++++++++++ testsuite/pyunit/units01/demo.vhdl | 12 ++++ testsuite/pyunit/units01/show_ports.py | 111 +++++++++++++++++++++++++++++++++ testsuite/pyunit/units01/show_units.py | 55 ++++++++++++++++ testsuite/pyunit/units01/testsuite.sh | 11 ++++ 5 files changed, 246 insertions(+) create mode 100755 testsuite/pyunit/testsuite.sh create mode 100644 testsuite/pyunit/units01/demo.vhdl create mode 100644 testsuite/pyunit/units01/show_ports.py create mode 100755 testsuite/pyunit/units01/show_units.py create mode 100755 testsuite/pyunit/units01/testsuite.sh (limited to 'testsuite/pyunit') diff --git a/testsuite/pyunit/testsuite.sh b/testsuite/pyunit/testsuite.sh new file mode 100755 index 000000000..56cfdec01 --- /dev/null +++ b/testsuite/pyunit/testsuite.sh @@ -0,0 +1,57 @@ +#! /bin/sh + +# Driver for a testsuite. + +set -e + +# This is the only place where test dirs are specified. Do not duplicate this +# line +#dirs="*[0-9]" +# +#failures="" +#full=n +# +#for opt; do +# case "$opt" in +# -k | --keep-going) full=y ;; +# --dir=*) dirs=`echo $opt | sed -e 's/--dir=//'` ;; +# --skip=*) d=`echo $opt | sed -e 's/--skip=//'` +# dirs=`echo "" $dirs | sed -e "s/ $d//"` ;; +# --start-at=*) d=`echo $opt | sed -e 's/--start-at=//'` +# dirs=`echo "" $dirs | sed -e "s/^.* $d//"` +# dirs="$d $dirs" ;; +# --list-tests) echo $dirs; exit 0;; +# *) echo "Unknown option $opt" +# exit 2 +# ;; +# esac +#done +# +#singlerun() { +# echo "" +# echo "dir $1:" +# cd $1 +# if ! ./testsuite.sh; then +# echo "#################################################################" +# echo "######### FAILURE: $1" +# echo "#################################################################" +# if [ $2 = "y" ]; then +# failures="$failures $1" +# else +# exit 1; +# fi +# fi +# cd .. +#} +# +#for i in $dirs; do singlerun $i $full; done +# +#if [ x"$failures" = x"" ]; then +# echo "tests are successful" && exit 0 +#else +# echo "test failed ($failures)" && exit 1 +#fi + +cd $(dirname "$0") + +python -m unittest . diff --git a/testsuite/pyunit/units01/demo.vhdl b/testsuite/pyunit/units01/demo.vhdl new file mode 100644 index 000000000..ed98c936a --- /dev/null +++ b/testsuite/pyunit/units01/demo.vhdl @@ -0,0 +1,12 @@ +entity e1 is +port ( + CLK: in std_logic; + RST: in std_logic; + Q: out std_logic_vector(7 downto 0) +); +end e1; + +architecture behav of e1 is +begin + assert false report "arch" severity note; +end behav; diff --git a/testsuite/pyunit/units01/show_ports.py b/testsuite/pyunit/units01/show_ports.py new file mode 100644 index 000000000..a11f2acbd --- /dev/null +++ b/testsuite/pyunit/units01/show_ports.py @@ -0,0 +1,111 @@ +#!/usr/bin/env python +from sys import argv +from pathlib import Path + +import libghdl +from libghdl.thin import name_table +from libghdl.thin import files_map +from libghdl.thin.vhdl import nodes +from libghdl.thin.vhdl import sem_lib +from libghdl.thin.vhdl import pyutils +from libghdl.thin import errorout_console + + +def get_identifier_ptr(n): + """Return the python string from node :param n: identifier""" + return name_table.Get_Name_Ptr(nodes.Get_Identifier(n)).decode("utf-8") + + +def get_port_mode(port) -> str: + """Return the Mode of a port, as a string""" + mode = nodes.Get_Mode(port) + return ( + "in" + if mode == nodes.Iir_Mode.In_Mode + else "out" + if mode == nodes.Iir_Mode.Out_Mode + else "inout" + if mode == nodes.Iir_Mode.Inout_Mode + else "buffer" + if mode == nodes.Iir_Mode.Buffer_Mode + else "linkage" + if mode == nodes.Iir_Mode.Linkage_Mode + else "unknown" + ) + + +def get_port_type(port) -> str: + "Return the Type of a port, as a string" + subtype = nodes.Get_Subtype_Indication(port) + skind = nodes.Get_Kind(subtype) + + if skind == nodes.Iir_Kind.Simple_Name: + return get_identifier_ptr(subtype) + + if skind == nodes.Iir_Kind.Array_Subtype_Definition: + mark = get_identifier_ptr(nodes.Get_Subtype_Type_Mark(subtype)) + + for rng in pyutils.flist_iter(nodes.Get_Index_Constraint_List(subtype)): + if nodes.Get_Kind(rng) == nodes.Iir_Kind.Range_Expression: + return "%s(%d %s %d)" % ( + mark, + nodes.Get_Value(nodes.Get_Left_Limit_Expr(rng)), + "downto" if nodes.Get_Direction(rng) else "to", + nodes.Get_Value(nodes.Get_Right_Limit_Expr(rng)), + ) + return "UNSUPPORTED array_subtype_definition" + + return "UNSUPPORTED" + + +def list_units(filename): + # Load the file + file_id = name_table.Get_Identifier(filename.encode("utf_8")) + sfe = files_map.Read_Source_File(name_table.Null_Identifier, file_id) + if sfe == files_map.No_Source_File_Entry: + print("cannot open file '%s'" % filename) + return + + # Parse + file = sem_lib.Load_File(sfe) + + # Display all design units + unit = nodes.Get_First_Design_Unit(file) + while unit != nodes.Null_Iir: + lib_unit = nodes.Get_Library_Unit(unit) + if nodes.Get_Kind(lib_unit) == nodes.Iir_Kind.Entity_Declaration: + print(" - entity %s" % get_identifier_ptr(lib_unit)) + for port in pyutils.chain_iter(nodes.Get_Port_Chain(lib_unit)): + print( + " * %s %s %s" + % ( + get_identifier_ptr(port), + get_port_mode(port), + get_port_type(port), + ) + ) + elif nodes.Get_Kind(lib_unit) == nodes.Iir_Kind.Architecture_Body: + print( + " - architecture %s of %s" + % ( + get_identifier_ptr(lib_unit), + get_identifier_ptr(nodes.Get_Entity_Name(lib_unit)), + ) + ) + else: + print("unknown unit!") + unit = nodes.Get_Chain(unit) + + +if __name__ == "__main__": + # Initialization: set options and then load libaries + errorout_console.Install_Handler() + libghdl.set_option(b"--std=08") + if libghdl.analyze_init_status() != 0: + raise Exception("libghdl initialization error") + + # Recursively find and parse all the files with extension *.vhdl + if len(argv) > 1: + for file in Path(argv[1]).glob("**/*.vhdl"): + print("· %s" % file) + list_units(str(file)) diff --git a/testsuite/pyunit/units01/show_units.py b/testsuite/pyunit/units01/show_units.py new file mode 100755 index 000000000..43baf9aed --- /dev/null +++ b/testsuite/pyunit/units01/show_units.py @@ -0,0 +1,55 @@ +#!/usr/bin/env python +import libghdl +from libghdl.thin import name_table +from libghdl.thin import files_map +from libghdl.thin.vhdl import nodes +from libghdl.thin.vhdl import sem_lib +from libghdl.thin import errorout_console + + +def init(): + """Initialization: set options and then load libaries""" + # Print error messages on the console + errorout_console.Install_Handler() + # Set options. This must be done before analyze_init() + libghdl.set_option(b"--std=08") + # Finish initialization. This will load the standard package + if libghdl.analyze_init_status() != 0: + raise Exception("libghdl initialization error") + +def get_identifier_ptr(n): + """Return the python string from node :param n: identifier""" + return name_table.Get_Name_Ptr(nodes.Get_Identifier(n)).decode("utf-8") + + +def list_units(filename): + # Load the file + file_id = name_table.Get_Identifier(filename.encode("utf_8")) + sfe = files_map.Read_Source_File(name_table.Null_Identifier, file_id) + if sfe == files_map.No_Source_File_Entry: + print("cannot open file '%s'" % filename) + return + + # Parse + file = sem_lib.Load_File(sfe) + + # Display all design units + unit = nodes.Get_First_Design_Unit(file) + while unit != nodes.Null_Iir: + lib_unit = nodes.Get_Library_Unit(unit) + if nodes.Get_Kind(lib_unit) == nodes.Iir_Kind.Entity_Declaration: + print("entity %s" % get_identifier_ptr(lib_unit)) + elif nodes.Get_Kind(lib_unit) == nodes.Iir_Kind.Architecture_Body: + print("architecture %s" % get_identifier_ptr(lib_unit)) + else: + print("unknown unit!") + unit = nodes.Get_Chain(unit) + + +def main(): + init() + list_units("demo.vhdl") + + +if __name__ == "__main__": + main() diff --git a/testsuite/pyunit/units01/testsuite.sh b/testsuite/pyunit/units01/testsuite.sh new file mode 100755 index 000000000..f45d12ac3 --- /dev/null +++ b/testsuite/pyunit/units01/testsuite.sh @@ -0,0 +1,11 @@ +#! /bin/sh + +. ../../testenv.sh + +$PYTHON show_units.py + +echo "" + +$PYTHON show_ports.py ./ + +echo "Test successful" -- cgit v1.2.3 From 147375c38a56820595df54047ad904cdc21d94ec Mon Sep 17 00:00:00 2001 From: umarcor Date: Mon, 28 Dec 2020 20:49:18 +0100 Subject: merge testsuite/python into testsuite/pyunit --- testsuite/pyunit/testsuite.sh | 57 +++++++++++++++++ testsuite/pyunit/units01/demo.vhdl | 12 ++++ testsuite/pyunit/units01/show_ports.py | 111 +++++++++++++++++++++++++++++++++ testsuite/pyunit/units01/show_units.py | 55 ++++++++++++++++ testsuite/pyunit/units01/testsuite.sh | 11 ++++ 5 files changed, 246 insertions(+) create mode 100755 testsuite/pyunit/testsuite.sh create mode 100644 testsuite/pyunit/units01/demo.vhdl create mode 100644 testsuite/pyunit/units01/show_ports.py create mode 100755 testsuite/pyunit/units01/show_units.py create mode 100755 testsuite/pyunit/units01/testsuite.sh (limited to 'testsuite/pyunit') diff --git a/testsuite/pyunit/testsuite.sh b/testsuite/pyunit/testsuite.sh new file mode 100755 index 000000000..7eac028ca --- /dev/null +++ b/testsuite/pyunit/testsuite.sh @@ -0,0 +1,57 @@ +#! /bin/sh + +# Driver for a testsuite. + +set -e + +# This is the only place where test dirs are specified. Do not duplicate this +# line +#dirs="*[0-9]" +# +#failures="" +#full=n +# +#for opt; do +# case "$opt" in +# -k | --keep-going) full=y ;; +# --dir=*) dirs=`echo $opt | sed -e 's/--dir=//'` ;; +# --skip=*) d=`echo $opt | sed -e 's/--skip=//'` +# dirs=`echo "" $dirs | sed -e "s/ $d//"` ;; +# --start-at=*) d=`echo $opt | sed -e 's/--start-at=//'` +# dirs=`echo "" $dirs | sed -e "s/^.* $d//"` +# dirs="$d $dirs" ;; +# --list-tests) echo $dirs; exit 0;; +# *) echo "Unknown option $opt" +# exit 2 +# ;; +# esac +#done +# +#singlerun() { +# echo "" +# echo "dir $1:" +# cd $1 +# if ! ./testsuite.sh; then +# echo "#################################################################" +# echo "######### FAILURE: $1" +# echo "#################################################################" +# if [ $2 = "y" ]; then +# failures="$failures $1" +# else +# exit 1; +# fi +# fi +# cd .. +#} +# +#for i in $dirs; do singlerun $i $full; done +# +#if [ x"$failures" = x"" ]; then +# echo "tests are successful" && exit 0 +#else +# echo "test failed ($failures)" && exit 1 +#fi + +cd $(dirname "$0")/.. + +python3 -m unittest pyunit diff --git a/testsuite/pyunit/units01/demo.vhdl b/testsuite/pyunit/units01/demo.vhdl new file mode 100644 index 000000000..ed98c936a --- /dev/null +++ b/testsuite/pyunit/units01/demo.vhdl @@ -0,0 +1,12 @@ +entity e1 is +port ( + CLK: in std_logic; + RST: in std_logic; + Q: out std_logic_vector(7 downto 0) +); +end e1; + +architecture behav of e1 is +begin + assert false report "arch" severity note; +end behav; diff --git a/testsuite/pyunit/units01/show_ports.py b/testsuite/pyunit/units01/show_ports.py new file mode 100644 index 000000000..a11f2acbd --- /dev/null +++ b/testsuite/pyunit/units01/show_ports.py @@ -0,0 +1,111 @@ +#!/usr/bin/env python +from sys import argv +from pathlib import Path + +import libghdl +from libghdl.thin import name_table +from libghdl.thin import files_map +from libghdl.thin.vhdl import nodes +from libghdl.thin.vhdl import sem_lib +from libghdl.thin.vhdl import pyutils +from libghdl.thin import errorout_console + + +def get_identifier_ptr(n): + """Return the python string from node :param n: identifier""" + return name_table.Get_Name_Ptr(nodes.Get_Identifier(n)).decode("utf-8") + + +def get_port_mode(port) -> str: + """Return the Mode of a port, as a string""" + mode = nodes.Get_Mode(port) + return ( + "in" + if mode == nodes.Iir_Mode.In_Mode + else "out" + if mode == nodes.Iir_Mode.Out_Mode + else "inout" + if mode == nodes.Iir_Mode.Inout_Mode + else "buffer" + if mode == nodes.Iir_Mode.Buffer_Mode + else "linkage" + if mode == nodes.Iir_Mode.Linkage_Mode + else "unknown" + ) + + +def get_port_type(port) -> str: + "Return the Type of a port, as a string" + subtype = nodes.Get_Subtype_Indication(port) + skind = nodes.Get_Kind(subtype) + + if skind == nodes.Iir_Kind.Simple_Name: + return get_identifier_ptr(subtype) + + if skind == nodes.Iir_Kind.Array_Subtype_Definition: + mark = get_identifier_ptr(nodes.Get_Subtype_Type_Mark(subtype)) + + for rng in pyutils.flist_iter(nodes.Get_Index_Constraint_List(subtype)): + if nodes.Get_Kind(rng) == nodes.Iir_Kind.Range_Expression: + return "%s(%d %s %d)" % ( + mark, + nodes.Get_Value(nodes.Get_Left_Limit_Expr(rng)), + "downto" if nodes.Get_Direction(rng) else "to", + nodes.Get_Value(nodes.Get_Right_Limit_Expr(rng)), + ) + return "UNSUPPORTED array_subtype_definition" + + return "UNSUPPORTED" + + +def list_units(filename): + # Load the file + file_id = name_table.Get_Identifier(filename.encode("utf_8")) + sfe = files_map.Read_Source_File(name_table.Null_Identifier, file_id) + if sfe == files_map.No_Source_File_Entry: + print("cannot open file '%s'" % filename) + return + + # Parse + file = sem_lib.Load_File(sfe) + + # Display all design units + unit = nodes.Get_First_Design_Unit(file) + while unit != nodes.Null_Iir: + lib_unit = nodes.Get_Library_Unit(unit) + if nodes.Get_Kind(lib_unit) == nodes.Iir_Kind.Entity_Declaration: + print(" - entity %s" % get_identifier_ptr(lib_unit)) + for port in pyutils.chain_iter(nodes.Get_Port_Chain(lib_unit)): + print( + " * %s %s %s" + % ( + get_identifier_ptr(port), + get_port_mode(port), + get_port_type(port), + ) + ) + elif nodes.Get_Kind(lib_unit) == nodes.Iir_Kind.Architecture_Body: + print( + " - architecture %s of %s" + % ( + get_identifier_ptr(lib_unit), + get_identifier_ptr(nodes.Get_Entity_Name(lib_unit)), + ) + ) + else: + print("unknown unit!") + unit = nodes.Get_Chain(unit) + + +if __name__ == "__main__": + # Initialization: set options and then load libaries + errorout_console.Install_Handler() + libghdl.set_option(b"--std=08") + if libghdl.analyze_init_status() != 0: + raise Exception("libghdl initialization error") + + # Recursively find and parse all the files with extension *.vhdl + if len(argv) > 1: + for file in Path(argv[1]).glob("**/*.vhdl"): + print("· %s" % file) + list_units(str(file)) diff --git a/testsuite/pyunit/units01/show_units.py b/testsuite/pyunit/units01/show_units.py new file mode 100755 index 000000000..43baf9aed --- /dev/null +++ b/testsuite/pyunit/units01/show_units.py @@ -0,0 +1,55 @@ +#!/usr/bin/env python +import libghdl +from libghdl.thin import name_table +from libghdl.thin import files_map +from libghdl.thin.vhdl import nodes +from libghdl.thin.vhdl import sem_lib +from libghdl.thin import errorout_console + + +def init(): + """Initialization: set options and then load libaries""" + # Print error messages on the console + errorout_console.Install_Handler() + # Set options. This must be done before analyze_init() + libghdl.set_option(b"--std=08") + # Finish initialization. This will load the standard package + if libghdl.analyze_init_status() != 0: + raise Exception("libghdl initialization error") + +def get_identifier_ptr(n): + """Return the python string from node :param n: identifier""" + return name_table.Get_Name_Ptr(nodes.Get_Identifier(n)).decode("utf-8") + + +def list_units(filename): + # Load the file + file_id = name_table.Get_Identifier(filename.encode("utf_8")) + sfe = files_map.Read_Source_File(name_table.Null_Identifier, file_id) + if sfe == files_map.No_Source_File_Entry: + print("cannot open file '%s'" % filename) + return + + # Parse + file = sem_lib.Load_File(sfe) + + # Display all design units + unit = nodes.Get_First_Design_Unit(file) + while unit != nodes.Null_Iir: + lib_unit = nodes.Get_Library_Unit(unit) + if nodes.Get_Kind(lib_unit) == nodes.Iir_Kind.Entity_Declaration: + print("entity %s" % get_identifier_ptr(lib_unit)) + elif nodes.Get_Kind(lib_unit) == nodes.Iir_Kind.Architecture_Body: + print("architecture %s" % get_identifier_ptr(lib_unit)) + else: + print("unknown unit!") + unit = nodes.Get_Chain(unit) + + +def main(): + init() + list_units("demo.vhdl") + + +if __name__ == "__main__": + main() diff --git a/testsuite/pyunit/units01/testsuite.sh b/testsuite/pyunit/units01/testsuite.sh new file mode 100755 index 000000000..f45d12ac3 --- /dev/null +++ b/testsuite/pyunit/units01/testsuite.sh @@ -0,0 +1,11 @@ +#! /bin/sh + +. ../../testenv.sh + +$PYTHON show_units.py + +echo "" + +$PYTHON show_ports.py ./ + +echo "Test successful" -- cgit v1.2.3 From d5b65813b36bf0e179d514ebd872a8b4f5cc79e7 Mon Sep 17 00:00:00 2001 From: Patrick Lehmann Date: Mon, 28 Dec 2020 23:53:07 +0100 Subject: Allow execution of tests within testsuite. --- testsuite/pyunit/__init__.py | 6 ++++-- testsuite/pyunit/dom/__init__.py | 5 ++++- testsuite/pyunit/libghdl/Initialize.py | 4 ++-- testsuite/pyunit/libghdl/__init__.py | 5 ++++- 4 files changed, 14 insertions(+), 6 deletions(-) (limited to 'testsuite/pyunit') diff --git a/testsuite/pyunit/__init__.py b/testsuite/pyunit/__init__.py index b73f051d4..eff53eb2f 100644 --- a/testsuite/pyunit/__init__.py +++ b/testsuite/pyunit/__init__.py @@ -1,7 +1,9 @@ from unittest import TestSuite -from testsuite.pyunit import libghdl, dom - +try: + from testsuite.pyunit import libghdl, dom +except ModuleNotFoundError: + from pyunit import libghdl, dom def load_tests(loader, testCases, pattern): suite = TestSuite() diff --git a/testsuite/pyunit/dom/__init__.py b/testsuite/pyunit/dom/__init__.py index 768810d72..9c103eb6a 100644 --- a/testsuite/pyunit/dom/__init__.py +++ b/testsuite/pyunit/dom/__init__.py @@ -1,6 +1,9 @@ from unittest import TestSuite -from testsuite.pyunit.dom import SimpleEntity +try: + from testsuite.pyunit.dom import SimpleEntity +except ModuleNotFoundError: + from pyunit.dom import SimpleEntity def load_tests(loader, testCases, pattern): suite = TestSuite() diff --git a/testsuite/pyunit/libghdl/Initialize.py b/testsuite/pyunit/libghdl/Initialize.py index 8bbc0e954..fb7196e7c 100644 --- a/testsuite/pyunit/libghdl/Initialize.py +++ b/testsuite/pyunit/libghdl/Initialize.py @@ -33,8 +33,8 @@ class Instantiate(TestCase): libghdl.set_option(b"--std=08") # Finish initialization. This will load the standard package. - if libghdl.analyze_init_status() != 0: - self.fail("libghdl initialization error") +# if libghdl.analyze_init_status() != 0: +# self.fail("libghdl initialization error") # Load the file file_id = name_table.Get_Identifier(str(self._filename).encode("utf_8")) diff --git a/testsuite/pyunit/libghdl/__init__.py b/testsuite/pyunit/libghdl/__init__.py index 24ce9e704..4aeab3ec3 100644 --- a/testsuite/pyunit/libghdl/__init__.py +++ b/testsuite/pyunit/libghdl/__init__.py @@ -1,6 +1,9 @@ from unittest import TestSuite -from testsuite.pyunit.libghdl import Initialize +try: + from testsuite.pyunit.libghdl import Initialize +except ModuleNotFoundError: + from pyunit.libghdl import Initialize def load_tests(loader, testCases, pattern): suite = TestSuite() -- cgit v1.2.3 From 9e991938ae1f0ad188ce33f73c51b1c9d4354589 Mon Sep 17 00:00:00 2001 From: Patrick Lehmann Date: Tue, 29 Dec 2020 00:26:19 +0100 Subject: Made path to VHDL files relative to the testcase. --- testsuite/pyunit/dom/SimpleEntity.py | 9 +++++---- testsuite/pyunit/libghdl/Initialize.py | 3 ++- 2 files changed, 7 insertions(+), 5 deletions(-) (limited to 'testsuite/pyunit') diff --git a/testsuite/pyunit/dom/SimpleEntity.py b/testsuite/pyunit/dom/SimpleEntity.py index a8caf9e6f..2f65c9813 100644 --- a/testsuite/pyunit/dom/SimpleEntity.py +++ b/testsuite/pyunit/dom/SimpleEntity.py @@ -11,7 +11,8 @@ if __name__ == "__main__": class SimpleEntity(TestCase): - _path: Path = Path("testsuite/pyunit/SimpleEntity.vhdl") + _root = Path(__file__).resolve().parent.parent + _filename : Path = _root / "SimpleEntity.vhdl" def test_Design(self): design = Design() @@ -23,14 +24,14 @@ class SimpleEntity(TestCase): def test_Document(self): design = Design() - document = Document(self._path) + document = Document(self._filename) design.Documents.append(document) self.assertTrue(len(design.Documents) == 1) def test_Entity(self): design = Design() - document = Document(self._path) + document = Document(self._filename) design.Documents.append(document) self.assertEqual(len(design.Documents[0].Entities), 1) @@ -38,7 +39,7 @@ class SimpleEntity(TestCase): def test_Architecture(self): design = Design() - document = Document(self._path) + document = Document(self._filename) design.Documents.append(document) self.assertEqual(len(design.Documents[0].Architectures), 1) diff --git a/testsuite/pyunit/libghdl/Initialize.py b/testsuite/pyunit/libghdl/Initialize.py index fb7196e7c..90692760c 100644 --- a/testsuite/pyunit/libghdl/Initialize.py +++ b/testsuite/pyunit/libghdl/Initialize.py @@ -16,7 +16,8 @@ if __name__ == "__main__": class Instantiate(TestCase): - _filename : Path = Path("testsuite/pyunit/SimpleEntity.vhdl") + _root = Path(__file__).resolve().parent.parent + _filename : Path = _root / "SimpleEntity.vhdl" @staticmethod def getIdentifier(node): -- cgit v1.2.3 From d855ec403d4e6cb7d88d58c9a54f7a157a7d02fe Mon Sep 17 00:00:00 2001 From: umarcor Date: Tue, 29 Dec 2020 00:27:07 +0100 Subject: testuite: run pyunit from the root of the repo --- testsuite/pyunit/testsuite.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'testsuite/pyunit') diff --git a/testsuite/pyunit/testsuite.sh b/testsuite/pyunit/testsuite.sh index 7eac028ca..6f363bc9b 100755 --- a/testsuite/pyunit/testsuite.sh +++ b/testsuite/pyunit/testsuite.sh @@ -52,6 +52,6 @@ set -e # echo "test failed ($failures)" && exit 1 #fi -cd $(dirname "$0")/.. +cd $(dirname "$0")/../.. -python3 -m unittest pyunit +python3 -m unittest testsuite.pyunit -- cgit v1.2.3 From 403ce633036dc9611c78fc5a0460ea7b856bd848 Mon Sep 17 00:00:00 2001 From: umarcor Date: Tue, 29 Dec 2020 00:31:59 +0100 Subject: testuite/pyunit: set PYTHONPATH --- testsuite/pyunit/testsuite.sh | 2 ++ 1 file changed, 2 insertions(+) (limited to 'testsuite/pyunit') diff --git a/testsuite/pyunit/testsuite.sh b/testsuite/pyunit/testsuite.sh index 6f363bc9b..3de4b3951 100755 --- a/testsuite/pyunit/testsuite.sh +++ b/testsuite/pyunit/testsuite.sh @@ -54,4 +54,6 @@ set -e cd $(dirname "$0")/../.. +export PYTHONPATH=$(pwd)/pyGHDL + python3 -m unittest testsuite.pyunit -- cgit v1.2.3 From 71a7c3b1102b888f0560de64d9efaa48d8a3738f Mon Sep 17 00:00:00 2001 From: Patrick Lehmann Date: Tue, 29 Dec 2020 00:46:41 +0100 Subject: Fixed package names in pyGHDL.dom and Initialize test case. --- testsuite/pyunit/libghdl/Initialize.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'testsuite/pyunit') diff --git a/testsuite/pyunit/libghdl/Initialize.py b/testsuite/pyunit/libghdl/Initialize.py index 90692760c..7ad00a995 100644 --- a/testsuite/pyunit/libghdl/Initialize.py +++ b/testsuite/pyunit/libghdl/Initialize.py @@ -1,12 +1,9 @@ -from pathlib import Path -from unittest import TestCase - -import libghdl -from libghdl.thin import name_table -from libghdl.thin import files_map -from libghdl.thin.vhdl import nodes -from libghdl.thin.vhdl import sem_lib -from libghdl.thin import errorout_console +from pathlib import Path +from unittest import TestCase + +import pyGHDL.libghdl as libghdl +from pyGHDL.libghdl import name_table, files_map, errorout_console +from pyGHDL.libghdl.vhdl import nodes, sem_lib if __name__ == "__main__": -- cgit v1.2.3 From 1c38bc3933ba4e469811c5898b9aeae896e23afc Mon Sep 17 00:00:00 2001 From: umarcor Date: Tue, 29 Dec 2020 02:40:13 +0100 Subject: pyGHDL/libghdl: fix absolute imports --- testsuite/pyunit/testsuite.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'testsuite/pyunit') diff --git a/testsuite/pyunit/testsuite.sh b/testsuite/pyunit/testsuite.sh index 3de4b3951..6a36bb0a6 100755 --- a/testsuite/pyunit/testsuite.sh +++ b/testsuite/pyunit/testsuite.sh @@ -54,6 +54,6 @@ set -e cd $(dirname "$0")/../.. -export PYTHONPATH=$(pwd)/pyGHDL +export PYTHONPATH=$(pwd) python3 -m unittest testsuite.pyunit -- cgit v1.2.3 From dbc0651008b4becac90450038c0f31d590bddbfc Mon Sep 17 00:00:00 2001 From: umarcor Date: Tue, 29 Dec 2020 03:06:42 +0100 Subject: testsuite: rm pyunit/testsuite.sh --- testsuite/pyunit/testsuite.sh | 59 ------------------------------------------- 1 file changed, 59 deletions(-) delete mode 100755 testsuite/pyunit/testsuite.sh (limited to 'testsuite/pyunit') diff --git a/testsuite/pyunit/testsuite.sh b/testsuite/pyunit/testsuite.sh deleted file mode 100755 index 6a36bb0a6..000000000 --- a/testsuite/pyunit/testsuite.sh +++ /dev/null @@ -1,59 +0,0 @@ -#! /bin/sh - -# Driver for a testsuite. - -set -e - -# This is the only place where test dirs are specified. Do not duplicate this -# line -#dirs="*[0-9]" -# -#failures="" -#full=n -# -#for opt; do -# case "$opt" in -# -k | --keep-going) full=y ;; -# --dir=*) dirs=`echo $opt | sed -e 's/--dir=//'` ;; -# --skip=*) d=`echo $opt | sed -e 's/--skip=//'` -# dirs=`echo "" $dirs | sed -e "s/ $d//"` ;; -# --start-at=*) d=`echo $opt | sed -e 's/--start-at=//'` -# dirs=`echo "" $dirs | sed -e "s/^.* $d//"` -# dirs="$d $dirs" ;; -# --list-tests) echo $dirs; exit 0;; -# *) echo "Unknown option $opt" -# exit 2 -# ;; -# esac -#done -# -#singlerun() { -# echo "" -# echo "dir $1:" -# cd $1 -# if ! ./testsuite.sh; then -# echo "#################################################################" -# echo "######### FAILURE: $1" -# echo "#################################################################" -# if [ $2 = "y" ]; then -# failures="$failures $1" -# else -# exit 1; -# fi -# fi -# cd .. -#} -# -#for i in $dirs; do singlerun $i $full; done -# -#if [ x"$failures" = x"" ]; then -# echo "tests are successful" && exit 0 -#else -# echo "test failed ($failures)" && exit 1 -#fi - -cd $(dirname "$0")/../.. - -export PYTHONPATH=$(pwd) - -python3 -m unittest testsuite.pyunit -- cgit v1.2.3 From 98054aaf2a21d3fab0fbaff4d347048d0d507413 Mon Sep 17 00:00:00 2001 From: Patrick Lehmann Date: Tue, 29 Dec 2020 09:56:33 +0100 Subject: Activated 'analyze_init_status' in Python code. --- testsuite/pyunit/libghdl/Initialize.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'testsuite/pyunit') diff --git a/testsuite/pyunit/libghdl/Initialize.py b/testsuite/pyunit/libghdl/Initialize.py index 7ad00a995..0a46fe8b4 100644 --- a/testsuite/pyunit/libghdl/Initialize.py +++ b/testsuite/pyunit/libghdl/Initialize.py @@ -31,8 +31,8 @@ class Instantiate(TestCase): libghdl.set_option(b"--std=08") # Finish initialization. This will load the standard package. -# if libghdl.analyze_init_status() != 0: -# self.fail("libghdl initialization error") + if libghdl.analyze_init_status() != 0: + self.fail("libghdl initialization error") # Load the file file_id = name_table.Get_Identifier(str(self._filename).encode("utf_8")) -- cgit v1.2.3