From: Mukund Sivaraman Date: Wed, 25 Feb 2015 03:36:45 +0000 (+0530) Subject: Add facility to run system test nameds under Valgrind (#38546) X-Git-Tag: v9.11.0a1~984 X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=5a505fc4c2e99842052d9409790c7da0b5663bce;p=thirdparty%2Fbind9.git Add facility to run system test nameds under Valgrind (#38546) --- diff --git a/bin/named/include/named/main.h b/bin/named/include/named/main.h index 1537fb641da..a54175a4ee3 100644 --- a/bin/named/include/named/main.h +++ b/bin/named/include/named/main.h @@ -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 @@ -26,6 +24,11 @@ #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; diff --git a/bin/named/main.c b/bin/named/main.c index caf4af35a4e..70fbb3a2fb1 100644 --- a/bin/named/main.c +++ b/bin/named/main.c @@ -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); diff --git a/bin/named/named.docbook b/bin/named/named.docbook index 28e7b7c9dbc..173d17e8a5e 100644 --- a/bin/named/named.docbook +++ b/bin/named/named.docbook @@ -67,6 +67,7 @@ + @@ -212,6 +213,19 @@ + + -M option + + + Sets the default memory context options. Currently + the only supported option is + external, + which causes the internal memory manager to be bypassed + in favor of system-provided memory allocation functions. + + + + -m flag diff --git a/bin/named/win32/ntservice.c b/bin/named/win32/ntservice.c index 83e71c17069..c1d342cebdb 100644 --- a/bin/named/win32/ntservice.c +++ b/bin/named/win32/ntservice.c @@ -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': diff --git a/bin/tests/system/README b/bin/tests/system/README index 2145a444a31..8b4a3bfda82 100644 --- a/bin/tests/system/README +++ b/bin/tests/system/README @@ -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. diff --git a/bin/tests/system/start.pl b/bin/tests/system/start.pl index bfd4c84e724..02d7873a991 100644 --- a/bin/tests/system/start.pl +++ b/bin/tests/system/start.pl @@ -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 { diff --git a/lib/isc/include/isc/mem.h b/lib/isc/include/isc/mem.h index 2be8a0629cc..c0847f176b2 100644 --- a/lib/isc/include/isc/mem.h +++ b/lib/isc/include/isc/mem.h @@ -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 diff --git a/lib/isc/mem.c b/lib/isc/mem.c index 67f36f411ff..2e9308fae2a 100644 --- a/lib/isc/mem.c +++ b/lib/isc/mem.c @@ -15,8 +15,6 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id$ */ - /*! \file */ #include @@ -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);