Added Windows OS support to MemCheckTests (#6684)
* Added Windows OS support to MemCheckTests * Move system headers to cpp file * Moved includes for windows to cpp file. Was rewrited function to get memory info * Was rewrite functions for getting information about memory * Moved implementation run_in_process to cpp file * Fixed implementation of run_in_process
This commit is contained in:
parent
c0eb700024
commit
6ee9285fe5
@ -94,7 +94,7 @@ void runTest(const std::function<void(std::string, std::string, int)> &tests_pip
|
||||
#if DEBUG_MODE
|
||||
tests_pipeline(params.model, params.device, params.numiters);
|
||||
#else
|
||||
int status = run_in_processes(params.numprocesses, _runTest, tests_pipeline, params);
|
||||
int status = run_in_processes(params.numprocesses, [&](){ _runTest(tests_pipeline, params); });
|
||||
ASSERT_EQ(status, 0) << "Test failed with exitcode " << std::to_string(status);
|
||||
#endif
|
||||
}
|
||||
|
@ -11,8 +11,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <thread>
|
||||
#include <unistd.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
|
||||
enum TestStatus
|
||||
{
|
||||
|
@ -7,6 +7,16 @@
|
||||
#include <string>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#include <psapi.h>
|
||||
#include <tlhelp32.h>
|
||||
#else
|
||||
#include <sys/unistd.h>
|
||||
#include <sys/wait.h>
|
||||
#endif
|
||||
|
||||
|
||||
std::string OS_PATH_JOIN(std::initializer_list<std::string> list) {
|
||||
if (!list.size())
|
||||
return "";
|
||||
@ -37,13 +47,52 @@ static int parseLine(std::string line) {
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
static PROCESS_MEMORY_COUNTERS getMemoryInfo() {
|
||||
static PROCESS_MEMORY_COUNTERS pmc;
|
||||
pmc.cb = sizeof(PROCESS_MEMORY_COUNTERS);
|
||||
GetProcessMemoryInfo(GetCurrentProcess(),&pmc, pmc.cb);
|
||||
return pmc;
|
||||
}
|
||||
|
||||
size_t getVmSizeInKB() {
|
||||
// TODO rewrite for Virtual Memory
|
||||
PROCESS_MEMORY_COUNTERS pmc;
|
||||
pmc.cb = sizeof(PROCESS_MEMORY_COUNTERS);
|
||||
GetProcessMemoryInfo(GetCurrentProcess(),&pmc, pmc.cb);
|
||||
return pmc.WorkingSetSize;
|
||||
}
|
||||
return getMemoryInfo().PagefileUsage / 1024;
|
||||
}
|
||||
|
||||
size_t getVmPeakInKB() {
|
||||
return getMemoryInfo().PeakPagefileUsage / 1024;
|
||||
}
|
||||
|
||||
size_t getVmRSSInKB() {
|
||||
return getMemoryInfo().WorkingSetSize / 1024;
|
||||
}
|
||||
|
||||
size_t getVmHWMInKB() {
|
||||
return getMemoryInfo().PeakWorkingSetSize / 1024;
|
||||
}
|
||||
|
||||
size_t getThreadsNum() {
|
||||
// first determine the id of the current process
|
||||
DWORD const id = GetCurrentProcessId();
|
||||
|
||||
// then get a process list snapshot.
|
||||
HANDLE const snapshot = CreateToolhelp32Snapshot( TH32CS_SNAPALL, 0 );
|
||||
|
||||
// initialize the process entry structure.
|
||||
PROCESSENTRY32 entry = { 0 };
|
||||
entry.dwSize = sizeof( entry );
|
||||
|
||||
// get the first process info.
|
||||
BOOL ret = true;
|
||||
ret = Process32First( snapshot, &entry );
|
||||
while( ret && entry.th32ProcessID != id ) {
|
||||
ret = Process32Next( snapshot, &entry );
|
||||
}
|
||||
CloseHandle( snapshot );
|
||||
return ret
|
||||
? entry.cntThreads
|
||||
: -1;
|
||||
}
|
||||
|
||||
#else
|
||||
size_t getSystemDataByName(char *name){
|
||||
FILE* file = fopen("/proc/self/status", "r");
|
||||
@ -70,6 +119,35 @@ size_t getThreadsNum() {return getSystemDataByName((char*) "Threads:");}
|
||||
|
||||
#endif
|
||||
|
||||
int run_in_processes(const int &numprocesses, const std::function<void()> &function) {
|
||||
#ifdef _WIN32
|
||||
// TODO: implement run in separate process by using WinAPI
|
||||
function;
|
||||
return 0;
|
||||
#else
|
||||
std::vector<pid_t> child_pids(numprocesses);
|
||||
|
||||
for (int i = 0; i < numprocesses; i++) {
|
||||
child_pids[i] = fork();
|
||||
if (child_pids[i] == 0) {
|
||||
function;
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
int status = 0;
|
||||
for (int i = 0; i < numprocesses; i++) {
|
||||
int _status = 0;
|
||||
waitpid(child_pids[i], &_status, WSTOPPED);
|
||||
if (_status) {
|
||||
log_err("Process run # " << i << " failed with exitcode " << _status);
|
||||
status = _status;
|
||||
}
|
||||
}
|
||||
return status;
|
||||
#endif
|
||||
}
|
||||
|
||||
void auto_expand_env_vars(std::string &input) {
|
||||
const static std::string pattern1 = "${", pattern2 = "}";
|
||||
size_t pattern1_pos, pattern2_pos, envvar_start_pos, envvar_finish_pos;
|
||||
|
@ -9,8 +9,6 @@
|
||||
#include <vector>
|
||||
#include <thread>
|
||||
#include <functional>
|
||||
#include <sys/unistd.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#define OS_SEP std::string("\\")
|
||||
@ -39,29 +37,7 @@ size_t getVmRSSInKB();
|
||||
size_t getVmHWMInKB();
|
||||
size_t getThreadsNum();
|
||||
|
||||
template<typename Function, typename ... Args>
|
||||
int run_in_processes(const int &numprocesses, Function const &function, Args ... args) {
|
||||
std::vector<pid_t> child_pids(numprocesses);
|
||||
|
||||
for (int i = 0; i < numprocesses; i++) {
|
||||
child_pids[i] = fork();
|
||||
if (child_pids[i] == 0) {
|
||||
function(args...);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
int status = 0;
|
||||
for (int i = 0; i < numprocesses; i++) {
|
||||
int _status = 0;
|
||||
waitpid(child_pids[i], &_status, WSTOPPED);
|
||||
if (_status) {
|
||||
log_err("Process run # " << i << " failed with exitcode " << _status);
|
||||
status = _status;
|
||||
}
|
||||
}
|
||||
return status;
|
||||
}
|
||||
int run_in_processes(const int &numprocesses, const std::function<void()> &function);
|
||||
|
||||
template<typename Function, typename ... Args>
|
||||
inline void run_in_threads(const int &numthreads, Function const &function, Args ... args) {
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
#include "../common/tests_utils.h"
|
||||
|
||||
#include <array>
|
||||
#include <pugixml.hpp>
|
||||
|
||||
// Measure values
|
||||
|
Loading…
Reference in New Issue
Block a user