aboutsummaryrefslogtreecommitdiff
path: root/support
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2016-12-31 14:06:16 +0100
committerFlorian Weimer <fweimer@redhat.com>2016-12-31 18:52:32 +0100
commit5840c75c2d6a9b980d6789f2ca7d47a9fa067263 (patch)
tree3eb4c28827ba0901f9ae7396d841c396c393805e /support
parentf47ae5186624e5bb3a2d2b25be742b90a1eee3cd (diff)
downloadglibc-5840c75c2d6a9b980d6789f2ca7d47a9fa067263.tar.xz
glibc-5840c75c2d6a9b980d6789f2ca7d47a9fa067263.zip
resolv: Add beginnings of a libresolv test suite
Diffstat (limited to 'support')
-rw-r--r--support/Makefile27
-rw-r--r--support/check_addrinfo.c42
-rw-r--r--support/check_dns_packet.c42
-rw-r--r--support/check_hostent.c42
-rw-r--r--support/check_netent.c42
-rw-r--r--support/check_nss.h42
-rw-r--r--support/format_nss.h41
-rw-r--r--support/resolv_test.c1150
-rw-r--r--support/resolv_test.h169
-rw-r--r--support/run_diff.h31
-rw-r--r--support/support.h1
-rw-r--r--support/support_format_address_family.c35
-rw-r--r--support/support_format_addrinfo.c202
-rw-r--r--support/support_format_dns_packet.c215
-rw-r--r--support/support_format_herrno.c45
-rw-r--r--support/support_format_hostent.c75
-rw-r--r--support/support_format_netent.c50
-rw-r--r--support/support_run_diff.c76
-rw-r--r--support/xaccept.c32
-rw-r--r--support/xbind.c30
-rw-r--r--support/xconnect.c30
-rw-r--r--support/xfclose.c33
-rw-r--r--support/xfopen.c31
-rw-r--r--support/xgetsockname.c30
-rw-r--r--support/xlisten.c30
-rw-r--r--support/xmemstream.c42
-rw-r--r--support/xmemstream.h49
-rw-r--r--support/xpoll.c32
-rw-r--r--support/xpthread_once.c25
-rw-r--r--support/xrecvfrom.c33
-rw-r--r--support/xsendto.c35
-rw-r--r--support/xsetsockopt.c31
-rw-r--r--support/xsocket.h11
-rw-r--r--support/xstdio.h32
-rw-r--r--support/xstrdup.c30
-rw-r--r--support/xthread.h1
-rw-r--r--support/xunistd.h3
-rw-r--r--support/xwrite.c39
38 files changed, 2906 insertions, 0 deletions
diff --git a/support/Makefile b/support/Makefile
index 9544a08573..7e34fcbfcb 100644
--- a/support/Makefile
+++ b/support/Makefile
@@ -26,21 +26,42 @@ extra-libs-noinstall := $(extra-libs)
libsupport-routines = \
check \
+ check_addrinfo \
+ check_dns_packet \
+ check_hostent \
+ check_netent \
delayed_exit \
ignore_stderr \
oom_error \
+ resolv_test \
set_fortify_handler \
support_become_root \
support_enter_network_namespace \
+ support_format_address_family \
+ support_format_addrinfo \
+ support_format_dns_packet \
+ support_format_herrno \
+ support_format_hostent \
+ support_format_netent \
support_record_failure \
+ support_run_diff \
support_test_main \
support_test_verify_impl \
temp_file \
write_message \
+ xaccept \
xasprintf \
+ xbind \
xcalloc \
+ xconnect \
+ xfclose \
+ xfopen \
xfork \
+ xgetsockname \
+ xlisten \
xmalloc \
+ xmemstream \
+ xpoll \
xpthread_barrier_destroy \
xpthread_barrier_init \
xpthread_barrier_wait \
@@ -52,12 +73,18 @@ libsupport-routines = \
xpthread_join \
xpthread_mutex_lock \
xpthread_mutex_unlock \
+ xpthread_once \
xpthread_sigmask \
xpthread_spin_lock \
xpthread_spin_unlock \
xrealloc \
+ xrecvfrom \
+ xsendto \
+ xsetsockopt \
xsocket \
+ xstrdup \
xwaitpid \
+ xwrite \
libsupport-static-only-routines := $(libsupport-routines)
# Only build one variant of the library.
diff --git a/support/check_addrinfo.c b/support/check_addrinfo.c
new file mode 100644
index 0000000000..793b34fef3
--- /dev/null
+++ b/support/check_addrinfo.c
@@ -0,0 +1,42 @@
+/* Compare struct addrinfo values against a formatted string.
+ Copyright (C) 2016 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <support/check_nss.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <support/check.h>
+#include <support/format_nss.h>
+#include <support/run_diff.h>
+
+void
+check_addrinfo (const char *query_description, struct addrinfo *ai, int ret,
+ const char *expected)
+{
+ char *formatted = support_format_addrinfo (ai, ret);
+ if (strcmp (formatted, expected) != 0)
+ {
+ support_record_failure ();
+ printf ("error: addrinfo comparison failure\n");
+ if (query_description != NULL)
+ printf ("query: %s\n", query_description);
+ support_run_diff ("expected", expected,
+ "actual", formatted);
+ }
+ free (formatted);
+}
diff --git a/support/check_dns_packet.c b/support/check_dns_packet.c
new file mode 100644
index 0000000000..a2c16b118d
--- /dev/null
+++ b/support/check_dns_packet.c
@@ -0,0 +1,42 @@
+/* Check that a DNS packet buffer has the expected contents.
+ Copyright (C) 2016 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <support/check_nss.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <support/check.h>
+#include <support/format_nss.h>
+#include <support/run_diff.h>
+
+void
+check_dns_packet (const char *query_description,
+ const unsigned char *buffer, size_t length,
+ const char *expected)
+{
+ char *formatted = support_format_dns_packet (buffer, length);
+ if (strcmp (formatted, expected) != 0)
+ {
+ support_record_failure ();
+ printf ("error: packet comparison failure\n");
+ if (query_description != NULL)
+ printf ("query: %s\n", query_description);
+ support_run_diff ("expected", expected, "actual", formatted);
+ }
+ free (formatted);
+}
diff --git a/support/check_hostent.c b/support/check_hostent.c
new file mode 100644
index 0000000000..b0661b1173
--- /dev/null
+++ b/support/check_hostent.c
@@ -0,0 +1,42 @@
+/* Compare struct hostent values against a formatted string.
+ Copyright (C) 2016 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <support/check_nss.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <support/check.h>
+#include <support/format_nss.h>
+#include <support/run_diff.h>
+
+void
+check_hostent (const char *query_description, struct hostent *h,
+ const char *expected)
+{
+ char *formatted = support_format_hostent (h);
+ if (strcmp (formatted, expected) != 0)
+ {
+ support_record_failure ();
+ printf ("error: hostent comparison failure\n");
+ if (query_description != NULL)
+ printf ("query: %s\n", query_description);
+ support_run_diff ("expected", expected,
+ "actual", formatted);
+ }
+ free (formatted);
+}
diff --git a/support/check_netent.c b/support/check_netent.c
new file mode 100644
index 0000000000..f20862403c
--- /dev/null
+++ b/support/check_netent.c
@@ -0,0 +1,42 @@
+/* Compare struct netent values against a formatted string.
+ Copyright (C) 2016 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <support/check_nss.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <support/check.h>
+#include <support/format_nss.h>
+#include <support/run_diff.h>
+
+void
+check_netent (const char *query_description, struct netent *e,
+ const char *expected)
+{
+ char *formatted = support_format_netent (e);
+ if (strcmp (formatted, expected) != 0)
+ {
+ support_record_failure ();
+ printf ("error: netent comparison failure\n");
+ if (query_description != NULL)
+ printf ("query: %s\n", query_description);
+ support_run_diff ("expected", expected,
+ "actual", formatted);
+ }
+ free (formatted);
+}
diff --git a/support/check_nss.h b/support/check_nss.h
new file mode 100644
index 0000000000..6ab2824327
--- /dev/null
+++ b/support/check_nss.h
@@ -0,0 +1,42 @@
+/* Test verification functions for NSS- and DNS-related data.
+ Copyright (C) 2016 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#ifndef SUPPORT_CHECK_NSS_H
+#define SUPPORT_CHECK_NSS_H
+
+#include <netdb.h>
+#include <sys/cdefs.h>
+
+__BEGIN_DECLS
+
+/* Compare the data structures against the expected values (which have
+ to be formatted according to the support_format_* functions in
+ <support/format_nss.h>). If there is a difference, a delayed test
+ failure is recorded, and a diff is written to standard output. */
+void check_addrinfo (const char *query_description,
+ struct addrinfo *, int ret, const char *expected);
+void check_dns_packet (const char *query_description,
+ const unsigned char *, size_t, const char *expected);
+void check_hostent (const char *query_description,
+ struct hostent *, const char *expected);
+void check_netent (const char *query_description,
+ struct netent *, const char *expected);
+
+__END_DECLS
+
+#endif /* SUPPORT_CHECK_NSS_H */
diff --git a/support/format_nss.h b/support/format_nss.h
new file mode 100644
index 0000000000..07e32f5fd1
--- /dev/null
+++ b/support/format_nss.h
@@ -0,0 +1,41 @@
+/* String formatting functions for NSS- and DNS-related data.
+ Copyright (C) 2016 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#ifndef SUPPORT_FORMAT_NSS_H
+#define SUPPORT_FORMAT_NSS_H
+
+#include <netdb.h>
+#include <sys/cdefs.h>
+
+__BEGIN_DECLS
+
+/* The following functions format their arguments as human-readable
+ strings (which can span multiple lines). The caller must free the
+ returned buffer. For NULL pointers or failure status arguments,
+ error variables such as h_errno and errno are included in the
+ result. */
+char *support_format_address_family (int);
+char *support_format_addrinfo (struct addrinfo *, int ret);
+char *support_format_dns_packet (const unsigned char *buffer, size_t length);
+char *support_format_herrno (int);
+char *support_format_hostent (struct hostent *);
+char *support_format_netent (struct netent *);
+
+__END_DECLS
+
+#endif /* SUPPORT_FORMAT_NSS_H */
diff --git a/support/resolv_test.c b/support/resolv_test.c
new file mode 100644
index 0000000000..80d8c74f5a
--- /dev/null
+++ b/support/resolv_test.c
@@ -0,0 +1,1150 @@
+/* DNS test framework and libresolv redirection.
+ Copyright (C) 2016 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <support/resolv_test.h>
+
+#include <arpa/inet.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <nss.h>
+#include <resolv.h>
+#include <search.h>
+#include <stdlib.h>
+#include <string.h>
+#include <support/check.h>
+#include <support/namespace.h>
+#include <support/support.h>
+#include <support/test-driver.h>
+#include <support/xsocket.h>
+#include <support/xthread.h>
+#include <unistd.h>
+
+/* Response builder. */
+
+enum
+ {
+ max_response_length = 65536
+ };
+
+/* List of pointers to be freed. The hash table implementation
+ (struct hsearch_data) does not provide a way to deallocate all
+ objects, so this approach is used to avoid memory leaks. */
+struct to_be_freed
+{
+ struct to_be_freed *next;
+ void *ptr;
+};
+
+struct resolv_response_builder
+{
+ const unsigned char *query_buffer;
+ size_t query_length;
+
+ size_t offset; /* Bytes written so far in buffer. */
+ ns_sect section; /* Current section in the DNS packet. */
+ unsigned int truncate_bytes; /* Bytes to remove at end of response. */
+ bool drop;