Changeset 60169 in vbox
- Timestamp:
- Mar 23, 2016 2:24:23 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/testcase/tstVBoxMultipleVM.cpp
r60168 r60169 46 46 * Global Variables & defs * 47 47 *********************************************************************************************************************************/ 48 typedef std::vector<Bstr> 49 static volatile BOOL g_RunTest = TRUE;50 static RTSEMEVENT 48 typedef std::vector<Bstr> TMachinesList; 49 static volatile bool g_RunTest = true; 50 static RTSEMEVENT g_PingEevent; 51 51 static volatile uint64_t g_Counter = 0; 52 static RTTEST 53 static Bstr 52 static RTTEST g_hTest; 53 static Bstr tstMachineName = "tstVBoxMultipleVM test multiple VM start/stop"; 54 54 55 55 /* Arguments of test thread */ 56 56 struct TestThreadArgs 57 57 { 58 /* number of machines that should be run simultaneousely */58 /** number of machines that should be run simultaneousely */ 59 59 uint32_t machinesPackSize; 60 /* percents of VM Stop operation what should be called */61 /*without session unlocking */60 /** percents of VM Stop operation what should be called 61 * without session unlocking */ 62 62 uint32_t percentsUnlok; 63 /* How much time inseconds test will be executed */64 uint64_t executionTime;65 /* How much machines create for the test */66 63 /** How much time in milliseconds test will be executed */ 64 uint64_t cMsExecutionTime; 65 /** How much machines create for the test */ 66 uint32_t numberMachines; 67 67 }; 68 68 … … 211 211 { 212 212 HRESULT rc; 213 uint32_t machinesCount = 0;213 size_t machinesCount = 0; 214 214 com::SafeIfaceArray<IMachine> machines; 215 215 … … 217 217 218 218 machinesCount = RT_MIN(machines.size(), maxCount); 219 for ( uint32_t i = 0; i < machinesCount; ++i)219 for (size_t i = 0; i < machinesCount; ++i) 220 220 { 221 221 // choose random index of machine 222 uint32_t idx = RTRandU32Ex(0, machines.size() - 1);222 uint32_t idx = RTRandU32Ex(0, (uint32_t)machines.size() - 1); 223 223 if (machines[idx]) 224 224 { 225 225 Bstr strId; 226 226 Bstr machineName; 227 227 CHECK_ERROR(machines[idx], COMGETTER(Id)(strId.asOutParam())); 228 229 230 if(SUCCEEDED(rc))231 232 if(Utf8Str(machineName).startsWith("umtvm"))233 234 228 if (SUCCEEDED(rc)) 229 CHECK_ERROR(machines[idx], COMGETTER(Name)(machineName.asOutParam())); 230 if (SUCCEEDED(rc)) 231 { 232 if (Utf8Str(machineName).startsWith("umtvm")) 233 listToFill.push_back(strId); 234 } 235 235 } 236 236 } … … 265 265 // start all machines in pack 266 266 for (TMachinesList::iterator it = machinesList.begin(); 267 it != machinesList.end() && g_RunTest; ++it) 267 it != machinesList.end() && g_RunTest; 268 ++it) 268 269 { 269 270 ComPtr<ISession> session; … … 278 279 // stop all machines in the pack 279 280 for (TMachinesList::iterator it = machinesList.begin(); 280 it != machinesList.end() && g_RunTest; ++it) 281 it != machinesList.end() && g_RunTest; 282 ++it) 281 283 { 282 284 ComPtr<ISession> session; … … 296 298 static Bstr tstMakeMachineName(int i) 297 299 { 298 299 300 300 char szMachineName[32]; 301 RTStrPrintf(szMachineName, sizeof(szMachineName), "umtvm%d", i); 302 return Bstr(szMachineName); 301 303 } 302 304 … … 304 306 static int tstCreateMachines(IVirtualBox* pVBox) 305 307 { 306 307 308 for(uint32_t i = 0; i < g_Args.numberMachines; i++)309 310 311 312 313 314 /** Default VM settings */315 CHECK_ERROR(pVBox, CreateMachine(NULL, /** Settings */316 machineName.raw(), /** Name */317 ComSafeArrayAsInParam(groups), /** Groups */318 NULL, /** OS Type */319 NULL, /** Create flags */320 ptrMachine.asOutParam()));308 HRESULT rc; 309 // create machines for the test 310 for (uint32_t i = 0; i < g_Args.numberMachines; i++) 311 { 312 ComPtr<IMachine> ptrMachine; 313 com::SafeArray<BSTR> groups; 314 315 Bstr machineName(tstMakeMachineName(i)); 316 /* Default VM settings */ 317 CHECK_ERROR(pVBox, CreateMachine(NULL, /* Settings */ 318 machineName.raw(), /* Name */ 319 ComSafeArrayAsInParam(groups), /* Groups */ 320 NULL, /* OS Type */ 321 NULL, /* Create flags */ 322 ptrMachine.asOutParam())); 321 323 if (SUCCEEDED(rc)) 322 324 { … … 325 327 } 326 328 327 329 RTSemEventSignal(g_PingEevent); 328 330 RTThreadSleep(100); 329 330 331 } 332 return rc; 331 333 } 332 334 … … 334 336 static int tstClean(IVirtualBox* pVBox, IVirtualBoxClient* pClient) 335 337 { 336 338 HRESULT rc; 337 339 MachineState_T machineState; 338 340 339 340 for(uint32_t i = 0; i < g_Args.numberMachines; i++)341 342 343 344 345 346 347 348 349 /** Delete created VM and its files */341 // stop all machines created for the test 342 for (uint32_t i = 0; i < g_Args.numberMachines; i++) 343 { 344 ComPtr<IMachine> machine; 345 ComPtr<IProgress> progress; 346 ComPtr<ISession> session; 347 SafeIfaceArray<IMedium> media; 348 349 Bstr machineName(tstMakeMachineName(i)); 350 351 /* Delete created VM and its files */ 350 352 CHECK_ERROR(pVBox, FindMachine(machineName.raw(), machine.asOutParam())); 351 353 … … 369 371 if (SUCCEEDED(rc)) 370 372 RTPrintf("Machine '%ls' deleted.\n", machineName.raw()); 371 372 373 } 374 375 376 DECLCALLBACK(int) tstThreadRun(RTTHREAD thread, void *pvUser)373 } 374 return rc; 375 } 376 377 378 static DECLCALLBACK(int) tstThreadRun(RTTHREAD thread, void *pvUser) 377 379 { 378 380 TestThreadArgs* args = (TestThreadArgs*)pvUser; … … 388 390 389 391 rc = TST_COM_EXPR(ptrVBoxClient.createInprocObject(CLSID_VirtualBoxClient)); 390 if (SUCCEEDED(rc))392 if (SUCCEEDED(rc)) 391 393 rc = TST_COM_EXPR(ptrVBoxClient->COMGETTER(VirtualBox)(ptrVBox.asOutParam())); 392 394 if (SUCCEEDED(rc)) … … 404 406 } 405 407 406 g_RunTest = FALSE;408 g_RunTest = false; 407 409 RTSemEventSignal(g_PingEevent); 408 410 RTThreadSleep(100); … … 416 418 417 419 418 int ParseArguments(int argc, char **argv, TestThreadArgs*pArgs)420 static int ParseArguments(int argc, char **argv, TestThreadArgs *pArgs) 419 421 { 420 422 RTGETOPTSTATE GetState; … … 422 424 static const RTGETOPTDEF s_aOptions[] = 423 425 { 424 { "--packsize",'p', RTGETOPT_REQ_UINT32 }, // number of machines to start together425 { "--lock",'s', RTGETOPT_REQ_UINT32 }, // percentage of VM sessions closed without Unlok426 { "--time",'t', RTGETOPT_REQ_UINT64 }, // required time of load test execution, in seconds427 { "--machines" , 'u', RTGETOPT_REQ_UINT64}426 { "--packsize", 'p', RTGETOPT_REQ_UINT32 }, // number of machines to start together 427 { "--lock", 's', RTGETOPT_REQ_UINT32 }, // percentage of VM sessions closed without Unlok 428 { "--time", 't', RTGETOPT_REQ_UINT64 }, // required time of load test execution, in seconds 429 { "--machines" , 'u', RTGETOPT_REQ_UINT32 } 428 430 }; 429 431 int rc = RTGetOptInit(&GetState, argc, argv, s_aOptions, RT_ELEMENTS(s_aOptions), 1, 0 /*fFlags*/); 430 AssertRC (rc);431 Assert (pArgs != NULL);432 AssertRCReturn(rc, rc); 433 AssertPtr(pArgs); 432 434 433 435 while ((rc = RTGetOpt(&GetState, &ValueUnion)) != 0) … … 435 437 switch (rc) 436 438 { 437 case 'p': 438 { 439 if (ValueUnion.u32 == 0) 440 { 441 RTPrintf("--packsize should be more then zero\n"); 442 return VERR_INVALID_PARAMETER; 443 } 444 if(ValueUnion.u32 > 16000) 445 { 446 RTPrintf("maximum --packsize value is 16000.\n" 447 "That means can use no more then 16000 machines for the test.\n"); 448 return VERR_INVALID_PARAMETER; 449 } 450 pArgs->machinesPackSize = ValueUnion.u32; 451 break; 452 } 453 case 's': 454 { 455 if (ValueUnion.u32 > 100) 456 { 457 RTPrintf("maximum --lock value is 100.\n" 458 "That means 100 percent of sessions should be closed without unlock.\n"); 459 return VERR_INVALID_PARAMETER; 460 } 461 pArgs->percentsUnlok = ValueUnion.u32; 462 break; 463 } 464 case 't': 465 { 466 pArgs->executionTime = ValueUnion.u64 * 1000; 467 break; 468 } 469 case 'u': 470 { 471 if (ValueUnion.u32 > 16000) 472 { 473 RTPrintf("maximum --machines value is 16000.\n" 474 "That means can make no more then 16000 machines for the test.\n"); 475 return VERR_INVALID_PARAMETER; 476 } 477 if (ValueUnion.u32 < pArgs->machinesPackSize) 478 { 479 RTPrintf("--machines value should be larger then --packsize value.\n"); 480 return VERR_INVALID_PARAMETER; 481 } 482 pArgs->numberMachines = ValueUnion.u32; 483 break; 484 } 485 default: 486 { 487 RTPrintf("Invalid arguments.\n"); 488 return rc; 489 } 490 } 439 case 'p': 440 if (ValueUnion.u32 == 0) 441 { 442 RTPrintf("--packsize should be more then zero\n"); 443 return VERR_INVALID_PARAMETER; 444 } 445 if (ValueUnion.u32 > 16000) 446 { 447 RTPrintf("maximum --packsize value is 16000.\n" 448 "That means can use no more then 16000 machines for the test.\n"); 449 return VERR_INVALID_PARAMETER; 450 } 451 pArgs->machinesPackSize = ValueUnion.u32; 452 break; 453 454 case 's': 455 if (ValueUnion.u32 > 100) 456 { 457 RTPrintf("maximum --lock value is 100.\n" 458 "That means 100 percent of sessions should be closed without unlock.\n"); 459 return VERR_INVALID_PARAMETER; 460 } 461 pArgs->percentsUnlok = ValueUnion.u32; 462 break; 463 464 case 't': 465 pArgs->cMsExecutionTime = ValueUnion.u64 * 1000; 466 break; 467 468 case 'u': 469 if (ValueUnion.u32 > 16000) 470 { 471 RTPrintf("maximum --machines value is 16000.\n" 472 "That means can make no more then 16000 machines for the test.\n"); 473 return VERR_INVALID_PARAMETER; 474 } 475 if (ValueUnion.u32 < pArgs->machinesPackSize) 476 { 477 RTPrintf("--machines value should be larger then --packsize value.\n"); 478 return VERR_INVALID_PARAMETER; 479 } 480 pArgs->numberMachines = ValueUnion.u32; 481 break; 482 483 default: 484 RTGetOptPrintError(rc, &ValueUnion); 485 return rc; 486 } 491 487 } 492 488 return rc; … … 495 491 496 492 /** 497 * Examples: 498 * - tstVBoxClientWatcherLoad --packsize 500 --lock 10 --time 14400 --machines 4000 499 * It will create 4000 VMs with names "utmvm0"..."utmvm3999" 500 * It will start 500 random VMs together, stop them, 501 * without closing their session with probability 10%, 502 * will repeat this during 4 hours. 503 * After test it will delete all "utmvm..." machines. 504 * 505 * - tstVBoxClientWatcherLoad --packsize 1 --lock 30 --time 3600 --machines 1000 506 * It will create 1000 VMs with names "utmvm0"..."utmvm999" 507 * It will start random VM - stop them, 508 * without closing their session with probability 30%, 509 * will repeat this during 30 minutes. 510 * After test it will delete all "utmvm..." machines. 511 */ 493 * 494 * Examples: 495 * - tstVBoxClientWatcherLoad --packsize 500 --lock 10 --time 14400 --machines 4000 496 * It will create 4000 VMs with names "utmvm0"..."utmvm3999" 497 * It will start 500 random VMs together, stop them, 498 * without closing their session with probability 10%, 499 * will repeat this during 4 hours. 500 * After test it will delete all "utmvm..." machines. 501 * 502 * - tstVBoxClientWatcherLoad --packsize 1 --lock 30 --time 3600 --machines 1000 503 * It will create 1000 VMs with names "utmvm0"..."utmvm999" 504 * It will start random VM - stop them, 505 * without closing their session with probability 30%, 506 * will repeat this during 30 minutes. 507 * After test it will delete all "utmvm..." machines. 508 */ 512 509 int main(int argc, char **argv) 513 510 { … … 516 513 return rcExit; 517 514 SUPR3Init(NULL); 518 com::Initialize(); 515 com::Initialize(); 519 516 RTTestBanner(g_hTest); 517 520 518 RTPrintf("Initializing ...\n"); 521 519 int rc = RTSemEventCreate(&g_PingEevent); … … 524 522 g_Args.machinesPackSize = 100; 525 523 g_Args.percentsUnlok = 10; 526 g_Args. executionTime = 3 * 60 * 1000; // 3 minutes of test execution by default527 524 g_Args.cMsExecutionTime = 3*RT_MS_1MIN; 525 g_Args.numberMachines = 200; 528 526 rc = ParseArguments(argc, argv, &g_Args); 529 527 if (RT_FAILURE(rc)) 530 {531 528 return RTTestSkipAndDestroy(g_hTest, "Invalid arguments.\n"); 532 } 533 RTPrintf("Arguments packSize = %d, percentUnlok = %d, time = %d.\n", 534 g_Args.machinesPackSize, 535 g_Args.percentsUnlok, 536 g_Args.executionTime); 529 530 RTPrintf("Arguments packSize = %d, percentUnlok = %d, time = %lld.\n", 531 g_Args.machinesPackSize, g_Args.percentsUnlok, g_Args.cMsExecutionTime); 537 532 538 RTTHREAD Thread; 539 rc = RTThreadCreate(&Thread, tstThreadRun, (void *)&g_Args, 540 0, RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE, "tstThreadRun"); 541 AssertRC(rc); 542 543 uint64_t start = RTTimeMilliTS(); 544 while (RTTimeMilliTS() - start < g_Args.executionTime && g_RunTest) 545 { 546 // check that test thread didn't hang and call us periodically 547 // allowed 30 seconds for operation - start or stop VM 548 rc = RTSemEventWait(g_PingEevent, 3 * 60 * 1000); 549 if (RT_FAILURE(rc)) 550 { 551 if (rc == VERR_TIMEOUT) 552 { 553 // seems that test thread hungs - alert 554 RTTestFailed(g_hTest, "Test failed - one of operations hunged. VBoxSvc deadlock detected.\n"); 555 com::Shutdown(); 556 return RTTestSummaryAndDestroy(g_hTest); 557 } 558 AssertRC(rc); 559 } 560 } 561 562 RTPrintf("Finishing...\n"); 563 564 // finish test thread 565 g_RunTest = FALSE; 566 // wait it for finish 567 RTThreadWait(Thread, RT_INDEFINITE_WAIT, &rc); 533 RTTHREAD hThread; 534 rc = RTThreadCreate(&hThread, tstThreadRun, (void *)&g_Args, 535 0, RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE, "tstThreadRun"); 536 if (RT_SUCCESS(rc)) 537 { 538 AssertRC(rc); 539 540 uint64_t msStart = RTTimeMilliTS(); 541 while (RTTimeMilliTS() - msStart < g_Args.cMsExecutionTime && g_RunTest) 542 { 543 // check that test thread didn't hang and call us periodically 544 // allowed 30 seconds for operation - msStart or stop VM 545 rc = RTSemEventWait(g_PingEevent, 3 * 60 * 1000); 546 if (RT_FAILURE(rc)) 547 { 548 if (rc == VERR_TIMEOUT) 549 { 550 // seems that test thread hungs - alert 551 RTTestFailed(g_hTest, "Test failed - one of operations hunged. VBoxSvc deadlock detected.\n"); 552 com::Shutdown(); 553 return RTTestSummaryAndDestroy(g_hTest); 554 } 555 AssertRC(rc); 556 } 557 } 558 559 RTPrintf("Finishing...\n"); 560 561 // finish test thread 562 g_RunTest = false; 563 // wait it for finish 564 RTThreadWait(hThread, RT_INDEFINITE_WAIT, &rc); 565 } 568 566 RTSemEventDestroy(g_PingEevent); 569 567 570 568 com::Shutdown(); 571 569 if (RT_FAILURE(rc)) 572 {573 570 RTTestFailed(g_hTest, "Test failed.\n"); 574 return RTTestSummaryAndDestroy(g_hTest);575 }576 571 else 577 {578 572 RTTestPassed(g_hTest, "Test finished.\n"); 579 }580 573 return RTTestSummaryAndDestroy(g_hTest); 581 574 } 575
Note:
See TracChangeset
for help on using the changeset viewer.