I have a directory and file structure like this:
vunit_multi/
alfa/
run.py
...
bravo/
run.py
...
The VUnit run.py
can run separately.
Is there any nice way to combine these multiple separate VUnit runs into a single run with a combined status report?
Let's say your alfa and bravo run scripts looks something like this
from os.path import join, dirname
from vunit import VUnit
prj = VUnit.from_argv()
root = dirname(__file__)
lib = prj.add_library("alfa_lib")
lib.add_source_files(join(root, "*.vhd"))
prj.main()
Now arrange your script to this
from os.path import join, dirname
from vunit import VUnit
def create_test_suite(prj):
root = dirname(__file__)
lib = prj.add_library("alfa_lib")
lib.add_source_files(join(root, "*.vhd"))
if __name__ == '__main__':
prj = VUnit.from_argv()
create_test_suite(prj)
prj.main()
The if statement at the bottom means that the last three lines are executed if the file is called as a script (so you can still use it to test alfa) but not if the file is imported as a module into another script.
Now put a new run script like this in the top-level directory (vunit_multi
)
from os.path import join, dirname
from vunit import VUnit
from glob import glob
import imp
def create_test_suites(prj):
root = dirname(__file__)
run_scripts = glob(join(root, "*", "run.py"))
for run_script in run_scripts:
file_handle, path_name, description = imp.find_module("run", [dirname(run_script)])
run = imp.load_module("run", file_handle, path_name, description)
run.create_test_suite(prj)
file_handle.close()
prj = VUnit.from_argv()
create_test_suites(prj)
prj.main()
create_test_suites
will find all run scripts and then iterate over those scripts. Each script file will be imported as a module to get access to the create_test_suite
function. The function is called with the prj
created in this top-level script to add the libraries and files specified for the module.
Now if you run the top-level script it will see all module testbenches.
Note: There are newer modules than imp
that you can use but imp
also works in older Python versions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With