summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLarina DSouza <larsouza@in.ibm.com>2012-07-12 10:52:06 +0530
committerA. Patrick Williams III <iawillia@us.ibm.com>2012-08-29 12:02:18 -0500
commit988dacf944579556cca7f8aafbb4b7fda8b17176 (patch)
tree867b724a2a25c2e56285fbd4014478b233bf8437
parent0e232093804bb6f062557dc76f3c89e220867a57 (diff)
downloadtalos-hostboot-988dacf944579556cca7f8aafbb4b7fda8b17176.tar.gz
talos-hostboot-988dacf944579556cca7f8aafbb4b7fda8b17176.zip
MDIA: Fix timing issue in unit test case. Issue 44509
Change-Id: Ibf7a761214027f180771901bcfd9b7d164eae427 Reviewed-on: http://gfw160.austin.ibm.com:8080/gerrit/1341 Tested-by: Jenkins Server Reviewed-by: Bradley W. Bishop <bradleyb@us.ibm.com> Reviewed-by: A. Patrick Williams III <iawillia@us.ibm.com>
-rw-r--r--src/usr/diag/mdia/test/makefile6
-rw-r--r--src/usr/diag/mdia/test/mdiafakesm.C152
-rw-r--r--src/usr/diag/mdia/test/mdiafakesm.H159
-rw-r--r--src/usr/diag/mdia/test/mdiatestmonitor.H245
4 files changed, 434 insertions, 128 deletions
diff --git a/src/usr/diag/mdia/test/makefile b/src/usr/diag/mdia/test/makefile
index 75b6f0a64..237b41868 100644
--- a/src/usr/diag/mdia/test/makefile
+++ b/src/usr/diag/mdia/test/makefile
@@ -1,4 +1,4 @@
-# IBM_PROLOG_BEGIN_TAG
+# IBM_PROLOG_BEGIN_TAG
# This is an automatically generated prolog.
#
# $Source: src/usr/diag/mdia/test/makefile $
@@ -19,11 +19,13 @@
#
# Origin: 30
#
-# IBM_PROLOG_END
+# IBM_PROLOG_END_TAG
ROOTPATH = ../../../../..
EXTRAINCDIR += ${ROOTPATH}/src/include/usr/diag
+OBJS = mdiafakesm.o
+
MODULE = testmdia
TESTS = *.H
diff --git a/src/usr/diag/mdia/test/mdiafakesm.C b/src/usr/diag/mdia/test/mdiafakesm.C
new file mode 100644
index 000000000..b53fecced
--- /dev/null
+++ b/src/usr/diag/mdia/test/mdiafakesm.C
@@ -0,0 +1,152 @@
+/* IBM_PROLOG_BEGIN_TAG
+ * This is an automatically generated prolog.
+ *
+ * $Source: src/usr/diag/mdia/test/mdiafakesm.C $
+ *
+ * IBM CONFIDENTIAL
+ *
+ * COPYRIGHT International Business Machines Corp. 2012
+ *
+ * p1
+ *
+ * Object Code Only (OCO) source materials
+ * Licensed Internal Code Source Materials
+ * IBM HostBoot Licensed Internal Code
+ *
+ * The source code for this program is not published or other-
+ * wise divested of its trade secrets, irrespective of what has
+ * been deposited with the U.S. Copyright Office.
+ *
+ * Origin: 30
+ *
+ * IBM_PROLOG_END_TAG
+ */
+#include "mdiafakesm.H"
+#include "../mdiatrace.H"
+
+namespace MDIA
+{
+
+void FakeStateMachine1::processCommandTimeout(
+ const std::vector<uint64_t> & i_monitorIDs)
+{
+ //Holds a collection of i_monitorIDs that timedout
+ static std::vector<uint64_t> monitorIDs;
+ std::vector<uint64_t>::const_iterator monIter;
+
+ for(monIter = i_monitorIDs.begin();
+ monIter != i_monitorIDs.end();
+ monIter++)
+ {
+ monitorIDs.push_back(*monIter);
+ }
+
+ //Only process Timeout if CommandMonitor has detected
+ //expected number(iv_totalExpectedMons)of monitorIDs to timeout
+ if(monitorIDs.size() == iv_totalExpectedMons)
+ {
+ if(true != isEqual(monitorIDs))
+ {
+ MDIA_FAST("Contents of iv_processedMonitors of size %d is not euqal"
+ "to content of iv_expectedMonitors of size %d",
+ monitorIDs.size(), iv_expectedMonitors.size());
+ for(monIter = monitorIDs.begin();
+ monIter != monitorIDs.end();
+ monIter++)
+ {
+ MDIA_FAST("monitorIDs: %d", *monIter);
+ }
+
+ for(monIter = iv_expectedMonitors.begin();
+ monIter != iv_expectedMonitors.end();
+ monIter++)
+ {
+ MDIA_FAST("iv_expectedMonitors: %d", *monIter);
+ }
+ }
+ else
+ iv_contentsEqual = true;
+ }
+
+ //Expected number of monitorIDs have timedout.
+ //Clear the vector before the next list timesout
+ monitorIDs.clear();
+
+ //Processed expected number of timeouts.
+ //Ready to continue testing
+ mutex_lock(iv_mutex);
+ iv_processedTimeout = true;
+ sync_cond_signal(iv_cond);
+ mutex_unlock(iv_mutex);
+
+}
+
+void FakeStateMachine1::addMonitor(uint64_t i_mon)
+{
+ iv_expectedMonitors.push_back(i_mon);
+}
+
+void FakeStateMachine1::removeMonitor(const uint64_t i_position)
+{
+ iv_expectedMonitors.erase(iv_expectedMonitors.begin() + i_position);
+}
+
+bool FakeStateMachine1::isTimeoutProcessed() const
+{
+ return iv_processedTimeout;
+}
+
+bool FakeStateMachine1::isContentsEqual() const
+{
+ return iv_contentsEqual;
+}
+
+void FakeStateMachine1::setTotalExpectedMons(const uint64_t i_count)
+{
+ iv_totalExpectedMons = i_count;
+}
+
+void FakeStateMachine1::setSyncVars(mutex_t *i_mutex, sync_cond_t *i_cond)
+{
+ iv_mutex = i_mutex;
+ iv_cond = i_cond;
+}
+
+FakeStateMachine1::FakeStateMachine1() : iv_processedTimeout(false),
+ iv_contentsEqual(false),
+ iv_totalExpectedMons(0)
+{}
+
+bool FakeStateMachine1::isEqual(
+ const std::vector<uint64_t> & i_monitorIDs) const
+{
+
+ bool isEqual = true;
+ if(i_monitorIDs.size() == iv_expectedMonitors.size())
+ {
+ std::vector<uint64_t>::const_iterator iterProc =
+ i_monitorIDs.begin();
+ std::vector<uint64_t>::const_iterator iterExpect =
+ iv_expectedMonitors.begin();
+ while(iterProc != i_monitorIDs.end())
+ {
+ if(*iterProc == *iterExpect)
+ {
+ iterProc++;
+ iterExpect++;
+ }
+ else
+ {
+ isEqual = false;
+ break;
+ }
+ }
+ }
+ else
+ {
+ isEqual = false;
+ }
+
+ return isEqual;
+}
+}
diff --git a/src/usr/diag/mdia/test/mdiafakesm.H b/src/usr/diag/mdia/test/mdiafakesm.H
new file mode 100644
index 000000000..61947736a
--- /dev/null
+++ b/src/usr/diag/mdia/test/mdiafakesm.H
@@ -0,0 +1,159 @@
+/* IBM_PROLOG_BEGIN_TAG
+ * This is an automatically generated prolog.
+ *
+ * $Source: src/usr/diag/mdia/test/mdiafakesm.H $
+ *
+ * IBM CONFIDENTIAL
+ *
+ * COPYRIGHT International Business Machines Corp. 2012
+ *
+ * p1
+ *
+ * Object Code Only (OCO) source materials
+ * Licensed Internal Code Source Materials
+ * IBM HostBoot Licensed Internal Code
+ *
+ * The source code for this program is not published or other-
+ * wise divested of its trade secrets, irrespective of what has
+ * been deposited with the U.S. Copyright Office.
+ *
+ * Origin: 30
+ *
+ * IBM_PROLOG_END_TAG
+ */
+#ifndef __TEST_MDIAFAKESM_H
+#define __TEST_MDIAFAKESM_H
+
+#include "../mdiasm.H"
+
+namespace MDIA
+{
+/**
+ * @brief FakeStateMachine1
+ *
+ * Used to test processing a maint command timeout
+ * from the CommandMonitor perspective
+ */
+class FakeStateMachine1 : public StateMachine
+{
+ public:
+ /**
+ * @brief processCommandTimeout
+ *
+ * Verifies if the vector of monitorIDs(i_monitorIDs) passed in
+ * is the expected vector of timed out monitorIDs(iv_monitors)
+ *
+ * @param[in] i_monitorIDs Vector of monitorIDs that have timed out
+ */
+ void processCommandTimeout(const std::vector<uint64_t> & i_monitorIDs);
+
+ /**
+ * @brief addMonitor
+ *
+ * Add a monitor to the vector of iv_monitors
+ *
+ * @param[in] i_mon Monitor ID of target
+ */
+ void addMonitor(uint64_t i_mon);
+
+ /**
+ * @brief removeMonitor
+ *
+ * Removes the monitor at position 'i_position' from iv_monitors
+ *
+ * @param[in] i_position Position of monitor ID in vector iv_monitors
+ */
+ void removeMonitor(const uint64_t i_position);
+
+ /**
+ * @brief isTimeoutProcessed
+ *
+ * Is the timeout processed
+ *
+ * @retval true if processed
+ * false is not processed
+ */
+ bool isTimeoutProcessed() const;
+
+ /**
+ * @brief isContentsEqual
+ *
+ * Are the contents of vector of monitorIDs sent from
+ * CommandMonitor equal to the expected value
+ *
+ * @retval true if equal
+ * false if not equal
+ */
+ bool isContentsEqual() const;
+
+ /**
+ * @brief setTotalExpectedMons
+ *
+ * Sets the expected number of monitor IDs that timeout
+ *
+ * @param[in] i_count Total number of expected timeouts
+ */
+ void setTotalExpectedMons(const uint64_t i_count);
+
+ /**
+ * @brief setSyncVars
+ *
+ * Sets the sync variables to be in-sync with the unit test
+ *
+ * @param[in] i_mutex Serialization Mutex
+ * @param[in] i_cond Synchronization condition
+ */
+ void setSyncVars(mutex_t *i_mutex, sync_cond_t *i_cond);
+
+ /**
+ * @brief ctor
+ */
+ FakeStateMachine1();
+
+ /**
+ * @brief dtor
+ */
+ ~FakeStateMachine1(){}
+
+ private:
+ /**
+ * @brief isEqual
+ *
+ * Compares two sets of vectors of monitorIDs
+ *
+ * @param[in] i_monitorIDs Vector of monitorIDs
+ */
+ bool isEqual(const std::vector<uint64_t> & i_monitorIDs) const;
+
+ /**
+ * @brief Processed timeout indicator
+ */
+ bool iv_processedTimeout;
+
+ /**
+ * @brief Contents of expected and real timeouts equality indicator
+ */
+ bool iv_contentsEqual;
+
+ /**
+ * @brief Vector of expected monitor IDs to timeout
+ */
+ std::vector<uint64_t> iv_expectedMonitors;
+
+ /**
+ * @brief Expected number to monitor IDs to timeout
+ */
+ uint64_t iv_totalExpectedMons;
+
+ /**
+ * @brief Processed timeout condition
+ */
+ sync_cond_t *iv_cond;
+
+ /**
+ * @brief serialization mutex
+ */
+ mutex_t *iv_mutex;
+};
+}
+#endif
diff --git a/src/usr/diag/mdia/test/mdiatestmonitor.H b/src/usr/diag/mdia/test/mdiatestmonitor.H
index 8f5547d0c..2c91fe586 100644
--- a/src/usr/diag/mdia/test/mdiatestmonitor.H
+++ b/src/usr/diag/mdia/test/mdiatestmonitor.H
@@ -33,97 +33,140 @@
#include "../mdiamonitor.H"
#include "../mdiasm.H"
#include "../mdiatrace.H"
+#include "mdiafakesm.H"
+
using namespace MDIA;
-class FakeStateMachineTest: public StateMachine
+class MdiaCommandMonitorTest: public CxxTest::TestSuite
{
- public:
- void processCommandTimeout(const std::vector<uint64_t> & i_monitorIDs)
+ private:
+ void nanoSleep(uint64_t i_sleepSec, uint64_t i_sleepNanoSec) const
{
- if(true != isEqual(i_monitorIDs))
+ if( TARGETING::is_vpo() )
{
- //TODO: This is commented out due to Issue 44509.
- //TS_FAIL("i_monitorIDs and iv_monitors vectors are not equal");
+ nanosleep(0, TEN_CTX_SWITCHES_NS);
+ }
+ else
+ {
+ nanosleep(i_sleepSec, i_sleepNanoSec);
}
-
- iv_processedTimeout = true;
}
- void addMonitor(uint64_t i_mon)
+ void TimeoutAll(mutex_t *i_mutex, sync_cond_t *i_cond)
{
- iv_monitors.push_back(i_mon);
- }
+ TS_TRACE(ENTER_MRK "TimeoutAll");
- void removeMonitor(const uint64_t i_position)
- {
- iv_monitors.erase(iv_monitors.begin() + i_position);
- }
+ uint64_t l_mntCmdTime = 10000000;
+ FakeStateMachine1 l_sm;
+ CommandMonitor l_cm;
- void clearMonitors()
- {
- iv_monitors.clear();
- }
+ //Start the CM thread. Force a timeout.
+ //All monitorIDs should timeout.
+ uint64_t l_monID1 = 0, l_monID2 = 0;
+ l_cm.start(l_sm);
+ l_monID1 = l_cm.addMonitor(l_mntCmdTime);
+ l_sm.addMonitor(l_monID1);
+ l_monID2 = l_cm.addMonitor(l_mntCmdTime);
+ l_sm.addMonitor(l_monID2);
- void resetTimeout()
- {
- iv_processedTimeout = false;
+ //2 monitorIDs should timeout
+ l_sm.setTotalExpectedMons(2);
+ l_sm.setSyncVars(i_mutex, i_cond);
+
+ mutex_lock(i_mutex);
+ // Wait until all monitorIDs timeout
+ while(false == l_sm.isTimeoutProcessed())
+ {
+ sync_cond_wait(i_cond, i_mutex);
+ }
+ mutex_unlock(i_mutex);
+
+ if(true != l_sm.isContentsEqual())
+ {
+ TS_FAIL("Expected monitorIDs to timeout are not equal "
+ "to actual timedout monitorIDs");
+ }
+
+ //All maint cmds/monitorIDs have timedout
+ //Therefore all timedout iv_monitors should be erased
+ if(l_cm.iv_monitors.size() != 0)
+ {
+ TS_FAIL("Size not zero");
+ }
+
+ TS_TRACE(EXIT_MRK "TimeoutAll");
}
- bool isTimeoutProcessed() const
+ void TimeoutSubset(mutex_t *i_mutex, sync_cond_t *i_cond)
{
- return iv_processedTimeout;
- }
+ TS_TRACE(ENTER_MRK "TimeoutSubset");
- FakeStateMachineTest() : iv_processedTimeout(false) {}
+ FakeStateMachine1 l_sm;
+ CommandMonitor l_cm;
+ l_sm.setSyncVars(i_mutex, i_cond);
+ l_cm.start(l_sm);
- ~FakeStateMachineTest() {}
+ uint64_t l_mntCmdTime = 10000000;
- private:
+ //Add 7 more
+ //3 of the 7 monitorIDs should timeout.
+ uint64_t l_monID1 = 0,
+ l_monID2 = 0,
+ l_monID3 = 0,
+ l_monID4 = 0,
+ l_monID5 = 0,
+ l_monID6 = 0,
+ 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);
- 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;
+ //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);
- return isEqual;
- }
+ //3 monitorIDs should timeout
+ l_sm.setTotalExpectedMons(3);
- bool iv_processedTimeout;
- std::vector<uint64_t> iv_monitors;
-};
+ if(false != l_sm.isTimeoutProcessed())
+ {
+ TS_FAIL("Unexpected timeout");
+ }
-class MdiaCommandMonitorTest: public CxxTest::TestSuite
-{
- private:
- void nanoSleep(uint64_t i_sleepSec, uint64_t i_sleepNanoSec) const
- {
- if( TARGETING::is_vpo() )
+ //Wait till all monitorIDs have timed out
+ mutex_lock(i_mutex);
+ while(false == l_sm.isTimeoutProcessed())
{
- nanosleep(0, TEN_CTX_SWITCHES_NS);
+ sync_cond_wait(i_cond, i_mutex);
}
- else
+ mutex_unlock(i_mutex);
+
+ if(true != l_sm.isContentsEqual())
{
- nanosleep(i_sleepSec, i_sleepNanoSec);
+ TS_FAIL("Expected monitorIDs to timeout are not equal "
+ "to actual timedout monitorIDs");
}
+
+ TS_TRACE(EXIT_MRK "TimeoutSubset");
+
}
public:
@@ -177,7 +220,7 @@ class MdiaCommandMonitorTest: public CxxTest::TestSuite
}
// Add monitor after starting the CM thread
- FakeStateMachineTest l_sm;
+ StateMachine l_sm;
l_cm1.start(l_sm);
l_cm1.addMonitor(++l_timeout);
l_mon = l_cm1.addMonitor(++l_timeout);
@@ -235,73 +278,23 @@ class MdiaCommandMonitorTest: public CxxTest::TestSuite
void testthreadMainTimeout(void)
{
TS_TRACE(ENTER_MRK "testthreadMainTimeout");
+ mutex_t mutex;
+ sync_cond_t cond;
+ mutex_init(&mutex);
+ sync_cond_init(&cond);
- 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_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())
- {
- TS_FAIL("Did not timeout");
- }
- 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)
+ for(uint64_t iterations=0; iterations<20; iterations++)
{
- TS_FAIL("Size not zero");
+ TimeoutAll(&mutex, &cond);
}
- //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())
+ for(uint64_t iterations=0; iterations<20; iterations++)
{
- TS_FAIL("Unexpected timeout");
+ TimeoutSubset(&mutex, &cond);
}
- nanoSleep(0, 100000000);
- if(true != l_sm.isTimeoutProcessed())
- {
- TS_FAIL("Did not timeout");
- }
+ sync_cond_destroy(&cond);
+ mutex_destroy(&mutex);
TS_TRACE(EXIT_MRK "testthreadMainTimeout");
}
OpenPOWER on IntegriCloud