xref: /aosp_15_r20/cts/flags/cc_tests/src/FlagMacrosTests.cpp (revision b7c941bb3fa97aba169d73cee0bed2de8ac964bf)
1 /*
2  * Copyright (C) 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <flag_macros.h>
18 #include <gtest/gtest.h>
19 #include "android_cts_flags_tests.h"
20 
21 #define TEST_NS android::cts::flags::tests
22 
23 class TestFWithFlagsTest : public ::testing::Test {
24 public:
25     static std::set<std::string> executed_tests;
26 protected:
TestFail()27     void TestFail() {
28         FAIL();
29     }
30 };
31 
32 std::set<std::string> TestFWithFlagsTest::executed_tests = {};
33 
TEST_F_WITH_FLAGS(TestFWithFlagsTest,requies_disabled_flag_enabled_skip,REQUIRES_FLAGS_DISABLED (ACONFIG_FLAG (TEST_NS,readwrite_enabled_flag)))34 TEST_F_WITH_FLAGS(
35     TestFWithFlagsTest,
36     requies_disabled_flag_enabled_skip,
37     REQUIRES_FLAGS_DISABLED(ACONFIG_FLAG(TEST_NS, readwrite_enabled_flag))
38 ) {
39     TestFail();
40 }
41 
42 TEST_F_WITH_FLAGS(
43     TestFWithFlagsTest,
44     requies_disabled_flag_disabled_execute,
45     REQUIRES_FLAGS_DISABLED(
46         LEGACY_FLAG(aconfig_flags.cts, TEST_NS, readwrite_disabled_flag))
47 ) {
48     executed_tests.insert("requies_disabled_flag_disabled_execute");
49 }
50 
TEST_F_WITH_FLAGS(TestFWithFlagsTest,requies_enabled_flag_disabled_skip,REQUIRES_FLAGS_ENABLED (ACONFIG_FLAG (TEST_NS,readwrite_disabled_flag)))51 TEST_F_WITH_FLAGS(
52     TestFWithFlagsTest,
53     requies_enabled_flag_disabled_skip,
54     REQUIRES_FLAGS_ENABLED(ACONFIG_FLAG(TEST_NS, readwrite_disabled_flag))
55 ) {
56     TestFail();
57 }
58 
59 TEST_F_WITH_FLAGS(
60     TestFWithFlagsTest,
61     requies_enabled_flag_enabled_executed,
62     REQUIRES_FLAGS_ENABLED(
63         LEGACY_FLAG(aconfig_flags.cts, TEST_NS, readwrite_enabled_flag))
64 ) {
65     executed_tests.insert("requies_enabled_flag_enabled_executed");
66 }
67 
68 TEST_F_WITH_FLAGS(
69     TestFWithFlagsTest,
70     multi_flags_skip,
71     REQUIRES_FLAGS_ENABLED(ACONFIG_FLAG(TEST_NS, readwrite_disabled_flag)),
72     REQUIRES_FLAGS_DISABLED(
73         LEGACY_FLAG(aconfig_flags.cts, TEST_NS, readwrite_enabled_flag))
74 ) {
75     TestFail();
76 }
77 
78 TEST_F_WITH_FLAGS(
79     TestFWithFlagsTest,
80     multi_flags_executed,
81     REQUIRES_FLAGS_ENABLED(ACONFIG_FLAG(TEST_NS, readwrite_enabled_flag)),
82     REQUIRES_FLAGS_DISABLED(
83         LEGACY_FLAG(aconfig_flags.cts, TEST_NS, readwrite_disabled_flag))
84 ) {
85     executed_tests.insert("multi_flags_executed");
86 }
87 
88 TEST_F_WITH_FLAGS(
89     TestFWithFlagsTest,
90     multi_flags_for_same_state_skip,
91     REQUIRES_FLAGS_ENABLED(
92         ACONFIG_FLAG(TEST_NS, readwrite_enabled_flag),
93         LEGACY_FLAG(aconfig_flags.cts, TEST_NS, readwrite_disabled_flag)
94     )
95 ) {
96     TestFail();
97 }
98 
99 TEST_F_WITH_FLAGS(
100     TestFWithFlagsTest,
101     multi_flags_for_same_state_executed,
102     REQUIRES_FLAGS_DISABLED(
103         ACONFIG_FLAG(TEST_NS, readwrite_disabled_flag),
104         LEGACY_FLAG(aconfig_flags.cts, TEST_NS, readwrite_disabled_flag_2)
105     )
106 ) {
107     executed_tests.insert("multi_flags_for_same_state_executed");
108 }
109 
TEST_F(TestFWithFlagsTest,check_n_executed_tests)110 TEST_F(TestFWithFlagsTest, check_n_executed_tests) {
111     std::set<std::string> expected_executed_tests = {
112         "requies_disabled_flag_disabled_execute",
113         "requies_enabled_flag_enabled_executed",
114         "multi_flags_executed",
115         "multi_flags_for_same_state_executed",
116     };
117     ASSERT_EQ(expected_executed_tests, executed_tests);
118 }
119 
120 class TestWithFlagsTestHelper {
121 public:
122     static std::set<std::string> executed_tests;
123 };
124 
125 std::set<std::string> TestWithFlagsTestHelper::executed_tests = {};
126 
127 TEST_WITH_FLAGS(
128     TestWithFlagsTest,
129     requies_disabled_flag_enabled_skip,
130     REQUIRES_FLAGS_DISABLED(
131         LEGACY_FLAG(aconfig_flags.cts, TEST_NS, readwrite_enabled_flag))
132 ) {
133     FAIL();
134 }
135 
TEST_WITH_FLAGS(TestWithFlagsTest,requies_disabled_flag_disabled_execute,REQUIRES_FLAGS_DISABLED (ACONFIG_FLAG (TEST_NS,readwrite_disabled_flag)))136 TEST_WITH_FLAGS(
137     TestWithFlagsTest,
138     requies_disabled_flag_disabled_execute,
139     REQUIRES_FLAGS_DISABLED(ACONFIG_FLAG(TEST_NS, readwrite_disabled_flag))
140 ) {
141     TestWithFlagsTestHelper::executed_tests.insert(
142         "requies_disabled_flag_disabled_execute");
143 }
144 
145 TEST_WITH_FLAGS(
146     TestWithFlagsTest,
147     requies_enabled_flag_disabled_skip,
148     REQUIRES_FLAGS_ENABLED(
149         LEGACY_FLAG(aconfig_flags.cts, TEST_NS, readwrite_disabled_flag))
150 ) {
151     FAIL();
152 }
153 
TEST_WITH_FLAGS(TestWithFlagsTest,requies_enabled_flag_enabled_executed,REQUIRES_FLAGS_ENABLED (ACONFIG_FLAG (TEST_NS,readwrite_enabled_flag)))154 TEST_WITH_FLAGS(
155     TestWithFlagsTest,
156     requies_enabled_flag_enabled_executed,
157     REQUIRES_FLAGS_ENABLED(ACONFIG_FLAG(TEST_NS, readwrite_enabled_flag))
158 ) {
159     TestWithFlagsTestHelper::executed_tests.insert(
160         "requies_enabled_flag_enabled_executed");
161 }
162 
163 TEST_WITH_FLAGS(
164     TestWithFlagsTest,
165     multi_flags_skip,
166     REQUIRES_FLAGS_ENABLED(
167         LEGACY_FLAG(aconfig_flags.cts, TEST_NS, readwrite_disabled_flag)),
168     REQUIRES_FLAGS_DISABLED(ACONFIG_FLAG(TEST_NS, readwrite_enabled_flag))
169 ) {
170     FAIL();
171 }
172 
173 TEST_WITH_FLAGS(
174     TestWithFlagsTest,
175     multi_flags_executed,
176     REQUIRES_FLAGS_ENABLED(
177         LEGACY_FLAG(aconfig_flags.cts, TEST_NS, readwrite_enabled_flag)),
178     REQUIRES_FLAGS_DISABLED(ACONFIG_FLAG(TEST_NS, readwrite_disabled_flag))
179 ) {
180     TestWithFlagsTestHelper::executed_tests.insert(
181         "multi_flags_executed");
182 }
183 
184 TEST_WITH_FLAGS(
185     TestWithFlagsTest,
186     multi_flags_for_same_state_skip,
187     REQUIRES_FLAGS_ENABLED(
188         LEGACY_FLAG(aconfig_flags.cts, TEST_NS, readwrite_enabled_flag),
189         ACONFIG_FLAG(TEST_NS, readwrite_disabled_flag)
190     )
191 ) {
192     FAIL();
193 }
194 
195 TEST_WITH_FLAGS(
196     TestWithFlagsTest,
197     multi_flags_for_same_state_executed,
198     REQUIRES_FLAGS_DISABLED(
199         LEGACY_FLAG(aconfig_flags.cts, TEST_NS, readwrite_disabled_flag),
200         ACONFIG_FLAG(TEST_NS, readwrite_disabled_flag_2)
201     )
202 ) {
203     TestWithFlagsTestHelper::executed_tests.insert(
204         "multi_flags_for_same_state_executed");
205 }
206 
TEST(TestWithFlagsTest,check_n_executed_tests)207 TEST(TestWithFlagsTest, check_n_executed_tests) {
208     std::set<std::string> expected_executed_tests = {
209         "requies_disabled_flag_disabled_execute",
210         "requies_enabled_flag_enabled_executed",
211         "multi_flags_executed",
212         "multi_flags_for_same_state_executed",
213     };
214     ASSERT_EQ(
215         expected_executed_tests,
216         TestWithFlagsTestHelper::executed_tests);
217 }
218 
main(int argc,char ** argv)219 int main(int argc, char **argv) {
220     testing::InitGoogleTest(&argc, argv);
221     return RUN_ALL_TESTS();
222 }
223