diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2024-02-03 00:03:09 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2024-02-03 00:03:09 +0000 |
commit | ab7b758680b8de463c835584187dbca333a952e3 (patch) | |
tree | 057dfbe33c594257a612532c9bea805766031d8e | |
parent | b0084b73a665b7bd4f389b986bcde90c7f887b7b (diff) | |
parent | 77649f57920a2c552ad406c15a12894c996dc837 (diff) | |
download | hidl-simpleperf-release.tar.gz |
Snap for 11400057 from 77649f57920a2c552ad406c15a12894c996dc837 to simpleperf-releasesimpleperf-release
Change-Id: I3fd8561322178917e25810bf175cf962af22c31d
-rw-r--r-- | build/Android.bp | 4 | ||||
-rw-r--r-- | build/go.mod | 2 | ||||
-rw-r--r-- | build/hidl_interface.go | 160 | ||||
-rw-r--r-- | build/hidl_interface_conversion_test.go | 127 | ||||
-rw-r--r-- | build/hidl_package_root.go | 26 | ||||
-rw-r--r-- | build/properties.go | 8 | ||||
-rw-r--r-- | test/hidl_test/hidl_test.py | 7 | ||||
-rw-r--r-- | test/hidl_test/hidl_test_client.cpp | 26 | ||||
-rw-r--r-- | test/java_test/hidl_test_java.py | 8 | ||||
-rw-r--r-- | test/java_test/hidl_test_java_native.cpp | 13 | ||||
-rw-r--r-- | test/java_test/src/com/android/commands/hidl_test_java/HidlTestJava.java | 8 | ||||
-rw-r--r-- | test/lazy_test/Android.bp | 8 | ||||
-rw-r--r-- | test/lazy_test/hidl_lazy_test.cpp | 14 |
13 files changed, 85 insertions, 326 deletions
diff --git a/build/Android.bp b/build/Android.bp index bebdd9db..963a6904 100644 --- a/build/Android.bp +++ b/build/Android.bp @@ -28,7 +28,6 @@ bootstrap_go_package { "blueprint", "soong", "soong-android", - "soong-bp2build", "soong-cc", "soong-genrule", "soong-java", @@ -40,9 +39,6 @@ bootstrap_go_package { "properties.go", "utils.go", ], - testSrcs: [ - "hidl_interface_conversion_test.go", - ], pluginFor: ["soong_build"], } diff --git a/build/go.mod b/build/go.mod index 2d75c6eb..6e3342ee 100644 --- a/build/go.mod +++ b/build/go.mod @@ -22,6 +22,6 @@ exclude github.com/golang/protobuf v1.5.0 replace github.com/google/go-cmp v0.5.5 => ../../../../external/go-cmp // Indirect dep from go-cmp -exclude golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 +exclude golang.org/x/xerrors v0.0.0-20220609144429-65e65417b02f go 1.18 diff --git a/build/hidl_interface.go b/build/hidl_interface.go index d0b5386b..ace42245 100644 --- a/build/hidl_interface.go +++ b/build/hidl_interface.go @@ -22,11 +22,9 @@ import ( "github.com/google/blueprint/proptools" "android/soong/android" - "android/soong/bazel" "android/soong/cc" "android/soong/genrule" "android/soong/java" - "android/soong/ui/metrics/bp2build_metrics_proto" ) var ( @@ -41,22 +39,22 @@ var ( intermediatesDir = pctx.IntermediatesPathVariable("intermediatesDir", "") hidlRule = pctx.StaticRule("hidlRule", blueprint.RuleParams{ - Depfile: "${depfile}", + Depfile: "${out}.d", Deps: blueprint.DepsGCC, - Command: "rm -rf ${genDir} && ${hidl} -R -p . -d ${depfile} -o ${genDir} -L ${language} ${options} ${fqName}", + Command: "rm -rf ${genDir} && ${hidl} -R -p . -d ${out}.d -o ${genDir} -L ${language} ${options} ${fqName}", CommandDeps: []string{"${hidl}"}, Description: "HIDL ${language}: ${in} => ${out}", - }, "depfile", "fqName", "genDir", "language", "options") + }, "fqName", "genDir", "language", "options") hidlSrcJarRule = pctx.StaticRule("hidlSrcJarRule", blueprint.RuleParams{ - Depfile: "${depfile}", + Depfile: "${out}.d", Deps: blueprint.DepsGCC, Command: "rm -rf ${genDir} && " + - "${hidl} -R -p . -d ${depfile} -o ${genDir}/srcs -L ${language} ${options} ${fqName} && " + + "${hidl} -R -p . -d ${out}.d -o ${genDir}/srcs -L ${language} ${options} ${fqName} && " + "${soong_zip} -o ${genDir}/srcs.srcjar -C ${genDir}/srcs -D ${genDir}/srcs", CommandDeps: []string{"${hidl}", "${soong_zip}"}, Description: "HIDL ${language}: ${in} => srcs.srcjar", - }, "depfile", "fqName", "genDir", "language", "options") + }, "fqName", "genDir", "language", "options") lintRule = pctx.StaticRule("lintRule", blueprint.RuleParams{ Command: "rm -f ${output} && touch ${output} && ${lint} -j -e -R -p . ${options} ${fqName} > ${output}", @@ -212,7 +210,6 @@ type hidlGenProperties struct { type hidlGenRule struct { android.ModuleBase - android.BazelModuleBase properties hidlGenProperties @@ -319,7 +316,6 @@ func (g *hidlGenRule) GenerateAndroidBuildActions(ctx android.ModuleContext) { Output: g.genOutputs[0], ImplicitOutputs: g.genOutputs[1:], Args: map[string]string{ - "depfile": g.genOutputs[0].String() + ".d", "genDir": g.genOutputDir.String(), "fqName": g.properties.FqName, "language": g.properties.Language, @@ -352,21 +348,10 @@ func (g *hidlGenRule) DepsMutator(ctx android.BottomUpMutatorContext) { ctx.AddReverseDependency(ctx.Module(), nil, hidlMetadataSingletonName) } -func (g *hidlGenRule) ConvertWithBp2build(ctx android.Bp2buildMutatorContext) { - hidlLang := g.properties.Language - switch hidlLang { - case "c++-sources", "c++-headers": - panic(fmt.Errorf("Conversion of %q is handled via macros in Bazel", ctx.ModuleName())) - default: - ctx.MarkBp2buildUnconvertible(bp2build_metrics_proto.UnconvertedReasonType_PROPERTY_UNSUPPORTED, fmt.Sprintf("Lang: %q", hidlLang)) - } -} - func hidlGenFactory() android.Module { g := &hidlGenRule{} g.AddProperties(&g.properties) android.InitAndroidModule(g) - android.InitBazelModule(g) return g } @@ -447,7 +432,6 @@ type hidlInterfaceProperties struct { type hidlInterface struct { android.ModuleBase - android.BazelModuleBase properties hidlInterfaceProperties } @@ -568,41 +552,11 @@ This corresponds to the "-r%s:<some path>" option that would be passed into hidl vendorAvailable = proptools.BoolPtr(true) } - var bp2build bool - // TODO: b/295566168 - this will need to change once build files are checked in to account for - // checked in modules in mixed builds - if b, ok := mctx.Module().(android.Bazelable); ok { - bp2build = b.ShouldConvertWithBp2build(mctx) - } - - var fgBp2build *bool - var fgLabel *string - if bp2build { - fgLabel = proptools.StringPtr(fmt.Sprintf("//%s:%s", mctx.ModuleDir(), name.fileGroupName())) - } else { - fgBp2build = proptools.BoolPtr(false) - } - // TODO(b/69002743): remove filegroups mctx.CreateModule(android.FileGroupFactory, &fileGroupProperties{ Name: proptools.StringPtr(name.fileGroupName()), Srcs: i.properties.Srcs, - }, - &bazelProperties{ - &Bazel_module{ - Label: fgLabel, - Bp2build_available: fgBp2build, - }}, - ) - - var ccBp2build *bool - var ccHeadersLabel, ccSourcesLabel *string - if bp2build { - ccHeadersLabel = proptools.StringPtr(fmt.Sprintf("//%s:%s", mctx.ModuleDir(), name.headersName())) - ccSourcesLabel = proptools.StringPtr(fmt.Sprintf("//%s:%s", mctx.ModuleDir(), name.sourcesName())) - } else { - ccBp2build = proptools.BoolPtr(false) - } + }) mctx.CreateModule(hidlGenFactory, &nameProperties{ Name: proptools.StringPtr(name.sourcesName()), @@ -613,13 +567,8 @@ This corresponds to the "-r%s:<some path>" option that would be passed into hidl Interfaces: i.properties.Interfaces, Inputs: i.properties.Srcs, Outputs: concat(wrap(name.dir(), interfaces, "All.cpp"), wrap(name.dir(), types, ".cpp")), - }, - &bazelProperties{ - &Bazel_module{ - Label: ccSourcesLabel, - Bp2build_available: ccBp2build, - }}, - ) + }) + mctx.CreateModule(hidlGenFactory, &nameProperties{ Name: proptools.StringPtr(name.headersName()), }, &hidlGenProperties{ @@ -635,19 +584,9 @@ This corresponds to the "-r%s:<some path>" option that would be passed into hidl wrap(name.dir()+"IHw", interfaces, ".h"), wrap(name.dir(), types, ".h"), wrap(name.dir()+"hw", types, ".h")), - }, - &bazelProperties{ - &Bazel_module{ - Label: ccHeadersLabel, - Bp2build_available: ccBp2build, - }}, - ) + }) if shouldGenerateLibrary { - var label *string - if bp2build { - label = proptools.StringPtr(fmt.Sprintf("//%s:%s", mctx.ModuleDir(), name.string())) - } mctx.CreateModule(cc.LibraryFactory, &ccProperties{ Name: proptools.StringPtr(name.string()), Host_supported: proptools.BoolPtr(true), @@ -672,13 +611,7 @@ This corresponds to the "-r%s:<some path>" option that would be passed into hidl Export_generated_headers: []string{name.headersName()}, Apex_available: i.properties.Apex_available, Min_sdk_version: getMinSdkVersion(name.string()), - }, &i.properties.VndkProperties, - &bazelProperties{ - &Bazel_module{ - Label: label, - Bp2build_available: ccBp2build, - }}, - ) + }, &i.properties.VndkProperties) } if shouldGenerateJava { @@ -711,21 +644,11 @@ This corresponds to the "-r%s:<some path>" option that would be passed into hidl mctx.CreateModule(java.LibraryFactory, &javaProperties{ Name: proptools.StringPtr(name.javaName()), Static_libs: javaDependencies, - }, &commonJavaProperties, - &bazelProperties{ - &Bazel_module{ - Bp2build_available: proptools.BoolPtr(false), - }}, - ) + }, &commonJavaProperties) mctx.CreateModule(java.LibraryFactory, &javaProperties{ Name: proptools.StringPtr(name.javaSharedName()), Libs: javaDependencies, - }, &commonJavaProperties, - &bazelProperties{ - &Bazel_module{ - Bp2build_available: proptools.BoolPtr(false), - }}, - ) + }, &commonJavaProperties) } if shouldGenerateJavaConstants { @@ -746,12 +669,7 @@ This corresponds to the "-r%s:<some path>" option that would be passed into hidl Srcs: []string{":" + name.javaConstantsSourcesName()}, Apex_available: i.properties.Apex_available, Min_sdk_version: getMinSdkVersion(name.string()), - }, - &bazelProperties{ - &Bazel_module{ - Bp2build_available: proptools.BoolPtr(false), - }}, - ) + }) } mctx.CreateModule(hidlGenFactory, &nameProperties{ @@ -803,60 +721,10 @@ func HidlInterfaceFactory() android.Module { i.AddProperties(&i.properties) android.InitAndroidModule(i) android.AddLoadHook(i, func(ctx android.LoadHookContext) { hidlInterfaceMutator(ctx, i) }) - android.InitBazelModule(i) return i } -type hidlInterfaceAttributes struct { - Srcs bazel.LabelListAttribute - Deps bazel.LabelListAttribute - Root bazel.Label - Min_sdk_version *string - Tags []string -} - -func (m *hidlInterface) ConvertWithBp2build(ctx android.Bp2buildMutatorContext) { - srcs := bazel.MakeLabelListAttribute( - android.BazelLabelForModuleSrc(ctx, m.properties.Srcs)) - - // The interface dependencies are added earlier with the suffix of "_interface", - // so we need to look for them with the hidlInterfaceSuffix added to the names. - // Later we trim the "_interface" suffix. Here is an example: - // hidl_interface( - // name = "android.hardware.nfc@1.1", - // deps = [ - // "//hardware/interfaces/nfc/1.0:android.hardware.nfc@1.0", - // "//system/libhidl/transport/base/1.0:android.hidl.base@1.0", - // ], - // ) - deps := android.BazelLabelForModuleDeps(ctx, wrap("", m.properties.Interfaces, hidlInterfaceSuffix)) - var dep_labels []bazel.Label - for _, label := range deps.Includes { - dep_labels = append(dep_labels, - bazel.Label{Label: strings.TrimSuffix(label.Label, hidlInterfaceSuffix)}) - } - - root := android.BazelLabelForModuleDepSingle(ctx, m.properties.Root) - - bazel_hidl_interface_name := strings.TrimSuffix(m.Name(), hidlInterfaceSuffix) - - attrs := &hidlInterfaceAttributes{ - Srcs: srcs, - Deps: bazel.MakeLabelListAttribute(bazel.MakeLabelList(dep_labels)), - Root: root, - Min_sdk_version: getMinSdkVersion(bazel_hidl_interface_name), - Tags: android.ConvertApexAvailableToTagsWithoutTestApexes(ctx, m.properties.Apex_available), - } - - props := bazel.BazelTargetModuleProperties{ - Rule_class: "hidl_interface", - Bzl_load_location: "//build/bazel/rules/hidl:hidl_interface.bzl", - } - - ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: bazel_hidl_interface_name}, attrs) -} - var minSdkVersion = map[string]string{ "android.hardware.audio.common@5.0": "30", "android.hardware.audio.common@6.0": "31", diff --git a/build/hidl_interface_conversion_test.go b/build/hidl_interface_conversion_test.go deleted file mode 100644 index fed5abda..00000000 --- a/build/hidl_interface_conversion_test.go +++ /dev/null @@ -1,127 +0,0 @@ -// Copyright 2022 Google Inc. All rights reserved. -// -// 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 hidl - -import ( - "testing" - - "android/soong/android" - "android/soong/bp2build" - "android/soong/cc" -) - -func runHidlInterfaceTestCase(t *testing.T, tc bp2build.Bp2buildTestCase) { - t.Helper() - bp2build.RunBp2BuildTestCase( - t, - func(ctx android.RegistrationContext) { - ctx.RegisterModuleType("cc_defaults", func() android.Module { return cc.DefaultsFactory() }) - ctx.RegisterModuleType("hidl_interface", HidlInterfaceFactory) - ctx.RegisterModuleType("hidl_package_root", HidlPackageRootFactory) - }, - tc, - ) -} - -func TestHidlInterface(t *testing.T) { - runHidlInterfaceTestCase(t, bp2build.Bp2buildTestCase{ - Description: `hidl_interface with common usage of properties`, - Filesystem: map[string]string{ - "current.txt": "", - }, - Blueprint: ` -hidl_package_root { - name: "android.hardware", - use_current: true, -} -cc_defaults { - name: "hidl-module-defaults", -} -hidl_interface { - name: "android.hardware.nfc@1.0", - srcs: ["types.hal", "IBase.hal"], - root: "android.hardware", - gen_java: false, -} -hidl_interface { - name: "android.hardware.nfc@1.1", - srcs: ["types.hal", "INfc.hal"], - interfaces: ["android.hardware.nfc@1.0"], - root: "android.hardware", - gen_java: false, -}`, - ExpectedBazelTargets: []string{ - bp2build.MakeBazelTargetNoRestrictions("hidl_interface", "android.hardware.nfc@1.0", bp2build.AttrNameToString{ - "min_sdk_version": `"29"`, - "root": `":android.hardware"`, - "srcs": `[ - "types.hal", - "IBase.hal", - ]`, - }), - bp2build.MakeBazelTargetNoRestrictions("hidl_interface", "android.hardware.nfc@1.1", bp2build.AttrNameToString{ - "deps": `[":android.hardware.nfc@1.0"]`, - "min_sdk_version": `"29"`, - "root": `":android.hardware"`, - "srcs": `[ - "types.hal", - "INfc.hal", - ]`, - }), - bp2build.MakeBazelTargetNoRestrictions("hidl_package_root", "android.hardware", bp2build.AttrNameToString{ - "current": `"current.txt"`, - }), - }, - }) -} - -func TestHidlInterfacePackageRootInAnotherBp(t *testing.T) { - runHidlInterfaceTestCase(t, bp2build.Bp2buildTestCase{ - Description: `hidl_interface with common usage of properties`, - Filesystem: map[string]string{ - "foo/bar/Android.bp": ` -hidl_package_root { - name: "android.hardware", - use_current: true, -}`, - "foo/bar/current.txt": "", - }, - Blueprint: ` -cc_defaults { - name: "hidl-module-defaults", -} -hidl_package_root{ - name: "foo", -} -hidl_interface { - name: "android.hardware.neuralnetworks@1.0", - srcs: ["types.hal", "IBase.hal"], - root: "android.hardware", - gen_java: false, -}`, - StubbedBuildDefinitions: []string{"//foo/bar:android.hardware"}, - ExpectedBazelTargets: []string{ - bp2build.MakeBazelTargetNoRestrictions("hidl_interface", "android.hardware.neuralnetworks@1.0", bp2build.AttrNameToString{ - "min_sdk_version": `"30"`, - "root": `"//foo/bar:android.hardware"`, - "srcs": `[ - "types.hal", - "IBase.hal", - ]`, - }), - bp2build.MakeBazelTargetNoRestrictions("hidl_package_root", "foo", bp2build.AttrNameToString{}), - }, - }) -} diff --git a/build/hidl_package_root.go b/build/hidl_package_root.go index 6e9a1557..628c210d 100644 --- a/build/hidl_package_root.go +++ b/build/hidl_package_root.go @@ -21,7 +21,6 @@ import ( "github.com/google/blueprint/proptools" "android/soong/android" - "android/soong/bazel" ) var ( @@ -51,7 +50,6 @@ func init() { type hidlPackageRoot struct { android.ModuleBase - android.BazelModuleBase properties hidlPackageRootProperties @@ -95,29 +93,6 @@ func (r *hidlPackageRoot) Srcs() android.Paths { return r.genOutputs } -type hidlPackageRootAttributes struct { - Path *string - Current bazel.LabelAttribute -} - -func (r *hidlPackageRoot) ConvertWithBp2build(ctx android.Bp2buildMutatorContext) { - attrs := &hidlPackageRootAttributes{ - Path: r.properties.Path, - } - currentPath := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "current.txt") - if currentPath.Valid() { - attrs.Current = *bazel.MakeLabelAttribute("current.txt") - } - - props := bazel.BazelTargetModuleProperties{ - Rule_class: "hidl_package_root", - Bzl_load_location: "//build/bazel/rules/hidl:hidl_package_root.bzl", - } - - ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: ctx.ModuleName()}, attrs) - -} - func (r *hidlPackageRoot) GenerateAndroidBuildActions(ctx android.ModuleContext) { if r.properties.Path == nil { r.properties.Path = proptools.StringPtr(ctx.ModuleDir()) @@ -150,7 +125,6 @@ func HidlPackageRootFactory() android.Module { r := &hidlPackageRoot{} r.AddProperties(&r.properties) android.InitAndroidModule(r) - android.InitBazelModule(r) packageRootsMutex.Lock() packageRoots = append(packageRoots, r) diff --git a/build/properties.go b/build/properties.go index 087530db..6d67033b 100644 --- a/build/properties.go +++ b/build/properties.go @@ -66,11 +66,3 @@ type fuzzProperties struct { Data []string Fuzz_config *fuzzConfig } - -type Bazel_module struct { - Bp2build_available *bool - Label *string -} -type bazelProperties struct { - *Bazel_module -} diff --git a/test/hidl_test/hidl_test.py b/test/hidl_test/hidl_test.py index 802ddebc..42c999e0 100644 --- a/test/hidl_test/hidl_test.py +++ b/test/hidl_test/hidl_test.py @@ -26,6 +26,13 @@ def run_cmd(cmd, ignore_error=False): raise subprocess.CalledProcessError(p.returncode, cmd) return p.returncode +def has_hwservicemanager(): + # if the property is set, or hwservicemanager is missing, then we don't have + # hwservicemanger running. + return 0 != run_cmd("echo '[[ \"$(getprop hwservicemanager.disabled)\" == \"true\" ]] || " + + "[[ ! -f /system/bin/hwservicemanager ]]' | adb shell sh", ignore_error=True) + +@unittest.skipUnless(has_hwservicemanager(), "no hwservicemanager") class TestHidl(unittest.TestCase): pass diff --git a/test/hidl_test/hidl_test_client.cpp b/test/hidl_test/hidl_test_client.cpp index d82dab60..614ffdbc 100644 --- a/test/hidl_test/hidl_test_client.cpp +++ b/test/hidl_test/hidl_test_client.cpp @@ -361,20 +361,26 @@ public: void getServices() { manager = IServiceManager::getService(); - // alternatively: // manager = defaultServiceManager() ASSERT_NE(manager, nullptr); ASSERT_TRUE(manager->isRemote()); // manager is always remote - tokenManager = ITokenManager::getService(); - ASSERT_NE(tokenManager, nullptr); - ASSERT_TRUE(tokenManager->isRemote()); // tokenManager is always remote + if (IServiceManager::Transport::EMPTY != + manager->getTransport(ITokenManager::descriptor, "default")) { + // Token manager only exists on devices before Android V + tokenManager = ITokenManager::getService(); + ASSERT_TRUE(tokenManager); + ASSERT_TRUE(tokenManager->isRemote()); // tokenManager is always remote + } - ashmemAllocator = IAllocator::getService("ashmem"); - ASSERT_NE(ashmemAllocator, nullptr); - ASSERT_TRUE(ashmemAllocator->isRemote()); // allocator is always remote + if (IServiceManager::Transport::EMPTY != + manager->getTransport(IAllocator::descriptor, "ashmem")) { + ashmemAllocator = IAllocator::getService("ashmem"); + ASSERT_NE(ashmemAllocator, nullptr); + ASSERT_TRUE(ashmemAllocator->isRemote()); // allocator is always remote + } // getStub is true if we are in passthrough mode to skip checking // binderized server, false for binderized mode. @@ -871,6 +877,9 @@ TEST_F(HidlTest, InterfacesEqualTest) { TEST_F(HidlTest, TestToken) { using android::hardware::interfacesEqual; + if (!tokenManager) { + GTEST_SKIP() << "Token manager is not available devices newer than Android U"; + } Return<void> ret = tokenManager->createToken(manager, [&] (const hidl_vec<uint8_t> &token) { Return<sp<IBase>> retService = tokenManager->get(token); EXPECT_OK(retService); @@ -893,6 +902,7 @@ TEST_F(HidlTest, TestToken) { } TEST_F(HidlTest, TestSharedMemory) { + if (!ashmemAllocator) GTEST_SKIP() << "ashmem allocator is not on the device"; const uint8_t kValue = 0xCA; hidl_memory mem_copy; EXPECT_OK(ashmemAllocator->allocate(1024, [&](bool success, const hidl_memory& mem) { @@ -956,6 +966,7 @@ TEST_F(HidlTest, TestSharedMemory) { } TEST_F(HidlTest, BatchSharedMemory) { + if (!ashmemAllocator) GTEST_SKIP() << "ashmem allocator is not on the device"; const uint8_t kValue = 0xCA; const uint64_t kBatchSize = 2; hidl_vec<hidl_memory> batchCopy; @@ -1005,6 +1016,7 @@ TEST_F(HidlTest, BatchSharedMemory) { } TEST_F(HidlTest, MemoryBlock) { + if (!ashmemAllocator) GTEST_SKIP() << "ashmem allocator is not on the device"; const uint8_t kValue = 0xCA; using ::android::hardware::IBinder; using ::android::hardware::interfacesEqual; diff --git a/test/java_test/hidl_test_java.py b/test/java_test/hidl_test_java.py index ccafd883..681935bc 100644 --- a/test/java_test/hidl_test_java.py +++ b/test/java_test/hidl_test_java.py @@ -28,6 +28,14 @@ def run_cmd(cmd, ignore_error=False): raise subprocess.CalledProcessError(p.returncode, cmd) return p.returncode + +def has_hwservicemanager(): + # if the property is set, or hwservicemanager is missing, then we don't have + # hwservicemanger running. + return 0 != run_cmd("echo '[[ \"$(getprop hwservicemanager.disabled)\" == \"true\" ]] || " + + "[[ ! -f /system/bin/hwservicemanager ]]' | adb shell sh", ignore_error=True) + +@unittest.skipUnless(has_hwservicemanager(), "no hwservicemanager") class TestHidlJava(unittest.TestCase): pass diff --git a/test/java_test/hidl_test_java_native.cpp b/test/java_test/hidl_test_java_native.cpp index 9827f072..149a17bf 100644 --- a/test/java_test/hidl_test_java_native.cpp +++ b/test/java_test/hidl_test_java_native.cpp @@ -1278,9 +1278,16 @@ int main(int argc, char **argv) { status = registerPassthroughServiceImplementation<ISafeUnion>(); CHECK(status == ::android::OK) << "ISafeUnion didn't register"; - sp<IMemoryInterface> memoryInterface = new MemoryInterface(); - status = memoryInterface->registerAsService(); - CHECK(status == ::android::OK) << "IMemoryInterface didn't register"; + using android::hardware::defaultServiceManager; + using android::hidl::manager::V1_0::IServiceManager; + // If the android.hidl.allocator service isn't on the device, then don't + // create or register the MemoryInterface + if (IServiceManager::Transport::EMPTY != + defaultServiceManager()->getTransport(IAllocator::descriptor, "ashmem")) { + sp<IMemoryInterface> memoryInterface = new MemoryInterface(); + status = memoryInterface->registerAsService(); + CHECK(status == ::android::OK) << "IMemoryInterface didn't register"; + } joinRpcThreadpool(); return 0; diff --git a/test/java_test/src/com/android/commands/hidl_test_java/HidlTestJava.java b/test/java_test/src/com/android/commands/hidl_test_java/HidlTestJava.java index 47adad8f..0999a92a 100644 --- a/test/java_test/src/com/android/commands/hidl_test_java/HidlTestJava.java +++ b/test/java_test/src/com/android/commands/hidl_test_java/HidlTestJava.java @@ -245,7 +245,13 @@ public final class HidlTestJava { } private void runClientMemoryTests() throws RemoteException, IOException, ErrnoException { - IMemoryInterface memoryInterface = IMemoryInterface.getService(); + IMemoryInterface memoryInterface; + try { + memoryInterface = IMemoryInterface.getService(); + } catch (NoSuchElementException e) { + // If the test didn't register the memory interface, don't try to test it. + return; + } { HidlMemory hidlMem = HidlMemoryUtil.byteArrayToHidlMemory( diff --git a/test/lazy_test/Android.bp b/test/lazy_test/Android.bp index 801c9e61..457b7c8f 100644 --- a/test/lazy_test/Android.bp +++ b/test/lazy_test/Android.bp @@ -13,9 +13,6 @@ cc_test { srcs: ["hidl_lazy_test.cpp"], shared_libs: [ - "android.hardware.tests.lazy@1.0", - "android.hardware.tests.lazy@1.1", - "android.hardware.tests.lazy_cb@1.0", "libbase", "libcutils", "libhidl-gen-utils", @@ -23,6 +20,11 @@ cc_test { "liblog", "libutils", ], + static_libs: [ + "android.hardware.tests.lazy@1.0", + "android.hardware.tests.lazy@1.1", + "android.hardware.tests.lazy_cb@1.0", + ], test_suites: ["general-tests"], require_root: true, diff --git a/test/lazy_test/hidl_lazy_test.cpp b/test/lazy_test/hidl_lazy_test.cpp index 4f27463f..381e16c4 100644 --- a/test/lazy_test/hidl_lazy_test.cpp +++ b/test/lazy_test/hidl_lazy_test.cpp @@ -67,6 +67,13 @@ class HidlLazyTestBase : public ::testing::Test { void SetUp() override { manager = IServiceManager::getService(); ASSERT_NE(manager, nullptr); + // if the services aren't installed/declared on the device, skip. + // if one is installed, the other(s) are also installed so skip on the + // first instance that isn't declared. + for (const auto& instance : gInstances) { + if (!isServiceDeclared(instance)) + GTEST_SKIP() << "No HIDL lazy test services on device"; + } } bool isServiceRunning(const FqInstance& instance) { @@ -83,6 +90,13 @@ class HidlLazyTestBase : public ::testing::Test { .isOk()); return isRunning; } + bool isServiceDeclared(const FqInstance& instance) { + const auto transport = + manager->getTransport(instance.getFqName().string(), instance.getInstance()); + EXPECT_TRUE(transport.isOk()); + if (transport == IServiceManager::Transport::HWBINDER) return true; + return false; + } }; class HidlLazyTest : public HidlLazyTestBase { |