Fix install location for vendor tests

These should be install in /data/nativetest* with the rest of the tests,
but had been moved to /vendor/nativetest* accidentally. Add some tests
so that this doesn't happen again.

Bug: 63393698
Test: m -j blueprint_tools
Test: compare out/soong/Android-aosp_arm64.mk
Test: compare out/soong/build.ninja
Change-Id: Id3b08a7e3908955df18a043a02ea576dc88086c3
This commit is contained in:
Dan Willemsen
2017-07-06 16:59:48 -07:00
parent 4c35af09ea
commit 00269f23ee
3 changed files with 188 additions and 13 deletions

View File

@@ -20,6 +20,8 @@ import (
"reflect"
"strings"
"testing"
"github.com/google/blueprint/pathtools"
)
type strsTestCase struct {
@@ -180,3 +182,161 @@ func p(in interface{}) string {
return fmt.Sprintf("%#v", in)
}
}
type moduleInstallPathContextImpl struct {
androidBaseContextImpl
inData bool
inSanitizerDir bool
}
func (moduleInstallPathContextImpl) Fs() pathtools.FileSystem {
return pathtools.MockFs(nil)
}
func (m moduleInstallPathContextImpl) Config() interface{} {
return m.androidBaseContextImpl.config
}
func (moduleInstallPathContextImpl) AddNinjaFileDeps(deps ...string) {}
func (m moduleInstallPathContextImpl) InstallInData() bool {
return m.inData
}
func (m moduleInstallPathContextImpl) InstallInSanitizerDir() bool {
return m.inSanitizerDir
}
func TestPathForModuleInstall(t *testing.T) {
testConfig := TestConfig("")
hostTarget := Target{Os: Linux}
deviceTarget := Target{Os: Android}
testCases := []struct {
name string
ctx *moduleInstallPathContextImpl
in []string
out string
}{
{
name: "host binary",
ctx: &moduleInstallPathContextImpl{
androidBaseContextImpl: androidBaseContextImpl{
target: hostTarget,
},
},
in: []string{"bin", "my_test"},
out: "host/linux-x86/bin/my_test",
},
{
name: "system binary",
ctx: &moduleInstallPathContextImpl{
androidBaseContextImpl: androidBaseContextImpl{
target: deviceTarget,
},
},
in: []string{"bin", "my_test"},
out: "target/product/test_device/system/bin/my_test",
},
{
name: "vendor binary",
ctx: &moduleInstallPathContextImpl{
androidBaseContextImpl: androidBaseContextImpl{
target: deviceTarget,
vendor: true,
},
},
in: []string{"bin", "my_test"},
out: "target/product/test_device/vendor/bin/my_test",
},
{
name: "system native test binary",
ctx: &moduleInstallPathContextImpl{
androidBaseContextImpl: androidBaseContextImpl{
target: deviceTarget,
},
inData: true,
},
in: []string{"nativetest", "my_test"},
out: "target/product/test_device/data/nativetest/my_test",
},
{
name: "vendor native test binary",
ctx: &moduleInstallPathContextImpl{
androidBaseContextImpl: androidBaseContextImpl{
target: deviceTarget,
vendor: true,
},
inData: true,
},
in: []string{"nativetest", "my_test"},
out: "target/product/test_device/data/nativetest/my_test",
},
{
name: "sanitized system binary",
ctx: &moduleInstallPathContextImpl{
androidBaseContextImpl: androidBaseContextImpl{
target: deviceTarget,
},
inSanitizerDir: true,
},
in: []string{"bin", "my_test"},
out: "target/product/test_device/data/asan/system/bin/my_test",
},
{
name: "sanitized vendor binary",
ctx: &moduleInstallPathContextImpl{
androidBaseContextImpl: androidBaseContextImpl{
target: deviceTarget,
vendor: true,
},
inSanitizerDir: true,
},
in: []string{"bin", "my_test"},
out: "target/product/test_device/data/asan/vendor/bin/my_test",
},
{
name: "sanitized system native test binary",
ctx: &moduleInstallPathContextImpl{
androidBaseContextImpl: androidBaseContextImpl{
target: deviceTarget,
},
inData: true,
inSanitizerDir: true,
},
in: []string{"nativetest", "my_test"},
out: "target/product/test_device/data/asan/data/nativetest/my_test",
},
{
name: "sanitized vendor native test binary",
ctx: &moduleInstallPathContextImpl{
androidBaseContextImpl: androidBaseContextImpl{
target: deviceTarget,
vendor: true,
},
inData: true,
inSanitizerDir: true,
},
in: []string{"nativetest", "my_test"},
out: "target/product/test_device/data/asan/data/nativetest/my_test",
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
tc.ctx.androidBaseContextImpl.config = testConfig
output := PathForModuleInstall(tc.ctx, tc.in...)
if output.basePath.path != tc.out {
t.Errorf("unexpected path:\n got: %q\nwant: %q\n",
output.basePath.path,
tc.out)
}
})
}
}