From: Noah Watkins Date: Mon, 4 Nov 2013 16:28:23 +0000 (-0800) Subject: test: test helper for get_block_device_size X-Git-Tag: v0.73~35^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=324dd54534e41598feb6169f33cfed85495fa91f;p=ceph.git test: test helper for get_block_device_size This is the start of a potential unit test for get_block_device_size. An actual unit test will probably need to be run as root, and either find a device, have one specified, or create one (e.g. ramdisk) in a platform agnostic way. In the mean time, this tool can be run by hand, or called for a bash script. Signed-off-by: Noah Watkins --- diff --git a/src/test/Makefile.am b/src/test/Makefile.am index 228a26e2bdac..da9f33b3d42d 100644 --- a/src/test/Makefile.am +++ b/src/test/Makefile.am @@ -863,6 +863,10 @@ ceph_test_c_headers_SOURCES = test/test_c_headers.c ceph_test_c_headers_LDADD = $(LIBRADOS) $(LIBCEPHFS) bin_DEBUGPROGRAMS += ceph_test_c_headers +ceph_test_get_blkdev_size_SOURCES = test/test_get_blkdev_size.cc +ceph_test_get_blkdev_size_LDADD = $(LIBCOMMON) +bin_DEBUGPROGRAMS += ceph_test_get_blkdev_size + noinst_HEADERS += \ test/osd/RadosModel.h \ test/osd/Object.h \ diff --git a/src/test/test_get_blkdev_size.cc b/src/test/test_get_blkdev_size.cc new file mode 100644 index 000000000000..ba28f1cd62f1 --- /dev/null +++ b/src/test/test_get_blkdev_size.cc @@ -0,0 +1,35 @@ +#include +#include +#include +#include +#include +#include +#include +#include "common/blkdev.h" + +int main(int argc, char **argv) +{ + int fd, ret; + int64_t size; + + if (argc != 2) { + fprintf(stderr, "usage: %s \n", argv[0]); + return -1; + } + + fd = open(argv[1], O_RDONLY); + if (fd < 0) { + perror("open"); + return -1; + } + + ret = get_block_device_size(fd, &size); + if (ret < 0) { + fprintf(stderr, "get_block_device_size: %s\n", strerror(-ret)); + return -1; + } + + fprintf(stdout, "%" PRId64, size); + + return 0; +}