summaryrefslogtreecommitdiffstats
path: root/src/usr
diff options
context:
space:
mode:
authorBrad Bishop <bradleyb@us.ibm.com>2012-07-11 20:03:00 -0500
committerA. Patrick Williams III <iawillia@us.ibm.com>2012-08-28 12:31:52 -0500
commit2da487f7f1a3ef81e37dd3bc987159e1209d0915 (patch)
treeb1cc361d64b3be0f54b80dbc02ecb5b593a94fdb /src/usr
parent428319443515f3eca49f4537422103f9534b8dd3 (diff)
downloadtalos-hostboot-2da487f7f1a3ef81e37dd3bc987159e1209d0915.tar.gz
talos-hostboot-2da487f7f1a3ef81e37dd3bc987159e1209d0915.zip
Attention handler random attention generator.
Thread that generates random attentions for unit testing. RTC: 41445 Change-Id: Ic63708f302f7b60c9ec20349a4dda39a23749bcd Reviewed-on: http://gfw160.austin.ibm.com:8080/gerrit/1359 Tested-by: Jenkins Server Reviewed-by: Zane Shelley <zshelle@us.ibm.com> Reviewed-by: LARINA M. DSOUZA <larsouza@in.ibm.com> Reviewed-by: A. Patrick Williams III <iawillia@us.ibm.com>
Diffstat (limited to 'src/usr')
-rw-r--r--src/usr/diag/attn/test/attnfakesys.C21
-rw-r--r--src/usr/diag/attn/test/attnrandsource.C137
-rw-r--r--src/usr/diag/attn/test/attnrandsource.H153
-rw-r--r--src/usr/diag/attn/test/attntest.C22
-rw-r--r--src/usr/diag/attn/test/attntest.H10
-rw-r--r--src/usr/diag/attn/test/makefile2
6 files changed, 323 insertions, 22 deletions
diff --git a/src/usr/diag/attn/test/attnfakesys.C b/src/usr/diag/attn/test/attnfakesys.C
index 1958ae39b..ae3697f9a 100644
--- a/src/usr/diag/attn/test/attnfakesys.C
+++ b/src/usr/diag/attn/test/attnfakesys.C
@@ -242,27 +242,6 @@ void FakeSystem::install()
getPrdWrapper().setImpl(*this);
}
-ATTENTION_VALUE_TYPE getRandomAttentionType()
-{
- ATTENTION_VALUE_TYPE a;
-
- switch (randint(1, 3))
- {
- case 1:
- a = CHECK_STOP;
- break;
- case 2:
- a = RECOVERABLE;
- break;
- case 3:
- default:
- a = SPECIAL;
- break;
- };
-
- return a;
-}
-
uint64_t FakeSystem::generateAttentions(uint64_t i_count, AttnList & io_list)
{
static const TargetHandle_t nullTarget = 0;
diff --git a/src/usr/diag/attn/test/attnrandsource.C b/src/usr/diag/attn/test/attnrandsource.C
new file mode 100644
index 000000000..daa09a4a8
--- /dev/null
+++ b/src/usr/diag/attn/test/attnrandsource.C
@@ -0,0 +1,137 @@
+/* IBM_PROLOG_BEGIN_TAG
+ * This is an automatically generated prolog.
+ *
+ * $Source: src/usr/diag/attn/test/attnrandsource.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
+ */
+/**
+ * @file attnrandsource.C
+ *
+ * @brief HBATTN Random attention source class method definitions.
+ */
+
+#include "attnrandsource.H"
+#include "attnfakesys.H"
+#include "sys/time.h"
+
+using namespace PRDF;
+using namespace TARGETING;
+using namespace std;
+
+namespace ATTN
+{
+
+bool RandSource::start()
+{
+ bool success = false;
+
+ mutex_lock(&iv_mutex);
+
+ if(!iv_tid)
+ {
+ iv_tid = task_create(&main, this);
+ }
+
+ success = iv_tid != 0;
+
+ mutex_unlock(&iv_mutex);
+
+ return success;
+}
+
+bool RandSource::wait()
+{
+ mutex_lock(&iv_mutex);
+
+ tid_t t = iv_tid;
+ iv_tid = 0;
+
+ mutex_unlock(&iv_mutex);
+
+ if(t)
+ {
+ task_wait_tid(t, 0, 0);
+ }
+
+ return true;
+}
+
+void RandSource::main(void * i_source)
+{
+ RandSource * src = static_cast<RandSource *>(i_source);
+
+ src->run();
+}
+
+void RandSource::run()
+{
+ mutex_lock(&iv_mutex);
+
+ uint64_t iterations = iv_iterations, delay, count;
+
+ mutex_unlock(&iv_mutex);
+
+ while(iterations--)
+ {
+ delay = randint(TEN_CTX_SWITCHES_NS, TEN_CTX_SWITCHES_NS * 10) / iv_iterations +1;
+ count = randint(1, iv_max);
+
+ nanosleep(0, delay);
+
+ AttnList l;
+ AttnData d;
+
+ while(count--)
+ {
+ // select a random target
+
+ // generate a random attention
+
+ d.targetHndl = *(iv_first + randint(0, distance(iv_first, iv_last) -1));
+ d.attnType = getRandomAttentionType();
+
+ l.push_back(d);
+ }
+
+ iv_system->putAttentions(l);
+ }
+}
+
+RandSource::RandSource(
+ uint64_t i_iterations,
+ uint64_t i_maxAttnsPerIteration,
+ FakeSystem & i_system,
+ TargetHandle_t * i_first,
+ TargetHandle_t * i_last)
+ : iv_tid(0),
+ iv_iterations(i_iterations),
+ iv_max(i_maxAttnsPerIteration),
+ iv_system(&i_system),
+ iv_first(i_first),
+ iv_last(i_last)
+{
+ mutex_init(&iv_mutex);
+}
+
+RandSource::~RandSource()
+{
+ mutex_destroy(&iv_mutex);
+}
+}
diff --git a/src/usr/diag/attn/test/attnrandsource.H b/src/usr/diag/attn/test/attnrandsource.H
new file mode 100644
index 000000000..50634fc9e
--- /dev/null
+++ b/src/usr/diag/attn/test/attnrandsource.H
@@ -0,0 +1,153 @@
+/* IBM_PROLOG_BEGIN_TAG
+ * This is an automatically generated prolog.
+ *
+ * $Source: src/usr/diag/attn/test/attnrandsource.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_ATTNRANDSOURCE_H
+#define __TEST_ATTNRANDSOURCE_H
+
+/**
+ * @file attnrandsource.H
+ *
+ * @brief HBATTN Random attention source class definitions.
+ */
+
+#include "attntest.H"
+#include "sys/task.h"
+
+namespace ATTN
+{
+
+/**
+ * @brief RandSource
+ *
+ * Random attention generator testcase.
+ */
+class RandSource
+{
+ public:
+
+ /**
+ * @brief start Start the testcase thread.
+ *
+ * @retval[true] Testcase thread started succesfully.
+ * @retval[false] Testcase thread failed to start.
+ */
+ bool start();
+
+ /**
+ * @brief wait Wait for the testcase to run to completion.
+ *
+ * @post All resources reclaimed.
+ *
+ * @retval[true] Testcase succesfully ran to completion.
+ * @retval[false] Testcase did not run succesfully to completion.
+ */
+ bool wait();
+
+ /**
+ * @brief ctor
+ *
+ * @param[in] i_iterations The number of attentions to inject.
+ * @param[in] i_maxAttnsPerIteration The upper bound on the number
+ * of attentions to inject per iteration.
+ * @param[in] i_system The fake hardware on which to inject attentions.
+ * @param[in] i_first The start of the range from which to
+ * generate attentions.
+ * @param[in] i_last The end of the range from which to
+ * generate attentions.
+ */
+ RandSource(
+ uint64_t i_iterations,
+ uint64_t i_maxAttnsPerIteration,
+ FakeSystem & i_system,
+ TARGETING::TargetHandle_t * i_rangeStart,
+ TARGETING::TargetHandle_t * i_rangeEnd);
+
+ /**
+ * @brief dtor
+ */
+ ~RandSource();
+
+ private:
+
+ /**
+ * @brief main Static wrapper for run.
+ *
+ * @param[in] i_source The source on which to call run.
+ */
+ static void main(void * i_source);
+
+ /**
+ * @brief run Execute the testcase.
+ */
+ void run();
+
+ /**
+ * @brief iv_mutex Shared data access serialization.
+ */
+ mutex_t iv_mutex;
+
+ /**
+ * @brief iv_tid Testcase thread number.
+ */
+ tid_t iv_tid;
+
+ /**
+ * @brief iv_iterations The number of attentions to inject.
+ */
+ uint64_t iv_iterations;
+
+ /**
+ * @brief iv_max The upper bound on the number of attentions
+ * to inject per iteration.
+ */
+ uint64_t iv_max;
+
+ /**
+ * @brief iv_system The system on which attentions are injected.
+ */
+ FakeSystem * iv_system;
+
+ /**
+ * @brief iv_rangeStart The start of the range from which to
+ * generate attentions.
+ */
+ TARGETING::TargetHandle_t * iv_first;
+
+ /**
+ * @brief iv_rangeEnd The end of the range from which to
+ * generate attentions.
+ */
+ TARGETING::TargetHandle_t * iv_last;
+
+ /**
+ * @brief copy disabled
+ */
+ RandSource(const RandSource &);
+
+ /**
+ * @brief assignment disabled
+ */
+ RandSource &operator=(const RandSource &);
+};
+}
+#endif
diff --git a/src/usr/diag/attn/test/attntest.C b/src/usr/diag/attn/test/attntest.C
index 136c7027f..69af786f9 100644
--- a/src/usr/diag/attn/test/attntest.C
+++ b/src/usr/diag/attn/test/attntest.C
@@ -33,6 +33,7 @@
#include "../attntrace.H"
using namespace std;
+using namespace PRDF;
namespace ATTN
{
@@ -75,4 +76,25 @@ uint64_t randint(uint64_t i_min, uint64_t i_max)
return ((lo | hi) % (i_max +1 - i_min)) + i_min;
}
+
+ATTENTION_VALUE_TYPE getRandomAttentionType()
+{
+ ATTENTION_VALUE_TYPE a;
+
+ switch (randint(1, 3))
+ {
+ case 1:
+ a = CHECK_STOP;
+ break;
+ case 2:
+ a = RECOVERABLE;
+ break;
+ case 3:
+ default:
+ a = SPECIAL;
+ break;
+ };
+
+ return a;
+}
}
diff --git a/src/usr/diag/attn/test/attntest.H b/src/usr/diag/attn/test/attntest.H
index 52862486e..8f6ce38f1 100644
--- a/src/usr/diag/attn/test/attntest.H
+++ b/src/usr/diag/attn/test/attntest.H
@@ -73,5 +73,15 @@ template <typename T>
{
};
+
+/**
+ * @brief getRandomAttentionType
+ *
+ * Obtain a random attention type.
+ *
+ * @return The generated attention type.
+ */
+PRDF::ATTENTION_VALUE_TYPE getRandomAttentionType();
+
}
#endif
diff --git a/src/usr/diag/attn/test/makefile b/src/usr/diag/attn/test/makefile
index cd3b4449a..e5363a2eb 100644
--- a/src/usr/diag/attn/test/makefile
+++ b/src/usr/diag/attn/test/makefile
@@ -25,7 +25,7 @@ ROOTPATH = ../../../../..
EXTRAINCDIR += ${ROOTPATH}/src/include/usr/diag
OBJS = attnfakesys.o attntest.o attnrand.o attnfakepresenter.o attnfakeprd.o \
- attnfaketarget.o
+ attnfaketarget.o attnrandsource.o
MODULE = testattn
OpenPOWER on IntegriCloud