summaryrefslogtreecommitdiffstats
path: root/src/test/compressor
diff options
context:
space:
mode:
authorVed-vampir <akiselyova@mirantis.com>2015-11-10 16:47:18 +0100
committerSage Weil <sage@redhat.com>2016-01-15 01:04:19 +0100
commit300c2f773b0cbd9eaf010994c68942a4bcf2885f (patch)
tree82dc44874fa872af04dd9a6c8344fad0f19219f7 /src/test/compressor
parentCompressor: compressor code extention: plugin system added (diff)
downloadceph-300c2f773b0cbd9eaf010994c68942a4bcf2885f.tar.xz
ceph-300c2f773b0cbd9eaf010994c68942a4bcf2885f.zip
Compressor: compressor plugins unit tests
Signed-off-by: Alyona Kiseleva <akiselyova@mirantis.com>
Diffstat (limited to 'src/test/compressor')
-rw-r--r--src/test/compressor/Makefile.am49
-rw-r--r--src/test/compressor/compressor_example.h53
-rw-r--r--src/test/compressor/compressor_plugin_example.cc57
-rw-r--r--src/test/compressor/test_compression_plugin.cc71
-rw-r--r--src/test/compressor/test_compression_plugin_snappy.cc58
-rw-r--r--src/test/compressor/test_compression_snappy.cc62
6 files changed, 350 insertions, 0 deletions
diff --git a/src/test/compressor/Makefile.am b/src/test/compressor/Makefile.am
new file mode 100644
index 00000000000..f5a8f4e536e
--- /dev/null
+++ b/src/test/compressor/Makefile.am
@@ -0,0 +1,49 @@
+if ENABLE_SERVER
+if WITH_OSD
+
+
+libceph_example_la_SOURCES = \
+ compressor/Compressor.cc \
+ test/compressor/compressor_plugin_example.cc
+noinst_HEADERS += test/compressor/compressor_example.h
+test/compressor/compressor_plugin_example.cc: ./ceph_ver.h
+libceph_example_la_CFLAGS = ${AM_CFLAGS}
+libceph_example_la_CXXFLAGS= ${AM_CXXFLAGS}
+libceph_example_la_LIBADD = $(LIBCRUSH) $(PTHREAD_LIBS) $(EXTRALIBS)
+libceph_example_la_LDFLAGS = ${AM_LDFLAGS} -export-symbols-regex '.*__compression_.*'
+compressorlib_LTLIBRARIES += libceph_example.la
+
+unittest_compression_plugin_SOURCES = \
+ compressor/Compressor.cc \
+ test/compressor/test_compression_plugin.cc
+unittest_compression_plugin_CXXFLAGS = $(UNITTEST_CXXFLAGS)
+unittest_compression_plugin_LDADD = $(LIBOSD) $(LIBCOMMON) $(UNITTEST_LDADD) $(CEPH_GLOBAL)
+if LINUX
+unittest_compression_plugin_LDADD += -ldl
+endif
+check_TESTPROGRAMS += unittest_compression_plugin
+
+unittest_compression_snappy_SOURCES = \
+ test/compressor/test_compression_snappy.cc \
+ ${snappy_sources}
+unittest_compression_snappy_CXXFLAGS = $(UNITTEST_CXXFLAGS)
+unittest_compression_snappy_LDADD = $(LIBOSD) $(LIBCOMMON) $(UNITTEST_LDADD) $(CEPH_GLOBAL)
+unittest_compression_snappy_LDFLAGS = -lsnappy
+if LINUX
+unittest_compression_snappy_LDADD += -ldl
+endif
+check_TESTPROGRAMS += unittest_compression_snappy
+
+unittest_compression_plugin_snappy_SOURCES = \
+ test/compressor/test_compression_plugin_snappy.cc \
+ ${snappy_sources}
+unittest_compression_plugin_snappy_CXXFLAGS = ${AM_CXXFLAGS} ${UNITTEST_CXXFLAGS}
+unittest_compression_plugin_snappy_LDADD = $(LIBOSD) $(LIBCOMMON) $(UNITTEST_LDADD) $(CEPH_GLOBAL) $(LIBCOMPRESSOR)
+unittest_compression_plugin_snappy_LDFLAGS = -lsnappy
+if LINUX
+unittest_compression_plugin_snappy_LDADD += -ldl
+endif
+check_TESTPROGRAMS += unittest_compression_plugin_snappy
+
+endif # WITH_OSD
+endif # ENABLE_SERVER
diff --git a/src/test/compressor/compressor_example.h b/src/test/compressor/compressor_example.h
new file mode 100644
index 00000000000..3a96f8807d3
--- /dev/null
+++ b/src/test/compressor/compressor_example.h
@@ -0,0 +1,53 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph distributed storage system
+ *
+ * Copyright (C) 2015 Mirantis, Inc.
+ *
+ * Author: Alyona Kiseleva <akiselyova@mirantis.com>
+ *
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ */
+
+#ifndef CEPH_COMPRESSOR_EXAMPLE_H
+#define CEPH_COMPRESSOR_EXAMPLE_H
+
+#include <unistd.h>
+#include <errno.h>
+#include <algorithm>
+#include <sstream>
+
+#include "crush/CrushWrapper.h"
+#include "osd/osd_types.h"
+#include "compressor/Compressor.h"
+
+class CompressorExample : public Compressor {
+public:
+ virtual ~CompressorExample() {}
+
+ virtual int compress(bufferlist &in, bufferlist &out)
+ {
+ out = in;
+ return 0;
+ }
+
+ virtual int decompress(bufferlist &in, bufferlist &out)
+ {
+ out = in;
+ return 0;
+ }
+
+ virtual const char* get_method_name()
+ {
+ return "example";
+ }
+
+};
+
+#endif
diff --git a/src/test/compressor/compressor_plugin_example.cc b/src/test/compressor/compressor_plugin_example.cc
new file mode 100644
index 00000000000..96914ee58dd
--- /dev/null
+++ b/src/test/compressor/compressor_plugin_example.cc
@@ -0,0 +1,57 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph distributed storage system
+ *
+ * Copyright (C) 2015 Mirantis, Inc.
+ *
+ * Author: Alyona Kiseleva <akiselyova@mirantis.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ */
+
+#include <unistd.h>
+
+#include "ceph_ver.h"
+#include "compressor/CompressionPlugin.h"
+#include "compressor_example.h"
+
+class CompressorPluginExample : public CompressionPlugin {
+public:
+
+ CompressorPluginExample(CephContext* cct) : CompressionPlugin(cct)
+ {}
+
+ virtual int factory(CompressorRef *cs,
+ ostream *ss)
+ {
+ if (compressor == 0) {
+ CompressorExample *interface = new CompressorExample();
+ compressor = CompressorRef(interface);
+ }
+ *cs = compressor;
+ return 0;
+ }
+};
+
+// -----------------------------------------------------------------------------
+
+const char *__ceph_plugin_version()
+{
+ return CEPH_GIT_NICE_VER;
+}
+
+// -----------------------------------------------------------------------------
+
+int __ceph_plugin_init(CephContext *cct,
+ const std::string& type,
+ const std::string& name)
+{
+ PluginRegistry *instance = cct->get_plugin_registry();
+
+ return instance->add(type, name, new CompressorPluginExample(cct));
+}
diff --git a/src/test/compressor/test_compression_plugin.cc b/src/test/compressor/test_compression_plugin.cc
new file mode 100644
index 00000000000..6d8153259f1
--- /dev/null
+++ b/src/test/compressor/test_compression_plugin.cc
@@ -0,0 +1,71 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph distributed storage system
+ *
+ * Copyright (C) 2015 Mirantis, Inc.
+ *
+ * Author: Alyona Kiseleva <akiselyova@mirantis.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ */
+
+#include <errno.h>
+#include <signal.h>
+#include <stdlib.h>
+#include <gtest/gtest.h>
+#include "global/global_init.h"
+#include "compressor/CompressionPlugin.h"
+#include "common/ceph_argparse.h"
+#include "global/global_context.h"
+#include "common/config.h"
+
+TEST(CompressionPlugin, all)
+{
+ string directory(".libs");
+ CompressorRef compressor;
+ PluginRegistry *reg = g_ceph_context->get_plugin_registry();
+ EXPECT_TRUE(reg);
+ CompressionPlugin *factory = dynamic_cast<CompressionPlugin*>(reg->get_with_load("compressor", "invalid"));
+ EXPECT_FALSE(factory);
+ factory = dynamic_cast<CompressionPlugin*>(reg->get_with_load("compressor", "example"));
+ EXPECT_TRUE(factory);
+ stringstream ss;
+ EXPECT_EQ(0, factory->factory(&compressor, &ss));
+ EXPECT_TRUE(compressor.get());
+ {
+ Mutex::Locker l(reg->lock);
+ EXPECT_EQ(-ENOENT, reg->remove("compressor", "does not exist"));
+ EXPECT_EQ(0, reg->remove("compressor", "example"));
+ EXPECT_EQ(0, reg->load("compressor", "example"));
+ }
+}
+
+int main(int argc, char **argv) {
+ vector<const char*> args;
+ argv_to_vec(argc, (const char **)argv, args);
+
+ global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT, CODE_ENVIRONMENT_UTILITY, 0);
+ common_init_finish(g_ceph_context);
+
+ system("mkdir -p .libs/compressor");
+ system("cp .libs/libceph_example.so* .libs/compressor/");
+ g_conf->set_val("plugin_dir", ".libs", false, false);
+
+ ::testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+}
+
+/*
+ * Local Variables:
+ * compile-command: "cd ../.. ; make -j4 &&
+ * make unittest_compression_plugin &&
+ * valgrind --tool=memcheck \
+ * ./unittest_compression_plugin \
+ * --gtest_filter=*.* --log-to-stderr=true --debug-osd=20"
+ * End:
+ */
diff --git a/src/test/compressor/test_compression_plugin_snappy.cc b/src/test/compressor/test_compression_plugin_snappy.cc
new file mode 100644
index 00000000000..495e641e09e
--- /dev/null
+++ b/src/test/compressor/test_compression_plugin_snappy.cc
@@ -0,0 +1,58 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph distributed storage system
+ *
+ * Copyright (C) 2015 Mirantis, Inc.
+ *
+ * Author: Alyona Kiseleva <akiselyova@mirantis.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ */
+
+#include <errno.h>
+#include <signal.h>
+#include <stdlib.h>
+#include <gtest/gtest.h>
+#include "global/global_init.h"
+#include "compressor/Compressor.h"
+#include "common/ceph_argparse.h"
+#include "global/global_context.h"
+#include "common/config.h"
+
+TEST(CompressionPluginSnappy, factory)
+{
+ CompressorRef compressor = Compressor::create(g_ceph_context, "snappy");
+ cout << compressor;
+ EXPECT_TRUE(compressor.get());
+}
+
+int main(int argc, char **argv) {
+ vector<const char*> args;
+ argv_to_vec(argc, (const char **)argv, args);
+
+ global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT, CODE_ENVIRONMENT_UTILITY, 0);
+ common_init_finish(g_ceph_context);
+
+ system("mkdir -p .libs/compressor");
+ system("cp .libs/libceph_snappy.so* .libs/compressor/");
+
+ g_conf->set_val("plugin_dir", ".libs", false, false);
+
+ ::testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+}
+
+/*
+ * Local Variables:
+ * compile-command: "cd ../.. ; make -j4 &&
+ * make unittest_compression_plugin_snappy &&
+ * valgrind --tool=memcheck \
+ * ./unittest_compression_plugin_snappy \
+ * --gtest_filter=*.* --log-to-stderr=true --debug-osd=20"
+ * End:
+ */
diff --git a/src/test/compressor/test_compression_snappy.cc b/src/test/compressor/test_compression_snappy.cc
new file mode 100644
index 00000000000..69b0ebfaeda
--- /dev/null
+++ b/src/test/compressor/test_compression_snappy.cc
@@ -0,0 +1,62 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph distributed storage system
+ *
+ * Copyright (C) 2015 Mirantis, Inc.
+ *
+ * Author: Alyona Kiseleva <akiselyova@mirantis.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ */
+
+#include <errno.h>
+#include <string.h>
+#include <gtest/gtest.h>
+#include "global/global_init.h"
+#include "compressor/snappy/SnappyCompressor.h"
+#include "common/ceph_argparse.h"
+#include "global/global_context.h"
+#include "common/config.h"
+
+TEST(SnappyCompressor, compress_decompress)
+{
+ SnappyCompressor sp;
+ EXPECT_EQ(sp.get_method_name(), "snappy");
+ char* test = "This is test text";
+ int len = strlen(test);
+ bufferlist in, out;
+ in.append(test, len);
+ int res = sp.compress(in, out);
+ EXPECT_EQ(res, 0);
+ bufferlist after;
+ res = sp.decompress(out, after);
+ EXPECT_EQ(res, 0);
+}
+
+int main(int argc, char **argv) {
+ vector<const char*> args;
+ argv_to_vec(argc, (const char **)argv, args);
+
+ global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT, CODE_ENVIRONMENT_UTILITY, 0);
+ common_init_finish(g_ceph_context);
+
+ g_conf->set_val("compression_dir", ".libs", false, false);
+
+ ::testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+}
+
+/*
+ * Local Variables:
+ * compile-command: "cd ../.. ; make -j4 &&
+ * make unittest_compression_snappy &&
+ * valgrind --tool=memcheck \
+ * ./unittest_compression_snappy \
+ * --gtest_filter=*.* --log-to-stderr=true --debug-osd=20"
+ * End:
+ */