• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Aucun tag

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

system/hardware/interfaces


Commit MetaInfo

Révision065b170e649d593105b3d84c77f95d044372a8c4 (tree)
l'heure2018-03-13 13:02:59
AuteurLorenzo Colitti <lorenzo@goog...>
Commiterandroid-build-merger

Message de Log

Make the VTS tests for the INetd HAL 1.0 more realistic.
am: 79f693702c

Change-Id: Id951ad6982142a423ffb881979d0ad9e660b4afe

Change Summary

Modification

--- a/net/netd/1.0/vts/functional/Android.bp
+++ b/net/netd/1.0/vts/functional/Android.bp
@@ -1,19 +1,37 @@
1+//
2+// Copyright (C) 2018 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+
116 cc_test {
217 name: "VtsHalNetNetdV1_0TargetTest",
318 srcs: [
419 "VtsHalNetNetdV1_0TargetTest.cpp",
520 ],
621 shared_libs: [
7- "liblog",
22+ "android.system.net.netd@1.0",
23+ "libandroid_net",
24+ "libbase",
825 "libhidlbase",
9- "libhidltransport",
26+ "liblog",
1027 "libutils",
11- "android.system.net.netd@1.0",
1228 ],
13- static_libs: ["VtsHalHidlTargetTestBase"],
29+ static_libs: [
30+ "VtsHalHidlTargetTestBase",
31+ "VtsHalNetNetdTestUtils",
32+ ],
1433 cflags: [
15- "-O0",
16- "-g",
34+ "-Og",
1735 "-Wall",
1836 "-Werror",
1937 ],
--- a/net/netd/1.0/vts/functional/VtsHalNetNetdV1_0TargetTest.cpp
+++ b/net/netd/1.0/vts/functional/VtsHalNetNetdV1_0TargetTest.cpp
@@ -20,15 +20,33 @@
2020 #include <android/system/net/netd/1.0/INetd.h>
2121 #include <log/log.h>
2222
23+#include "VtsHalNetNetdTestUtils.h"
24+
2325 using ::android::system::net::netd::V1_0::INetd;
2426 using ::android::hardware::Return;
2527 using ::android::sp;
2628
29+// Test environment for Netd HIDL HAL.
30+class NetdHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
31+ public:
32+ // get the test environment singleton
33+ static NetdHidlEnvironment* Instance() {
34+ static NetdHidlEnvironment* instance = new NetdHidlEnvironment;
35+ return instance;
36+ }
37+
38+ virtual void registerTestServices() override { registerTestService<INetd>(); }
39+
40+ private:
41+ NetdHidlEnvironment() {}
42+};
43+
2744 class NetdHidlTest : public ::testing::VtsHalHidlTargetTestBase {
2845 public:
2946 virtual void SetUp() override {
30- netd = ::testing::VtsHalHidlTargetTestBase::getService<INetd>();
31- ASSERT_NE(nullptr, netd.get()) << "Could not get HIDL instance";
47+ netd = ::testing::VtsHalHidlTargetTestBase::getService<INetd>(
48+ NetdHidlEnvironment::Instance()->getServiceName<INetd>());
49+ ASSERT_NE(netd, nullptr) << "Could not get HIDL instance";
3250 }
3351
3452 sp<INetd> netd;
@@ -36,17 +54,28 @@ class NetdHidlTest : public ::testing::VtsHalHidlTargetTestBase {
3654
3755 // positive test. Ensure netd creates an oem network and returns valid netHandle, and destroys it.
3856 TEST_F(NetdHidlTest, TestCreateAndDestroyOemNetworkOk) {
39- auto cb = [this](uint64_t netHandle, uint32_t packetMark, INetd::StatusCode status) {
40- ASSERT_EQ(INetd::StatusCode::OK, status);
41- ASSERT_NE((uint64_t)0, netHandle);
42- ASSERT_NE((uint32_t)0, packetMark);
57+ net_handle_t netHandle;
58+ uint32_t packetMark;
59+ INetd::StatusCode status;
4360
44- Return<INetd::StatusCode> retStatus = netd->destroyOemNetwork(netHandle);
45- ASSERT_EQ(INetd::StatusCode::OK, retStatus);
46- };
61+ Return<void> ret = netd->createOemNetwork([&](net_handle_t n, uint32_t p, INetd::StatusCode s) {
62+ status = s;
63+ netHandle = n;
64+ packetMark = p;
65+ });
4766
48- Return<void> ret = netd->createOemNetwork(cb);
4967 ASSERT_TRUE(ret.isOk());
68+ ASSERT_EQ(INetd::StatusCode::OK, status);
69+ ASSERT_NE(NETWORK_UNSPECIFIED, netHandle);
70+ ASSERT_NE((uint32_t)0, packetMark);
71+
72+ ASSERT_EQ(0, checkNetworkExists(netHandle));
73+ ASSERT_EQ(0, countRulesForFwmark(packetMark));
74+
75+ Return<INetd::StatusCode> retStatus = netd->destroyOemNetwork(netHandle);
76+ ASSERT_EQ(INetd::StatusCode::OK, retStatus);
77+
78+ ASSERT_EQ(-ENONET, checkNetworkExists(netHandle));
5079 }
5180
5281 // negative test. Ensure destroy for invalid OEM network fails appropriately
@@ -58,7 +87,9 @@ TEST_F(NetdHidlTest, TestDestroyOemNetworkInvalid) {
5887 }
5988
6089 int main(int argc, char** argv) {
90+ ::testing::AddGlobalTestEnvironment(NetdHidlEnvironment::Instance());
6191 ::testing::InitGoogleTest(&argc, argv);
92+ NetdHidlEnvironment::Instance()->init(&argc, argv);
6293 int status = RUN_ALL_TESTS();
6394 ALOGE("Test result with status=%d", status);
6495 return status;
--- /dev/null
+++ b/net/netd/testutils/Android.bp
@@ -0,0 +1,31 @@
1+//
2+// Copyright (C) 2018 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+cc_library {
17+ name: "VtsHalNetNetdTestUtils",
18+ srcs: [
19+ "VtsHalNetNetdTestUtils.cpp",
20+ ],
21+ export_include_dirs: ["."],
22+ shared_libs: [
23+ "libbase",
24+ "libandroid_net",
25+ ],
26+ cflags: [
27+ "-Og",
28+ "-Wall",
29+ "-Werror",
30+ ],
31+}
--- /dev/null
+++ b/net/netd/testutils/VtsHalNetNetdTestUtils.cpp
@@ -0,0 +1,92 @@
1+/*
2+ * Copyright 2018 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 <regex>
18+#include <string>
19+#include <vector>
20+
21+#include <errno.h>
22+#include <sys/socket.h>
23+#include <sys/types.h>
24+#include <unistd.h>
25+
26+#include <android-base/stringprintf.h>
27+#include <android/multinetwork.h>
28+
29+#include "VtsHalNetNetdTestUtils.h"
30+
31+using android::base::StringPrintf;
32+
33+int checkNetworkExists(net_handle_t netHandle) {
34+ int sock = socket(AF_INET6, SOCK_STREAM, 0);
35+ if (sock == -1) {
36+ return -ENOTSOCK;
37+ }
38+ int ret = android_setsocknetwork(netHandle, sock);
39+ if (ret) {
40+ ret = -errno;
41+ }
42+ close(sock);
43+ return ret;
44+}
45+
46+// TODO: deduplicate this with system/netd/server/binder_test.cpp.
47+static std::vector<std::string> runCommand(const std::string& command) {
48+ std::vector<std::string> lines;
49+ FILE* f;
50+
51+ if ((f = popen(command.c_str(), "r")) == nullptr) {
52+ perror("popen");
53+ return lines;
54+ }
55+
56+ char* line = nullptr;
57+ size_t bufsize = 0;
58+ ssize_t linelen = 0;
59+ while ((linelen = getline(&line, &bufsize, f)) >= 0) {
60+ lines.push_back(std::string(line, linelen));
61+ }
62+
63+ free(line);
64+ pclose(f);
65+ return lines;
66+}
67+
68+static std::vector<std::string> listIpRules(const char* ipVersion) {
69+ std::string command = StringPrintf("%s %s rule list", IP_PATH, ipVersion);
70+ return runCommand(command);
71+}
72+
73+static int countMatchingIpRules(const std::string& regexString) {
74+ const std::regex regex(regexString, std::regex_constants::extended);
75+ int matches = 0;
76+
77+ for (const char* version : {"-4", "-6"}) {
78+ std::vector<std::string> rules = listIpRules(version);
79+ for (const auto& rule : rules) {
80+ if (std::regex_search(rule, regex)) {
81+ matches++;
82+ }
83+ }
84+ }
85+
86+ return matches;
87+}
88+
89+int countRulesForFwmark(const uint32_t fwmark) {
90+ std::string regex = StringPrintf("from all fwmark 0x%x/.* lookup ", fwmark);
91+ return countMatchingIpRules(regex);
92+}
--- /dev/null
+++ b/net/netd/testutils/VtsHalNetNetdTestUtils.h
@@ -0,0 +1,31 @@
1+/*
2+ * Copyright 2018 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+#ifndef VTS_HAL_NET_NETD_TEST_UTILS_H
18+#define VTS_HAL_NET_NETD_TEST_UTILS_H
19+
20+#include <android/multinetwork.h>
21+
22+#define IP_PATH "/system/bin/ip"
23+
24+// Checks that the given network exists.
25+// Returns 0 if it exists or -errno if it does not.
26+int checkNetworkExists(net_handle_t netHandle);
27+
28+// Counts the number of IPv4 and IPv6 routing rules that select the specified fwmark.
29+int countRulesForFwmark(const uint32_t fwmark);
30+
31+#endif