Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testsuite: convert unit tests to TAP #121

Merged
merged 15 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
sudo apt-get install -y \
libpopt-dev ncurses-dev automake autoconf pkgconf \
lua5.3 liblua5.3-dev libmunge-dev libwrap0-dev libcap-dev \
libattr1-dev dbench attr scrub ${{matrix.cc}}
libattr1-dev dbench attr scrub valgrind ${{matrix.cc}}
- name: Display configuration
run: |
echo "C compiler:"
Expand All @@ -38,6 +38,10 @@ jobs:
run: make
- name: make check
run: make check
- name: valgrind some unit tests
run: scripts/check-valgrind.sh
- name: sudo some unit tests
run: scripts/check-root.sh
- name: check with linux/9p
run: sudo make check -C tests/kern
- name: make distcheck
Expand Down
2 changes: 2 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ AC_CONFIG_AUX_DIR([config])
AC_CONFIG_MACRO_DIR([config])
AC_CONFIG_SRCDIR([NEWS])
AC_CANONICAL_HOST
AC_REQUIRE_AUX_FILE([tap-driver.sh])
X_AC_EXPAND_INSTALL_DIRS

##
Expand Down Expand Up @@ -217,6 +218,7 @@ RRA_WITH_SYSTEMD_UNITDIR
AC_CONFIG_FILES( \
Makefile \
diod.spec \
src/libtap/Makefile \
src/libdiod/Makefile \
src/liblsd/Makefile \
src/libnpfs/Makefile \
Expand Down
17 changes: 17 additions & 0 deletions scripts/check-root.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/sh

die () {
echo "$@" >&2
exit 1
}

sudo -n /bin/true || die "passwordless sudo is required to run privileged tests"

sudo -n make -C src/libnpfs check TESTS="\
test_capability.t \
test_setfsuid.t \
test_setgroups.t \
test_setreuid.t" || die "test failed"

sudo -n make -C src/daemon check TESTS="\
test_multiuser.t" || die "test failed"
31 changes: 31 additions & 0 deletions scripts/check-valgrind.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/sh

die () {
echo "$@" >&2
exit 1
}

which valgrind >/dev/null 2>&1 || die "valgrind is missing"

TESTS="src/libnpfs/test_encoding.t \
src/libnpfs/test_fidpool.t \
src/libnpclient/test_simple.t \
src/libdiod/test_configfile.t \
src/daemon/test_read.t \
src/daemon/test_directory.t"

exit_rc=0

for test in $TESTS; do
valgrind \
--tool=memcheck \
--leak-check=full \
--error-exitcode=1 \
--leak-resolution=med \
--trace-children=no \
--child-silent-after-fork=yes \
$test
test $? -eq 0 || exit_rc=1
done

exit $exit_rc
3 changes: 2 additions & 1 deletion scripts/install-deps-deb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ apt install \
libc6-dev \
libpopt-dev \
libncurses-dev \
libcap2-dev \
lua5.1 \
liblua5.1-dev \
valgrind
valgrind \

# to build test DEBs you need devscripts and debhelper too
1 change: 1 addition & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
SUBDIRS = \
libtap \
liblsd \
libnpfs \
libnpclient \
Expand Down
15 changes: 15 additions & 0 deletions src/cmd/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,18 @@ diodshowmount_SOURCES = diodshowmount.c $(common_sources)

dioddate_LDADD = $(common_ldadd)
dioddate_SOURCES = dioddate.c $(common_sources)

TESTS = \
test_opt.t

check_PROGRAMS = $(TESTS)

TEST_EXTENSIONS = .t
T_LOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) \
$(top_srcdir)/config/tap-driver.sh

test_opt_t_SOURCES = test/opt.c
test_opt_t_LDADD = \
$(builddir)/opt.o \
$(common_ldadd) \
$(top_builddir)/src/libtap/libtap.a
79 changes: 79 additions & 0 deletions src/cmd/test/opt.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/************************************************************\
* Copyright 2010 Lawrence Livermore National Security, LLC
* (c.f. AUTHORS, NOTICE.LLNS, COPYING)
*
* This file is part of the diod 9P server project.
* For details, see https://github.com/chaos/diod.
*
* SPDX-License-Identifier: GPL-2.0-or-later
\************************************************************/

/* topt.c - test didomount/opt.c */

#if HAVE_CONFIG_H
#include "config.h"
#endif
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <stdarg.h>
#include <assert.h>

#include "src/libtap/tap.h"
#include "opt.h"

int
main (int argc, char *argv[])
{
Opt o;

char *s;
int i;

plan (NO_PLAN);

o = opt_create ();
ok (o != NULL, "opt_create works");

ok (opt_addf (o, "mickey=%d", 42) == 1, "opt_addf mickey=42 works");
ok (opt_addf (o, "goofey=%s", "yes") == 1, "opt_addf goofey=yes works");
ok (opt_addf (o, "donald") == 1, "opt_addf donald works");
ok (opt_addf (o, "foo,bar,baz") == 1, "opt_addf foo,bar,baz works");
ok (opt_addf (o, "lastone") == 1, "opt_addf lastone works");

s = opt_csv (o);
ok (s != NULL
&& !strcmp (s, "mickey=42,goofey=yes,donald,foo,bar,baz,lastone"),
"opt_csv returned expected result");
free (s);

ok (opt_find (o, "mickey") != NULL, "opt_find mickey works");
ok (opt_find (o, "bar") != NULL, "opt_find bar works");
ok (opt_find (o, "barn") == NULL, "opt_find barn fails as expected");

i = -1;
ok (opt_scanf (o, "mickey=%d", &i) && i == 42,
"opt_scanf mickey value of 42");

ok (opt_addf (o, "mickey=string,foo=%d,bar=%d,baz", 12, 15) == 1,
"opt_addf mickey=string,foo=12,bar=15,baz works");
s = opt_csv (o);
ok (s != NULL
&& !strcmp (s,
"goofey=yes,donald,lastone,"
"mickey=string,foo=12,bar=15,baz"),
"opt_csv returned expected result");
free (s);

opt_destroy (o);

done_testing ();

exit (0);
}

/*
* vi:tabstop=4 shiftwidth=4 expandtab
*/
44 changes: 44 additions & 0 deletions src/daemon/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,47 @@ diod_SOURCES = \
fid.h \
xattr.c \
xattr.h

test_ldadd = \
$(top_builddir)/src/libdiod/libdiod.a \
$(top_builddir)/src/libnpclient/libnpclient.a \
$(top_builddir)/src/libnpfs/libnpfs.a \
$(top_builddir)/src/liblsd/liblsd.a \
$(top_builddir)/src/libtap/libtap.a \
$(LIBPTHREAD)

xtest_ldadd = \
$(builddir)/ops.o \
$(builddir)/fid.o \
$(builddir)/exp.o \
$(builddir)/ioctx.o \
$(builddir)/xattr.o \
$(test_ldadd) \
$(LUA_LIB) \
$(LIBCAP) \
$(LIBMUNGE) \
$(LIBWRAP)

TESTS = \
test_threadwrlock.t \
test_read.t \
test_directory.t \
test_multiuser.t

check_PROGRAMS = $(TESTS)

TEST_EXTENSIONS = .t
T_LOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) \
$(top_srcdir)/config/tap-driver.sh

test_threadwrlock_t_SOURCES = test/threadwrlock.c
test_threadwrlock_t_LDADD = $(test_ldadd)

test_read_t_SOURCES = test/read.c
test_read_t_LDADD = $(xtest_ldadd)

test_directory_t_SOURCES = test/directory.c
test_directory_t_LDADD = $(xtest_ldadd)

test_multiuser_t_SOURCES = test/multiuser.c
test_multiuser_t_LDADD = $(xtest_ldadd)
Loading
Loading