summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xsrc/usr/diag/mdia/mdiamonitor.C48
-rwxr-xr-xsrc/usr/diag/mdia/mdiamonitor.H2
-rw-r--r--src/usr/diag/mdia/mdiasm.H3
-rw-r--r--src/usr/diag/mdia/test/mdiatestmonitor.H307
4 files changed, 254 insertions, 106 deletions
diff --git a/src/usr/diag/mdia/mdiamonitor.C b/src/usr/diag/mdia/mdiamonitor.C
index df763de04..72c7002e7 100755
--- a/src/usr/diag/mdia/mdiamonitor.C
+++ b/src/usr/diag/mdia/mdiamonitor.C
@@ -27,6 +27,7 @@
#include <diag/mdia/mdiamevent.H>
#include "mdiamonitor.H"
#include "mdiasm.H"
+#include "mdiatrace.H"
using namespace TARGETING;
@@ -73,45 +74,6 @@ void CommandMonitor::removeMonitor(uint64_t i_monitor)
mutex_unlock(&iv_mutex);
}
-tid_t CommandMonitor::getTID()
-{
- tid_t tid = 0;
-
- mutex_lock(&iv_mutex);
-
- tid = iv_tid;
-
- mutex_unlock(&iv_mutex);
-
- return tid;
-}
-
-bool CommandMonitor::isShutdown()
-{
- bool shutdown = false;
-
- mutex_lock(&iv_mutex);
-
- shutdown = iv_shutdown;
-
- mutex_unlock(&iv_mutex);
-
- return shutdown;
-}
-
-uint64_t CommandMonitor::getMonitorID()
-{
- uint64_t monitor = 0;
-
- mutex_lock(&iv_mutex);
-
- monitor = iv_nextMonitor;
-
- mutex_unlock(&iv_mutex);
-
- return monitor;
-}
-
uint64_t CommandMonitor::getMonitorMapTimeoutEntry(uint64_t i_monitor)
{
uint64_t timeout = 0;
@@ -173,7 +135,7 @@ void CommandMonitor::threadMain(StateMachine & i_sm)
// scan the monitor map and if any
// timed out, inform the state machine
- iterator it = iv_monitors.begin();
+ monitorMapIterator it = iv_monitors.begin();
while(it != iv_monitors.end())
{
@@ -192,7 +154,6 @@ void CommandMonitor::threadMain(StateMachine & i_sm)
iv_monitors.erase(it++);
}
}
-
#ifdef MDIA_DO_POLLING
swap(pollingList, iv_pollingList);
#endif
@@ -224,7 +185,10 @@ void CommandMonitor::threadMain(StateMachine & i_sm)
// istep finished...shutdown
if(shutdown)
+ {
+ MDIA_FAST("cm: CommandMonitor will be shutdown");
break;
+ }
}
}
@@ -239,6 +203,8 @@ struct ThreadArgs
void CommandMonitor::start(StateMachine & i_sm)
{
+ MDIA_FAST("cm: Start the CommandMonitor");
+
using namespace CommandMonitorImpl;
// start the monitor thread
diff --git a/src/usr/diag/mdia/mdiamonitor.H b/src/usr/diag/mdia/mdiamonitor.H
index 10dd35720..866829233 100755
--- a/src/usr/diag/mdia/mdiamonitor.H
+++ b/src/usr/diag/mdia/mdiamonitor.H
@@ -162,7 +162,7 @@ class CommandMonitor
* @brief aliases. Map containing monitorID key and timeout entries.
*/
typedef std::map<uint64_t, uint64_t> MonitorMap;
- typedef MonitorMap::iterator iterator;
+ typedef MonitorMap::iterator monitorMapIterator;
/**
* @brief maint command monitors
diff --git a/src/usr/diag/mdia/mdiasm.H b/src/usr/diag/mdia/mdiasm.H
index 44cc23b51..58668d7a3 100644
--- a/src/usr/diag/mdia/mdiasm.H
+++ b/src/usr/diag/mdia/mdiasm.H
@@ -49,7 +49,8 @@ class StateMachine
*
* @param[in] i_monitorIDs Vector of monitorIDs
*/
- virtual void processCommandTimeout(std::vector<uint64_t> i_monitorIDs) {}
+ virtual void processCommandTimeout(
+ const std::vector<uint64_t> & i_monitorIDs) {}
/**
* @brief run the state machine to completion
diff --git a/src/usr/diag/mdia/test/mdiatestmonitor.H b/src/usr/diag/mdia/test/mdiatestmonitor.H
index 504accf92..18050be89 100644
--- a/src/usr/diag/mdia/test/mdiatestmonitor.H
+++ b/src/usr/diag/mdia/test/mdiatestmonitor.H
@@ -31,175 +31,356 @@
#include "../mdiafwd.H"
#include "../mdiamonitor.H"
#include "../mdiasm.H"
-
+#include "../mdiatrace.H"
using namespace MDIA;
-class MdiaStateMachineTest: public StateMachine
+class FakeStateMachineTest: public StateMachine
{
public:
- void processCommandTimeout(std::vector<uint64_t>)
+ void processCommandTimeout(const std::vector<uint64_t> & i_monitorIDs)
{
+ if(true != isEqual(i_monitorIDs))
+ {
+ TS_FAIL("i_monitorIDs and iv_monitors vectors are not equal");
+ }
+
iv_processedTimeout = true;
}
- bool timeoutProcessed()
+ void addMonitor(uint64_t i_mon)
{
- return iv_processedTimeout;
+ iv_monitors.push_back(i_mon);
}
- MdiaStateMachineTest() : iv_processedTimeout(false) {}
+ void removeMonitor(const uint64_t i_position)
+ {
+ iv_monitors.erase(iv_monitors.begin() + i_position);
+ }
- ~MdiaStateMachineTest()
+ void clearMonitors()
+ {
+ iv_monitors.clear();
+ }
+
+ void resetTimeout()
{
iv_processedTimeout = false;
}
+ bool isTimeoutProcessed() const
+ {
+ return iv_processedTimeout;
+ }
+
+ FakeStateMachineTest() : iv_processedTimeout(false) {}
+
+ ~FakeStateMachineTest() {}
+
private:
+ bool isEqual(const std::vector<uint64_t> & i_monitorIDs) const
+ {
+ bool isEqual = true;
+ if(i_monitorIDs.size() == iv_monitors.size())
+ {
+ std::vector<uint64_t>::const_iterator mon = i_monitorIDs.begin();
+ std::vector<uint64_t>::const_iterator mon1 = iv_monitors.begin();
+ while(mon != i_monitorIDs.end())
+ {
+ if(*mon == *mon1)
+ {
+ mon++;
+ mon1++;
+ }
+ else
+ {
+ isEqual = false;
+ break;
+ }
+ }
+ }
+ else
+ isEqual = false;
+
+ return isEqual;
+ }
+
bool iv_processedTimeout;
+ std::vector<uint64_t> iv_monitors;
};
class MdiaCommandMonitorTest: public CxxTest::TestSuite
{
+ private:
+ void nanoSleep(uint64_t i_sleepSec, uint64_t i_sleepNanoSec) const
+ {
+ if( TARGETING::is_vpo() )
+ {
+ nanosleep(0, TEN_CTX_SWITCHES_NS);
+ }
+ else
+ {
+ nanosleep(i_sleepSec, i_sleepNanoSec);
+ }
+ }
+
public:
void testCommandMonitor(void)
{
+ TS_TRACE(ENTER_MRK "testCommandMonitor");
+
CommandMonitor l_cm;
do
{
- if( 0 != l_cm.getTID())
+ if(0 != l_cm.iv_tid)
{
TS_FAIL("Thread id != 0");
break;
}
- else if(true == l_cm.isShutdown())
+ else if(true == l_cm.iv_shutdown)
{
TS_FAIL("Var iv_shutdown != false");
break;
}
- else if(0 != l_cm.getMonitorID())
+ else if(0 != l_cm.iv_nextMonitor)
{
TS_FAIL("Monitor ID counter != 0");
break;
}
- else
- {
- TS_TRACE("SUCCESS:Dflt CommandMonitor ctor");
- }
}while(0);
+
+ TS_TRACE(EXIT_MRK "testCommandMonitor");
}
- void teststart(void)
+ void testaddMonitor(void)
{
- tid_t l_tid = 0;
- StateMachine l_sm;
- CommandMonitor* l_cm1 = new CommandMonitor();
- l_cm1->start(l_sm);
- l_tid = l_cm1->getTID();
- if(0 == l_cm1->getTID())
+ TS_TRACE(ENTER_MRK "testaddMonitor");
+
+ uint64_t l_timeout = 10;
+ CommandMonitor l_cm1;
+
+ //Add mutiple <monitor, timeout> entries
+ uint64_t l_mon = l_cm1.addMonitor(l_timeout);
+ if(1 != l_mon)
{
- TS_FAIL("Command Monitor task not started");
+ TS_FAIL("Key monitor ID not set corretly");
}
else
{
- l_cm1->start(l_sm);
- if(l_tid != l_cm1->getTID())
+ l_mon = l_cm1.addMonitor(++l_timeout);
+ if(l_timeout != l_cm1.getMonitorMapTimeoutEntry(l_mon))
{
- TS_FAIL("Command Monitor task started again");
+ TS_FAIL("Map entries not set right (1)");
}
- else
+
+ // Add monitor after starting the CM thread
+ FakeStateMachineTest l_sm;
+ l_cm1.start(l_sm);
+ l_cm1.addMonitor(++l_timeout);
+ l_mon = l_cm1.addMonitor(++l_timeout);
+ if(l_timeout != l_cm1.getMonitorMapTimeoutEntry(l_mon))
{
- TS_TRACE("SUCCESS: CommandMonitor::start");
+ TS_FAIL("Map entries not set right (2)");
}
}
- delete l_cm1;
- l_cm1 = NULL;
+ TS_TRACE(EXIT_MRK "testaddMonitor");
}
- void testaddMonitor(void)
+ void teststart(void)
{
- uint64_t l_timeout = 10;
+ TS_TRACE(ENTER_MRK "teststart");
+
+ tid_t l_tid = 0;
+ StateMachine l_sm;
CommandMonitor l_cm1;
- uint64_t l_mon = l_cm1.addMonitor(l_timeout);
- if(1 != l_mon)
+ //Check if CM thread was created.
+ l_cm1.start(l_sm);
+ l_tid = l_cm1.iv_tid;
+ if(0 == l_tid)
{
- TS_FAIL("Key monitor ID not set corretly");
+ TS_FAIL("Command Monitor task not started (1)");
}
else
{
- l_mon = l_cm1.addMonitor(++l_timeout);
+ //Once started should not start again.
+ l_cm1.start(l_sm);
+ if(l_tid != l_cm1.iv_tid)
+ {
+ TS_FAIL("Command Monitor task started again");
+ }
- if(l_timeout != l_cm1.getMonitorMapTimeoutEntry(l_mon))
+ //Call start after shutdown
+ l_cm1.shutdown();
+ if(0 != l_cm1.iv_tid)
{
- TS_FAIL("Map entries not set right");
+ TS_FAIL("CM not shutdown");
}
else
{
- TS_TRACE("SUCCESS: CommandMonitor::addMonitor");
+ l_cm1.start(l_sm);
+ if(0 == l_cm1.iv_tid)
+ {
+ TS_FAIL("CommandMonitor task not started (2)");
+ }
}
}
+
+ TS_TRACE(EXIT_MRK "teststart");
}
void testthreadMainTimeout(void)
{
- uint64_t timeoutNanosecs = 10000000;
- MdiaStateMachineTest l_sm;
+ TS_TRACE(ENTER_MRK "testthreadMainTimeout");
+
+ uint64_t l_mntCmdTime = 10000000;
+ FakeStateMachineTest l_sm;
CommandMonitor l_cm;
+
+ //Start the CM thread. Force a timeout.
+ //All monitorIDs should timeout.
+ uint64_t l_monID1, l_monID2 = 0;
l_cm.start(l_sm);
- l_cm.addMonitor(timeoutNanosecs);
- l_cm.addMonitor(timeoutNanosecs);
- if( TARGETING::is_vpo() )
+ l_monID1 = l_cm.addMonitor(l_mntCmdTime);
+ l_sm.addMonitor(l_monID1);
+ l_monID2 = l_cm.addMonitor(l_mntCmdTime);
+ l_sm.addMonitor(l_monID2);
+ nanoSleep(0, 100000000);
+ if(true != l_sm.isTimeoutProcessed())
{
- nanosleep(0, TEN_CTX_SWITCHES_NS);
+ TS_FAIL("Did not timeout");
}
- else
+ l_sm.clearMonitors();
+ l_sm.resetTimeout();
+
+ //All maint cmds/monitorIDs have timedout
+ //Therefore all timedout iv_monitors should be erased
+ if(l_cm.iv_monitors.size() != 0)
{
- //sleep for 100ms
- nanosleep(0, 100000000);
+ TS_FAIL("Size not zero");
}
- if(true != l_sm.timeoutProcessed())
+
+ //Add 7 more
+ //3 of the 7 monitorIDs should timeout.
+ uint64_t l_monID3, l_monID4, l_monID5, l_monID6, l_monID7 = 0;
+ l_monID1 = l_cm.addMonitor(l_mntCmdTime);
+ l_sm.addMonitor(l_monID1);
+ l_monID2 = l_cm.addMonitor(l_mntCmdTime);
+ l_sm.addMonitor(l_monID2);
+ l_monID3 = l_cm.addMonitor(l_mntCmdTime);
+ l_sm.addMonitor(l_monID3);
+ l_monID4 = l_cm.addMonitor(l_mntCmdTime);
+ l_sm.addMonitor(l_monID4);
+ l_monID5 = l_cm.addMonitor(l_mntCmdTime);
+ l_sm.addMonitor(l_monID5);
+ l_monID6 = l_cm.addMonitor(l_mntCmdTime);
+ l_sm.addMonitor(l_monID6);
+ l_monID7 = l_cm.addMonitor(l_mntCmdTime);
+ l_sm.addMonitor(l_monID7);
+
+ //Remove 4 of the 7 monIDs
+ l_cm.removeMonitor(l_monID1);
+ l_sm.removeMonitor(0);
+ nanoSleep(0, 100);
+ l_cm.removeMonitor(l_monID4);
+ l_sm.removeMonitor(2);
+ l_cm.removeMonitor(l_monID5);
+ l_sm.removeMonitor(2);
+ l_cm.removeMonitor(l_monID6);
+ l_sm.removeMonitor(2);
+
+ if(false != l_sm.isTimeoutProcessed())
{
- TS_FAIL("Not a timeout");
+ TS_FAIL("Unexpected timeout");
}
- else
+
+ nanoSleep(0, 100000000);
+ if(true != l_sm.isTimeoutProcessed())
{
- TS_TRACE("SUCCESS: testthreadMainTimeout");
+ TS_FAIL("Did not timeout");
}
+
+ TS_TRACE(EXIT_MRK "testthreadMainTimeout");
}
void testremoveMonitor(void)
{
- uint64_t l_timeout = 20;
+ TS_TRACE(ENTER_MRK "testremoveMonitor");
+
CommandMonitor l_cm1;
- l_cm1.addMonitor(l_timeout);
- l_cm1.addMonitor(++l_timeout);
- l_cm1.removeMonitor(2);
- if(0 != l_cm1.getMonitorMapTimeoutEntry(2))
+ uint64_t l_monID = 0;
+ //Removing from empty list
+ l_cm1.removeMonitor(l_monID);
+
+ //Populate monitor. Remove last entry
+ uint64_t l_timeout = 20;
+ l_monID = l_cm1.addMonitor(l_timeout);
+ l_monID = l_cm1.addMonitor(++l_timeout);
+ l_monID = l_cm1.addMonitor(++l_timeout);
+ l_cm1.removeMonitor(l_monID);
+ //Check if removed
+ if(0 != l_cm1.getMonitorMapTimeoutEntry(l_monID))
{
- TS_FAIL("Map entry not removed");
+ TS_FAIL("Last Map entry not removed");
}
- else
+
+ //Remove first entry
+ l_monID = 1;
+ l_cm1.removeMonitor(l_monID);
+ if(0 != l_cm1.getMonitorMapTimeoutEntry(l_monID))
+ {
+ TS_FAIL("First Map entry not removed");
+ }
+
+ l_cm1.addMonitor(l_timeout);
+ l_cm1.addMonitor(l_timeout);
+ l_cm1.addMonitor(l_timeout);
+ l_cm1.addMonitor(l_timeout);
+ l_cm1.addMonitor(l_timeout);
+ //Remove 2nd and 3rd entry
+ l_cm1.removeMonitor(2);
+ l_cm1.removeMonitor(4);
+ //Verify removal
+ if(0 != l_cm1.getMonitorMapTimeoutEntry(2) &&
+ 0 != l_cm1.getMonitorMapTimeoutEntry(4) )
{
- TS_TRACE("SUCCESS: CommandMonitor::removeMonitor");
+ TS_FAIL("Entries in middle not removed");
}
+
+ TS_TRACE(EXIT_MRK "testremoveMonitor");
}
void testshutdown(void)
{
+ TS_TRACE(ENTER_MRK "testshutdown");
+
StateMachine l_sm;
CommandMonitor l_cm;
+
+ //Shutdown without starting CM
+ l_cm.shutdown();
+ if(false == l_cm.iv_shutdown && (0 != l_cm.iv_tid))
+ {
+ TS_FAIL("Command Monitor not shutdown (1)");
+ }
+
+ //Start CM, then shutdown
l_cm.start(l_sm);
l_cm.shutdown();
- if(false == l_cm.isShutdown() && (0 != l_cm.getTID()))
+ if(false == l_cm.iv_shutdown && (0 != l_cm.iv_tid))
{
- TS_FAIL("Command Monitor not shutdown");
+ TS_FAIL("Command Monitor not shutdown (2)");
}
- else
+
+ //Shutdown again
+ l_cm.shutdown();
+ if(false == l_cm.iv_shutdown && (0 != l_cm.iv_tid))
{
- TS_TRACE("SUCCESS: CommandMonitor::shutdown");
+ TS_FAIL("Command Monitor not shutdown (3");
}
+
+ TS_TRACE(EXIT_MRK "testshutdown");
}
};
OpenPOWER on IntegriCloud