How to combine multiple VUnit run.py files into one VUnit launch?

I have a directory and file structure like this:

vunit_multi/
    alfa/
        run.py
        ...
    bravo/
        run.py
        ...

VUnit run.pycan work separately.

Is there a good way to combine these several separate VUnit runs into one run with a combined status report?

+4
source share
1 answer

Let's say your alfa and bravo startup scripts look 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 place the script on 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 below means that the last three lines are executed if the file is called as a script (so you can use it to test alfa anyway), but not if the file is imported as a module into another script.

script (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 , . script create_test_suite. prj, script, , .

, script, .

. , imp, , imp Python.

+4

Source: https://habr.com/ru/post/1673021/


All Articles