1 /*
2 * Copyright (C) 2017 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 #define LOG_TAG "VtsOffloadControlV1_0TargetTest"
18
19 #include <OffloadControlTestV1_0.h>
20 #include <android-base/stringprintf.h>
21 #include <gtest/gtest.h>
22 #include <hidl/GtestPrinter.h>
23 #include <hidl/ServiceManagement.h>
24 #include <net/if.h>
25 #include <sys/socket.h>
26
27 using android::base::StringPrintf;
28 using android::hardware::Return;
29 using android::hardware::tetheroffload::config::V1_0::IOffloadConfig;
30 using android::hardware::tetheroffload::control::V1_0::IOffloadControl;
31 using android::hardware::Void;
32
33 constexpr const char* TEST_IFACE = "rmnet_data0";
34
35 // Call initOffload() multiple times. Check that non-first initOffload() calls return false.
TEST_P(OffloadControlTestV1_0_HalNotStarted,AdditionalInitsWithoutStopReturnFalse)36 TEST_P(OffloadControlTestV1_0_HalNotStarted, AdditionalInitsWithoutStopReturnFalse) {
37 initOffload(true);
38 initOffload(false);
39 initOffload(false);
40 initOffload(false);
41 }
42
43 // Check that calling stopOffload() without first having called initOffload() returns false.
TEST_P(OffloadControlTestV1_0_HalNotStarted,MultipleStopsWithoutInitReturnFalse)44 TEST_P(OffloadControlTestV1_0_HalNotStarted, MultipleStopsWithoutInitReturnFalse) {
45 stopOffload(ExpectBoolean::False);
46 stopOffload(ExpectBoolean::False);
47 stopOffload(ExpectBoolean::False);
48 }
49
50 // Check whether the specified interface is up.
interfaceIsUp(const char * name)51 bool interfaceIsUp(const char* name) {
52 if (name == nullptr) return false;
53 struct ifreq ifr = {};
54 strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
55 int sock = socket(AF_INET6, SOCK_DGRAM, 0);
56 if (sock == -1) return false;
57 int ret = ioctl(sock, SIOCGIFFLAGS, &ifr, sizeof(ifr));
58 close(sock);
59 return (ret == 0) && (ifr.ifr_flags & IFF_UP);
60 }
61
62 // Check that calling stopOffload() after a complete init/stop cycle returns false.
TEST_P(OffloadControlTestV1_0_HalNotStarted,AdditionalStopsWithInitReturnFalse)63 TEST_P(OffloadControlTestV1_0_HalNotStarted, AdditionalStopsWithInitReturnFalse) {
64 initOffload(true);
65 // Call setUpstreamParameters() so that "offload" can be reasonably said
66 // to be both requested and operational.
67 const hidl_string v4Addr("192.0.0.2");
68 const hidl_string v4Gw("192.0.0.1");
69 const vector<hidl_string> v6Gws{hidl_string("fe80::db8:1"), hidl_string("fe80::db8:2")};
70 const Return<void> upstream =
71 control->setUpstreamParameters(TEST_IFACE, v4Addr, v4Gw, v6Gws, ASSERT_TRUE_CALLBACK);
72 EXPECT_TRUE(upstream.isOk());
73 if (!interfaceIsUp(TEST_IFACE)) {
74 return;
75 }
76 SCOPED_TRACE("Expecting stopOffload to succeed");
77 stopOffload(ExpectBoolean::Ignored); // balance out initOffload(true)
78 SCOPED_TRACE("Expecting stopOffload to fail the first time");
79 stopOffload(ExpectBoolean::False);
80 SCOPED_TRACE("Expecting stopOffload to fail the second time");
81 stopOffload(ExpectBoolean::False);
82 }
83
84 // Check that calling setLocalPrefixes() without first having called initOffload() returns false.
TEST_P(OffloadControlTestV1_0_HalNotStarted,SetLocalPrefixesWithoutInitReturnsFalse)85 TEST_P(OffloadControlTestV1_0_HalNotStarted, SetLocalPrefixesWithoutInitReturnsFalse) {
86 const vector<hidl_string> prefixes{hidl_string("2001:db8::/64")};
87 const Return<void> ret = control->setLocalPrefixes(prefixes, ASSERT_FALSE_CALLBACK);
88 EXPECT_TRUE(ret.isOk());
89 }
90
91 // Check that calling getForwardedStats() without first having called initOffload()
92 // returns zero bytes statistics.
TEST_P(OffloadControlTestV1_0_HalNotStarted,GetForwardedStatsWithoutInitReturnsZeroValues)93 TEST_P(OffloadControlTestV1_0_HalNotStarted, GetForwardedStatsWithoutInitReturnsZeroValues) {
94 const hidl_string upstream(TEST_IFACE);
95 const Return<void> ret = control->getForwardedStats(upstream, ASSERT_ZERO_BYTES_CALLBACK);
96 EXPECT_TRUE(ret.isOk());
97 }
98
99 // Check that calling setDataLimit() without first having called initOffload() returns false.
TEST_P(OffloadControlTestV1_0_HalNotStarted,SetDataLimitWithoutInitReturnsFalse)100 TEST_P(OffloadControlTestV1_0_HalNotStarted, SetDataLimitWithoutInitReturnsFalse) {
101 const hidl_string upstream(TEST_IFACE);
102 const uint64_t limit = 5000ULL;
103 const Return<void> ret = control->setDataLimit(upstream, limit, ASSERT_FALSE_CALLBACK);
104 EXPECT_TRUE(ret.isOk());
105 }
106
107 // Check that calling setUpstreamParameters() without first having called initOffload()
108 // returns false.
TEST_P(OffloadControlTestV1_0_HalNotStarted,SetUpstreamParametersWithoutInitReturnsFalse)109 TEST_P(OffloadControlTestV1_0_HalNotStarted, SetUpstreamParametersWithoutInitReturnsFalse) {
110 const hidl_string iface(TEST_IFACE);
111 const hidl_string v4Addr("192.0.2.0/24");
112 const hidl_string v4Gw("192.0.2.1");
113 const vector<hidl_string> v6Gws{hidl_string("fe80::db8:1")};
114 const Return<void> ret =
115 control->setUpstreamParameters(iface, v4Addr, v4Gw, v6Gws, ASSERT_FALSE_CALLBACK);
116 EXPECT_TRUE(ret.isOk());
117 }
118
119 // Check that calling addDownstream() with an IPv4 prefix without first having called
120 // initOffload() returns false.
TEST_P(OffloadControlTestV1_0_HalNotStarted,AddIPv4DownstreamWithoutInitReturnsFalse)121 TEST_P(OffloadControlTestV1_0_HalNotStarted, AddIPv4DownstreamWithoutInitReturnsFalse) {
122 const hidl_string iface(TEST_IFACE);
123 const hidl_string prefix("192.0.2.0/24");
124 const Return<void> ret = control->addDownstream(iface, prefix, ASSERT_FALSE_CALLBACK);
125 EXPECT_TRUE(ret.isOk());
126 }
127
128 // Check that calling addDownstream() with an IPv6 prefix without first having called
129 // initOffload() returns false.
TEST_P(OffloadControlTestV1_0_HalNotStarted,AddIPv6DownstreamWithoutInitReturnsFalse)130 TEST_P(OffloadControlTestV1_0_HalNotStarted, AddIPv6DownstreamWithoutInitReturnsFalse) {
131 const hidl_string iface(TEST_IFACE);
132 const hidl_string prefix("2001:db8::/64");
133 const Return<void> ret = control->addDownstream(iface, prefix, ASSERT_FALSE_CALLBACK);
134 EXPECT_TRUE(ret.isOk());
135 }
136
137 // Check that calling removeDownstream() with an IPv4 prefix without first having called
138 // initOffload() returns false.
TEST_P(OffloadControlTestV1_0_HalNotStarted,RemoveIPv4DownstreamWithoutInitReturnsFalse)139 TEST_P(OffloadControlTestV1_0_HalNotStarted, RemoveIPv4DownstreamWithoutInitReturnsFalse) {
140 const hidl_string iface(TEST_IFACE);
141 const hidl_string prefix("192.0.2.0/24");
142 const Return<void> ret = control->removeDownstream(iface, prefix, ASSERT_FALSE_CALLBACK);
143 EXPECT_TRUE(ret.isOk());
144 }
145
146 // Check that calling removeDownstream() with an IPv6 prefix without first having called
147 // initOffload() returns false.
TEST_P(OffloadControlTestV1_0_HalNotStarted,RemoveIPv6DownstreamWithoutInitReturnsFalse)148 TEST_P(OffloadControlTestV1_0_HalNotStarted, RemoveIPv6DownstreamWithoutInitReturnsFalse) {
149 const hidl_string iface(TEST_IFACE);
150 const hidl_string prefix("2001:db8::/64");
151 const Return<void> ret = control->removeDownstream(iface, prefix, ASSERT_FALSE_CALLBACK);
152 EXPECT_TRUE(ret.isOk());
153 }
154
155 /*
156 * Tests for IOffloadControl::setLocalPrefixes().
157 */
158
159 // Test setLocalPrefixes() accepts an IPv4 address.
TEST_P(OffloadControlTestV1_0_HalStarted,SetLocalPrefixesIPv4AddressOk)160 TEST_P(OffloadControlTestV1_0_HalStarted, SetLocalPrefixesIPv4AddressOk) {
161 const vector<hidl_string> prefixes{hidl_string("192.0.2.1")};
162 const Return<void> ret = control->setLocalPrefixes(prefixes, ASSERT_TRUE_CALLBACK);
163 EXPECT_TRUE(ret.isOk());
164 }
165
166 // Test setLocalPrefixes() accepts an IPv6 address.
TEST_P(OffloadControlTestV1_0_HalStarted,SetLocalPrefixesIPv6AddressOk)167 TEST_P(OffloadControlTestV1_0_HalStarted, SetLocalPrefixesIPv6AddressOk) {
168 const vector<hidl_string> prefixes{hidl_string("fe80::1")};
169 const Return<void> ret = control->setLocalPrefixes(prefixes, ASSERT_TRUE_CALLBACK);
170 EXPECT_TRUE(ret.isOk());
171 }
172
173 // Test setLocalPrefixes() accepts both IPv4 and IPv6 prefixes.
TEST_P(OffloadControlTestV1_0_HalStarted,SetLocalPrefixesIPv4v6PrefixesOk)174 TEST_P(OffloadControlTestV1_0_HalStarted, SetLocalPrefixesIPv4v6PrefixesOk) {
175 const vector<hidl_string> prefixes{hidl_string("192.0.2.0/24"), hidl_string("fe80::/64")};
176 const Return<void> ret = control->setLocalPrefixes(prefixes, ASSERT_TRUE_CALLBACK);
177 EXPECT_TRUE(ret.isOk());
178 }
179
180 // Test that setLocalPrefixes() fails given empty input. There is always
181 // a non-empty set of local prefixes; when all networking interfaces are down
182 // we still apply {127.0.0.0/8, ::1/128, fe80::/64} here.
TEST_P(OffloadControlTestV1_0_HalStarted,SetLocalPrefixesEmptyFails)183 TEST_P(OffloadControlTestV1_0_HalStarted, SetLocalPrefixesEmptyFails) {
184 const vector<hidl_string> prefixes{};
185 const Return<void> ret = control->setLocalPrefixes(prefixes, ASSERT_FALSE_CALLBACK);
186 EXPECT_TRUE(ret.isOk());
187 }
188
189 // Test setLocalPrefixes() fails on incorrectly formed input strings.
TEST_P(OffloadControlTestV1_0_HalStarted,SetLocalPrefixesInvalidFails)190 TEST_P(OffloadControlTestV1_0_HalStarted, SetLocalPrefixesInvalidFails) {
191 const vector<hidl_string> prefixes{hidl_string("192.0.2.0/24"), hidl_string("invalid")};
192 const Return<void> ret = control->setLocalPrefixes(prefixes, ASSERT_FALSE_CALLBACK);
193 EXPECT_TRUE(ret.isOk());
194 }
195
196 /*
197 * Tests for IOffloadControl::getForwardedStats().
198 */
199
200 // Test that getForwardedStats() for a non-existent upstream yields zero bytes statistics.
TEST_P(OffloadControlTestV1_0_HalStarted,GetForwardedStatsInvalidUpstreamIface)201 TEST_P(OffloadControlTestV1_0_HalStarted, GetForwardedStatsInvalidUpstreamIface) {
202 const hidl_string upstream("invalid");
203 const Return<void> ret = control->getForwardedStats(upstream, ASSERT_ZERO_BYTES_CALLBACK);
204 EXPECT_TRUE(ret.isOk());
205 }
206
207 // TEST_IFACE is presumed to exist on the device and be up. No packets
208 // are ever actually caused to be forwarded.
TEST_P(OffloadControlTestV1_0_HalStarted,GetForwardedStatsDummyIface)209 TEST_P(OffloadControlTestV1_0_HalStarted, GetForwardedStatsDummyIface) {
210 const hidl_string upstream(TEST_IFACE);
211 const Return<void> ret = control->getForwardedStats(upstream, ASSERT_ZERO_BYTES_CALLBACK);
212 EXPECT_TRUE(ret.isOk());
213 }
214
215 /*
216 * Tests for IOffloadControl::setDataLimit().
217 */
218
219 // Test that setDataLimit() for an empty interface name fails.
TEST_P(OffloadControlTestV1_0_HalStarted,SetDataLimitEmptyUpstreamIfaceFails)220 TEST_P(OffloadControlTestV1_0_HalStarted, SetDataLimitEmptyUpstreamIfaceFails) {
221 const hidl_string upstream("");
222 const uint64_t limit = 5000ULL;
223 const Return<void> ret = control->setDataLimit(upstream, limit, ASSERT_FALSE_CALLBACK);
224 EXPECT_TRUE(ret.isOk());
225 }
226
227 // TEST_IFACE is presumed to exist on the device and be up. No packets
228 // are ever actually caused to be forwarded.
TEST_P(OffloadControlTestV1_0_HalStarted,SetDataLimitNonZeroOk)229 TEST_P(OffloadControlTestV1_0_HalStarted, SetDataLimitNonZeroOk) {
230 const hidl_string upstream(TEST_IFACE);
231 const uint64_t limit = 5000ULL;
232 const Return<void> ret = control->setDataLimit(upstream, limit, ASSERT_TRUE_CALLBACK);
233 EXPECT_TRUE(ret.isOk());
234 }
235
236 // TEST_IFACE is presumed to exist on the device and be up. No packets
237 // are ever actually caused to be forwarded.
TEST_P(OffloadControlTestV1_0_HalStarted,SetDataLimitZeroOk)238 TEST_P(OffloadControlTestV1_0_HalStarted, SetDataLimitZeroOk) {
239 const hidl_string upstream(TEST_IFACE);
240 const uint64_t limit = 0ULL;
241 const Return<void> ret = control->setDataLimit(upstream, limit, ASSERT_TRUE_CALLBACK);
242 EXPECT_TRUE(ret.isOk());
243 }
244
245 /*
246 * Tests for IOffloadControl::setUpstreamParameters().
247 */
248
249 // TEST_IFACE is presumed to exist on the device and be up. No packets
250 // are ever actually caused to be forwarded.
TEST_P(OffloadControlTestV1_0_HalStarted,SetUpstreamParametersIPv6OnlyOk)251 TEST_P(OffloadControlTestV1_0_HalStarted, SetUpstreamParametersIPv6OnlyOk) {
252 const hidl_string iface(TEST_IFACE);
253 const hidl_string v4Addr("");
254 const hidl_string v4Gw("");
255 const vector<hidl_string> v6Gws{hidl_string("fe80::db8:1"), hidl_string("fe80::db8:2")};
256 const Return<void> ret =
257 control->setUpstreamParameters(iface, v4Addr, v4Gw, v6Gws, ASSERT_TRUE_CALLBACK);
258 EXPECT_TRUE(ret.isOk());
259 }
260
261 // TEST_IFACE is presumed to exist on the device and be up. No packets
262 // are ever actually caused to be forwarded.
TEST_P(OffloadControlTestV1_0_HalStarted,SetUpstreamParametersAlternateIPv6OnlyOk)263 TEST_P(OffloadControlTestV1_0_HalStarted, SetUpstreamParametersAlternateIPv6OnlyOk) {
264 const hidl_string iface(TEST_IFACE);
265 const hidl_string v4Addr;
266 const hidl_string v4Gw;
267 const vector<hidl_string> v6Gws{hidl_string("fe80::db8:1"), hidl_string("fe80::db8:3")};
268 const Return<void> ret =
269 control->setUpstreamParameters(iface, v4Addr, v4Gw, v6Gws, ASSERT_TRUE_CALLBACK);
270 EXPECT_TRUE(ret.isOk());
271 }
272
273 // TEST_IFACE is presumed to exist on the device and be up. No packets
274 // are ever actually caused to be forwarded.
TEST_P(OffloadControlTestV1_0_HalStarted,SetUpstreamParametersIPv4OnlyOk)275 TEST_P(OffloadControlTestV1_0_HalStarted, SetUpstreamParametersIPv4OnlyOk) {
276 const hidl_string iface(TEST_IFACE);
277 const hidl_string v4Addr("192.0.2.2");
278 const hidl_string v4Gw("192.0.2.1");
279 const vector<hidl_string> v6Gws{};
280 const Return<void> ret =
281 control->setUpstreamParameters(iface, v4Addr, v4Gw, v6Gws, ASSERT_TRUE_CALLBACK);
282 EXPECT_TRUE(ret.isOk());
283 }
284
285 // TEST_IFACE is presumed to exist on the device and be up. No packets
286 // are ever actually caused to be forwarded.
TEST_P(OffloadControlTestV1_0_HalStarted,SetUpstreamParametersIPv4v6Ok)287 TEST_P(OffloadControlTestV1_0_HalStarted, SetUpstreamParametersIPv4v6Ok) {
288 const hidl_string iface(TEST_IFACE);
289 const hidl_string v4Addr("192.0.2.2");
290 const hidl_string v4Gw("192.0.2.1");
291 const vector<hidl_string> v6Gws{hidl_string("fe80::db8:1"), hidl_string("fe80::db8:2")};
292 const Return<void> ret =
293 control->setUpstreamParameters(iface, v4Addr, v4Gw, v6Gws, ASSERT_TRUE_CALLBACK);
294 EXPECT_TRUE(ret.isOk());
295 }
296
297 // Test that setUpstreamParameters() fails when all parameters are empty.
TEST_P(OffloadControlTestV1_0_HalStarted,SetUpstreamParametersEmptyFails)298 TEST_P(OffloadControlTestV1_0_HalStarted, SetUpstreamParametersEmptyFails) {
299 const hidl_string iface("");
300 const hidl_string v4Addr("");
301 const hidl_string v4Gw("");
302 const vector<hidl_string> v6Gws{};
303 const Return<void> ret =
304 control->setUpstreamParameters(iface, v4Addr, v4Gw, v6Gws, ASSERT_FALSE_CALLBACK);
305 EXPECT_TRUE(ret.isOk());
306 }
307
308 // Test that setUpstreamParameters() fails when given empty or non-existent interface names.
TEST_P(OffloadControlTestV1_0_HalStarted,SetUpstreamParametersBogusIfaceFails)309 TEST_P(OffloadControlTestV1_0_HalStarted, SetUpstreamParametersBogusIfaceFails) {
310 const hidl_string v4Addr("192.0.2.2");
311 const hidl_string v4Gw("192.0.2.1");
312 const vector<hidl_string> v6Gws{hidl_string("fe80::db8:1")};
313 for (const auto& bogus : {"", "invalid"}) {
314 SCOPED_TRACE(StringPrintf("iface='%s'", bogus));
315 const hidl_string iface(bogus);
316 const Return<void> ret =
317 control->setUpstreamParameters(iface, v4Addr, v4Gw, v6Gws, ASSERT_FALSE_CALLBACK);
318 EXPECT_TRUE(ret.isOk());
319 }
320 }
321
322 // Test that setUpstreamParameters() fails when given unparseable IPv4 addresses.
TEST_P(OffloadControlTestV1_0_HalStarted,SetUpstreamParametersInvalidIPv4AddrFails)323 TEST_P(OffloadControlTestV1_0_HalStarted, SetUpstreamParametersInvalidIPv4AddrFails) {
324 const hidl_string iface(TEST_IFACE);
325 const hidl_string v4Gw("192.0.2.1");
326 const vector<hidl_string> v6Gws{hidl_string("fe80::db8:1")};
327 for (const auto& bogus : {"invalid", "192.0.2"}) {
328 SCOPED_TRACE(StringPrintf("v4addr='%s'", bogus));
329 const hidl_string v4Addr(bogus);
330 const Return<void> ret =
331 control->setUpstreamParameters(iface, v4Addr, v4Gw, v6Gws, ASSERT_FALSE_CALLBACK);
332 EXPECT_TRUE(ret.isOk());
333 }
334 }
335
336 // Test that setUpstreamParameters() fails when given unparseable IPv4 gateways.
TEST_P(OffloadControlTestV1_0_HalStarted,SetUpstreamParametersInvalidIPv4GatewayFails)337 TEST_P(OffloadControlTestV1_0_HalStarted, SetUpstreamParametersInvalidIPv4GatewayFails) {
338 const hidl_string iface(TEST_IFACE);
339 const hidl_string v4Addr("192.0.2.2");
340 const vector<hidl_string> v6Gws{hidl_string("fe80::db8:1")};
341 for (const auto& bogus : {"invalid", "192.0.2"}) {
342 SCOPED_TRACE(StringPrintf("v4gateway='%s'", bogus));
343 const hidl_string v4Gw(bogus);
344 const Return<void> ret =
345 control->setUpstreamParameters(iface, v4Addr, v4Gw, v6Gws, ASSERT_FALSE_CALLBACK);
346 EXPECT_TRUE(ret.isOk());
347 }
348 }
349
350 // Test that setUpstreamParameters() fails when given unparseable IPv6 gateways.
TEST_P(OffloadControlTestV1_0_HalStarted,SetUpstreamParametersBadIPv6GatewaysFail)351 TEST_P(OffloadControlTestV1_0_HalStarted, SetUpstreamParametersBadIPv6GatewaysFail) {
352 const hidl_string iface(TEST_IFACE);
353 const hidl_string v4Addr("192.0.2.2");
354 const hidl_string v4Gw("192.0.2.1");
355 for (const auto& bogus : {"", "invalid", "fe80::bogus", "192.0.2.66"}) {
356 SCOPED_TRACE(StringPrintf("v6gateway='%s'", bogus));
357 const vector<hidl_string> v6Gws{hidl_string("fe80::1"), hidl_string(bogus)};
358 const Return<void> ret =
359 control->setUpstreamParameters(iface, v4Addr, v4Gw, v6Gws, ASSERT_FALSE_CALLBACK);
360 EXPECT_TRUE(ret.isOk());
361 }
362 }
363
364 /*
365 * Tests for IOffloadControl::addDownstream().
366 */
367
368 // Test addDownstream() works given an IPv4 prefix.
TEST_P(OffloadControlTestV1_0_HalStarted,AddDownstreamIPv4)369 TEST_P(OffloadControlTestV1_0_HalStarted, AddDownstreamIPv4) {
370 const hidl_string iface("dummy0");
371 const hidl_string prefix("192.0.2.0/24");
372 const Return<void> ret = control->addDownstream(iface, prefix, ASSERT_TRUE_CALLBACK);
373 EXPECT_TRUE(ret.isOk());
374 }
375
376 // Test addDownstream() works given an IPv6 prefix.
TEST_P(OffloadControlTestV1_0_HalStarted,AddDownstreamIPv6)377 TEST_P(OffloadControlTestV1_0_HalStarted, AddDownstreamIPv6) {
378 const hidl_string iface("dummy0");
379 const hidl_string prefix("2001:db8::/64");
380 const Return<void> ret = control->addDownstream(iface, prefix, ASSERT_TRUE_CALLBACK);
381 EXPECT_TRUE(ret.isOk());
382 }
383
384 // Test addDownstream() fails given all empty parameters.
TEST_P(OffloadControlTestV1_0_HalStarted,AddDownstreamEmptyFails)385 TEST_P(OffloadControlTestV1_0_HalStarted, AddDownstreamEmptyFails) {
386 const hidl_string iface("");
387 const hidl_string prefix("");
388 const Return<void> ret = control->addDownstream(iface, prefix, ASSERT_FALSE_CALLBACK);
389 EXPECT_TRUE(ret.isOk());
390 }
391
392 // Test addDownstream() fails given empty or non-existent interface names.
TEST_P(OffloadControlTestV1_0_HalStarted,AddDownstreamInvalidIfaceFails)393 TEST_P(OffloadControlTestV1_0_HalStarted, AddDownstreamInvalidIfaceFails) {
394 const hidl_string prefix("192.0.2.0/24");
395 for (const auto& bogus : {"", "invalid"}) {
396 SCOPED_TRACE(StringPrintf("iface='%s'", bogus));
397 const hidl_string iface(bogus);
398 const Return<void> ret = control->addDownstream(iface, prefix, ASSERT_FALSE_CALLBACK);
399 EXPECT_TRUE(ret.isOk());
400 }
401 }
402
403 // Test addDownstream() fails given unparseable prefix arguments.
TEST_P(OffloadControlTestV1_0_HalStarted,AddDownstreamBogusPrefixFails)404 TEST_P(OffloadControlTestV1_0_HalStarted, AddDownstreamBogusPrefixFails) {
405 const hidl_string iface("dummy0");
406 for (const auto& bogus : {"", "192.0.2/24", "2001:db8/64"}) {
407 SCOPED_TRACE(StringPrintf("prefix='%s'", bogus));
408 const hidl_string prefix(bogus);
409 const Return<void> ret = control->addDownstream(iface, prefix, ASSERT_FALSE_CALLBACK);
410 EXPECT_TRUE(ret.isOk());
411 }
412 }
413
414 /*
415 * Tests for IOffloadControl::removeDownstream().
416 */
417
418 // Test removeDownstream() works given an IPv4 prefix.
TEST_P(OffloadControlTestV1_0_HalStarted,RemoveDownstreamIPv4)419 TEST_P(OffloadControlTestV1_0_HalStarted, RemoveDownstreamIPv4) {
420 const hidl_string iface("dummy0");
421 const hidl_string prefix("192.0.2.0/24");
422 // First add the downstream, otherwise removeDownstream logic can reasonably
423 // return false for downstreams not previously added.
424 const Return<void> add = control->addDownstream(iface, prefix, ASSERT_TRUE_CALLBACK);
425 EXPECT_TRUE(add.isOk());
426 const Return<void> del = control->removeDownstream(iface, prefix, ASSERT_TRUE_CALLBACK);
427 EXPECT_TRUE(del.isOk());
428 }
429
430 // Test removeDownstream() works given an IPv6 prefix.
TEST_P(OffloadControlTestV1_0_HalStarted,RemoveDownstreamIPv6)431 TEST_P(OffloadControlTestV1_0_HalStarted, RemoveDownstreamIPv6) {
432 const hidl_string iface("dummy0");
433 const hidl_string prefix("2001:db8::/64");
434 // First add the downstream, otherwise removeDownstream logic can reasonably
435 // return false for downstreams not previously added.
436 const Return<void> add = control->addDownstream(iface, prefix, ASSERT_TRUE_CALLBACK);
437 EXPECT_TRUE(add.isOk());
438 const Return<void> del = control->removeDownstream(iface, prefix, ASSERT_TRUE_CALLBACK);
439 EXPECT_TRUE(del.isOk());
440 }
441
442 // Test removeDownstream() fails given all empty parameters.
TEST_P(OffloadControlTestV1_0_HalStarted,RemoveDownstreamEmptyFails)443 TEST_P(OffloadControlTestV1_0_HalStarted, RemoveDownstreamEmptyFails) {
444 const hidl_string iface("");
445 const hidl_string prefix("");
446 const Return<void> ret = control->removeDownstream(iface, prefix, ASSERT_FALSE_CALLBACK);
447 EXPECT_TRUE(ret.isOk());
448 }
449
450 // Test removeDownstream() fails given empty or non-existent interface names.
TEST_P(OffloadControlTestV1_0_HalStarted,RemoveDownstreamBogusIfaceFails)451 TEST_P(OffloadControlTestV1_0_HalStarted, RemoveDownstreamBogusIfaceFails) {
452 const hidl_string prefix("192.0.2.0/24");
453 for (const auto& bogus : {"", "invalid"}) {
454 SCOPED_TRACE(StringPrintf("iface='%s'", bogus));
455 const hidl_string iface(bogus);
456 const Return<void> ret = control->removeDownstream(iface, prefix, ASSERT_FALSE_CALLBACK);
457 EXPECT_TRUE(ret.isOk());
458 }
459 }
460
461 // Test removeDownstream() fails given unparseable prefix arguments.
TEST_P(OffloadControlTestV1_0_HalStarted,RemoveDownstreamBogusPrefixFails)462 TEST_P(OffloadControlTestV1_0_HalStarted, RemoveDownstreamBogusPrefixFails) {
463 const hidl_string iface("dummy0");
464 for (const auto& bogus : {"", "192.0.2/24", "2001:db8/64"}) {
465 SCOPED_TRACE(StringPrintf("prefix='%s'", bogus));
466 const hidl_string prefix(bogus);
467 const Return<void> ret = control->removeDownstream(iface, prefix, ASSERT_FALSE_CALLBACK);
468 EXPECT_TRUE(ret.isOk());
469 }
470 }
471
472 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(OffloadControlTestV1_0_HalNotStarted);
473 INSTANTIATE_TEST_CASE_P(
474 PerInstance, OffloadControlTestV1_0_HalNotStarted,
475 testing::Combine(testing::ValuesIn(android::hardware::getAllHalInstanceNames(
476 IOffloadConfig::descriptor)),
477 testing::ValuesIn(android::hardware::getAllHalInstanceNames(
478 IOffloadControl::descriptor))),
479 android::hardware::PrintInstanceTupleNameToString<>);
480
481 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(OffloadControlTestV1_0_HalStarted);
482 INSTANTIATE_TEST_CASE_P(
483 PerInstance, OffloadControlTestV1_0_HalStarted,
484 testing::Combine(testing::ValuesIn(android::hardware::getAllHalInstanceNames(
485 IOffloadConfig::descriptor)),
486 testing::ValuesIn(android::hardware::getAllHalInstanceNames(
487 IOffloadControl::descriptor))),
488 android::hardware::PrintInstanceTupleNameToString<>);
489