diff --git a/examples/verilog/uart/run.py b/examples/verilog/uart/run.py index a92f92ee1..9df241494 100644 --- a/examples/verilog/uart/run.py +++ b/examples/verilog/uart/run.py @@ -15,15 +15,14 @@ from os.path import join, dirname from vunit.verilog import VUnit -ui = VUnit.from_argv() +vu = VUnit.from_argv() src_path = join(dirname(__file__), "src") -uart_lib = ui.add_library("uart_lib") +uart_lib = vu.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 = vu.add_library("tb_uart_lib") tb_uart_lib.add_source_files(join(src_path, "test", "*.sv")) -if __name__ == '__main__': - ui.main() +vu.main() diff --git a/examples/verilog/user_guide/run.py b/examples/verilog/user_guide/run.py index 6e9f8564c..38ae89728 100644 --- a/examples/verilog/user_guide/run.py +++ b/examples/verilog/user_guide/run.py @@ -17,9 +17,8 @@ root = dirname(__file__) -ui = VUnit.from_argv() -lib = ui.add_library("lib") +vu = VUnit.from_argv() +lib = vu.add_library("lib") lib.add_source_files(join(root, "*.sv")) -if __name__ == '__main__': - ui.main() +vu.main() diff --git a/examples/verilog/verilog_ams/run.py b/examples/verilog/verilog_ams/run.py index 800d4ed05..209b98bae 100644 --- a/examples/verilog/verilog_ams/run.py +++ b/examples/verilog/verilog_ams/run.py @@ -9,10 +9,9 @@ root = dirname(__file__) -ui = VUnit.from_argv() -lib = ui.add_library("lib") +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"]) -if __name__ == '__main__': - ui.main() +vu.main() diff --git a/examples/vhdl/array/run.py b/examples/vhdl/array/run.py index 380b43df8..7aca3583c 100644 --- a/examples/vhdl/array/run.py +++ b/examples/vhdl/array/run.py @@ -18,12 +18,15 @@ 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.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 27af6730d..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() 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")) +src_path = join(dirname(__file__), "src") + +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']) -if __name__ == '__main__': - vu.main() +vu.main() diff --git a/examples/vhdl/axi_dma/run.py b/examples/vhdl/axi_dma/run.py index 41dbfeccb..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 -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") -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") +]) -if __name__ == '__main__': - ui.main() +vu.main() diff --git a/examples/vhdl/check/run.py b/examples/vhdl/check/run.py index 4d7716c84..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 -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( +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")) -if __name__ == '__main__': - ui.main() +vu.main() diff --git a/examples/vhdl/com/run.py b/examples/vhdl/com/run.py index 8712e0fb6..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 -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')) - -if __name__ == '__main__': - prj.main() +vu.main() diff --git a/examples/vhdl/composite_generics/run.py b/examples/vhdl/composite_generics/run.py index 5381339c1..5009b8606 100644 --- a/examples/vhdl/composite_generics/run.py +++ b/examples/vhdl/composite_generics/run.py @@ -14,18 +14,17 @@ from os.path import join, dirname from vunit import VUnit -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))) @@ -33,5 +32,4 @@ def encode(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() +vu.main() diff --git a/examples/vhdl/coverage/run.py b/examples/vhdl/coverage/run.py index 6c42142e9..71da7977a 100644 --- a/examples/vhdl/coverage/run.py +++ b/examples/vhdl/coverage/run.py @@ -7,11 +7,15 @@ from os.path import join, dirname from vunit import VUnit -root = dirname(__file__) -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") + + +vu = VUnit.from_argv() + +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"]) @@ -19,8 +23,4 @@ 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") - -if __name__ == '__main__': - ui.main(post_run=post_run) +vu.main(post_run=post_run) diff --git a/examples/vhdl/generate_tests/run.py b/examples/vhdl/generate_tests/run.py index 5fc5f1c5f..9c580c14c 100644 --- a/examples/vhdl/generate_tests/run.py +++ b/examples/vhdl/generate_tests/run.py @@ -54,17 +54,19 @@ 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") -ui = VUnit.from_argv() -lib = ui.add_library("lib") +vu = VUnit.from_argv() +lib = vu.add_library("lib") lib.add_source_files(join(test_path, "*.vhd")) tb_generated = lib.test_bench("tb_generated") @@ -81,5 +83,4 @@ def generate_tests(obj, signs, data_widths): # 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() +vu.main() diff --git a/examples/vhdl/json4vhdl/run.py b/examples/vhdl/json4vhdl/run.py index f7d755d50..34ab4fa05 100644 --- a/examples/vhdl/json4vhdl/run.py +++ b/examples/vhdl/json4vhdl/run.py @@ -19,15 +19,12 @@ root = dirname(__file__) vu = VUnit.from_argv() - vu.add_json4vhdl() -lib = vu.add_library("test") -lib.add_source_files(join(root, "src/test/*.vhd")) +vu.add_library("test").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)) -if __name__ == '__main__': - vu.main() +vu.main() diff --git a/examples/vhdl/logging/run.py b/examples/vhdl/logging/run.py index d368e2125..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 -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")) -if __name__ == '__main__': - ui.main() +vu.main() diff --git a/examples/vhdl/run/run.py b/examples/vhdl/run/run.py index 00790f2d1..5fc7a1d9d 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") +vu = VUnit.from_argv() + +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")) -if __name__ == '__main__': - ui.main() +vu.main() diff --git a/examples/vhdl/third_party_integration/run.py b/examples/vhdl/third_party_integration/run.py index 99c420cd4..7d9af0575 100644 --- a/examples/vhdl/third_party_integration/run.py +++ b/examples/vhdl/third_party_integration/run.py @@ -7,11 +7,6 @@ from os.path import join, dirname 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.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 4c46f8c92..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 -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") -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")) - -if __name__ == '__main__': - ui.main() +vu.main() diff --git a/examples/vhdl/user_guide/run.py b/examples/vhdl/user_guide/run.py index de6c1ef87..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__) - -ui = VUnit.from_argv() -lib = ui.add_library("lib") -lib.add_source_files(join(root, "*.vhd")) - -if __name__ == '__main__': - 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 08ad72bee..235683e2f 100644 --- a/examples/vhdl/vivado/run.py +++ b/examples/vhdl/vivado/run.py @@ -16,20 +16,18 @@ 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")) +vu = VUnit.from_argv() -tb_lib = ui.add_library("tb_lib") -tb_lib.add_source_files(join(src_path, "test", "*.vhd")) +vu.add_library("lib").add_source_files(join(src_path, "*.vhd")) +vu.add_library("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")) +add_vivado_ip( + vu, + 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 d4d7f39a2..70753ddd7 100644 --- a/tools/docs_utils.py +++ b/tools/docs_utils.py @@ -8,10 +8,12 @@ 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 import listdir +from os.path import basename, dirname, isdir, isfile, join +from os import listdir, remove ROOT = join(dirname(__file__), '..', 'docs') @@ -38,28 +40,51 @@ 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( + "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' + ])