summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorYu Jiung <jiung.yu@samsung.com>2016-11-09 02:23:06 (GMT)
committerYu Jiung <jiung.yu@samsung.com>2016-11-09 02:23:15 (GMT)
commit8e609b5f488d486a9e066ed494218d966f489938 (patch)
tree0a169eb7025401e0a14ab5d5e74db5b27954f591 /test
parenteb886f120599b2a184db20b527db6dfdfcb7852e (diff)
downloadc-ares-8e609b5f488d486a9e066ed494218d966f489938.zip
c-ares-8e609b5f488d486a9e066ed494218d966f489938.tar.gz
c-ares-8e609b5f488d486a9e066ed494218d966f489938.tar.bz2
Imported Upstream version 1.12.0upstream/1.12.0upstreamrefs/changes/19/96419/1
Change-Id: I6a571bddd24d1cb7d64b74bc66e878ccba2ce638
Diffstat (limited to 'test')
-rw-r--r--test/Makefile.am7
-rw-r--r--test/Makefile.in94
-rw-r--r--test/Makefile.inc7
-rw-r--r--test/ares-fuzz.c58
-rw-r--r--test/ares-fuzz.cc20
-rw-r--r--test/ares-test-fuzz.c (renamed from test/ares-test-fuzz.cc)28
-rw-r--r--test/ares-test-init.cc59
-rw-r--r--test/ares-test-live.cc6
-rw-r--r--test/ares-test-main.cc7
-rw-r--r--test/ares-test-misc.cc13
-rw-r--r--test/ares-test-mock.cc35
-rw-r--r--test/ares-test.cc2
-rw-r--r--test/dns-dump.cc35
-rw-r--r--test/dns-proto.cc3
14 files changed, 299 insertions, 75 deletions
diff --git a/test/Makefile.am b/test/Makefile.am
index 4809b51..da771ab 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -13,9 +13,9 @@ CXXFLAGS += -Wall $(PTHREAD_CFLAGS)
# Makefile.inc provides the TESTSOURCES, TESTHEADERS and FUZZSOURCES defines
include Makefile.inc
-TESTS = arestest
+TESTS = arestest fuzzcheck.sh
-noinst_PROGRAMS = arestest aresfuzz
+noinst_PROGRAMS = arestest aresfuzz dnsdump
arestest_SOURCES = $(TESTSOURCES) $(TESTHEADERS)
arestest_LDADD = libgmock.la libgtest.la $(ARES_BLD_DIR)/libcares.la $(PTHREAD_LIBS)
@@ -33,4 +33,7 @@ libgtest_la_CPPFLAGS = -isystem $(GTEST_DIR)/include -I$(GTEST_DIR) -isystem $(G
aresfuzz_SOURCES = $(FUZZSOURCES)
aresfuzz_LDADD = $(ARES_BLD_DIR)/libcares.la
+dnsdump_SOURCES = $(DUMPSOURCES)
+dnsdump_LDADD = $(ARES_BLD_DIR)/libcares.la
+
test: check
diff --git a/test/Makefile.in b/test/Makefile.in
index 0bebc91..f558f0c 100644
--- a/test/Makefile.in
+++ b/test/Makefile.in
@@ -89,8 +89,8 @@ PRE_UNINSTALL = :
POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
-TESTS = arestest$(EXEEXT)
-noinst_PROGRAMS = arestest$(EXEEXT) aresfuzz$(EXEEXT)
+TESTS = arestest$(EXEEXT) fuzzcheck.sh
+noinst_PROGRAMS = arestest$(EXEEXT) aresfuzz$(EXEEXT) dnsdump$(EXEEXT)
subdir = .
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/../m4/ax_check_user_namespace.m4 \
@@ -148,6 +148,10 @@ arestest_DEPENDENCIES = libgmock.la libgtest.la \
arestest_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=link $(CXXLD) $(AM_CXXFLAGS) \
$(CXXFLAGS) $(arestest_LDFLAGS) $(LDFLAGS) -o $@
+am__objects_4 = dns-proto.$(OBJEXT) dns-dump.$(OBJEXT)
+am_dnsdump_OBJECTS = $(am__objects_4)
+dnsdump_OBJECTS = $(am_dnsdump_OBJECTS)
+dnsdump_DEPENDENCIES = $(ARES_BLD_DIR)/libcares.la
AM_V_P = $(am__v_P_@AM_V@)
am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
am__v_P_0 = false
@@ -164,24 +168,6 @@ DEFAULT_INCLUDES = -I.@am__isrc@
depcomp = $(SHELL) $(top_srcdir)/../depcomp
am__depfiles_maybe = depfiles
am__mv = mv -f
-CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
- $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
-LTCXXCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) \
- $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) \
- $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
- $(AM_CXXFLAGS) $(CXXFLAGS)
-AM_V_CXX = $(am__v_CXX_@AM_V@)
-am__v_CXX_ = $(am__v_CXX_@AM_DEFAULT_V@)
-am__v_CXX_0 = @echo " CXX " $@;
-am__v_CXX_1 =
-CXXLD = $(CXX)
-CXXLINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) \
- $(LIBTOOLFLAGS) --mode=link $(CXXLD) $(AM_CXXFLAGS) \
- $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
-AM_V_CXXLD = $(am__v_CXXLD_@AM_V@)
-am__v_CXXLD_ = $(am__v_CXXLD_@AM_DEFAULT_V@)
-am__v_CXXLD_0 = @echo " CXXLD " $@;
-am__v_CXXLD_1 =
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
@@ -200,10 +186,28 @@ AM_V_CCLD = $(am__v_CCLD_@AM_V@)
am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
am__v_CCLD_0 = @echo " CCLD " $@;
am__v_CCLD_1 =
+CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
+ $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
+LTCXXCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) \
+ $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) \
+ $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
+ $(AM_CXXFLAGS) $(CXXFLAGS)
+AM_V_CXX = $(am__v_CXX_@AM_V@)
+am__v_CXX_ = $(am__v_CXX_@AM_DEFAULT_V@)
+am__v_CXX_0 = @echo " CXX " $@;
+am__v_CXX_1 =
+CXXLD = $(CXX)
+CXXLINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) \
+ $(LIBTOOLFLAGS) --mode=link $(CXXLD) $(AM_CXXFLAGS) \
+ $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
+AM_V_CXXLD = $(am__v_CXXLD_@AM_V@)
+am__v_CXXLD_ = $(am__v_CXXLD_@AM_DEFAULT_V@)
+am__v_CXXLD_0 = @echo " CXXLD " $@;
+am__v_CXXLD_1 =
SOURCES = $(libgmock_la_SOURCES) $(libgtest_la_SOURCES) \
- $(aresfuzz_SOURCES) $(arestest_SOURCES)
+ $(aresfuzz_SOURCES) $(arestest_SOURCES) $(dnsdump_SOURCES)
DIST_SOURCES = $(libgmock_la_SOURCES) $(libgtest_la_SOURCES) \
- $(aresfuzz_SOURCES) $(arestest_SOURCES)
+ $(aresfuzz_SOURCES) $(arestest_SOURCES) $(dnsdump_SOURCES)
am__can_run_installinfo = \
case $$AM_UPDATE_INFO_DIR in \
n|no|NO) false;; \
@@ -625,8 +629,11 @@ TESTSOURCES = ares-test-main.cc \
TESTHEADERS = ares-test.h \
dns-proto.h
-FUZZSOURCES = ares-test-fuzz.cc \
- ares-fuzz.cc
+FUZZSOURCES = ares-test-fuzz.c \
+ ares-fuzz.c
+
+DUMPSOURCES = dns-proto.cc \
+ dns-dump.cc
arestest_SOURCES = $(TESTSOURCES) $(TESTHEADERS)
arestest_LDADD = libgmock.la libgtest.la $(ARES_BLD_DIR)/libcares.la $(PTHREAD_LIBS)
@@ -638,11 +645,13 @@ libgtest_la_SOURCES = $(GTEST_DIR)/src/gtest-all.cc
libgtest_la_CPPFLAGS = -isystem $(GTEST_DIR)/include -I$(GTEST_DIR) -isystem $(GMOCK_DIR)/include -I$(GMOCK_DIR)
aresfuzz_SOURCES = $(FUZZSOURCES)
aresfuzz_LDADD = $(ARES_BLD_DIR)/libcares.la
+dnsdump_SOURCES = $(DUMPSOURCES)
+dnsdump_LDADD = $(ARES_BLD_DIR)/libcares.la
all: config.h
$(MAKE) $(AM_MAKEFLAGS) all-am
.SUFFIXES:
-.SUFFIXES: .cc .lo .log .o .obj .test .test$(EXEEXT) .trs
+.SUFFIXES: .c .cc .lo .log .o .obj .test .test$(EXEEXT) .trs
am--refresh: Makefile
@:
$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(srcdir)/Makefile.inc $(am__configure_deps)
@@ -721,12 +730,16 @@ clean-noinstPROGRAMS:
aresfuzz$(EXEEXT): $(aresfuzz_OBJECTS) $(aresfuzz_DEPENDENCIES) $(EXTRA_aresfuzz_DEPENDENCIES)
@rm -f aresfuzz$(EXEEXT)
- $(AM_V_CXXLD)$(CXXLINK) $(aresfuzz_OBJECTS) $(aresfuzz_LDADD) $(LIBS)
+ $(AM_V_CCLD)$(LINK) $(aresfuzz_OBJECTS) $(aresfuzz_LDADD) $(LIBS)
arestest$(EXEEXT): $(arestest_OBJECTS) $(arestest_DEPENDENCIES) $(EXTRA_arestest_DEPENDENCIES)
@rm -f arestest$(EXEEXT)
$(AM_V_CXXLD)$(arestest_LINK) $(arestest_OBJECTS) $(arestest_LDADD) $(LIBS)
+dnsdump$(EXEEXT): $(dnsdump_OBJECTS) $(dnsdump_DEPENDENCIES) $(EXTRA_dnsdump_DEPENDENCIES)
+ @rm -f dnsdump$(EXEEXT)
+ $(AM_V_CXXLD)$(CXXLINK) $(dnsdump_OBJECTS) $(dnsdump_LDADD) $(LIBS)
+
mostlyclean-compile:
-rm -f *.$(OBJEXT)
@@ -753,11 +766,33 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ares-test-parse-txt.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ares-test-parse.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ares-test.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dns-dump.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dns-proto-test.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dns-proto.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libgmock_la-gmock-all.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libgtest_la-gtest-all.Plo@am__quote@
+.c.o:
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ $<
+
+.c.obj:
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'`
+
+.c.lo:
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $<
+
.cc.o:
@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
@@ -1009,6 +1044,13 @@ arestest.log: arestest$(EXEEXT)
--log-file $$b.log --trs-file $$b.trs \
$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
"$$tst" $(AM_TESTS_FD_REDIRECT)
+fuzzcheck.sh.log: fuzzcheck.sh
+ @p='fuzzcheck.sh'; \
+ b='fuzzcheck.sh'; \
+ $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
+ --log-file $$b.log --trs-file $$b.trs \
+ $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
+ "$$tst" $(AM_TESTS_FD_REDIRECT)
.test.log:
@p='$<'; \
$(am__set_b); \
diff --git a/test/Makefile.inc b/test/Makefile.inc
index 54e424b..2fa98b1 100644
--- a/test/Makefile.inc
+++ b/test/Makefile.inc
@@ -22,5 +22,8 @@ TESTSOURCES = ares-test-main.cc \
TESTHEADERS = ares-test.h \
dns-proto.h
-FUZZSOURCES = ares-test-fuzz.cc \
- ares-fuzz.cc
+FUZZSOURCES = ares-test-fuzz.c \
+ ares-fuzz.c
+
+DUMPSOURCES = dns-proto.cc \
+ dns-dump.cc
diff --git a/test/ares-fuzz.c b/test/ares-fuzz.c
new file mode 100644
index 0000000..9276128
--- /dev/null
+++ b/test/ares-fuzz.c
@@ -0,0 +1,58 @@
+/*
+ * General driver to allow command-line fuzzer (i.e. afl) to
+ * exercise the libFuzzer entrypoint.
+ */
+
+#include <sys/types.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#define kMaxAflInputSize (1 << 20)
+static unsigned char afl_buffer[kMaxAflInputSize];
+
+#ifdef __AFL_LOOP
+/* If we are built with afl-clang-fast, use persistent mode */
+#define KEEP_FUZZING(count) __AFL_LOOP(1000)
+#else
+/* If we are built with afl-clang, execute each input once */
+#define KEEP_FUZZING(count) ((count) < 1)
+#endif
+
+/* In ares-test-fuzz.c: */
+int LLVMFuzzerTestOneInput(const unsigned char *data, unsigned long size);
+
+static void ProcessFile(int fd) {
+ ssize_t count = read(fd, afl_buffer, kMaxAflInputSize);
+ /*
+ * Make a copy of the data so that it's not part of a larger
+ * buffer (where buffer overflows would go unnoticed).
+ */
+ unsigned char *copied_data = (unsigned char *)malloc(count);
+ LLVMFuzzerTestOneInput(copied_data, count);
+ free(copied_data);
+}
+
+int main(int argc, char *argv[]) {
+ if (argc == 1) {
+ int count = 0;
+ while (KEEP_FUZZING(count)) {
+ ProcessFile(fileno(stdin));
+ count++;
+ }
+ } else {
+ int ii;
+ for (ii = 1; ii < argc; ++ii) {
+ int fd = open(argv[ii], O_RDONLY);
+ if (fd < 0) {
+ fprintf(stderr, "Failed to open '%s'\n", argv[ii]);
+ continue;
+ }
+ ProcessFile(fd);
+ close(fd);
+ }
+ }
+ return 0;
+}
diff --git a/test/ares-fuzz.cc b/test/ares-fuzz.cc
deleted file mode 100644
index 4680b72..0000000
--- a/test/ares-fuzz.cc
+++ /dev/null
@@ -1,20 +0,0 @@
-// General driver to allow command-line fuzzer (i.e. afl) to
-// fuzz the libfuzzer entrypoint.
-#include <stdio.h>
-#include <unistd.h>
-
-#include <vector>
-
-extern "C" void LLVMFuzzerTestOneInput(const unsigned char *data,
- unsigned long size);
-int main() {
- std::vector<unsigned char> input;
- while (true) {
- unsigned char buffer[1024];
- int len = read(fileno(stdin), buffer, sizeof(buffer));
- if (len <= 0) break;
- input.insert(input.end(), buffer, buffer + len);
- }
- LLVMFuzzerTestOneInput(input.data(), input.size());
- return 0;
-}
diff --git a/test/ares-test-fuzz.cc b/test/ares-test-fuzz.c
index 49d844c..528e76c 100644
--- a/test/ares-test-fuzz.cc
+++ b/test/ares-test-fuzz.c
@@ -1,44 +1,46 @@
-#include "ares-test.h"
-#include <vector>
+#include <stddef.h>
+
+#include "ares.h"
// Entrypoint for Clang's libfuzzer
-extern "C" void LLVMFuzzerTestOneInput(const unsigned char *data,
- unsigned long size) {
+int LLVMFuzzerTestOneInput(const unsigned char *data,
+ unsigned long size) {
// Feed the data into each of the ares_parse_*_reply functions.
- struct hostent *host = nullptr;
+ struct hostent *host = NULL;
struct ares_addrttl info[5];
int count = 5;
ares_parse_a_reply(data, size, &host, info, &count);
if (host) ares_free_hostent(host);
- host = nullptr;
+ host = NULL;
struct ares_addr6ttl info6[5];
count = 5;
ares_parse_aaaa_reply(data, size, &host, info6, &count);
if (host) ares_free_hostent(host);
- host = nullptr;
- ares::byte addrv4[4] = {0x10, 0x20, 0x30, 0x40};
+ host = NULL;
+ unsigned char addrv4[4] = {0x10, 0x20, 0x30, 0x40};
ares_parse_ptr_reply(data, size, addrv4, sizeof(addrv4), AF_INET, &host);
if (host) ares_free_hostent(host);
- host = nullptr;
+ host = NULL;
ares_parse_ns_reply(data, size, &host);
if (host) ares_free_hostent(host);
- struct ares_srv_reply* srv = nullptr;
+ struct ares_srv_reply* srv = NULL;
ares_parse_srv_reply(data, size, &srv);
if (srv) ares_free_data(srv);
- struct ares_mx_reply* mx = nullptr;
+ struct ares_mx_reply* mx = NULL;
ares_parse_mx_reply(data, size, &mx);
if (mx) ares_free_data(mx);
- struct ares_txt_reply* txt = nullptr;
+ struct ares_txt_reply* txt = NULL;
ares_parse_txt_reply(data, size, &txt);
if (txt) ares_free_data(txt);
- struct ares_soa_reply* soa = nullptr;
+ struct ares_soa_reply* soa = NULL;
ares_parse_soa_reply(data, size, &soa);
if (soa) ares_free_data(soa);
+ return 0;
}
diff --git a/test/ares-test-init.cc b/test/ares-test-init.cc
index c9c6089..66570ac 100644
--- a/test/ares-test-init.cc
+++ b/test/ares-test-init.cc
@@ -354,6 +354,26 @@ CONTAINED_TEST_F(LibraryTest, ContainerChannelInit,
return HasFailure();
}
+CONTAINED_TEST_F(LibraryTest, ContainerSortlistOptionInit,
+ "myhostname", "mydomainname.org", filelist) {
+ ares_channel channel = nullptr;
+ struct ares_options opts = {0};
+ int optmask = 0;
+ optmask |= ARES_OPT_SORTLIST;
+ opts.nsort = 0;
+ // Explicitly specifying an empty sortlist in the options should override the
+ // environment.
+ EXPECT_EQ(ARES_SUCCESS, ares_init_options(&channel, &opts, optmask));
+ ares_save_options(channel, &opts, &optmask);
+ EXPECT_EQ(0, opts.nsort);
+ EXPECT_EQ(nullptr, opts.sortlist);
+ EXPECT_EQ(ARES_OPT_SORTLIST, (optmask & ARES_OPT_SORTLIST));
+ ares_destroy_options(&opts);
+
+ ares_destroy(channel);
+ return HasFailure();
+}
+
NameContentList fullresolv = {
{"/etc/resolv.conf", " nameserver 1.2.3.4 \n"
"search first.com second.com\n"
@@ -431,8 +451,8 @@ CONTAINED_TEST_F(LibraryTest, ContainerResolvConfNotReadable,
"myhostname", "mydomainname.org", filelist) {
ares_channel channel = nullptr;
MakeUnreadable hide("/etc/resolv.conf");
- // Unavailable /etc/resolv.conf fails initialization.
- EXPECT_EQ(ARES_EFILE, ares_init(&channel));
+ // Unavailable /etc/resolv.conf falls back to defaults
+ EXPECT_EQ(ARES_SUCCESS, ares_init(&channel));
return HasFailure();
}
CONTAINED_TEST_F(LibraryTest, ContainerNsswitchConfNotReadable,
@@ -470,6 +490,41 @@ CONTAINED_TEST_F(LibraryTest, ContainerSvcConfNotReadable,
return HasFailure();
}
+NameContentList rotateenv = {
+ {"/etc/resolv.conf", "nameserver 1.2.3.4\n"
+ "search first.com second.com\n"
+ "options rotate\n"}};
+CONTAINED_TEST_F(LibraryTest, ContainerRotateInit,
+ "myhostname", "mydomainname.org", rotateenv) {
+ ares_channel channel = nullptr;
+ EXPECT_EQ(ARES_SUCCESS, ares_init(&channel));
+
+ struct ares_options opts;
+ int optmask = 0;
+ ares_save_options(channel, &opts, &optmask);
+ EXPECT_EQ(ARES_OPT_ROTATE, (optmask & ARES_OPT_ROTATE));
+ ares_destroy_options(&opts);
+
+ ares_destroy(channel);
+ return HasFailure();
+}
+
+CONTAINED_TEST_F(LibraryTest, ContainerRotateOverride,
+ "myhostname", "mydomainname.org", rotateenv) {
+ ares_channel channel = nullptr;
+ struct ares_options opts = {0};
+ int optmask = ARES_OPT_NOROTATE;
+ EXPECT_EQ(ARES_SUCCESS, ares_init_options(&channel, &opts, optmask));
+
+ optmask = 0;
+ ares_save_options(channel, &opts, &optmask);
+ EXPECT_EQ(ARES_OPT_NOROTATE, (optmask & ARES_OPT_NOROTATE));
+ ares_destroy_options(&opts);
+
+ ares_destroy(channel);
+ return HasFailure();
+}
+
NameContentList multiresolv = {
{"/etc/resolv.conf", " nameserver 1::2 ; ;;\n"
" domain first.com\n"},
diff --git a/test/ares-test-live.cc b/test/ares-test-live.cc
index bbf9b4e..b8ff8eb 100644
--- a/test/ares-test-live.cc
+++ b/test/ares-test-live.cc
@@ -157,7 +157,9 @@ TEST_P(DefaultChannelModeTest, LiveGetLocalhostByAddrV4) {
TEST_P(DefaultChannelModeTest, LiveGetLocalhostByAddrV6) {
HostResult result;
- struct in6_addr addr = in6addr_loopback;
+ struct in6_addr addr;
+ memset(&addr, 0, sizeof(addr));
+ addr.s6_addr[15] = 1; // in6addr_loopback
ares_gethostbyaddr(channel_, &addr, sizeof(addr), AF_INET6, HostCallback, &result);
Process();
EXPECT_TRUE(result.done_);
@@ -203,7 +205,7 @@ INSTANTIATE_TEST_CASE_P(Modes, DefaultChannelModeTest,
TEST_F(DefaultChannelTest, LiveSearchA) {
SearchResult result;
- ares_search(channel_, "www.facebook.com.", ns_c_in, ns_t_a,
+ ares_search(channel_, "www.youtube.com.", ns_c_in, ns_t_a,
SearchCallback, &result);
Process();
EXPECT_TRUE(result.done_);
diff --git a/test/ares-test-main.cc b/test/ares-test-main.cc
index 329d34d..f7e90cb 100644
--- a/test/ares-test-main.cc
+++ b/test/ares-test-main.cc
@@ -4,15 +4,20 @@
#include "ares-test.h"
int main(int argc, char* argv[]) {
- ::testing::InitGoogleTest(&argc, argv);
+ std::vector<char*> gtest_argv = {argv[0]};
for (int ii = 1; ii < argc; ii++) {
if (strcmp(argv[ii], "-v") == 0) {
ares::test::verbose = true;
} else if ((strcmp(argv[ii], "-p") == 0) && (ii + 1 < argc)) {
ii++;
ares::test::mock_port = atoi(argv[ii]);
+ } else {
+ gtest_argv.push_back(argv[ii]);
}
}
+ int gtest_argc = gtest_argv.size();
+ gtest_argv.push_back(nullptr);
+ ::testing::InitGoogleTest(&gtest_argc, gtest_argv.data());
#ifdef WIN32
WORD wVersionRequested = MAKEWORD(2, 2);
diff --git a/test/ares-test-misc.cc b/test/ares-test-misc.cc
index bde4678..5e5bc0b 100644
--- a/test/ares-test-misc.cc
+++ b/test/ares-test-misc.cc
@@ -193,6 +193,19 @@ TEST_F(LibraryTest, CreateQuery) {
EXPECT_EQ(expected, actual);
}
+TEST_F(LibraryTest, CreateQueryTrailingEscapedDot) {
+ byte* p;
+ int len;
+ EXPECT_EQ(ARES_SUCCESS,
+ ares_create_query("example.com\\.", ns_c_in, ns_t_a, 0x1234, 0,
+ &p, &len, 0));
+ std::vector<byte> data(p, p + len);
+ ares_free_string(p);
+
+ std::string actual = PacketToString(data);
+ EXPECT_EQ("REQ QRY Q:{'example.com\\.' IN A}", actual);
+}
+
TEST_F(LibraryTest, CreateQueryFailures) {
byte* p;
int len;
diff --git a/test/ares-test-mock.cc b/test/ares-test-mock.cc
index 29b77b1..2cbe6b4 100644
--- a/test/ares-test-mock.cc
+++ b/test/ares-test-mock.cc
@@ -647,17 +647,17 @@ TEST_P(MockChannelTest, UnspecifiedFamilyV6) {
}
TEST_P(MockChannelTest, UnspecifiedFamilyV4) {
+ DNSPacket rsp6;
+ rsp6.set_response().set_aa()
+ .add_question(new DNSQuestion("example.com", ns_t_aaaa));
+ ON_CALL(server_, OnRequest("example.com", ns_t_aaaa))
+ .WillByDefault(SetReply(&server_, &rsp6));
DNSPacket rsp4;
rsp4.set_response().set_aa()
.add_question(new DNSQuestion("example.com", ns_t_a))
.add_answer(new DNSARR("example.com", 100, {2, 3, 4, 5}));
ON_CALL(server_, OnRequest("example.com", ns_t_a))
.WillByDefault(SetReply(&server_, &rsp4));
- DNSPacket rsp6;
- rsp6.set_response().set_aa()
- .add_question(new DNSQuestion("example.com", ns_t_aaaa));
- ON_CALL(server_, OnRequest("example.com", ns_t_aaaa))
- .WillByDefault(SetReply(&server_, &rsp6));
HostResult result;
ares_gethostbyname(channel_, "example.com.", AF_UNSPEC, HostCallback, &result);
@@ -669,17 +669,40 @@ TEST_P(MockChannelTest, UnspecifiedFamilyV4) {
}
TEST_P(MockChannelTest, UnspecifiedFamilyNoData) {
+ DNSPacket rsp6;
+ rsp6.set_response().set_aa()
+ .add_question(new DNSQuestion("example.com", ns_t_aaaa))
+ .add_answer(new DNSCnameRR("example.com", 100, "elsewhere.com"));
+ ON_CALL(server_, OnRequest("example.com", ns_t_aaaa))
+ .WillByDefault(SetReply(&server_, &rsp6));
DNSPacket rsp4;
rsp4.set_response().set_aa()
.add_question(new DNSQuestion("example.com", ns_t_a));
ON_CALL(server_, OnRequest("example.com", ns_t_a))
.WillByDefault(SetReply(&server_, &rsp4));
+
+ HostResult result;
+ ares_gethostbyname(channel_, "example.com.", AF_UNSPEC, HostCallback, &result);
+ Process();
+ EXPECT_TRUE(result.done_);
+ std::stringstream ss;
+ ss << result.host_;
+ EXPECT_EQ("{'' aliases=[] addrs=[]}", ss.str());
+}
+
+TEST_P(MockChannelTest, UnspecifiedFamilyCname6A4) {
DNSPacket rsp6;
rsp6.set_response().set_aa()
.add_question(new DNSQuestion("example.com", ns_t_aaaa))
.add_answer(new DNSCnameRR("example.com", 100, "elsewhere.com"));
ON_CALL(server_, OnRequest("example.com", ns_t_aaaa))
.WillByDefault(SetReply(&server_, &rsp6));
+ DNSPacket rsp4;
+ rsp4.set_response().set_aa()
+ .add_question(new DNSQuestion("example.com", ns_t_a))
+ .add_answer(new DNSARR("example.com", 100, {1, 2, 3, 4}));
+ ON_CALL(server_, OnRequest("example.com", ns_t_a))
+ .WillByDefault(SetReply(&server_, &rsp4));
HostResult result;
ares_gethostbyname(channel_, "example.com.", AF_UNSPEC, HostCallback, &result);
@@ -687,7 +710,7 @@ TEST_P(MockChannelTest, UnspecifiedFamilyNoData) {
EXPECT_TRUE(result.done_);
std::stringstream ss;
ss << result.host_;
- EXPECT_EQ("{'' aliases=[] addrs=[]}", ss.str());
+ EXPECT_EQ("{'example.com' aliases=[] addrs=[1.2.3.4]}", ss.str());
}
TEST_P(MockChannelTest, ExplicitIP) {
diff --git a/test/ares-test.cc b/test/ares-test.cc
index 96c80b9..b86cba4 100644
--- a/test/ares-test.cc
+++ b/test/ares-test.cc
@@ -180,7 +180,7 @@ MockServer::MockServer(int family, int port, int tcpport)
struct sockaddr_in6 addr;
memset(&addr, 0, sizeof(addr));
addr.sin6_family = AF_INET6;
- addr.sin6_addr = in6addr_any;
+ memset(&addr.sin6_addr, 0, sizeof(addr.sin6_addr)); // in6addr_any
addr.sin6_port = htons(tcpport_);
int tcprc = bind(tcpfd_, (struct sockaddr*)&addr, sizeof(addr));
EXPECT_EQ(0, tcprc) << "Failed to bind AF_INET6 to TCP port " << tcpport_;
diff --git a/test/dns-dump.cc b/test/dns-dump.cc
new file mode 100644
index 0000000..023de36
--- /dev/null
+++ b/test/dns-dump.cc
@@ -0,0 +1,35 @@
+#include <sys/types.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#include <iostream>
+#include <vector>
+
+#include "dns-proto.h"
+
+namespace ares {
+
+static void ShowFile(const char* filename) {
+ int fd = open(filename, O_RDONLY);
+ if (fd < 0) {
+ std::cerr << "Failed to open '" << filename << "'" << std::endl;
+ return;
+ }
+ std::vector<unsigned char> contents;
+ while (true) {
+ unsigned char buffer[1024];
+ int len = read(fd, buffer, sizeof(buffer));
+ if (len <= 0) break;
+ contents.insert(contents.end(), buffer, buffer + len);
+ }
+ std::cout << PacketToString(contents) << std::endl;
+}
+
+} // namespace ares
+
+int main(int argc, char* argv[]) {
+ for (int ii = 1; ii < argc; ++ii) {
+ ares::ShowFile(argv[ii]);
+ }
+}
+
diff --git a/test/dns-proto.cc b/test/dns-proto.cc
index 8814d28..8eb7f2e 100644
--- a/test/dns-proto.cc
+++ b/test/dns-proto.cc
@@ -4,6 +4,9 @@
#include "ares.h"
#include "ares_dns.h"
+#include <stdio.h>
+#include <stdlib.h>
+
#include <sstream>
namespace ares {