summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTyler Wear2017-07-19 15:48:57 -0500
committerErik Kline2017-08-07 12:54:06 -0500
commit36678525469e9c92f5f1d603c57ab55845bc2b31 (patch)
tree9dd5c86d8642cbfadb7c0393bf6122bbcd209586 /tetheroffload/config
parent781ce91bcdf825ea5eb282adf095814f5898adcd (diff)
downloadplatform-hardware-interfaces-36678525469e9c92f5f1d603c57ab55845bc2b31.tar.gz
platform-hardware-interfaces-36678525469e9c92f5f1d603c57ab55845bc2b31.tar.xz
platform-hardware-interfaces-36678525469e9c92f5f1d603c57ab55845bc2b31.zip
Tetheroffload Control and Config VTS
Basic VTS for Tetheroffload Config and Control HALs. Bug: 38220415 Change-Id: I6d0867e019aca58d8a6bd1404b8b85ed98274f11 CRs-fixed: 2083182
Diffstat (limited to 'tetheroffload/config')
-rw-r--r--tetheroffload/config/1.0/vts/functional/Android.bp18
-rw-r--r--tetheroffload/config/1.0/vts/functional/VtsHalTetheroffloadConfigV1_0TargetTest.cpp186
2 files changed, 204 insertions, 0 deletions
diff --git a/tetheroffload/config/1.0/vts/functional/Android.bp b/tetheroffload/config/1.0/vts/functional/Android.bp
new file mode 100644
index 00000000..ba6d809a
--- /dev/null
+++ b/tetheroffload/config/1.0/vts/functional/Android.bp
@@ -0,0 +1,18 @@
1cc_test {
2 name: "VtsHalTetheroffloadConfigV1_0TargetTest",
3 defaults: ["hidl_defaults"],
4 srcs: ["VtsHalTetheroffloadConfigV1_0TargetTest.cpp"],
5 shared_libs: [
6 "android.hardware.tetheroffload.config@1.0",
7 "libcutils",
8 "libhidlbase",
9 "libhidltransport",
10 "liblog",
11 "libutils",
12 ],
13 static_libs: ["VtsHalHidlTargetTestBase"],
14 cflags: [
15 "-O0",
16 "-g",
17 ],
18}
diff --git a/tetheroffload/config/1.0/vts/functional/VtsHalTetheroffloadConfigV1_0TargetTest.cpp b/tetheroffload/config/1.0/vts/functional/VtsHalTetheroffloadConfigV1_0TargetTest.cpp
new file mode 100644
index 00000000..b0ded4f5
--- /dev/null
+++ b/tetheroffload/config/1.0/vts/functional/VtsHalTetheroffloadConfigV1_0TargetTest.cpp
@@ -0,0 +1,186 @@
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#define LOG_TAG "VtsOffloadConfigV1_0TargetTest"
17
18#include <android-base/unique_fd.h>
19#include <android/hardware/tetheroffload/config/1.0/IOffloadConfig.h>
20#include <linux/netfilter/nfnetlink.h>
21#include <linux/netlink.h>
22#include <log/log.h>
23#include <set>
24#include <sys/socket.h>
25#include <unistd.h>
26#include <VtsHalHidlTargetTestBase.h>
27
28using android::hardware::hidl_handle;
29using android::hardware::hidl_string;
30using android::hardware::Return;
31using android::hardware::tetheroffload::config::V1_0::IOffloadConfig;
32using android::hardware::Void;
33using android::sp;
34
35inline const sockaddr * asSockaddr(const sockaddr_nl *nladdr) {
36 return reinterpret_cast<const sockaddr *>(nladdr);
37}
38
39int conntrackSocket(unsigned groups) {
40 android::base::unique_fd s(socket(AF_NETLINK, SOCK_DGRAM, NETLINK_NETFILTER));
41 if (s.get() < 0) {
42 return -errno;
43 }
44
45 const struct sockaddr_nl bind_addr = {
46 .nl_family = AF_NETLINK,
47 .nl_pad = 0,
48 .nl_pid = 0,
49 .nl_groups = groups,
50 };
51 if (::bind(s.get(), asSockaddr(&bind_addr), sizeof(bind_addr)) != 0) {
52 return -errno;
53 }
54
55 const struct sockaddr_nl kernel_addr = {
56 .nl_family = AF_NETLINK,
57 .nl_pad = 0,
58 .nl_pid = 0,
59 .nl_groups = groups,
60 };
61 if (connect(s.get(), asSockaddr(&kernel_addr), sizeof(kernel_addr)) != 0) {
62 return -errno;
63 }
64
65 return s.release();
66}
67
68class OffloadConfigHidlTest : public testing::VtsHalHidlTargetTestBase {
69public:
70 virtual void SetUp() override {
71 config = testing::VtsHalHidlTargetTestBase::getService<IOffloadConfig>();
72 ASSERT_NE(nullptr, config.get()) << "Could not get HIDL instance";
73 }
74
75 virtual void TearDown() override {}
76
77 sp<IOffloadConfig> config;
78};
79
80/**
81 * Ensure handles can be set with correct socket options.
82 */
83TEST_F(OffloadConfigHidlTest, TestSetHandles) {
84 android::base::unique_fd
85 fd1(conntrackSocket(NFNLGRP_CONNTRACK_NEW | NFNLGRP_CONNTRACK_DESTROY)),
86 fd2(conntrackSocket(NFNLGRP_CONNTRACK_UPDATE | NFNLGRP_CONNTRACK_DESTROY));
87
88 if (fd1.get() < 0 || fd2.get() < 0) {
89 ALOGE("Unable to create conntrack handles: %d/%s", errno, strerror(errno));
90 return;
91 }
92
93 native_handle_t* nativeHandle1 = native_handle_create(1, 0);
94 nativeHandle1->data[0] = fd1;
95 hidl_handle h1 = hidl_handle(nativeHandle1);
96
97 native_handle_t* nativeHandle2 = native_handle_create(1, 0);
98 nativeHandle2->data[0] = fd2;
99 hidl_handle h2 = hidl_handle(nativeHandle2);
100
101 if(h1->numFds == 1 && h2->numFds == 1) {
102 ALOGE("Num FDs for both is 1");
103 } else {
104 ALOGE("num FDs not 1: %d %d", h1->numFds, h2->numFds);
105 }
106
107 auto cb = [&](bool success, const hidl_string& errMsg) {
108 ASSERT_TRUE(success) << errMsg.c_str();
109 };
110
111 Return<void> ret = config->setHandles(h1, h2, cb);
112 ASSERT_TRUE(ret.isOk());
113}
114
115/**
116 * Negative testcase
117 * Passing a handle without an associated FD should return an
118 * error (Failed Input Checks). Check that this occurs when
119 * neither handle has an associated FD.
120 */
121TEST_F(OffloadConfigHidlTest, TestSetHandleNone) {
122 native_handle_t* nativeHandle1 = native_handle_create(0, 0);
123 hidl_handle h1 = hidl_handle(nativeHandle1);
124 native_handle_t* nativeHandle2 = native_handle_create(0, 0);
125 hidl_handle h2 = hidl_handle(nativeHandle2);
126
127 auto cb = [&](bool success, const hidl_string& errMsg) {
128 ASSERT_FALSE(success) << errMsg.c_str();
129 };
130
131 Return<void> ret = config->setHandles(h1, h2, cb);
132 ASSERT_TRUE(ret.isOk());
133}
134
135/**
136 * Negative testcase
137 * Passing a handle without an associated FD should return an
138 * error (Failed Input Checks). Check that this occurs with FD2.
139 */
140TEST_F(OffloadConfigHidlTest, TestSetHandle1Only) {
141 android::base::unique_fd
142 fd1(conntrackSocket(NFNLGRP_CONNTRACK_NEW | NFNLGRP_CONNTRACK_DESTROY));
143
144 native_handle_t* nativeHandle1 = native_handle_create(1, 0);
145 nativeHandle1->data[0] = fd1;
146 hidl_handle h1 = hidl_handle(nativeHandle1);
147 native_handle_t* nativeHandle2 = native_handle_create(0, 0);
148 hidl_handle h2 = hidl_handle(nativeHandle2);
149
150 auto cb = [&](bool success, const hidl_string& errMsg) {
151 ASSERT_FALSE(success) << errMsg.c_str();
152 };
153
154 Return<void> ret = config->setHandles(h1, h2, cb);
155 ASSERT_TRUE(ret.isOk());
156}
157
158/**
159 * Negative testcase
160 * Passing a handle without an associated FD should return an
161 * error (Failed Input Checks). Check that this occurs with FD1.
162 */
163TEST_F(OffloadConfigHidlTest, TestSetHandle2OnlyNotOk) {
164 android::base::unique_fd
165 fd2(conntrackSocket(NFNLGRP_CONNTRACK_UPDATE | NFNLGRP_CONNTRACK_DESTROY));
166
167 native_handle_t* nativeHandle1 = native_handle_create(0, 0);
168 hidl_handle h1 = hidl_handle(nativeHandle1);
169 native_handle_t* nativeHandle2 = native_handle_create(1, 0);
170 nativeHandle2->data[0] = fd2;
171 hidl_handle h2 = hidl_handle(nativeHandle2);
172
173 auto cb = [&](bool success, const hidl_string& errMsg) {
174 ASSERT_FALSE(success) << errMsg.c_str();
175 };
176
177 Return<void> ret = config->setHandles(h1, h2, cb);
178 ASSERT_TRUE(ret.isOk());
179}
180
181int main(int argc, char** argv) {
182 testing::InitGoogleTest(&argc, argv);
183 int status = RUN_ALL_TESTS();
184 ALOGE("Test result with status=%d", status);
185 return status;
186}