2019-02-08 20:00:45 +08:00
|
|
|
// Copyright (C) 2019 The Android Open Source Project
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package sysprop
|
|
|
|
|
|
|
|
import (
|
2020-03-31 01:00:25 +08:00
|
|
|
"reflect"
|
|
|
|
|
2019-02-08 20:00:45 +08:00
|
|
|
"android/soong/android"
|
|
|
|
"android/soong/cc"
|
|
|
|
"android/soong/java"
|
|
|
|
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/google/blueprint/proptools"
|
|
|
|
)
|
|
|
|
|
|
|
|
var buildDir string
|
|
|
|
|
|
|
|
func setUp() {
|
|
|
|
var err error
|
|
|
|
buildDir, err = ioutil.TempDir("", "soong_sysprop_test")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func tearDown() {
|
|
|
|
os.RemoveAll(buildDir)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMain(m *testing.M) {
|
|
|
|
run := func() int {
|
|
|
|
setUp()
|
|
|
|
defer tearDown()
|
|
|
|
|
|
|
|
return m.Run()
|
|
|
|
}
|
|
|
|
|
|
|
|
os.Exit(run())
|
|
|
|
}
|
|
|
|
|
2019-12-14 12:41:13 +08:00
|
|
|
func testContext(config android.Config) *android.TestContext {
|
2019-02-08 20:00:45 +08:00
|
|
|
|
2020-10-30 08:09:13 +08:00
|
|
|
ctx := android.NewTestArchContext(config)
|
2021-01-21 01:13:52 +08:00
|
|
|
java.RegisterRequiredBuildComponentsForTest(ctx)
|
2019-12-19 19:18:54 +08:00
|
|
|
|
2019-02-08 20:00:45 +08:00
|
|
|
ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
|
|
|
|
|
2020-07-30 23:04:17 +08:00
|
|
|
android.RegisterPrebuiltMutators(ctx)
|
|
|
|
|
2019-12-20 00:01:36 +08:00
|
|
|
cc.RegisterRequiredBuildComponentsForTest(ctx)
|
2019-02-08 20:00:45 +08:00
|
|
|
|
2019-11-23 07:25:03 +08:00
|
|
|
ctx.RegisterModuleType("sysprop_library", syspropLibraryFactory)
|
2019-02-08 20:00:45 +08:00
|
|
|
|
2020-10-30 08:09:13 +08:00
|
|
|
ctx.Register()
|
2019-02-08 20:00:45 +08:00
|
|
|
|
2019-12-14 12:41:13 +08:00
|
|
|
return ctx
|
|
|
|
}
|
|
|
|
|
|
|
|
func run(t *testing.T, ctx *android.TestContext, config android.Config) {
|
|
|
|
t.Helper()
|
|
|
|
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
|
|
|
|
android.FailIfErrored(t, errs)
|
|
|
|
_, errs = ctx.PrepareBuildActions(config)
|
|
|
|
android.FailIfErrored(t, errs)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testConfig(env map[string]string, bp string, fs map[string][]byte) android.Config {
|
2019-02-08 20:00:45 +08:00
|
|
|
bp += cc.GatherRequiredDepsForTest(android.Android)
|
|
|
|
|
|
|
|
mockFS := map[string][]byte{
|
2019-07-30 16:55:33 +08:00
|
|
|
"a.java": nil,
|
|
|
|
"b.java": nil,
|
|
|
|
"c.java": nil,
|
|
|
|
"d.cpp": nil,
|
|
|
|
"api/sysprop-platform-current.txt": nil,
|
|
|
|
"api/sysprop-platform-latest.txt": nil,
|
|
|
|
"api/sysprop-platform-on-product-current.txt": nil,
|
|
|
|
"api/sysprop-platform-on-product-latest.txt": nil,
|
|
|
|
"api/sysprop-vendor-current.txt": nil,
|
|
|
|
"api/sysprop-vendor-latest.txt": nil,
|
2020-10-20 15:29:55 +08:00
|
|
|
"api/sysprop-vendor-on-product-current.txt": nil,
|
|
|
|
"api/sysprop-vendor-on-product-latest.txt": nil,
|
2019-07-30 16:55:33 +08:00
|
|
|
"api/sysprop-odm-current.txt": nil,
|
|
|
|
"api/sysprop-odm-latest.txt": nil,
|
|
|
|
"framework/aidl/a.aidl": nil,
|
2019-02-08 20:00:45 +08:00
|
|
|
|
|
|
|
// For framework-res, which is an implicit dependency for framework
|
2019-04-10 12:36:26 +08:00
|
|
|
"AndroidManifest.xml": nil,
|
|
|
|
"build/make/target/product/security/testkey": nil,
|
2019-02-08 20:00:45 +08:00
|
|
|
|
|
|
|
"build/soong/scripts/jar-wrapper.sh": nil,
|
|
|
|
|
|
|
|
"build/make/core/proguard.flags": nil,
|
|
|
|
"build/make/core/proguard_basic_keeps.flags": nil,
|
|
|
|
|
|
|
|
"jdk8/jre/lib/jce.jar": nil,
|
|
|
|
"jdk8/jre/lib/rt.jar": nil,
|
|
|
|
"jdk8/lib/tools.jar": nil,
|
|
|
|
|
|
|
|
"bar-doc/a.java": nil,
|
|
|
|
"bar-doc/b.java": nil,
|
|
|
|
"bar-doc/IFoo.aidl": nil,
|
|
|
|
"bar-doc/known_oj_tags.txt": nil,
|
|
|
|
"external/doclava/templates-sdk": nil,
|
|
|
|
|
|
|
|
"cert/new_cert.x509.pem": nil,
|
|
|
|
"cert/new_cert.pk8": nil,
|
|
|
|
|
|
|
|
"android/sysprop/PlatformProperties.sysprop": nil,
|
|
|
|
"com/android/VendorProperties.sysprop": nil,
|
2019-07-30 16:55:33 +08:00
|
|
|
"com/android2/OdmProperties.sysprop": nil,
|
2019-02-08 20:00:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for k, v := range fs {
|
|
|
|
mockFS[k] = v
|
|
|
|
}
|
|
|
|
|
2019-12-14 12:41:13 +08:00
|
|
|
config := java.TestConfig(buildDir, env, bp, mockFS)
|
2019-02-16 02:37:39 +08:00
|
|
|
|
2019-02-08 20:00:45 +08:00
|
|
|
config.TestProductVariables.DeviceSystemSdkVersions = []string{"28"}
|
|
|
|
config.TestProductVariables.DeviceVndkVersion = proptools.StringPtr("current")
|
|
|
|
config.TestProductVariables.Platform_vndk_version = proptools.StringPtr("VER")
|
2019-02-16 02:37:39 +08:00
|
|
|
|
2019-02-08 20:00:45 +08:00
|
|
|
return config
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func test(t *testing.T, bp string) *android.TestContext {
|
|
|
|
t.Helper()
|
2019-12-14 12:41:13 +08:00
|
|
|
config := testConfig(nil, bp, nil)
|
|
|
|
ctx := testContext(config)
|
2019-02-08 20:00:45 +08:00
|
|
|
run(t, ctx, config)
|
|
|
|
|
|
|
|
return ctx
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSyspropLibrary(t *testing.T) {
|
|
|
|
ctx := test(t, `
|
|
|
|
sysprop_library {
|
|
|
|
name: "sysprop-platform",
|
2020-03-31 01:00:25 +08:00
|
|
|
apex_available: ["//apex_available:platform"],
|
2019-02-08 20:00:45 +08:00
|
|
|
srcs: ["android/sysprop/PlatformProperties.sysprop"],
|
|
|
|
api_packages: ["android.sysprop"],
|
|
|
|
property_owner: "Platform",
|
|
|
|
vendor_available: true,
|
2020-02-03 17:06:46 +08:00
|
|
|
host_supported: true,
|
2019-02-08 20:00:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
sysprop_library {
|
|
|
|
name: "sysprop-platform-on-product",
|
|
|
|
srcs: ["android/sysprop/PlatformProperties.sysprop"],
|
|
|
|
api_packages: ["android.sysprop"],
|
|
|
|
property_owner: "Platform",
|
|
|
|
product_specific: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
sysprop_library {
|
|
|
|
name: "sysprop-vendor",
|
|
|
|
srcs: ["com/android/VendorProperties.sysprop"],
|
|
|
|
api_packages: ["com.android"],
|
|
|
|
property_owner: "Vendor",
|
2020-10-20 15:29:55 +08:00
|
|
|
vendor: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
sysprop_library {
|
|
|
|
name: "sysprop-vendor-on-product",
|
|
|
|
srcs: ["com/android/VendorProperties.sysprop"],
|
|
|
|
api_packages: ["com.android"],
|
|
|
|
property_owner: "Vendor",
|
2019-02-08 20:00:45 +08:00
|
|
|
product_specific: true,
|
|
|
|
}
|
|
|
|
|
2019-07-30 16:55:33 +08:00
|
|
|
sysprop_library {
|
|
|
|
name: "sysprop-odm",
|
|
|
|
srcs: ["com/android2/OdmProperties.sysprop"],
|
|
|
|
api_packages: ["com.android2"],
|
|
|
|
property_owner: "Odm",
|
|
|
|
device_specific: true,
|
|
|
|
}
|
|
|
|
|
2019-02-08 20:00:45 +08:00
|
|
|
java_library {
|
|
|
|
name: "java-platform",
|
|
|
|
srcs: ["c.java"],
|
|
|
|
sdk_version: "system_current",
|
|
|
|
libs: ["sysprop-platform"],
|
|
|
|
}
|
|
|
|
|
2019-12-09 17:15:47 +08:00
|
|
|
java_library {
|
|
|
|
name: "java-platform-private",
|
|
|
|
srcs: ["c.java"],
|
|
|
|
platform_apis: true,
|
|
|
|
libs: ["sysprop-platform"],
|
|
|
|
}
|
|
|
|
|
2019-02-08 20:00:45 +08:00
|
|
|
java_library {
|
|
|
|
name: "java-product",
|
|
|
|
srcs: ["c.java"],
|
|
|
|
sdk_version: "system_current",
|
|
|
|
product_specific: true,
|
2020-10-20 15:29:55 +08:00
|
|
|
libs: ["sysprop-platform", "sysprop-vendor-on-product"],
|
2019-02-08 20:00:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "java-vendor",
|
|
|
|
srcs: ["c.java"],
|
|
|
|
sdk_version: "system_current",
|
|
|
|
soc_specific: true,
|
|
|
|
libs: ["sysprop-platform", "sysprop-vendor"],
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "cc-client-platform",
|
|
|
|
srcs: ["d.cpp"],
|
|
|
|
static_libs: ["sysprop-platform"],
|
|
|
|
}
|
|
|
|
|
2019-02-25 21:14:17 +08:00
|
|
|
cc_library_static {
|
|
|
|
name: "cc-client-platform-static",
|
|
|
|
srcs: ["d.cpp"],
|
|
|
|
whole_static_libs: ["sysprop-platform"],
|
|
|
|
}
|
|
|
|
|
2019-02-08 20:00:45 +08:00
|
|
|
cc_library {
|
|
|
|
name: "cc-client-product",
|
|
|
|
srcs: ["d.cpp"],
|
|
|
|
product_specific: true,
|
2020-10-20 15:29:55 +08:00
|
|
|
static_libs: ["sysprop-platform-on-product", "sysprop-vendor-on-product"],
|
2019-02-08 20:00:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "cc-client-vendor",
|
|
|
|
srcs: ["d.cpp"],
|
|
|
|
soc_specific: true,
|
|
|
|
static_libs: ["sysprop-platform", "sysprop-vendor"],
|
|
|
|
}
|
2019-03-27 16:20:37 +08:00
|
|
|
|
2020-02-03 17:06:46 +08:00
|
|
|
cc_library {
|
|
|
|
name: "libbase",
|
|
|
|
host_supported: true,
|
|
|
|
}
|
|
|
|
|
2019-03-27 16:20:37 +08:00
|
|
|
cc_library_headers {
|
|
|
|
name: "libbase_headers",
|
|
|
|
vendor_available: true,
|
|
|
|
recovery_available: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_library {
|
|
|
|
name: "liblog",
|
2019-06-02 15:53:50 +08:00
|
|
|
no_libcrt: true,
|
2019-03-27 16:20:37 +08:00
|
|
|
nocrt: true,
|
|
|
|
system_shared_libs: [],
|
|
|
|
recovery_available: true,
|
2020-02-03 17:06:46 +08:00
|
|
|
host_supported: true,
|
2020-10-14 09:43:54 +08:00
|
|
|
llndk_stubs: "liblog.llndk",
|
2020-02-03 17:06:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
cc_binary_host {
|
|
|
|
name: "hostbin",
|
|
|
|
static_libs: ["sysprop-platform"],
|
2019-03-27 16:20:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
llndk_library {
|
2020-10-14 09:43:54 +08:00
|
|
|
name: "liblog.llndk",
|
2019-03-27 16:20:37 +08:00
|
|
|
symbol_file: "",
|
|
|
|
}
|
2019-07-30 16:55:33 +08:00
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "sysprop-library-stub-platform",
|
|
|
|
sdk_version: "core_current",
|
|
|
|
}
|
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "sysprop-library-stub-vendor",
|
|
|
|
soc_specific: true,
|
|
|
|
sdk_version: "core_current",
|
|
|
|
}
|
2020-10-20 15:29:55 +08:00
|
|
|
|
|
|
|
java_library {
|
|
|
|
name: "sysprop-library-stub-product",
|
|
|
|
product_specific: true,
|
|
|
|
sdk_version: "core_current",
|
|
|
|
}
|
2019-02-08 20:00:45 +08:00
|
|
|
`)
|
|
|
|
|
2019-07-30 16:55:33 +08:00
|
|
|
// Check for generated cc_library
|
2019-02-08 20:00:45 +08:00
|
|
|
for _, variant := range []string{
|
2019-11-21 09:12:35 +08:00
|
|
|
"android_vendor.VER_arm_armv7-a-neon_shared",
|
|
|
|
"android_vendor.VER_arm_armv7-a-neon_static",
|
|
|
|
"android_vendor.VER_arm64_armv8-a_shared",
|
|
|
|
"android_vendor.VER_arm64_armv8-a_static",
|
2019-02-08 20:00:45 +08:00
|
|
|
} {
|
|
|
|
ctx.ModuleForTests("libsysprop-platform", variant)
|
|
|
|
ctx.ModuleForTests("libsysprop-vendor", variant)
|
2019-07-30 16:55:33 +08:00
|
|
|
ctx.ModuleForTests("libsysprop-odm", variant)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, variant := range []string{
|
2019-11-21 08:39:12 +08:00
|
|
|
"android_arm_armv7-a-neon_shared",
|
|
|
|
"android_arm_armv7-a-neon_static",
|
|
|
|
"android_arm64_armv8-a_shared",
|
|
|
|
"android_arm64_armv8-a_static",
|
2019-07-30 16:55:33 +08:00
|
|
|
} {
|
2020-03-31 01:00:25 +08:00
|
|
|
library := ctx.ModuleForTests("libsysprop-platform", variant).Module().(*cc.Module)
|
|
|
|
expectedApexAvailableOnLibrary := []string{"//apex_available:platform"}
|
|
|
|
if !reflect.DeepEqual(library.ApexProperties.Apex_available, expectedApexAvailableOnLibrary) {
|
|
|
|
t.Errorf("apex available property on libsysprop-platform must be %#v, but was %#v.",
|
|
|
|
expectedApexAvailableOnLibrary, library.ApexProperties.Apex_available)
|
|
|
|
}
|
2019-07-30 16:55:33 +08:00
|
|
|
|
2020-10-20 15:29:55 +08:00
|
|
|
// product variant of vendor-owned sysprop_library
|
|
|
|
ctx.ModuleForTests("libsysprop-vendor-on-product", variant)
|
2019-02-08 20:00:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ctx.ModuleForTests("sysprop-platform", "android_common")
|
2019-12-09 17:15:47 +08:00
|
|
|
ctx.ModuleForTests("sysprop-platform_public", "android_common")
|
2019-02-08 20:00:45 +08:00
|
|
|
ctx.ModuleForTests("sysprop-vendor", "android_common")
|
2020-10-20 15:29:55 +08:00
|
|
|
ctx.ModuleForTests("sysprop-vendor-on-product", "android_common")
|
2019-02-08 20:00:45 +08:00
|
|
|
|
|
|
|
// Check for exported includes
|
2019-11-21 08:39:12 +08:00
|
|
|
coreVariant := "android_arm64_armv8-a_static"
|
2019-11-21 09:12:35 +08:00
|
|
|
vendorVariant := "android_vendor.VER_arm64_armv8-a_static"
|
2019-02-08 20:00:45 +08:00
|
|
|
|
2019-11-21 08:39:12 +08:00
|
|
|
platformInternalPath := "libsysprop-platform/android_arm64_armv8-a_static/gen/sysprop/include"
|
|
|
|
platformPublicCorePath := "libsysprop-platform/android_arm64_armv8-a_static/gen/sysprop/public/include"
|
2019-11-21 09:12:35 +08:00
|
|
|
platformPublicVendorPath := "libsysprop-platform/android_vendor.VER_arm64_armv8-a_static/gen/sysprop/public/include"
|
2019-02-08 20:00:45 +08:00
|
|
|
|
2019-11-21 08:39:12 +08:00
|
|
|
platformOnProductPath := "libsysprop-platform-on-product/android_arm64_armv8-a_static/gen/sysprop/public/include"
|
2019-02-08 20:00:45 +08:00
|
|
|
|
2019-11-21 09:12:35 +08:00
|
|
|
vendorInternalPath := "libsysprop-vendor/android_vendor.VER_arm64_armv8-a_static/gen/sysprop/include"
|
2020-10-20 15:29:55 +08:00
|
|
|
vendorPublicPath := "libsysprop-vendor-on-product/android_arm64_armv8-a_static/gen/sysprop/public/include"
|
2019-02-08 20:00:45 +08:00
|
|
|
|
|
|
|
platformClient := ctx.ModuleForTests("cc-client-platform", coreVariant)
|
|
|
|
platformFlags := platformClient.Rule("cc").Args["cFlags"]
|
|
|
|
|
2019-02-25 21:14:17 +08:00
|
|
|
// platform should use platform's internal header
|
2019-02-08 20:00:45 +08:00
|
|
|
if !strings.Contains(platformFlags, platformInternalPath) {
|
|
|
|
t.Errorf("flags for platform must contain %#v, but was %#v.",
|
|
|
|
platformInternalPath, platformFlags)
|
|
|
|
}
|
|
|
|
|
2019-02-25 21:14:17 +08:00
|
|
|
platformStaticClient := ctx.ModuleForTests("cc-client-platform-static", coreVariant)
|
|
|
|
platformStaticFlags := platformStaticClient.Rule("cc").Args["cFlags"]
|
|
|
|
|
|
|
|
// platform-static should use platform's internal header
|
|
|
|
if !strings.Contains(platformStaticFlags, platformInternalPath) {
|
|
|
|
t.Errorf("flags for platform-static must contain %#v, but was %#v.",
|
|
|
|
platformInternalPath, platformStaticFlags)
|
|
|
|
}
|
|
|
|
|
2019-02-08 20:00:45 +08:00
|
|
|
productClient := ctx.ModuleForTests("cc-client-product", coreVariant)
|
|
|
|
productFlags := productClient.Rule("cc").Args["cFlags"]
|
|
|
|
|
2019-06-08 19:36:59 +08:00
|
|
|
// Product should use platform's and vendor's public headers
|
2019-02-08 20:00:45 +08:00
|
|
|
if !strings.Contains(productFlags, platformOnProductPath) ||
|
2019-06-08 19:36:59 +08:00
|
|
|
!strings.Contains(productFlags, vendorPublicPath) {
|
2019-02-08 20:00:45 +08:00
|
|
|
t.Errorf("flags for product must contain %#v and %#v, but was %#v.",
|
2019-06-08 19:36:59 +08:00
|
|
|
platformPublicCorePath, vendorPublicPath, productFlags)
|
2019-02-08 20:00:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
vendorClient := ctx.ModuleForTests("cc-client-vendor", vendorVariant)
|
|
|
|
vendorFlags := vendorClient.Rule("cc").Args["cFlags"]
|
|
|
|
|
2019-06-08 19:36:59 +08:00
|
|
|
// Vendor should use platform's public header and vendor's internal header
|
|
|
|
if !strings.Contains(vendorFlags, platformPublicVendorPath) ||
|
2019-02-08 20:00:45 +08:00
|
|
|
!strings.Contains(vendorFlags, vendorInternalPath) {
|
|
|
|
t.Errorf("flags for vendor must contain %#v and %#v, but was %#v.",
|
2019-06-08 19:36:59 +08:00
|
|
|
platformPublicVendorPath, vendorInternalPath, vendorFlags)
|
2019-02-08 20:00:45 +08:00
|
|
|
}
|
2019-12-09 17:15:47 +08:00
|
|
|
|
|
|
|
// Java modules linking against system API should use public stub
|
2021-02-27 08:20:32 +08:00
|
|
|
javaSystemApiClient := ctx.ModuleForTests("java-platform", "android_common").Rule("javac")
|
|
|
|
syspropPlatformPublic := ctx.ModuleForTests("sysprop-platform_public", "android_common").Description("for turbine")
|
|
|
|
if g, w := javaSystemApiClient.Implicits.Strings(), syspropPlatformPublic.Output.String(); !android.InList(w, g) {
|
|
|
|
t.Errorf("system api client should use public stub %q, got %q", w, g)
|
2019-12-09 17:15:47 +08:00
|
|
|
}
|
2019-02-08 20:00:45 +08:00
|
|
|
}
|