TESTS: Add tests for nfs_lstat64()
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>libnfs-4.0.0-vitalif
parent
546c9455c7
commit
0d95058e4e
|
@ -4,9 +4,9 @@ AM_CPPFLAGS = -I${srcdir}/../include -I${srcdir}/../include/nfsc \
|
|||
AM_CFLAGS = $(WARN_CFLAGS)
|
||||
LDADD = ../lib/libnfs.la
|
||||
|
||||
noinst_PROGRAMS = prog_create prog_fstat prog_link prog_mkdir prog_mknod \
|
||||
prog_open_read prog_rename prog_rmdir prog_stat prog_symlink \
|
||||
prog_timeout prog_unlink
|
||||
noinst_PROGRAMS = prog_create prog_fstat prog_link prog_lstat prog_mkdir \
|
||||
prog_mknod prog_open_read prog_rename prog_rmdir prog_stat \
|
||||
prog_symlink prog_timeout prog_unlink
|
||||
|
||||
EXTRA_PROGRAMS = ld_timeout
|
||||
CLEANFILES = ld_timeout.o ld_timeout.so
|
||||
|
|
|
@ -0,0 +1,100 @@
|
|||
/* -*- 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 "libnfs.h"
|
||||
|
||||
void usage(void)
|
||||
{
|
||||
fprintf(stderr, "Usage: prog_lstat <url> <cwd> <path>\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
struct nfs_context *nfs = NULL;
|
||||
struct nfs_url *url = NULL;
|
||||
struct nfs_stat_64 st;
|
||||
int ret = 0;
|
||||
|
||||
if (argc != 4) {
|
||||
usage();
|
||||
}
|
||||
|
||||
nfs = nfs_init_context();
|
||||
if (nfs == NULL) {
|
||||
printf("failed to init context\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
nfs_set_timeout(nfs, 1000);
|
||||
|
||||
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_lstat64(nfs, argv[3], &st)) {
|
||||
fprintf(stderr, "Failed to lstat file : %s\n",
|
||||
nfs_get_error(nfs));
|
||||
ret = 1;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
printf("nfs_ino:%" PRIu64 "\n", st.nfs_ino);
|
||||
printf("nfs_mode:%" PRIo64 "\n", st.nfs_mode);
|
||||
printf("nfs_nlink:%" PRIu64 "\n", st.nfs_nlink);
|
||||
printf("nfs_uid:%" PRIu64 "\n", st.nfs_uid);
|
||||
printf("nfs_gid:%" PRIu64 "\n", st.nfs_gid);
|
||||
printf("nfs_size:%" PRIu64 "\n", st.nfs_size);
|
||||
printf("nfs_atime:%" PRIu64 "\n", st.nfs_atime);
|
||||
printf("nfs_mtime:%" PRIu64 "\n", st.nfs_mtime);
|
||||
printf("nfs_ctime:%" PRIu64 "\n", st.nfs_ctime);
|
||||
|
||||
finished:
|
||||
nfs_destroy_url(url);
|
||||
nfs_destroy_context(nfs);
|
||||
|
||||
return ret;
|
||||
}
|
|
@ -2,12 +2,13 @@
|
|||
|
||||
. ./functions.sh
|
||||
|
||||
echo "basic stat test"
|
||||
echo "stat test on symlink"
|
||||
|
||||
start_share
|
||||
|
||||
dd if=/dev/zero of=testdata/testfile count=1 bs=32768 2>/dev/null
|
||||
chmod 644 "${TESTDIR}/testfile"
|
||||
ln -s testfile "${TESTDIR}/lstat1"
|
||||
|
||||
|
||||
echo -n "test nfs_stat64() ... "
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
. ./functions.sh
|
||||
|
||||
echo "basic nfs_stat64() test"
|
||||
echo "nfs_stat64() path tests"
|
||||
|
||||
start_share
|
||||
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
#!/bin/sh
|
||||
|
||||
. ./functions.sh
|
||||
|
||||
echo "stat test on symlink"
|
||||
|
||||
start_share
|
||||
|
||||
dd if=/dev/zero of=testdata/testfile count=1 bs=32768 2>/dev/null
|
||||
chmod 644 "${TESTDIR}/testfile"
|
||||
ln -s testfile "${TESTDIR}/lstat1"
|
||||
|
||||
|
||||
echo -n "test nfs_stat64() ... "
|
||||
./prog_stat "${TESTURL}/" "." /lstat1 > "${TESTDIR}/output" || failure
|
||||
success
|
||||
|
||||
echo -n "test nfs_ino ... "
|
||||
INO=`stat --printf="%i" testdata/testfile`
|
||||
grep "nfs_ino:$INO" "${TESTDIR}/output" >/dev/null || failure
|
||||
success
|
||||
|
||||
echo -n "test nfs_mode ... "
|
||||
grep "nfs_mode:100644" "${TESTDIR}/output" >/dev/null || failure
|
||||
success
|
||||
|
||||
echo -n "test nfs_nlink ... "
|
||||
grep "nfs_nlink:1" "${TESTDIR}/output" >/dev/null || failure
|
||||
success
|
||||
|
||||
echo -n "test nfs_uid ... "
|
||||
grep "nfs_uid:$UID" "${TESTDIR}/output" >/dev/null || failure
|
||||
success
|
||||
|
||||
echo -n "test nfs_gid ... "
|
||||
grep "nfs_gid:$GID" "${TESTDIR}/output" >/dev/null || failure
|
||||
success
|
||||
|
||||
echo -n "test nfs_size ... "
|
||||
grep "nfs_size:32768" "${TESTDIR}/output" >/dev/null || failure
|
||||
success
|
||||
|
||||
echo -n "test nfs_atime ... "
|
||||
ATIME=`stat --printf="%X" testdata/testfile`
|
||||
grep "nfs_atime:$ATIME" "${TESTDIR}/output" >/dev/null || failure
|
||||
success
|
||||
|
||||
echo -n "test nfs_mtime ... "
|
||||
MTIME=`stat --printf="%Y" testdata/testfile`
|
||||
grep "nfs_mtime:$MTIME" "${TESTDIR}/output" >/dev/null || failure
|
||||
success
|
||||
|
||||
echo -n "test nfs_ctime ... "
|
||||
CTIME=`stat --printf="%Z" testdata/testfile`
|
||||
grep "nfs_ctime:$CTIME" "${TESTDIR}/output" >/dev/null || failure
|
||||
success
|
||||
|
||||
stop_share
|
||||
|
||||
exit 0
|
|
@ -0,0 +1,60 @@
|
|||
#!/bin/sh
|
||||
|
||||
. ./functions.sh
|
||||
|
||||
echo "basic lstat test"
|
||||
|
||||
start_share
|
||||
|
||||
dd if=/dev/zero of=testdata/testfile count=1 bs=32768 2>/dev/null
|
||||
chmod 644 "${TESTDIR}/testfile"
|
||||
ln -s testfile "${TESTDIR}/lstat1"
|
||||
|
||||
|
||||
echo -n "test nfs_lstat64() ... "
|
||||
./prog_lstat "${TESTURL}/" "." /lstat1 > "${TESTDIR}/output" || failure
|
||||
success
|
||||
|
||||
echo -n "test nfs_ino ... "
|
||||
INO=`stat --printf="%i" testdata/lstat1`
|
||||
grep "nfs_ino:$INO" "${TESTDIR}/output" >/dev/null || failure
|
||||
success
|
||||
|
||||
echo -n "test nfs_mode ... "
|
||||
grep "nfs_mode:120777" "${TESTDIR}/output" >/dev/null || failure
|
||||
success
|
||||
|
||||
echo -n "test nfs_nlink ... "
|
||||
grep "nfs_nlink:1" "${TESTDIR}/output" >/dev/null || failure
|
||||
success
|
||||
|
||||
echo -n "test nfs_uid ... "
|
||||
grep "nfs_uid:$UID" "${TESTDIR}/output" >/dev/null || failure
|
||||
success
|
||||
|
||||
echo -n "test nfs_gid ... "
|
||||
grep "nfs_gid:$GID" "${TESTDIR}/output" >/dev/null || failure
|
||||
success
|
||||
|
||||
echo -n "test nfs_size ... "
|
||||
grep "nfs_size:8" "${TESTDIR}/output" >/dev/null || failure
|
||||
success
|
||||
|
||||
echo -n "test nfs_atime ... "
|
||||
ATIME=`stat --printf="%X" testdata/lstat1`
|
||||
grep "nfs_atime:$ATIME" "${TESTDIR}/output" >/dev/null || failure
|
||||
success
|
||||
|
||||
echo -n "test nfs_mtime ... "
|
||||
MTIME=`stat --printf="%Y" testdata/lstat1`
|
||||
grep "nfs_mtime:$MTIME" "${TESTDIR}/output" >/dev/null || failure
|
||||
success
|
||||
|
||||
echo -n "test nfs_ctime ... "
|
||||
CTIME=`stat --printf="%Z" testdata/lstat1`
|
||||
grep "nfs_ctime:$CTIME" "${TESTDIR}/output" >/dev/null || failure
|
||||
success
|
||||
|
||||
stop_share
|
||||
|
||||
exit 0
|
|
@ -0,0 +1,40 @@
|
|||
#!/bin/sh
|
||||
|
||||
. ./functions.sh
|
||||
|
||||
echo "nfs_lstat64() path tests"
|
||||
|
||||
start_share
|
||||
|
||||
mkdir "${TESTDIR}/subdir"
|
||||
mkdir "${TESTDIR}/subdir2"
|
||||
|
||||
echo -n "Test nfs_lstat64() for a root file (abs) (1)... "
|
||||
ln -s foo "${TESTDIR}/stat1"
|
||||
./prog_lstat "${TESTURL}/" "." /stat1 >/dev/null || failure
|
||||
success
|
||||
|
||||
echo -n "Test nfs_lstat64() for a root file (rel) (2)... "
|
||||
./prog_lstat "${TESTURL}/" "." stat1 >/dev/null || failure
|
||||
success
|
||||
|
||||
echo -n "Test nfs_lstat64() for a subdir file (abs) (3)... "
|
||||
ln -s foo "${TESTDIR}/subdir/stat3"
|
||||
./prog_lstat "${TESTURL}/" "." /subdir/stat3 >/dev/null || failure
|
||||
success
|
||||
|
||||
echo -n "Test nfs_lstat64() for a subdir file (rel) (4)... "
|
||||
./prog_lstat "${TESTURL}/" "." subdir/stat3 >/dev/null || failure
|
||||
success
|
||||
|
||||
echo -n "Test nfs_lstat64() from a different cwd (rel) (5)... "
|
||||
./prog_lstat "${TESTURL}/" "subdir2" ../subdir/stat3 >/dev/null || failure
|
||||
success
|
||||
|
||||
echo -n "Test nfs_lstat64() outside the share (rel) (6)... "
|
||||
./prog_lstat "${TESTURL}/" "subdir2" ../../subdir/stat3 >/dev/null 2>&1 && failure
|
||||
success
|
||||
|
||||
stop_share
|
||||
|
||||
exit 0
|
|
@ -0,0 +1,42 @@
|
|||
#!/bin/sh
|
||||
|
||||
. ./functions.sh
|
||||
|
||||
echo "basic valgrind leak check for nfs_lstat64()"
|
||||
|
||||
start_share
|
||||
|
||||
mkdir "${TESTDIR}/subdir"
|
||||
mkdir "${TESTDIR}/subdir2"
|
||||
|
||||
|
||||
echo -n "test nfs_lstat64() (1) ... "
|
||||
ln -s foo "${TESTDIR}/stat1"
|
||||
libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_lstat "${TESTURL}/" "." /stat1 >/dev/null 2>&1 || failure
|
||||
success
|
||||
|
||||
echo -n "test nfs_lstat64() (2) ... "
|
||||
libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_lstat "${TESTURL}/" "." stat1 >/dev/null 2>&1 || failure
|
||||
success
|
||||
|
||||
echo -n "test nfs_lstat64() (3) ... "
|
||||
ln -s foo "${TESTDIR}/subdir/stat3"
|
||||
libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_lstat "${TESTURL}/" "." /subdir/stat3 >/dev/null 2>&1 || failure
|
||||
success
|
||||
|
||||
echo -n "test nfs_lstat64() (4) ... "
|
||||
libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_lstat "${TESTURL}/" "." subdir/stat3 >/dev/null 2>&1 || failure
|
||||
success
|
||||
|
||||
echo -n "test nfs_lstat64() (5) ... "
|
||||
libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_lstat "${TESTURL}/" "subdir2" ../subdir/stat3 >/dev/null 2>&1 || failure
|
||||
success
|
||||
|
||||
echo -n "test nfs_lstat64() (6) ... "
|
||||
libtool --mode=execute valgrind --leak-check=full --error-exitcode=99 ./prog_lstat "${TESTURL}/" "subdir2" ../../subdir/stat3 2>/dev/null || expr $? != 99 >/dev/null || failure
|
||||
success
|
||||
|
||||
|
||||
stop_share
|
||||
|
||||
exit 0
|
Loading…
Reference in New Issue