From: Kefu Chai Date: Sun, 20 Dec 2020 04:15:06 +0000 (+0800) Subject: test/erasure-code: define variables closer to where they are used X-Git-Tag: v16.1.0~173^2~5 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=9e0fe82ddeb9a00b7fd6d5b50c5250cdfde09970;p=ceph.git test/erasure-code: define variables closer to where they are used for better readability. Signed-off-by: Kefu Chai --- diff --git a/src/test/erasure-code/TestErasureCodeShec_arguments.cc b/src/test/erasure-code/TestErasureCodeShec_arguments.cc index f01db75ed23..14c4f5f403c 100644 --- a/src/test/erasure-code/TestErasureCodeShec_arguments.cc +++ b/src/test/erasure-code/TestErasureCodeShec_arguments.cc @@ -164,8 +164,6 @@ bool search_table_shec432(set want_to_read, set available_chunks) { TEST(ParameterTest, combination_all) { - int result; - unsigned alignment, tail, padded_length; const unsigned int kObjectSize = 128; //get profile @@ -175,10 +173,10 @@ TEST(ParameterTest, combination_all) int i_k = atoi(k); int i_m = atoi(m); int i_c = atoi(c); - alignment = i_k * 8 * sizeof(int); - tail = kObjectSize % alignment; - padded_length = kObjectSize + (tail ? (alignment - tail) : 0); - unsigned c_size = padded_length / i_k; + const unsigned alignment = i_k * 8 * sizeof(int); + const unsigned tail = kObjectSize % alignment; + const unsigned padded_length = kObjectSize + (tail ? (alignment - tail) : 0); + const unsigned c_size = padded_length / i_k; //init ErasureCodeShecTableCache tcache; @@ -194,7 +192,7 @@ TEST(ParameterTest, combination_all) (*profile)["m"] = m; (*profile)["c"] = c; - result = shec->init(*profile, &cerr); + int result = shec->init(*profile, &cerr); //check profile EXPECT_EQ(i_k, shec->k); @@ -208,60 +206,48 @@ TEST(ParameterTest, combination_all) EXPECT_EQ(0, result); //encode - bufferlist in,out1; - set want_to_encode; - map encoded; - + bufferlist in; in.append("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"//length = 62 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"//124 "0123"//128 ); + set want_to_encode; for (unsigned int i = 0; i < shec->get_chunk_count(); ++i) { want_to_encode.insert(i); } + map encoded; result = shec->encode(want_to_encode, in, &encoded); EXPECT_EQ(0, result); EXPECT_EQ(i_k+i_m, (int)encoded.size()); EXPECT_EQ(c_size, encoded[0].length()); + bufferlist out1; //out1 is "encoded" for (unsigned int i = 0; i < encoded.size(); ++i) { out1.append(encoded[i]); } EXPECT_FALSE(out1 == in); - set want_to_read, available_chunks, want_to_read_without_avails; - map>> minimum_chunks; - set::iterator itr; - int array_want_to_read[shec->get_chunk_count()]; - int array_available_chunks[shec->get_chunk_count()]; - int dresult,cmp; - map inchunks,decoded; - bufferlist usable; - unsigned int minimum_count; - for (unsigned int w1 = 0; w1 <= shec->get_chunk_count(); ++w1) { const unsigned int r1 = w1; // combination(k+m,r1) - for (unsigned int i = 0; i < r1; ++i) { - array_want_to_read[i] = 1; - } - for (unsigned int i = r1; i < shec->get_chunk_count(); ++i) { - array_want_to_read[i] = 0; + int array_want_to_read[shec->get_chunk_count()]; + for (unsigned int i = 0; i < shec->get_chunk_count(); ++i) { + array_want_to_read[i] = i < r1 ? 1 : 0; } for (unsigned w2 = 0; w2 <= shec->get_chunk_count(); ++w2) { const unsigned int r2 = w2; // combination(k+m,r2) - for (unsigned int i = 0; i < r2; ++i ) { - array_available_chunks[i] = 1; - } - for (unsigned int i = r2; i < shec->get_chunk_count(); ++i ) { - array_available_chunks[i] = 0; + int array_available_chunks[shec->get_chunk_count()]; + for (unsigned int i = 0; i < shec->get_chunk_count(); ++i ) { + array_available_chunks[i] = i < r2 ? 1 : 0; } do { do { + set want_to_read, available_chunks; + map inchunks; for (unsigned int i = 0; i < shec->get_chunk_count(); ++i) { if (array_want_to_read[i]) { want_to_read.insert(i); @@ -272,12 +258,14 @@ TEST(ParameterTest, combination_all) } } + map>> minimum_chunks; + map decoded; result = shec->minimum_to_decode(want_to_read, available_chunks, &minimum_chunks); - dresult = shec->decode(want_to_read, inchunks, &decoded, - shec->get_chunk_size(kObjectSize)); + int dresult = shec->decode(want_to_read, inchunks, &decoded, + shec->get_chunk_size(kObjectSize)); ++count_num; - minimum_count = 0; + unsigned int minimum_count = 0; if (want_to_read.size() == 0) { EXPECT_EQ(0, result); @@ -290,9 +278,10 @@ TEST(ParameterTest, combination_all) } } else { // want - avail - for (itr = want_to_read.begin();itr != want_to_read.end(); ++itr) { - if (!available_chunks.count(*itr)) { - want_to_read_without_avails.insert(*itr); + set want_to_read_without_avails; + for (auto chunk : want_to_read) { + if (!available_chunks.count(chunk)) { + want_to_read_without_avails.insert(chunk); } else { ++minimum_count; } @@ -306,9 +295,9 @@ TEST(ParameterTest, combination_all) EXPECT_NE(0u, decoded.size()); for (unsigned int i = 0; i < shec->get_data_chunk_count(); ++i) { if (array_want_to_read[i]) { - usable.clear(); + bufferlist usable; usable.substr_of(in, c_size * i, c_size); - cmp = memcmp(decoded[i].c_str(), usable.c_str(), c_size); + int cmp = memcmp(decoded[i].c_str(), usable.c_str(), c_size); EXPECT_EQ(c_size, decoded[i].length()); EXPECT_EQ(0, cmp); if (cmp != 0) { @@ -337,9 +326,9 @@ TEST(ParameterTest, combination_all) EXPECT_NE(0u, decoded.size()); for (unsigned int i = 0; i < shec->get_data_chunk_count(); ++i) { if (array_want_to_read[i]) { - usable.clear(); + bufferlist usable; usable.substr_of(in, c_size * i, c_size); - cmp = memcmp(decoded[i].c_str(), usable.c_str(), c_size); + int cmp = memcmp(decoded[i].c_str(), usable.c_str(), c_size); EXPECT_EQ(c_size, decoded[i].length()); EXPECT_EQ(0, cmp); if (cmp != 0) { @@ -366,14 +355,6 @@ TEST(ParameterTest, combination_all) } } } - - want_to_read.clear(); - want_to_read_without_avails.clear(); - available_chunks.clear(); - minimum_chunks.clear(); - inchunks.clear(); - decoded.clear(); - usable.clear(); } while (std::prev_permutation( array_want_to_read, array_want_to_read + shec->get_chunk_count()));