TESTS Add tests for nfs_open()
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>libnfs-4.0.0-vitalif
parent
2762897585
commit
4ed461ffee
File diff suppressed because it is too large
Load Diff
|
@ -5,7 +5,8 @@ AM_CFLAGS = $(WARN_CFLAGS)
|
||||||
LDADD = ../lib/libnfs.la
|
LDADD = ../lib/libnfs.la
|
||||||
|
|
||||||
noinst_PROGRAMS = prog_create prog_fstat prog_link prog_mkdir prog_mknod \
|
noinst_PROGRAMS = prog_create prog_fstat prog_link prog_mkdir prog_mknod \
|
||||||
prog_rename prog_rmdir prog_stat prog_symlink prog_timeout prog_unlink
|
prog_open_read prog_rename prog_rmdir prog_stat prog_symlink \
|
||||||
|
prog_timeout prog_unlink
|
||||||
|
|
||||||
EXTRA_PROGRAMS = ld_timeout
|
EXTRA_PROGRAMS = ld_timeout
|
||||||
CLEANFILES = ld_timeout.o ld_timeout.so
|
CLEANFILES = ld_timeout.o ld_timeout.so
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
|
|
||||||
void usage(void)
|
void usage(void)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Usage: prog-create <url> <cwd> <path> <mode(octal)>"
|
fprintf(stderr, "Usage: prog_create <url> <cwd> <path> <mode(octal)>"
|
||||||
"\n");
|
"\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
|
|
||||||
void usage(void)
|
void usage(void)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Usage: prog-fstat <url> <cwd> <path>\n");
|
fprintf(stderr, "Usage: prog_fstat <url> <cwd> <path>\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
|
|
||||||
void usage(void)
|
void usage(void)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Usage: prog-link <url> <cwd> <oldpath> <newpath>\n");
|
fprintf(stderr, "Usage: prog_link <url> <cwd> <oldpath> <newpath>\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
|
|
||||||
void usage(void)
|
void usage(void)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Usage: prog-mkdir <url> <cwd> <path>\n");
|
fprintf(stderr, "Usage: prog_mkdir <url> <cwd> <path>\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
|
|
||||||
void usage(void)
|
void usage(void)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Usage: prog-mknod <url> <cwd> <path> <mode(octal)>"
|
fprintf(stderr, "Usage: prog_mknod <url> <cwd> <path> <mode(octal)>"
|
||||||
"<dev(hex)>\n");
|
"<dev(hex)>\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,128 @@
|
||||||
|
/* -*- mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil; -*- */
|
||||||
|
/*
|
||||||
|
Copyright (C) by Ronnie Sahlberg <ronniesahlberg@gmail.com> 2017
|
||||||
|
|
||||||
|
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 _FILE_OFFSET_BITS 64
|
||||||
|
#define _GNU_SOURCE
|
||||||
|
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "libnfs.h"
|
||||||
|
|
||||||
|
void usage(void)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Usage: prog_open_read <url> <cwd> <path> <flags>"
|
||||||
|
"\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
struct nfs_context *nfs = NULL;
|
||||||
|
struct nfs_url *url = NULL;
|
||||||
|
int ret = 0;
|
||||||
|
int flags = 0, count;
|
||||||
|
struct nfsfh *fh;
|
||||||
|
char buf[1024];
|
||||||
|
|
||||||
|
if (argc != 5) {
|
||||||
|
usage();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strstr(argv[4], "O_RDONLY")) {
|
||||||
|
flags |= O_RDONLY;
|
||||||
|
}
|
||||||
|
if (strstr(argv[4], "O_RDWR")) {
|
||||||
|
flags |= O_RDWR;
|
||||||
|
}
|
||||||
|
if (strstr(argv[4], "O_WRONLY")) {
|
||||||
|
flags |= O_WRONLY;
|
||||||
|
}
|
||||||
|
if (strstr(argv[4], "O_NOFOLLOW")) {
|
||||||
|
flags |= O_NOFOLLOW;
|
||||||
|
}
|
||||||
|
if (strstr(argv[4], "O_APPEND")) {
|
||||||
|
flags |= O_APPEND;
|
||||||
|
}
|
||||||
|
if (strstr(argv[4], "O_TRUNC")) {
|
||||||
|
flags |= O_TRUNC;
|
||||||
|
}
|
||||||
|
|
||||||
|
nfs = nfs_init_context();
|
||||||
|
if (nfs == NULL) {
|
||||||
|
printf("failed to init context\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
url = nfs_parse_url_full(nfs, argv[1]);
|
||||||
|
if (url == NULL) {
|
||||||
|
fprintf(stderr, "%s\n", nfs_get_error(nfs));
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nfs_mount(nfs, url->server, url->path) != 0) {
|
||||||
|
fprintf(stderr, "Failed to mount nfs share : %s\n",
|
||||||
|
nfs_get_error(nfs));
|
||||||
|
ret = 1;
|
||||||
|
goto finished;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nfs_chdir(nfs, argv[2]) != 0) {
|
||||||
|
fprintf(stderr, "Failed to chdir to \"%s\" : %s\n",
|
||||||
|
argv[2], nfs_get_error(nfs));
|
||||||
|
ret = 1;
|
||||||
|
goto finished;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nfs_open(nfs, argv[3],flags, &fh)) {
|
||||||
|
fprintf(stderr, "Failed to open(): %s\n",
|
||||||
|
nfs_get_error(nfs));
|
||||||
|
ret = 1;
|
||||||
|
goto finished;
|
||||||
|
}
|
||||||
|
|
||||||
|
count = nfs_read(nfs, fh, sizeof(buf), buf);
|
||||||
|
if (count < 0) {
|
||||||
|
fprintf(stderr, "Failed to read(): %s\n",
|
||||||
|
nfs_get_error(nfs));
|
||||||
|
ret = 1;
|
||||||
|
goto finished;
|
||||||
|
}
|
||||||
|
|
||||||
|
write(1, buf, count);
|
||||||
|
|
||||||
|
if (nfs_close(nfs, fh)) {
|
||||||
|
fprintf(stderr, "Failed to close(): %s\n",
|
||||||
|
nfs_get_error(nfs));
|
||||||
|
ret = 1;
|
||||||
|
goto finished;
|
||||||
|
}
|
||||||
|
|
||||||
|
finished:
|
||||||
|
nfs_destroy_url(url);
|
||||||
|
nfs_destroy_context(nfs);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
|
@ -33,7 +33,7 @@
|
||||||
|
|
||||||
void usage(void)
|
void usage(void)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Usage: prog-rename <url> <cwd> <oldpath> <newpath>\n");
|
fprintf(stderr, "Usage: prog_rename <url> <cwd> <oldpath> <newpath>\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
|
|
||||||
void usage(void)
|
void usage(void)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Usage: prog-rmdir <url> <cwd> <path>\n");
|
fprintf(stderr, "Usage: prog_rmdir <url> <cwd> <path>\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
|
|
||||||
void usage(void)
|
void usage(void)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Usage: prog-stat <url> <cwd> <path>\n");
|
fprintf(stderr, "Usage: prog_stat <url> <cwd> <path>\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
|
|
||||||
void usage(void)
|
void usage(void)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Usage: prog-symlink <url> <cwd> <target> <link>\n");
|
fprintf(stderr, "Usage: prog_symlink <url> <cwd> <target> <link>\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
|
|
||||||
void usage(void)
|
void usage(void)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Usage: prog-stat <file>\n");
|
fprintf(stderr, "Usage: prog_timeout <file>\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
|
|
||||||
void usage(void)
|
void usage(void)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Usage: prog-unlink <url> <cwd> <path>\n");
|
fprintf(stderr, "Usage: prog_unlink <url> <cwd> <path>\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,65 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
. ./functions.sh
|
||||||
|
|
||||||
|
echo "basic open path tests"
|
||||||
|
|
||||||
|
start_share
|
||||||
|
|
||||||
|
mkdir "${TESTDIR}/subdir"
|
||||||
|
mkdir "${TESTDIR}/subdir2"
|
||||||
|
|
||||||
|
echo -n "Open a file in root (abs) (1) ... "
|
||||||
|
echo -n "kangabanga" > "${TESTDIR}/open1"
|
||||||
|
./prog_open_read "${TESTURL}/" "." /open1 O_RDONLY >/dev/null || failure
|
||||||
|
success
|
||||||
|
|
||||||
|
echo -n "Open a file in root (rel) (2) ... "
|
||||||
|
./prog_open_read "${TESTURL}/" "." open1 O_RDONLY >/dev/null || failure
|
||||||
|
success
|
||||||
|
|
||||||
|
echo -n "Open a file in a subdir (abs) (3) ... "
|
||||||
|
echo -n "kangabanga" > "${TESTDIR}/subdir/open3"
|
||||||
|
./prog_open_read "${TESTURL}/" "." /subdir/open3 O_RDONLY >/dev/null || failure
|
||||||
|
success
|
||||||
|
|
||||||
|
echo -n "Open a file in root (rel) (4) ... "
|
||||||
|
./prog_open_read "${TESTURL}/" "." subdir/open3 O_RDONLY >/dev/null || failure
|
||||||
|
success
|
||||||
|
|
||||||
|
echo -n "Open a file from a different cwd (rel) (5) ... "
|
||||||
|
./prog_open_read "${TESTURL}/" "subdir2" ../subdir/open3 O_RDONLY >/dev/null || failure
|
||||||
|
success
|
||||||
|
|
||||||
|
echo -n "Open a file outside the share (rel) (5) ... "
|
||||||
|
./prog_open_read "${TESTURL}/" "subdir2" ../../subdir/open3 O_RDONLY >/dev/null 2>&1 && failure
|
||||||
|
success
|
||||||
|
|
||||||
|
echo -n "Create a directory symlink (rel) (6) ... "
|
||||||
|
./prog_symlink "${TESTURL}/" "." subdir /subdir4 || failure
|
||||||
|
success
|
||||||
|
|
||||||
|
echo -n "Open a file in a symlinked subdir (rel) (7) ... "
|
||||||
|
./prog_open_read "${TESTURL}/" "." subdir4/open3 O_RDONLY >/dev/null || failure
|
||||||
|
success
|
||||||
|
|
||||||
|
echo -n "Create a file symlink (rel) (8) ... "
|
||||||
|
./prog_symlink "${TESTURL}/" "." open3 /subdir4/open8 || failure
|
||||||
|
success
|
||||||
|
|
||||||
|
echo -n "Open a symlinked file (rel) (9) ... "
|
||||||
|
./prog_open_read "${TESTURL}/" "." subdir4/open8 O_RDONLY >/dev/null || failure
|
||||||
|
success
|
||||||
|
|
||||||
|
echo -n "Open a symlinked path with O_NOFOLLOW (rel) (10) ... "
|
||||||
|
./prog_open_read "${TESTURL}/" "." subdir4/open3 O_RDONLY,O_NOFOLLOW 2>/dev/null && failure
|
||||||
|
success
|
||||||
|
|
||||||
|
echo -n "Open a symlinked file with O_NOFOLLOW (rel) (11) ... "
|
||||||
|
./prog_open_read "${TESTURL}/" "." subdir/open8 O_RDONLY,O_NOFOLLOW 2>/dev/null && failure
|
||||||
|
success
|
||||||
|
|
||||||
|
|
||||||
|
stop_share
|
||||||
|
|
||||||
|
exit 0
|
|
@ -0,0 +1,42 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
. ./functions.sh
|
||||||
|
|
||||||
|
echo "basic valgrind leak check for nfs_open()"
|
||||||
|
|
||||||
|
start_share
|
||||||
|
|
||||||
|
mkdir "${TESTDIR}/subdir"
|
||||||
|
mkdir "${TESTDIR}/subdir2"
|
||||||
|
|
||||||
|
|
||||||
|
echo -n "test nfs_open() (1) ... "
|
||||||
|
echo -n "kangabanga" > "${TESTDIR}/open1"
|
||||||
|
libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_open_read "${TESTURL}/" "." /open1 O_RDONLY >/dev/null 2>&1 || failure
|
||||||
|
success
|
||||||
|
|
||||||
|
echo -n "test nfs_open() (2) ... "
|
||||||
|
libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_open_read "${TESTURL}/" "." open1 O_RDONLY >/dev/null 2>&1 || failure
|
||||||
|
success
|
||||||
|
|
||||||
|
echo -n "test nfs_open() (3) ... "
|
||||||
|
echo -n "kangabanga" > "${TESTDIR}/subdir/open3"
|
||||||
|
libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_open_read "${TESTURL}/" "." /subdir/open3 O_RDONLY >/dev/null 2>&1 || failure
|
||||||
|
success
|
||||||
|
|
||||||
|
echo -n "test nfs_open() (4) ... "
|
||||||
|
libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_open_read "${TESTURL}/" "." subdir/open3 O_RDONLY >/dev/null 2>&1 || failure
|
||||||
|
success
|
||||||
|
|
||||||
|
echo -n "test nfs_open() (5) ... "
|
||||||
|
libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_open_read "${TESTURL}/" "subdir2" ../subdir/open3 O_RDONLY >/dev/null 2>&1 || failure
|
||||||
|
success
|
||||||
|
|
||||||
|
echo -n "test nfs_open() (6) ... "
|
||||||
|
libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_open_read "${TESTURL}/" "subdir2" ../../subdir/open3 O_RDONLY 2>/dev/null || expr $? != 99 >/dev/null || failure
|
||||||
|
success
|
||||||
|
|
||||||
|
|
||||||
|
stop_share
|
||||||
|
|
||||||
|
exit 0
|
Loading…
Reference in New Issue