Skip to content

Commit

Permalink
review feedback, minor refactoring, added a disabled test in simplectrl
Browse files Browse the repository at this point in the history
  • Loading branch information
mraduldubey committed Oct 1, 2024
1 parent bdb9776 commit b4f29a4
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 11 deletions.
4 changes: 2 additions & 2 deletions base/include/AbsControlModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ class AbsControlModule : public Module {
virtual void handleHealthCallback(const APHealthObject& healthObj);
/**
* @brief Register external function to be triggered on every health callBack that control modules recieves from the modules.
* In SimpleControlModule, this extention is called at the end of handleHealthCallback function.
* For eg. In SimpleControlModule, this extention is called at the end of handleHealthCallback function.
* @param function with signature void f(const APHealthObject*, unsigned short)
* @return nothing.
*/
void register_healthCallback_extention(
void registerHealthCallbackExtention(
boost::function<void(const APHealthObject*, unsigned short)> callbackFunction);
protected:
bool process(frame_container& frames);
Expand Down
2 changes: 1 addition & 1 deletion base/include/PipeLine.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class PipeLine {
void stop();
void term();
void wait_for_all(bool ignoreStatus = false);
void interrup_wait_for_all();
void interrupt_wait_for_all();
void flushAllQueues(bool flushControlModuleQ=false);
const char* getStatus();
};
Expand Down
1 change: 0 additions & 1 deletion base/include/SimpleControlModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class SimpleControlModule : public AbsControlModule
std::string printStatus();
void handleError(const APErrorObject &error) override;
void handleHealthCallback(const APHealthObject &healthObj) override;
// ErrorCallbacks
protected:
void sendEOS();
void sendEOS(frame_sp& frame);
Expand Down
6 changes: 3 additions & 3 deletions base/src/AbsControlModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ boost::shared_ptr<Module> AbsControlModule::getModuleofRole(std::string role)
return moduleWithRole;
}

void AbsControlModule::register_healthCallback_extention(
void AbsControlModule::registerHealthCallbackExtention(
boost::function<void(const APHealthObject*, unsigned short)> callbackFunction)
{
healthCallbackExtention = callbackFunction;
Expand Down Expand Up @@ -129,9 +129,9 @@ std::vector<std::string> AbsControlModule::serializeControlModule()
std::string cbStatus = "registered for...\n";
if (it.second.lock()->getProps().enableHealthCallBack)
{
cbStatus += spacedLineFmt + "<health callbacks> \n";
cbStatus += spacedLineFmt + "health callbacks \n";
}
cbStatus += spacedLineFmt + "<error callbacks>";
cbStatus += spacedLineFmt + "error callbacks \n";
status.push_back(spacedLineFmt + cbStatus);
}
return status;
Expand Down
3 changes: 1 addition & 2 deletions base/src/PipeLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ bool PipeLine::init()
{
myStatus = PL_INITFAILED;
return false;
return false;
}

LOG_TRACE << " Initializing pipeline";
Expand Down Expand Up @@ -270,7 +269,7 @@ void PipeLine::wait_for_all(bool ignoreStatus)
}


void PipeLine::interrup_wait_for_all()
void PipeLine::interrupt_wait_for_all()
{
if (myStatus > PL_STOPPING)
{
Expand Down
63 changes: 61 additions & 2 deletions base/test/simpleControlModuleTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ struct SimpleControlModuleTests

auto metadata = framemetadata_sp(new FrameMetadata(FrameMetadata::GENERAL));
sourceMod = boost::shared_ptr<TestModuleSrc>(new TestModuleSrc);
//auto source_pin_1 = sourceMod->addOutputPin(metadata);

/* set transform module health callbacks */
TestModuleTransformProps props;
Expand All @@ -168,6 +167,10 @@ struct SimpleControlModuleTests

sinkMod = boost::shared_ptr<TestSink>(new TestSink);

// pins connection
sourceMod->setNext(transformMod1);
transformMod1->setNext(sinkMod);

auto simpleCtrlProps = SimpleControlModuleProps();
simpleCtrl = boost::shared_ptr<SimpleControlModule>(new SimpleControlModule(simpleCtrlProps));

Expand Down Expand Up @@ -248,7 +251,7 @@ void TestCallackExtention(const APHealthObject* healthObj, unsigned int eventId)
BOOST_AUTO_TEST_CASE(simpleControlModule_healthCallback)
{
SimpleControlModuleTests t;
t.simpleCtrl->register_healthCallback_extention(TestCallackExtention);
t.simpleCtrl->registerHealthCallbackExtention(TestCallackExtention);

t.startPipeline();
t.addControlModule();
Expand All @@ -258,4 +261,60 @@ BOOST_AUTO_TEST_CASE(simpleControlModule_healthCallback)
boost::this_thread::sleep_for(boost::chrono::milliseconds(3000));
}

BOOST_AUTO_TEST_CASE(simpleControlModule_enroll_ctrlMod_step_test, *boost::unit_test::disabled())
{
SimpleControlModuleTests t;

t.simpleCtrl->registerHealthCallbackExtention(TestCallackExtention);
t.addControlModule();

t.sourceMod->init();
t.transformMod1->init();
t.sinkMod->init();
t.simpleCtrl->init();

t.sourceMod->step();
t.transformMod1->step();
t.sinkMod->step();

t.simpleCtrl->enrollModule("transform_test_module", t.transformMod1);
t.simpleCtrl->enrollModule("source_test_module", t.sourceMod);

// BOOSTASSERT the printStatus for enrollment
auto status = t.simpleCtrl->printStatus();
BOOST_ASSERT(status.find("transform_test_module") != std::string::npos);
BOOST_ASSERT(status.find("source_test_module") != std::string::npos);

// since we are queueing any command in control module, the step should remain blocked at mQue->pop inside step()
// the following code tests exactly that.
auto future = std::async(std::launch::async, &SimpleControlModule::step, t.simpleCtrl.get());
if (future.wait_for(std::chrono::seconds(2)) == std::future_status::ready)
{
try
{
bool result = future.get();
LOG_ERROR << "Simple control module step() unexpectedly returned a value <" << result << ">";
}
catch (const std::exception& e)
{
std::cout << "Task threw an exception: " << e.what() << std::endl;
}
BOOST_ASSERT(false);
}
BOOST_ASSERT(true);

t.sourceMod->stop();
t.transformMod1->stop();
t.sinkMod->stop();
t.simpleCtrl->stop();

t.sourceMod->term();
t.transformMod1->term();
t.sinkMod->term();
t.simpleCtrl->term();

LOG_INFO << "SUCCESS: do not wait for step() to finish..."; // future.get()
return;
}

BOOST_AUTO_TEST_SUITE_END()

0 comments on commit b4f29a4

Please sign in to comment.