From 91176f142c1bd525cedce85867dcf4f049b6e8a7 Mon Sep 17 00:00:00 2001 From: Loic Dachary Date: Thu, 27 Mar 2014 11:07:11 +0100 Subject: [PATCH] erasure-code: test encode/decode of SSE optimized jerasure plugins If the machine running make check has the required CPU features available, load the SSE optimized plugin and check that it can encode / decode a simple payload. If the CPU features are not available, only test the generic plugin and display an informative message about the tests that were skipped. Signed-off-by: Loic Dachary --- .../TestErasureCodePluginJerasure.cc | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/src/test/erasure-code/TestErasureCodePluginJerasure.cc b/src/test/erasure-code/TestErasureCodePluginJerasure.cc index 0e0e31e27f63b..21f661577a02d 100644 --- a/src/test/erasure-code/TestErasureCodePluginJerasure.cc +++ b/src/test/erasure-code/TestErasureCodePluginJerasure.cc @@ -127,7 +127,89 @@ TEST(ErasureCodePlugin, select) ceph_arch_intel_sse2 = arch_intel_sse2; } +TEST(ErasureCodePlugin, sse) +{ + ceph_arch_probe(); + bool sse4 = ceph_arch_intel_pclmul && + ceph_arch_intel_sse42 && ceph_arch_intel_sse41 && + ceph_arch_intel_ssse3 && ceph_arch_intel_sse3 && + ceph_arch_intel_sse2; + bool sse3 = ceph_arch_intel_ssse3 && ceph_arch_intel_sse3 && + ceph_arch_intel_sse2; + vector sse_variants; + sse_variants.push_back("generic"); + if (!sse3) + cerr << "SKIP sse3 plugin testing because CPU does not support it\n"; + else + sse_variants.push_back("sse3"); + if (!sse4) + cerr << "SKIP sse4 plugin testing because CPU does not support it\n"; + else + sse_variants.push_back("sse4"); + +#define LARGE_ENOUGH 2048 + bufferptr in_ptr(buffer::create_page_aligned(LARGE_ENOUGH)); + in_ptr.zero(); + in_ptr.set_length(0); + const char *payload = + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; + in_ptr.append(payload, strlen(payload)); + bufferlist in; + in.push_front(in_ptr); + + ErasureCodePluginRegistry &instance = ErasureCodePluginRegistry::instance(); + map parameters; + parameters["directory"] = ".libs"; + parameters["technique"] = "reed_sol_van"; + parameters["k"] = "2"; + parameters["m"] = "1"; + for (vector::iterator sse_variant = sse_variants.begin(); + sse_variant != sse_variants.end(); + sse_variant++) { + // + // load the plugin variant + // + ErasureCodeInterfaceRef erasure_code; + EXPECT_FALSE(erasure_code); + EXPECT_EQ(0, instance.factory("jerasure_" + *sse_variant, parameters, + &erasure_code, cerr)); EXPECT_TRUE(erasure_code); + + // + // encode + // + int want_to_encode[] = { 0, 1, 2 }; + map encoded; + EXPECT_EQ(0, erasure_code->encode(set(want_to_encode, want_to_encode+3), + in, + &encoded)); + EXPECT_EQ(3u, encoded.size()); + unsigned length = encoded[0].length(); + EXPECT_EQ(0, strncmp(encoded[0].c_str(), in.c_str(), length)); + EXPECT_EQ(0, strncmp(encoded[1].c_str(), in.c_str() + length, + in.length() - length)); + + // + // decode with reconstruction + // + map degraded = encoded; + degraded.erase(1); + EXPECT_EQ(2u, degraded.size()); + int want_to_decode[] = { 0, 1 }; + map decoded; + EXPECT_EQ(0, erasure_code->decode(set(want_to_decode, want_to_decode+2), + degraded, + &decoded)); + EXPECT_EQ(3u, decoded.size()); + EXPECT_EQ(length, decoded[0].length()); + EXPECT_EQ(0, strncmp(decoded[0].c_str(), in.c_str(), length)); + EXPECT_EQ(0, strncmp(decoded[1].c_str(), in.c_str() + length, + in.length() - length)); + } } -- 2.39.5