TESTS: Verify we fail on RPC timeouts

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
libnfs-4.0.0-vitalif
Ronnie Sahlberg 2017-06-29 08:34:44 +10:00
parent c030d82d99
commit 04cdb72bb1
4 changed files with 115 additions and 0 deletions

View File

@ -6,6 +6,22 @@ LDADD = ../lib/libnfs.la
noinst_PROGRAMS = prog_fstat prog_stat
EXTRA_PROGRAMS = ld_timeout
CLEANFILES = ld_timeout.o ld_timeout.so
ld_timeout_SOURCES = ld_timeout.c
ld_timeout_CFLAGS = $(AM_CFLAGS) -fPIC
bin_SCRIPTS = ld_timeout.so
ld_timeout.o: ld_timeout-ld_timeout.o
$(LIBTOOL) --mode=link $(CC) -o $@ $^
ld_timeout.so: ld_timeout.o
$(CC) -shared -o ld_timeout.so ld_timeout.o -ldl
T = `ls test_*.sh`
test: $(noinst_PROGRAMS)

79
tests/ld_timeout.c Normal file
View File

@ -0,0 +1,79 @@
/* -*- mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil; -*- */
/*
Copyright (C) 2017 by Ronnie Sahlberg <ronniesahlberg@gmail.com>
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 3 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, see <http://www.gnu.org/licenses/>.
*/
#define _GNU_SOURCE
#include <asm/fcntl.h>
#include <errno.h>
#include <poll.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <nfsc/libnfs.h>
#include <sys/syscall.h>
#include <dlfcn.h>
#ifndef discard_const
#define discard_const(ptr) ((void *)((intptr_t)(ptr)))
#endif
#define PRINTF(fmt, args...) \
do { \
fprintf(stderr,"ld_nfs: "); \
fprintf(stderr, (fmt), ##args); \
fprintf(stderr,"\n"); \
} while (0);
int timeout_start = 0;
int (*real_rpc_service)(struct rpc_context *rpc, int revents);
int rpc_service(struct rpc_context *rpc, int revents)
{
static int call_idx = 0;
call_idx++;
if (call_idx >= timeout_start) {
PRINTF("sleep for 2 seconds causing a timeout");
sleep(2);
/* Strip off all the POLLINs so that we will not try
* to process them in rpc_service and instead fall-through
* to the rpc_timeout_scan() and handle the PDUs there
* instead.
*/
revents &= ~POLLIN;
}
return real_rpc_service(rpc, revents);
}
static void __attribute__((constructor))
_init(void)
{
/* Start timing out calls at this index */
if (getenv("TIMEOUT_START") != NULL) {
timeout_start = atoi(getenv("TIMEOUT_START"));
}
real_rpc_service = dlsym(RTLD_NEXT, "rpc_service");
}

View File

@ -51,6 +51,8 @@ int main(int argc, char *argv[])
exit(1);
}
nfs_set_timeout(nfs, 1000);
url = nfs_parse_url_full(nfs, argv[argc - 1]);
if (url == NULL) {
fprintf(stderr, "%s\n", nfs_get_error(nfs));

18
tests/test_8000_timeout.sh Executable file
View File

@ -0,0 +1,18 @@
#!/bin/sh
. ./functions.sh
echo "basic timeout test"
start_share
touch "${TESTDIR}/testfile"
for IDX in `seq 1 28`; do
echo -n "Test timeout at socket event ${IDX} ... "
TIMEOUT_START=${IDX} LD_PRELOAD=./ld_timeout.so ./prog_stat "${TESTURL}/testfile" >/dev/null 2>&1 && failure
success
done
stop_share
exit 0