Skip to content

Commit d58f327

Browse files
committed
uadk: add unit tests
Signed-off-by: Rongqi Sun <[email protected]>
1 parent e93c7e0 commit d58f327

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed

src/test/compressor/test_compression.cc

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,3 +610,88 @@ TEST(QAT, enc_noqat_dec_qat) {
610610
}
611611

612612
#endif // HAVE_QATZIP
613+
614+
#ifdef HAVE_UADK
615+
TEST(UADK, enc_uadk_dec_nouadk) {
616+
//reserve for more algs in the future
617+
const char* alg_collection[] = {"zlib"};
618+
619+
for (auto alg : alg_collection) {
620+
g_conf().set_val("uadk_compressor_enabled", "true");
621+
g_conf().set_val("compressor_zlib_winsize", "15");
622+
g_ceph_context->_conf.apply_changes(nullptr);
623+
CompressorRef hw = Compressor::create(g_ceph_context, alg);
624+
if (hw == NULL)
625+
return;
626+
627+
g_conf().set_val("uadk_compressor_enabled", "false");
628+
g_conf().set_val("compressor_zlib_winsize", "15");
629+
g_ceph_context->_conf.apply_changes(nullptr);
630+
CompressorRef sw = Compressor::create(g_ceph_context, alg);
631+
632+
//generate random buffer
633+
for (int cnt = 0; cnt < 100; cnt++) {
634+
srand(cnt + 1000);
635+
int log2 = (rand()%18) + 1;
636+
int size = (rand() % (1 << log2)) + 1;
637+
638+
char test[size];
639+
for (int i = 0; i < size; ++i)
640+
test[i] = rand()%256;
641+
bufferlist in, out;
642+
in.append(test, size);
643+
644+
std::optional<int32_t> compressor_message;
645+
int res = hw->compress(in, out, compressor_message);
646+
EXPECT_EQ(res, 0);
647+
bufferlist after;
648+
res = sw->decompress(out, after, compressor_message);
649+
EXPECT_EQ(res, 0);
650+
bufferlist exp;
651+
exp.append(test, size);
652+
EXPECT_TRUE(exp.contents_equal(after));
653+
}
654+
}
655+
}
656+
657+
TEST(UADK, enc_nouadk_dec_uadk) {
658+
const char* alg_collection[] = {"zlib"};
659+
660+
for (auto alg : alg_collection) {
661+
g_conf().set_val("uadk_compressor_enabled", "true");
662+
g_conf().set_val("compressor_zlib_winsize", "15");
663+
g_ceph_context->_conf.apply_changes(nullptr);
664+
CompressorRef hw = Compressor::create(g_ceph_context, alg);
665+
if (hw == NULL)
666+
return;
667+
g_conf().set_val("uadk_compressor_enabled", "false");
668+
g_conf().set_val("compressor_zlib_winsize", "15");
669+
g_ceph_context->_conf.apply_changes(nullptr);
670+
CompressorRef sw = Compressor::create(g_ceph_context, alg);
671+
672+
//generate random buffer
673+
for (int cnt = 0; cnt < 100; cnt++) {
674+
srand(cnt + 1000);
675+
int log2 = (rand()%18) +1;
676+
int size = (rand() % (1 << log2)) + 1;
677+
678+
char test[size];
679+
for (int i = 0; i < size; ++i)
680+
test[i] = rand()%256;
681+
bufferlist in, out;
682+
in.append(test, size);
683+
684+
std::optional<int32_t> compressor_message;
685+
int res = sw->compress(in, out, compressor_message);
686+
EXPECT_EQ(res, 0);
687+
bufferlist after;
688+
res = hw->decompress(out, after, compressor_message);
689+
EXPECT_EQ(res, 0);
690+
bufferlist exp;
691+
exp.append(test, size);
692+
EXPECT_TRUE(exp.contents_equal(after));
693+
}
694+
}
695+
}
696+
697+
#endif //HAVE_UADK

0 commit comments

Comments
 (0)