Commit f31c3e38 authored by Geoffrey Hausheer's avatar Geoffrey Hausheer Committed by Alexandre Julliard

Cleaned up a bit, removed todos for OpenThread, avoid TerminateThread

race.
parent 01c8ec3a
...@@ -18,18 +18,15 @@ ...@@ -18,18 +18,15 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include <stdio.h> #include "wine/test.h"
#include <winbase.h> #include <winbase.h>
#include <winnt.h> #include <winnt.h>
#include <winerror.h> #include <winerror.h>
#include "wine/test.h"
/* Specify the number of simultaneous threads to test */ /* Specify the number of simultaneous threads to test */
#define NUM_THREADS 4 #define NUM_THREADS 4
/* Specify whether to test the extended priorities for Win2k/XP */ /* Specify whether to test the extended priorities for Win2k/XP */
#define USE_EXTENDED_PRIORITIES 0 #define USE_EXTENDED_PRIORITIES 0
/* Specify whether the TerminateThread tests should be skipped */
#define SKIP_TERMINATE 0
/* Specify whether to test the stack allocation in CreateThread */ /* Specify whether to test the stack allocation in CreateThread */
#define CHECK_STACK 0 #define CHECK_STACK 0
...@@ -118,8 +115,11 @@ VOID WINAPI threadFunc3() ...@@ -118,8 +115,11 @@ VOID WINAPI threadFunc3()
ExitThread(99); ExitThread(99);
} }
VOID WINAPI threadFunc4() VOID WINAPI threadFunc4(HANDLE event)
{ {
if(event != (HANDLE)NULL) {
SetEvent(event);
}
Sleep(99000); Sleep(99000);
ExitThread(0); ExitThread(0);
} }
...@@ -264,16 +264,14 @@ VOID test_SuspendThread(DWORD version) ...@@ -264,16 +264,14 @@ VOID test_SuspendThread(DWORD version)
/* check that access restrictions are obeyed */ /* check that access restrictions are obeyed */
if(WIN2K_PLUS(version)) { if(WIN2K_PLUS(version)) {
access_thread=OpenThreadPtr(THREAD_ALL_ACCESS & (~THREAD_SUSPEND_RESUME), access_thread=OpenThreadPtr(THREAD_ALL_ACCESS & (~THREAD_SUSPEND_RESUME),
0,threadId); 0,threadId);
todo_wine { ok(access_thread!=(HANDLE)NULL,"OpenThread returned an invalid handle");
ok(access_thread!=(HANDLE)NULL,"OpenThread returned an invalid handle"); if(access_thread!=(HANDLE)NULL) {
if(access_thread!=(HANDLE)NULL) { ok(SuspendThread(access_thread)==-1,
ok(SuspendThread(access_thread)==-1, "SuspendThread did not obey access restrictions");
"SuspendThread did not obey access restrictions"); ok(ResumeThread(access_thread)==-1,
ok(ResumeThread(access_thread)==-1, "ResumeThread did not obey access restrictions");
"ResumeThread did not obey access restrictions"); ok(CloseHandle(access_thread)!=0,"CloseHandle Failed");
ok(CloseHandle(access_thread)!=0,"CloseHandle Failed");
}
} }
} }
/* Double check that the thread really is suspended */ /* Double check that the thread really is suspended */
...@@ -290,31 +288,33 @@ VOID test_SuspendThread(DWORD version) ...@@ -290,31 +288,33 @@ VOID test_SuspendThread(DWORD version)
} }
/* Check that TerminateThread works properly /* Check that TerminateThread works properly
NOTE: in my wine version (As of March 30, 2002), this code leaves a wine
process after the test completes. You can use SKIP_TERMINATE to disable
the testing, and not leave the wine process around.
*/ */
VOID test_TerminateThread(DWORD version) VOID test_TerminateThread(DWORD version)
{ {
HANDLE thread,access_thread; HANDLE thread,access_thread,event;
DWORD threadId,exitCode; DWORD threadId,exitCode;
int i,error; int i,error;
char msg[80];
i=0; error=0; i=0; error=0;
thread = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)threadFunc4,NULL, event=CreateEventA(NULL,TRUE,FALSE,NULL);
0,&threadId); thread = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)threadFunc4,
(LPVOID)event, 0,&threadId);
ok(thread!=(HANDLE)NULL,"Create Thread failed."); ok(thread!=(HANDLE)NULL,"Create Thread failed.");
/* Terminate thread has a race condition in Wine. If the thread is terminated
before it starts, it leaves a process behind. Therefore, we wait for the
thread to signal that it has started. There is no easy way to force the
race to occur, so we don't try to find it.
*/
ok(WaitForSingleObject(event,5000)==WAIT_OBJECT_0,
"TerminateThread didn't work");
/* check that access restrictions are obeyed */ /* check that access restrictions are obeyed */
if(WIN2K_PLUS(version)) { if(WIN2K_PLUS(version)) {
access_thread=OpenThreadPtr(THREAD_ALL_ACCESS & (~THREAD_TERMINATE), access_thread=OpenThreadPtr(THREAD_ALL_ACCESS & (~THREAD_TERMINATE),
0,threadId); 0,threadId);
todo_wine { ok(access_thread!=(HANDLE)NULL,"OpenThread returned an invalid handle");
ok(access_thread!=(HANDLE)NULL,"OpenThread returned an invalid handle"); if(access_thread!=(HANDLE)NULL) {
if(access_thread!=(HANDLE)NULL) { ok(TerminateThread(access_thread,99)==0,
ok(TerminateThread(access_thread,99)==0, "TerminateThread did not obey access restrictions");
"TerminateThread did not obey access restrictions"); ok(CloseHandle(access_thread)!=0,"CloseHandle Failed");
ok(CloseHandle(access_thread)!=0,"CloseHandle Failed");
}
} }
} }
/* terminate a job and make sure it terminates */ /* terminate a job and make sure it terminates */
...@@ -328,8 +328,7 @@ VOID test_TerminateThread(DWORD version) ...@@ -328,8 +328,7 @@ VOID test_TerminateThread(DWORD version)
TerminateThread, even though MSDN says it should. So currently TerminateThread, even though MSDN says it should. So currently
there is no check being done for this. there is no check being done for this.
*/ */
sprintf(msg,"TerminateThread returned: 0x%lx instead of 0x%x\n",exitCode,99); trace("TerminateThread returned: 0x%lx instead of 0x%x\n",exitCode,99);
trace(msg);
} else { } else {
ok(exitCode==99, "TerminateThread returned invalid exit code"); ok(exitCode==99, "TerminateThread returned invalid exit code");
} }
...@@ -372,7 +371,6 @@ VOID test_thread_priority(DWORD version) ...@@ -372,7 +371,6 @@ VOID test_thread_priority(DWORD version)
DWORD curthreadId,exitCode; DWORD curthreadId,exitCode;
int min_priority=-2,max_priority=2; int min_priority=-2,max_priority=2;
int i,error; int i,error;
char msg1[80],msg2[80];
curthread=GetCurrentThread(); curthread=GetCurrentThread();
curthreadId=GetCurrentThreadId(); curthreadId=GetCurrentThreadId();
...@@ -390,31 +388,29 @@ VOID test_thread_priority(DWORD version) ...@@ -390,31 +388,29 @@ VOID test_thread_priority(DWORD version)
access_thread=OpenThreadPtr(THREAD_ALL_ACCESS & access_thread=OpenThreadPtr(THREAD_ALL_ACCESS &
(~THREAD_QUERY_INFORMATION) & (~THREAD_SET_INFORMATION), (~THREAD_QUERY_INFORMATION) & (~THREAD_SET_INFORMATION),
0,curthreadId); 0,curthreadId);
todo_wine { ok(access_thread!=(HANDLE)NULL,"OpenThread returned an invalid handle");
ok(access_thread!=(HANDLE)NULL,"OpenThread returned an invalid handle"); if(access_thread!=(HANDLE)NULL) {
if(access_thread!=(HANDLE)NULL) { ok(SetThreadPriority(access_thread,1)==0,
ok(SetThreadPriority(access_thread,1)==0, "SetThreadPriority did not obey access restrictions");
"SetThreadPriority did not obey access restrictions"); ok(GetThreadPriority(access_thread)==THREAD_PRIORITY_ERROR_RETURN,
ok(GetThreadPriority(access_thread)==THREAD_PRIORITY_ERROR_RETURN, "GetThreadPriority did not obey access restrictions");
"GetThreadPriority did not obey access restrictions"); ok(SetThreadPriorityBoost(access_thread,1)==0,
ok(SetThreadPriorityBoost(access_thread,1)==0, "SetThreadPriorityBoost did not obey access restrictions");
"SetThreadPriorityBoost did not obey access restrictions"); ok(GetThreadPriorityBoost(access_thread,&error)==0,
ok(GetThreadPriorityBoost(access_thread,&error)==0, "GetThreadPriorityBoost did not obey access restrictions");
"GetThreadPriorityBoost did not obey access restrictions"); ok(GetExitCodeThread(access_thread,&exitCode)==0,
ok(GetExitCodeThread(access_thread,&exitCode)==0, "GetExitCodeThread did not obey access restrictions");
"GetExitCodeThread did not obey access restrictions"); ok(CloseHandle(access_thread),"Error Closing thread handle");
ok(CloseHandle(access_thread),"Error Closing thread handle");
}
} }
#if USE_EXTENDED_PRIORITIES #if USE_EXTENDED_PRIORITIES
min_priority=-7; max_priority=6; min_priority=-7; max_priority=6;
#endif #endif
} }
for(i=min_priority;i<=max_priority;i++) { for(i=min_priority;i<=max_priority;i++) {
sprintf(msg1,"SetThreadPriority Failed for priority: %d",i); ok(SetThreadPriority(curthread,i)!=0,
sprintf(msg2,"GetThreadPriority Failed for priority: %d",i); "SetThreadPriority Failed for priority: %d",i);
ok(SetThreadPriority(curthread,i)!=0,msg1); ok(GetThreadPriority(curthread)==i,
ok(GetThreadPriority(curthread)==i,msg2); "GetThreadPriority Failed for priority: %d",i);
} }
ok(SetThreadPriority(curthread,THREAD_PRIORITY_TIME_CRITICAL)!=0, ok(SetThreadPriority(curthread,THREAD_PRIORITY_TIME_CRITICAL)!=0,
"SetThreadPriority Failed"); "SetThreadPriority Failed");
...@@ -458,10 +454,8 @@ VOID test_GetThreadTimes(DWORD version) ...@@ -458,10 +454,8 @@ VOID test_GetThreadTimes(DWORD version)
if(WIN2K_PLUS(version)) { if(WIN2K_PLUS(version)) {
access_thread=OpenThreadPtr(THREAD_ALL_ACCESS & access_thread=OpenThreadPtr(THREAD_ALL_ACCESS &
(~THREAD_QUERY_INFORMATION), 0,threadId); (~THREAD_QUERY_INFORMATION), 0,threadId);
todo_wine { ok(access_thread!=(HANDLE)NULL,
ok(access_thread!=(HANDLE)NULL, "OpenThread returned an invalid handle");
"OpenThread returned an invalid handle");
}
} }
ok(ResumeThread(thread)==1,"Resume thread returned an invalid value"); ok(ResumeThread(thread)==1,"Resume thread returned an invalid value");
ok(WaitForSingleObject(thread,5000)==WAIT_OBJECT_0, ok(WaitForSingleObject(thread,5000)==WAIT_OBJECT_0,
...@@ -554,9 +548,7 @@ START_TEST(thread) ...@@ -554,9 +548,7 @@ START_TEST(thread)
test_CreateThread_basic(version); test_CreateThread_basic(version);
test_CreateThread_suspended(version); test_CreateThread_suspended(version);
test_SuspendThread(version); test_SuspendThread(version);
#if ! SKIP_TERMINATE
test_TerminateThread(version); test_TerminateThread(version);
#endif
test_CreateThread_stack(version); test_CreateThread_stack(version);
test_thread_priority(version); test_thread_priority(version);
test_GetThreadTimes(version); test_GetThreadTimes(version);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment