From 66cc3510400f7f73529aeb3f627bcbc5d4f86554 Mon Sep 17 00:00:00 2001 From: Nathan Brei Date: Sat, 27 Apr 2024 20:12:54 -0400 Subject: [PATCH] Migrate test cases --- src/programs/unit_tests/BarrierEventTests.h | 14 +++++++---- src/programs/unit_tests/ExactlyOnceTests.h | 8 +++++-- src/programs/unit_tests/GetObjectsTests.cc | 9 ++++--- .../JEventProcessorSequentialTests.cc | 9 ++----- .../unit_tests/JFactoryDefTagsTests.cc | 9 +------ src/programs/unit_tests/JFactoryTests.h | 7 +++++- src/programs/unit_tests/ScaleTests.h | 7 +++++- src/programs/unit_tests/SubeventTests.cc | 11 +++++---- src/programs/unit_tests/TerminationTests.h | 24 ++++++++++++++----- src/programs/unit_tests/TimeoutTests.h | 9 ++++--- src/programs/unit_tests/UserExceptionTests.h | 9 ++++--- 11 files changed, 73 insertions(+), 43 deletions(-) diff --git a/src/programs/unit_tests/BarrierEventTests.h b/src/programs/unit_tests/BarrierEventTests.h index 09f7c2823..761b98096 100644 --- a/src/programs/unit_tests/BarrierEventTests.h +++ b/src/programs/unit_tests/BarrierEventTests.h @@ -17,23 +17,27 @@ class BarrierSource : public JEventSource { public: + BarrierSource() { + SetCallbackStyle(CallbackStyle::ExpertMode); + } + void Open() override { } - void GetEvent(std::shared_ptr event) override { + Result Emit(JEvent& event) override { event_count++; if (event_count >= 100) { - throw RETURN_STATUS::kNO_MORE_EVENTS; + return Result::FailureFinished; } LOG << "Emitting event " << event_count << LOG_END; - event->SetEventNumber(event_count); + event.SetEventNumber(event_count); if (event_count % 10 == 0) { - event->SetSequential(true); + event.SetSequential(true); } - + return Result::Success; } }; diff --git a/src/programs/unit_tests/ExactlyOnceTests.h b/src/programs/unit_tests/ExactlyOnceTests.h index 282bcfa5c..62b3f0e19 100644 --- a/src/programs/unit_tests/ExactlyOnceTests.h +++ b/src/programs/unit_tests/ExactlyOnceTests.h @@ -16,15 +16,19 @@ struct SimpleSource : public JEventSource { std::atomic_int close_count {0}; std::atomic_int event_count {0}; + SimpleSource() { + SetCallbackStyle(CallbackStyle::ExpertMode); + } void Open() override { open_count += 1; } - void GetEvent(std::shared_ptr) override { + Result Emit(JEvent&) override { if (++event_count == 5) { - throw JEventSource::RETURN_STATUS::kNO_MORE_EVENTS; + return Result::FailureFinished; } + return Result::Success; } void Close() override { close_count += 1; diff --git a/src/programs/unit_tests/GetObjectsTests.cc b/src/programs/unit_tests/GetObjectsTests.cc index 3b14d5b4c..05e8399d2 100644 --- a/src/programs/unit_tests/GetObjectsTests.cc +++ b/src/programs/unit_tests/GetObjectsTests.cc @@ -10,11 +10,14 @@ struct Obj3 : public JObject { int data; }; struct Obj4 : public JObject { int data; }; class Src : public JEventSource { - - void GetEvent(std::shared_ptr event) override { + Src() { + SetCallbackStyle(CallbackStyle::ExpertMode); + } + Result Emit(JEvent& event) override { auto obj = new Obj1; obj->data = 21; - event->Insert(obj); + event.Insert(obj); + return Result::Success; } bool GetObjects(const std::shared_ptr&, JFactory* fac) override { if (fac->GetObjectName() == "Obj2") { diff --git a/src/programs/unit_tests/JEventProcessorSequentialTests.cc b/src/programs/unit_tests/JEventProcessorSequentialTests.cc index f971fbc4c..31aaebb16 100644 --- a/src/programs/unit_tests/JEventProcessorSequentialTests.cc +++ b/src/programs/unit_tests/JEventProcessorSequentialTests.cc @@ -13,11 +13,6 @@ namespace jeventprocessorsequentialtests { // the linker will cheerfully not notice and you will get VERY weird errors. // Hence, we protect each Catch test with its own namespace. -struct DummySource : public JEventSource { - - // By default, this will emit empty events with event numbers 0,1,2... - void GetEvent(std::shared_ptr) override {} -}; struct MyRootProcessor : public JEventProcessorSequentialRoot { std::vector> access_log; @@ -51,7 +46,7 @@ struct MyRootProcessor : public JEventProcessorSequentialRoot { TEST_CASE("JEventProcessorSequentialRootTests") { JApplication app; - app.Add(new DummySource); + app.Add(new JEventSource()); app.SetParameterValue("nthreads", 4); app.SetParameterValue("jana:nevents", 4); app.SetParameterValue("jana:event_source_chunksize", 1); @@ -138,7 +133,7 @@ struct MySeqProcessor : public JEventProcessorSequential { TEST_CASE("JEventProcessorSequentialTests") { JApplication app; - app.Add(new DummySource); + app.Add(new JEventSource()); app.SetParameterValue("nthreads", 4); app.SetParameterValue("jana:nevents", 4); app.SetParameterValue("jana:event_source_chunksize", 1); diff --git a/src/programs/unit_tests/JFactoryDefTagsTests.cc b/src/programs/unit_tests/JFactoryDefTagsTests.cc index a18831bdf..a85e93455 100644 --- a/src/programs/unit_tests/JFactoryDefTagsTests.cc +++ b/src/programs/unit_tests/JFactoryDefTagsTests.cc @@ -102,13 +102,6 @@ TEST_CASE("MediumDefTags") { } namespace deftagstest { -struct DummySource : public JEventSource { - DummySource() { - SetTypeName(NAME_OF_THIS); - }; - - void GetEvent(std::shared_ptr) override {}; -}; struct DummyProcessor : public JEventProcessor { double E = 0.5; @@ -135,7 +128,7 @@ TEST_CASE("LargeDefTags") { JApplication app; app.Add(new JFactoryGeneratorT); app.Add(new JFactoryGeneratorT); - app.Add(new DummySource); + app.Add(new JEventSource); auto proc = new DummyProcessor; app.Add(proc); app.SetParameterValue("jana:nevents", 3); diff --git a/src/programs/unit_tests/JFactoryTests.h b/src/programs/unit_tests/JFactoryTests.h index fdb9362c5..eb3c98801 100644 --- a/src/programs/unit_tests/JFactoryTests.h +++ b/src/programs/unit_tests/JFactoryTests.h @@ -69,7 +69,12 @@ struct JFactoryTestExceptingInInitFactory : public JFactoryT) override { + JFactoryTestDummySource() { + SetCallbackStyle(CallbackStyle::ExpertMode); + } + + Result Emit(JEvent&) override { + return Result::Success; }; bool GetObjects(const std::shared_ptr&, JFactory* aFactory) override { diff --git a/src/programs/unit_tests/ScaleTests.h b/src/programs/unit_tests/ScaleTests.h index ffbda6a14..23e7cb49d 100644 --- a/src/programs/unit_tests/ScaleTests.h +++ b/src/programs/unit_tests/ScaleTests.h @@ -12,9 +12,14 @@ namespace scaletest { struct DummySource : public JEventSource { - void GetEvent(std::shared_ptr) override { + DummySource() { + SetCallbackStyle(CallbackStyle::ExpertMode); + } + + Result Emit(JEvent&) override { consume_cpu_ms(20); std::this_thread::sleep_for(std::chrono::nanoseconds(1)); + return Result::Success; } }; diff --git a/src/programs/unit_tests/SubeventTests.cc b/src/programs/unit_tests/SubeventTests.cc index c4b1608af..1d20470e4 100644 --- a/src/programs/unit_tests/SubeventTests.cc +++ b/src/programs/unit_tests/SubeventTests.cc @@ -144,15 +144,18 @@ TEST_CASE("Basic subevent arrow functionality") { } struct SimpleSource : public JEventSource { - void GetEvent(std::shared_ptr event) override { + SimpleSource() { + SetCallbackStyle(CallbackStyle::ExpertMode); + } + Result Emit(JEvent& event) override { + if (GetEventCount() == 10) return Result::FailureFinished; std::vector inputs; inputs.push_back(new MyInput(22,3.6)); inputs.push_back(new MyInput(23,3.5)); inputs.push_back(new MyInput(24,3.4)); inputs.push_back(new MyInput(25,3.3)); - event->Insert(inputs); - if (GetEventCount() == 10) - throw JEventSource::RETURN_STATUS::kNO_MORE_EVENTS; + event.Insert(inputs); + return Result::Success; } }; diff --git a/src/programs/unit_tests/TerminationTests.h b/src/programs/unit_tests/TerminationTests.h index 0ba1b7e06..bdfde313c 100644 --- a/src/programs/unit_tests/TerminationTests.h +++ b/src/programs/unit_tests/TerminationTests.h @@ -12,22 +12,30 @@ #include "catch.hpp" struct InterruptedSource : public JEventSource { + InterruptedSource() { + SetCallbackStyle(CallbackStyle::ExpertMode); + } void Open() override { GetApplication()->Stop(); } - void GetEvent(std::shared_ptr) override {} + Result Emit(JEvent&) override { return Result::Success; } }; struct BoundedSource : public JEventSource { uint64_t event_count = 0; + BoundedSource() { + SetCallbackStyle(CallbackStyle::ExpertMode); + } + void Open() override { } - void GetEvent(std::shared_ptr) override { + Result Emit(JEvent&) override { if (event_count >= 10) { - throw JEventSource::RETURN_STATUS::kNO_MORE_EVENTS; + return Result::FailureFinished; } event_count += 1; + return Result::Success; } }; @@ -35,14 +43,18 @@ struct UnboundedSource : public JEventSource { uint64_t event_count = 0; + UnboundedSource() { + SetCallbackStyle(CallbackStyle::ExpertMode); + } + void Open() override { } - void GetEvent(std::shared_ptr event) override { + Result Emit(JEvent& event) override { event_count += 1; - event->SetEventNumber(event_count); + event.SetEventNumber(event_count); std::this_thread::sleep_for(std::chrono::milliseconds(200)); - // jout << "Emitting " << event_count << jendl; + return Result::Success; } }; diff --git a/src/programs/unit_tests/TimeoutTests.h b/src/programs/unit_tests/TimeoutTests.h index 35690f55d..d1587f497 100644 --- a/src/programs/unit_tests/TimeoutTests.h +++ b/src/programs/unit_tests/TimeoutTests.h @@ -20,12 +20,14 @@ struct SourceWithTimeout : public JEventSource { : timeout_on_event_nr(timeout_on_event_nr) , first_event_delay_ms(first_delay_ms) - { } + { + SetCallbackStyle(CallbackStyle::ExpertMode); + } void Open() override { } - void GetEvent(std::shared_ptr) override { + Result Emit(JEvent&) override { event_count += 1; std::cout << "Processing event # " << event_count << std::endl; std::flush(std::cout); @@ -35,7 +37,7 @@ struct SourceWithTimeout : public JEventSource { } if (event_count == 100) { - throw RETURN_STATUS::kNO_MORE_EVENTS; + return Result::FailureFinished; } if (event_count == timeout_on_event_nr) { @@ -43,6 +45,7 @@ struct SourceWithTimeout : public JEventSource { std::this_thread::sleep_for(std::chrono::milliseconds(100)); }; // Endless loop } + return Result::Success; } }; diff --git a/src/programs/unit_tests/UserExceptionTests.h b/src/programs/unit_tests/UserExceptionTests.h index 558ffaa90..7fa6e5f26 100644 --- a/src/programs/unit_tests/UserExceptionTests.h +++ b/src/programs/unit_tests/UserExceptionTests.h @@ -17,7 +17,9 @@ struct FlakySource : public JEventSource { int event_count = 0; FlakySource(bool open_excepts, bool getevent_excepts) - : open_excepts(open_excepts), getevent_excepts(getevent_excepts) {} + : open_excepts(open_excepts), getevent_excepts(getevent_excepts) { + SetCallbackStyle(CallbackStyle::ExpertMode); + } void Open() override { if (open_excepts) { @@ -25,15 +27,16 @@ struct FlakySource : public JEventSource { } } - void GetEvent(std::shared_ptr) override { + Result Emit(JEvent&) override { if (++event_count > 10) { - throw JEventSource::RETURN_STATUS::kNO_MORE_EVENTS; + return Result::FailureFinished; } if (getevent_excepts) { throw JException("Unable to getEvent!"); } + return Result::Success; } };