blob: 6f17c7594e44c028ec476dd4299ef368667266c9 [file] [log] [blame]
Dennis Shenc5e39f52023-09-14 18:52:49 +00001// 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
15package aconfig
16
17import (
18 "fmt"
19 "testing"
20
21 "android/soong/android"
22 "android/soong/cc"
23)
24
25var codegenModeTestData = []struct {
26 setting, expected string
27}{
28 {"", "production"},
29 {"test: false,", "production"},
30 {"test: true,", "test"},
31}
32
33func TestCCCodegenMode(t *testing.T) {
34 for _, testData := range codegenModeTestData {
35 testCCCodegenModeHelper(t, testData.setting, testData.expected)
36 }
37}
38
39func testCCCodegenModeHelper(t *testing.T, bpMode string, ruleMode string) {
40 t.Helper()
41 result := android.GroupFixturePreparers(
42 PrepareForTestWithAconfigBuildComponents,
43 cc.PrepareForTestWithCcDefaultModules).
44 ExtendWithErrorHandler(android.FixtureExpectsNoErrors).
45 RunTestWithBp(t, fmt.Sprintf(`
46 aconfig_declarations {
47 name: "my_aconfig_declarations",
48 package: "com.example.package",
49 srcs: ["foo.aconfig"],
50 }
51
52 cc_library {
53 name: "server_configurable_flags",
54 srcs: ["server_configurable_flags.cc"],
55 }
56
57 cc_aconfig_library {
58 name: "my_cc_aconfig_library",
59 aconfig_declarations: "my_aconfig_declarations",
60 %s
61 }
62 `, bpMode))
63
64 module := result.ModuleForTests("my_cc_aconfig_library", "android_arm64_armv8-a_shared")
65 rule := module.Rule("cc_aconfig_library")
66 android.AssertStringEquals(t, "rule must contain test mode", rule.Args["mode"], ruleMode)
67}