From 8de182808c5f6182cd33f1dae37e5accd015dd66 Mon Sep 17 00:00:00 2001 From: "Jesse F. Williamson" <1643380+chardan@users.noreply.github.com> Date: Wed, 18 Dec 2024 06:38:56 -0800 Subject: [PATCH] Fix signed/unsigned warning and add parameter range checking. Signed-off-by: Jesse F. Williamson <1643380+chardan@users.noreply.github.com> --- src/test/objectstore/allocsim/ops_replayer.cc | 35 +++++++++++++++---- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/src/test/objectstore/allocsim/ops_replayer.cc b/src/test/objectstore/allocsim/ops_replayer.cc index fd947f5c454..c5908d9f576 100644 --- a/src/test/objectstore/allocsim/ops_replayer.cc +++ b/src/test/objectstore/allocsim/ops_replayer.cc @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -13,26 +14,46 @@ #include #include #include -#include "include/rados/buffer_fwd.h" -#include "include/rados/librados.hpp" #include -#include #include #include #include #include #include #include +#include + +#include #include #include +#include "include/rados/buffer_fwd.h" +#include "include/rados/librados.hpp" + namespace po = boost::program_options; using namespace std; using namespace ceph; +namespace settings { + +// Returns a function which restricts a value to a specified range by throwing if it is not in range: +// (Note: std::clamp() does not throw.) +auto clamp_or_throw(auto min, auto max) +{ + return [=](auto& x) { + if(std::less<>{}(x, min) or std::greater<>{}(x, max)) { + throw std::out_of_range(fmt::format("value expected between {} and {}, but got {}", min, max, x)); + } + + return x; + }; +} + +} // namespace settings + // compare shared_ptr struct StringPtrCompare { @@ -338,8 +359,8 @@ int main(int argc, char** argv) { // options uint64_t io_depth = 8; - uint64_t nparser_threads = 16; - uint64_t nworker_threads = 16; + int nparser_threads = 16; + int nworker_threads = 16; string file("input.txt"); string ceph_conf_path("./ceph.conf"); string pool("test_pool"); @@ -351,8 +372,8 @@ int main(int argc, char** argv) { ("input-files,i", po::value>()->multitoken(), "List of input files (output of op_scraper.py). Multiple files will be merged and sorted by time order") ("ceph-conf", po::value(&ceph_conf_path)->default_value("ceph.conf"), "Path to ceph conf") ("io-depth", po::value(&io_depth)->default_value(64), "I/O depth") - ("parser-threads", po::value(&nparser_threads)->default_value(16), "Number of parser threads") - ("worker-threads", po::value(&nworker_threads)->default_value(16), "Number of I/O worker threads") + ("parser-threads", po::value(&nparser_threads)->default_value(16)->notifier(settings::clamp_or_throw(1, 256)), "Number of parser threads") + ("worker-threads", po::value(&nworker_threads)->default_value(16)->notifier(settings::clamp_or_throw(1, 256)), "Number of I/O worker threads") ("pool", po::value(&pool)->default_value("test_pool"), "Pool to use for I/O") ("skip-do-ops", po::bool_switch(&skip_do_ops)->default_value(false), "Skip doing operations") ; -- 2.39.5