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 cc 16 17import ( 18 "testing" 19 20 "android/soong/android" 21 "github.com/google/blueprint" 22) 23 24func TestAfdoDeps(t *testing.T) { 25 bp := ` 26 cc_library { 27 name: "libTest", 28 srcs: ["foo.c"], 29 static_libs: ["libFoo"], 30 afdo: true, 31 } 32 33 cc_library { 34 name: "libFoo", 35 static_libs: ["libBar"], 36 } 37 38 cc_library { 39 name: "libBar", 40 } 41 ` 42 prepareForAfdoTest := android.FixtureAddTextFile("toolchain/pgo-profiles/sampling/libTest.afdo", "TEST") 43 44 result := android.GroupFixturePreparers( 45 prepareForCcTest, 46 prepareForAfdoTest, 47 ).RunTestWithBp(t, bp) 48 49 libTest := result.ModuleForTests("libTest", "android_arm64_armv8-a_shared").Module() 50 libFoo := result.ModuleForTests("libFoo", "android_arm64_armv8-a_static_afdo-libTest").Module() 51 libBar := result.ModuleForTests("libBar", "android_arm64_armv8-a_static_afdo-libTest").Module() 52 53 hasDep := func(m android.Module, wantDep android.Module) bool { 54 var found bool 55 result.VisitDirectDeps(m, func(dep blueprint.Module) { 56 if dep == wantDep { 57 found = true 58 } 59 }) 60 return found 61 } 62 63 if !hasDep(libTest, libFoo) { 64 t.Errorf("libTest missing dependency on afdo variant of libFoo") 65 } 66 67 if !hasDep(libFoo, libBar) { 68 t.Errorf("libTest missing dependency on afdo variant of libBar") 69 } 70} 71