summaryrefslogtreecommitdiffstats
path: root/src/usr/initservice/test/initservicetest.H
diff options
context:
space:
mode:
authorMark Wenning <wenning@us.ibm.com>2011-06-06 14:07:51 -0500
committerA. Patrick Williams III <iawillia@us.ibm.com>2011-06-21 17:54:41 -0500
commita2fbc8cb2e51821331f3ba8d920dddf8ab0fb96d (patch)
treea8f2b80dd70837255c2012f86917cb1f9e8c415a /src/usr/initservice/test/initservicetest.H
parenta1450c913cb7864234ae1adea8aaffe561a627d6 (diff)
downloadtalos-hostboot-a2fbc8cb2e51821331f3ba8d920dddf8ab0fb96d.tar.gz
talos-hostboot-a2fbc8cb2e51821331f3ba8d920dddf8ab0fb96d.zip
Initialization Service (Flow Control)
- save off changes before switch branch - rename to get rid of '_' in filenames. - split into separate files - adding errorlogs, saved off so CC guru could work - fix problem in vfs_main where we would crash if there is no _start in launched task. - refactor - fix problems with coding guidelines - add testcases for startTask and reportError - add fixes from code review Change-Id: I2ae34cb6097c466d4f6d0e41b4b32c2eba47e9df Reviewed-on: http://gfw160.austin.ibm.com:8080/gerrit/145 Tested-by: Jenkins Server Reviewed-by: A. Patrick Williams III <iawillia@us.ibm.com>
Diffstat (limited to 'src/usr/initservice/test/initservicetest.H')
-rw-r--r--src/usr/initservice/test/initservicetest.H237
1 files changed, 237 insertions, 0 deletions
diff --git a/src/usr/initservice/test/initservicetest.H b/src/usr/initservice/test/initservicetest.H
new file mode 100644
index 000000000..3edfa2885
--- /dev/null
+++ b/src/usr/initservice/test/initservicetest.H
@@ -0,0 +1,237 @@
+/**
+ * @file initservicetest.H
+ *
+ * Private functions for VFS2 phase.
+ */
+
+#ifndef __TEST_INIT_SERVICETEST_H
+#define __TEST_INIT_SERVICETEST_H
+
+/**
+ * @file initservicetest.H
+ *
+ * @brief Unit tests for initservice module
+ */
+
+#include <cxxtest/TestSuite.H>
+
+#include "../initservice.H"
+
+/**
+ * @brief set up a dummy TaskInfo struct for test 1.
+ * this taskname should not exist, so we are expecting an error log back.
+ *
+ */
+const INITSERVICE::TaskInfo TASK_TEST1 = {
+ "libtestinitsvc_noexist.so" , // taskname
+ {
+ true, // startflag=true, try to start
+ INITSERVICE::BASE_MODULE, // Base Module
+ INITSERVICE::INIT_SVC_TEST1_ID, // module id for errorlog
+ },
+};
+
+
+/**
+ * @brief set up a dummy TaskInfo struct for test 2.
+ * example.C does indeed have a _start() function so this should return OK.
+ *
+ * @todo this needs to be replaced with a test module
+ */
+const INITSERVICE::TaskInfo TASK_TEST2 = {
+ "libexample.so" , // taskname
+ {
+ true, // startflag=true, try to start
+ INITSERVICE::BASE_MODULE, // Base Module
+ INITSERVICE::INIT_SVC_TEST2_ID, // module id for errorlog
+ },
+};
+
+
+/**
+ * @brief set up a dummy TaskInfo struct.
+ * libtrace does NOT have a _start() function so this should return an errorlog.
+ *
+ * @todo this needs to be replaced with a test module
+ */
+const INITSERVICE::TaskInfo TASK_TEST3 = {
+ "libtrace.so" , // taskname
+ {
+ true, // startflag=true, try to start
+ INITSERVICE::BASE_MODULE, // Base Module
+ INITSERVICE::INIT_SVC_TEST3_ID, // module id for errorlog
+ },
+};
+
+/**
+ * @class InitServiceTest
+ *
+ * runs unit testa against InitService class
+ *
+ */
+class InitServiceTest: public CxxTest::TestSuite
+{
+
+public:
+ /**
+ * @brief testInitServiceStartTask1
+ * this should try to run a nonexistent task, return an
+ * errorlog, and not blow up
+ *
+ */
+ void testInitServiceStartTask1(void)
+ {
+ errlHndl_t errl = NULL;
+ /**
+ * @todo use a separate instance here, not the singleton
+ */
+ INITSERVICE::InitService &l_is = INITSERVICE::InitService::getTheInstance();
+ tid_t tidrc = 0;
+
+
+ TS_TRACE( "=====>Attempt to run a nonexistent task.\n ");
+ tidrc = l_is.startTask( TASK_TEST1, errl );
+ printk( "testInitServiceStartTask1: startTask returned %d: errl=%p\n", tidrc, errl );
+ if ( (int16_t)tidrc < 0 )
+ {
+ TS_TRACE( "SUCCESS: startTask returned an errorlog.\n");
+ // @todo dump error log to trace?
+ }
+ else
+ {
+ TS_FAIL( "ERROR: no error log was returned.\n");
+ }
+
+
+ return;
+ }
+
+ /**
+ * @brief testInitServiceStartTask2
+ * this should try to run a task that does have a _start() function.
+ * it should return OK.
+ */
+ void testInitServiceStartTask2(void)
+ {
+ errlHndl_t errl = NULL;
+ /**
+ * @todo use a separate instance here, not the singleton
+ */
+ INITSERVICE::InitService &l_is = INITSERVICE::InitService::getTheInstance();
+ tid_t tidrc = 0;
+
+
+ TS_TRACE( "=====>Attempt to run a task with a _start() function.\n ");
+ tidrc = l_is.startTask( TASK_TEST2, errl );
+ printk( "testInitServiceStartTask2: startTask returned %d: errl=%p\n", tidrc, errl );
+ if ( (int16_t)tidrc >= 0 )
+ {
+ TS_TRACE( "SUCCESS: startTask returned OK.\n");
+ // @todo dump error log to trace?
+ }
+ else
+ {
+ TS_FAIL( "ERROR: StartTask returned an error log.\n");
+ }
+
+
+ return;
+ }
+
+
+ /**
+ * @brief testInitServiceStartTask3
+ * this should try to run a task that does NOT have a _start() function.
+ * it should fail
+ */
+ void testInitServiceStartTask3(void)
+ {
+ errlHndl_t errl = NULL;
+ /**
+ * @todo use a separate instance here, not the singleton
+ */
+ INITSERVICE::InitService &l_is = INITSERVICE::InitService::getTheInstance();
+ tid_t tidrc = 0;
+
+
+ TS_TRACE( "====>Attempt to run a task with NO _start() function.\n ");
+ tidrc = l_is.startTask( TASK_TEST3, errl );
+ printk( "testInitServiceStartTask3: startTask returned %d: errl=%p\n", tidrc, errl );
+ if ( (int16_t)tidrc < 0 )
+ {
+ TS_TRACE( "SUCCESS: startTask returned an error log.\n");
+ // @todo dump error log to trace?
+ }
+ else
+ {
+ TS_FAIL( "ERROR: StartTask did not return an error log.\n");
+ }
+
+ return;
+ }
+
+ /**
+ * @brief testInitServicereportError1
+ * This will call reportError with a NULL errlHndl_t . It should handle it
+ * OK (reportError() will print an error message to trace)
+ */
+ void testInitServicereportError1(void)
+ {
+ errlHndl_t errl = NULL;
+ /**
+ * @todo use a separate instance here, not the singleton
+ */
+ INITSERVICE::InitService &l_is = INITSERVICE::InitService::getTheInstance();
+
+ TS_TRACE( "====> call reportError with NULL handle, should handle it OK\n ");
+ l_is.reportError( errl );
+
+ // reportError() might crash, if it returns, just make sure it didn't modify
+ // the input pointer
+ if ( errl != NULL)
+ {
+ TS_FAIL( "ERROR: expected the NULL errlHndl_t to stay NULL\n");
+ }
+
+ return;
+ }
+
+ /**
+ * @brief testInitServicereportError1
+ * This will call reportError with a good errorlog.
+ * on return, it should be NULLED out
+ * @todo can we check with the errorlogging facility to see if it got
+ * posted??
+ */
+ void testInitServicereportError2(void)
+ {
+ errlHndl_t errl = NULL;
+ /**
+ * @todo use a separate instance here, not the singleton
+ */
+ INITSERVICE::InitService &l_is = INITSERVICE::InitService::getTheInstance();
+
+ errl = new ERRORLOG::ErrlEntry(
+ ERRORLOG::ERRL_SEV_INFORMATIONAL,
+ INITSERVICE::INIT_SVC_TEST5_ID,
+ INITSERVICE::START_TASK_FAILED,
+ 0,
+ 0
+ );
+
+ TS_TRACE( "====> call reportError with good error handle, should commit and then delete\n ");
+ l_is.reportError( errl );
+ if ( errl !=NULL )
+ {
+ TS_FAIL( "ERROR: reportError did not delete the errlHndl_t handle!\n" );
+ }
+
+
+
+ return;
+ }
+}; // class InitServiceTest
+
+
+#endif // __TEST_INIT_SERVICETEST_H
+
OpenPOWER on IntegriCloud