From bbf38735d84e5e9f1a3205c6893802b450252b98 Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Fri, 16 Jun 2017 12:37:42 -0700 Subject: [PATCH] TESTS: Initial test directory. Signed-off-by: Ronnie Sahlberg --- configure.ac | 3 ++- tests/Makefile.am | 17 +++++++++++++++++ tests/README | 8 ++++++++ tests/functions.sh | 25 +++++++++++++++++++++++++ tests/test_0100_ls_basic.sh | 21 +++++++++++++++++++++ 5 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 tests/Makefile.am create mode 100644 tests/README create mode 100755 tests/functions.sh create mode 100755 tests/test_0100_ls_basic.sh diff --git a/configure.ac b/configure.ac index df7e949..fa878de 100755 --- a/configure.ac +++ b/configure.ac @@ -227,6 +227,7 @@ AC_HEADER_MAJOR #output AC_CONFIG_FILES([Makefile] [doc/Makefile] + [examples/Makefile] [include/Makefile] [lib/Makefile] [mount/Makefile] @@ -236,8 +237,8 @@ AC_CONFIG_FILES([Makefile] [nsm/Makefile] [portmap/Makefile] [rquota/Makefile] + [tests/Makefile] [utils/Makefile] - [examples/Makefile] ) AC_OUTPUT([libnfs.pc]) diff --git a/tests/Makefile.am b/tests/Makefile.am new file mode 100644 index 0000000..475ec55 --- /dev/null +++ b/tests/Makefile.am @@ -0,0 +1,17 @@ +AM_CPPFLAGS = -I${srcdir}/../include "-D_U_=__attribute__((unused))" \ + "-D_R_(A,B)=__attribute__((format(printf,A,B)))" +AM_CFLAGS = $(WARN_CFLAGS) +LDADD = ../lib/libnfs.la + +#noinst_PROGRAMS = prog_reconnect + +T = `ls test_*.sh` + +test: $(noinst_PROGRAMS) + for TEST in $(T); do \ + echo "Running $$TEST"; \ + echo "--------------"; \ + sh $$TEST || exit 1; \ + echo "--------------"; \ + echo; \ + done diff --git a/tests/README b/tests/README new file mode 100644 index 0000000..4b76324 --- /dev/null +++ b/tests/README @@ -0,0 +1,8 @@ +Testsuite for libnfs. + +To run the tests : + sudo make test + +It needs to run under sudo as it needs to create/remove nfs shares to test +against. + diff --git a/tests/functions.sh b/tests/functions.sh new file mode 100755 index 0000000..74281e7 --- /dev/null +++ b/tests/functions.sh @@ -0,0 +1,25 @@ +export TGT_IPC_SOCKET=`pwd`/tgtd.socket + +TESTDIR=`pwd`/testdata +TESTSHARE="127.0.0.1:${TESTDIR}" +TESTURL="nfs://127.0.0.1/${TESTDIR}" + +start_share() { + mkdir "${TESTDIR}" 2>/dev/null + exportfs -o rw,no_root_squash "${TESTSHARE}" +} + +stop_share() { + exportfs -u "${TESTSHARE}" + rm -rf "${TESTDIR}" +} + +success() { + echo "[OK]" +} + +failure() { + echo "[FAILED]" + exit 1 +} + diff --git a/tests/test_0100_ls_basic.sh b/tests/test_0100_ls_basic.sh new file mode 100755 index 0000000..e08bf27 --- /dev/null +++ b/tests/test_0100_ls_basic.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +. ./functions.sh + +echo "basic ls test" + +start_share + +echo -n "Testing nfs-ls on root of export ... " +../utils/nfs-ls "${TESTURL}" > /dev/null || failure +success + +echo -n "Create a file and verify nfs-ls can see it ... " +touch "${TESTDIR}/testfile" +../utils/nfs-ls "${TESTURL}" > "${TESTDIR}/output" || failure +grep testfile "${TESTDIR}/output" > /dev/null || failure +success + +stop_share + +exit 0