Skip to content

Commit

Permalink
add new valgrind test for serialize/deserialize functions and fix a
Browse files Browse the repository at this point in the history
wire size problem it found (issue 20)
  • Loading branch information
garlick committed Apr 13, 2011
1 parent 5a08bc7 commit 34a8fc8
Show file tree
Hide file tree
Showing 8 changed files with 264 additions and 19 deletions.
8 changes: 8 additions & 0 deletions ChangeLog
@@ -1,3 +1,11 @@
2011-04-13 Jim Garlick <garlick@llnl.gov>

* libnpfs/np.c : Fix problem with too large wire size found
by valgrind (issue 20).

* tests/misc/t07*, tests/misc/tserialize.c : New valgrind test for
serialize/deserialize functions.

2011-04-12 Jim Garlick <garlick@llnl.gov>

* libnpfs/srv.c, libnpfs/conn.c : Handle unchecked malloc () results.
Expand Down
23 changes: 13 additions & 10 deletions libnpfs/np.c
Expand Up @@ -34,6 +34,9 @@
#include "npfs.h"
#include "npfsimpl.h"

/* wire sizes */
#define QIDSIZE (sizeof(u8) + sizeof(u32) + sizeof(u64))

struct cbuf {
unsigned char *sp;
unsigned char *p;
Expand Down Expand Up @@ -389,7 +392,7 @@ np_create_tauth(u32 fid, char *uname, char *aname, u32 n_uname)
Npfcall *
np_create_rauth(Npqid *aqid)
{
int size = sizeof(*aqid);
int size = QIDSIZE;
Npfcall *fc;
struct cbuf buffer;
struct cbuf *bufp = &buffer;
Expand Down Expand Up @@ -473,7 +476,7 @@ np_create_rattach(Npqid *qid)
struct cbuf *bufp;

bufp = &buffer;
size = 13; /* qid[13] */
size = QIDSIZE; /* qid[13] */
fc = np_create_common(bufp, size, P9_RATTACH);
if (!fc)
return NULL;
Expand Down Expand Up @@ -527,7 +530,7 @@ np_create_rwalk(int nwqid, Npqid *wqids)
}

bufp = &buffer;
size = 2 + nwqid*13; /* nwqid[2] nwqid*wqid[13] */
size = 2 + nwqid*QIDSIZE; /* nwqid[2] nwqid*wqid[13] */
fc = np_create_common(bufp, size, P9_RWALK);
if (!fc)
return NULL;
Expand Down Expand Up @@ -900,7 +903,7 @@ np_create_tlopen(u32 fid, u32 mode)
Npfcall *
np_create_rlopen(Npqid *qid, u32 iounit)
{
int size = sizeof(*qid) + sizeof(u32);
int size = QIDSIZE + sizeof(u32);
struct cbuf buffer;
struct cbuf *bufp = &buffer;
Npfcall *fc;
Expand Down Expand Up @@ -938,7 +941,7 @@ np_create_tlcreate(u32 fid, char *name, u32 flags, u32 mode, u32 gid)
Npfcall *
np_create_rlcreate(struct p9_qid *qid, u32 iounit)
{
int size = sizeof(*qid) + sizeof(u32);
int size = QIDSIZE + sizeof(u32);
Npfcall *fc;
struct cbuf buffer;
struct cbuf *bufp = &buffer;
Expand All @@ -954,7 +957,7 @@ np_create_rlcreate(struct p9_qid *qid, u32 iounit)
Npfcall *
np_create_rsymlink(struct p9_qid *qid)
{
int size = sizeof(*qid);
int size = QIDSIZE;
Npfcall *fc;
struct cbuf buffer;
struct cbuf *bufp = &buffer;
Expand All @@ -969,7 +972,7 @@ np_create_rsymlink(struct p9_qid *qid)
Npfcall *
np_create_rmknod (struct p9_qid *qid)
{
int size = sizeof(*qid);
int size = QIDSIZE;
Npfcall *fc;
struct cbuf buffer;
struct cbuf *bufp = &buffer;
Expand Down Expand Up @@ -1035,7 +1038,7 @@ np_create_rgetattr(u64 valid, struct p9_qid *qid, u32 mode,
u64 btime_sec, u64 btime_nsec,
u64 gen, u64 data_version)
{
int bufsize = sizeof(u64) + sizeof(*qid) + 3*sizeof(u32) + 15*sizeof(u64);
int bufsize = sizeof(u64) + QIDSIZE + 3*sizeof(u32) + 15*sizeof(u64);
Npfcall *fc;
struct cbuf buffer;
struct cbuf *bufp = &buffer;
Expand Down Expand Up @@ -1201,7 +1204,7 @@ np_create_tmkdir(u32 dfid, char *name, u32 mode, u32 gid)
Npfcall *
np_create_rmkdir(struct p9_qid *qid)
{
int size = sizeof(*qid);
int size = QIDSIZE;
Npfcall *fc;
struct cbuf buffer;
struct cbuf *bufp = &buffer;
Expand Down Expand Up @@ -1529,7 +1532,7 @@ np_serialize_p9dirent(Npqid *qid, u64 offset, u8 type, char *name,
{
struct cbuf buffer;
struct cbuf *bufp = &buffer;
int size = sizeof(*qid) + sizeof(u64) + sizeof(u8) + strlen(name) + 2;
int size = QIDSIZE + sizeof(u64) + sizeof(u8) + strlen(name) + 2;
Npstr nstr;
Npqid nqid;

Expand Down
15 changes: 12 additions & 3 deletions tests/misc/Makefile.am
@@ -1,6 +1,14 @@
check_PROGRAMS = tfcntl tsetfsuid tsetfsuidsupp tsetuid tsuppgrp topt tconf

TESTS = t00 t01 t02 t03 t04 t05 t06
check_PROGRAMS = \
tfcntl \
tsetfsuid \
tsetfsuidsupp \
tsetuid \
tsuppgrp \
topt \
tconf \
tserialize

TESTS = t00 t01 t02 t03 t04 t05 t06 t07

CLEANFILES = *.out *.diff *.stats

Expand Down Expand Up @@ -30,5 +38,6 @@ tsetfsuidsupp_SOURCES = tsetfsuidsupp.c $(common_sources)
tfcntl_SOURCES = tfcntl.c $(common_sources)
topt_SOURCES = topt.c $(common_sources)
tconf_SOURCES = tconf.c $(common_sources)
tserialize_SOURCES = tserialize.c $(common_sources)

EXTRA_DIST = $(TESTS) $(TESTS:%=%.exp) t06.conf
27 changes: 21 additions & 6 deletions tests/misc/Makefile.in
Expand Up @@ -36,7 +36,7 @@ host_triplet = @host@
target_triplet = @target@
check_PROGRAMS = tfcntl$(EXEEXT) tsetfsuid$(EXEEXT) \
tsetfsuidsupp$(EXEEXT) tsetuid$(EXEEXT) tsuppgrp$(EXEEXT) \
topt$(EXEEXT) tconf$(EXEEXT)
topt$(EXEEXT) tconf$(EXEEXT) tserialize$(EXEEXT)
subdir = tests/misc
DIST_COMMON = README $(srcdir)/Makefile.am $(srcdir)/Makefile.in
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
Expand Down Expand Up @@ -79,6 +79,14 @@ topt_DEPENDENCIES = $(top_builddir)/libdiod/libdiod.a \
$(top_builddir)/liblsd/liblsd.a $(am__DEPENDENCIES_1) \
$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1)
am_tserialize_OBJECTS = tserialize.$(OBJEXT) $(am__objects_1)
tserialize_OBJECTS = $(am_tserialize_OBJECTS)
tserialize_LDADD = $(LDADD)
tserialize_DEPENDENCIES = $(top_builddir)/libdiod/libdiod.a \
$(top_builddir)/libnpfs/libnpfs.a \
$(top_builddir)/liblsd/liblsd.a $(am__DEPENDENCIES_1) \
$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1)
am_tsetfsuid_OBJECTS = tsetfsuid.$(OBJEXT) $(am__objects_1)
tsetfsuid_OBJECTS = $(am_tsetfsuid_OBJECTS)
tsetfsuid_LDADD = $(LDADD)
Expand Down Expand Up @@ -120,11 +128,13 @@ COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
CCLD = $(CC)
LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
SOURCES = $(tconf_SOURCES) $(tfcntl_SOURCES) $(topt_SOURCES) \
$(tsetfsuid_SOURCES) $(tsetfsuidsupp_SOURCES) \
$(tsetuid_SOURCES) $(tsuppgrp_SOURCES)
$(tserialize_SOURCES) $(tsetfsuid_SOURCES) \
$(tsetfsuidsupp_SOURCES) $(tsetuid_SOURCES) \
$(tsuppgrp_SOURCES)
DIST_SOURCES = $(tconf_SOURCES) $(tfcntl_SOURCES) $(topt_SOURCES) \
$(tsetfsuid_SOURCES) $(tsetfsuidsupp_SOURCES) \
$(tsetuid_SOURCES) $(tsuppgrp_SOURCES)
$(tserialize_SOURCES) $(tsetfsuid_SOURCES) \
$(tsetfsuidsupp_SOURCES) $(tsetuid_SOURCES) \
$(tsuppgrp_SOURCES)
ETAGS = etags
CTAGS = ctags
am__tty_colors = \
Expand Down Expand Up @@ -259,7 +269,7 @@ target_vendor = @target_vendor@
top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
TESTS = t00 t01 t02 t03 t04 t05 t06
TESTS = t00 t01 t02 t03 t04 t05 t06 t07
CLEANFILES = *.out *.diff *.stats
AM_CFLAGS = @GCCWARN@
AM_CPPFLAGS = \
Expand All @@ -285,6 +295,7 @@ tsetfsuidsupp_SOURCES = tsetfsuidsupp.c $(common_sources)
tfcntl_SOURCES = tfcntl.c $(common_sources)
topt_SOURCES = topt.c $(common_sources)
tconf_SOURCES = tconf.c $(common_sources)
tserialize_SOURCES = tserialize.c $(common_sources)
EXTRA_DIST = $(TESTS) $(TESTS:%=%.exp) t06.conf
all: all-am

Expand Down Expand Up @@ -332,6 +343,9 @@ tfcntl$(EXEEXT): $(tfcntl_OBJECTS) $(tfcntl_DEPENDENCIES)
topt$(EXEEXT): $(topt_OBJECTS) $(topt_DEPENDENCIES)
@rm -f topt$(EXEEXT)
$(LINK) $(topt_OBJECTS) $(topt_LDADD) $(LIBS)
tserialize$(EXEEXT): $(tserialize_OBJECTS) $(tserialize_DEPENDENCIES)
@rm -f tserialize$(EXEEXT)
$(LINK) $(tserialize_OBJECTS) $(tserialize_LDADD) $(LIBS)
tsetfsuid$(EXEEXT): $(tsetfsuid_OBJECTS) $(tsetfsuid_DEPENDENCIES)
@rm -f tsetfsuid$(EXEEXT)
$(LINK) $(tsetfsuid_OBJECTS) $(tsetfsuid_LDADD) $(LIBS)
Expand All @@ -355,6 +369,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tconf.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tfcntl.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/topt.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tserialize.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tsetfsuid.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tsetfsuidsupp.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tsetuid.Po@am__quote@
Expand Down
1 change: 1 addition & 0 deletions tests/misc/README
Expand Up @@ -18,5 +18,6 @@ t04 Demonstrate that fcntl advisory locking does not treat threads
of multiple remote processes.
t05 Unit test for diodmount option handling module.
t06 Unit test for parsing diod.conf.
t07 Use valgrind to check for leaks in libnpfs serialize/deserialize

(*) Requires root, will be marked as NOTRUN if run as an unprivileged user.
9 changes: 9 additions & 0 deletions tests/misc/t07
@@ -0,0 +1,9 @@
#!/bin/bash -e

TEST=$(basename $0 | cut -d- -f1)
# test $(id -u) == 0 || exit 77 #skip if not root
which valgrind >/dev/null 2>&1 || exit 77 # skip if no valgrind

valgrind --error-exitcode=1 --tool=memcheck --track-origins=yes \
--leak-check=yes --quiet ./tserialize >$TEST.out 2>&1
diff $TEST.exp $TEST.out >$TEST.diff
4 changes: 4 additions & 0 deletions tests/misc/t07.exp
@@ -0,0 +1,4 @@
test_tversion: 21
test_rversion: 21
test_tgetattr: 19
test_rgetattr: 160

0 comments on commit 34a8fc8

Please sign in to comment.