* If we have a buffer of 5 bytes (X below) and a chunk size of 3 * bytes, for k=3, m=1 an additional 7 bytes (P and C below) will * need to be allocated for padding (P) and the 3 coding bytes (C). * * X -+ +----------+ +-X * X | | data 0 | | X * X | +----------+ | X * X | +----------+ | X -> +-X * X -+ | data 1 | +-X -> | X * P -+ +----------+ | P * P | +--------
| 110 | * underlying allocation function enforces it. |
| 111 | */ |
| 112 | TEST(ErasureCodeTest, encode_memory_align) |
| 113 | { |
| 114 | int k = 3; |
| 115 | int m = 1; |
| 116 | unsigned chunk_size = ErasureCode::SIMD_ALIGN * 7; |
| 117 | ErasureCodeTest erasure_code(k, m, chunk_size); |
| 118 | |
| 119 | shard_id_set want_to_encode; |
| 120 | want_to_encode.insert_range(shard_id_t(0), erasure_code.get_chunk_count()); |
| 121 | string data(chunk_size + chunk_size / 2, 'X'); // uses 1.5 chunks out of 3 |
| 122 | // make sure nothing is memory aligned |
| 123 | bufferptr ptr(buffer::create_aligned(data.length() + 1, ErasureCode::SIMD_ALIGN)); |
| 124 | ptr.copy_in(1, data.length(), data.c_str()); |
| 125 | ptr.set_offset(1); |
| 126 | ptr.set_length(data.length()); |
| 127 | bufferlist in; |
| 128 | in.append(ptr); |
| 129 | shard_id_map<bufferlist> encoded(k+m); |
| 130 | |
| 131 | ASSERT_FALSE(in.is_aligned(ErasureCode::SIMD_ALIGN)); |
| 132 | ASSERT_EQ(0, erasure_code.encode(want_to_encode, in, &encoded)); |
| 133 | for (shard_id_t i; i < erasure_code.get_chunk_count(); ++i) |
| 134 | ASSERT_TRUE(encoded[i].is_aligned(ErasureCode::SIMD_ALIGN)); |
| 135 | for (unsigned i = 0; i < chunk_size / 2; i++) |
| 136 | ASSERT_EQ(encoded[shard_id_t(1)][i], 'X'); |
| 137 | ASSERT_NE(encoded[shard_id_t(1)][chunk_size / 2], 'X'); |
| 138 | } |
| 139 | |
| 140 | TEST(ErasureCodeTest, encode_misaligned_non_contiguous) |
| 141 | { |
nothing calls this directly
no test coverage detected