diff options
| author | Nick Bofferding <bofferdn@us.ibm.com> | 2012-08-18 13:12:13 -0500 |
|---|---|---|
| committer | A. Patrick Williams III <iawillia@us.ibm.com> | 2012-08-27 16:21:45 -0500 |
| commit | 8542d295bb993a74f5037e9d48258a49afe49071 (patch) | |
| tree | c2ed0de110ae8769ed902bdcfccf6dbe94c4425b /src | |
| parent | 08b394126bfa79b46042ac1c101904a9ed133cf4 (diff) | |
| download | blackbird-hostboot-8542d295bb993a74f5037e9d48258a49afe49071.tar.gz blackbird-hostboot-8542d295bb993a74f5037e9d48258a49afe49071.zip | |
Support for HWAS state predicate
- Created new .C/.H for HWAS state predicate support
- Updated testcommontargeting.H with HWAS state predicate testcases
- Updated common makefile to include HWAS state predicate file
- Updated predicates.H to include the HWAS state predicate
RTC: 46236
Change-Id: If7552abab270f06ab538144cf299b27460e51394
Reviewed-on: http://gfw160.austin.ibm.com:8080/gerrit/1563
Tested-by: Jenkins Server
Reviewed-by: A. Patrick Williams III <iawillia@us.ibm.com>
Diffstat (limited to 'src')
| -rw-r--r-- | src/include/usr/targeting/common/predicates/predicatehwas.H | 262 | ||||
| -rw-r--r-- | src/include/usr/targeting/common/predicates/predicates.H | 47 | ||||
| -rw-r--r-- | src/usr/targeting/common/common.mk | 48 | ||||
| -rw-r--r-- | src/usr/targeting/common/predicates/predicatehwas.C | 109 | ||||
| -rw-r--r-- | src/usr/targeting/common/test/testcommontargeting.H | 157 |
5 files changed, 552 insertions, 71 deletions
diff --git a/src/include/usr/targeting/common/predicates/predicatehwas.H b/src/include/usr/targeting/common/predicates/predicatehwas.H new file mode 100644 index 000000000..07e623314 --- /dev/null +++ b/src/include/usr/targeting/common/predicates/predicatehwas.H @@ -0,0 +1,262 @@ +/* IBM_PROLOG_BEGIN_TAG + * This is an automatically generated prolog. + * + * $Source: src/include/usr/targeting/common/predicates/predicatehwas.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 __TARGETING_COMMON_PREDICATEHWAS_H +#define __TARGETING_COMMON_PREDICATEHWAS_H + +/** + * @file targeting/common/predicates/predicatehwas.H + * + * @brief Interface for a predicate which fiters a target based on its HWAS + * state + */ + +//****************************************************************************** +// Includes +//****************************************************************************** + +// STD + +// Other Host Boot Components + +// Targeting Component +#include <targeting/common/target.H> +#include <targeting/common/attributes.H> +#include <targeting/common/predicates/predicatebase.H> + +//****************************************************************************** +// Macros +//****************************************************************************** + +#undef TARG_NAMESPACE +#undef TARG_CLASS +#undef TARG_FN + +//****************************************************************************** +// Interface +//****************************************************************************** + +namespace TARGETING +{ + +#define TARG_NAMESPACE "TARGETING::" +#define TARG_CLASS "PredicateHWAS::" + +class Target; + +/** + * @brief Predicate class which filters a target based on its HWAS state + */ +class PredicateHwas : public PredicateBase +{ + public: + + /** + * @brief Create an HWAS state predicate + */ + PredicateHwas(); + + /** + * @brief Destroy an HWAS state predicate + */ + virtual ~PredicateHwas(); + + /** + * @brief Reset the predicate to match everything + * + * @return Reference to the predicate, for chaining + */ + PredicateHwas& reset(); + + /** + * @brief Configure predicate to look for the given powered on state + * + * @param[in] i_poweredOn Desired powered on state + * + * @return Reference to the predicate, for chaining + */ + PredicateHwas& poweredOn(const bool i_poweredOn); + + /** + * @brief Configure predicate to look for the given present state + * + * @param[in] i_present Desired present state + * + * @return Reference to the predicate, for chaining + */ + PredicateHwas& present(const bool i_present); + + /** + * @brief Configure predicate to look for the given functional state + * + * @param[in] i_functional Desired functional state + * + * @return Reference to the predicate, for chaining + */ + PredicateHwas& functional(const bool i_functional); + + /** + * @brief Configure predicate to look for the given changed since last + * IPL state + * + * @param[in] i_changedSinceLastIpl Desired changed since last IPL + * state + * + * @return Reference to the predicate, for chaining + */ + PredicateHwas& changedSinceLastIpl(const bool i_changedSinceLastIpl); + + /** + * @brief Configure predicate to look for the given dump functional + * state + * + * @param[in] i_dumpFunctional Desired dump functional state + * + * @return Reference to the predicate, for chaining + */ + PredicateHwas& dumpFunctional(const bool i_dumpFunctional); + + /** + * @brief Returns whether target matches the desired HWAS state + * + * @par Detailed Description: + * Returns whether target matches the desired HWAS state. Current + * HWAS sub-fields compared include poweredOn, present, functional, + * changedSinceLastIpl, and dumpFunctional. On construction, the + * predicate matches any state of those five fields. To make the + * filter more restrictive, call any combination of the state + * configuration functions with the desired values. The filter + * will make sure all the desired fields have requested values + * before returning a match. To reset the filter to match all + * targets, call reset(). See PredicateBase class for + * parameter/return description. + * + * @param[in] i_pTarget + * Target handle pointing to the target to compare to + * + * @return bool indicating whether the target matches or not + */ + virtual bool operator()( + const Target* i_pTarget) const; + + private: + + /** + * @brief Union that exposes raw value of an HWAS state attribute + * for purposes of bitwise comparison + * + * @warning ATTR_HWAS_STATE size must be <= uint64_t in size, otherwise + * code cannot guarantee that the required bitfields fit. This + * requirement is enforced by a compile-time assert + */ + union hwasState + { + ATTR_HWAS_STATE_type attribute; // Attribute + uint64_t rawValue; // Flattened representation + + }; + + hwasState iv_desired; ///< Desired states + hwasState iv_valid; ///< Validity of each field + + TARG_DISABLE_COPY_AND_ASSIGNMENT_OPERATORS(PredicateHwas); +}; + +//****************************************************************************** +// PredicateHwas::PredicateHwas +//****************************************************************************** + +inline PredicateHwas::PredicateHwas() +{ + // Ignore reference + reset(); +} + +//****************************************************************************** +// PredicateHwas::poweredOn +//****************************************************************************** + +inline PredicateHwas& PredicateHwas::poweredOn( + const bool i_poweredOn) +{ + iv_desired.attribute.poweredOn = i_poweredOn; + iv_valid.attribute.poweredOn = true; + return *this; +} + +//****************************************************************************** +// PredicateHwas::present +//****************************************************************************** + +inline PredicateHwas& PredicateHwas::present( + const bool i_present) +{ + iv_desired.attribute.present = i_present; + iv_valid.attribute.present = true; + return *this; +} + +//****************************************************************************** +// PredicateHwas::functional +//****************************************************************************** + +inline PredicateHwas& PredicateHwas::functional( + const bool i_functional) +{ + iv_desired.attribute.functional = i_functional; + iv_valid.attribute.functional = true; + return *this; +} + +//****************************************************************************** +// PredicateHwas::changedSinceLastIpl +//****************************************************************************** + +inline PredicateHwas& PredicateHwas::changedSinceLastIpl( + const bool i_changedSinceLastIpl) +{ + iv_desired.attribute.changedSinceLastIPL = i_changedSinceLastIpl; + iv_valid.attribute.changedSinceLastIPL = true; + return *this; +} + +//****************************************************************************** +// PredicateHwas::dumpFunctional +//****************************************************************************** + +inline PredicateHwas& PredicateHwas::dumpFunctional( + const bool i_dumpFunctional) +{ + iv_desired.attribute.dumpfunctional = i_dumpFunctional; + iv_valid.attribute.dumpfunctional = true; + return *this; +} + +#undef TARG_CLASS +#undef TARG_NAMESPACE + +} // End namespace TARGETING + +#endif // __TARGETING_COMMON_PREDICATEHWAS_H + diff --git a/src/include/usr/targeting/common/predicates/predicates.H b/src/include/usr/targeting/common/predicates/predicates.H index 5a7cf04d9..e0dbdf248 100644 --- a/src/include/usr/targeting/common/predicates/predicates.H +++ b/src/include/usr/targeting/common/predicates/predicates.H @@ -1,26 +1,26 @@ -// IBM_PROLOG_BEGIN_TAG -// This is an automatically generated prolog. -// -// $Source: src/include/usr/targeting/predicates/predicates.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 - +/* IBM_PROLOG_BEGIN_TAG + * This is an automatically generated prolog. + * + * $Source: src/include/usr/targeting/common/predicates/predicates.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 __TARGETING_COMMON_PREDICATES_H #define __TARGETING_COMMON_PREDICATES_H @@ -33,6 +33,7 @@ #include <targeting/common/predicates/predicatebase.H> #include <targeting/common/predicates/predicatectm.H> #include <targeting/common/predicates/predicateisfunctional.H> +#include <targeting/common/predicates/predicatehwas.H> #include <targeting/common/predicates/predicatepostfixexpr.H> // please keep up to date... diff --git a/src/usr/targeting/common/common.mk b/src/usr/targeting/common/common.mk index a6e32c169..9608bd86e 100644 --- a/src/usr/targeting/common/common.mk +++ b/src/usr/targeting/common/common.mk @@ -1,26 +1,25 @@ -# IBM_PROLOG_BEGIN_TAG -# This is an automatically generated prolog. -# -# $Source: src/usr/targeting/makefile $ -# -# IBM CONFIDENTIAL -# -# COPYRIGHT International Business Machines Corp. 2011 -# -# 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 - +# IBM_PROLOG_BEGIN_TAG +# This is an automatically generated prolog. +# +# $Source: src/usr/targeting/common/common.mk $ +# +# IBM CONFIDENTIAL +# +# COPYRIGHT International Business Machines Corp. 2011,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 otherwise +# divested of its trade secrets, irrespective of what has been +# deposited with the U.S. Copyright Office. +# +# Origin: 30 +# +# IBM_PROLOG_END_TAG ################################################################################ # # @file targeting/common/common.mk @@ -36,7 +35,8 @@ PREDICATES_OBJS = \ predicatebase.o \ predicatepostfixexpr.o \ predicatectm.o \ - predicateisfunctional.o + predicateisfunctional.o \ + predicatehwas.o ITERATORS_OBJS = \ targetiterator.o \ diff --git a/src/usr/targeting/common/predicates/predicatehwas.C b/src/usr/targeting/common/predicates/predicatehwas.C new file mode 100644 index 000000000..d92536269 --- /dev/null +++ b/src/usr/targeting/common/predicates/predicatehwas.C @@ -0,0 +1,109 @@ +/* IBM_PROLOG_BEGIN_TAG + * This is an automatically generated prolog. + * + * $Source: src/usr/targeting/common/predicates/predicatehwas.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 targeting/common/predicates/predicatehwas.C + * + * @brief Implementation for a predicate which fiters a target based on its + * HWAS state + */ + +//****************************************************************************** +// Includes +//****************************************************************************** + +// STD +#include <string.h> + +// Other Host Boot Components + +// Targeting Component +#include <targeting/common/attributes.H> +#include <targeting/common/target.H> +#include <targeting/common/predicates/predicates.H> +#include <targeting/adapters/assertadapter.H> + +//****************************************************************************** +// Macros +//****************************************************************************** + +#undef TARG_NAMESPACE +#undef TARG_CLASS +#undef TARG_FN + +//****************************************************************************** +// Interface +//****************************************************************************** + +namespace TARGETING +{ + +#define TARG_NAMESPACE "TARGETING::" +#define TARG_CLASS "PredicateHwas::" + +//****************************************************************************** +// PredicateHwas::~PredicateHwas() +//****************************************************************************** + +PredicateHwas::~PredicateHwas() +{ + #define TARG_FUNC "~PredicateHwas()" + #undef TARG_FUNC +} + +//****************************************************************************** +// PredicateHwas::reset +//****************************************************************************** + +PredicateHwas& PredicateHwas::reset() +{ + memset(&iv_valid,0x00,sizeof(iv_valid)); + memset(&iv_desired,0x00,sizeof(iv_desired)); + return *this; +} + +//****************************************************************************** +// PredicateHwas::operator() +//****************************************************************************** + +bool PredicateHwas::operator()( + const Target* const i_pTarget) const +{ + #define TARG_FUNC "operator()(...)" + + hwasState actual = { rawValue: 0}; + CPPASSERT(sizeof(actual.attribute) <= sizeof(actual.rawValue)); + actual.attribute = i_pTarget->getAttr<ATTR_HWAS_STATE>(); + + return ( (actual.rawValue & iv_valid.rawValue) + == (iv_desired.rawValue & iv_valid.rawValue)); + + #undef TARG_FUNC +} + +#undef TARG_CLASS +#undef TARG_NAMESPACE + +} // End namespace TARGETING + diff --git a/src/usr/targeting/common/test/testcommontargeting.H b/src/usr/targeting/common/test/testcommontargeting.H index 6a0ea8d8f..1be81cc38 100644 --- a/src/usr/targeting/common/test/testcommontargeting.H +++ b/src/usr/targeting/common/test/testcommontargeting.H @@ -1,26 +1,25 @@ -/* IBM_PROLOG_BEGIN_TAG - * This is an automatically generated prolog. - * - * $Source: src/usr/targeting/common/test/testcommontargeting.H $ - * - * IBM CONFIDENTIAL - * - * COPYRIGHT International Business Machines Corp. 2011-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 - */ +/* IBM_PROLOG_BEGIN_TAG */ +/* This is an automatically generated prolog. */ +/* */ +/* $Source: src/usr/targeting/common/test/testcommontargeting.H $ */ +/* */ +/* IBM CONFIDENTIAL */ +/* */ +/* COPYRIGHT International Business Machines Corp. 2011,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 otherwise */ +/* divested of its trade secrets, irrespective of what has been */ +/* deposited with the U.S. Copyright Office. */ +/* */ +/* Origin: 30 */ +/* */ +/* IBM_PROLOG_END_TAG */ #ifndef __TARGETING_COMMON_TESTCOMMONTARGETING_H #define __TARGETING_COMMON_TESTCOMMONTARGETING_H @@ -539,6 +538,117 @@ class CommonTargetingTestSuite: public CxxTest::TestSuite TARG_TS_TRACE(EXIT_MRK "testTargetClass" ); } + void testPredicateHwas() + { + TARG_TS_TRACE(ENTER_MRK "testPredicateHwas" ); + + do { + + using namespace TARGETING; + TargetService& l_targetService = targetService(); + + // Get top level (system) target + Target* l_pTopLevel = NULL; + (void) l_targetService.getTopLevelTarget(l_pTopLevel); + if (l_pTopLevel == NULL) + { + TARG_TS_FAIL("Top level handle was NULL when initialization " + "complete"); + break; + } + + PredicateHwas hwasPredicate; + + ATTR_HWAS_STATE_type savedHwasState + = l_pTopLevel->getAttr<ATTR_HWAS_STATE>(); + + // Test: Given a target with any HWAS state, default HWAS predicate + // should return a match + for(size_t i=0; i<32; ++i) + { + ATTR_HWAS_STATE_type sweepHwasState + = { i&16, i&8, i&4, i&2, i&1 }; + l_pTopLevel->setAttr<ATTR_HWAS_STATE>(sweepHwasState); + + if(!hwasPredicate(l_pTopLevel)) + { + TARG_TS_FAIL("Expected default HWAS predicate to match the " + "target's HWAS state, using i = %d",i); + } + } + + // Test: Given a target with cleared HWAS state of functional, predicate + // looking for functional should return false + hwasPredicate.reset().functional(true); + ATTR_HWAS_STATE_type nonFunctionalHwasState = {0}; + l_pTopLevel->setAttr<ATTR_HWAS_STATE>(nonFunctionalHwasState); + if(hwasPredicate(l_pTopLevel)) + { + TARG_TS_FAIL("Expected HWAS functional predicate not to match the " + "target's cleared HWAS state"); + } + + // Test: Having previously not matched a target, resetting the HWAS + // predicate should match the target again + hwasPredicate.reset(); + if(!hwasPredicate(l_pTopLevel)) + { + TARG_TS_FAIL("Expected HWAS reset predicate to match the " + "target's functional HWAS state"); + } + + // Test: Given a target with HWAS state of functional, predicate + // looking for functional should return true + hwasPredicate.reset().functional(true); + ATTR_HWAS_STATE_type functionalHwasState = {0}; + functionalHwasState.functional = true; + l_pTopLevel->setAttr<ATTR_HWAS_STATE>(functionalHwasState); + if(!hwasPredicate(l_pTopLevel)) + { + TARG_TS_FAIL("Expected HWAS functional predicate to match the " + "target's functional HWAS state"); + } + + // Test: Given a target with HWAS state of non-functional, predicate + // looking for non-functional should return true + hwasPredicate.reset().functional(false); + l_pTopLevel->setAttr<ATTR_HWAS_STATE>(nonFunctionalHwasState); + if(!hwasPredicate(l_pTopLevel)) + { + TARG_TS_FAIL("Expected HWAS non-functional predicate to match the " + "target's non-functional HWAS state"); + } + + // Test: Given a predicate looking for target whose HWAS state + // exactly matches all 5 configurable HWAS states, filter should + // return true + hwasPredicate.reset().poweredOn(true).present(true).functional(false); + hwasPredicate.changedSinceLastIpl(true).dumpFunctional(false); + + ATTR_HWAS_STATE_type allFiveHwasState = {true,true,false,true,false}; + l_pTopLevel->setAttr<ATTR_HWAS_STATE>(allFiveHwasState); + if(!hwasPredicate(l_pTopLevel)) + { + TARG_TS_FAIL("Expected 5 setting HWAS predicate to match the " + "target's similarly configured HWAS state"); + } + + // Test: Given a predicate looking for target whose HWAS state + // exactly matches all 4 of 5 configurable HWAS states, filter + // should return false + allFiveHwasState.dumpfunctional = true; + l_pTopLevel->setAttr<ATTR_HWAS_STATE>(allFiveHwasState); + if(hwasPredicate(l_pTopLevel)) + { + TARG_TS_FAIL("Expected HWAS predicate not to match the target's " + "4/5 matching HWAS state configuration"); + } + + } while(0); + + TARG_TS_TRACE(EXIT_MRK "testPredicateHwas" ); + } + void testPredicateCtm() { TARG_TS_TRACE(ENTER_MRK "testPredicateCtm" ); @@ -632,7 +742,6 @@ class CommonTargetingTestSuite: public CxxTest::TestSuite l_pBase = NULL; TARG_TS_TRACE(EXIT_MRK "testPredicateCtm" ); - } void testPredicatePostfixExpr() |

