]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
test: test helper for get_block_device_size 813/head
authorNoah Watkins <noahwatkins@gmail.com>
Mon, 4 Nov 2013 16:28:23 +0000 (08:28 -0800)
committerNoah Watkins <noahwatkins@gmail.com>
Mon, 4 Nov 2013 18:13:50 +0000 (10:13 -0800)
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 <noahwatkins@gmail.com>
src/test/Makefile.am
src/test/test_get_blkdev_size.cc [new file with mode: 0644]

index 228a26e2bdac727ed3ec9210ba77bd86a579d3da..da9f33b3d42d21c499b86a7048d7a5df4b005750 100644 (file)
@@ -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 (file)
index 0000000..ba28f1c
--- /dev/null
@@ -0,0 +1,35 @@
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include "common/blkdev.h"
+
+int main(int argc, char **argv)
+{
+       int fd, ret;
+       int64_t size;
+
+       if (argc != 2) {
+               fprintf(stderr, "usage: %s <blkdev>\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;
+}