Skip to content

Commit 12efdb6

Browse files
committed
aaa
1 parent 7e36b58 commit 12efdb6

File tree

5 files changed

+35
-17
lines changed

5 files changed

+35
-17
lines changed

Diff for: test/cases/test-ping.cc

+7
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ TEST_F(Ping, icmp)
5454
{
5555
struct ping_host_struct *ping_host;
5656
int count = 0;
57+
58+
if (smartdns::IsICMPAvailable() == false) {
59+
tlog(TLOG_INFO, "ICMP is not available, skip this test.");
60+
GTEST_SKIP();
61+
return;
62+
}
63+
5764
ping_host = fast_ping_start(PING_TYPE_ICMP, "127.0.0.1", 1, 1, 200, ping_result_callback, &count);
5865
ASSERT_NE(ping_host, nullptr);
5966
usleep(10000);

Diff for: test/cases/test-speed-check.cc

+7-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ domain-rules /a.com/ -r fastest-response
5555
std::cout << client.GetResult() << std::endl;
5656
ASSERT_EQ(client.GetAnswerNum(), 1);
5757
EXPECT_EQ(client.GetStatus(), "NOERROR");
58-
EXPECT_GT(client.GetQueryTime(), 100);
58+
if (smartdns::IsICMPAvailable()) {
59+
EXPECT_GT(client.GetQueryTime(), 100);
60+
}
5961
EXPECT_EQ(client.GetAnswer()[0].GetName(), "b.com");
6062
EXPECT_EQ(client.GetAnswer()[0].GetTTL(), 600);
6163

@@ -131,7 +133,10 @@ domain-rules /a.com/ -c none
131133
std::cout << client.GetResult() << std::endl;
132134
ASSERT_EQ(client.GetAnswerNum(), 1);
133135
EXPECT_EQ(client.GetStatus(), "NOERROR");
134-
EXPECT_GT(client.GetQueryTime(), 200);
136+
if (smartdns::IsICMPAvailable()) {
137+
EXPECT_GT(client.GetQueryTime(), 200);
138+
}
139+
135140
EXPECT_EQ(client.GetAnswer()[0].GetName(), "b.com");
136141
EXPECT_EQ(client.GetAnswer()[0].GetTTL(), 600);
137142

Diff for: test/include/utils.h

+2
Original file line numberDiff line numberDiff line change
@@ -109,5 +109,7 @@ int ParserArg(const std::string &cmd, std::vector<std::string> &args);
109109

110110
std::vector<std::string> GetAvailableIPAddresses();
111111

112+
bool IsICMPAvailable();
113+
112114
} // namespace smartdns
113115
#endif // _SMARTDNS_TEST_UTILS_

Diff for: test/server.cc

-15
Original file line numberDiff line numberDiff line change
@@ -325,21 +325,6 @@ void Server::StartPost(void *arg)
325325
fast_ping_fake_ip_add(it.type, it.host.c_str(), it.ttl, it.time);
326326
}
327327

328-
int fd = -1;
329-
if (has_unprivileged_ping()) {
330-
fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_ICMP);
331-
} else {
332-
fd = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP);
333-
}
334-
335-
if (fd > 0) {
336-
close(fd);
337-
} else {
338-
fast_ping_fake_ip_add(PING_TYPE_ICMP, "127.0.0.1", 64, 10);
339-
fast_ping_fake_ip_add(PING_TYPE_TCP, "127.0.0.1:80", 64, 10);
340-
fast_ping_fake_ip_add(PING_TYPE_TCP, "127.0.0.1:443", 64, 10);
341-
}
342-
343328
tlog(TLOG_ERROR, "add mock ping %d\n", has_ipv6);
344329
if (has_ipv6 == true) {
345330
fast_ping_fake_ip_add(PING_TYPE_ICMP, "2001::", 64, 10);

Diff for: test/utils.cc

+19
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "include/utils.h"
2+
#include "util.h"
23
#include <arpa/inet.h>
34
#include <ifaddrs.h>
45
#include <netinet/in.h>
@@ -305,4 +306,22 @@ std::vector<std::string> GetAvailableIPAddresses()
305306
return ipAddresses;
306307
}
307308

309+
bool IsICMPAvailable()
310+
{
311+
int fd = -1;
312+
if (has_unprivileged_ping()) {
313+
fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_ICMP);
314+
} else {
315+
fd = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP);
316+
}
317+
318+
if (fd < 0) {
319+
return false;
320+
}
321+
322+
close(fd);
323+
324+
return true;
325+
}
326+
308327
} // namespace smartdns

0 commit comments

Comments
 (0)