Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

examples/vhdl: use pathlib instead of join and dirname #612

Merged
merged 1 commit into from
Jan 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions examples/vhdl/array/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,16 @@
loading it from csv and raw files.
"""

from os.path import join, dirname
from pathlib import Path
from vunit import VUnit

root = dirname(__file__)

vu = VUnit.from_argv()
vu.add_osvvm()

src_path = join(dirname(__file__), "src")
src_path = Path(__file__).parent / "src"

vu.add_library("lib").add_source_files(
[join(src_path, "*.vhd"), join(src_path, "test", "*.vhd")]
[src_path / "*.vhd", src_path / "test" / "*.vhd"]
)

vu.set_compile_option("ghdl.flags", ["-frelaxed"])
Expand Down
8 changes: 3 additions & 5 deletions examples/vhdl/array_axis_vcs/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,15 @@
:vunit_file:`vhdl/verification_components/test/tb_axi_stream.vhd <vunit/vhdl/verification_components/test/tb_axi_stream.vhd>`.
"""

from os.path import join, dirname
from pathlib import Path
from vunit import VUnit

vu = VUnit.from_argv()
vu.add_verification_components()

src_path = join(dirname(__file__), "src")
src_path = Path(__file__).parent / "src"

vu.add_library("lib").add_source_files(
[join(src_path, "*.vhd"), join(src_path, "**", "*.vhd")]
)
vu.add_library("lib").add_source_files([src_path / "*.vhd", src_path / "**" / "*.vhd"])

# vu.set_sim_option('modelsim.init_files.after_load',['runall_addwave.do'])

Expand Down
6 changes: 3 additions & 3 deletions examples/vhdl/axi_dma/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@
via AXI-lite.
"""

from os.path import join, dirname
from pathlib import Path
from vunit import VUnit

vu = VUnit.from_argv()
vu.add_osvvm()
vu.add_verification_components()

src_path = join(dirname(__file__), "src")
src_path = Path(__file__).parent / "src"

vu.add_library("axi_dma_lib").add_source_files(
[join(src_path, "*.vhd"), join(src_path, "test", "*.vhd")]
[src_path / "*.vhd", src_path / "test" / "*.vhd"]
)

vu.main()
4 changes: 2 additions & 2 deletions examples/vhdl/check/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
Demonstrates the VUnit check library.
"""

from os.path import join, dirname
from pathlib import Path
from vunit import VUnit

vu = VUnit.from_argv()
Expand All @@ -38,6 +38,6 @@

vu.enable_check_preprocessing()

vu.add_library("lib").add_source_files(join(dirname(__file__), "tb_example.vhd"))
vu.add_library("lib").add_source_files(Path(__file__).parent / "tb_example.vhd")

vu.main()
8 changes: 5 additions & 3 deletions examples/vhdl/com/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@
can be found in the :ref:`com user guide <com_user_guide>`.
"""

from os.path import join, dirname
from pathlib import Path
from vunit import VUnit

vu = VUnit.from_argv()
vu.add_com()
vu.add_verification_components()
vu.add_osvvm()

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"))
root = Path(__file__).parent

vu.add_library("lib").add_source_files(root / "src" / "*.vhd")
vu.add_library("tb_lib").add_source_files(root / "test" / "*.vhd")

vu.main()
4 changes: 2 additions & 2 deletions examples/vhdl/composite_generics/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
See `Enable Your Simulator to Handle Complex Top-Level Generics <https://vunit.github.io/posts/2017_06_03_enable_your_simulator_to_handle_complex_top_level_generics/post.html>`_.
"""

from os.path import join, dirname
from pathlib import Path
from vunit import VUnit


Expand All @@ -22,7 +22,7 @@ def encode(tb_cfg):
vu = VUnit.from_argv()

tb_lib = vu.add_library("tb_lib")
tb_lib.add_source_files(join(dirname(__file__), "test", "*.vhd"))
tb_lib.add_source_files(Path(__file__).parent / "test" / "*.vhd")

test_1 = tb_lib.test_bench("tb_composite_generics").test("Test 1")

Expand Down
4 changes: 2 additions & 2 deletions examples/vhdl/coverage/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
# Copyright (c) 2014-2020, Lars Asplund [email protected]

from os.path import join, dirname
from pathlib import Path
from vunit import VUnit


Expand All @@ -15,7 +15,7 @@ def post_run(results):
vu = VUnit.from_argv()

lib = vu.add_library("lib")
lib.add_source_files(join(dirname(__file__), "*.vhd"))
lib.add_source_files(Path(__file__).parent / "*.vhd")

lib.set_compile_option("rivierapro.vcom_flags", ["-coverage", "bs"])
lib.set_compile_option("rivierapro.vlog_flags", ["-coverage", "bs"])
Expand Down
16 changes: 7 additions & 9 deletions examples/vhdl/external_buffer/cp.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,23 @@
# Copyright (c) 2014-2020, Lars Asplund [email protected]

from vunit import VUnit
from os import popen
from os.path import join, dirname
from subprocess import check_call
from pathlib import Path

src_path = join(dirname(__file__), "src")
src_path = Path(__file__).parent / "src"

c_obj = join(src_path, "cp.o")
c_obj = src_path / "cp.o"
# Compile C application to an object
print(
popen(" ".join(["gcc", "-fPIC", "-c", join(src_path, "cp.c"), "-o", c_obj])).read()
)
check_call(["gcc", "-fPIC", "-c", str(src_path / "cp.c"), "-o", str(c_obj)])

# Enable the external feature for strings
vu = VUnit.from_argv(vhdl_standard="2008", compile_builtins=False)
vu.add_builtins({"string": True})

lib = vu.add_library("lib")
lib.add_source_files(join(src_path, "tb_extcp_*.vhd"))
lib.add_source_files(str(src_path / "tb_extcp_*.vhd"))

# Add the C object to the elaboration of GHDL
vu.set_sim_option("ghdl.elab_flags", ["-Wl," + c_obj])
vu.set_sim_option("ghdl.elab_flags", ["-Wl," + str(c_obj)])

vu.main()
46 changes: 21 additions & 25 deletions examples/vhdl/external_buffer/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,53 +26,49 @@
"""

from vunit import VUnit, ROOT
from os import popen
from os.path import join, dirname
from subprocess import check_call
from pathlib import Path

src_path = join(dirname(__file__), "src")
ext_srcs = join(ROOT, "vunit", "vhdl", "data_types", "src", "external", "ghdl")
src_path = Path(__file__).parent / "src"
ext_srcs = Path(ROOT) / "vunit" / "vhdl" / "data_types" / "src" / "external" / "ghdl"

# Compile C applications to an objects
c_iobj = join(src_path, "imain.o")
c_bobj = join(src_path, "bmain.o")
c_iobj = src_path / "imain.o"
c_bobj = src_path / "bmain.o"

for val in [["int32_t", c_iobj], ["uint8_t", c_bobj]]:
print(
popen(
" ".join(
[
"gcc",
"-fPIC",
"-DTYPE=" + val[0],
"-I",
ext_srcs,
"-c",
join(src_path, "main.c"),
"-o",
val[1],
]
)
).read()
check_call(
[
"gcc",
"-fPIC",
"-DTYPE=" + val[0],
"-I",
ext_srcs,
"-c",
src_path / "main.c",
"-o",
val[1],
]
)

# Enable the external feature for strings/byte_vectors and integer_vectors
vu = VUnit.from_argv(vhdl_standard="2008", compile_builtins=False)
vu.add_builtins({"string": True, "integer": True})

lib = vu.add_library("lib")
lib.add_source_files(join(src_path, "tb_ext_*.vhd"))
lib.add_source_files(src_path / "tb_ext_*.vhd")

# Add the C object to the elaboration of GHDL
for tb in lib.get_test_benches(pattern="*tb_ext*", allow_empty=False):
tb.set_sim_option(
"ghdl.elab_flags",
["-Wl," + c_bobj, "-Wl,-Wl,--version-script=" + join(ext_srcs, "grt.ver")],
["-Wl," + str(c_bobj), "-Wl,-Wl,--version-script=" + str(ext_srcs / "grt.ver")],
overwrite=True,
)
for tb in lib.get_test_benches(pattern="*tb_ext*_integer*", allow_empty=False):
tb.set_sim_option(
"ghdl.elab_flags",
["-Wl," + c_iobj, "-Wl,-Wl,--version-script=" + join(ext_srcs, "grt.ver")],
["-Wl," + str(c_iobj), "-Wl,-Wl,--version-script=" + str(ext_srcs / "grt.ver")],
overwrite=True,
)

Expand Down
12 changes: 5 additions & 7 deletions examples/vhdl/generate_tests/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
to create test bench output files in location specified by VUnit python runner.
"""

from os.path import join, dirname
from pathlib import Path
from itertools import product
from vunit import VUnit

Expand All @@ -30,10 +30,10 @@ def post_check(output_path):

expected = ", ".join([str(data_width), str(sign).lower()]) + "\n"

output_file = join(output_path, "generics.txt")
output_file = Path(output_path) / "generics.txt"

print("Post check: %s" % output_file)
with open(output_file, "r") as fread:
print("Post check: %s" % str(output_file))
with output_file.open("r") as fread:
got = fread.read()
if not got == expected:
print("Content mismatch, got %r expected %r" % (got, expected))
Expand All @@ -60,11 +60,9 @@ def generate_tests(obj, signs, data_widths):
)


test_path = join(dirname(__file__), "test")

vu = VUnit.from_argv()
lib = vu.add_library("lib")
lib.add_source_files(join(test_path, "*.vhd"))
lib.add_source_files(Path(__file__).parent / "test" / "*.vhd")

tb_generated = lib.test_bench("tb_generated")

Expand Down
8 changes: 4 additions & 4 deletions examples/vhdl/json4vhdl/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@
This is an alternative to composite generics, that supports any depth in the content structure.
"""

from os.path import join, dirname
from pathlib import Path
from vunit import VUnit, read_json, encode_json

root = dirname(__file__)
test_path = Path(__file__).parent / "src" / "test"

vu = VUnit.from_argv()
vu.add_json4vhdl()

vu.add_library("test").add_source_files(join(root, "src/test/*.vhd"))
vu.add_library("test").add_source_files(test_path / "*.vhd")

tb_cfg = read_json(join(root, "src/test/data/data.json"))
tb_cfg = read_json(test_path / "data" / "data.json")
tb_cfg["dump_debug_data"] = False
vu.set_generic("tb_cfg", encode_json(tb_cfg))

Expand Down
4 changes: 2 additions & 2 deletions examples/vhdl/logging/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
Demonstrates VUnit's support for logging.
"""

from os.path import join, dirname
from pathlib import Path
from vunit import VUnit

vu = VUnit.from_argv()
vu.add_library("lib").add_source_files(join(dirname(__file__), "*.vhd"))
vu.add_library("lib").add_source_files(Path(__file__).parent / "*.vhd")

vu.main()
8 changes: 4 additions & 4 deletions examples/vhdl/run/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@
Demonstrates the VUnit run library.
"""

from os.path import join, dirname
from pathlib import Path
from vunit import VUnit

root = dirname(__file__)
root = Path(__file__).parent

vu = VUnit.from_argv()

lib = vu.add_library("lib")
lib.add_source_files(join(root, "*.vhd"))
lib.add_source_files(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"))
tb_with_lower_level_control.scan_tests_from_file(root / "test_control.vhd")

vu.main()
4 changes: 2 additions & 2 deletions examples/vhdl/third_party_integration/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#
# Copyright (c) 2014-2020, Lars Asplund [email protected]

from os.path import join, dirname
from pathlib import Path
from vunit import VUnit

vu = VUnit.from_argv()
vu.add_library("lib").add_source_files(join(dirname(__file__), "test", "*.vhd"))
vu.add_library("lib").add_source_files(Path(__file__).parent / "test" / "*.vhd")
vu.main()
8 changes: 4 additions & 4 deletions examples/vhdl/uart/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@
typical module.
"""

from os.path import join, dirname
from pathlib import Path
from vunit import VUnit

vu = VUnit.from_argv()
vu.add_osvvm()
vu.add_verification_components()

src_path = join(dirname(__file__), "src")
src_path = Path(__file__).parent / "src"

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"))
vu.add_library("uart_lib").add_source_files(src_path / "*.vhd")
vu.add_library("tb_uart_lib").add_source_files(src_path / "test" / "*.vhd")

vu.main()
4 changes: 2 additions & 2 deletions examples/vhdl/user_guide/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
:ref:`User Guide <user_guide>`.
"""

from os.path import join, dirname
from pathlib import Path
from vunit import VUnit

vu = VUnit.from_argv()
vu.add_library("lib").add_source_files(join(dirname(__file__), "*.vhd"))
vu.add_library("lib").add_source_files(Path(__file__).parent / "*.vhd")
vu.main()
Loading