/* IBM_PROLOG_BEGIN_TAG */ /* This is an automatically generated prolog. */ /* */ /* $Source: src/usr/devicefw/test/associatortest.H $ */ /* */ /* OpenPOWER HostBoot Project */ /* */ /* Contributors Listed Below - COPYRIGHT 2011,2018 */ /* [+] International Business Machines Corp. */ /* */ /* */ /* Licensed under the Apache License, Version 2.0 (the "License"); */ /* you may not use this file except in compliance with the License. */ /* You may obtain a copy of the License at */ /* */ /* http://www.apache.org/licenses/LICENSE-2.0 */ /* */ /* Unless required by applicable law or agreed to in writing, software */ /* distributed under the License is distributed on an "AS IS" BASIS, */ /* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or */ /* implied. See the License for the specific language governing */ /* permissions and limitations under the License. */ /* */ /* IBM_PROLOG_END_TAG */ #ifndef __TEST_ASSOCIATORTEST_H #define __TEST_ASSOCIATORTEST_H #include #include #include #include "../associator.H" using namespace DeviceFW; using namespace TARGETING; class AssociatorTest; typedef void (AssociatorTest::*test_fn)(); static test_fn g_associatorTest_value; static test_fn g_associatorTest_result; static OperationType g_associatorTest_opType; static int64_t g_associatorTest_accessType; class AssociatorTest: public CxxTest::TestSuite { public: /** * @test Ensure AssociationContainer can be constructed. */ void testConstruct() { Associator* as = new Associator(); if (NULL == as) { TS_FAIL("Unable to construct Associator."); } delete as; } // Used for registration testing. static errlHndl_t performOperation(OperationType i_opType, Target* i_target, void* io_buffer, size_t& io_buflen, int64_t i_accessType, va_list i_addr) { g_associatorTest_result = g_associatorTest_value; g_associatorTest_opType = i_opType; g_associatorTest_accessType = i_accessType; return NULL; } /** * @test Verify simple registration. */ void testSimpleRegistration() { void* buf = NULL; size_t bufsize = 0; g_associatorTest_value = &AssociatorTest::testSimpleRegistration; Associator as; as.registerRoute(READ, SCOM, TYPE_PROC, &performOperation); errlHndl_t l_errl = as.performOp(READ, MASTER_PROCESSOR_CHIP_TARGET_SENTINEL, buf, bufsize, SCOM, va_list()); if (l_errl) { TS_FAIL("Error received from performOp."); } if (g_associatorTest_result != g_associatorTest_value) { TS_FAIL("PerformOperation does not appear to have been called."); } if (g_associatorTest_opType != READ) { TS_FAIL("Invalid operation type."); } if (g_associatorTest_accessType != SCOM) { TS_FAIL("Invalid access type."); } } /** * @test Verify we catch double registration. */ void testDoubleRegistration() { errlHndl_t l_errl = NULL; // Register non-sensical SCOM-READ to Nodes Associator as; l_errl = as.registerRoute(READ, SCOM, TYPE_NODE, &performOperation); if (l_errl) { TS_FAIL("testDoubleRegistration> Error received from registerRoute (1)."); } // Register the exact same thing again l_errl = as.registerRoute(READ, SCOM, TYPE_NODE, &performOperation); if (l_errl) { // error log is expected case, delete it delete l_errl; } else { TS_FAIL("testDoubleRegistration> No error from duplicate registration."); } // Register a wildcard that overlaps l_errl = as.registerRoute(WILDCARD, SCOM, TYPE_NODE, &performOperation); if (l_errl) { // error log is expected case, delete it delete l_errl; } else { TS_FAIL("testDoubleRegistration> No error from wildcard registration."); } // Reverse the wildcard test l_errl = as.registerRoute(WILDCARD, DeviceFW::PNOR, TYPE_NODE, &performOperation); if (l_errl) { TS_FAIL("testDoubleRegistration> Error received from registerRoute (2)."); } l_errl = as.registerRoute(WRITE, DeviceFW::PNOR, TYPE_NODE, &performOperation); if (l_errl) { // error log is expected case, delete it delete l_errl; } else { TS_FAIL("testDoubleRegistration> No error from registration after wildcard."); } } /** * @test Verify registration with an operator as a WILDCARD. */ void testOpWildcard() { void* buf = NULL; size_t bufsize = 0; g_associatorTest_value = &AssociatorTest::testOpWildcard; Associator as; as.registerRoute(WILDCARD, SCOM, TYPE_PROC, &performOperation); errlHndl_t l_errl = as.performOp(WRITE, MASTER_PROCESSOR_CHIP_TARGET_SENTINEL, buf, bufsize, SCOM, va_list()); if (l_errl) { TS_FAIL("Error received from performOp."); } if (g_associatorTest_result != g_associatorTest_value) { TS_FAIL("PerformOperation does not appear to have been called."); } if (g_associatorTest_opType != WRITE) { TS_FAIL("Invalid operation type."); } if (g_associatorTest_accessType != SCOM) { TS_FAIL("Invalid access type."); } } /** * @test Verify registration with a target type as a WILDCARD. */ void testTargTypeWildcard() { void* buf = NULL; size_t bufsize = 0; g_associatorTest_value = &AssociatorTest::testTargTypeWildcard; Associator as; as.registerRoute(READ, SCOM, WILDCARD, &performOperation); errlHndl_t l_errl = as.performOp(READ, MASTER_PROCESSOR_CHIP_TARGET_SENTINEL, buf, bufsize, SCOM, va_list()); if (l_errl) { TS_FAIL("Error received from performOp."); } if (g_associatorTest_result != g_associatorTest_value) { TS_FAIL("PerformOperation does not appear to have been called."); } if (g_associatorTest_opType != READ) { TS_FAIL("Invalid operation type."); } if (g_associatorTest_accessType != SCOM) { TS_FAIL("Invalid access type."); } } /** * @test Verify missing registration returns an error log. */ void testMissingRegistration() { void* buf = NULL; size_t bufsize = 0; g_associatorTest_value = &AssociatorTest::testMissingRegistration; Associator as; as.registerRoute(READ, SCOM, WILDCARD, &performOperation); errlHndl_t l_errl = as.performOp(READ, MASTER_PROCESSOR_CHIP_TARGET_SENTINEL, buf, bufsize, MAILBOX, va_list()); if (NULL == l_errl) { TS_FAIL("Error not received from performOp."); } else if (DEVFW_RC_NO_ROUTE_FOUND != l_errl->reasonCode()) { TS_FAIL("Reason code different from DEVFW_RC_NO_ROUTE_FOUND."); } else { delete l_errl; } } }; #endif