From: Rongqi Sun Date: Mon, 12 Aug 2024 10:20:09 +0000 (+0800) Subject: uadk: add unit tests X-Git-Tag: v20.0.0~1221^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=d58f32726be607ea3b5ce2b4c88cb30c3e5765ca;p=ceph.git uadk: add unit tests Signed-off-by: Rongqi Sun --- diff --git a/src/test/compressor/test_compression.cc b/src/test/compressor/test_compression.cc index 6ae49daf544..98ef159dfb8 100644 --- a/src/test/compressor/test_compression.cc +++ b/src/test/compressor/test_compression.cc @@ -610,3 +610,88 @@ TEST(QAT, enc_noqat_dec_qat) { } #endif // HAVE_QATZIP + +#ifdef HAVE_UADK +TEST(UADK, enc_uadk_dec_nouadk) { + //reserve for more algs in the future + const char* alg_collection[] = {"zlib"}; + + for (auto alg : alg_collection) { + g_conf().set_val("uadk_compressor_enabled", "true"); + g_conf().set_val("compressor_zlib_winsize", "15"); + g_ceph_context->_conf.apply_changes(nullptr); + CompressorRef hw = Compressor::create(g_ceph_context, alg); + if (hw == NULL) + return; + + g_conf().set_val("uadk_compressor_enabled", "false"); + g_conf().set_val("compressor_zlib_winsize", "15"); + g_ceph_context->_conf.apply_changes(nullptr); + CompressorRef sw = 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); + + std::optional compressor_message; + int res = hw->compress(in, out, compressor_message); + EXPECT_EQ(res, 0); + bufferlist after; + res = sw->decompress(out, after, compressor_message); + EXPECT_EQ(res, 0); + bufferlist exp; + exp.append(test, size); + EXPECT_TRUE(exp.contents_equal(after)); + } + } +} + +TEST(UADK, enc_nouadk_dec_uadk) { + const char* alg_collection[] = {"zlib"}; + + for (auto alg : alg_collection) { + g_conf().set_val("uadk_compressor_enabled", "true"); + g_conf().set_val("compressor_zlib_winsize", "15"); + g_ceph_context->_conf.apply_changes(nullptr); + CompressorRef hw = Compressor::create(g_ceph_context, alg); + if (hw == NULL) + return; + g_conf().set_val("uadk_compressor_enabled", "false"); + g_conf().set_val("compressor_zlib_winsize", "15"); + g_ceph_context->_conf.apply_changes(nullptr); + CompressorRef sw = 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); + + std::optional compressor_message; + int res = sw->compress(in, out, compressor_message); + EXPECT_EQ(res, 0); + bufferlist after; + res = hw->decompress(out, after, compressor_message); + EXPECT_EQ(res, 0); + bufferlist exp; + exp.append(test, size); + EXPECT_TRUE(exp.contents_equal(after)); + } + } +} + +#endif //HAVE_UADK