Home | History | Annotate | Download | only in libpthread
History log of /src/tests/lib/libpthread/t_condwait.c
RevisionDateAuthorComments
 1.10  11-Dec-2022  kre This test makes (made) a false assumption about the way that
process scheduling works. That a process (or in this case,
a thread) is no longer blocked at time T does not mean that it
will resume execution at time T. The OS is free to devote
resources to other processes/threads instead - all we should
normally be able to expect is that if it is not unblocked before
time T, that it will not start running before then.

In general though, the pthread_cond_*wait() functions don't guarantee
even that - but for this test, the possibility of something else
randomly signalling the condvar isn't believable, so don't worry about
that possibility (but do fail without calling strerror(0) on the off
chance it does happen).

Once we cease testing that the process resumed running before some
particular time, we can stop dealing with qemu timekeeping issues,
it might (seem to) take qemu twice as long as was requested before
the thread resumes, but that's OK - the same thing could happen on
a loaded system for other reasons.

Beyond that, the test also has (had) a race condition. When using
CLOCK_REALTIME though that clock needed to have advanced to T before
the ETIMEDOUT should happen, there is no guarantee that it will stay >T
(CLOCK_REALTIME is allowed to be reset backwards). So, only test
that the current time (after ETIMEDOUT) >= T when we're using
CLOCK_MONOTONIC - for CLOCK_REALTIME the time might have stepped
back between when the ETIMEDOUT happened and when the thread
obtains the current clock reading. For that case, all we can test
is that the ETIMEDOUT actually happens.

With much of what was there now gone, the code can be simplified,
we no longer need to do timespec arithmetic, just one comparison
(simpler to test that Tend >= Tstart+period than Tend-Tstart > period
as we need Tstart+period for the abstime value for the timeout anyway).

Note that this still tests for the issue reported in PR lib/47703
which is where the test came from in the first place.

ps: we seem to be missing pthread_cond_clockwait() which is the same
as pthread_cond_timedwait() except that the clock to use is passed
as a parameter, rather than as an attribute of the condition variable.
 1.9  16-Apr-2022  andvar fix various typos in comments and log messages.
 1.8  11-Aug-2019  martin Re-enable the QEMU specific timing limits, but only an increased upper
limit for now - let's see if that works on the test-bed.
 1.7  10-Aug-2019  martin PR lib/54440: adapt the FreeBSD change to this test and calculate time
differences more exact, allowing between 0 and 1 s delay between the
expected wakeup and the actual event happening.
Also convert the QEMU special case code to the same scheme, but for now
disable it (with XXX mark) and see if the proper timing limits fix that
case too.
If not, we will re-enable the QEMU special case.
 1.6  09-Jul-2019  maya return return atf_no_error() instead of 0 for consistency.

suggested by moritzbuhl in https://github.com/NetBSD/src/pull/11/
 1.5  16-Jan-2017  christos branches: 1.5.12;
PR/51884: Ngie Cooper: Include and message fixes
 1.4  12-Apr-2013  christos branches: 1.4.2; 1.4.8; 1.4.14; 1.4.18;
loosen the test only for qemu.
 1.3  12-Apr-2013  gson Make cond_wait_mono and cond_wait_real tests accept a wait time in the
range of 90% to 250% of nominal, to allow the test to pass under qemu
which has a known issue where timing can be off by a factor of two.
 1.2  29-Mar-2013  christos fix printf formats
 1.1  28-Mar-2013  christos Add pthread_cond_timedwait(3) test from PR/47703
 1.4.18.1  21-Apr-2017  bouyer Sync with HEAD
 1.4.14.1  20-Mar-2017  pgoyette Sync with HEAD
 1.4.8.2  22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.4.8.1  12-Apr-2013  yamt file t_condwait.c was added on branch yamt-pagecache on 2014-05-22 11:42:22 +0000
 1.4.2.2  23-Jun-2013  tls resync from head
 1.4.2.1  12-Apr-2013  tls file t_condwait.c was added on branch tls-maxphys on 2013-06-23 06:28:57 +0000
 1.5.12.1  13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411

RSS XML Feed