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>
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 \
--- /dev/null
+#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;
+}