diff options
author | Patrick Williams <iawillia@us.ibm.com> | 2011-05-18 11:49:26 -0500 |
---|---|---|
committer | A. Patrick Williams III <iawillia@us.ibm.com> | 2011-06-02 09:54:48 -0500 |
commit | 83e18669b6c2322c8eb5f8632ac823877d765e0d (patch) | |
tree | 780c62fbc578e5a3b6c362db40b84e468611dd13 /src/usr/devicefw/test | |
parent | 40d7b75141080adb8b42cc5ea058c91944e7621e (diff) | |
download | talos-hostboot-83e18669b6c2322c8eb5f8632ac823877d765e0d.tar.gz talos-hostboot-83e18669b6c2322c8eb5f8632ac823877d765e0d.zip |
Device Framework support.
Change-Id: I133f58df309c7fc3a7faa261699eba66a6bae4be
Reviewed-on: http://gfw160.austin.ibm.com:8080/gerrit/98
Tested-by: Jenkins Server
Reviewed-by: Thi N. Tran <thi@us.ibm.com>
Reviewed-by: Andrew J. Geissler <andrewg@us.ibm.com>
Diffstat (limited to 'src/usr/devicefw/test')
-rw-r--r-- | src/usr/devicefw/test/assoccontaintest.H | 102 | ||||
-rw-r--r-- | src/usr/devicefw/test/associatortest.H | 174 | ||||
-rw-r--r-- | src/usr/devicefw/test/makefile | 6 |
3 files changed, 282 insertions, 0 deletions
diff --git a/src/usr/devicefw/test/assoccontaintest.H b/src/usr/devicefw/test/assoccontaintest.H new file mode 100644 index 000000000..160a8c2f9 --- /dev/null +++ b/src/usr/devicefw/test/assoccontaintest.H @@ -0,0 +1,102 @@ +#ifndef __TEST_ASSOCCONTAINTEST_H +#define __TEST_ASSOCCONTAINTEST_H + +#include <cxxtest/TestSuite.H> +#include "../assoccontain.H" + +using namespace DeviceFW; + +class AssocContainTest: public CxxTest::TestSuite +{ +public: + + /** + * @test Ensure AssociationContainer can be constructed. + */ + void testConstruct() + { + AssociationContainer* ac = new AssociationContainer(); + if (NULL == ac) + { + TS_FAIL("NULL pointer returned for 'new AssociationContainer'."); + } + delete ac; + } + + /** + * @test Verify allocate operation. + */ + void testAllocate() + { + AssociationContainer ac; + + // Allocation of a single block. + size_t root = ac.allocate(5); + + // Index operation on block. + AssociationData* root_ptr = ac[root]; + if (NULL == root_ptr) + { + TS_FAIL("NULL pointer returned for newly allocated block."); + } + + // Freshly allocated block is empty. + for(int i = 0; i < 5; i++) + { + if (root_ptr[i].flag) + { + TS_FAIL("Wildcard flag set on newly allocated block."); + } + if (0 != root_ptr[i].offset) + { + TS_FAIL("Non-zero value set in newly allocated block."); + } + } + + // Second allocated block is outside original. + size_t second_block = ac.allocate(2); + if (((second_block + 2) > root) && + (second_block < (root + 5))) + { + TS_FAIL("Newly allocated block is inside previous block."); + } + } + + /** + * @test Verify operator[]. + */ + void testIndex() + { + AssociationContainer ac; + + AssociationData root; + AssociationData second; + + root.offset = ac.allocate(5); + second.offset = ac.allocate(2); + second.flag = true; + + ac[second.offset][1].offset = 0x42; + + AssociationData* root_ptr = ac[root.offset]; + root_ptr[2] = second; + + // Check initial level block index. + if ((ac[root.offset + 2]->flag != second.flag) || + (ac[root.offset + 2]->offset != second.offset)) + { + TS_FAIL("Index operator points to incorrect block."); + } + + // Check second level indirection block index. + if (ac[ac[root.offset + 2]->offset + 1]->offset != 0x42) + { + TS_FAIL("Index operator points to incorrect block."); + } + } + + +}; + +#endif + diff --git a/src/usr/devicefw/test/associatortest.H b/src/usr/devicefw/test/associatortest.H new file mode 100644 index 000000000..792b6c3ef --- /dev/null +++ b/src/usr/devicefw/test/associatortest.H @@ -0,0 +1,174 @@ +#ifndef __TEST_ASSOCIATORTEST_H +#define __TEST_ASSOCIATORTEST_H + +#include <cxxtest/TestSuite.H> +#include "../associator.H" + +using namespace DeviceFW; + +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 + ErrorHandle_t performOperation(OperationType i_opType, + TargetHandle_t 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, + PROCESSOR, + &performOperation); + + ErrorHandle_t l_errl = as.performOp(READ, TargetHandle_t(), + 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 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, + PROCESSOR, + &performOperation); + + ErrorHandle_t l_errl = as.performOp(WRITE, TargetHandle_t(), + 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); + + ErrorHandle_t l_errl = as.performOp(READ, TargetHandle_t(), + 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."); + } + } + +}; + +#endif + diff --git a/src/usr/devicefw/test/makefile b/src/usr/devicefw/test/makefile new file mode 100644 index 000000000..b3571ae96 --- /dev/null +++ b/src/usr/devicefw/test/makefile @@ -0,0 +1,6 @@ +ROOTPATH = ../../../.. + +MODULE = testdevicefw +TESTS = *.H + +include ${ROOTPATH}/config.mk |