Commit Graph

77 Commits

Author SHA1 Message Date
lukem a11399dd2d fix build of h_thread_local_dtor.cpp 2020-06-21 07:06:05 +00:00
martin b7244a59d8 Do not destroy mutices that failed to init - fixes a run with
PTHREAD_DIAGASSERT set to "a". Pointed out by joerg.
2020-06-11 11:40:54 +00:00
ad a1d54d8ee2 Adjust cond_timedwait_race to take account of spurious wakeups (which are
completely legit).
2020-06-10 21:46:50 +00:00
msaitoh 8012ca3f0e Remove extra semicolon. 2020-05-14 08:34:17 +00:00
kamil 8265fdce60 Fix the t_join test
For pthread_attr_get_np() attr should be initialized prior to the call by
using pthread_attr_init(3). pthread_getattr_np() does this
automatically so switch to it.
2020-01-29 13:40:23 +00:00
martin 7f7ec27799 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.
2019-08-11 11:42:23 +00:00
martin 98d251c113 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.
2019-08-10 07:36:15 +00:00
maya 36592171e1 return return atf_no_error() instead of 0 for consistency.
suggested by moritzbuhl in https://github.com/NetBSD/src/pull/11/
2019-07-09 16:24:01 +00:00
kamil a9ca1710c0 Add a complete C11 threads(3) implementation
C11 Thread support library is a portable threading C API between OSs,
similar to std::threads in the C++ world.

The library is implemented as a thin shim over POSIX interfaces.

NetBSD implements the API as a part of the POSIX threading library
(libpthread(3)).

C11 threads(3) are in the process of making them an integral part
of the POSIX standard. The interface has been implemented in major
OSs and used with stopgap libraries for older versions of them.

C11 threading library is already used (with a stopgap implementation)
in the NetBSD distribution in MESA.

Original implementation by myself from 2016.

ATF tests are new and cover almost all interfaces.

Proposed on tech-userlevel@.
2019-04-24 11:43:19 +00:00
christos f0d208fdc0 add joins 2019-03-06 01:20:15 +00:00
uwe cd711bd2b9 Simplify - it's enough to set nctx.uc_link to &octx to restore old
context automatically when swapfunc() returns.
2018-02-28 21:36:50 +00:00
uwe 5eea33881e Add missing $ in the RCSID. 2018-02-28 21:29:10 +00:00
uwe da83da02db threadfunc - we do return from swapcontext() (since revision 1.2),
so drop the NOTREACHED comment.
2018-02-27 20:34:04 +00:00
uwe 02b9aeb870 swapfunc() is not passed to pthread_create, there's no need for it to
have any arguments.
2018-02-27 20:31:35 +00:00
uwe 738b2ab23a Drop unnecessary cast to makecontext() argument. 2018-02-27 20:24:50 +00:00
uwe 79bd7f2c4b Cleanup trailing whitespace. 2018-02-27 20:22:31 +00:00
kre e55c81dc8f Since there has been no objection (or even comment) in response
to my message on tech-userlevel ...

    Subject: tests/lib/libpthread/t_mutex:mutex6
    Date: Thu, 23 Nov 2017 17:34:54 +0700
    Message-ID: <28385.1511433294@andromeda.noi.kre.to>

which can be found at:
	http://mail-index.netbsd.org/tech-userlevel/2017/11/23/msg011010.html

which analysed the mutex6 test case of this test, and concluded
that it was useless, nonsense, and broken (the whole test is just a
race - not even really using or testing mutexes), let it be henceforth
forever gone.
2017-12-01 13:25:29 +00:00
ginsbach af29f831e2 PR/49003: Ngie Cooper: add <sys/time.h> 2017-08-25 22:59:47 +00:00
joerg e5678be828 Implement __cxa_thread_atexit and __cxa_thread_atexit_impl. This
functions are used for destructors of thread_local objects.

If a pending destructor exists, prevent unloading of shared objects.
Introduce __dl_cxa_refcount interface for this purpose. When the last
reference is gone and the object has been dlclose'd before, the
unloading is finalized.

Ideally, __cxa_thread_atexit_impl wouldn't exist, but libstdc++ insists
on providing __cxa_thread_atexit as direct wrapper without further
patching.
2017-07-11 15:21:31 +00:00
joerg 5f391f4ae2 Export the guard size of the main thread via vm.guard_size. Add a
complementary writable sysctl for the initial guard size of threads
created via pthread_create. Let the existing attribut accessors do the
right thing. Raise the default guard size for threads to 64KB.
2017-07-02 16:41:32 +00:00
martin 75bf572ad0 Make the mutex6 test (which fails every know and then, but too rarely
to actually debug it) print some debug info when failing.
2017-04-01 17:19:40 +00:00
martin 44424683d9 Avoid using an uninitialized mutex. 2017-03-23 08:31:00 +00:00
chs 36c31375b6 reenable mutex2 and mutex3 on powerpc now that PR 44387 is fixed. 2017-03-05 16:08:23 +00:00
christos acb4286257 beware of your shadow 2017-01-16 19:07:06 +00:00
christos 78c0e08e9b PR/51885: Ngie Cooper: Add delays to avoid races. 2017-01-16 16:29:54 +00:00
christos 2d6ff91c6a PR/51884: Ngie Cooper: Include and message fixes 2017-01-16 16:29:19 +00:00
christos 9ac9a14dec PR/51886: Ngie Cooper: Use _exit instead of exit 2017-01-16 16:28:27 +00:00
christos 75e7228cd4 PR/51887: Ngie Cooper: Include and error message fixes 2017-01-16 16:27:43 +00:00
christos 138b5d077b PR/51890: Ngie Cooper: include and error message fixes. 2017-01-16 16:27:06 +00:00
christos ab92520e8c PR/51888: Ngie Cooper: more error checking, missing includes 2017-01-16 16:23:41 +00:00
christos 17284898e1 PR/51889: Ngie Cooper: add sys/time.h 2017-01-16 16:22:22 +00:00
christos b6bcbcb52f more tests from kamil 2016-10-31 23:51:20 +00:00
christos 73f2b871c9 fix typos 2016-10-31 16:23:03 +00:00
christos 179c7d3b31 Merge and fix the timed mutex tests to use absolute time.
NB: the new tests are broken?
2016-10-31 16:21:23 +00:00
kamil 53e134ea9e Add new test t_timedmutex
This test is a clone on t_mutex with additional two tests for timed-mutex
specific block.

All simple-mutex (not with the timed property according to the C11 wording)
specific tests are covered by pthread_mutex_timedlock(3) with parameter
ts_lengthy of sufficiently large tv_sec value (right now UINT16_MAX). If,
a test will hang, it won't wait UINT16_MAX seconds, but will be terminated
within the default timeout for ATF tests (right now 300 [sec] in my
NetBSD/amd64 setup).

This test was inspired by a classic selflock test failure of
pthread_mutex_timedlock(3) of the following form:

#include <assert.h>
#include <errno.h>
#include <pthread.h>
#include <stdio.h>
#include <time.h>

int main(int argc, char **argv)
{
	pthread_mutex_t mtx;
        struct timespec ts;

        ts.tv_sec = 0;
        ts.tv_nsec = 1000;
        printf("ts{.tv_sec = %d, .tv_nsec=%ld}\n", ts.tv_sec, ts.tv_nsec);
        fflush(stdout);

        printf("mtx_init\n");
	assert(pthread_mutex_init(&mtx, NULL) == 0);

        printf("mtx_lock\n");
	assert(pthread_mutex_lock(&mtx) == 0);

        printf("mtx_timedlock\n");
	assert(pthread_mutex_timedlock(&mtx, &ts) == ETIMEDOUT);

        printf("mtx_unlock\n");
	assert(pthread_mutex_unlock(&mtx) == 0);

	printf("mtx_destroy\n");
        assert(pthread_mutex_destroy(&mtx) == 0);

	return 0;
}

Current NetBSD implementation wrongly hangs on this test.

The issue was detected during development of the C11 portable threads.

My local tests in chroot presents that the are further issues:

t_timedmutex (21/25): 10 test cases
    mutex1: [0.001142s] Failed: /usr/src/tests/lib/libpthread/t_timedmutex.c:75: *param != 20
    mutex2: [0.261499s] Passed.
    mutex3: [0.261496s] Passed.
    mutex4: [0.001204s] Failed: /usr/src/tests/lib/libpthread/t_timedmutex.c:265: pthread_mutex_timedlock(&mutex, &ts_lengthy): Connection timed out
    mutex5: [0.001235s] Failed: /usr/src/tests/lib/libpthread/t_timedmutex.c:337: pthread_mutex_timedlock(&mutex5, &ts_lengthy): Connection timed out
    mutex6: [21.218497s] Failed: /usr/src/tests/lib/libpthread/t_timedmutex.c:512: start != 1
    mutexattr1: [0.001328s] Passed.
    mutexattr2: [0.001175s] Passed.
    timedmutex1: [301.119397s] Failed: Test case timed out after 300 seconds
    timedmutex2: [301.123081s] Failed: Test case timed out after 300 seconds
[623.990659s]

I'm also receiveing the same failure in the mutex6 test in t_mutex, so
there might be a false positives due to local chroot(8) issues.

Commit approved by <christos>.
2016-10-30 16:17:16 +00:00
christos 59c5c6b5ef we require root for sched_fifo, and more verbose messages. 2016-07-31 13:01:29 +00:00
christos 82732dd294 fix uninitialized var. 2016-07-06 14:42:53 +00:00
christos 7cf7644fc7 GSoC 2016 Charles Cui: Implement thread priority protection based on work
by Andy Doran. Also document the get/set pshared thread calls as not
implemented, and add a skeleton implementation that is disabled.
XXX: document _sched_protect(2).
2016-07-03 14:24:58 +00:00
pooka aba7ab9c93 Check that PTHREAD_RWLOCK_INITIALIZER works. 2015-06-26 11:07:20 +00:00
justin 97c0a6f647 PR misc/49356 remove unnecessary references to atf-c/config.h
The function included via this header is not used and is removed in
later versions of atf, so let us avoid it.
2014-11-04 00:20:19 +00:00
gson 35cbd4f0ac The cond_timedwait_race test case is no longer expected to fail; it
has been consistently passing since CVS date 2014.01.31.19.22.00.
See also PR lib/44756.
2014-09-03 16:23:24 +00:00
bouyer 18d9435662 Go back to the initial context (as tests/lib/libc/sys/t_swapcontext.c does)
after checking pthread_self() didn't change. Otherwise the process exits
outside of atf context.
Should fix "Test case exited normally but failed to create the results file: Results file is empty" reports from atf-run.
2014-08-25 16:31:15 +00:00
jmmv e110dcc954 Use compiler builtins instead of atf_arch and atf_machine.
The atf_arch and atf_machine configuration variables were removed from
atf-0.19 without me realizing that some tests were querying them directly.

Instead of reintroducing those variables, just rely on compiler builtins
as many other tests already do.

Should fix PR bin/48582.
2014-02-09 21:26:07 +00:00
christos d56fcfc956 fix unused variable warnings 2013-10-19 17:45:00 +00:00
christos 1e97173517 loosen the test only for qemu. 2013-04-12 17:18:11 +00:00
gson 44da6cec61 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.
2013-04-12 14:21:52 +00:00
christos 3993b5d374 fix printf formats 2013-03-29 02:32:38 +00:00
christos dd14258bb5 Add pthread_cond_timedwait(3) test from PR/47703 2013-03-28 18:50:01 +00:00
christos a4ddc2c8fb new dlopen tests for libpthread from manu@ 2013-03-21 16:50:21 +00:00
jmmv 33af199a4a Try to trigger the cond_timedwait_race race several times.
Sometime this tests passes (after all, it's exercising a race condition) and
when it does it's reported as a failure.  By giving the test a few chances
to expose the problem, we prevent this noisy signal.  When the race is really
addressed, this will start failing consistently as expected.
2013-03-17 05:13:13 +00:00