diff --git a/src/lib/test/run.hpp b/src/lib/test/run.hpp index c716cceb8..b6894642c 100644 --- a/src/lib/test/run.hpp +++ b/src/lib/test/run.hpp @@ -22,13 +22,14 @@ */ /** @file run.hpp - ** Simple test class runner. Allows for writing unit tests as subclass of + ** Simplistic test class runner. Allows for writing unit tests as subclass of ** test::Test . They may be installed for automatic invocation through test::Suite ** by defining a Launcher instance, which can be done conveniently by the macro LAUNCHER ** ** @see HelloWorld_test ** @see test::Suite ** @see testrunner.cpp + ** @see random.hpp ** @see main.cpp */ @@ -51,7 +52,7 @@ namespace test { using std::string; using std::shared_ptr; - typedef std::vector & Arg; + using Arg = std::vector &; @@ -62,15 +63,17 @@ namespace test { class Test { public: - virtual ~Test() = default; + virtual ~Test() = default; ///< this is an interface virtual void run(Arg arg) = 0; - void seedRand(); - lib::Random makeRandGen(); + void seedRand(); ///< draw a new random seed from a common nucleus, and re-seed the default-Gen. + lib::Random makeRandGen(); ///< build a dedicated new RandomGen, seeded from the default-Gen + static string firstTok (Arg); ///< conveniently pick the first token from the argument line + static uint firstVal (Arg, uint =1); ///< conveniently use some number given as argument, with optional default }; - - - + + + /** interface: generic testcase creating functor. */ class Launcher { @@ -78,7 +81,7 @@ namespace test { virtual ~Launcher() = default; virtual shared_ptr makeInstance() =0; }; - + /** * Helper class for running a collection of tests. @@ -109,7 +112,7 @@ namespace test { } // namespace test -// make them global for convenience +// make those global for convenience.... using ::test::Arg; using ::test::Test; using ::test::Launch; @@ -121,8 +124,8 @@ using lib::defaultGen; // and provide shortcut for registration #define LAUNCHER(_TEST_CLASS_, _GROUPS_) \ - /** Register _TEST_CLASS_ to be invoked in some test suites (groups) _GROUPS_ */ \ - Launch<_TEST_CLASS_> run_##_TEST_CLASS_##_(STRINGIFY(_TEST_CLASS_), _GROUPS_); + /** Register _TEST_CLASS_ to be invoked in some test suites (groups) _GROUPS_ */ \ + Launch<_TEST_CLASS_> run_##_TEST_CLASS_##_(STRINGIFY(_TEST_CLASS_), _GROUPS_); -#endif +#endif /*TESTHELPER_RUN_H*/ diff --git a/src/lib/test/suite.cpp b/src/lib/test/suite.cpp index 539032e41..205912d61 100644 --- a/src/lib/test/suite.cpp +++ b/src/lib/test/suite.cpp @@ -215,7 +215,7 @@ namespace test { } - /** draw a new random seed from a common nucleus, and re-seed the default-Gen. */ + void Test::seedRand() { @@ -223,13 +223,28 @@ namespace test { } - /** build a dedicated new RandomGen, seeded from the default-Gen */ Random Test::makeRandGen() { return Random{lib::seedFromDefaultGen()}; } - + + + uint + Test::firstVal (Arg arg, uint someNumber) + { + if (not isnil(arg)) + someNumber = boost::lexical_cast (arg[1]); // may throw + return someNumber; + } + + string + Test::firstTok (Arg arg) + { + return isnil(arg)? util::BOTTOM_INDICATOR + : arg[1]; + } + /** run all testcases contained in this Suite. diff --git a/tests/32scheduler.tests b/tests/32scheduler.tests index 9f6badc45..7687236eb 100644 --- a/tests/32scheduler.tests +++ b/tests/32scheduler.tests @@ -56,7 +56,7 @@ END -TEST "Scheduler Performance" SchedulerStress_test <(arg[1]); - + uint num{firstVal (arg)}; cout << _Fmt("using the Singleton should create TargetObj(%d)...\n") % num; Interface::setCountParam(num); diff --git a/tests/basics/singleton-test.cpp b/tests/basics/singleton-test.cpp index bee1e11d5..55a64bb37 100644 --- a/tests/basics/singleton-test.cpp +++ b/tests/basics/singleton-test.cpp @@ -83,7 +83,7 @@ namespace test{ virtual void run (Arg arg) { - uint num= isnil(arg)? 1 : lexical_cast(arg[1]); + uint num{firstVal (arg)}; Depend singleton; diff --git a/tests/core/steam/render-segment-test.cpp b/tests/core/steam/render-segment-test.cpp index 7e5add18f..cc56aff08 100644 --- a/tests/core/steam/render-segment-test.cpp +++ b/tests/core/steam/render-segment-test.cpp @@ -49,7 +49,8 @@ namespace test { */ class RenderSegment_test : public Test { - virtual void run(Arg arg) + virtual void + run (Arg) { UNIMPLEMENTED ("complete render process for a given test segment of the Session"); } diff --git a/tests/library/helloworldtest.cpp b/tests/library/helloworldtest.cpp index f0993fc78..83c05384b 100644 --- a/tests/library/helloworldtest.cpp +++ b/tests/library/helloworldtest.cpp @@ -49,8 +49,7 @@ namespace test { virtual void run (Arg arg) { - int num= isnil(arg)? 1 : lexical_cast (arg[1]); - + uint num{firstVal (arg)}; for ( ; 0 < num-- ; ) greeting(); } diff --git a/tests/library/iter-adapter-stl-test.cpp b/tests/library/iter-adapter-stl-test.cpp index ad6715043..e91c4720a 100644 --- a/tests/library/iter-adapter-stl-test.cpp +++ b/tests/library/iter-adapter-stl-test.cpp @@ -60,11 +60,6 @@ namespace test{ cout << "-----"<() << endl; - namespace { - uint NUM_ELMS = 10; - } - - @@ -90,11 +85,12 @@ namespace test{ */ class IterAdapterSTL_test : public Test { + uint NUM_ELMS{0}; virtual void run (Arg arg) { - if (0 < arg.size()) NUM_ELMS = lexical_cast (arg[1]); + NUM_ELMS = firstVal (arg, 10); checkDistinctValIter(); diff --git a/tests/library/iter-adapter-test.cpp b/tests/library/iter-adapter-test.cpp index 1da93eee0..1ccf08b97 100644 --- a/tests/library/iter-adapter-test.cpp +++ b/tests/library/iter-adapter-test.cpp @@ -52,11 +52,9 @@ namespace test{ namespace { - - uint NUM_ELMS = 10; - - /** example of simply wrapping an STL container - * and exposing a range as Lumiera Forward Iterator + /** + * example of simply wrapping an STL container + * and exposing a range as Lumiera Forward Iterator */ struct WrappedVector { @@ -81,7 +79,7 @@ namespace test{ }; - /** + /** * Example of a more elaborate custom container exposing an iteration API. * While the demo implementation here is based on pointers within a vector, * we hand out a IterAdapter, which will call back when used by the client, @@ -188,15 +186,16 @@ namespace test{ * @note see Ticket #182 * @see IterAdapter * @see itertools.hpp - * @see IterSource + * @see IterSource */ class IterAdapter_test : public Test { + uint NUM_ELMS{0}; virtual void run (Arg arg) { - if (0 < arg.size()) NUM_ELMS = lexical_cast (arg[1]); + NUM_ELMS = firstVal (arg, 10); useSimpleWrappedContainer (); @@ -414,7 +413,7 @@ namespace test{ // building a const iterator needs to be done in a somewhat weird way; // since we're exposing the pointer as value, the solution is to add - // the const on the immediately wrapped iterator type + // the const on the immediately wrapped iterator type typedef vector::const_iterator ConstRawIter; typedef RangeIter ConstRange; typedef AddressExposingIter ConstAddrIter; diff --git a/tests/library/iter-source-test.cpp b/tests/library/iter-source-test.cpp index 5e38bd0ab..1a392c7a0 100644 --- a/tests/library/iter-source-test.cpp +++ b/tests/library/iter-source-test.cpp @@ -69,11 +69,6 @@ namespace test{ namespace { // Subject of test - - uint NUM_ELMS = 10; - - typedef const char* CStr; - /** * Explicit implementation of the IterSource interface (test dummy) * Creates a random string and chops off a character on each iteration @@ -181,11 +176,13 @@ namespace test{ typedef std::unordered_multimapHashMultimap; + uint NUM_ELMS{0}; + virtual void run (Arg arg) { seedRand(); - if (0 < arg.size()) NUM_ELMS = lexical_cast (arg[1]); + NUM_ELMS = firstVal (arg, 10); verify_simpleIters(); verify_transformIter(); diff --git a/tests/library/itertools-test.cpp b/tests/library/itertools-test.cpp index ae9dc4937..49550f3e5 100644 --- a/tests/library/itertools-test.cpp +++ b/tests/library/itertools-test.cpp @@ -54,8 +54,6 @@ namespace test{ namespace { // Test data - uint NUM_ELMS = 10; - struct TestSource { vector data_; @@ -94,11 +92,13 @@ namespace test{ typedef TestSource::iterator Iter; + uint NUM_ELMS{0}; + virtual void run (Arg arg) { - if (0 < arg.size()) NUM_ELMS = lexical_cast (arg[1]); + NUM_ELMS = firstVal (arg, 10); TestSource source(NUM_ELMS); diff --git a/tests/library/util-collection-test.cpp b/tests/library/util-collection-test.cpp index 7a60c06e9..ad49d03aa 100644 --- a/tests/library/util-collection-test.cpp +++ b/tests/library/util-collection-test.cpp @@ -59,8 +59,6 @@ namespace test { namespace{ // Test data and operations - uint NUM_ELMS = 20; - VecI someNumberz (uint count) { @@ -85,14 +83,12 @@ namespace test { */ class UtilCollection_test : public Test { - - void + virtual void run (Arg arg) { verify_typeDetectors(); - if (0 < arg.size()) NUM_ELMS = lexical_cast (arg[0]); - + uint NUM_ELMS = firstVal (arg, 20); VecI container = someNumberz (NUM_ELMS); RangeI iterator(container.begin(), container.end()); diff --git a/tests/library/util-foreach-test.cpp b/tests/library/util-foreach-test.cpp index 624308fae..518f6c9e2 100644 --- a/tests/library/util-foreach-test.cpp +++ b/tests/library/util-foreach-test.cpp @@ -59,8 +59,6 @@ namespace test { namespace{ // Test data and operations - uint NUM_ELMS = 10; - // Placeholder for argument in bind-expressions std::_Placeholder<1> _1; @@ -122,12 +120,12 @@ namespace test { */ class UtilForeach_test : public Test { + uint NUM_ELMS{0}; - void + virtual void run (Arg arg) { - if (0 < arg.size()) NUM_ELMS = lexical_cast (arg[1]); - + NUM_ELMS = firstVal (arg, 10); VecI container = buildTestNumberz (NUM_ELMS); RangeI iterator(container.begin(), container.end()); @@ -377,9 +375,9 @@ namespace test { CHECK ( and_all (coll, [] (uint elm) { return 0 < elm; })); CHECK (!and_all (coll, [] (uint elm) { return 1 < elm; })); - CHECK ( has_any (coll, [] (uint elm) { return 0 < elm; })); - CHECK ( has_any (coll, [] (uint elm) { return elm == NUM_ELMS; })); - CHECK (!has_any (coll, [] (uint elm) { return elm > NUM_ELMS; })); + CHECK ( has_any (coll, [] (uint elm) { return 0 < elm; })); + CHECK ( has_any (coll, [this](uint elm) { return elm == NUM_ELMS; })); + CHECK (!has_any (coll, [this](uint elm) { return elm > NUM_ELMS; })); } diff --git a/tests/test.sh b/tests/test.sh index 2504050db..0f7730c82 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -246,10 +246,10 @@ function compare_template() # template plainfile #tests `TESTSUITES` environment variable. #tests #tests HEAD~ Testsuites; test files; writing tests -#tests It is common to start the name of the '.test' files with a 2 digi number to give them a proper +#tests It is common to start the name of the '.test' files with a 2 digit number to give them a proper #tests order: '10foo.test', '20bar.test' and so on. Each such test should only test a certain aspect of #tests the system. You have to select the testing binary with the `TESTING` function and then write -#tests certain TEST's defining how the test should react. Since tests are shell scripts it is possible +#tests certain TESTs defining how the test should react. Since tests are shell scripts it is possible #tests to add some supplemental commands there to set and clean up the given test environment. #tests #tests HEAD^ TESTING; TESTING; set the test binary diff --git a/tests/vault/gear/scheduler-stress-test.cpp b/tests/vault/gear/scheduler-stress-test.cpp index dbe0a0637..3d82ebe38 100644 --- a/tests/vault/gear/scheduler-stress-test.cpp +++ b/tests/vault/gear/scheduler-stress-test.cpp @@ -65,10 +65,13 @@ namespace test { { virtual void - run (Arg) + run (Arg arg) { seedRand(); smokeTest(); + if ("quick" == firstTok (arg)) + return; + setup_systematicSchedule(); verify_instrumentation(); search_breaking_point(); @@ -83,7 +86,7 @@ namespace test { smokeTest() { MARK_TEST_FUN - TestChainLoad testLoad{512}; + TestChainLoad testLoad{1024}; testLoad.configureShape_chain_loadBursts() .buildTopology() // .printTopologyDOT() @@ -120,8 +123,8 @@ namespace test { double performanceTime = testLoad.setupSchedule(scheduler) .withLoadTimeBase(LOAD_BASE) - .withJobDeadline(150ms) - .withPlanningStep(200us) + .withJobDeadline (150ms) // ◁─────────────── rather tight (and below overall run time) + .withPlanningStep(300us) .withChunkSize(20) .launch_and_wait();