|
|
|
|
@@ -16,215 +16,24 @@
|
|
|
|
|
|
|
|
|
|
#define LOG_TAG "VtsOffloadControlV1_0TargetTest"
|
|
|
|
|
|
|
|
|
|
#include <VtsHalHidlTargetCallbackBase.h>
|
|
|
|
|
#include <OffloadControlTestV1_0.h>
|
|
|
|
|
#include <android-base/stringprintf.h>
|
|
|
|
|
#include <android-base/unique_fd.h>
|
|
|
|
|
#include <android/hardware/tetheroffload/config/1.0/IOffloadConfig.h>
|
|
|
|
|
#include <android/hardware/tetheroffload/control/1.0/IOffloadControl.h>
|
|
|
|
|
#include <android/hardware/tetheroffload/control/1.0/types.h>
|
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
#include <hidl/GtestPrinter.h>
|
|
|
|
|
#include <hidl/ServiceManagement.h>
|
|
|
|
|
#include <linux/netfilter/nfnetlink.h>
|
|
|
|
|
#include <linux/netlink.h>
|
|
|
|
|
#include <log/log.h>
|
|
|
|
|
#include <net/if.h>
|
|
|
|
|
#include <sys/socket.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <set>
|
|
|
|
|
|
|
|
|
|
using android::base::StringPrintf;
|
|
|
|
|
using android::base::unique_fd;
|
|
|
|
|
using android::hardware::hidl_handle;
|
|
|
|
|
using android::hardware::hidl_string;
|
|
|
|
|
using android::hardware::hidl_vec;
|
|
|
|
|
using android::hardware::Return;
|
|
|
|
|
using android::hardware::tetheroffload::config::V1_0::IOffloadConfig;
|
|
|
|
|
using android::hardware::tetheroffload::control::V1_0::IOffloadControl;
|
|
|
|
|
using android::hardware::tetheroffload::control::V1_0::IPv4AddrPortPair;
|
|
|
|
|
using android::hardware::tetheroffload::control::V1_0::ITetheringOffloadCallback;
|
|
|
|
|
using android::hardware::tetheroffload::control::V1_0::OffloadCallbackEvent;
|
|
|
|
|
using android::hardware::tetheroffload::control::V1_0::NatTimeoutUpdate;
|
|
|
|
|
using android::hardware::tetheroffload::control::V1_0::NetworkProtocol;
|
|
|
|
|
using android::hardware::Void;
|
|
|
|
|
using android::sp;
|
|
|
|
|
|
|
|
|
|
enum class ExpectBoolean {
|
|
|
|
|
Ignored = -1,
|
|
|
|
|
False = 0,
|
|
|
|
|
True = 1,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
constexpr const char* TEST_IFACE = "rmnet_data0";
|
|
|
|
|
|
|
|
|
|
// We use #defines here so as to get local lamba captures and error message line numbers
|
|
|
|
|
#define ASSERT_TRUE_CALLBACK \
|
|
|
|
|
[&](bool success, std::string errMsg) { \
|
|
|
|
|
std::string msg = StringPrintf("unexpected error: %s", errMsg.c_str()); \
|
|
|
|
|
ASSERT_TRUE(success) << msg; \
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define ASSERT_FALSE_CALLBACK \
|
|
|
|
|
[&](bool success, std::string errMsg) { \
|
|
|
|
|
std::string msg = StringPrintf("expected error: %s", errMsg.c_str()); \
|
|
|
|
|
ASSERT_FALSE(success) << msg; \
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define ASSERT_ZERO_BYTES_CALLBACK \
|
|
|
|
|
[&](uint64_t rxBytes, uint64_t txBytes) { \
|
|
|
|
|
EXPECT_EQ(0ULL, rxBytes); \
|
|
|
|
|
EXPECT_EQ(0ULL, txBytes); \
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline const sockaddr* asSockaddr(const sockaddr_nl* nladdr) {
|
|
|
|
|
return reinterpret_cast<const sockaddr*>(nladdr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int conntrackSocket(unsigned groups) {
|
|
|
|
|
unique_fd s(socket(AF_NETLINK, SOCK_DGRAM, NETLINK_NETFILTER));
|
|
|
|
|
if (s.get() < 0) {
|
|
|
|
|
return -errno;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const struct sockaddr_nl bind_addr = {
|
|
|
|
|
.nl_family = AF_NETLINK, .nl_pad = 0, .nl_pid = 0, .nl_groups = groups,
|
|
|
|
|
};
|
|
|
|
|
if (::bind(s.get(), asSockaddr(&bind_addr), sizeof(bind_addr)) < 0) {
|
|
|
|
|
return -errno;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const struct sockaddr_nl kernel_addr = {
|
|
|
|
|
.nl_family = AF_NETLINK, .nl_pad = 0, .nl_pid = 0, .nl_groups = groups,
|
|
|
|
|
};
|
|
|
|
|
if (connect(s.get(), asSockaddr(&kernel_addr), sizeof(kernel_addr)) != 0) {
|
|
|
|
|
return -errno;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return s.release();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
constexpr char kCallbackOnEvent[] = "onEvent";
|
|
|
|
|
constexpr char kCallbackUpdateTimeout[] = "updateTimeout";
|
|
|
|
|
|
|
|
|
|
class TetheringOffloadCallbackArgs {
|
|
|
|
|
public:
|
|
|
|
|
OffloadCallbackEvent last_event;
|
|
|
|
|
NatTimeoutUpdate last_params;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class OffloadControlHidlTestBase
|
|
|
|
|
: public testing::TestWithParam<std::tuple<std::string, std::string>> {
|
|
|
|
|
public:
|
|
|
|
|
virtual void SetUp() override {
|
|
|
|
|
setupConfigHal();
|
|
|
|
|
prepareControlHal();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual void TearDown() override {
|
|
|
|
|
// For good measure, we should try stopOffload() once more. Since we
|
|
|
|
|
// don't know where we are in HAL call test cycle we don't know what
|
|
|
|
|
// return code to actually expect, so we just ignore it.
|
|
|
|
|
stopOffload(ExpectBoolean::Ignored);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// The IOffloadConfig HAL is tested more thoroughly elsewhere. He we just
|
|
|
|
|
// setup everything correctly and verify basic readiness.
|
|
|
|
|
void setupConfigHal() {
|
|
|
|
|
config = IOffloadConfig::getService(std::get<0>(GetParam()));
|
|
|
|
|
ASSERT_NE(nullptr, config.get()) << "Could not get HIDL instance";
|
|
|
|
|
|
|
|
|
|
unique_fd fd1(conntrackSocket(NF_NETLINK_CONNTRACK_NEW | NF_NETLINK_CONNTRACK_DESTROY));
|
|
|
|
|
if (fd1.get() < 0) {
|
|
|
|
|
ALOGE("Unable to create conntrack handles: %d/%s", errno, strerror(errno));
|
|
|
|
|
FAIL();
|
|
|
|
|
}
|
|
|
|
|
native_handle_t* const nativeHandle1 = native_handle_create(1, 0);
|
|
|
|
|
nativeHandle1->data[0] = fd1.release();
|
|
|
|
|
hidl_handle h1;
|
|
|
|
|
h1.setTo(nativeHandle1, true);
|
|
|
|
|
|
|
|
|
|
unique_fd fd2(conntrackSocket(NF_NETLINK_CONNTRACK_UPDATE | NF_NETLINK_CONNTRACK_DESTROY));
|
|
|
|
|
if (fd2.get() < 0) {
|
|
|
|
|
ALOGE("Unable to create conntrack handles: %d/%s", errno, strerror(errno));
|
|
|
|
|
FAIL();
|
|
|
|
|
}
|
|
|
|
|
native_handle_t* const nativeHandle2 = native_handle_create(1, 0);
|
|
|
|
|
nativeHandle2->data[0] = fd2.release();
|
|
|
|
|
hidl_handle h2;
|
|
|
|
|
h2.setTo(nativeHandle2, true);
|
|
|
|
|
|
|
|
|
|
const Return<void> ret = config->setHandles(h1, h2, ASSERT_TRUE_CALLBACK);
|
|
|
|
|
ASSERT_TRUE(ret.isOk());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void prepareControlHal() {
|
|
|
|
|
control = IOffloadControl::getService(std::get<1>(GetParam()));
|
|
|
|
|
ASSERT_NE(nullptr, control.get()) << "Could not get HIDL instance";
|
|
|
|
|
|
|
|
|
|
control_cb = new TetheringOffloadCallback();
|
|
|
|
|
ASSERT_NE(nullptr, control_cb.get()) << "Could not get get offload callback";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void initOffload(const bool expected_result) {
|
|
|
|
|
auto init_cb = [&](bool success, std::string errMsg) {
|
|
|
|
|
std::string msg = StringPrintf("Unexpectedly %s to init offload: %s",
|
|
|
|
|
success ? "succeeded" : "failed", errMsg.c_str());
|
|
|
|
|
ASSERT_EQ(expected_result, success) << msg;
|
|
|
|
|
};
|
|
|
|
|
const Return<void> ret = control->initOffload(control_cb, init_cb);
|
|
|
|
|
ASSERT_TRUE(ret.isOk());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void setupControlHal() {
|
|
|
|
|
prepareControlHal();
|
|
|
|
|
initOffload(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void stopOffload(const ExpectBoolean value) {
|
|
|
|
|
auto cb = [&](bool success, const hidl_string& errMsg) {
|
|
|
|
|
switch (value) {
|
|
|
|
|
case ExpectBoolean::False:
|
|
|
|
|
ASSERT_EQ(false, success) << "Unexpectedly able to stop offload: " << errMsg;
|
|
|
|
|
break;
|
|
|
|
|
case ExpectBoolean::True:
|
|
|
|
|
ASSERT_EQ(true, success) << "Unexpectedly failed to stop offload: " << errMsg;
|
|
|
|
|
break;
|
|
|
|
|
case ExpectBoolean::Ignored:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
const Return<void> ret = control->stopOffload(cb);
|
|
|
|
|
ASSERT_TRUE(ret.isOk());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Callback class for both events and NAT timeout updates.
|
|
|
|
|
class TetheringOffloadCallback
|
|
|
|
|
: public testing::VtsHalHidlTargetCallbackBase<TetheringOffloadCallbackArgs>,
|
|
|
|
|
public ITetheringOffloadCallback {
|
|
|
|
|
public:
|
|
|
|
|
TetheringOffloadCallback() = default;
|
|
|
|
|
virtual ~TetheringOffloadCallback() = default;
|
|
|
|
|
|
|
|
|
|
Return<void> onEvent(OffloadCallbackEvent event) override {
|
|
|
|
|
const TetheringOffloadCallbackArgs args{.last_event = event};
|
|
|
|
|
NotifyFromCallback(kCallbackOnEvent, args);
|
|
|
|
|
return Void();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Return<void> updateTimeout(const NatTimeoutUpdate& params) override {
|
|
|
|
|
const TetheringOffloadCallbackArgs args{.last_params = params};
|
|
|
|
|
NotifyFromCallback(kCallbackUpdateTimeout, args);
|
|
|
|
|
return Void();
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
sp<IOffloadConfig> config;
|
|
|
|
|
sp<IOffloadControl> control;
|
|
|
|
|
sp<TetheringOffloadCallback> control_cb;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Call initOffload() multiple times. Check that non-first initOffload() calls return false.
|
|
|
|
|
TEST_P(OffloadControlHidlTestBase, AdditionalInitsWithoutStopReturnFalse) {
|
|
|
|
|
TEST_P(OffloadControlTestV1_0_HalNotStarted, AdditionalInitsWithoutStopReturnFalse) {
|
|
|
|
|
initOffload(true);
|
|
|
|
|
initOffload(false);
|
|
|
|
|
initOffload(false);
|
|
|
|
|
@@ -232,7 +41,7 @@ TEST_P(OffloadControlHidlTestBase, AdditionalInitsWithoutStopReturnFalse) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check that calling stopOffload() without first having called initOffload() returns false.
|
|
|
|
|
TEST_P(OffloadControlHidlTestBase, MultipleStopsWithoutInitReturnFalse) {
|
|
|
|
|
TEST_P(OffloadControlTestV1_0_HalNotStarted, MultipleStopsWithoutInitReturnFalse) {
|
|
|
|
|
stopOffload(ExpectBoolean::False);
|
|
|
|
|
stopOffload(ExpectBoolean::False);
|
|
|
|
|
stopOffload(ExpectBoolean::False);
|
|
|
|
|
@@ -251,7 +60,7 @@ bool interfaceIsUp(const char* name) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check that calling stopOffload() after a complete init/stop cycle returns false.
|
|
|
|
|
TEST_P(OffloadControlHidlTestBase, AdditionalStopsWithInitReturnFalse) {
|
|
|
|
|
TEST_P(OffloadControlTestV1_0_HalNotStarted, AdditionalStopsWithInitReturnFalse) {
|
|
|
|
|
initOffload(true);
|
|
|
|
|
// Call setUpstreamParameters() so that "offload" can be reasonably said
|
|
|
|
|
// to be both requested and operational.
|
|
|
|
|
@@ -273,7 +82,7 @@ TEST_P(OffloadControlHidlTestBase, AdditionalStopsWithInitReturnFalse) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check that calling setLocalPrefixes() without first having called initOffload() returns false.
|
|
|
|
|
TEST_P(OffloadControlHidlTestBase, SetLocalPrefixesWithoutInitReturnsFalse) {
|
|
|
|
|
TEST_P(OffloadControlTestV1_0_HalNotStarted, SetLocalPrefixesWithoutInitReturnsFalse) {
|
|
|
|
|
const vector<hidl_string> prefixes{hidl_string("2001:db8::/64")};
|
|
|
|
|
const Return<void> ret = control->setLocalPrefixes(prefixes, ASSERT_FALSE_CALLBACK);
|
|
|
|
|
EXPECT_TRUE(ret.isOk());
|
|
|
|
|
@@ -281,14 +90,14 @@ TEST_P(OffloadControlHidlTestBase, SetLocalPrefixesWithoutInitReturnsFalse) {
|
|
|
|
|
|
|
|
|
|
// Check that calling getForwardedStats() without first having called initOffload()
|
|
|
|
|
// returns zero bytes statistics.
|
|
|
|
|
TEST_P(OffloadControlHidlTestBase, GetForwardedStatsWithoutInitReturnsZeroValues) {
|
|
|
|
|
TEST_P(OffloadControlTestV1_0_HalNotStarted, GetForwardedStatsWithoutInitReturnsZeroValues) {
|
|
|
|
|
const hidl_string upstream(TEST_IFACE);
|
|
|
|
|
const Return<void> ret = control->getForwardedStats(upstream, ASSERT_ZERO_BYTES_CALLBACK);
|
|
|
|
|
EXPECT_TRUE(ret.isOk());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check that calling setDataLimit() without first having called initOffload() returns false.
|
|
|
|
|
TEST_P(OffloadControlHidlTestBase, SetDataLimitWithoutInitReturnsFalse) {
|
|
|
|
|
TEST_P(OffloadControlTestV1_0_HalNotStarted, SetDataLimitWithoutInitReturnsFalse) {
|
|
|
|
|
const hidl_string upstream(TEST_IFACE);
|
|
|
|
|
const uint64_t limit = 5000ULL;
|
|
|
|
|
const Return<void> ret = control->setDataLimit(upstream, limit, ASSERT_FALSE_CALLBACK);
|
|
|
|
|
@@ -297,7 +106,7 @@ TEST_P(OffloadControlHidlTestBase, SetDataLimitWithoutInitReturnsFalse) {
|
|
|
|
|
|
|
|
|
|
// Check that calling setUpstreamParameters() without first having called initOffload()
|
|
|
|
|
// returns false.
|
|
|
|
|
TEST_P(OffloadControlHidlTestBase, SetUpstreamParametersWithoutInitReturnsFalse) {
|
|
|
|
|
TEST_P(OffloadControlTestV1_0_HalNotStarted, SetUpstreamParametersWithoutInitReturnsFalse) {
|
|
|
|
|
const hidl_string iface(TEST_IFACE);
|
|
|
|
|
const hidl_string v4Addr("192.0.2.0/24");
|
|
|
|
|
const hidl_string v4Gw("192.0.2.1");
|
|
|
|
|
@@ -309,7 +118,7 @@ TEST_P(OffloadControlHidlTestBase, SetUpstreamParametersWithoutInitReturnsFalse)
|
|
|
|
|
|
|
|
|
|
// Check that calling addDownstream() with an IPv4 prefix without first having called
|
|
|
|
|
// initOffload() returns false.
|
|
|
|
|
TEST_P(OffloadControlHidlTestBase, AddIPv4DownstreamWithoutInitReturnsFalse) {
|
|
|
|
|
TEST_P(OffloadControlTestV1_0_HalNotStarted, AddIPv4DownstreamWithoutInitReturnsFalse) {
|
|
|
|
|
const hidl_string iface(TEST_IFACE);
|
|
|
|
|
const hidl_string prefix("192.0.2.0/24");
|
|
|
|
|
const Return<void> ret = control->addDownstream(iface, prefix, ASSERT_FALSE_CALLBACK);
|
|
|
|
|
@@ -318,7 +127,7 @@ TEST_P(OffloadControlHidlTestBase, AddIPv4DownstreamWithoutInitReturnsFalse) {
|
|
|
|
|
|
|
|
|
|
// Check that calling addDownstream() with an IPv6 prefix without first having called
|
|
|
|
|
// initOffload() returns false.
|
|
|
|
|
TEST_P(OffloadControlHidlTestBase, AddIPv6DownstreamWithoutInitReturnsFalse) {
|
|
|
|
|
TEST_P(OffloadControlTestV1_0_HalNotStarted, AddIPv6DownstreamWithoutInitReturnsFalse) {
|
|
|
|
|
const hidl_string iface(TEST_IFACE);
|
|
|
|
|
const hidl_string prefix("2001:db8::/64");
|
|
|
|
|
const Return<void> ret = control->addDownstream(iface, prefix, ASSERT_FALSE_CALLBACK);
|
|
|
|
|
@@ -327,7 +136,7 @@ TEST_P(OffloadControlHidlTestBase, AddIPv6DownstreamWithoutInitReturnsFalse) {
|
|
|
|
|
|
|
|
|
|
// Check that calling removeDownstream() with an IPv4 prefix without first having called
|
|
|
|
|
// initOffload() returns false.
|
|
|
|
|
TEST_P(OffloadControlHidlTestBase, RemoveIPv4DownstreamWithoutInitReturnsFalse) {
|
|
|
|
|
TEST_P(OffloadControlTestV1_0_HalNotStarted, RemoveIPv4DownstreamWithoutInitReturnsFalse) {
|
|
|
|
|
const hidl_string iface(TEST_IFACE);
|
|
|
|
|
const hidl_string prefix("192.0.2.0/24");
|
|
|
|
|
const Return<void> ret = control->removeDownstream(iface, prefix, ASSERT_FALSE_CALLBACK);
|
|
|
|
|
@@ -336,48 +145,33 @@ TEST_P(OffloadControlHidlTestBase, RemoveIPv4DownstreamWithoutInitReturnsFalse)
|
|
|
|
|
|
|
|
|
|
// Check that calling removeDownstream() with an IPv6 prefix without first having called
|
|
|
|
|
// initOffload() returns false.
|
|
|
|
|
TEST_P(OffloadControlHidlTestBase, RemoveIPv6DownstreamWithoutInitReturnsFalse) {
|
|
|
|
|
TEST_P(OffloadControlTestV1_0_HalNotStarted, RemoveIPv6DownstreamWithoutInitReturnsFalse) {
|
|
|
|
|
const hidl_string iface(TEST_IFACE);
|
|
|
|
|
const hidl_string prefix("2001:db8::/64");
|
|
|
|
|
const Return<void> ret = control->removeDownstream(iface, prefix, ASSERT_FALSE_CALLBACK);
|
|
|
|
|
EXPECT_TRUE(ret.isOk());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class OffloadControlHidlTest : public OffloadControlHidlTestBase {
|
|
|
|
|
public:
|
|
|
|
|
virtual void SetUp() override {
|
|
|
|
|
setupConfigHal();
|
|
|
|
|
setupControlHal();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual void TearDown() override {
|
|
|
|
|
// For good measure, we should try stopOffload() once more. Since we
|
|
|
|
|
// don't know where we are in HAL call test cycle we don't know what
|
|
|
|
|
// return code to actually expect, so we just ignore it.
|
|
|
|
|
stopOffload(ExpectBoolean::Ignored);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Tests for IOffloadControl::setLocalPrefixes().
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// Test setLocalPrefixes() accepts an IPv4 address.
|
|
|
|
|
TEST_P(OffloadControlHidlTest, SetLocalPrefixesIPv4AddressOk) {
|
|
|
|
|
TEST_P(OffloadControlTestV1_0_HalStarted, SetLocalPrefixesIPv4AddressOk) {
|
|
|
|
|
const vector<hidl_string> prefixes{hidl_string("192.0.2.1")};
|
|
|
|
|
const Return<void> ret = control->setLocalPrefixes(prefixes, ASSERT_TRUE_CALLBACK);
|
|
|
|
|
EXPECT_TRUE(ret.isOk());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test setLocalPrefixes() accepts an IPv6 address.
|
|
|
|
|
TEST_P(OffloadControlHidlTest, SetLocalPrefixesIPv6AddressOk) {
|
|
|
|
|
TEST_P(OffloadControlTestV1_0_HalStarted, SetLocalPrefixesIPv6AddressOk) {
|
|
|
|
|
const vector<hidl_string> prefixes{hidl_string("fe80::1")};
|
|
|
|
|
const Return<void> ret = control->setLocalPrefixes(prefixes, ASSERT_TRUE_CALLBACK);
|
|
|
|
|
EXPECT_TRUE(ret.isOk());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test setLocalPrefixes() accepts both IPv4 and IPv6 prefixes.
|
|
|
|
|
TEST_P(OffloadControlHidlTest, SetLocalPrefixesIPv4v6PrefixesOk) {
|
|
|
|
|
TEST_P(OffloadControlTestV1_0_HalStarted, SetLocalPrefixesIPv4v6PrefixesOk) {
|
|
|
|
|
const vector<hidl_string> prefixes{hidl_string("192.0.2.0/24"), hidl_string("fe80::/64")};
|
|
|
|
|
const Return<void> ret = control->setLocalPrefixes(prefixes, ASSERT_TRUE_CALLBACK);
|
|
|
|
|
EXPECT_TRUE(ret.isOk());
|
|
|
|
|
@@ -386,14 +180,14 @@ TEST_P(OffloadControlHidlTest, SetLocalPrefixesIPv4v6PrefixesOk) {
|
|
|
|
|
// Test that setLocalPrefixes() fails given empty input. There is always
|
|
|
|
|
// a non-empty set of local prefixes; when all networking interfaces are down
|
|
|
|
|
// we still apply {127.0.0.0/8, ::1/128, fe80::/64} here.
|
|
|
|
|
TEST_P(OffloadControlHidlTest, SetLocalPrefixesEmptyFails) {
|
|
|
|
|
TEST_P(OffloadControlTestV1_0_HalStarted, SetLocalPrefixesEmptyFails) {
|
|
|
|
|
const vector<hidl_string> prefixes{};
|
|
|
|
|
const Return<void> ret = control->setLocalPrefixes(prefixes, ASSERT_FALSE_CALLBACK);
|
|
|
|
|
EXPECT_TRUE(ret.isOk());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test setLocalPrefixes() fails on incorrectly formed input strings.
|
|
|
|
|
TEST_P(OffloadControlHidlTest, SetLocalPrefixesInvalidFails) {
|
|
|
|
|
TEST_P(OffloadControlTestV1_0_HalStarted, SetLocalPrefixesInvalidFails) {
|
|
|
|
|
const vector<hidl_string> prefixes{hidl_string("192.0.2.0/24"), hidl_string("invalid")};
|
|
|
|
|
const Return<void> ret = control->setLocalPrefixes(prefixes, ASSERT_FALSE_CALLBACK);
|
|
|
|
|
EXPECT_TRUE(ret.isOk());
|
|
|
|
|
@@ -404,7 +198,7 @@ TEST_P(OffloadControlHidlTest, SetLocalPrefixesInvalidFails) {
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// Test that getForwardedStats() for a non-existent upstream yields zero bytes statistics.
|
|
|
|
|
TEST_P(OffloadControlHidlTest, GetForwardedStatsInvalidUpstreamIface) {
|
|
|
|
|
TEST_P(OffloadControlTestV1_0_HalStarted, GetForwardedStatsInvalidUpstreamIface) {
|
|
|
|
|
const hidl_string upstream("invalid");
|
|
|
|
|
const Return<void> ret = control->getForwardedStats(upstream, ASSERT_ZERO_BYTES_CALLBACK);
|
|
|
|
|
EXPECT_TRUE(ret.isOk());
|
|
|
|
|
@@ -412,7 +206,7 @@ TEST_P(OffloadControlHidlTest, GetForwardedStatsInvalidUpstreamIface) {
|
|
|
|
|
|
|
|
|
|
// TEST_IFACE is presumed to exist on the device and be up. No packets
|
|
|
|
|
// are ever actually caused to be forwarded.
|
|
|
|
|
TEST_P(OffloadControlHidlTest, GetForwardedStatsDummyIface) {
|
|
|
|
|
TEST_P(OffloadControlTestV1_0_HalStarted, GetForwardedStatsDummyIface) {
|
|
|
|
|
const hidl_string upstream(TEST_IFACE);
|
|
|
|
|
const Return<void> ret = control->getForwardedStats(upstream, ASSERT_ZERO_BYTES_CALLBACK);
|
|
|
|
|
EXPECT_TRUE(ret.isOk());
|
|
|
|
|
@@ -423,7 +217,7 @@ TEST_P(OffloadControlHidlTest, GetForwardedStatsDummyIface) {
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// Test that setDataLimit() for an empty interface name fails.
|
|
|
|
|
TEST_P(OffloadControlHidlTest, SetDataLimitEmptyUpstreamIfaceFails) {
|
|
|
|
|
TEST_P(OffloadControlTestV1_0_HalStarted, SetDataLimitEmptyUpstreamIfaceFails) {
|
|
|
|
|
const hidl_string upstream("");
|
|
|
|
|
const uint64_t limit = 5000ULL;
|
|
|
|
|
const Return<void> ret = control->setDataLimit(upstream, limit, ASSERT_FALSE_CALLBACK);
|
|
|
|
|
@@ -432,7 +226,7 @@ TEST_P(OffloadControlHidlTest, SetDataLimitEmptyUpstreamIfaceFails) {
|
|
|
|
|
|
|
|
|
|
// TEST_IFACE is presumed to exist on the device and be up. No packets
|
|
|
|
|
// are ever actually caused to be forwarded.
|
|
|
|
|
TEST_P(OffloadControlHidlTest, SetDataLimitNonZeroOk) {
|
|
|
|
|
TEST_P(OffloadControlTestV1_0_HalStarted, SetDataLimitNonZeroOk) {
|
|
|
|
|
const hidl_string upstream(TEST_IFACE);
|
|
|
|
|
const uint64_t limit = 5000ULL;
|
|
|
|
|
const Return<void> ret = control->setDataLimit(upstream, limit, ASSERT_TRUE_CALLBACK);
|
|
|
|
|
@@ -441,7 +235,7 @@ TEST_P(OffloadControlHidlTest, SetDataLimitNonZeroOk) {
|
|
|
|
|
|
|
|
|
|
// TEST_IFACE is presumed to exist on the device and be up. No packets
|
|
|
|
|
// are ever actually caused to be forwarded.
|
|
|
|
|
TEST_P(OffloadControlHidlTest, SetDataLimitZeroOk) {
|
|
|
|
|
TEST_P(OffloadControlTestV1_0_HalStarted, SetDataLimitZeroOk) {
|
|
|
|
|
const hidl_string upstream(TEST_IFACE);
|
|
|
|
|
const uint64_t limit = 0ULL;
|
|
|
|
|
const Return<void> ret = control->setDataLimit(upstream, limit, ASSERT_TRUE_CALLBACK);
|
|
|
|
|
@@ -454,7 +248,7 @@ TEST_P(OffloadControlHidlTest, SetDataLimitZeroOk) {
|
|
|
|
|
|
|
|
|
|
// TEST_IFACE is presumed to exist on the device and be up. No packets
|
|
|
|
|
// are ever actually caused to be forwarded.
|
|
|
|
|
TEST_P(OffloadControlHidlTest, SetUpstreamParametersIPv6OnlyOk) {
|
|
|
|
|
TEST_P(OffloadControlTestV1_0_HalStarted, SetUpstreamParametersIPv6OnlyOk) {
|
|
|
|
|
const hidl_string iface(TEST_IFACE);
|
|
|
|
|
const hidl_string v4Addr("");
|
|
|
|
|
const hidl_string v4Gw("");
|
|
|
|
|
@@ -466,7 +260,7 @@ TEST_P(OffloadControlHidlTest, SetUpstreamParametersIPv6OnlyOk) {
|
|
|
|
|
|
|
|
|
|
// TEST_IFACE is presumed to exist on the device and be up. No packets
|
|
|
|
|
// are ever actually caused to be forwarded.
|
|
|
|
|
TEST_P(OffloadControlHidlTest, SetUpstreamParametersAlternateIPv6OnlyOk) {
|
|
|
|
|
TEST_P(OffloadControlTestV1_0_HalStarted, SetUpstreamParametersAlternateIPv6OnlyOk) {
|
|
|
|
|
const hidl_string iface(TEST_IFACE);
|
|
|
|
|
const hidl_string v4Addr;
|
|
|
|
|
const hidl_string v4Gw;
|
|
|
|
|
@@ -478,7 +272,7 @@ TEST_P(OffloadControlHidlTest, SetUpstreamParametersAlternateIPv6OnlyOk) {
|
|
|
|
|
|
|
|
|
|
// TEST_IFACE is presumed to exist on the device and be up. No packets
|
|
|
|
|
// are ever actually caused to be forwarded.
|
|
|
|
|
TEST_P(OffloadControlHidlTest, SetUpstreamParametersIPv4OnlyOk) {
|
|
|
|
|
TEST_P(OffloadControlTestV1_0_HalStarted, SetUpstreamParametersIPv4OnlyOk) {
|
|
|
|
|
const hidl_string iface(TEST_IFACE);
|
|
|
|
|
const hidl_string v4Addr("192.0.2.2");
|
|
|
|
|
const hidl_string v4Gw("192.0.2.1");
|
|
|
|
|
@@ -490,7 +284,7 @@ TEST_P(OffloadControlHidlTest, SetUpstreamParametersIPv4OnlyOk) {
|
|
|
|
|
|
|
|
|
|
// TEST_IFACE is presumed to exist on the device and be up. No packets
|
|
|
|
|
// are ever actually caused to be forwarded.
|
|
|
|
|
TEST_P(OffloadControlHidlTest, SetUpstreamParametersIPv4v6Ok) {
|
|
|
|
|
TEST_P(OffloadControlTestV1_0_HalStarted, SetUpstreamParametersIPv4v6Ok) {
|
|
|
|
|
const hidl_string iface(TEST_IFACE);
|
|
|
|
|
const hidl_string v4Addr("192.0.2.2");
|
|
|
|
|
const hidl_string v4Gw("192.0.2.1");
|
|
|
|
|
@@ -501,7 +295,7 @@ TEST_P(OffloadControlHidlTest, SetUpstreamParametersIPv4v6Ok) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test that setUpstreamParameters() fails when all parameters are empty.
|
|
|
|
|
TEST_P(OffloadControlHidlTest, SetUpstreamParametersEmptyFails) {
|
|
|
|
|
TEST_P(OffloadControlTestV1_0_HalStarted, SetUpstreamParametersEmptyFails) {
|
|
|
|
|
const hidl_string iface("");
|
|
|
|
|
const hidl_string v4Addr("");
|
|
|
|
|
const hidl_string v4Gw("");
|
|
|
|
|
@@ -512,7 +306,7 @@ TEST_P(OffloadControlHidlTest, SetUpstreamParametersEmptyFails) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test that setUpstreamParameters() fails when given empty or non-existent interface names.
|
|
|
|
|
TEST_P(OffloadControlHidlTest, SetUpstreamParametersBogusIfaceFails) {
|
|
|
|
|
TEST_P(OffloadControlTestV1_0_HalStarted, SetUpstreamParametersBogusIfaceFails) {
|
|
|
|
|
const hidl_string v4Addr("192.0.2.2");
|
|
|
|
|
const hidl_string v4Gw("192.0.2.1");
|
|
|
|
|
const vector<hidl_string> v6Gws{hidl_string("fe80::db8:1")};
|
|
|
|
|
@@ -526,7 +320,7 @@ TEST_P(OffloadControlHidlTest, SetUpstreamParametersBogusIfaceFails) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test that setUpstreamParameters() fails when given unparseable IPv4 addresses.
|
|
|
|
|
TEST_P(OffloadControlHidlTest, SetUpstreamParametersInvalidIPv4AddrFails) {
|
|
|
|
|
TEST_P(OffloadControlTestV1_0_HalStarted, SetUpstreamParametersInvalidIPv4AddrFails) {
|
|
|
|
|
const hidl_string iface(TEST_IFACE);
|
|
|
|
|
const hidl_string v4Gw("192.0.2.1");
|
|
|
|
|
const vector<hidl_string> v6Gws{hidl_string("fe80::db8:1")};
|
|
|
|
|
@@ -540,7 +334,7 @@ TEST_P(OffloadControlHidlTest, SetUpstreamParametersInvalidIPv4AddrFails) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test that setUpstreamParameters() fails when given unparseable IPv4 gateways.
|
|
|
|
|
TEST_P(OffloadControlHidlTest, SetUpstreamParametersInvalidIPv4GatewayFails) {
|
|
|
|
|
TEST_P(OffloadControlTestV1_0_HalStarted, SetUpstreamParametersInvalidIPv4GatewayFails) {
|
|
|
|
|
const hidl_string iface(TEST_IFACE);
|
|
|
|
|
const hidl_string v4Addr("192.0.2.2");
|
|
|
|
|
const vector<hidl_string> v6Gws{hidl_string("fe80::db8:1")};
|
|
|
|
|
@@ -554,7 +348,7 @@ TEST_P(OffloadControlHidlTest, SetUpstreamParametersInvalidIPv4GatewayFails) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test that setUpstreamParameters() fails when given unparseable IPv6 gateways.
|
|
|
|
|
TEST_P(OffloadControlHidlTest, SetUpstreamParametersBadIPv6GatewaysFail) {
|
|
|
|
|
TEST_P(OffloadControlTestV1_0_HalStarted, SetUpstreamParametersBadIPv6GatewaysFail) {
|
|
|
|
|
const hidl_string iface(TEST_IFACE);
|
|
|
|
|
const hidl_string v4Addr("192.0.2.2");
|
|
|
|
|
const hidl_string v4Gw("192.0.2.1");
|
|
|
|
|
@@ -572,7 +366,7 @@ TEST_P(OffloadControlHidlTest, SetUpstreamParametersBadIPv6GatewaysFail) {
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// Test addDownstream() works given an IPv4 prefix.
|
|
|
|
|
TEST_P(OffloadControlHidlTest, AddDownstreamIPv4) {
|
|
|
|
|
TEST_P(OffloadControlTestV1_0_HalStarted, AddDownstreamIPv4) {
|
|
|
|
|
const hidl_string iface("dummy0");
|
|
|
|
|
const hidl_string prefix("192.0.2.0/24");
|
|
|
|
|
const Return<void> ret = control->addDownstream(iface, prefix, ASSERT_TRUE_CALLBACK);
|
|
|
|
|
@@ -580,7 +374,7 @@ TEST_P(OffloadControlHidlTest, AddDownstreamIPv4) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test addDownstream() works given an IPv6 prefix.
|
|
|
|
|
TEST_P(OffloadControlHidlTest, AddDownstreamIPv6) {
|
|
|
|
|
TEST_P(OffloadControlTestV1_0_HalStarted, AddDownstreamIPv6) {
|
|
|
|
|
const hidl_string iface("dummy0");
|
|
|
|
|
const hidl_string prefix("2001:db8::/64");
|
|
|
|
|
const Return<void> ret = control->addDownstream(iface, prefix, ASSERT_TRUE_CALLBACK);
|
|
|
|
|
@@ -588,7 +382,7 @@ TEST_P(OffloadControlHidlTest, AddDownstreamIPv6) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test addDownstream() fails given all empty parameters.
|
|
|
|
|
TEST_P(OffloadControlHidlTest, AddDownstreamEmptyFails) {
|
|
|
|
|
TEST_P(OffloadControlTestV1_0_HalStarted, AddDownstreamEmptyFails) {
|
|
|
|
|
const hidl_string iface("");
|
|
|
|
|
const hidl_string prefix("");
|
|
|
|
|
const Return<void> ret = control->addDownstream(iface, prefix, ASSERT_FALSE_CALLBACK);
|
|
|
|
|
@@ -596,7 +390,7 @@ TEST_P(OffloadControlHidlTest, AddDownstreamEmptyFails) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test addDownstream() fails given empty or non-existent interface names.
|
|
|
|
|
TEST_P(OffloadControlHidlTest, AddDownstreamInvalidIfaceFails) {
|
|
|
|
|
TEST_P(OffloadControlTestV1_0_HalStarted, AddDownstreamInvalidIfaceFails) {
|
|
|
|
|
const hidl_string prefix("192.0.2.0/24");
|
|
|
|
|
for (const auto& bogus : {"", "invalid"}) {
|
|
|
|
|
SCOPED_TRACE(StringPrintf("iface='%s'", bogus));
|
|
|
|
|
@@ -607,7 +401,7 @@ TEST_P(OffloadControlHidlTest, AddDownstreamInvalidIfaceFails) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test addDownstream() fails given unparseable prefix arguments.
|
|
|
|
|
TEST_P(OffloadControlHidlTest, AddDownstreamBogusPrefixFails) {
|
|
|
|
|
TEST_P(OffloadControlTestV1_0_HalStarted, AddDownstreamBogusPrefixFails) {
|
|
|
|
|
const hidl_string iface("dummy0");
|
|
|
|
|
for (const auto& bogus : {"", "192.0.2/24", "2001:db8/64"}) {
|
|
|
|
|
SCOPED_TRACE(StringPrintf("prefix='%s'", bogus));
|
|
|
|
|
@@ -622,7 +416,7 @@ TEST_P(OffloadControlHidlTest, AddDownstreamBogusPrefixFails) {
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// Test removeDownstream() works given an IPv4 prefix.
|
|
|
|
|
TEST_P(OffloadControlHidlTest, RemoveDownstreamIPv4) {
|
|
|
|
|
TEST_P(OffloadControlTestV1_0_HalStarted, RemoveDownstreamIPv4) {
|
|
|
|
|
const hidl_string iface("dummy0");
|
|
|
|
|
const hidl_string prefix("192.0.2.0/24");
|
|
|
|
|
// First add the downstream, otherwise removeDownstream logic can reasonably
|
|
|
|
|
@@ -634,7 +428,7 @@ TEST_P(OffloadControlHidlTest, RemoveDownstreamIPv4) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test removeDownstream() works given an IPv6 prefix.
|
|
|
|
|
TEST_P(OffloadControlHidlTest, RemoveDownstreamIPv6) {
|
|
|
|
|
TEST_P(OffloadControlTestV1_0_HalStarted, RemoveDownstreamIPv6) {
|
|
|
|
|
const hidl_string iface("dummy0");
|
|
|
|
|
const hidl_string prefix("2001:db8::/64");
|
|
|
|
|
// First add the downstream, otherwise removeDownstream logic can reasonably
|
|
|
|
|
@@ -646,7 +440,7 @@ TEST_P(OffloadControlHidlTest, RemoveDownstreamIPv6) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test removeDownstream() fails given all empty parameters.
|
|
|
|
|
TEST_P(OffloadControlHidlTest, RemoveDownstreamEmptyFails) {
|
|
|
|
|
TEST_P(OffloadControlTestV1_0_HalStarted, RemoveDownstreamEmptyFails) {
|
|
|
|
|
const hidl_string iface("");
|
|
|
|
|
const hidl_string prefix("");
|
|
|
|
|
const Return<void> ret = control->removeDownstream(iface, prefix, ASSERT_FALSE_CALLBACK);
|
|
|
|
|
@@ -654,7 +448,7 @@ TEST_P(OffloadControlHidlTest, RemoveDownstreamEmptyFails) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test removeDownstream() fails given empty or non-existent interface names.
|
|
|
|
|
TEST_P(OffloadControlHidlTest, RemoveDownstreamBogusIfaceFails) {
|
|
|
|
|
TEST_P(OffloadControlTestV1_0_HalStarted, RemoveDownstreamBogusIfaceFails) {
|
|
|
|
|
const hidl_string prefix("192.0.2.0/24");
|
|
|
|
|
for (const auto& bogus : {"", "invalid"}) {
|
|
|
|
|
SCOPED_TRACE(StringPrintf("iface='%s'", bogus));
|
|
|
|
|
@@ -665,7 +459,7 @@ TEST_P(OffloadControlHidlTest, RemoveDownstreamBogusIfaceFails) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test removeDownstream() fails given unparseable prefix arguments.
|
|
|
|
|
TEST_P(OffloadControlHidlTest, RemoveDownstreamBogusPrefixFails) {
|
|
|
|
|
TEST_P(OffloadControlTestV1_0_HalStarted, RemoveDownstreamBogusPrefixFails) {
|
|
|
|
|
const hidl_string iface("dummy0");
|
|
|
|
|
for (const auto& bogus : {"", "192.0.2/24", "2001:db8/64"}) {
|
|
|
|
|
SCOPED_TRACE(StringPrintf("prefix='%s'", bogus));
|
|
|
|
|
@@ -677,21 +471,18 @@ TEST_P(OffloadControlHidlTest, RemoveDownstreamBogusPrefixFails) {
|
|
|
|
|
|
|
|
|
|
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(OffloadControlHidlTestBase);
|
|
|
|
|
INSTANTIATE_TEST_CASE_P(
|
|
|
|
|
PerInstance, OffloadControlHidlTestBase,
|
|
|
|
|
testing::Combine(
|
|
|
|
|
testing::ValuesIn(
|
|
|
|
|
android::hardware::getAllHalInstanceNames(IOffloadConfig::descriptor)),
|
|
|
|
|
testing::ValuesIn(
|
|
|
|
|
android::hardware::getAllHalInstanceNames(IOffloadControl::descriptor))),
|
|
|
|
|
android::hardware::PrintInstanceTupleNameToString<>);
|
|
|
|
|
PerInstance, OffloadControlTestV1_0_HalNotStarted,
|
|
|
|
|
testing::Combine(testing::ValuesIn(android::hardware::getAllHalInstanceNames(
|
|
|
|
|
IOffloadConfig::descriptor)),
|
|
|
|
|
testing::ValuesIn(android::hardware::getAllHalInstanceNames(
|
|
|
|
|
IOffloadControl::descriptor))),
|
|
|
|
|
android::hardware::PrintInstanceTupleNameToString<>);
|
|
|
|
|
|
|
|
|
|
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(OffloadControlHidlTest);
|
|
|
|
|
INSTANTIATE_TEST_CASE_P(
|
|
|
|
|
PerInstance, OffloadControlHidlTest,
|
|
|
|
|
testing::Combine(
|
|
|
|
|
testing::ValuesIn(
|
|
|
|
|
android::hardware::getAllHalInstanceNames(IOffloadConfig::descriptor)),
|
|
|
|
|
testing::ValuesIn(
|
|
|
|
|
android::hardware::getAllHalInstanceNames(IOffloadControl::descriptor))),
|
|
|
|
|
android::hardware::PrintInstanceTupleNameToString<>);
|
|
|
|
|
|
|
|
|
|
PerInstance, OffloadControlTestV1_0_HalStarted,
|
|
|
|
|
testing::Combine(testing::ValuesIn(android::hardware::getAllHalInstanceNames(
|
|
|
|
|
IOffloadConfig::descriptor)),
|
|
|
|
|
testing::ValuesIn(android::hardware::getAllHalInstanceNames(
|
|
|
|
|
IOffloadControl::descriptor))),
|
|
|
|
|
android::hardware::PrintInstanceTupleNameToString<>);
|
|
|
|
|
|