Merge "Refactor and expand tetheroffload Control and Config VTS" into oc-dr1-dev

am: 6d5cf73b75

Change-Id: I004e81a764313fdaf23f9580b144e1ee2ba79b27
This commit is contained in:
Erik Kline
2017-08-08 04:04:48 +00:00
committed by android-build-merger
4 changed files with 540 additions and 778 deletions

View File

@@ -1,9 +1,24 @@
// Copyright (C) 2017 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
cc_test { cc_test {
name: "VtsHalTetheroffloadConfigV1_0TargetTest", name: "VtsHalTetheroffloadConfigV1_0TargetTest",
defaults: ["hidl_defaults"], defaults: ["hidl_defaults"],
srcs: ["VtsHalTetheroffloadConfigV1_0TargetTest.cpp"], srcs: ["VtsHalTetheroffloadConfigV1_0TargetTest.cpp"],
shared_libs: [ shared_libs: [
"android.hardware.tetheroffload.config@1.0", "android.hardware.tetheroffload.config@1.0",
"libbase",
"libcutils", "libcutils",
"libhidlbase", "libhidlbase",
"libhidltransport", "libhidltransport",

View File

@@ -13,18 +13,23 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#define LOG_TAG "VtsOffloadConfigV1_0TargetTest" #define LOG_TAG "VtsOffloadConfigV1_0TargetTest"
#include <VtsHalHidlTargetTestBase.h>
#include <android-base/stringprintf.h>
#include <android-base/unique_fd.h> #include <android-base/unique_fd.h>
#include <android/hardware/tetheroffload/config/1.0/IOffloadConfig.h> #include <android/hardware/tetheroffload/config/1.0/IOffloadConfig.h>
#include <linux/netfilter/nfnetlink.h> #include <linux/netfilter/nfnetlink.h>
#include <linux/netlink.h> #include <linux/netlink.h>
#include <linux/rtnetlink.h>
#include <log/log.h> #include <log/log.h>
#include <set>
#include <sys/socket.h> #include <sys/socket.h>
#include <unistd.h> #include <unistd.h>
#include <VtsHalHidlTargetTestBase.h> #include <set>
using android::base::StringPrintf;
using android::base::unique_fd;
using android::hardware::hidl_handle; using android::hardware::hidl_handle;
using android::hardware::hidl_string; using android::hardware::hidl_string;
using android::hardware::Return; using android::hardware::Return;
@@ -32,41 +37,48 @@ using android::hardware::tetheroffload::config::V1_0::IOffloadConfig;
using android::hardware::Void; using android::hardware::Void;
using android::sp; using android::sp;
inline const sockaddr * asSockaddr(const sockaddr_nl *nladdr) { #define ASSERT_TRUE_CALLBACK \
return reinterpret_cast<const sockaddr *>(nladdr); [&](bool success, const hidl_string& errMsg) { ASSERT_TRUE(success) << errMsg.c_str(); }
#define ASSERT_FALSE_CALLBACK \
[&](bool success, const hidl_string& errMsg) { ASSERT_FALSE(success) << errMsg.c_str(); }
const unsigned kFd1Groups = NFNLGRP_CONNTRACK_NEW | NFNLGRP_CONNTRACK_DESTROY;
const unsigned kFd2Groups = NFNLGRP_CONNTRACK_UPDATE | NFNLGRP_CONNTRACK_DESTROY;
inline const sockaddr* asSockaddr(const sockaddr_nl* nladdr) {
return reinterpret_cast<const sockaddr*>(nladdr);
} }
int conntrackSocket(unsigned groups) { int netlinkSocket(int protocol, unsigned groups) {
android::base::unique_fd s(socket(AF_NETLINK, SOCK_DGRAM, NETLINK_NETFILTER)); unique_fd s(socket(AF_NETLINK, SOCK_DGRAM, protocol));
if (s.get() < 0) { if (s.get() < 0) {
return -errno; return -errno;
} }
const struct sockaddr_nl bind_addr = { const struct sockaddr_nl bind_addr = {
.nl_family = AF_NETLINK, .nl_family = AF_NETLINK, .nl_pad = 0, .nl_pid = 0, .nl_groups = groups,
.nl_pad = 0,
.nl_pid = 0,
.nl_groups = groups,
}; };
if (::bind(s.get(), asSockaddr(&bind_addr), sizeof(bind_addr)) != 0) { if (::bind(s.get(), asSockaddr(&bind_addr), sizeof(bind_addr)) != 0) {
return -errno; return -errno;
} }
const struct sockaddr_nl kernel_addr = { const struct sockaddr_nl kernel_addr = {
.nl_family = AF_NETLINK, .nl_family = AF_NETLINK, .nl_pad = 0, .nl_pid = 0, .nl_groups = groups,
.nl_pad = 0,
.nl_pid = 0,
.nl_groups = groups,
}; };
if (connect(s.get(), asSockaddr(&kernel_addr), sizeof(kernel_addr)) != 0) { if (::connect(s.get(), asSockaddr(&kernel_addr), sizeof(kernel_addr)) != 0) {
return -errno; return -errno;
} }
return s.release(); return s.release();
} }
int netlinkSocket(unsigned groups) {
return netlinkSocket(NETLINK_NETFILTER, groups);
}
class OffloadConfigHidlTest : public testing::VtsHalHidlTargetTestBase { class OffloadConfigHidlTest : public testing::VtsHalHidlTargetTestBase {
public: public:
virtual void SetUp() override { virtual void SetUp() override {
config = testing::VtsHalHidlTargetTestBase::getService<IOffloadConfig>(); config = testing::VtsHalHidlTargetTestBase::getService<IOffloadConfig>();
ASSERT_NE(nullptr, config.get()) << "Could not get HIDL instance"; ASSERT_NE(nullptr, config.get()) << "Could not get HIDL instance";
@@ -77,104 +89,77 @@ public:
sp<IOffloadConfig> config; sp<IOffloadConfig> config;
}; };
/** // Ensure handles can be set with correct socket options.
* Ensure handles can be set with correct socket options.
*/
TEST_F(OffloadConfigHidlTest, TestSetHandles) { TEST_F(OffloadConfigHidlTest, TestSetHandles) {
android::base::unique_fd unique_fd fd1(netlinkSocket(kFd1Groups));
fd1(conntrackSocket(NFNLGRP_CONNTRACK_NEW | NFNLGRP_CONNTRACK_DESTROY)), if (fd1.get() < 0) {
fd2(conntrackSocket(NFNLGRP_CONNTRACK_UPDATE | NFNLGRP_CONNTRACK_DESTROY));
if (fd1.get() < 0 || fd2.get() < 0) {
ALOGE("Unable to create conntrack handles: %d/%s", errno, strerror(errno)); ALOGE("Unable to create conntrack handles: %d/%s", errno, strerror(errno));
return; FAIL();
} }
native_handle_t* const nativeHandle1 = native_handle_create(1, 0);
nativeHandle1->data[0] = fd1.release();
const hidl_handle h1 = hidl_handle(nativeHandle1);
native_handle_t* nativeHandle1 = native_handle_create(1, 0); unique_fd fd2(netlinkSocket(kFd2Groups));
nativeHandle1->data[0] = fd1; if (fd2.get() < 0) {
hidl_handle h1 = hidl_handle(nativeHandle1); ALOGE("Unable to create conntrack handles: %d/%s", errno, strerror(errno));
FAIL();
native_handle_t* nativeHandle2 = native_handle_create(1, 0);
nativeHandle2->data[0] = fd2;
hidl_handle h2 = hidl_handle(nativeHandle2);
if(h1->numFds == 1 && h2->numFds == 1) {
ALOGE("Num FDs for both is 1");
} else {
ALOGE("num FDs not 1: %d %d", h1->numFds, h2->numFds);
} }
native_handle_t* const nativeHandle2 = native_handle_create(1, 0);
nativeHandle2->data[0] = fd2.release();
const hidl_handle h2 = hidl_handle(nativeHandle2);
auto cb = [&](bool success, const hidl_string& errMsg) { const Return<void> ret = config->setHandles(h1, h2, ASSERT_TRUE_CALLBACK);
ASSERT_TRUE(success) << errMsg.c_str();
};
Return<void> ret = config->setHandles(h1, h2, cb);
ASSERT_TRUE(ret.isOk()); ASSERT_TRUE(ret.isOk());
} }
/** // Passing a handle without an associated file descriptor should return an error
* Negative testcase // (e.g. "Failed Input Checks"). Check that this occurs when both FDs are empty.
* Passing a handle without an associated FD should return an
* error (Failed Input Checks). Check that this occurs when
* neither handle has an associated FD.
*/
TEST_F(OffloadConfigHidlTest, TestSetHandleNone) { TEST_F(OffloadConfigHidlTest, TestSetHandleNone) {
native_handle_t* nativeHandle1 = native_handle_create(0, 0); native_handle_t* const nativeHandle1 = native_handle_create(0, 0);
hidl_handle h1 = hidl_handle(nativeHandle1); const hidl_handle h1 = hidl_handle(nativeHandle1);
native_handle_t* nativeHandle2 = native_handle_create(0, 0); native_handle_t* const nativeHandle2 = native_handle_create(0, 0);
hidl_handle h2 = hidl_handle(nativeHandle2); const hidl_handle h2 = hidl_handle(nativeHandle2);
auto cb = [&](bool success, const hidl_string& errMsg) { const Return<void> ret = config->setHandles(h1, h2, ASSERT_FALSE_CALLBACK);
ASSERT_FALSE(success) << errMsg.c_str();
};
Return<void> ret = config->setHandles(h1, h2, cb);
ASSERT_TRUE(ret.isOk()); ASSERT_TRUE(ret.isOk());
} }
/** // Passing a handle without an associated file descriptor should return an error
* Negative testcase // (e.g. "Failed Input Checks"). Check that this occurs when FD2 is empty.
* Passing a handle without an associated FD should return an
* error (Failed Input Checks). Check that this occurs with FD2.
*/
TEST_F(OffloadConfigHidlTest, TestSetHandle1Only) { TEST_F(OffloadConfigHidlTest, TestSetHandle1Only) {
android::base::unique_fd unique_fd fd1(netlinkSocket(kFd1Groups));
fd1(conntrackSocket(NFNLGRP_CONNTRACK_NEW | NFNLGRP_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();
const hidl_handle h1 = hidl_handle(nativeHandle1);
native_handle_t* nativeHandle1 = native_handle_create(1, 0); native_handle_t* const nativeHandle2 = native_handle_create(0, 0);
nativeHandle1->data[0] = fd1; const hidl_handle h2 = hidl_handle(nativeHandle2);
hidl_handle h1 = hidl_handle(nativeHandle1);
native_handle_t* nativeHandle2 = native_handle_create(0, 0);
hidl_handle h2 = hidl_handle(nativeHandle2);
auto cb = [&](bool success, const hidl_string& errMsg) { const Return<void> ret = config->setHandles(h1, h2, ASSERT_FALSE_CALLBACK);
ASSERT_FALSE(success) << errMsg.c_str();
};
Return<void> ret = config->setHandles(h1, h2, cb);
ASSERT_TRUE(ret.isOk()); ASSERT_TRUE(ret.isOk());
} }
/** // Passing a handle without an associated file descriptor should return an error
* Negative testcase // (e.g. "Failed Input Checks"). Check that this occurs when FD1 is empty.
* Passing a handle without an associated FD should return an
* error (Failed Input Checks). Check that this occurs with FD1.
*/
TEST_F(OffloadConfigHidlTest, TestSetHandle2OnlyNotOk) { TEST_F(OffloadConfigHidlTest, TestSetHandle2OnlyNotOk) {
android::base::unique_fd native_handle_t* const nativeHandle1 = native_handle_create(0, 0);
fd2(conntrackSocket(NFNLGRP_CONNTRACK_UPDATE | NFNLGRP_CONNTRACK_DESTROY)); const hidl_handle h1 = hidl_handle(nativeHandle1);
native_handle_t* nativeHandle1 = native_handle_create(0, 0); unique_fd fd2(netlinkSocket(kFd2Groups));
hidl_handle h1 = hidl_handle(nativeHandle1); if (fd2.get() < 0) {
native_handle_t* nativeHandle2 = native_handle_create(1, 0); ALOGE("Unable to create conntrack handles: %d/%s", errno, strerror(errno));
nativeHandle2->data[0] = fd2; FAIL();
hidl_handle h2 = hidl_handle(nativeHandle2); }
native_handle_t* const nativeHandle2 = native_handle_create(1, 0);
nativeHandle2->data[0] = fd2.release();
const hidl_handle h2 = hidl_handle(nativeHandle2);
auto cb = [&](bool success, const hidl_string& errMsg) { const Return<void> ret = config->setHandles(h1, h2, ASSERT_FALSE_CALLBACK);
ASSERT_FALSE(success) << errMsg.c_str();
};
Return<void> ret = config->setHandles(h1, h2, cb);
ASSERT_TRUE(ret.isOk()); ASSERT_TRUE(ret.isOk());
} }

View File

@@ -1,3 +1,17 @@
// Copyright (C) 2017 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
cc_test { cc_test {
name: "VtsHalTetheroffloadControlV1_0TargetTest", name: "VtsHalTetheroffloadControlV1_0TargetTest",
defaults: ["hidl_defaults"], defaults: ["hidl_defaults"],
@@ -5,6 +19,7 @@ cc_test {
shared_libs: [ shared_libs: [
"android.hardware.tetheroffload.config@1.0", "android.hardware.tetheroffload.config@1.0",
"android.hardware.tetheroffload.control@1.0", "android.hardware.tetheroffload.control@1.0",
"libbase",
"libcutils", "libcutils",
"libhidlbase", "libhidlbase",
"libhidltransport", "libhidltransport",