|
|
|
@ -29,7 +29,7 @@ |
|
|
|
|
|
|
|
|
|
#include "ares_setup.h" |
|
|
|
|
#ifdef HAVE_CONFIG_H |
|
|
|
|
#include "ares_config.h" |
|
|
|
|
# include "ares_config.h" |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
#include "dns-proto.h" |
|
|
|
@ -70,9 +70,12 @@ extern const std::vector<std::pair<int, bool>> both_families_both_modes; |
|
|
|
|
extern const std::vector<std::pair<int, bool>> ipv4_family_both_modes; |
|
|
|
|
extern const std::vector<std::pair<int, bool>> ipv6_family_both_modes; |
|
|
|
|
|
|
|
|
|
extern const std::vector<std::tuple<ares_evsys_t, int, bool>> all_evsys_ipv4_family_both_modes; |
|
|
|
|
extern const std::vector<std::tuple<ares_evsys_t, int, bool>> all_evsys_ipv6_family_both_modes; |
|
|
|
|
extern const std::vector<std::tuple<ares_evsys_t, int, bool>> all_evsys_both_families_both_modes; |
|
|
|
|
extern const std::vector<std::tuple<ares_evsys_t, int, bool>> |
|
|
|
|
all_evsys_ipv4_family_both_modes; |
|
|
|
|
extern const std::vector<std::tuple<ares_evsys_t, int, bool>> |
|
|
|
|
all_evsys_ipv6_family_both_modes; |
|
|
|
|
extern const std::vector<std::tuple<ares_evsys_t, int, bool>> |
|
|
|
|
all_evsys_both_families_both_modes; |
|
|
|
|
|
|
|
|
|
extern const std::vector<std::tuple<ares_evsys_t, int>> all_evsys_ipv4_family; |
|
|
|
|
extern const std::vector<std::tuple<ares_evsys_t, int>> all_evsys_ipv6_family; |
|
|
|
@ -93,13 +96,12 @@ void ProcessWork(ares_channel_t *cha |
|
|
|
|
unsigned int cancel_ms = 0); |
|
|
|
|
std::set<ares_socket_t> NoExtraFDs(); |
|
|
|
|
|
|
|
|
|
const char *af_tostr(int af); |
|
|
|
|
const char *mode_tostr(bool mode); |
|
|
|
|
std::string PrintFamilyMode(const testing::TestParamInfo<std::pair<int, bool>> &info); |
|
|
|
|
const char *af_tostr(int af); |
|
|
|
|
const char *mode_tostr(bool mode); |
|
|
|
|
std::string |
|
|
|
|
PrintFamilyMode(const testing::TestParamInfo<std::pair<int, bool>> &info); |
|
|
|
|
std::string PrintFamily(const testing::TestParamInfo<int> &info); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Test fixture that ensures library initialization, and allows
|
|
|
|
|
// memory allocations to be failed.
|
|
|
|
|
class LibraryTest : public ::testing::Test { |
|
|
|
@ -345,17 +347,20 @@ public: |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MockEventThreadOptsTest : public MockChannelOptsTest { |
|
|
|
|
public: |
|
|
|
|
MockEventThreadOptsTest(int count, ares_evsys_t evsys, int family, bool force_tcp, |
|
|
|
|
struct ares_options *givenopts, int optmask) |
|
|
|
|
: MockChannelOptsTest(count, family, force_tcp, FillOptionsET(&evopts_, givenopts, evsys), optmask | ARES_OPT_EVENT_THREAD) |
|
|
|
|
MockEventThreadOptsTest(int count, ares_evsys_t evsys, int family, |
|
|
|
|
bool force_tcp, struct ares_options *givenopts, |
|
|
|
|
int optmask) |
|
|
|
|
: MockChannelOptsTest(count, family, force_tcp, |
|
|
|
|
FillOptionsET(&evopts_, givenopts, evsys), |
|
|
|
|
optmask | ARES_OPT_EVENT_THREAD) |
|
|
|
|
{ |
|
|
|
|
cancel_ms_ = 0; |
|
|
|
|
isup = true; |
|
|
|
|
thread = std::thread(&MockEventThreadOptsTest::ProcessThread, this); |
|
|
|
|
isup = true; |
|
|
|
|
thread = std::thread(&MockEventThreadOptsTest::ProcessThread, this); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
~MockEventThreadOptsTest() |
|
|
|
|
{ |
|
|
|
|
mutex.lock(); |
|
|
|
@ -364,7 +369,10 @@ public: |
|
|
|
|
thread.join(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static struct ares_options *FillOptionsET(struct ares_options *opts, struct ares_options *givenopts, ares_evsys_t evsys) { |
|
|
|
|
static struct ares_options *FillOptionsET(struct ares_options *opts, |
|
|
|
|
struct ares_options *givenopts, |
|
|
|
|
ares_evsys_t evsys) |
|
|
|
|
{ |
|
|
|
|
if (givenopts) { |
|
|
|
|
memcpy(opts, givenopts, sizeof(*opts)); |
|
|
|
|
} else { |
|
|
|
@ -374,7 +382,8 @@ public: |
|
|
|
|
return opts; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Process(unsigned int cancel_ms = 0) { |
|
|
|
|
void Process(unsigned int cancel_ms = 0) |
|
|
|
|
{ |
|
|
|
|
mutex.lock(); |
|
|
|
|
cancel_ms_ = cancel_ms; |
|
|
|
|
mutex.unlock(); |
|
|
|
@ -382,12 +391,12 @@ public: |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private: |
|
|
|
|
void ProcessThread(); |
|
|
|
|
void ProcessThread(); |
|
|
|
|
struct ares_options evopts_; |
|
|
|
|
unsigned int cancel_ms_; |
|
|
|
|
bool isup; |
|
|
|
|
std::mutex mutex; |
|
|
|
|
std::thread thread; |
|
|
|
|
unsigned int cancel_ms_; |
|
|
|
|
bool isup; |
|
|
|
|
std::mutex mutex; |
|
|
|
|
std::thread thread; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
class MockEventThreadTest |
|
|
|
@ -395,30 +404,35 @@ class MockEventThreadTest |
|
|
|
|
public ::testing::WithParamInterface<std::tuple<ares_evsys_t, int, bool>> { |
|
|
|
|
public: |
|
|
|
|
MockEventThreadTest() |
|
|
|
|
: MockEventThreadOptsTest(1, std::get<0>(GetParam()), std::get<1>(GetParam()), std::get<2>(GetParam()), nullptr, 0) |
|
|
|
|
: MockEventThreadOptsTest(1, std::get<0>(GetParam()), |
|
|
|
|
std::get<1>(GetParam()), std::get<2>(GetParam()), |
|
|
|
|
nullptr, 0) |
|
|
|
|
{ |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
class MockUDPEventThreadTest : public MockEventThreadOptsTest, |
|
|
|
|
public ::testing::WithParamInterface<std::tuple<ares_evsys_t,int>> { |
|
|
|
|
class MockUDPEventThreadTest |
|
|
|
|
: public MockEventThreadOptsTest, |
|
|
|
|
public ::testing::WithParamInterface<std::tuple<ares_evsys_t, int>> { |
|
|
|
|
public: |
|
|
|
|
MockUDPEventThreadTest() : MockEventThreadOptsTest(1, std::get<0>(GetParam()), std::get<1>(GetParam()), false, nullptr, 0) |
|
|
|
|
MockUDPEventThreadTest() |
|
|
|
|
: MockEventThreadOptsTest(1, std::get<0>(GetParam()), |
|
|
|
|
std::get<1>(GetParam()), false, nullptr, 0) |
|
|
|
|
{ |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
class MockTCPEventThreadTest : public MockEventThreadOptsTest, |
|
|
|
|
public ::testing::WithParamInterface<std::tuple<ares_evsys_t,int>> { |
|
|
|
|
class MockTCPEventThreadTest |
|
|
|
|
: public MockEventThreadOptsTest, |
|
|
|
|
public ::testing::WithParamInterface<std::tuple<ares_evsys_t, int>> { |
|
|
|
|
public: |
|
|
|
|
MockTCPEventThreadTest() : MockEventThreadOptsTest(1, std::get<0>(GetParam()), std::get<1>(GetParam()), true, nullptr, 0) |
|
|
|
|
MockTCPEventThreadTest() |
|
|
|
|
: MockEventThreadOptsTest(1, std::get<0>(GetParam()), |
|
|
|
|
std::get<1>(GetParam()), true, nullptr, 0) |
|
|
|
|
{ |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// gMock action to set the reply for a mock server.
|
|
|
|
|
ACTION_P2(SetReplyData, mockserver, data) |
|
|
|
|
{ |
|
|
|
|