diff options
author | Nick Bofferding <bofferdn@us.ibm.com> | 2012-04-17 22:30:59 -0500 |
---|---|---|
committer | A. Patrick Williams III <iawillia@us.ibm.com> | 2012-04-24 15:48:42 -0500 |
commit | 4157b5631a1bbfcc7f9f95480b54e9ade7abce7d (patch) | |
tree | 423f4f13a4a0e2d6e76898992a37b4d2db302b3b /src/usr/targeting/test | |
parent | 5631ede5d2e63fa8585505eb29c6d86f420c9344 (diff) | |
download | blackbird-hostboot-4157b5631a1bbfcc7f9f95480b54e9ade7abce7d.tar.gz blackbird-hostboot-4157b5631a1bbfcc7f9f95480b54e9ade7abce7d.zip |
Support targeting code commonality
- Moved common targeting code to own subtrees
- Updated many components with header file changes
- Implemented abstract pointer class
- Implemented Hostboot specific support for targeting commonality
- Changed attribute VMM base address to 4 GB (From 3 GB)
- Removed tabs, fixed > 80 character lines
Change-Id: Ie5a6956670bfa4f262f7691b4f0ce5a20ed289fe
RTC: 35569
Reviewed-on: http://gfw160.austin.ibm.com:8080/gerrit/909
Tested-by: Jenkins Server
Reviewed-by: A. Patrick Williams III <iawillia@us.ibm.com>
Diffstat (limited to 'src/usr/targeting/test')
-rw-r--r-- | src/usr/targeting/test/makefile | 60 | ||||
-rw-r--r-- | src/usr/targeting/test/targetingtest.H | 1773 | ||||
-rw-r--r-- | src/usr/targeting/test/testtargeting.H | 245 | ||||
-rw-r--r-- | src/usr/targeting/test/unittestadapter.H | 45 |
4 files changed, 341 insertions, 1782 deletions
diff --git a/src/usr/targeting/test/makefile b/src/usr/targeting/test/makefile index 4e51e8849..dc33093bc 100644 --- a/src/usr/targeting/test/makefile +++ b/src/usr/targeting/test/makefile @@ -20,22 +20,64 @@ # Origin: 30 # # IBM_PROLOG_END + +################################################################################ +# +# @file src/usr/targeting/test/makefile +# +# @brief Makefile for building Hostboot's targeting test dir +# +################################################################################ + ROOTPATH = ../../../.. -EXTRAINCDIR += ${ROOTPATH}/src/include/usr/hwpf/fapi -EXTRAINCDIR += ${ROOTPATH}/src/include/usr/hwpf/plat -EXTRAINCDIR += ${ROOTPATH}/src/include/usr/hwpf/hwp -EXTRAINCDIR += ${ROOTPATH}/src/include/usr/ecmddatabuffer +# Determine relative paths to common targeting makefile + +COMMON_TARGETING_REL_PATH = ../common +COMMON_MAKEFILE = ${COMMON_TARGETING_REL_PATH}/test/common.mk + +# Suck in the common targeting makefile, verbatim + +include ${COMMON_MAKEFILE} + +# Defines from the common makefile included above: +# - COMMON_TESTCASES (name of common testcase .H's) +# - HWPF_INC_DIRS (subdirs of HWPF to look for includes) -# Allow testcase to access component trace macros -EXTRAINCDIR += ../ +# Point "make" to find sources and includes in the common and platform +# specific trees + +VPATH += ${COMMON_TARGETING_REL_PATH}/test + +HWPF_REL_PATH = ${ROOTPATH}/src/include/usr/hwpf + +EXTRAINCDIR += \ + $(addprefix ${HWPF_REL_PATH}/, ${HWPF_INC_DIRS}) \ + ${ROOTPATH}/src/include/usr/ecmddatabuffer \ + ../ + +# Generate the test suite MODULE = testtargeting -TESTS = *.H -OBJS = attributestrings.o +COMMON_TESTCASE_REL_PATHS = \ + $(addprefix ${COMMON_TARGETING_REL_PATH}/test/,${COMMON_TESTCASES}) + +TESTS = testtargeting.H ${COMMON_TESTCASE_REL_PATHS} + +OBJS = attributestrings.o + +#debug : +# @echo EXTRAINCDIR = ${EXTRAINCDIR} +# @echo COMMON_TARGETING_REL_PATH = ${COMMON_TARGETING_REL_PATH} +# @echo COMMON_MAKEFILE = ${COMMON_MAKEFILE} +# @echo VPATH = ${VPATH} +# @echo INCLUDES = ${INCLUDES} +# @echo COMMON_TESTCASE_REL_PATHS = ${COMMON_TESTCASE_REL_PATHS} +# @echo COMMON_TESTCASES = ${COMMON_TESTCASES} +# @echo HWPF_INC_DIRS = ${HWPF_INC_DIRS} +# @echo TESTS = ${TESTS} include ${ROOTPATH}/config.mk vpath %.C ${GENDIR} - diff --git a/src/usr/targeting/test/targetingtest.H b/src/usr/targeting/test/targetingtest.H deleted file mode 100644 index aaba63027..000000000 --- a/src/usr/targeting/test/targetingtest.H +++ /dev/null @@ -1,1773 +0,0 @@ -// IBM_PROLOG_BEGIN_TAG -// This is an automatically generated prolog. -// -// $Source: src/usr/targeting/test/targetingtest.H $ -// -// 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 -#ifndef __TESTTARGETING_H -#define __TESTTARGETING_H - -/** - * @file testtargeting.H - * - * @brief All unit tests for the targeting infrastructure - */ - -//****************************************************************************** -// Includes -//****************************************************************************** - -// STD -#include <stdio.h> -#include <sys/time.h> - -// CXXTEST -#include <cxxtest/TestSuite.H> -#include <hwpf/plat/fapiPlatAttributeService.H> -#include <fapiReturnCode.H> -#include <fapiAttributeIds.H> -#include <fapiAttributeService.H> -#include <errl/errlmanager.H> -#include <sys/sync.h> -#include <sys/task.h> -#include <sys/time.h> - -// This component -#include <targeting/attributes.H> -#include <targeting/entitypath.H> -#include <targeting/target.H> -#include <targeting/targetservice.H> -#include <targeting/iterators/rangefilter.H> -#include <targeting/predicates/predicatectm.H> -#include <targeting/predicates/predicatepostfixexpr.H> -#include <targeting/targreasoncodes.H> -#include <errl/errludtarget.H> -#include "trace.H" - -trace_desc_t* g_trac_targeting = NULL; -TRAC_INIT(&g_trac_targeting, "TARG", 4096); - - -namespace TARGETING { -extern void dumpAllAttributes(trace_desc_t*); -}; - -/** - * @brief Struct to hold pointers to a mutex / protected value - */ -struct MutexTestData_t -{ - mutex_t* pMutex; // Pointer to mutex - barrier_t* pBarrier; // Pointer to barrier - volatile uint32_t* pVar; // Pointer to value protected by mutex -}; - -/** - * @brief Function which attempts to write a protected variable - * - * @param[in] i_pData Pointer to mutex pointer/value pointer structure - * - * @return N/A - */ -void funcTestMutex(void* i_pData) -{ - MutexTestData_t* l_pData = static_cast<MutexTestData_t*>(i_pData); - barrier_wait(l_pData->pBarrier); - mutex_lock(l_pData->pMutex); - *(l_pData->pVar) = 1; - mutex_unlock(l_pData->pMutex); - barrier_wait(l_pData->pBarrier); - task_end(); -} - -class TargetingTestSuite: public CxxTest::TestSuite -{ - public: - - /** - * @brief Test the TargetService class (except debug cases) - */ - void testTargetServiceClass() - { - return; //@fixme - found a Data Storage Exception that needs to be fixed (Task 4485) - TS_TRACE(ENTER_MRK "testTargetServiceClass" ); - - using namespace TARGETING; - - TargetService& l_targetService = targetService(); - - l_targetService.init(); - - // Post init - // Test: void masterProcChipTarget( - // TargetHandleList& o_masterProcChipTarget) const; - - Target* l_pMasterProcChipTargetHandle = NULL; - (void) l_targetService.masterProcChipTargetHandle( - l_pMasterProcChipTargetHandle); - - if ( l_pMasterProcChipTargetHandle - == MASTER_PROCESSOR_CHIP_TARGET_SENTINEL) - { - TS_FAIL("Post init; master proc chip target handle should not " - "be the sentinel value"); - } - - if (l_pMasterProcChipTargetHandle == NULL) - { - TS_FAIL("Post init; master proc chip target handle should not " - "be the NULL value"); - } - - ScomSwitches l_switches = {0}; - l_switches = - l_pMasterProcChipTargetHandle->getAttr<ATTR_SCOM_SWITCHES>(); - if( l_switches.useFsiScom != 0 - || l_switches.useXscom != 1 - || l_switches.useInbandScom != 0 - || l_switches.reserved != 0) - { - TS_FAIL("SCOM Switches stuct was not correct (%d, %d, %d, %d)", - l_switches.useFsiScom, l_switches.useXscom, - l_switches.useInbandScom , - l_switches.reserved); - } - - if ( l_pMasterProcChipTargetHandle->getAttr<ATTR_CLASS> () - != CLASS_CHIP) - { - TS_FAIL("Post init; master proc chip target handle was not of " - "chip class"); - } - - if ( l_pMasterProcChipTargetHandle->getAttr<ATTR_TYPE> () - != TYPE_PROC) - { - TS_FAIL("Post init; master proc chip target handle was not of " - "proc type"); - } - - // Post init - // Test: void getTopLevelTarget(Target*& o_targetHandle) const; - - Target* l_pTopLevel = NULL; - (void) l_targetService.getTopLevelTarget(l_pTopLevel); - if (l_pTopLevel == NULL) - { - TS_FAIL("Top level handle was NULL when initialization " - "complete"); - } - - if (l_pTopLevel->getAttr<ATTR_CLASS> () != CLASS_SYS) - { - TS_FAIL("Post init; top level target class != CLASS_SYS"); - } - - // Post init - // Test: void exists( - // const EntityPath& i_entityPath, - // bool& o_exists) const; - bool l_exists = false; - (void) l_targetService.exists( - l_pTopLevel->getAttr<ATTR_PHYS_PATH> (), l_exists); - - if (l_exists != true) - { - TS_FAIL("Expected top level target to exist"); - } - - // Post init - // Test: Target* toTarget( - // const EntityPath& i_entityPath) const; - - Target* l_pInverseTarget = NULL; - l_pInverseTarget = l_targetService.toTarget( - l_pTopLevel->getAttr<ATTR_PHYS_PATH> ()); - - if (l_pInverseTarget != l_pTopLevel) - { - TS_FAIL("Expected to get the original target"); - } - - // Post init - // Test: void getAssociated( - // const Target* i_pTarget, - // ASSOCIATION_TYPE i_type, - // RECURSION_LEVEL i_recursionLevel, - // TargetHandleList& o_list) const; - - TargetHandleList l_list; - (void) l_targetService.getAssociated( - l_list, - l_pTopLevel, - TARGETING::TargetService::CHILD, - TARGETING::TargetService::IMMEDIATE); - if (!l_list.size()) - { - TS_FAIL("Should have found some child elements" ); - } - - // Verify child of given target has a parent that is the original - // target - - TargetHandleList l_parentList; - (void) l_targetService.getAssociated( - l_parentList, - l_list[0], - TARGETING::TargetService::PARENT, - TARGETING::TargetService::IMMEDIATE); - - if (l_parentList.size() != 1) - { - TS_FAIL("Should have found a parent element" ); - } - - if (l_parentList[0] != l_pTopLevel) - { - TS_FAIL("Parent handle should have matched original target " - "handle" ); - } - - (void) l_targetService.getAssociated( - l_list, - l_pTopLevel, - TARGETING::TargetService::CHILD_BY_AFFINITY, - TARGETING::TargetService::IMMEDIATE); - - if (!l_list.size()) - { - TS_FAIL("Should have found some child elements" ); - } - - (void) l_targetService.getAssociated( - l_list, - l_pTopLevel, - TARGETING::TargetService::CHILD_BY_AFFINITY, - TARGETING::TargetService::ALL); - - if (!l_list.size()) - { - TS_FAIL("Should have found more child elements" ); - } - - l_targetService.dump(); - - TS_TRACE(EXIT_MRK "testTargetServiceClass" ); - } - - /** - * @test Tests the EntityPath class (except debug cases) - */ - void testEntityPathClass(void) - { - TS_TRACE(ENTER_MRK "testEntityPathClass" ); - - using namespace TARGETING; - - EntityPath l_defaultPath; - if(l_defaultPath.size() != 0) - { - TS_FAIL("Default entity path's size was not 0"); - } - - if(l_defaultPath.type() != EntityPath::PATH_NA) - { - TS_FAIL("Default entity path's type was not PATH_NA"); - } - - EntityPath l_nonDefaultPath(EntityPath::PATH_PHYSICAL); - if(l_nonDefaultPath.size() != 0) - { - TS_FAIL("Non-default entity path's size was not 0"); - } - - if(l_nonDefaultPath.type() != EntityPath::PATH_PHYSICAL) - { - TS_FAIL("Non-default entity path's type was not " - "EntityPath::PATH_PHYSICAL"); - } - - l_defaultPath.setType(EntityPath::PATH_AFFINITY); - if(l_defaultPath.type() != EntityPath::PATH_AFFINITY) - { - TS_FAIL("Default entity path's type was not " - "EntityPath::PATH_AFFINITY after setting"); - } - - l_defaultPath.setType(EntityPath::PATH_PHYSICAL); - if(!(l_defaultPath == l_nonDefaultPath)) - { - TS_FAIL("Default entity path should have been equal to " - "the non-default entity path"); - } - - if(!l_defaultPath.equals(l_nonDefaultPath,0)) - { - TS_FAIL("Default entity path should have been equal to " - "the non-default entity path (equals API)"); - } - - l_defaultPath.addLast(TYPE_PROC,0); - if(l_defaultPath == l_nonDefaultPath) - { - TS_FAIL("Default entity path should NOT have been equal to " - "the non-default entity path"); - } - - if(l_defaultPath.equals(l_nonDefaultPath,1)) - { - TS_FAIL("Default entity path should NOT have been equal to " - "the non-default entity path (equals API, comparing 1 " - "element)"); - } - - if(l_defaultPath.size() != 1) - { - TS_FAIL("Default entity path should have had one path element" - "after adding PROC0"); - } - - l_nonDefaultPath.addLast(TYPE_PROC,0); - if(! (l_defaultPath == l_nonDefaultPath) ) - { - TS_FAIL("Default entity path should have been equal to " - "the non-default entity path since they now" - "both have the same 1 path element"); - } - - l_defaultPath.addLast(TYPE_MBA,1).addLast(TYPE_MBS,2); - if(l_defaultPath.size() != 3) - { - TS_FAIL("Default entity path should have had two path elements" - "after adding MBA1 and MBS2"); - } - - if( (l_defaultPath[0].type != TYPE_PROC) - || (l_defaultPath[0].instance != 0) - || (l_defaultPath[1].type != TYPE_MBA) - || (l_defaultPath[1].instance != 1) - || (l_defaultPath[2].type != TYPE_MBS) - || (l_defaultPath[2].instance != 2)) - { - TS_FAIL("Default entity path should have had correct 3 path " - "elements"); - } - - l_defaultPath.removeLast(); - if(l_defaultPath.size() != 2) - { - TS_FAIL("Default entity path should have had two path elements" - "after removing MBS2"); - } - - if( (l_defaultPath[0].type != TYPE_PROC) - || (l_defaultPath[0].instance != 0) - || (l_defaultPath[1].type != TYPE_MBA) - || (l_defaultPath[1].instance != 1)) - { - TS_FAIL("Default entity path should have had correct 2 path " - "elements"); - } - - l_nonDefaultPath.addLast(TYPE_MBA,1).addLast(TYPE_MBS,2); - - // Default now has proc/mba/ - // Non-default now has proc/mba/mbs - if(l_defaultPath == l_nonDefaultPath) - { - TS_FAIL("Default entity path should NOT have been equal to " - "the non-default entity path since they now" - "have different number of path elements"); - } - - if( !l_defaultPath.equals(l_nonDefaultPath,2) ) - { - TS_FAIL("Default entity path should have been equal to " - "the non-default entity path since they have the same" - "first two path elements"); - } - - l_defaultPath.removeLast().removeLast(); - if(l_defaultPath.size() != 0) - { - TS_FAIL("Default entity path should have had no path element" - "after removing MBA1 and PROC0"); - } - - TargetService& l_targetService = targetService(); - l_targetService.init(); - - EntityPath l_realPath(EntityPath::PATH_PHYSICAL); - l_realPath.addLast(TYPE_SYS,0).addLast(TYPE_NODE,0) - .addLast(TYPE_PROC,0); - - Target* l_pTarget = l_realPath.operator->(); - if(l_pTarget == NULL) - { - TS_FAIL("Real entity path should have mapped to an existing " - "target"); - } - - EntityPath l_path(EntityPath::PATH_PHYSICAL); - l_path.addLast(TYPE_SYS,0); - EntityPath l_changedPath = l_path.copyRemoveLast(); - if( (l_changedPath.size() != 0) - || (l_path.size() != 1)) - { - TS_FAIL("Const entity path should not have been altered in " - "const add test"); - } - - l_changedPath = l_path.copyAddLast(TYPE_NODE,0); - if( (l_changedPath.size() != 2) - || (l_path.size() != 1)) - { - TS_FAIL("Const entity path should not have been altered " - "in const add test"); - } - - TS_TRACE(EXIT_MRK "testEntityPathClass" ); - } - - /** - * @test Tests the EntityPath class (except debug cases) - */ - void testTargetClass(void) - { - TS_TRACE(ENTER_MRK "testTargetClass" ); - - using namespace TARGETING; - TargetService& l_targetService = targetService(); - l_targetService.init(); - - EntityPath l_realPath(EntityPath::PATH_PHYSICAL); - l_realPath.addLast(TYPE_SYS,0).addLast(TYPE_NODE,0) - .addLast(TYPE_PROC,0); - l_realPath.dump(); - - Target* l_pTarget = l_realPath.operator->(); - if(l_pTarget == NULL) - { - TS_FAIL("Failed to convert entity path to initial target"); - } - - CLASS l_class = l_pTarget->getAttr<ATTR_CLASS>(); - if(l_class != CLASS_CHIP) - { - TS_FAIL("Failed to get the class attribute"); - } - - l_class = CLASS_NA; - if( !l_pTarget->tryGetAttr<ATTR_CLASS>(l_class) ) - { - TS_FAIL("Failed to get the class attribute"); - } - - if(l_class != CLASS_CHIP) - { - TS_FAIL("Failed to try/get the class attribute"); - } - - attrToString<ATTR_CLASS>(l_class); - - uint8_t l_scom = 0; - if( l_pTarget->tryGetAttr<ATTR_DUMMY_RO>(l_scom) ) - { - TS_FAIL("ATTR_DUMMY_RO attribute should not have been available " - "to read"); - } - - if(l_scom != 0) - { - TS_FAIL("Failed ! try/get should not have set the SCOM attribute"); - } - - l_scom = 5; - if( l_pTarget->trySetAttr<ATTR_DUMMY_WO>(l_scom) ) - { - TS_FAIL("ATTR_DUMMY_WO attribute should not have been available " - "to write"); - } - - if(l_scom != 5) - { - TS_FAIL("SCOM attribute should not have been altered in the " - "failed write"); - } - - DUMMY_RW_ATTR l_wo; - memset(l_wo,0x00,sizeof(l_wo)); - l_wo[0][1][2] = 6; - if( !l_pTarget->trySetAttr<ATTR_DUMMY_RW>(l_wo) ) - { - TS_FAIL("ATTR_DUMMY_RW should have been available for write"); - } - - if(l_wo[0][1][2] != 6) - { - TS_FAIL("ATTR_DUMMY_RW local attribute should not have been " - "altered in the successful write"); - } - - DUMMY_RW_ATTR l_read; - l_pTarget->tryGetAttr<ATTR_DUMMY_RW>(l_read); - if(memcmp(l_read,l_wo,sizeof(l_read))) - { - TS_FAIL("Failed to read back the correct ATTR_DUMMY_RW"); - } - - DUMMY_RW_ATTR l_setWo; - memset(l_setWo,0x00,sizeof(l_setWo)); - l_setWo[0][2][4] = 9; - l_pTarget->setAttr<ATTR_DUMMY_RW>(l_setWo); - if(l_setWo[0][2][4] != 9) - { - TS_FAIL("ATTR_DUMMY_RW local attribute should not have been " - "altered in the successful setAttr"); - } - - DUMMY_RW_ATTR l_setWoVerify; - l_pTarget->tryGetAttr<ATTR_DUMMY_RW>(l_setWoVerify); - if(memcmp(l_setWoVerify,l_setWo,sizeof(l_setWoVerify))) - { - TS_FAIL("ATTR_DUMMY_RW read should have matched prior write"); - } - - memset(l_setWo,0x05,sizeof(l_setWo)); - l_pTarget->setAttr<ATTR_DUMMY_RW>(l_setWo); - - TS_TRACE(EXIT_MRK "testTargetClass" ); - } - - void testPredicateCtm() - { - TS_TRACE(ENTER_MRK "testPredicateCtm" ); - - 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) - { - TS_FAIL("Top level handle was NULL when initialization " - "complete"); - } - - PredicateCTM l_allWild; - if( ! l_allWild(l_pTopLevel) ) - { - TS_FAIL("CTM all wildcards filter should have matched system " - "target"); - } - - PredicateCTM l_typeModelWild(CLASS_SYS); - if( ! l_typeModelWild(l_pTopLevel) ) - { - TS_FAIL("CTM class sys, remaining wildcards filter should have " - "matched system "); - } - - PredicateCTM l_modelWild(CLASS_SYS,TYPE_SYS); - if( ! l_modelWild(l_pTopLevel) ) - { - TS_FAIL("CTM class sys, type sys, remaining wildcards filter " - "should have matched system "); - } - - PredicateCTM l_noWild(CLASS_SYS,TYPE_SYS,MODEL_POWER8); - if( ! l_noWild(l_pTopLevel) ) - { - TS_FAIL("CTM class sys, type sys, model power8 should have " - "matched system "); - } - - PredicateCTM l_classWild(CLASS_NA,TYPE_SYS,MODEL_POWER8); - if( ! l_classWild(l_pTopLevel) ) - { - TS_FAIL("CTM class wild, type sys, model power8 should have " - "matched system "); - } - - PredicateCTM l_typeWild(CLASS_SYS,TYPE_NA,MODEL_POWER8); - if( ! l_typeWild(l_pTopLevel) ) - { - TS_FAIL("CTM class sys, wild, model power8 should have " - "matched system "); - } - - PredicateCTM l_classModelWild(CLASS_NA,TYPE_SYS,MODEL_NA); - if( ! l_classModelWild(l_pTopLevel) ) - { - TS_FAIL("CTM wild, type sys, wild should have " - "matched system "); - } - - PredicateCTM l_classTypeWild(CLASS_NA,TYPE_NA,MODEL_NA); - if( ! l_classTypeWild(l_pTopLevel) ) - { - TS_FAIL("CTM wild, wild, model should have " - "matched system "); - } - - PredicateCTM l_chipClass(CLASS_CHIP,TYPE_NA,MODEL_NA); - if( l_chipClass(l_pTopLevel) ) - { - TS_FAIL("CTM of class chip, wild, wild should not have matched " - "matched system "); - } - -#if 0 // Prove copy CTOR/assignment operator is disabled - PredicateCTM l_ctmLhs; - PredicateCTM l_ctmRhs; - - l_ctmLhs = l_ctmRhs; - - PredicateCTM l_ctmCtor(l_ctmRhs); -#endif - - PredicateBase* l_pBase = new PredicateCTM(CLASS_SYS); - delete l_pBase; - l_pBase = NULL; - - TS_TRACE(EXIT_MRK "testPredicateCtm" ); - - } - - void testPredicatePostfixExpr() - { - TS_TRACE(ENTER_MRK "testPredicatePostfixExpr" ); - - 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) - { - TS_FAIL("Top level handle was NULL when initialization " - "complete"); - } - - PredicatePostfixExpr l_alwaysTrueExpr; - if(!l_alwaysTrueExpr(l_pTopLevel) ) - { - TS_FAIL("Always true filter should have matched system"); - } - -#if 0 - // Triggers NULL assertion check on push - l_alwaysTrueExpr.push(NULL); -#endif - -#if 0 - // Triggers not enough stack elements assertion when evaluating Not - l_alwaysTrueExpr.Not(); - if(l_alwaysTrueExpr(l_pTopLevel) ) - { - TS_FAIL("Negated always true filter should not have matched " - "system"); - } -#endif - -#if 0 - // Triggers illegal target assertion - l_alwaysTrueExpr(NULL); -#endif - -#if 0 - // Triggers formatting assertion - l_alwaysTrueExpr.And(); - l_alwaysTrueExpr(l_pTopLevel); -#endif - -#if 0 - // Triggers formatting assertion - l_alwaysTrueExpr.Or(); - l_alwaysTrueExpr(l_pTopLevel); -#endif - - PredicateCTM l_sysClass(CLASS_SYS); - -#if 0 - // Triggers formatting assertion - l_alwaysTrueExpr.push(&l_sysClass); - l_alwaysTrueExpr.And(); - l_alwaysTrueExpr(l_pTopLevel); -#endif - -#if 0 - // Triggers formatting assertion - l_alwaysTrueExpr.push(&l_sysClass); - l_alwaysTrueExpr.Or(); - l_alwaysTrueExpr(l_pTopLevel); -#endif - -#if 0 - // Triggers illegal formatting exception - // != 1 results on stack - l_alwaysTrueExpr.push(&l_sysClass); - l_alwaysTrueExpr.push(&l_sysClass); - l_alwaysTrueExpr.Not(); - l_alwaysTrueExpr(l_pTopLevel); -#endif - - PredicateCTM l_sysType(CLASS_NA,TYPE_SYS); - PredicateCTM l_power8Model(CLASS_NA,TYPE_NA,MODEL_POWER8); - PredicatePostfixExpr l_expr; - l_expr.push(&l_sysClass).push(&l_sysType).And(); - l_expr.push(&l_power8Model).And(); - - if(!l_expr(l_pTopLevel) ) - { - TS_FAIL("CTM of class sys && type sys && model power8 should " - "have matched system"); - } - - l_expr.Not(); - - if(l_expr(l_pTopLevel) ) - { - TS_FAIL("CTM of class sys && type sys && model power8 should " - "npt have matched system after negation"); - } - - l_expr.push(&l_sysClass); - l_expr.Or(); - - if(!l_expr(l_pTopLevel) ) - { - TS_FAIL("CTM of class sys && type sys && model power8 should " - "have matched system after negation then || sys class"); - } - - PredicatePostfixExpr* l_pExpr = new PredicatePostfixExpr; - l_pExpr->push(&l_sysClass).push(&l_sysType).And(); - l_pExpr->push(&l_power8Model).And(); - delete (static_cast<PredicateBase*>(l_pExpr)); - -#if 0 - PredicatePostfixExpr l_lhs; - PredicatePostfixExpr l_rhs; - - l_lhs = l_rhs; - - PredicatePostfixExpr l_cpCtor(l_rhs); -#endif - - TS_TRACE(EXIT_MRK "testPredicatePostfixExpr" ); - } - - void testTargetIterator() - { - TS_TRACE(ENTER_MRK "testTargetIterator"); - - using namespace TARGETING; - TargetService& l_targetService = targetService(); - - - TargetIterator l_pIt; - if( l_pIt != l_targetService.end() ) - { - TS_FAIL("Default TargetIterator should point to past the end " - "of container"); - } - - ++l_pIt; - if( l_pIt != l_targetService.end() ) - { - TS_FAIL("Default TargetIterator preincremented should point to " - "past the end of container"); - } - - TargetIterator* l_pItNew = new TargetIterator; - delete l_pItNew; - l_pItNew = NULL; - - if(*l_pIt != NULL) - { - TS_FAIL("Default TargetIterator dereference should return NULL"); - } - - // Get top level (system) target to verify at least 1 target - Target* l_pTopLevel = NULL; - (void) l_targetService.getTopLevelTarget(l_pTopLevel); - if (l_pTopLevel == NULL) - { - TS_FAIL("Top level handle was NULL when initialization " - "complete"); - } - - l_pIt = l_targetService.begin(); - if((*l_pIt) == NULL) - { - TS_FAIL("TargetService begin() should return !NULL"); - } - - CLASS l_class = CLASS_NA; - if( !l_pIt->tryGetAttr<ATTR_CLASS>(l_class) ) - { - TS_FAIL("Failed to get expected class attribute"); - } - - TargetIterator l_rhs = l_targetService.begin(); - if( ! (l_pIt == l_rhs) ) - { - TS_FAIL("Iterators should be equal, but aren't"); - } - - l_rhs = l_targetService.begin(); - if( l_pIt != l_rhs ) - { - TS_FAIL("Iterators should be equal, but aren't"); - } - - TargetIterator l_rhs2 = l_targetService.begin(); - ++l_rhs2; - ++l_pIt; - if( l_pIt != l_rhs2 ) - { - TS_FAIL("Iterators should be equal, but aren't"); - } - - l_rhs2++; - l_pIt++; - if( l_pIt != l_rhs2 ) - { - TS_FAIL("Iterators should be equal, but aren't"); - } - - TargetIterator l_pItClone(l_rhs2); - if( l_pIt != l_pItClone) - { - TS_FAIL("Iterators should be equal, but aren't"); - } - - if(l_pIt != l_pItClone++) - { - TS_FAIL("Iterators should be equal, but aren't"); - } - - if( (++l_pIt) != l_pItClone) - { - TS_FAIL("Iterators should be equal, but aren't"); - } - - const TargetService& l_constTargetService = targetService(); - - ConstTargetIterator l_pConstIt; - if( l_pConstIt != l_constTargetService.end() ) - { - TS_FAIL("Default ConstTargetIterator should point to past the " - "end of container"); - } - - l_pConstIt = l_constTargetService.begin(); - if( (*l_pConstIt) == NULL) - { - TS_FAIL("Iterator does not point to valid Target as expected"); - } - - TS_TRACE(EXIT_MRK "testTargetIterator" ); - } - - void testRangeFilter(void) - { - TS_TRACE(ENTER_MRK "testRangeFilters" ); - - using namespace TARGETING; - - TargetRangeFilter* l_pRangeFilter = new TargetRangeFilter( - targetService().begin(), - targetService().end(), - NULL); - delete l_pRangeFilter; - l_pRangeFilter = NULL; - - - TargetRangeFilter l_f1( - targetService().begin(), - targetService().end(), - NULL); - - Target* l_pBegin = (*l_f1); - ++l_f1; - Target* l_pNext = (*l_f1); - if( (l_pBegin == NULL) - || (l_pNext == NULL) - || (l_pBegin == l_pNext) - ) - { - TS_FAIL("Target* pointed to by Begin/next NULL -or- begin ==" - "next"); - } - - l_f1.reset(); - if( *l_f1 != l_pBegin ) - { - TS_FAIL("Target* after reset should be equal to original"); - } - - l_f1.reset(); - TargetRangeFilter l_f2 = l_f1; - PredicateCTM l_ctm(CLASS_SYS,TYPE_CORE); // Nonsense CTM - l_f1.setPredicate(&l_ctm); - if( *l_f1 == l_pBegin ) - { - TS_FAIL("Target* after reset and change of predicate should be" - "different than the original"); - } - - PredicateCTM l_ctm1(CLASS_CHIP,TYPE_PROC); - - TargetRangeFilter l_f3( - targetService().begin(), - targetService().end(), - &l_ctm1); - for(;l_f3;++l_f3) - { - if(l_f3->getAttr<ATTR_TYPE>() != TYPE_PROC) - { - TS_FAIL("Should only have returned type proc"); - break; - } - } - - TargetIterator l_pIt = targetService().begin(); - ++l_pIt; - ++l_pIt; - - if(l_pIt == targetService().end()) - { - TS_FAIL("Not enough elements for test"); - } - - TargetRangeFilter l_partial( - targetService().begin(), - l_pIt, - NULL); - int i=0; - - for(; l_partial; ++l_partial) - { - i++; - } - - if(i != 2) - { - TS_FAIL("Should have gotten 2 elements %d",i); - } - - TS_TRACE(EXIT_MRK "testRangeFilter" ); - } - - void testComplexFilter(void) - { - TS_TRACE(ENTER_MRK "testComplexFilter" ); - - using namespace TARGETING; - - TargetService& l_targetService = targetService(); - - TargetRangeFilter f(l_targetService.begin(), - l_targetService.end(), - NULL); - int l_count = 0; - for(; f; ++f, l_count++) - { - } - - TS_TRACE(INF_MRK "Found %d total targets", l_count); - - PredicateCTM l_procs(CLASS_CHIP); - PredicateCTM l_enclosures(CLASS_ENC); - PredicatePostfixExpr l_query; - l_query.push(&l_procs).push(&l_enclosures).Or(); - - f.setPredicate(&l_query); - f.reset(); - - l_count = 0; - for(; f; ++f, ++l_count) - { - EntityPath l_path = f->getAttr<ATTR_PHYS_PATH>(); - l_path.dump(); - } - - TS_TRACE(INF_MRK "Found %d targets that are chips or enclosures ", - l_count); - - l_query.Not(); - f.reset(); - - l_count = 0; - for(; f; ++f, ++l_count) - { - } - - TS_TRACE(INF_MRK "Found %d targets that are not chips or " - "enclosures",l_count); - - Target* l_pMasterProcChipTargetHandle = NULL; - (void) l_targetService.masterProcChipTargetHandle( - l_pMasterProcChipTargetHandle); - if(l_pMasterProcChipTargetHandle == NULL) - { - TS_FAIL("Master processor chip target not found"); - } - - PredicateCTM l_ex(CLASS_UNIT,TYPE_EX); - PredicateCTM l_mba(CLASS_UNIT,TYPE_MBA); - PredicatePostfixExpr l_procquery; - l_procquery.push(&l_ex).push(&l_mba).Or(); - - TargetHandleList l_list; - (void) targetService().getAssociated( - l_list, - l_pMasterProcChipTargetHandle, - TARGETING::TargetService::CHILD, - TARGETING::TargetService::ALL, - &l_procquery); - - l_count = 0; - for(uint32_t i=0; i<l_list.size(); ++i, ++l_count) - { - EntityPath l_path = l_list[i]->getAttr<ATTR_PHYS_PATH>(); - l_path.dump(); - } - - TS_TRACE(INF_MRK "Found %d targets that are ex/mba units off " - "master processor",l_count); - - TS_TRACE(EXIT_MRK "testComplexFilter" ); - } - - void testFapiToHbMacros () - { - TS_TRACE(ENTER_MRK "testFapiToHbMacros" ); - - TS_TRACE(INF_MRK "Now using direct access macros"); - - using namespace TARGETING; - using namespace fapi; - - TargetService& l_targetService = targetService(); - - TARGETING::Target* l_pTarget = NULL; - (void) l_targetService.getTopLevelTarget(l_pTarget); - if (l_pTarget == NULL) - { - TS_FAIL("Top level handle was NULL when initialization " - "complete"); - } - - DUMMY_RW_ATTR l_dummyRw; - memset(l_dummyRw,0x00,sizeof(l_dummyRw)); - l_pTarget->tryGetAttr<TARGETING::ATTR_DUMMY_RW>(l_dummyRw); - if(l_dummyRw[0][1][2] != 5) - { - TS_FAIL("l_dummyRw value is %d, not 5 as expected in direct " - "attribute access",l_dummyRw[0][1][2]); - } - - TARGETING::CLASS l_class = - l_pTarget->getAttr<TARGETING::ATTR_CLASS>(); - if(l_class != TARGETING::CLASS_SYS) - { - TS_FAIL("l_class value is %d, not %d as expected in direct " - "attribute access",l_class,TARGETING::CLASS_SYS); - } - - TARGETING::TYPE l_type = l_pTarget->getAttr<TARGETING::ATTR_TYPE>(); - if(l_type != TARGETING::TYPE_SYS) - { - TS_FAIL("l_type value is %d, not %d as expected in direct " - "attribute access",l_type,TARGETING::TYPE_SYS); - } - - uint64_t l_xscom = - l_pTarget->getAttr<TARGETING::ATTR_XSCOM_BASE_ADDRESS>(); - if(l_xscom != 0x300000000000) - { - TS_FAIL("l_xscom value is %x, not %x as expected in direct " - "attribute access",l_xscom,0x300000000000); - } - - TS_TRACE(INF_MRK "Now using FAPI get macros"); - - memset(l_dummyRw,0x00,sizeof(l_dummyRw)); - fapi::ReturnCode l_rc = FAPI_ATTR_GET( - ATTR_DUMMY_SCRATCH_PLAT_INIT_UINT8, NULL, l_dummyRw); - if(l_rc != 0) - { - TS_FAIL("Failed to get dummy RW attribute on system target"); - } - - if(l_dummyRw[0][2][4] != 5) - { - TS_FAIL("l_dummyRw value is %d, not 5 as expected", - l_dummyRw[0][2][4]); - } - - TS_TRACE(INF_MRK "Now using FAPI set macros"); - - l_dummyRw[0][2][3] = 6; - l_rc = FAPI_ATTR_SET(ATTR_DUMMY_SCRATCH_PLAT_INIT_UINT8, NULL, - l_dummyRw); - if(l_rc != 0) - { - TS_FAIL("Failed to write dummy RW attribute on system target"); - } - - memset(l_dummyRw,0x00,sizeof(l_dummyRw)); - l_rc = FAPI_ATTR_GET(ATTR_DUMMY_SCRATCH_PLAT_INIT_UINT8, NULL, - l_dummyRw); - if(l_rc != 0) - { - TS_FAIL("Failed to get dummy RW attribute on system target"); - } - - if(l_dummyRw[0][2][3] != 6) - { - TS_FAIL("l_dummyRw value is %d, not 6 as expected due to a " - "prior write",l_dummyRw[0][2][3]); - } - - TS_TRACE(INF_MRK "Now using targets without the attribute"); - - memset(l_dummyRw,0x00,sizeof(l_dummyRw)); - EntityPath l_realPath(EntityPath::PATH_PHYSICAL); - l_realPath.addLast(TYPE_SYS,0).addLast(TYPE_NODE,0); - l_pTarget = l_realPath.operator->(); - if (l_pTarget == NULL) - { - TS_FAIL("Node 0 target handle should not be NULL"); - } - - fapi::Target* l_pFapiTarget = new fapi::Target( - fapi::TARGET_TYPE_PROC_CHIP, l_pTarget); - l_rc = FAPI_ATTR_GET(ATTR_DUMMY_SCRATCH_PLAT_INIT_UINT8, - l_pFapiTarget , l_dummyRw); - if(l_rc == 0) - { - TS_FAIL("Should have failed getting the attribute on " - "non-supporting target"); - } - else if(l_rc != FAPI_RC_PLAT_ERR_SEE_DATA) - { - TS_FAIL("Should have been a platform handled error"); - } - - // The error log will get deleted when the ReturnCode is destructed. The - // error log is not committed here to avoid it getting interpreted as a - // real problem - - delete l_pFapiTarget; - l_pFapiTarget = NULL; - - TS_TRACE(EXIT_MRK "testFapiToHbMacros" ); - } - - void testFapiAttributes () - { - TS_TRACE(ENTER_MRK "testFapiAttributes" ); - - using namespace TARGETING; - using namespace fapi; - - fapi::ReturnCode l_rc; - - //---------------------------------------------------------------------- - // Test ATTR_MSS_EFF_PRIMARY_RANK - //---------------------------------------------------------------------- - -// @TODO ATTR_MSS_EFF_PRIMARY_RANK - Enable once we pull in XML file with this attribute. -#if ATTR_MSS_EFF_PRIMARY_RANK - // Find all MBA's in this system - PredicateCTM l_mba_pred(CLASS_UNIT,TYPE_MBA); - TargetRangeFilter l_mba_filter( - targetService().begin(), - targetService().end(), - &l_mba_pred); - // Loop through all MBA's and validate the attribute - for(;l_mba_filter;++l_mba_filter) - { - if(l_mba_filter->getAttr<ATTR_TYPE>() != TYPE_MBA) - { - TS_FAIL("Should only have returned type MBA!"); - break; - } - else - { - uint8_t l_uint8_mss_eff_primary_rank[4][4]; - - fapi::Target* l_pFapiTarget = new fapi::Target(TARGET_TYPE_MBA_CHIPLET, *l_mba_filter); - - // Test get - l_rc = FAPI_ATTR_GET(ATTR_MSS_EFF_PRIMARY_RANK, l_pFapiTarget,l_uint8_mss_eff_primary_rank); - if (l_rc) - { - TS_FAIL("hwpTestAttributes: ATTR_MSS_EFF_PRIMARY_RANK. Error from GET"); - break; - } - - // Test set - l_rc = FAPI_ATTR_SET(ATTR_MSS_EFF_PRIMARY_RANK, l_pFapiTarget, l_uint8_mss_eff_primary_rank); - if (l_rc) - { - TS_FAIL("hwpTestAttributes: ATTR_MSS_EFF_PRIMARY_RANK. Error from SET"); - break; - } - - delete l_pFapiTarget; - l_pFapiTarget = NULL; - TS_TRACE("hwpTestAttributes: Test of ATTR_MSS_EFF_PRIMARY_RANK Passed!"); - } - } -#endif - TS_TRACE(EXIT_MRK "testFapiAttributes" ); - - if(l_rc) - { - errlHndl_t l_pErrLog = static_cast<ERRORLOG::ErrlEntry*>(l_rc.releasePlatData()); - ERRORLOG::errlCommit(l_pErrLog,TARG_COMP_ID); - } - } - - void testPodNumericalTypes() - { - TS_TRACE(ENTER_MRK "testPodNumericalTypes" ); - - using namespace TARGETING; - using namespace fapi; - - TargetService& l_targetService = targetService(); - - TARGETING::Target* l_pTarget = NULL; - (void) l_targetService.getTopLevelTarget(l_pTarget); - if (l_pTarget == NULL) - { - TS_FAIL("Top level handle was NULL when initialization " - "complete"); - } - - NUMERIC_POD_TYPE_TEST_ATTR l_pod; - memset(&l_pod,0x00,sizeof(l_pod)); - if(!l_pTarget->tryGetAttr<TARGETING::ATTR_NUMERIC_POD_TYPE_TEST>(l_pod)) - { - TS_FAIL("Numeric POD type not found"); - } - if( (l_pod.fsiPath.type() != EntityPath::PATH_PHYSICAL) - || (l_pod.fsiPath[0].type != TYPE_SYS) - || (l_pod.fsiPath[0].instance != 0) - || (l_pod.fsiPath.size() != 1 ) ) - { - TS_FAIL("Expected physical:sys-0, got a different result"); - - } - if(l_pod.className != CLASS_CHIP) - { - TS_FAIL("Expected CLASS value of 0x%08X, got 0x%08X", - CLASS_CHIP,l_pod.className); - } - if(l_pod.uint8 != 0xAB) - { - TS_FAIL("Expected uint8_t value of 0xAB, got 0x%02X", - l_pod.uint8); - } - if (l_pod.uint16 != 0xABCD) - { - TS_FAIL("Expected uint16_t value of 0xABCD, got 0x%04X", - l_pod.uint16); - } - if (l_pod.uint32 != 0xABCDEF01) - { - TS_FAIL("Expected uint32_t value of 0xABCDEF01, got 0x%08X", - l_pod.uint32); - } - if (l_pod.uint64 != 0xABCDEF0123456789ULL) - { - TS_FAIL("Expected uint64_t value of 0xABCDEF0123456789, got 0x%016lX", - l_pod.uint64); - } - if(l_pod.int8 != -124) - { - TS_FAIL("Expected int8_t value of -124, got %d", - l_pod.int8); - } - if (l_pod.int16 != -32764) - { - TS_FAIL("Expected int16_t value of -32764, got %d", - l_pod.int16); - } - if (l_pod.int32 != -2147483644) - { - TS_FAIL("Expected int32_t value of -2147483644, got %d", - l_pod.int32); - } - if (l_pod.int64 != -9223372036854775804LL) - { - TS_FAIL("Expected int64_t value of -9223372036854775804, got %ld", - l_pod.int64); - } - - TS_TRACE(EXIT_MRK "testPodNumericalTypes" ); - } - - void testCentaurs() - { - TS_TRACE(ENTER_MRK "testCentaurs" ); - - using namespace TARGETING; - - PredicateCTM l_procChip(CLASS_CHIP,TYPE_PROC,MODEL_VENICE); - TargetRangeFilter l_filter( - targetService().begin(), - targetService().end(), - &l_procChip); - - PredicateCTM l_mbs(CLASS_UNIT,TYPE_MBS); - uint32_t l_count = 0; - uint32_t l_procs = 0; - - // For each processor - for(;l_filter;++l_filter) - { - l_procs++; - - TargetHandleList l_list; - (void) targetService().getAssociated( - l_list, - *l_filter, - TARGETING::TargetService::CHILD_BY_AFFINITY, - TARGETING::TargetService::ALL, - &l_mbs); - l_count += l_list.size(); - } - - if(l_procs) - { - if(l_count <= 0) - { - TS_FAIL("Did not find any Centaur chips connected to processors"); - } - else - { - TS_TRACE("Found %d Centaur chips connected to processors",l_count); - } - } - - TS_TRACE(EXIT_MRK "testCentaurs" ); - } - - void testHbMutexAttr() - { - TS_TRACE(ENTER_MRK "testHbMutexAttr" ); - - using namespace TARGETING; - using namespace fapi; - - do { - - // Get a reference to the target service - TargetService& l_targetService = targetService(); - - // Get the system target containing the test mutex - TARGETING::Target* l_pTarget = NULL; - (void) l_targetService.getTopLevelTarget(l_pTarget); - if (l_pTarget == NULL) - { - TS_FAIL("Top level target handle is NULL"); - break; - } - - // Get the mutex attribute (actually a mutex_t* which points to - // a mutex) - HB_MUTEX_TEST_LOCK_ATTR l_pLock - = l_pTarget->getHbMutexAttr<TARGETING::ATTR_HB_MUTEX_TEST_LOCK>(); - - // Test: Verify the value pointed to by the mutex_t* is zero - if ( (*reinterpret_cast<uint64_t*>(l_pLock)) != 0) - { - TS_FAIL("Mutex attribute must be initialized to zero, but got %ld", - *reinterpret_cast<uint64_t*>(l_pLock)); - break; - } - - // Try to get the attribute, and ensure it's the same - HB_MUTEX_TEST_LOCK_ATTR l_pLockTry = NULL; - if(l_pTarget->tryGetHbMutexAttr<TARGETING::ATTR_HB_MUTEX_TEST_LOCK> - (l_pLockTry)) - { - if(l_pLockTry != l_pLock) - { - TS_FAIL("Mutex attributes should match, but dont. " - "l_pLockTry = %ld, l_pLock = %ld",l_pLockTry, - l_pLock); - break; - } - } - else - { - TS_FAIL("Mutex attribute tryGet failed, even though it exists"); - break; - } - - // Create a structue holding pointers to the mutex and a protected value - volatile uint32_t l_var = 0; - (void)mutex_lock(l_pLock); - barrier_t l_barrier; - (void)barrier_init(&l_barrier, 2); - MutexTestData_t l_mutexTestData = { l_pLock, &l_barrier, &l_var }; - - // Spawn off a function which tries to write the protected value to - // something unexpected. If the mutex is working, the for loop will - // always poll the expected value. - task_create(funcTestMutex, static_cast<void*>(&l_mutexTestData)); - - // Guarantee the child process runs and blocks on the mutex prior to - // modifying the protected value. isync to ensure the processor doesn't - // speculatively perform the comparison prior to the sleep completing - barrier_wait(&l_barrier); - nanosleep(0,TEN_CTX_SWITCHES_NS); isync(); - - if(l_var != 0) - { - TS_FAIL("Protected value must be 0, was %d instead",l_var); - break; - } - - // Now unlock the mutex, allowing the other thread to overwrite the - // protected value; which should happen within 100,000 reads of the - // var. This will confirm the other thread was actively trying to - // write the controlled value - (void)mutex_unlock(l_pLock); - - // Guarantee the child process acquires the mutex and modifies the - // protected value. - barrier_wait(&l_barrier); - - if(l_var != 1) - { - TS_FAIL("Protected value must now be 1, was %d instead",l_var); - break; - } - - barrier_destroy(&l_barrier); - - } while(0); - - TS_TRACE(EXIT_MRK "testHbMutexAttr"); - } - - void testErrlTargetFFDC() - { - TS_TRACE(ENTER_MRK "testErrlTargetFFDC" ); - - using namespace ERRORLOG; - using namespace TARGETING; - using namespace fapi; - - // Get a reference to the target service - TargetService& l_service = targetService(); - - // Get the master proc target - TARGETING::Target* l_pTarget1 = NULL; - TARGETING::Target* l_pTarget2 = MASTER_PROCESSOR_CHIP_TARGET_SENTINEL; - l_service.masterProcChipTargetHandle( l_pTarget1); - - // Create an errorlog to test FFDC capture of targets - /*@ - * @errortype - * @severity ERRORLOG_SEV_INFORMATIONAL - * @moduleid TARG_MOD_TEST - * @reasoncode TARG_RC_TEST_TARGET_FFDC - * @userdata1 Test data 1 - * @userdata2 Test data 2 - * @devdesc User Details unit test - create target user detail data - */ - errlHndl_t l_err; - l_err = new ErrlEntry(ERRL_SEV_INFORMATIONAL, - TARG_MOD_TEST, - TARG_RC_TEST_TARGET_FFDC, - 0x0011223344556677, - 0x8899aabbccddeeff); - - ErrlUserDetailsTarget(l_pTarget1).addToLog(l_err); - ErrlUserDetailsTarget(l_pTarget2).addToLog(l_err); - - errlCommit(l_err, CXXTEST_COMP_ID); - - TS_TRACE(EXIT_MRK "testErrlTargetFFDC"); - } - - /** - * @test Tests string attributes - */ - void testStringAttributes(void) - { - TS_TRACE(ENTER_MRK "testStringAttributes" ); - - using namespace TARGETING; - - do { - - TargetService& l_targetService = targetService(); - - // Get the top level target for the string attribute tests - Target* l_pTopLevel = NULL; - (void) l_targetService.getTopLevelTarget(l_pTopLevel); - if (l_pTopLevel == NULL) - { - TS_FAIL("ERROR: Can not find top level target; bypassing " - "remaining string attribute tests"); - break; - } - - // TC1: Test NULL string attribute - // TC1.1: String storage size must match the stated size - ATTR_TEST_NULL_STRING_type l_nullStringReference = {0}; - ATTR_TEST_NULL_STRING_type l_nullString = {0}; - if(sizeof(l_nullString) != ATTR_TEST_NULL_STRING_max_chars+1) - { - TS_FAIL("ERROR: l_nullString size (%d) " - "does not match stated size (%d)", - sizeof(l_nullString), - ATTR_TEST_NULL_STRING_max_chars+1); - } - - // TC1.2: String size must be non-zero - if(sizeof(l_nullString) == 0) - { - TS_FAIL("ERROR: l_nullString size is zero"); - } - - // TC1.3: Must be able to read the string - if(!l_pTopLevel->tryGetAttr<ATTR_TEST_NULL_STRING>(l_nullString)) - { - TS_FAIL("ERROR: Can not read l_nullString attribute"); - } - - // TC1.4: All bytes of the string must match the reference version - if(memcmp(l_nullStringReference, - l_nullString, - sizeof(l_nullStringReference))) - { - TS_FAIL("ERROR: l_nullString bytes do not match the reference" - "version"); - TARG_BIN("Expected (l_nullStringReference)", - l_nullStringReference,sizeof(l_nullStringReference)); - TARG_BIN("Actual (l_nullString)", - l_nullString,sizeof(l_nullString)); - } - - // TC1.5: String must equal the empty string by string comparison - if(strcmp(l_nullString,"") != 0) - { - TS_FAIL("ERROR: l_nullString does not strcmp to the empty string"); - TARG_BIN("Actual (l_nullString)", - l_nullString,sizeof(l_nullString)); - } - - // TC2: Test string attribute with only 1 character - // TC2.1: String storage size must match the stated size - ATTR_TEST_MIN_STRING_type l_minStringReference = {0}; - l_minStringReference[0] = 'Z'; - ATTR_TEST_MIN_STRING_type l_minString = {0}; - if(sizeof(l_minString) != ATTR_TEST_MIN_STRING_max_chars+1) - { - TS_FAIL("ERROR: l_minString size (%d) " - "does not match stated size (%d)", - sizeof(l_minString), - ATTR_TEST_MIN_STRING_max_chars+1); - } - - // TC2.2: String size must be non-zero - if(sizeof(l_minString) == 0) - { - TS_FAIL("ERROR: l_minString size is zero"); - } - - // TC2.3: Must be able to read the string - if(!l_pTopLevel->tryGetAttr<ATTR_TEST_MIN_STRING>(l_minString)) - { - TS_FAIL("ERROR: Can not read l_minString attribute"); - } - - // TC2.4: All bytes in string must match the reference string - if(memcmp(l_minStringReference, - l_minString, - sizeof(l_minStringReference))) - { - TS_FAIL("ERROR l_minString bytes do not match the reference " - "version"); - TARG_BIN("Expected (l_minStringReference)", - l_minStringReference,sizeof(l_minStringReference)); - TARG_BIN("Actual (l_minString)", - l_minString,sizeof(l_minString)); - } - - // TC2.5: String must equal "Z" by comparison - if(strcmp(l_minString,l_minStringReference) != 0) - { - TS_FAIL("ERROR l_minString does not strcmp to the reference " - "string"); - TARG_BIN("Actual (l_minString)", - l_minString,sizeof(l_minString)); - } - - // TC3: Test string with maximum number of characters (including NULL) - // TC3.1: String storage size must match the stated size - ATTR_TEST_MAX_STRING_type l_maxStringReference = {0}; - l_maxStringReference[0] = 'a'; - l_maxStringReference[1] = 'b'; - l_maxStringReference[2] = 'c'; - ATTR_TEST_MAX_STRING_type l_maxString = {0}; - if(sizeof(l_maxString) != ATTR_TEST_MAX_STRING_max_chars+1) - { - TS_FAIL("ERROR: l_maxString size (%d) " - "does not match stated size (%d)", - sizeof(l_maxString), - ATTR_TEST_MAX_STRING_max_chars+1); - } - - // TC3.2: String storage size must be non-zero - if(sizeof(l_maxString) == 0) - { - TS_FAIL("ERROR: l_maxString storage size is zero"); - } - - // TC3.3: Must be able to read the string - if(!l_pTopLevel->tryGetAttr<ATTR_TEST_MAX_STRING>(l_maxString)) - { - TS_FAIL("ERROR: Could not read l_maxString"); - } - - // TC3.4: All bytes in string must match the reference - if(memcmp(l_maxStringReference, - l_maxString, - sizeof(l_maxStringReference))) - { - TS_FAIL("ERROR: l_maxString bytes do not match the reference " - "version"); - TARG_BIN("Expected (l_maxStringReference)", - l_maxStringReference,sizeof(l_maxStringReference)); - TARG_BIN("Actual (l_maxString)", - l_maxString,sizeof(l_maxString)); - } - - // TC3.5: String must equal "abc" by comparison - if(strcmp(l_maxString,l_maxStringReference) != 0) - { - TS_FAIL("ERROR: l_maxString does not strcmp to the reference " - "string"); - TARG_BIN("Actual (l_maxString)", - l_maxString,sizeof(l_maxString)); - } - - // TC4: Test string with no supplied default value - // TC4.1: String storage size must match stated size - ATTR_TEST_NO_DEFAULT_STRING_type l_noDefaultStringReference = {0}; - ATTR_TEST_NO_DEFAULT_STRING_type l_noDefaultString = {0}; - if(sizeof(l_noDefaultString) != ATTR_TEST_NO_DEFAULT_STRING_max_chars+1) - { - TS_FAIL("ERROR: l_noDefaultString size (%d) " - "does not match stated size (%d)", - sizeof(l_noDefaultString), - ATTR_TEST_NO_DEFAULT_STRING_max_chars+1); - } - - // TC4.2: String storage size must be non-zero - if(sizeof(l_noDefaultString) == 0) - { - TS_FAIL("ERROR: l_noDefaultString storage size is zero"); - } - - // TC4.3: Must be able to read the string - if(!l_pTopLevel->tryGetAttr<ATTR_TEST_NO_DEFAULT_STRING>( - l_noDefaultString)) - { - TS_FAIL("ERROR: Could not read l_noDefaultString"); - } - - // TC4.4: All bytes in string must match the reference - if(memcmp(l_noDefaultStringReference, - l_noDefaultString, - sizeof(l_noDefaultStringReference))) - { - TS_FAIL("ERROR: l_noDefaultString bytes do not match the " - "reference"); - TARG_BIN("Expected (l_noDefaultStringReference)", - l_noDefaultStringReference, - sizeof(l_noDefaultStringReference)); - TARG_BIN("Actual (l_noDefaultString)", - l_noDefaultString,sizeof(l_noDefaultString)); - } - - // TC4.5: String must equal empty string by comparison - if(strcmp(l_noDefaultString,l_noDefaultStringReference) != 0) - { - TS_FAIL("ERROR: l_noDefaultString does not strcmp to the reference " - "string"); - TARG_BIN("Actual (l_noDefaultString)", - l_noDefaultString,sizeof(l_noDefaultString)); - } - - // TC5: Write string and read back - // TC5.1: Must be able to write the string - ATTR_TEST_NO_DEFAULT_STRING_type l_writeString = {0}; - strcpy(l_writeString,"aabbcc"); - if(!l_pTopLevel->trySetAttr<ATTR_TEST_NO_DEFAULT_STRING>(l_writeString)) - { - TS_FAIL("ERROR: Could not write l_writeString"); - } - - ATTR_TEST_NO_DEFAULT_STRING_type l_readString = {0}; - if(!l_pTopLevel->tryGetAttr<ATTR_TEST_NO_DEFAULT_STRING>(l_readString)) - { - TS_FAIL("ERROR: Could not read l_readString"); - } - - if(strcmp(l_writeString,l_readString) != 0) - { - TS_FAIL("ERROR: String does not match what was written"); - TARG_BIN("Expected (l_writeString)", - l_writeString, - sizeof(l_writeString)); - TARG_BIN("Actual (l_readString)", - l_readString, - sizeof(l_readString)); - } - - } while(0); - - TS_TRACE(EXIT_MRK "testStringAttributes" ); - } - - - void testDump() - { - //fixme-remove this completely when RTC:38386 is done - //TARGETING::dumpAllAttributes(g_trac_targeting); - } -}; - -#endif // End __TESTTARGETING_H diff --git a/src/usr/targeting/test/testtargeting.H b/src/usr/targeting/test/testtargeting.H new file mode 100644 index 000000000..a3c6232ea --- /dev/null +++ b/src/usr/targeting/test/testtargeting.H @@ -0,0 +1,245 @@ +// IBM_PROLOG_BEGIN_TAG +// This is an automatically generated prolog. +// +// $Source: src/usr/targeting/test/testtargeting.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 + +#ifndef __TARGETING_TESTTARGETING_H +#define __TARGETING_TESTTARGETING_H + +/** + * @file targeting/test/testtargeting.H + * + * @brief All unit tests which test targeting in a platform specific way + */ + +//****************************************************************************** +// Includes +//****************************************************************************** + +// STD +#include <stdio.h> +#include <sys/time.h> + +// CXXTEST +#include <cxxtest/TestSuite.H> +#include <hwpf/plat/fapiPlatAttributeService.H> +#include <fapiReturnCode.H> +#include <fapiAttributeIds.H> +#include <fapiAttributeService.H> +#include <errl/errlmanager.H> +#include <sys/sync.h> +#include <sys/task.h> +#include <sys/time.h> + +// This component +#include <targeting/common/attributes.H> +#include <targeting/common/entitypath.H> +#include <targeting/common/target.H> +#include <targeting/common/targetservice.H> +#include <targeting/common/iterators/rangefilter.H> +#include <targeting/common/predicates/predicatectm.H> +#include <targeting/common/predicates/predicatepostfixexpr.H> +#include <targeting/common/targreasoncodes.H> +#include <errl/errludtarget.H> +#include <targeting/common/trace.H> +#include <kernel/console.H> + +/** + * @brief Struct to hold pointers to a mutex / protected value + */ +struct MutexTestData_t +{ + mutex_t* pMutex; // Pointer to mutex + barrier_t* pBarrier; // Pointer to barrier + volatile uint32_t* pVar; // Pointer to value protected by mutex +}; + +/** + * @brief Function which attempts to write a protected variable + * + * @param[in] i_pData Pointer to mutex pointer/value pointer structure + * + * @return N/A + */ +void funcTestMutex(void* i_pData) +{ + MutexTestData_t* l_pData = static_cast<MutexTestData_t*>(i_pData); + barrier_wait(l_pData->pBarrier); + mutex_lock(l_pData->pMutex); + *(l_pData->pVar) = 1; + mutex_unlock(l_pData->pMutex); + barrier_wait(l_pData->pBarrier); + task_end(); +} + +class TargetingTestSuite : public CxxTest::TestSuite +{ + public: + + /** + * @brief Test Hostboot specific mutex attribute support + */ + void testHbMutexAttr() + { + TS_TRACE(ENTER_MRK "testHbMutexAttr" ); + + using namespace TARGETING; + using namespace fapi; + + do { + + // Get a reference to the target service + TargetService& l_targetService = targetService(); + + // Get the system target containing the test mutex + TARGETING::Target* l_pTarget = NULL; + (void) l_targetService.getTopLevelTarget(l_pTarget); + if (l_pTarget == NULL) + { + TS_FAIL("Top level target handle is NULL"); + break; + } + + // Get the mutex attribute (actually a mutex_t* which points to + // a mutex) + HB_MUTEX_TEST_LOCK_ATTR l_pLock + = l_pTarget->getHbMutexAttr<TARGETING::ATTR_HB_MUTEX_TEST_LOCK>(); + + // Test: Verify the value pointed to by the mutex_t* is zero + if ( (*reinterpret_cast<uint64_t*>(l_pLock)) != 0) + { + TS_FAIL("Mutex attribute must be initialized to zero, but got %ld", + *reinterpret_cast<uint64_t*>(l_pLock)); + break; + } + + // Try to get the attribute, and ensure it's the same + HB_MUTEX_TEST_LOCK_ATTR l_pLockTry = NULL; + if(l_pTarget->tryGetHbMutexAttr<TARGETING::ATTR_HB_MUTEX_TEST_LOCK> + (l_pLockTry)) + { + if(l_pLockTry != l_pLock) + { + TS_FAIL("Mutex attributes should match, but dont. " + "l_pLockTry = %ld, l_pLock = %ld",l_pLockTry, + l_pLock); + break; + } + } + else + { + TS_FAIL("Mutex attribute tryGet failed, even though it exists"); + break; + } + + // Create a structue holding pointers to the mutex and a protected value + volatile uint32_t l_var = 0; + (void)mutex_lock(l_pLock); + barrier_t l_barrier; + (void)barrier_init(&l_barrier, 2); + MutexTestData_t l_mutexTestData = { l_pLock, &l_barrier, &l_var }; + + // Spawn off a function which tries to write the protected value to + // something unexpected. If the mutex is working, the for loop will + // always poll the expected value. + task_create(funcTestMutex, static_cast<void*>(&l_mutexTestData)); + + // Guarantee the child process runs and blocks on the mutex prior to + // modifying the protected value. isync to ensure the processor doesn't + // speculatively perform the comparison prior to the sleep completing + barrier_wait(&l_barrier); + nanosleep(0,TEN_CTX_SWITCHES_NS); isync(); + + if(l_var != 0) + { + TS_FAIL("Protected value must be 0, was %d instead",l_var); + break; + } + + // Now unlock the mutex, allowing the other thread to overwrite the + // protected value; which should happen within 100,000 reads of the + // var. This will confirm the other thread was actively trying to + // write the controlled value + (void)mutex_unlock(l_pLock); + + // Guarantee the child process acquires the mutex and modifies the + // protected value. + barrier_wait(&l_barrier); + + if(l_var != 1) + { + TS_FAIL("Protected value must now be 1, was %d instead",l_var); + break; + } + + barrier_destroy(&l_barrier); + + } while(0); + + TS_TRACE(EXIT_MRK "testHbMutexAttr"); + } + + /** + * @brief Test Hostboot specific error target FFDC support + */ + void testErrlTargetFFDC() + { + TS_TRACE(ENTER_MRK "testErrlTargetFFDC" ); + + using namespace ERRORLOG; + using namespace TARGETING; + using namespace fapi; + + // Get a reference to the target service + TargetService& l_service = targetService(); + + // Get the master proc target + TARGETING::Target* l_pTarget1 = NULL; + TARGETING::Target* l_pTarget2 = MASTER_PROCESSOR_CHIP_TARGET_SENTINEL; + l_service.masterProcChipTargetHandle( l_pTarget1); + + // Create an errorlog to test FFDC capture of targets + /*@ + * @errortype + * @severity ERRORLOG_SEV_INFORMATIONAL + * @moduleid TARG_MOD_TEST + * @reasoncode TARG_RC_TEST_TARGET_FFDC + * @userdata1 Test data 1 + * @userdata2 Test data 2 + * @devdesc User Details unit test - create target user detail data + */ + errlHndl_t l_err; + l_err = new ErrlEntry(ERRL_SEV_INFORMATIONAL, + TARG_MOD_TEST, + TARG_RC_TEST_TARGET_FFDC, + 0x0011223344556677, + 0x8899aabbccddeeff); + + ErrlUserDetailsTarget(l_pTarget1).addToLog(l_err); + ErrlUserDetailsTarget(l_pTarget2).addToLog(l_err); + + errlCommit(l_err, TARG_COMP_ID); + + TS_TRACE(EXIT_MRK "testErrlTargetFFDC"); + } +}; + +#endif // End __TARGETING_TESTTARGETING_H diff --git a/src/usr/targeting/test/unittestadapter.H b/src/usr/targeting/test/unittestadapter.H new file mode 100644 index 000000000..781b837e5 --- /dev/null +++ b/src/usr/targeting/test/unittestadapter.H @@ -0,0 +1,45 @@ +// IBM_PROLOG_BEGIN_TAG +// This is an automatically generated prolog. +// +// $Source: src/usr/targeting/test/unittestadapter.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 + +#ifndef _TARGETING_UNITTESTADAPTER_H +#define _TARGETING_UNITTESTADAPTER_H + +/** + * @file targeting/test/unittestadapter.H + * + * @brief Header file which pulls in platform specific CXX testcase headers + */ + +//****************************************************************************** +// Includes +//****************************************************************************** + +#include <cxxtest/TestSuite.H> + +// Just forward common API call to platform specific call +#define TARG_TS_TRACE TS_TRACE + +// Just forward common API call to platform specific call +#define TARG_TS_FAIL TS_FAIL + +#endif // _TARGETING_UNITTESTADAPTER_H |