1 #include <gtest/gtest.h>
28 std::vector<unsigned int> tasks;
29 std::vector<std::string> jsons;
31 unsigned int taskId(0), caseNumber(0);
32 for (;
taskId<requestCount;)
34 jsons.push_back(std::forward<std::string>(DRCEStressTest::getJsonRequestSetExecuteAsyncLongTask(sessionType, ++
taskId)));
37 jsons.push_back(std::forward<std::string>(DRCEStressTest::getJsonRequestSetExecuteAsyncExpitedTask(sessionType, ++
taskId)));
38 jsons.push_back(std::forward<std::string>(DRCEStressTest::getJsonRequestSetExecuteAsyncShortTask(sessionType, ++
taskId)));
39 jsons.push_back(std::forward<std::string>(DRCEStressTest::getJsonRequestSetExecuteSyncShortTask(sessionType, ++
taskId)));
41 jsons.push_back(std::forward<std::string>(DRCEStressTest::generateJsonRequest(caseNumber++, tasks.back())));
46 for (
size_t i=0;i<tasks.size();++i)
48 jsons.push_back(std::forward<std::string>(DRCEStressTest::generateJsonRequest(caseNumber++, tasks.back())));
53 for (
size_t i=0;i<jsons.size();++i)
55 DRCEStressTest::executeRequest(fObj, jsons[i]);
59 Poco::Thread::sleep(1000);
62 printSuccess (
"Test Multiple Requests");
67 std::string resultJson = fObj.
Process(json);
74 ASSERT_FALSE(resultJsonMessage.isError()) <<
printError(resultJsonMessage);
75 ASSERT_EQ(resultJsonMessage.getErrorCode(),
NO_ERROR);
76 ASSERT_TRUE(resultJsonMessage.getErrorMsg().empty());
79 std::string DRCEStressTest::generateJsonRequest(
unsigned int caseNumber,
unsigned int requestId)
84 case 0: json = DRCEStressTest::getJsonRequestCheckState(DRCETaskRequestCheckState::CheckType::ctUninitialized, requestId);
86 case 1: json = DRCEStressTest::getJsonRequestCheckState(DRCETaskRequestCheckState::CheckType::ctSimple, requestId);
88 case 2: json = DRCEStressTest::getJsonRequestCheckState(DRCETaskRequestCheckState::CheckType::ctExtended, requestId);
90 case 3: json = DRCEStressTest::getJsonRequestGetData(DRCETaskRequestGetData::FetchType::ftUninitialized, requestId);
92 case 4: json = DRCEStressTest::getJsonRequestGetData(DRCETaskRequestGetData::FetchType::ftDeleteDataAfterFetch, requestId);
94 case 5: json = DRCEStressTest::getJsonRequestGetData(DRCETaskRequestGetData::FetchType::ftNotDeleteDataAfterFetch, requestId);
96 case 6: json = DRCEStressTest::getJsonRequestTerminate(DRCETaskRequestTerminate::AlgorithmType::atDefault, requestId);
98 case 7: json = DRCEStressTest::getJsonRequestTerminate(DRCETaskRequestTerminate::AlgorithmType::atCustom, requestId);
106 std::string DRCEStressTest::getJsonRequestSetExecute(DRCETaskRequestSetExecute& requestSetExecute,
unsigned int requestId)
108 std::stringstream sourceJson;
109 sourceJson << requestSetExecute;
113 DRCEInputJsonMessage inputJsonMessage;
114 inputJsonMessage.setRequestType(DRCETaskRequest::RequestType::rtSetTaskExecute);
115 inputJsonMessage.setRequestData(sourceJson.str());
116 inputJsonMessage.setRequestId(requestId);
119 sourceJson << inputJsonMessage;
121 return sourceJson.str();
126 const std::string
command =
"echo \"scale=4000; 4*a(1)\" | bc -l && sleep 60 && ps xau";
128 DRCETaskRequestSetExecute requestSetExecute;
132 sessionOptions.timeMax = 10000;
133 sessionOptions.tmode = SessionOptions::ThreadMode::tmAsync;
134 requestSetExecute.setSessionOptions(std::forward<SessionOptions>(sessionOptions));
135 requestSetExecute.setCommandLine(command);
137 return DRCEStressTest::getJsonRequestSetExecute(requestSetExecute, requestId);
142 const std::string command =
"echo \"scale=4000; 4*a(1)\" | bc -l && ps xau";
144 DRCETaskRequestSetExecute requestSetExecute;
148 sessionOptions.timeMax = 100000;
149 sessionOptions.tmode = SessionOptions::ThreadMode::tmAsync;
150 requestSetExecute.setSessionOptions(std::forward<SessionOptions>(sessionOptions));
151 requestSetExecute.setCommandLine(command);
153 return DRCEStressTest::getJsonRequestSetExecute(requestSetExecute, requestId);
156 std::string DRCEStressTest::getJsonRequestSetExecuteAsyncShortTask(
SessionOptions::SessionType sessionType,
unsigned int requestId)
158 const std::string command =
"sort";
161 DRCETaskRequestSetExecute requestSetExecute;
165 sessionOptions.timeMax = 100000;
166 sessionOptions.tmode = SessionOptions::ThreadMode::tmAsync;
167 requestSetExecute.setSessionOptions(std::forward<SessionOptions>(sessionOptions));
170 resourceLimits.procMax = 500;
171 resourceLimits.rramFreeMin = 100000;
172 requestSetExecute.setResourceLimits(resourceLimits);
174 requestSetExecute.setCommandLine(command);
175 requestSetExecute.setInputStream(inputStream);
177 return DRCEStressTest::getJsonRequestSetExecute(requestSetExecute, requestId);
182 const std::string command =
"sort";
183 const std::string inputStream =
"def\nabc\n123\n";
185 DRCETaskRequestSetExecute requestSetExecute;
189 sessionOptions.timeMax = 100000;
190 sessionOptions.tmode = SessionOptions::ThreadMode::tmSync;
191 requestSetExecute.setSessionOptions(std::forward<SessionOptions>(sessionOptions));
192 requestSetExecute.setCommandLine(command);
193 requestSetExecute.setInputStream(inputStream);
195 return DRCEStressTest::getJsonRequestSetExecute(requestSetExecute, requestId);
201 DRCETaskRequestCheckState requestCheckState;
202 requestCheckState.setCheckType(checkType);
204 std::stringstream sourceJson;
205 sourceJson << requestCheckState;
207 DRCEInputJsonMessage inputJsonMessage;
208 inputJsonMessage.setRequestType(DRCETaskRequest::RequestType::rtCheckTaskState);
209 inputJsonMessage.setRequestData(sourceJson.str());
210 inputJsonMessage.setRequestId(requestId);
213 sourceJson << inputJsonMessage;
215 return sourceJson.str();
220 DRCETaskRequestGetData requestGetData;
221 requestGetData.setFetchType(fetchType);
223 std::stringstream sourceJson;
224 sourceJson << requestGetData;
226 DRCEInputJsonMessage inputJsonMessage;
227 inputJsonMessage.setRequestType(DRCETaskRequest::RequestType::rtGetTaskData);
228 inputJsonMessage.setRequestData(sourceJson.str());
229 inputJsonMessage.setRequestId(requestId);
232 sourceJson << inputJsonMessage;
234 return sourceJson.str();
239 DRCETaskRequestTerminate requestTerminate;
240 requestTerminate.setTaskId(requestId);
241 requestTerminate.setAlgorithmType(algorithmType);
242 requestTerminate.setDelayValue(1000);
243 requestTerminate.setRepeatValue(3);
244 requestTerminate.setSignalValue(9);
246 std::stringstream sourceJson;
247 sourceJson << requestTerminate;
250 DRCEInputJsonMessage inputJsonMessage;
251 inputJsonMessage.setRequestType(DRCETaskRequest::RequestType::rtTerminateTask);
252 inputJsonMessage.setRequestData(sourceJson.str());
253 inputJsonMessage.setRequestId(requestId);
256 sourceJson << inputJsonMessage;
258 return sourceJson.str();
264 const std::string command = (commandLine.empty())?(
"echo \"scale=2000; 4*a(1)\" | bc -l && ps xau"):
commandLine;
266 DRCETaskRequestSetExecute requestSetExecute;
270 sessionOptions.timeMax = 1000000;
271 sessionOptions.tmode = threadMode;
272 requestSetExecute.setSessionOptions(std::forward<SessionOptions>(sessionOptions));
273 requestSetExecute.setCommandLine(command);
274 requestSetExecute.setResourceLimits(resourceLimits);
276 return DRCEStressTest::getJsonRequestSetExecute(requestSetExecute, requestId);
280 unsigned int DRCEStressTest::getRequestTime(DRCEFunctionalObject& fObj,
unsigned int requestId)
283 std::string resultJson = fObj.Process(DRCEStressTest::getJsonRequestGetData(DRCETaskRequestGetData::FetchType::ftNotDeleteDataAfterFetch, requestId));
285 DRCEOutputJsonMessage resultJsonMessage(resultJson);
286 if (resultJsonMessage.getResultData().getItemsCount()==1)
287 elapsedTime = resultJsonMessage.getResultData().getDataItem(0).getTime();
293 std::map<unsigned int, unsigned int>& delayTimes, std::map<unsigned int, unsigned int>& times)
297 fObj.setMaxThreadCount(requestCount);
298 fObj.setResourceMonitorTimePeriod(10000);
301 for (;taskId<requestCount;)
304 std::string resultJson = fObj.Process(DRCEStressTest::getJsonRequestSetExecuteAsyncLongTask(sessionType, ++taskId));
306 ASSERT_FALSE(fObj.isError()) <<
printError(fObj);
307 ASSERT_EQ(fObj.getErrorCode(),
NO_ERROR);
308 ASSERT_TRUE(fObj.getErrorMsg().empty());
310 DRCEOutputJsonMessage resultJsonMessage(resultJson);
311 ASSERT_FALSE(resultJsonMessage.isError()) <<
printError(resultJsonMessage);
312 ASSERT_EQ(resultJsonMessage.getErrorCode(),
NO_ERROR);
313 ASSERT_TRUE(resultJsonMessage.getErrorMsg().empty());
315 Poco::Timestamp::TimeDiff diff = now.elapsed();
316 delayTimes[
taskId] = diff;
322 while(fObj.getAsyncTasksCount())
324 Poco::Thread::sleep(5000);
327 for (
size_t i=0;i<requestCount;++i)
329 times[i+1] = DRCEStressTest::getRequestTime(fObj, i+1);
336 const unsigned int SZ = repeat;
337 unsigned int requestCounts[SZ];
338 for (
unsigned int i=0;i<SZ;++i)
340 requestCounts[i] =
static_cast<double>(requestCount/(i+1));
343 std::map<unsigned int, unsigned int> delayTimes[SZ];
344 std::map<unsigned int, unsigned int> times[SZ];
347 for (
unsigned int i=0;i<SZ;++i)
354 Poco::Thread::sleep(1000);
357 std::ofstream ofs(
"timeDelay.log", std::fstream::trunc);
358 ofs <<
"time delay (in microseconds):\n";
359 for (
unsigned int i=0;i<SZ;++i)
361 for (
size_t k=0;k<requestCount;++k)
362 ofs << delayTimes[i][k+1] <<
"\t";
365 ofs <<
"\nfull time (in msec):\n";
366 for (
unsigned int i=0;i<SZ;++i)
368 for (
size_t k=0;k<requestCount;++k)
369 ofs << times[i][k+1] <<
"\t";
375 printSuccess (
"Test Requests Time Delay");
383 unsigned int& taskId,
385 const std::string& commandLine)
387 std::string resultJson = fObj.
Process(DRCEStressTest::getJsonRequestResourceLimits(sessionType, threadMode, ++taskId, resourceLimits, commandLine));
396 ASSERT_FALSE(resultJsonMessage.isError()) <<
printError(resultJsonMessage);
397 ASSERT_EQ(resultJsonMessage.getErrorCode(),
NO_ERROR) <<
printError(resultJsonMessage);
398 ASSERT_TRUE(resultJsonMessage.getErrorMsg().empty()) <<
printError(resultJsonMessage);
399 ASSERT_EQ(resultJsonMessage.getResultData().getItemsCount(), 1);
406 if (exceededLimits==
true)
408 resultJsonMessage.getResultData().getDataItem(0).getErrorCode()==
NO_ERROR);
411 if (resultJsonMessage.getResultData().getDataItem(0).getErrorCode() !=
NO_ERROR)
413 std::cout <<
">>>>> taskId: " << taskId <<
" code: " << resultJsonMessage.getResultData().getDataItem(0).getErrorCode()
414 <<
" message: " << resultJsonMessage.getResultData().getDataItem(0).getErrorMessage()
435 printSuccess(
"Test Cpu usage");
437 resourceLimits.
cpuMax = 0;
442 printSuccess(
"Test getting IOWAIT");
444 resourceLimits.
clear();
450 printSuccess(
"Test Free Disk");
452 resourceLimits.
clear();
457 printSuccess(
"Test Free Disk Percent");
459 resourceLimits.
clear();
465 printSuccess(
"Test RRAM Free Min");
467 resourceLimits.
clear();
472 printSuccess(
"Test RRAM Free Percent");
474 resourceLimits.
clear();
479 printSuccess(
"Test VRAM Free Min");
481 resourceLimits.
clear();
486 printSuccess(
"Test VRAM Free Percent");
488 resourceLimits.
clear();
493 printSuccess(
"Test Proc Max");
495 resourceLimits.
clear();
500 printSuccess(
"Test Threads Max");
504 Poco::Thread::sleep(10000);
507 printSuccess (
"Test Resource Limits");
512 const std::string command =
"echo Hello && sleep 10 && ps auxf && sleep 10 && ls -l";
525 printSuccess(
"Test usage IOWAIT limit");
527 resourceLimits.
clear();
532 printSuccess(
"Test usage RRAM limit");
534 resourceLimits.
clear();
539 printSuccess(
"Test usage VRAM limit");
541 resourceLimits.
clear();
546 printSuccess(
"Test usage HDD limit percent");
548 resourceLimits.
clear();
553 printSuccess(
"Test usage HDD limit bytes");
557 Poco::Thread::sleep(10000);
559 printSuccess (
"Test Resource Usage Limits");