#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"
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('/');
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 {
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));
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);
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;
int res = compressor->compress(in, out);
EXPECT_EQ(res, 0);
}
+ free(data);
}
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)
#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));
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();
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"));
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++)
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++)
}
#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