xref: /aosp_15_r20/build/bazel/toolchains/clang/host/linux-x86/cc_toolchain_features_arm_isa_test.bzl (revision 7594170e27e0732bc44b93d1440d87a54b6ffe7c)
1"""Copyright (C) 2022 The Android Open Source Project
2
3Licensed under the Apache License, Version 2.0 (the "License");
4you may not use this file except in compliance with the License.
5You may obtain a copy of the License at
6
7     http://www.apache.org/licenses/LICENSE-2.0
8
9Unless required by applicable law or agreed to in writing, software
10distributed under the License is distributed on an "AS IS" BASIS,
11WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12See the License for the specific language governing permissions and
13limitations under the License.
14"""
15
16load(":cc_toolchain_constants.bzl", "generated_config_constants")
17load(
18    "//build/bazel/rules/test_common:flags.bzl",
19    "action_flags_absent_for_mnemonic_test_with_config_settings",
20    "action_flags_present_only_for_mnemonic_test_with_config_settings",
21)
22
23_action_flags_present_arm_test = action_flags_present_only_for_mnemonic_test_with_config_settings(
24    {
25        "//command_line_option:platforms": [
26            "@//build/bazel/tests/products:aosp_arm_for_testing",
27        ],
28    },
29)
30_action_flags_absent_arm_test = action_flags_absent_for_mnemonic_test_with_config_settings(
31    {
32        "//command_line_option:platforms": [
33            "@//build/bazel/tests/products:aosp_arm_for_testing",
34        ],
35    },
36)
37
38_compile_action_mnemonic = "CppCompile"
39
40def _test_arm_isa_thumb_enabled_by_default():
41    name = "arm_isa_thumb_enabled_by_default"
42    thumb_flags_present_test_name = name + "_thumb_flags_present_test"
43    arm_flags_absent_test_name = name + "_arm_flags_absent_test"
44
45    native.cc_binary(
46        name = name,
47        srcs = ["foo.cpp"],
48        tags = ["manual"],
49    )
50
51    _action_flags_present_arm_test(
52        name = thumb_flags_present_test_name,
53        target_under_test = name,
54        mnemonics = [_compile_action_mnemonic],
55        expected_flags = generated_config_constants.ArmThumbCflags,
56    )
57
58    _action_flags_absent_arm_test(
59        name = arm_flags_absent_test_name,
60        target_under_test = name,
61        mnemonics = [_compile_action_mnemonic],
62        expected_absent_flags = ["-fstrict-aliasing"],
63    )
64
65    return [
66        thumb_flags_present_test_name,
67        arm_flags_absent_test_name,
68    ]
69
70def _test_arm_isa_arm_overrides_thumb():
71    name = "arm_isa_arm_overrides_thumb"
72    arm_flags_present_test_name = name + "_arm_flags_present_test"
73    thumb_flags_absent_test_name = name + "_thumb_flags_absent_test"
74
75    native.cc_binary(
76        name = name,
77        srcs = ["foo.cpp"],
78        features = ["arm_isa_arm"],
79        tags = ["manual"],
80    )
81
82    _action_flags_present_arm_test(
83        name = arm_flags_present_test_name,
84        target_under_test = name,
85        mnemonics = [_compile_action_mnemonic],
86        expected_flags = ["-fstrict-aliasing"],
87    )
88
89    _action_flags_absent_arm_test(
90        name = thumb_flags_absent_test_name,
91        target_under_test = name,
92        mnemonics = [_compile_action_mnemonic],
93        expected_absent_flags = generated_config_constants.ArmThumbCflags,
94    )
95
96    return [
97        arm_flags_present_test_name,
98        thumb_flags_absent_test_name,
99    ]
100
101_action_flags_absent_arm64_test = action_flags_absent_for_mnemonic_test_with_config_settings(
102    {
103        "//command_line_option:platforms": [
104            "@//build/bazel/tests/products:aosp_arm64_for_testing",
105        ],
106    },
107)
108
109def _test_arm_isa_arm_flags_absent_when_arch_not_arm():
110    name = "arm_isa_flags_absent_when_arch_not_arm"
111    test_name = name + "_test"
112
113    native.cc_binary(
114        name = name,
115        srcs = ["foo.cpp"],
116        features = ["arm_isa_arm"],
117        tags = ["manual"],
118    )
119
120    _action_flags_absent_arm64_test(
121        name = test_name,
122        target_under_test = name,
123        mnemonics = [_compile_action_mnemonic],
124        expected_absent_flags = ["-fstrict-aliasing"],
125    )
126
127    return [test_name]
128
129def _test_arm_isa_thumb_flags_absent_when_arch_not_arm():
130    name = "arm_isa_thumb_flags_absent_when_arch_not_arm"
131    test_name = name + "_test"
132
133    native.cc_binary(
134        name = name,
135        srcs = ["foo.cpp"],
136        tags = ["manual"],
137    )
138
139    _action_flags_absent_arm64_test(
140        name = test_name,
141        target_under_test = name,
142        mnemonics = [_compile_action_mnemonic],
143        expected_absent_flags = generated_config_constants.ArmThumbCflags,
144    )
145
146    return [test_name]
147
148def cc_toolchain_features_arm_isa_test_suite(name):
149    native.test_suite(
150        name = name,
151        tests = (
152            _test_arm_isa_thumb_enabled_by_default() +
153            _test_arm_isa_arm_overrides_thumb() +
154            _test_arm_isa_arm_flags_absent_when_arch_not_arm() +
155            _test_arm_isa_thumb_flags_absent_when_arch_not_arm()
156        ),
157    )
158