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 bp2build 16 17import ( 18 "android/soong/android" 19 "android/soong/bpf" 20 21 "testing" 22) 23 24func runBpfTestCase(t *testing.T, tc Bp2buildTestCase) { 25 t.Helper() 26 (&tc).ModuleTypeUnderTest = "bpf" 27 (&tc).ModuleTypeUnderTestFactory = bpf.BpfFactory 28 RunBp2BuildTestCase(t, registerBpfModuleTypes, tc) 29} 30 31func registerBpfModuleTypes(ctx android.RegistrationContext) {} 32 33func TestBpfSupportedAttrs(t *testing.T) { 34 runBpfTestCase(t, Bp2buildTestCase{ 35 Description: "Bpf module only converts supported attributes", 36 Filesystem: map[string]string{}, 37 Blueprint: ` 38bpf { 39 name: "bpfTestOut.o", 40 srcs: ["bpfTestSrcOne.c", 41 "bpfTestSrcTwo.c"], 42 btf: true, 43 cflags: ["-bpfCflagOne", 44 "-bpfCflagTwo"], 45 include_dirs: ["ia/ib/ic"], 46 sub_dir: "sa/ab", 47} 48`, 49 ExpectedBazelTargets: []string{ 50 MakeBazelTarget("bpf", "bpfTestOut.o", AttrNameToString{ 51 "absolute_includes": `["ia/ib/ic"]`, 52 "btf": `True`, 53 "copts": `[ 54 "-bpfCflagOne", 55 "-bpfCflagTwo", 56 ]`, 57 "srcs": `[ 58 "bpfTestSrcOne.c", 59 "bpfTestSrcTwo.c", 60 ]`, 61 "target_compatible_with": `["//build/bazel/platforms/os:android"]`, 62 }), 63 }, 64 }) 65} 66