From 0b9e184fa32e6e069abe8eeaa4063f1ad6ad3828 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Wed, 13 Nov 2024 02:23:23 +0100 Subject: [PATCH] Library: replace usages of `rand()` in the whole code base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * most usages are drop-in replacements * occasionally the other convenience functions can be used * verify call-paths from core code to identify usages * ensure reseeding for all tests involving some kind of randomness... __Note__: some tests were not yet converted, since their usage of randomness is actually not thread-safe. This problem existed previously, since also `rand()` is not thread safe, albeit in most cases it is possible to ignore this problem, as ''garbled internal state'' is also somehow „random“ --- research/gtk-canvas-experiment.cpp | 16 +- src/lib/luid.c | 4 +- src/lib/query-diagnostics.hpp | 13 +- src/lib/random-draw.hpp | 5 +- src/lib/test/test-helper.cpp | 9 +- src/lib/test/test-helper.hpp | 5 +- src/lib/test/tracking-dummy.hpp | 5 +- src/stage/dialog/test-control.hpp | 2 +- src/steam/mobject/test-dummy-mobject.hpp | 3 +- tests/basics/call-queue-test.cpp | 3 +- tests/basics/dependency-factory-test.cpp | 3 +- tests/basics/diagnostic-context-test.cpp | 2 +- tests/basics/singleton-testmock-test.cpp | 2 +- tests/basics/time/digxel-test.cpp | 12 +- tests/basics/time/quantiser-basics-test.cpp | 11 +- tests/basics/time/time-basics-test.cpp | 12 +- tests/basics/time/time-control-test.cpp | 4 +- tests/basics/time/time-formats-test.cpp | 5 +- tests/basics/time/time-mutation-test.cpp | 4 +- tests/basics/time/time-quantisation-test.cpp | 7 +- tests/basics/time/time-value-test.cpp | 5 +- tests/basics/typed-counter-test.cpp | 10 +- .../application/subsystem-runner-test.cpp | 12 +- .../asset/meta/time-grid-basics-test.cpp | 5 +- .../steam/control/command-argument-test.cpp | 11 +- .../core/steam/control/command-basic-test.cpp | 7 +- .../control/command-clone-builder-test.cpp | 3 +- .../control/command-instance-manager-test.cpp | 7 +- .../steam/control/command-mutation-test.cpp | 4 +- .../core/steam/control/command-use1-test.cpp | 3 +- .../core/steam/control/command-use2-test.cpp | 3 +- .../control/handling-pattern-basics-test.cpp | 14 +- tests/core/steam/control/memento-tie-test.cpp | 7 +- .../steam/engine/buffer-metadata-key-test.cpp | 18 +- .../steam/engine/buffer-metadata-test.cpp | 10 +- .../engine/dispatcher-interface-test.cpp | 1 + .../core/steam/engine/feed-manifold-test.cpp | 10 +- tests/core/steam/engine/job-hash-test.cpp | 1 + .../engine/job-planning-pipeline-test.cpp | 3 +- tests/core/steam/engine/job-planning-test.cpp | 2 + tests/core/steam/engine/mock-dispatcher.cpp | 8 +- tests/core/steam/engine/mock-dispatcher.hpp | 6 +- tests/core/steam/engine/mock-support-test.cpp | 8 +- .../steam/engine/scheduler-interface-test.cpp | 1 + tests/core/steam/engine/testframe-test.cpp | 5 +- tests/core/steam/engine/testframe.cpp | 4 +- tests/core/steam/engine/timings-test.cpp | 4 +- .../tracking-heap-block-provider-test.cpp | 9 +- .../steam/fixture/fixture-segment-test.cpp | 1 + .../fixture/node-graph-attachment-test.cpp | 1 + .../session/defs-manager-impl-test.cpp | 4 +- .../mobject/session/defs-manager-test.cpp | 3 +- .../session/defs-registry-impl-test.cpp | 4 +- tests/library/advice/advice-basics-test.cpp | 17 +- tests/library/allocation-cluster-test.cpp | 6 +- tests/library/del-stash-test.cpp | 10 +- tests/library/format-string-test.cpp | 3 +- tests/library/hash-generator-test.cpp | 3 +- tests/library/item-wrapper-test.cpp | 26 +-- tests/library/iter-explorer-test.cpp | 4 +- tests/library/iter-source-test.cpp | 7 +- tests/library/itertools-test.cpp | 4 +- tests/library/lazy-init-test.cpp | 16 +- .../library/meta/late-bind-instance-test.cpp | 7 +- .../meta/variadic-argument-picker-test.cpp | 3 +- .../meta/virtual-copy-support-test.cpp | 3 +- tests/library/null-value-test.cpp | 7 +- tests/library/polymorphic-value-test.cpp | 3 +- tests/library/rational-test.cpp | 2 +- tests/library/ref-array-test.cpp | 6 +- tests/library/replaceable-item-test.cpp | 18 +- tests/library/scoped-collection-test.cpp | 7 +- tests/library/several-builder-test.cpp | 5 +- tests/library/simple-allocator-test.cpp | 6 +- tests/library/symbol-hashtable-test.cpp | 5 +- tests/library/sync-locking-test.cpp | 3 +- tests/library/sync-waiting-test.cpp | 3 +- tests/library/thread-wrapper-join-test.cpp | 4 +- tests/library/thread-wrapper-test.cpp | 3 +- .../library/typed-allocation-manager-test.cpp | 7 +- tests/library/util-floordiv-test.cpp | 7 +- tests/library/variant-test.cpp | 5 +- tests/library/vector-transfer-test.cpp | 7 +- tests/stage/abstract-tangible-test.cpp | 4 +- tests/stage/model/canvas-hook-test.cpp | 15 +- tests/stage/model/view-hook-test.cpp | 3 +- tests/stage/model/w-link-test.cpp | 3 +- tests/vault/gear/activity-detector-test.cpp | 8 +- tests/vault/gear/activity-detector.hpp | 4 +- tests/vault/gear/block-flow-test.cpp | 3 +- tests/vault/gear/scheduler-activity-test.cpp | 4 +- .../vault/gear/scheduler-commutator-test.cpp | 1 + tests/vault/gear/scheduler-service-test.cpp | 1 + tests/vault/gear/scheduler-stress-test.cpp | 1 + tests/vault/gear/stress-test-rig.hpp | 3 +- tests/vault/gear/test-chain-load-test.cpp | 1 + tests/vault/gear/test-chain-load.hpp | 2 +- tests/vault/mem/extent-family-test.cpp | 3 +- wiki/thinkPad.ichthyo.mm | 165 ++++++++++++++---- 99 files changed, 454 insertions(+), 295 deletions(-) diff --git a/research/gtk-canvas-experiment.cpp b/research/gtk-canvas-experiment.cpp index af3132789..cbfb7a728 100644 --- a/research/gtk-canvas-experiment.cpp +++ b/research/gtk-canvas-experiment.cpp @@ -35,6 +35,7 @@ #include "lib/format-string.hpp" #include "lib/format-cout.hpp" +#include "lib/random.hpp" #include "lib/util.hpp" #include @@ -43,6 +44,7 @@ +using lib::rani; using util::_Fmt; using util::isnil; using Gtk::Widget; @@ -136,8 +138,8 @@ namespace demo { ChildEx* chld = makeChld(); childz_.push_back(chld); - uint x = rand() % 1000; - uint y = rand() % 500; + uint x = rani (1000); + uint y = rani (500); canvas_.put(*chld, x, y); chld->show(); canvas_.adjustSize(); @@ -152,8 +154,8 @@ namespace demo { { uint x = canvas_.child_property_x(*chld); uint y = canvas_.child_property_y(*chld); - int deltaX = -20 + rand() % 41; - int deltaY = -15 + rand() % 31; + int deltaX = -20 + rani(41); + int deltaY = -15 + rani(31); x = uint(max (0, int(x) + deltaX)); y = uint(max (0, int(y) + deltaY)); @@ -170,7 +172,7 @@ namespace demo { uint pos=0; for (Widget* chld : childz_) { - uint y = rand() % 30; + uint y = rani(30); canvas_.move (*chld, pos, y); int width = chld->get_allocated_width(); @@ -189,7 +191,7 @@ namespace demo { ERROR (test, "need to fabricate more childz before you can grow 'em..."); return; } - uint selector = rand() % childz_.size(); + uint selector = rani(childz_.size()); ChildEx& toGrow = *childz_[selector]; toGrow.set_label ("***"+toGrow.get_label()+"***"); } @@ -204,7 +206,7 @@ namespace demo { WARN (test, "no children to kill. so sad."); return; } - uint killPos = rand() % childz_.size(); + uint killPos = rani (childz_.size()); ChildV::iterator killThat(&childz_[killPos]); ChildEx* victim = *killThat; childz_.erase (killThat); diff --git a/src/lib/luid.c b/src/lib/luid.c index 25a50ead7..aa197a380 100644 --- a/src/lib/luid.c +++ b/src/lib/luid.c @@ -72,7 +72,7 @@ lumiera_uid_gen (lumiera_uid* luid) if (fd >= 0) fcntl (fd, F_SETFD, FD_CLOEXEC); else - srand (getpid () + time (NULL)); + srand (getpid () + time (NULL)); //////////////////////////////////////////////////////////////////TICKET #1381 : entropy source should be configurable } do @@ -80,7 +80,7 @@ lumiera_uid_gen (lumiera_uid* luid) if (fd < 0) { for (int i = 0; i < 16; ++i) - ((unsigned char*)luid)[i] = (unsigned char)(rand()>>7); + ((unsigned char*)luid)[i] = (unsigned char)(rand()>>7); ///////////////////////////////////////TICKET #1381 : this fallback should certainly not happen silently } else { diff --git a/src/lib/query-diagnostics.hpp b/src/lib/query-diagnostics.hpp index f7283fe37..2156074bf 100644 --- a/src/lib/query-diagnostics.hpp +++ b/src/lib/query-diagnostics.hpp @@ -31,6 +31,7 @@ #include "lib/format-string.hpp" +#include "lib/random.hpp" using util::_Fmt; using std::string; @@ -44,8 +45,8 @@ namespace test { namespace {// implementation constants - _Fmt predicatePattern ("%s_%02i( %s )"); - const string garbage ("asanisimasabibeddiboom"); + _Fmt predicatePattern{"%s_%02i( %s )"}; + const string garbage {"asanisimasasmicksmaggtutti"}; const uint MAX_DEGREE_RAND = 9; @@ -57,9 +58,9 @@ namespace test { garbage_term () ///< yields a random string of 3 letters { return predicatePattern - % char ('a'+ rand() % 26) - % (rand() % 100) - % garbage.substr(rand() % 19 , 3); + % char ('a'+ rani(26)) + % rani (100) + % garbage.substr (rani(23) , 3); } inline string @@ -67,7 +68,7 @@ namespace test { { string fake; if (!degree) - degree = 1 + rand() % MAX_DEGREE_RAND; + degree = 1 + rani(MAX_DEGREE_RAND); while (0 < --degree) fake += garbage_term() + ", "; fake += garbage_term() + "."; diff --git a/src/lib/random-draw.hpp b/src/lib/random-draw.hpp index 2c235a40d..ec7023709 100644 --- a/src/lib/random-draw.hpp +++ b/src/lib/random-draw.hpp @@ -73,7 +73,7 @@ ** ## Copy inhibition ** The configuration of the RandomDraw processing pipeline makes heavy use of function composition ** and adaptation to handle a wide selection of input types and usage patterns. Unfortunately this - ** requires to like the generated configuration-λ to the object instance (capturing by reference); + ** requires to link the generated configuration-λ to the object instance (capturing by reference); ** not allowing this would severely limit the possible configurations. This implies that an object ** instance must not be moved anymore, once the processing pipeline has been configured. And this ** in turn would severely limit it's usage in a DSL. As a compromise, RandomDraw relies on @@ -96,6 +96,7 @@ #include "lib/error.h" +#include "lib/random.hpp" #include "lib/lazy-init.hpp" #include "lib/meta/function.hpp" #include "lib/meta/function-closure.hpp" @@ -163,7 +164,7 @@ namespace lib { struct LimitedRandomGenerate : function(void)> { - static double defaultSrc() { return rand()/double(RAND_MAX); } + static double defaultSrc() { return lib::defaultGen.uni(); } }; }//(End)Policy definitions diff --git a/src/lib/test/test-helper.cpp b/src/lib/test/test-helper.cpp index adf0b79e1..81191dc7a 100644 --- a/src/lib/test/test-helper.cpp +++ b/src/lib/test/test-helper.cpp @@ -32,9 +32,10 @@ #include "lib/test/test-helper.hpp" #include "lib/test/tracking-dummy.hpp" +#include "lib/unique-malloc-owner.hpp" #include "lib/format-string.hpp" #include "lib/format-cout.hpp" -#include "lib/unique-malloc-owner.hpp" +#include "lib/random.hpp" #include @@ -68,13 +69,13 @@ namespace test{ string randStr (size_t len) { - static const string alpha ("aaaabbccddeeeeffgghiiiijjkkllmmnnooooppqqrrssttuuuuvvwwxxyyyyzz0123456789"); - static const size_t MAXAL (alpha.size()); + static const string alpha{"aaaabbccddeeeeffgghiiiijjkkllmmnnooooppqqrrssttuuuuvvwwxxyyyyzz0123456789"}; + static const size_t MAXAL{alpha.size()}; string garbage(len,'\0'); size_t p = len; while (p) - garbage[--p] = alpha[rand() % MAXAL]; + garbage[--p] = alpha[rani (MAXAL)]; return garbage; } diff --git a/src/lib/test/test-helper.hpp b/src/lib/test/test-helper.hpp index db7ec9a31..ea937f2e5 100644 --- a/src/lib/test/test-helper.hpp +++ b/src/lib/test/test-helper.hpp @@ -45,6 +45,7 @@ #include "lib/time/timevalue.hpp" #include "lib/test/transiently.hpp" #include "lib/format-obj.hpp" +#include "lib/random.hpp" #include #include @@ -60,7 +61,7 @@ namespace test{ using lib::Literal; using std::string; - using std::rand; + using lib::rani; using lib::meta::demangleCxx; @@ -308,7 +309,7 @@ namespace test{ inline lib::time::Time randTime () { - return lib::time::Time (500 * (rand() % 2), (rand() % 600) + 1); + return lib::time::Time (500 * rani(2), 1 + rani(600)); } /** create garbage string of given length diff --git a/src/lib/test/tracking-dummy.hpp b/src/lib/test/tracking-dummy.hpp index 4f2d2f670..465b14112 100644 --- a/src/lib/test/tracking-dummy.hpp +++ b/src/lib/test/tracking-dummy.hpp @@ -36,6 +36,7 @@ #include "lib/nocopy.hpp" #include "lib/test/event-log.hpp" #include "lib/format-string.hpp" +#include "lib/random.hpp" #include "lib/util.hpp" #include @@ -67,7 +68,7 @@ namespace test{ } Dummy () - : val_(1 + (rand() % 100'000'000)) + : val_{1 + rani (100'000'000)} { init(); } Dummy (int v) @@ -165,7 +166,7 @@ namespace test{ } Tracker() - : val{rand() % 1000} + : val{rani (1000)} { log.call (this,"ctor"); } diff --git a/src/stage/dialog/test-control.hpp b/src/stage/dialog/test-control.hpp index f776347e8..109eb0571 100644 --- a/src/stage/dialog/test-control.hpp +++ b/src/stage/dialog/test-control.hpp @@ -294,7 +294,7 @@ namespace dialog { pickDummyID() { string dummyID = sanitise (dummy_.get_text()); - dummy_.set_text (string{_Fmt{"d%s%02d"} % lib::test::randStr(2) % (1 + rand() % 99)}); + dummy_.set_text (string{_Fmt{"d%s%02d"} % lib::test::randStr(2) % (1 + lib::rani(99))}); return dummyID; } diff --git a/src/steam/mobject/test-dummy-mobject.hpp b/src/steam/mobject/test-dummy-mobject.hpp index 969ce5126..ba17c1b93 100644 --- a/src/steam/mobject/test-dummy-mobject.hpp +++ b/src/steam/mobject/test-dummy-mobject.hpp @@ -62,6 +62,7 @@ namespace steam { namespace mobject { namespace test { + using lib::rani; using lib::Symbol; using builder::BuilderTool; @@ -75,7 +76,7 @@ namespace test { int id_; public: - DummyMO() : id_(rand() % 1000) {} + DummyMO() : id_{rani(1000)} {} DummyMO(int i) : id_(i) {} DEFINE_PROCESSABLE_BY (BuilderTool); diff --git a/tests/basics/call-queue-test.cpp b/tests/basics/call-queue-test.cpp index f30b16f55..239aab0b1 100644 --- a/tests/basics/call-queue-test.cpp +++ b/tests/basics/call-queue-test.cpp @@ -198,7 +198,7 @@ namespace test{ Worker(CallQueue& queue, SyncBarrier& commonTrigger) : ThreadJoinable{"CallQueue_test: concurrent dispatch" , [&]() { - uint cnt = rand() % MAX_RAND_STEPS; + uint cnt = rand() % MAX_RAND_STEPS; //////////////////////////////OOO brauche rani auf lokalem Generator! uint delay = rand() % MAX_RAND_DELAY; trigger_.sync(); // block until all threads are ready @@ -227,6 +227,7 @@ namespace test{ void verify_ThreadSafety() { + ////////////////////////////////////////////////OOO seedRandom() CallQueue queue; SyncBarrier trigger{NUM_OF_THREADS + 1}; diff --git a/tests/basics/dependency-factory-test.cpp b/tests/basics/dependency-factory-test.cpp index 3ac29aa6c..b503c730a 100644 --- a/tests/basics/dependency-factory-test.cpp +++ b/tests/basics/dependency-factory-test.cpp @@ -37,8 +37,6 @@ #include "lib/depend-inject.hpp" #include "test-target-obj.hpp" -#include - namespace lib { @@ -106,6 +104,7 @@ namespace test{ virtual void run (Arg) { + seedRand(); verify_defaultSingletonCreation(); verify_SubclassCreation(); verify_FactoryDefinition_is_sticky(); diff --git a/tests/basics/diagnostic-context-test.cpp b/tests/basics/diagnostic-context-test.cpp index f7aea1400..9a3457faf 100644 --- a/tests/basics/diagnostic-context-test.cpp +++ b/tests/basics/diagnostic-context-test.cpp @@ -201,7 +201,7 @@ namespace test{ static VecI verifyDiagnosticStack() { - uint seed (1 + rand() % MAX_RAND); + uint seed (1 + rand() % MAX_RAND); /////////////////////////OOO brauche rani() auf lokalem Generator return descend (seed); } diff --git a/tests/basics/singleton-testmock-test.cpp b/tests/basics/singleton-testmock-test.cpp index 90f0cd91d..eac064b3d 100644 --- a/tests/basics/singleton-testmock-test.cpp +++ b/tests/basics/singleton-testmock-test.cpp @@ -148,7 +148,7 @@ namespace test{ DependInject::Local mock_2 ([&]{ return new Mock_2{"Mock", instanceID}; }); // NOTE: the ctor call for the Mock really happens delayed... - instanceID = rand() % 10; + instanceID = rani(10); sing().doIt(); // ctor invoked on first access CHECK (sing().getCnt() == 1); diff --git a/tests/basics/time/digxel-test.cpp b/tests/basics/time/digxel-test.cpp index f8eb7efc5..85fc51334 100644 --- a/tests/basics/time/digxel-test.cpp +++ b/tests/basics/time/digxel-test.cpp @@ -30,15 +30,13 @@ #include "lib/format-string.hpp" #include "lib/test/test-helper.hpp" #include "lib/time/digxel.hpp" +#include "lib/random.hpp" #include "lib/util.hpp" -#include -#include - using lumiera::error::LUMIERA_ERROR_ASSERTION; using util::isSameObject; using util::isnil; -using std::rand; +using lib::rani; namespace lib { @@ -55,8 +53,8 @@ namespace test{ inline double randomFrac() { - double arbitrary = (1 + rand() % RAND_RANGE); - arbitrary /= (1 + rand() % RAND_DENOM); + double arbitrary = 1 + rani(RAND_RANGE); + arbitrary /= 1 + rani(RAND_DENOM); static double prevVal; if (arbitrary != prevVal) @@ -150,6 +148,8 @@ namespace test{ virtual void run (Arg arg) { + seedRand(); + checkSimpleUsage(); checkMutation (); verifyMutatorInfluence(); diff --git a/tests/basics/time/quantiser-basics-test.cpp b/tests/basics/time/quantiser-basics-test.cpp index 8f3700778..3d6a84cf3 100644 --- a/tests/basics/time/quantiser-basics-test.cpp +++ b/tests/basics/time/quantiser-basics-test.cpp @@ -28,12 +28,12 @@ #include "lib/test/run.hpp" #include "lib/test/test-helper.hpp" #include "lib/time/quantiser.hpp" +#include "lib/random.hpp" #include "lib/util.hpp" -#include using lumiera::error::LUMIERA_ERROR_BOTTOM_VALUE; using util::isnil; -using std::rand; +using lib::rani; @@ -80,7 +80,8 @@ namespace test{ virtual void run (Arg) { - checkSimpleQuantisation (); + seedRand(); + checkSimpleQuantisation(); coverQuantisationStandardCases(); coverQuantisationCornerCases(); } @@ -91,8 +92,8 @@ namespace test{ { FixedFrameQuantiser fixQ(25); - int frames = (rand() % MAX_FRAMES); - FSecs dirt = (F25 / (2 + rand() % DIRT_GRAIN)); + int frames = rani(MAX_FRAMES); + FSecs dirt = (F25 / (2 + rani(DIRT_GRAIN))); Time rawTime = Time(frames*F25) + Duration(dirt); diff --git a/tests/basics/time/time-basics-test.cpp b/tests/basics/time/time-basics-test.cpp index e8bf048b5..c8161e3fe 100644 --- a/tests/basics/time/time-basics-test.cpp +++ b/tests/basics/time/time-basics-test.cpp @@ -29,14 +29,13 @@ #include "lib/time/timevalue.hpp" #include "lib/time/diagnostics.hpp" #include "lib/format-cout.hpp" +#include "lib/random.hpp" #include "lib/util.hpp" #include -#include using boost::lexical_cast; using util::isnil; -using std::rand; namespace lib { @@ -131,10 +130,11 @@ namespace test{ void checkComponentDiagnostics() { - int millis = rand() % 1000; - int secs = rand() % 60; - int mins = rand() % 60; - int hours = rand() % 100; + seedRand(); + int millis = rani(1000); + int secs = rani (60); + int mins = rani (60); + int hours = rani (100); Time time(millis,secs,mins,hours); CHECK (Time() < time); diff --git a/tests/basics/time/time-control-test.cpp b/tests/basics/time/time-control-test.cpp index e1cef771b..93f044573 100644 --- a/tests/basics/time/time-control-test.cpp +++ b/tests/basics/time/time-control-test.cpp @@ -136,7 +136,7 @@ namespace test{ random_or_get (string arg) { if (isnil(arg)) - return gavl_time_t (1 + (rand() % 100000)) * TimeValue::SCALE; + return gavl_time_t(1 + rani (100000)) * TimeValue::SCALE; else return lexical_cast (arg); } @@ -145,6 +145,8 @@ namespace test{ virtual void run (Arg arg) { + if (isnil(arg)) + seedRand(); TimeValue o (random_or_get (pop(arg))); TimeValue c (random_or_get (pop(arg))); CHECK (c!=Time::ZERO && o != c, "unsuitable testdata"); diff --git a/tests/basics/time/time-formats-test.cpp b/tests/basics/time/time-formats-test.cpp index 97e1b6e3e..12f333000 100644 --- a/tests/basics/time/time-formats-test.cpp +++ b/tests/basics/time/time-formats-test.cpp @@ -35,11 +35,9 @@ #include "lib/util.hpp" #include -#include using boost::lexical_cast; using util::isnil; -using std::rand; using std::string; @@ -60,7 +58,7 @@ namespace test{ { FrameCnt frameNr(0); while (!frameNr) - frameNr = rand() % (2*MAX_FRAME) - MAX_FRAME; + frameNr = rani(2*MAX_FRAME) - MAX_FRAME; return toString(frameNr)+"#"; } @@ -80,6 +78,7 @@ namespace test{ virtual void run (Arg) { + seedRand(); TimeGrid::build("pal0", FrameRate::PAL); checkTimecodeUsageCycle (); diff --git a/tests/basics/time/time-mutation-test.cpp b/tests/basics/time/time-mutation-test.cpp index 8f7b06289..178b1ffe0 100644 --- a/tests/basics/time/time-mutation-test.cpp +++ b/tests/basics/time/time-mutation-test.cpp @@ -74,7 +74,7 @@ namespace test{ random_or_get (string arg) { if (isnil(arg)) - return gavl_time_t (1 + (rand() % 100000)) * TimeValue::SCALE; + return gavl_time_t(1 + rani (100000)) * TimeValue::SCALE; else return lexical_cast (arg); } @@ -98,6 +98,8 @@ namespace test{ virtual void run (Arg arg) { + if (isnil(arg)) + seedRand(); TimeValue o (random_or_get (pop(arg))); TimeValue c (random_or_get (pop(arg))); CHECK (o != c, "unsuitable testdata"); diff --git a/tests/basics/time/time-quantisation-test.cpp b/tests/basics/time/time-quantisation-test.cpp index 5f21579f5..3e220c1a3 100644 --- a/tests/basics/time/time-quantisation-test.cpp +++ b/tests/basics/time/time-quantisation-test.cpp @@ -33,12 +33,10 @@ #include "lib/util.hpp" #include -#include using boost::lexical_cast; using util::isnil; using util::contains; -using std::rand; namespace lib { @@ -63,7 +61,10 @@ namespace test{ random_or_get (Arg arg) { if (isnil(arg)) - return 1 + (rand() % 10000); + {// use random time value for all tests + seedRand(); + return 1 + rani(10000); + } else return lexical_cast (arg[1]); } diff --git a/tests/basics/time/time-value-test.cpp b/tests/basics/time/time-value-test.cpp index 26b299a30..611962ed6 100644 --- a/tests/basics/time/time-value-test.cpp +++ b/tests/basics/time/time-value-test.cpp @@ -57,7 +57,10 @@ namespace test{ random_or_get (Arg arg) { if (isnil(arg)) - return 1 + (rand() % 10000); + {// use random time value for all tests + seedRand(); + return 1 + rani(10000); + } else return lexical_cast (arg[1]); } diff --git a/tests/basics/typed-counter-test.cpp b/tests/basics/typed-counter-test.cpp index 6c7e0f365..619a51080 100644 --- a/tests/basics/typed-counter-test.cpp +++ b/tests/basics/typed-counter-test.cpp @@ -44,9 +44,9 @@ #include "lib/test/run.hpp" #include "lib/typed-counter.hpp" #include "lib/test/microbenchmark.hpp" +#include "lib/random.hpp" #include "lib/util.hpp" -#include #include #include @@ -55,7 +55,7 @@ namespace lib { namespace test{ using util::isnil; - using std::rand; + using lib::rani; namespace { // test parametrisation... @@ -176,16 +176,16 @@ namespace test{ void tortureTest() { - std::srand (::time (NULL)); + seedRand(); using IDX = std::make_index_sequence; auto operators = buildOperatorsTable(IDX{}); TypedCounter testCounter; - auto testSubject = [&](size_t) -> size_t + auto testSubject = [&, i = rani(MAX_INDEX)] + (size_t) -> size_t { - uint i = rand() % MAX_INDEX; operators[i](testCounter); return 1; }; diff --git a/tests/core/application/subsystem-runner-test.cpp b/tests/core/application/subsystem-runner-test.cpp index 5a888c69a..84e730408 100644 --- a/tests/core/application/subsystem-runner-test.cpp +++ b/tests/core/application/subsystem-runner-test.cpp @@ -69,6 +69,13 @@ namespace test { const uint MAX_RUNNING_TIME_ms = 80; const uint MIN_RUNNING_TIME_ms = 20; + inline int + draw_rand_runtime() + { + return MIN_RUNNING_TIME_ms + + rani (MAX_RUNNING_TIME_ms - MIN_RUNNING_TIME_ms); + } + /** the "running" subsystem checks for a * shutdown request every XX milliseconds */ const uint TICK_DURATION_ms = 5; @@ -110,6 +117,7 @@ namespace test { atomic_bool started_{false}; atomic_bool termRequest_{false}; int running_duration_{0}; + const int TIME_GOAL{draw_rand_runtime()}; lib::SyncBarrier barrier_{}; unique_ptr thread_{}; @@ -193,8 +201,7 @@ namespace test { if (isUp_) //-------------actually enter running state for some time { - running_duration_ = MIN_RUNNING_TIME_ms; - running_duration_ += (rand() % (MAX_RUNNING_TIME_ms - MIN_RUNNING_TIME_ms)); + running_duration_ = TIME_GOAL; // prepared when creating instance INFO (test, "thread %s now running....", cStr(*this)); @@ -275,6 +282,7 @@ namespace test { virtual void run (Arg) { + seedRand(); singleSubsys_complete_cycle(); singleSubsys_start_failure(); singleSubsys_emegency_exit(); diff --git a/tests/core/steam/asset/meta/time-grid-basics-test.cpp b/tests/core/steam/asset/meta/time-grid-basics-test.cpp index 778576155..7252bfedd 100644 --- a/tests/core/steam/asset/meta/time-grid-basics-test.cpp +++ b/tests/core/steam/asset/meta/time-grid-basics-test.cpp @@ -74,6 +74,7 @@ namespace test { virtual void run (Arg) { + seedRand(); createGrid_fullProcedure(); createGrid_simplified(); } @@ -98,12 +99,12 @@ namespace test { // now verify the grid // by performing some conversions... - int randomFrame = (rand() % MAX_FRAMES); + int randomFrame = rani(MAX_FRAMES); Time point (myGrid->timeOf (randomFrame)); CHECK (point == TEST_ORIGIN + randomFrame * TEST_FPS.duration()); - int fract = 2 + rand() % DIRT_GRAIN; + int fract = 2 + rani(DIRT_GRAIN); FSecs dirt = (1/TEST_FPS) / fract; ASSERT (Time(dirt) < TEST_FPS.duration()); ASSERT (0 < dirt); diff --git a/tests/core/steam/control/command-argument-test.cpp b/tests/core/steam/control/command-argument-test.cpp index 1247c8b0a..ef544c504 100644 --- a/tests/core/steam/control/command-argument-test.cpp +++ b/tests/core/steam/control/command-argument-test.cpp @@ -158,7 +158,7 @@ namespace test { /// another dummy-UNDO function void dummyU (int,int,int) { } - int dummyC (int u,int o) { return u + rand() % (o-u+1); } + int dummyC (int u,int o) { return u + rani(o-u+1); } @@ -181,7 +181,7 @@ namespace test { int twoRandomDigits() { - return 10 + rand() % 90; + return 10 + rani(90); } @@ -206,6 +206,7 @@ namespace test { virtual void run (Arg) { + seedRand(); ArgTuples testTuples; prepareEmptyMemento(); Tracker::instanceCnt = 0; @@ -256,9 +257,9 @@ namespace test { for_each (tup, showIt); arg1->storeTuple (std::tuple<>()); - arg2->storeTuple (make_tuple (rand() % 10)); - arg3->storeTuple (make_tuple (rand() % 10, TimeVar(randTime()))); - arg4->storeTuple (make_tuple (rand() % 10, TimeVar(randTime()))); + arg2->storeTuple (make_tuple (rani(10))); + arg3->storeTuple (make_tuple (rani(10), TimeVar(randTime()))); + arg4->storeTuple (make_tuple (rani(10), TimeVar(randTime()))); arg5->storeTuple (make_tuple (TTime (randTime()), Tstr("glorious"), twoRandomDigits() )); diff --git a/tests/core/steam/control/command-basic-test.cpp b/tests/core/steam/control/command-basic-test.cpp index 658e1ed55..b2d1c2a82 100644 --- a/tests/core/steam/control/command-basic-test.cpp +++ b/tests/core/steam/control/command-basic-test.cpp @@ -30,10 +30,6 @@ #include "lib/time/timevalue.hpp" #include "lib/p.hpp" -#include - -using std::rand; - namespace steam { namespace control { @@ -96,7 +92,8 @@ namespace test { virtual void run (Arg) { - int randVal ((rand() % 10) - 5); + seedRand(); + int randVal{rani(10) - 5}; Time five(TimeValue(5)); TimeValue randomTime(randVal); auto obj = makeP(five); diff --git a/tests/core/steam/control/command-clone-builder-test.cpp b/tests/core/steam/control/command-clone-builder-test.cpp index 27d399b17..f082202d1 100644 --- a/tests/core/steam/control/command-clone-builder-test.cpp +++ b/tests/core/steam/control/command-clone-builder-test.cpp @@ -77,6 +77,7 @@ namespace test { virtual void run (Arg) { + seedRand(); CommandRegistry& registry = CommandRegistry::instance(); CHECK (®istry); uint cnt_inst = registry.instance_count(); @@ -120,7 +121,7 @@ namespace test { bindRandArgument (CommandImpl& cmd) { typedef Types ArgType; - TypedArguments> arg (std::make_tuple (rand() % 10000)); + TypedArguments> arg (std::make_tuple (rani (10000))); cmd.setArguments (arg); CHECK (cmd.canExec()); } diff --git a/tests/core/steam/control/command-instance-manager-test.cpp b/tests/core/steam/control/command-instance-manager-test.cpp index 5d210899a..0577dcb7c 100644 --- a/tests/core/steam/control/command-instance-manager-test.cpp +++ b/tests/core/steam/control/command-instance-manager-test.cpp @@ -34,7 +34,6 @@ #include "lib/util.hpp" #include -#include #include #include #include @@ -48,7 +47,6 @@ namespace test { using std::string; using util::_Fmt; using std::move; - using std::rand; using LERR_(LIFECYCLE); using LERR_(INVALID_COMMAND); @@ -119,6 +117,7 @@ namespace test { virtual void run (Arg) { + seedRand(); verify_simpleUsage(); verify_extendedUsage(); verify_instanceIdentity(); @@ -145,7 +144,7 @@ namespace test { CommandInstanceManager iManager{fixture}; CHECK (not iManager.contains (COMMAND_PROTOTYPE)); - int r1{rand()%1000}, r2{rand()%2000}; + int r1{rani(1000)}, r2{rani(2000)}; command1::check_ = 0; // commands will add to this on invocation iManager.bindAndDispatch (COMMAND_PROTOTYPE, Rec{r1}); @@ -230,7 +229,7 @@ namespace test { CHECK (c11.isValid()); CHECK (not c11.canExec()); - int r1{rand()%100}, r2{rand()%200}, r3{rand()%300}; + int r1{rani(100)}, r2{rani(200)}, r3{rani(300)}; command1::check_ = 0; // commands will add to this on invocation c11.bind (r1); diff --git a/tests/core/steam/control/command-mutation-test.cpp b/tests/core/steam/control/command-mutation-test.cpp index 545c743a2..71d73286f 100644 --- a/tests/core/steam/control/command-mutation-test.cpp +++ b/tests/core/steam/control/command-mutation-test.cpp @@ -90,6 +90,8 @@ namespace test { virtual void run (Arg) { + seedRand(); + checkMutation(); checkUndoMutation(); checkStateCapturingMechanism(); @@ -203,7 +205,7 @@ namespace test { function bound_cap_func = mementoHolder.tieCaptureFunc(); - int rr (rand() % 100); + int rr{rani (100)}; testVal = rr; bound_cap_func(); // invoke state capturing CHECK (rr == mementoHolder.getState()); diff --git a/tests/core/steam/control/command-use1-test.cpp b/tests/core/steam/control/command-use1-test.cpp index fd2f2d6f0..0ed7ca76f 100644 --- a/tests/core/steam/control/command-use1-test.cpp +++ b/tests/core/steam/control/command-use1-test.cpp @@ -60,13 +60,14 @@ namespace test { { int randVal; - int random() { return randVal = 10 + (rand() % 40); } + int random() { return randVal = 10 + rani(40); } virtual void run (Arg) { + seedRand(); command1::check_ = 0; uint cnt_defs = Command::definition_count(); uint cnt_inst = Command::instance_count(); diff --git a/tests/core/steam/control/command-use2-test.cpp b/tests/core/steam/control/command-use2-test.cpp index 8f66e68d1..e2f17ad3a 100644 --- a/tests/core/steam/control/command-use2-test.cpp +++ b/tests/core/steam/control/command-use2-test.cpp @@ -97,7 +97,7 @@ namespace test { { _Fmt fmt ("invoked( %2d )"); - randVal_ = rand() % 100; + randVal_ = rani (100); return fmt % randVal_; } @@ -107,6 +107,7 @@ namespace test { virtual void run (Arg) { + seedRand(); command2::check_.seekp(0); uint cnt_defs = Command::definition_count(); uint cnt_inst = Command::instance_count(); diff --git a/tests/core/steam/control/handling-pattern-basics-test.cpp b/tests/core/steam/control/handling-pattern-basics-test.cpp index c2a53de63..8ad5708ac 100644 --- a/tests/core/steam/control/handling-pattern-basics-test.cpp +++ b/tests/core/steam/control/handling-pattern-basics-test.cpp @@ -35,17 +35,12 @@ #include "steam/control/test-dummy-commands.hpp" -#include - -namespace steam { -namespace control { -namespace test { - +namespace steam { +namespace control{ +namespace test { using std::function; - using std::rand; - namespace { // test fixture... @@ -128,6 +123,7 @@ namespace test { virtual void run (Arg) { + seedRand(); CommandRegistry& registry = CommandRegistry::instance(); CHECK (®istry); @@ -182,7 +178,7 @@ namespace test { CHECK (!com->canExec()); typedef Types ArgType; - const int ARGR (1 + rand() % 1000); + const int ARGR{1 + rani (1000)}; Tuple tuple(ARGR); TypedArguments> arg(tuple); com->setArguments(arg); diff --git a/tests/core/steam/control/memento-tie-test.cpp b/tests/core/steam/control/memento-tie-test.cpp index c7580b1d8..317f12d4d 100644 --- a/tests/core/steam/control/memento-tie-test.cpp +++ b/tests/core/steam/control/memento-tie-test.cpp @@ -30,11 +30,9 @@ #include "steam/control/memento-tie.hpp" #include -#include using std::function; using std::bind; -using std::rand; namespace steam { @@ -85,6 +83,7 @@ namespace test { virtual void run (Arg) { + seedRand(); checkStateCapturingMechanism(); } @@ -112,7 +111,7 @@ namespace test { VERIFY_ERROR (MISSING_MEMENTO, bound_undo_func(123) ); VERIFY_ERROR (MISSING_MEMENTO, mementoHolder.getState() ); - short rr (rand() %100); + short rr (rani (100)); testVal = 0; bound_cap_func(rr); // invoke state capturing @@ -123,7 +122,7 @@ namespace test { CHECK (testVal == 10-rr); // this cycle can be repeated with different state values - rr = (rand() %100); + rr = rani (100); testVal = rr; bound_cap_func(5); // capture new state CHECK (5+rr == mementoHolder.getState()); diff --git a/tests/core/steam/engine/buffer-metadata-key-test.cpp b/tests/core/steam/engine/buffer-metadata-key-test.cpp index d55cb5efb..215d64bb3 100644 --- a/tests/core/steam/engine/buffer-metadata-key-test.cpp +++ b/tests/core/steam/engine/buffer-metadata-key-test.cpp @@ -47,9 +47,6 @@ namespace test { const size_t TEST_MAX_SIZE = 1024 * 1024; - const size_t SIZE_A = 1 + rand() % TEST_MAX_SIZE; - const size_t SIZE_B = 1 + rand() % TEST_MAX_SIZE; - /** * Test Mock to verify the attachment of objects to the buffer. @@ -166,10 +163,17 @@ namespace test { */ class BufferMetadataKey_test : public Test { + size_t SIZE_A{0}; + size_t SIZE_B{0}; + virtual void run (Arg) { + seedRand(); + SIZE_A = 1 + rani(TEST_MAX_SIZE); + SIZE_B = 1 + rani(TEST_MAX_SIZE); + CHECK (ensure_proper_fixture()); buildSimpleKeys(); verifyChainedHashes(); @@ -190,7 +194,7 @@ namespace test { { HashVal family(123); Key k1(family, SIZE_A); - Key k12(k1, SIZE_B); + Key k12(k1, SIZE_B); Key k123(k12, LocalTag(56)); CHECK (HashVal (k1)); @@ -213,7 +217,7 @@ namespace test { CHECK (HashVal(k1) == HashVal(Key(family, SIZE_A))); // differentiate on buffer size - Key k12(k1, SIZE_B); + Key k12(k1, SIZE_B); Key k121(k12, SIZE_A); Key k2(family, SIZE_B); @@ -257,8 +261,8 @@ namespace test { TypeHandler placeMarker = TypeHandler::create(); TypeHandler noHandler; - LocalTag opaque1 (rand() % 1000); - LocalTag opaque2 (1000 + rand() % 1000); + LocalTag opaque1 (rani(1000)); + LocalTag opaque2 (1000 + rani(1000)); Key k_siz (kb, SIZE_B); // sub-key to "root": use a different buffer size Key k_han0(kb, noHandler); // sub-key to "root": use a locally defined type functor diff --git a/tests/core/steam/engine/buffer-metadata-test.cpp b/tests/core/steam/engine/buffer-metadata-test.cpp index 3ad3dca00..94e2de7ea 100644 --- a/tests/core/steam/engine/buffer-metadata-test.cpp +++ b/tests/core/steam/engine/buffer-metadata-test.cpp @@ -71,9 +71,6 @@ namespace test { const size_t TEST_MAX_SIZE = 1024 * 1024; - const size_t SIZE_A = 1 + rand() % TEST_MAX_SIZE; - const size_t SIZE_B = 1 + rand() % TEST_MAX_SIZE; - HashVal JUST_SOMETHING = 123; auto SOME_POINTER = mark_as_Buffer(JUST_SOMETHING); @@ -91,12 +88,19 @@ namespace test { */ class BufferMetadata_test : public Test { + size_t SIZE_A{0}; + size_t SIZE_B{0}; + /** common Metadata table to be tested */ unique_ptr meta_; virtual void run (Arg) { + seedRand(); + SIZE_A = 1 + rani(TEST_MAX_SIZE); + SIZE_B = 1 + rani(TEST_MAX_SIZE); + CHECK (ensure_proper_fixture()); verifyBasicProperties(); verifyStandardCase(); diff --git a/tests/core/steam/engine/dispatcher-interface-test.cpp b/tests/core/steam/engine/dispatcher-interface-test.cpp index bdb6bf811..312215ba6 100644 --- a/tests/core/steam/engine/dispatcher-interface-test.cpp +++ b/tests/core/steam/engine/dispatcher-interface-test.cpp @@ -70,6 +70,7 @@ namespace test { virtual void run (Arg) { + seedRand(); resolveModelPort(); accessJobTicket(); pipelineBuilder(); diff --git a/tests/core/steam/engine/feed-manifold-test.cpp b/tests/core/steam/engine/feed-manifold-test.cpp index b3e730204..1d6720a48 100644 --- a/tests/core/steam/engine/feed-manifold-test.cpp +++ b/tests/core/steam/engine/feed-manifold-test.cpp @@ -70,8 +70,8 @@ namespace test { MockSizeRequest() : Connectivity(dummy1,dummy2,0,NodeID()), - ii(rand() % CHUNK_MAX), - oo(rand() % CHUNK_MAX) + ii(rani (CHUNK_MAX)), + oo(rani (CHUNK_MAX)) { } virtual uint getNrI() const { return ii; } @@ -141,8 +141,10 @@ namespace test { #endif /////////////////////////////////////////////////////////////////////////////////////////////////////////////UNIMPLEMENTED :: TICKET #852 ulong counter; - virtual void run(Arg) + void + run(Arg) override { + seedRand(); ////////////////TODO RLY? counter = 0; #if false /////////////////////////////////////////////////////////////////////////////////////////////////////////////UNIMPLEMENTED :: TICKET #852 @@ -173,7 +175,7 @@ namespace test { BuffTableChunk thisChunk (numbers, *pStorage); CHECK (consistencyCheck (thisChunk, numbers, lastLevel)); - uint nrBranches ( 1 + (rand() % WIDTH_MAX)); + uint nrBranches ( 1 + rani(WIDTH_MAX)); while (nrBranches--) invocation (consumed, first_behind (thisChunk,numbers.getNrI())); #endif /////////////////////////////////////////////////////////////////////////////////////////////////////////////UNIMPLEMENTED :: TICKET #833 diff --git a/tests/core/steam/engine/job-hash-test.cpp b/tests/core/steam/engine/job-hash-test.cpp index 89379f019..e2de70a12 100644 --- a/tests/core/steam/engine/job-hash-test.cpp +++ b/tests/core/steam/engine/job-hash-test.cpp @@ -62,6 +62,7 @@ namespace test { virtual void run (Arg) { + seedRand(); verify_simple_job_properties(); verify_job_identity(); } diff --git a/tests/core/steam/engine/job-planning-pipeline-test.cpp b/tests/core/steam/engine/job-planning-pipeline-test.cpp index 76a536272..8c6160b3c 100644 --- a/tests/core/steam/engine/job-planning-pipeline-test.cpp +++ b/tests/core/steam/engine/job-planning-pipeline-test.cpp @@ -92,6 +92,7 @@ namespace test { virtual void run (Arg) { + seedRand(); demonstrateScaffolding(); buildBaseTickGenerator(); accessTopLevelJobTicket(); @@ -105,7 +106,7 @@ namespace test { demonstrateScaffolding() { Time nominalTime = lib::test::randTime(); - int additionalKey = rand() % 5000; + int additionalKey = rani(5000); // (1) mocked render Job MockJob mockJob{nominalTime, additionalKey}; diff --git a/tests/core/steam/engine/job-planning-test.cpp b/tests/core/steam/engine/job-planning-test.cpp index 3a2fba4ab..2ec0ab1a4 100644 --- a/tests/core/steam/engine/job-planning-test.cpp +++ b/tests/core/steam/engine/job-planning-test.cpp @@ -62,6 +62,8 @@ namespace test { virtual void run (Arg) { + seedRand(); + simpleUsage(); calculateDeadline(); setupDependentJob(); diff --git a/tests/core/steam/engine/mock-dispatcher.cpp b/tests/core/steam/engine/mock-dispatcher.cpp index f0bcc1bb7..2a6a567b0 100644 --- a/tests/core/steam/engine/mock-dispatcher.cpp +++ b/tests/core/steam/engine/mock-dispatcher.cpp @@ -49,7 +49,6 @@ #include "lib/depend.hpp" #include "lib/util.hpp" -#include #include #include @@ -60,6 +59,7 @@ namespace test { namespace { // MockJob and DummyClosure implementation details... + using lib::rani; using lib::HashVal; using lib::NullValue; using lib::time::TimeVar; @@ -185,8 +185,8 @@ namespace test { MockJob::build() { InvocationInstanceID invoKey; - invoKey.part.a = rand() % MAX_PARAM_A; - invoKey.part.b = rand() % (2*MAX_PARAM_B) - MAX_PARAM_B; + invoKey.part.a = rani (MAX_PARAM_A); + invoKey.part.b = rani (2*MAX_PARAM_B - MAX_PARAM_B); Time nominalTime = lib::test::randTime(); @@ -199,7 +199,7 @@ namespace test { { InvocationInstanceID invoKey; invoKey.part.a = additionalKey; - invoKey.part.b = rand() % (2*MAX_PARAM_B) - MAX_PARAM_B; + invoKey.part.b = rani (2*MAX_PARAM_B - MAX_PARAM_B); return Job(dummyClosure, invoKey, nominalTime); } diff --git a/tests/core/steam/engine/mock-dispatcher.hpp b/tests/core/steam/engine/mock-dispatcher.hpp index 96db84a78..6db6ef474 100644 --- a/tests/core/steam/engine/mock-dispatcher.hpp +++ b/tests/core/steam/engine/mock-dispatcher.hpp @@ -82,6 +82,8 @@ namespace test { using lib::time::TimeValue; using lib::time::Time; using lib::HashVal; + using lib::ranHash; + using lib::rani; using util::isnil; using util::isSameObject; using fixture::Segmentation; @@ -152,7 +154,7 @@ namespace test { /** provide a test specification wired to MockJob */ static ExitNode - defineSimpleSpec (HashVal seed = 1+rand()) + defineSimpleSpec (HashVal seed =ranHash()) { return ExitNode{seed, DUMMY_JOB_RUNTIME ,ExitNodes{} @@ -239,7 +241,7 @@ namespace test { buildSeed (GenNode const& spec) { auto seed = spec.retrieveAttribute ("mark"); - return seed? HashVal(*seed) : HashVal(rand() % 1000); + return seed? HashVal(*seed) : HashVal(1 +rani(1000)); } Duration diff --git a/tests/core/steam/engine/mock-support-test.cpp b/tests/core/steam/engine/mock-support-test.cpp index f5a07590c..360c97e7a 100644 --- a/tests/core/steam/engine/mock-support-test.cpp +++ b/tests/core/steam/engine/mock-support-test.cpp @@ -65,6 +65,8 @@ namespace test { virtual void run (Arg) { + seedRand(); + simpleUsage(); verify_MockJob(); verify_MockJobTicket(); @@ -103,7 +105,7 @@ namespace test { verify_MockJob() { Time nominalTime = lib::test::randTime(); - int additionalKey = rand() % 5000; + int additionalKey = rani(5000); MockJob mockJob{nominalTime, additionalKey}; CHECK (mockJob.getNominalTime() == nominalTime); CHECK (not MockJob::was_invoked (mockJob)); @@ -188,7 +190,7 @@ namespace test { //-----------------------------------------------------------------/// Segmentation with a segment spanning part of the timeline > 10s { // Marker to verify the job calls back into the right segment - int marker = rand() % 1000; + int marker = rani(1000); // // Build a Segmentation partitioned at 10s MockSegmentation mockSegs{MakeRec() @@ -224,7 +226,7 @@ namespace test { } //-----------------------------------------------------------------/// Segmentation with one delineated segment, and otherwise empty { - int marker = rand() % 1000; + int marker = rani(1000); // Build Segmentation with one fully defined segment MockSegmentation mockSegs{MakeRec() .attrib ("start", Time{0,10} diff --git a/tests/core/steam/engine/scheduler-interface-test.cpp b/tests/core/steam/engine/scheduler-interface-test.cpp index fcee26add..745a73084 100644 --- a/tests/core/steam/engine/scheduler-interface-test.cpp +++ b/tests/core/steam/engine/scheduler-interface-test.cpp @@ -84,6 +84,7 @@ namespace test { virtual void run (Arg) { + seedRand(); SchedulerFrontend& scheduler = SchedulerFrontend::instance(); verify_simple_job_specification (scheduler); diff --git a/tests/core/steam/engine/testframe-test.cpp b/tests/core/steam/engine/testframe-test.cpp index baa6bfbdb..7bfead6de 100644 --- a/tests/core/steam/engine/testframe-test.cpp +++ b/tests/core/steam/engine/testframe-test.cpp @@ -29,12 +29,10 @@ #include "steam/engine/testframe.hpp" #include "lib/util.hpp" -#include #include #include using test::Test; -using std::rand; using util::isSameObject; using std::unique_ptr; @@ -54,7 +52,7 @@ namespace test { { char* accessor = reinterpret_cast (base); while (count--) - accessor[offset+count] = rand() % CHAR_MAX; + accessor[offset+count] = rani(CHAR_MAX); } } // (End) internal defs @@ -80,6 +78,7 @@ namespace test { virtual void run (Arg) { + seedRand(); verifyBasicProperties(); verifyFrameLifecycle(); verifyFrameSeries(); diff --git a/tests/core/steam/engine/testframe.cpp b/tests/core/steam/engine/testframe.cpp index 521fc1ec6..b074fc582 100644 --- a/tests/core/steam/engine/testframe.cpp +++ b/tests/core/steam/engine/testframe.cpp @@ -26,6 +26,7 @@ #include "lib/error.hpp" +#include "lib/random.hpp" #include "steam/engine/testframe.hpp" #include @@ -42,6 +43,7 @@ namespace test { using std::vector; using std::memcpy; + using lib::rani; typedef boost::rand48 PseudoRandom; @@ -62,7 +64,7 @@ namespace test { generateDistinction(uint seq, uint family) { // random offset, but fixed per executable run - static uint base(10 + rand() % 990); + static uint base(10 + rani(990)); /////////////////////////////////////////////////////////////////////TICKET #1372 this is not reproducible!! // use the family as stepping return (seq+1) * (base+family); diff --git a/tests/core/steam/engine/timings-test.cpp b/tests/core/steam/engine/timings-test.cpp index 6b7410a8f..7db07d19f 100644 --- a/tests/core/steam/engine/timings-test.cpp +++ b/tests/core/steam/engine/timings-test.cpp @@ -44,7 +44,6 @@ using test::Test; using util::isnil; //using std::vector; //using std::function; -using std::rand; namespace steam { @@ -70,7 +69,7 @@ namespace test { FSecs randTicks() { - return FSecs{1 + rand() % 600, 1 + rand() % 600}; + return FSecs{1 + rani(600), 1 + rani(600)}; } } // (End) Test fixture @@ -90,6 +89,7 @@ namespace test { virtual void run (Arg) { + seedRand(); verify_simpleFrameStep(); verify_next_startPoint(); } diff --git a/tests/core/steam/engine/tracking-heap-block-provider-test.cpp b/tests/core/steam/engine/tracking-heap-block-provider-test.cpp index 511fa4d18..274f0f70b 100644 --- a/tests/core/steam/engine/tracking-heap-block-provider-test.cpp +++ b/tests/core/steam/engine/tracking-heap-block-provider-test.cpp @@ -31,11 +31,8 @@ #include "steam/engine/buffhandle-attach.hpp" #include "steam/engine/testframe.hpp" -#include #include -using std::rand; - namespace steam { namespace engine{ @@ -82,6 +79,8 @@ namespace test { virtual void run (Arg) { + seedRand(); + simpleExample(); verifyStandardCase(); verifyTestProtocol(); @@ -97,7 +96,7 @@ namespace test { CHECK (testBuff); CHECK (testBuff.accessAs().isSane()); - uint dataID = 1 + rand() % 29; + uint dataID = 1 + rani(29); testBuff.accessAs() = testData(dataID); provider.emitBuffer (testBuff); @@ -121,7 +120,7 @@ namespace test { for (uint i=0; i() = testNumbers[i] = rand() % 100000; + buff.accessAs() = testNumbers[i] = rani(100000); provider.emitBuffer (buff); provider.releaseBuffer(buff); } diff --git a/tests/core/steam/fixture/fixture-segment-test.cpp b/tests/core/steam/fixture/fixture-segment-test.cpp index edf12f166..a68353456 100644 --- a/tests/core/steam/fixture/fixture-segment-test.cpp +++ b/tests/core/steam/fixture/fixture-segment-test.cpp @@ -63,6 +63,7 @@ namespace test { virtual void run (Arg) { + seedRand(); fabricate_MockSegment(); retrieve_JobTicket(); } diff --git a/tests/core/steam/fixture/node-graph-attachment-test.cpp b/tests/core/steam/fixture/node-graph-attachment-test.cpp index db7c7aebb..67fded65c 100644 --- a/tests/core/steam/fixture/node-graph-attachment-test.cpp +++ b/tests/core/steam/fixture/node-graph-attachment-test.cpp @@ -60,6 +60,7 @@ namespace test { virtual void run (Arg) { + seedRand(); access_ExitNodeTree(); fabricate_MockExitNode(); } diff --git a/tests/core/steam/mobject/session/defs-manager-impl-test.cpp b/tests/core/steam/mobject/session/defs-manager-impl-test.cpp index 58e1b6a80..c78a0e5b1 100644 --- a/tests/core/steam/mobject/session/defs-manager-impl-test.cpp +++ b/tests/core/steam/mobject/session/defs-manager-impl-test.cpp @@ -79,7 +79,7 @@ namespace test { string newID (Symbol prefix) { - return pattern % prefix % std::rand(); + return pattern % prefix % rani(10'000); } }//(end)test fixture @@ -96,6 +96,8 @@ namespace test { virtual void run(Arg) { + seedRand(); + define_and_search(); string pipeID = create(); forget(pipeID); diff --git a/tests/core/steam/mobject/session/defs-manager-test.cpp b/tests/core/steam/mobject/session/defs-manager-test.cpp index 76d23aa2c..8481a2980 100644 --- a/tests/core/steam/mobject/session/defs-manager-test.cpp +++ b/tests/core/steam/mobject/session/defs-manager-test.cpp @@ -88,6 +88,7 @@ namespace test { virtual void run (Arg arg) { + seedRand(); string pipeID = isnil(arg)? "Black Hole" : arg[1]; string streamID = 2>arg.size()? "teststream" : arg[2]; @@ -149,7 +150,7 @@ namespace test { string new_pID = _Fmt{"dummy_%s_%i"} % pipe1->getPipeID() - % std::rand() + % rani(10'000) ; // make random new pipeID Query query_for_new{"pipe("+new_pID+")"}; diff --git a/tests/core/steam/mobject/session/defs-registry-impl-test.cpp b/tests/core/steam/mobject/session/defs-registry-impl-test.cpp index 3822635fd..6a96eb50a 100644 --- a/tests/core/steam/mobject/session/defs-registry-impl-test.cpp +++ b/tests/core/steam/mobject/session/defs-registry-impl-test.cpp @@ -44,7 +44,6 @@ using lib::P; using std::unique_ptr; using std::string; -using std::rand; using std::map; @@ -62,7 +61,7 @@ namespace test { string newID (string prefix) { - return instancePatt % prefix % rand(); + return instancePatt % prefix % rani(10'000); } @@ -139,6 +138,7 @@ namespace test { virtual void run (Arg) { + seedRand(); this->reg_.reset (new DefsRegistry); fill_table (); diff --git a/tests/library/advice/advice-basics-test.cpp b/tests/library/advice/advice-basics-test.cpp index ccb46e2dd..8e7704520 100644 --- a/tests/library/advice/advice-basics-test.cpp +++ b/tests/library/advice/advice-basics-test.cpp @@ -28,11 +28,6 @@ #include "lib/test/run.hpp" #include "common/advice.hpp" -#include - -using std::rand; - - namespace lumiera { namespace advice { @@ -116,6 +111,8 @@ namespace test { virtual void run (Arg) { + seedRand(); + simpleExchange(); createCollaboration(); overwriting_and_retracting(); @@ -133,7 +130,7 @@ namespace test { TheAdvisor server; // implicitly prepares an advice provision CHECK (client.got (0)); // but as no advice was provided yet, nothing happens - int rr (1 + (rand() % 1000)); + int rr{ 1 + rani(1000)}; server.publish (rr); // now an match is detected, creating an advice channel CHECK (client.got (rr)); // ..so the client can pick up the provided advice value @@ -147,8 +144,8 @@ namespace test { TheAdvised client1 ("topic1()"); TheAdvisor server2 ("topic2()"); - int r1 (1 + (rand() % 1000)); - int r2 (1 + (rand() % 1000)); + int r1{ 1 + rani(1000)}; + int r2{ 1 + rani(1000)}; server2.publish (r2); CHECK (client1.got(0)); @@ -186,8 +183,8 @@ namespace test { CHECK (client1.got(0)); CHECK (client2.got(0)); - int r1 (1 + (rand() % 1000)); - int r2 (1 + (rand() % 1000)); + int r1{ 1 + rani(1000)}; + int r2{ 1 + rani(1000)}; { TheAdvisor server("slot1()"); diff --git a/tests/library/allocation-cluster-test.cpp b/tests/library/allocation-cluster-test.cpp index 9bca60770..82d9cafdb 100644 --- a/tests/library/allocation-cluster-test.cpp +++ b/tests/library/allocation-cluster-test.cpp @@ -128,7 +128,7 @@ namespace test { { auto invoker = buildTrampoline(); for (uint i=0; i (1 + uint16_t(rand())); + auto& i1 = clu.create (1 + uint16_t(rani())); CHECK (i1 > 0); CHECK (1 == clu.numExtents()); CHECK (2 == clu.numBytes()); diff --git a/tests/library/del-stash-test.cpp b/tests/library/del-stash-test.cpp index ea1548a77..45ab2bd45 100644 --- a/tests/library/del-stash-test.cpp +++ b/tests/library/del-stash-test.cpp @@ -28,17 +28,11 @@ #include "lib/test/run.hpp" #include "lib/del-stash.hpp" -#include - namespace lib { namespace test{ - using std::rand; - - - namespace { // probe victims ulong MAX_MASS = 200; // number of victims to kill at once @@ -59,7 +53,7 @@ namespace test{ REQUIRE (siz); for (uint i=0; i #include -#include using boost::lexical_cast; using std::cout; @@ -94,7 +93,7 @@ namespace test { string formatString = "%p %|20T_| %u"; _Fmt formatter (formatString); - uint val = rand() % 100; + uint val = rani (100); void *pt = &val; formatter % pt; diff --git a/tests/library/hash-generator-test.cpp b/tests/library/hash-generator-test.cpp index b6ee9f1b2..176e85c47 100644 --- a/tests/library/hash-generator-test.cpp +++ b/tests/library/hash-generator-test.cpp @@ -61,6 +61,7 @@ namespace test{ virtual void run (Arg) { + seedRand(); demonstrate_boost_hash_weakness(); verify_Knuth_workaround(); } @@ -133,7 +134,7 @@ namespace test{ { StringsTable hashValues; string prefix = "Entry."; - const size_t seed = rand(); + const size_t seed = rani(); const size_t KNUTH_MAGIC = 2654435761; diff --git a/tests/library/item-wrapper-test.cpp b/tests/library/item-wrapper-test.cpp index f336e066d..57ddf03e7 100644 --- a/tests/library/item-wrapper-test.cpp +++ b/tests/library/item-wrapper-test.cpp @@ -28,13 +28,14 @@ #include "lib/test/run.hpp" #include "lib/test/test-helper.hpp" +#include "lib/format-cout.hpp" +#include "lib/random.hpp" #include "lib/util.hpp" #include "lib/wrapper.hpp" #include #include -#include #include #include #include @@ -55,9 +56,6 @@ namespace test{ using std::shared_ptr; using std::vector; using std::string; - using std::rand; - using std::cout; - using std::endl; @@ -69,9 +67,9 @@ namespace test{ { uint i_; - Tracker() : i_(rand() % 500) { ++cntTracker; } - Tracker(Tracker const& ot) : i_(ot.i_) { ++cntTracker; } - ~Tracker() { --cntTracker; } + Tracker() : i_(rani(500)) { ++cntTracker; } + Tracker(Tracker const& ot) : i_(ot.i_) { ++cntTracker; } + ~Tracker() { --cntTracker; } }; bool operator== (Tracker const& t1, Tracker const& t2) { return t1.i_ == t2.i_; } @@ -112,8 +110,10 @@ namespace test{ virtual void run (Arg) { - ulong l1 (rand() % 1000); - ulong l2 (rand() % 1000); + seedRand(); + + ulong l1 (rani (1000)); + ulong l2 (rani (1000)); string s1 (randStr(50)); string s2 (randStr(50)); const char* cp (s1.c_str()); @@ -304,15 +304,17 @@ namespace test{ } + static auto produceResult() { return rani(); } + /** @test verify an extension built on top of the ItemWrapper: * a function which remembers the last result. As a simple test, - * we bind the \c rand() standard lib function and remember the - * last returned random value. + * we bind a static helper function to produce a random value + * and remember the result returned last. */ void verifyFunctionResult() { - FunctionResult randomVal (std::rand); + FunctionResult randomVal (produceResult); // function was never invoked, thus the remembered result is NIL CHECK (!randomVal); diff --git a/tests/library/iter-explorer-test.cpp b/tests/library/iter-explorer-test.cpp index 39114607d..9bb11a507 100644 --- a/tests/library/iter-explorer-test.cpp +++ b/tests/library/iter-explorer-test.cpp @@ -161,7 +161,7 @@ namespace test{ static char rndLetter() { - return 'A' + rand() % 26; + return 'A' + rani(26); } public: @@ -274,6 +274,8 @@ namespace test{ virtual void run (Arg) { + seedRand(); + verify_wrappedState(); verify_wrappedIterator(); diff --git a/tests/library/iter-source-test.cpp b/tests/library/iter-source-test.cpp index d031a8f2e..5e38bd0ab 100644 --- a/tests/library/iter-source-test.cpp +++ b/tests/library/iter-source-test.cpp @@ -36,7 +36,6 @@ #include #include -#include #include #include #include @@ -47,15 +46,14 @@ namespace lib { namespace test{ using ::Test; + using util::isnil; using boost::lexical_cast; using lib::time::TimeVar; using lib::test::randStr; using lib::test::randTime; - using util::isnil; using std::make_pair; using std::string; using std::list; - using std::rand; using LERR_(ITER_EXHAUST); @@ -186,6 +184,7 @@ namespace test{ virtual void run (Arg arg) { + seedRand(); if (0 < arg.size()) NUM_ELMS = lexical_cast (arg[1]); verify_simpleIters(); @@ -329,7 +328,7 @@ namespace test{ MAP testMap; for (uint i=0; i -#include #include @@ -48,7 +47,6 @@ namespace test{ using util::for_each; using util::isnil; using std::vector; - using std::rand; using LERR_(ITER_EXHAUST); @@ -246,7 +244,7 @@ namespace test{ vector numberz; for (uint i=0; i (&fun)); - beacon = rand(); + beacon = rani(); uint c = beacon % 42; // verify we can invoke the target function CHECK (beacon+c == fun(c)); @@ -130,7 +132,7 @@ namespace test{ // repeat same with a copy, and changed beacon value auto trojanClone = trojanLambda; - beacon = rand(); + beacon = rani(); c = beacon % 55; CHECK (beacon+c == trojanClone(c)); CHECK (location == &trojanClone); @@ -193,8 +195,8 @@ namespace test{ { struct Nested { - int unrelated{rand()}; - int anchor{rand()}; + int unrelated{rani()}; + int anchor{rani()}; }; struct Demo { @@ -262,7 +264,7 @@ namespace test{ CHECK (0 == report); // invoke function - int feed{1+rand()%100}; + int feed{1 + rani (100)}; float res = theFun (feed); // delegate *and* realFun were invoked @@ -271,7 +273,7 @@ namespace test{ // again... report = 0; - feed = -1-rand()%20; + feed = -1-rani(20); res = theFun (feed); // this time the delegate was *not* invoked, @@ -307,7 +309,7 @@ namespace test{ CHECK (not init); CHECK (funny); - int feed = 1 + rand()%99; + int feed = 1 + rani(99); CHECK (feed*0.555f == funny(feed)); CHECK (1 == invoked); CHECK (init); diff --git a/tests/library/meta/late-bind-instance-test.cpp b/tests/library/meta/late-bind-instance-test.cpp index 4ef327e9f..dd9e354bd 100644 --- a/tests/library/meta/late-bind-instance-test.cpp +++ b/tests/library/meta/late-bind-instance-test.cpp @@ -36,7 +36,6 @@ #include #include -#include namespace lib { @@ -44,7 +43,6 @@ namespace meta { namespace test { using std::move; - using std::rand; using std::tuple; using std::string; using lib::meta::dump; @@ -68,6 +66,7 @@ namespace test { void run (Arg) { + seedRand(); demonstrateUsage(); verify_forwarding(); verify_cornerCases(); @@ -84,7 +83,7 @@ namespace test { void demonstrateUsage() { - uint randomLimit = 2 + rand() % 98; + uint randomLimit = 2 + rani(98); auto plannedArgs = tuple{InstancePlaceholder{} @@ -104,7 +103,7 @@ namespace test { uint theMember (uint limit) { - return rand() % limit; + return rani (limit); } diff --git a/tests/library/meta/variadic-argument-picker-test.cpp b/tests/library/meta/variadic-argument-picker-test.cpp index 46ee16955..221449770 100644 --- a/tests/library/meta/variadic-argument-picker-test.cpp +++ b/tests/library/meta/variadic-argument-picker-test.cpp @@ -71,7 +71,7 @@ namespace test { uint i_; static int instanceCnt; - N (uint x = rand() % (abs(n)+1)) + N (uint x = rani(1 + abs(n))) : i_{x} { ++instanceCnt; @@ -136,6 +136,7 @@ namespace test { virtual void run (Arg) { + seedRand(); verify_fixture(); check_pickArg (); check_pickInit(); diff --git a/tests/library/meta/virtual-copy-support-test.cpp b/tests/library/meta/virtual-copy-support-test.cpp index 20c18ee04..79e48b877 100644 --- a/tests/library/meta/virtual-copy-support-test.cpp +++ b/tests/library/meta/virtual-copy-support-test.cpp @@ -133,7 +133,7 @@ namespace test { } Sub() { - access() = 'A' + rand() % 23; + access() = 'A' + rani(23); _CheckSum_ += access(); } Sub (Sub const& osub) @@ -253,6 +253,7 @@ namespace test { virtual void run (Arg) { + seedRand(); CHECK(0 == _CheckSum_); verify_TestFixture(); diff --git a/tests/library/null-value-test.cpp b/tests/library/null-value-test.cpp index 31f387f7b..3dc906398 100644 --- a/tests/library/null-value-test.cpp +++ b/tests/library/null-value-test.cpp @@ -31,15 +31,11 @@ #include "lib/null-value.hpp" #include "lib/util.hpp" -#include - namespace lib { namespace test{ using util::isSameObject; - using std::rand; - namespace { // test data and helpers... @@ -52,7 +48,7 @@ namespace test{ uint id_; DummyType() - : id_(1 + (rand() % 100)) + : id_(1 + rani(100)) { created = true; } @@ -78,6 +74,7 @@ namespace test{ void run (Arg) { + seedRand(); CHECK (long() == NullValue::get()); CHECK (short() == NullValue::get()); CHECK (isSameObject(NullValue::get(), NullValue::get())); diff --git a/tests/library/polymorphic-value-test.cpp b/tests/library/polymorphic-value-test.cpp index 3371208f1..7d2d7579b 100644 --- a/tests/library/polymorphic-value-test.cpp +++ b/tests/library/polymorphic-value-test.cpp @@ -121,7 +121,7 @@ namespace test{ virtual long apiFunc() { - long rr = ii * (1 + rand() % MAX_RAND); + long rr = ii * (1 + rani(MAX_RAND)); mark (rr); _callSum += rr; return rr; @@ -180,6 +180,7 @@ namespace test{ _checkSum = 0; _callSum = 0; _created = 0; + seedRand(); verifyBasics(); diff --git a/tests/library/rational-test.cpp b/tests/library/rational-test.cpp index 0ada52d48..4389e3ea4 100644 --- a/tests/library/rational-test.cpp +++ b/tests/library/rational-test.cpp @@ -264,7 +264,7 @@ namespace test { array numz; for (auto& n : numz) { - n = rand() * uint64_t(1 << 31); + n = rani() * uint64_t(1 << 31); CHECK (ilog2(n) == floatLog(n)); CHECK (ilog2(n) == bitshift(n)); } diff --git a/tests/library/ref-array-test.cpp b/tests/library/ref-array-test.cpp index 3d608cdb5..a4169c450 100644 --- a/tests/library/ref-array-test.cpp +++ b/tests/library/ref-array-test.cpp @@ -36,13 +36,11 @@ using ::test::Test; using std::vector; -using std::rand; namespace lib { namespace test{ - namespace { // test types struct I @@ -118,6 +116,8 @@ namespace test{ virtual void run (Arg) { + seedRand(); + checkWrapper(); checkVector(); checkTable(); @@ -216,7 +216,7 @@ namespace test{ for (uint i=0; i<500; ++i) { Sub3::sum = 0; - Sub3::trigger = (rand() % 50); // when hitting the trigger Sub3 throws + Sub3::trigger = rani(50); // when hitting the trigger Sub3 throws try { { diff --git a/tests/library/replaceable-item-test.cpp b/tests/library/replaceable-item-test.cpp index 26ef5669f..3c80b2136 100644 --- a/tests/library/replaceable-item-test.cpp +++ b/tests/library/replaceable-item-test.cpp @@ -44,7 +44,6 @@ namespace test{ using time::Time; using time::Duration; using std::string; - using std::rand; using std::swap; @@ -57,10 +56,10 @@ namespace test{ { uint i_; - Tracker() : i_(rand() % 500) { ++cntTracker; } - Tracker(Tracker const& ot) : i_(ot.i_) { ++cntTracker; } - Tracker(uint i) : i_(i) { ++cntTracker; } - ~Tracker() { --cntTracker; } + Tracker() : i_(rani(500)) { ++cntTracker; } + Tracker(Tracker const& ot) : i_(ot.i_) { ++cntTracker; } + Tracker(uint i) : i_(i) { ++cntTracker; } + ~Tracker() { --cntTracker; } }; struct NonAssign @@ -101,8 +100,9 @@ namespace test{ virtual void run (Arg) { - ulong l1 (1 + rand() % 1000); - ulong l2 (1 + rand() % 1000); + seedRand(); + ulong l1 (1 + rani(1000)); + ulong l2 (1 + rani(1000)); string s1 (randStr(50)); string s2 (randStr(50)); const char* cp (s1.c_str()); @@ -239,7 +239,7 @@ namespace test{ { struct Wrap { - int i = -10 + rand() % 21; + int i = -10 + rani(21); }; ReplaceableItem w1 =Wrap{}, @@ -268,7 +268,7 @@ namespace test{ { struct Cagey { - int i = -10 + rand() % 21; + int i = -10 + rani(21); Cagey(Cagey && privy) : i(55) diff --git a/tests/library/scoped-collection-test.cpp b/tests/library/scoped-collection-test.cpp index 17a170eb7..3dcaff1fa 100644 --- a/tests/library/scoped-collection-test.cpp +++ b/tests/library/scoped-collection-test.cpp @@ -33,8 +33,6 @@ #include "lib/scoped-collection.hpp" #include "lib/test/tracking-dummy.hpp" -#include - namespace lib { namespace test{ @@ -109,6 +107,7 @@ namespace test{ virtual void run (Arg) { + seedRand(); simpleUsage(); building_RAII_Style(); building_StackStyle(); @@ -229,7 +228,7 @@ namespace test{ CHECK (0 == Dummy::checksum()); { - int rr = rand() % 100; + int rr = rani(100); CollD coll(3); CHECK (0 == coll.size()); @@ -308,7 +307,7 @@ namespace test{ { CHECK (0 == Dummy::checksum()); { - int rr = rand() % 100; + int rr = rani(100); int trigger = 100 + 5 + 1; // prevents the bomb from exploding (since rr < 100) CollD coll (6, Populator(rr, trigger)); diff --git a/tests/library/several-builder-test.cpp b/tests/library/several-builder-test.cpp index a0fea46e7..eaf76dcf0 100644 --- a/tests/library/several-builder-test.cpp +++ b/tests/library/several-builder-test.cpp @@ -42,7 +42,6 @@ using ::test::Test; using std::array; -using std::rand; using lib::explore; using util::isSameObject; @@ -125,7 +124,7 @@ namespace test{ { int16_t val; - ShortBlocker (short r = 1 + (rand() % 1'000)) + ShortBlocker (short r = 1 + rani(1'000)) : val(r) { }; }; @@ -152,6 +151,8 @@ namespace test{ virtual void run (Arg) { + seedRand(); + simpleUsage(); check_Builder(); check_ErrorHandling(); diff --git a/tests/library/simple-allocator-test.cpp b/tests/library/simple-allocator-test.cpp index d876a2947..31b84fec6 100644 --- a/tests/library/simple-allocator-test.cpp +++ b/tests/library/simple-allocator-test.cpp @@ -29,17 +29,14 @@ #include "lib/simple-allocator.hpp" #include "lib/util.hpp" -#include #include namespace lib { namespace test{ - using util::isSameObject; using std::string; - using std::rand; @@ -60,7 +57,7 @@ namespace test{ { REQUIRE (siz); for (uint i=0; i()); CHECK (can_calc_without_Error()); CHECK (not can_calc_without_Error()); diff --git a/tests/library/sync-waiting-test.cpp b/tests/library/sync-waiting-test.cpp index c8323408e..0d66b1a22 100644 --- a/tests/library/sync-waiting-test.cpp +++ b/tests/library/sync-waiting-test.cpp @@ -93,6 +93,7 @@ namespace test{ virtual void run (Arg) { + seedRand(); SyncOnBool token; ThreadJoinable ping ("SyncWaiting ping", [&]{ token.getIt(); }); @@ -105,7 +106,7 @@ namespace test{ sleep_for (100ms); // if the threads don't block correctly, they've missed their chance by now... // kick off the notification cascade... - uint val = (rand() % 1000); + uint val = rani(1000); token.provide (val); // wait for the two Threads to finish their handshake diff --git a/tests/library/thread-wrapper-join-test.cpp b/tests/library/thread-wrapper-join-test.cpp index 015510fc8..9269b26ee 100644 --- a/tests/library/thread-wrapper-join-test.cpp +++ b/tests/library/thread-wrapper-join-test.cpp @@ -65,6 +65,8 @@ namespace test { virtual void run (Arg) { + seedRand(); + simpleUse(); returnValue(); detectFailure(); @@ -100,7 +102,7 @@ namespace test { void returnValue() { - int mySecret = rand() % 1000; + int mySecret = rani(1000); ThreadJoinable theThread{"test join-2" ,&ThreadWrapperJoin_test::theAction diff --git a/tests/library/thread-wrapper-test.cpp b/tests/library/thread-wrapper-test.cpp index 9ac7ccae8..703386d67 100644 --- a/tests/library/thread-wrapper-test.cpp +++ b/tests/library/thread-wrapper-test.cpp @@ -65,6 +65,7 @@ namespace test{ virtual void run (Arg) { + seedRand(); demonstrateSimpleUsage(); verifyConcurrentExecution(); } @@ -122,7 +123,7 @@ namespace test{ { for (uint i=1; i<=NUM_THREADS; ++i) { - uint x = rand() % 1000; + uint x = rani(1000); globalSum += (i + x); threads.emplace (&TestThread::doIt, i, x); } // Note: bind to member function, copying arguments diff --git a/tests/library/typed-allocation-manager-test.cpp b/tests/library/typed-allocation-manager-test.cpp index 90fe1c444..0a562d589 100644 --- a/tests/library/typed-allocation-manager-test.cpp +++ b/tests/library/typed-allocation-manager-test.cpp @@ -29,18 +29,14 @@ #include "lib/typed-allocation-manager.hpp" #include "lib/util.hpp" - #include -#include namespace lib { namespace test{ - using util::isSameObject; using std::shared_ptr; - using std::rand; @@ -61,7 +57,7 @@ namespace test{ { REQUIRE (siz); for (uint i=0; i using ::Test; -using std::rand; using util::isnil; using util::_Fmt; @@ -60,8 +59,8 @@ namespace test { VecI data; for (uint i=0; i(); diff --git a/tests/library/variant-test.cpp b/tests/library/variant-test.cpp index 7340efc67..9433244e5 100644 --- a/tests/library/variant-test.cpp +++ b/tests/library/variant-test.cpp @@ -33,11 +33,9 @@ #include "lib/variant.hpp" #include "lib/util.hpp" - #include - namespace lib { namespace test{ @@ -78,6 +76,7 @@ namespace test{ virtual void run (Arg) { + seedRand(); createVariant(); accessVariant(); acceptPredicate(); @@ -123,7 +122,7 @@ namespace test{ void accessVariant() { - int someVal = rand() % 10000; + int someVal = rani(10000); string someStr = randStr(55); Time someTime = randTime(); diff --git a/tests/library/vector-transfer-test.cpp b/tests/library/vector-transfer-test.cpp index 16905c0de..ff07f64c0 100644 --- a/tests/library/vector-transfer-test.cpp +++ b/tests/library/vector-transfer-test.cpp @@ -30,8 +30,8 @@ #include "lib/scoped-holder-transfer.hpp" #include "lib/test/tracking-dummy.hpp" +#include "lib/format-cout.hpp" -#include #include @@ -40,7 +40,6 @@ namespace test { using ::Test; using std::vector; - using std::cout; namespace { // extending the Dummy for our special purpose.... @@ -84,7 +83,7 @@ namespace test { void setup (int x=0) { - setVal (x? x : (rand() % 10000)); + setVal (x? x : rani (10000)); TRACE (test, "CREATE val=%d ---> this=%p", getVal(),this); } @@ -131,6 +130,8 @@ namespace test { virtual void run (Arg) { + seedRand(); + cout << "\n..setup table space for 2 elements\n"; TransDummyVector table; table.reserve(2); diff --git a/tests/stage/abstract-tangible-test.cpp b/tests/stage/abstract-tangible-test.cpp index 3d020e021..47f3e1bee 100644 --- a/tests/stage/abstract-tangible-test.cpp +++ b/tests/stage/abstract-tangible-test.cpp @@ -176,6 +176,8 @@ namespace test { virtual void run (Arg) { + seedRand(); + verify_mockManipulation(); invokeCommand(); markState(); @@ -327,7 +329,7 @@ namespace test { MockElm mock("uiElm"); int prevState = dummyState; - int concreteParam = 1 +rand() % 100; + int concreteParam = 1 + rani(100); // on bus no traces from this command yet... CHECK (nexusLog.ensureNot(string(DUMMY_CMD_ID))); diff --git a/tests/stage/model/canvas-hook-test.cpp b/tests/stage/model/canvas-hook-test.cpp index 20a8aab50..836404337 100644 --- a/tests/stage/model/canvas-hook-test.cpp +++ b/tests/stage/model/canvas-hook-test.cpp @@ -57,7 +57,7 @@ namespace test { struct DummyWidget { - int i = rand(); // "identity" + int i = rani(); // "identity" friend bool operator== (DummyWidget const& wa, DummyWidget const& wb) @@ -180,6 +180,7 @@ namespace test { virtual void run (Arg) { + seedRand(); attach2canvas(); relocateWidget(); } @@ -219,12 +220,12 @@ namespace test { void relocateWidget() { - int x1 = rand() % 100; - int y1 = rand() % 100; - int x2 = rand() % 100; - int y2 = rand() % 100; - int x3 = rand() % 100; - int y3 = rand() % 100; + int x1 = rani (100); + int y1 = rani (100); + int x2 = rani (100); + int y2 = rani (100); + int x3 = rani (100); + int y3 = rani (100); FakeCanvas canvas; HookedWidget w1{canvas.hookedAt(x1,y1)}; diff --git a/tests/stage/model/view-hook-test.cpp b/tests/stage/model/view-hook-test.cpp index cc7a76107..08acb6e6f 100644 --- a/tests/stage/model/view-hook-test.cpp +++ b/tests/stage/model/view-hook-test.cpp @@ -56,7 +56,7 @@ namespace test { struct DummyWidget { - int i = rand(); // "identity" + int i = rani(); // "identity" friend bool operator== (DummyWidget const& wa, DummyWidget const& wb) @@ -167,6 +167,7 @@ namespace test { virtual void run (Arg) { + seedRand(); verify_standardUsage(); verify_multiplicity(); reOrderHooked(); diff --git a/tests/stage/model/w-link-test.cpp b/tests/stage/model/w-link-test.cpp index d59595982..e3f8297f0 100644 --- a/tests/stage/model/w-link-test.cpp +++ b/tests/stage/model/w-link-test.cpp @@ -50,7 +50,7 @@ namespace test { struct DummyWidget : public sigc::trackable { - X val = 1 + rand() % 100; + X val = 1 + rani(100); }; } @@ -67,6 +67,7 @@ namespace test { virtual void run (Arg) { + seedRand(); verify_standardUsage(); verify_reconnect(); verify_copy(); diff --git a/tests/vault/gear/activity-detector-test.cpp b/tests/vault/gear/activity-detector-test.cpp index e0588baf0..1b591efa9 100644 --- a/tests/vault/gear/activity-detector-test.cpp +++ b/tests/vault/gear/activity-detector-test.cpp @@ -58,6 +58,8 @@ namespace test { virtual void run (Arg) { + seedRand(); + simpleUsage(); verifyMockInvocation(); @@ -101,7 +103,7 @@ namespace test { { ActivityDetector detector; auto fun = detector.buildDiagnosticFun ("funny"); - uint rnd = rand() % 10000; + uint rnd = rani(10000); detector.incrementSeq(); CHECK (1 == detector.currSeq()); @@ -147,7 +149,7 @@ namespace test { { ActivityDetector detector; auto fun = detector.buildDiagnosticFun ("fakeFun"); - uint rnd = rand() % 10000; + uint rnd = rani(10000); CHECK (0 == fun (rnd)); @@ -219,7 +221,7 @@ namespace test { Time t = randTime(); Time td{t+Time(0,1)}; - size_t x = rand(); + size_t x = rani(); Activity a; CHECK (detector.ensureNoInvocation(CTX_WORK)); diff --git a/tests/vault/gear/activity-detector.hpp b/tests/vault/gear/activity-detector.hpp index cb896dd5f..8956a6d35 100644 --- a/tests/vault/gear/activity-detector.hpp +++ b/tests/vault/gear/activity-detector.hpp @@ -83,6 +83,7 @@ #include "lib/meta/function.hpp" #include "lib/wrapper.hpp" #include "lib/format-util.hpp" +#include "lib/random.hpp" #include "lib/util.hpp" #include @@ -104,6 +105,7 @@ namespace test { using lib::meta::RebindVariadic; using util::unConst; using util::isnil; + using lib::rani; using std::forward; using std::move; @@ -531,7 +533,7 @@ namespace test { Job buildMockJob (string id ="" ,Time nominal = lib::test::randTime() - ,size_t extra = rand()) + ,size_t extra = rani()) { InvocationInstanceID invoKey; invoKey.part.a = extra; diff --git a/tests/vault/gear/block-flow-test.cpp b/tests/vault/gear/block-flow-test.cpp index b52be0f74..23ca9e8d7 100644 --- a/tests/vault/gear/block-flow-test.cpp +++ b/tests/vault/gear/block-flow-test.cpp @@ -84,6 +84,7 @@ namespace test { virtual void run (Arg) { + seedRand(); simpleUsage(); handleEpoch(); placeActivity(); @@ -425,7 +426,7 @@ namespace test { const size_t MIN_DEAD = _raw(BASE_DEADLINE) - _raw(SPREAD_DEAD); auto&[t,r] = testData[i]; - r = rand() % SPREAD; + r = rani (SPREAD); t = TimeValue(i*STP + MIN_DEAD + r); } diff --git a/tests/vault/gear/scheduler-activity-test.cpp b/tests/vault/gear/scheduler-activity-test.cpp index d622dc8d3..809648a94 100644 --- a/tests/vault/gear/scheduler-activity-test.cpp +++ b/tests/vault/gear/scheduler-activity-test.cpp @@ -56,6 +56,8 @@ namespace test { virtual void run (Arg) { + seedRand(); + simpleUsage(); verifyActivity_Post(); @@ -140,7 +142,7 @@ namespace test { { ActivityDetector detector; - uint64_t x1=rand(), x2=rand(); + uint64_t x1=rani(), x2=rani(); Time nomTime = lib::test::randTime(); Activity feed{x1,x2}; Activity feed2{x1+1,x1+2}; diff --git a/tests/vault/gear/scheduler-commutator-test.cpp b/tests/vault/gear/scheduler-commutator-test.cpp index 34a166119..c39860d35 100644 --- a/tests/vault/gear/scheduler-commutator-test.cpp +++ b/tests/vault/gear/scheduler-commutator-test.cpp @@ -93,6 +93,7 @@ namespace test { virtual void run (Arg) { + seedRand(); demonstrateSimpleUsage(); verify_GroomingToken(); verify_GroomingGuard(); diff --git a/tests/vault/gear/scheduler-service-test.cpp b/tests/vault/gear/scheduler-service-test.cpp index 9350d5aba..bef60e46b 100644 --- a/tests/vault/gear/scheduler-service-test.cpp +++ b/tests/vault/gear/scheduler-service-test.cpp @@ -76,6 +76,7 @@ namespace test { virtual void run (Arg) { + seedRand(); simpleUsage(); verify_StartStop(); verify_LoadFactor(); diff --git a/tests/vault/gear/scheduler-stress-test.cpp b/tests/vault/gear/scheduler-stress-test.cpp index e8f156927..dbe0a0637 100644 --- a/tests/vault/gear/scheduler-stress-test.cpp +++ b/tests/vault/gear/scheduler-stress-test.cpp @@ -67,6 +67,7 @@ namespace test { virtual void run (Arg) { + seedRand(); smokeTest(); setup_systematicSchedule(); verify_instrumentation(); diff --git a/tests/vault/gear/stress-test-rig.hpp b/tests/vault/gear/stress-test-rig.hpp index d536f1da3..74163eaf9 100644 --- a/tests/vault/gear/stress-test-rig.hpp +++ b/tests/vault/gear/stress-test-rig.hpp @@ -153,6 +153,7 @@ #include "lib/gnuplot-gen.hpp" #include "lib/stat/statistic.hpp" #include "lib/stat/data.hpp" +#include "lib/random.hpp" #include "lib/util.hpp" #include @@ -529,7 +530,7 @@ namespace test { Param minP{upper}, maxP{lower}; for (uint i=0; ihash = seed; return move(*this); diff --git a/tests/vault/mem/extent-family-test.cpp b/tests/vault/mem/extent-family-test.cpp index 6c09bbca9..377351699 100644 --- a/tests/vault/mem/extent-family-test.cpp +++ b/tests/vault/mem/extent-family-test.cpp @@ -60,6 +60,7 @@ namespace test { virtual void run (Arg) { + seedRand(); simpleUsage(); use_and_drop(); iteration(); @@ -78,7 +79,7 @@ namespace test { Extent& extent = *extents.begin(); CHECK (10 == extent.size()); - int num = rand() % 1000; + int num = rani(1000); extent[2] = num; extent[5] = num+5; CHECK (num == extent[2]); diff --git a/wiki/thinkPad.ichthyo.mm b/wiki/thinkPad.ichthyo.mm index 772f9394c..d9b67468c 100644 --- a/wiki/thinkPad.ichthyo.mm +++ b/wiki/thinkPad.ichthyo.mm @@ -16105,9 +16105,7 @@ - - - +
  • @@ -16856,9 +16854,7 @@ - - - +

    ...denn das ist das vereinfachte Setup für "einfache" Applikationen @@ -17291,9 +17287,7 @@ - - - +

    ...d.h. „konventionell“, per ctor-Parameter @@ -17824,9 +17818,7 @@ - - - +

    das verdrängt lediglich das Kontext-Menü @@ -18988,9 +18980,7 @@ - - - +

    BEDINGUNG: ΔMenu > goal @@ -46330,9 +46320,7 @@ - - - +

    (GlobalCtx)->WindowLocator @@ -46714,9 +46702,7 @@ - - - +

    ich wollte explizit kein generisch-introspektives UI, @@ -47097,9 +47083,7 @@ - - - +

    nach Broadcast von "reset" @@ -47433,9 +47417,7 @@ - - - +

    Nein @@ -47696,9 +47678,7 @@ - - - +

    ...because it is also used to discard garbage after a findSrc operation. @@ -57426,7 +57406,14 @@ - + + + + + + + + @@ -57518,11 +57505,119 @@ - - + + - - + + + + + + + + + +

    + 0000000515: CHECK: rational-test.cpp:90: thread_1: demonstrate_basics: (util::toString(23_r/55) == "23/55sec") +

    + + +
    +
    + + + + +

    + 0000000514: INFO: suite.cpp:202: thread_1: invokeTestCase: ++------------------- invoking TEST: vault::gear::test::SchedulerCommutator_test +

    +

    + 0000000515: NOTICE: suite.cpp:118: thread_1: getSeed:      ++>>> SEED(rand) <<<: 12483615036814281831 +

    +

    + 0000000598: UNIMPLEMENTED: scheduler-commutator.hpp:204: thread_1: findWork: how to trigger a Scheduler-Emergency from here +

    + + +
    +
    + + + + +

    + TEST Scheduler Performance: SchedulerStress_test .. FAILED +

    +

    + unexpected return value 152, expected 0 +

    +

    + stderr was: +

    +

    + 0000000514: INFO: suite.cpp:202: thread_1: invokeTestCase: ++------------------- invoking TEST: vault::gear::test::SchedulerStress_test +

    +

    + 0000000515: NOTICE: suite.cpp:118: thread_1: getSeed:      ++>>> SEED(rand) <<<: 401457506165208591 +

    +

    + END +

    + + +
    +
    + + + + + +

    + 0000000516: PRECONDITION: tracking-heap-block-provider.cpp:281: thread_1: detachBuffer: (util::isSameObject(storage, block4buffer->accessMemory())) +

    + + +
    + + +
    +
    + + + + + + +
    + + + + + + + + + + + + + + +

    + erzeugt die zufälligen Summanden vorher im Haupt-Thread +

    + +
    + +
    + + + + + + + +