Skip to content

Commit

Permalink
Implemented a command in DummyUDPProcessPlugin and tests to verify th…
Browse files Browse the repository at this point in the history
…e functionality.

Fixed runtime error in Dummy plugin and throw an exception if the supported
command is not requested when execution is called.

Added tests that use the Dummy plugin to test execute and requestCommands methods.

Update cpp/frameProcessor/test/DummyUDPProcessPluginTest.cpp

Co-authored-by: Gary Yendell <gary.yendell@diamond.ac.uk>

Added clarification comments.  Simplified boost test calls.

Updated to use string commands with no parameters.

Removed unused test code.

Removed unused execution parameter constant.
  • Loading branch information
ajgdls committed Oct 9, 2024
1 parent 86c25d1 commit 03168c3
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cpp/frameProcessor/include/DummyUDPProcessPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class DummyUDPProcessPlugin : public FrameProcessorPlugin

void configure(OdinData::IpcMessage& config, OdinData::IpcMessage& reply);
void requestConfiguration(OdinData::IpcMessage& reply);
void execute(const std::string& command, OdinData::IpcMessage& reply);
std::vector<std::string> requestCommands();
void status(OdinData::IpcMessage& status);
bool reset_statistics(void);

Expand All @@ -54,6 +56,9 @@ class DummyUDPProcessPlugin : public FrameProcessorPlugin
/** Configuraiton constant for copy frame mode **/
static const std::string CONFIG_COPY_FRAME;

/** Command execution constant for print command **/
static const std::string EXECUTE_PRINT;

void process_frame(boost::shared_ptr<Frame> frame);
void process_lost_packets(boost::shared_ptr<Frame>& frame);

Expand Down
39 changes: 39 additions & 0 deletions cpp/frameProcessor/src/DummyUDPProcessPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ namespace FrameProcessor
const std::string DummyUDPProcessPlugin::CONFIG_IMAGE_WIDTH = "width";
const std::string DummyUDPProcessPlugin::CONFIG_IMAGE_HEIGHT = "height";
const std::string DummyUDPProcessPlugin::CONFIG_COPY_FRAME = "copy_frame";
// Command and parameters
const std::string DummyUDPProcessPlugin::EXECUTE_PRINT = "print";

/**
* The constructor sets up default configuration parameters and logging used within the class.
Expand Down Expand Up @@ -135,6 +137,43 @@ namespace FrameProcessor
reply.set_param(base_str + DummyUDPProcessPlugin::CONFIG_COPY_FRAME, copy_frame_);
}

/**
* Execute a command on the plugin. This receives an IpcMessage which should be processed
* to execute a command within the plugin, and any response can be added to the reply IpcMessage.
* The dummy plugin implements a single command "print" that prints the value of the parameter named.
*
* \param[in] config - String containing the command to execute.
* \param[out] reply - Reference to the reply IpcMessage object.
*/
void DummyUDPProcessPlugin::execute(const std::string& command, OdinData::IpcMessage& reply)
{
if (command == DummyUDPProcessPlugin::EXECUTE_PRINT){
LOG4CXX_INFO(logger_, "Image width is " << image_width_);
LOG4CXX_INFO(logger_, "Image height is " << image_height_);
LOG4CXX_INFO(logger_, "Copy frame is " << copy_frame_);
} else {
std::stringstream is;
is << "Submitted command not supported: " << command;
LOG4CXX_ERROR(logger_, is.str());
throw std::runtime_error(is.str().c_str());
}
}

/**
* Respond to command execution requests from clients.
*
* This method responds to command executions requests from client, populating the supplied IpcMessage
* reply with the commands and command parameters supported by this plugin.
*
* \return - Vector containing supported command strings.
*/
std::vector<std::string> DummyUDPProcessPlugin::requestCommands()
{
// Reply with a vector of supported command strings.
std::vector<std::string> cmds = {DummyUDPProcessPlugin::EXECUTE_PRINT};
return cmds;
}

/**
* Collate status information for the plugin. The status is added to the status IpcMessage object.
*
Expand Down
2 changes: 2 additions & 0 deletions cpp/frameProcessor/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ file(GLOB TEST_SOURCES
FrameProcessorTest.cpp
GapFillPluginTest.cpp
MetaMessageTest.cpp
DummyUDPProcessPluginTest.cpp
)
# Add tests for BloscPlugin if Blosc is present
if (${BLOSC_FOUND})
Expand Down Expand Up @@ -39,6 +40,7 @@ target_link_libraries(frameProcessorTest
LiveViewPlugin
SumPlugin
GapFillPlugin
DummyUDPProcessPlugin
${COMMON_LIBRARY})

# Link for BloscPlugin if Blosc is present
Expand Down
47 changes: 47 additions & 0 deletions cpp/frameProcessor/test/DummyUDPProcessPluginTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* DummyUDPProcessPluginTest.cpp
*
* Created on: 25 Sep 2024
* Author: Alan Greer
*/

#include <boost/test/unit_test.hpp>
#include <DebugLevelLogger.h>
#include "FrameProcessorDefinitions.h"
#include "DummyUDPProcessPlugin.h"
#include "IpcMessage.h"

class DummyUDPProcessPluginTestFixture {
public:
DummyUDPProcessPluginTestFixture() {
set_debug_level(3);

dummy_plugin.set_name("dummy");
}

~DummyUDPProcessPluginTestFixture() {}

FrameProcessor::DummyUDPProcessPlugin dummy_plugin;
};

BOOST_FIXTURE_TEST_SUITE(DummyUDPProcessPluginUnitTest, DummyUDPProcessPluginTestFixture);

BOOST_AUTO_TEST_CASE( DummyUDPProcessPlugin_commands )
{
std::vector<std::string> commands_reply;
OdinData::IpcMessage command_reply;

// Request the command set of the DummyUDPProcessPlugin
BOOST_REQUIRE_NO_THROW(commands_reply = dummy_plugin.requestCommands());

// Verify the returned command set is as expected
BOOST_CHECK_EQUAL(commands_reply[0], std::string("print"));

// Verify that an incorrect commmand request is rejected
BOOST_CHECK_THROW(dummy_plugin.execute("bad_command", command_reply), std::runtime_error);

// Verify that a supported commmand request is accepted
BOOST_REQUIRE_NO_THROW(dummy_plugin.execute("print", command_reply));
};

BOOST_AUTO_TEST_SUITE_END(); //DummyUDPProcessPluginUnitTest

0 comments on commit 03168c3

Please sign in to comment.