]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
test: Replace std::uniform_int_distribution with manual code
authorMatty Williams <Matty.Williams@ibm.com>
Fri, 17 Oct 2025 09:59:47 +0000 (10:59 +0100)
committerMatty Williams <Matty.Williams@ibm.com>
Wed, 25 Mar 2026 15:13:24 +0000 (15:13 +0000)
Signed-off-by: Matty Williams <Matty.Williams@ibm.com>
src/common/io_exerciser/ObjectModel.cc
src/test/osd/ceph_test_rados_io_sequence/ProgramOptionReader.h
src/test/osd/ceph_test_rados_io_sequence/ceph_test_rados_io_sequence.cc

index 92cc8f9fdf6b466cf4d1a3b0bd1f9f675f433811..3e47caeca3382c068f360c1c5a01d0ab3f7016d2 100644 (file)
@@ -5,6 +5,12 @@
 #include <execution>
 #include <iterator>
 
+#include "common/debug.h"
+#include "common/dout.h"
+
+#define dout_subsys ceph_subsys_rados
+#define dout_context g_ceph_context
+
 using ObjectModel = ceph::io_exerciser::ObjectModel;
 
 ObjectModel::ObjectModel(const std::string& primary_oid, const std::string& secondary_oid,
@@ -48,8 +54,14 @@ bool ObjectModel::readyForIoOp(IoOp& op) { return true; }
 
 void ObjectModel::applyIoOp(IoOp& op) {
   auto generate_random = [&rng = rng]() {
-    std::uniform_int_distribution<long long> distMax(1, std::numeric_limits<int>::max());
-    return distMax(rng);
+    constexpr int64_t min = 1;
+    constexpr int64_t max = static_cast<int64_t>(std::numeric_limits<int>::max());
+    constexpr uint64_t range = static_cast<uint64_t>(max - min + 1);
+    uint64_t rand_value = rng();
+    int64_t result = static_cast<int64_t>(rand_value % range + min);
+    dout(0) << "S1 rand_value: " << rand_value << " range: " 
+            << range << " result: " << result  << " addr: " << &rng << dendl;
+    return result;
   };
 
   auto verify_and_record_read_op =
index ebfdd1a31cda7bd3310e4e603832912853db0e6d..15a268cb2c5779ef40d8275d5f2f6df40b998745 100644 (file)
@@ -5,9 +5,14 @@
 #include <random>
 #include <string>
 
+#include "common/debug.h"
+#include "common/dout.h"
 #include "include/ceph_assert.h"
 #include "include/random.h"
 
+#define dout_subsys ceph_subsys_rados
+#define dout_context g_ceph_context
+
 /* Overview
  *
  * class ProgramOptionReader
@@ -106,11 +111,16 @@ class ProgramOptionSelector : public ProgramOptionReader<option_type> {
     } else if (first_value.has_value()) {
       return *std::exchange(first_value, std::nullopt);
     } else {
-      std::uniform_int_distribution<long long> dist_selections(0, num_selections - 1);
-      return selections_array[dist_selections(rng)];
+      uint64_t range = static_cast<uint64_t>(num_selections);
+      uint64_t rand_value = rng();
+      size_t index = static_cast<size_t>(rand_value % range);
+      dout(0) << "S4 rand_value: " << rand_value << " range: " 
+            << range << " index: " << index  << " addr: " << &rng << dendl;
+      return selections_array[index];
     }
   }
 
+
  protected:
   std::mt19937_64& rng;
 
@@ -123,7 +133,7 @@ template <typename option_type,
                             num_selections>& selections_array,
           int num_selections_stable,
           const std::array< option_type,
-                            num_selections_stable>& elections_array_stable>
+                            num_selections_stable>& selections_array_stable>
 class StableOptionSelector : public ProgramOptionReader<option_type> {
 public:
   StableOptionSelector(std::mt19937_64& rng,
@@ -136,7 +146,7 @@ public:
     if (select_first) {
       if (stable) {
         ceph_assert(selections_array.size() > 0);
-        first_value = elections_array_stable[0];
+        first_value = selections_array_stable[0];
       } else {
         ceph_assert(selections_array.size() > 0);
         first_value = selections_array[0];
@@ -152,11 +162,19 @@ public:
     } else if (first_value.has_value()) {
       return *std::exchange(first_value, std::nullopt);
     } else if (stable) {
-      std::uniform_int_distribution<long long> dist_selections_stable(0, num_selections_stable - 1);
-      return elections_array_stable[dist_selections_stable(rng)];
+      uint64_t range = static_cast<uint64_t>(num_selections_stable);
+      uint64_t rand_value = rng();
+      size_t index = static_cast<size_t>(rand_value % range);
+      dout(0) << "S2 rand_value: " << rand_value << " range: " 
+            << range << " index: " << index << " addr: " << &rng << dendl;
+      return selections_array_stable[index];
     } else {
-      std::uniform_int_distribution<long long> dist_selections(0, num_selections - 1);
-      return selections_array[dist_selections(rng)];
+      uint64_t range = static_cast<uint64_t>(num_selections);
+      uint64_t rand_value = rng();
+      size_t index = static_cast<size_t>(rand_value % range);
+      dout(0) << "S6 rand_value: " << rand_value << " range: " 
+            << range << " index: " << index << " addr: " << &rng << dendl;
+      return selections_array[index];
     }
   }
 
@@ -200,9 +218,14 @@ class ProgramOptionGeneratedSelector
 
   virtual const std::optional<option_type> selectRandom() {
     std::vector<option_type> selection = generate_selections();
-    if (selection.size() > 0) {
-      std::uniform_int_distribution<long long> dist_selection(0, selection.size() - 1);
-      return selection[dist_selection(rng)];
+
+    if (!selection.empty()) {
+      uint64_t range = static_cast<uint64_t>(selection.size());
+      uint64_t rand_value = rng();
+      size_t index = static_cast<size_t>(rand_value % range);
+      dout(0) << "S3 rand_value: " << rand_value << " range: " 
+            << range << " index: " << index  << " addr: " << &rng << dendl;
+      return selection[index];
     } else {
       return std::nullopt;
     }
index 0c932f1a90a40bb3272041763d76cff4b1216964..a8e66354890ee975fa6f034d20a3aa89b7369b2e 100644 (file)
@@ -550,25 +550,33 @@ ceph::io_sequence::tester::SelectErasureChunkSize::generate_selections() {
 
   std::vector<uint64_t> choices = {};
 
+  auto generate_random_int = [this](uint64_t range) -> uint64_t {
+    uint64_t rand_value = rng();
+    uint64_t index = rand_value % range;
+    dout(0) << "S5 rand_value: " << rand_value << " range: " 
+            << range << " index: " << index  << " addr: " << &rng << dendl;
+    return index;
+  };
+
   if (4096 % minimum_chunksize == 0) {
     choices.push_back(4096);
   } else {
-    std::uniform_int_distribution<long long> dist4(0, 3);
-    choices.push_back(minimum_chunksize * (dist4(rng) + 1));
+    uint64_t r = generate_random_int(4); // 0–3
+    choices.push_back(minimum_chunksize * (r + 1));
   }
 
   if ((64 * 1024) % minimum_chunksize == 0) {
     choices.push_back(64 * 1024);
   } else {
-    std::uniform_int_distribution<long long> dist64(0, 63);
-    choices.push_back(minimum_chunksize * (dist64(rng) + 1));
+    uint64_t r = generate_random_int(64); // 0–63
+    choices.push_back(minimum_chunksize * (r + 1));
   }
 
   if ((256 * 1024) % minimum_chunksize == 0) {
     choices.push_back(256 * 1024);
   } else {
-    std::uniform_int_distribution<long long> dist256(0, 255);
-    choices.push_back(minimum_chunksize * (dist256(rng) + 1));
+    uint64_t r = generate_random_int(256); // 0–255
+    choices.push_back(minimum_chunksize * (r + 1));
   }
 
   return choices;