⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 benchmarktest.cpp

📁 Pegasus is an open-source implementationof the DMTF CIM and WBEM standards. It is designed to be por
💻 CPP
📖 第 1 页 / 共 4 页
字号:
//%2006//////////////////////////////////////////////////////////////////////////// Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development// Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.// Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;// IBM Corp.; EMC Corporation, The Open Group.// Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;// IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.// Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;// EMC Corporation; VERITAS Software Corporation; The Open Group.// Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;// EMC Corporation; Symantec Corporation; The Open Group.//// Permission is hereby granted, free of charge, to any person obtaining a copy// of this software and associated documentation files (the "Software"), to// deal in the Software without restriction, including without limitation the// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or// sell copies of the Software, and to permit persons to whom the Software is// furnished to do so, subject to the following conditions:// // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN// ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED// "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT// LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.////==============================================================================//// Author: Denise Eckstein, Hewlett-Packard Company//         Significant portions of the code in this application were copied//         from the wbemexec application.//// Modified By: David Dillard, VERITAS Software Corp.//                  (david.dillard@veritas.com)////%/////////////////////////////////////////////////////////////////////////////////L10N TODO: Internal benchmark utility. Although this module contains//messages, there is currently no expectation that it will be//localized.#include <iostream>#include <Pegasus/Common/Config.h>#include <Pegasus/Common/Constants.h>#include <Pegasus/Common/System.h>#include <Pegasus/Common/FileSystem.h>#include <Pegasus/Common/String.h>#include <Pegasus/Common/PegasusVersion.h>#include <Pegasus/Common/SSLContext.h>#include <Pegasus/Common/Stopwatch.h>#include <Pegasus/Common/Tracer.h>#include <Pegasus/getoopt/getoopt.h>#include <Clients/cliutils/CommandException.h>#include "benchmarkTest.h"#include "../benchmarkDefinition/benchmarkDefinition.h"FILE *_resultsFileHandle = NULL;String _startTime;#ifndef PLATFORM_PRODUCT_VERSION #define PLATFORM_PRODUCT_VERSION "1.0.0"#endifPEGASUS_NAMESPACE_BEGIN#define NAMESPACE CIMNamespaceName ("root/benchmark")#define MODULENAME String ("benchmarkProviderModule")benchmarkDefinition test;/**    The command name. */const char   benchmarkTestCommand::COMMAND_NAME []      = "benchmarkTest";//    Label for the usage string for this command.const char   benchmarkTestCommand::_USAGE []            = "usage: ";//    The option character used to specify the hostname.const char   benchmarkTestCommand::_OPTION_HOSTNAME     = 'h';//    The option character used to specify the port number.const char   benchmarkTestCommand::_OPTION_PORTNUMBER   = 'p';//    The option character used to specify SSL usage.const char   benchmarkTestCommand::_OPTION_SSL          = 's';//    The option character to request that the version be displayed.const char   benchmarkTestCommand::_OPTION_VERSION      = 'v';//    The option character used to specify the timeout value.const char   benchmarkTestCommand::_OPTION_TIMEOUT      = 't';//    The option character used to specify the username.const char   benchmarkTestCommand::_OPTION_USERNAME     = 'u';//    The option character used to specify the password.const char   benchmarkTestCommand::_OPTION_PASSWORD     = 'w';//    The option character used to specify the iteration parameter.const char benchmarkTestCommand::_OPTION_ITERATIONS     = 'i';//    The option character used to specify the TESTID parameter.const char benchmarkTestCommand::_OPTION_TESTID         = 'n';//    The option character used to specify the TESTID parameter.const char benchmarkTestCommand::_OPTION_RESULTS_DIRECTORY  = 'D';//    The option character used to specify that a debug option is requested.const char   benchmarkTestCommand::_OPTION_DEBUG        = 'd';//    The minimum valid portnumber.const Uint32 benchmarkTestCommand::_MIN_PORTNUMBER      = 0;//    The maximum valid portnumber.const Uint32 benchmarkTestCommand::_MAX_PORTNUMBER      = 65535;static const char PASSWORD_PROMPT []  =                     "Please enter your password: ";static const char PASSWORD_BLANK []  =                     "Password cannot be blank. Please re-enter your password.";//    The debug option argument value used to enable client-side tracing.const char   benchmarkTestCommand::_DEBUG_OPTION1       = '1';//    The debug option argument value used to disable printing verbose report.const char   benchmarkTestCommand::_DEBUG_OPTION2       = '2';static const Uint32 MAX_PW_RETRIES = 3;static Boolean verifyCertificate(SSLCertificateInfo &certInfo){#if 0    outPrintWriter << certInfo.getSubjectName() << endl;#endif    return true;}/**    Constructs a benchmarkTestCommand and initializes instance variables. */benchmarkTestCommand::benchmarkTestCommand (){    _hostName            = String ();    _resultsDirectory        = String ();    _hostNameSet         = false;    _portNumber          = WBEM_DEFAULT_HTTP_PORT;    _portNumberSet       = false;    char buffer[32];    sprintf(buffer, "%lu", (unsigned long) _portNumber);    _portNumberStr       = buffer;    _testID              = 0;    _testIDSet           = false;    _timeout             = DEFAULT_TIMEOUT_MILLISECONDS;    _userName            = String ();    _userNameSet         = false;    _password            = String ();    _passwordSet         = false;    _useSSL              = false;    _displayVersion      = false;    _iterations          = DEFAULT_NUMBER_OF_ITERATIONS;    _iterationsSet       = false;    _debugOption1        = false;    _generateReport      = true;    String usage = String (_USAGE);    usage.append (COMMAND_NAME);    usage.append (" [ -");    usage.append (_OPTION_SSL);    usage.append (" ] [ -");    usage.append (_OPTION_VERSION);    usage.append (" ] [ -");    usage.append (_OPTION_HOSTNAME);    usage.append (" hostname ] [ -");    usage.append (_OPTION_PORTNUMBER);    usage.append (" portnumber ] [ -");    usage.append (_OPTION_USERNAME);    usage.append (" username ] [ -");    usage.append (_OPTION_PASSWORD);    usage.append (" password ] [ -");    usage.append (_OPTION_TIMEOUT);    usage.append (" timeout ] [ -");    usage.append (_OPTION_RESULTS_DIRECTORY);    usage.append (" resultsDirectory ] [ -");    usage.append (_OPTION_ITERATIONS);    usage.append (" iterations ] [ -");    usage.append (_OPTION_TESTID);    usage.append (" testNumber ] [ -");    usage.append (_OPTION_DEBUG);    usage.append (_DEBUG_OPTION1);    usage.append (" [ -");    usage.append (_OPTION_DEBUG);    usage.append (_DEBUG_OPTION2);    usage.append (" ]");    setUsage (usage);}String benchmarkTestCommand::_promptForPassword( ostream& outPrintWriter ){  //  // Password is not set, prompt for non-blank password  //  String pw = String::EMPTY;  Uint32 retries = 1;  do    {      pw = System::getPassword( PASSWORD_PROMPT );      if ( pw == String::EMPTY || pw == "" )        {          if( retries < MAX_PW_RETRIES )            {              retries++;            }          else            {              break;            }          outPrintWriter << PASSWORD_BLANK << endl;          pw = String::EMPTY;          continue;        }    }  while ( pw == String::EMPTY );  return( pw );}/**    Connects to cimserver.    @param   outPrintWriter     the ostream to which error output should be                                written    @exception       Exception  if an error is encountered in creating                               the connection */ void benchmarkTestCommand::_connectToServer( CIMClient& client,                         ostream& outPrintWriter ){    String                 host                  = String ();    Uint32                 portNumber            = 0;    Boolean                connectToLocal        = false;    //    //  Construct host address    //    if ((!_hostNameSet) && (!_portNumberSet) && \        (!_userNameSet) && (!_passwordSet))    {        connectToLocal = true;    }    else    {        if (!_hostNameSet)        {           _hostName = System::getHostName();        }        if( !_portNumberSet )        {           if( _useSSL )           {               _portNumber = System::lookupPort( WBEM_HTTPS_SERVICE_NAME,                                          WBEM_DEFAULT_HTTPS_PORT );           }           else           {               _portNumber = System::lookupPort( WBEM_HTTP_SERVICE_NAME,                                          WBEM_DEFAULT_HTTP_PORT );           }           char buffer[32];           sprintf( buffer, "%lu", (unsigned long) _portNumber );           _portNumberStr = buffer;        }    }    host = _hostName;    portNumber = _portNumber;    if( connectToLocal )    {        client.connectLocal();    }    else if( _useSSL )    {        //        // Get environment variables:        //        const char* pegasusHome = getenv("PEGASUS_HOME");    String certpath = FileSystem::getAbsolutePath(           pegasusHome, PEGASUS_SSLCLIENT_CERTIFICATEFILE);    String randFile = String::EMPTY;    randFile = FileSystem::getAbsolutePath(            pegasusHome, PEGASUS_SSLCLIENT_RANDOMFILE);        SSLContext  sslcontext (certpath, verifyCertificate, randFile);        if (!_userNameSet)        {           _userName = System::getEffectiveUserName();        }        if (!_passwordSet)        {            _password = _promptForPassword( outPrintWriter );        }    client.connect(host, portNumber, sslcontext,  _userName, _password );    }    else    {        if (!_passwordSet)        {            _password = _promptForPassword( outPrintWriter );        }        client.connect(host, portNumber, _userName, _password );     }}/**    Parses the command line, validates the options, and sets instance    variables based on the option arguments.    @param   argc  the number of command line arguments    @param   argv  the string vector of command line arguments    @exception  CommandFormatException  if an error is encountered in parsing                                        the command line */void benchmarkTestCommand::setCommand (Uint32 argc, char* argv []){    Uint32         i              = 0;    Uint32         c              = 0;    String         httpVersion    = String ();    String         httpMethod     = String ();    String         timeoutStr     = String ();    String         GetOptString   = String ();    getoopt        getOpts;    //    //  Construct GetOptString    //    GetOptString.append (_OPTION_HOSTNAME);    GetOptString.append (getoopt::GETOPT_ARGUMENT_DESIGNATOR);    GetOptString.append (_OPTION_PORTNUMBER);    GetOptString.append (getoopt::GETOPT_ARGUMENT_DESIGNATOR);    GetOptString.append (_OPTION_VERSION);    GetOptString.append (_OPTION_SSL);    GetOptString.append (_OPTION_TIMEOUT);    GetOptString.append (getoopt::GETOPT_ARGUMENT_DESIGNATOR);    GetOptString.append (_OPTION_USERNAME);    GetOptString.append (getoopt::GETOPT_ARGUMENT_DESIGNATOR);    GetOptString.append (_OPTION_PASSWORD);    GetOptString.append (getoopt::GETOPT_ARGUMENT_DESIGNATOR);    GetOptString.append (_OPTION_RESULTS_DIRECTORY);    GetOptString.append (getoopt::GETOPT_ARGUMENT_DESIGNATOR);    GetOptString.append (_OPTION_ITERATIONS);    GetOptString.append (getoopt::GETOPT_ARGUMENT_DESIGNATOR);    GetOptString.append (_OPTION_TESTID);    GetOptString.append (getoopt::GETOPT_ARGUMENT_DESIGNATOR);    GetOptString.append (_OPTION_DEBUG);    GetOptString.append (getoopt::GETOPT_ARGUMENT_DESIGNATOR);    //    //  Initialize and parse getOpts    //    getOpts = getoopt ();    getOpts.addFlagspec (GetOptString);    getOpts.parse (argc, argv);    if (getOpts.hasErrors ())    {        CommandFormatException e (getOpts.getErrorStrings () [0]);        throw e;    }    //    //  Get options and arguments from the command line    //

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -