From 33afa7ab5f114988b2079305f0cb53cc3e04b672 Mon Sep 17 00:00:00 2001 From: umarcor Date: Sat, 7 Sep 2019 18:20:14 +0200 Subject: [PATCH 1/3] fix(egs): ensure that VUnit is not executed when docs are built --- examples/verilog/uart/run.py | 15 +++++----- examples/verilog/user_guide/run.py | 8 +++--- examples/verilog/verilog_ams/run.py | 10 +++---- examples/vhdl/array/run.py | 14 ++++----- examples/vhdl/array_axis_vcs/run.py | 18 ++++++------ examples/vhdl/axi_dma/run.py | 16 +++++------ examples/vhdl/check/run.py | 20 ++++++------- examples/vhdl/com/run.py | 18 ++++++------ examples/vhdl/composite_generics/run.py | 24 ++++++++-------- examples/vhdl/coverage/run.py | 22 +++++++------- examples/vhdl/generate_tests/run.py | 30 ++++++++++---------- examples/vhdl/json4vhdl/run.py | 16 +++++------ examples/vhdl/logging/run.py | 8 +++--- examples/vhdl/run/run.py | 12 ++++---- examples/vhdl/third_party_integration/run.py | 9 +++--- examples/vhdl/uart/run.py | 18 ++++++------ examples/vhdl/user_guide/run.py | 8 +++--- examples/vhdl/vivado/run.py | 17 +++++------ 18 files changed, 143 insertions(+), 140 deletions(-) diff --git a/examples/verilog/uart/run.py b/examples/verilog/uart/run.py index a92f92ee1..947984da5 100644 --- a/examples/verilog/uart/run.py +++ b/examples/verilog/uart/run.py @@ -15,15 +15,16 @@ from os.path import join, dirname from vunit.verilog import VUnit -ui = VUnit.from_argv() -src_path = join(dirname(__file__), "src") +if __name__ == '__main__': + ui = VUnit.from_argv() -uart_lib = ui.add_library("uart_lib") -uart_lib.add_source_files(join(src_path, "*.sv")) + src_path = join(dirname(__file__), "src") -tb_uart_lib = ui.add_library("tb_uart_lib") -tb_uart_lib.add_source_files(join(src_path, "test", "*.sv")) + uart_lib = ui.add_library("uart_lib") + uart_lib.add_source_files(join(src_path, "*.sv")) + + tb_uart_lib = ui.add_library("tb_uart_lib") + tb_uart_lib.add_source_files(join(src_path, "test", "*.sv")) -if __name__ == '__main__': ui.main() diff --git a/examples/verilog/user_guide/run.py b/examples/verilog/user_guide/run.py index 6e9f8564c..1ef6d9b92 100644 --- a/examples/verilog/user_guide/run.py +++ b/examples/verilog/user_guide/run.py @@ -17,9 +17,9 @@ root = dirname(__file__) -ui = VUnit.from_argv() -lib = ui.add_library("lib") -lib.add_source_files(join(root, "*.sv")) - if __name__ == '__main__': + ui = VUnit.from_argv() + lib = ui.add_library("lib") + lib.add_source_files(join(root, "*.sv")) + ui.main() diff --git a/examples/verilog/verilog_ams/run.py b/examples/verilog/verilog_ams/run.py index 800d4ed05..ca4f0e917 100644 --- a/examples/verilog/verilog_ams/run.py +++ b/examples/verilog/verilog_ams/run.py @@ -9,10 +9,10 @@ root = dirname(__file__) -ui = VUnit.from_argv() -lib = ui.add_library("lib") -lib.add_source_files(join(root, "*.sv")) -lib.add_source_files(join(root, "*.vams")).set_compile_option("modelsim.vlog_flags", ["-ams"]) - if __name__ == '__main__': + ui = VUnit.from_argv() + lib = ui.add_library("lib") + lib.add_source_files(join(root, "*.sv")) + lib.add_source_files(join(root, "*.vams")).set_compile_option("modelsim.vlog_flags", ["-ams"]) + ui.main() diff --git a/examples/vhdl/array/run.py b/examples/vhdl/array/run.py index 380b43df8..640167da5 100644 --- a/examples/vhdl/array/run.py +++ b/examples/vhdl/array/run.py @@ -18,12 +18,12 @@ root = dirname(__file__) -ui = VUnit.from_argv() -ui.add_osvvm() -ui.add_array_util() -lib = ui.add_library("lib") -lib.add_source_files(join(root, "src", "*.vhd")) -lib.add_source_files(join(root, "src", "test", "*.vhd")) - if __name__ == '__main__': + ui = VUnit.from_argv() + ui.add_osvvm() + ui.add_array_util() + lib = ui.add_library("lib") + lib.add_source_files(join(root, "src", "*.vhd")) + lib.add_source_files(join(root, "src", "test", "*.vhd")) + ui.main() diff --git a/examples/vhdl/array_axis_vcs/run.py b/examples/vhdl/array_axis_vcs/run.py index 27af6730d..60856f9a5 100644 --- a/examples/vhdl/array_axis_vcs/run.py +++ b/examples/vhdl/array_axis_vcs/run.py @@ -23,17 +23,17 @@ root = dirname(__file__) -vu = VUnit.from_argv() +if __name__ == '__main__': + vu = VUnit.from_argv() -vu.add_osvvm() -vu.add_array_util() -vu.add_verification_components() + vu.add_osvvm() + vu.add_array_util() + vu.add_verification_components() -lib = vu.add_library("lib") -lib.add_source_files(join(root, "src/*.vhd")) -lib.add_source_files(join(root, "src/**/*.vhd")) + lib = vu.add_library("lib") + lib.add_source_files(join(root, "src/*.vhd")) + lib.add_source_files(join(root, "src/**/*.vhd")) -# vu.set_sim_option('modelsim.init_files.after_load',['runall_addwave.do']) + # vu.set_sim_option('modelsim.init_files.after_load',['runall_addwave.do']) -if __name__ == '__main__': vu.main() diff --git a/examples/vhdl/axi_dma/run.py b/examples/vhdl/axi_dma/run.py index 41dbfeccb..7084fde25 100644 --- a/examples/vhdl/axi_dma/run.py +++ b/examples/vhdl/axi_dma/run.py @@ -18,15 +18,15 @@ from os.path import join, dirname from vunit import VUnit -ui = VUnit.from_argv() -ui.add_osvvm() -ui.add_verification_components() +if __name__ == '__main__': + ui = VUnit.from_argv() + ui.add_osvvm() + ui.add_verification_components() -src_path = join(dirname(__file__), "src") + src_path = join(dirname(__file__), "src") -axi_dma_lib = ui.add_library("axi_dma_lib") -axi_dma_lib.add_source_files(join(src_path, "*.vhd")) -axi_dma_lib.add_source_files(join(src_path, "test", "*.vhd")) + axi_dma_lib = ui.add_library("axi_dma_lib") + axi_dma_lib.add_source_files(join(src_path, "*.vhd")) + axi_dma_lib.add_source_files(join(src_path, "test", "*.vhd")) -if __name__ == '__main__': ui.main() diff --git a/examples/vhdl/check/run.py b/examples/vhdl/check/run.py index 4d7716c84..8d1f2d5f3 100644 --- a/examples/vhdl/check/run.py +++ b/examples/vhdl/check/run.py @@ -14,18 +14,18 @@ from os.path import join, dirname from vunit import VUnit -ui = VUnit.from_argv() +if __name__ == '__main__': + ui = VUnit.from_argv() -# Enable location preprocessing but exclude all but check_false to make the example less bloated -ui.enable_location_preprocessing( - exclude_subprograms=['debug', 'info', 'check', 'check_failed', 'check_true', 'check_implication', - 'check_stable', 'check_equal', 'check_not_unknown', 'check_zero_one_hot', - 'check_one_hot', 'check_next', 'check_sequence', 'check_relation']) + # Enable location preprocessing but exclude all but check_false to make the example less bloated + ui.enable_location_preprocessing( + exclude_subprograms=['debug', 'info', 'check', 'check_failed', 'check_true', 'check_implication', + 'check_stable', 'check_equal', 'check_not_unknown', 'check_zero_one_hot', + 'check_one_hot', 'check_next', 'check_sequence', 'check_relation']) -ui.enable_check_preprocessing() + ui.enable_check_preprocessing() -lib = ui.add_library("lib") -lib.add_source_files(join(dirname(__file__), "tb_example.vhd")) + lib = ui.add_library("lib") + lib.add_source_files(join(dirname(__file__), "tb_example.vhd")) -if __name__ == '__main__': ui.main() diff --git a/examples/vhdl/com/run.py b/examples/vhdl/com/run.py index 8712e0fb6..64c050891 100644 --- a/examples/vhdl/com/run.py +++ b/examples/vhdl/com/run.py @@ -16,16 +16,16 @@ from os.path import join, dirname from vunit import VUnit -prj = VUnit.from_argv() -prj.add_com() -prj.add_verification_components() -prj.add_osvvm() +if __name__ == '__main__': + prj = VUnit.from_argv() + prj.add_com() + prj.add_verification_components() + prj.add_osvvm() -lib = prj.add_library('lib') -lib.add_source_files(join(dirname(__file__), 'src', '*.vhd')) + lib = prj.add_library('lib') + lib.add_source_files(join(dirname(__file__), 'src', '*.vhd')) -tb_lib = prj.add_library('tb_lib') -tb_lib.add_source_files(join(dirname(__file__), 'test', '*.vhd')) + tb_lib = prj.add_library('tb_lib') + tb_lib.add_source_files(join(dirname(__file__), 'test', '*.vhd')) -if __name__ == '__main__': prj.main() diff --git a/examples/vhdl/composite_generics/run.py b/examples/vhdl/composite_generics/run.py index 5381339c1..bba083de7 100644 --- a/examples/vhdl/composite_generics/run.py +++ b/examples/vhdl/composite_generics/run.py @@ -14,24 +14,24 @@ from os.path import join, dirname from vunit import VUnit -prj = VUnit.from_argv() +if __name__ == '__main__': + prj = VUnit.from_argv() -tb_lib = prj.add_library('tb_lib') -tb_lib.add_source_files(join(dirname(__file__), 'test', '*.vhd')) + tb_lib = prj.add_library('tb_lib') + tb_lib.add_source_files(join(dirname(__file__), 'test', '*.vhd')) -testbench = tb_lib.test_bench("tb_composite_generics") -test_1 = testbench.test("Test 1") + testbench = tb_lib.test_bench("tb_composite_generics") + test_1 = testbench.test("Test 1") -def encode(tb_cfg): - return ", ".join(["%s:%s" % (key, str(tb_cfg[key])) for key in tb_cfg]) + def encode(tb_cfg): + return ", ".join(["%s:%s" % (key, str(tb_cfg[key])) for key in tb_cfg]) -vga_tb_cfg = dict(image_width=640, image_height=480, dump_debug_data=False) -test_1.add_config(name='VGA', generics=dict(encoded_tb_cfg=encode(vga_tb_cfg))) + vga_tb_cfg = dict(image_width=640, image_height=480, dump_debug_data=False) + test_1.add_config(name='VGA', generics=dict(encoded_tb_cfg=encode(vga_tb_cfg))) -tiny_tb_cfg = dict(image_width=4, image_height=3, dump_debug_data=True) -test_1.add_config(name='tiny', generics=dict(encoded_tb_cfg=encode(tiny_tb_cfg))) + tiny_tb_cfg = dict(image_width=4, image_height=3, dump_debug_data=True) + test_1.add_config(name='tiny', generics=dict(encoded_tb_cfg=encode(tiny_tb_cfg))) -if __name__ == '__main__': prj.main() diff --git a/examples/vhdl/coverage/run.py b/examples/vhdl/coverage/run.py index 6c42142e9..aee0f22de 100644 --- a/examples/vhdl/coverage/run.py +++ b/examples/vhdl/coverage/run.py @@ -9,18 +9,18 @@ root = dirname(__file__) -ui = VUnit.from_argv() -lib = ui.add_library("lib") -lib.add_source_files(join(root, "*.vhd")) +if __name__ == '__main__': + ui = VUnit.from_argv() + lib = ui.add_library("lib") + lib.add_source_files(join(root, "*.vhd")) -lib.set_compile_option("rivierapro.vcom_flags", ["-coverage", "bs"]) -lib.set_compile_option("rivierapro.vlog_flags", ["-coverage", "bs"]) -lib.set_compile_option("modelsim.vcom_flags", ["+cover=bs"]) -lib.set_compile_option("modelsim.vlog_flags", ["+cover=bs"]) -lib.set_sim_option("enable_coverage", True) + lib.set_compile_option("rivierapro.vcom_flags", ["-coverage", "bs"]) + lib.set_compile_option("rivierapro.vlog_flags", ["-coverage", "bs"]) + lib.set_compile_option("modelsim.vcom_flags", ["+cover=bs"]) + lib.set_compile_option("modelsim.vlog_flags", ["+cover=bs"]) + lib.set_sim_option("enable_coverage", True) -def post_run(results): - results.merge_coverage(file_name="coverage_data") + def post_run(results): + results.merge_coverage(file_name="coverage_data") -if __name__ == '__main__': ui.main(post_run=post_run) diff --git a/examples/vhdl/generate_tests/run.py b/examples/vhdl/generate_tests/run.py index 5fc5f1c5f..fdb6ab25b 100644 --- a/examples/vhdl/generate_tests/run.py +++ b/examples/vhdl/generate_tests/run.py @@ -63,23 +63,23 @@ def generate_tests(obj, signs, data_widths): test_path = join(dirname(__file__), "test") -ui = VUnit.from_argv() -lib = ui.add_library("lib") -lib.add_source_files(join(test_path, "*.vhd")) +if __name__ == '__main__': + ui = VUnit.from_argv() + lib = ui.add_library("lib") + lib.add_source_files(join(test_path, "*.vhd")) -tb_generated = lib.test_bench("tb_generated") + tb_generated = lib.test_bench("tb_generated") -# Just set a generic for all configurations within the test bench -tb_generated.set_generic("message", "set-for-entity") + # Just set a generic for all configurations within the test bench + tb_generated.set_generic("message", "set-for-entity") -for test in tb_generated.get_tests(): - if test.name == "Test 2": - # Test 2 should only be run with signed width of 16 - generate_tests(test, [True], [16]) - test.set_generic("message", "set-for-test") - else: - # Run all other tests with signed/unsigned and data width in range [1,5[ - generate_tests(test, [False, True], range(1, 5)) + for test in tb_generated.get_tests(): + if test.name == "Test 2": + # Test 2 should only be run with signed width of 16 + generate_tests(test, [True], [16]) + test.set_generic("message", "set-for-test") + else: + # Run all other tests with signed/unsigned and data width in range [1,5[ + generate_tests(test, [False, True], range(1, 5)) -if __name__ == '__main__': ui.main() diff --git a/examples/vhdl/json4vhdl/run.py b/examples/vhdl/json4vhdl/run.py index f7d755d50..cfb1bf9e0 100644 --- a/examples/vhdl/json4vhdl/run.py +++ b/examples/vhdl/json4vhdl/run.py @@ -18,16 +18,16 @@ root = dirname(__file__) -vu = VUnit.from_argv() +if __name__ == '__main__': + vu = VUnit.from_argv() -vu.add_json4vhdl() + vu.add_json4vhdl() -lib = vu.add_library("test") -lib.add_source_files(join(root, "src/test/*.vhd")) + lib = vu.add_library("test") + lib.add_source_files(join(root, "src/test/*.vhd")) -tb_cfg = read_json(join(root, "src/test/data/data.json")) -tb_cfg["dump_debug_data"]=False -vu.set_generic("tb_cfg", encode_json(tb_cfg)) + tb_cfg = read_json(join(root, "src/test/data/data.json")) + tb_cfg["dump_debug_data"]=False + vu.set_generic("tb_cfg", encode_json(tb_cfg)) -if __name__ == '__main__': vu.main() diff --git a/examples/vhdl/logging/run.py b/examples/vhdl/logging/run.py index d368e2125..b42bbc44d 100644 --- a/examples/vhdl/logging/run.py +++ b/examples/vhdl/logging/run.py @@ -14,9 +14,9 @@ from os.path import join, dirname from vunit import VUnit -ui = VUnit.from_argv() -lib = ui.add_library("lib") -lib.add_source_files(join(dirname(__file__), "*.vhd")) - if __name__ == '__main__': + ui = VUnit.from_argv() + lib = ui.add_library("lib") + lib.add_source_files(join(dirname(__file__), "*.vhd")) + ui.main() diff --git a/examples/vhdl/run/run.py b/examples/vhdl/run/run.py index 00790f2d1..b37f31f2a 100644 --- a/examples/vhdl/run/run.py +++ b/examples/vhdl/run/run.py @@ -16,11 +16,11 @@ root = dirname(__file__) -ui = VUnit.from_argv() -lib = ui.add_library("lib") -lib.add_source_files(join(root, "*.vhd")) -tb_with_lower_level_control = lib.entity("tb_with_lower_level_control") -tb_with_lower_level_control.scan_tests_from_file(join(root, "test_control.vhd")) - if __name__ == '__main__': + ui = VUnit.from_argv() + lib = ui.add_library("lib") + lib.add_source_files(join(root, "*.vhd")) + tb_with_lower_level_control = lib.entity("tb_with_lower_level_control") + tb_with_lower_level_control.scan_tests_from_file(join(root, "test_control.vhd")) + ui.main() diff --git a/examples/vhdl/third_party_integration/run.py b/examples/vhdl/third_party_integration/run.py index 99c420cd4..e16ce0b16 100644 --- a/examples/vhdl/third_party_integration/run.py +++ b/examples/vhdl/third_party_integration/run.py @@ -8,10 +8,11 @@ from vunit import VUnit root = dirname(__file__) -ui = VUnit.from_argv() - -lib = ui.add_library("lib") -lib.add_source_files(join(root, 'test', '*.vhd')) if __name__ == '__main__': + ui = VUnit.from_argv() + + lib = ui.add_library("lib") + lib.add_source_files(join(root, 'test', '*.vhd')) + ui.main() diff --git a/examples/vhdl/uart/run.py b/examples/vhdl/uart/run.py index 4c46f8c92..f56460c2f 100644 --- a/examples/vhdl/uart/run.py +++ b/examples/vhdl/uart/run.py @@ -15,17 +15,17 @@ from os.path import join, dirname from vunit import VUnit -ui = VUnit.from_argv() -ui.add_osvvm() -ui.add_verification_components() +if __name__ == '__main__': + ui = VUnit.from_argv() + ui.add_osvvm() + ui.add_verification_components() -src_path = join(dirname(__file__), "src") + src_path = join(dirname(__file__), "src") -uart_lib = ui.add_library("uart_lib") -uart_lib.add_source_files(join(src_path, "*.vhd")) + uart_lib = ui.add_library("uart_lib") + uart_lib.add_source_files(join(src_path, "*.vhd")) -tb_uart_lib = ui.add_library("tb_uart_lib") -tb_uart_lib.add_source_files(join(src_path, "test", "*.vhd")) + tb_uart_lib = ui.add_library("tb_uart_lib") + tb_uart_lib.add_source_files(join(src_path, "test", "*.vhd")) -if __name__ == '__main__': ui.main() diff --git a/examples/vhdl/user_guide/run.py b/examples/vhdl/user_guide/run.py index de6c1ef87..3c5af774f 100644 --- a/examples/vhdl/user_guide/run.py +++ b/examples/vhdl/user_guide/run.py @@ -17,9 +17,9 @@ root = dirname(__file__) -ui = VUnit.from_argv() -lib = ui.add_library("lib") -lib.add_source_files(join(root, "*.vhd")) - if __name__ == '__main__': + ui = VUnit.from_argv() + lib = ui.add_library("lib") + lib.add_source_files(join(root, "*.vhd")) + ui.main() diff --git a/examples/vhdl/vivado/run.py b/examples/vhdl/vivado/run.py index 08ad72bee..e2597c4f7 100644 --- a/examples/vhdl/vivado/run.py +++ b/examples/vhdl/vivado/run.py @@ -16,18 +16,19 @@ from vunit import VUnit from vivado_util import add_vivado_ip -ui = VUnit.from_argv() - root = dirname(__file__) -src_path = join(root, "src") -lib = ui.add_library("lib") -lib.add_source_files(join(src_path, "*.vhd")) +if __name__ == '__main__': + ui = VUnit.from_argv() -tb_lib = ui.add_library("tb_lib") -tb_lib.add_source_files(join(src_path, "test", "*.vhd")) + src_path = join(root, "src") + + lib = ui.add_library("lib") + lib.add_source_files(join(src_path, "*.vhd")) + + tb_lib = ui.add_library("tb_lib") + tb_lib.add_source_files(join(src_path, "test", "*.vhd")) -if __name__ == '__main__': add_vivado_ip(ui, output_path=join(root, "vivado_libs"), project_file=join(root, "myproject", "myproject.xpr")) From 3a251bcc4b4d9d82cfc74ee753de86af040c7c74 Mon Sep 17 00:00:00 2001 From: umarcor Date: Fri, 6 Sep 2019 07:36:07 +0200 Subject: [PATCH 2/3] fix: allow docs_utils to handle empty eg subdirs --- tools/docs_utils.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tools/docs_utils.py b/tools/docs_utils.py index d4d7f39a2..8e92ecc7d 100644 --- a/tools/docs_utils.py +++ b/tools/docs_utils.py @@ -8,9 +8,11 @@ Helper functions to generate examples.rst from docstrings in run.py files """ +from __future__ import print_function + import sys import inspect -from os.path import join, dirname, isdir +from os.path import basename, dirname, isdir, isfile, join from os import listdir @@ -38,16 +40,23 @@ def examples(): for item in listdir(join(eg_path, subdir)): loc = join(eg_path, subdir, item) if isdir(loc): - egs_fptr.write(_get_eg_doc( + _data = _get_eg_doc( loc, 'https://github.com/VUnit/vunit/tree/master/examples/%s/%s' % (subdir, item) - )) + ) + if _data: + egs_fptr.write(_data) def _get_eg_doc(location, ref): """ Reads the docstring from a run.py file and rewrites the title to make it a ref """ + if not isfile(join(location, 'run.py')): + print("Example subdir '" + basename(location) + "' does not contain a 'run.py' file. Skipping...") + return None + + print("Extracting docs from '" + basename(location) + "'...") sys.path.append(location) import run # pylint: disable=import-error vc_doc = inspect.getdoc(run) From 5e744ebcee5e5044099d645de7a809f5fbe0c235 Mon Sep 17 00:00:00 2001 From: umarcor Date: Tue, 10 Sep 2019 01:04:58 +0200 Subject: [PATCH 3/3] examples: simplify run.py scripts --- examples/verilog/uart/run.py | 16 +++---- examples/verilog/user_guide/run.py | 9 ++-- examples/verilog/verilog_ams/run.py | 11 +++-- examples/vhdl/array/run.py | 21 +++++---- examples/vhdl/array_axis_vcs/run.py | 22 +++++----- examples/vhdl/axi_dma/run.py | 18 ++++---- examples/vhdl/check/run.py | 20 ++++----- examples/vhdl/com/run.py | 18 +++----- examples/vhdl/composite_generics/run.py | 24 +++++----- examples/vhdl/coverage/run.py | 26 +++++------ examples/vhdl/generate_tests/run.py | 43 +++++++++--------- examples/vhdl/json4vhdl/run.py | 17 +++----- examples/vhdl/logging/run.py | 8 ++-- examples/vhdl/run/run.py | 14 +++--- examples/vhdl/third_party_integration/run.py | 12 ++--- examples/vhdl/uart/run.py | 18 +++----- examples/vhdl/user_guide/run.py | 11 ++--- examples/vhdl/vivado/run.py | 23 +++++----- tools/docs_utils.py | 46 +++++++++++++------- 19 files changed, 181 insertions(+), 196 deletions(-) diff --git a/examples/verilog/uart/run.py b/examples/verilog/uart/run.py index 947984da5..9df241494 100644 --- a/examples/verilog/uart/run.py +++ b/examples/verilog/uart/run.py @@ -15,16 +15,14 @@ from os.path import join, dirname from vunit.verilog import VUnit +vu = VUnit.from_argv() -if __name__ == '__main__': - ui = VUnit.from_argv() +src_path = join(dirname(__file__), "src") - src_path = join(dirname(__file__), "src") +uart_lib = vu.add_library("uart_lib") +uart_lib.add_source_files(join(src_path, "*.sv")) - uart_lib = ui.add_library("uart_lib") - uart_lib.add_source_files(join(src_path, "*.sv")) +tb_uart_lib = vu.add_library("tb_uart_lib") +tb_uart_lib.add_source_files(join(src_path, "test", "*.sv")) - tb_uart_lib = ui.add_library("tb_uart_lib") - tb_uart_lib.add_source_files(join(src_path, "test", "*.sv")) - - ui.main() +vu.main() diff --git a/examples/verilog/user_guide/run.py b/examples/verilog/user_guide/run.py index 1ef6d9b92..38ae89728 100644 --- a/examples/verilog/user_guide/run.py +++ b/examples/verilog/user_guide/run.py @@ -17,9 +17,8 @@ root = dirname(__file__) -if __name__ == '__main__': - ui = VUnit.from_argv() - lib = ui.add_library("lib") - lib.add_source_files(join(root, "*.sv")) +vu = VUnit.from_argv() +lib = vu.add_library("lib") +lib.add_source_files(join(root, "*.sv")) - ui.main() +vu.main() diff --git a/examples/verilog/verilog_ams/run.py b/examples/verilog/verilog_ams/run.py index ca4f0e917..209b98bae 100644 --- a/examples/verilog/verilog_ams/run.py +++ b/examples/verilog/verilog_ams/run.py @@ -9,10 +9,9 @@ root = dirname(__file__) -if __name__ == '__main__': - ui = VUnit.from_argv() - lib = ui.add_library("lib") - lib.add_source_files(join(root, "*.sv")) - lib.add_source_files(join(root, "*.vams")).set_compile_option("modelsim.vlog_flags", ["-ams"]) +vu = VUnit.from_argv() +lib = vu.add_library("lib") +lib.add_source_files(join(root, "*.sv")) +lib.add_source_files(join(root, "*.vams")).set_compile_option("modelsim.vlog_flags", ["-ams"]) - ui.main() +vu.main() diff --git a/examples/vhdl/array/run.py b/examples/vhdl/array/run.py index 640167da5..7aca3583c 100644 --- a/examples/vhdl/array/run.py +++ b/examples/vhdl/array/run.py @@ -18,12 +18,15 @@ root = dirname(__file__) -if __name__ == '__main__': - ui = VUnit.from_argv() - ui.add_osvvm() - ui.add_array_util() - lib = ui.add_library("lib") - lib.add_source_files(join(root, "src", "*.vhd")) - lib.add_source_files(join(root, "src", "test", "*.vhd")) - - ui.main() +vu = VUnit.from_argv() +vu.add_osvvm() +vu.add_array_util() + +src_path = join(dirname(__file__), 'src') + +vu.add_library('lib').add_source_files([ + join(src_path, '*.vhd'), + join(src_path, 'test', '*.vhd') +]) + +vu.main() diff --git a/examples/vhdl/array_axis_vcs/run.py b/examples/vhdl/array_axis_vcs/run.py index 60856f9a5..8c4d45776 100644 --- a/examples/vhdl/array_axis_vcs/run.py +++ b/examples/vhdl/array_axis_vcs/run.py @@ -21,19 +21,19 @@ from os.path import join, dirname from vunit import VUnit -root = dirname(__file__) +vu = VUnit.from_argv() -if __name__ == '__main__': - vu = VUnit.from_argv() +vu.add_osvvm() +vu.add_array_util() +vu.add_verification_components() - vu.add_osvvm() - vu.add_array_util() - vu.add_verification_components() +src_path = join(dirname(__file__), "src") - lib = vu.add_library("lib") - lib.add_source_files(join(root, "src/*.vhd")) - lib.add_source_files(join(root, "src/**/*.vhd")) +vu.add_library("lib").add_source_files([ + join(src_path, "*.vhd"), + join(src_path, "**", "*.vhd") +]) - # vu.set_sim_option('modelsim.init_files.after_load',['runall_addwave.do']) +# vu.set_sim_option('modelsim.init_files.after_load',['runall_addwave.do']) - vu.main() +vu.main() diff --git a/examples/vhdl/axi_dma/run.py b/examples/vhdl/axi_dma/run.py index 7084fde25..58a964c05 100644 --- a/examples/vhdl/axi_dma/run.py +++ b/examples/vhdl/axi_dma/run.py @@ -18,15 +18,15 @@ from os.path import join, dirname from vunit import VUnit -if __name__ == '__main__': - ui = VUnit.from_argv() - ui.add_osvvm() - ui.add_verification_components() +vu = VUnit.from_argv() +vu.add_osvvm() +vu.add_verification_components() - src_path = join(dirname(__file__), "src") +src_path = join(dirname(__file__), "src") - axi_dma_lib = ui.add_library("axi_dma_lib") - axi_dma_lib.add_source_files(join(src_path, "*.vhd")) - axi_dma_lib.add_source_files(join(src_path, "test", "*.vhd")) +vu.add_library("axi_dma_lib").add_source_files([ + join(src_path, "*.vhd"), + join(src_path, "test", "*.vhd") +]) - ui.main() +vu.main() diff --git a/examples/vhdl/check/run.py b/examples/vhdl/check/run.py index 8d1f2d5f3..214912045 100644 --- a/examples/vhdl/check/run.py +++ b/examples/vhdl/check/run.py @@ -14,18 +14,16 @@ from os.path import join, dirname from vunit import VUnit -if __name__ == '__main__': - ui = VUnit.from_argv() +vu = VUnit.from_argv() - # Enable location preprocessing but exclude all but check_false to make the example less bloated - ui.enable_location_preprocessing( - exclude_subprograms=['debug', 'info', 'check', 'check_failed', 'check_true', 'check_implication', - 'check_stable', 'check_equal', 'check_not_unknown', 'check_zero_one_hot', - 'check_one_hot', 'check_next', 'check_sequence', 'check_relation']) +# Enable location preprocessing but exclude all but check_false to make the example less bloated +vu.enable_location_preprocessing( + exclude_subprograms=['debug', 'info', 'check', 'check_failed', 'check_true', 'check_implication', + 'check_stable', 'check_equal', 'check_not_unknown', 'check_zero_one_hot', + 'check_one_hot', 'check_next', 'check_sequence', 'check_relation']) - ui.enable_check_preprocessing() +vu.enable_check_preprocessing() - lib = ui.add_library("lib") - lib.add_source_files(join(dirname(__file__), "tb_example.vhd")) +vu.add_library("lib").add_source_files(join(dirname(__file__), "tb_example.vhd")) - ui.main() +vu.main() diff --git a/examples/vhdl/com/run.py b/examples/vhdl/com/run.py index 64c050891..fa6740fed 100644 --- a/examples/vhdl/com/run.py +++ b/examples/vhdl/com/run.py @@ -16,16 +16,12 @@ from os.path import join, dirname from vunit import VUnit -if __name__ == '__main__': - prj = VUnit.from_argv() - prj.add_com() - prj.add_verification_components() - prj.add_osvvm() +vu = VUnit.from_argv() +vu.add_com() +vu.add_verification_components() +vu.add_osvvm() - lib = prj.add_library('lib') - lib.add_source_files(join(dirname(__file__), 'src', '*.vhd')) +vu.add_library('lib').add_source_files(join(dirname(__file__), 'src', '*.vhd')) +vu.add_library('tb_lib').add_source_files(join(dirname(__file__), 'test', '*.vhd')) - tb_lib = prj.add_library('tb_lib') - tb_lib.add_source_files(join(dirname(__file__), 'test', '*.vhd')) - - prj.main() +vu.main() diff --git a/examples/vhdl/composite_generics/run.py b/examples/vhdl/composite_generics/run.py index bba083de7..5009b8606 100644 --- a/examples/vhdl/composite_generics/run.py +++ b/examples/vhdl/composite_generics/run.py @@ -14,24 +14,22 @@ from os.path import join, dirname from vunit import VUnit -if __name__ == '__main__': - prj = VUnit.from_argv() - tb_lib = prj.add_library('tb_lib') - tb_lib.add_source_files(join(dirname(__file__), 'test', '*.vhd')) +def encode(tb_cfg): + return ", ".join(["%s:%s" % (key, str(tb_cfg[key])) for key in tb_cfg]) - testbench = tb_lib.test_bench("tb_composite_generics") - test_1 = testbench.test("Test 1") +vu = VUnit.from_argv() - def encode(tb_cfg): - return ", ".join(["%s:%s" % (key, str(tb_cfg[key])) for key in tb_cfg]) +tb_lib = vu.add_library('tb_lib') +tb_lib.add_source_files(join(dirname(__file__), 'test', '*.vhd')) +test_1 = tb_lib.test_bench("tb_composite_generics").test("Test 1") - vga_tb_cfg = dict(image_width=640, image_height=480, dump_debug_data=False) - test_1.add_config(name='VGA', generics=dict(encoded_tb_cfg=encode(vga_tb_cfg))) +vga_tb_cfg = dict(image_width=640, image_height=480, dump_debug_data=False) +test_1.add_config(name='VGA', generics=dict(encoded_tb_cfg=encode(vga_tb_cfg))) - tiny_tb_cfg = dict(image_width=4, image_height=3, dump_debug_data=True) - test_1.add_config(name='tiny', generics=dict(encoded_tb_cfg=encode(tiny_tb_cfg))) +tiny_tb_cfg = dict(image_width=4, image_height=3, dump_debug_data=True) +test_1.add_config(name='tiny', generics=dict(encoded_tb_cfg=encode(tiny_tb_cfg))) - prj.main() +vu.main() diff --git a/examples/vhdl/coverage/run.py b/examples/vhdl/coverage/run.py index aee0f22de..71da7977a 100644 --- a/examples/vhdl/coverage/run.py +++ b/examples/vhdl/coverage/run.py @@ -7,20 +7,20 @@ from os.path import join, dirname from vunit import VUnit -root = dirname(__file__) -if __name__ == '__main__': - ui = VUnit.from_argv() - lib = ui.add_library("lib") - lib.add_source_files(join(root, "*.vhd")) +def post_run(results): + results.merge_coverage(file_name="coverage_data") - lib.set_compile_option("rivierapro.vcom_flags", ["-coverage", "bs"]) - lib.set_compile_option("rivierapro.vlog_flags", ["-coverage", "bs"]) - lib.set_compile_option("modelsim.vcom_flags", ["+cover=bs"]) - lib.set_compile_option("modelsim.vlog_flags", ["+cover=bs"]) - lib.set_sim_option("enable_coverage", True) - def post_run(results): - results.merge_coverage(file_name="coverage_data") +vu = VUnit.from_argv() - ui.main(post_run=post_run) +lib = vu.add_library("lib") +lib.add_source_files(join(dirname(__file__), "*.vhd")) + +lib.set_compile_option("rivierapro.vcom_flags", ["-coverage", "bs"]) +lib.set_compile_option("rivierapro.vlog_flags", ["-coverage", "bs"]) +lib.set_compile_option("modelsim.vcom_flags", ["+cover=bs"]) +lib.set_compile_option("modelsim.vlog_flags", ["+cover=bs"]) +lib.set_sim_option("enable_coverage", True) + +vu.main(post_run=post_run) diff --git a/examples/vhdl/generate_tests/run.py b/examples/vhdl/generate_tests/run.py index fdb6ab25b..9c580c14c 100644 --- a/examples/vhdl/generate_tests/run.py +++ b/examples/vhdl/generate_tests/run.py @@ -54,32 +54,33 @@ def generate_tests(obj, signs, data_widths): config_name = "data_width=%i,sign=%s" % (data_width, sign) # Add the configuration with a post check function to verify the output - obj.add_config(name=config_name, - generics=dict( - data_width=data_width, - sign=sign), - post_check=make_post_check(data_width, sign)) + obj.add_config( + name=config_name, + generics=dict( + data_width=data_width, + sign=sign), + post_check=make_post_check(data_width, sign) + ) test_path = join(dirname(__file__), "test") -if __name__ == '__main__': - ui = VUnit.from_argv() - lib = ui.add_library("lib") - lib.add_source_files(join(test_path, "*.vhd")) +vu = VUnit.from_argv() +lib = vu.add_library("lib") +lib.add_source_files(join(test_path, "*.vhd")) - tb_generated = lib.test_bench("tb_generated") +tb_generated = lib.test_bench("tb_generated") - # Just set a generic for all configurations within the test bench - tb_generated.set_generic("message", "set-for-entity") +# Just set a generic for all configurations within the test bench +tb_generated.set_generic("message", "set-for-entity") - for test in tb_generated.get_tests(): - if test.name == "Test 2": - # Test 2 should only be run with signed width of 16 - generate_tests(test, [True], [16]) - test.set_generic("message", "set-for-test") - else: - # Run all other tests with signed/unsigned and data width in range [1,5[ - generate_tests(test, [False, True], range(1, 5)) +for test in tb_generated.get_tests(): + if test.name == "Test 2": + # Test 2 should only be run with signed width of 16 + generate_tests(test, [True], [16]) + test.set_generic("message", "set-for-test") + else: + # Run all other tests with signed/unsigned and data width in range [1,5[ + generate_tests(test, [False, True], range(1, 5)) - ui.main() +vu.main() diff --git a/examples/vhdl/json4vhdl/run.py b/examples/vhdl/json4vhdl/run.py index cfb1bf9e0..34ab4fa05 100644 --- a/examples/vhdl/json4vhdl/run.py +++ b/examples/vhdl/json4vhdl/run.py @@ -18,16 +18,13 @@ root = dirname(__file__) -if __name__ == '__main__': - vu = VUnit.from_argv() +vu = VUnit.from_argv() +vu.add_json4vhdl() - vu.add_json4vhdl() +vu.add_library("test").add_source_files(join(root, "src/test/*.vhd")) - lib = vu.add_library("test") - lib.add_source_files(join(root, "src/test/*.vhd")) +tb_cfg = read_json(join(root, "src/test/data/data.json")) +tb_cfg["dump_debug_data"]=False +vu.set_generic("tb_cfg", encode_json(tb_cfg)) - tb_cfg = read_json(join(root, "src/test/data/data.json")) - tb_cfg["dump_debug_data"]=False - vu.set_generic("tb_cfg", encode_json(tb_cfg)) - - vu.main() +vu.main() diff --git a/examples/vhdl/logging/run.py b/examples/vhdl/logging/run.py index b42bbc44d..8f555a552 100644 --- a/examples/vhdl/logging/run.py +++ b/examples/vhdl/logging/run.py @@ -14,9 +14,7 @@ from os.path import join, dirname from vunit import VUnit -if __name__ == '__main__': - ui = VUnit.from_argv() - lib = ui.add_library("lib") - lib.add_source_files(join(dirname(__file__), "*.vhd")) +vu = VUnit.from_argv() +vu.add_library("lib").add_source_files(join(dirname(__file__), "*.vhd")) - ui.main() +vu.main() diff --git a/examples/vhdl/run/run.py b/examples/vhdl/run/run.py index b37f31f2a..5fc7a1d9d 100644 --- a/examples/vhdl/run/run.py +++ b/examples/vhdl/run/run.py @@ -16,11 +16,11 @@ root = dirname(__file__) -if __name__ == '__main__': - ui = VUnit.from_argv() - lib = ui.add_library("lib") - lib.add_source_files(join(root, "*.vhd")) - tb_with_lower_level_control = lib.entity("tb_with_lower_level_control") - tb_with_lower_level_control.scan_tests_from_file(join(root, "test_control.vhd")) +vu = VUnit.from_argv() - ui.main() +lib = vu.add_library("lib") +lib.add_source_files(join(root, "*.vhd")) +tb_with_lower_level_control = lib.entity("tb_with_lower_level_control") +tb_with_lower_level_control.scan_tests_from_file(join(root, "test_control.vhd")) + +vu.main() diff --git a/examples/vhdl/third_party_integration/run.py b/examples/vhdl/third_party_integration/run.py index e16ce0b16..7d9af0575 100644 --- a/examples/vhdl/third_party_integration/run.py +++ b/examples/vhdl/third_party_integration/run.py @@ -7,12 +7,6 @@ from os.path import join, dirname from vunit import VUnit -root = dirname(__file__) - -if __name__ == '__main__': - ui = VUnit.from_argv() - - lib = ui.add_library("lib") - lib.add_source_files(join(root, 'test', '*.vhd')) - - ui.main() +vu = VUnit.from_argv() +vu.add_library("lib").add_source_files(join(dirname(__file__), 'test', '*.vhd')) +vu.main() diff --git a/examples/vhdl/uart/run.py b/examples/vhdl/uart/run.py index f56460c2f..4fff1a480 100644 --- a/examples/vhdl/uart/run.py +++ b/examples/vhdl/uart/run.py @@ -15,17 +15,13 @@ from os.path import join, dirname from vunit import VUnit -if __name__ == '__main__': - ui = VUnit.from_argv() - ui.add_osvvm() - ui.add_verification_components() +vu = VUnit.from_argv() +vu.add_osvvm() +vu.add_verification_components() - src_path = join(dirname(__file__), "src") +src_path = join(dirname(__file__), "src") - uart_lib = ui.add_library("uart_lib") - uart_lib.add_source_files(join(src_path, "*.vhd")) +vu.add_library("uart_lib").add_source_files(join(src_path, "*.vhd")) +vu.add_library("tb_uart_lib").add_source_files(join(src_path, "test", "*.vhd")) - tb_uart_lib = ui.add_library("tb_uart_lib") - tb_uart_lib.add_source_files(join(src_path, "test", "*.vhd")) - - ui.main() +vu.main() diff --git a/examples/vhdl/user_guide/run.py b/examples/vhdl/user_guide/run.py index 3c5af774f..717d9c6d9 100644 --- a/examples/vhdl/user_guide/run.py +++ b/examples/vhdl/user_guide/run.py @@ -15,11 +15,6 @@ from os.path import join, dirname from vunit import VUnit -root = dirname(__file__) - -if __name__ == '__main__': - ui = VUnit.from_argv() - lib = ui.add_library("lib") - lib.add_source_files(join(root, "*.vhd")) - - ui.main() +vu = VUnit.from_argv() +vu.add_library("lib").add_source_files(join(dirname(__file__), "*.vhd")) +vu.main() diff --git a/examples/vhdl/vivado/run.py b/examples/vhdl/vivado/run.py index e2597c4f7..235683e2f 100644 --- a/examples/vhdl/vivado/run.py +++ b/examples/vhdl/vivado/run.py @@ -17,20 +17,17 @@ from vivado_util import add_vivado_ip root = dirname(__file__) +src_path = join(root, "src") -if __name__ == '__main__': - ui = VUnit.from_argv() +vu = VUnit.from_argv() - src_path = join(root, "src") +vu.add_library("lib").add_source_files(join(src_path, "*.vhd")) +vu.add_library("tb_lib").add_source_files(join(src_path, "test", "*.vhd")) - lib = ui.add_library("lib") - lib.add_source_files(join(src_path, "*.vhd")) +add_vivado_ip( + vu, + output_path=join(root, "vivado_libs"), + project_file=join(root, "myproject", "myproject.xpr") +) - tb_lib = ui.add_library("tb_lib") - tb_lib.add_source_files(join(src_path, "test", "*.vhd")) - - add_vivado_ip(ui, - output_path=join(root, "vivado_libs"), - project_file=join(root, "myproject", "myproject.xpr")) - - ui.main() +vu.main() diff --git a/tools/docs_utils.py b/tools/docs_utils.py index 8e92ecc7d..70753ddd7 100644 --- a/tools/docs_utils.py +++ b/tools/docs_utils.py @@ -13,7 +13,7 @@ import sys import inspect from os.path import basename, dirname, isdir, isfile, join -from os import listdir +from os import listdir, remove ROOT = join(dirname(__file__), '..', 'docs') @@ -53,22 +53,38 @@ def _get_eg_doc(location, ref): Reads the docstring from a run.py file and rewrites the title to make it a ref """ if not isfile(join(location, 'run.py')): - print("Example subdir '" + basename(location) + "' does not contain a 'run.py' file. Skipping...") + print( + "WARNING: Example subdir '" + + basename(location) + + "' does not contain a 'run.py' file. Skipping...") return None + print("Generating '_main.py' from 'run.py' in '" + basename(location) + "'...") + with open(join(location, 'run.py'), 'r') as ifile: + with open(join(location, '_main.py'), 'w') as ofile: + ofile.writelines(['def _main():\n']) + ofile.writelines([''.join([' ', x]) for x in ifile]) + print("Extracting docs from '" + basename(location) + "'...") sys.path.append(location) - import run # pylint: disable=import-error - vc_doc = inspect.getdoc(run) - del sys.modules['run'] + from _main import _main # pylint: disable=import-error + eg_doc = inspect.getdoc(_main) + del sys.modules['_main'] sys.path.remove(location) - doc = '' - if vc_doc: - title = '`%s <%s/>`_' % (vc_doc.split('---', 1)[0][0:-1], ref) - doc = '\n'.join([ - title, - '-' * len(title), - vc_doc.split('---\n', 1)[1], - '\n' - ]) - return doc + remove(join(location, '_main.py')) + + if not eg_doc: + print( + "WARNING: 'run.py' file in example subdir '" + + basename(location) + + "' does not contain a docstring. Skipping..." + ) + return '' + + title = '`%s <%s/>`_' % (eg_doc.split('---', 1)[0][0:-1], ref) + return '\n'.join([ + title, + '-' * len(title), + eg_doc.split('---\n', 1)[1], + '\n' + ])