From 9e3882819ce9d1fcc99a3ea3efa549e87efa7e7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Boisnard?= Date: Fri, 10 Jan 2014 18:43:04 +0100 Subject: Add Exit command to test-platform MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BZ: 151780 The only way to exit test-platform is to kill it. However during the build process, the hostDomainGenerator.sh script needs to start and exit test-platform, without knowing its PID. Allow exiting the test-plaform though a new 'exit' command. Change-Id: Ifb94ea1c2017a0b23e25b42a06e2ceeae69ace89 Signed-off-by: Frédéric Boisnard --- test/test-platform/TestPlatform.cpp | 21 +++++++++++++++++++-- test/test-platform/TestPlatform.h | 16 ++++++++++++++-- test/test-platform/main.cpp | 13 ++++++++----- 3 files changed, 41 insertions(+), 9 deletions(-) (limited to 'test') diff --git a/test/test-platform/TestPlatform.cpp b/test/test-platform/TestPlatform.cpp index 2ff704b..b69a10e 100644 --- a/test/test-platform/TestPlatform.cpp +++ b/test/test-platform/TestPlatform.cpp @@ -50,13 +50,16 @@ public: } }; -CTestPlatform::CTestPlatform(const string& strClass, int iPortNumber) : +CTestPlatform::CTestPlatform(const string& strClass, int iPortNumber, sem_t& exitSemaphore) : _pParameterMgrPlatformConnector(new CParameterMgrPlatformConnector(strClass)), - _pParameterMgrPlatformConnectorLogger(new CParameterMgrPlatformConnectorLogger) + _pParameterMgrPlatformConnectorLogger(new CParameterMgrPlatformConnectorLogger), + _exitSemaphore(exitSemaphore) { _pCommandHandler = new CCommandHandler(this); // Add command parsers + _pCommandHandler->addCommandParser("exit", &CTestPlatform::exit, + 0, "", "Exit TestPlatform"); _pCommandHandler->addCommandParser( "createExclusiveSelectionCriterionFromStateList", &CTestPlatform::createExclusiveSelectionCriterionFromStateList, @@ -124,6 +127,20 @@ CTestPlatform::~CTestPlatform() delete _pParameterMgrPlatformConnector; } +CTestPlatform::CommandReturn CTestPlatform::exit( + const IRemoteCommand& remoteCommand, string& strResult) +{ + (void)remoteCommand; + + // Stop local server + _pRemoteProcessorServer->stop(); + + // Release the main blocking semaphore to quit application + sem_post(&_exitSemaphore); + + return CTestPlatform::CCommandHandler::EDone; +} + bool CTestPlatform::load(std::string& strError) { // Start remote processor server diff --git a/test/test-platform/TestPlatform.h b/test/test-platform/TestPlatform.h index e8b9823..8673e9d 100644 --- a/test/test-platform/TestPlatform.h +++ b/test/test-platform/TestPlatform.h @@ -28,6 +28,7 @@ #include "RemoteCommandHandlerTemplate.h" #include #include +#include using namespace std; @@ -40,7 +41,7 @@ class CTestPlatform typedef TRemoteCommandHandlerTemplate CCommandHandler; typedef CCommandHandler::CommandStatus CommandReturn; public: - CTestPlatform(const string &strclass, int iPortNumber); + CTestPlatform(const string &strclass, int iPortNumber, sem_t& exitSemaphore); virtual ~CTestPlatform(); // Init @@ -89,6 +90,14 @@ private: CommandReturn applyConfigurations( const IRemoteCommand& remoteCommand, string& strResult); + /** Callback to exit the test-platform. + * + * @param[in] remoteCommand is ignored + * + * @return EDone (never fails) + */ + CommandReturn exit(const IRemoteCommand& remoteCommand, string& strResult); + /** The type of a CParameterMgrPlatformConnector boolean setter. */ typedef bool (CParameterMgrPlatformConnector::*setter_t)(bool, string&); /** Template callback to create a _pParameterMgrPlatformConnector boolean setter callback. @@ -112,7 +121,7 @@ private: * Convert to boolean returned by the template parameter function converted to a * string ("True", "False") and return it. * - * @tparam the boolean getter method. + * @param the boolean getter method. * @param[in] remoteCommand is ignored * * @return EDone (never fails) @@ -140,5 +149,8 @@ private: // Remote Processor Server CRemoteProcessorServer* _pRemoteProcessorServer; + + // Semaphore used by calling thread to avoid exiting + sem_t& _exitSemaphore; }; diff --git a/test/test-platform/main.cpp b/test/test-platform/main.cpp index 953d649..d97a449 100644 --- a/test/test-platform/main.cpp +++ b/test/test-platform/main.cpp @@ -44,24 +44,27 @@ int main(int argc, char *argv[]) string strError; + // Init semaphore + sem_t sem; + + sem_init(&sem, false, 0); + // Create param mgr - CTestPlatform testPlatform(argv[1], argc > 2 ? atoi(argv[2]) : iDefaultPortNumber); + CTestPlatform testPlatform(argv[1], argc > 2 ? atoi(argv[2]) : iDefaultPortNumber, sem); // Start platformmgr if (!testPlatform.load(strError)) { cerr << strError << endl; + sem_destroy(&sem); + return -1; } // Change criteria // Block here - sem_t sem; - - sem_init(&sem, false, 0); - sem_wait(&sem); sem_destroy(&sem); -- cgit v1.1