summaryrefslogtreecommitdiff
path: root/src/pal/tests
diff options
context:
space:
mode:
authorJan Vorlicek <janvorli@microsoft.com>2018-03-15 19:57:01 +0100
committerGitHub <noreply@github.com>2018-03-15 19:57:01 +0100
commit2f19f9bc20b6c18161555ca774eb6931d289202f (patch)
tree7105f88345c9a080d3e805b6e7978bcecc38bda6 /src/pal/tests
parent4813d29b7ec505f698a0446d6d8614ec03651c9a (diff)
downloadcoreclr-2f19f9bc20b6c18161555ca774eb6931d289202f.tar.gz
coreclr-2f19f9bc20b6c18161555ca774eb6931d289202f.tar.bz2
coreclr-2f19f9bc20b6c18161555ca774eb6931d289202f.zip
Fix error type check in InternalSetThreadPriority (#16959)
The pthread_setschedparam returns error code as a return value and not in the errno as the existing code supposes. I have found it when a test in the lab has failed to set the priority and asserted in this code, but reported errno as 0. Also fix the flaky DuplicateHandle test7 that was failing rarely due to the fact that the secondary thread it has created didn't wait until the main thread finished fiddling with the priority of that thread.
Diffstat (limited to 'src/pal/tests')
-rw-r--r--src/pal/tests/palsuite/threading/DuplicateHandle/test7/test7.cpp33
1 files changed, 31 insertions, 2 deletions
diff --git a/src/pal/tests/palsuite/threading/DuplicateHandle/test7/test7.cpp b/src/pal/tests/palsuite/threading/DuplicateHandle/test7/test7.cpp
index 0477291922..bd09283b74 100644
--- a/src/pal/tests/palsuite/threading/DuplicateHandle/test7/test7.cpp
+++ b/src/pal/tests/palsuite/threading/DuplicateHandle/test7/test7.cpp
@@ -25,6 +25,7 @@ int __cdecl main(int argc, char* argv[])
HANDLE hDupThread;
DWORD dwThreadId = 0;
LPTHREAD_START_ROUTINE lpStartAddress = &CreateTestThread;
+ HANDLE hSyncEvent;
int threadPriority;
int duplicatePriority;
@@ -36,11 +37,25 @@ int __cdecl main(int argc, char* argv[])
return (FAIL);
}
+ LPSECURITY_ATTRIBUTES lpEventAttributes = NULL;
+ BOOL bManualReset = TRUE;
+ BOOL bInitialState = FALSE;
+ hSyncEvent = CreateEvent(lpEventAttributes,
+ bManualReset,
+ bInitialState,
+ NULL);
+
+ if (hSyncEvent == NULL)
+ {
+ Fail("ERROR:%u: Unable to create sync event.\n",
+ GetLastError());
+ }
+
/* Create a thread.*/
hThread = CreateThread(NULL, /* SD*/
(DWORD)0, /* initial stack size*/
lpStartAddress, /* thread function*/
- NULL, /* thread argument*/
+ (VOID*)hSyncEvent,/* thread argument*/
(DWORD)0, /* creation option*/
&dwThreadId); /* thread identifier*/
if (hThread == NULL)
@@ -123,6 +138,13 @@ int __cdecl main(int argc, char* argv[])
Fail("");
}
+ /* Signal the helper thread that it can shut down */
+ if (!SetEvent(hSyncEvent))
+ {
+ Fail("ERROR:%u: Failed to set event.\n",
+ GetLastError());
+ }
+
/* Wait on the original thread.*/
if((WaitForSingleObject(hThread, 100)) != WAIT_OBJECT_0)
{
@@ -136,14 +158,21 @@ int __cdecl main(int argc, char* argv[])
}
/* Clean-up thread and Terminate the PAL.*/
+ CloseHandle(hSyncEvent);
CloseHandle(hThread);
CloseHandle(hDupThread);
PAL_Terminate();
return PASS;
}
-/*Thread testing function, only return '0'*/
+/*Thread testing function*/
DWORD PALAPI CreateTestThread(LPVOID lpParam)
{
+ HANDLE hSyncEvent = (HANDLE)lpParam;
+
+ /* Wait until the main thread signals that this helper thread should shut down */
+ WaitForSingleObject(hSyncEvent, INFINITE);
+
return (DWORD)0;
}
+