tests/gfapi:Adding testcase to check handling of "." and ".."

Adding a testcase to check the proper handling of "." and ".."
in gfapi path.
The patch which fix the issue is https://review.gluster.org/#/c/17177

Change-Id: I5c9cceade30f7d8a3b451b5f34f1cf9815729c4a
BUG: 1447266
Signed-off-by: Mohammed Rafi KC <rkavunga@redhat.com>
Reviewed-on: https://review.gluster.org/17216
Smoke: Gluster Build System <jenkins@build.gluster.org>
NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
Reviewed-by: Niels de Vos <ndevos@redhat.com>
Reviewed-by: Jeff Darcy <jeff@pl.atyp.us>
CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
This commit is contained in:
Mohammed Rafi KC 2017-05-09 16:11:52 +05:30 committed by Jeff Darcy
parent ef61a79f33
commit 642f3e290a
2 changed files with 165 additions and 0 deletions

View File

@ -0,0 +1,105 @@
#include <glusterfs/api/glfs.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#define TOTAL_ARGS 4
int main(int argc, char *argv[])
{
char *cwd = (char *)malloc(PATH_MAX*sizeof(char *));
char *resolved = NULL;
char *result = NULL;
char *buf = NULL;
struct stat st;
char *path = NULL;
int ret;
if (argc != TOTAL_ARGS) {
printf ("Please give all required command line args.\n"
"Format : <volname> <server_ip> <path_name>\n");
goto out;
}
glfs_t *fs = glfs_new (argv[1]);
if (fs == NULL) {
printf ("glfs_new: %s\n", strerror(errno));
/* No need to fail the test for this error */
ret = 0;
goto out;
}
ret = glfs_set_volfile_server(fs, "tcp", argv[2], 24007);
if (ret) {
printf ("glfs_set_volfile_server: %s\n", strerror(errno));
/* No need to fail the test for this error */
ret = 0;
goto out;
}
path = argv[3];
ret = glfs_set_logging(fs, "/tmp/gfapi.log", 7);
if (ret) {
printf ("glfs_set_logging: %s\n", strerror(errno));
/* No need to fail the test for this error */
ret = 0;
goto out;
}
ret = glfs_init(fs);
if (ret) {
printf ("glfs_init: %s\n", strerror(errno));
/* No need to fail the test for this error */
ret = 0;
goto out;
}
sleep(1);
ret = glfs_chdir(fs, path);
if (ret) {
printf ("glfs_chdir: %s\n", strerror(errno));
goto out;
}
buf = glfs_getcwd(fs, cwd, PATH_MAX);
if (cwd == NULL) {
printf ("glfs_getcwd: %s\n", strerror(errno));
goto out;
}
printf ("\ncwd = %s\n\n", cwd);
result = glfs_realpath(fs, path, resolved);
if (result == NULL) {
printf ("glfs_realpath: %s\n", strerror(errno));
goto out;
}
ret = glfs_stat(fs, path, &st);
if (ret) {
printf ("glfs_stat: %s\n", strerror(errno));
goto out;
}
if (cwd)
free(cwd);
result = glfs_realpath(fs, path, resolved);
if (result == NULL) {
printf ("glfs_realpath: %s\n", strerror(errno));
goto out;
}
ret = glfs_fini(fs);
if (ret) {
printf ("glfs_fini: %s\n", strerror(errno));
/* No need to fail the test for this error */
ret = 0;
goto out;
}
printf ("\n");
out:
return ret;
}

View File

@ -0,0 +1,60 @@
#!/bin/bash
. $(dirname $0)/../../../include.rc
. $(dirname $0)/../../../volume.rc
. $(dirname $0)/../../../snapshot.rc
cleanup;
TEST init_n_bricks 3;
TEST setup_lvm 3;
TEST glusterd;
TEST pidof glusterd;
TEST $CLI volume create $V0 $H0:$L1 $H0:$L2 $H0:$L3;
TEST $CLI volume set $V0 nfs.disable false
TEST $CLI volume start $V0;
TEST $GFS --volfile-server=$H0 --volfile-id=$V0 $M0;
for i in {1..10} ; do echo "file" > $M0/file$i ; done
# Create file and hard-links
TEST touch $M0/f1
TEST mkdir $M0/dir
TEST ln $M0/f1 $M0/f2
TEST ln $M0/f1 $M0/dir/f3
TEST $CLI snapshot config activate-on-create enable
TEST $CLI volume set $V0 features.uss enable;
TEST $CLI snapshot create snap1 $V0 no-timestamp;
for i in {11..20} ; do echo "file" > $M0/file$i ; done
TEST $CLI snapshot create snap2 $V0 no-timestamp;
TEST build_tester $(dirname $0)/bug-1447266.c -lgfapi
#Testing strts from here-->
TEST $(dirname $0)/bug-1447266 $V0 $H0 "/.."
TEST $(dirname $0)/bug-1447266 $V0 $H0 "/."
TEST $(dirname $0)/bug-1447266 $V0 $H0 "/../."
TEST $(dirname $0)/bug-1447266 $V0 $H0 "/../.."
TEST $(dirname $0)/bug-1447266 $V0 $H0 "/dir/../."
#Since dir1 is not present, this test should fail
TEST ! $(dirname $0)/bug-1447266 $V0 $H0 "/dir/../dir1"
TEST $(dirname $0)/bug-1447266 $V0 $H0 "/dir/.."
TEST $(dirname $0)/bug-1447266 $V0 $H0 "/.snaps"
TEST $(dirname $0)/bug-1447266 $V0 $H0 "/.snaps/."
#Since snap3 is not present, this test should fail
TEST ! $(dirname $0)/bug-1447266 $V0 $H0 "/.snaps/.././snap3"
TEST $(dirname $0)/bug-1447266 $V0 $H0 "/.snaps/../."
TEST $(dirname $0)/bug-1447266 $V0 $H0 "/.snaps/./snap1/./../snap1/dir/."
cleanup_tester $(dirname $0)/bug-1319374
cleanup;