1// Copyright 2022 Google Inc. All rights reserved. 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15package hidl 16 17import ( 18 "testing" 19 20 "android/soong/android" 21 "android/soong/bp2build" 22 "android/soong/cc" 23) 24 25func runHidlInterfaceTestCase(t *testing.T, tc bp2build.Bp2buildTestCase) { 26 t.Helper() 27 bp2build.RunBp2BuildTestCase( 28 t, 29 func(ctx android.RegistrationContext) { 30 ctx.RegisterModuleType("cc_defaults", func() android.Module { return cc.DefaultsFactory() }) 31 ctx.RegisterModuleType("hidl_interface", HidlInterfaceFactory) 32 ctx.RegisterModuleType("hidl_package_root", HidlPackageRootFactory) 33 }, 34 tc, 35 ) 36} 37 38func TestHidlInterface(t *testing.T) { 39 runHidlInterfaceTestCase(t, bp2build.Bp2buildTestCase{ 40 Description: `hidl_interface with common usage of properties`, 41 Blueprint: ` 42hidl_package_root { 43 name: "android.hardware", 44 use_current: true, 45} 46cc_defaults { 47 name: "hidl-module-defaults", 48} 49hidl_interface { 50 name: "android.hardware.nfc@1.0", 51 srcs: ["types.hal", "IBase.hal"], 52 root: "android.hardware", 53 gen_java: false, 54} 55hidl_interface { 56 name: "android.hardware.nfc@1.1", 57 srcs: ["types.hal", "INfc.hal"], 58 interfaces: ["android.hardware.nfc@1.0"], 59 root: "android.hardware", 60 gen_java: false, 61}`, 62 ExpectedBazelTargets: []string{ 63 bp2build.MakeBazelTargetNoRestrictions("hidl_interface", "android.hardware.nfc@1.0", bp2build.AttrNameToString{ 64 "min_sdk_version": `"29"`, 65 "root": `"android.hardware"`, 66 "root_interface_file": `":current.txt"`, 67 "srcs": `[ 68 "types.hal", 69 "IBase.hal", 70 ]`, 71 }), 72 bp2build.MakeBazelTargetNoRestrictions("hidl_interface", "android.hardware.nfc@1.1", bp2build.AttrNameToString{ 73 "deps": `[":android.hardware.nfc@1.0"]`, 74 "min_sdk_version": `"29"`, 75 "root": `"android.hardware"`, 76 "root_interface_file": `":current.txt"`, 77 "srcs": `[ 78 "types.hal", 79 "INfc.hal", 80 ]`, 81 }), 82 }, 83 }) 84} 85 86func TestHidlInterfacePackageRootInAnotherBp(t *testing.T) { 87 runHidlInterfaceTestCase(t, bp2build.Bp2buildTestCase{ 88 Description: `hidl_interface with common usage of properties`, 89 Filesystem: map[string]string{ 90 "foo/bar/Android.bp": ` 91hidl_package_root { 92 name: "android.hardware", 93 use_current: true, 94}`}, 95 Blueprint: ` 96cc_defaults { 97 name: "hidl-module-defaults", 98} 99hidl_interface { 100 name: "android.hardware.nfc@1.0", 101 srcs: ["types.hal", "IBase.hal"], 102 root: "android.hardware", 103 gen_java: false, 104}`, 105 ExpectedBazelTargets: []string{ 106 bp2build.MakeBazelTargetNoRestrictions("hidl_interface", "android.hardware.nfc@1.0", bp2build.AttrNameToString{ 107 "min_sdk_version": `"29"`, 108 "root": `"android.hardware"`, 109 "root_interface_file": `"//foo/bar:current.txt"`, 110 "srcs": `[ 111 "types.hal", 112 "IBase.hal", 113 ]`, 114 }), 115 }, 116 }) 117} 118