Merge "Add ModuleInstallPathContextForTesting."

This commit is contained in:
Ulyana Trafimovich 2020-10-30 10:47:21 +00:00 committed by Gerrit Code Review
commit f1a2e55ac9
2 changed files with 95 additions and 85 deletions

View file

@ -1557,6 +1557,72 @@ func PathContextForTesting(config Config) PathContext {
} }
} }
type testModuleInstallPathContext struct {
baseModuleContext
inData bool
inTestcases bool
inSanitizerDir bool
inRamdisk bool
inVendorRamdisk bool
inRecovery bool
inRoot bool
forceOS *OsType
forceArch *ArchType
}
func (m testModuleInstallPathContext) Config() Config {
return m.baseModuleContext.config
}
func (testModuleInstallPathContext) AddNinjaFileDeps(deps ...string) {}
func (m testModuleInstallPathContext) InstallInData() bool {
return m.inData
}
func (m testModuleInstallPathContext) InstallInTestcases() bool {
return m.inTestcases
}
func (m testModuleInstallPathContext) InstallInSanitizerDir() bool {
return m.inSanitizerDir
}
func (m testModuleInstallPathContext) InstallInRamdisk() bool {
return m.inRamdisk
}
func (m testModuleInstallPathContext) InstallInVendorRamdisk() bool {
return m.inVendorRamdisk
}
func (m testModuleInstallPathContext) InstallInRecovery() bool {
return m.inRecovery
}
func (m testModuleInstallPathContext) InstallInRoot() bool {
return m.inRoot
}
func (m testModuleInstallPathContext) InstallBypassMake() bool {
return false
}
func (m testModuleInstallPathContext) InstallForceOS() (*OsType, *ArchType) {
return m.forceOS, m.forceArch
}
// Construct a minimal ModuleInstallPathContext for testing. Note that baseModuleContext is
// default-initialized, which leaves blueprint.baseModuleContext set to nil, so methods that are
// delegated to it will panic.
func ModuleInstallPathContextForTesting(config Config) ModuleInstallPathContext {
ctx := &testModuleInstallPathContext{}
ctx.config = config
ctx.os = Android
return ctx
}
// Rel performs the same function as filepath.Rel, but reports errors to a PathContext, and reports an error if // Rel performs the same function as filepath.Rel, but reports errors to a PathContext, and reports an error if
// targetPath is not inside basePath. // targetPath is not inside basePath.
func Rel(ctx PathContext, basePath string, targetPath string) string { func Rel(ctx PathContext, basePath string, targetPath string) string {

View file

@ -197,62 +197,6 @@ func p(in interface{}) string {
} }
} }
type moduleInstallPathContextImpl struct {
baseModuleContext
inData bool
inTestcases bool
inSanitizerDir bool
inRamdisk bool
inVendorRamdisk bool
inRecovery bool
inRoot bool
forceOS *OsType
forceArch *ArchType
}
func (m moduleInstallPathContextImpl) Config() Config {
return m.baseModuleContext.config
}
func (moduleInstallPathContextImpl) AddNinjaFileDeps(deps ...string) {}
func (m moduleInstallPathContextImpl) InstallInData() bool {
return m.inData
}
func (m moduleInstallPathContextImpl) InstallInTestcases() bool {
return m.inTestcases
}
func (m moduleInstallPathContextImpl) InstallInSanitizerDir() bool {
return m.inSanitizerDir
}
func (m moduleInstallPathContextImpl) InstallInRamdisk() bool {
return m.inRamdisk
}
func (m moduleInstallPathContextImpl) InstallInVendorRamdisk() bool {
return m.inVendorRamdisk
}
func (m moduleInstallPathContextImpl) InstallInRecovery() bool {
return m.inRecovery
}
func (m moduleInstallPathContextImpl) InstallInRoot() bool {
return m.inRoot
}
func (m moduleInstallPathContextImpl) InstallBypassMake() bool {
return false
}
func (m moduleInstallPathContextImpl) InstallForceOS() (*OsType, *ArchType) {
return m.forceOS, m.forceArch
}
func pathTestConfig(buildDir string) Config { func pathTestConfig(buildDir string) Config {
return TestConfig(buildDir, nil, "", nil) return TestConfig(buildDir, nil, "", nil)
} }
@ -265,14 +209,14 @@ func TestPathForModuleInstall(t *testing.T) {
testCases := []struct { testCases := []struct {
name string name string
ctx *moduleInstallPathContextImpl ctx *testModuleInstallPathContext
in []string in []string
out string out string
partitionDir string partitionDir string
}{ }{
{ {
name: "host binary", name: "host binary",
ctx: &moduleInstallPathContextImpl{ ctx: &testModuleInstallPathContext{
baseModuleContext: baseModuleContext{ baseModuleContext: baseModuleContext{
os: hostTarget.Os, os: hostTarget.Os,
target: hostTarget, target: hostTarget,
@ -285,7 +229,7 @@ func TestPathForModuleInstall(t *testing.T) {
{ {
name: "system binary", name: "system binary",
ctx: &moduleInstallPathContextImpl{ ctx: &testModuleInstallPathContext{
baseModuleContext: baseModuleContext{ baseModuleContext: baseModuleContext{
os: deviceTarget.Os, os: deviceTarget.Os,
target: deviceTarget, target: deviceTarget,
@ -297,7 +241,7 @@ func TestPathForModuleInstall(t *testing.T) {
}, },
{ {
name: "vendor binary", name: "vendor binary",
ctx: &moduleInstallPathContextImpl{ ctx: &testModuleInstallPathContext{
baseModuleContext: baseModuleContext{ baseModuleContext: baseModuleContext{
os: deviceTarget.Os, os: deviceTarget.Os,
target: deviceTarget, target: deviceTarget,
@ -312,7 +256,7 @@ func TestPathForModuleInstall(t *testing.T) {
}, },
{ {
name: "odm binary", name: "odm binary",
ctx: &moduleInstallPathContextImpl{ ctx: &testModuleInstallPathContext{
baseModuleContext: baseModuleContext{ baseModuleContext: baseModuleContext{
os: deviceTarget.Os, os: deviceTarget.Os,
target: deviceTarget, target: deviceTarget,
@ -327,7 +271,7 @@ func TestPathForModuleInstall(t *testing.T) {
}, },
{ {
name: "product binary", name: "product binary",
ctx: &moduleInstallPathContextImpl{ ctx: &testModuleInstallPathContext{
baseModuleContext: baseModuleContext{ baseModuleContext: baseModuleContext{
os: deviceTarget.Os, os: deviceTarget.Os,
target: deviceTarget, target: deviceTarget,
@ -342,7 +286,7 @@ func TestPathForModuleInstall(t *testing.T) {
}, },
{ {
name: "system_ext binary", name: "system_ext binary",
ctx: &moduleInstallPathContextImpl{ ctx: &testModuleInstallPathContext{
baseModuleContext: baseModuleContext{ baseModuleContext: baseModuleContext{
os: deviceTarget.Os, os: deviceTarget.Os,
target: deviceTarget, target: deviceTarget,
@ -357,7 +301,7 @@ func TestPathForModuleInstall(t *testing.T) {
}, },
{ {
name: "root binary", name: "root binary",
ctx: &moduleInstallPathContextImpl{ ctx: &testModuleInstallPathContext{
baseModuleContext: baseModuleContext{ baseModuleContext: baseModuleContext{
os: deviceTarget.Os, os: deviceTarget.Os,
target: deviceTarget, target: deviceTarget,
@ -370,7 +314,7 @@ func TestPathForModuleInstall(t *testing.T) {
}, },
{ {
name: "recovery binary", name: "recovery binary",
ctx: &moduleInstallPathContextImpl{ ctx: &testModuleInstallPathContext{
baseModuleContext: baseModuleContext{ baseModuleContext: baseModuleContext{
os: deviceTarget.Os, os: deviceTarget.Os,
target: deviceTarget, target: deviceTarget,
@ -383,7 +327,7 @@ func TestPathForModuleInstall(t *testing.T) {
}, },
{ {
name: "recovery root binary", name: "recovery root binary",
ctx: &moduleInstallPathContextImpl{ ctx: &testModuleInstallPathContext{
baseModuleContext: baseModuleContext{ baseModuleContext: baseModuleContext{
os: deviceTarget.Os, os: deviceTarget.Os,
target: deviceTarget, target: deviceTarget,
@ -398,7 +342,7 @@ func TestPathForModuleInstall(t *testing.T) {
{ {
name: "system native test binary", name: "system native test binary",
ctx: &moduleInstallPathContextImpl{ ctx: &testModuleInstallPathContext{
baseModuleContext: baseModuleContext{ baseModuleContext: baseModuleContext{
os: deviceTarget.Os, os: deviceTarget.Os,
target: deviceTarget, target: deviceTarget,
@ -411,7 +355,7 @@ func TestPathForModuleInstall(t *testing.T) {
}, },
{ {
name: "vendor native test binary", name: "vendor native test binary",
ctx: &moduleInstallPathContextImpl{ ctx: &testModuleInstallPathContext{
baseModuleContext: baseModuleContext{ baseModuleContext: baseModuleContext{
os: deviceTarget.Os, os: deviceTarget.Os,
target: deviceTarget, target: deviceTarget,
@ -427,7 +371,7 @@ func TestPathForModuleInstall(t *testing.T) {
}, },
{ {
name: "odm native test binary", name: "odm native test binary",
ctx: &moduleInstallPathContextImpl{ ctx: &testModuleInstallPathContext{
baseModuleContext: baseModuleContext{ baseModuleContext: baseModuleContext{
os: deviceTarget.Os, os: deviceTarget.Os,
target: deviceTarget, target: deviceTarget,
@ -443,7 +387,7 @@ func TestPathForModuleInstall(t *testing.T) {
}, },
{ {
name: "product native test binary", name: "product native test binary",
ctx: &moduleInstallPathContextImpl{ ctx: &testModuleInstallPathContext{
baseModuleContext: baseModuleContext{ baseModuleContext: baseModuleContext{
os: deviceTarget.Os, os: deviceTarget.Os,
target: deviceTarget, target: deviceTarget,
@ -460,7 +404,7 @@ func TestPathForModuleInstall(t *testing.T) {
{ {
name: "system_ext native test binary", name: "system_ext native test binary",
ctx: &moduleInstallPathContextImpl{ ctx: &testModuleInstallPathContext{
baseModuleContext: baseModuleContext{ baseModuleContext: baseModuleContext{
os: deviceTarget.Os, os: deviceTarget.Os,
target: deviceTarget, target: deviceTarget,
@ -477,7 +421,7 @@ func TestPathForModuleInstall(t *testing.T) {
{ {
name: "sanitized system binary", name: "sanitized system binary",
ctx: &moduleInstallPathContextImpl{ ctx: &testModuleInstallPathContext{
baseModuleContext: baseModuleContext{ baseModuleContext: baseModuleContext{
os: deviceTarget.Os, os: deviceTarget.Os,
target: deviceTarget, target: deviceTarget,
@ -490,7 +434,7 @@ func TestPathForModuleInstall(t *testing.T) {
}, },
{ {
name: "sanitized vendor binary", name: "sanitized vendor binary",
ctx: &moduleInstallPathContextImpl{ ctx: &testModuleInstallPathContext{
baseModuleContext: baseModuleContext{ baseModuleContext: baseModuleContext{
os: deviceTarget.Os, os: deviceTarget.Os,
target: deviceTarget, target: deviceTarget,
@ -506,7 +450,7 @@ func TestPathForModuleInstall(t *testing.T) {
}, },
{ {
name: "sanitized odm binary", name: "sanitized odm binary",
ctx: &moduleInstallPathContextImpl{ ctx: &testModuleInstallPathContext{
baseModuleContext: baseModuleContext{ baseModuleContext: baseModuleContext{
os: deviceTarget.Os, os: deviceTarget.Os,
target: deviceTarget, target: deviceTarget,
@ -522,7 +466,7 @@ func TestPathForModuleInstall(t *testing.T) {
}, },
{ {
name: "sanitized product binary", name: "sanitized product binary",
ctx: &moduleInstallPathContextImpl{ ctx: &testModuleInstallPathContext{
baseModuleContext: baseModuleContext{ baseModuleContext: baseModuleContext{
os: deviceTarget.Os, os: deviceTarget.Os,
target: deviceTarget, target: deviceTarget,
@ -539,7 +483,7 @@ func TestPathForModuleInstall(t *testing.T) {
{ {
name: "sanitized system_ext binary", name: "sanitized system_ext binary",
ctx: &moduleInstallPathContextImpl{ ctx: &testModuleInstallPathContext{
baseModuleContext: baseModuleContext{ baseModuleContext: baseModuleContext{
os: deviceTarget.Os, os: deviceTarget.Os,
target: deviceTarget, target: deviceTarget,
@ -556,7 +500,7 @@ func TestPathForModuleInstall(t *testing.T) {
{ {
name: "sanitized system native test binary", name: "sanitized system native test binary",
ctx: &moduleInstallPathContextImpl{ ctx: &testModuleInstallPathContext{
baseModuleContext: baseModuleContext{ baseModuleContext: baseModuleContext{
os: deviceTarget.Os, os: deviceTarget.Os,
target: deviceTarget, target: deviceTarget,
@ -570,7 +514,7 @@ func TestPathForModuleInstall(t *testing.T) {
}, },
{ {
name: "sanitized vendor native test binary", name: "sanitized vendor native test binary",
ctx: &moduleInstallPathContextImpl{ ctx: &testModuleInstallPathContext{
baseModuleContext: baseModuleContext{ baseModuleContext: baseModuleContext{
os: deviceTarget.Os, os: deviceTarget.Os,
target: deviceTarget, target: deviceTarget,
@ -587,7 +531,7 @@ func TestPathForModuleInstall(t *testing.T) {
}, },
{ {
name: "sanitized odm native test binary", name: "sanitized odm native test binary",
ctx: &moduleInstallPathContextImpl{ ctx: &testModuleInstallPathContext{
baseModuleContext: baseModuleContext{ baseModuleContext: baseModuleContext{
os: deviceTarget.Os, os: deviceTarget.Os,
target: deviceTarget, target: deviceTarget,
@ -604,7 +548,7 @@ func TestPathForModuleInstall(t *testing.T) {
}, },
{ {
name: "sanitized product native test binary", name: "sanitized product native test binary",
ctx: &moduleInstallPathContextImpl{ ctx: &testModuleInstallPathContext{
baseModuleContext: baseModuleContext{ baseModuleContext: baseModuleContext{
os: deviceTarget.Os, os: deviceTarget.Os,
target: deviceTarget, target: deviceTarget,
@ -621,7 +565,7 @@ func TestPathForModuleInstall(t *testing.T) {
}, },
{ {
name: "sanitized system_ext native test binary", name: "sanitized system_ext native test binary",
ctx: &moduleInstallPathContextImpl{ ctx: &testModuleInstallPathContext{
baseModuleContext: baseModuleContext{ baseModuleContext: baseModuleContext{
os: deviceTarget.Os, os: deviceTarget.Os,
target: deviceTarget, target: deviceTarget,
@ -637,7 +581,7 @@ func TestPathForModuleInstall(t *testing.T) {
partitionDir: "target/product/test_device/data/asan/data", partitionDir: "target/product/test_device/data/asan/data",
}, { }, {
name: "device testcases", name: "device testcases",
ctx: &moduleInstallPathContextImpl{ ctx: &testModuleInstallPathContext{
baseModuleContext: baseModuleContext{ baseModuleContext: baseModuleContext{
os: deviceTarget.Os, os: deviceTarget.Os,
target: deviceTarget, target: deviceTarget,
@ -649,7 +593,7 @@ func TestPathForModuleInstall(t *testing.T) {
partitionDir: "target/product/test_device/testcases", partitionDir: "target/product/test_device/testcases",
}, { }, {
name: "host testcases", name: "host testcases",
ctx: &moduleInstallPathContextImpl{ ctx: &testModuleInstallPathContext{
baseModuleContext: baseModuleContext{ baseModuleContext: baseModuleContext{
os: hostTarget.Os, os: hostTarget.Os,
target: hostTarget, target: hostTarget,
@ -661,7 +605,7 @@ func TestPathForModuleInstall(t *testing.T) {
partitionDir: "host/linux-x86/testcases", partitionDir: "host/linux-x86/testcases",
}, { }, {
name: "forced host testcases", name: "forced host testcases",
ctx: &moduleInstallPathContextImpl{ ctx: &testModuleInstallPathContext{
baseModuleContext: baseModuleContext{ baseModuleContext: baseModuleContext{
os: deviceTarget.Os, os: deviceTarget.Os,
target: deviceTarget, target: deviceTarget,
@ -697,7 +641,7 @@ func TestBaseDirForInstallPath(t *testing.T) {
testConfig := pathTestConfig("") testConfig := pathTestConfig("")
deviceTarget := Target{Os: Android, Arch: Arch{ArchType: Arm64}} deviceTarget := Target{Os: Android, Arch: Arch{ArchType: Arm64}}
ctx := &moduleInstallPathContextImpl{ ctx := &testModuleInstallPathContext{
baseModuleContext: baseModuleContext{ baseModuleContext: baseModuleContext{
os: deviceTarget.Os, os: deviceTarget.Os,
target: deviceTarget, target: deviceTarget,