]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Add facility to run system test nameds under Valgrind (#38546)
authorMukund Sivaraman <muks@isc.org>
Wed, 25 Feb 2015 03:36:45 +0000 (09:06 +0530)
committerMukund Sivaraman <muks@isc.org>
Wed, 25 Feb 2015 03:36:45 +0000 (09:06 +0530)
bin/named/include/named/main.h
bin/named/main.c
bin/named/named.docbook
bin/named/win32/ntservice.c
bin/tests/system/README
bin/tests/system/start.pl
lib/isc/include/isc/mem.h
lib/isc/mem.c

index 1537fb641da60bea6ed23b8d4bca550319629fa2..a54175a4ee31ed0d22a54c63d3721109f684074c 100644 (file)
@@ -15,8 +15,6 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: main.h,v 1.17 2009/09/29 23:48:03 tbox Exp $ */
-
 #ifndef NAMED_MAIN_H
 #define NAMED_MAIN_H 1
 
 #define main(argc, argv) bindmain(argc, argv)
 #endif
 
+/*
+ * Commandline arguments for named; also referenced in win32/ntservice.c
+ */
+#define NS_MAIN_ARGS "46c:C:d:D:E:fFgi:lL:M:m:n:N:p:P:sS:t:T:U:u:vVx:X:"
+
 ISC_PLATFORM_NORETURN_PRE void
 ns_main_earlyfatal(const char *format, ...)
 ISC_FORMAT_PRINTF(1, 2) ISC_PLATFORM_NORETURN_POST;
index caf4af35a4e096fed7f1b9c5f7e3c7dcc582f24c..70fbb3a2fb17c6abe8643411c0a804a2286876a2 100644 (file)
@@ -387,6 +387,7 @@ static struct flag_def {
        const char *name;
        unsigned int value;
 } mem_debug_flags[] = {
+       { "none", 0},
        { "trace",  ISC_MEM_DEBUGTRACE },
        { "record", ISC_MEM_DEBUGRECORD },
        { "usage", ISC_MEM_DEBUGUSAGE },
@@ -397,6 +398,8 @@ static struct flag_def {
 
 static void
 set_flags(const char *arg, struct flag_def *defs, unsigned int *ret) {
+       isc_boolean_t clear = ISC_FALSE;
+
        for (;;) {
                const struct flag_def *def;
                const char *end = strchr(arg, ',');
@@ -407,16 +410,21 @@ set_flags(const char *arg, struct flag_def *defs, unsigned int *ret) {
                for (def = defs; def->name != NULL; def++) {
                        if (arglen == (int)strlen(def->name) &&
                            memcmp(arg, def->name, arglen) == 0) {
+                               if (def->value == 0)
+                                       clear = ISC_TRUE;
                                *ret |= def->value;
                                goto found;
                        }
                }
                ns_main_earlyfatal("unrecognized flag '%.*s'", arglen, arg);
         found:
-               if (*end == '\0')
+               if (clear || (*end == '\0'))
                        break;
                arg = end + 1;
        }
+
+       if (clear)
+               *ret = 0;
 }
 
 static void
@@ -427,10 +435,12 @@ parse_command_line(int argc, char *argv[]) {
 
        save_command_line(argc, argv);
 
-       /* PLEASE keep options synchronized when main is hooked! */
-#define CMDLINE_FLAGS "46c:C:d:D:E:fFgi:lL:m:n:N:p:P:sS:t:T:U:u:vVx:X:"
+       /*
+        * NS_MAIN_ARGS is defined in main.h, so that it can be used
+        * both by named and by ntservice hooks.
+        */
        isc_commandline_errprint = ISC_FALSE;
-       while ((ch = isc_commandline_parse(argc, argv, CMDLINE_FLAGS)) != -1) {
+       while ((ch = isc_commandline_parse(argc, argv, NS_MAIN_ARGS)) != -1) {
                switch (ch) {
                case '4':
                        if (ns_g_disable4)
@@ -488,6 +498,10 @@ parse_command_line(int argc, char *argv[]) {
                case 'L':
                        ns_g_logfile = isc_commandline_argument;
                        break;
+               case 'M':
+                       if (strcmp(isc_commandline_argument, "external") == 0)
+                               isc_mem_defaultflags = 0;
+                       break;
                case 'm':
                        set_flags(isc_commandline_argument, mem_debug_flags,
                                  &isc_mem_debugging);
@@ -665,7 +679,7 @@ parse_command_line(int argc, char *argv[]) {
                        usage();
                        if (isc_commandline_option == '?')
                                exit(0);
-                       p = strchr(CMDLINE_FLAGS, isc_commandline_option);
+                       p = strchr(NS_MAIN_ARGS, isc_commandline_option);
                        if (p == NULL || *++p != ':')
                                ns_main_earlyfatal("unknown option '-%c'",
                                                   isc_commandline_option);
index 28e7b7c9dbc98a4aa7a8c295f7d8148515175c2f..173d17e8a5ec3c7ec7e4d6dbb922e682cd78d781 100644 (file)
@@ -67,6 +67,7 @@
       <arg><option>-f</option></arg>
       <arg><option>-g</option></arg>
       <arg><option>-L <replaceable class="parameter">logfile</replaceable></option></arg>
+      <arg><option>-M <replaceable class="parameter">option</replaceable></option></arg>
       <arg><option>-m <replaceable class="parameter">flag</replaceable></option></arg>
       <arg><option>-n <replaceable class="parameter">#cpus</replaceable></option></arg>
       <arg><option>-p <replaceable class="parameter">port</replaceable></option></arg>
         </listitem>
       </varlistentry>
 
+      <varlistentry>
+        <term>-M <replaceable class="parameter">option</replaceable></term>
+        <listitem>
+          <para>
+           Sets the default memory context options.  Currently
+           the only supported option is
+           <replaceable class="parameter">external</replaceable>,
+           which causes the internal memory manager to be bypassed
+           in favor of system-provided memory allocation functions.
+          </para>
+        </listitem>
+      </varlistentry>
+
       <varlistentry>
         <term>-m <replaceable class="parameter">flag</replaceable></term>
         <listitem>
index 83e71c170690824fca4ad9269451cb32f1c616c3..c1d342cebdb445b3ad16e5f5b9304de2d1a5af24 100644 (file)
@@ -140,9 +140,7 @@ int main(int argc, char *argv[])
 
        /* Command line users should put -f in the options. */
        isc_commandline_errprint = ISC_FALSE;
-       while ((ch = isc_commandline_parse(argc, argv,
-                                          "46c:C:d:D:E:fFgi:lm:n:N:p:P:"
-                                          "sS:t:T:U:u:vVx:")) != -1) {
+       while ((ch = isc_commandline_parse(argc, argv, NS_MAIN_ARGS)) != -1) {
                switch (ch) {
                case 'f':
                case 'g':
index 2145a444a3173d5abac8dc5161f74c39e1928ba8..8b4a3bfda82c49ff1adaafcb8a6e2c834d299362 100644 (file)
@@ -59,4 +59,7 @@ The tests can be run individually like this:
 
 To run all the tests, just type "make test".
 
-$Id: README,v 1.16 2011/01/13 04:59:24 tbox Exp $
+When running system tests, named and lwresd can be run under
+Valgrind. The output from Valgrind are sent to per-process files that
+can be reviewed after the test has completed. To enable this, set the
+USE_VALGRIND environment variable.
index bfd4c84e724be67549bfddb584ded7660570a9e3..02d7873a99105124645c67ff7b156f9b65ab5f33 100644 (file)
@@ -149,7 +149,11 @@ sub start_server {
 
        if ($server =~ /^ns/) {
                $cleanup_files = "{*.jnl,*.bk,*.st,named.run}";
-               $command = "$NAMED ";
+               if ($ENV{'USE_VALGRIND'}) {
+                       $command = "valgrind -q --gen-suppressions=all --track-origins=yes --num-callers=48 --leak-check=full --fullpath-after= --log-file=named-$server-valgrind-%p.log $NAMED -m none -M external ";
+               } else {
+                       $command = "$NAMED ";
+               }
                if ($options) {
                        $command .= "$options";
                } elsif (-e $args_file) {
@@ -195,7 +199,11 @@ sub start_server {
                $pid_file = "named.pid";
        } elsif ($server =~ /^lwresd/) {
                $cleanup_files = "{lwresd.run}";
-               $command = "$LWRESD ";
+               if ($ENV{'USE_VALGRIND'}) {
+                       $command = "valgrind -q --gen-suppressions=all --track-origins=yes --num-callers=48 --leak-check=full --fullpath-after= --log-file=lwresd-valgrind-%p.log $LWRESD -m none -M external ";
+               } else {
+                       $command = "$LWRESD ";
+               }
                if ($options) {
                        $command .= "$options";
                } else {
index 2be8a0629ccdc31d5536f731c9f1bb0355c7c2e3..c0847f176b232a2eb61c5382b9c18aea0c2c2f67 100644 (file)
@@ -15,8 +15,6 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id$ */
-
 #ifndef ISC_MEM_H
 #define ISC_MEM_H 1
 
@@ -76,6 +74,8 @@ typedef void (*isc_memfree_t)(void *, void *);
 #endif
 
 LIBISC_EXTERNAL_DATA extern unsigned int isc_mem_debugging;
+LIBISC_EXTERNAL_DATA extern unsigned int isc_mem_defaultflags;
+
 /*@{*/
 #define ISC_MEM_DEBUGTRACE             0x00000001U
 #define ISC_MEM_DEBUGRECORD            0x00000002U
index 67f36f411ff9f5cf1f530c09beababa1147c0e0c..2e9308fae2a636cda8a3acc40808bfcfdf0ca955 100644 (file)
@@ -15,8 +15,6 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id$ */
-
 /*! \file */
 
 #include <config.h>
@@ -47,6 +45,7 @@
 #define ISC_MEM_DEBUGGING 0
 #endif
 LIBISC_EXTERNAL_DATA unsigned int isc_mem_debugging = ISC_MEM_DEBUGGING;
+LIBISC_EXTERNAL_DATA unsigned int isc_mem_defaultflags = ISC_MEMFLAG_DEFAULT;
 
 /*
  * Constants.
@@ -888,7 +887,7 @@ isc_mem_createx(size_t init_max_size, size_t target_size,
                 isc_mem_t **ctxp)
 {
        return (isc_mem_createx2(init_max_size, target_size, memalloc, memfree,
-                                arg, ctxp, ISC_MEMFLAG_DEFAULT));
+                                arg, ctxp, isc_mem_defaultflags));
 
 }
 
@@ -2715,12 +2714,12 @@ isc_mem_create(size_t init_max_size, size_t target_size, isc_mem_t **mctxp) {
        if (isc_bind9)
                return (isc_mem_createx2(init_max_size, target_size,
                                         default_memalloc, default_memfree,
-                                        NULL, mctxp, ISC_MEMFLAG_DEFAULT));
+                                        NULL, mctxp, isc_mem_defaultflags));
        LOCK(&createlock);
 
        REQUIRE(mem_createfunc != NULL);
        result = (*mem_createfunc)(init_max_size, target_size, mctxp,
-                                  ISC_MEMFLAG_DEFAULT);
+                                  isc_mem_defaultflags);
 
        UNLOCK(&createlock);