summaryrefslogtreecommitdiffstats
path: root/src/usr/util
diff options
context:
space:
mode:
authorCorey Swenson <cswenson@us.ibm.com>2016-09-20 13:29:49 -0500
committerDaniel M. Crowell <dcrowell@us.ibm.com>2016-10-12 11:55:48 -0400
commitd32a09cc6edff8d296f64238fd5c0884472fcbc0 (patch)
tree6098d70e3013894002ec2a8df0dc34016c58883a /src/usr/util
parent3ab150991f977e81505114f0a20a9d5e5e29f230 (diff)
downloadtalos-hostboot-d32a09cc6edff8d296f64238fd5c0884472fcbc0.tar.gz
talos-hostboot-d32a09cc6edff8d296f64238fd5c0884472fcbc0.zip
Enable Host interface run_command
Change-Id: I689d0f20d65f75299a341f23c2eb1b923dd2aa76 RTC:146148 Reviewed-on: http://ralgit01.raleigh.ibm.com/gerrit1/29980 Tested-by: Jenkins Server <pfd-jenkins+hostboot@us.ibm.com> Tested-by: FSP CI Jenkins <fsp-CI-jenkins+hostboot@us.ibm.com> Reviewed-by: Elizabeth K. Liner <eliner@us.ibm.com> Reviewed-by: Daniel M. Crowell <dcrowell@us.ibm.com>
Diffstat (limited to 'src/usr/util')
-rw-r--r--src/usr/util/runtime/makefile3
-rw-r--r--src/usr/util/runtime/rt_cmds.C101
-rw-r--r--src/usr/util/runtime/test/testruncommand.H83
3 files changed, 186 insertions, 1 deletions
diff --git a/src/usr/util/runtime/makefile b/src/usr/util/runtime/makefile
index 8947811ef..e61091cc5 100644
--- a/src/usr/util/runtime/makefile
+++ b/src/usr/util/runtime/makefile
@@ -5,7 +5,7 @@
#
# OpenPOWER HostBoot Project
#
-# Contributors Listed Below - COPYRIGHT 2013,2015
+# Contributors Listed Below - COPYRIGHT 2013,2016
# [+] International Business Machines Corp.
#
#
@@ -32,6 +32,7 @@ OBJS += utilmem.o
OBJS += utillidmgr_rt.o
OBJS += utilfile.o
OBJS += utillidpnor.o
+OBJS += rt_cmds.o
SUBDIRS += test.d
diff --git a/src/usr/util/runtime/rt_cmds.C b/src/usr/util/runtime/rt_cmds.C
new file mode 100644
index 000000000..b94fdd23e
--- /dev/null
+++ b/src/usr/util/runtime/rt_cmds.C
@@ -0,0 +1,101 @@
+/* IBM_PROLOG_BEGIN_TAG */
+/* This is an automatically generated prolog. */
+/* */
+/* $Source: src/usr/util/runtime/rt_cmds.C $ */
+/* */
+/* OpenPOWER HostBoot Project */
+/* */
+/* Contributors Listed Below - COPYRIGHT 2015,2016 */
+/* [+] 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 */
+#include <runtime/interface.h>
+#include <stdio.h>
+#include <trace/interface.H>
+#include <string.h>
+#include "../utilbase.H"
+
+/**
+ * @brief Execute an arbitrary command inside Hostboot Runtime
+ * @param[in] Number of arguments (standard C args)
+ * @param[in] Array of argument values (standard C args)
+ * @param[out] Response message (NULL terminated), memory allocated
+ * by hbrt, if o_outString is NULL then no response will
+ * be sent
+ * @return 0 on success, else error code
+ */
+int hbrtCommand( int argc,
+ const char** argv,
+ char** o_outString )
+{
+ int rc = 0;
+ UTIL_FT("Executing run_command : argc=%d, o_outString=%p",
+ argc, o_outString);
+
+ if( !argc )
+ {
+ UTIL_FT("run_command : Number of arguments = 0");
+ return rc;
+ }
+
+ if( argv == NULL )
+ {
+ UTIL_FT("run_command : Argument array is empty");
+ return rc;
+ }
+
+ for( int aa=0; aa<argc; aa++ )
+ {
+ UTIL_FT("run_command : %d=%s",aa,argv[aa]);
+ }
+
+ // If no output is specified, trace it instead
+ bool l_traceOut = false;
+ char* l_outPtr = NULL; //local value to use if needed
+ char** l_output = o_outString;
+ if( o_outString == NULL )
+ {
+ l_output = &l_outPtr;
+ l_traceOut = true;
+ }
+
+ // Test path
+ if( (argc == 2) && !strcmp( argv[0], "testRunCommand" ) )
+ {
+ *l_output = new char[strlen(argv[1])+1+5];//arg0+arg1+\0
+ sprintf( *l_output, "TEST:%s", argv[1] );
+ }
+
+ if( l_traceOut && (*l_output != NULL) )
+ {
+ UTIL_FT("Output::%s",*l_output);
+ delete *l_output;
+ }
+
+ return rc;
+}
+
+
+struct registerCmds
+{
+ registerCmds()
+ {
+ getRuntimeInterfaces()->run_command = &hbrtCommand;
+ }
+};
+
+registerCmds g_registerCmds;
+
diff --git a/src/usr/util/runtime/test/testruncommand.H b/src/usr/util/runtime/test/testruncommand.H
new file mode 100644
index 000000000..5e2383fe4
--- /dev/null
+++ b/src/usr/util/runtime/test/testruncommand.H
@@ -0,0 +1,83 @@
+/* IBM_PROLOG_BEGIN_TAG */
+/* This is an automatically generated prolog. */
+/* */
+/* $Source: src/usr/util/runtime/test/testruncommand.H $ */
+/* */
+/* OpenPOWER HostBoot Project */
+/* */
+/* Contributors Listed Below - COPYRIGHT 2015,2016 */
+/* [+] 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 */
+#include <cxxtest/TestSuite.H>
+#include <errl/errlmanager.H>
+#include <config.h>
+#include <runtime/interface.h>
+#include <string.h>
+#include <stdio.h>
+#include "utilbase.H"
+
+class RunCommandTest : public CxxTest::TestSuite
+{
+ public:
+ /**
+ * @brief Test basic command/response
+ */
+ void testRunCommand()
+ {
+ int argc = 2;
+
+ char arg0[10]; memcpy( arg0, "testRunCommand", 15 );
+ char arg1[10]; memcpy( arg1, "arg1", 5 );
+
+ const char* argv[] = { arg0, arg1 };
+
+ char* outstr = NULL;
+
+ int rc = (getRuntimeInterfaces()->run_command)( argc, argv, &outstr );
+
+ TRACFCOMP( Util::g_util_trace, "testRunCommand> rc=%d :: %s",
+ rc, outstr == NULL ? "null" : outstr );
+
+ char expected[21];
+ sprintf( expected, "TEST:arg1" );
+
+ if( strcmp( outstr, expected ) )
+ {
+ TS_FAIL( "testRunCommand> Unexpected result : Exp=%s, Act=%s",
+ expected, outstr );
+ }
+
+ if( outstr )
+ {
+ delete[] outstr;
+ }
+ }
+
+ /**
+ * @brief Test invalid parms
+ */
+ void testRunCommandBad(void)
+ {
+ int rc = 0;
+
+ rc = (getRuntimeInterfaces()->run_command)( 0, NULL, NULL );
+ if( rc )
+ {
+ TS_FAIL( "testRunCommandBad> Error from no args" );
+ }
+ }
+};
OpenPOWER on IntegriCloud