}
}
+TEST(ZlibCompressor, isal_compress_zlib_decompress_random)
+{
+ g_conf->set_val("compressor_zlib_isal", "true");
+ g_ceph_context->_conf->apply_changes(NULL);
+ CompressorRef isal = Compressor::create(g_ceph_context, "zlib");
+ g_conf->set_val("compressor_zlib_isal", "false");
+ g_ceph_context->_conf->apply_changes(NULL);
+ CompressorRef zlib = Compressor::create(g_ceph_context, "zlib");
+
+ for (int cnt=0; cnt<1000; 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 = isal->compress(in, out);
+ EXPECT_EQ(res, 0);
+ bufferlist after;
+ res = zlib->decompress(out, after);
+ EXPECT_EQ(res, 0);
+ bufferlist exp;
+ exp.append(test, size);
+ EXPECT_TRUE(exp.contents_equal(after));
+ }
+}
+
+TEST(ZlibCompressor, isal_compress_zlib_decompress_walk)
+{
+ g_conf->set_val("compressor_zlib_isal", "true");
+ g_ceph_context->_conf->apply_changes(NULL);
+ CompressorRef isal = Compressor::create(g_ceph_context, "zlib");
+ g_conf->set_val("compressor_zlib_isal", "false");
+ g_ceph_context->_conf->apply_changes(NULL);
+ CompressorRef zlib = Compressor::create(g_ceph_context, "zlib");
+
+ for (int cnt=0; cnt<1000; cnt++)
+ {
+ srand(cnt + 1000);
+ int log2 = (rand()%18) + 1;
+ int size = (rand() % (1 << log2)) + 1;
+
+ int range = 1;
+
+ char test[size];
+ test[0] = rand()%256;
+ for (int i=1; i<size; ++i)
+ test[i] = test[i-1] + rand()%(range*2+1) - range;
+ bufferlist in, out;
+ in.append(test, size);
+
+ int res = isal->compress(in, out);
+ EXPECT_EQ(res, 0);
+ bufferlist after;
+ res = zlib->decompress(out, after);
+ EXPECT_EQ(res, 0);
+ bufferlist exp;
+ exp.append(test, size);
+ EXPECT_TRUE(exp.contents_equal(after));
+ }
+}
+
+
int main(int argc, char **argv) {
vector<const char*> args;
argv_to_vec(argc, (const char **)argv, args);