summaryrefslogtreecommitdiff
path: root/src/pal/tests/palsuite/threading/ReleaseMutex/test3/ReleaseMutex.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/pal/tests/palsuite/threading/ReleaseMutex/test3/ReleaseMutex.cpp')
-rw-r--r--src/pal/tests/palsuite/threading/ReleaseMutex/test3/ReleaseMutex.cpp103
1 files changed, 103 insertions, 0 deletions
diff --git a/src/pal/tests/palsuite/threading/ReleaseMutex/test3/ReleaseMutex.cpp b/src/pal/tests/palsuite/threading/ReleaseMutex/test3/ReleaseMutex.cpp
new file mode 100644
index 0000000000..5f6adb0419
--- /dev/null
+++ b/src/pal/tests/palsuite/threading/ReleaseMutex/test3/ReleaseMutex.cpp
@@ -0,0 +1,103 @@
+// 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: ReleaseMutex/test3/ReleaseMutex.c
+**
+** Purpose: Test failure code for ReleaseMutex.
+**
+** Dependencies: CreateMutex
+** ReleaseMutex
+** CreateThread
+**
+
+**
+**=========================================================*/
+
+#include <palsuite.h>
+
+DWORD dwTestResult; /* global for test result */
+
+DWORD dwThreadId; /* consumer thread identifier */
+
+HANDLE hMutex; /* handle to mutex */
+
+HANDLE hThread; /* handle to thread */
+
+/*
+ * Thread function.
+ */
+DWORD
+PALAPI
+ThreadFunction( LPVOID lpNoArg )
+{
+
+ dwTestResult = ReleaseMutex(hMutex);
+
+ return 0;
+}
+
+int __cdecl main (int argc, char **argv)
+{
+
+ if(0 != (PAL_Initialize(argc, argv)))
+ {
+ return (FAIL);
+ }
+
+ /*
+ * set dwTestResult so test fails even if ReleaseMutex is not called
+ */
+ dwTestResult = 1;
+
+ /*
+ * Create mutex
+ */
+ hMutex = CreateMutexW (
+ NULL,
+ TRUE,
+ NULL);
+
+ if ( NULL == hMutex )
+ {
+ Fail ( "hMutex = CreateMutex () - returned NULL\n"
+ "Failing Test.\nGetLastError returned %d\n", GetLastError());
+ }
+
+ /*
+ * Create ThreadFunction
+ */
+ hThread = CreateThread(
+ NULL,
+ 0,
+ ThreadFunction,
+ NULL,
+ 0,
+ &dwThreadId);
+
+ if ( NULL == hThread )
+ {
+
+ Fail ( "CreateThread() returned NULL. Failing test.\n"
+ "GetLastError returned %d\n", GetLastError());
+ }
+
+ /*
+ * Wait for ThreadFunction to complete
+ */
+ WaitForSingleObject (hThread, INFINITE);
+
+ if (dwTestResult)
+ {
+ Fail ("ReleaseMutex() test was expected to return 0.\n"
+ "It returned %d. Failing test.\n", dwTestResult );
+ }
+
+ Trace ("ReleaseMutex() test returned 0.\nTest passed.\n");
+
+ PAL_Terminate();
+ return ( PASS );
+
+}