Vinh Tran | ce40b92 | 2023-06-05 12:57:55 -0400 | [diff] [blame] | 1 | // Copyright 2023 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 | |
| 15 | package bp2build |
| 16 | |
| 17 | import ( |
| 18 | "testing" |
| 19 | |
| 20 | "android/soong/android" |
| 21 | "android/soong/cc" |
| 22 | ) |
| 23 | |
| 24 | func runFdoProfileTestCase(t *testing.T, tc Bp2buildTestCase) { |
| 25 | t.Helper() |
| 26 | (&tc).ModuleTypeUnderTest = "fdo_profile" |
| 27 | (&tc).ModuleTypeUnderTestFactory = cc.FdoProfileFactory |
| 28 | RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, tc) |
| 29 | } |
| 30 | |
| 31 | func TestFdoProfile(t *testing.T) { |
| 32 | testcases := []struct { |
| 33 | name string |
| 34 | bp string |
| 35 | expectedBazelAttrs AttrNameToString |
| 36 | }{ |
| 37 | { |
| 38 | name: "fdo_profile with arch-specific profiles", |
| 39 | bp: ` |
| 40 | fdo_profile { |
| 41 | name: "foo", |
| 42 | arch: { |
| 43 | arm: { |
| 44 | profile: "foo_arm.afdo", |
| 45 | }, |
| 46 | arm64: { |
| 47 | profile: "foo_arm64.afdo", |
| 48 | } |
| 49 | } |
| 50 | }`, |
| 51 | expectedBazelAttrs: AttrNameToString{ |
| 52 | "profile": `select({ |
Jingwen Chen | 9c2e3ee | 2023-10-11 10:51:28 +0000 | [diff] [blame] | 53 | "//build/bazel_common_rules/platforms/arch:arm": "foo_arm.afdo", |
| 54 | "//build/bazel_common_rules/platforms/arch:arm64": "foo_arm64.afdo", |
Vinh Tran | ce40b92 | 2023-06-05 12:57:55 -0400 | [diff] [blame] | 55 | "//conditions:default": None, |
| 56 | })`, |
| 57 | }, |
| 58 | }, |
| 59 | { |
| 60 | name: "fdo_profile with arch-agnostic profile", |
| 61 | bp: ` |
| 62 | fdo_profile { |
| 63 | name: "foo", |
| 64 | profile: "foo.afdo", |
| 65 | }`, |
| 66 | expectedBazelAttrs: AttrNameToString{ |
| 67 | "profile": `"foo.afdo"`, |
| 68 | }, |
| 69 | }, |
| 70 | } |
| 71 | |
| 72 | for _, test := range testcases { |
| 73 | t.Run(test.name, func(t *testing.T) { |
| 74 | expectedBazelTargets := []string{ |
| 75 | // TODO(b/276287371): Add device-only restriction back to fdo_profile targets |
| 76 | MakeBazelTargetNoRestrictions("fdo_profile", "foo", test.expectedBazelAttrs), |
| 77 | } |
| 78 | runFdoProfileTestCase(t, Bp2buildTestCase{ |
| 79 | Description: test.name, |
| 80 | Blueprint: test.bp, |
| 81 | ExpectedBazelTargets: expectedBazelTargets, |
| 82 | }) |
| 83 | }) |
| 84 | } |
| 85 | } |