From: Matty Williams Date: Fri, 17 Oct 2025 09:59:47 +0000 (+0100) Subject: test: Replace std::uniform_int_distribution with manual code X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=1f435e8c6e24d13bb6590f581573aea86083da73;p=ceph.git test: Replace std::uniform_int_distribution with manual code Signed-off-by: Matty Williams --- diff --git a/src/common/io_exerciser/ObjectModel.cc b/src/common/io_exerciser/ObjectModel.cc index 92cc8f9fdf6b..3e47caeca338 100644 --- a/src/common/io_exerciser/ObjectModel.cc +++ b/src/common/io_exerciser/ObjectModel.cc @@ -5,6 +5,12 @@ #include #include +#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 distMax(1, std::numeric_limits::max()); - return distMax(rng); + constexpr int64_t min = 1; + constexpr int64_t max = static_cast(std::numeric_limits::max()); + constexpr uint64_t range = static_cast(max - min + 1); + uint64_t rand_value = rng(); + int64_t result = static_cast(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 = diff --git a/src/test/osd/ceph_test_rados_io_sequence/ProgramOptionReader.h b/src/test/osd/ceph_test_rados_io_sequence/ProgramOptionReader.h index ebfdd1a31cda..15a268cb2c57 100644 --- a/src/test/osd/ceph_test_rados_io_sequence/ProgramOptionReader.h +++ b/src/test/osd/ceph_test_rados_io_sequence/ProgramOptionReader.h @@ -5,9 +5,14 @@ #include #include +#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 { } else if (first_value.has_value()) { return *std::exchange(first_value, std::nullopt); } else { - std::uniform_int_distribution dist_selections(0, num_selections - 1); - return selections_array[dist_selections(rng)]; + uint64_t range = static_cast(num_selections); + uint64_t rand_value = rng(); + size_t index = static_cast(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 & 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 { 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 dist_selections_stable(0, num_selections_stable - 1); - return elections_array_stable[dist_selections_stable(rng)]; + uint64_t range = static_cast(num_selections_stable); + uint64_t rand_value = rng(); + size_t index = static_cast(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 dist_selections(0, num_selections - 1); - return selections_array[dist_selections(rng)]; + uint64_t range = static_cast(num_selections); + uint64_t rand_value = rng(); + size_t index = static_cast(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 selectRandom() { std::vector selection = generate_selections(); - if (selection.size() > 0) { - std::uniform_int_distribution dist_selection(0, selection.size() - 1); - return selection[dist_selection(rng)]; + + if (!selection.empty()) { + uint64_t range = static_cast(selection.size()); + uint64_t rand_value = rng(); + size_t index = static_cast(rand_value % range); + dout(0) << "S3 rand_value: " << rand_value << " range: " + << range << " index: " << index << " addr: " << &rng << dendl; + return selection[index]; } else { return std::nullopt; } diff --git a/src/test/osd/ceph_test_rados_io_sequence/ceph_test_rados_io_sequence.cc b/src/test/osd/ceph_test_rados_io_sequence/ceph_test_rados_io_sequence.cc index 0c932f1a90a4..a8e66354890e 100644 --- a/src/test/osd/ceph_test_rados_io_sequence/ceph_test_rados_io_sequence.cc +++ b/src/test/osd/ceph_test_rados_io_sequence/ceph_test_rados_io_sequence.cc @@ -550,25 +550,33 @@ ceph::io_sequence::tester::SelectErasureChunkSize::generate_selections() { std::vector 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 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 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 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;