Add test_for property
This change adds 'test_for' property to cc_test_* types. The property is
used to mark a module as a test for one or more APEXes, in which case
the module has accecss to the private part of the listed APEXes. For
example, the module is linked with the actrual shared library in the
APEX instead of the stub of the shared library.
Exempt-From-Owner-Approval: cherry-pick from AOSP
Bug: 129539670
Bug: 153046163
Test: m
Merged-In: I45ed0d7a15540b0d69b2a3b8d9c4cb202adff6f2
(cherry picked from commit 62304bbeec
)
Change-Id: I45ed0d7a15540b0d69b2a3b8d9c4cb202adff6f2
This commit is contained in:
parent
785afdb04c
commit
f0d01b7c98
4 changed files with 90 additions and 0 deletions
|
@ -114,6 +114,11 @@ type ApexModule interface {
|
||||||
// For example, with maxSdkVersion is 10 and versionList is [9,11]
|
// For example, with maxSdkVersion is 10 and versionList is [9,11]
|
||||||
// it returns 9 as string
|
// it returns 9 as string
|
||||||
ChooseSdkVersion(versionList []string, maxSdkVersion int) (string, error)
|
ChooseSdkVersion(versionList []string, maxSdkVersion int) (string, error)
|
||||||
|
|
||||||
|
// List of APEXes that this module tests. The module has access to
|
||||||
|
// the private part of the listed APEXes even when it is not included in the
|
||||||
|
// APEXes.
|
||||||
|
TestFor() []string
|
||||||
}
|
}
|
||||||
|
|
||||||
type ApexProperties struct {
|
type ApexProperties struct {
|
||||||
|
@ -159,6 +164,11 @@ func (m *ApexModuleBase) ApexAvailable() []string {
|
||||||
return m.ApexProperties.Apex_available
|
return m.ApexProperties.Apex_available
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *ApexModuleBase) TestFor() []string {
|
||||||
|
// To be implemented by concrete types inheriting ApexModuleBase
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (m *ApexModuleBase) BuildForApexes(apexes []ApexInfo) {
|
func (m *ApexModuleBase) BuildForApexes(apexes []ApexInfo) {
|
||||||
m.apexVariationsLock.Lock()
|
m.apexVariationsLock.Lock()
|
||||||
defer m.apexVariationsLock.Unlock()
|
defer m.apexVariationsLock.Unlock()
|
||||||
|
|
|
@ -4386,6 +4386,58 @@ func TestNoUpdatableJarsInBootImage(t *testing.T) {
|
||||||
testNoUpdatableJarsInBootImage(t, "", bp, transform)
|
testNoUpdatableJarsInBootImage(t, "", bp, transform)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestTestFor(t *testing.T) {
|
||||||
|
ctx, _ := testApex(t, `
|
||||||
|
apex {
|
||||||
|
name: "myapex",
|
||||||
|
key: "myapex.key",
|
||||||
|
native_shared_libs: ["mylib", "myprivlib"],
|
||||||
|
}
|
||||||
|
|
||||||
|
apex_key {
|
||||||
|
name: "myapex.key",
|
||||||
|
public_key: "testkey.avbpubkey",
|
||||||
|
private_key: "testkey.pem",
|
||||||
|
}
|
||||||
|
|
||||||
|
cc_library {
|
||||||
|
name: "mylib",
|
||||||
|
srcs: ["mylib.cpp"],
|
||||||
|
system_shared_libs: [],
|
||||||
|
stl: "none",
|
||||||
|
stubs: {
|
||||||
|
versions: ["1"],
|
||||||
|
},
|
||||||
|
apex_available: ["myapex"],
|
||||||
|
}
|
||||||
|
|
||||||
|
cc_library {
|
||||||
|
name: "myprivlib",
|
||||||
|
srcs: ["mylib.cpp"],
|
||||||
|
system_shared_libs: [],
|
||||||
|
stl: "none",
|
||||||
|
apex_available: ["myapex"],
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
cc_test {
|
||||||
|
name: "mytest",
|
||||||
|
gtest: false,
|
||||||
|
srcs: ["mylib.cpp"],
|
||||||
|
system_shared_libs: [],
|
||||||
|
stl: "none",
|
||||||
|
shared_libs: ["mylib", "myprivlib"],
|
||||||
|
test_for: ["myapex"]
|
||||||
|
}
|
||||||
|
`)
|
||||||
|
|
||||||
|
// the test 'mytest' is a test for the apex, therefore is linked to the
|
||||||
|
// actual implementation of mylib instead of its stub.
|
||||||
|
ldFlags := ctx.ModuleForTests("mytest", "android_arm64_armv8-a").Rule("ld").Args["libFlags"]
|
||||||
|
ensureContains(t, ldFlags, "mylib/android_arm64_armv8-a_shared/mylib.so")
|
||||||
|
ensureNotContains(t, ldFlags, "mylib/android_arm64_armv8-a_shared_1/mylib.so")
|
||||||
|
}
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
run := func() int {
|
run := func() int {
|
||||||
setUp()
|
setUp()
|
||||||
|
|
19
cc/cc.go
19
cc/cc.go
|
@ -2301,6 +2301,15 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
|
||||||
// always link to non-stub variant
|
// always link to non-stub variant
|
||||||
useThisDep = !depIsStubs
|
useThisDep = !depIsStubs
|
||||||
}
|
}
|
||||||
|
for _, testFor := range c.TestFor() {
|
||||||
|
// Another exception: if this module is bundled with an APEX, then
|
||||||
|
// it is linked with the non-stub variant of a module in the APEX
|
||||||
|
// as if this is part of the APEX.
|
||||||
|
if android.DirectlyInApex(testFor, depName) {
|
||||||
|
useThisDep = !depIsStubs
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// If building for APEX, use stubs only when it is not from
|
// If building for APEX, use stubs only when it is not from
|
||||||
// the same APEX
|
// the same APEX
|
||||||
|
@ -2727,6 +2736,16 @@ func (c *Module) AvailableFor(what string) bool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Module) TestFor() []string {
|
||||||
|
if test, ok := c.linker.(interface {
|
||||||
|
testFor() []string
|
||||||
|
}); ok {
|
||||||
|
return test.testFor()
|
||||||
|
} else {
|
||||||
|
return c.ApexModuleBase.TestFor()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Return true if the module is ever installable.
|
// Return true if the module is ever installable.
|
||||||
func (c *Module) EverInstallable() bool {
|
func (c *Module) EverInstallable() bool {
|
||||||
return c.installer != nil &&
|
return c.installer != nil &&
|
||||||
|
|
|
@ -29,6 +29,11 @@ type TestProperties struct {
|
||||||
|
|
||||||
// if set, use the isolated gtest runner. Defaults to false.
|
// if set, use the isolated gtest runner. Defaults to false.
|
||||||
Isolated *bool
|
Isolated *bool
|
||||||
|
|
||||||
|
// List of APEXes that this module tests. The module has access to
|
||||||
|
// the private part of the listed APEXes even when it is not included in the
|
||||||
|
// APEXes.
|
||||||
|
Test_for []string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test option struct.
|
// Test option struct.
|
||||||
|
@ -215,6 +220,10 @@ func (test *testDecorator) gtest() bool {
|
||||||
return BoolDefault(test.Properties.Gtest, true)
|
return BoolDefault(test.Properties.Gtest, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (test *testDecorator) testFor() []string {
|
||||||
|
return test.Properties.Test_for
|
||||||
|
}
|
||||||
|
|
||||||
func (test *testDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags {
|
func (test *testDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags {
|
||||||
if !test.gtest() {
|
if !test.gtest() {
|
||||||
return flags
|
return flags
|
||||||
|
|
Loading…
Reference in a new issue