2002-04-22 00:07:03 +02:00
|
|
|
/*
|
2010-01-23 16:46:09 +01:00
|
|
|
* Unit test suite for process functions
|
2002-04-22 00:07:03 +02:00
|
|
|
*
|
|
|
|
* Copyright 2002 Eric Pouech
|
2006-11-08 16:45:33 +01:00
|
|
|
* Copyright 2006 Dmitry Timoshkov
|
2015-06-29 06:27:26 +02:00
|
|
|
* Copyright 2014 Michael Müller
|
2002-04-22 00:07:03 +02:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-04-22 00:07:03 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2002-04-22 00:07:03 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2002-05-23 04:40:07 +02:00
|
|
|
|
2008-10-15 16:44:54 +02:00
|
|
|
#include "ntstatus.h"
|
|
|
|
#define WIN32_NO_STATUS
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "windef.h"
|
2002-04-22 00:07:03 +02:00
|
|
|
#include "winbase.h"
|
|
|
|
#include "winuser.h"
|
2003-06-18 05:24:20 +02:00
|
|
|
#include "wincon.h"
|
|
|
|
#include "winnls.h"
|
2008-10-15 16:44:54 +02:00
|
|
|
#include "winternl.h"
|
2015-12-21 13:06:37 +01:00
|
|
|
#include "tlhelp32.h"
|
2008-10-15 16:44:54 +02:00
|
|
|
|
|
|
|
#include "wine/test.h"
|
2002-04-22 00:07:03 +02:00
|
|
|
|
2014-02-07 15:08:48 +01:00
|
|
|
/* PROCESS_ALL_ACCESS in Vista+ PSDKs is incompatible with older Windows versions */
|
|
|
|
#define PROCESS_ALL_ACCESS_NT4 (PROCESS_ALL_ACCESS & ~0xf000)
|
2015-12-21 13:06:37 +01:00
|
|
|
/* THREAD_ALL_ACCESS in Vista+ PSDKs is incompatible with older Windows versions */
|
|
|
|
#define THREAD_ALL_ACCESS_NT4 (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 0x3ff)
|
2014-02-07 15:08:48 +01:00
|
|
|
|
2009-03-29 23:36:33 +02:00
|
|
|
#define expect_eq_d(expected, actual) \
|
|
|
|
do { \
|
|
|
|
int value = (actual); \
|
|
|
|
ok((expected) == value, "Expected " #actual " to be %d (" #expected ") is %d\n", \
|
|
|
|
(expected), value); \
|
|
|
|
} while (0)
|
2009-06-10 20:39:42 +02:00
|
|
|
#define expect_eq_s(expected, actual) \
|
|
|
|
do { \
|
|
|
|
LPCSTR value = (actual); \
|
|
|
|
ok(lstrcmpA((expected), value) == 0, "Expected " #actual " to be L\"%s\" (" #expected ") is L\"%s\"\n", \
|
|
|
|
expected, value); \
|
|
|
|
} while (0)
|
2009-03-29 23:36:33 +02:00
|
|
|
#define expect_eq_ws_i(expected, actual) \
|
|
|
|
do { \
|
|
|
|
LPCWSTR value = (actual); \
|
|
|
|
ok(lstrcmpiW((expected), value) == 0, "Expected " #actual " to be L\"%s\" (" #expected ") is L\"%s\"\n", \
|
|
|
|
wine_dbgstr_w(expected), wine_dbgstr_w(value)); \
|
|
|
|
} while (0)
|
|
|
|
|
2015-01-04 07:37:42 +01:00
|
|
|
static HINSTANCE hkernel32, hntdll;
|
2010-05-12 22:58:34 +02:00
|
|
|
static void (WINAPI *pGetNativeSystemInfo)(LPSYSTEM_INFO);
|
2010-10-11 12:16:16 +02:00
|
|
|
static BOOL (WINAPI *pGetSystemRegistryQuota)(PDWORD, PDWORD);
|
2010-05-12 22:58:34 +02:00
|
|
|
static BOOL (WINAPI *pIsWow64Process)(HANDLE,PBOOL);
|
2006-11-19 16:05:47 +01:00
|
|
|
static LPVOID (WINAPI *pVirtualAllocEx)(HANDLE, LPVOID, SIZE_T, DWORD, DWORD);
|
2007-01-20 12:38:14 +01:00
|
|
|
static BOOL (WINAPI *pVirtualFreeEx)(HANDLE, LPVOID, SIZE_T, DWORD);
|
2009-06-10 20:39:42 +02:00
|
|
|
static BOOL (WINAPI *pQueryFullProcessImageNameA)(HANDLE hProcess, DWORD dwFlags, LPSTR lpExeName, PDWORD lpdwSize);
|
2009-03-29 23:36:33 +02:00
|
|
|
static BOOL (WINAPI *pQueryFullProcessImageNameW)(HANDLE hProcess, DWORD dwFlags, LPWSTR lpExeName, PDWORD lpdwSize);
|
2011-10-04 05:11:40 +02:00
|
|
|
static DWORD (WINAPI *pK32GetProcessImageFileNameA)(HANDLE,LPSTR,DWORD);
|
2015-01-04 07:37:42 +01:00
|
|
|
static struct _TEB * (WINAPI *pNtCurrentTeb)(void);
|
2015-03-28 03:25:45 +01:00
|
|
|
static HANDLE (WINAPI *pCreateJobObjectW)(LPSECURITY_ATTRIBUTES sa, LPCWSTR name);
|
|
|
|
static BOOL (WINAPI *pAssignProcessToJobObject)(HANDLE job, HANDLE process);
|
|
|
|
static BOOL (WINAPI *pIsProcessInJob)(HANDLE process, HANDLE job, PBOOL result);
|
2015-03-28 03:23:28 +01:00
|
|
|
static BOOL (WINAPI *pTerminateJobObject)(HANDLE job, UINT exit_code);
|
2015-03-28 03:23:51 +01:00
|
|
|
static BOOL (WINAPI *pQueryInformationJobObject)(HANDLE job, JOBOBJECTINFOCLASS class, LPVOID info, DWORD len, LPDWORD ret_len);
|
2015-03-28 03:24:12 +01:00
|
|
|
static BOOL (WINAPI *pSetInformationJobObject)(HANDLE job, JOBOBJECTINFOCLASS class, LPVOID info, DWORD len);
|
|
|
|
static HANDLE (WINAPI *pCreateIoCompletionPort)(HANDLE file, HANDLE existing_port, ULONG_PTR key, DWORD threads);
|
2015-06-29 06:27:26 +02:00
|
|
|
static BOOL (WINAPI *pGetNumaProcessorNode)(UCHAR, PUCHAR);
|
2015-08-20 05:06:38 +02:00
|
|
|
static NTSTATUS (WINAPI *pNtQueryInformationProcess)(HANDLE, PROCESSINFOCLASS, PVOID, ULONG, PULONG);
|
2015-10-08 14:20:17 +02:00
|
|
|
static BOOL (WINAPI *pProcessIdToSessionId)(DWORD,DWORD*);
|
|
|
|
static DWORD (WINAPI *pWTSGetActiveConsoleSessionId)(void);
|
2015-12-21 13:06:37 +01:00
|
|
|
static HANDLE (WINAPI *pCreateToolhelp32Snapshot)(DWORD, DWORD);
|
|
|
|
static BOOL (WINAPI *pProcess32First)(HANDLE, PROCESSENTRY32*);
|
|
|
|
static BOOL (WINAPI *pProcess32Next)(HANDLE, PROCESSENTRY32*);
|
|
|
|
static BOOL (WINAPI *pThread32First)(HANDLE, THREADENTRY32*);
|
|
|
|
static BOOL (WINAPI *pThread32Next)(HANDLE, THREADENTRY32*);
|
2016-01-03 23:56:46 +01:00
|
|
|
static BOOL (WINAPI *pGetLogicalProcessorInformationEx)(LOGICAL_PROCESSOR_RELATIONSHIP,SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX*,DWORD*);
|
2006-11-19 16:05:47 +01:00
|
|
|
|
2007-01-20 12:38:14 +01:00
|
|
|
/* ############################### */
|
2002-04-22 00:07:03 +02:00
|
|
|
static char base[MAX_PATH];
|
|
|
|
static char selfname[MAX_PATH];
|
2006-12-20 18:28:11 +01:00
|
|
|
static char* exename;
|
2002-04-22 00:07:03 +02:00
|
|
|
static char resfile[MAX_PATH];
|
|
|
|
|
|
|
|
static int myARGC;
|
|
|
|
static char** myARGV;
|
|
|
|
|
2003-11-18 20:38:51 +01:00
|
|
|
/* As some environment variables get very long on Unix, we only test for
|
|
|
|
* the first 127 bytes.
|
|
|
|
* Note that increasing this value past 256 may exceed the buffer size
|
|
|
|
* limitations of the *Profile functions (at least on Wine).
|
2003-01-13 19:28:43 +01:00
|
|
|
*/
|
|
|
|
#define MAX_LISTED_ENV_VAR 128
|
|
|
|
|
2002-04-22 00:07:03 +02:00
|
|
|
/* ---------------- portable memory allocation thingie */
|
|
|
|
|
2006-11-15 11:31:41 +01:00
|
|
|
static char memory[1024*256];
|
2002-04-22 00:07:03 +02:00
|
|
|
static char* memory_index = memory;
|
|
|
|
|
|
|
|
static char* grab_memory(size_t len)
|
|
|
|
{
|
|
|
|
char* ret = memory_index;
|
|
|
|
/* align on dword */
|
|
|
|
len = (len + 3) & ~3;
|
|
|
|
memory_index += len;
|
|
|
|
assert(memory_index <= memory + sizeof(memory));
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void release_memory(void)
|
|
|
|
{
|
|
|
|
memory_index = memory;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------- simplistic tool to encode/decode strings (to hide \ " ' and such) */
|
|
|
|
|
2003-11-09 01:30:36 +01:00
|
|
|
static const char* encodeA(const char* str)
|
2002-04-22 00:07:03 +02:00
|
|
|
{
|
|
|
|
char* ptr;
|
2002-12-18 03:22:51 +01:00
|
|
|
size_t len,i;
|
2002-04-22 00:07:03 +02:00
|
|
|
|
|
|
|
if (!str) return "";
|
|
|
|
len = strlen(str) + 1;
|
|
|
|
ptr = grab_memory(len * 2 + 1);
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
sprintf(&ptr[i * 2], "%02x", (unsigned char)str[i]);
|
|
|
|
ptr[2 * len] = '\0';
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
2003-11-09 01:30:36 +01:00
|
|
|
static const char* encodeW(const WCHAR* str)
|
2002-04-22 00:07:03 +02:00
|
|
|
{
|
|
|
|
char* ptr;
|
2002-12-18 03:22:51 +01:00
|
|
|
size_t len,i;
|
2002-04-22 00:07:03 +02:00
|
|
|
|
|
|
|
if (!str) return "";
|
|
|
|
len = lstrlenW(str) + 1;
|
|
|
|
ptr = grab_memory(len * 4 + 1);
|
|
|
|
assert(ptr);
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
sprintf(&ptr[i * 4], "%04x", (unsigned int)(unsigned short)str[i]);
|
|
|
|
ptr[4 * len] = '\0';
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned decode_char(char c)
|
|
|
|
{
|
|
|
|
if (c >= '0' && c <= '9') return c - '0';
|
|
|
|
if (c >= 'a' && c <= 'f') return c - 'a' + 10;
|
|
|
|
assert(c >= 'A' && c <= 'F');
|
|
|
|
return c - 'A' + 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char* decodeA(const char* str)
|
|
|
|
{
|
|
|
|
char* ptr;
|
2002-12-18 03:22:51 +01:00
|
|
|
size_t len,i;
|
2002-04-22 00:07:03 +02:00
|
|
|
|
|
|
|
len = strlen(str) / 2;
|
|
|
|
if (!len--) return NULL;
|
|
|
|
ptr = grab_memory(len + 1);
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
ptr[i] = (decode_char(str[2 * i]) << 4) | decode_char(str[2 * i + 1]);
|
|
|
|
ptr[len] = '\0';
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
2002-12-18 21:51:33 +01:00
|
|
|
/* This will be needed to decode Unicode strings saved by the child process
|
|
|
|
* when we test Unicode functions.
|
|
|
|
*/
|
2002-04-22 00:07:03 +02:00
|
|
|
static WCHAR* decodeW(const char* str)
|
|
|
|
{
|
|
|
|
size_t len;
|
|
|
|
WCHAR* ptr;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
len = strlen(str) / 4;
|
|
|
|
if (!len--) return NULL;
|
|
|
|
ptr = (WCHAR*)grab_memory(len * 2 + 1);
|
|
|
|
for (i = 0; i < len; i++)
|
2002-06-01 01:06:46 +02:00
|
|
|
ptr[i] = (decode_char(str[4 * i]) << 12) |
|
2002-04-22 00:07:03 +02:00
|
|
|
(decode_char(str[4 * i + 1]) << 8) |
|
|
|
|
(decode_char(str[4 * i + 2]) << 4) |
|
|
|
|
(decode_char(str[4 * i + 3]) << 0);
|
|
|
|
ptr[len] = '\0';
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* init
|
|
|
|
*
|
|
|
|
* generates basic information like:
|
|
|
|
* base: absolute path to curr dir
|
|
|
|
* selfname: the way to reinvoke ourselves
|
2006-12-20 18:28:11 +01:00
|
|
|
* exename: executable without the path
|
2006-11-19 16:05:47 +01:00
|
|
|
* function-pointers, which are not implemented in all windows versions
|
2002-04-22 00:07:03 +02:00
|
|
|
*/
|
2013-10-24 00:40:23 +02:00
|
|
|
static BOOL init(void)
|
2002-04-22 00:07:03 +02:00
|
|
|
{
|
2006-12-20 18:28:11 +01:00
|
|
|
char *p;
|
|
|
|
|
2002-04-22 00:07:03 +02:00
|
|
|
myARGC = winetest_get_mainargs( &myARGV );
|
2013-10-24 00:40:23 +02:00
|
|
|
if (!GetCurrentDirectoryA(sizeof(base), base)) return FALSE;
|
2002-05-12 05:16:39 +02:00
|
|
|
strcpy(selfname, myARGV[0]);
|
2006-11-19 16:05:47 +01:00
|
|
|
|
2006-12-20 18:28:11 +01:00
|
|
|
/* Strip the path of selfname */
|
|
|
|
if ((p = strrchr(selfname, '\\')) != NULL) exename = p + 1;
|
|
|
|
else exename = selfname;
|
|
|
|
|
|
|
|
if ((p = strrchr(exename, '/')) != NULL) exename = p + 1;
|
|
|
|
|
2006-11-19 16:05:47 +01:00
|
|
|
hkernel32 = GetModuleHandleA("kernel32");
|
2015-01-04 07:37:42 +01:00
|
|
|
hntdll = GetModuleHandleA("ntdll.dll");
|
|
|
|
|
2015-08-20 05:06:38 +02:00
|
|
|
pNtCurrentTeb = (void *)GetProcAddress(hntdll, "NtCurrentTeb");
|
|
|
|
pNtQueryInformationProcess = (void *)GetProcAddress(hntdll, "NtQueryInformationProcess");
|
|
|
|
|
2010-05-12 22:58:34 +02:00
|
|
|
pGetNativeSystemInfo = (void *) GetProcAddress(hkernel32, "GetNativeSystemInfo");
|
2010-10-11 12:16:16 +02:00
|
|
|
pGetSystemRegistryQuota = (void *) GetProcAddress(hkernel32, "GetSystemRegistryQuota");
|
2010-05-12 22:58:34 +02:00
|
|
|
pIsWow64Process = (void *) GetProcAddress(hkernel32, "IsWow64Process");
|
2006-11-19 16:05:47 +01:00
|
|
|
pVirtualAllocEx = (void *) GetProcAddress(hkernel32, "VirtualAllocEx");
|
|
|
|
pVirtualFreeEx = (void *) GetProcAddress(hkernel32, "VirtualFreeEx");
|
2009-06-10 20:39:42 +02:00
|
|
|
pQueryFullProcessImageNameA = (void *) GetProcAddress(hkernel32, "QueryFullProcessImageNameA");
|
2009-03-29 23:36:33 +02:00
|
|
|
pQueryFullProcessImageNameW = (void *) GetProcAddress(hkernel32, "QueryFullProcessImageNameW");
|
2011-10-04 05:11:40 +02:00
|
|
|
pK32GetProcessImageFileNameA = (void *) GetProcAddress(hkernel32, "K32GetProcessImageFileNameA");
|
2015-03-28 03:25:45 +01:00
|
|
|
pCreateJobObjectW = (void *)GetProcAddress(hkernel32, "CreateJobObjectW");
|
|
|
|
pAssignProcessToJobObject = (void *)GetProcAddress(hkernel32, "AssignProcessToJobObject");
|
|
|
|
pIsProcessInJob = (void *)GetProcAddress(hkernel32, "IsProcessInJob");
|
2015-03-28 03:23:28 +01:00
|
|
|
pTerminateJobObject = (void *)GetProcAddress(hkernel32, "TerminateJobObject");
|
2015-03-28 03:23:51 +01:00
|
|
|
pQueryInformationJobObject = (void *)GetProcAddress(hkernel32, "QueryInformationJobObject");
|
2015-03-28 03:24:12 +01:00
|
|
|
pSetInformationJobObject = (void *)GetProcAddress(hkernel32, "SetInformationJobObject");
|
|
|
|
pCreateIoCompletionPort = (void *)GetProcAddress(hkernel32, "CreateIoCompletionPort");
|
2015-06-29 06:27:26 +02:00
|
|
|
pGetNumaProcessorNode = (void *)GetProcAddress(hkernel32, "GetNumaProcessorNode");
|
2015-10-08 14:20:17 +02:00
|
|
|
pProcessIdToSessionId = (void *)GetProcAddress(hkernel32, "ProcessIdToSessionId");
|
|
|
|
pWTSGetActiveConsoleSessionId = (void *)GetProcAddress(hkernel32, "WTSGetActiveConsoleSessionId");
|
2015-12-21 13:06:37 +01:00
|
|
|
pCreateToolhelp32Snapshot = (void *)GetProcAddress(hkernel32, "CreateToolhelp32Snapshot");
|
|
|
|
pProcess32First = (void *)GetProcAddress(hkernel32, "Process32First");
|
|
|
|
pProcess32Next = (void *)GetProcAddress(hkernel32, "Process32Next");
|
|
|
|
pThread32First = (void *)GetProcAddress(hkernel32, "Thread32First");
|
|
|
|
pThread32Next = (void *)GetProcAddress(hkernel32, "Thread32Next");
|
2016-01-03 23:56:46 +01:00
|
|
|
pGetLogicalProcessorInformationEx = (void *)GetProcAddress(hkernel32, "GetLogicalProcessorInformationEx");
|
2015-12-21 13:06:37 +01:00
|
|
|
|
2013-10-24 00:40:23 +02:00
|
|
|
return TRUE;
|
2002-04-22 00:07:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* get_file_name
|
|
|
|
*
|
|
|
|
* generates an absolute file_name for temporary file
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static void get_file_name(char* buf)
|
|
|
|
{
|
|
|
|
char path[MAX_PATH];
|
|
|
|
|
|
|
|
buf[0] = '\0';
|
|
|
|
GetTempPathA(sizeof(path), path);
|
|
|
|
GetTempFileNameA(path, "wt", 0, buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* static void childPrintf
|
|
|
|
*
|
|
|
|
*/
|
2016-01-13 12:43:04 +01:00
|
|
|
static void WINETEST_PRINTF_ATTR(2,3) childPrintf(HANDLE h, const char* fmt, ...)
|
2002-04-22 00:07:03 +02:00
|
|
|
{
|
|
|
|
va_list valist;
|
2003-11-18 20:38:51 +01:00
|
|
|
char buffer[1024+4*MAX_LISTED_ENV_VAR];
|
2002-04-22 00:07:03 +02:00
|
|
|
DWORD w;
|
|
|
|
|
|
|
|
va_start(valist, fmt);
|
|
|
|
vsprintf(buffer, fmt, valist);
|
|
|
|
va_end(valist);
|
|
|
|
WriteFile(h, buffer, strlen(buffer), &w, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* doChild
|
|
|
|
*
|
|
|
|
* output most of the information in the child process
|
|
|
|
*/
|
2003-06-18 05:24:20 +02:00
|
|
|
static void doChild(const char* file, const char* option)
|
2002-04-22 00:07:03 +02:00
|
|
|
{
|
|
|
|
STARTUPINFOA siA;
|
|
|
|
STARTUPINFOW siW;
|
|
|
|
int i;
|
2011-01-16 11:35:21 +01:00
|
|
|
char *ptrA, *ptrA_save;
|
|
|
|
WCHAR *ptrW, *ptrW_save;
|
2002-04-22 00:07:03 +02:00
|
|
|
char bufA[MAX_PATH];
|
|
|
|
WCHAR bufW[MAX_PATH];
|
|
|
|
HANDLE hFile = CreateFileA(file, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0);
|
2015-12-21 13:06:37 +01:00
|
|
|
HANDLE snapshot;
|
|
|
|
PROCESSENTRY32 pe;
|
2004-12-27 18:26:37 +01:00
|
|
|
BOOL ret;
|
2002-04-22 00:07:03 +02:00
|
|
|
|
|
|
|
if (hFile == INVALID_HANDLE_VALUE) return;
|
|
|
|
|
|
|
|
/* output of startup info (Ansi) */
|
|
|
|
GetStartupInfoA(&siA);
|
2002-06-01 01:06:46 +02:00
|
|
|
childPrintf(hFile,
|
2016-01-13 12:43:04 +01:00
|
|
|
"[StartupInfoA]\ncb=%08u\nlpDesktop=%s\nlpTitle=%s\n"
|
|
|
|
"dwX=%u\ndwY=%u\ndwXSize=%u\ndwYSize=%u\n"
|
|
|
|
"dwXCountChars=%u\ndwYCountChars=%u\ndwFillAttribute=%u\n"
|
|
|
|
"dwFlags=%u\nwShowWindow=%u\n"
|
2002-04-22 00:07:03 +02:00
|
|
|
"hStdInput=%lu\nhStdOutput=%lu\nhStdError=%lu\n\n",
|
|
|
|
siA.cb, encodeA(siA.lpDesktop), encodeA(siA.lpTitle),
|
2002-06-01 01:06:46 +02:00
|
|
|
siA.dwX, siA.dwY, siA.dwXSize, siA.dwYSize,
|
|
|
|
siA.dwXCountChars, siA.dwYCountChars, siA.dwFillAttribute,
|
|
|
|
siA.dwFlags, siA.wShowWindow,
|
2009-01-08 13:17:53 +01:00
|
|
|
(DWORD_PTR)siA.hStdInput, (DWORD_PTR)siA.hStdOutput, (DWORD_PTR)siA.hStdError);
|
2002-04-22 00:07:03 +02:00
|
|
|
|
2015-01-04 07:37:42 +01:00
|
|
|
if (pNtCurrentTeb)
|
|
|
|
{
|
|
|
|
RTL_USER_PROCESS_PARAMETERS *params = pNtCurrentTeb()->Peb->ProcessParameters;
|
|
|
|
|
|
|
|
/* check the console handles in the TEB */
|
|
|
|
childPrintf(hFile, "[TEB]\nhStdInput=%lu\nhStdOutput=%lu\nhStdError=%lu\n\n",
|
|
|
|
(DWORD_PTR)params->hStdInput, (DWORD_PTR)params->hStdOutput,
|
|
|
|
(DWORD_PTR)params->hStdError);
|
|
|
|
}
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
/* since GetStartupInfoW is only implemented in win2k,
|
2002-04-22 00:07:03 +02:00
|
|
|
* zero out before calling so we can notice the difference
|
|
|
|
*/
|
|
|
|
memset(&siW, 0, sizeof(siW));
|
|
|
|
GetStartupInfoW(&siW);
|
2002-06-01 01:06:46 +02:00
|
|
|
childPrintf(hFile,
|
2016-01-13 12:43:04 +01:00
|
|
|
"[StartupInfoW]\ncb=%08u\nlpDesktop=%s\nlpTitle=%s\n"
|
|
|
|
"dwX=%u\ndwY=%u\ndwXSize=%u\ndwYSize=%u\n"
|
|
|
|
"dwXCountChars=%u\ndwYCountChars=%u\ndwFillAttribute=%u\n"
|
|
|
|
"dwFlags=%u\nwShowWindow=%u\n"
|
2002-04-22 00:07:03 +02:00
|
|
|
"hStdInput=%lu\nhStdOutput=%lu\nhStdError=%lu\n\n",
|
|
|
|
siW.cb, encodeW(siW.lpDesktop), encodeW(siW.lpTitle),
|
2002-06-01 01:06:46 +02:00
|
|
|
siW.dwX, siW.dwY, siW.dwXSize, siW.dwYSize,
|
|
|
|
siW.dwXCountChars, siW.dwYCountChars, siW.dwFillAttribute,
|
|
|
|
siW.dwFlags, siW.wShowWindow,
|
2009-01-08 13:17:53 +01:00
|
|
|
(DWORD_PTR)siW.hStdInput, (DWORD_PTR)siW.hStdOutput, (DWORD_PTR)siW.hStdError);
|
2002-04-22 00:07:03 +02:00
|
|
|
|
|
|
|
/* Arguments */
|
|
|
|
childPrintf(hFile, "[Arguments]\nargcA=%d\n", myARGC);
|
|
|
|
for (i = 0; i < myARGC; i++)
|
|
|
|
{
|
|
|
|
childPrintf(hFile, "argvA%d=%s\n", i, encodeA(myARGV[i]));
|
|
|
|
}
|
|
|
|
childPrintf(hFile, "CommandLineA=%s\n", encodeA(GetCommandLineA()));
|
|
|
|
childPrintf(hFile, "CommandLineW=%s\n\n", encodeW(GetCommandLineW()));
|
|
|
|
|
2015-12-21 13:06:37 +01:00
|
|
|
/* output toolhelp information */
|
|
|
|
snapshot = pCreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
|
|
|
|
ok(snapshot != INVALID_HANDLE_VALUE, "CreateToolhelp32Snapshot failed %u\n", GetLastError());
|
|
|
|
memset(&pe, 0, sizeof(pe));
|
|
|
|
pe.dwSize = sizeof(pe);
|
|
|
|
if (pProcess32First(snapshot, &pe))
|
|
|
|
{
|
|
|
|
while (pe.th32ProcessID != GetCurrentProcessId())
|
|
|
|
if (!pProcess32Next(snapshot, &pe)) break;
|
|
|
|
}
|
|
|
|
CloseHandle(snapshot);
|
|
|
|
ok(pe.th32ProcessID == GetCurrentProcessId(), "failed to find current process in snapshot\n");
|
|
|
|
childPrintf(hFile,
|
|
|
|
"[Toolhelp]\ncntUsage=%u\nth32DefaultHeapID=%lu\n"
|
|
|
|
"th32ModuleID=%u\ncntThreads=%u\nth32ParentProcessID=%u\n"
|
|
|
|
"pcPriClassBase=%u\ndwFlags=%u\nszExeFile=%s\n\n",
|
|
|
|
pe.cntUsage, pe.th32DefaultHeapID, pe.th32ModuleID,
|
|
|
|
pe.cntThreads, pe.th32ParentProcessID, pe.pcPriClassBase,
|
|
|
|
pe.dwFlags, encodeA(pe.szExeFile));
|
|
|
|
|
2002-04-22 00:07:03 +02:00
|
|
|
/* output of environment (Ansi) */
|
2011-01-16 11:35:21 +01:00
|
|
|
ptrA_save = ptrA = GetEnvironmentStringsA();
|
2002-04-22 00:07:03 +02:00
|
|
|
if (ptrA)
|
|
|
|
{
|
2003-01-13 19:28:43 +01:00
|
|
|
char env_var[MAX_LISTED_ENV_VAR];
|
|
|
|
|
2002-04-22 00:07:03 +02:00
|
|
|
childPrintf(hFile, "[EnvironmentA]\n");
|
|
|
|
i = 0;
|
|
|
|
while (*ptrA)
|
|
|
|
{
|
2005-03-28 16:17:51 +02:00
|
|
|
lstrcpynA(env_var, ptrA, MAX_LISTED_ENV_VAR);
|
2003-01-13 19:28:43 +01:00
|
|
|
childPrintf(hFile, "env%d=%s\n", i, encodeA(env_var));
|
|
|
|
i++;
|
2002-04-22 00:07:03 +02:00
|
|
|
ptrA += strlen(ptrA) + 1;
|
|
|
|
}
|
2003-01-13 19:28:43 +01:00
|
|
|
childPrintf(hFile, "len=%d\n\n", i);
|
2011-01-16 11:35:21 +01:00
|
|
|
FreeEnvironmentStringsA(ptrA_save);
|
2002-04-22 00:07:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* output of environment (Unicode) */
|
2011-01-16 11:35:21 +01:00
|
|
|
ptrW_save = ptrW = GetEnvironmentStringsW();
|
2002-04-22 00:07:03 +02:00
|
|
|
if (ptrW)
|
|
|
|
{
|
2003-01-13 19:28:43 +01:00
|
|
|
WCHAR env_var[MAX_LISTED_ENV_VAR];
|
|
|
|
|
2002-04-22 00:07:03 +02:00
|
|
|
childPrintf(hFile, "[EnvironmentW]\n");
|
|
|
|
i = 0;
|
|
|
|
while (*ptrW)
|
|
|
|
{
|
2003-01-13 19:28:43 +01:00
|
|
|
lstrcpynW(env_var, ptrW, MAX_LISTED_ENV_VAR - 1);
|
|
|
|
env_var[MAX_LISTED_ENV_VAR - 1] = '\0';
|
2003-11-09 01:30:36 +01:00
|
|
|
childPrintf(hFile, "env%d=%s\n", i, encodeW(env_var));
|
2003-01-13 19:28:43 +01:00
|
|
|
i++;
|
2002-04-22 00:07:03 +02:00
|
|
|
ptrW += lstrlenW(ptrW) + 1;
|
|
|
|
}
|
2003-01-13 19:28:43 +01:00
|
|
|
childPrintf(hFile, "len=%d\n\n", i);
|
2011-01-16 11:35:21 +01:00
|
|
|
FreeEnvironmentStringsW(ptrW_save);
|
2002-04-22 00:07:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
childPrintf(hFile, "[Misc]\n");
|
|
|
|
if (GetCurrentDirectoryA(sizeof(bufA), bufA))
|
|
|
|
childPrintf(hFile, "CurrDirA=%s\n", encodeA(bufA));
|
|
|
|
if (GetCurrentDirectoryW(sizeof(bufW) / sizeof(bufW[0]), bufW))
|
|
|
|
childPrintf(hFile, "CurrDirW=%s\n", encodeW(bufW));
|
|
|
|
childPrintf(hFile, "\n");
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2003-06-18 05:24:20 +02:00
|
|
|
if (option && strcmp(option, "console") == 0)
|
|
|
|
{
|
|
|
|
CONSOLE_SCREEN_BUFFER_INFO sbi;
|
|
|
|
HANDLE hConIn = GetStdHandle(STD_INPUT_HANDLE);
|
|
|
|
HANDLE hConOut = GetStdHandle(STD_OUTPUT_HANDLE);
|
|
|
|
DWORD modeIn, modeOut;
|
|
|
|
|
|
|
|
childPrintf(hFile, "[Console]\n");
|
|
|
|
if (GetConsoleScreenBufferInfo(hConOut, &sbi))
|
|
|
|
{
|
|
|
|
childPrintf(hFile, "SizeX=%d\nSizeY=%d\nCursorX=%d\nCursorY=%d\nAttributes=%d\n",
|
|
|
|
sbi.dwSize.X, sbi.dwSize.Y, sbi.dwCursorPosition.X, sbi.dwCursorPosition.Y, sbi.wAttributes);
|
|
|
|
childPrintf(hFile, "winLeft=%d\nwinTop=%d\nwinRight=%d\nwinBottom=%d\n",
|
|
|
|
sbi.srWindow.Left, sbi.srWindow.Top, sbi.srWindow.Right, sbi.srWindow.Bottom);
|
|
|
|
childPrintf(hFile, "maxWinWidth=%d\nmaxWinHeight=%d\n",
|
|
|
|
sbi.dwMaximumWindowSize.X, sbi.dwMaximumWindowSize.Y);
|
|
|
|
}
|
|
|
|
childPrintf(hFile, "InputCP=%d\nOutputCP=%d\n",
|
|
|
|
GetConsoleCP(), GetConsoleOutputCP());
|
|
|
|
if (GetConsoleMode(hConIn, &modeIn))
|
2016-01-13 12:43:04 +01:00
|
|
|
childPrintf(hFile, "InputMode=%u\n", modeIn);
|
2003-06-18 05:24:20 +02:00
|
|
|
if (GetConsoleMode(hConOut, &modeOut))
|
2016-01-13 12:43:04 +01:00
|
|
|
childPrintf(hFile, "OutputMode=%u\n", modeOut);
|
2003-06-18 05:24:20 +02:00
|
|
|
|
|
|
|
/* now that we have written all relevant information, let's change it */
|
2008-09-20 12:49:41 +02:00
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = SetConsoleCP(1252);
|
|
|
|
if (!ret && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
|
|
|
|
{
|
2009-06-01 20:28:37 +02:00
|
|
|
win_skip("Setting the codepage is not implemented\n");
|
2008-09-20 12:49:41 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ok(ret, "Setting CP\n");
|
|
|
|
ok(SetConsoleOutputCP(1252), "Setting SB CP\n");
|
|
|
|
}
|
|
|
|
|
2004-12-27 18:26:37 +01:00
|
|
|
ret = SetConsoleMode(hConIn, modeIn ^ 1);
|
2006-10-10 01:06:48 +02:00
|
|
|
ok( ret, "Setting mode (%d)\n", GetLastError());
|
2004-12-27 18:26:37 +01:00
|
|
|
ret = SetConsoleMode(hConOut, modeOut ^ 1);
|
2006-10-10 01:06:48 +02:00
|
|
|
ok( ret, "Setting mode (%d)\n", GetLastError());
|
2003-06-18 05:24:20 +02:00
|
|
|
sbi.dwCursorPosition.X ^= 1;
|
|
|
|
sbi.dwCursorPosition.Y ^= 1;
|
2004-12-27 18:26:37 +01:00
|
|
|
ret = SetConsoleCursorPosition(hConOut, sbi.dwCursorPosition);
|
2006-10-10 01:06:48 +02:00
|
|
|
ok( ret, "Setting cursor position (%d)\n", GetLastError());
|
2003-06-18 05:24:20 +02:00
|
|
|
}
|
|
|
|
if (option && strcmp(option, "stdhandle") == 0)
|
|
|
|
{
|
|
|
|
HANDLE hStdIn = GetStdHandle(STD_INPUT_HANDLE);
|
|
|
|
HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
|
|
|
|
|
|
|
|
if (hStdIn != INVALID_HANDLE_VALUE || hStdOut != INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
char buf[1024];
|
|
|
|
DWORD r, w;
|
|
|
|
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(ReadFile(hStdIn, buf, sizeof(buf), &r, NULL) && r > 0, "Reading message from input pipe\n");
|
2003-06-18 05:24:20 +02:00
|
|
|
childPrintf(hFile, "[StdHandle]\nmsg=%s\n\n", encodeA(buf));
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(WriteFile(hStdOut, buf, r, &w, NULL) && w == r, "Writing message to output pipe\n");
|
2003-06-18 05:24:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-06-26 04:05:40 +02:00
|
|
|
if (option && strcmp(option, "exit_code") == 0)
|
|
|
|
{
|
|
|
|
childPrintf(hFile, "[ExitCode]\nvalue=%d\n\n", 123);
|
|
|
|
CloseHandle(hFile);
|
|
|
|
ExitProcess(123);
|
|
|
|
}
|
|
|
|
|
2002-04-22 00:07:03 +02:00
|
|
|
CloseHandle(hFile);
|
|
|
|
}
|
|
|
|
|
|
|
|
static char* getChildString(const char* sect, const char* key)
|
|
|
|
{
|
2003-11-18 20:38:51 +01:00
|
|
|
char buf[1024+4*MAX_LISTED_ENV_VAR];
|
2002-04-22 00:07:03 +02:00
|
|
|
char* ret;
|
|
|
|
|
|
|
|
GetPrivateProfileStringA(sect, key, "-", buf, sizeof(buf), resfile);
|
|
|
|
if (buf[0] == '\0' || (buf[0] == '-' && buf[1] == '\0')) return NULL;
|
|
|
|
assert(!(strlen(buf) & 1));
|
|
|
|
ret = decodeA(buf);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-10-15 16:30:28 +02:00
|
|
|
static WCHAR* getChildStringW(const char* sect, const char* key)
|
|
|
|
{
|
|
|
|
char buf[1024+4*MAX_LISTED_ENV_VAR];
|
|
|
|
WCHAR* ret;
|
|
|
|
|
|
|
|
GetPrivateProfileStringA(sect, key, "-", buf, sizeof(buf), resfile);
|
|
|
|
if (buf[0] == '\0' || (buf[0] == '-' && buf[1] == '\0')) return NULL;
|
|
|
|
assert(!(strlen(buf) & 1));
|
|
|
|
ret = decodeW(buf);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2002-04-22 00:07:03 +02:00
|
|
|
/* FIXME: this may be moved to the wtmain.c file, because it may be needed by
|
|
|
|
* others... (windows uses stricmp while Un*x uses strcasecmp...)
|
|
|
|
*/
|
|
|
|
static int wtstrcasecmp(const char* p1, const char* p2)
|
|
|
|
{
|
|
|
|
char c1, c2;
|
|
|
|
|
|
|
|
c1 = c2 = '@';
|
|
|
|
while (c1 == c2 && c1)
|
|
|
|
{
|
|
|
|
c1 = *p1++; c2 = *p2++;
|
|
|
|
if (c1 != c2)
|
|
|
|
{
|
|
|
|
c1 = toupper(c1); c2 = toupper(c2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return c1 - c2;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int strCmp(const char* s1, const char* s2, BOOL sensitive)
|
|
|
|
{
|
|
|
|
if (!s1 && !s2) return 0;
|
|
|
|
if (!s2) return -1;
|
|
|
|
if (!s1) return 1;
|
|
|
|
return (sensitive) ? strcmp(s1, s2) : wtstrcasecmp(s1, s2);
|
|
|
|
}
|
|
|
|
|
2007-10-17 14:15:40 +02:00
|
|
|
static void ok_child_string( int line, const char *sect, const char *key,
|
|
|
|
const char *expect, int sensitive )
|
|
|
|
{
|
|
|
|
char* result = getChildString( sect, key );
|
|
|
|
ok_(__FILE__, line)( strCmp(result, expect, sensitive) == 0, "%s:%s expected '%s', got '%s'\n",
|
|
|
|
sect, key, expect ? expect : "(null)", result );
|
|
|
|
}
|
2002-04-22 00:07:03 +02:00
|
|
|
|
2008-10-15 16:30:28 +02:00
|
|
|
static void ok_child_stringWA( int line, const char *sect, const char *key,
|
|
|
|
const char *expect, int sensitive )
|
|
|
|
{
|
|
|
|
WCHAR* expectW;
|
|
|
|
CHAR* resultA;
|
|
|
|
DWORD len;
|
|
|
|
WCHAR* result = getChildStringW( sect, key );
|
|
|
|
|
|
|
|
len = MultiByteToWideChar( CP_ACP, 0, expect, -1, NULL, 0);
|
|
|
|
expectW = HeapAlloc(GetProcessHeap(),0,len*sizeof(WCHAR));
|
|
|
|
MultiByteToWideChar( CP_ACP, 0, expect, -1, expectW, len);
|
|
|
|
|
|
|
|
len = WideCharToMultiByte( CP_ACP, 0, result, -1, NULL, 0, NULL, NULL);
|
|
|
|
resultA = HeapAlloc(GetProcessHeap(),0,len*sizeof(CHAR));
|
|
|
|
WideCharToMultiByte( CP_ACP, 0, result, -1, resultA, len, NULL, NULL);
|
|
|
|
|
|
|
|
if (sensitive)
|
|
|
|
ok_(__FILE__, line)( lstrcmpW(result, expectW) == 0, "%s:%s expected '%s', got '%s'\n",
|
|
|
|
sect, key, expect ? expect : "(null)", resultA );
|
|
|
|
else
|
|
|
|
ok_(__FILE__, line)( lstrcmpiW(result, expectW) == 0, "%s:%s expected '%s', got '%s'\n",
|
|
|
|
sect, key, expect ? expect : "(null)", resultA );
|
|
|
|
HeapFree(GetProcessHeap(),0,expectW);
|
|
|
|
HeapFree(GetProcessHeap(),0,resultA);
|
|
|
|
}
|
|
|
|
|
2007-10-17 14:15:40 +02:00
|
|
|
#define okChildString(sect, key, expect) ok_child_string(__LINE__, (sect), (key), (expect), 1 )
|
|
|
|
#define okChildIString(sect, key, expect) ok_child_string(__LINE__, (sect), (key), (expect), 0 )
|
2008-10-15 16:30:28 +02:00
|
|
|
#define okChildStringWA(sect, key, expect) ok_child_stringWA(__LINE__, (sect), (key), (expect), 1 )
|
2002-04-22 00:07:03 +02:00
|
|
|
|
2005-08-17 11:56:24 +02:00
|
|
|
/* using !expect ensures that the test will fail if the sect/key isn't present
|
2002-06-01 01:06:46 +02:00
|
|
|
* in result file
|
2002-04-22 00:07:03 +02:00
|
|
|
*/
|
|
|
|
#define okChildInt(sect, key, expect) \
|
|
|
|
do { \
|
2002-12-18 03:22:51 +01:00
|
|
|
UINT result = GetPrivateProfileIntA((sect), (key), !(expect), resfile); \
|
2009-01-08 13:17:53 +01:00
|
|
|
ok(result == expect, "%s:%s expected %u, but got %u\n", (sect), (key), (UINT)(expect), result); \
|
2002-04-22 00:07:03 +02:00
|
|
|
} while (0)
|
|
|
|
|
|
|
|
static void test_Startup(void)
|
|
|
|
{
|
|
|
|
char buffer[MAX_PATH];
|
|
|
|
PROCESS_INFORMATION info;
|
2002-12-18 21:51:33 +01:00
|
|
|
STARTUPINFOA startup,si;
|
2010-06-08 11:50:20 +02:00
|
|
|
char *result;
|
2006-06-02 20:01:23 +02:00
|
|
|
static CHAR title[] = "I'm the title string",
|
2008-11-17 23:37:00 +01:00
|
|
|
desktop[] = "winsta0\\default",
|
2006-06-02 20:01:23 +02:00
|
|
|
empty[] = "";
|
2002-04-22 00:07:03 +02:00
|
|
|
|
|
|
|
/* let's start simplistic */
|
|
|
|
memset(&startup, 0, sizeof(startup));
|
|
|
|
startup.cb = sizeof(startup);
|
|
|
|
startup.dwFlags = STARTF_USESHOWWINDOW;
|
|
|
|
startup.wShowWindow = SW_SHOWNORMAL;
|
|
|
|
|
|
|
|
get_file_name(resfile);
|
2015-02-26 05:18:09 +01:00
|
|
|
sprintf(buffer, "\"%s\" tests/process.c dump \"%s\"", selfname, resfile);
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
|
2002-04-22 00:07:03 +02:00
|
|
|
/* wait for child to terminate */
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
|
2002-04-22 00:07:03 +02:00
|
|
|
/* child process has changed result file, so let profile functions know about it */
|
|
|
|
WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
|
|
|
|
|
2002-12-18 21:51:33 +01:00
|
|
|
GetStartupInfoA(&si);
|
2002-04-22 00:07:03 +02:00
|
|
|
okChildInt("StartupInfoA", "cb", startup.cb);
|
2002-12-18 21:51:33 +01:00
|
|
|
okChildString("StartupInfoA", "lpDesktop", si.lpDesktop);
|
2002-04-22 00:07:03 +02:00
|
|
|
okChildInt("StartupInfoA", "dwX", startup.dwX);
|
|
|
|
okChildInt("StartupInfoA", "dwY", startup.dwY);
|
|
|
|
okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
|
|
|
|
okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
|
|
|
|
okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
|
|
|
|
okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
|
|
|
|
okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
|
|
|
|
okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
|
|
|
|
okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
|
|
|
|
release_memory();
|
|
|
|
assert(DeleteFileA(resfile) != 0);
|
|
|
|
|
|
|
|
/* not so simplistic now */
|
|
|
|
memset(&startup, 0, sizeof(startup));
|
|
|
|
startup.cb = sizeof(startup);
|
|
|
|
startup.dwFlags = STARTF_USESHOWWINDOW;
|
|
|
|
startup.wShowWindow = SW_SHOWNORMAL;
|
2006-06-02 20:01:23 +02:00
|
|
|
startup.lpTitle = title;
|
|
|
|
startup.lpDesktop = desktop;
|
2002-04-22 00:07:03 +02:00
|
|
|
startup.dwXCountChars = 0x12121212;
|
|
|
|
startup.dwYCountChars = 0x23232323;
|
|
|
|
startup.dwX = 0x34343434;
|
|
|
|
startup.dwY = 0x45454545;
|
|
|
|
startup.dwXSize = 0x56565656;
|
|
|
|
startup.dwYSize = 0x67676767;
|
|
|
|
startup.dwFillAttribute = 0xA55A;
|
|
|
|
|
|
|
|
get_file_name(resfile);
|
2015-02-26 05:18:09 +01:00
|
|
|
sprintf(buffer, "\"%s\" tests/process.c dump \"%s\"", selfname, resfile);
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
|
2002-04-22 00:07:03 +02:00
|
|
|
/* wait for child to terminate */
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
|
2002-04-22 00:07:03 +02:00
|
|
|
/* child process has changed result file, so let profile functions know about it */
|
|
|
|
WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
|
|
|
|
|
|
|
|
okChildInt("StartupInfoA", "cb", startup.cb);
|
|
|
|
okChildString("StartupInfoA", "lpDesktop", startup.lpDesktop);
|
|
|
|
okChildString("StartupInfoA", "lpTitle", startup.lpTitle);
|
|
|
|
okChildInt("StartupInfoA", "dwX", startup.dwX);
|
|
|
|
okChildInt("StartupInfoA", "dwY", startup.dwY);
|
|
|
|
okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
|
|
|
|
okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
|
|
|
|
okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
|
|
|
|
okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
|
|
|
|
okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
|
|
|
|
okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
|
|
|
|
okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
|
|
|
|
release_memory();
|
|
|
|
assert(DeleteFileA(resfile) != 0);
|
|
|
|
|
|
|
|
/* not so simplistic now */
|
|
|
|
memset(&startup, 0, sizeof(startup));
|
|
|
|
startup.cb = sizeof(startup);
|
|
|
|
startup.dwFlags = STARTF_USESHOWWINDOW;
|
|
|
|
startup.wShowWindow = SW_SHOWNORMAL;
|
2006-06-02 20:01:23 +02:00
|
|
|
startup.lpTitle = title;
|
2002-04-22 00:07:03 +02:00
|
|
|
startup.lpDesktop = NULL;
|
|
|
|
startup.dwXCountChars = 0x12121212;
|
|
|
|
startup.dwYCountChars = 0x23232323;
|
|
|
|
startup.dwX = 0x34343434;
|
|
|
|
startup.dwY = 0x45454545;
|
|
|
|
startup.dwXSize = 0x56565656;
|
|
|
|
startup.dwYSize = 0x67676767;
|
|
|
|
startup.dwFillAttribute = 0xA55A;
|
|
|
|
|
|
|
|
get_file_name(resfile);
|
2015-02-26 05:18:09 +01:00
|
|
|
sprintf(buffer, "\"%s\" tests/process.c dump \"%s\"", selfname, resfile);
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
|
2002-04-22 00:07:03 +02:00
|
|
|
/* wait for child to terminate */
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
|
2002-04-22 00:07:03 +02:00
|
|
|
/* child process has changed result file, so let profile functions know about it */
|
|
|
|
WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
|
|
|
|
|
|
|
|
okChildInt("StartupInfoA", "cb", startup.cb);
|
2002-12-18 21:51:33 +01:00
|
|
|
okChildString("StartupInfoA", "lpDesktop", si.lpDesktop);
|
2002-04-22 00:07:03 +02:00
|
|
|
okChildString("StartupInfoA", "lpTitle", startup.lpTitle);
|
|
|
|
okChildInt("StartupInfoA", "dwX", startup.dwX);
|
|
|
|
okChildInt("StartupInfoA", "dwY", startup.dwY);
|
|
|
|
okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
|
|
|
|
okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
|
|
|
|
okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
|
|
|
|
okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
|
|
|
|
okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
|
|
|
|
okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
|
|
|
|
okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
|
|
|
|
release_memory();
|
|
|
|
assert(DeleteFileA(resfile) != 0);
|
|
|
|
|
|
|
|
/* not so simplistic now */
|
|
|
|
memset(&startup, 0, sizeof(startup));
|
|
|
|
startup.cb = sizeof(startup);
|
|
|
|
startup.dwFlags = STARTF_USESHOWWINDOW;
|
|
|
|
startup.wShowWindow = SW_SHOWNORMAL;
|
2006-06-02 20:01:23 +02:00
|
|
|
startup.lpTitle = title;
|
|
|
|
startup.lpDesktop = empty;
|
2002-04-22 00:07:03 +02:00
|
|
|
startup.dwXCountChars = 0x12121212;
|
|
|
|
startup.dwYCountChars = 0x23232323;
|
|
|
|
startup.dwX = 0x34343434;
|
|
|
|
startup.dwY = 0x45454545;
|
|
|
|
startup.dwXSize = 0x56565656;
|
|
|
|
startup.dwYSize = 0x67676767;
|
|
|
|
startup.dwFillAttribute = 0xA55A;
|
|
|
|
|
|
|
|
get_file_name(resfile);
|
2015-02-26 05:18:09 +01:00
|
|
|
sprintf(buffer, "\"%s\" tests/process.c dump \"%s\"", selfname, resfile);
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
|
2002-04-22 00:07:03 +02:00
|
|
|
/* wait for child to terminate */
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
|
2002-04-22 00:07:03 +02:00
|
|
|
/* child process has changed result file, so let profile functions know about it */
|
|
|
|
WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
|
|
|
|
|
|
|
|
okChildInt("StartupInfoA", "cb", startup.cb);
|
2010-06-08 11:53:58 +02:00
|
|
|
okChildString("StartupInfoA", "lpDesktop", startup.lpDesktop);
|
2002-04-22 00:07:03 +02:00
|
|
|
okChildString("StartupInfoA", "lpTitle", startup.lpTitle);
|
|
|
|
okChildInt("StartupInfoA", "dwX", startup.dwX);
|
|
|
|
okChildInt("StartupInfoA", "dwY", startup.dwY);
|
|
|
|
okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
|
|
|
|
okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
|
|
|
|
okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
|
|
|
|
okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
|
|
|
|
okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
|
|
|
|
okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
|
|
|
|
okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
|
|
|
|
release_memory();
|
|
|
|
assert(DeleteFileA(resfile) != 0);
|
|
|
|
|
|
|
|
/* not so simplistic now */
|
|
|
|
memset(&startup, 0, sizeof(startup));
|
|
|
|
startup.cb = sizeof(startup);
|
|
|
|
startup.dwFlags = STARTF_USESHOWWINDOW;
|
|
|
|
startup.wShowWindow = SW_SHOWNORMAL;
|
|
|
|
startup.lpTitle = NULL;
|
2006-06-02 20:01:23 +02:00
|
|
|
startup.lpDesktop = desktop;
|
2002-04-22 00:07:03 +02:00
|
|
|
startup.dwXCountChars = 0x12121212;
|
|
|
|
startup.dwYCountChars = 0x23232323;
|
|
|
|
startup.dwX = 0x34343434;
|
|
|
|
startup.dwY = 0x45454545;
|
|
|
|
startup.dwXSize = 0x56565656;
|
|
|
|
startup.dwYSize = 0x67676767;
|
|
|
|
startup.dwFillAttribute = 0xA55A;
|
|
|
|
|
|
|
|
get_file_name(resfile);
|
2015-02-26 05:18:09 +01:00
|
|
|
sprintf(buffer, "\"%s\" tests/process.c dump \"%s\"", selfname, resfile);
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
|
2002-04-22 00:07:03 +02:00
|
|
|
/* wait for child to terminate */
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
|
2002-04-22 00:07:03 +02:00
|
|
|
/* child process has changed result file, so let profile functions know about it */
|
|
|
|
WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
|
|
|
|
|
|
|
|
okChildInt("StartupInfoA", "cb", startup.cb);
|
|
|
|
okChildString("StartupInfoA", "lpDesktop", startup.lpDesktop);
|
2010-06-08 11:50:20 +02:00
|
|
|
result = getChildString( "StartupInfoA", "lpTitle" );
|
2010-06-08 11:53:58 +02:00
|
|
|
ok( broken(!result) || (result && !strCmp( result, selfname, 0 )),
|
|
|
|
"expected '%s' or null, got '%s'\n", selfname, result );
|
2002-04-22 00:07:03 +02:00
|
|
|
okChildInt("StartupInfoA", "dwX", startup.dwX);
|
|
|
|
okChildInt("StartupInfoA", "dwY", startup.dwY);
|
|
|
|
okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
|
|
|
|
okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
|
|
|
|
okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
|
|
|
|
okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
|
|
|
|
okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
|
|
|
|
okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
|
|
|
|
okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
|
|
|
|
release_memory();
|
|
|
|
assert(DeleteFileA(resfile) != 0);
|
|
|
|
|
|
|
|
/* not so simplistic now */
|
|
|
|
memset(&startup, 0, sizeof(startup));
|
|
|
|
startup.cb = sizeof(startup);
|
|
|
|
startup.dwFlags = STARTF_USESHOWWINDOW;
|
|
|
|
startup.wShowWindow = SW_SHOWNORMAL;
|
2006-06-02 20:01:23 +02:00
|
|
|
startup.lpTitle = empty;
|
|
|
|
startup.lpDesktop = desktop;
|
2002-04-22 00:07:03 +02:00
|
|
|
startup.dwXCountChars = 0x12121212;
|
|
|
|
startup.dwYCountChars = 0x23232323;
|
|
|
|
startup.dwX = 0x34343434;
|
|
|
|
startup.dwY = 0x45454545;
|
|
|
|
startup.dwXSize = 0x56565656;
|
|
|
|
startup.dwYSize = 0x67676767;
|
|
|
|
startup.dwFillAttribute = 0xA55A;
|
|
|
|
|
|
|
|
get_file_name(resfile);
|
2015-02-26 05:18:09 +01:00
|
|
|
sprintf(buffer, "\"%s\" tests/process.c dump \"%s\"", selfname, resfile);
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
|
2002-04-22 00:07:03 +02:00
|
|
|
/* wait for child to terminate */
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
|
2002-04-22 00:07:03 +02:00
|
|
|
/* child process has changed result file, so let profile functions know about it */
|
|
|
|
WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
|
|
|
|
|
|
|
|
okChildInt("StartupInfoA", "cb", startup.cb);
|
|
|
|
okChildString("StartupInfoA", "lpDesktop", startup.lpDesktop);
|
2010-06-08 11:53:58 +02:00
|
|
|
okChildString("StartupInfoA", "lpTitle", startup.lpTitle);
|
2002-04-22 00:07:03 +02:00
|
|
|
okChildInt("StartupInfoA", "dwX", startup.dwX);
|
|
|
|
okChildInt("StartupInfoA", "dwY", startup.dwY);
|
|
|
|
okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
|
|
|
|
okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
|
|
|
|
okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
|
|
|
|
okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
|
|
|
|
okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
|
|
|
|
okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
|
|
|
|
okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
|
|
|
|
release_memory();
|
|
|
|
assert(DeleteFileA(resfile) != 0);
|
|
|
|
|
|
|
|
/* not so simplistic now */
|
|
|
|
memset(&startup, 0, sizeof(startup));
|
|
|
|
startup.cb = sizeof(startup);
|
|
|
|
startup.dwFlags = STARTF_USESHOWWINDOW;
|
|
|
|
startup.wShowWindow = SW_SHOWNORMAL;
|
2006-06-02 20:01:23 +02:00
|
|
|
startup.lpTitle = empty;
|
|
|
|
startup.lpDesktop = empty;
|
2002-04-22 00:07:03 +02:00
|
|
|
startup.dwXCountChars = 0x12121212;
|
|
|
|
startup.dwYCountChars = 0x23232323;
|
|
|
|
startup.dwX = 0x34343434;
|
|
|
|
startup.dwY = 0x45454545;
|
|
|
|
startup.dwXSize = 0x56565656;
|
|
|
|
startup.dwYSize = 0x67676767;
|
|
|
|
startup.dwFillAttribute = 0xA55A;
|
|
|
|
|
|
|
|
get_file_name(resfile);
|
2015-02-26 05:18:09 +01:00
|
|
|
sprintf(buffer, "\"%s\" tests/process.c dump \"%s\"", selfname, resfile);
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
|
2002-04-22 00:07:03 +02:00
|
|
|
/* wait for child to terminate */
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
|
2002-04-22 00:07:03 +02:00
|
|
|
/* child process has changed result file, so let profile functions know about it */
|
|
|
|
WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
|
|
|
|
|
|
|
|
okChildInt("StartupInfoA", "cb", startup.cb);
|
2010-06-08 11:53:58 +02:00
|
|
|
okChildString("StartupInfoA", "lpDesktop", startup.lpDesktop);
|
|
|
|
okChildString("StartupInfoA", "lpTitle", startup.lpTitle);
|
2002-04-22 00:07:03 +02:00
|
|
|
okChildInt("StartupInfoA", "dwX", startup.dwX);
|
|
|
|
okChildInt("StartupInfoA", "dwY", startup.dwY);
|
|
|
|
okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
|
|
|
|
okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
|
|
|
|
okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
|
|
|
|
okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
|
|
|
|
okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
|
|
|
|
okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
|
|
|
|
okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
|
|
|
|
release_memory();
|
|
|
|
assert(DeleteFileA(resfile) != 0);
|
|
|
|
|
|
|
|
/* TODO: test for A/W and W/A and W/W */
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_CommandLine(void)
|
|
|
|
{
|
2005-10-27 12:25:49 +02:00
|
|
|
char buffer[MAX_PATH], fullpath[MAX_PATH], *lpFilePart, *p;
|
2008-10-15 16:30:21 +02:00
|
|
|
char buffer2[MAX_PATH];
|
2002-04-22 00:07:03 +02:00
|
|
|
PROCESS_INFORMATION info;
|
|
|
|
STARTUPINFOA startup;
|
2006-12-14 14:29:45 +01:00
|
|
|
BOOL ret;
|
2002-04-22 00:07:03 +02:00
|
|
|
|
|
|
|
memset(&startup, 0, sizeof(startup));
|
|
|
|
startup.cb = sizeof(startup);
|
|
|
|
startup.dwFlags = STARTF_USESHOWWINDOW;
|
|
|
|
startup.wShowWindow = SW_SHOWNORMAL;
|
|
|
|
|
|
|
|
/* the basics */
|
|
|
|
get_file_name(resfile);
|
2015-02-26 05:18:09 +01:00
|
|
|
sprintf(buffer, "\"%s\" tests/process.c dump \"%s\" \"C:\\Program Files\\my nice app.exe\"", selfname, resfile);
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
|
2002-04-22 00:07:03 +02:00
|
|
|
/* wait for child to terminate */
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
|
2002-04-22 00:07:03 +02:00
|
|
|
/* child process has changed result file, so let profile functions know about it */
|
|
|
|
WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
|
|
|
|
|
2015-02-26 05:18:09 +01:00
|
|
|
okChildInt("Arguments", "argcA", 5);
|
|
|
|
okChildString("Arguments", "argvA4", "C:\\Program Files\\my nice app.exe");
|
|
|
|
okChildString("Arguments", "argvA5", NULL);
|
2002-04-22 00:07:03 +02:00
|
|
|
okChildString("Arguments", "CommandLineA", buffer);
|
|
|
|
release_memory();
|
|
|
|
assert(DeleteFileA(resfile) != 0);
|
|
|
|
|
|
|
|
memset(&startup, 0, sizeof(startup));
|
|
|
|
startup.cb = sizeof(startup);
|
|
|
|
startup.dwFlags = STARTF_USESHOWWINDOW;
|
|
|
|
startup.wShowWindow = SW_SHOWNORMAL;
|
|
|
|
|
2011-08-03 23:50:18 +02:00
|
|
|
/* from François */
|
2002-04-22 00:07:03 +02:00
|
|
|
get_file_name(resfile);
|
2015-02-26 05:18:09 +01:00
|
|
|
sprintf(buffer, "\"%s\" tests/process.c dump \"%s\" \"a\\\"b\\\\\" c\\\" d", selfname, resfile);
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
|
2002-04-22 00:07:03 +02:00
|
|
|
/* wait for child to terminate */
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
|
2002-04-22 00:07:03 +02:00
|
|
|
/* child process has changed result file, so let profile functions know about it */
|
|
|
|
WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
|
|
|
|
|
2015-02-26 05:18:09 +01:00
|
|
|
okChildInt("Arguments", "argcA", 7);
|
|
|
|
okChildString("Arguments", "argvA4", "a\"b\\");
|
|
|
|
okChildString("Arguments", "argvA5", "c\"");
|
|
|
|
okChildString("Arguments", "argvA6", "d");
|
|
|
|
okChildString("Arguments", "argvA7", NULL);
|
2002-04-22 00:07:03 +02:00
|
|
|
okChildString("Arguments", "CommandLineA", buffer);
|
|
|
|
release_memory();
|
|
|
|
assert(DeleteFileA(resfile) != 0);
|
2005-10-27 12:25:49 +02:00
|
|
|
|
|
|
|
/* Test for Bug1330 to show that XP doesn't change '/' to '\\' in argv[0]*/
|
|
|
|
get_file_name(resfile);
|
2006-12-20 18:28:11 +01:00
|
|
|
/* Use exename to avoid buffer containing things like 'C:' */
|
2015-02-26 05:18:09 +01:00
|
|
|
sprintf(buffer, "./%s tests/process.c dump \"%s\" \"a\\\"b\\\\\" c\\\" d", exename, resfile);
|
2006-12-14 14:29:45 +01:00
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info);
|
|
|
|
ok(ret, "CreateProcess (%s) failed : %d\n", buffer, GetLastError());
|
2005-10-27 12:25:49 +02:00
|
|
|
/* wait for child to terminate */
|
|
|
|
ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
|
|
|
|
/* child process has changed result file, so let profile functions know about it */
|
|
|
|
WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
|
2006-12-20 18:28:11 +01:00
|
|
|
sprintf(buffer, "./%s", exename);
|
2005-10-27 12:25:49 +02:00
|
|
|
okChildString("Arguments", "argvA0", buffer);
|
|
|
|
release_memory();
|
|
|
|
assert(DeleteFileA(resfile) != 0);
|
|
|
|
|
|
|
|
get_file_name(resfile);
|
2006-12-20 18:28:11 +01:00
|
|
|
/* Use exename to avoid buffer containing things like 'C:' */
|
2015-02-26 05:18:09 +01:00
|
|
|
sprintf(buffer, ".\\%s tests/process.c dump \"%s\" \"a\\\"b\\\\\" c\\\" d", exename, resfile);
|
2006-12-14 14:29:45 +01:00
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info);
|
|
|
|
ok(ret, "CreateProcess (%s) failed : %d\n", buffer, GetLastError());
|
2005-10-27 12:25:49 +02:00
|
|
|
/* wait for child to terminate */
|
|
|
|
ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
|
|
|
|
/* child process has changed result file, so let profile functions know about it */
|
|
|
|
WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
|
2006-12-20 18:28:11 +01:00
|
|
|
sprintf(buffer, ".\\%s", exename);
|
2005-10-27 12:25:49 +02:00
|
|
|
okChildString("Arguments", "argvA0", buffer);
|
|
|
|
release_memory();
|
|
|
|
assert(DeleteFileA(resfile) != 0);
|
|
|
|
|
|
|
|
get_file_name(resfile);
|
2010-05-05 00:24:09 +02:00
|
|
|
GetFullPathNameA(selfname, MAX_PATH, fullpath, &lpFilePart);
|
2005-10-27 12:25:49 +02:00
|
|
|
assert ( lpFilePart != 0);
|
|
|
|
*(lpFilePart -1 ) = 0;
|
|
|
|
p = strrchr(fullpath, '\\');
|
2006-12-20 18:28:11 +01:00
|
|
|
/* Use exename to avoid buffer containing things like 'C:' */
|
2015-02-26 05:18:09 +01:00
|
|
|
if (p) sprintf(buffer, "..%s/%s tests/process.c dump \"%s\" \"a\\\"b\\\\\" c\\\" d", p, exename, resfile);
|
|
|
|
else sprintf(buffer, "./%s tests/process.c dump \"%s\" \"a\\\"b\\\\\" c\\\" d", exename, resfile);
|
2006-12-14 14:29:45 +01:00
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info);
|
|
|
|
ok(ret, "CreateProcess (%s) failed : %d\n", buffer, GetLastError());
|
2005-10-27 12:25:49 +02:00
|
|
|
/* wait for child to terminate */
|
|
|
|
ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
|
|
|
|
/* child process has changed result file, so let profile functions know about it */
|
|
|
|
WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
|
2008-11-17 23:37:00 +01:00
|
|
|
if (p) sprintf(buffer, "..%s/%s", p, exename);
|
|
|
|
else sprintf(buffer, "./%s", exename);
|
2005-10-27 12:25:49 +02:00
|
|
|
okChildString("Arguments", "argvA0", buffer);
|
|
|
|
release_memory();
|
|
|
|
assert(DeleteFileA(resfile) != 0);
|
2008-10-15 16:30:21 +02:00
|
|
|
|
|
|
|
/* Using AppName */
|
|
|
|
get_file_name(resfile);
|
2010-05-05 00:24:09 +02:00
|
|
|
GetFullPathNameA(selfname, MAX_PATH, fullpath, &lpFilePart);
|
2008-10-15 16:30:21 +02:00
|
|
|
assert ( lpFilePart != 0);
|
|
|
|
*(lpFilePart -1 ) = 0;
|
|
|
|
p = strrchr(fullpath, '\\');
|
|
|
|
/* Use exename to avoid buffer containing things like 'C:' */
|
2008-11-17 23:37:00 +01:00
|
|
|
if (p) sprintf(buffer, "..%s/%s", p, exename);
|
|
|
|
else sprintf(buffer, "./%s", exename);
|
2015-02-26 05:18:09 +01:00
|
|
|
sprintf(buffer2, "dummy tests/process.c dump \"%s\" \"a\\\"b\\\\\" c\\\" d", resfile);
|
2008-10-15 16:30:21 +02:00
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = CreateProcessA(buffer, buffer2, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info);
|
|
|
|
ok(ret, "CreateProcess (%s) failed : %d\n", buffer, GetLastError());
|
|
|
|
/* wait for child to terminate */
|
|
|
|
ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
|
|
|
|
/* child process has changed result file, so let profile functions know about it */
|
|
|
|
WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
|
2015-02-26 05:18:09 +01:00
|
|
|
sprintf(buffer, "tests/process.c dump %s", resfile);
|
2008-10-15 16:30:21 +02:00
|
|
|
okChildString("Arguments", "argvA0", "dummy");
|
|
|
|
okChildString("Arguments", "CommandLineA", buffer2);
|
2008-10-15 16:30:28 +02:00
|
|
|
okChildStringWA("Arguments", "CommandLineW", buffer2);
|
2008-10-15 16:30:21 +02:00
|
|
|
release_memory();
|
|
|
|
assert(DeleteFileA(resfile) != 0);
|
2009-05-18 12:07:04 +02:00
|
|
|
|
|
|
|
if (0) /* Test crashes on NT-based Windows. */
|
|
|
|
{
|
|
|
|
/* Test NULL application name and command line parameters. */
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = CreateProcessA(NULL, NULL, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info);
|
|
|
|
ok(!ret, "CreateProcessA unexpectedly succeeded\n");
|
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER,
|
|
|
|
"Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
|
|
|
|
}
|
2009-05-18 12:07:10 +02:00
|
|
|
|
|
|
|
buffer[0] = '\0';
|
|
|
|
|
|
|
|
/* Test empty application name parameter. */
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = CreateProcessA(buffer, NULL, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info);
|
|
|
|
ok(!ret, "CreateProcessA unexpectedly succeeded\n");
|
|
|
|
ok(GetLastError() == ERROR_PATH_NOT_FOUND ||
|
2009-05-18 19:22:28 +02:00
|
|
|
broken(GetLastError() == ERROR_FILE_NOT_FOUND) /* Win9x/WinME */ ||
|
2009-05-18 12:07:10 +02:00
|
|
|
broken(GetLastError() == ERROR_ACCESS_DENIED) /* Win98 */,
|
|
|
|
"Expected ERROR_PATH_NOT_FOUND, got %d\n", GetLastError());
|
|
|
|
|
|
|
|
buffer2[0] = '\0';
|
|
|
|
|
|
|
|
/* Test empty application name and command line parameters. */
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = CreateProcessA(buffer, buffer2, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info);
|
|
|
|
ok(!ret, "CreateProcessA unexpectedly succeeded\n");
|
|
|
|
ok(GetLastError() == ERROR_PATH_NOT_FOUND ||
|
2009-05-18 19:22:28 +02:00
|
|
|
broken(GetLastError() == ERROR_FILE_NOT_FOUND) /* Win9x/WinME */ ||
|
2009-05-18 12:07:10 +02:00
|
|
|
broken(GetLastError() == ERROR_ACCESS_DENIED) /* Win98 */,
|
|
|
|
"Expected ERROR_PATH_NOT_FOUND, got %d\n", GetLastError());
|
2009-05-18 12:07:18 +02:00
|
|
|
|
|
|
|
/* Test empty command line parameter. */
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = CreateProcessA(NULL, buffer2, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info);
|
|
|
|
ok(!ret, "CreateProcessA unexpectedly succeeded\n");
|
|
|
|
ok(GetLastError() == ERROR_FILE_NOT_FOUND ||
|
|
|
|
GetLastError() == ERROR_PATH_NOT_FOUND /* NT4 */ ||
|
2001-09-17 00:00:00 +02:00
|
|
|
GetLastError() == ERROR_BAD_PATHNAME /* Win98 */ ||
|
|
|
|
GetLastError() == ERROR_INVALID_PARAMETER /* Win7 */,
|
2009-05-18 12:07:18 +02:00
|
|
|
"Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
|
|
|
|
|
|
|
|
strcpy(buffer, "doesnotexist.exe");
|
|
|
|
strcpy(buffer2, "does not exist.exe");
|
|
|
|
|
|
|
|
/* Test nonexistent application name. */
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = CreateProcessA(buffer, NULL, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info);
|
|
|
|
ok(!ret, "CreateProcessA unexpectedly succeeded\n");
|
|
|
|
ok(GetLastError() == ERROR_FILE_NOT_FOUND, "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = CreateProcessA(buffer2, NULL, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info);
|
|
|
|
ok(!ret, "CreateProcessA unexpectedly succeeded\n");
|
|
|
|
ok(GetLastError() == ERROR_FILE_NOT_FOUND, "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
|
|
|
|
|
|
|
|
/* Test nonexistent command line parameter. */
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info);
|
|
|
|
ok(!ret, "CreateProcessA unexpectedly succeeded\n");
|
|
|
|
ok(GetLastError() == ERROR_FILE_NOT_FOUND, "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = CreateProcessA(NULL, buffer2, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info);
|
|
|
|
ok(!ret, "CreateProcessA unexpectedly succeeded\n");
|
|
|
|
ok(GetLastError() == ERROR_FILE_NOT_FOUND, "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
|
2002-04-22 00:07:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_Directory(void)
|
|
|
|
{
|
|
|
|
char buffer[MAX_PATH];
|
|
|
|
PROCESS_INFORMATION info;
|
|
|
|
STARTUPINFOA startup;
|
|
|
|
char windir[MAX_PATH];
|
2006-08-01 21:16:41 +02:00
|
|
|
static CHAR cmdline[] = "winver.exe";
|
2002-04-22 00:07:03 +02:00
|
|
|
|
|
|
|
memset(&startup, 0, sizeof(startup));
|
|
|
|
startup.cb = sizeof(startup);
|
|
|
|
startup.dwFlags = STARTF_USESHOWWINDOW;
|
|
|
|
startup.wShowWindow = SW_SHOWNORMAL;
|
|
|
|
|
|
|
|
/* the basics */
|
|
|
|
get_file_name(resfile);
|
2015-02-26 05:18:09 +01:00
|
|
|
sprintf(buffer, "\"%s\" tests/process.c dump \"%s\"", selfname, resfile);
|
2002-04-22 00:07:03 +02:00
|
|
|
GetWindowsDirectoryA( windir, sizeof(windir) );
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, windir, &startup, &info), "CreateProcess\n");
|
2002-04-22 00:07:03 +02:00
|
|
|
/* wait for child to terminate */
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
|
2002-04-22 00:07:03 +02:00
|
|
|
/* child process has changed result file, so let profile functions know about it */
|
|
|
|
WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
|
|
|
|
|
|
|
|
okChildIString("Misc", "CurrDirA", windir);
|
|
|
|
release_memory();
|
|
|
|
assert(DeleteFileA(resfile) != 0);
|
2006-03-27 05:53:09 +02:00
|
|
|
|
|
|
|
/* search PATH for the exe if directory is NULL */
|
2006-08-01 21:16:41 +02:00
|
|
|
ok(CreateProcessA(NULL, cmdline, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
|
2006-03-27 05:53:09 +02:00
|
|
|
ok(TerminateProcess(info.hProcess, 0), "Child process termination\n");
|
|
|
|
|
|
|
|
/* if any directory is provided, don't search PATH, error on bad directory */
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
memset(&info, 0, sizeof(info));
|
2006-08-01 21:16:41 +02:00
|
|
|
ok(!CreateProcessA(NULL, cmdline, NULL, NULL, FALSE, 0L,
|
2006-03-27 05:53:09 +02:00
|
|
|
NULL, "non\\existent\\directory", &startup, &info), "CreateProcess\n");
|
2006-10-10 01:06:48 +02:00
|
|
|
ok(GetLastError() == ERROR_DIRECTORY, "Expected ERROR_DIRECTORY, got %d\n", GetLastError());
|
2006-03-27 05:53:09 +02:00
|
|
|
ok(!TerminateProcess(info.hProcess, 0), "Child process should not exist\n");
|
2002-04-22 00:07:03 +02:00
|
|
|
}
|
|
|
|
|
2015-12-21 13:06:37 +01:00
|
|
|
static void test_Toolhelp(void)
|
|
|
|
{
|
|
|
|
char buffer[MAX_PATH];
|
|
|
|
STARTUPINFOA startup;
|
|
|
|
PROCESS_INFORMATION info;
|
|
|
|
HANDLE process, thread, snapshot;
|
|
|
|
PROCESSENTRY32 pe;
|
|
|
|
THREADENTRY32 te;
|
|
|
|
DWORD ret;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
memset(&startup, 0, sizeof(startup));
|
|
|
|
startup.cb = sizeof(startup);
|
|
|
|
startup.dwFlags = STARTF_USESHOWWINDOW;
|
|
|
|
startup.wShowWindow = SW_SHOWNORMAL;
|
|
|
|
|
|
|
|
get_file_name(resfile);
|
|
|
|
sprintf(buffer, "\"%s\" tests/process.c dump \"%s\"", selfname, resfile);
|
|
|
|
ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess failed\n");
|
|
|
|
ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
|
|
|
|
CloseHandle(info.hProcess);
|
|
|
|
CloseHandle(info.hThread);
|
|
|
|
|
|
|
|
WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
|
|
|
|
okChildInt("Toolhelp", "cntUsage", 0);
|
|
|
|
okChildInt("Toolhelp", "th32DefaultHeapID", 0);
|
|
|
|
okChildInt("Toolhelp", "th32ModuleID", 0);
|
|
|
|
okChildInt("Toolhelp", "th32ParentProcessID", GetCurrentProcessId());
|
|
|
|
todo_wine okChildInt("Toolhelp", "pcPriClassBase", 8);
|
|
|
|
okChildInt("Toolhelp", "dwFlags", 0);
|
|
|
|
|
|
|
|
release_memory();
|
|
|
|
DeleteFileA(resfile);
|
|
|
|
|
|
|
|
get_file_name(resfile);
|
|
|
|
sprintf(buffer, "\"%s\" tests/process.c nested \"%s\"", selfname, resfile);
|
|
|
|
ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess failed\n");
|
|
|
|
ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
|
|
|
|
|
|
|
|
process = OpenProcess(PROCESS_ALL_ACCESS_NT4, FALSE, info.dwProcessId);
|
|
|
|
ok(process != NULL, "OpenProcess failed %u\n", GetLastError());
|
|
|
|
CloseHandle(process);
|
|
|
|
|
|
|
|
CloseHandle(info.hProcess);
|
|
|
|
CloseHandle(info.hThread);
|
|
|
|
|
|
|
|
for (i = 0; i < 20; i++)
|
|
|
|
{
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
process = OpenProcess(PROCESS_ALL_ACCESS_NT4, FALSE, info.dwProcessId);
|
|
|
|
ok(process || GetLastError() == ERROR_INVALID_PARAMETER, "OpenProcess failed %u\n", GetLastError());
|
|
|
|
if (!process) break;
|
|
|
|
CloseHandle(process);
|
|
|
|
Sleep(100);
|
|
|
|
}
|
|
|
|
/* The following test fails randomly on some Windows versions, but Gothic 2 depends on it */
|
|
|
|
todo_wine ok(i < 20 || broken(i == 20), "process object not released\n");
|
|
|
|
|
|
|
|
snapshot = pCreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
|
|
|
|
ok(snapshot != INVALID_HANDLE_VALUE, "CreateToolhelp32Snapshot failed %u\n", GetLastError());
|
|
|
|
memset(&pe, 0, sizeof(pe));
|
|
|
|
pe.dwSize = sizeof(pe);
|
|
|
|
if (pProcess32First(snapshot, &pe))
|
|
|
|
{
|
|
|
|
while (pe.th32ParentProcessID != info.dwProcessId)
|
|
|
|
if (!pProcess32Next(snapshot, &pe)) break;
|
|
|
|
}
|
|
|
|
CloseHandle(snapshot);
|
|
|
|
ok(pe.th32ParentProcessID == info.dwProcessId, "failed to find nested child process\n");
|
|
|
|
|
|
|
|
process = OpenProcess(PROCESS_ALL_ACCESS_NT4, FALSE, pe.th32ProcessID);
|
|
|
|
ok(process != NULL, "OpenProcess failed %u\n", GetLastError());
|
|
|
|
|
|
|
|
snapshot = pCreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);
|
|
|
|
ok(snapshot != INVALID_HANDLE_VALUE, "CreateToolhelp32Snapshot failed %u\n", GetLastError());
|
|
|
|
memset(&te, 0, sizeof(te));
|
|
|
|
te.dwSize = sizeof(te);
|
|
|
|
if (pThread32First(snapshot, &te))
|
|
|
|
{
|
|
|
|
while (te.th32OwnerProcessID != pe.th32ProcessID)
|
|
|
|
if (!pThread32Next(snapshot, &te)) break;
|
|
|
|
}
|
|
|
|
CloseHandle(snapshot);
|
|
|
|
ok(te.th32OwnerProcessID == pe.th32ProcessID, "failed to find suspended thread\n");
|
|
|
|
|
|
|
|
thread = OpenThread(THREAD_ALL_ACCESS_NT4, FALSE, te.th32ThreadID);
|
|
|
|
ok(thread != NULL, "OpenThread failed %u\n", GetLastError());
|
|
|
|
ret = ResumeThread(thread);
|
|
|
|
ok(ret == 1, "expected 1, got %u\n", ret);
|
|
|
|
CloseHandle(thread);
|
|
|
|
|
|
|
|
ok(WaitForSingleObject(process, 30000) == WAIT_OBJECT_0, "Child process termination\n");
|
|
|
|
CloseHandle(process);
|
|
|
|
|
|
|
|
WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
|
|
|
|
okChildInt("Toolhelp", "cntUsage", 0);
|
|
|
|
okChildInt("Toolhelp", "th32DefaultHeapID", 0);
|
|
|
|
okChildInt("Toolhelp", "th32ModuleID", 0);
|
|
|
|
okChildInt("Toolhelp", "th32ParentProcessID", info.dwProcessId);
|
|
|
|
todo_wine okChildInt("Toolhelp", "pcPriClassBase", 8);
|
|
|
|
okChildInt("Toolhelp", "dwFlags", 0);
|
|
|
|
|
|
|
|
release_memory();
|
|
|
|
DeleteFileA(resfile);
|
|
|
|
}
|
|
|
|
|
2003-01-13 19:28:43 +01:00
|
|
|
static BOOL is_str_env_drive_dir(const char* str)
|
|
|
|
{
|
|
|
|
return str[0] == '=' && str[1] >= 'A' && str[1] <= 'Z' && str[2] == ':' &&
|
|
|
|
str[3] == '=' && str[4] == str[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* compared expected child's environment (in gesA) from actual
|
|
|
|
* environment our child got
|
|
|
|
*/
|
|
|
|
static void cmpEnvironment(const char* gesA)
|
|
|
|
{
|
|
|
|
int i, clen;
|
|
|
|
const char* ptrA;
|
|
|
|
char* res;
|
|
|
|
char key[32];
|
|
|
|
BOOL found;
|
|
|
|
|
|
|
|
clen = GetPrivateProfileIntA("EnvironmentA", "len", 0, resfile);
|
|
|
|
|
|
|
|
/* now look each parent env in child */
|
|
|
|
if ((ptrA = gesA) != NULL)
|
|
|
|
{
|
|
|
|
while (*ptrA)
|
|
|
|
{
|
|
|
|
for (i = 0; i < clen; i++)
|
|
|
|
{
|
|
|
|
sprintf(key, "env%d", i);
|
|
|
|
res = getChildString("EnvironmentA", key);
|
|
|
|
if (strncmp(ptrA, res, MAX_LISTED_ENV_VAR - 1) == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
found = i < clen;
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(found, "Parent-env string %s isn't in child process\n", ptrA);
|
2003-01-13 19:28:43 +01:00
|
|
|
|
|
|
|
ptrA += strlen(ptrA) + 1;
|
|
|
|
release_memory();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* and each child env in parent */
|
|
|
|
for (i = 0; i < clen; i++)
|
|
|
|
{
|
|
|
|
sprintf(key, "env%d", i);
|
|
|
|
res = getChildString("EnvironmentA", key);
|
|
|
|
if ((ptrA = gesA) != NULL)
|
|
|
|
{
|
|
|
|
while (*ptrA)
|
|
|
|
{
|
|
|
|
if (strncmp(res, ptrA, MAX_LISTED_ENV_VAR - 1) == 0)
|
|
|
|
break;
|
|
|
|
ptrA += strlen(ptrA) + 1;
|
|
|
|
}
|
|
|
|
if (!*ptrA) ptrA = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!is_str_env_drive_dir(res))
|
|
|
|
{
|
|
|
|
found = ptrA != NULL;
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(found, "Child-env string %s isn't in parent process\n", res);
|
2003-01-13 19:28:43 +01:00
|
|
|
}
|
|
|
|
/* else => should also test we get the right per drive default directory here... */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_Environment(void)
|
|
|
|
{
|
|
|
|
char buffer[MAX_PATH];
|
|
|
|
PROCESS_INFORMATION info;
|
|
|
|
STARTUPINFOA startup;
|
2011-01-21 12:02:57 +01:00
|
|
|
char *child_env;
|
2004-11-22 19:28:56 +01:00
|
|
|
int child_env_len;
|
2011-01-21 12:02:57 +01:00
|
|
|
char *ptr;
|
|
|
|
char *ptr2;
|
|
|
|
char *env;
|
2004-11-22 19:28:56 +01:00
|
|
|
int slen;
|
2003-01-13 19:28:43 +01:00
|
|
|
|
|
|
|
memset(&startup, 0, sizeof(startup));
|
|
|
|
startup.cb = sizeof(startup);
|
|
|
|
startup.dwFlags = STARTF_USESHOWWINDOW;
|
|
|
|
startup.wShowWindow = SW_SHOWNORMAL;
|
|
|
|
|
|
|
|
/* the basics */
|
|
|
|
get_file_name(resfile);
|
2015-02-26 05:18:09 +01:00
|
|
|
sprintf(buffer, "\"%s\" tests/process.c dump \"%s\"", selfname, resfile);
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
|
2003-01-13 19:28:43 +01:00
|
|
|
/* wait for child to terminate */
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
|
2003-01-13 19:28:43 +01:00
|
|
|
/* child process has changed result file, so let profile functions know about it */
|
|
|
|
WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
|
2011-01-21 12:02:57 +01:00
|
|
|
|
|
|
|
env = GetEnvironmentStringsA();
|
|
|
|
cmpEnvironment(env);
|
2003-01-13 19:28:43 +01:00
|
|
|
release_memory();
|
|
|
|
assert(DeleteFileA(resfile) != 0);
|
|
|
|
|
|
|
|
memset(&startup, 0, sizeof(startup));
|
|
|
|
startup.cb = sizeof(startup);
|
|
|
|
startup.dwFlags = STARTF_USESHOWWINDOW;
|
|
|
|
startup.wShowWindow = SW_SHOWNORMAL;
|
|
|
|
|
|
|
|
/* the basics */
|
|
|
|
get_file_name(resfile);
|
2015-02-26 05:18:09 +01:00
|
|
|
sprintf(buffer, "\"%s\" tests/process.c dump \"%s\"", selfname, resfile);
|
2011-01-21 12:02:57 +01:00
|
|
|
|
2004-11-22 19:28:56 +01:00
|
|
|
child_env_len = 0;
|
2011-01-21 12:02:57 +01:00
|
|
|
ptr = env;
|
2004-11-22 19:28:56 +01:00
|
|
|
while(*ptr)
|
|
|
|
{
|
|
|
|
slen = strlen(ptr)+1;
|
|
|
|
child_env_len += slen;
|
|
|
|
ptr += slen;
|
|
|
|
}
|
|
|
|
/* Add space for additional environment variables */
|
|
|
|
child_env_len += 256;
|
|
|
|
child_env = HeapAlloc(GetProcessHeap(), 0, child_env_len);
|
2011-01-21 12:02:57 +01:00
|
|
|
|
2003-01-13 19:28:43 +01:00
|
|
|
ptr = child_env;
|
|
|
|
sprintf(ptr, "=%c:=%s", 'C', "C:\\FOO\\BAR");
|
|
|
|
ptr += strlen(ptr) + 1;
|
|
|
|
strcpy(ptr, "PATH=C:\\WINDOWS;C:\\WINDOWS\\SYSTEM;C:\\MY\\OWN\\DIR");
|
|
|
|
ptr += strlen(ptr) + 1;
|
|
|
|
strcpy(ptr, "FOO=BAR");
|
|
|
|
ptr += strlen(ptr) + 1;
|
|
|
|
strcpy(ptr, "BAR=FOOBAR");
|
|
|
|
ptr += strlen(ptr) + 1;
|
|
|
|
/* copy all existing variables except:
|
|
|
|
* - WINELOADER
|
|
|
|
* - PATH (already set above)
|
|
|
|
* - the directory definitions (=[A-Z]:=)
|
|
|
|
*/
|
2011-01-21 12:02:57 +01:00
|
|
|
for (ptr2 = env; *ptr2; ptr2 += strlen(ptr2) + 1)
|
2003-01-13 19:28:43 +01:00
|
|
|
{
|
2011-01-21 12:02:57 +01:00
|
|
|
if (strncmp(ptr2, "PATH=", 5) != 0 &&
|
|
|
|
strncmp(ptr2, "WINELOADER=", 11) != 0 &&
|
|
|
|
!is_str_env_drive_dir(ptr2))
|
2003-01-13 19:28:43 +01:00
|
|
|
{
|
2011-01-21 12:02:57 +01:00
|
|
|
strcpy(ptr, ptr2);
|
2003-01-13 19:28:43 +01:00
|
|
|
ptr += strlen(ptr) + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*ptr = '\0';
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, child_env, NULL, &startup, &info), "CreateProcess\n");
|
2003-01-13 19:28:43 +01:00
|
|
|
/* wait for child to terminate */
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
|
2003-01-13 19:28:43 +01:00
|
|
|
/* child process has changed result file, so let profile functions know about it */
|
|
|
|
WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
|
2011-01-21 12:02:57 +01:00
|
|
|
|
2003-01-13 19:28:43 +01:00
|
|
|
cmpEnvironment(child_env);
|
|
|
|
|
2004-11-22 19:28:56 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, child_env);
|
2011-01-21 12:02:57 +01:00
|
|
|
FreeEnvironmentStringsA(env);
|
2003-01-13 19:28:43 +01:00
|
|
|
release_memory();
|
|
|
|
assert(DeleteFileA(resfile) != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_SuspendFlag(void)
|
|
|
|
{
|
|
|
|
char buffer[MAX_PATH];
|
|
|
|
PROCESS_INFORMATION info;
|
2004-07-20 03:20:50 +02:00
|
|
|
STARTUPINFOA startup, us;
|
2003-01-13 19:28:43 +01:00
|
|
|
DWORD exit_status;
|
2010-06-08 11:50:20 +02:00
|
|
|
char *result;
|
2003-01-13 19:28:43 +01:00
|
|
|
|
|
|
|
/* let's start simplistic */
|
|
|
|
memset(&startup, 0, sizeof(startup));
|
|
|
|
startup.cb = sizeof(startup);
|
|
|
|
startup.dwFlags = STARTF_USESHOWWINDOW;
|
|
|
|
startup.wShowWindow = SW_SHOWNORMAL;
|
|
|
|
|
|
|
|
get_file_name(resfile);
|
2015-02-26 05:18:09 +01:00
|
|
|
sprintf(buffer, "\"%s\" tests/process.c dump \"%s\"", selfname, resfile);
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, CREATE_SUSPENDED, NULL, NULL, &startup, &info), "CreateProcess\n");
|
2003-01-13 19:28:43 +01:00
|
|
|
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(GetExitCodeThread(info.hThread, &exit_status) && exit_status == STILL_ACTIVE, "thread still running\n");
|
2003-01-13 19:28:43 +01:00
|
|
|
Sleep(8000);
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(GetExitCodeThread(info.hThread, &exit_status) && exit_status == STILL_ACTIVE, "thread still running\n");
|
|
|
|
ok(ResumeThread(info.hThread) == 1, "Resuming thread\n");
|
2003-01-13 19:28:43 +01:00
|
|
|
|
|
|
|
/* wait for child to terminate */
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
|
2003-01-13 19:28:43 +01:00
|
|
|
/* child process has changed result file, so let profile functions know about it */
|
|
|
|
WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
|
|
|
|
|
2004-07-20 03:20:50 +02:00
|
|
|
GetStartupInfoA(&us);
|
|
|
|
|
2003-01-13 19:28:43 +01:00
|
|
|
okChildInt("StartupInfoA", "cb", startup.cb);
|
2004-07-20 03:20:50 +02:00
|
|
|
okChildString("StartupInfoA", "lpDesktop", us.lpDesktop);
|
2010-06-08 11:50:20 +02:00
|
|
|
result = getChildString( "StartupInfoA", "lpTitle" );
|
2010-06-08 11:53:58 +02:00
|
|
|
ok( broken(!result) || (result && !strCmp( result, selfname, 0 )),
|
|
|
|
"expected '%s' or null, got '%s'\n", selfname, result );
|
2003-01-13 19:28:43 +01:00
|
|
|
okChildInt("StartupInfoA", "dwX", startup.dwX);
|
|
|
|
okChildInt("StartupInfoA", "dwY", startup.dwY);
|
|
|
|
okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
|
|
|
|
okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
|
|
|
|
okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
|
|
|
|
okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
|
|
|
|
okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
|
|
|
|
okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
|
|
|
|
okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
|
|
|
|
release_memory();
|
|
|
|
assert(DeleteFileA(resfile) != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_DebuggingFlag(void)
|
|
|
|
{
|
|
|
|
char buffer[MAX_PATH];
|
2009-08-17 09:19:53 +02:00
|
|
|
void *processbase = NULL;
|
2003-01-13 19:28:43 +01:00
|
|
|
PROCESS_INFORMATION info;
|
2004-07-20 03:20:50 +02:00
|
|
|
STARTUPINFOA startup, us;
|
2003-01-13 19:28:43 +01:00
|
|
|
DEBUG_EVENT de;
|
|
|
|
unsigned dbg = 0;
|
2010-06-08 11:50:20 +02:00
|
|
|
char *result;
|
2003-01-13 19:28:43 +01:00
|
|
|
|
|
|
|
/* let's start simplistic */
|
|
|
|
memset(&startup, 0, sizeof(startup));
|
|
|
|
startup.cb = sizeof(startup);
|
|
|
|
startup.dwFlags = STARTF_USESHOWWINDOW;
|
|
|
|
startup.wShowWindow = SW_SHOWNORMAL;
|
|
|
|
|
|
|
|
get_file_name(resfile);
|
2015-02-26 05:18:09 +01:00
|
|
|
sprintf(buffer, "\"%s\" tests/process.c dump \"%s\"", selfname, resfile);
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, DEBUG_PROCESS, NULL, NULL, &startup, &info), "CreateProcess\n");
|
2003-01-13 19:28:43 +01:00
|
|
|
|
|
|
|
/* get all startup events up to the entry point break exception */
|
|
|
|
do
|
|
|
|
{
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(WaitForDebugEvent(&de, INFINITE), "reading debug event\n");
|
2003-01-13 19:28:43 +01:00
|
|
|
ContinueDebugEvent(de.dwProcessId, de.dwThreadId, DBG_CONTINUE);
|
2009-08-17 09:19:53 +02:00
|
|
|
if (!dbg)
|
|
|
|
{
|
|
|
|
ok(de.dwDebugEventCode == CREATE_PROCESS_DEBUG_EVENT,
|
|
|
|
"first event: %d\n", de.dwDebugEventCode);
|
|
|
|
processbase = de.u.CreateProcessInfo.lpBaseOfImage;
|
|
|
|
}
|
2003-01-13 19:28:43 +01:00
|
|
|
if (de.dwDebugEventCode != EXCEPTION_DEBUG_EVENT) dbg++;
|
2009-08-17 09:19:53 +02:00
|
|
|
ok(de.dwDebugEventCode != LOAD_DLL_DEBUG_EVENT ||
|
|
|
|
de.u.LoadDll.lpBaseOfDll != processbase, "got LOAD_DLL for main module\n");
|
2003-01-13 19:28:43 +01:00
|
|
|
} while (de.dwDebugEventCode != EXIT_PROCESS_DEBUG_EVENT);
|
|
|
|
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(dbg, "I have seen a debug event\n");
|
2003-01-13 19:28:43 +01:00
|
|
|
/* wait for child to terminate */
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
|
2003-01-13 19:28:43 +01:00
|
|
|
/* child process has changed result file, so let profile functions know about it */
|
|
|
|
WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
|
|
|
|
|
2004-07-20 03:20:50 +02:00
|
|
|
GetStartupInfoA(&us);
|
|
|
|
|
2003-01-13 19:28:43 +01:00
|
|
|
okChildInt("StartupInfoA", "cb", startup.cb);
|
2004-07-20 03:20:50 +02:00
|
|
|
okChildString("StartupInfoA", "lpDesktop", us.lpDesktop);
|
2010-06-08 11:50:20 +02:00
|
|
|
result = getChildString( "StartupInfoA", "lpTitle" );
|
2010-06-08 11:53:58 +02:00
|
|
|
ok( broken(!result) || (result && !strCmp( result, selfname, 0 )),
|
|
|
|
"expected '%s' or null, got '%s'\n", selfname, result );
|
2003-01-13 19:28:43 +01:00
|
|
|
okChildInt("StartupInfoA", "dwX", startup.dwX);
|
|
|
|
okChildInt("StartupInfoA", "dwY", startup.dwY);
|
|
|
|
okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
|
|
|
|
okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
|
|
|
|
okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
|
|
|
|
okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
|
|
|
|
okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
|
|
|
|
okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
|
|
|
|
okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
|
|
|
|
release_memory();
|
|
|
|
assert(DeleteFileA(resfile) != 0);
|
|
|
|
}
|
|
|
|
|
2005-06-27 11:54:09 +02:00
|
|
|
static BOOL is_console(HANDLE h)
|
|
|
|
{
|
|
|
|
return h != INVALID_HANDLE_VALUE && ((ULONG_PTR)h & 3) == 3;
|
|
|
|
}
|
|
|
|
|
2003-06-18 05:24:20 +02:00
|
|
|
static void test_Console(void)
|
|
|
|
{
|
|
|
|
char buffer[MAX_PATH];
|
|
|
|
PROCESS_INFORMATION info;
|
2004-07-20 03:20:50 +02:00
|
|
|
STARTUPINFOA startup, us;
|
2003-06-18 05:24:20 +02:00
|
|
|
SECURITY_ATTRIBUTES sa;
|
|
|
|
CONSOLE_SCREEN_BUFFER_INFO sbi, sbiC;
|
|
|
|
DWORD modeIn, modeOut, modeInC, modeOutC;
|
|
|
|
DWORD cpIn, cpOut, cpInC, cpOutC;
|
|
|
|
DWORD w;
|
|
|
|
HANDLE hChildIn, hChildInInh, hChildOut, hChildOutInh, hParentIn, hParentOut;
|
|
|
|
const char* msg = "This is a std-handle inheritance test.";
|
|
|
|
unsigned msg_len;
|
2008-09-20 12:49:41 +02:00
|
|
|
BOOL run_tests = TRUE;
|
2010-06-08 11:50:20 +02:00
|
|
|
char *result;
|
2003-06-18 05:24:20 +02:00
|
|
|
|
|
|
|
memset(&startup, 0, sizeof(startup));
|
|
|
|
startup.cb = sizeof(startup);
|
|
|
|
startup.dwFlags = STARTF_USESHOWWINDOW|STARTF_USESTDHANDLES;
|
|
|
|
startup.wShowWindow = SW_SHOWNORMAL;
|
|
|
|
|
|
|
|
sa.nLength = sizeof(sa);
|
|
|
|
sa.lpSecurityDescriptor = NULL;
|
|
|
|
sa.bInheritHandle = TRUE;
|
|
|
|
|
|
|
|
startup.hStdInput = CreateFileA("CONIN$", GENERIC_READ|GENERIC_WRITE, 0, &sa, OPEN_EXISTING, 0, 0);
|
|
|
|
startup.hStdOutput = CreateFileA("CONOUT$", GENERIC_READ|GENERIC_WRITE, 0, &sa, OPEN_EXISTING, 0, 0);
|
|
|
|
|
|
|
|
/* first, we need to be sure we're attached to a console */
|
2005-06-27 11:54:09 +02:00
|
|
|
if (!is_console(startup.hStdInput) || !is_console(startup.hStdOutput))
|
2003-06-18 05:24:20 +02:00
|
|
|
{
|
|
|
|
/* we're not attached to a console, let's do it */
|
|
|
|
AllocConsole();
|
|
|
|
startup.hStdInput = CreateFileA("CONIN$", GENERIC_READ|GENERIC_WRITE, 0, &sa, OPEN_EXISTING, 0, 0);
|
|
|
|
startup.hStdOutput = CreateFileA("CONOUT$", GENERIC_READ|GENERIC_WRITE, 0, &sa, OPEN_EXISTING, 0, 0);
|
|
|
|
}
|
|
|
|
/* now verify everything's ok */
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(startup.hStdInput != INVALID_HANDLE_VALUE, "Opening ConIn\n");
|
|
|
|
ok(startup.hStdOutput != INVALID_HANDLE_VALUE, "Opening ConOut\n");
|
2003-06-18 05:24:20 +02:00
|
|
|
startup.hStdError = startup.hStdOutput;
|
|
|
|
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(GetConsoleScreenBufferInfo(startup.hStdOutput, &sbi), "Getting sb info\n");
|
2003-06-18 05:24:20 +02:00
|
|
|
ok(GetConsoleMode(startup.hStdInput, &modeIn) &&
|
2004-02-06 06:24:34 +01:00
|
|
|
GetConsoleMode(startup.hStdOutput, &modeOut), "Getting console modes\n");
|
2003-06-18 05:24:20 +02:00
|
|
|
cpIn = GetConsoleCP();
|
|
|
|
cpOut = GetConsoleOutputCP();
|
|
|
|
|
|
|
|
get_file_name(resfile);
|
2015-02-26 05:18:09 +01:00
|
|
|
sprintf(buffer, "\"%s\" tests/process.c dump \"%s\" console", selfname, resfile);
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(CreateProcessA(NULL, buffer, NULL, NULL, TRUE, 0, NULL, NULL, &startup, &info), "CreateProcess\n");
|
2003-06-18 05:24:20 +02:00
|
|
|
|
|
|
|
/* wait for child to terminate */
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
|
2003-06-18 05:24:20 +02:00
|
|
|
/* child process has changed result file, so let profile functions know about it */
|
|
|
|
WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
|
|
|
|
|
|
|
|
/* now get the modification the child has made, and resets parents expected values */
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(GetConsoleScreenBufferInfo(startup.hStdOutput, &sbiC), "Getting sb info\n");
|
2003-06-18 05:24:20 +02:00
|
|
|
ok(GetConsoleMode(startup.hStdInput, &modeInC) &&
|
2004-02-06 06:24:34 +01:00
|
|
|
GetConsoleMode(startup.hStdOutput, &modeOutC), "Getting console modes\n");
|
2003-06-18 05:24:20 +02:00
|
|
|
|
|
|
|
SetConsoleMode(startup.hStdInput, modeIn);
|
|
|
|
SetConsoleMode(startup.hStdOutput, modeOut);
|
|
|
|
|
|
|
|
cpInC = GetConsoleCP();
|
|
|
|
cpOutC = GetConsoleOutputCP();
|
2007-05-10 19:24:11 +02:00
|
|
|
|
|
|
|
/* Try to set invalid CP */
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ok(!SetConsoleCP(0), "Shouldn't succeed\n");
|
2008-08-29 04:14:47 +02:00
|
|
|
ok(GetLastError()==ERROR_INVALID_PARAMETER ||
|
2008-09-20 12:49:41 +02:00
|
|
|
broken(GetLastError() == ERROR_CALL_NOT_IMPLEMENTED), /* win9x */
|
2007-05-10 19:24:11 +02:00
|
|
|
"GetLastError: expecting %u got %u\n",
|
|
|
|
ERROR_INVALID_PARAMETER, GetLastError());
|
2008-09-20 12:49:41 +02:00
|
|
|
if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
|
|
|
|
run_tests = FALSE;
|
|
|
|
|
2007-05-10 19:24:11 +02:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ok(!SetConsoleOutputCP(0), "Shouldn't succeed\n");
|
2008-08-29 04:14:47 +02:00
|
|
|
ok(GetLastError()==ERROR_INVALID_PARAMETER ||
|
2008-09-20 12:49:41 +02:00
|
|
|
broken(GetLastError() == ERROR_CALL_NOT_IMPLEMENTED), /* win9x */
|
2007-05-10 19:24:11 +02:00
|
|
|
"GetLastError: expecting %u got %u\n",
|
|
|
|
ERROR_INVALID_PARAMETER, GetLastError());
|
|
|
|
|
2003-06-18 05:24:20 +02:00
|
|
|
SetConsoleCP(cpIn);
|
|
|
|
SetConsoleOutputCP(cpOut);
|
|
|
|
|
2004-07-20 03:20:50 +02:00
|
|
|
GetStartupInfoA(&us);
|
|
|
|
|
2003-06-18 05:24:20 +02:00
|
|
|
okChildInt("StartupInfoA", "cb", startup.cb);
|
2004-07-20 03:20:50 +02:00
|
|
|
okChildString("StartupInfoA", "lpDesktop", us.lpDesktop);
|
2010-06-08 11:50:20 +02:00
|
|
|
result = getChildString( "StartupInfoA", "lpTitle" );
|
2010-06-08 11:53:58 +02:00
|
|
|
ok( broken(!result) || (result && !strCmp( result, selfname, 0 )),
|
|
|
|
"expected '%s' or null, got '%s'\n", selfname, result );
|
2003-06-18 05:24:20 +02:00
|
|
|
okChildInt("StartupInfoA", "dwX", startup.dwX);
|
|
|
|
okChildInt("StartupInfoA", "dwY", startup.dwY);
|
|
|
|
okChildInt("StartupInfoA", "dwXSize", startup.dwXSize);
|
|
|
|
okChildInt("StartupInfoA", "dwYSize", startup.dwYSize);
|
|
|
|
okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars);
|
|
|
|
okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars);
|
|
|
|
okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute);
|
|
|
|
okChildInt("StartupInfoA", "dwFlags", startup.dwFlags);
|
|
|
|
okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow);
|
|
|
|
|
|
|
|
/* check child correctly inherited the console */
|
2009-01-08 13:17:53 +01:00
|
|
|
okChildInt("StartupInfoA", "hStdInput", (DWORD_PTR)startup.hStdInput);
|
|
|
|
okChildInt("StartupInfoA", "hStdOutput", (DWORD_PTR)startup.hStdOutput);
|
|
|
|
okChildInt("StartupInfoA", "hStdError", (DWORD_PTR)startup.hStdError);
|
2004-08-10 01:42:19 +02:00
|
|
|
okChildInt("Console", "SizeX", (DWORD)sbi.dwSize.X);
|
|
|
|
okChildInt("Console", "SizeY", (DWORD)sbi.dwSize.Y);
|
|
|
|
okChildInt("Console", "CursorX", (DWORD)sbi.dwCursorPosition.X);
|
|
|
|
okChildInt("Console", "CursorY", (DWORD)sbi.dwCursorPosition.Y);
|
2003-06-18 05:24:20 +02:00
|
|
|
okChildInt("Console", "Attributes", sbi.wAttributes);
|
2004-08-10 01:42:19 +02:00
|
|
|
okChildInt("Console", "winLeft", (DWORD)sbi.srWindow.Left);
|
|
|
|
okChildInt("Console", "winTop", (DWORD)sbi.srWindow.Top);
|
|
|
|
okChildInt("Console", "winRight", (DWORD)sbi.srWindow.Right);
|
|
|
|
okChildInt("Console", "winBottom", (DWORD)sbi.srWindow.Bottom);
|
|
|
|
okChildInt("Console", "maxWinWidth", (DWORD)sbi.dwMaximumWindowSize.X);
|
|
|
|
okChildInt("Console", "maxWinHeight", (DWORD)sbi.dwMaximumWindowSize.Y);
|
2003-06-18 05:24:20 +02:00
|
|
|
okChildInt("Console", "InputCP", cpIn);
|
|
|
|
okChildInt("Console", "OutputCP", cpOut);
|
|
|
|
okChildInt("Console", "InputMode", modeIn);
|
|
|
|
okChildInt("Console", "OutputMode", modeOut);
|
|
|
|
|
2008-09-20 12:49:41 +02:00
|
|
|
if (run_tests)
|
|
|
|
{
|
|
|
|
ok(cpInC == 1252, "Wrong console CP (expected 1252 got %d/%d)\n", cpInC, cpIn);
|
|
|
|
ok(cpOutC == 1252, "Wrong console-SB CP (expected 1252 got %d/%d)\n", cpOutC, cpOut);
|
|
|
|
}
|
|
|
|
else
|
2008-10-07 14:07:50 +02:00
|
|
|
win_skip("Setting the codepage is not implemented\n");
|
2008-09-20 12:49:41 +02:00
|
|
|
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(modeInC == (modeIn ^ 1), "Wrong console mode\n");
|
|
|
|
ok(modeOutC == (modeOut ^ 1), "Wrong console-SB mode\n");
|
2008-05-08 00:44:48 +02:00
|
|
|
trace("cursor position(X): %d/%d\n",sbi.dwCursorPosition.X, sbiC.dwCursorPosition.X);
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(sbiC.dwCursorPosition.Y == (sbi.dwCursorPosition.Y ^ 1), "Wrong cursor position\n");
|
2003-06-18 05:24:20 +02:00
|
|
|
|
|
|
|
release_memory();
|
|
|
|
assert(DeleteFileA(resfile) != 0);
|
|
|
|
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(CreatePipe(&hParentIn, &hChildOut, NULL, 0), "Creating parent-input pipe\n");
|
2003-06-18 05:24:20 +02:00
|
|
|
ok(DuplicateHandle(GetCurrentProcess(), hChildOut, GetCurrentProcess(),
|
|
|
|
&hChildOutInh, 0, TRUE, DUPLICATE_SAME_ACCESS),
|
2004-02-06 06:24:34 +01:00
|
|
|
"Duplicating as inheritable child-output pipe\n");
|
2003-06-18 05:24:20 +02:00
|
|
|
CloseHandle(hChildOut);
|
|
|
|
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(CreatePipe(&hChildIn, &hParentOut, NULL, 0), "Creating parent-output pipe\n");
|
2003-06-18 05:24:20 +02:00
|
|
|
ok(DuplicateHandle(GetCurrentProcess(), hChildIn, GetCurrentProcess(),
|
|
|
|
&hChildInInh, 0, TRUE, DUPLICATE_SAME_ACCESS),
|
2004-02-06 06:24:34 +01:00
|
|
|
"Duplicating as inheritable child-input pipe\n");
|
2003-06-18 05:24:20 +02:00
|
|
|
CloseHandle(hChildIn);
|
|
|
|
|
|
|
|
memset(&startup, 0, sizeof(startup));
|
|
|
|
startup.cb = sizeof(startup);
|
|
|
|
startup.dwFlags = STARTF_USESHOWWINDOW|STARTF_USESTDHANDLES;
|
|
|
|
startup.wShowWindow = SW_SHOWNORMAL;
|
|
|
|
startup.hStdInput = hChildInInh;
|
|
|
|
startup.hStdOutput = hChildOutInh;
|
|
|
|
startup.hStdError = hChildOutInh;
|
|
|
|
|
|
|
|
get_file_name(resfile);
|
2015-02-26 05:18:09 +01:00
|
|
|
sprintf(buffer, "\"%s\" tests/process.c dump \"%s\" stdhandle", selfname, resfile);
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(CreateProcessA(NULL, buffer, NULL, NULL, TRUE, DETACHED_PROCESS, NULL, NULL, &startup, &info), "CreateProcess\n");
|
|
|
|
ok(CloseHandle(hChildInInh), "Closing handle\n");
|
|
|
|
ok(CloseHandle(hChildOutInh), "Closing handle\n");
|
2003-06-18 05:24:20 +02:00
|
|
|
|
|
|
|
msg_len = strlen(msg) + 1;
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(WriteFile(hParentOut, msg, msg_len, &w, NULL), "Writing to child\n");
|
2006-10-10 01:06:48 +02:00
|
|
|
ok(w == msg_len, "Should have written %u bytes, actually wrote %u\n", msg_len, w);
|
2003-06-18 05:24:20 +02:00
|
|
|
memset(buffer, 0, sizeof(buffer));
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(ReadFile(hParentIn, buffer, sizeof(buffer), &w, NULL), "Reading from child\n");
|
|
|
|
ok(strcmp(buffer, msg) == 0, "Should have received '%s'\n", msg);
|
2003-06-18 05:24:20 +02:00
|
|
|
|
|
|
|
/* wait for child to terminate */
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
|
2003-06-18 05:24:20 +02:00
|
|
|
/* child process has changed result file, so let profile functions know about it */
|
|
|
|
WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
|
|
|
|
|
|
|
|
okChildString("StdHandle", "msg", msg);
|
|
|
|
|
|
|
|
release_memory();
|
|
|
|
assert(DeleteFileA(resfile) != 0);
|
|
|
|
}
|
|
|
|
|
2003-06-26 04:05:40 +02:00
|
|
|
static void test_ExitCode(void)
|
|
|
|
{
|
|
|
|
char buffer[MAX_PATH];
|
|
|
|
PROCESS_INFORMATION info;
|
|
|
|
STARTUPINFOA startup;
|
|
|
|
DWORD code;
|
|
|
|
|
|
|
|
/* let's start simplistic */
|
|
|
|
memset(&startup, 0, sizeof(startup));
|
|
|
|
startup.cb = sizeof(startup);
|
|
|
|
startup.dwFlags = STARTF_USESHOWWINDOW;
|
|
|
|
startup.wShowWindow = SW_SHOWNORMAL;
|
|
|
|
|
|
|
|
get_file_name(resfile);
|
2015-02-26 05:18:09 +01:00
|
|
|
sprintf(buffer, "\"%s\" tests/process.c dump \"%s\" exit_code", selfname, resfile);
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0, NULL, NULL, &startup, &info), "CreateProcess\n");
|
2003-06-26 04:05:40 +02:00
|
|
|
|
|
|
|
/* wait for child to terminate */
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
|
2003-06-26 04:05:40 +02:00
|
|
|
/* child process has changed result file, so let profile functions know about it */
|
|
|
|
WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
|
|
|
|
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(GetExitCodeProcess(info.hProcess, &code), "Getting exit code\n");
|
2003-06-26 04:05:40 +02:00
|
|
|
okChildInt("ExitCode", "value", code);
|
|
|
|
|
|
|
|
release_memory();
|
|
|
|
assert(DeleteFileA(resfile) != 0);
|
|
|
|
}
|
|
|
|
|
2006-11-08 16:45:33 +01:00
|
|
|
static void test_OpenProcess(void)
|
|
|
|
{
|
|
|
|
HANDLE hproc;
|
|
|
|
void *addr1;
|
|
|
|
MEMORY_BASIC_INFORMATION info;
|
|
|
|
SIZE_T dummy, read_bytes;
|
2011-01-11 20:30:00 +01:00
|
|
|
BOOL ret;
|
2006-11-08 16:45:33 +01:00
|
|
|
|
2007-01-20 12:38:14 +01:00
|
|
|
/* not exported in all windows versions */
|
|
|
|
if ((!pVirtualAllocEx) || (!pVirtualFreeEx)) {
|
2009-02-24 00:03:07 +01:00
|
|
|
win_skip("VirtualAllocEx not found\n");
|
2007-01-20 12:38:14 +01:00
|
|
|
return;
|
|
|
|
}
|
2006-11-19 16:05:47 +01:00
|
|
|
|
2006-11-08 16:45:33 +01:00
|
|
|
/* without PROCESS_VM_OPERATION */
|
2014-02-07 15:08:48 +01:00
|
|
|
hproc = OpenProcess(PROCESS_ALL_ACCESS_NT4 & ~PROCESS_VM_OPERATION, FALSE, GetCurrentProcessId());
|
2006-11-08 16:45:33 +01:00
|
|
|
ok(hproc != NULL, "OpenProcess error %d\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2006-11-19 16:05:47 +01:00
|
|
|
addr1 = pVirtualAllocEx(hproc, 0, 0xFFFC, MEM_RESERVE, PAGE_NOACCESS);
|
2006-11-08 16:45:33 +01:00
|
|
|
ok(!addr1, "VirtualAllocEx should fail\n");
|
2007-01-06 11:44:36 +01:00
|
|
|
if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
|
|
|
|
{ /* Win9x */
|
|
|
|
CloseHandle(hproc);
|
2009-02-24 00:03:07 +01:00
|
|
|
win_skip("VirtualAllocEx not implemented\n");
|
2007-01-06 11:44:36 +01:00
|
|
|
return;
|
|
|
|
}
|
2006-11-08 16:45:33 +01:00
|
|
|
ok(GetLastError() == ERROR_ACCESS_DENIED, "wrong error %d\n", GetLastError());
|
|
|
|
|
|
|
|
read_bytes = 0xdeadbeef;
|
|
|
|
SetLastError(0xdeadbeef);
|
2011-01-11 20:30:00 +01:00
|
|
|
ret = ReadProcessMemory(hproc, test_OpenProcess, &dummy, sizeof(dummy), &read_bytes);
|
|
|
|
ok(ret, "ReadProcessMemory error %d\n", GetLastError());
|
2006-11-08 16:45:33 +01:00
|
|
|
ok(read_bytes == sizeof(dummy), "wrong read bytes %ld\n", read_bytes);
|
|
|
|
|
|
|
|
CloseHandle(hproc);
|
|
|
|
|
|
|
|
hproc = OpenProcess(PROCESS_VM_OPERATION, FALSE, GetCurrentProcessId());
|
|
|
|
ok(hproc != NULL, "OpenProcess error %d\n", GetLastError());
|
|
|
|
|
2006-11-19 16:05:47 +01:00
|
|
|
addr1 = pVirtualAllocEx(hproc, 0, 0xFFFC, MEM_RESERVE, PAGE_NOACCESS);
|
2006-11-08 16:45:33 +01:00
|
|
|
ok(addr1 != NULL, "VirtualAllocEx error %d\n", GetLastError());
|
|
|
|
|
|
|
|
/* without PROCESS_QUERY_INFORMATION */
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ok(!VirtualQueryEx(hproc, addr1, &info, sizeof(info)),
|
|
|
|
"VirtualQueryEx without PROCESS_QUERY_INFORMATION rights should fail\n");
|
|
|
|
ok(GetLastError() == ERROR_ACCESS_DENIED, "wrong error %d\n", GetLastError());
|
|
|
|
|
|
|
|
/* without PROCESS_VM_READ */
|
|
|
|
read_bytes = 0xdeadbeef;
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ok(!ReadProcessMemory(hproc, addr1, &dummy, sizeof(dummy), &read_bytes),
|
|
|
|
"ReadProcessMemory without PROCESS_VM_READ rights should fail\n");
|
|
|
|
ok(GetLastError() == ERROR_ACCESS_DENIED, "wrong error %d\n", GetLastError());
|
|
|
|
ok(read_bytes == 0, "wrong read bytes %ld\n", read_bytes);
|
|
|
|
|
|
|
|
CloseHandle(hproc);
|
|
|
|
|
|
|
|
hproc = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, GetCurrentProcessId());
|
|
|
|
|
2008-03-05 12:04:43 +01:00
|
|
|
memset(&info, 0xcc, sizeof(info));
|
2011-01-11 20:30:00 +01:00
|
|
|
read_bytes = VirtualQueryEx(hproc, addr1, &info, sizeof(info));
|
|
|
|
ok(read_bytes == sizeof(info), "VirtualQueryEx error %d\n", GetLastError());
|
2006-11-08 16:45:33 +01:00
|
|
|
|
|
|
|
ok(info.BaseAddress == addr1, "%p != %p\n", info.BaseAddress, addr1);
|
|
|
|
ok(info.AllocationBase == addr1, "%p != %p\n", info.AllocationBase, addr1);
|
|
|
|
ok(info.AllocationProtect == PAGE_NOACCESS, "%x != PAGE_NOACCESS\n", info.AllocationProtect);
|
|
|
|
ok(info.RegionSize == 0x10000, "%lx != 0x10000\n", info.RegionSize);
|
|
|
|
ok(info.State == MEM_RESERVE, "%x != MEM_RESERVE\n", info.State);
|
|
|
|
/* NT reports Protect == 0 for a not committed memory block */
|
|
|
|
ok(info.Protect == 0 /* NT */ ||
|
|
|
|
info.Protect == PAGE_NOACCESS, /* Win9x */
|
|
|
|
"%x != PAGE_NOACCESS\n", info.Protect);
|
|
|
|
ok(info.Type == MEM_PRIVATE, "%x != MEM_PRIVATE\n", info.Type);
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2006-11-19 16:05:47 +01:00
|
|
|
ok(!pVirtualFreeEx(hproc, addr1, 0, MEM_RELEASE),
|
2006-11-08 16:45:33 +01:00
|
|
|
"VirtualFreeEx without PROCESS_VM_OPERATION rights should fail\n");
|
|
|
|
ok(GetLastError() == ERROR_ACCESS_DENIED, "wrong error %d\n", GetLastError());
|
|
|
|
|
|
|
|
CloseHandle(hproc);
|
|
|
|
|
2015-08-20 05:06:38 +02:00
|
|
|
hproc = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, GetCurrentProcessId());
|
|
|
|
if (hproc)
|
|
|
|
{
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
memset(&info, 0xcc, sizeof(info));
|
|
|
|
read_bytes = VirtualQueryEx(hproc, addr1, &info, sizeof(info));
|
|
|
|
if (read_bytes) /* win8 */
|
|
|
|
{
|
|
|
|
ok(read_bytes == sizeof(info), "VirtualQueryEx error %d\n", GetLastError());
|
|
|
|
ok(info.BaseAddress == addr1, "%p != %p\n", info.BaseAddress, addr1);
|
|
|
|
ok(info.AllocationBase == addr1, "%p != %p\n", info.AllocationBase, addr1);
|
|
|
|
ok(info.AllocationProtect == PAGE_NOACCESS, "%x != PAGE_NOACCESS\n", info.AllocationProtect);
|
|
|
|
ok(info.RegionSize == 0x10000, "%lx != 0x10000\n", info.RegionSize);
|
|
|
|
ok(info.State == MEM_RESERVE, "%x != MEM_RESERVE\n", info.State);
|
|
|
|
ok(info.Protect == 0, "%x != PAGE_NOACCESS\n", info.Protect);
|
|
|
|
ok(info.Type == MEM_PRIVATE, "%x != MEM_PRIVATE\n", info.Type);
|
|
|
|
}
|
|
|
|
else /* before win8 */
|
|
|
|
ok(GetLastError() == ERROR_ACCESS_DENIED, "wrong error %d\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ok(!pVirtualFreeEx(hproc, addr1, 0, MEM_RELEASE),
|
|
|
|
"VirtualFreeEx without PROCESS_VM_OPERATION rights should fail\n");
|
|
|
|
ok(GetLastError() == ERROR_ACCESS_DENIED, "wrong error %d\n", GetLastError());
|
|
|
|
|
|
|
|
CloseHandle(hproc);
|
|
|
|
}
|
|
|
|
|
2006-11-08 16:45:33 +01:00
|
|
|
ok(VirtualFree(addr1, 0, MEM_RELEASE), "VirtualFree failed\n");
|
|
|
|
}
|
|
|
|
|
2008-10-15 16:44:54 +02:00
|
|
|
static void test_GetProcessVersion(void)
|
|
|
|
{
|
|
|
|
static char cmdline[] = "winver.exe";
|
|
|
|
PROCESS_INFORMATION pi;
|
|
|
|
STARTUPINFOA si;
|
|
|
|
DWORD ret;
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = GetProcessVersion(0);
|
|
|
|
ok(ret, "GetProcessVersion error %u\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = GetProcessVersion(GetCurrentProcessId());
|
|
|
|
ok(ret, "GetProcessVersion error %u\n", GetLastError());
|
|
|
|
|
|
|
|
memset(&si, 0, sizeof(si));
|
|
|
|
si.cb = sizeof(si);
|
|
|
|
si.dwFlags = STARTF_USESHOWWINDOW;
|
|
|
|
si.wShowWindow = SW_HIDE;
|
|
|
|
SetLastError(0xdeadbeef);
|
2013-05-29 03:39:54 +02:00
|
|
|
ret = CreateProcessA(NULL, cmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
|
2008-10-15 16:44:54 +02:00
|
|
|
ok(ret, "CreateProcess error %u\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = GetProcessVersion(pi.dwProcessId);
|
|
|
|
ok(ret, "GetProcessVersion error %u\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = TerminateProcess(pi.hProcess, 0);
|
|
|
|
ok(ret, "TerminateProcess error %u\n", GetLastError());
|
|
|
|
|
|
|
|
CloseHandle(pi.hProcess);
|
|
|
|
CloseHandle(pi.hThread);
|
|
|
|
}
|
|
|
|
|
2011-10-04 05:11:40 +02:00
|
|
|
static void test_GetProcessImageFileNameA(void)
|
|
|
|
{
|
|
|
|
DWORD rc;
|
|
|
|
CHAR process[MAX_PATH];
|
|
|
|
static const char harddisk[] = "\\Device\\HarddiskVolume";
|
|
|
|
|
|
|
|
if (!pK32GetProcessImageFileNameA)
|
|
|
|
{
|
|
|
|
win_skip("K32GetProcessImageFileNameA is unavailable\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* callers must guess the buffer size */
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
rc = pK32GetProcessImageFileNameA(GetCurrentProcess(), NULL, 0);
|
|
|
|
ok(!rc && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
|
|
|
|
"K32GetProcessImageFileNameA(no buffer): returned %u, le=%u\n", rc, GetLastError());
|
|
|
|
|
|
|
|
*process = '\0';
|
|
|
|
rc = pK32GetProcessImageFileNameA(GetCurrentProcess(), process, sizeof(process));
|
|
|
|
expect_eq_d(rc, lstrlenA(process));
|
|
|
|
if (strncmp(process, harddisk, lstrlenA(harddisk)))
|
|
|
|
{
|
|
|
|
todo_wine win_skip("%s is probably on a network share, skipping tests\n", process);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!pQueryFullProcessImageNameA)
|
|
|
|
win_skip("QueryFullProcessImageNameA unavailable (added in Windows Vista)\n");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CHAR image[MAX_PATH];
|
|
|
|
DWORD length;
|
|
|
|
|
|
|
|
length = sizeof(image);
|
|
|
|
expect_eq_d(TRUE, pQueryFullProcessImageNameA(GetCurrentProcess(), PROCESS_NAME_NATIVE, image, &length));
|
|
|
|
expect_eq_d(length, lstrlenA(image));
|
2013-10-17 04:45:27 +02:00
|
|
|
ok(lstrcmpiA(process, image) == 0, "expected '%s' to be equal to '%s'\n", process, image);
|
2011-10-04 05:11:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_QueryFullProcessImageNameA(void)
|
2009-06-10 20:39:42 +02:00
|
|
|
{
|
|
|
|
#define INIT_STR "Just some words"
|
|
|
|
DWORD length, size;
|
2011-10-04 05:11:40 +02:00
|
|
|
CHAR buf[MAX_PATH], module[MAX_PATH];
|
2009-06-10 20:39:42 +02:00
|
|
|
|
|
|
|
if (!pQueryFullProcessImageNameA)
|
|
|
|
{
|
|
|
|
win_skip("QueryFullProcessImageNameA unavailable (added in Windows Vista)\n");
|
|
|
|
return;
|
|
|
|
}
|
2011-10-04 05:11:40 +02:00
|
|
|
|
|
|
|
*module = '\0';
|
|
|
|
SetLastError(0); /* old Windows don't reset it on success */
|
|
|
|
size = GetModuleFileNameA(NULL, module, sizeof(module));
|
|
|
|
ok(size && GetLastError() != ERROR_INSUFFICIENT_BUFFER, "GetModuleFileName failed: %u le=%u\n", size, GetLastError());
|
|
|
|
|
2009-06-10 20:39:42 +02:00
|
|
|
/* get the buffer length without \0 terminator */
|
2011-10-04 05:11:40 +02:00
|
|
|
length = sizeof(buf);
|
2009-06-10 20:39:42 +02:00
|
|
|
expect_eq_d(TRUE, pQueryFullProcessImageNameA(GetCurrentProcess(), 0, buf, &length));
|
|
|
|
expect_eq_d(length, lstrlenA(buf));
|
2011-10-04 05:11:40 +02:00
|
|
|
ok((buf[0] == '\\' && buf[1] == '\\') ||
|
2013-10-17 04:45:27 +02:00
|
|
|
lstrcmpiA(buf, module) == 0, "expected %s to match %s\n", buf, module);
|
2009-06-10 20:39:42 +02:00
|
|
|
|
|
|
|
/* when the buffer is too small
|
|
|
|
* - function fail with error ERROR_INSUFFICIENT_BUFFER
|
|
|
|
* - the size variable is not modified
|
|
|
|
* tested with the biggest too small size
|
|
|
|
*/
|
|
|
|
size = length;
|
|
|
|
sprintf(buf,INIT_STR);
|
|
|
|
expect_eq_d(FALSE, pQueryFullProcessImageNameA(GetCurrentProcess(), 0, buf, &size));
|
|
|
|
expect_eq_d(ERROR_INSUFFICIENT_BUFFER, GetLastError());
|
|
|
|
expect_eq_d(length, size);
|
|
|
|
expect_eq_s(INIT_STR, buf);
|
|
|
|
|
|
|
|
/* retest with smaller buffer size
|
|
|
|
*/
|
|
|
|
size = 4;
|
|
|
|
sprintf(buf,INIT_STR);
|
|
|
|
expect_eq_d(FALSE, pQueryFullProcessImageNameA(GetCurrentProcess(), 0, buf, &size));
|
|
|
|
expect_eq_d(ERROR_INSUFFICIENT_BUFFER, GetLastError());
|
|
|
|
expect_eq_d(4, size);
|
|
|
|
expect_eq_s(INIT_STR, buf);
|
|
|
|
|
|
|
|
/* this is a difference between the ascii and the unicode version
|
2011-11-28 11:37:42 +01:00
|
|
|
* the unicode version crashes when the size is big enough to hold
|
|
|
|
* the result while the ascii version throws an error
|
2009-06-10 20:39:42 +02:00
|
|
|
*/
|
|
|
|
size = 1024;
|
|
|
|
expect_eq_d(FALSE, pQueryFullProcessImageNameA(GetCurrentProcess(), 0, NULL, &size));
|
|
|
|
expect_eq_d(1024, size);
|
|
|
|
expect_eq_d(ERROR_INVALID_PARAMETER, GetLastError());
|
|
|
|
}
|
|
|
|
|
2011-10-04 05:11:40 +02:00
|
|
|
static void test_QueryFullProcessImageNameW(void)
|
2009-03-29 23:36:33 +02:00
|
|
|
{
|
|
|
|
HANDLE hSelf;
|
2011-10-03 23:55:09 +02:00
|
|
|
WCHAR module_name[1024], device[1024];
|
2009-03-29 23:36:33 +02:00
|
|
|
WCHAR deviceW[] = {'\\','D', 'e','v','i','c','e',0};
|
|
|
|
WCHAR buf[1024];
|
2011-10-03 23:55:09 +02:00
|
|
|
DWORD size, len;
|
2009-03-29 23:36:33 +02:00
|
|
|
|
|
|
|
if (!pQueryFullProcessImageNameW)
|
|
|
|
{
|
|
|
|
win_skip("QueryFullProcessImageNameW unavailable (added in Windows Vista)\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ok(GetModuleFileNameW(NULL, module_name, 1024), "GetModuleFileNameW(NULL, ...) failed\n");
|
|
|
|
|
|
|
|
/* GetCurrentProcess pseudo-handle */
|
|
|
|
size = sizeof(buf) / sizeof(buf[0]);
|
|
|
|
expect_eq_d(TRUE, pQueryFullProcessImageNameW(GetCurrentProcess(), 0, buf, &size));
|
|
|
|
expect_eq_d(lstrlenW(buf), size);
|
|
|
|
expect_eq_ws_i(buf, module_name);
|
|
|
|
|
|
|
|
hSelf = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, GetCurrentProcessId());
|
|
|
|
/* Real handle */
|
|
|
|
size = sizeof(buf) / sizeof(buf[0]);
|
|
|
|
expect_eq_d(TRUE, pQueryFullProcessImageNameW(hSelf, 0, buf, &size));
|
|
|
|
expect_eq_d(lstrlenW(buf), size);
|
|
|
|
expect_eq_ws_i(buf, module_name);
|
|
|
|
|
|
|
|
/* Buffer too small */
|
|
|
|
size = lstrlenW(module_name)/2;
|
|
|
|
lstrcpyW(buf, deviceW);
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
expect_eq_d(FALSE, pQueryFullProcessImageNameW(hSelf, 0, buf, &size));
|
|
|
|
expect_eq_d(lstrlenW(module_name)/2, size); /* size not changed(!) */
|
|
|
|
expect_eq_d(ERROR_INSUFFICIENT_BUFFER, GetLastError());
|
|
|
|
expect_eq_ws_i(deviceW, buf); /* buffer not changed */
|
|
|
|
|
|
|
|
/* Too small - not space for NUL terminator */
|
|
|
|
size = lstrlenW(module_name);
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
expect_eq_d(FALSE, pQueryFullProcessImageNameW(hSelf, 0, buf, &size));
|
|
|
|
expect_eq_d(lstrlenW(module_name), size); /* size not changed(!) */
|
|
|
|
expect_eq_d(ERROR_INSUFFICIENT_BUFFER, GetLastError());
|
|
|
|
|
|
|
|
/* NULL buffer */
|
|
|
|
size = 0;
|
|
|
|
expect_eq_d(FALSE, pQueryFullProcessImageNameW(hSelf, 0, NULL, &size));
|
|
|
|
expect_eq_d(0, size);
|
|
|
|
expect_eq_d(ERROR_INSUFFICIENT_BUFFER, GetLastError());
|
|
|
|
|
|
|
|
/* Buffer too small */
|
|
|
|
size = lstrlenW(module_name)/2;
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
lstrcpyW(buf, module_name);
|
|
|
|
expect_eq_d(FALSE, pQueryFullProcessImageNameW(hSelf, 0, buf, &size));
|
|
|
|
expect_eq_d(lstrlenW(module_name)/2, size); /* size not changed(!) */
|
|
|
|
expect_eq_d(ERROR_INSUFFICIENT_BUFFER, GetLastError());
|
|
|
|
expect_eq_ws_i(module_name, buf); /* buffer not changed */
|
|
|
|
|
2011-10-03 23:55:09 +02:00
|
|
|
|
|
|
|
/* native path */
|
|
|
|
size = sizeof(buf) / sizeof(buf[0]);
|
|
|
|
expect_eq_d(TRUE, pQueryFullProcessImageNameW(hSelf, PROCESS_NAME_NATIVE, buf, &size));
|
|
|
|
expect_eq_d(lstrlenW(buf), size);
|
|
|
|
ok(buf[0] == '\\', "NT path should begin with '\\'\n");
|
2011-10-03 23:56:12 +02:00
|
|
|
ok(memcmp(buf, deviceW, sizeof(WCHAR)*lstrlenW(deviceW)) == 0, "NT path should begin with \\Device\n");
|
2011-10-03 23:55:09 +02:00
|
|
|
|
|
|
|
module_name[2] = '\0';
|
|
|
|
*device = '\0';
|
2011-10-08 14:21:36 +02:00
|
|
|
size = QueryDosDeviceW(module_name, device, sizeof(device)/sizeof(device[0]));
|
2011-10-03 23:55:09 +02:00
|
|
|
ok(size, "QueryDosDeviceW failed: le=%u\n", GetLastError());
|
|
|
|
len = lstrlenW(device);
|
|
|
|
ok(size >= len+2, "expected %d to be greater than %d+2 = strlen(%s)\n", size, len, wine_dbgstr_w(device));
|
|
|
|
|
|
|
|
if (size >= lstrlenW(buf))
|
|
|
|
{
|
|
|
|
ok(0, "expected %s\\ to match the start of %s\n", wine_dbgstr_w(device), wine_dbgstr_w(buf));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-10-03 23:56:12 +02:00
|
|
|
ok(buf[len] == '\\', "expected '%c' to be a '\\' in %s\n", buf[len], wine_dbgstr_w(module_name));
|
2011-10-03 23:55:09 +02:00
|
|
|
buf[len] = '\0';
|
2011-10-03 23:56:12 +02:00
|
|
|
ok(lstrcmpiW(device, buf) == 0, "expected %s to match %s\n", wine_dbgstr_w(device), wine_dbgstr_w(buf));
|
|
|
|
ok(lstrcmpiW(module_name+3, buf+len+1) == 0, "expected '%s' to match '%s'\n", wine_dbgstr_w(module_name+3), wine_dbgstr_w(buf+len+1));
|
2011-10-03 23:55:09 +02:00
|
|
|
}
|
|
|
|
|
2009-03-29 23:36:33 +02:00
|
|
|
CloseHandle(hSelf);
|
|
|
|
}
|
|
|
|
|
2008-12-08 13:39:31 +01:00
|
|
|
static void test_Handles(void)
|
|
|
|
{
|
|
|
|
HANDLE handle = GetCurrentProcess();
|
2010-05-28 11:21:44 +02:00
|
|
|
HANDLE h2, h3;
|
2008-12-08 13:39:31 +01:00
|
|
|
BOOL ret;
|
|
|
|
DWORD code;
|
|
|
|
|
2008-12-08 21:19:39 +01:00
|
|
|
ok( handle == (HANDLE)~(ULONG_PTR)0 ||
|
|
|
|
handle == (HANDLE)(ULONG_PTR)0x7fffffff /* win9x */,
|
|
|
|
"invalid current process handle %p\n", handle );
|
2008-12-08 13:39:31 +01:00
|
|
|
ret = GetExitCodeProcess( handle, &code );
|
|
|
|
ok( ret, "GetExitCodeProcess failed err %u\n", GetLastError() );
|
|
|
|
#ifdef _WIN64
|
|
|
|
/* truncated handle */
|
|
|
|
SetLastError( 0xdeadbeef );
|
|
|
|
handle = (HANDLE)((ULONG_PTR)handle & ~0u);
|
|
|
|
ret = GetExitCodeProcess( handle, &code );
|
|
|
|
ok( !ret, "GetExitCodeProcess succeeded for %p\n", handle );
|
|
|
|
ok( GetLastError() == ERROR_INVALID_HANDLE, "wrong error %u\n", GetLastError() );
|
|
|
|
/* sign-extended handle */
|
|
|
|
SetLastError( 0xdeadbeef );
|
|
|
|
handle = (HANDLE)((LONG_PTR)(int)(ULONG_PTR)handle);
|
|
|
|
ret = GetExitCodeProcess( handle, &code );
|
|
|
|
ok( ret, "GetExitCodeProcess failed err %u\n", GetLastError() );
|
|
|
|
/* invalid high-word */
|
|
|
|
SetLastError( 0xdeadbeef );
|
|
|
|
handle = (HANDLE)(((ULONG_PTR)handle & ~0u) + ((ULONG_PTR)1 << 32));
|
|
|
|
ret = GetExitCodeProcess( handle, &code );
|
|
|
|
ok( !ret, "GetExitCodeProcess succeeded for %p\n", handle );
|
|
|
|
ok( GetLastError() == ERROR_INVALID_HANDLE, "wrong error %u\n", GetLastError() );
|
|
|
|
#endif
|
2010-05-26 22:10:52 +02:00
|
|
|
|
|
|
|
handle = GetStdHandle( STD_ERROR_HANDLE );
|
|
|
|
ok( handle != 0, "handle %p\n", handle );
|
2010-05-28 11:21:44 +02:00
|
|
|
DuplicateHandle( GetCurrentProcess(), handle, GetCurrentProcess(), &h3,
|
|
|
|
0, TRUE, DUPLICATE_SAME_ACCESS );
|
|
|
|
SetStdHandle( STD_ERROR_HANDLE, h3 );
|
2010-05-26 22:10:52 +02:00
|
|
|
CloseHandle( (HANDLE)STD_ERROR_HANDLE );
|
|
|
|
h2 = GetStdHandle( STD_ERROR_HANDLE );
|
|
|
|
ok( h2 == 0 ||
|
2010-05-28 11:21:44 +02:00
|
|
|
broken( h2 == h3) || /* nt4, w2k */
|
2010-05-26 22:10:52 +02:00
|
|
|
broken( h2 == INVALID_HANDLE_VALUE), /* win9x */
|
2010-05-28 11:21:44 +02:00
|
|
|
"wrong handle %p/%p\n", h2, h3 );
|
|
|
|
SetStdHandle( STD_ERROR_HANDLE, handle );
|
2008-12-08 13:39:31 +01:00
|
|
|
}
|
|
|
|
|
2015-01-16 19:17:31 +01:00
|
|
|
static void test_IsWow64Process(void)
|
|
|
|
{
|
|
|
|
PROCESS_INFORMATION pi;
|
|
|
|
STARTUPINFOA si;
|
|
|
|
DWORD ret;
|
|
|
|
BOOL is_wow64;
|
|
|
|
static char cmdline[] = "C:\\Program Files\\Internet Explorer\\iexplore.exe";
|
|
|
|
static char cmdline_wow64[] = "C:\\Program Files (x86)\\Internet Explorer\\iexplore.exe";
|
|
|
|
|
|
|
|
if (!pIsWow64Process)
|
|
|
|
{
|
|
|
|
skip("IsWow64Process is not available\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(&si, 0, sizeof(si));
|
|
|
|
si.cb = sizeof(si);
|
|
|
|
si.dwFlags = STARTF_USESHOWWINDOW;
|
|
|
|
si.wShowWindow = SW_HIDE;
|
|
|
|
ret = CreateProcessA(NULL, cmdline_wow64, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
trace("Created process %s\n", cmdline_wow64);
|
|
|
|
is_wow64 = FALSE;
|
|
|
|
ret = pIsWow64Process(pi.hProcess, &is_wow64);
|
|
|
|
ok(ret, "IsWow64Process failed.\n");
|
|
|
|
ok(is_wow64, "is_wow64 returned FALSE.\n");
|
|
|
|
|
|
|
|
ret = TerminateProcess(pi.hProcess, 0);
|
|
|
|
ok(ret, "TerminateProcess error\n");
|
|
|
|
|
|
|
|
CloseHandle(pi.hProcess);
|
|
|
|
CloseHandle(pi.hThread);
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(&si, 0, sizeof(si));
|
|
|
|
si.cb = sizeof(si);
|
|
|
|
si.dwFlags = STARTF_USESHOWWINDOW;
|
|
|
|
si.wShowWindow = SW_HIDE;
|
|
|
|
ret = CreateProcessA(NULL, cmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
trace("Created process %s\n", cmdline);
|
|
|
|
is_wow64 = TRUE;
|
|
|
|
ret = pIsWow64Process(pi.hProcess, &is_wow64);
|
|
|
|
ok(ret, "IsWow64Process failed.\n");
|
|
|
|
ok(!is_wow64, "is_wow64 returned TRUE.\n");
|
|
|
|
|
|
|
|
ret = TerminateProcess(pi.hProcess, 0);
|
|
|
|
ok(ret, "TerminateProcess error\n");
|
|
|
|
|
|
|
|
CloseHandle(pi.hProcess);
|
|
|
|
CloseHandle(pi.hThread);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-12 22:58:34 +02:00
|
|
|
static void test_SystemInfo(void)
|
|
|
|
{
|
|
|
|
SYSTEM_INFO si, nsi;
|
|
|
|
BOOL is_wow64;
|
|
|
|
|
|
|
|
if (!pGetNativeSystemInfo)
|
|
|
|
{
|
|
|
|
win_skip("GetNativeSystemInfo is not available\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!pIsWow64Process || !pIsWow64Process( GetCurrentProcess(), &is_wow64 )) is_wow64 = FALSE;
|
|
|
|
|
|
|
|
GetSystemInfo(&si);
|
|
|
|
pGetNativeSystemInfo(&nsi);
|
|
|
|
if (is_wow64)
|
|
|
|
{
|
2010-08-31 11:49:00 +02:00
|
|
|
if (S(U(si)).wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL)
|
2010-05-12 22:58:34 +02:00
|
|
|
{
|
2010-08-31 11:49:00 +02:00
|
|
|
ok(S(U(nsi)).wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64,
|
2010-05-12 22:58:34 +02:00
|
|
|
"Expected PROCESSOR_ARCHITECTURE_AMD64, got %d\n",
|
2010-08-31 11:49:00 +02:00
|
|
|
S(U(nsi)).wProcessorArchitecture);
|
2010-05-12 22:58:34 +02:00
|
|
|
ok(nsi.dwProcessorType == PROCESSOR_AMD_X8664,
|
|
|
|
"Expected PROCESSOR_AMD_X8664, got %d\n",
|
|
|
|
nsi.dwProcessorType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-08-31 11:49:00 +02:00
|
|
|
ok(S(U(si)).wProcessorArchitecture == S(U(nsi)).wProcessorArchitecture,
|
2010-05-12 22:58:34 +02:00
|
|
|
"Expected no difference for wProcessorArchitecture, got %d and %d\n",
|
2010-08-31 11:49:00 +02:00
|
|
|
S(U(si)).wProcessorArchitecture, S(U(nsi)).wProcessorArchitecture);
|
2010-05-12 22:58:34 +02:00
|
|
|
ok(si.dwProcessorType == nsi.dwProcessorType,
|
|
|
|
"Expected no difference for dwProcessorType, got %d and %d\n",
|
|
|
|
si.dwProcessorType, nsi.dwProcessorType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-11 12:16:16 +02:00
|
|
|
static void test_RegistryQuota(void)
|
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
DWORD max_quota, used_quota;
|
|
|
|
|
|
|
|
if (!pGetSystemRegistryQuota)
|
|
|
|
{
|
|
|
|
win_skip("GetSystemRegistryQuota is not available\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = pGetSystemRegistryQuota(NULL, NULL);
|
|
|
|
ok(ret == TRUE,
|
|
|
|
"Expected GetSystemRegistryQuota to return TRUE, got %d\n", ret);
|
|
|
|
|
|
|
|
ret = pGetSystemRegistryQuota(&max_quota, NULL);
|
|
|
|
ok(ret == TRUE,
|
|
|
|
"Expected GetSystemRegistryQuota to return TRUE, got %d\n", ret);
|
|
|
|
|
|
|
|
ret = pGetSystemRegistryQuota(NULL, &used_quota);
|
|
|
|
ok(ret == TRUE,
|
|
|
|
"Expected GetSystemRegistryQuota to return TRUE, got %d\n", ret);
|
|
|
|
|
|
|
|
ret = pGetSystemRegistryQuota(&max_quota, &used_quota);
|
|
|
|
ok(ret == TRUE,
|
|
|
|
"Expected GetSystemRegistryQuota to return TRUE, got %d\n", ret);
|
|
|
|
}
|
|
|
|
|
2013-05-24 09:57:16 +02:00
|
|
|
static void test_TerminateProcess(void)
|
|
|
|
{
|
|
|
|
static char cmdline[] = "winver.exe";
|
|
|
|
PROCESS_INFORMATION pi;
|
2013-10-17 04:45:27 +02:00
|
|
|
STARTUPINFOA si;
|
2013-05-24 09:57:16 +02:00
|
|
|
DWORD ret;
|
|
|
|
HANDLE dummy, thread;
|
|
|
|
|
|
|
|
memset(&si, 0, sizeof(si));
|
|
|
|
si.cb = sizeof(si);
|
|
|
|
SetLastError(0xdeadbeef);
|
2013-10-17 04:45:27 +02:00
|
|
|
ret = CreateProcessA(NULL, cmdline, NULL, NULL, FALSE, CREATE_SUSPENDED, NULL, NULL, &si, &pi);
|
2013-05-24 09:57:16 +02:00
|
|
|
ok(ret, "CreateProcess error %u\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
thread = CreateRemoteThread(pi.hProcess, NULL, 0, (void *)0xdeadbeef, NULL, CREATE_SUSPENDED, &ret);
|
|
|
|
ok(thread != 0, "CreateRemoteThread error %d\n", GetLastError());
|
|
|
|
|
|
|
|
/* create a not closed thread handle duplicate in the target process */
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = DuplicateHandle(GetCurrentProcess(), thread, pi.hProcess, &dummy,
|
|
|
|
0, FALSE, DUPLICATE_SAME_ACCESS);
|
|
|
|
ok(ret, "DuplicateHandle error %u\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = TerminateThread(thread, 0);
|
|
|
|
ok(ret, "TerminateThread error %u\n", GetLastError());
|
|
|
|
CloseHandle(thread);
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = TerminateProcess(pi.hProcess, 0);
|
|
|
|
ok(ret, "TerminateProcess error %u\n", GetLastError());
|
|
|
|
|
|
|
|
CloseHandle(pi.hProcess);
|
|
|
|
CloseHandle(pi.hThread);
|
|
|
|
}
|
|
|
|
|
2013-06-05 11:33:29 +02:00
|
|
|
static void test_DuplicateHandle(void)
|
|
|
|
{
|
|
|
|
char path[MAX_PATH], file_name[MAX_PATH];
|
|
|
|
HANDLE f, fmin, out;
|
|
|
|
DWORD info;
|
|
|
|
BOOL r;
|
|
|
|
|
|
|
|
r = DuplicateHandle(GetCurrentProcess(), GetCurrentProcess(),
|
|
|
|
GetCurrentProcess(), &out, 0, FALSE,
|
|
|
|
DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE);
|
|
|
|
ok(r, "DuplicateHandle error %u\n", GetLastError());
|
|
|
|
r = GetHandleInformation(out, &info);
|
|
|
|
ok(r, "GetHandleInformation error %u\n", GetLastError());
|
|
|
|
ok(info == 0, "info = %x\n", info);
|
|
|
|
ok(out != GetCurrentProcess(), "out = GetCurrentProcess()\n");
|
|
|
|
CloseHandle(out);
|
|
|
|
|
|
|
|
r = DuplicateHandle(GetCurrentProcess(), GetCurrentProcess(),
|
|
|
|
GetCurrentProcess(), &out, 0, TRUE,
|
|
|
|
DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE);
|
|
|
|
ok(r, "DuplicateHandle error %u\n", GetLastError());
|
|
|
|
r = GetHandleInformation(out, &info);
|
|
|
|
ok(r, "GetHandleInformation error %u\n", GetLastError());
|
|
|
|
ok(info == HANDLE_FLAG_INHERIT, "info = %x\n", info);
|
|
|
|
ok(out != GetCurrentProcess(), "out = GetCurrentProcess()\n");
|
|
|
|
CloseHandle(out);
|
|
|
|
|
2013-10-17 04:45:27 +02:00
|
|
|
GetTempPathA(MAX_PATH, path);
|
|
|
|
GetTempFileNameA(path, "wt", 0, file_name);
|
|
|
|
f = CreateFileA(file_name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0);
|
2013-06-05 11:33:29 +02:00
|
|
|
if (f == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
ok(0, "could not create %s\n", file_name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = DuplicateHandle(GetCurrentProcess(), f, GetCurrentProcess(), &out,
|
|
|
|
0, FALSE, DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE);
|
|
|
|
ok(r, "DuplicateHandle error %u\n", GetLastError());
|
|
|
|
ok(f == out, "f != out\n");
|
|
|
|
r = GetHandleInformation(out, &info);
|
|
|
|
ok(r, "GetHandleInformation error %u\n", GetLastError());
|
|
|
|
ok(info == 0, "info = %x\n", info);
|
|
|
|
|
|
|
|
r = DuplicateHandle(GetCurrentProcess(), f, GetCurrentProcess(), &out,
|
|
|
|
0, TRUE, DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE);
|
|
|
|
ok(r, "DuplicateHandle error %u\n", GetLastError());
|
|
|
|
ok(f == out, "f != out\n");
|
|
|
|
r = GetHandleInformation(out, &info);
|
|
|
|
ok(r, "GetHandleInformation error %u\n", GetLastError());
|
|
|
|
ok(info == HANDLE_FLAG_INHERIT, "info = %x\n", info);
|
|
|
|
|
|
|
|
r = SetHandleInformation(f, HANDLE_FLAG_PROTECT_FROM_CLOSE, HANDLE_FLAG_PROTECT_FROM_CLOSE);
|
|
|
|
ok(r, "SetHandleInformation error %u\n", GetLastError());
|
|
|
|
r = DuplicateHandle(GetCurrentProcess(), f, GetCurrentProcess(), &out,
|
|
|
|
0, TRUE, DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE);
|
|
|
|
ok(r, "DuplicateHandle error %u\n", GetLastError());
|
|
|
|
ok(f != out, "f == out\n");
|
|
|
|
r = GetHandleInformation(out, &info);
|
|
|
|
ok(r, "GetHandleInformation error %u\n", GetLastError());
|
|
|
|
ok(info == HANDLE_FLAG_INHERIT, "info = %x\n", info);
|
|
|
|
r = SetHandleInformation(f, HANDLE_FLAG_PROTECT_FROM_CLOSE, 0);
|
|
|
|
ok(r, "SetHandleInformation error %u\n", GetLastError());
|
|
|
|
|
|
|
|
/* Test if DuplicateHandle allocates first free handle */
|
|
|
|
if (f > out)
|
|
|
|
{
|
|
|
|
fmin = out;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fmin = f;
|
|
|
|
f = out;
|
|
|
|
}
|
|
|
|
CloseHandle(fmin);
|
|
|
|
r = DuplicateHandle(GetCurrentProcess(), f, GetCurrentProcess(), &out,
|
|
|
|
0, TRUE, DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE);
|
|
|
|
ok(r, "DuplicateHandle error %u\n", GetLastError());
|
|
|
|
ok(f == out, "f != out\n");
|
|
|
|
CloseHandle(out);
|
2013-10-17 04:45:27 +02:00
|
|
|
DeleteFileA(file_name);
|
2013-06-05 11:33:29 +02:00
|
|
|
|
2013-10-17 04:45:27 +02:00
|
|
|
f = CreateFileA("CONIN$", GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0);
|
2013-06-05 11:33:29 +02:00
|
|
|
if (!is_console(f))
|
|
|
|
{
|
2013-06-06 10:16:43 +02:00
|
|
|
skip("DuplicateHandle on console handle\n");
|
2013-06-05 11:33:29 +02:00
|
|
|
CloseHandle(f);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = DuplicateHandle(GetCurrentProcess(), f, GetCurrentProcess(), &out,
|
|
|
|
0, FALSE, DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE);
|
|
|
|
ok(r, "DuplicateHandle error %u\n", GetLastError());
|
|
|
|
todo_wine ok(f != out, "f == out\n");
|
|
|
|
CloseHandle(out);
|
|
|
|
}
|
|
|
|
|
2015-03-28 03:24:12 +01:00
|
|
|
#define test_completion(a, b, c, d, e) _test_completion(__LINE__, a, b, c, d, e)
|
|
|
|
static void _test_completion(int line, HANDLE port, DWORD ekey, ULONG_PTR evalue, ULONG_PTR eoverlapped, DWORD wait)
|
|
|
|
{
|
|
|
|
LPOVERLAPPED overlapped;
|
|
|
|
ULONG_PTR value;
|
|
|
|
DWORD key;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
ret = GetQueuedCompletionStatus(port, &key, &value, &overlapped, wait);
|
|
|
|
|
|
|
|
ok_(__FILE__, line)(ret, "GetQueuedCompletionStatus: %x\n", GetLastError());
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
ok_(__FILE__, line)(key == ekey, "unexpected key %x\n", key);
|
|
|
|
ok_(__FILE__, line)(value == evalue, "unexpected value %p\n", (void *)value);
|
|
|
|
ok_(__FILE__, line)(overlapped == (LPOVERLAPPED)eoverlapped, "unexpected overlapped %p\n", overlapped);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-28 03:25:45 +01:00
|
|
|
#define create_process(cmd, pi) _create_process(__LINE__, cmd, pi)
|
|
|
|
static void _create_process(int line, const char *command, LPPROCESS_INFORMATION pi)
|
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
char buffer[MAX_PATH];
|
|
|
|
STARTUPINFOA si = {0};
|
|
|
|
|
2015-08-20 05:06:32 +02:00
|
|
|
sprintf(buffer, "\"%s\" tests/process.c %s", selfname, command);
|
2015-03-28 03:25:45 +01:00
|
|
|
|
|
|
|
ret = CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0, NULL, NULL, &si, pi);
|
|
|
|
ok_(__FILE__, line)(ret, "CreateProcess error %u\n", GetLastError());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void test_IsProcessInJob(void)
|
|
|
|
{
|
2015-04-01 03:48:34 +02:00
|
|
|
HANDLE job, job2;
|
2015-03-28 03:25:45 +01:00
|
|
|
PROCESS_INFORMATION pi;
|
|
|
|
BOOL ret, out;
|
|
|
|
DWORD dwret;
|
|
|
|
|
|
|
|
if (!pIsProcessInJob)
|
|
|
|
{
|
|
|
|
win_skip("IsProcessInJob not available.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
job = pCreateJobObjectW(NULL, NULL);
|
|
|
|
ok(job != NULL, "CreateJobObject error %u\n", GetLastError());
|
|
|
|
|
2015-04-01 03:48:34 +02:00
|
|
|
job2 = pCreateJobObjectW(NULL, NULL);
|
|
|
|
ok(job2 != NULL, "CreateJobObject error %u\n", GetLastError());
|
|
|
|
|
2015-03-28 03:25:45 +01:00
|
|
|
create_process("wait", &pi);
|
|
|
|
|
|
|
|
out = TRUE;
|
|
|
|
ret = pIsProcessInJob(pi.hProcess, job, &out);
|
|
|
|
ok(ret, "IsProcessInJob error %u\n", GetLastError());
|
|
|
|
ok(!out, "IsProcessInJob returned out=%u\n", out);
|
|
|
|
|
2015-04-01 03:48:34 +02:00
|
|
|
out = TRUE;
|
|
|
|
ret = pIsProcessInJob(pi.hProcess, job2, &out);
|
|
|
|
ok(ret, "IsProcessInJob error %u\n", GetLastError());
|
|
|
|
ok(!out, "IsProcessInJob returned out=%u\n", out);
|
|
|
|
|
|
|
|
out = TRUE;
|
|
|
|
ret = pIsProcessInJob(pi.hProcess, NULL, &out);
|
|
|
|
ok(ret, "IsProcessInJob error %u\n", GetLastError());
|
|
|
|
ok(!out, "IsProcessInJob returned out=%u\n", out);
|
|
|
|
|
2015-03-28 03:25:45 +01:00
|
|
|
ret = pAssignProcessToJobObject(job, pi.hProcess);
|
|
|
|
ok(ret, "AssignProcessToJobObject error %u\n", GetLastError());
|
|
|
|
|
|
|
|
out = FALSE;
|
|
|
|
ret = pIsProcessInJob(pi.hProcess, job, &out);
|
|
|
|
ok(ret, "IsProcessInJob error %u\n", GetLastError());
|
|
|
|
ok(out, "IsProcessInJob returned out=%u\n", out);
|
|
|
|
|
2015-04-01 03:48:34 +02:00
|
|
|
out = TRUE;
|
|
|
|
ret = pIsProcessInJob(pi.hProcess, job2, &out);
|
|
|
|
ok(ret, "IsProcessInJob error %u\n", GetLastError());
|
|
|
|
ok(!out, "IsProcessInJob returned out=%u\n", out);
|
|
|
|
|
|
|
|
out = FALSE;
|
|
|
|
ret = pIsProcessInJob(pi.hProcess, NULL, &out);
|
|
|
|
ok(ret, "IsProcessInJob error %u\n", GetLastError());
|
|
|
|
ok(out, "IsProcessInJob returned out=%u\n", out);
|
|
|
|
|
2015-03-28 03:25:45 +01:00
|
|
|
TerminateProcess(pi.hProcess, 0);
|
|
|
|
|
|
|
|
dwret = WaitForSingleObject(pi.hProcess, 1000);
|
|
|
|
ok(dwret == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", dwret);
|
|
|
|
|
|
|
|
out = FALSE;
|
|
|
|
ret = pIsProcessInJob(pi.hProcess, job, &out);
|
|
|
|
ok(ret, "IsProcessInJob error %u\n", GetLastError());
|
|
|
|
ok(out, "IsProcessInJob returned out=%u\n", out);
|
|
|
|
|
|
|
|
CloseHandle(pi.hProcess);
|
|
|
|
CloseHandle(pi.hThread);
|
|
|
|
CloseHandle(job);
|
2015-04-01 03:48:34 +02:00
|
|
|
CloseHandle(job2);
|
2015-03-28 03:25:45 +01:00
|
|
|
}
|
|
|
|
|
2015-03-28 03:23:28 +01:00
|
|
|
static void test_TerminateJobObject(void)
|
|
|
|
{
|
|
|
|
HANDLE job;
|
|
|
|
PROCESS_INFORMATION pi;
|
|
|
|
BOOL ret;
|
|
|
|
DWORD dwret;
|
|
|
|
|
|
|
|
job = pCreateJobObjectW(NULL, NULL);
|
|
|
|
ok(job != NULL, "CreateJobObject error %u\n", GetLastError());
|
|
|
|
|
|
|
|
create_process("wait", &pi);
|
|
|
|
|
|
|
|
ret = pAssignProcessToJobObject(job, pi.hProcess);
|
|
|
|
ok(ret, "AssignProcessToJobObject error %u\n", GetLastError());
|
|
|
|
|
|
|
|
ret = pTerminateJobObject(job, 123);
|
|
|
|
ok(ret, "TerminateJobObject error %u\n", GetLastError());
|
|
|
|
|
|
|
|
dwret = WaitForSingleObject(pi.hProcess, 1000);
|
|
|
|
ok(dwret == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", dwret);
|
|
|
|
if (dwret == WAIT_TIMEOUT) TerminateProcess(pi.hProcess, 0);
|
|
|
|
|
|
|
|
ret = GetExitCodeProcess(pi.hProcess, &dwret);
|
|
|
|
ok(ret, "GetExitCodeProcess error %u\n", GetLastError());
|
|
|
|
ok(dwret == 123 || broken(dwret == 0) /* randomly fails on Win 2000 / XP */,
|
|
|
|
"wrong exitcode %u\n", dwret);
|
|
|
|
|
|
|
|
CloseHandle(pi.hProcess);
|
|
|
|
CloseHandle(pi.hThread);
|
2015-02-28 06:34:24 +01:00
|
|
|
|
|
|
|
/* Test adding an already terminated process to a job object */
|
|
|
|
create_process("exit", &pi);
|
|
|
|
|
|
|
|
dwret = WaitForSingleObject(pi.hProcess, 1000);
|
|
|
|
ok(dwret == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", dwret);
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = pAssignProcessToJobObject(job, pi.hProcess);
|
|
|
|
ok(!ret, "AssignProcessToJobObject unexpectedly succeeded\n");
|
|
|
|
expect_eq_d(ERROR_ACCESS_DENIED, GetLastError());
|
|
|
|
|
|
|
|
CloseHandle(pi.hProcess);
|
|
|
|
CloseHandle(pi.hThread);
|
|
|
|
|
2015-03-28 03:23:28 +01:00
|
|
|
CloseHandle(job);
|
|
|
|
}
|
|
|
|
|
2015-03-28 03:23:51 +01:00
|
|
|
static void test_QueryInformationJobObject(void)
|
|
|
|
{
|
2015-08-20 05:06:32 +02:00
|
|
|
char buf[sizeof(JOBOBJECT_BASIC_PROCESS_ID_LIST) + sizeof(ULONG_PTR) * 4];
|
2015-03-28 03:23:51 +01:00
|
|
|
PJOBOBJECT_BASIC_PROCESS_ID_LIST pid_list = (JOBOBJECT_BASIC_PROCESS_ID_LIST *)buf;
|
2015-07-31 07:49:04 +02:00
|
|
|
JOBOBJECT_EXTENDED_LIMIT_INFORMATION ext_limit_info;
|
|
|
|
JOBOBJECT_BASIC_LIMIT_INFORMATION *basic_limit_info = &ext_limit_info.BasicLimitInformation;
|
2015-03-28 03:23:51 +01:00
|
|
|
DWORD dwret, ret_len;
|
|
|
|
PROCESS_INFORMATION pi[2];
|
|
|
|
HANDLE job;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
job = pCreateJobObjectW(NULL, NULL);
|
|
|
|
ok(job != NULL, "CreateJobObject error %u\n", GetLastError());
|
|
|
|
|
|
|
|
/* Only active processes are returned */
|
|
|
|
create_process("exit", &pi[0]);
|
|
|
|
ret = pAssignProcessToJobObject(job, pi[0].hProcess);
|
|
|
|
ok(ret, "AssignProcessToJobObject error %u\n", GetLastError());
|
|
|
|
dwret = WaitForSingleObject(pi[0].hProcess, 1000);
|
|
|
|
ok(dwret == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", dwret);
|
|
|
|
|
|
|
|
CloseHandle(pi[0].hProcess);
|
|
|
|
CloseHandle(pi[0].hThread);
|
|
|
|
|
|
|
|
create_process("wait", &pi[0]);
|
|
|
|
ret = pAssignProcessToJobObject(job, pi[0].hProcess);
|
|
|
|
ok(ret, "AssignProcessToJobObject error %u\n", GetLastError());
|
|
|
|
|
|
|
|
create_process("wait", &pi[1]);
|
|
|
|
ret = pAssignProcessToJobObject(job, pi[1].hProcess);
|
|
|
|
ok(ret, "AssignProcessToJobObject error %u\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = QueryInformationJobObject(job, JobObjectBasicProcessIdList, pid_list,
|
|
|
|
FIELD_OFFSET(JOBOBJECT_BASIC_PROCESS_ID_LIST, ProcessIdList), &ret_len);
|
|
|
|
ok(!ret, "QueryInformationJobObject expected failure\n");
|
|
|
|
todo_wine
|
|
|
|
expect_eq_d(ERROR_BAD_LENGTH, GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
memset(buf, 0, sizeof(buf));
|
|
|
|
pid_list->NumberOfAssignedProcesses = 42;
|
|
|
|
pid_list->NumberOfProcessIdsInList = 42;
|
|
|
|
ret = QueryInformationJobObject(job, JobObjectBasicProcessIdList, pid_list,
|
|
|
|
FIELD_OFFSET(JOBOBJECT_BASIC_PROCESS_ID_LIST, ProcessIdList[1]), &ret_len);
|
|
|
|
ok(!ret, "QueryInformationJobObject expected failure\n");
|
|
|
|
todo_wine
|
|
|
|
expect_eq_d(ERROR_MORE_DATA, GetLastError());
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
expect_eq_d(42, pid_list->NumberOfAssignedProcesses);
|
|
|
|
expect_eq_d(42, pid_list->NumberOfProcessIdsInList);
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(buf, 0, sizeof(buf));
|
|
|
|
ret = pQueryInformationJobObject(job, JobObjectBasicProcessIdList, pid_list, sizeof(buf), &ret_len);
|
|
|
|
todo_wine
|
|
|
|
ok(ret, "QueryInformationJobObject error %u\n", GetLastError());
|
|
|
|
if(ret)
|
|
|
|
{
|
|
|
|
if (pid_list->NumberOfAssignedProcesses == 3) /* Win 8 */
|
|
|
|
win_skip("Number of assigned processes broken on Win 8\n");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ULONG_PTR *list = pid_list->ProcessIdList;
|
|
|
|
|
|
|
|
ok(ret_len == FIELD_OFFSET(JOBOBJECT_BASIC_PROCESS_ID_LIST, ProcessIdList[2]),
|
|
|
|
"QueryInformationJobObject returned ret_len=%u\n", ret_len);
|
|
|
|
|
|
|
|
expect_eq_d(2, pid_list->NumberOfAssignedProcesses);
|
|
|
|
expect_eq_d(2, pid_list->NumberOfProcessIdsInList);
|
|
|
|
expect_eq_d(pi[0].dwProcessId, list[0]);
|
|
|
|
expect_eq_d(pi[1].dwProcessId, list[1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-31 07:49:04 +02:00
|
|
|
/* test JobObjectBasicLimitInformation */
|
|
|
|
ret = pQueryInformationJobObject(job, JobObjectBasicLimitInformation, basic_limit_info,
|
|
|
|
sizeof(*basic_limit_info) - 1, &ret_len);
|
|
|
|
ok(!ret, "QueryInformationJobObject expected failure\n");
|
|
|
|
expect_eq_d(ERROR_BAD_LENGTH, GetLastError());
|
|
|
|
|
|
|
|
ret_len = 0xdeadbeef;
|
|
|
|
memset(basic_limit_info, 0x11, sizeof(*basic_limit_info));
|
|
|
|
ret = pQueryInformationJobObject(job, JobObjectBasicLimitInformation, basic_limit_info,
|
|
|
|
sizeof(*basic_limit_info), &ret_len);
|
|
|
|
ok(ret, "QueryInformationJobObject error %u\n", GetLastError());
|
|
|
|
ok(ret_len == sizeof(*basic_limit_info), "QueryInformationJobObject returned ret_len=%u\n", ret_len);
|
|
|
|
expect_eq_d(0, basic_limit_info->LimitFlags);
|
|
|
|
|
|
|
|
/* test JobObjectExtendedLimitInformation */
|
|
|
|
ret = pQueryInformationJobObject(job, JobObjectExtendedLimitInformation, &ext_limit_info,
|
|
|
|
sizeof(ext_limit_info) - 1, &ret_len);
|
|
|
|
ok(!ret, "QueryInformationJobObject expected failure\n");
|
|
|
|
expect_eq_d(ERROR_BAD_LENGTH, GetLastError());
|
|
|
|
|
|
|
|
ret_len = 0xdeadbeef;
|
|
|
|
memset(&ext_limit_info, 0x11, sizeof(ext_limit_info));
|
|
|
|
ret = pQueryInformationJobObject(job, JobObjectExtendedLimitInformation, &ext_limit_info,
|
|
|
|
sizeof(ext_limit_info), &ret_len);
|
|
|
|
ok(ret, "QueryInformationJobObject error %u\n", GetLastError());
|
|
|
|
ok(ret_len == sizeof(ext_limit_info), "QueryInformationJobObject returned ret_len=%u\n", ret_len);
|
|
|
|
expect_eq_d(0, basic_limit_info->LimitFlags);
|
|
|
|
|
2015-03-28 03:23:51 +01:00
|
|
|
TerminateProcess(pi[0].hProcess, 0);
|
|
|
|
CloseHandle(pi[0].hProcess);
|
|
|
|
CloseHandle(pi[0].hThread);
|
|
|
|
|
|
|
|
TerminateProcess(pi[1].hProcess, 0);
|
|
|
|
CloseHandle(pi[1].hProcess);
|
|
|
|
CloseHandle(pi[1].hThread);
|
|
|
|
|
|
|
|
CloseHandle(job);
|
|
|
|
}
|
|
|
|
|
2015-03-28 03:24:12 +01:00
|
|
|
static void test_CompletionPort(void)
|
|
|
|
{
|
|
|
|
JOBOBJECT_ASSOCIATE_COMPLETION_PORT port_info;
|
|
|
|
PROCESS_INFORMATION pi;
|
|
|
|
HANDLE job, port;
|
|
|
|
DWORD dwret;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
job = pCreateJobObjectW(NULL, NULL);
|
|
|
|
ok(job != NULL, "CreateJobObject error %u\n", GetLastError());
|
|
|
|
|
|
|
|
port = pCreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, 0, 1);
|
|
|
|
ok(port != NULL, "CreateIoCompletionPort error %u\n", GetLastError());
|
|
|
|
|
|
|
|
port_info.CompletionKey = job;
|
|
|
|
port_info.CompletionPort = port;
|
|
|
|
ret = pSetInformationJobObject(job, JobObjectAssociateCompletionPortInformation, &port_info, sizeof(port_info));
|
|
|
|
ok(ret, "SetInformationJobObject error %u\n", GetLastError());
|
|
|
|
|
|
|
|
create_process("wait", &pi);
|
|
|
|
|
|
|
|
ret = pAssignProcessToJobObject(job, pi.hProcess);
|
|
|
|
ok(ret, "AssignProcessToJobObject error %u\n", GetLastError());
|
|
|
|
|
|
|
|
test_completion(port, JOB_OBJECT_MSG_NEW_PROCESS, (DWORD_PTR)job, pi.dwProcessId, 0);
|
|
|
|
|
|
|
|
TerminateProcess(pi.hProcess, 0);
|
|
|
|
dwret = WaitForSingleObject(pi.hProcess, 1000);
|
|
|
|
ok(dwret == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", dwret);
|
|
|
|
|
|
|
|
test_completion(port, JOB_OBJECT_MSG_EXIT_PROCESS, (DWORD_PTR)job, pi.dwProcessId, 0);
|
|
|
|
test_completion(port, JOB_OBJECT_MSG_ACTIVE_PROCESS_ZERO, (DWORD_PTR)job, 0, 100);
|
|
|
|
|
|
|
|
CloseHandle(pi.hProcess);
|
|
|
|
CloseHandle(pi.hThread);
|
|
|
|
CloseHandle(job);
|
|
|
|
CloseHandle(port);
|
|
|
|
}
|
|
|
|
|
2015-03-28 03:24:30 +01:00
|
|
|
static void test_KillOnJobClose(void)
|
|
|
|
{
|
|
|
|
JOBOBJECT_EXTENDED_LIMIT_INFORMATION limit_info;
|
|
|
|
PROCESS_INFORMATION pi;
|
|
|
|
DWORD dwret;
|
|
|
|
HANDLE job;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
job = pCreateJobObjectW(NULL, NULL);
|
|
|
|
ok(job != NULL, "CreateJobObject error %u\n", GetLastError());
|
|
|
|
|
|
|
|
limit_info.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE;
|
|
|
|
ret = pSetInformationJobObject(job, JobObjectExtendedLimitInformation, &limit_info, sizeof(limit_info));
|
|
|
|
if (!ret && GetLastError() == ERROR_INVALID_PARAMETER)
|
|
|
|
{
|
|
|
|
win_skip("Kill on job close limit not available\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ok(ret, "SetInformationJobObject error %u\n", GetLastError());
|
|
|
|
|
|
|
|
create_process("wait", &pi);
|
|
|
|
|
|
|
|
ret = pAssignProcessToJobObject(job, pi.hProcess);
|
|
|
|
ok(ret, "AssignProcessToJobObject error %u\n", GetLastError());
|
|
|
|
|
|
|
|
CloseHandle(job);
|
|
|
|
|
|
|
|
dwret = WaitForSingleObject(pi.hProcess, 1000);
|
|
|
|
ok(dwret == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", dwret);
|
|
|
|
if (dwret == WAIT_TIMEOUT) TerminateProcess(pi.hProcess, 0);
|
|
|
|
|
|
|
|
CloseHandle(pi.hProcess);
|
|
|
|
CloseHandle(pi.hThread);
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:20:05 +02:00
|
|
|
static void test_WaitForJobObject(void)
|
|
|
|
{
|
|
|
|
HANDLE job;
|
|
|
|
PROCESS_INFORMATION pi;
|
|
|
|
BOOL ret;
|
|
|
|
DWORD dwret;
|
|
|
|
|
|
|
|
/* test waiting for a job object when the process is killed */
|
|
|
|
job = pCreateJobObjectW(NULL, NULL);
|
|
|
|
ok(job != NULL, "CreateJobObject error %u\n", GetLastError());
|
|
|
|
|
|
|
|
dwret = WaitForSingleObject(job, 100);
|
|
|
|
ok(dwret == WAIT_TIMEOUT, "WaitForSingleObject returned %u\n", dwret);
|
|
|
|
|
|
|
|
create_process("wait", &pi);
|
|
|
|
|
|
|
|
ret = pAssignProcessToJobObject(job, pi.hProcess);
|
|
|
|
ok(ret, "AssignProcessToJobObject error %u\n", GetLastError());
|
|
|
|
|
|
|
|
dwret = WaitForSingleObject(job, 100);
|
|
|
|
ok(dwret == WAIT_TIMEOUT, "WaitForSingleObject returned %u\n", dwret);
|
|
|
|
|
|
|
|
ret = pTerminateJobObject(job, 123);
|
|
|
|
ok(ret, "TerminateJobObject error %u\n", GetLastError());
|
|
|
|
|
|
|
|
dwret = WaitForSingleObject(job, 500);
|
|
|
|
ok(dwret == WAIT_OBJECT_0 || broken(dwret == WAIT_TIMEOUT),
|
|
|
|
"WaitForSingleObject returned %u\n", dwret);
|
|
|
|
|
|
|
|
if (dwret == WAIT_TIMEOUT) /* Win 2000/XP */
|
|
|
|
{
|
|
|
|
CloseHandle(pi.hProcess);
|
|
|
|
CloseHandle(pi.hThread);
|
|
|
|
CloseHandle(job);
|
|
|
|
win_skip("TerminateJobObject doesn't signal job, skipping tests\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* the object is not reset immediately */
|
|
|
|
dwret = WaitForSingleObject(job, 100);
|
|
|
|
ok(dwret == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", dwret);
|
|
|
|
|
|
|
|
CloseHandle(pi.hProcess);
|
|
|
|
CloseHandle(pi.hThread);
|
|
|
|
|
|
|
|
/* creating a new process doesn't reset the signalled state */
|
|
|
|
create_process("wait", &pi);
|
|
|
|
|
|
|
|
ret = pAssignProcessToJobObject(job, pi.hProcess);
|
|
|
|
ok(ret, "AssignProcessToJobObject error %u\n", GetLastError());
|
|
|
|
|
|
|
|
dwret = WaitForSingleObject(job, 100);
|
|
|
|
ok(dwret == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", dwret);
|
|
|
|
|
|
|
|
ret = pTerminateJobObject(job, 123);
|
|
|
|
ok(ret, "TerminateJobObject error %u\n", GetLastError());
|
|
|
|
|
|
|
|
CloseHandle(pi.hProcess);
|
|
|
|
CloseHandle(pi.hThread);
|
|
|
|
|
|
|
|
CloseHandle(job);
|
|
|
|
|
|
|
|
/* repeat the test, but this time the process terminates properly */
|
|
|
|
job = pCreateJobObjectW(NULL, NULL);
|
|
|
|
ok(job != NULL, "CreateJobObject error %u\n", GetLastError());
|
|
|
|
|
|
|
|
dwret = WaitForSingleObject(job, 100);
|
|
|
|
ok(dwret == WAIT_TIMEOUT, "WaitForSingleObject returned %u\n", dwret);
|
|
|
|
|
|
|
|
create_process("exit", &pi);
|
|
|
|
|
|
|
|
ret = pAssignProcessToJobObject(job, pi.hProcess);
|
|
|
|
ok(ret, "AssignProcessToJobObject error %u\n", GetLastError());
|
|
|
|
|
|
|
|
dwret = WaitForSingleObject(job, 100);
|
|
|
|
ok(dwret == WAIT_TIMEOUT, "WaitForSingleObject returned %u\n", dwret);
|
|
|
|
|
|
|
|
CloseHandle(pi.hProcess);
|
|
|
|
CloseHandle(pi.hThread);
|
|
|
|
CloseHandle(job);
|
|
|
|
}
|
|
|
|
|
2015-03-28 03:24:48 +01:00
|
|
|
static HANDLE test_AddSelfToJob(void)
|
|
|
|
{
|
|
|
|
HANDLE job;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
job = pCreateJobObjectW(NULL, NULL);
|
|
|
|
ok(job != NULL, "CreateJobObject error %u\n", GetLastError());
|
|
|
|
|
|
|
|
ret = pAssignProcessToJobObject(job, GetCurrentProcess());
|
|
|
|
ok(ret, "AssignProcessToJobObject error %u\n", GetLastError());
|
|
|
|
|
|
|
|
return job;
|
|
|
|
}
|
|
|
|
|
2015-03-28 03:26:30 +01:00
|
|
|
static void test_jobInheritance(HANDLE job)
|
|
|
|
{
|
|
|
|
char buffer[MAX_PATH];
|
|
|
|
PROCESS_INFORMATION pi;
|
|
|
|
STARTUPINFOA si = {0};
|
|
|
|
DWORD dwret;
|
|
|
|
BOOL ret, out;
|
|
|
|
|
|
|
|
if (!pIsProcessInJob)
|
|
|
|
{
|
|
|
|
win_skip("IsProcessInJob not available.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-08-20 05:06:32 +02:00
|
|
|
sprintf(buffer, "\"%s\" tests/process.c %s", selfname, "exit");
|
2015-03-28 03:26:30 +01:00
|
|
|
|
|
|
|
ret = CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
|
|
|
|
ok(ret, "CreateProcessA error %u\n", GetLastError());
|
|
|
|
|
|
|
|
out = FALSE;
|
|
|
|
ret = pIsProcessInJob(pi.hProcess, job, &out);
|
|
|
|
ok(ret, "IsProcessInJob error %u\n", GetLastError());
|
|
|
|
ok(out, "IsProcessInJob returned out=%u\n", out);
|
|
|
|
|
|
|
|
dwret = WaitForSingleObject(pi.hProcess, 1000);
|
|
|
|
ok(dwret == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", dwret);
|
|
|
|
|
|
|
|
CloseHandle(pi.hProcess);
|
|
|
|
CloseHandle(pi.hThread);
|
|
|
|
}
|
|
|
|
|
2015-03-28 03:24:48 +01:00
|
|
|
static void test_BreakawayOk(HANDLE job)
|
|
|
|
{
|
|
|
|
JOBOBJECT_EXTENDED_LIMIT_INFORMATION limit_info;
|
|
|
|
PROCESS_INFORMATION pi;
|
|
|
|
STARTUPINFOA si = {0};
|
|
|
|
char buffer[MAX_PATH];
|
|
|
|
BOOL ret, out;
|
|
|
|
DWORD dwret;
|
|
|
|
|
|
|
|
if (!pIsProcessInJob)
|
|
|
|
{
|
|
|
|
win_skip("IsProcessInJob not available.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-08-20 05:06:32 +02:00
|
|
|
sprintf(buffer, "\"%s\" tests/process.c %s", selfname, "exit");
|
2015-03-28 03:24:48 +01:00
|
|
|
|
|
|
|
ret = CreateProcessA(NULL, buffer, NULL, NULL, FALSE, CREATE_BREAKAWAY_FROM_JOB, NULL, NULL, &si, &pi);
|
|
|
|
ok(!ret, "CreateProcessA expected failure\n");
|
|
|
|
expect_eq_d(ERROR_ACCESS_DENIED, GetLastError());
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
TerminateProcess(pi.hProcess, 0);
|
|
|
|
|
|
|
|
dwret = WaitForSingleObject(pi.hProcess, 1000);
|
|
|
|
ok(dwret == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", dwret);
|
|
|
|
|
|
|
|
CloseHandle(pi.hProcess);
|
|
|
|
CloseHandle(pi.hThread);
|
|
|
|
}
|
|
|
|
|
|
|
|
limit_info.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_BREAKAWAY_OK;
|
|
|
|
ret = pSetInformationJobObject(job, JobObjectExtendedLimitInformation, &limit_info, sizeof(limit_info));
|
|
|
|
ok(ret, "SetInformationJobObject error %u\n", GetLastError());
|
|
|
|
|
|
|
|
ret = CreateProcessA(NULL, buffer, NULL, NULL, FALSE, CREATE_BREAKAWAY_FROM_JOB, NULL, NULL, &si, &pi);
|
|
|
|
ok(ret, "CreateProcessA error %u\n", GetLastError());
|
|
|
|
|
|
|
|
ret = pIsProcessInJob(pi.hProcess, job, &out);
|
|
|
|
ok(ret, "IsProcessInJob error %u\n", GetLastError());
|
|
|
|
ok(!out, "IsProcessInJob returned out=%u\n", out);
|
|
|
|
|
|
|
|
dwret = WaitForSingleObject(pi.hProcess, 1000);
|
|
|
|
ok(dwret == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", dwret);
|
|
|
|
|
|
|
|
CloseHandle(pi.hProcess);
|
|
|
|
CloseHandle(pi.hThread);
|
|
|
|
|
|
|
|
limit_info.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_SILENT_BREAKAWAY_OK;
|
|
|
|
ret = pSetInformationJobObject(job, JobObjectExtendedLimitInformation, &limit_info, sizeof(limit_info));
|
|
|
|
ok(ret, "SetInformationJobObject error %u\n", GetLastError());
|
|
|
|
|
|
|
|
ret = CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
|
|
|
|
ok(ret, "CreateProcess error %u\n", GetLastError());
|
|
|
|
|
|
|
|
ret = pIsProcessInJob(pi.hProcess, job, &out);
|
|
|
|
ok(ret, "IsProcessInJob error %u\n", GetLastError());
|
|
|
|
ok(!out, "IsProcessInJob returned out=%u\n", out);
|
|
|
|
|
|
|
|
dwret = WaitForSingleObject(pi.hProcess, 1000);
|
|
|
|
ok(dwret == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", dwret);
|
|
|
|
|
|
|
|
CloseHandle(pi.hProcess);
|
|
|
|
CloseHandle(pi.hThread);
|
|
|
|
|
|
|
|
/* unset breakaway ok */
|
|
|
|
limit_info.BasicLimitInformation.LimitFlags = 0;
|
|
|
|
ret = pSetInformationJobObject(job, JobObjectExtendedLimitInformation, &limit_info, sizeof(limit_info));
|
|
|
|
ok(ret, "SetInformationJobObject error %u\n", GetLastError());
|
|
|
|
}
|
|
|
|
|
2015-04-25 10:03:36 +02:00
|
|
|
static void test_StartupNoConsole(void)
|
2015-01-04 07:37:42 +01:00
|
|
|
{
|
|
|
|
#ifndef _WIN64
|
|
|
|
char buffer[MAX_PATH];
|
|
|
|
STARTUPINFOA startup;
|
|
|
|
PROCESS_INFORMATION info;
|
|
|
|
|
|
|
|
if (!pNtCurrentTeb)
|
|
|
|
{
|
|
|
|
win_skip( "NtCurrentTeb not supported\n" );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(&startup, 0, sizeof(startup));
|
|
|
|
startup.cb = sizeof(startup);
|
|
|
|
startup.dwFlags = STARTF_USESHOWWINDOW;
|
|
|
|
startup.wShowWindow = SW_SHOWNORMAL;
|
|
|
|
get_file_name(resfile);
|
|
|
|
sprintf(buffer, "\"%s\" tests/process.c dump \"%s\"", selfname, resfile);
|
|
|
|
ok(CreateProcessA(NULL, buffer, NULL, NULL, TRUE, DETACHED_PROCESS, NULL, NULL, &startup,
|
|
|
|
&info), "CreateProcess\n");
|
|
|
|
ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
|
|
|
|
WritePrivateProfileStringA(NULL, NULL, NULL, resfile);
|
|
|
|
okChildInt("StartupInfoA", "hStdInput", (UINT)INVALID_HANDLE_VALUE);
|
|
|
|
okChildInt("StartupInfoA", "hStdOutput", (UINT)INVALID_HANDLE_VALUE);
|
|
|
|
okChildInt("StartupInfoA", "hStdError", (UINT)INVALID_HANDLE_VALUE);
|
|
|
|
okChildInt("TEB", "hStdInput", 0);
|
|
|
|
okChildInt("TEB", "hStdOutput", 0);
|
|
|
|
okChildInt("TEB", "hStdError", 0);
|
|
|
|
release_memory();
|
|
|
|
DeleteFileA(resfile);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-06-29 06:27:26 +02:00
|
|
|
static void test_GetNumaProcessorNode(void)
|
|
|
|
{
|
|
|
|
SYSTEM_INFO si;
|
|
|
|
UCHAR node;
|
|
|
|
BOOL ret;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!pGetNumaProcessorNode)
|
|
|
|
{
|
2015-06-29 06:27:34 +02:00
|
|
|
win_skip("GetNumaProcessorNode is missing\n");
|
2015-06-29 06:27:26 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
GetSystemInfo(&si);
|
|
|
|
for (i = 0; i < 256; i++)
|
|
|
|
{
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
node = (i < si.dwNumberOfProcessors) ? 0xFF : 0xAA;
|
|
|
|
ret = pGetNumaProcessorNode(i, &node);
|
|
|
|
if (i < si.dwNumberOfProcessors)
|
|
|
|
{
|
|
|
|
ok(ret, "GetNumaProcessorNode returned FALSE for processor %d\n", i);
|
|
|
|
ok(node != 0xFF, "expected node != 0xFF, but got 0xFF\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ok(!ret, "GetNumaProcessorNode returned TRUE for processor %d\n", i);
|
|
|
|
ok(node == 0xFF || broken(node == 0xAA) /* WinXP */, "expected node 0xFF, got %x\n", node);
|
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-08 14:20:17 +02:00
|
|
|
static void test_session_info(void)
|
|
|
|
{
|
|
|
|
DWORD session_id, active_session;
|
|
|
|
BOOL r;
|
|
|
|
|
|
|
|
if (!pProcessIdToSessionId)
|
|
|
|
{
|
|
|
|
win_skip("ProcessIdToSessionId is missing\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = pProcessIdToSessionId(GetCurrentProcessId(), &session_id);
|
|
|
|
ok(r, "ProcessIdToSessionId failed: %u\n", GetLastError());
|
|
|
|
trace("session_id = %x\n", session_id);
|
|
|
|
|
|
|
|
active_session = pWTSGetActiveConsoleSessionId();
|
|
|
|
trace("active_session = %x\n", active_session);
|
|
|
|
}
|
|
|
|
|
2015-08-20 05:06:38 +02:00
|
|
|
static void test_process_info(void)
|
|
|
|
{
|
|
|
|
char buf[4096];
|
|
|
|
static const ULONG info_size[] =
|
|
|
|
{
|
|
|
|
sizeof(PROCESS_BASIC_INFORMATION) /* ProcessBasicInformation */,
|
|
|
|
sizeof(QUOTA_LIMITS) /* ProcessQuotaLimits */,
|
|
|
|
sizeof(IO_COUNTERS) /* ProcessIoCounters */,
|
|
|
|
sizeof(VM_COUNTERS) /* ProcessVmCounters */,
|
|
|
|
sizeof(KERNEL_USER_TIMES) /* ProcessTimes */,
|
|
|
|
sizeof(ULONG) /* ProcessBasePriority */,
|
|
|
|
sizeof(ULONG) /* ProcessRaisePriority */,
|
|
|
|
sizeof(HANDLE) /* ProcessDebugPort */,
|
|
|
|
sizeof(HANDLE) /* ProcessExceptionPort */,
|
|
|
|
0 /* FIXME: sizeof(PROCESS_ACCESS_TOKEN) ProcessAccessToken */,
|
|
|
|
0 /* FIXME: sizeof(PROCESS_LDT_INFORMATION) ProcessLdtInformation */,
|
|
|
|
0 /* FIXME: sizeof(PROCESS_LDT_SIZE) ProcessLdtSize */,
|
|
|
|
sizeof(ULONG) /* ProcessDefaultHardErrorMode */,
|
|
|
|
0 /* ProcessIoPortHandlers: kernel-mode only */,
|
|
|
|
0 /* FIXME: sizeof(POOLED_USAGE_AND_LIMITS) ProcessPooledUsageAndLimits */,
|
|
|
|
0 /* FIXME: sizeof(PROCESS_WS_WATCH_INFORMATION) ProcessWorkingSetWatch */,
|
|
|
|
sizeof(ULONG) /* ProcessUserModeIOPL */,
|
|
|
|
sizeof(BOOLEAN) /* ProcessEnableAlignmentFaultFixup */,
|
|
|
|
sizeof(PROCESS_PRIORITY_CLASS) /* ProcessPriorityClass */,
|
|
|
|
sizeof(ULONG) /* ProcessWx86Information */,
|
|
|
|
sizeof(ULONG) /* ProcessHandleCount */,
|
|
|
|
sizeof(ULONG_PTR) /* ProcessAffinityMask */,
|
|
|
|
sizeof(ULONG) /* ProcessPriorityBoost */,
|
|
|
|
0 /* sizeof(PROCESS_DEVICEMAP_INFORMATION) ProcessDeviceMap */,
|
|
|
|
0 /* sizeof(PROCESS_SESSION_INFORMATION) ProcessSessionInformation */,
|
|
|
|
0 /* sizeof(PROCESS_FOREGROUND_BACKGROUND) ProcessForegroundInformation */,
|
|
|
|
sizeof(ULONG_PTR) /* ProcessWow64Information */,
|
|
|
|
sizeof(buf) /* ProcessImageFileName */,
|
|
|
|
sizeof(ULONG) /* ProcessLUIDDeviceMapsEnabled */,
|
|
|
|
sizeof(ULONG) /* ProcessBreakOnTermination */,
|
|
|
|
sizeof(HANDLE) /* ProcessDebugObjectHandle */,
|
|
|
|
sizeof(ULONG) /* ProcessDebugFlags */,
|
|
|
|
sizeof(buf) /* ProcessHandleTracing */,
|
|
|
|
sizeof(ULONG) /* ProcessIoPriority */,
|
|
|
|
sizeof(ULONG) /* ProcessExecuteFlags */,
|
|
|
|
#if 0 /* FIXME: Add remaning classes */
|
|
|
|
ProcessResourceManagement,
|
|
|
|
sizeof(ULONG) /* ProcessCookie */,
|
|
|
|
sizeof(SECTION_IMAGE_INFORMATION) /* ProcessImageInformation */,
|
|
|
|
sizeof(PROCESS_CYCLE_TIME_INFORMATION) /* ProcessCycleTime */,
|
|
|
|
sizeof(ULONG) /* ProcessPagePriority */,
|
|
|
|
40 /* ProcessInstrumentationCallback */,
|
|
|
|
sizeof(PROCESS_STACK_ALLOCATION_INFORMATION) /* ProcessThreadStackAllocation */,
|
|
|
|
sizeof(PROCESS_WS_WATCH_INFORMATION_EX[]) /* ProcessWorkingSetWatchEx */,
|
|
|
|
sizeof(buf) /* ProcessImageFileNameWin32 */,
|
|
|
|
sizeof(HANDLE) /* ProcessImageFileMapping */,
|
|
|
|
sizeof(PROCESS_AFFINITY_UPDATE_MODE) /* ProcessAffinityUpdateMode */,
|
|
|
|
sizeof(PROCESS_MEMORY_ALLOCATION_MODE) /* ProcessMemoryAllocationMode */,
|
|
|
|
sizeof(USHORT[]) /* ProcessGroupInformation */,
|
|
|
|
sizeof(ULONG) /* ProcessTokenVirtualizationEnabled */,
|
|
|
|
sizeof(ULONG_PTR) /* ProcessConsoleHostProcess */,
|
|
|
|
sizeof(PROCESS_WINDOW_INFORMATION) /* ProcessWindowInformation */,
|
|
|
|
sizeof(PROCESS_HANDLE_SNAPSHOT_INFORMATION) /* ProcessHandleInformation */,
|
|
|
|
sizeof(PROCESS_MITIGATION_POLICY_INFORMATION) /* ProcessMitigationPolicy */,
|
|
|
|
sizeof(ProcessDynamicFunctionTableInformation) /* ProcessDynamicFunctionTableInformation */,
|
|
|
|
sizeof(?) /* ProcessHandleCheckingMode */,
|
|
|
|
sizeof(PROCESS_KEEPALIVE_COUNT_INFORMATION) /* ProcessKeepAliveCount */,
|
|
|
|
sizeof(PROCESS_REVOKE_FILE_HANDLES_INFORMATION) /* ProcessRevokeFileHandles */,
|
|
|
|
sizeof(PROCESS_WORKING_SET_CONTROL) /* ProcessWorkingSetControl */,
|
|
|
|
sizeof(?) /* ProcessHandleTable */,
|
|
|
|
sizeof(?) /* ProcessCheckStackExtentsMode */,
|
|
|
|
sizeof(buf) /* ProcessCommandLineInformation */,
|
|
|
|
sizeof(PS_PROTECTION) /* ProcessProtectionInformation */,
|
|
|
|
sizeof(PROCESS_MEMORY_EXHAUSTION_INFO) /* ProcessMemoryExhaustion */,
|
|
|
|
sizeof(PROCESS_FAULT_INFORMATION) /* ProcessFaultInformation */,
|
|
|
|
sizeof(PROCESS_TELEMETRY_ID_INFORMATION) /* ProcessTelemetryIdInformation */,
|
|
|
|
sizeof(PROCESS_COMMIT_RELEASE_INFORMATION) /* ProcessCommitReleaseInformation */,
|
|
|
|
sizeof(?) /* ProcessDefaultCpuSetsInformation */,
|
|
|
|
sizeof(?) /* ProcessAllowedCpuSetsInformation */,
|
|
|
|
0 /* ProcessReserved1Information */,
|
|
|
|
0 /* ProcessReserved2Information */,
|
|
|
|
sizeof(?) /* ProcessSubsystemProcess */,
|
|
|
|
sizeof(PROCESS_JOB_MEMORY_INFO) /* ProcessJobMemoryInformation */,
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
HANDLE hproc;
|
|
|
|
ULONG i, status, ret_len, size;
|
|
|
|
|
|
|
|
if (!pNtQueryInformationProcess)
|
|
|
|
{
|
|
|
|
win_skip("NtQueryInformationProcess is not available on this platform\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
hproc = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, GetCurrentProcessId());
|
|
|
|
if (!hproc)
|
|
|
|
{
|
|
|
|
win_skip("PROCESS_QUERY_LIMITED_INFORMATION is not supported on this platform\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < MaxProcessInfoClass; i++)
|
|
|
|
{
|
|
|
|
size = info_size[i];
|
|
|
|
if (!size) size = sizeof(buf);
|
|
|
|
ret_len = 0;
|
|
|
|
status = pNtQueryInformationProcess(hproc, i, buf, info_size[i], &ret_len);
|
|
|
|
if (status == STATUS_NOT_IMPLEMENTED) continue;
|
|
|
|
if (status == STATUS_INVALID_INFO_CLASS) continue;
|
|
|
|
if (status == STATUS_INFO_LENGTH_MISMATCH) continue;
|
|
|
|
|
|
|
|
switch (i)
|
|
|
|
{
|
|
|
|
case ProcessBasicInformation:
|
|
|
|
case ProcessQuotaLimits:
|
|
|
|
case ProcessTimes:
|
|
|
|
case ProcessPriorityClass:
|
|
|
|
case ProcessPriorityBoost:
|
|
|
|
case ProcessLUIDDeviceMapsEnabled:
|
|
|
|
case 33 /* ProcessIoPriority */:
|
|
|
|
case ProcessIoCounters:
|
|
|
|
case ProcessVmCounters:
|
|
|
|
case ProcessWow64Information:
|
|
|
|
case ProcessDefaultHardErrorMode:
|
|
|
|
case ProcessHandleCount:
|
|
|
|
ok(status == STATUS_SUCCESS, "for info %u expected STATUS_SUCCESS, got %08x (ret_len %u)\n", i, status, ret_len);
|
|
|
|
break;
|
|
|
|
|
2015-08-21 06:14:19 +02:00
|
|
|
case ProcessImageFileName:
|
|
|
|
todo_wine
|
|
|
|
ok(status == STATUS_SUCCESS, "for info %u expected STATUS_SUCCESS, got %08x (ret_len %u)\n", i, status, ret_len);
|
|
|
|
break;
|
|
|
|
|
2015-08-20 05:06:38 +02:00
|
|
|
case ProcessAffinityMask:
|
|
|
|
case ProcessBreakOnTermination:
|
|
|
|
ok(status == STATUS_ACCESS_DENIED /* before win8 */ || status == STATUS_SUCCESS /* win8 is less strict */,
|
|
|
|
"for info %u expected STATUS_SUCCESS, got %08x (ret_len %u)\n", i, status, ret_len);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ProcessDebugObjectHandle:
|
|
|
|
ok(status == STATUS_ACCESS_DENIED || status == STATUS_PORT_NOT_SET,
|
|
|
|
"for info %u expected STATUS_ACCESS_DENIED, got %08x (ret_len %u)\n", i, status, ret_len);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ProcessExecuteFlags:
|
2015-08-21 06:14:19 +02:00
|
|
|
case ProcessDebugPort:
|
|
|
|
case ProcessDebugFlags:
|
2015-08-20 05:06:38 +02:00
|
|
|
todo_wine
|
|
|
|
ok(status == STATUS_ACCESS_DENIED, "for info %u expected STATUS_ACCESS_DENIED, got %08x (ret_len %u)\n", i, status, ret_len);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
ok(status == STATUS_ACCESS_DENIED, "for info %u expected STATUS_ACCESS_DENIED, got %08x (ret_len %u)\n", i, status, ret_len);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CloseHandle(hproc);
|
|
|
|
}
|
|
|
|
|
2016-01-03 23:56:46 +01:00
|
|
|
static void test_GetLogicalProcessorInformationEx(void)
|
|
|
|
{
|
|
|
|
SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX *info;
|
|
|
|
DWORD len;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
if (!pGetLogicalProcessorInformationEx)
|
|
|
|
{
|
|
|
|
win_skip("GetLogicalProcessorInformationEx() is not supported\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = pGetLogicalProcessorInformationEx(RelationAll, NULL, NULL);
|
2016-01-03 23:56:48 +01:00
|
|
|
ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, "got %d, error %d\n", ret, GetLastError());
|
2016-01-03 23:56:46 +01:00
|
|
|
|
2016-01-03 23:56:48 +01:00
|
|
|
len = 0;
|
|
|
|
ret = pGetLogicalProcessorInformationEx(RelationProcessorCore, NULL, &len);
|
|
|
|
ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %d, error %d\n", ret, GetLastError());
|
|
|
|
ok(len > 0, "got %u\n", len);
|
2016-01-25 15:47:10 +01:00
|
|
|
|
2016-01-03 23:56:46 +01:00
|
|
|
len = 0;
|
|
|
|
ret = pGetLogicalProcessorInformationEx(RelationAll, NULL, &len);
|
|
|
|
ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %d, error %d\n", ret, GetLastError());
|
|
|
|
ok(len > 0, "got %u\n", len);
|
|
|
|
|
|
|
|
info = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
|
|
|
|
ret = pGetLogicalProcessorInformationEx(RelationAll, info, &len);
|
|
|
|
ok(ret, "got %d, error %d\n", ret, GetLastError());
|
|
|
|
ok(info->Size > 0, "got %u\n", info->Size);
|
|
|
|
HeapFree(GetProcessHeap(), 0, info);
|
|
|
|
}
|
|
|
|
|
2002-04-22 00:07:03 +02:00
|
|
|
START_TEST(process)
|
|
|
|
{
|
2015-03-28 03:24:48 +01:00
|
|
|
HANDLE job;
|
2013-10-24 00:40:23 +02:00
|
|
|
BOOL b = init();
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(b, "Basic init of CreateProcess test\n");
|
2002-04-22 00:07:03 +02:00
|
|
|
if (!b) return;
|
|
|
|
|
2015-03-28 03:25:45 +01:00
|
|
|
if (myARGC >= 3)
|
2002-04-22 00:07:03 +02:00
|
|
|
{
|
2015-03-28 03:25:45 +01:00
|
|
|
if (!strcmp(myARGV[2], "dump") && myARGC >= 4)
|
2015-02-26 05:18:09 +01:00
|
|
|
{
|
|
|
|
doChild(myARGV[3], (myARGC >= 5) ? myARGV[4] : NULL);
|
|
|
|
return;
|
|
|
|
}
|
2015-03-28 03:25:45 +01:00
|
|
|
else if (!strcmp(myARGV[2], "wait"))
|
|
|
|
{
|
|
|
|
Sleep(30000);
|
|
|
|
ok(0, "Child process not killed\n");
|
|
|
|
return;
|
|
|
|
}
|
2015-03-28 03:23:51 +01:00
|
|
|
else if (!strcmp(myARGV[2], "exit"))
|
|
|
|
{
|
|
|
|
Sleep(100);
|
|
|
|
return;
|
|
|
|
}
|
2015-12-21 13:06:37 +01:00
|
|
|
else if (!strcmp(myARGV[2], "nested") && myARGC >= 4)
|
|
|
|
{
|
|
|
|
char buffer[MAX_PATH];
|
|
|
|
STARTUPINFOA startup;
|
|
|
|
PROCESS_INFORMATION info;
|
|
|
|
|
|
|
|
memset(&startup, 0, sizeof(startup));
|
|
|
|
startup.cb = sizeof(startup);
|
|
|
|
startup.dwFlags = STARTF_USESHOWWINDOW;
|
|
|
|
startup.wShowWindow = SW_SHOWNORMAL;
|
|
|
|
|
|
|
|
sprintf(buffer, "\"%s\" tests/process.c dump \"%s\"", selfname, myARGV[3]);
|
|
|
|
ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, CREATE_SUSPENDED, NULL, NULL, &startup, &info), "CreateProcess failed\n");
|
|
|
|
CloseHandle(info.hProcess);
|
|
|
|
CloseHandle(info.hThread);
|
|
|
|
return;
|
|
|
|
}
|
2015-02-26 05:18:09 +01:00
|
|
|
|
|
|
|
ok(0, "Unexpected command %s\n", myARGV[2]);
|
2002-04-22 00:07:03 +02:00
|
|
|
return;
|
|
|
|
}
|
2016-01-03 23:56:46 +01:00
|
|
|
|
2015-08-20 05:06:38 +02:00
|
|
|
test_process_info();
|
2013-05-24 09:57:16 +02:00
|
|
|
test_TerminateProcess();
|
2002-04-22 00:07:03 +02:00
|
|
|
test_Startup();
|
|
|
|
test_CommandLine();
|
|
|
|
test_Directory();
|
2015-12-21 13:06:37 +01:00
|
|
|
test_Toolhelp();
|
2003-01-13 19:28:43 +01:00
|
|
|
test_Environment();
|
|
|
|
test_SuspendFlag();
|
|
|
|
test_DebuggingFlag();
|
2003-06-18 05:24:20 +02:00
|
|
|
test_Console();
|
2003-06-26 04:05:40 +02:00
|
|
|
test_ExitCode();
|
2006-11-08 16:45:33 +01:00
|
|
|
test_OpenProcess();
|
2008-10-15 16:44:54 +02:00
|
|
|
test_GetProcessVersion();
|
2011-10-04 05:11:40 +02:00
|
|
|
test_GetProcessImageFileNameA();
|
|
|
|
test_QueryFullProcessImageNameA();
|
|
|
|
test_QueryFullProcessImageNameW();
|
2008-12-08 13:39:31 +01:00
|
|
|
test_Handles();
|
2015-01-16 19:17:31 +01:00
|
|
|
test_IsWow64Process();
|
2010-05-12 22:58:34 +02:00
|
|
|
test_SystemInfo();
|
2010-10-11 12:16:16 +02:00
|
|
|
test_RegistryQuota();
|
2013-06-05 11:33:29 +02:00
|
|
|
test_DuplicateHandle();
|
2015-01-04 07:37:42 +01:00
|
|
|
test_StartupNoConsole();
|
2015-06-29 06:27:26 +02:00
|
|
|
test_GetNumaProcessorNode();
|
2015-10-08 14:20:17 +02:00
|
|
|
test_session_info();
|
2016-01-03 23:56:46 +01:00
|
|
|
test_GetLogicalProcessorInformationEx();
|
2015-10-08 14:20:17 +02:00
|
|
|
|
2002-04-22 00:07:03 +02:00
|
|
|
/* things that can be tested:
|
|
|
|
* lookup: check the way program to be executed is searched
|
|
|
|
* handles: check the handle inheritance stuff (+sec options)
|
|
|
|
* console: check if console creation parameters work
|
|
|
|
*/
|
2015-03-28 03:25:45 +01:00
|
|
|
|
|
|
|
if (!pCreateJobObjectW)
|
|
|
|
{
|
|
|
|
win_skip("No job object support\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
test_IsProcessInJob();
|
2015-03-28 03:23:28 +01:00
|
|
|
test_TerminateJobObject();
|
2015-03-28 03:23:51 +01:00
|
|
|
test_QueryInformationJobObject();
|
2015-03-28 03:24:12 +01:00
|
|
|
test_CompletionPort();
|
2015-03-28 03:24:30 +01:00
|
|
|
test_KillOnJobClose();
|
2015-04-03 08:20:05 +02:00
|
|
|
test_WaitForJobObject();
|
2015-03-28 03:24:48 +01:00
|
|
|
job = test_AddSelfToJob();
|
2015-03-28 03:26:30 +01:00
|
|
|
test_jobInheritance(job);
|
2015-03-28 03:24:48 +01:00
|
|
|
test_BreakawayOk(job);
|
|
|
|
CloseHandle(job);
|
2002-04-22 00:07:03 +02:00
|
|
|
}
|