blob: 9a819e59e5f87cdba3b6150fd619e7e950ddc3ec [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
Zi Wang275f6542023-11-09 14:59:31 -080025var ccCodegenModeTestData = []struct {
Dennis Shenc5e39f52023-09-14 18:52:49 +000026 setting, expected string
27}{
28 {"", "production"},
Zi Wang275f6542023-11-09 14:59:31 -080029 {"mode: `production`,", "production"},
30 {"mode: `test`,", "test"},
31 {"mode: `exported`,", "exported"},
Dennis Shenc5e39f52023-09-14 18:52:49 +000032}
33
34func TestCCCodegenMode(t *testing.T) {
Zi Wang275f6542023-11-09 14:59:31 -080035 for _, testData := range ccCodegenModeTestData {
Dennis Shenc5e39f52023-09-14 18:52:49 +000036 testCCCodegenModeHelper(t, testData.setting, testData.expected)
37 }
38}
39
40func testCCCodegenModeHelper(t *testing.T, bpMode string, ruleMode string) {
41 t.Helper()
42 result := android.GroupFixturePreparers(
43 PrepareForTestWithAconfigBuildComponents,
44 cc.PrepareForTestWithCcDefaultModules).
45 ExtendWithErrorHandler(android.FixtureExpectsNoErrors).
46 RunTestWithBp(t, fmt.Sprintf(`
47 aconfig_declarations {
48 name: "my_aconfig_declarations",
49 package: "com.example.package",
50 srcs: ["foo.aconfig"],
51 }
52
53 cc_library {
54 name: "server_configurable_flags",
55 srcs: ["server_configurable_flags.cc"],
56 }
57
58 cc_aconfig_library {
59 name: "my_cc_aconfig_library",
60 aconfig_declarations: "my_aconfig_declarations",
61 %s
62 }
63 `, bpMode))
64
65 module := result.ModuleForTests("my_cc_aconfig_library", "android_arm64_armv8-a_shared")
66 rule := module.Rule("cc_aconfig_library")
67 android.AssertStringEquals(t, "rule must contain test mode", rule.Args["mode"], ruleMode)
68}
Zi Wang275f6542023-11-09 14:59:31 -080069
70var incorrectCCCodegenModeTestData = []struct {
71 setting, expectedErr string
72}{
73 {"mode: `unsupported`,", "mode: \"unsupported\" is not a supported mode"},
74 // TODO: remove this test case when test prop is removed
75 {"mode: `test`, test: true", "test prop should not be specified when mode prop is set"},
76}
77
78func TestIncorrectCCCodegenMode(t *testing.T) {
79 for _, testData := range incorrectCCCodegenModeTestData {
80 testIncorrectCCCodegenModeHelper(t, testData.setting, testData.expectedErr)
81 }
82}
83
84func testIncorrectCCCodegenModeHelper(t *testing.T, bpMode string, err string) {
85 t.Helper()
86 android.GroupFixturePreparers(
87 PrepareForTestWithAconfigBuildComponents,
88 cc.PrepareForTestWithCcDefaultModules).
89 ExtendWithErrorHandler(android.FixtureExpectsOneErrorPattern(err)).
90 RunTestWithBp(t, fmt.Sprintf(`
91 aconfig_declarations {
92 name: "my_aconfig_declarations",
93 package: "com.example.package",
94 srcs: ["foo.aconfig"],
95 }
96
97 cc_library {
98 name: "server_configurable_flags",
99 srcs: ["server_configurable_flags.cc"],
100 }
101
102 cc_aconfig_library {
103 name: "my_cc_aconfig_library",
104 aconfig_declarations: "my_aconfig_declarations",
105 %s
106 }
107 `, bpMode))
108}