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 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <stdio.h>
#include "wine/test.h"
#include <winbase.h>
#include <winnt.h>
#include <winerror.h>
#include "wine/test.h"
/* Specify the number of simultaneous threads to test */
#define NUM_THREADS 4
/* Specify whether to test the extended priorities for Win2k/XP */
#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 */
#define CHECK_STACK 0
......@@ -118,8 +115,11 @@ VOID WINAPI threadFunc3()
ExitThread(99);
}
VOID WINAPI threadFunc4()
VOID WINAPI threadFunc4(HANDLE event)
{
if(event != (HANDLE)NULL) {
SetEvent(event);
}
Sleep(99000);
ExitThread(0);
}
......@@ -265,7 +265,6 @@ VOID test_SuspendThread(DWORD version)
if(WIN2K_PLUS(version)) {
access_thread=OpenThreadPtr(THREAD_ALL_ACCESS & (~THREAD_SUSPEND_RESUME),
0,threadId);
todo_wine {
ok(access_thread!=(HANDLE)NULL,"OpenThread returned an invalid handle");
if(access_thread!=(HANDLE)NULL) {
ok(SuspendThread(access_thread)==-1,
......@@ -275,7 +274,6 @@ VOID test_SuspendThread(DWORD version)
ok(CloseHandle(access_thread)!=0,"CloseHandle Failed");
}
}
}
/* Double check that the thread really is suspended */
ok((error=GetExitCodeThread(thread,&exitCode))!=0 && exitCode==STILL_ACTIVE,
"Thread did not really suspend");
......@@ -290,25 +288,28 @@ VOID test_SuspendThread(DWORD version)
}
/* 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)
{
HANDLE thread,access_thread;
HANDLE thread,access_thread,event;
DWORD threadId,exitCode;
int i,error;
char msg[80];
i=0; error=0;
thread = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)threadFunc4,NULL,
0,&threadId);
event=CreateEventA(NULL,TRUE,FALSE,NULL);
thread = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)threadFunc4,
(LPVOID)event, 0,&threadId);
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 */
if(WIN2K_PLUS(version)) {
access_thread=OpenThreadPtr(THREAD_ALL_ACCESS & (~THREAD_TERMINATE),
0,threadId);
todo_wine {
ok(access_thread!=(HANDLE)NULL,"OpenThread returned an invalid handle");
if(access_thread!=(HANDLE)NULL) {
ok(TerminateThread(access_thread,99)==0,
......@@ -316,7 +317,6 @@ VOID test_TerminateThread(DWORD version)
ok(CloseHandle(access_thread)!=0,"CloseHandle Failed");
}
}
}
/* terminate a job and make sure it terminates */
ok(TerminateThread(thread,99)!=0,"TerminateThread failed");
ok(WaitForSingleObject(thread,5000)==WAIT_OBJECT_0,
......@@ -328,8 +328,7 @@ VOID test_TerminateThread(DWORD version)
TerminateThread, even though MSDN says it should. So currently
there is no check being done for this.
*/
sprintf(msg,"TerminateThread returned: 0x%lx instead of 0x%x\n",exitCode,99);
trace(msg);
trace("TerminateThread returned: 0x%lx instead of 0x%x\n",exitCode,99);
} else {
ok(exitCode==99, "TerminateThread returned invalid exit code");
}
......@@ -372,7 +371,6 @@ VOID test_thread_priority(DWORD version)
DWORD curthreadId,exitCode;
int min_priority=-2,max_priority=2;
int i,error;
char msg1[80],msg2[80];
curthread=GetCurrentThread();
curthreadId=GetCurrentThreadId();
......@@ -390,7 +388,6 @@ VOID test_thread_priority(DWORD version)
access_thread=OpenThreadPtr(THREAD_ALL_ACCESS &
(~THREAD_QUERY_INFORMATION) & (~THREAD_SET_INFORMATION),
0,curthreadId);
todo_wine {
ok(access_thread!=(HANDLE)NULL,"OpenThread returned an invalid handle");
if(access_thread!=(HANDLE)NULL) {
ok(SetThreadPriority(access_thread,1)==0,
......@@ -405,16 +402,15 @@ VOID test_thread_priority(DWORD version)
"GetExitCodeThread did not obey access restrictions");
ok(CloseHandle(access_thread),"Error Closing thread handle");
}
}
#if USE_EXTENDED_PRIORITIES
min_priority=-7; max_priority=6;
#endif
}
for(i=min_priority;i<=max_priority;i++) {
sprintf(msg1,"SetThreadPriority Failed for priority: %d",i);
sprintf(msg2,"GetThreadPriority Failed for priority: %d",i);
ok(SetThreadPriority(curthread,i)!=0,msg1);
ok(GetThreadPriority(curthread)==i,msg2);
ok(SetThreadPriority(curthread,i)!=0,
"SetThreadPriority Failed for priority: %d",i);
ok(GetThreadPriority(curthread)==i,
"GetThreadPriority Failed for priority: %d",i);
}
ok(SetThreadPriority(curthread,THREAD_PRIORITY_TIME_CRITICAL)!=0,
"SetThreadPriority Failed");
......@@ -458,11 +454,9 @@ VOID test_GetThreadTimes(DWORD version)
if(WIN2K_PLUS(version)) {
access_thread=OpenThreadPtr(THREAD_ALL_ACCESS &
(~THREAD_QUERY_INFORMATION), 0,threadId);
todo_wine {
ok(access_thread!=(HANDLE)NULL,
"OpenThread returned an invalid handle");
}
}
ok(ResumeThread(thread)==1,"Resume thread returned an invalid value");
ok(WaitForSingleObject(thread,5000)==WAIT_OBJECT_0,
"ResumeThread didn't work");
......@@ -554,9 +548,7 @@ START_TEST(thread)
test_CreateThread_basic(version);
test_CreateThread_suspended(version);
test_SuspendThread(version);
#if ! SKIP_TERMINATE
test_TerminateThread(version);
#endif
test_CreateThread_stack(version);
test_thread_priority(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