如何将多个 VUnit run.py 文件合并到单个 VUnit 运行中? [英] How to combine multiple VUnit run.py files into a single VUnit run?
问题描述
我有一个这样的目录和文件结构:
I have a directory and file structure like this:
vunit_multi/
alfa/
run.py
...
bravo/
run.py
...
VUnit run.py
可以单独运行.
The VUnit run.py
can run separately.
有什么好的方法可以将这些多个单独的 VUnit 运行组合成一个带有组合状态报告的运行吗?
Is there any nice way to combine these multiple separate VUnit runs into a single run with a combined status report?
推荐答案
假设你的 alfa 和 bravo 运行脚本看起来像这样
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()
现在安排你的脚本
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()
底部的 if 语句意味着如果文件作为脚本调用(因此您仍然可以使用它来测试 alfa),则执行最后三行,但如果文件作为模块导入另一个脚本,则不会执行.
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.
现在在顶级目录(vunit_multi
)中放置一个像这样的新运行脚本
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
将查找所有运行脚本,然后遍历这些脚本.每个脚本文件都将作为模块导入以访问 create_test_suite
函数.使用在此顶级脚本中创建的 prj
调用该函数,以添加为模块指定的库和文件.
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.
注意:您可以使用比 imp
更新的模块,但 imp
也适用于较旧的 Python 版本.
Note: There are newer modules than imp
that you can use but imp
also works in older Python versions.
这篇关于如何将多个 VUnit run.py 文件合并到单个 VUnit 运行中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!