aboutsummaryrefslogtreecommitdiffstats
path: root/context_test.go
diff options
context:
space:
mode:
authorColin Cross <ccross@android.com>2018-06-20 11:16:37 -0700
committerColin Cross <ccross@android.com>2018-06-20 14:10:18 -0700
commit9607a9f248c2aaf207c5175417004e159cb9176f (patch)
tree81c997e25e79eae2e5b970a940c2f44055196370 /context_test.go
parent3a16825a7ca3332092439bcac8533fd65a477d43 (diff)
downloadandroid_build_blueprint-9607a9f248c2aaf207c5175417004e159cb9176f.tar.gz
android_build_blueprint-9607a9f248c2aaf207c5175417004e159cb9176f.tar.bz2
android_build_blueprint-9607a9f248c2aaf207c5175417004e159cb9176f.zip
Allow multiple dependencies on the same module
Allow adding multiple dependencies on the same module. Adds a flag to Context.walkDeps to determine whether dependencies should be visited multiple times, and clarifies the behavior of VisitDepsDepthFirst (continues to visit each module once, even if there are multiple dependencies on it) and VisitDirectDeps (may visit a module multiple times). Test: TestWalkDepsDuplicates, TestVisit Change-Id: I58afbe90490aca102d242d63e185386e1fe55d73
Diffstat (limited to 'context_test.go')
-rw-r--r--context_test.go95
1 files changed, 92 insertions, 3 deletions
diff --git a/context_test.go b/context_test.go
index 635f73e..c08b0b7 100644
--- a/context_test.go
+++ b/context_test.go
@@ -189,7 +189,7 @@ func TestWalkDeps(t *testing.T) {
var outputDown string
var outputUp string
topModule := ctx.modulesFromName("A", nil)[0]
- ctx.walkDeps(topModule,
+ ctx.walkDeps(topModule, false,
func(dep depInfo, parent *moduleInfo) bool {
if dep.module.logicModule.(Walker).Walk() {
outputDown += ctx.ModuleName(dep.module.logicModule)
@@ -203,10 +203,99 @@ func TestWalkDeps(t *testing.T) {
}
})
if outputDown != "CFG" {
- t.Fatalf("unexpected walkDeps behaviour: %s\ndown should be: CFG", outputDown)
+ t.Errorf("unexpected walkDeps behaviour: %s\ndown should be: CFG", outputDown)
}
if outputUp != "GFC" {
- t.Fatalf("unexpected walkDeps behaviour: %s\nup should be: GFC", outputUp)
+ t.Errorf("unexpected walkDeps behaviour: %s\nup should be: GFC", outputUp)
+ }
+}
+
+// |---B===D - represents a non-walkable edge
+// A = represents a walkable edge
+// |===C===E===\
+// | | A should not be visited because it's the root node.
+// |===F===G B, D should not be walked.
+// \===/ G should be visited multiple times
+func TestWalkDepsDuplicates(t *testing.T) {
+ ctx := NewContext()
+ ctx.MockFileSystem(map[string][]byte{
+ "Blueprints": []byte(`
+ foo_module {
+ name: "A",
+ deps: ["B", "C"],
+ }
+
+ bar_module {
+ name: "B",
+ deps: ["D"],
+ }
+
+ foo_module {
+ name: "C",
+ deps: ["E", "F"],
+ }
+
+ foo_module {
+ name: "D",
+ }
+
+ foo_module {
+ name: "E",
+ deps: ["G"],
+ }
+
+ foo_module {
+ name: "F",
+ deps: ["G", "G"],
+ }
+
+ foo_module {
+ name: "G",
+ }
+ `),
+ })
+
+ ctx.RegisterModuleType("foo_module", newFooModule)
+ ctx.RegisterModuleType("bar_module", newBarModule)
+ _, errs := ctx.ParseBlueprintsFiles("Blueprints")
+ if len(errs) > 0 {
+ t.Errorf("unexpected parse errors:")
+ for _, err := range errs {
+ t.Errorf(" %s", err)
+ }
+ t.FailNow()
+ }
+
+ _, errs = ctx.ResolveDependencies(nil)
+ if len(errs) > 0 {
+ t.Errorf("unexpected dep errors:")
+ for _, err := range errs {
+ t.Errorf(" %s", err)
+ }
+ t.FailNow()
+ }
+
+ var outputDown string
+ var outputUp string
+ topModule := ctx.modulesFromName("A", nil)[0]
+ ctx.walkDeps(topModule, true,
+ func(dep depInfo, parent *moduleInfo) bool {
+ if dep.module.logicModule.(Walker).Walk() {
+ outputDown += ctx.ModuleName(dep.module.logicModule)
+ return true
+ }
+ return false
+ },
+ func(dep depInfo, parent *moduleInfo) {
+ if dep.module.logicModule.(Walker).Walk() {
+ outputUp += ctx.ModuleName(dep.module.logicModule)
+ }
+ })
+ if outputDown != "CEGFGG" {
+ t.Errorf("unexpected walkDeps behaviour: %s\ndown should be: CEGFGG", outputDown)
+ }
+ if outputUp != "GEGGFC" {
+ t.Errorf("unexpected walkDeps behaviour: %s\nup should be: GEGGFC", outputUp)
}
}