From 03168c396e3c8642ac1bec874b20b59f733f7d74 Mon Sep 17 00:00:00 2001 From: Alan Greer Date: Fri, 20 Sep 2024 16:26:04 +0100 Subject: [PATCH] Implemented a command in DummyUDPProcessPlugin and tests to verify the 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 Added clarification comments. Simplified boost test calls. Updated to use string commands with no parameters. Removed unused test code. Removed unused execution parameter constant. --- .../include/DummyUDPProcessPlugin.h | 5 ++ .../src/DummyUDPProcessPlugin.cpp | 39 +++++++++++++++ cpp/frameProcessor/test/CMakeLists.txt | 2 + .../test/DummyUDPProcessPluginTest.cpp | 47 +++++++++++++++++++ 4 files changed, 93 insertions(+) create mode 100644 cpp/frameProcessor/test/DummyUDPProcessPluginTest.cpp diff --git a/cpp/frameProcessor/include/DummyUDPProcessPlugin.h b/cpp/frameProcessor/include/DummyUDPProcessPlugin.h index 522681327..514e000b5 100644 --- a/cpp/frameProcessor/include/DummyUDPProcessPlugin.h +++ b/cpp/frameProcessor/include/DummyUDPProcessPlugin.h @@ -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 requestCommands(); void status(OdinData::IpcMessage& status); bool reset_statistics(void); @@ -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); void process_lost_packets(boost::shared_ptr& frame); diff --git a/cpp/frameProcessor/src/DummyUDPProcessPlugin.cpp b/cpp/frameProcessor/src/DummyUDPProcessPlugin.cpp index 69826a08c..c14b1db2c 100644 --- a/cpp/frameProcessor/src/DummyUDPProcessPlugin.cpp +++ b/cpp/frameProcessor/src/DummyUDPProcessPlugin.cpp @@ -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. @@ -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 DummyUDPProcessPlugin::requestCommands() + { + // Reply with a vector of supported command strings. + std::vector cmds = {DummyUDPProcessPlugin::EXECUTE_PRINT}; + return cmds; + } + /** * Collate status information for the plugin. The status is added to the status IpcMessage object. * diff --git a/cpp/frameProcessor/test/CMakeLists.txt b/cpp/frameProcessor/test/CMakeLists.txt index 704a3acfc..5c7c490e4 100644 --- a/cpp/frameProcessor/test/CMakeLists.txt +++ b/cpp/frameProcessor/test/CMakeLists.txt @@ -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}) @@ -39,6 +40,7 @@ target_link_libraries(frameProcessorTest LiveViewPlugin SumPlugin GapFillPlugin + DummyUDPProcessPlugin ${COMMON_LIBRARY}) # Link for BloscPlugin if Blosc is present diff --git a/cpp/frameProcessor/test/DummyUDPProcessPluginTest.cpp b/cpp/frameProcessor/test/DummyUDPProcessPluginTest.cpp new file mode 100644 index 000000000..b26cf15a2 --- /dev/null +++ b/cpp/frameProcessor/test/DummyUDPProcessPluginTest.cpp @@ -0,0 +1,47 @@ +/* + * DummyUDPProcessPluginTest.cpp + * + * Created on: 25 Sep 2024 + * Author: Alan Greer + */ + +#include +#include +#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 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