Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test and Potential Fix for Issue #363 Native Windows Condition Variables do not set errno to ETIME #364

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions ACE/ace/OS_NS_Thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1623,7 +1623,15 @@ ACE_OS::cond_timedwait (ACE_cond_t *cv,
ACE_OSCALL (ACE_ADAPT_RETVAL (::SleepConditionVariableCS (cv, external_mutex, msec_timeout),
result),
int, -1, result);

// Make sure we mutate errno if required
if (result == -1)
{
ACE_FAIL_RETURN(result);
}

return result;

#else
// Prevent race conditions on the <waiters_> count.
if (ACE_OS::thread_mutex_lock (&cv->waiters_lock_) != 0)
Expand Down
1 change: 1 addition & 0 deletions ACE/ace/OS_NS_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
case ERROR_FILE_EXISTS: errno = EEXIST; break; \
case ERROR_SHARING_VIOLATION: errno = EACCES; break; \
case ERROR_PATH_NOT_FOUND: errno = ENOENT; break; \
case ERROR_TIMEOUT: errno = ETIME; break; \
} \
return RESULT; } while (0)

Expand Down
47 changes: 47 additions & 0 deletions ACE/tests/Native_Condition_Variable_Test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

//=============================================================================
/**
* @file Native_Condition_Variable_Test.cpp
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would propose to remove Native_ from the name of this test, it just tests the condition variable behavior on any platform

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, I will probably change it to something like Condition_Variable_Timeout_Test.

*
* This program tests the support of Native Condition Variables on
* Microsoft Windows. It checks that errno is correctly mutated to
* ensure return and errno values are consistent across implementations
* using ACE_Condition.
*
* @author Michael Mathers <[email protected]>
*/
//=============================================================================


#include "test_config.h"
#include "ace/Condition_T.h"
#include "ace/Guard_T.h"


int
run_main(int, ACE_TCHAR *[])
{
ACE_START_TEST(ACE_TEXT("Native_Condition_Variable_Test"));

ACE_SYNCH_MUTEX mutex;
ACE_Condition<ACE_SYNCH_MUTEX> cond(mutex);
ACE_Time_Value timeout(1, 0);
bool condition = false; // Condition we are waiting on - will never changed (never intentionally signalled)
int result = 0;

// Place the wait within a loop such that we don't just pass on account of a spurious wakeup
while (!condition && !(result == -1))
{
ACE_Guard<ACE_SYNCH_MUTEX> guard(mutex);
result = cond.wait(&timeout);
}

// We should've timed out waiting for the condition variable to be signalled
// Expected behavior is to return -1 and have errno set to ETIME
// Note that native Windows condition variable will set errno to ERROR_TIMEOUT instead (mutation required)
ACE_TEST_ASSERT(result == -1);
ACE_TEST_ASSERT(ACE_OS::last_error() == ETIME);

ACE_END_TEST;
return 0;
}
1 change: 1 addition & 0 deletions ACE/tests/run_test.lst
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ Monotonic_Task_Test: !ACE_FOR_TAO
Multicast_Test: !ST !NO_MCAST !nsk !LynxOS !LabVIEW_RT
Multihomed_INET_Addr_Test: !ACE_FOR_TAO
Naming_Test: !NO_OTHER !LynxOS !VxWorks !nsk !ACE_FOR_TAO !PHARLAP
Native_Condition_Variable_Test
Network_Adapters_Test: !ACE_FOR_TAO
New_Fail_Test: ALL !DISABLED
NonBlocking_Conn_Test
Expand Down
9 changes: 9 additions & 0 deletions ACE/tests/tests.mpc
Original file line number Diff line number Diff line change
Expand Up @@ -2236,3 +2236,12 @@ project(Missing_Svc_Conf_Test) : acetest {
Missing_Svc_Conf_Test.cpp
}
}


project(Native_Condition_Variable_Test) : acetest {
exename = *
Source_Files {
Native_Condition_Variable_Test.cpp
}
}