]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
test: Change random number generator to be complr independent
authorMatty Williams <Matty.Williams@ibm.com>
Wed, 15 Oct 2025 15:58:15 +0000 (16:58 +0100)
committerMatty Williams <Matty.Williams@ibm.com>
Wed, 25 Mar 2026 15:13:24 +0000 (15:13 +0000)
Changed from using ceph util random_number_generator class to using std::mt19937_64 as it is compiler independent.

Fixes: https://tracker.ceph.com/issues/73553
Signed-off-by: Matty Williams <Matty.Williams@ibm.com>
src/common/io_exerciser/ObjectModel.cc
src/common/io_exerciser/ObjectModel.h
src/test/osd/ceph_test_rados_io_sequence/ProgramOptionReader.h
src/test/osd/ceph_test_rados_io_sequence/ceph_test_rados_io_sequence.cc
src/test/osd/ceph_test_rados_io_sequence/ceph_test_rados_io_sequence.h

index 7f155d12220369d91dad66d36bde002ce6686ce8..92cc8f9fdf6b466cf4d1a3b0bd1f9f675f433811 100644 (file)
@@ -48,7 +48,8 @@ bool ObjectModel::readyForIoOp(IoOp& op) { return true; }
 
 void ObjectModel::applyIoOp(IoOp& op) {
   auto generate_random = [&rng = rng]() {
-    return rng(1, std::numeric_limits<int>::max());
+    std::uniform_int_distribution<long long> distMax(1, std::numeric_limits<int>::max());
+    return distMax(rng);
   };
 
   auto verify_and_record_read_op =
index e16658085b6ea6fa6fe767f6c19a16cb4b6fc9e7..f14bfd0c64b805243af9d1be4ab9a2aa4714e41e 100644 (file)
@@ -29,8 +29,8 @@ class ObjectModel : public Model {
   bool secondary_created;
   std::vector<int> primary_contents;
   std::vector<int> secondary_contents;
-  ceph::util::random_number_generator<int> rng =
-      ceph::util::random_number_generator<int>();
+  std::mt19937_64 rng =
+      std::mt19937_64();
 
   // Track read and write I/Os that can be submitted in
   // parallel to detect violations:
index cf56134d447c7d09b0c6b4789714cb4d2558dff5..ebfdd1a31cda7bd3310e4e603832912853db0e6d 100644 (file)
@@ -2,6 +2,7 @@
 
 #include <boost/program_options.hpp>
 #include <optional>
+#include <random>
 #include <string>
 
 #include "include/ceph_assert.h"
@@ -86,7 +87,7 @@ template <typename option_type,
                             num_selections>& selections_array>
 class ProgramOptionSelector : public ProgramOptionReader<option_type> {
  public:
-  ProgramOptionSelector(ceph::util::random_number_generator<int>& rng,
+  ProgramOptionSelector(std::mt19937_64& rng,
                         po::variables_map& vm,
                         const std::string& option_name,
                         bool select_first)
@@ -105,12 +106,13 @@ class ProgramOptionSelector : public ProgramOptionReader<option_type> {
     } else if (first_value.has_value()) {
       return *std::exchange(first_value, std::nullopt);
     } else {
-      return selections_array[rng(num_selections - 1)];
+      std::uniform_int_distribution<long long> dist_selections(0, num_selections - 1);
+      return selections_array[dist_selections(rng)];
     }
   }
 
  protected:
-  ceph::util::random_number_generator<int>& rng;
+  std::mt19937_64& rng;
 
   std::optional<option_type> first_value;
 };
@@ -124,7 +126,7 @@ template <typename option_type,
                             num_selections_stable>& elections_array_stable>
 class StableOptionSelector : public ProgramOptionReader<option_type> {
 public:
-  StableOptionSelector(ceph::util::random_number_generator<int>& rng,
+  StableOptionSelector(std::mt19937_64& rng,
                         po::variables_map& vm,
                         const std::string& option_name,
                         bool select_first)
@@ -150,14 +152,16 @@ public:
     } else if (first_value.has_value()) {
       return *std::exchange(first_value, std::nullopt);
     } else if (stable) {
-      return elections_array_stable[rng(num_selections_stable - 1)];
+      std::uniform_int_distribution<long long> dist_selections_stable(0, num_selections_stable - 1);
+      return elections_array_stable[dist_selections_stable(rng)];
     } else {
-      return selections_array[rng(num_selections - 1)];
+      std::uniform_int_distribution<long long> dist_selections(0, num_selections - 1);
+      return selections_array[dist_selections(rng)];
     }
   }
 
 protected:
-  ceph::util::random_number_generator<int>& rng;
+  std::mt19937_64& rng;
   std::optional<option_type> first_value;
   bool stable;
 };
@@ -166,7 +170,7 @@ template <typename option_type>
 class ProgramOptionGeneratedSelector
     : public OptionalProgramOptionReader<option_type> {
  public:
-  ProgramOptionGeneratedSelector(ceph::util::random_number_generator<int>& rng,
+  ProgramOptionGeneratedSelector(std::mt19937_64& rng,
                                  po::variables_map& vm,
                                  const std::string& option_name,
                                  bool first_use)
@@ -196,16 +200,18 @@ class ProgramOptionGeneratedSelector
 
   virtual const std::optional<option_type> selectRandom() {
     std::vector<option_type> selection = generate_selections();
-    if (selection.size() > 0)
-      return selection[rng(selection.size() - 1)];
-    else
+    if (selection.size() > 0) {
+      std::uniform_int_distribution<long long> dist_selection(0, selection.size() - 1);
+      return selection[dist_selection(rng)];
+    } else {
       return std::nullopt;
+    }
   }
 
   bool is_first_use() { return first_use; }
 
  private:
-  ceph::util::random_number_generator<int>& rng;
+  std::mt19937_64& rng;
 
   bool first_use;
 };
index 709f6e5e6932e14433b6fbd92d5ea711ef964bb8..0c932f1a90a40bb3272041763d76cff4b1216964 100644 (file)
@@ -2,6 +2,7 @@
 
 #include <boost/asio/io_context.hpp>
 #include <iostream>
+#include <random>
 #include <vector>
 
 #include "common/Formatter.h"
@@ -301,7 +302,7 @@ ceph::io_sequence::tester::SelectSeqRange::select() {
 }
 
 ceph::io_sequence::tester::SelectErasureTechnique::SelectErasureTechnique(
-    ceph::util::random_number_generator<int>& rng,
+    std::mt19937_64& rng,
     po::variables_map& vm,
     std::string_view plugin,
     bool first_use)
@@ -339,7 +340,7 @@ ceph::io_sequence::tester::SelectErasureTechnique::generate_selections() {
 }
 
 ceph::io_sequence::tester::lrc::SelectMappingAndLayers::SelectMappingAndLayers(
-    ceph::util::random_number_generator<int>& rng,
+    std::mt19937_64& rng,
     po::variables_map& vm,
     bool first_use)
     : rng_seed(rng()),
@@ -366,7 +367,7 @@ ceph::io_sequence::tester::lrc::SelectMappingAndLayers::select() {
 }
 
 ceph::io_sequence::tester::SelectErasureKM::SelectErasureKM(
-    ceph::util::random_number_generator<int>& rng,
+    std::mt19937_64& rng,
     po::variables_map& vm,
     std::string_view plugin,
     const std::optional<std::string>& technique,
@@ -416,7 +417,7 @@ ceph::io_sequence::tester::SelectErasureKM::generate_selections() {
 }
 
 ceph::io_sequence::tester::jerasure::SelectErasureW::SelectErasureW(
-    ceph::util::random_number_generator<int>& rng,
+    std::mt19937_64& rng,
     po::variables_map& vm,
     std::string_view plugin,
     const std::optional<std::string_view>& technique,
@@ -457,7 +458,7 @@ ceph::io_sequence::tester::jerasure::SelectErasureW::generate_selections() {
 }
 
 ceph::io_sequence::tester::shec::SelectErasureC::SelectErasureC(
-    ceph::util::random_number_generator<int>& rng,
+    std::mt19937_64& rng,
     po::variables_map& vm,
     std::string_view plugin,
     const std::optional<std::pair<int, int>>& km,
@@ -484,7 +485,7 @@ ceph::io_sequence::tester::shec::SelectErasureC::generate_selections() {
 }
 
 ceph::io_sequence::tester::jerasure::SelectErasurePacketSize::
-    SelectErasurePacketSize(ceph::util::random_number_generator<int>& rng,
+    SelectErasurePacketSize(std::mt19937_64& rng,
                             po::variables_map& vm,
                             std::string_view plugin,
                             const std::optional<std::string_view>& technique,
@@ -532,7 +533,7 @@ const std::vector<uint64_t> ceph::io_sequence::tester::jerasure::
 }
 
 ceph::io_sequence::tester::SelectErasureChunkSize::SelectErasureChunkSize(
-    ceph::util::random_number_generator<int>& rng,
+    std::mt19937_64& rng,
     po::variables_map& vm,
     ErasureCodeInterfaceRef ec_impl,
     bool first_use)
@@ -552,19 +553,22 @@ ceph::io_sequence::tester::SelectErasureChunkSize::generate_selections() {
   if (4096 % minimum_chunksize == 0) {
     choices.push_back(4096);
   } else {
-    choices.push_back(minimum_chunksize * (rng(4) + 1));
+    std::uniform_int_distribution<long long> dist4(0, 3);
+    choices.push_back(minimum_chunksize * (dist4(rng) + 1));
   }
 
   if ((64 * 1024) % minimum_chunksize == 0) {
     choices.push_back(64 * 1024);
   } else {
-    choices.push_back(minimum_chunksize * (rng(64) + 1));
+    std::uniform_int_distribution<long long> dist64(0, 63);
+    choices.push_back(minimum_chunksize * (dist64(rng) + 1));
   }
 
   if ((256 * 1024) % minimum_chunksize == 0) {
     choices.push_back(256 * 1024);
   } else {
-    choices.push_back(minimum_chunksize * (rng(256) + 1));
+    std::uniform_int_distribution<long long> dist256(0, 255);
+    choices.push_back(minimum_chunksize * (dist256(rng) + 1));
   }
 
   return choices;
@@ -572,7 +576,7 @@ ceph::io_sequence::tester::SelectErasureChunkSize::generate_selections() {
 
 ceph::io_sequence::tester::SelectErasureProfile::SelectErasureProfile(
     boost::intrusive_ptr<CephContext> cct,
-    ceph::util::random_number_generator<int>& rng,
+    std::mt19937_64& rng,
     po::variables_map& vm,
     librados::Rados& rados,
     bool dry_run,
@@ -795,7 +799,7 @@ ceph::io_sequence::tester::SelectErasureProfile::selectExistingProfile(
 
 ceph::io_sequence::tester::SelectErasurePool::SelectErasurePool(
     boost::intrusive_ptr<CephContext> cct,
-    ceph::util::random_number_generator<int>& rng,
+    std::mt19937_64& rng,
     po::variables_map& vm,
     librados::Rados& rados,
     bool dry_run,
@@ -1024,7 +1028,7 @@ ceph::io_sequence::tester::TestObject::TestObject(
     const std::string primary_oid, const std::string secondary_oid, librados::Rados& rados,
     boost::asio::io_context& asio, SelectBlockSize& sbs, SelectErasurePool& spo,
     SelectObjectSize& sos, SelectNumThreads& snt, SelectSeqRange& ssr,
-    ceph::util::random_number_generator<int>& rng, ceph::mutex& lock,
+    std::mt19937_64& rng, ceph::mutex& lock,
     ceph::condition_variable& cond, bool dryrun, bool verbose,
     std::optional<int> seqseed, bool testrecovery, bool checkconsistency, bool delete_objects)
     : rng(rng), verbose(verbose), seqseed(seqseed), testrecovery(testrecovery), checkconsistency(checkconsistency),
@@ -1133,7 +1137,7 @@ ceph::io_sequence::tester::TestRunner::TestRunner(
     librados::Rados& rados)
     : rados(rados),
       seed(vm.contains("seed") ? vm["seed"].as<int>() : time(nullptr)),
-      rng(ceph::util::random_number_generator<int>(seed)),
+      rng(seed),
       sbs{rng, vm, "blocksize", true},
       sos{rng, vm, "objectsize", true},
       spo{cct,
@@ -1316,6 +1320,7 @@ bool ceph::io_sequence::tester::TestRunner::run_interactive_test() {
         primary_object_name, secondary_object_name, sbs.select(), rng());
   } else {
     const std::string pool = spo.select();
+    dout(0) << "Pool name: " << pool << dendl;
 
     model = std::make_unique<ceph::io_exerciser::RadosIo>(
         rados, asio, pool, primary_object_name, secondary_object_name, sbs.select(), rng(),
index a48564f5c6df84296a3cc8432602e07727be8605..a0940d3a7c137755620e410e9801d42be282d60d 100644 (file)
@@ -1,6 +1,7 @@
 #include <boost/asio/io_context.hpp>
 #include <boost/program_options.hpp>
 #include <optional>
+#include <random>
 #include <string>
 #include <utility>
 
@@ -161,7 +162,7 @@ using SelectErasurePlugin =
 class SelectErasureKM
     : public ProgramOptionGeneratedSelector<std::pair<int, int>> {
  public:
-  SelectErasureKM(ceph::util::random_number_generator<int>& rng,
+  SelectErasureKM(std::mt19937_64& rng,
                   po::variables_map& vm,
                   std::string_view plugin,
                   const std::optional<std::string>& technique,
@@ -170,7 +171,7 @@ class SelectErasureKM
   const std::vector<std::pair<int, int>> generate_selections() override;
 
  private:
-  ceph::util::random_number_generator<int>& rng;
+  std::mt19937_64& rng;
 
   std::string_view plugin;
   std::optional<std::string> technique;
@@ -179,7 +180,7 @@ class SelectErasureKM
 namespace shec {
 class SelectErasureC : public ProgramOptionGeneratedSelector<uint64_t> {
  public:
-  SelectErasureC(ceph::util::random_number_generator<int>& rng,
+  SelectErasureC(std::mt19937_64& rng,
                  po::variables_map& vm,
                  std::string_view plugin,
                  const std::optional<std::pair<int, int>>& km,
@@ -188,7 +189,7 @@ class SelectErasureC : public ProgramOptionGeneratedSelector<uint64_t> {
   const std::vector<uint64_t> generate_selections() override;
 
  private:
-  ceph::util::random_number_generator<int>& rng;
+  std::mt19937_64& rng;
 
   std::string_view plugin;
   std::optional<std::pair<int, int>> km;
@@ -198,7 +199,7 @@ class SelectErasureC : public ProgramOptionGeneratedSelector<uint64_t> {
 namespace jerasure {
 class SelectErasureW : public ProgramOptionGeneratedSelector<uint64_t> {
  public:
-  SelectErasureW(ceph::util::random_number_generator<int>& rng,
+  SelectErasureW(std::mt19937_64& rng,
                  po::variables_map& vm,
                  std::string_view plugin,
                  const std::optional<std::string_view>& technique,
@@ -209,7 +210,7 @@ class SelectErasureW : public ProgramOptionGeneratedSelector<uint64_t> {
   const std::vector<uint64_t> generate_selections() override;
 
  private:
-  ceph::util::random_number_generator<int>& rng;
+  std::mt19937_64& rng;
 
   std::string_view plugin;
   std::optional<std::string_view> technique;
@@ -220,7 +221,7 @@ class SelectErasureW : public ProgramOptionGeneratedSelector<uint64_t> {
 class SelectErasurePacketSize
     : public ProgramOptionGeneratedSelector<uint64_t> {
  public:
-  SelectErasurePacketSize(ceph::util::random_number_generator<int>& rng,
+  SelectErasurePacketSize(std::mt19937_64& rng,
                           po::variables_map& vm,
                           std::string_view plugin,
                           const std::optional<std::string_view>& technique,
@@ -230,7 +231,7 @@ class SelectErasurePacketSize
   const std::vector<uint64_t> generate_selections() override;
 
  private:
-  ceph::util::random_number_generator<int>& rng;
+  std::mt19937_64& rng;
 
   std::string_view plugin;
   std::optional<std::string_view> technique;
@@ -291,7 +292,7 @@ using SelectLayers =
 
 class SelectMappingAndLayers {
  public:
-  SelectMappingAndLayers(ceph::util::random_number_generator<int>& rng,
+  SelectMappingAndLayers(std::mt19937_64& rng,
                          po::variables_map& vm,
                          bool first_use);
   const std::pair<std::string, std::string> select();
@@ -299,8 +300,8 @@ class SelectMappingAndLayers {
  private:
   uint64_t rng_seed;
 
-  ceph::util::random_number_generator<int> mapping_rng;
-  ceph::util::random_number_generator<int> layers_rng;
+  std::mt19937_64 mapping_rng;
+  std::mt19937_64 layers_rng;
 
   SelectMapping sma;
   SelectLayers sly;
@@ -310,7 +311,7 @@ class SelectMappingAndLayers {
 class SelectErasureTechnique
     : public ProgramOptionGeneratedSelector<std::string> {
  public:
-  SelectErasureTechnique(ceph::util::random_number_generator<int>& rng,
+  SelectErasureTechnique(std::mt19937_64& rng,
                          po::variables_map& vm,
                          std::string_view plugin,
                          bool first_use);
@@ -318,7 +319,7 @@ class SelectErasureTechnique
   const std::vector<std::string> generate_selections() override;
 
  private:
-  ceph::util::random_number_generator<int>& rng;
+  std::mt19937_64& rng;
 
   std::string_view plugin;
   bool stable;
@@ -326,14 +327,14 @@ class SelectErasureTechnique
 
 class SelectErasureChunkSize : public ProgramOptionGeneratedSelector<uint64_t> {
  public:
-  SelectErasureChunkSize(ceph::util::random_number_generator<int>& rng,
+  SelectErasureChunkSize(std::mt19937_64& rng,
                          po::variables_map& vm,
                          ErasureCodeInterfaceRef ec_impl,
                          bool first_use);
   const std::vector<uint64_t> generate_selections() override;
 
  private:
-  ceph::util::random_number_generator<int>& rng;
+  std::mt19937_64& rng;
 
   ErasureCodeInterfaceRef ec_impl;
 };
@@ -355,7 +356,7 @@ struct Profile {
 class SelectErasureProfile : public ProgramOptionReader<Profile> {
  public:
   SelectErasureProfile(boost::intrusive_ptr<CephContext> cct,
-                       ceph::util::random_number_generator<int>& rng,
+                       std::mt19937_64& rng,
                        po::variables_map& vm, librados::Rados& rados,
                        bool dry_run, bool first_use);
   const Profile select() override;
@@ -366,7 +367,7 @@ class SelectErasureProfile : public ProgramOptionReader<Profile> {
   boost::intrusive_ptr<CephContext> cct;
   librados::Rados& rados;
   bool dry_run;
-  ceph::util::random_number_generator<int>& rng;
+  std::mt19937_64& rng;
   po::variables_map& vm;
 
   bool first_use;
@@ -380,7 +381,7 @@ class SelectErasureProfile : public ProgramOptionReader<Profile> {
 class SelectErasurePool : public ProgramOptionReader<std::string> {
  public:
   SelectErasurePool(boost::intrusive_ptr<CephContext> cct,
-                    ceph::util::random_number_generator<int>& rng,
+                    std::mt19937_64& rng,
                     po::variables_map& vm,
                     librados::Rados& rados,
                     bool dry_run,
@@ -453,7 +454,7 @@ class TestObject {
              ceph::io_sequence::tester::SelectObjectSize& sos,
              ceph::io_sequence::tester::SelectNumThreads& snt,
              ceph::io_sequence::tester::SelectSeqRange& ssr,
-             ceph::util::random_number_generator<int>& rng,
+             std::mt19937_64& rng,
              ceph::mutex& lock,
              ceph::condition_variable& cond,
              bool dryrun,
@@ -477,7 +478,7 @@ class TestObject {
   std::unique_ptr<ceph::io_exerciser::IoSequence> seq;
   std::unique_ptr<ceph::io_exerciser::IoOp> op;
   bool done;
-  ceph::util::random_number_generator<int>& rng;
+  std::mt19937_64& rng;
   bool verbose;
   std::optional<int> seqseed;
   std::optional<std::pair<int, int>> pool_km;
@@ -500,7 +501,7 @@ class TestRunner {
  private:
   librados::Rados& rados;
   int seed;
-  ceph::util::random_number_generator<int> rng;
+  std::mt19937_64 rng;
 
   ceph::io_sequence::tester::SelectBlockSize sbs;
   ceph::io_sequence::tester::SelectObjectSize sos;