From d32a09cc6edff8d296f64238fd5c0884472fcbc0 Mon Sep 17 00:00:00 2001 From: Corey Swenson Date: Tue, 20 Sep 2016 13:29:49 -0500 Subject: Enable Host interface run_command Change-Id: I689d0f20d65f75299a341f23c2eb1b923dd2aa76 RTC:146148 Reviewed-on: http://ralgit01.raleigh.ibm.com/gerrit1/29980 Tested-by: Jenkins Server Tested-by: FSP CI Jenkins Reviewed-by: Elizabeth K. Liner Reviewed-by: Daniel M. Crowell --- src/include/runtime/interface.h | 6 +- src/usr/util/runtime/makefile | 3 +- src/usr/util/runtime/rt_cmds.C | 101 +++++++++++++++++++++++++++++ src/usr/util/runtime/test/testruncommand.H | 83 ++++++++++++++++++++++++ 4 files changed, 189 insertions(+), 4 deletions(-) create mode 100644 src/usr/util/runtime/rt_cmds.C create mode 100644 src/usr/util/runtime/test/testruncommand.H diff --git a/src/include/runtime/interface.h b/src/include/runtime/interface.h index 2140f69a2..d03ff0fae 100644 --- a/src/include/runtime/interface.h +++ b/src/include/runtime/interface.h @@ -620,9 +620,9 @@ typedef struct runtimeInterfaces * @return 0 on success, else error code * @platform FSP, OpenPOWER */ - int run_command( int argc, - const char** argv, - char** o_outString ); + int (*run_command)( int argc, + const char** argv, + char** o_outString ); /** * @brief Verify integrity of a secure container 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 +#include +#include +#include +#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; aarun_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 +#include +#include +#include +#include +#include +#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" ); + } + } +}; -- cgit v1.2.3