Skip to content

Commit

Permalink
Test dependency resolution in CoreManager
Browse files Browse the repository at this point in the history
The CoreManager provides the interface to the dependency resolution
process. Add a test to check if the ordered list of files and
dependencies is correct.
  • Loading branch information
imphil committed Mar 23, 2020
1 parent b788e8a commit 198106f
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tests/capi2_cores/deptree/child1.core
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
CAPI=2:
name: ::deptree-child1

filesets:
fs1:
depend:
- ::deptree-child3
files:
- "child1-fs1-f1.sv"
- "child1-fs1-f2.sv"
fileType: systemVerilogSource

targets:
default:
filesets:
- fs1
14 changes: 14 additions & 0 deletions tests/capi2_cores/deptree/child2.core
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
CAPI=2:
name: ::deptree-child2

filesets:
fs1:
files:
- "child2-fs1-f1.sv"
- "child2-fs1-f2.sv"
fileType: systemVerilogSource

targets:
default:
filesets:
- fs1
14 changes: 14 additions & 0 deletions tests/capi2_cores/deptree/child3.core
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
CAPI=2:
name: ::deptree-child3

filesets:
fs1:
files:
- "child3-fs1-f1.sv"
- "child3-fs1-f2.sv"
fileType: systemVerilogSource

targets:
default:
filesets:
- fs1
28 changes: 28 additions & 0 deletions tests/capi2_cores/deptree/root.core
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
CAPI=2:
name: ::deptree-root

filesets:
fs1:
depend:
# Child 3 is also included from child1; having it listed first here should
# ensure that the files from child3 appear before the files from child2.
- ::deptree-child3
- ::deptree-child2
- ::deptree-child1
files:
- "root-fs1-f1.sv"
- "root-fs1-f2.sv"
fileType: systemVerilogSource
fs2:
depend:
- ::deptree-child3
files:
- "root-fs2-f1.sv"
- "root-fs2-f2.sv"
fileType: systemVerilogSource

targets:
default:
filesets:
- fs1
- fs2
47 changes: 47 additions & 0 deletions tests/test_coremanager.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,53 @@
import pytest


def test_deptree():
from fusesoc.coremanager import CoreManager
from fusesoc.config import Config
from fusesoc.librarymanager import Library
from fusesoc.vlnv import Vlnv
import os

tests_dir = os.path.dirname(__file__)
deptree_cores_dir = os.path.join(tests_dir, "capi2_cores", "deptree")
lib = Library("deptree", deptree_cores_dir)

cm = CoreManager(Config())
cm.add_library(lib)

root_core = cm.get_core(Vlnv("::deptree-root"))

# Check dependency tree
deps = cm.get_depends(root_core.name, {})
deps_names = [str(c) for c in deps]
deps_names_expected = [
"::deptree-child2:0",
"::deptree-child3:0",
"::deptree-child1:0",
"::deptree-root:0",
]
assert deps_names == deps_names_expected

# Check files in dependency tree
files_expected = [
"child2-fs1-f1.sv",
"child2-fs1-f2.sv",
"child3-fs1-f1.sv",
"child3-fs1-f2.sv",
"child1-fs1-f1.sv",
"child1-fs1-f2.sv",
"root-fs1-f1.sv",
"root-fs1-f2.sv",
"root-fs2-f1.sv",
"root-fs2-f2.sv",
]
files = []
for d in deps:
files += [f.name for f in d.get_files({})]

assert files == files_expected


def test_copyto():
import os
import tempfile
Expand Down

0 comments on commit 198106f

Please sign in to comment.