📄 testclient.cpp
字号:
{"simultaneous", "1", false, Option::WHOLE_NUMBER, 0, 0, "t", "Number of simultaneous client threads" }, {"timeout","30000", false, Option::WHOLE_NUMBER, 0, 0, "to", "Client connection timeout value" } }; const Uint32 NUM_OPTIONS = sizeof(optionsTable) / sizeof(optionsTable[0]); om.registerOptions(optionsTable, NUM_OPTIONS); String configFile = pegasusHome + "/cimserver.conf"; cout << "Config file from " << configFile << endl; if (FileSystem::exists(configFile)) om.mergeFile(configFile); om.mergeCommandLine(argc, argv); om.checkRequiredOptions();}ThreadReturnType PEGASUS_THREAD_CDECL executeTests(void *parm){ Thread *my_thread = (Thread *)parm; T_Parms *parms = (T_Parms *)my_thread->get_parm(); CIMClient *client = parms->client.get(); Uint32 testCount = parms->testCount; Boolean verboseTest = parms->verboseTest == 0 ? false : true; Boolean activeTest = parms->activeTest == 0 ? false : true; int id = parms->uniqueID; char id_[4]; memset(id_,0x00,sizeof(id_)); sprintf(id_,"%i",id); String uniqueID = "_"; uniqueID.append(id_); for(Uint32 i=0; i<testCount; i++){ try{ Stopwatch elapsedTime; testStart("Test NameSpace Operations"); elapsedTime.reset(); elapsedTime.start(); TestNameSpaceOperations(client, activeTest, verboseTest, uniqueID); elapsedTime.stop(); testEnd(elapsedTime.getElapsed()); testStart("Test Qualifier Operations"); elapsedTime.reset(); elapsedTime.start(); TestQualifierOperations(client,activeTest,verboseTest, uniqueID); elapsedTime.stop(); testEnd(elapsedTime.getElapsed()); testStart("Test EnumerateClassNames"); elapsedTime.reset(); elapsedTime.start(); TestEnumerateClassNames(client,activeTest,verboseTest, uniqueID); elapsedTime.stop(); testEnd(elapsedTime.getElapsed()); testStart("Test Class Operations"); elapsedTime.reset(); elapsedTime.start(); TestClassOperations(client,activeTest,verboseTest, uniqueID); elapsedTime.stop(); testEnd(elapsedTime.getElapsed()); testStart("Test Instance Get Operations"); elapsedTime.reset(); elapsedTime.start(); TestInstanceGetOperations(client,activeTest,verboseTest, uniqueID); elapsedTime.stop(); testEnd(elapsedTime.getElapsed()); testStart("Test Instance Modification Operations"); elapsedTime.reset(); elapsedTime.start(); TestInstanceModifyOperations(client, activeTest, verboseTest, uniqueID); elapsedTime.stop(); testEnd(elapsedTime.getElapsed()); testStart("Test Associations"); elapsedTime.reset(); elapsedTime.start(); TestAssociationOperations(client, activeTest, verboseTest, uniqueID); elapsedTime.stop(); testEnd(elapsedTime.getElapsed()); /* Turn this one off until we get valid method to execute testStart("Test Method Execution"); elapsedTime.reset(); elapsedTime.start(); TestMethodOperations(client, activeTest, verboseTest, uniqueID); elapsedTime.stop(); testEnd(elapsedTime.getElapsed()); */ testStart("Test Invoke Method Execution"); elapsedTime.reset(); elapsedTime.start(); TestInvokeMethod(client, activeTest, verboseTest, uniqueID); elapsedTime.stop(); testEnd(elapsedTime.getElapsed()); testStart("Test Enumerate Instances Execution"); elapsedTime.reset(); elapsedTime.start(); TestEnumerateInstances(client, activeTest, verboseTest, uniqueID); elapsedTime.stop(); testEnd(elapsedTime.getElapsed()); }catch(Exception& e){ cout << e.getMessage() << endl; errorCount++; } } my_thread->exit_self((ThreadReturnType)5); return(0);}Thread * runTests(CIMClient *client, Uint32 testCount, Boolean activeTest, Boolean verboseTest, int uniqueID){ // package parameters, create thread and run... AutoPtr<T_Parms> parms(new T_Parms()); parms->client.reset(client); parms->testCount = testCount; parms->activeTest = (activeTest) ? 1 : 0; parms->verboseTest = (verboseTest) ? 1 : 0; parms->uniqueID = uniqueID; AutoPtr<Thread> t(new Thread(executeTests, (void*)parms.release(), false)); // zzzzz... (1 second) zzzzz... Threads::sleep(1000); t->run(); return t.release();}void connectClient( CIMClient *client, String host, Uint32 portNumber, String userName, String password, Boolean useSSL, Boolean localConnection, Uint32 timeout){ try { client->setTimeout(timeout); if (useSSL) { if (localConnection) { cout << "Using local connection mechanism " << endl; client->connectLocal(); } else { // // Get environment variables: // const char* pegasusHome = getenv("PEGASUS_HOME"); String trustpath = FileSystem::getAbsolutePath( pegasusHome, PEGASUS_SSLCLIENT_CERTIFICATEFILE); String randFile = String::EMPTY;#ifdef PEGASUS_SSL_RANDOMFILE randFile = FileSystem::getAbsolutePath( pegasusHome, PEGASUS_SSLCLIENT_RANDOMFILE);#endif SSLContext sslcontext( trustpath, verifyCertificate, randFile); cout << "connecting to " << host << ":" << portNumber << " using SSL" << endl; client->connect (host, portNumber, sslcontext, userName, password); } } // useSSL else { if (localConnection) { cout << "Using local connection mechanism " << endl; client->connectLocal(); } else { cout << "Connecting to " << host << ":" << portNumber << endl; client->connect (host, portNumber, userName, password); } } cout << "Client Connected" << endl; } catch(ConnectionTimeoutException& e) { PEGASUS_STD(cerr) << "Warning: " << e.getMessage() << PEGASUS_STD(endl); exit(2); } catch(Exception& e) { PEGASUS_STD(cerr) << "Error: " << e.getMessage() << PEGASUS_STD(endl); exit(1); }}///////////////////////////////////////////////////////////////// MAIN///////////////////////////////////////////////////////////////int main(int argc, char** argv){ // char connection[50] = "localhost:5988"; char *address_string = NULL; Uint32 repetitions = 1; // Get environment variables: String pegasusHome; pegasusHome = "/"; // GetEnvironmentVariables(argv[0], pegasusHome); // Get options (from command line and from configuration file); this // removes corresponding options and their arguments fromt he command // line. // Get options (from command line and from configuration file); this // removes corresponding options and their arguments fromt he command // line. OptionManager om; try { GetOptions(om, argc, argv, pegasusHome); } catch (Exception& e) { cerr << argv[0] << ": " << e.getMessage() << endl; exit(1); } // Check to see if user asked for help (-h otpion): if (om.valueEquals("help", "true")) { String header = "Usage "; header.append(argv[0]); header.append(" -parameters host [host]"); String trailer = "Assumes localhost:5988 if host not specified"; trailer.append("\nHost may be of the form name or name:port"); trailer.append("\nPort 5988 assumed if port number missing."); om.printOptionsHelpTxt(header, trailer); exit(0); } if (om.valueEquals("version","true")) { cout << argv[0] << " version " <<programVersion << endl; //cout << argv[0] << endl; exit(0); } String tmp; om.lookupValue("namespace", tmp); CIMNamespaceName localNameSpace = CIMNamespaceName (tmp); globalNamespace = localNameSpace; cout << "Namespace = " << localNameSpace << endl; Boolean verboseTest = om.isTrue("verbose"); // Set up number of test repetitions. Will repeat entire test this number of times // Default is zero // String repeats; Uint32 repeatTestCount = 0; /* ATTN: KS P0 Test and fix function added to Option Manager */ if (!om.lookupIntegerValue("repeat", repeatTestCount)) repeatTestCount = 1; if(verboseTest) cout << "Test repeat count " << repeatTestCount << endl; // Setup the active test flag. Determines if we change repository. Boolean activeTest = false; if (om.valueEquals("active", "true")) activeTest = true; String userName; om.lookupValue("user", userName); if (userName != String::EMPTY) { cout << "Username = " << userName << endl; } String password; om.lookupValue("password", password); if (password != String::EMPTY) { cout << "password = " << password << endl; } Boolean useSLP = false; Boolean localConnection = (om.valueEquals("local", "true"))? true: false; Boolean useSSL = om.isTrue("ssl"); Array<String> connectionList; if (argc > 1 && !localConnection) for (Sint32 i = 1; i < argc; i++) connectionList.append(argv[i]); // setup default connection definitions if needed if (useSSL) connectionList.append("localhost:5989"); else if(useSLP == false && argc < 2) connectionList.append("localhost:5988"); // timeout Uint32 timeout = 30000; om.lookupIntegerValue("timeout",timeout); // create clients Uint32 clients = 1; om.lookupIntegerValue("simultaneous",clients); String host; Uint32 portNumber; for (Uint32 i = 0; i < connectionList.size(); i++) { // ---------------------------------------- // * Get host and port number from hostport // ---------------------------------------- Uint32 index = connectionList[i].find (':'); host = connectionList[i].subString (0, index); portNumber = 0; if (index != PEG_NOT_FOUND) { String portStr = connectionList[i].subString(index + 1, connectionList[i].size ()); sscanf (portStr.getCString (), "%u", &portNumber); } Array<CIMClient*> clientConnections; CIMClient* client; for(Uint32 i = 0; i < clients; i++) { client = new CIMClient(); clientConnections.append(client); } // connect the clients for(Uint32 i=0; i<clients; i++) { connectClient(clientConnections[i], host, portNumber, userName, password, useSSL, localConnection, timeout); } // run tests Array<Thread *> clientThreads; Stopwatch elapsedTime; testStart("Begin tests..."); elapsedTime.reset(); elapsedTime.start(); for(Uint32 i=0; i< clientConnections.size(); i++) { clientThreads.append(runTests(clientConnections[i], repeatTestCount, activeTest, verboseTest, i)); } elapsedTime.stop(); testEnd(elapsedTime.getElapsed()); for(Uint32 i=0; i< clientThreads.size(); i++) { clientThreads[i]->join(); } // clean up for(Uint32 i=0; i< clientConnections.size(); i++){ if(clientConnections[i]) delete clientConnections[i]; } for(Uint32 i=0; i < clientThreads.size(); i++){ if(clientThreads[i]) delete clientThreads[i]; } } if (errorCount.get() == 0) { cout << "+++++ "<< argv[0] << " Terminated Normally" << endl; return 0; } else { cout << "Test case failures: "<< errorCount.get() << endl; cout << "+++++ "<< argv[0] << " Failed" << endl; exit(1); }}/* TODO: 3. Make test loop tool 5. Make test multiple systems. 6. Get rid of diagnostics and clean display 7. Add correct successful at end 8. Make OO 9. Add associations test 10. Add cim references test. 11. Add test all namespaces test.*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -