win32: Task #2933 Prevent multiple integ tests from running in parallel (had to expose some arch misc windows functions)
This commit is contained in:
parent
8ea964c331
commit
933522451a
|
@ -179,6 +179,11 @@ public:
|
||||||
|
|
||||||
static void setInstanceWin32(HINSTANCE instance);
|
static void setInstanceWin32(HINSTANCE instance);
|
||||||
|
|
||||||
|
static BOOL WINAPI getProcessEntry(PROCESSENTRY32& entry, DWORD processID);
|
||||||
|
static BOOL WINAPI getProcessEntry(PROCESSENTRY32& entry, std::string processName);
|
||||||
|
static BOOL WINAPI getSelfProcessEntry(PROCESSENTRY32& entry);
|
||||||
|
static BOOL WINAPI getParentProcessEntry(PROCESSENTRY32& entry);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//! Open and return a registry key, closing the parent key
|
//! Open and return a registry key, closing the parent key
|
||||||
static HKEY openKey(HKEY parent, const TCHAR* child, bool create);
|
static HKEY openKey(HKEY parent, const TCHAR* child, bool create);
|
||||||
|
@ -195,10 +200,6 @@ private:
|
||||||
|
|
||||||
static DWORD WINAPI dummySetThreadExecutionState(DWORD);
|
static DWORD WINAPI dummySetThreadExecutionState(DWORD);
|
||||||
|
|
||||||
static BOOL WINAPI getProcessEntry(PROCESSENTRY32& entry, DWORD processID);
|
|
||||||
static BOOL WINAPI getSelfProcessEntry(PROCESSENTRY32& entry);
|
|
||||||
static BOOL WINAPI getParentProcessEntry(PROCESSENTRY32& entry);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef std::set<HWND> CDialogs;
|
typedef std::set<HWND> CDialogs;
|
||||||
typedef DWORD (WINAPI *STES_t)(DWORD);
|
typedef DWORD (WINAPI *STES_t)(DWORD);
|
||||||
|
|
|
@ -23,10 +23,20 @@
|
||||||
#include "CArchMiscWindows.h"
|
#include "CArchMiscWindows.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define ERROR_ALREADY_RUNNING 1
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
void
|
||||||
|
ensureSingleInstance();
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
std::cout << "Synergy integration tests\n";
|
// make sure integ tests don't run in parallel.
|
||||||
|
int err = ensureSingleInstance();
|
||||||
|
if (err != 0)
|
||||||
|
return err;
|
||||||
|
|
||||||
#if SYSAPI_WIN32
|
#if SYSAPI_WIN32
|
||||||
// record window instance for tray icon, etc
|
// record window instance for tray icon, etc
|
||||||
|
@ -39,3 +49,50 @@ main(int argc, char **argv)
|
||||||
|
|
||||||
return RUN_ALL_TESTS();
|
return RUN_ALL_TESTS();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
ensureSingleInstance()
|
||||||
|
{
|
||||||
|
#if SYSAPI_WIN32
|
||||||
|
|
||||||
|
// get info for current process (we'll use the name later).
|
||||||
|
PROCESSENTRY32 selfEntry;
|
||||||
|
if (!CArchMiscWindows::getSelfProcessEntry(selfEntry))
|
||||||
|
cerr << "could not process info for self "
|
||||||
|
<< "(error: " << GetLastError() << ")" << endl;
|
||||||
|
|
||||||
|
// get current task list.
|
||||||
|
HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
|
||||||
|
if (snapshot == INVALID_HANDLE_VALUE)
|
||||||
|
cerr << "could not get process snapshot "
|
||||||
|
<< "(error: " << GetLastError() << ")" << endl;
|
||||||
|
|
||||||
|
PROCESSENTRY32 entry;
|
||||||
|
BOOL gotEntry = Process32First(snapshot, &entry);
|
||||||
|
if (!gotEntry)
|
||||||
|
cerr << "could not get first process entry "
|
||||||
|
<< "(error: " << GetLastError() << ")" << endl;
|
||||||
|
|
||||||
|
while (gotEntry)
|
||||||
|
{
|
||||||
|
string checkName(entry.szExeFile);
|
||||||
|
|
||||||
|
// if entry has the same name as this process, but is not
|
||||||
|
// the current process...
|
||||||
|
if ((checkName.find(selfEntry.szExeFile) != string::npos) &&
|
||||||
|
(entry.th32ProcessID != selfEntry.th32ProcessID))
|
||||||
|
{
|
||||||
|
cerr << "error: process already running: "
|
||||||
|
<< entry.th32ProcessID << " -> " << entry.szExeFile << endl;
|
||||||
|
|
||||||
|
return ERROR_ALREADY_RUNNING;
|
||||||
|
}
|
||||||
|
|
||||||
|
gotEntry = Process32Next(snapshot, &entry);
|
||||||
|
}
|
||||||
|
#elif SYSAPI_UNIX
|
||||||
|
// TODO
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue