]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
unittest_compressor: unified compression tests, parameterized by plugin
authorSage Weil <sage@redhat.com>
Thu, 6 Oct 2016 15:25:56 +0000 (11:25 -0400)
committerSage Weil <sage@redhat.com>
Thu, 6 Oct 2016 19:36:07 +0000 (15:36 -0400)
This obsoletes the per-plugin plugin tests, which are tedious anyway.

Signed-off-by: Sage Weil <sage@redhat.com>
src/test/compressor/CMakeLists.txt
src/test/compressor/test_compression.cc [new file with mode: 0644]
src/test/compressor/test_compression_plugin_snappy.cc [deleted file]
src/test/compressor/test_compression_plugin_zlib.cc [deleted file]

index acad2517fa33bb8aaaca9cc78159958d40de2fa4..99edf0b7485ca8f5722542a6530bcf38fc63e1c7 100644 (file)
@@ -1,5 +1,13 @@
 add_library(ceph_example SHARED compressor_plugin_example.cc)
 
+# unittest_compression
+add_executable(unittest_compression
+  test_compression.cc
+  )
+add_ceph_unittest(unittest_compression ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/unittest_compression)
+target_link_libraries(unittest_compression global)
+add_dependencies(unittest_compression ceph_example)
+
 # unittest_compression_plugin
 add_executable(unittest_compression_plugin
   test_compression_plugin.cc
@@ -15,25 +23,9 @@ add_executable(unittest_compression_snappy
 add_ceph_unittest(unittest_compression_snappy ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/unittest_compression_snappy)
 target_link_libraries(unittest_compression_snappy global ceph_snappy)
 
-# unittest_compression_plugin_snappy
-add_executable(unittest_compression_plugin_snappy
-  test_compression_plugin_snappy.cc
-  )
-add_ceph_unittest(unittest_compression_plugin_snappy ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/unittest_compression_plugin_snappy)
-target_link_libraries(unittest_compression_plugin_snappy global)
-add_dependencies(unittest_compression_plugin_snappy ceph_snappy)
-
 # unittest_compression_zlib
 add_executable(unittest_compression_zlib
   test_compression_zlib.cc
   )
 add_ceph_unittest(unittest_compression_zlib ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/unittest_compression_zlib)
 target_link_libraries(unittest_compression_zlib global ceph_zlib)
-
-# unittest_compression_plugin_zlib
-add_executable(unittest_compression_plugin_zlib
-  test_compression_plugin_zlib.cc
-  )
-add_ceph_unittest(unittest_compression_plugin_zlib ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/unittest_compression_plugin_zlib)
-target_link_libraries(unittest_compression_plugin_zlib global)
-add_dependencies(unittest_compression_plugin_zlib ceph_zlib)
diff --git a/src/test/compressor/test_compression.cc b/src/test/compressor/test_compression.cc
new file mode 100644 (file)
index 0000000..12e49b6
--- /dev/null
@@ -0,0 +1,153 @@
+// -*- 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"
+
+class CompressionTest : public ::testing::Test,
+                       public ::testing::WithParamInterface<const char*> {
+public:
+  CompressorRef compressor;
+
+  void SetUp() {
+    compressor = Compressor::create(g_ceph_context, GetParam());
+    ASSERT_TRUE(compressor);
+  }
+  void TearDown() {
+    compressor.reset();
+  }
+};
+
+TEST_P(CompressionTest, load_plugin)
+{
+}
+
+TEST_P(CompressionTest, small_round_trip)
+{
+  bufferlist orig;
+  orig.append("This is a short string.  There are many strings like it but this one is mine.");
+  bufferlist compressed;
+  int r = compressor->compress(orig, compressed);
+  ASSERT_EQ(0, r);
+  bufferlist decompressed;
+  r = compressor->decompress(compressed, decompressed);
+  ASSERT_EQ(0, r);
+  ASSERT_EQ(decompressed.length(), orig.length());
+  ASSERT_TRUE(decompressed.contents_equal(orig));
+  cout << "orig " << orig.length() << " compressed " << compressed.length()
+       << " with " << GetParam() << std::endl;
+}
+
+TEST_P(CompressionTest, big_round_trip_repeated)
+{
+  unsigned len = 1048576 * 4;
+  bufferlist orig;
+  while (orig.length() < len) {
+    orig.append("This is a short string.  There are many strings like it but this one is mine.");
+  }
+  bufferlist compressed;
+  int r = compressor->compress(orig, compressed);
+  ASSERT_EQ(0, r);
+  bufferlist decompressed;
+  r = compressor->decompress(compressed, decompressed);
+  ASSERT_EQ(0, r);
+  ASSERT_EQ(decompressed.length(), orig.length());
+  ASSERT_TRUE(decompressed.contents_equal(orig));
+  cout << "orig " << orig.length() << " compressed " << compressed.length()
+       << " with " << GetParam() << std::endl;
+}
+
+TEST_P(CompressionTest, big_round_trip_randomish)
+{
+  unsigned len = 1048576 * 269;
+  bufferlist orig;
+  const char *alphabet = "abcdefghijklmnopqrstuvwxyz";
+  if (false) {
+    while (orig.length() < len) {
+      orig.append(alphabet[rand() % 10]);
+    }
+  } else {
+    bufferptr bp(len);
+    char *p = bp.c_str();
+    for (unsigned i=0; i<len; ++i) {
+      p[i] = alphabet[rand() % 10];
+    }
+    orig.append(bp);
+  }
+  bufferlist compressed;
+  int r = compressor->compress(orig, compressed);
+  ASSERT_EQ(0, r);
+  bufferlist decompressed;
+  r = compressor->decompress(compressed, decompressed);
+  ASSERT_EQ(0, r);
+  ASSERT_EQ(decompressed.length(), orig.length());
+  ASSERT_TRUE(decompressed.contents_equal(orig));
+  cout << "orig " << orig.length() << " compressed " << compressed.length()
+       << " with " << GetParam() << std::endl;
+}
+
+#if 0
+TEST_P(CompressionTest, big_round_trip_file)
+{
+  bufferlist orig;
+  int fd = ::open("bin/ceph-osd", O_RDONLY);
+  struct stat st;
+  ::fstat(fd, &st);
+  orig.read_fd(fd, st.st_size);
+
+  bufferlist compressed;
+  int r = compressor->compress(orig, compressed);
+  ASSERT_EQ(0, r);
+  bufferlist decompressed;
+  r = compressor->decompress(compressed, decompressed);
+  ASSERT_EQ(0, r);
+  ASSERT_EQ(decompressed.length(), orig.length());
+  ASSERT_TRUE(decompressed.contents_equal(orig));
+  cout << "orig " << orig.length() << " compressed " << compressed.length()
+       << " with " << GetParam() << std::endl;
+}
+#endif
+
+
+INSTANTIATE_TEST_CASE_P(
+  Compression,
+  CompressionTest,
+  ::testing::Values(
+    "zlib",
+    "snappy"));
+
+int main(int argc, char **argv) {
+  vector<const char*> args;
+  argv_to_vec(argc, (const char **)argv, args);
+  env_to_vec(args);
+
+  global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT, CODE_ENVIRONMENT_UTILITY, 0);
+  common_init_finish(g_ceph_context);
+
+  const char* env = getenv("CEPH_LIB");
+  if (env)
+    g_conf->set_val("plugin_dir", env, false, false);
+
+  ::testing::InitGoogleTest(&argc, argv);
+  return RUN_ALL_TESTS();
+}
diff --git a/src/test/compressor/test_compression_plugin_snappy.cc b/src/test/compressor/test_compression_plugin_snappy.cc
deleted file mode 100644 (file)
index 8b70c8c..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-// -*- 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);
-
-  const char* env = getenv("CEPH_LIB");
-  if (env)
-    g_conf->set_val("plugin_dir", env, 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_plugin_zlib.cc b/src/test/compressor/test_compression_plugin_zlib.cc
deleted file mode 100644 (file)
index fec8421..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-// -*- 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(CompressionPluginZlib, all)
-{
-  CompressorRef compressor = Compressor::create(g_ceph_context, "zlib");
-  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);
-
-  const char* env = getenv("CEPH_LIB");
-  if (env)
-    g_conf->set_val("plugin_dir", env, false, false);
-
-
-  ::testing::InitGoogleTest(&argc, argv);
-  return RUN_ALL_TESTS();
-}
-
-/*
- * Local Variables:
- * compile-command: "cd ../.. ; make -j4 && 
- *   make unittest_compression_plugin_zlib && 
- *   valgrind --tool=memcheck \
- *      ./unittest_compression_plugin_zlib \
- *      --gtest_filter=*.* --log-to-stderr=true --debug-osd=20"
- * End:
- */