nfs-utils: add testing infrastructure to nfs-utils (try #5)
Subsystems (3)
cover nfs-utils: add testing infrastructure to nfs-utils (try #5)
This is an updated patchset for adding test infrastructure to nfs-utils. The main differences in this patchset are mostly small cleanups and changes response to comments from Chuck Lever.
This patchset is intended as a starting point for an automated test suite for nfs-utils. The idea here is to start simply and add a suite of tests that we can run via "make check" -- the standard automake method for running tests.
Clearly there are limits to what we can test without a multi-host test harness. My hope is that this should help keep us from breaking basic functionality by allowing us to test it in a very simple fashion. At some point in the future we should also consider how to best handle multi-machine testing, but I see that as complimenting this code rather than replacing it.
For this set, the focus is on testing statd, which is particularly susceptible to subtle breakage. Problems with it are often not noticed until lock recovery breaks, and that may greatly lag the actual breakage.
To faciitate statd testing, I've added a "nsm_client" program that can serve as a synthetic statd client and an NLM simulator. It's very loosely based on the old statd simulator code. That program is dependent on some of Chuck Lever's recent statd patches -- notably the ones that break out common NSM code into libnsm.a.
For this initial drop, I'm just adding a single test that tests mon and unmon functionality with statd. Adding more tests should be fairly simple to do.
Jeff Layton (4):
nfs-utils: make private cookie to hex conversion a library routine
nfs-utils: introduce new statd testing simulator
nfs-utils: add statdb_dump utility
nfs-utils: add initial tests for statd that run via "make check"
Makefile.am | 2 +- configure.ac | 4 +- support/include/nsm.h | 2 + support/nsm/file.c | 44 +++- tests/Makefile.am | 13 + tests/nsm_client/Makefile.am | 45 ++++ tests/nsm_client/README | 12 + tests/nsm_client/nlm_sm_inter.x | 43 +++ tests/nsm_client/nsm_client.c | 465 ++++++++++++++++++++++++++++++++++ tests/statdb_dump.c | 99 +++++++ tests/t0001-statd-basic-mon-unmon.sh | 55 ++++ tests/test-lib.sh | 48 ++++ 12 files changed, 820 insertions(+), 12 deletions(-) create mode 100644 tests/Makefile.am create mode 100644 tests/nsm_client/Makefile.am create mode 100644 tests/nsm_client/README create mode 100644 tests/nsm_client/nlm_sm_inter.x create mode 100644 tests/nsm_client/nsm_client.c create mode 100644 tests/statdb_dump.c create mode 100755 tests/t0001-statd-basic-mon-unmon.sh create mode 100755 tests/test-lib.sh
PATCH 1/4 nfs-utils: make private cookie to hex conversion a library routine
--- support/include/nsm.h | 2 ++ support/nsm/file.c | 44 ++++++++++++++++++++++++++++++++++---------- 2 files changed, 36 insertions(+), 10 deletions(-)
support/include/nsm.h +2 -0
@@ -69,6 +69,8 @@ extern _Bool nsm_insert_monitored_host(const char *hostname, const struct sockaddr *sap, const struct mon *m);extern void nsm_delete_monitored_host (const char *hostname);extern void nsm_delete_notified_host (const char *hostname); +extern size_t nsm_priv_to_hex (const char *priv,char *buf, +const size_t buflen);/* rpc.c */
support/nsm/file.c +34 -10
62 lines not on this page · raw message
Signature · 1 line
1.6.5.2
Re: [PATCH 1/4] nfs-utils: make private cookie to hex conversion a library routine
Quoted 26 lines · Jeff Layton
Signed-off-by Jeff Layton <[email protected]>---
support/include/nsm.h| 2 ++support/nsm/file.c| 44 +++++++++++++++++++++++++++++++++
+----------2 files changed, 36 insertions(+), 10 deletions(-)support/include/nsm.h +2
-0@@ -69,6 +69,8 @@ extern _Bool nsm_insert_monitored_host(const char *hostname, const struct sockaddr *sap, const struct mon *m);extern void nsm_delete_monitored_host (const char *hostname);extern void nsm_delete_notified_host (const char *hostname); +extern size_t nsm_priv_to_hex (const char *priv,char *buf, +const size_t buflen);/* rpc.c */ support/nsm/file.c +0
-0
support/nsm/file.c nsm_retire_monitored_hosts(void) · line 684
Quoted 7 lines
support/nsm/file.c +4
-0@@ -678,6 +678,33 @@ nsm_retire_monitored_hosts(void) }/* +* nsm_priv_to_hex - convert a NSM private cookie to a hex string. +* +* @priv: buffer holding the binary NSM private cookie +* @buf: output buffer for hex string
If you're going to respin anyway, this comment should mention that the output string is terminated with '\0'.
Quoted 58 lines
support/nsm/file.c +23
-0+* @buflen: size of output buffer +* +* Returns the length of the resulting string or 0 on error. +*/ +size_t +nsm_priv_to_hex (const char *priv,char *buf,const size_t buflen) +{ +int i, len; +size_t remaining = buflen; + +for (i =0 ; i <SM_PRIV_SIZE ; i++) { + len =snprintf (buf, remaining,"%02x" , + (unsigned int )(0xff & priv[i])); +if (error_check (len, remaining)) +return 0 ; + buf += len; + remaining -= (size_t )len; + } + +return buflen - remaining; +} + +/* * Returns the length in bytes of the created record. */
__attribute_noinline__support/nsm/file.c +2
-2@@ -686,8 +713,8 @@ nsm_create_monitor_record(char *buf, constsize_t buflen, const struct sockaddr *sap, const struct mon *m) { const struct sockaddr_in *sin = (const struct sockaddr_in *)sap; -size_t remaining = buflen; -int i, len; +size_t hexlen, remaining = buflen; +int len; len = snprintf(buf, remaining, "%08x %08x %08x %08x ",(unsigned int)sin->sin_addr.s_addr,support/nsm/file.c +5
-8@@ -699,14 +726,11 @@ nsm_create_monitor_record(char *buf, constsize_t buflen, buf += len; remaining -= (size_t )len; -for (i =0 ; i <SM_PRIV_SIZE ; i++) { - len =snprintf (buf, remaining,"%02x" , - (unsigned int )(0xff & m->priv[i])); -if (error_check (len, remaining)) -return 0 ; - buf += len; - remaining -= (size_t )len; - } + hexlen =nsm_priv_to_hex (m->priv, buf, remaining); +if (hexlen ==0 ) +return 0 ; + buf += hexlen; + remaining -= hexlen; len = snprintf(buf, remaining, " %s %s\n",
Quoted 4 lines
m->mon_id.mon_name, m->mon_id.my_id.my_name);Signature · 1 line
1.6.5.2
--
Chuck Lever
chuck[dot]lever[at]oracle[dot]com
PATCH 2/4 nfs-utils: introduce new statd testing simulator
In reply to Jeff Laytonrpc.statd is often prone to subtle, difficult to detect breakage. When it has problems, they're often invisible and only manifest themselves as failed lock recovery.
This program is intended to function as part of a test harness for statd. It's a multicall binary that serves as a synthetic NSM client program, and a daemon that can simulate lockd for purposes of testing the NSM to NLM downcall.
A new top level "tests/" directory is also added to nfs-utils to start as a repository for automated tests of nfs-utils components.
--- Makefile.am | 2 +- configure.ac | 4 +- tests/Makefile.am | 5 + tests/nsm_client/Makefile.am | 45 ++++ tests/nsm_client/README | 12 + tests/nsm_client/nlm_sm_inter.x | 43 ++++ tests/nsm_client/nsm_client.c | 465 +++++++++++++++++++++++++++++++++++++++ 7 files changed, 574 insertions(+), 2 deletions(-) create mode 100644 tests/Makefile.am create mode 100644 tests/nsm_client/Makefile.am create mode 100644 tests/nsm_client/README create mode 100644 tests/nsm_client/nlm_sm_inter.x create mode 100644 tests/nsm_client/nsm_client.c
Makefile.am +1 -1
@@ -2,7 +2,7 @@ AUTOMAKE_OPTIONS = foreign -SUBDIRS = tools support utils linux-nfs +SUBDIRS = tools support utils linux-nfs tests MAINTAINERCLEANFILES = Makefile.in
configure.ac +3 -1
@@ -420,6 +420,8 @@ AC_CONFIG_FILES([ utils/nfsd/Makefile utils/nfsstat/Makefile utils/showmount/Makefile - utils/statd/Makefile]) + utils/statd/Makefile + tests/Makefile + tests/nsm_client/Makefile]) AC_OUTPUT
tests/Makefile.am new file +5 -0
@@ -0,0 +1,5 @@ +## Process this file with automake to produce Makefile.in + +SUBDIRS = nsm_client + +MAINTAINERCLEANFILES = Makefile.in
tests/nsm_client/Makefile.am new file +45 -0
45 lines not on this page · raw message
tests/nsm_client/README new file +12 -0
@@ -0,0 +1,12 @@ +The nsm_client program is intended for testing statd. It has the ability +to act as a synthetic NSM client for sending artificial NSM calls to any +host you choose. + +It also has an NLM simulator that implements the call that statd uses to +communicate with lockd. The daemon simulator will start itself up, +register as an NLM service and listen for "downcalls" from statd. When +it gets one, it will log a message. + +Note that lockd will need to be down when using the daemon simulator. It +also does not implement the entire NLM protocol and is only really +useful for testing statd's downcall.
tests/nsm_client/nlm_sm_inter.x new file +43 -0
43 lines not on this page · raw message
tests/nsm_client/nsm_client.c new file +465 -0
465 lines not on this page · raw message
Signature · 1 line
1.6.5.2
PATCH 3/4 nfs-utils: add statdb_dump utility
In reply to Jeff LaytonTo dump contents of statd's monitor DB.
--- tests/Makefile.am | 6 +++ tests/statdb_dump.c | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 105 insertions(+), 0 deletions(-) create mode 100644 tests/statdb_dump.c
tests/Makefile.am +6 -0
@@ -1,5 +1,11 @@ ## Process this file with automake to produce Makefile.in +check_PROGRAMS = statdb_dump +statdb_dump_SOURCES = statdb_dump.c + +statdb_dump_LDADD = ../support/nfs/libnfs.a \ + ../support/nsm/libnsm.a $(LIBCAP) + SUBDIRS = nsm_client MAINTAINERCLEANFILES = Makefile.in
tests/statdb_dump.c new file +99 -0
99 lines not on this page · raw message
Signature · 1 line
1.6.5.2
Re: [PATCH 3/4] nfs-utils: add statdb_dump utility
Quoted 56 lines · Jeff Layton
To dump contents of statd's monitor DB.
Signed-off-by Jeff Layton <[email protected]>---
tests/Makefile.am | 6 +++tests/statdb_dump.c| 99 ++++++++++++++++++++++++++++++++++++++++++
+++++++++2 files changed, 105 insertions(+), 0 deletions(-)create mode 100644
tests/statdb_dump.ctests/Makefile.am +6
-0@@ -1,5 +1,11 @@ ## Process this file with automake to produce Makefile.in +check_PROGRAMS = statdb_dump +statdb_dump_SOURCES = statdb_dump.c + +statdb_dump_LDADD = ../support/nfs/libnfs.a \ + ../support/nsm/libnsm.a $(LIBCAP) +SUBDIRS =
nsm_clientMAINTAINERCLEANFILES = Makefile.in
tests/statdb_dump.c new file +24
-0@@ -0,0 +1,99 @@ +/* +* statdb_dump.c -- dump contents of statd's monitor DB +* +* Copyright (C) 2010 Red Hat, Jeff Layton <[email protected]> +* +* 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; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, +* Boston, MA 02110-1301, USA. +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif
tests/statdb_dump.c line 34
Quoted 10 lines
tests/statdb_dump.c new file +10
-0+ +#include <stdio.h> +#include <errno.h> +#include <arpa/inet.h> + +#include "nsm.h" +#include "xlog.h" + +static char cookiebuf[(SM_PRIV_SIZE *2 ) +1 ]; +static char addrbuf[INET6_ADDRSTRLEN +1 ];
Just a nit, but if you use these only inside of dump_host(), you could declare them in there too, even though they are static. Both are pretty small buffers, so you could just as easily put them on the stack, I suppose.
tests/statdb_dump.c line 43
Quoted 10 lines
tests/statdb_dump.c new file +3
-0+ +static unsigned int +dump_host(const char *hostname, const struct sockaddr *sa, conststruct mon *m,
tests/statdb_dump.c new file +6
-0+ const time_t timestamp) +{ +int ret; +const char *addr; +struct sockaddr_in *sin; +struct sockaddr_in6 *sin6;
Since *sa is a const pointer, do these need to be const as well?
tests/statdb_dump.c line 53
Quoted 10 lines
tests/statdb_dump.c new file +10
-0+ + ret =nsm_priv_to_hex (m->priv, cookiebuf,sizeof (cookiebuf)); +if (!ret) { +xlog (L_ERROR ,"Unable to convert cookie to hex string.\n" ); +return ret; + } + +switch (sa->sa_family) { +case AF_INET : + sin = (struct sockaddr_in *)sa;
If you build with -Wstrict-aliasing=2 (I think) you might see some warnings about pointer aliasing here. I'm pretty sure if you cast to (char *) you will eliminate that warning, and help the compiler create better optimized code.
tests/statdb_dump.c line 55
Quoted 2 lines
tests/statdb_dump.c new file +2
-0+ addr =inet_ntop (sa->sa_family, &sin->sin_addr.s_addr, addrbuf, +sizeof (*sin));
As you discovered, this needs to be (socklen_t)sizeof(addrbuf), not sizeof(*sin). Likewise below.
Quoted 48 lines
tests/statdb_dump.c new file +44
-0+break ; +case AF_INET6 : + sin6 = (struct sockaddr_in6 *)sa; + addr =inet_ntop (sa->sa_family, &sin6->sin6_addr, addrbuf, +sizeof (*sin6)); +break ; +default : +xlog (L_ERROR ,"Unrecognized address family: %hu\n" , + sa->sa_family); +return 0 ; + } + +if (addr ==NULL ) { +xlog (L_ERROR ,"Unable to convert sockaddr to string: %s\n" , +strerror (errno)); +return 0 ; + } + +/* +* Callers of this program should assume that in the future, extra +* fields may be added to the output. Anyone adding extra fields to +* the output should add them to the end of the line. +*/ +printf ("%s %s %s %s %s %d %d %d\n" , + hostname, addr, cookiebuf, + m->mon_id.mon_name, + m->mon_id.my_id.my_name, + m->mon_id.my_id.my_prog, + m->mon_id.my_id.my_vers, + m->mon_id.my_id.my_proc); + +return 1 ; +} + +int +main (int argc,char **argv) +{ +xlog_syslog (0 ); +xlog_stderr (1 ); +xlog_open (argv[0 ]); + +nsm_load_monitor_list (dump_host); +return 0 ; +}Signature · 1 line
1.6.5.2
--
Chuck Lever
chuck[dot]lever[at]oracle[dot]com
PATCH 4/4 nfs-utils: add initial tests for statd that run via "make check"
In reply to Jeff LaytonLeverage the support that automake already has for running tests via make check. Add a simple test that just checks that the statd mon and unmon calls actually work.
Adding more tests should be a simple matter of adding new scripts exit 0 on success and non-zero on fail, and adding those to the Makefile.am.
--- tests/Makefile.am | 2 + tests/t0001-statd-basic-mon-unmon.sh | 55 ++++++++++++++++++++++++++++++++++ tests/test-lib.sh | 48 +++++++++++++++++++++++++++++ 3 files changed, 105 insertions(+), 0 deletions(-) create mode 100755 tests/t0001-statd-basic-mon-unmon.sh create mode 100755 tests/test-lib.sh
tests/Makefile.am +2 -0
@@ -9,3 +9,5 @@ statdb_dump_LDADD = ../support/nfs/libnfs.a \ SUBDIRS = nsm_client MAINTAINERCLEANFILES = Makefile.in + +TESTS = t0001-statd-basic-mon-unmon.sh
tests/t0001-statd-basic-mon-unmon.sh new file +55 -0
55 lines not on this page · raw message
tests/test-lib.sh new file +48 -0
48 lines not on this page · raw message
Signature · 1 line
1.6.5.2