[60168] | 1 | /** @file
|
---|
| 2 | * tstVBoxMultipleVM - load test for ClientWatcher.
|
---|
| 3 | */
|
---|
| 4 |
|
---|
| 5 | /*
|
---|
[98103] | 6 | * Copyright (C) 2006-2023 Oracle and/or its affiliates.
|
---|
[60168] | 7 | *
|
---|
[96407] | 8 | * This file is part of VirtualBox base platform packages, as
|
---|
| 9 | * available from https://www.virtualbox.org.
|
---|
| 10 | *
|
---|
| 11 | * This program is free software; you can redistribute it and/or
|
---|
| 12 | * modify it under the terms of the GNU General Public License
|
---|
| 13 | * as published by the Free Software Foundation, in version 3 of the
|
---|
| 14 | * License.
|
---|
| 15 | *
|
---|
| 16 | * This program is distributed in the hope that it will be useful, but
|
---|
| 17 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 19 | * General Public License for more details.
|
---|
| 20 | *
|
---|
| 21 | * You should have received a copy of the GNU General Public License
|
---|
| 22 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
| 23 | *
|
---|
| 24 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
[60168] | 25 | */
|
---|
| 26 |
|
---|
| 27 |
|
---|
| 28 | /*********************************************************************************************************************************
|
---|
| 29 | * Header Files *
|
---|
| 30 | *********************************************************************************************************************************/
|
---|
| 31 | #include <VBox/com/com.h>
|
---|
| 32 | #include <VBox/com/string.h>
|
---|
| 33 | #include <VBox/com/array.h>
|
---|
| 34 | #include <VBox/com/Guid.h>
|
---|
| 35 | #include <VBox/com/ErrorInfo.h>
|
---|
| 36 | #include <VBox/com/errorprint.h>
|
---|
| 37 | #include <iprt/assert.h>
|
---|
[76474] | 38 | #include <iprt/errcore.h>
|
---|
[60168] | 39 | #include <VBox/com/VirtualBox.h>
|
---|
| 40 | #include <iprt/stream.h>
|
---|
| 41 | #include <iprt/semaphore.h>
|
---|
| 42 | #include <iprt/thread.h>
|
---|
| 43 | #include <VBox/sup.h>
|
---|
| 44 |
|
---|
| 45 | #include <vector>
|
---|
| 46 | #include <algorithm>
|
---|
| 47 |
|
---|
| 48 | #include <iprt/test.h>
|
---|
| 49 | #include <iprt/time.h>
|
---|
| 50 | #include <iprt/rand.h>
|
---|
| 51 | #include <iprt/getopt.h>
|
---|
| 52 |
|
---|
| 53 | using namespace com;
|
---|
| 54 |
|
---|
| 55 |
|
---|
| 56 | /*********************************************************************************************************************************
|
---|
[63412] | 57 | * Structures and Typedefs *
|
---|
[60168] | 58 | *********************************************************************************************************************************/
|
---|
| 59 | /* Arguments of test thread */
|
---|
| 60 | struct TestThreadArgs
|
---|
| 61 | {
|
---|
[60169] | 62 | /** number of machines that should be run simultaneousely */
|
---|
[60168] | 63 | uint32_t machinesPackSize;
|
---|
[60169] | 64 | /** percents of VM Stop operation what should be called
|
---|
| 65 | * without session unlocking */
|
---|
[60168] | 66 | uint32_t percentsUnlok;
|
---|
[60169] | 67 | /** How much time in milliseconds test will be executed */
|
---|
| 68 | uint64_t cMsExecutionTime;
|
---|
| 69 | /** How much machines create for the test */
|
---|
| 70 | uint32_t numberMachines;
|
---|
[60168] | 71 | };
|
---|
| 72 |
|
---|
| 73 |
|
---|
[63412] | 74 | /*********************************************************************************************************************************
|
---|
| 75 | * Global Variables & defs *
|
---|
| 76 | *********************************************************************************************************************************/
|
---|
| 77 | static RTTEST g_hTest;
|
---|
| 78 | #ifdef RT_ARCH_AMD64
|
---|
| 79 | typedef std::vector<Bstr> TMachinesList;
|
---|
| 80 | static volatile bool g_RunTest = true;
|
---|
| 81 | static RTSEMEVENT g_PingEevent;
|
---|
| 82 | static volatile uint64_t g_Counter = 0;
|
---|
| 83 | static TestThreadArgs g_Args;
|
---|
[60168] | 84 |
|
---|
[63412] | 85 |
|
---|
[60168] | 86 | /** Worker for TST_COM_EXPR(). */
|
---|
| 87 | static HRESULT tstComExpr(HRESULT hrc, const char *pszOperation, int iLine)
|
---|
| 88 | {
|
---|
| 89 | if (FAILED(hrc))
|
---|
| 90 | {
|
---|
| 91 | RTTestFailed(g_hTest, "%s failed on line %u with hrc=%Rhrc\n", pszOperation, iLine, hrc);
|
---|
| 92 | }
|
---|
| 93 | return hrc;
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 |
|
---|
[60383] | 97 | #define CHECK_ERROR_L(iface, method) \
|
---|
| 98 | do { \
|
---|
[95142] | 99 | hrc = iface->method; \
|
---|
[95143] | 100 | if (FAILED(hrc)) \
|
---|
| 101 | RTPrintf("warning: %s->%s failed on line %u with hrc=%Rhrc\n", #iface, #method, __LINE__, hrc);\
|
---|
[60383] | 102 | } while (0)
|
---|
| 103 |
|
---|
| 104 |
|
---|
[60168] | 105 | /** Macro that executes the given expression and report any failure.
|
---|
| 106 | * The expression must return a HRESULT. */
|
---|
| 107 | #define TST_COM_EXPR(expr) tstComExpr(expr, #expr, __LINE__)
|
---|
| 108 |
|
---|
| 109 |
|
---|
[60170] | 110 | static int tstStartVM(IVirtualBox *pVBox, ISession *pSession, Bstr machineID, bool fSkipUnlock)
|
---|
[60168] | 111 | {
|
---|
[95142] | 112 | HRESULT hrc;
|
---|
[60168] | 113 | ComPtr<IProgress> progress;
|
---|
| 114 | ComPtr<IMachine> machine;
|
---|
| 115 | Bstr machineName;
|
---|
| 116 |
|
---|
[95142] | 117 | hrc = TST_COM_EXPR(pVBox->FindMachine(machineID.raw(), machine.asOutParam()));
|
---|
| 118 | if(SUCCEEDED(hrc))
|
---|
| 119 | hrc = TST_COM_EXPR(machine->COMGETTER(Name)(machineName.asOutParam()));
|
---|
| 120 | if(SUCCEEDED(hrc))
|
---|
[80824] | 121 | {
|
---|
[95142] | 122 | hrc = machine->LaunchVMProcess(pSession, Bstr("headless").raw(),
|
---|
[80824] | 123 | ComSafeArrayNullInParam(), progress.asOutParam());
|
---|
| 124 | }
|
---|
[95142] | 125 | if (SUCCEEDED(hrc) && !progress.isNull())
|
---|
[60168] | 126 | {
|
---|
[60383] | 127 | CHECK_ERROR_L(progress, WaitForCompletion(-1));
|
---|
[95142] | 128 | if (SUCCEEDED(hrc))
|
---|
[60168] | 129 | {
|
---|
| 130 | BOOL completed = true;
|
---|
[60383] | 131 | CHECK_ERROR_L(progress, COMGETTER(Completed)(&completed));
|
---|
[95142] | 132 | if (SUCCEEDED(hrc))
|
---|
[60168] | 133 | {
|
---|
| 134 | Assert(completed);
|
---|
| 135 | LONG iRc;
|
---|
[60383] | 136 | CHECK_ERROR_L(progress, COMGETTER(ResultCode)(&iRc));
|
---|
[95142] | 137 | if (SUCCEEDED(hrc))
|
---|
[60168] | 138 | {
|
---|
| 139 | if (FAILED(iRc))
|
---|
| 140 | {
|
---|
| 141 | ProgressErrorInfo info(progress);
|
---|
[60383] | 142 | RTPrintf("Start VM '%ls' failed. Warning: %ls.\n", machineName.raw(), info.getText().raw());
|
---|
[60168] | 143 | }
|
---|
| 144 | else
|
---|
| 145 | RTPrintf("VM '%ls' started.\n", machineName.raw());
|
---|
| 146 | }
|
---|
| 147 | }
|
---|
| 148 | }
|
---|
[60170] | 149 | if (!fSkipUnlock)
|
---|
[60168] | 150 | pSession->UnlockMachine();
|
---|
| 151 | else
|
---|
| 152 | RTPrintf("Session unlock skipped.\n");
|
---|
| 153 | }
|
---|
[95142] | 154 | return hrc;
|
---|
[60168] | 155 | }
|
---|
| 156 |
|
---|
| 157 |
|
---|
[60170] | 158 | static int tstStopVM(IVirtualBox* pVBox, ISession* pSession, Bstr machineID, bool fSkipUnlock)
|
---|
[60168] | 159 | {
|
---|
| 160 | ComPtr<IMachine> machine;
|
---|
[95143] | 161 | HRESULT hrc = TST_COM_EXPR(pVBox->FindMachine(machineID.raw(), machine.asOutParam()));
|
---|
| 162 | if (SUCCEEDED(hrc))
|
---|
[63177] | 163 | {
|
---|
| 164 | Bstr machineName;
|
---|
[95143] | 165 | hrc = TST_COM_EXPR(machine->COMGETTER(Name)(machineName.asOutParam()));
|
---|
| 166 | if (SUCCEEDED(hrc))
|
---|
[60168] | 167 | {
|
---|
[63177] | 168 | MachineState_T machineState;
|
---|
[95143] | 169 | hrc = TST_COM_EXPR(machine->COMGETTER(State)(&machineState));
|
---|
[63177] | 170 | // check that machine is in running state
|
---|
[95143] | 171 | if ( SUCCEEDED(hrc)
|
---|
[63177] | 172 | && ( machineState == MachineState_Running
|
---|
| 173 | || machineState == MachineState_Paused))
|
---|
[60168] | 174 | {
|
---|
[63177] | 175 | ComPtr<IConsole> console;
|
---|
| 176 | ComPtr<IProgress> progress;
|
---|
| 177 |
|
---|
[95143] | 178 | hrc = TST_COM_EXPR(machine->LockMachine(pSession, LockType_Shared));
|
---|
| 179 | if(SUCCEEDED(hrc))
|
---|
[63177] | 180 | TST_COM_EXPR(pSession->COMGETTER(Console)(console.asOutParam()));
|
---|
[95143] | 181 | if(SUCCEEDED(hrc))
|
---|
| 182 | hrc = console->PowerDown(progress.asOutParam());
|
---|
| 183 | if (SUCCEEDED(hrc) && !progress.isNull())
|
---|
[60168] | 184 | {
|
---|
[63177] | 185 | //RTPrintf("Stopping VM %ls...\n", machineName.raw());
|
---|
| 186 | CHECK_ERROR_L(progress, WaitForCompletion(-1));
|
---|
[95143] | 187 | if (SUCCEEDED(hrc))
|
---|
[60168] | 188 | {
|
---|
[63177] | 189 | BOOL completed = true;
|
---|
| 190 | CHECK_ERROR_L(progress, COMGETTER(Completed)(&completed));
|
---|
[95143] | 191 | if (SUCCEEDED(hrc))
|
---|
[60168] | 192 | {
|
---|
[63177] | 193 | //ASSERT(completed);
|
---|
| 194 | LONG iRc;
|
---|
| 195 | CHECK_ERROR_L(progress, COMGETTER(ResultCode)(&iRc));
|
---|
[95143] | 196 | if (SUCCEEDED(hrc))
|
---|
[63177] | 197 | {
|
---|
| 198 | if (FAILED(iRc))
|
---|
| 199 | {
|
---|
| 200 | ProgressErrorInfo info(progress);
|
---|
| 201 | RTPrintf("Stop VM %ls failed. Warning: %ls.\n", machineName.raw(), info.getText().raw());
|
---|
[95143] | 202 | hrc = iRc;
|
---|
[63177] | 203 | }
|
---|
| 204 | else
|
---|
| 205 | {
|
---|
| 206 | RTPrintf("VM '%ls' stopped.\n", machineName.raw());
|
---|
| 207 | }
|
---|
| 208 | }
|
---|
[60168] | 209 | }
|
---|
| 210 | }
|
---|
[63177] | 211 | if (!fSkipUnlock)
|
---|
| 212 | pSession->UnlockMachine();
|
---|
| 213 | else
|
---|
| 214 | RTPrintf("Session unlock skipped.\n");
|
---|
[60168] | 215 | }
|
---|
| 216 | }
|
---|
| 217 | }
|
---|
| 218 | }
|
---|
[95143] | 219 | return hrc;
|
---|
[60168] | 220 | }
|
---|
| 221 |
|
---|
[62468] | 222 |
|
---|
[60168] | 223 | /**
|
---|
[60170] | 224 | * Get random @a maxCount machines from list of existing VMs.
|
---|
| 225 | *
|
---|
| 226 | * @note Can return less then maxCount machines.
|
---|
| 227 | */
|
---|
| 228 | static int tstGetMachinesList(IVirtualBox *pVBox, uint32_t maxCount, TMachinesList &listToFill)
|
---|
[60168] | 229 | {
|
---|
| 230 | com::SafeIfaceArray<IMachine> machines;
|
---|
[95143] | 231 | HRESULT hrc = TST_COM_EXPR(pVBox->COMGETTER(Machines)(ComSafeArrayAsOutParam(machines)));
|
---|
| 232 | if (SUCCEEDED(hrc))
|
---|
[63177] | 233 | {
|
---|
[62468] | 234 |
|
---|
[63177] | 235 | size_t cMachines = RT_MIN(machines.size(), maxCount);
|
---|
| 236 | for (size_t i = 0; i < cMachines; ++i)
|
---|
[60168] | 237 | {
|
---|
[63177] | 238 | // choose random index of machine
|
---|
| 239 | uint32_t idx = RTRandU32Ex(0, (uint32_t)machines.size() - 1);
|
---|
| 240 | if (machines[idx])
|
---|
[60169] | 241 | {
|
---|
[63177] | 242 | Bstr bstrId;
|
---|
| 243 | Bstr machineName;
|
---|
| 244 | CHECK_ERROR_L(machines[idx], COMGETTER(Id)(bstrId.asOutParam()));
|
---|
[95143] | 245 | if (SUCCEEDED(hrc))
|
---|
[63177] | 246 | CHECK_ERROR_L(machines[idx], COMGETTER(Name)(machineName.asOutParam()));
|
---|
[95143] | 247 | if (SUCCEEDED(hrc))
|
---|
[63177] | 248 | {
|
---|
| 249 | if (Utf8Str(machineName).startsWith("umtvm"))
|
---|
| 250 | listToFill.push_back(bstrId);
|
---|
| 251 | }
|
---|
[60169] | 252 | }
|
---|
[60168] | 253 | }
|
---|
[63177] | 254 |
|
---|
| 255 | // remove duplicates from the vector
|
---|
| 256 | std::sort(listToFill.begin(), listToFill.end());
|
---|
| 257 | listToFill.erase(std::unique(listToFill.begin(), listToFill.end()), listToFill.end());
|
---|
| 258 | RTPrintf("Filled pack of %d from %d machines.\n", listToFill.size(), machines.size());
|
---|
[60168] | 259 | }
|
---|
| 260 |
|
---|
[95143] | 261 | return hrc;
|
---|
[60168] | 262 | }
|
---|
| 263 |
|
---|
| 264 |
|
---|
| 265 | static int tstMachinesPack(IVirtualBox *pVBox, uint32_t maxPackSize, uint32_t percentage)
|
---|
| 266 | {
|
---|
[95143] | 267 | HRESULT hrc = S_OK;
|
---|
[60168] | 268 | TMachinesList machinesList;
|
---|
| 269 | bool alwaysUnlock = false;
|
---|
| 270 | uint64_t percN = 0;
|
---|
| 271 |
|
---|
[62468] | 272 | // choose and fill pack of machines for test
|
---|
[60168] | 273 | tstGetMachinesList(pVBox, maxPackSize, machinesList);
|
---|
| 274 |
|
---|
| 275 | RTPrintf("Start test.\n");
|
---|
| 276 | // screw up counter
|
---|
| 277 | g_Counter = UINT64_MAX - machinesList.size() <= g_Counter ? 0 : g_Counter;
|
---|
| 278 | if (percentage > 0)
|
---|
| 279 | percN = 100 / percentage;
|
---|
| 280 | else
|
---|
| 281 | alwaysUnlock = true;
|
---|
| 282 |
|
---|
| 283 | // start all machines in pack
|
---|
[62468] | 284 | for (TMachinesList::iterator it = machinesList.begin();
|
---|
[60169] | 285 | it != machinesList.end() && g_RunTest;
|
---|
| 286 | ++it)
|
---|
[60168] | 287 | {
|
---|
| 288 | ComPtr<ISession> session;
|
---|
[95143] | 289 | hrc = session.createInprocObject(CLSID_Session);
|
---|
| 290 | if (SUCCEEDED(hrc))
|
---|
[60168] | 291 | {
|
---|
[95143] | 292 | hrc = tstStartVM(pVBox, session, *it, !(alwaysUnlock || g_Counter++ % percN));
|
---|
[60168] | 293 | }
|
---|
| 294 | RTSemEventSignal(g_PingEevent);
|
---|
| 295 | RTThreadSleep(100);
|
---|
| 296 | }
|
---|
| 297 | // stop all machines in the pack
|
---|
[62468] | 298 | for (TMachinesList::iterator it = machinesList.begin();
|
---|
[60170] | 299 | it != machinesList.end() && g_RunTest;
|
---|
[60169] | 300 | ++it)
|
---|
[60168] | 301 | {
|
---|
| 302 | ComPtr<ISession> session;
|
---|
[95143] | 303 | hrc = session.createInprocObject(CLSID_Session);
|
---|
| 304 | if (SUCCEEDED(hrc))
|
---|
[60168] | 305 | {
|
---|
| 306 | // stop machines, skip session unlock of given % of machines
|
---|
[95143] | 307 | hrc = tstStopVM(pVBox, session, *it, !(alwaysUnlock || g_Counter++ % percN));
|
---|
[60168] | 308 | }
|
---|
| 309 | RTSemEventSignal(g_PingEevent);
|
---|
| 310 | RTThreadSleep(100);
|
---|
| 311 | }
|
---|
[95143] | 312 | return hrc;
|
---|
[60168] | 313 | }
|
---|
| 314 |
|
---|
| 315 |
|
---|
| 316 | static Bstr tstMakeMachineName(int i)
|
---|
| 317 | {
|
---|
[60169] | 318 | char szMachineName[32];
|
---|
| 319 | RTStrPrintf(szMachineName, sizeof(szMachineName), "umtvm%d", i);
|
---|
| 320 | return Bstr(szMachineName);
|
---|
[60168] | 321 | }
|
---|
| 322 |
|
---|
| 323 |
|
---|
[60170] | 324 | static int tstCreateMachines(IVirtualBox *pVBox)
|
---|
[60168] | 325 | {
|
---|
[95143] | 326 | HRESULT hrc = S_OK;
|
---|
[60169] | 327 | // create machines for the test
|
---|
| 328 | for (uint32_t i = 0; i < g_Args.numberMachines; i++)
|
---|
| 329 | {
|
---|
| 330 | ComPtr<IMachine> ptrMachine;
|
---|
| 331 | com::SafeArray<BSTR> groups;
|
---|
| 332 |
|
---|
| 333 | Bstr machineName(tstMakeMachineName(i));
|
---|
| 334 | /* Default VM settings */
|
---|
[60383] | 335 | CHECK_ERROR_L(pVBox, CreateMachine(NULL, /* Settings */
|
---|
[101035] | 336 | machineName.raw(), /* Name */
|
---|
| 337 | PlatformArchitecture_x86,
|
---|
| 338 | ComSafeArrayAsInParam(groups), /* Groups */
|
---|
| 339 | NULL, /* OS Type */
|
---|
| 340 | NULL, /** Cipher */
|
---|
| 341 | NULL, /** Password id */
|
---|
| 342 | NULL, /** Password */
|
---|
| 343 | NULL, /* Create flags */
|
---|
| 344 | ptrMachine.asOutParam()));
|
---|
[95143] | 345 | if (SUCCEEDED(hrc))
|
---|
[60168] | 346 | {
|
---|
[60383] | 347 | CHECK_ERROR_L(pVBox, RegisterMachine(ptrMachine));
|
---|
[60168] | 348 | RTPrintf("Machine '%ls' created\n", machineName.raw());
|
---|
| 349 | }
|
---|
| 350 |
|
---|
[60169] | 351 | RTSemEventSignal(g_PingEevent);
|
---|
[60168] | 352 | RTThreadSleep(100);
|
---|
[60169] | 353 | }
|
---|
[95143] | 354 | return hrc;
|
---|
[60168] | 355 | }
|
---|
| 356 |
|
---|
| 357 |
|
---|
[60170] | 358 | static int tstClean(IVirtualBox *pVBox, IVirtualBoxClient *pClient)
|
---|
[60168] | 359 | {
|
---|
[95143] | 360 | RT_NOREF(pClient);
|
---|
| 361 | HRESULT hrc = S_OK;
|
---|
[60168] | 362 |
|
---|
[60169] | 363 | // stop all machines created for the test
|
---|
| 364 | for (uint32_t i = 0; i < g_Args.numberMachines; i++)
|
---|
| 365 | {
|
---|
| 366 | ComPtr<IMachine> machine;
|
---|
| 367 | ComPtr<IProgress> progress;
|
---|
| 368 | ComPtr<ISession> session;
|
---|
| 369 | SafeIfaceArray<IMedium> media;
|
---|
| 370 |
|
---|
| 371 | Bstr machineName(tstMakeMachineName(i));
|
---|
| 372 |
|
---|
| 373 | /* Delete created VM and its files */
|
---|
[60383] | 374 | CHECK_ERROR_L(pVBox, FindMachine(machineName.raw(), machine.asOutParam()));
|
---|
[60168] | 375 |
|
---|
| 376 | // try to stop it again if it was not stopped
|
---|
[95143] | 377 | if (SUCCEEDED(hrc))
|
---|
[63177] | 378 | {
|
---|
| 379 | MachineState_T machineState;
|
---|
[60383] | 380 | CHECK_ERROR_L(machine, COMGETTER(State)(&machineState));
|
---|
[95143] | 381 | if ( SUCCEEDED(hrc)
|
---|
[63177] | 382 | && ( machineState == MachineState_Running
|
---|
| 383 | || machineState == MachineState_Paused) )
|
---|
| 384 | {
|
---|
[95143] | 385 | hrc = session.createInprocObject(CLSID_Session);
|
---|
| 386 | if (SUCCEEDED(hrc))
|
---|
[63177] | 387 | tstStopVM(pVBox, session, machineName, FALSE);
|
---|
| 388 | }
|
---|
[60168] | 389 | }
|
---|
| 390 |
|
---|
[95143] | 391 | if (SUCCEEDED(hrc))
|
---|
[60383] | 392 | CHECK_ERROR_L(machine, Unregister(CleanupMode_DetachAllReturnHardDisksOnly, ComSafeArrayAsOutParam(media)));
|
---|
[95143] | 393 | if (SUCCEEDED(hrc))
|
---|
[60383] | 394 | CHECK_ERROR_L(machine, DeleteConfig(ComSafeArrayAsInParam(media), progress.asOutParam()));
|
---|
[95143] | 395 | if (SUCCEEDED(hrc))
|
---|
[60383] | 396 | CHECK_ERROR_L(progress, WaitForCompletion(-1));
|
---|
[95143] | 397 | if (SUCCEEDED(hrc))
|
---|
[60168] | 398 | RTPrintf("Machine '%ls' deleted.\n", machineName.raw());
|
---|
[60169] | 399 | }
|
---|
[95143] | 400 | return hrc;
|
---|
[60168] | 401 | }
|
---|
| 402 |
|
---|
| 403 |
|
---|
[63258] | 404 | static DECLCALLBACK(int) tstThreadRun(RTTHREAD hThreadSelf, void *pvUser)
|
---|
[60168] | 405 | {
|
---|
[63258] | 406 | RT_NOREF(hThreadSelf);
|
---|
[60168] | 407 | TestThreadArgs* args = (TestThreadArgs*)pvUser;
|
---|
| 408 | Assert(args != NULL);
|
---|
| 409 | uint32_t maxPackSize = args->machinesPackSize;
|
---|
| 410 | uint32_t percentage = args->percentsUnlok;
|
---|
| 411 |
|
---|
[95143] | 412 | HRESULT hrc = com::Initialize();
|
---|
| 413 | if (SUCCEEDED(hrc))
|
---|
[60168] | 414 | {
|
---|
| 415 | ComPtr<IVirtualBoxClient> ptrVBoxClient;
|
---|
| 416 | ComPtr<IVirtualBox> ptrVBox;
|
---|
| 417 |
|
---|
[95143] | 418 | hrc = TST_COM_EXPR(ptrVBoxClient.createInprocObject(CLSID_VirtualBoxClient));
|
---|
| 419 | if (SUCCEEDED(hrc))
|
---|
| 420 | hrc = TST_COM_EXPR(ptrVBoxClient->COMGETTER(VirtualBox)(ptrVBox.asOutParam()));
|
---|
| 421 | if (SUCCEEDED(hrc))
|
---|
[60168] | 422 | {
|
---|
| 423 | RTPrintf("Creating machines...\n");
|
---|
| 424 | tstCreateMachines(ptrVBox);
|
---|
| 425 |
|
---|
| 426 | while (g_RunTest)
|
---|
| 427 | {
|
---|
[95143] | 428 | hrc = tstMachinesPack(ptrVBox, maxPackSize, percentage);
|
---|
[60168] | 429 | }
|
---|
| 430 |
|
---|
| 431 | RTPrintf("Deleting machines...\n");
|
---|
| 432 | tstClean(ptrVBox, ptrVBoxClient);
|
---|
| 433 | }
|
---|
| 434 |
|
---|
[60169] | 435 | g_RunTest = false;
|
---|
[60168] | 436 | RTSemEventSignal(g_PingEevent);
|
---|
| 437 | RTThreadSleep(100);
|
---|
| 438 |
|
---|
| 439 | ptrVBox = NULL;
|
---|
| 440 | ptrVBoxClient = NULL;
|
---|
| 441 | com::Shutdown();
|
---|
| 442 | }
|
---|
[95143] | 443 | return hrc;
|
---|
[60168] | 444 | }
|
---|
| 445 |
|
---|
| 446 |
|
---|
[60169] | 447 | static int ParseArguments(int argc, char **argv, TestThreadArgs *pArgs)
|
---|
[60168] | 448 | {
|
---|
| 449 | RTGETOPTSTATE GetState;
|
---|
| 450 | RTGETOPTUNION ValueUnion;
|
---|
| 451 | static const RTGETOPTDEF s_aOptions[] =
|
---|
| 452 | {
|
---|
[60169] | 453 | { "--packsize", 'p', RTGETOPT_REQ_UINT32 }, // number of machines to start together
|
---|
| 454 | { "--lock", 's', RTGETOPT_REQ_UINT32 }, // percentage of VM sessions closed without Unlok
|
---|
| 455 | { "--time", 't', RTGETOPT_REQ_UINT64 }, // required time of load test execution, in seconds
|
---|
| 456 | { "--machines" , 'u', RTGETOPT_REQ_UINT32 }
|
---|
[60168] | 457 | };
|
---|
| 458 | int rc = RTGetOptInit(&GetState, argc, argv, s_aOptions, RT_ELEMENTS(s_aOptions), 1, 0 /*fFlags*/);
|
---|
[60169] | 459 | AssertRCReturn(rc, rc);
|
---|
| 460 | AssertPtr(pArgs);
|
---|
[62468] | 461 |
|
---|
[60168] | 462 | while ((rc = RTGetOpt(&GetState, &ValueUnion)) != 0)
|
---|
| 463 | {
|
---|
| 464 | switch (rc)
|
---|
| 465 | {
|
---|
[60169] | 466 | case 'p':
|
---|
| 467 | if (ValueUnion.u32 == 0)
|
---|
| 468 | {
|
---|
| 469 | RTPrintf("--packsize should be more then zero\n");
|
---|
| 470 | return VERR_INVALID_PARAMETER;
|
---|
| 471 | }
|
---|
| 472 | if (ValueUnion.u32 > 16000)
|
---|
| 473 | {
|
---|
| 474 | RTPrintf("maximum --packsize value is 16000.\n"
|
---|
| 475 | "That means can use no more then 16000 machines for the test.\n");
|
---|
| 476 | return VERR_INVALID_PARAMETER;
|
---|
| 477 | }
|
---|
| 478 | pArgs->machinesPackSize = ValueUnion.u32;
|
---|
| 479 | break;
|
---|
| 480 |
|
---|
| 481 | case 's':
|
---|
| 482 | if (ValueUnion.u32 > 100)
|
---|
| 483 | {
|
---|
| 484 | RTPrintf("maximum --lock value is 100.\n"
|
---|
| 485 | "That means 100 percent of sessions should be closed without unlock.\n");
|
---|
| 486 | return VERR_INVALID_PARAMETER;
|
---|
| 487 | }
|
---|
| 488 | pArgs->percentsUnlok = ValueUnion.u32;
|
---|
| 489 | break;
|
---|
| 490 |
|
---|
| 491 | case 't':
|
---|
| 492 | pArgs->cMsExecutionTime = ValueUnion.u64 * 1000;
|
---|
| 493 | break;
|
---|
| 494 |
|
---|
| 495 | case 'u':
|
---|
| 496 | if (ValueUnion.u32 > 16000)
|
---|
| 497 | {
|
---|
| 498 | RTPrintf("maximum --machines value is 16000.\n"
|
---|
| 499 | "That means can make no more then 16000 machines for the test.\n");
|
---|
| 500 | return VERR_INVALID_PARAMETER;
|
---|
| 501 | }
|
---|
| 502 | if (ValueUnion.u32 < pArgs->machinesPackSize)
|
---|
| 503 | {
|
---|
| 504 | RTPrintf("--machines value should be larger then --packsize value.\n");
|
---|
| 505 | return VERR_INVALID_PARAMETER;
|
---|
| 506 | }
|
---|
| 507 | pArgs->numberMachines = ValueUnion.u32;
|
---|
| 508 | break;
|
---|
| 509 |
|
---|
| 510 | default:
|
---|
| 511 | RTGetOptPrintError(rc, &ValueUnion);
|
---|
| 512 | return rc;
|
---|
[60168] | 513 | }
|
---|
| 514 | }
|
---|
| 515 | return rc;
|
---|
| 516 | }
|
---|
| 517 |
|
---|
[63412] | 518 | #endif /* RT_ARCH_AMD64 */
|
---|
[60168] | 519 |
|
---|
[63412] | 520 |
|
---|
[60168] | 521 | /**
|
---|
[60169] | 522 | *
|
---|
| 523 | * Examples:
|
---|
| 524 | * - tstVBoxClientWatcherLoad --packsize 500 --lock 10 --time 14400 --machines 4000
|
---|
[60170] | 525 | * It will create 4000 VMs with names "utmvm0"..."utmvm3999". It will start
|
---|
| 526 | * 500 random VMs together, stop them, without closing their session with
|
---|
| 527 | * probability 10%, will repeat this over 4 hours. After test it will
|
---|
| 528 | * delete all "utmvm..." machines.
|
---|
[60169] | 529 | *
|
---|
| 530 | * - tstVBoxClientWatcherLoad --packsize 1 --lock 30 --time 3600 --machines 1000
|
---|
[60170] | 531 | * It will create 1000 VMs with names "utmvm0"..."utmvm999". It will start
|
---|
| 532 | * random VM - stop them, without closing their session with probability
|
---|
| 533 | * 30%, will repeat this over 30 minutes. After test it will delete all
|
---|
| 534 | * "utmvm..." machines.
|
---|
[60169] | 535 | */
|
---|
[60168] | 536 | int main(int argc, char **argv)
|
---|
| 537 | {
|
---|
[63260] | 538 | RT_NOREF(argc, argv);
|
---|
[60168] | 539 | RTEXITCODE rcExit = RTTestInitAndCreate("tstVBoxMultipleVM", &g_hTest);
|
---|
| 540 | if (rcExit != RTEXITCODE_SUCCESS)
|
---|
| 541 | return rcExit;
|
---|
| 542 | SUPR3Init(NULL);
|
---|
[60169] | 543 | com::Initialize();
|
---|
[60168] | 544 | RTTestBanner(g_hTest);
|
---|
[60169] | 545 |
|
---|
[60383] | 546 | #ifndef RT_ARCH_AMD64
|
---|
| 547 | /*
|
---|
[60385] | 548 | * Linux OOM killer when running many VMs on a 32-bit host.
|
---|
| 549 | */
|
---|
[63412] | 550 | return RTTestSkipAndDestroy(g_hTest, "The test can only run reliably on 64-bit hosts.");
|
---|
| 551 | #else /* RT_ARCH_AMD64 */
|
---|
[60383] | 552 |
|
---|
[60168] | 553 | RTPrintf("Initializing ...\n");
|
---|
| 554 | int rc = RTSemEventCreate(&g_PingEevent);
|
---|
| 555 | AssertRC(rc);
|
---|
| 556 |
|
---|
| 557 | g_Args.machinesPackSize = 100;
|
---|
| 558 | g_Args.percentsUnlok = 10;
|
---|
[60169] | 559 | g_Args.cMsExecutionTime = 3*RT_MS_1MIN;
|
---|
| 560 | g_Args.numberMachines = 200;
|
---|
[61099] | 561 |
|
---|
| 562 | /*
|
---|
| 563 | * Skip this test for the time being. Saw crashes on several test boxes but no time
|
---|
| 564 | * to debug.
|
---|
| 565 | */
|
---|
| 566 | if (argc == 1)
|
---|
| 567 | return RTTestSkipAndDestroy(g_hTest, "Test crashes sometimes.\n");
|
---|
| 568 |
|
---|
[60168] | 569 | rc = ParseArguments(argc, argv, &g_Args);
|
---|
| 570 | if (RT_FAILURE(rc))
|
---|
| 571 | return RTTestSkipAndDestroy(g_hTest, "Invalid arguments.\n");
|
---|
[60169] | 572 |
|
---|
| 573 | RTPrintf("Arguments packSize = %d, percentUnlok = %d, time = %lld.\n",
|
---|
| 574 | g_Args.machinesPackSize, g_Args.percentsUnlok, g_Args.cMsExecutionTime);
|
---|
[60170] | 575 |
|
---|
[60169] | 576 | RTTHREAD hThread;
|
---|
| 577 | rc = RTThreadCreate(&hThread, tstThreadRun, (void *)&g_Args,
|
---|
| 578 | 0, RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE, "tstThreadRun");
|
---|
| 579 | if (RT_SUCCESS(rc))
|
---|
[60168] | 580 | {
|
---|
[60169] | 581 | AssertRC(rc);
|
---|
| 582 |
|
---|
| 583 | uint64_t msStart = RTTimeMilliTS();
|
---|
| 584 | while (RTTimeMilliTS() - msStart < g_Args.cMsExecutionTime && g_RunTest)
|
---|
[60168] | 585 | {
|
---|
[60169] | 586 | // check that test thread didn't hang and call us periodically
|
---|
| 587 | // allowed 30 seconds for operation - msStart or stop VM
|
---|
| 588 | rc = RTSemEventWait(g_PingEevent, 3 * 60 * 1000);
|
---|
| 589 | if (RT_FAILURE(rc))
|
---|
[60168] | 590 | {
|
---|
[60169] | 591 | if (rc == VERR_TIMEOUT)
|
---|
| 592 | {
|
---|
[60649] | 593 | RTTestFailed(g_hTest, "Timeout. Deadlock?\n");
|
---|
[60169] | 594 | com::Shutdown();
|
---|
| 595 | return RTTestSummaryAndDestroy(g_hTest);
|
---|
| 596 | }
|
---|
| 597 | AssertRC(rc);
|
---|
[60168] | 598 | }
|
---|
| 599 | }
|
---|
[60169] | 600 |
|
---|
| 601 | RTPrintf("Finishing...\n");
|
---|
| 602 |
|
---|
| 603 | // finish test thread
|
---|
| 604 | g_RunTest = false;
|
---|
| 605 | // wait it for finish
|
---|
| 606 | RTThreadWait(hThread, RT_INDEFINITE_WAIT, &rc);
|
---|
[60168] | 607 | }
|
---|
| 608 | RTSemEventDestroy(g_PingEevent);
|
---|
[60170] | 609 |
|
---|
[60169] | 610 | com::Shutdown();
|
---|
[60168] | 611 | if (RT_FAILURE(rc))
|
---|
| 612 | RTTestFailed(g_hTest, "Test failed.\n");
|
---|
| 613 | else
|
---|
| 614 | RTTestPassed(g_hTest, "Test finished.\n");
|
---|
| 615 | return RTTestSummaryAndDestroy(g_hTest);
|
---|
[63412] | 616 | #endif /* RT_ARCH_AMD64 */
|
---|
[60168] | 617 | }
|
---|
[60169] | 618 |
|
---|