]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/test/compressor/test_compression.cc
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / test / compressor / test_compression.cc
index 179d1acbf54a30ce0b6d8bd1bd998144113eb198..102ab56153db7d73fb9b5b04cb907c3f0bc1495f 100644 (file)
@@ -18,7 +18,9 @@
 #include <signal.h>
 #include <stdlib.h>
 #include "gtest/gtest.h"
+#include "common/ceph_context.h"
 #include "common/config.h"
+#include "common/Mutex.h"
 #include "compressor/Compressor.h"
 #include "compressor/CompressionPlugin.h"
 #include "global/global_context.h"
@@ -32,7 +34,7 @@ public:
 
   CompressorTest() {
     // note for later
-    old_zlib_isal = g_conf->compressor_zlib_isal;
+    old_zlib_isal = g_conf()->compressor_zlib_isal;
 
     plugin = GetParam();
     size_t pos = plugin.find('/');
@@ -40,20 +42,20 @@ public:
       string isal = plugin.substr(pos + 1);
       plugin = plugin.substr(0, pos);
       if (isal == "isal") {
-       g_conf->set_val("compressor_zlib_isal", "true");
-       g_ceph_context->_conf->apply_changes(NULL);
+       g_conf().set_val("compressor_zlib_isal", "true");
+       g_ceph_context->_conf.apply_changes(nullptr);
       } else if (isal == "noisal") {
-       g_conf->set_val("compressor_zlib_isal", "false");
-       g_ceph_context->_conf->apply_changes(NULL);
+       g_conf().set_val("compressor_zlib_isal", "false");
+       g_ceph_context->_conf.apply_changes(nullptr);
       } else {
-       assert(0 == "bad option");
+       ceph_abort_msg("bad option");
       }
     }
     cout << "[plugin " << plugin << " (" << GetParam() << ")]" << std::endl;
   }
   ~CompressorTest() override {
-    g_conf->set_val("compressor_zlib_isal", old_zlib_isal ? "true" : "false");
-    g_ceph_context->_conf->apply_changes(NULL);
+    g_conf().set_val("compressor_zlib_isal", old_zlib_isal ? "true" : "false");
+    g_ceph_context->_conf.apply_changes(nullptr);
   }
 
   void SetUp() override {
@@ -174,7 +176,7 @@ TEST_P(CompressorTest, compress_decompress)
   after.clear();
   size_t compressed_len = out.length();
   out.append_zero(12);
-  auto it = out.begin();
+  auto it = out.cbegin();
   res = compressor->decompress(it, compressed_len, after);
   EXPECT_EQ(res, 0);
   EXPECT_TRUE(exp.contents_equal(after));
@@ -197,8 +199,9 @@ TEST_P(CompressorTest, compress_decompress)
   bufferlist prefix;
   prefix.append(string("some prefix"));
   size_t prefix_len = prefix.length();
-  out.claim_prepend(prefix);
-  it = out.begin();
+  prefix.claim_append(out);
+  out.swap(prefix);
+  it = out.cbegin();
   it.advance(prefix_len);
   res = compressor->decompress(it, compressed_len, after);
   EXPECT_EQ(res, 0);
@@ -223,7 +226,7 @@ TEST_P(CompressorTest, sharded_input_decompress)
   size_t left = out.length()-small_prefix_size;
   size_t offs = small_prefix_size;
   while( left > 0 ){
-    size_t shard_size = MIN( 2048, left );
+    size_t shard_size = std::min<size_t>(2048, left);
     tmp.substr_of(out, offs, shard_size );
     out2.append( tmp );
     left -= shard_size;
@@ -248,6 +251,7 @@ void test_compress(CompressorRef compressor, size_t size)
     int res = compressor->compress(in, out);
     EXPECT_EQ(res, 0);
   }
+  free(data);
 }
 
 void test_decompress(CompressorRef compressor, size_t size)
@@ -265,6 +269,7 @@ void test_decompress(CompressorRef compressor, size_t size)
     int res = compressor->decompress(out, out_dec);
     EXPECT_EQ(res, 0);
   }
+  free(data);
 }
 
 TEST_P(CompressorTest, compress_1024)
@@ -330,21 +335,24 @@ INSTANTIATE_TEST_CASE_P(
 #endif
     "zlib/noisal",
     "snappy",
+#ifdef HAVE_BROTLI
+    "brotli",
+#endif
     "zstd"));
 
 #ifdef __x86_64__
 
 TEST(ZlibCompressor, zlib_isal_compatibility)
 {
-  g_conf->set_val("compressor_zlib_isal", "true");
-  g_ceph_context->_conf->apply_changes(NULL);
+  g_conf().set_val("compressor_zlib_isal", "true");
+  g_ceph_context->_conf.apply_changes(nullptr);
   CompressorRef isal = Compressor::create(g_ceph_context, "zlib");
   if (!isal) {
     // skip the test if the plugin is not ready
     return;
   }
-  g_conf->set_val("compressor_zlib_isal", "false");
-  g_ceph_context->_conf->apply_changes(NULL);
+  g_conf().set_val("compressor_zlib_isal", "false");
+  g_ceph_context->_conf.apply_changes(nullptr);
   CompressorRef zlib = Compressor::create(g_ceph_context, "zlib");
   char test[101];
   srand(time(0));
@@ -361,7 +369,7 @@ TEST(ZlibCompressor, zlib_isal_compatibility)
   res = zlib->decompress(out, after);
   EXPECT_EQ(res, 0);
   bufferlist exp;
-  exp.append(test);
+  exp.append(static_cast<char*>(test));
   EXPECT_TRUE(exp.contents_equal(after));
   after.clear();
   out.clear();
@@ -371,27 +379,25 @@ TEST(ZlibCompressor, zlib_isal_compatibility)
   EXPECT_EQ(res, 0);
   res = isal->decompress(out, after);
   EXPECT_EQ(res, 0);
-  exp.append(test);
+  exp.append(static_cast<char*>(test));
   EXPECT_TRUE(exp.contents_equal(after));
 }
 #endif
 
 TEST(CompressionPlugin, all)
 {
-  const char* env = getenv("CEPH_LIB");
-  std::string directory(env ? env : ".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);
+  ASSERT_TRUE(factory);
   stringstream ss;
   EXPECT_EQ(0, factory->factory(&compressor, &ss));
   EXPECT_TRUE(compressor.get());
   {
-    Mutex::Locker l(reg->lock);
+    std::lock_guard 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"));
@@ -402,15 +408,15 @@ TEST(CompressionPlugin, all)
 
 TEST(ZlibCompressor, isal_compress_zlib_decompress_random)
 {
-  g_conf->set_val("compressor_zlib_isal", "true");
-  g_ceph_context->_conf->apply_changes(NULL);
+  g_conf().set_val("compressor_zlib_isal", "true");
+  g_ceph_context->_conf.apply_changes(nullptr);
   CompressorRef isal = Compressor::create(g_ceph_context, "zlib");
   if (!isal) {
     // skip the test if the plugin is not ready
     return;
   }
-  g_conf->set_val("compressor_zlib_isal", "false");
-  g_ceph_context->_conf->apply_changes(NULL);
+  g_conf().set_val("compressor_zlib_isal", "false");
+  g_ceph_context->_conf.apply_changes(nullptr);
   CompressorRef zlib = Compressor::create(g_ceph_context, "zlib");
 
   for (int cnt=0; cnt<100; cnt++)
@@ -438,15 +444,15 @@ TEST(ZlibCompressor, isal_compress_zlib_decompress_random)
 
 TEST(ZlibCompressor, isal_compress_zlib_decompress_walk)
 {
-  g_conf->set_val("compressor_zlib_isal", "true");
-  g_ceph_context->_conf->apply_changes(NULL);
+  g_conf().set_val("compressor_zlib_isal", "true");
+  g_ceph_context->_conf.apply_changes(nullptr);
   CompressorRef isal = Compressor::create(g_ceph_context, "zlib");
   if (!isal) {
     // skip the test if the plugin is not ready
     return;
   }
-  g_conf->set_val("compressor_zlib_isal", "false");
-  g_ceph_context->_conf->apply_changes(NULL);
+  g_conf().set_val("compressor_zlib_isal", "false");
+  g_ceph_context->_conf.apply_changes(nullptr);
   CompressorRef zlib = Compressor::create(g_ceph_context, "zlib");
 
   for (int cnt=0; cnt<100; cnt++)
@@ -476,3 +482,78 @@ TEST(ZlibCompressor, isal_compress_zlib_decompress_walk)
 }
 
 #endif // __x86_64__
+
+#ifdef HAVE_QATZIP
+TEST(QAT, enc_qat_dec_noqat) {
+#ifdef HAVE_LZ4
+  const char* alg_collection[] = {"zlib", "lz4", "snappy"}; 
+#else
+  const char* alg_collection[] = {"zlib", "snappy"}; 
+#endif
+  for (auto alg : alg_collection) {
+    g_conf().set_val("qat_compressor_enabled", "true");
+    CompressorRef q = Compressor::create(g_ceph_context, alg);
+    g_conf().set_val("qat_compressor_enabled", "false");
+    CompressorRef noq = Compressor::create(g_ceph_context, alg);
+
+    // generate random buffer
+    for (int cnt=0; cnt<100; cnt++) {
+      srand(cnt + 1000);
+      int log2 = (rand()%18) + 1;
+      int size = (rand() % (1 << log2)) + 1;
+  
+      char test[size];
+      for (int i=0; i<size; ++i)
+        test[i] = rand()%256;
+      bufferlist in, out;
+      in.append(test, size);
+  
+      int res = q->compress(in, out);
+      EXPECT_EQ(res, 0);
+      bufferlist after;
+      res = noq->decompress(out, after);
+      EXPECT_EQ(res, 0);
+      bufferlist exp;
+      exp.append(test, size);
+      EXPECT_TRUE(exp.contents_equal(after));
+    }
+  }
+}
+
+TEST(QAT, enc_noqat_dec_qat) {
+#ifdef HAVE_LZ4
+  const char* alg_collection[] = {"zlib", "lz4", "snappy"}; 
+#else
+  const char* alg_collection[] = {"zlib", "snappy"}; 
+#endif
+  for (auto alg : alg_collection) {
+    g_conf().set_val("qat_compressor_enabled", "true");
+    CompressorRef q = Compressor::create(g_ceph_context, alg);
+    g_conf().set_val("qat_compressor_enabled", "false");
+    CompressorRef noq = Compressor::create(g_ceph_context, alg);
+
+    // generate random buffer
+    for (int cnt=0; cnt<100; cnt++) {
+      srand(cnt + 1000);
+      int log2 = (rand()%18) + 1;
+      int size = (rand() % (1 << log2)) + 1;
+  
+      char test[size];
+      for (int i=0; i<size; ++i)
+        test[i] = rand()%256;
+      bufferlist in, out;
+      in.append(test, size);
+  
+      int res = noq->compress(in, out);
+      EXPECT_EQ(res, 0);
+      bufferlist after;
+      res = q->decompress(out, after);
+      EXPECT_EQ(res, 0);
+      bufferlist exp;
+      exp.append(test, size);
+      EXPECT_TRUE(exp.contents_equal(after));
+    }
+  }
+}
+
+#endif // HAVE_QATZIP