Blob Blame History Raw
From 2419f7df9fbe9c63c6c41acec2b38684c6bc09d8 Mon Sep 17 00:00:00 2001
From: Mohammed Rafi KC <rkavunga@redhat.com>
Date: Tue, 9 May 2017 16:11:52 +0530
Subject: [PATCH 449/473] 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

Backport of>
>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>

Change-Id: I5c9cceade30f7d8a3b451b5f34f1cf9815729c4a
BUG: 1441280
Signed-off-by: Mohammed Rafi KC <rkavunga@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/106339
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
---
 tests/bugs/gfapi/bug-1447266/bug-1447266.c | 105 +++++++++++++++++++++++++++++
 tests/bugs/gfapi/bug-1447266/bug-1447266.t |  60 +++++++++++++++++
 2 files changed, 165 insertions(+)
 create mode 100644 tests/bugs/gfapi/bug-1447266/bug-1447266.c
 create mode 100644 tests/bugs/gfapi/bug-1447266/bug-1447266.t

diff --git a/tests/bugs/gfapi/bug-1447266/bug-1447266.c b/tests/bugs/gfapi/bug-1447266/bug-1447266.c
new file mode 100644
index 0000000..e4b3c88
--- /dev/null
+++ b/tests/bugs/gfapi/bug-1447266/bug-1447266.c
@@ -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;
+}
diff --git a/tests/bugs/gfapi/bug-1447266/bug-1447266.t b/tests/bugs/gfapi/bug-1447266/bug-1447266.t
new file mode 100644
index 0000000..2bf72f8
--- /dev/null
+++ b/tests/bugs/gfapi/bug-1447266/bug-1447266.t
@@ -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;
-- 
1.8.3.1