blob: b2bb97fd67fb374557e066ad46d93b28038d6b27 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
/*============================================================
**
** Source: GetCurrentThread/test1/thread.c
**
** Purpose: Test to ensure GetCurrentThread returns a handle to
** the current thread.
**
** Dependencies: GetThreadPriority
** SetThreadPriority
** Fail
** Trace
**
**
**=========================================================*/
#include <palsuite.h>
int __cdecl main( int argc, char **argv )
{
HANDLE hThread;
int nPriority;
if(0 != (PAL_Initialize(argc, argv)))
{
return ( FAIL );
}
#if !HAVE_SCHED_OTHER_ASSIGNABLE
/* Defining thread priority for SCHED_OTHER is implementation defined.
Some platforms like NetBSD cannot reassign it as they are dynamic.
*/
printf("paltest_getcurrentthread_test1 has been disabled on this platform\n");
#else
hThread = GetCurrentThread();
nPriority = GetThreadPriority(hThread);
if ( THREAD_PRIORITY_NORMAL != nPriority )
{
if ( THREAD_PRIORITY_ERROR_RETURN == nPriority )
{
Fail ("GetThreadPriority function call failed for %s\n"
"GetLastError returned %d\n", argv[0], GetLastError());
}
else
{
Fail ("GetThreadPriority function call failed for %s\n"
"The priority returned was %d\n", argv[0], nPriority);
}
}
else
{
nPriority = 0;
if (0 == SetThreadPriority(hThread, THREAD_PRIORITY_HIGHEST))
{
Fail ("Unable to set thread priority. Either handle doesn't"
" point to current thread \nor SetThreadPriority "
"function failed. Failing test.\n");
}
nPriority = GetThreadPriority(hThread);
if ( THREAD_PRIORITY_ERROR_RETURN == nPriority )
{
Fail ("GetThreadPriority function call failed for %s\n"
"GetLastError returned %d\n", argv[0], GetLastError());
}
else if ( THREAD_PRIORITY_HIGHEST == nPriority )
{
Trace ("GetCurrentThread returns handle to the current "
"thread.\n");
exit ( PASS );
}
else
{
Fail ("Unable to set thread priority. Either handle doesn't"
" point to current thread \nor SetThreadPriority "
"function failed. Failing test.\n");
}
}
#endif
PAL_Terminate();
return ( PASS );
}
|