]> git.puffer.fish Git - matthieu/frr.git/commitdiff
tests: add c-ares "exercise" tool
authorDavid Lamparter <equinox@opensourcerouting.org>
Sun, 7 Nov 2021 14:54:55 +0000 (15:54 +0100)
committerDavid Lamparter <equinox@opensourcerouting.org>
Mon, 8 Nov 2021 13:06:21 +0000 (14:06 +0100)
This can't really be run as part of CI, it's intended as a helper
instead, to use manually after poking around in the c-ares binding code.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
tests/.gitignore
tests/lib/test_resolver.c [new file with mode: 0644]
tests/subdir.am

index 8cc2aa98f92b081a41574c76a640aef8283f61c3..53dbd68c9ab6ed50b591f3a9f47a9376fd95c797 100644 (file)
@@ -41,6 +41,7 @@
 /lib/test_prefix2str
 /lib/test_printfrr
 /lib/test_privs
+/lib/test_resolver
 /lib/test_ringbuf
 /lib/test_segv
 /lib/test_seqlock
diff --git a/tests/lib/test_resolver.c b/tests/lib/test_resolver.c
new file mode 100644 (file)
index 0000000..0b3dccc
--- /dev/null
@@ -0,0 +1,81 @@
+/*
+ * FRR c-ares integration test
+ * Copyright (C) 2021  David Lamparter for NetDEF, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ * This program 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 General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; see the file COPYING; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/* this test is not run automatically since tests MUST NOT rely on any outside
+ * state.  DNS is most definitely "outside state".  A testbed may not have any
+ * internet connectivity at all.  It may not have working DNS.  Or worst of
+ * all, whatever name we use to test may have a temporary failure entirely
+ * beyond our control.
+ *
+ * The only way this test could be run in a testbed is with an all-local DNS
+ * setup, which considering the resolver code is rarely touched is not worth
+ * the time at all.  Instead, after touching the resolver code, manually run
+ * this test and throw some names at it.
+ */
+
+#include <zebra.h>
+
+#include "vty.h"
+#include "command.h"
+#include "resolver.h"
+#include "log.h"
+#include "sockunion.h"
+
+#include "tests/lib/cli/common_cli.h"
+
+extern struct thread_master *master;
+
+static void resolver_result(struct resolver_query *resq, const char *errstr,
+                           int numaddrs, union sockunion *addr)
+{
+       int i;
+
+       if (numaddrs <= 0) {
+               zlog_warn("hostname resolution failed: %s", errstr);
+               return;
+       }
+
+       for (i = 0; i < numaddrs; i++)
+               zlog_info("resolver result: %pSU", &addr[i]);
+}
+
+struct resolver_query query;
+
+DEFUN (test_resolve,
+       test_resolve_cmd,
+       "resolve WORD",
+       "DNS resolver\n"
+       "Name to resolve\n")
+{
+       resolver_resolve(&query, AF_UNSPEC, argv[1]->arg, resolver_result);
+       return CMD_SUCCESS;
+}
+
+__attribute__((_CONSTRUCTOR(2000)))
+static void test_setup(void)
+{
+       test_log_prio = LOG_DEBUG;
+}
+
+void test_init(int argc, char **argv)
+{
+       resolver_init(master);
+
+       install_element(VIEW_NODE, &test_resolve_cmd);
+}
index f21e12ecbb38aff48936b20ba7626839241edb05..cd6e4101dd6844ff1e678786aef8ce0cad2d3a45 100644 (file)
@@ -132,6 +132,12 @@ check_PROGRAMS += \
        # end
 endif
 
+if CARES
+check_PROGRAMS += \
+       tests/lib/test_resolver \
+       # end
+endif
+
 tests/lib/cli/test_commands_defun.c: vtysh/vtysh_cmd.c
        mkdir -p tests/lib/cli
        sed \
@@ -351,6 +357,10 @@ tests_lib_test_privs_CFLAGS = $(TESTS_CFLAGS)
 tests_lib_test_privs_CPPFLAGS = $(TESTS_CPPFLAGS)
 tests_lib_test_privs_LDADD = $(ALL_TESTS_LDADD)
 tests_lib_test_privs_SOURCES = tests/lib/test_privs.c
+tests_lib_test_resolver_CFLAGS = $(TESTS_CFLAGS)
+tests_lib_test_resolver_CPPFLAGS = $(TESTS_CPPFLAGS)
+tests_lib_test_resolver_LDADD = $(ALL_TESTS_LDADD) lib/libfrrcares.la
+tests_lib_test_resolver_SOURCES = tests/lib/test_resolver.c tests/lib/cli/common_cli.c
 tests_lib_test_ringbuf_CFLAGS = $(TESTS_CFLAGS)
 tests_lib_test_ringbuf_CPPFLAGS = $(TESTS_CPPFLAGS)
 tests_lib_test_ringbuf_LDADD = $(ALL_TESTS_LDADD)