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