| 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: test1.c |
| 8 | ** |
| 9 | ** Purpose: Test for CreateThread. Call CreateThread and ensure |
| 10 | ** that it succeeds. Also check to ensure the paramater is passed |
| 11 | ** properly. |
| 12 | ** |
| 13 | ** |
| 14 | **=========================================================*/ |
| 15 | |
| 16 | #include <palsuite.h> |
| 17 | |
| 18 | #define LLFORMAT "%llu" |
| 19 | |
| 20 | ULONGLONG dwCreateThreadTestParameter = 0; |
| 21 | |
| 22 | DWORD PALAPI CreateThreadTestThread( LPVOID lpParameter) |
| 23 | { |
| 24 | DWORD dwRet = 0; |
| 25 | |
| 26 | /* save parameter for test */ |
| 27 | dwCreateThreadTestParameter = (ULONGLONG)lpParameter; |
| 28 | |
| 29 | return dwRet; |
| 30 | } |
| 31 | |
| 32 | BOOL CreateThreadTest() |
| 33 | { |
| 34 | BOOL bRet = FALSE; |
| 35 | DWORD dwRet = 0; |
| 36 | |
| 37 | LPSECURITY_ATTRIBUTES lpThreadAttributes = NULL; |
| 38 | DWORD dwStackSize = 0; |
| 39 | LPTHREAD_START_ROUTINE lpStartAddress = &CreateThreadTestThread; |
| 40 | LPVOID lpParameter = (LPVOID)lpStartAddress; |
| 41 | DWORD dwCreationFlags = 0; /* run immediately */ |
| 42 | DWORD dwThreadId = 0; |
| 43 | |
| 44 | HANDLE hThread = 0; |
| 45 | |
| 46 | dwCreateThreadTestParameter = 0; |
| 47 | |
| 48 | /* Create a thread, passing the appropriate paramaters as declared |
| 49 | above. |
| 50 | */ |
| 51 | |
| 52 | hThread = CreateThread( lpThreadAttributes, |
| 53 | dwStackSize, |
| 54 | lpStartAddress, |
| 55 | lpParameter, |
| 56 | dwCreationFlags, |
| 57 | &dwThreadId ); |
| 58 | |
| 59 | /* Ensure that the HANDLE is not invalid! */ |
| 60 | if (hThread != INVALID_HANDLE_VALUE) |
| 61 | { |
| 62 | dwRet = WaitForSingleObject(hThread,INFINITE); |
| 63 | |
| 64 | if (dwRet != WAIT_OBJECT_0) |
| 65 | { |
| 66 | Trace("CreateThreadTest:WaitForSingleObject " |
| 67 | "failed (%x)\n" ,GetLastError()); |
| 68 | } |
| 69 | else |
| 70 | { |
| 71 | /* Check to ensure that the parameter passed to the thread |
| 72 | function is the same in the function as what we passed. |
| 73 | */ |
| 74 | |
| 75 | if (dwCreateThreadTestParameter != (ULONGLONG)lpParameter) |
| 76 | { |
| 77 | Trace("CreateThreadTest:parameter error. The " |
| 78 | "parameter passed should have been " LLFORMAT " but when " |
| 79 | "passed to the Thread function it was " LLFORMAT " . GetLastError[%x]\n" , |
| 80 | dwCreateThreadTestParameter,lpParameter, GetLastError()); |
| 81 | } |
| 82 | else |
| 83 | { |
| 84 | bRet = TRUE; |
| 85 | } |
| 86 | |
| 87 | } |
| 88 | CloseHandle(hThread); |
| 89 | } |
| 90 | else |
| 91 | { |
| 92 | Trace("CreateThreadTest:CreateThread failed (%x)\n" ,GetLastError()); |
| 93 | } |
| 94 | |
| 95 | return bRet; |
| 96 | } |
| 97 | |
| 98 | |
| 99 | int __cdecl main(int argc, char **argv) |
| 100 | { |
| 101 | if(0 != (PAL_Initialize(argc, argv))) |
| 102 | { |
| 103 | return ( FAIL ); |
| 104 | } |
| 105 | |
| 106 | if(!CreateThreadTest()) |
| 107 | { |
| 108 | Fail ("Test failed\n" ); |
| 109 | } |
| 110 | |
| 111 | Trace("Test Passed\n" ); |
| 112 | PAL_Terminate(); |
| 113 | return ( PASS ); |
| 114 | |
| 115 | } |
| 116 | |