]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
unittest_cdc: adjust tests a bit
authorSage Weil <sage@newdream.net>
Thu, 14 May 2020 21:17:54 +0000 (16:17 -0500)
committerSage Weil <sage@newdream.net>
Wed, 27 May 2020 12:47:28 +0000 (07:47 -0500)
Seed random buffers!

Include average in histogram, and do the binning slightly differently.

Signed-off-by: Sage Weil <sage@newdream.net>
src/test/common/test_cdc.cc

index 65385836b962cbc38d1abb9c64bbbe94e6f537a5..7e89bb755c6b65cc038cdfea71d1792ea9dcf650 100644 (file)
 #include "common/CDC.h"
 #include "gtest/gtest.h"
 
-void generate_buffer(int size, bufferlist *outbl)
+void generate_buffer(int size, bufferlist *outbl, int seed = 0)
 {
   outbl->clear();
   outbl->append_zero(size);
   char *b = outbl->c_str();
   std::mt19937_64 engine;
+  engine.seed(seed);
   for (size_t i = 0; i < size / sizeof(uint64_t); ++i) {
     ((uint64_t*)b)[i] = engine();
   }
@@ -109,18 +110,27 @@ void do_size_histogram(CDC& cdc, bufferlist& bl,
 {
   vector<pair<uint64_t, uint64_t>> chunks;
   cdc.calc_chunks(bl, &chunks);
+  uint64_t total = 0;
+  uint64_t num = 0;
   for (auto& i : chunks) {
     //unsigned b = i.second & 0xfffff000;
-    unsigned b = 1 << cbits(i.second);
+    unsigned b = 1 << (cbits(i.second - 1));
     (*h)[b]++;
+    ++num;
+    total += i.second;
   }
+  (*h)[0] = total / num;
 }
 
 void print_histogram(map<int,int>& h)
 {
   cout << "size\tcount" << std::endl;
   for (auto i : h) {
-    cout << i.first << "\t" << i.second << std::endl;
+    if (i.first) {
+      cout << i.first << "\t" << i.second << std::endl;
+    } else {
+      cout << "avg\t" << i.second << std::endl;
+    }
   }
 }
 
@@ -131,7 +141,7 @@ TEST_P(CDCTest, chunk_random)
     cout << ".";
     cout.flush();
     bufferlist r;
-    generate_buffer(16*1024*1024, &r);
+    generate_buffer(16*1024*1024, &r, i);
     do_size_histogram(*cdc, r, &h);
   }
   cout << std::endl;