diff options
author | Amar Tumballi <amarts@redhat.com> | 2019-07-25 11:00:29 +0530 |
---|---|---|
committer | Amar Tumballi <amarts@redhat.com> | 2019-07-31 00:53:11 +0000 |
commit | 7124fc6d01aa23e9a218d0ce608242d0ae320193 (patch) | |
tree | e6d2b75927e9562baf26d6f727e6008db0e79afe /tests | |
parent | a31fad885c30cbc1bea652349c7d52bac1414c08 (diff) |
gfapi: increase function-coverage
* Add few more mgmt functions to the coverage
* While testing mgmt function, found an issue, where if the
'glfs_set_volfile_server()' is not called before calling
'glfs_unset_volfile_server()', unset would cause a crash.
Null check of few variables fixes the issue, which is handled
in this patch itself.
* Added a test for volfile API
Updates: bz#1693692
Change-Id: Iba151f8da1b64107e2f436ddbfef9da45b1c1588
Signed-off-by: Amar Tumballi <amarts@redhat.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/basic/gfapi/glfsxmp-coverage.c | 69 | ||||
-rw-r--r-- | tests/basic/gfapi/glfsxmp.t | 5 |
2 files changed, 49 insertions, 25 deletions
diff --git a/tests/basic/gfapi/glfsxmp-coverage.c b/tests/basic/gfapi/glfsxmp-coverage.c index 8bf9b46529a..474ba9c0949 100644 --- a/tests/basic/gfapi/glfsxmp-coverage.c +++ b/tests/basic/gfapi/glfsxmp-coverage.c @@ -1791,29 +1791,40 @@ main(int argc, char *argv[]) struct statvfs sfs; char readbuf[32]; char writebuf[32]; + char volumeid[64]; char *filename = "/filename2"; - if (argc != 3) { - printf("Expect following args\n\t%s <volname> <hostname>\n", argv[0]); + if ((argc < 2) || (argc > 3)) { + printf("Usage:\n\t%s <volname> <hostname>\n\t%s <volfile-path>", + argv[0], argv[0]); return -1; } - fs = glfs_new(argv[1]); - if (!fs) { - fprintf(stderr, "glfs_new: returned NULL\n"); - return 1; + if (argc == 2) { + /* Generally glfs_new() requires volume name as an argument */ + fs = glfs_new("test-only"); + if (!fs) { + fprintf(stderr, "glfs_new: returned NULL\n"); + return 1; + } + ret = glfs_set_volfile(fs, argv[1]); + if (ret) + fprintf(stderr, "glfs_set_volfile failed\n"); + } else { + fs = glfs_new(argv[1]); + if (!fs) { + fprintf(stderr, "glfs_new: returned NULL\n"); + return 1; + } + // ret = glfs_set_volfile_server (fs, "unix", "/tmp/gluster.sock", 0); + ret = glfs_set_volfile_server(fs, "tcp", argv[2], 24007); + if (ret) + fprintf(stderr, "glfs_set_volfile_server failed\n"); } - // ret = glfs_set_volfile (fs, "/tmp/posix.vol"); - - ret = glfs_set_volfile_server(fs, "tcp", argv[2], 24007); - if (ret) - fprintf(stderr, "glfs_set_volfile_server failed\n"); - - // ret = glfs_set_volfile_server (fs, "unix", "/tmp/gluster.sock", 0); - - ret = glfs_set_logging(fs, "/dev/stderr", 7); + /* Change this to relevant file when running locally */ + ret = glfs_set_logging(fs, "/dev/stderr", 5); if (ret) fprintf(stderr, "glfs_set_logging failed\n"); @@ -1824,6 +1835,12 @@ main(int argc, char *argv[]) if (ret) goto out; + /* no major use for getting the volume id in this test, done for coverage */ + ret = glfs_get_volumeid(fs, volumeid, 64); + if (ret) { + fprintf(stderr, "glfs_get_volumeid: returned %d\n", ret); + } + sleep(2); fs2 = glfs_new(argv[1]); @@ -1831,16 +1848,16 @@ main(int argc, char *argv[]) fprintf(stderr, "glfs_new: returned NULL\n"); return 1; } - - // ret = glfs_set_volfile (fs2, "/tmp/posix.vol"); - - ret = glfs_set_volfile_server(fs2, "tcp", argv[2], 24007); - if (ret) - fprintf(stderr, "glfs_set_volfile_server failed\n"); - - ret = glfs_set_logging(fs2, "/dev/stderr", 7); - if (ret) - fprintf(stderr, "glfs_set_logging failed\n"); + if (argc == 2) { + ret = glfs_set_volfile(fs2, argv[1]); + if (ret) + fprintf(stderr, "glfs_set_volfile failed\n"); + } else { + // ret = glfs_set_volfile_server (fs2, "unix", "/tmp/gluster.sock", 0); + ret = glfs_set_volfile_server(fs2, "tcp", argv[2], 24007); + if (ret) + fprintf(stderr, "glfs_set_volfile_server failed\n"); + } ret = glfs_set_statedump_path(fs2, "/tmp"); if (ret) { @@ -1867,6 +1884,8 @@ main(int argc, char *argv[]) glfs_statvfs(fs, "/", &sfs); + glfs_unset_volfile_server(fs, "tcp", argv[2], 24007); + glfs_fini(fs); glfs_fini(fs2); diff --git a/tests/basic/gfapi/glfsxmp.t b/tests/basic/gfapi/glfsxmp.t index 4f0d90d059f..b3e6645c0f5 100644 --- a/tests/basic/gfapi/glfsxmp.t +++ b/tests/basic/gfapi/glfsxmp.t @@ -13,9 +13,14 @@ EXPECT 'Created' volinfo_field $V0 'Status' TEST $CLI volume start $V0 EXPECT 'Started' volinfo_field $V0 'Status' +$CLI system getspec $V0 > fubar.vol + TEST cp $(dirname $0)/glfsxmp-coverage.c ./glfsxmp.c TEST build_tester ./glfsxmp.c -lgfapi TEST ./glfsxmp $V0 $H0 + +TEST ./glfsxmp fubar.vol + TEST cleanup_tester ./glfsxmp TEST rm ./glfsxmp.c |