diff --git a/cc/Android.bp b/cc/Android.bp index cf4563070..9103a48b4 100644 --- a/cc/Android.bp +++ b/cc/Android.bp @@ -88,6 +88,7 @@ bootstrap_go_package { "stub_library.go", ], testSrcs: [ + "afdo_test.go", "cc_test.go", "compiler_test.go", "gen_test.go", diff --git a/cc/OWNERS b/cc/OWNERS index 811d88183..a7e6ebb0b 100644 --- a/cc/OWNERS +++ b/cc/OWNERS @@ -1,4 +1,4 @@ per-file ndk_*.go = danalbert@google.com per-file tidy.go = srhines@google.com, chh@google.com -per-file afdo.go,lto.go,pgo.go = srhines@google.com, pirama@google.com, yikong@google.com +per-file afdo.go,afdo_test.go,lto.go,pgo.go = srhines@google.com, pirama@google.com, yikong@google.com diff --git a/cc/afdo_test.go b/cc/afdo_test.go new file mode 100644 index 000000000..551546424 --- /dev/null +++ b/cc/afdo_test.go @@ -0,0 +1,70 @@ +// 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 cc + +import ( + "testing" + + "android/soong/android" + "github.com/google/blueprint" +) + +func TestAfdoDeps(t *testing.T) { + bp := ` + cc_library { + name: "libTest", + srcs: ["foo.c"], + static_libs: ["libFoo"], + afdo: true, + } + + cc_library { + name: "libFoo", + static_libs: ["libBar"], + } + + cc_library { + name: "libBar", + } + ` + prepareForAfdoTest := android.FixtureAddTextFile("toolchain/pgo-profiles/sampling/libTest.afdo", "TEST") + + result := android.GroupFixturePreparers( + prepareForCcTest, + prepareForAfdoTest, + ).RunTestWithBp(t, bp) + + libTest := result.ModuleForTests("libTest", "android_arm64_armv8-a_shared").Module() + libFoo := result.ModuleForTests("libFoo", "android_arm64_armv8-a_static_afdo-libTest").Module() + libBar := result.ModuleForTests("libBar", "android_arm64_armv8-a_static_afdo-libTest").Module() + + hasDep := func(m android.Module, wantDep android.Module) bool { + var found bool + result.VisitDirectDeps(m, func(dep blueprint.Module) { + if dep == wantDep { + found = true + } + }) + return found + } + + if !hasDep(libTest, libFoo) { + t.Errorf("libTest missing dependency on afdo variant of libFoo") + } + + if !hasDep(libFoo, libBar) { + t.Errorf("libTest missing dependency on afdo variant of libBar") + } +}