diff options
author | ngie <ngie@FreeBSD.org> | 2014-12-31 20:13:31 +0000 |
---|---|---|
committer | ngie <ngie@FreeBSD.org> | 2014-12-31 20:13:31 +0000 |
commit | b429a2bfd1380c777b9d59e54e17886b3855073e (patch) | |
tree | f5eb9fb5c3b79a2f3a7cba500581d24f4676622d /contrib/netbsd-tests/lib/libpthread | |
parent | 155ee9c2f7fcb97a502844e0ca346b9f919b8cb2 (diff) | |
download | FreeBSD-src-b429a2bfd1380c777b9d59e54e17886b3855073e.zip FreeBSD-src-b429a2bfd1380c777b9d59e54e17886b3855073e.tar.gz |
MFC r272343,r272458,r272890,r272891,r272901,r272902,r272903,r272905,r272908,r272909,r272910,r272914,r272915,r272979,r272980,r273010,r273011,r273012,r273015,r273017,r273019,r273020,r273021,r273022,r273023,r273024,r273025,r273389,r273390,r273391,r273393,r273395,r273396,r273397,r273410,r273516,r273517,r273520,r273521,r273522,r273523,r273524,r273525,r273526,r273527,r273528,r273529,r273530,r273533,r273534,r273535,r273536,r273537,r273538,r273539,r273540,r273572,r273574,r273578,r273579,r273591,r273592,r273928,r273933,r273935,r273936,r273937,r273938,r273942,r273943,r273945,r273946,r273947,r273948,r273949,r273950,r273951,r273952,r274061,r274062,r274066,r274067,r274072,r274074,r274079,r274090,r274142,r274143,r274571,r274572,r274573,r274574,r274575,r274576,r274577,r274579,r274597,r274598,r274599,r274600,r274601,r274626,r275033,r276046,r276430:
r272343:
r272458:
Import the NetBSD test suite from ^/vendor/NetBSD/tests/09.30.2014_20.45 ,
minus the vendor Makefiles
Provide directions for how to bootstrap the vendor sources in
FREEBSD-upgrade
MFC after 2 weeks
Discussed with: rpaulo
Sponsored by: EMC / Isilon Storage Division
r272890:
Only build/run hsearch_basic and hsearch_r_basic on NetBSD
hdestroy1 is not present on FreeBSD
Sponsored by: EMC / Isilon Storage Division
r272891:
Expect SIGSEGV in lib/libc/stdlib/t_getenv:setenv_basic
See bin/189805 for more details
In collaboration with: pho
Sponsored by: EMC / Isilon Storage Division
r272901:
Disable tests that don't pass on FreeBSD due to missing support in
humanize_number(3). Bringing in additional revisions from NetBSD's
humanize_number(3) will fix the tests
Account for the fact that util.h on NetBSD is libutil.h on FreeBSD
Submitted by: pho
Sponsored by: EMC / Isilon Storage Division
r272902:
Add missing #include <sys/time.h> for gettimeofday
Sponsored by: EMC / Isilon Storage Division
r272903:
FreeBSD returns ENOTTY instead of EBADF in ttyname_r; mark it as an expected
failure
PR: 191936
In collaboration with: pho
Sponsored by: EMC / Isilon Storage Division
r272905:
FreeBSD doesn't support strings greater than MAXHOSTNAMELEN-1 in
{get,set}{domain,host}name. Adjust the tests to not exceed that
value when testing out the code
Add a positive and negative test for MAXHOSTNAMELEN-1 and
MAXHOSTNAMELEN, respectively
PR: 181127
In collaboration with: pho
Sponsored by: EMC / Isilon Storage Division
r272908:
Disable the invalid pointer test on FreeBSD
FreeBSD segfaults on invalid pointers passed to getcwd because it throbs the
address passed in in libc, whereas NetBSD just passes the information off to
the syscall, which allows the kernel to return EFAULT on bad pointers.
In collaboration with: pho
Sponsored by: EMC / Isilon Storage Division
r272909:
Handle getting/setting niceness/priority correctly on FreeBSD vs NetBSD
This might be fallout from PR: 189821
Submitted by: pho
Sponsored by: EMC / Isilon Storage Division
r272910:
SIGPWR does not exist on FreeBSD
Sponsored by: EMC / Isilon Storage Division
r272914:
Skip over t_spawn_open_nonexistent_diag because it requires NetBSD specific
additions to posix_spawn
Sponsored by: EMC / Isilon Storage Division
r272915:
Port the testcase to FreeBSD
- Make #include path to h_macros.h a non-relative path
- __gl_stat_t is synonymous with struct stat on FreeBSD
- FreeBSD doesn't have _DIRENT_RECLEN
- Skip over glob_star on FreeBSD (testcase doesn't pass)
In collaboration with: pho
Sponsored by: EMC / Isilon Storage Division
r272979:
Only #include <sys/tls.h> on NetBSD
Sponsored by: EMC / Isilon Storage Division
r272980:
#include libutil.h for fparseln on FreeBSD
Sponsored by: EMC / Isilon Storage Division
r273010:
Implement 64MB memory limit for test to ensure that it fails reliably in
600 seconds; it would previously fail inconsistently when run in some virtual
machine configurations
This patch might need to be reverted or revisited later (see the attached PR
for more details)
PR: 169302
Submitted by: pho
Sponsored by: EMC / Isilon Storage Division
r273011:
Fix compilation errors with missing wide-type headers and fix compilation
warnings with -Wformat
In collaboration with: pho
Sponsored by: EMC / Isilon Storage Division
r273012:
- Add libutil #include for fparseln
- Change ATF_REQUIRE_EQ_MSG to ATF_CHECK_EQ_MSG to gather all failing results
possible (currently 12 with leftassoc)
- Mark leftassoc "atf_tc_expect_fail" on FreeBSD (PR coming soon after further
analysis is done on the code)
In collaboration with: pho
Sponsored by: EMC / Isilon Storage Division
r273015:
Expect nice_err to fail on FreeBSD with unprivileged users
PR: 189821
Sponsored by: EMC / Isilon Storage Division
r273017:
Add #include <stdio.h> for printf
Sponsored by: EMC / Isilon Storage Division
r273019:
Do initial port of contrib/netbsd-tests/lib/libc/locale
t_io:
- Expect failures potentially related to implementation-specific knowledge of
the zh_TW.Big5 locale [*]
t_mbrtowc:
- Handle unknown locales more gracefully (do not test if the locale doesn't
exist)
- Expect failure with mbrtowc_internal dealing with Japanese locales
(potentially related to implementation detail knowledge of the ja_* locales) [*].
t_mbstowcs, t_mbtowc, t_wctomb:
- Handle unknown locales more gracefully (do not test if the locale doesn't
exist)
t_wcstod:
- Treat FreeBSD like NetBSD and Linux in the XXX: FIXME section
[*] More investigation is required to determine the root cause of the failures
Submitted by: pho
Sponsored by: EMC / Isilon Storage Division
r273020:
memmem with NUL length "needle" (aka small) strings on FreeBSD/OSX returns
NULL instead of the "haystack" value (aka big)
Submitted by: pho
Sponsored by: EMC / Isilon Storage Division
r273021:
Use 1 as a random seed, as recommended in srandom(3). Adjust the random values
accordingly
Submitted by: pho
Sponsored by: EMC / Isilon Storage Division
r273022:
Add #include <stdio.h> to get sys_nerr definition
Sponsored by: EMC / Isilon Storage Division
r273023:
__isnanl is automatically picked according to data type in <math.h>. There
isn't a need for the explicit __isnanl test
Sponsored by: EMC / Isilon Storage Division
r273024:
Only test the return value in mktime_negyear
Testing for the errno is an optional requirement according to POSIX, and
FreeBSD doesn't document that errno would be set on failure with mktime
Submitted by: pho
Sponsored by: EMC / Isilon Storage Division
r273025:
Change ATF_REQUIRE_MSG calls to ATF_CHECK_MSG to get as many errors as possible
t_strptime:common..
- Expect the testcase body as a whole to fail. Multiple PRs will be filed to
track the issues (there are 18 check failures)
t_strptime:day..
- %EA and %OA seem to be case insensitive on FreeBSD
r273389:
Port lib/libc/gen/t_siginfo to FreeBSD
- mcontext_t on FreeBSD doesn't have a __gregs field (it's split out on FreeBSD
into separate fields). In order to avoid muddying the test code with MD code,
the debugging trace info has not been implemented
- FreeBSD does not implement the si_stime and si_utime fields in siginfo_t, so
omit the debugging code that dumps the values
- sys/inttypes.h doesn't exist on FreeBSD
Sponsored by: EMC / Isilon Storage Division
r273390:
libutil.h is required for fparseln on FreeBSD
Sponsored by: EMC / Isilon Storage Division
r273391:
Add missing #include for sys/stat.h for fchmod
Sponsored by: EMC / Isilon Storage Division
r273393:
Port t_write to FreeBSD
- Mark the signo variable for the signal handle __unused
- Use limits.h instead of sys/syslimits.h (the latter does not
exist on FreeBSD)
Sponsored by: EMC / Isilon Storage Division
r273395:
Mark osi __unused so this compiles cleanly on FreeBSD
Sponsored by: EMC / Isilon Storage Division
r273396:
unlink("/") fails with EISDIR instead of EBUSY on FreeBSD; test for that
instead
Sponsored by: EMC / Isilon Storage Division
r273397:
Port t_chroot to FreeBSD
- Add missing #include sys/stat.h for mkdir(2)
- Omit the fchroot(2) tests because the support is not present on FreeBSD
Sponsored by: EMC / Isilon Storage Division
r273410:
Add sys/socket.h #include for bind(2), et al
Sponsored by: EMC / Isilon Storage Division
r273516:
Add netinet/in.h for struct sockaddr_in
Sponsored by: EMC / Isilon Storage Division
r273517:
Expect getgroups_err to fail on FreeBSD
PR: 189941
Submitted by: pho
Sponsored by: EMC / Isilon Storage Division
r273520:
Port t_pipe2.c to FreeBSD
- Omit the pipe2_nosigpipe testcase on FreeBSD (FreeBSD doesn't have
O_NOSIGPIPE).
- Convert "fcntl(n, F_CLOSEM)" to "closefrom(n)".
- Save and restore the resource limit on the number of files (RLIMIT_NOFILE).
In collaboration with: pho
Sponsored by: EMC / Isilon Storage Division
r273521:
Convert "fcntl(n, F_CLOSEM)" to "closefrom(n)"
Submitted by: pho
Sponsored by: EMC / Isilon Storage Division
r273522:
- Mark unused parameters __unused in handler
- Call sigqueue with getpid() instead of 0 -- the latter idiom appears to only
be valid on NetBSD
In collaboration with: pho
Sponsored by: EMC / Isilon Storage Division
r273523:
Add limits.h #include for LINE_MAX
Sponsored by: EMC / Isilon Storage Division
r273524:
Add sys/socket.h #include for struct sockaddr_in
Sponsored by: EMC / Isilon Storage Division
r273525:
Port t_mmap.c to FreeBSD
- Add needed headers for the testcases
- Omit mmap_block on non-NetBSD OSes
- Use "security.bsd.map_at_zero" instead of "vm.user_va0_disable"
Submitted by: pho
Sponsored by: EMC / Isilon Storage Division
r273526:
Omit the pollts testcases on FreeBSD
Sponsored by: EMC / Isilon Storage Division
r273527:
Omit all of the testcases as revoke(2) is only implemented on devfs(5)
Submitted by: pho
Sponsored by: EMC / Isilon Storage Division
r273528:
Mark signo __unused in handler(..)
Sponsored by: EMC / Isilon Storage Division
r273529:
- Omit the poll testcases on FreeBSD (they require pollts)
- Add necessary headers for the testcases
Sponsored by: EMC / Isilon Storage Division
r273530:
Add limits.h #include for INT_MAX
Sponsored by: EMC / Isilon Storage Division
r273533:
Use <atf_srcdir>/truncate_test.root_owned instead of /usr/bin/fpr as fpr does
not exist on FreeBSD
truncate_test.root_owned will be generated at build time and owned by root
In collaboration with: pho
Sponsored by: EMC / Isilon Storage Division
r273534:
- Mark sig/signo __unused
- Do not provide a relative path via #include "h_macros.h"
Sponsored by: EMC / Isilon Storage Division
r273535:
- Omit setrlimit_nthr testcase on FreeBSD (requires lwp.h, et al)
- Expect overflow with rlim_max at INT64_MAX, not UINT64_MAX (rlim_t is int64_t
on FreeBSD)
In collaboration with: pho
Sponsored by: EMC / Isilon Storage Division
r273536:
Add limits.h #include for SSIZE_MAX
Sponsored by: EMC / Isilon Storage Division
r273537:
Add limits.h #include for SSIZE_MAX
Sponsored by: EMC / Isilon Storage Division
r273538:
Fix a typo (__FreeBSD__ -> __NetBSD__ when omitting setrlimit_nthr)
r273539:
Mark signum __unused
Sponsored by: EMC / Isilon Storage Division
r273540:
Omit the mprotect_exec testcase on FreeBSD
Sponsored by: EMC / Isilon Storage Division
r273572:
- Ignore EINVAL check with mknod(path, S_IFCHR, -1) as the testcase is always
executed on a non-devfs filesystem
- Expect mknod(path, S_IFREG, 0) to fail on FreeBSD
Submitted by: pho
Sponsored by: EMC / Isilon Storage Division
r273574:
- Test for EINVAL requirement when passing an invalid flag in to msync(2)
- Expect ENOMEM instead of EFAULT when msync'ing a previously munmap'ed region
on FreeBSD
Submitted by: pho
Sponsored by: EMC / Isilon Storage Division
r273578:
- Add inttypes.h and stdint.h in lieu of int_limits.h from NetBSD
- Use #include "h_macros.h" instead of relative path analog
Sponsored by: EMC / Isilon Storage Division
r273579:
- Mark signo __unused in the signal handler function
- Effectively #if 0 out some code that does not fail on FreeBSD
In collaboration with: pho
Sponsored by: EMC / Isilon Storage Division
r273591:
Correct my previous commit:
- getrusage_utime_back succeeds reliably on FreeBSD
- getrusage_utime_zero passes/fails in a seemingly non-deterministic manner.
Skip it for now (and fix it later)
In the initial port of this testcase to FreeBSD, the results failed reliably
in the same manner as it does on NetBSD
Sponsored by: EMC / Isilon Storage Division
r273592:
- Add sys/types.h for the APIs in sys/sysctl.h
- Poke at VM_MIN_ADDRESS in machine/vmparam.h because FreeBSD doesn't have a
vm.minaddress sysctl analog
- Expect ENOMEM instead of EAGAIN in mlock_limits
- Provide mlock an mmap'ed page twice to simulate MAP_WIRED on NetBSD
In collaboration with: pho
Sponsored by: EMC / Isilon Storage Division
r273928:
Put mtree test files into a subdirectory.
Kyua 0.11 points TMPDIR to the test's work directory, and atf_check creates
auxiliary files in TMPDIR. This confuses a couple of mtree tests that were
using the work directory's root to validate the contents of the directory.
Fix the two affected tests by creating an auxiliary directory to use for
the mtree tests. (Kyua should probably do this on its own; filed bug #133
upstream to take a look at this.)
r273933:
Don't prune duplicate services in the expected output from /etc/services on
FreeBSD
Submitted by: pho
r273935:
Port tests to FreeBSD/Linux
Some of the testcases don't work outside of NetBSD, and the behavior of
ether_aton_r differs between FreeBSD, Linux, and NetBSD, and the calls to the
API need to be massaged for FreeBSD and Linux.
Submitted by: pho
r273936:
Port lib/libc/net/h_dns_server to FreeBSD
Submitted by: pho
r273937:
Port lib/libc/sys/t_dup to FreeBSD/Linux
- The requirements differ between FreeBSD/Linux when dealing with oldd/newd
being equal (both fail with EINVAL, not EBADF)
- Add an EBADF testcase
- Fix compilation issues on clang
In collaboration with: pho
r273938:
getitimer on FreeBSD returns the last set time instead of the remaining time;
test for that instead
Submitted by: pho
r273942:
Skip :sethostname_basic because it messes up the test host's hostname
Convert code from #if defined(__FreeBSD__) to #ifdef __FreeBSD__
r273943:
Port t_kevent to FreeBSD
Submitted by: pho
r273945:
Port t_mincore to FreeBSD
Mark :mincore_resid as atf_tc_expect_fail on FreeBSD because of new bug
discovered in running the tests (it succeeded from earlier on in the year to
September/October on FreeBSD, at least)
Submitted by: pho
r273946:
Port h_atexit to FreeBSD
__cxa_atexit varies between FreeBSD and NetBSD, and thus we must use pointers
instead of static fields in the BSS. More extensive discussion is included in
the source code
In collaboration with: kib
Submitted by: pho
r273947:
Expect :snprintf_posarg_error to blow up with a SIGSEGV on !NetBSD OSes
r273948:
Disable testcases 12 and 15-22 on FreeBSD
Submitted by: pho
r273949:
Add new atf_tc_expect_fail to fflush_err; this is a new (within the past couple months) bug
r273950:
Skip :fopen_regular on !NetBSD because it's a NetBSD specific test
Submitted by: pho
r273951:
Expect :sscanf_whitespace to fail on !NetBSD OSes
Submitted by: pho
r273952:
Port h_hash and t_sha2 to FreeBSD
t_sha2 contains dirty copy-paste hacks that need to be fixed with the openssh
OpenBSD compat layer
Submitted by: pho
r274061:
Port t_db.sh to FreeBSD
- The blocksize on FreeBSD is 32kB, not 64kB
- Add some detection for MK_DICT == no; /nonexistent is echoed along with
atf_skip to ensure that the test will fail if dict(..) is called in the
non-final stage of the pipeline
Submitted by: pho
r274062:
inet_network on FreeBSD returns NULL when provided "0x" to inet_network
Submitted by: pho
r274066:
Port lib/libc/ssp to FreeBSD
In most cases, the buffers and data were resized, but when dealing with the
helpers, some of the code was adjusted to fail more reliably
Submitted by: pho
r274067:
rpc_control on FreeBSD is a public-ish API (not prefixed with __), not private
like NetBSD
Submitted by: pho
r274072:
Finish off lib/libc/stdlib/t_strtod.c port by checking for "y" twice on
FreeBSD, and always assume long long double exists on FreeBSD
Submitted by: pho
r274074:
Add Makefile snippet to ease porting NetBSD testcases to FreeBSD from
contrib/netbsd-tests
This Makefile snippet handles polluting testcases with -lnetbsd, specific
headers for ATF version differences, and does necessary rewriting for the
testcases to match the format discussed on the TestSuite wiki page
(t_<foo> -> <foo>_test)
One must define SRCTOP (inspired by projects/bmake), OBJTOP, and TESTSRC
(e.g. contrib/netbsd-tests/lib/libc/gen) to use the Makefile snippet
Test programs are specific either via NETBSD_ATF_TESTS_C or NETBSD_ATF_TESTS_SH
C++ analogs aren't currently implemented.
The imported testcases will be cleaned up to use this Makefile snippet pseudo
"API".
r274079:
Import proper fix for misc/49356 (/usr/include/atf-c/config.h) after atf-c/config.h
was removed from the build
Pointyhat to: me (again, for not running make delete-old after running test builds)
r274090:
Fix the Jenkins test run by skipping the negative testcases earlier
The problem is that lib.libc.locale.t_io:bad_big5_wprintf was printing out
illegal Unicode characters, which causes XML parsers to bail immediately, e.g.
% kyua report-junit > ~/report.junit
% python2 -c 'import xml.dom.minidom as md; md.parse("/home/ngie/report.junit")'
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/local/lib/python2.7/xml/dom/minidom.py", line 1918, in parse
return expatbuilder.parse(file)
File "/usr/local/lib/python2.7/xml/dom/expatbuilder.py", line 924, in parse
result = builder.parseFile(fp)
File "/usr/local/lib/python2.7/xml/dom/expatbuilder.py", line 207, in parseFile
parser.Parse(buffer, 0)
xml.parsers.expat.ExpatError: not well-formed (invalid token): line 27137, column 13
r274142:
Remove expected failure from lib.libc.sys.t_mincore:mincore_resid
The failure was added based on observation seen on 11.0-CURRENT @ r273153, not
based on internal testing at EMC/Isilon
PR: 194829
Tested with the following configuration:
- amd64/i386
- 11.0-CURRENT @ r273153
- 100 times in a tight loop as root with the following commands...
-- kyua test lib/libc
-- kyua test lib/libc/sys
-- kyua test lib/libc/sys/mincore_test
r274143:
Expect lib.libc.sys.getcontext_test.setcontext_link to fail on amd64; add
additional debugging to make the underlying problem more visible
Calling setcontext(2) on amd64 as shown in the test program is failing on
amd64, not i386, with a return code of -1 and an errno of EINVAL
Further investigation is being done in the PR to determine the root cause for
the failure
PR: 194828
Tested with the following configuration:
- amd64/i386
- 11.0-CURRENT @ r273153
- 100 times in a tight loop as root with the following commands...
-- kyua test lib/libc
-- kyua test lib/libc/sys
-- kyua test lib/libc/sys/getcontext_test
r274571:
Use _exit instead of exit so the file descriptors aren't flushed twice in the
child processes
Submitted by: pho
r274572:
Only expect timeouts on powerpc with NetBSD
Submitted by: pho
r274573:
Expect :pthread_detach to fail with EINVAL instead of ESRCH on FreeBSD
PR: 191906
In collaboration with: pho
r274574:
Add pthread_np.h #include and initialize the pthread attribute on FreeBSD
Submitted by: pho
r274575:
#ifdef out a printf on !NetBSD that causes the testcase to fail when comparing
the output from the helper program
Submitted by: pho
r274576:
Port helper program to FreeBSD, similar to ../../lib/libc/stdlib/h_atexit.c
Submitted by: pho
In collaboration with: kib
r274577:
Add missing sys/time.h #include for timespecsub macro in lib/libnetbsd/sys/time.h
r274579:
Call sem_unlink on semaphores before attempting to create them
Due to the lack of uniqueness in the semaphore name, and the fact that the
tests don't have cleanup routines, an interrupted test can leave a semaphore
"laying around", causing all subsequent attempts to run the test to fail
I will file a NetBSD PR for this issue soon
r274597:
Skip the long-double epsilon checks on FreeBSD/i386
Sponsored by: EMC / Isilon Storage Division
r274598:
Reset errno to 0 before running scalbn to be sure that the tested errno is
valid
Sponsored by: EMC / Isilon Storage Division
r274599:
Alias isinff to isinf on FreeBSD
isinf on FreeBSD automatically picks the appropriate type per math.h
Sponsored by: EMC / Isilon Storage Division
r274600:
- Expect exp2_powers to fail on FreeBSD/i386
- Expect exp2_values to fail on FreeBSD due to the small epsilon
Sponsored by: EMC / Isilon Storage Division
r274601:
- Skip over the testcases that call cbrtl on platforms where LDBL_PREC == 53
(arm, mips, powerpc). This fixes the build on these platforms, based on some
ad hoc tinderbox runs I did a while ago
- Skip cast the arguments to powl as long double so powl properly interprets
those arugments at compile-time when picking the type
Sponsored by: EMC / Isilon Storage Division
r274626:
Mechanically replace #if defined(__FreeBSD__) and #if defined(__NetBSD__) with
their #ifdef equivalents for everything changed in contrib/netbsd-tests. There
are some items from the vendor tree that use #if defined(__FreeBSD__) or
#if defined(__NetBSD__) which are being left alone
Requested by: bde, rpaulo
Sponsored by: EMC / Isilon Storage Division
r275033:
Only pass 6 arguments to the 'run' function on amd64. amd64's
makecontext on FreeBSD only supports a maximum of 6 arguments. This
fixes the setcontext_link test on amd64.
PR: 194828
r276046:
Add __FreeBSD_version guards around hsearch_r to ease MFCing the code to
stable/10
It was added when __FreeBSD_version was ~1100027
r276430:
Expect access_test:access_inval to fail before __FreeBSD_version == 1100033
This will allow me to MFC the test, as jilles@ requested that I don't MFC the
access(2) KBI change to 10-STABLE in r271655
Diffstat (limited to 'contrib/netbsd-tests/lib/libpthread')
35 files changed, 4812 insertions, 0 deletions
diff --git a/contrib/netbsd-tests/lib/libpthread/d_mach b/contrib/netbsd-tests/lib/libpthread/d_mach new file mode 100644 index 0000000..f3c3981 --- /dev/null +++ b/contrib/netbsd-tests/lib/libpthread/d_mach @@ -0,0 +1,92 @@ +above.warped.net +anoncvs.cirr.com +anoncvs.isc.netbsd.org +anoncvs.leo.org +anoncvs.netbsd.lt +anoncvs.netbsd.ro +anoncvs.netbsd.se +antioche.antioche.eu.org +boulder.tele.dk +centaurus.4web.cz +chur.math.ntnu.no +cnftp.bjpu.edu.cn +console.netbsd.org +cvs.fi.netbsd.org +cvs.mikrolahti.fi +cvs.netbsd.org +cvsup-netbsd.leo.org +cvsup.netbsd.se +cvsup.pasta.cs.uit.no +ftp.bitcon.no +ftp.chg.ru +ftp.duth.gr +ftp.estpak.ee +ftp.fsn.hu +ftp.funet.fi +ftp.grondar.za +ftp.leo.org +ftp.netbsd.lt +ftp.netbsd.org +ftp.nluug.nl +ftp.plig.org +ftp.uni-erlangen.de +ftp.xgate.co.kr +gd.tuwien.ac.at +gort.ludd.luth.se +grappa.unix-ag.uni-kl.de +info.wins.uva.nl +irc.warped.net +knug.youn.co.kr +lala.iri.co.jp +mail.jp.netbsd.org +mail.kr.netbsd.org +mail.netbsd.org +melanoma.cs.rmit.edu.au +mirror.aarnet.edu.au +mirror.netbsd.com.br +mirror03.inet.tele.dk +moon.vub.ac.be +nbwww.sergei.cc +net.bsd.cz +netbsd.3miasto.net +netbsd.4ka.mipt.ru +netbsd.apk.od.ua +netbsd.csie.nctu.edu.tw +netbsd.enderunix.org +netbsd.ftp.fu-berlin.de +netbsd.netlead.com.au +netbsd.nsysu.edu.tw +netbsd.pair.com +netbsd.stevens-tech.edu +netbsd.triada.bg +netbsd.unix.net.nz +netbsd.unixtech.be +netbsd.vejas.lt +netbsd.wagener-consulting.lu +netbsd.zarco.org +netbsdiso.interoute.net.uk +netbsdwww.bitcon.no +netbsdwww.cordef.com.pl +netbsdwww.cs.rmit.edu.au +netbsdwww.interoute.net.uk +news.gw.com +ns.netbsd.org +pigu.iri.co.jp +pluto.cdpa.nsysu.edu.tw +projects.slowass.net +server6.pasta.cs.uit.no +skeleton.phys.spbu.ru +snoopy.allbsd.org +spike.allbsd.org +sundry.netbsd.org +tanya.sergei.cc +web-a.fi.gw.com +web-a.us.gw.com +web.netbsd.mirror.arhea.net +www.en.netbsd.de +www.netbsd.cl +www.netbsd.nl +www.netbsd.org +www.netbsd.ro +zathras.netbsd.org +zeppo.rediris.es diff --git a/contrib/netbsd-tests/lib/libpthread/dlopen/dso/h_pthread_dlopen.c b/contrib/netbsd-tests/lib/libpthread/dlopen/dso/h_pthread_dlopen.c new file mode 100644 index 0000000..63bf6a3 --- /dev/null +++ b/contrib/netbsd-tests/lib/libpthread/dlopen/dso/h_pthread_dlopen.c @@ -0,0 +1,86 @@ +/* $NetBSD: h_pthread_dlopen.c,v 1.1 2013/03/21 16:50:22 christos Exp $ */ +/*- + * Copyright (c) 2013 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Emmanuel Dreyfus. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__RCSID("$NetBSD: h_pthread_dlopen.c,v 1.1 2013/03/21 16:50:22 christos Exp $"); + +#if 0 +#include <atf-c.h> +#else +#include <assert.h> +#define ATF_REQUIRE(a) assert(a) +#endif +#include <unistd.h> +#include <pthread.h> + +int testf_dso_null(void); +int testf_dso_mutex_lock(pthread_mutex_t *); +int testf_dso_mutex_unlock(pthread_mutex_t *); +int testf_dso_pthread_create(pthread_t *, const pthread_attr_t *, + void *(*)(void *), void *); + +int +testf_dso_null(void) +{ + return 0xcafe; +} + +int +testf_dso_mutex_lock(pthread_mutex_t *mtx) +{ + ATF_REQUIRE(mtx != NULL); + ATF_REQUIRE(pthread_mutex_lock(mtx) == 0); + + return 0xcafe; +} + +int +testf_dso_mutex_unlock(pthread_mutex_t *mtx) +{ + ATF_REQUIRE(mtx != NULL); + ATF_REQUIRE(pthread_mutex_unlock(mtx) == 0); + + return 0xcafe; +} + +int +testf_dso_pthread_create(pthread_t *thread, const pthread_attr_t *attr, + void *(*routine)(void *), void *arg) +{ + int ret; + + ret = pthread_create(thread, attr, routine, arg); + ATF_REQUIRE(ret == 0); + + return 0; +} diff --git a/contrib/netbsd-tests/lib/libpthread/dlopen/t_dlopen.c b/contrib/netbsd-tests/lib/libpthread/dlopen/t_dlopen.c new file mode 100644 index 0000000..68e9835 --- /dev/null +++ b/contrib/netbsd-tests/lib/libpthread/dlopen/t_dlopen.c @@ -0,0 +1,171 @@ +/* $NetBSD: t_dlopen.c,v 1.1 2013/03/21 16:50:21 christos Exp $ */ +/*- + * Copyright (c) 2013 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Emmanuel Dreyfus + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__RCSID("$NetBSD: t_dlopen.c,v 1.1 2013/03/21 16:50:21 christos Exp $"); + +#include <atf-c.h> +#include <dlfcn.h> +#include <pthread.h> +#include <unistd.h> + +ATF_TC(dlopen); + +ATF_TC_HEAD(dlopen, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Test if dlopen can load -lpthread DSO"); +} + +#define DSO TESTDIR "/h_pthread_dlopen.so" + +ATF_TC_BODY(dlopen, tc) +{ + void *handle; + int (*testf_dso_null)(void); + handle = dlopen(DSO, RTLD_NOW | RTLD_LOCAL); + ATF_REQUIRE_MSG(handle != NULL, "dlopen fails: %s", dlerror()); + + testf_dso_null = dlsym(handle, "testf_dso_null"); + ATF_REQUIRE_MSG(testf_dso_null != NULL, "dlsym fails: %s", dlerror()); + + ATF_REQUIRE(testf_dso_null() == 0xcafe); + + ATF_REQUIRE(dlclose(handle) == 0); +} + +ATF_TC(dlopen_mutex); + +ATF_TC_HEAD(dlopen_mutex, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Test if dlopen can load -lpthread DSO without breaking mutex"); +} + +ATF_TC_BODY(dlopen_mutex, tc) +{ + pthread_mutex_t mtx; + void *handle; + int (*testf_dso_null)(void); + + ATF_REQUIRE(pthread_mutex_init(&mtx, NULL) == 0); + ATF_REQUIRE(pthread_mutex_lock(&mtx) == 0); + + handle = dlopen(DSO, RTLD_NOW | RTLD_LOCAL); + ATF_REQUIRE_MSG(handle != NULL, "dlopen fails: %s", dlerror()); + + testf_dso_null = dlsym(handle, "testf_dso_null"); + ATF_REQUIRE_MSG(testf_dso_null != NULL, "dlsym fails: %s", dlerror()); + + ATF_REQUIRE(testf_dso_null() == 0xcafe); + + ATF_REQUIRE(pthread_mutex_unlock(&mtx) == 0); + + ATF_REQUIRE(dlclose(handle) == 0); + + pthread_mutex_destroy(&mtx); +} + +ATF_TC(dlopen_mutex_libc); + +ATF_TC_HEAD(dlopen_mutex_libc, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Test if dlopen can load -lpthread DSO and use libc locked mutex"); +} + +ATF_TC_BODY(dlopen_mutex_libc, tc) +{ + pthread_mutex_t mtx; + void *handle; + int (*testf_dso_mutex_unlock)(pthread_mutex_t *); + + ATF_REQUIRE(pthread_mutex_init(&mtx, NULL) == 0); + ATF_REQUIRE(pthread_mutex_lock(&mtx) == 0); + + handle = dlopen(DSO, RTLD_NOW | RTLD_LOCAL); + ATF_REQUIRE_MSG(handle != NULL, "dlopen fails: %s", dlerror()); + + testf_dso_mutex_unlock = dlsym(handle, "testf_dso_mutex_unlock"); + ATF_REQUIRE_MSG(testf_dso_mutex_unlock != NULL, + "dlsym fails: %s", dlerror()); + + ATF_REQUIRE(testf_dso_mutex_unlock(&mtx) == 0xcafe); + + dlclose(handle); + + pthread_mutex_destroy(&mtx); +} + +ATF_TC(dlopen_mutex_libpthread); + +ATF_TC_HEAD(dlopen_mutex_libpthread, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Test if dlopen can load -lpthread DSO and use " + "libpthread locked mutex"); +} + +ATF_TC_BODY(dlopen_mutex_libpthread, tc) +{ + pthread_mutex_t mtx; + void *handle; + int (*testf_dso_mutex_lock)(pthread_mutex_t *); + + ATF_REQUIRE(pthread_mutex_init(&mtx, NULL) == 0); + + handle = dlopen(DSO, RTLD_NOW | RTLD_LOCAL); + ATF_REQUIRE_MSG(handle != NULL, "dlopen fails: %s", dlerror()); + + testf_dso_mutex_lock = dlsym(handle, "testf_dso_mutex_lock"); + ATF_REQUIRE_MSG(testf_dso_mutex_lock != NULL, + "dlsym fails: %s", dlerror()); + + ATF_REQUIRE(testf_dso_mutex_lock(&mtx) == 0xcafe); + + ATF_REQUIRE(pthread_mutex_unlock(&mtx) == 0); + + dlclose(handle); + + pthread_mutex_destroy(&mtx); +} + +ATF_TP_ADD_TCS(tp) +{ + ATF_TP_ADD_TC(tp, dlopen); + ATF_TP_ADD_TC(tp, dlopen_mutex); + ATF_TP_ADD_TC(tp, dlopen_mutex_libc); + ATF_TP_ADD_TC(tp, dlopen_mutex_libpthread); + + return atf_no_error(); +} diff --git a/contrib/netbsd-tests/lib/libpthread/dlopen/t_dso_pthread_create.c b/contrib/netbsd-tests/lib/libpthread/dlopen/t_dso_pthread_create.c new file mode 100644 index 0000000..ab8bec3 --- /dev/null +++ b/contrib/netbsd-tests/lib/libpthread/dlopen/t_dso_pthread_create.c @@ -0,0 +1,96 @@ +/* $NetBSD: t_dso_pthread_create.c,v 1.1 2013/03/21 16:50:21 christos Exp $ */ +/*- + * Copyright (c) 2013 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Emmanuel Dreyfus + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__RCSID("$NetBSD: t_dso_pthread_create.c,v 1.1 2013/03/21 16:50:21 christos Exp $"); + +#include <sys/resource.h> +#include <atf-c.h> +#include <dlfcn.h> +#include <pthread.h> +#include <unistd.h> + +#define DSO TESTDIR "/h_pthread_dlopen.so" + +void * +routine(void *arg) +{ + ATF_REQUIRE((intptr_t)arg == 0xcafe); + return NULL; +} + +ATF_TC(dso_pthread_create_dso); + +ATF_TC_HEAD(dso_pthread_create_dso, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Test if non -lpthread main can call pthread_create() " + "in -lpthread DSO"); +} + +ATF_TC_BODY(dso_pthread_create_dso, tc) +{ + int ret; + pthread_t thread; + void *arg = (void *)0xcafe; + void *handle; + int (*testf_dso_pthread_create)(pthread_t *, pthread_attr_t *, + void *(*)(void *), void *); + struct rlimit rl; + + atf_tc_expect_signal(6, + "calling pthread_create() requires -lpthread main"); + + rl.rlim_max = rl.rlim_cur = 0; + ATF_REQUIRE_EQ(setrlimit(RLIMIT_CORE, &rl), 0); + + handle = dlopen(DSO, RTLD_NOW | RTLD_LOCAL); + ATF_REQUIRE_MSG(handle != NULL, "dlopen fails: %s", dlerror()); + + testf_dso_pthread_create = dlsym(handle, "testf_dso_pthread_create"); + ATF_REQUIRE_MSG(testf_dso_pthread_create != NULL, + "dlsym fails: %s", dlerror()); + + ret = testf_dso_pthread_create(&thread, NULL, routine, arg); + ATF_REQUIRE(ret == 0); + + ATF_REQUIRE(dlclose(handle) == 0); + +} + +ATF_TP_ADD_TCS(tp) +{ + ATF_TP_ADD_TC(tp, dso_pthread_create_dso); + + return atf_no_error(); +} diff --git a/contrib/netbsd-tests/lib/libpthread/dlopen/t_main_pthread_create.c b/contrib/netbsd-tests/lib/libpthread/dlopen/t_main_pthread_create.c new file mode 100644 index 0000000..7ba89b3 --- /dev/null +++ b/contrib/netbsd-tests/lib/libpthread/dlopen/t_main_pthread_create.c @@ -0,0 +1,106 @@ +/* $NetBSD: t_main_pthread_create.c,v 1.1 2013/03/21 16:50:21 christos Exp $ */ +/*- + * Copyright (c) 2013 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Emmanuel Dreyfus + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__RCSID("$NetBSD: t_main_pthread_create.c,v 1.1 2013/03/21 16:50:21 christos Exp $"); + +#include <atf-c.h> +#include <dlfcn.h> +#include <pthread.h> +#include <unistd.h> + +#define DSO TESTDIR "/h_pthread_dlopen.so" + +void * +routine(void *arg) +{ + ATF_REQUIRE((intptr_t)arg == 0xcafe); + return NULL; +} + +ATF_TC(main_pthread_create_main); + +ATF_TC_HEAD(main_pthread_create_main, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Test if -lpthread main can call pthread_create() in main()"); +} + +ATF_TC_BODY(main_pthread_create_main, tc) +{ + int ret; + pthread_t thread; + void *arg = (void *)0xcafe; + + ret = pthread_create(&thread, NULL, routine, arg); + ATF_REQUIRE(ret == 0); +} + +ATF_TC(main_pthread_create_dso); + +ATF_TC_HEAD(main_pthread_create_dso, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Test if -lpthread main can call pthread_create() in DSO"); +} + +ATF_TC_BODY(main_pthread_create_dso, tc) +{ + int ret; + pthread_t thread; + void *arg = (void *)0xcafe; + void *handle; + int (*testf_dso_pthread_create)(pthread_t *, pthread_attr_t *, + void *(*)(void *), void *); + + handle = dlopen(DSO, RTLD_NOW | RTLD_LOCAL); + ATF_REQUIRE_MSG(handle != NULL, "dlopen fails: %s", dlerror()); + + testf_dso_pthread_create = dlsym(handle, "testf_dso_pthread_create"); + ATF_REQUIRE_MSG(testf_dso_pthread_create != NULL, + "dlsym fails: %s", dlerror()); + + ret = testf_dso_pthread_create(&thread, NULL, routine, arg); + ATF_REQUIRE(ret == 0); + + ATF_REQUIRE(dlclose(handle) == 0); + +} + +ATF_TP_ADD_TCS(tp) +{ + ATF_TP_ADD_TC(tp, main_pthread_create_main); + ATF_TP_ADD_TC(tp, main_pthread_create_dso); + + return atf_no_error(); +} diff --git a/contrib/netbsd-tests/lib/libpthread/h_atexit.c b/contrib/netbsd-tests/lib/libpthread/h_atexit.c new file mode 100644 index 0000000..29b8775 --- /dev/null +++ b/contrib/netbsd-tests/lib/libpthread/h_atexit.c @@ -0,0 +1,203 @@ +/* $NetBSD: h_atexit.c,v 1.1 2010/07/16 15:42:53 jmmv Exp $ */ + +/* + * Copyright (c) 2008 The NetBSD Foundation, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Program to test atexit(3) and __cxa_atexit()/__cxa_finalize(). + * + * Written by Jason R. Thorpe, February 2003. + * Public domain. + */ + +#include <sys/cdefs.h> +__COPYRIGHT("@(#) Copyright (c) 2008\ + The NetBSD Foundation, inc. All rights reserved."); +__RCSID("$NetBSD: h_atexit.c,v 1.1 2010/07/16 15:42:53 jmmv Exp $"); + +#include <stdio.h> +#include <stdlib.h> +#include <signal.h> +#include <string.h> +#include <unistd.h> + +extern int __cxa_atexit(void (*func)(void *), void *, void *); +extern void __cxa_finalize(void *); + +#ifdef __FreeBSD__ +/* + * See comments in ../../lib/libc/stdlib/h_atexit.c about the deviation + * between FreeBSD and NetBSD with this helper program + */ +static void *dso_handle_1 = (void *)1; +static void *dso_handle_2 = (void *)2; +static void *dso_handle_3 = (void *)3; +#else +static int dso_handle_1; +static int dso_handle_2; +static int dso_handle_3; +#endif + +static int arg_1; +static int arg_2; +static int arg_3; + +static int exiting_state; + +#define ASSERT(expr) \ +do { \ + if ((expr) == 0) { \ + write(STDERR_FILENO, __func__, strlen(__func__)); \ + write(STDERR_FILENO, ": ", 2); \ + write(STDERR_FILENO, __STRING(expr), \ + strlen(__STRING(expr))); \ + write(STDERR_FILENO, "\n", 1); \ + my_abort(); \ + } \ +} while (/*CONSTCOND*/0) + +#define SUCCESS() \ +do { \ + write(STDOUT_FILENO, __func__, strlen(__func__)); \ + write(STDOUT_FILENO, "\n", 1); \ +} while (/*CONSTCOND*/0) + +static void +my_abort(void) +{ + + kill(getpid(), SIGABRT); + /* NOTREACHED */ +} + +static void +cxa_handler_5(void *arg) +{ + static int cxa_handler_5_called; + + ASSERT(arg == (void *)&arg_1); + ASSERT(cxa_handler_5_called == 0); + ASSERT(exiting_state == 5); + + exiting_state--; + cxa_handler_5_called = 1; + SUCCESS(); +} + +static void +cxa_handler_4(void *arg) +{ + static int cxa_handler_4_called; + + ASSERT(arg == (void *)&arg_1); + ASSERT(cxa_handler_4_called == 0); + ASSERT(exiting_state == 4); + + exiting_state--; + cxa_handler_4_called = 1; + SUCCESS(); +} + +static void +cxa_handler_3(void *arg) +{ + static int cxa_handler_3_called; + + ASSERT(arg == (void *)&arg_2); + ASSERT(cxa_handler_3_called == 0); + ASSERT(exiting_state == 3); + + exiting_state--; + cxa_handler_3_called = 1; + SUCCESS(); +} + +static void +cxa_handler_2(void *arg) +{ + static int cxa_handler_2_called; + + ASSERT(arg == (void *)&arg_3); + ASSERT(cxa_handler_2_called == 0); + ASSERT(exiting_state == 2); + + exiting_state--; + cxa_handler_2_called = 1; + SUCCESS(); +} + +static void +normal_handler_1(void) +{ + static int normal_handler_1_called; + + ASSERT(normal_handler_1_called == 0); + ASSERT(exiting_state == 1); + + exiting_state--; + normal_handler_1_called = 1; + SUCCESS(); +} + +static void +normal_handler_0(void) +{ + static int normal_handler_0_called; + + ASSERT(normal_handler_0_called == 0); + ASSERT(exiting_state == 0); + + normal_handler_0_called = 1; + SUCCESS(); +} + +int +main(int argc, char *argv[]) +{ + + exiting_state = 5; + +#ifdef __FreeBSD__ + ASSERT(0 == atexit(normal_handler_0)); + ASSERT(0 == atexit(normal_handler_1)); + ASSERT(0 == __cxa_atexit(cxa_handler_4, &arg_1, dso_handle_1)); + ASSERT(0 == __cxa_atexit(cxa_handler_5, &arg_1, dso_handle_1)); + ASSERT(0 == __cxa_atexit(cxa_handler_3, &arg_2, dso_handle_2)); + ASSERT(0 == __cxa_atexit(cxa_handler_2, &arg_3, dso_handle_3)); + + __cxa_finalize(dso_handle_1); + __cxa_finalize(dso_handle_2); +#else + ASSERT(0 == __cxa_atexit(cxa_handler_4, &arg_1, &dso_handle_1)); + ASSERT(0 == __cxa_atexit(cxa_handler_5, &arg_1, &dso_handle_1)); + ASSERT(0 == __cxa_atexit(cxa_handler_3, &arg_2, &dso_handle_2)); + ASSERT(0 == __cxa_atexit(cxa_handler_2, &arg_3, &dso_handle_3)); + + __cxa_finalize(&dso_handle_1); + __cxa_finalize(&dso_handle_2); +#endif + exit(0); +} diff --git a/contrib/netbsd-tests/lib/libpthread/h_cancel.c b/contrib/netbsd-tests/lib/libpthread/h_cancel.c new file mode 100644 index 0000000..b7a9363 --- /dev/null +++ b/contrib/netbsd-tests/lib/libpthread/h_cancel.c @@ -0,0 +1,60 @@ +/* $NetBSD: h_cancel.c,v 1.1 2010/07/16 15:42:53 jmmv Exp $ */ + +/* + * Copyright (c) 2008 The NetBSD Foundation, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__COPYRIGHT("@(#) Copyright (c) 2008\ + The NetBSD Foundation, inc. All rights reserved."); +__RCSID("$NetBSD: h_cancel.c,v 1.1 2010/07/16 15:42:53 jmmv Exp $"); + +#include <stdio.h> +#include <stdlib.h> +#include <pthread.h> +#include <unistd.h> + +int +main(void) +{ + char str1[] = "You should see this.\n"; + char str2[] = "You should not see this.\n"; + +#ifdef __NetBSD__ + printf("Cancellation test: Self-cancellation and disabling.\n"); +#endif + + pthread_cancel(pthread_self()); + + pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL); + + write(STDOUT_FILENO, str1, sizeof(str1)-1); + + pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); + + write(STDOUT_FILENO, str2, sizeof(str2)-1); + + exit(1); +} diff --git a/contrib/netbsd-tests/lib/libpthread/h_common.h b/contrib/netbsd-tests/lib/libpthread/h_common.h new file mode 100644 index 0000000..f4d03bc --- /dev/null +++ b/contrib/netbsd-tests/lib/libpthread/h_common.h @@ -0,0 +1,12 @@ +#ifndef H_COMMON_H +#define H_COMMON_H + +#include <string.h> + +#define PTHREAD_REQUIRE(x) \ + do { \ + int ret = (x); \ + ATF_REQUIRE_MSG(ret == 0, "%s: %s", #x, strerror(ret)); \ + } while (0) + +#endif // H_COMMON_H diff --git a/contrib/netbsd-tests/lib/libpthread/h_exit.c b/contrib/netbsd-tests/lib/libpthread/h_exit.c new file mode 100644 index 0000000..a37f88f --- /dev/null +++ b/contrib/netbsd-tests/lib/libpthread/h_exit.c @@ -0,0 +1,47 @@ +/* $NetBSD: h_exit.c,v 1.1 2010/07/16 15:42:53 jmmv Exp $ */ + +/* + * Copyright (c) 2008 The NetBSD Foundation, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__COPYRIGHT("@(#) Copyright (c) 2008\ + The NetBSD Foundation, inc. All rights reserved."); +__RCSID("$NetBSD: h_exit.c,v 1.1 2010/07/16 15:42:53 jmmv Exp $"); + +#include <stdio.h> +#include <stdlib.h> +#include <pthread.h> + +int +main(void) +{ + printf("Test of pthread_exit() in main thread only.\n"); + + pthread_exit(NULL); + + printf("You shouldn't see this."); + exit(1); +} diff --git a/contrib/netbsd-tests/lib/libpthread/h_resolv.c b/contrib/netbsd-tests/lib/libpthread/h_resolv.c new file mode 100644 index 0000000..9c5fedc --- /dev/null +++ b/contrib/netbsd-tests/lib/libpthread/h_resolv.c @@ -0,0 +1,208 @@ +/* $NetBSD: h_resolv.c,v 1.2 2010/11/03 16:10:22 christos Exp $ */ + +/*- + * Copyright (c) 2004, 2008 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Christos Zoulas. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__COPYRIGHT("@(#) Copyright (c) 2008\ + The NetBSD Foundation, inc. All rights reserved."); +__RCSID("$NetBSD: h_resolv.c,v 1.2 2010/11/03 16:10:22 christos Exp $"); + +#include <pthread.h> +#include <stdio.h> +#include <netdb.h> +#include <stdlib.h> +#include <unistd.h> +#include <err.h> +#include <string.h> +#include <stringlist.h> + +#define NTHREADS 10 +#define NHOSTS 100 +#define WS " \t\n\r" + +static StringList *hosts = NULL; +static int debug = 0; +static int *ask = NULL; +static int *got = NULL; + +static void usage(void) __attribute__((__noreturn__)); +static void load(const char *); +static void resolvone(int); +static void *resolvloop(void *); +static void run(int *); + +static pthread_mutex_t stats = PTHREAD_MUTEX_INITIALIZER; + +static void +usage(void) +{ + (void)fprintf(stderr, + "Usage: %s [-d] [-h <nhosts>] [-n <nthreads>] <file> ...\n", + getprogname()); + exit(1); +} + +static void +load(const char *fname) +{ + FILE *fp; + size_t len; + char *line; + + if ((fp = fopen(fname, "r")) == NULL) + err(1, "Cannot open `%s'", fname); + while ((line = fgetln(fp, &len)) != NULL) { + char c = line[len]; + char *ptr; + line[len] = '\0'; + for (ptr = strtok(line, WS); ptr; ptr = strtok(NULL, WS)) + sl_add(hosts, strdup(ptr)); + line[len] = c; + } + + (void)fclose(fp); +} + +static void +resolvone(int n) +{ + char buf[1024]; + pthread_t self = pthread_self(); + size_t i = (random() & 0x0fffffff) % hosts->sl_cur; + char *host = hosts->sl_str[i]; + struct addrinfo *res; + int error, len; + if (debug) { + len = snprintf(buf, sizeof(buf), "%p: %d resolving %s %d\n", + self, n, host, (int)i); + (void)write(STDOUT_FILENO, buf, len); + } + error = getaddrinfo(host, NULL, NULL, &res); + if (debug) { + len = snprintf(buf, sizeof(buf), "%p: host %s %s\n", + self, host, error ? "not found" : "ok"); + (void)write(STDOUT_FILENO, buf, len); + } + pthread_mutex_lock(&stats); + ask[i]++; + got[i] += error == 0; + pthread_mutex_unlock(&stats); + if (error == 0) + freeaddrinfo(res); +} + +static void * +resolvloop(void *p) +{ + int *nhosts = (int *)p; + if (*nhosts == 0) + return NULL; + do + resolvone(*nhosts); + while (--(*nhosts)); + return NULL; +} + +static void +run(int *nhosts) +{ + pthread_t self = pthread_self(); + if (pthread_create(&self, NULL, resolvloop, nhosts) != 0) + err(1, "pthread_create"); +} + +int +main(int argc, char *argv[]) +{ + int nthreads = NTHREADS; + int nhosts = NHOSTS; + int i, c, done, *nleft; + hosts = sl_init(); + + srandom(1234); + + while ((c = getopt(argc, argv, "dh:n:")) != -1) + switch (c) { + case 'd': + debug++; + break; + case 'h': + nhosts = atoi(optarg); + break; + case 'n': + nthreads = atoi(optarg); + break; + default: + usage(); + } + + for (i = optind; i < argc; i++) + load(argv[i]); + + if (hosts->sl_cur == 0) + usage(); + + if ((nleft = malloc(nthreads * sizeof(int))) == NULL) + err(1, "malloc"); + if ((ask = calloc(hosts->sl_cur, sizeof(int))) == NULL) + err(1, "calloc"); + if ((got = calloc(hosts->sl_cur, sizeof(int))) == NULL) + err(1, "calloc"); + + + for (i = 0; i < nthreads; i++) { + nleft[i] = nhosts; + run(&nleft[i]); + } + + for (done = 0; !done;) { + done = 1; + for (i = 0; i < nthreads; i++) { + if (nleft[i] != 0) { + done = 0; + break; + } + } + sleep(1); + } + c = 0; + for (i = 0; i < (int)hosts->sl_cur; i++) { + if (ask[i] != got[i] && got[i] != 0) { + warnx("Error: host %s ask %d got %d\n", + hosts->sl_str[i], ask[i], got[i]); + c++; + } + } + free(nleft); + free(ask); + free(got); + sl_free(hosts, 1); + return c; +} diff --git a/contrib/netbsd-tests/lib/libpthread/t_atexit.sh b/contrib/netbsd-tests/lib/libpthread/t_atexit.sh new file mode 100755 index 0000000..7b99618 --- /dev/null +++ b/contrib/netbsd-tests/lib/libpthread/t_atexit.sh @@ -0,0 +1,49 @@ +# $NetBSD: t_atexit.sh,v 1.2 2010/11/07 17:51:20 jmmv Exp $ +# +# Copyright (c) 2008 The NetBSD Foundation, Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + +atf_test_case atexit +atexit_head() +{ + atf_set "descr" "Checks atexit functionality" +} +atexit_body() +{ + cat >expout <<EOF +cxa_handler_5 +cxa_handler_4 +cxa_handler_3 +cxa_handler_2 +normal_handler_1 +normal_handler_0 +EOF + atf_check -o file:expout "$(atf_get_srcdir)/h_atexit" +} + +atf_init_test_cases() +{ + atf_add_test_case atexit +} diff --git a/contrib/netbsd-tests/lib/libpthread/t_barrier.c b/contrib/netbsd-tests/lib/libpthread/t_barrier.c new file mode 100644 index 0000000..a06cfd9 --- /dev/null +++ b/contrib/netbsd-tests/lib/libpthread/t_barrier.c @@ -0,0 +1,110 @@ +/* $NetBSD: t_barrier.c,v 1.2 2010/11/03 16:10:22 christos Exp $ */ + +/* + * Copyright (c) 2008 The NetBSD Foundation, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__COPYRIGHT("@(#) Copyright (c) 2008\ + The NetBSD Foundation, inc. All rights reserved."); +__RCSID("$NetBSD: t_barrier.c,v 1.2 2010/11/03 16:10:22 christos Exp $"); + +#include <pthread.h> +#include <stdio.h> +#include <unistd.h> + +#include <atf-c.h> + +#include "h_common.h" + +#define COUNT 5 + +pthread_barrier_t barrier; +pthread_mutex_t mutex; +int serial_count; +int after_barrier_count; + +static void * +threadfunc(void *arg) +{ + int which = (int)(long)arg; + int rv; + + printf("thread %d entering barrier\n", which); + rv = pthread_barrier_wait(&barrier); + printf("thread %d leaving barrier -> %d\n", which, rv); + + PTHREAD_REQUIRE(pthread_mutex_lock(&mutex)); + after_barrier_count++; + if (rv == PTHREAD_BARRIER_SERIAL_THREAD) + serial_count++; + PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex)); + + return NULL; +} + +ATF_TC(barrier); +ATF_TC_HEAD(barrier, tc) +{ + atf_tc_set_md_var(tc, "descr", "Checks barriers"); +} +ATF_TC_BODY(barrier, tc) +{ + int i; + pthread_t new[COUNT]; + void *joinval; + + PTHREAD_REQUIRE(pthread_mutex_init(&mutex, NULL)); + PTHREAD_REQUIRE(pthread_barrier_init(&barrier, NULL, COUNT)); + + for (i = 0; i < COUNT; i++) { + PTHREAD_REQUIRE(pthread_mutex_lock(&mutex)); + ATF_REQUIRE_EQ(after_barrier_count, 0); + PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex)); + PTHREAD_REQUIRE(pthread_create(&new[i], NULL, threadfunc, + (void *)(long)i)); + sleep(2); + } + + for (i = 0; i < COUNT; i++) { + PTHREAD_REQUIRE(pthread_join(new[i], &joinval)); + PTHREAD_REQUIRE(pthread_mutex_lock(&mutex)); + ATF_REQUIRE(after_barrier_count > i); + PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex)); + printf("main joined with thread %d\n", i); + } + + PTHREAD_REQUIRE(pthread_mutex_lock(&mutex)); + ATF_REQUIRE_EQ(after_barrier_count, COUNT); + PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex)); + ATF_REQUIRE_EQ(serial_count, 1); +} + +ATF_TP_ADD_TCS(tp) +{ + ATF_TP_ADD_TC(tp, barrier); + + return atf_no_error(); +} diff --git a/contrib/netbsd-tests/lib/libpthread/t_cancel.sh b/contrib/netbsd-tests/lib/libpthread/t_cancel.sh new file mode 100755 index 0000000..4a0701e --- /dev/null +++ b/contrib/netbsd-tests/lib/libpthread/t_cancel.sh @@ -0,0 +1,44 @@ +# $NetBSD: t_cancel.sh,v 1.1 2010/07/16 15:42:53 jmmv Exp $ +# +# Copyright (c) 2008 The NetBSD Foundation, Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + +atf_test_case register_while_disabled +register_while_disabled_head() +{ + atf_set "descr" "Checks that a cancellation registered while" \ + "cancellation is enabled is not honored while cancellation is" \ + "disabled" +} +register_while_disabled_body() +{ + atf_check -o inline:"You should see this.\n" \ + "$(atf_get_srcdir)/h_cancel" +} + +atf_init_test_cases() +{ + atf_add_test_case register_while_disabled +} diff --git a/contrib/netbsd-tests/lib/libpthread/t_cond.c b/contrib/netbsd-tests/lib/libpthread/t_cond.c new file mode 100644 index 0000000..9f33c9e --- /dev/null +++ b/contrib/netbsd-tests/lib/libpthread/t_cond.c @@ -0,0 +1,563 @@ +/* $NetBSD: t_cond.c,v 1.6 2014/09/03 16:23:24 gson Exp $ */ + +/* + * Copyright (c) 2008 The NetBSD Foundation, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__COPYRIGHT("@(#) Copyright (c) 2008\ + The NetBSD Foundation, inc. All rights reserved."); +__RCSID("$NetBSD: t_cond.c,v 1.6 2014/09/03 16:23:24 gson Exp $"); + +#include <sys/time.h> + +#include <errno.h> +#include <pthread.h> +#include <stdio.h> +#include <unistd.h> + +#include <atf-c.h> + +#include "h_common.h" + +static pthread_mutex_t mutex; +static pthread_cond_t cond; +static pthread_mutex_t static_mutex = PTHREAD_MUTEX_INITIALIZER; +static pthread_cond_t static_cond = PTHREAD_COND_INITIALIZER; +static int count, share, toggle, total; + +static void * +signal_delay_wait_threadfunc(void *arg) +{ + int *shared = (int *) arg; + + printf("2: Second thread.\n"); + + printf("2: Locking mutex\n"); + PTHREAD_REQUIRE(pthread_mutex_lock(&mutex)); + printf("2: Got mutex.\n"); + printf("Shared value: %d. Changing to 0.\n", *shared); + *shared = 0; + + PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex)); + PTHREAD_REQUIRE(pthread_cond_signal(&cond)); + + return NULL; +} + +ATF_TC(signal_delay_wait); +ATF_TC_HEAD(signal_delay_wait, tc) +{ + atf_tc_set_md_var(tc, "descr", "Checks condition variables"); +} +ATF_TC_BODY(signal_delay_wait, tc) +{ + pthread_t new; + void *joinval; + int sharedval; + + printf("1: condition variable test 1\n"); + + PTHREAD_REQUIRE(pthread_mutex_init(&mutex, NULL)); + PTHREAD_REQUIRE(pthread_cond_init(&cond, NULL)); + + PTHREAD_REQUIRE(pthread_mutex_lock(&mutex)); + + sharedval = 1; + + PTHREAD_REQUIRE(pthread_create(&new, NULL, signal_delay_wait_threadfunc, + &sharedval)); + + printf("1: Before waiting.\n"); + do { + sleep(2); + PTHREAD_REQUIRE(pthread_cond_wait(&cond, &mutex)); + printf("1: After waiting, in loop.\n"); + } while (sharedval != 0); + + printf("1: After the loop.\n"); + + PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex)); + + printf("1: After releasing the mutex.\n"); + PTHREAD_REQUIRE(pthread_join(new, &joinval)); + + printf("1: Thread joined.\n"); +} + +static void * +signal_before_unlock_threadfunc(void *arg) +{ + int *shared = (int *) arg; + + printf("2: Second thread.\n"); + + printf("2: Locking mutex\n"); + PTHREAD_REQUIRE(pthread_mutex_lock(&mutex)); + printf("2: Got mutex.\n"); + printf("Shared value: %d. Changing to 0.\n", *shared); + *shared = 0; + + /* Signal first, then unlock, for a different test than #1. */ + PTHREAD_REQUIRE(pthread_cond_signal(&cond)); + PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex)); + + return NULL; +} + +ATF_TC(signal_before_unlock); +ATF_TC_HEAD(signal_before_unlock, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Checks condition variables: signal before unlocking mutex"); +} +ATF_TC_BODY(signal_before_unlock, tc) +{ + pthread_t new; + void *joinval; + int sharedval; + + printf("1: condition variable test 2\n"); + + PTHREAD_REQUIRE(pthread_mutex_init(&mutex, NULL)); + PTHREAD_REQUIRE(pthread_cond_init(&cond, NULL)); + + PTHREAD_REQUIRE(pthread_mutex_lock(&mutex)); + + sharedval = 1; + + PTHREAD_REQUIRE(pthread_create(&new, NULL, + signal_before_unlock_threadfunc, &sharedval)); + + printf("1: Before waiting.\n"); + do { + sleep(2); + PTHREAD_REQUIRE(pthread_cond_wait(&cond, &mutex)); + printf("1: After waiting, in loop.\n"); + } while (sharedval != 0); + + printf("1: After the loop.\n"); + + PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex)); + + printf("1: After releasing the mutex.\n"); + PTHREAD_REQUIRE(pthread_join(new, &joinval)); + + printf("1: Thread joined.\n"); +} + +static void * +signal_before_unlock_static_init_threadfunc(void *arg) +{ + int *shared = (int *) arg; + + printf("2: Second thread.\n"); + + printf("2: Locking mutex\n"); + PTHREAD_REQUIRE(pthread_mutex_lock(&static_mutex)); + printf("2: Got mutex.\n"); + printf("Shared value: %d. Changing to 0.\n", *shared); + *shared = 0; + + /* Signal first, then unlock, for a different test than #1. */ + PTHREAD_REQUIRE(pthread_cond_signal(&static_cond)); + PTHREAD_REQUIRE(pthread_mutex_unlock(&static_mutex)); + + return NULL; +} + +ATF_TC(signal_before_unlock_static_init); +ATF_TC_HEAD(signal_before_unlock_static_init, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Checks condition variables: signal before unlocking " + "mutex, use static initializers"); +} +ATF_TC_BODY(signal_before_unlock_static_init, tc) +{ + pthread_t new; + void *joinval; + int sharedval; + + printf("1: condition variable test 3\n"); + + PTHREAD_REQUIRE(pthread_mutex_lock(&static_mutex)); + + sharedval = 1; + + PTHREAD_REQUIRE(pthread_create(&new, NULL, + signal_before_unlock_static_init_threadfunc, &sharedval)); + + printf("1: Before waiting.\n"); + do { + sleep(2); + PTHREAD_REQUIRE(pthread_cond_wait(&static_cond, &static_mutex)); + printf("1: After waiting, in loop.\n"); + } while (sharedval != 0); + + printf("1: After the loop.\n"); + + PTHREAD_REQUIRE(pthread_mutex_unlock(&static_mutex)); + + printf("1: After releasing the mutex.\n"); + PTHREAD_REQUIRE(pthread_join(new, &joinval)); + + printf("1: Thread joined.\n"); +} + +static void * +signal_wait_race_threadfunc(void *arg) +{ + printf("2: Second thread.\n"); + PTHREAD_REQUIRE(pthread_mutex_lock(&static_mutex)); + printf("2: Before the loop.\n"); + while (count>0) { + count--; + total++; + toggle = 0; + /* printf("2: Before signal %d.\n", count); */ + PTHREAD_REQUIRE(pthread_cond_signal(&static_cond)); + do { + PTHREAD_REQUIRE(pthread_cond_wait(&static_cond, + &static_mutex)); + } while (toggle != 1); + } + printf("2: After the loop.\n"); + PTHREAD_REQUIRE(pthread_mutex_unlock(&static_mutex)); + + return NULL; +} + +ATF_TC(signal_wait_race); +ATF_TC_HEAD(signal_wait_race, tc) +{ + atf_tc_set_md_var(tc, "descr", "Checks condition variables"); +} +ATF_TC_BODY(signal_wait_race, tc) +{ + pthread_t new; + void *joinval; + int sharedval; + + printf("1: condition variable test 4\n"); + + PTHREAD_REQUIRE(pthread_mutex_lock(&static_mutex)); + + count = 50000; + toggle = 0; + + PTHREAD_REQUIRE(pthread_create(&new, NULL, signal_wait_race_threadfunc, + &sharedval)); + + printf("1: Before waiting.\n"); + while (count>0) { + count--; + total++; + toggle = 1; + /* printf("1: Before signal %d.\n", count); */ + PTHREAD_REQUIRE(pthread_cond_signal(&static_cond)); + do { + PTHREAD_REQUIRE(pthread_cond_wait(&static_cond, + &static_mutex)); + } while (toggle != 0); + } + printf("1: After the loop.\n"); + + toggle = 1; + PTHREAD_REQUIRE(pthread_mutex_unlock(&static_mutex)); + PTHREAD_REQUIRE(pthread_cond_signal(&static_cond)); + + printf("1: After releasing the mutex.\n"); + PTHREAD_REQUIRE(pthread_join(new, &joinval)); + + printf("1: Thread joined. Final count = %d, total = %d\n", + count, total); + + ATF_REQUIRE_EQ(count, 0); + ATF_REQUIRE_EQ(total, 50000); +} + +static void * +pthread_cond_timedwait_func(void *arg) +{ + struct timespec ts; + size_t i = 0; + int rv; + + for (;;) { + + if (i++ >= 10000) + pthread_exit(NULL); + + (void)memset(&ts, 0, sizeof(struct timespec)); + + ATF_REQUIRE(clock_gettime(CLOCK_REALTIME, &ts) == 0); + + /* + * Set to one second in the past: + * pthread_cond_timedwait(3) should + * return ETIMEDOUT immediately. + */ + ts.tv_sec = ts.tv_sec - 1; + + PTHREAD_REQUIRE(pthread_mutex_lock(&static_mutex)); + rv = pthread_cond_timedwait(&static_cond, &static_mutex, &ts); + + /* + * Sometimes we catch ESRCH. + * This should never happen. + */ + ATF_REQUIRE(rv == ETIMEDOUT); + PTHREAD_REQUIRE(pthread_mutex_unlock(&static_mutex)); + } +} + +ATF_TC(cond_timedwait_race); +ATF_TC_HEAD(cond_timedwait_race, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test pthread_cond_timedwait(3)"); + +} +ATF_TC_BODY(cond_timedwait_race, tc) +{ + pthread_t tid[64]; + size_t i; + + for (i = 0; i < __arraycount(tid); i++) { + + PTHREAD_REQUIRE(pthread_create(&tid[i], NULL, + pthread_cond_timedwait_func, NULL)); + } + + for (i = 0; i < __arraycount(tid); i++) { + + PTHREAD_REQUIRE(pthread_join(tid[i], NULL)); + } +} + +static void * +broadcast_threadfunc(void *arg) +{ + printf("2: Second thread.\n"); + + PTHREAD_REQUIRE(pthread_mutex_lock(&static_mutex)); + while (count>0) { + count--; + total++; + toggle = 0; + PTHREAD_REQUIRE(pthread_cond_signal(&static_cond)); + do { + PTHREAD_REQUIRE(pthread_cond_wait(&static_cond, + &static_mutex)); + } while (toggle != 1); + } + printf("2: After the loop.\n"); + PTHREAD_REQUIRE(pthread_mutex_unlock(&static_mutex)); + + return NULL; +} + + +ATF_TC(broadcast); +ATF_TC_HEAD(broadcast, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Checks condition variables: use pthread_cond_broadcast()"); +} +ATF_TC_BODY(broadcast, tc) +{ + pthread_t new; + void *joinval; + int sharedval; + + printf("1: condition variable test 5\n"); + + PTHREAD_REQUIRE(pthread_mutex_lock(&static_mutex)); + + count = 50000; + toggle = 0; + + PTHREAD_REQUIRE(pthread_create(&new, NULL, broadcast_threadfunc, + &sharedval)); + + printf("1: Before waiting.\n"); + while (count>0) { + count--; + total++; + toggle = 1; + PTHREAD_REQUIRE(pthread_cond_broadcast(&static_cond)); + do { + PTHREAD_REQUIRE(pthread_cond_wait(&static_cond, + &static_mutex)); + } while (toggle != 0); + } + printf("1: After the loop.\n"); + + toggle = 1; + PTHREAD_REQUIRE(pthread_mutex_unlock(&static_mutex)); + PTHREAD_REQUIRE(pthread_cond_signal(&static_cond)); + + printf("1: After releasing the mutex.\n"); + PTHREAD_REQUIRE(pthread_join(new, &joinval)); + + printf("1: Thread joined. Final count = %d, total = %d\n", count, + total); + + ATF_REQUIRE_EQ(count, 0); + ATF_REQUIRE_EQ(total, 50000); +} + +static void * +bogus_timedwaits_threadfunc(void *arg) +{ + return NULL; +} + +ATF_TC(bogus_timedwaits); +ATF_TC_HEAD(bogus_timedwaits, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Checks condition variables: bogus timedwaits"); +} +ATF_TC_BODY(bogus_timedwaits, tc) +{ + pthread_t new; + struct timespec ts; + struct timeval tv; + + printf("condition variable test 6: bogus timedwaits\n"); + + PTHREAD_REQUIRE(pthread_mutex_lock(&static_mutex)); + + printf("unthreaded test (past)\n"); + gettimeofday(&tv, NULL); + tv.tv_sec -= 2; /* Place the time in the past */ + TIMEVAL_TO_TIMESPEC(&tv, &ts); + + ATF_REQUIRE_EQ_MSG(pthread_cond_timedwait(&static_cond, &static_mutex, + &ts), ETIMEDOUT, "pthread_cond_timedwait() (unthreaded) in the " + "past"); + + printf("unthreaded test (zero time)\n"); + tv.tv_sec = 0; + tv.tv_usec = 0; + TIMEVAL_TO_TIMESPEC(&tv, &ts); + + ATF_REQUIRE_EQ_MSG(pthread_cond_timedwait(&static_cond, &static_mutex, + &ts), ETIMEDOUT, "pthread_cond_timedwait() (unthreaded) with zero " + "time"); + + PTHREAD_REQUIRE(pthread_create(&new, NULL, bogus_timedwaits_threadfunc, + NULL)); + PTHREAD_REQUIRE(pthread_join(new, NULL)); + + printf("threaded test\n"); + gettimeofday(&tv, NULL); + tv.tv_sec -= 2; /* Place the time in the past */ + TIMEVAL_TO_TIMESPEC(&tv, &ts); + + ATF_REQUIRE_EQ_MSG(pthread_cond_timedwait(&static_cond, &static_mutex, + &ts), ETIMEDOUT, "pthread_cond_timedwait() (threaded) in the past"); + + printf("threaded test (zero time)\n"); + tv.tv_sec = 0; + tv.tv_usec = 0; + TIMEVAL_TO_TIMESPEC(&tv, &ts); + + ATF_REQUIRE_EQ_MSG(pthread_cond_timedwait(&static_cond, &static_mutex, + &ts), ETIMEDOUT, "pthread_cond_timedwait() (threaded) with zero " + "time"); + + PTHREAD_REQUIRE(pthread_mutex_unlock(&static_mutex)); +} + +static void +unlock(void *arg) +{ + pthread_mutex_unlock((pthread_mutex_t *)arg); +} + +static void * +destroy_after_cancel_threadfunc(void *arg) +{ + PTHREAD_REQUIRE(pthread_mutex_lock(&mutex)); + + pthread_cleanup_push(unlock, &mutex); + + while (1) { + share = 1; + PTHREAD_REQUIRE(pthread_cond_broadcast(&cond)); + PTHREAD_REQUIRE(pthread_cond_wait(&cond, &mutex)); + } + + pthread_cleanup_pop(0); + PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex)); + + return NULL; +} + +ATF_TC(destroy_after_cancel); +ATF_TC_HEAD(destroy_after_cancel, tc) +{ + atf_tc_set_md_var(tc, "descr", "Checks destroying a condition variable " + "after cancelling a wait"); +} +ATF_TC_BODY(destroy_after_cancel, tc) +{ + pthread_t thread; + + PTHREAD_REQUIRE(pthread_mutex_init(&mutex, NULL)); + PTHREAD_REQUIRE(pthread_cond_init(&cond, NULL)); + PTHREAD_REQUIRE(pthread_mutex_lock(&mutex)); + PTHREAD_REQUIRE(pthread_create(&thread, NULL, + destroy_after_cancel_threadfunc, NULL)); + + while (share == 0) { + PTHREAD_REQUIRE(pthread_cond_wait(&cond, &mutex)); + } + + PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex)); + PTHREAD_REQUIRE(pthread_cancel(thread)); + + PTHREAD_REQUIRE(pthread_join(thread, NULL)); + PTHREAD_REQUIRE(pthread_cond_destroy(&cond)); + + PTHREAD_REQUIRE(pthread_mutex_destroy(&mutex)); +} + +ATF_TP_ADD_TCS(tp) +{ + + ATF_TP_ADD_TC(tp, signal_delay_wait); + ATF_TP_ADD_TC(tp, signal_before_unlock); + ATF_TP_ADD_TC(tp, signal_before_unlock_static_init); + ATF_TP_ADD_TC(tp, signal_wait_race); + ATF_TP_ADD_TC(tp, cond_timedwait_race); + ATF_TP_ADD_TC(tp, broadcast); + ATF_TP_ADD_TC(tp, bogus_timedwaits); + ATF_TP_ADD_TC(tp, destroy_after_cancel); + + return atf_no_error(); +} diff --git a/contrib/netbsd-tests/lib/libpthread/t_condwait.c b/contrib/netbsd-tests/lib/libpthread/t_condwait.c new file mode 100644 index 0000000..17bbb89 --- /dev/null +++ b/contrib/netbsd-tests/lib/libpthread/t_condwait.c @@ -0,0 +1,146 @@ +/* $NetBSD: t_condwait.c,v 1.4 2013/04/12 17:18:11 christos Exp $ */ + +/* + * Copyright (c) 2013 The NetBSD Foundation, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#include <sys/cdefs.h> +__RCSID("$NetBSD: t_condwait.c,v 1.4 2013/04/12 17:18:11 christos Exp $"); + +#include <errno.h> +#include <pthread.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <time.h> +#include <unistd.h> + +#include <atf-c.h> + +#include "isqemu.h" + +#ifdef __FreeBSD__ +#include <sys/time.h> +#endif + +#define WAITTIME 2 /* Timeout wait secound */ + +static const int debug = 1; + +static void * +run(void *param) +{ + struct timespec ts, to, te; + clockid_t clck; + pthread_condattr_t attr; + pthread_cond_t cond; + pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER; + int ret = 0; + + + clck = *(clockid_t *)param; + pthread_condattr_init(&attr); + pthread_condattr_setclock(&attr, clck); /* MONOTONIC or MONOTONIC */ + pthread_cond_init(&cond, &attr); + + ATF_REQUIRE_EQ((ret = pthread_mutex_lock(&m)), 0); + + ATF_REQUIRE_EQ(clock_gettime(clck, &ts), 0); + to = ts; + + if (debug) + printf("started: %lld.%09ld sec\n", (long long)to.tv_sec, + to.tv_nsec); + + ts.tv_sec += WAITTIME; /* Timeout wait */ + + switch (ret = pthread_cond_timedwait(&cond, &m, &ts)) { + case ETIMEDOUT: + /* Timeout */ + ATF_REQUIRE_EQ(clock_gettime(clck, &te), 0); + timespecsub(&te, &to, &to); + if (debug) { + printf("timeout: %lld.%09ld sec\n", + (long long)te.tv_sec, te.tv_nsec); + printf("elapsed: %lld.%09ld sec\n", + (long long)to.tv_sec, to.tv_nsec); + } + if (isQEMU()) { + double to_seconds = to.tv_sec + 1e-9 * to.tv_nsec; + ATF_REQUIRE(to_seconds >= WAITTIME * 0.9); + /* Loose upper limit because of qemu timing bugs */ + ATF_REQUIRE(to_seconds < WAITTIME * 2.5); + } else { + ATF_REQUIRE_EQ(to.tv_sec, WAITTIME); + } + break; + default: + ATF_REQUIRE_MSG(0, "pthread_cond_timedwait: %s", strerror(ret)); + } + + ATF_REQUIRE_MSG(!(ret = pthread_mutex_unlock(&m)), + "pthread_mutex_unlock: %s", strerror(ret)); + pthread_exit(&ret); +} + +static void +cond_wait(clockid_t clck, const char *msg) { + pthread_t child; + + if (debug) + printf( "**** %s clock wait starting\n", msg); + ATF_REQUIRE_EQ(pthread_create(&child, NULL, run, &clck), 0); + ATF_REQUIRE_EQ(pthread_join(child, NULL), 0); /* wait for terminate */ + if (debug) + printf( "**** %s clock wait ended\n", msg); +} + +ATF_TC(cond_wait_real); +ATF_TC_HEAD(cond_wait_real, tc) +{ + atf_tc_set_md_var(tc, "descr", "Checks pthread_cond_timedwait " + "with CLOCK_REALTIME"); +} + +ATF_TC_BODY(cond_wait_real, tc) { + cond_wait(CLOCK_REALTIME, "CLOCK_REALTIME"); +} + +ATF_TC(cond_wait_mono); +ATF_TC_HEAD(cond_wait_mono, tc) +{ + atf_tc_set_md_var(tc, "descr", "Checks pthread_cond_timedwait " + "with CLOCK_MONOTONIC"); +} + +ATF_TC_BODY(cond_wait_mono, tc) { + cond_wait(CLOCK_MONOTONIC, "CLOCK_MONOTONIC"); +} + +ATF_TP_ADD_TCS(tp) +{ + ATF_TP_ADD_TC(tp, cond_wait_real); + ATF_TP_ADD_TC(tp, cond_wait_mono); + return 0; +} diff --git a/contrib/netbsd-tests/lib/libpthread/t_detach.c b/contrib/netbsd-tests/lib/libpthread/t_detach.c new file mode 100644 index 0000000..8922d5a --- /dev/null +++ b/contrib/netbsd-tests/lib/libpthread/t_detach.c @@ -0,0 +1,95 @@ +/* $NetBSD: t_detach.c,v 1.1 2011/03/24 13:52:04 jruoho Exp $ */ + +/*- + * Copyright (c) 2011 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Jukka Ruohonen. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#include <sys/cdefs.h> +__RCSID("$NetBSD: t_detach.c,v 1.1 2011/03/24 13:52:04 jruoho Exp $"); + +#include <pthread.h> +#include <errno.h> + +#include <atf-c.h> + +#include "h_common.h" + +static void *func(void *); + +static void * +func(void *arg) +{ + return NULL; +} + +ATF_TC(pthread_detach); +ATF_TC_HEAD(pthread_detach, tc) +{ + atf_tc_set_md_var(tc, "descr", "A test of pthread_detach(3)"); +} + +ATF_TC_BODY(pthread_detach, tc) +{ + const int state = PTHREAD_CREATE_JOINABLE; + pthread_attr_t attr; + pthread_t t; + int rv; + + /* + * Create a joinable thread. + */ + PTHREAD_REQUIRE(pthread_attr_init(&attr)); + PTHREAD_REQUIRE(pthread_attr_setdetachstate(&attr, state)); + PTHREAD_REQUIRE(pthread_create(&t, &attr, func, NULL)); + + /* + * Detach the thread and try to + * join it; EINVAL should follow. + */ + PTHREAD_REQUIRE(pthread_detach(t)); + + rv = pthread_join(t, NULL); + ATF_REQUIRE(rv == EINVAL); + +#ifdef __FreeBSD__ + atf_tc_expect_fail("PR # 191906: fails with EINVAL, not ESRCH"); +#endif + + /* + * As usual, ESRCH should follow if + * we try to detach an invalid thread. + */ + rv = pthread_cancel(NULL); + ATF_REQUIRE(rv == ESRCH); +} + +ATF_TP_ADD_TCS(tp) +{ + ATF_TP_ADD_TC(tp, pthread_detach); + + return atf_no_error(); +} diff --git a/contrib/netbsd-tests/lib/libpthread/t_equal.c b/contrib/netbsd-tests/lib/libpthread/t_equal.c new file mode 100644 index 0000000..bcda996 --- /dev/null +++ b/contrib/netbsd-tests/lib/libpthread/t_equal.c @@ -0,0 +1,74 @@ +/* $NetBSD: t_equal.c,v 1.1 2011/03/24 12:40:59 jruoho Exp $ */ + +/*- + * Copyright (c) 2011 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Jukka Ruohonen. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#include <sys/cdefs.h> +__RCSID("$NetBSD: t_equal.c,v 1.1 2011/03/24 12:40:59 jruoho Exp $"); + +#include <pthread.h> + +#include <atf-c.h> + +#include "h_common.h" + +static void *func(void *); + +static void * +func(void *arg) +{ + return NULL; +} + +ATF_TC(pthread_equal); +ATF_TC_HEAD(pthread_equal, tc) +{ + atf_tc_set_md_var(tc, "descr", "A test of pthread_equal(3)"); +} + +ATF_TC_BODY(pthread_equal, tc) +{ + pthread_t t1, t2; + + ATF_REQUIRE(pthread_create(&t1, NULL, func, NULL) == 0); + ATF_REQUIRE(pthread_create(&t2, NULL, func, NULL) == 0); + + ATF_REQUIRE(pthread_equal(t1, t1) != 0); + ATF_REQUIRE(pthread_equal(t2, t2) != 0); + ATF_REQUIRE(pthread_equal(t1, t2) == 0); + + ATF_REQUIRE(pthread_join(t1, NULL) == 0); + ATF_REQUIRE(pthread_join(t2, NULL) == 0); +} + +ATF_TP_ADD_TCS(tp) +{ + ATF_TP_ADD_TC(tp, pthread_equal); + + return atf_no_error(); +} diff --git a/contrib/netbsd-tests/lib/libpthread/t_exit.sh b/contrib/netbsd-tests/lib/libpthread/t_exit.sh new file mode 100755 index 0000000..7fbd689 --- /dev/null +++ b/contrib/netbsd-tests/lib/libpthread/t_exit.sh @@ -0,0 +1,41 @@ +# $NetBSD: t_exit.sh,v 1.1 2010/07/16 15:42:53 jmmv Exp $ +# +# Copyright (c) 2008 The NetBSD Foundation, Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + +atf_test_case main_thread +main_thread_head() +{ + atf_set "descr" "Checks calling pthread_exit() in the main thread" +} +main_thread_body() +{ + atf_check -o ignore "$(atf_get_srcdir)/h_exit" +} + +atf_init_test_cases() +{ + atf_add_test_case main_thread +} diff --git a/contrib/netbsd-tests/lib/libpthread/t_fork.c b/contrib/netbsd-tests/lib/libpthread/t_fork.c new file mode 100644 index 0000000..a58c1a6 --- /dev/null +++ b/contrib/netbsd-tests/lib/libpthread/t_fork.c @@ -0,0 +1,115 @@ +/* $NetBSD: t_fork.c,v 1.1 2010/07/16 15:42:53 jmmv Exp $ */ + +/* + * Copyright (c) 2008 The NetBSD Foundation, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__COPYRIGHT("@(#) Copyright (c) 2008\ + The NetBSD Foundation, inc. All rights reserved."); +__RCSID("$NetBSD: t_fork.c,v 1.1 2010/07/16 15:42:53 jmmv Exp $"); + +/* + * Written by Love Hörnquist Åstrand <lha@NetBSD.org>, March 2003. + * Public domain. + */ + +#include <sys/types.h> +#include <sys/wait.h> + +#include <errno.h> +#include <pthread.h> +#include <signal.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#include <atf-c.h> + +#include "h_common.h" + +static pid_t parent; +static int thread_survived = 0; + +static void * +print_pid(void *arg) +{ + sleep(3); + + thread_survived = 1; + if (parent != getpid()) { +#ifdef __FreeBSD__ + _exit(1); +#else + exit(1); +#endif + } + return NULL; +} + +ATF_TC(fork); +ATF_TC_HEAD(fork, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Checks that child process doesn't get threads"); +} +ATF_TC_BODY(fork, tc) +{ + pthread_t p; + pid_t fork_pid; + + parent = getpid(); + + PTHREAD_REQUIRE(pthread_create(&p, NULL, print_pid, NULL)); + + fork_pid = fork(); + ATF_REQUIRE(fork_pid != -1); + + if (fork_pid) { + int status; + + PTHREAD_REQUIRE(pthread_join(p, NULL)); + ATF_REQUIRE_MSG(thread_survived, "thread did not survive in parent"); + + waitpid(fork_pid, &status, 0); + ATF_REQUIRE_MSG(WIFEXITED(status), "child died wrongly"); + ATF_REQUIRE_EQ_MSG(WEXITSTATUS(status), 0, "thread survived in child"); + } else { + sleep(5); +#ifdef __FreeBSD__ + _exit(thread_survived ? 1 : 0); +#else + exit(thread_survived ? 1 : 0); +#endif + } +} + +ATF_TP_ADD_TCS(tp) +{ + ATF_TP_ADD_TC(tp, fork); + + return atf_no_error(); +} diff --git a/contrib/netbsd-tests/lib/libpthread/t_fpu.c b/contrib/netbsd-tests/lib/libpthread/t_fpu.c new file mode 100644 index 0000000..4047b1f --- /dev/null +++ b/contrib/netbsd-tests/lib/libpthread/t_fpu.c @@ -0,0 +1,148 @@ +/* $NetBSD: t_fpu.c,v 1.2 2013/01/27 14:47:37 mbalmer Exp $ */ + +/* + * Copyright (c) 2008 The NetBSD Foundation, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__COPYRIGHT("@(#) Copyright (c) 2008\ + The NetBSD Foundation, inc. All rights reserved."); +__RCSID("$NetBSD: t_fpu.c,v 1.2 2013/01/27 14:47:37 mbalmer Exp $"); + +/* + * This is adapted from part of csw/cstest of the MPD implementation by + * the University of Arizona CS department (http://www.cs.arizona.edu/sr/) + * which is in the public domain: + * + * "The MPD system is in the public domain and you may use and distribute it + * as you wish. We ask that you retain credits referencing the University + * of Arizona and that you identify any changes you make. + * + * We can't provide a warranty with MPD; it's up to you to determine its + * suitability and reliability for your needs. We would like to hear of + * any problems you encounter but we cannot promise a timely correction." + * + * It was changed to use pthread_create() and sched_yield() instead of + * the internal MPD context switching primitives by Ignatios Souvatzis + * <is@netbsd.org>. + */ + +#include <math.h> +#include <pthread.h> +#include <sched.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> + +#include <atf-c.h> + +#include "h_common.h" + +#define N_RECURSE 10 + +static void recurse(void); + +int recursion_depth = 0; +pthread_mutex_t recursion_depth_lock; + +static void * +stir(void *p) +{ + double *q = (double *)p; + double x = *q++; + double y = *q++; + double z = *q++; + + for (;;) { + x = sin ((y = cos (x + y + .4)) - (z = cos (x + z + .6))); + PTHREAD_REQUIRE(sched_yield()); + } +} + +static double +mul3(double x, double y, double z) +{ + PTHREAD_REQUIRE(sched_yield()); + + return x * y * z; +} + +static void * +bar(void *p) +{ + double d; + int rc; + + d = mul3(mul3(2., 3., 5.), mul3(7., 11., 13.), mul3(17., 19., 23.)); + ATF_REQUIRE_EQ(d, 223092870.); + + PTHREAD_REQUIRE(pthread_mutex_lock(&recursion_depth_lock)); + rc = recursion_depth++; + PTHREAD_REQUIRE(pthread_mutex_unlock(&recursion_depth_lock)); + + if (rc < N_RECURSE) + recurse(); + else + atf_tc_pass(); + + /* NOTREACHED */ + return NULL; +} + +static void +recurse(void) { + pthread_t s2; + pthread_create(&s2, 0, bar, 0); + sleep(20); /* XXX must be long enough for our slowest machine */ +} + +ATF_TC(fpu); +ATF_TC_HEAD(fpu, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Checks that thread context switches will leave the " + "floating point computations unharmed"); +} +ATF_TC_BODY(fpu, tc) +{ + double stirseed[] = { 1.7, 3.2, 2.4 }; + pthread_t s5; + + printf("Testing threaded floating point computations...\n"); + + PTHREAD_REQUIRE(pthread_mutex_init(&recursion_depth_lock, 0)); + + pthread_create(&s5, 0, stir, stirseed); + recurse(); + + atf_tc_fail("exiting from main"); +} + +ATF_TP_ADD_TCS(tp) +{ + ATF_TP_ADD_TC(tp, fpu); + + return atf_no_error(); +} diff --git a/contrib/netbsd-tests/lib/libpthread/t_join.c b/contrib/netbsd-tests/lib/libpthread/t_join.c new file mode 100644 index 0000000..71b6775 --- /dev/null +++ b/contrib/netbsd-tests/lib/libpthread/t_join.c @@ -0,0 +1,181 @@ +/* $NetBSD: t_join.c,v 1.8 2012/03/12 20:17:16 joerg Exp $ */ + +/*- + * Copyright (c) 2010 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Jukka Ruohonen. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#include <sys/cdefs.h> +__RCSID("$NetBSD: t_join.c,v 1.8 2012/03/12 20:17:16 joerg Exp $"); + +#include <errno.h> +#include <pthread.h> +#include <stdint.h> + +#include <atf-c.h> + +#ifdef __FreeBSD__ +#include <pthread_np.h> +#endif + +#include "h_common.h" + +#ifdef CHECK_STACK_ALIGNMENT +extern int check_stack_alignment(void); +#endif + +#define STACKSIZE 65536 + +static bool error; + +static void *threadfunc1(void *); +static void *threadfunc2(void *); + +ATF_TC(pthread_join); +ATF_TC_HEAD(pthread_join, tc) +{ + + atf_tc_set_md_var(tc, "descr", + "Checks basic error conditions in pthread_join(3)"); +} + +ATF_TC_BODY(pthread_join, tc) +{ + pthread_t thread; + + PTHREAD_REQUIRE(pthread_create(&thread, NULL, threadfunc1, NULL)); + PTHREAD_REQUIRE(pthread_join(thread, NULL)); +} + +static void * +threadfunc1(void *arg) +{ + pthread_t thread[25]; + pthread_t caller; + void *val = NULL; + uintptr_t i; + int rv; + pthread_attr_t attr; + + caller = pthread_self(); + +#ifdef CHECK_STACK_ALIGNMENT + /* + * Check alignment of thread stack, if supported. + */ + ATF_REQUIRE(check_stack_alignment()); +#endif + + /* + * The behavior is undefined, but should error + * out, if we try to join the calling thread. + */ + rv = pthread_join(caller, NULL); + + /* + * The specification recommends EDEADLK. + */ + ATF_REQUIRE(rv != 0); + ATF_REQUIRE_EQ(rv, EDEADLK); + + ATF_REQUIRE(pthread_attr_init(&attr) == 0); + + for (i = 0; i < __arraycount(thread); i++) { + + error = true; + + ATF_REQUIRE(pthread_attr_setstacksize(&attr, STACKSIZE * (i + 1)) == 0); + + rv = pthread_create(&thread[i], &attr, threadfunc2, (void *)i); + + ATF_REQUIRE_EQ(rv, 0); + + /* + * Check join and exit condition. + */ + PTHREAD_REQUIRE(pthread_join(thread[i], &val)); + + ATF_REQUIRE_EQ(error, false); + + ATF_REQUIRE(val != NULL); + ATF_REQUIRE(val == (void *)(i + 1)); + + /* + * Once the thread has returned, ESRCH should + * again follow if we try to join it again. + */ + rv = pthread_join(thread[i], NULL); + + ATF_REQUIRE_EQ(rv, ESRCH); + + /* + * Try to detach the exited thread. + */ + rv = pthread_detach(thread[i]); + + ATF_REQUIRE(rv != 0); + } + + ATF_REQUIRE(pthread_attr_destroy(&attr) == 0); + + pthread_exit(NULL); + + return NULL; +} + +static void * +threadfunc2(void *arg) +{ + static uintptr_t i = 0; + uintptr_t j; + pthread_attr_t attr; + size_t stacksize; + + j = (uintptr_t)arg; + +#ifdef __FreeBSD__ + pthread_attr_init(&attr); +#endif + ATF_REQUIRE(pthread_attr_get_np(pthread_self(), &attr) == 0); + ATF_REQUIRE(pthread_attr_getstacksize(&attr, &stacksize) == 0); + ATF_REQUIRE(stacksize == STACKSIZE * (j + 1)); + ATF_REQUIRE(pthread_attr_destroy(&attr) == 0); + + if (i++ == j) + error = false; + + pthread_exit((void *)i); + + return NULL; +} + +ATF_TP_ADD_TCS(tp) +{ + + ATF_TP_ADD_TC(tp, pthread_join); + + return atf_no_error(); +} diff --git a/contrib/netbsd-tests/lib/libpthread/t_kill.c b/contrib/netbsd-tests/lib/libpthread/t_kill.c new file mode 100644 index 0000000..2fcdd99 --- /dev/null +++ b/contrib/netbsd-tests/lib/libpthread/t_kill.c @@ -0,0 +1,147 @@ +/* $NetBSD: t_kill.c,v 1.1 2010/07/16 15:42:53 jmmv Exp $ */ + +/* + * Copyright (c) 2008 The NetBSD Foundation, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/*- + * Copyright (c)2004 YAMAMOTO Takashi, + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__COPYRIGHT("@(#) Copyright (c) 2008\ + The NetBSD Foundation, inc. All rights reserved."); +__RCSID("$NetBSD: t_kill.c,v 1.1 2010/07/16 15:42:53 jmmv Exp $"); + +#include <pthread.h> +#include <signal.h> +#include <stdlib.h> +#include <string.h> +#include <stdio.h> + +#include <atf-c.h> + +#include "h_common.h" + +#define NTHREAD 2 + +struct threadinfo { + pthread_t id; + sig_atomic_t gotsignal; +} th[NTHREAD]; + +pthread_t mainthread; + +static void +sighandler(int signo) +{ + pthread_t self; + int i; + + self = pthread_self(); + ATF_REQUIRE_MSG((self != mainthread) && (signo == SIGUSR1), + "unexpected signal"); + + for (i = 0; i < NTHREAD; i++) + if (self == th[i].id) + break; + + ATF_REQUIRE_MSG(i != NTHREAD, "unknown thread"); + + th[i].gotsignal++; +} + +static void * +f(void *arg) +{ + struct threadinfo volatile *t = arg; + + while (t->gotsignal < 1) { + /* busy loop */ + } + + return NULL; +} + +ATF_TC(simple); +ATF_TC_HEAD(simple, tc) +{ + atf_tc_set_md_var(tc, "descr", "Checks pthread_kill()"); +} +ATF_TC_BODY(simple, tc) +{ + int i; + pthread_t self; + + mainthread = pthread_self(); + + ATF_REQUIRE(signal(SIGUSR1, sighandler) != SIG_ERR); + + for (i = 0; i < NTHREAD; i++) { + PTHREAD_REQUIRE(pthread_create(&th[i].id, NULL, f, &th[i])); + } + + sched_yield(); + + self = pthread_self(); + ATF_REQUIRE_EQ_MSG(self, mainthread, "thread id changed"); + + for (i = 0; i < NTHREAD; i++) { + PTHREAD_REQUIRE(pthread_kill(th[i].id, SIGUSR1)); + } + + for (i = 0; i < NTHREAD; i++) { + PTHREAD_REQUIRE(pthread_join(th[i].id, NULL)); + } +} + +ATF_TP_ADD_TCS(tp) +{ + ATF_TP_ADD_TC(tp, simple); + + return atf_no_error(); +} diff --git a/contrib/netbsd-tests/lib/libpthread/t_mutex.c b/contrib/netbsd-tests/lib/libpthread/t_mutex.c new file mode 100644 index 0000000..eb371fa --- /dev/null +++ b/contrib/netbsd-tests/lib/libpthread/t_mutex.c @@ -0,0 +1,327 @@ +/* $NetBSD: t_mutex.c,v 1.7 2014/11/04 00:20:19 justin Exp $ */ + +/* + * Copyright (c) 2008 The NetBSD Foundation, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__COPYRIGHT("@(#) Copyright (c) 2008\ + The NetBSD Foundation, inc. All rights reserved."); +__RCSID("$NetBSD: t_mutex.c,v 1.7 2014/11/04 00:20:19 justin Exp $"); + +#include <pthread.h> +#include <stdio.h> +#include <string.h> +#include <unistd.h> + +#include <atf-c.h> + +#include "h_common.h" + +static pthread_mutex_t mutex; +static pthread_mutex_t static_mutex = PTHREAD_MUTEX_INITIALIZER; +static int global_x; + +static void * +mutex1_threadfunc(void *arg) +{ + int *param; + + printf("2: Second thread.\n"); + + param = arg; + printf("2: Locking mutex\n"); + pthread_mutex_lock(&mutex); + printf("2: Got mutex. *param = %d\n", *param); + ATF_REQUIRE_EQ(*param, 20); + (*param)++; + + pthread_mutex_unlock(&mutex); + + return param; +} + +ATF_TC(mutex1); +ATF_TC_HEAD(mutex1, tc) +{ + atf_tc_set_md_var(tc, "descr", "Checks mutexes"); +} +ATF_TC_BODY(mutex1, tc) +{ + int x; + pthread_t new; + void *joinval; + + printf("1: Mutex-test 1\n"); + + PTHREAD_REQUIRE(pthread_mutex_init(&mutex, NULL)); + x = 1; + PTHREAD_REQUIRE(pthread_mutex_lock(&mutex)); + PTHREAD_REQUIRE(pthread_create(&new, NULL, mutex1_threadfunc, &x)); + printf("1: Before changing the value.\n"); + sleep(2); + x = 20; + printf("1: Before releasing the mutex.\n"); + sleep(2); + PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex)); + printf("1: After releasing the mutex.\n"); + PTHREAD_REQUIRE(pthread_join(new, &joinval)); + + PTHREAD_REQUIRE(pthread_mutex_lock(&mutex)); + printf("1: Thread joined. X was %d. Return value (int) was %d\n", + x, *(int *)joinval); + ATF_REQUIRE_EQ(x, 21); + ATF_REQUIRE_EQ(*(int *)joinval, 21); + PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex)); +} + +static void * +mutex2_threadfunc(void *arg) +{ + long count = *(int *)arg; + + printf("2: Second thread (%p). Count is %ld\n", pthread_self(), count); + + while (count--) { + PTHREAD_REQUIRE(pthread_mutex_lock(&mutex)); + global_x++; + PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex)); + } + + return (void *)count; +} + +ATF_TC(mutex2); +ATF_TC_HEAD(mutex2, tc) +{ + atf_tc_set_md_var(tc, "descr", "Checks mutexes"); +#ifdef __NetBSD__ +#if defined(__powerpc__) + atf_tc_set_md_var(tc, "timeout", "40"); +#endif +#endif +} +ATF_TC_BODY(mutex2, tc) +{ + int count, count2; + pthread_t new; + void *joinval; + + printf("1: Mutex-test 2\n"); + +#ifdef __NetBSD__ +#if defined(__powerpc__) + atf_tc_expect_timeout("PR port-powerpc/44387"); +#endif +#endif + + PTHREAD_REQUIRE(pthread_mutex_init(&mutex, NULL)); + + global_x = 0; + count = count2 = 10000000; + + PTHREAD_REQUIRE(pthread_mutex_lock(&mutex)); + PTHREAD_REQUIRE(pthread_create(&new, NULL, mutex2_threadfunc, &count2)); + + printf("1: Thread %p\n", pthread_self()); + + PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex)); + + while (count--) { + PTHREAD_REQUIRE(pthread_mutex_lock(&mutex)); + global_x++; + PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex)); + } + + PTHREAD_REQUIRE(pthread_join(new, &joinval)); + + PTHREAD_REQUIRE(pthread_mutex_lock(&mutex)); + printf("1: Thread joined. X was %d. Return value (long) was %ld\n", + global_x, (long)joinval); + ATF_REQUIRE_EQ(global_x, 20000000); + +#ifdef __NetBSD__ +#if defined(__powerpc__) + /* XXX force a timeout in ppc case since an un-triggered race + otherwise looks like a "failure" */ + /* We sleep for longer than the timeout to make ATF not + complain about unexpected success */ + sleep(41); +#endif +#endif +} + +static void * +mutex3_threadfunc(void *arg) +{ + long count = *(int *)arg; + + printf("2: Second thread (%p). Count is %ld\n", pthread_self(), count); + + while (count--) { + PTHREAD_REQUIRE(pthread_mutex_lock(&static_mutex)); + global_x++; + PTHREAD_REQUIRE(pthread_mutex_unlock(&static_mutex)); + } + + return (void *)count; +} + +ATF_TC(mutex3); +ATF_TC_HEAD(mutex3, tc) +{ + atf_tc_set_md_var(tc, "descr", "Checks mutexes using a static " + "initializer"); +#ifdef __NetBSD__ +#if defined(__powerpc__) + atf_tc_set_md_var(tc, "timeout", "40"); +#endif +#endif +} +ATF_TC_BODY(mutex3, tc) +{ + int count, count2; + pthread_t new; + void *joinval; + + printf("1: Mutex-test 3\n"); + +#ifdef __NetBSD__ +#if defined(__powerpc__) + atf_tc_expect_timeout("PR port-powerpc/44387"); +#endif +#endif + + global_x = 0; + count = count2 = 10000000; + + PTHREAD_REQUIRE(pthread_mutex_lock(&static_mutex)); + PTHREAD_REQUIRE(pthread_create(&new, NULL, mutex3_threadfunc, &count2)); + + printf("1: Thread %p\n", pthread_self()); + + PTHREAD_REQUIRE(pthread_mutex_unlock(&static_mutex)); + + while (count--) { + PTHREAD_REQUIRE(pthread_mutex_lock(&static_mutex)); + global_x++; + PTHREAD_REQUIRE(pthread_mutex_unlock(&static_mutex)); + } + + PTHREAD_REQUIRE(pthread_join(new, &joinval)); + + PTHREAD_REQUIRE(pthread_mutex_lock(&static_mutex)); + printf("1: Thread joined. X was %d. Return value (long) was %ld\n", + global_x, (long)joinval); + ATF_REQUIRE_EQ(global_x, 20000000); + +#ifdef __NetBSD__ +#if defined(__powerpc__) + /* XXX force a timeout in ppc case since an un-triggered race + otherwise looks like a "failure" */ + /* We sleep for longer than the timeout to make ATF not + complain about unexpected success */ + sleep(41); +#endif +#endif +} + +static void * +mutex4_threadfunc(void *arg) +{ + int *param; + + printf("2: Second thread.\n"); + + param = arg; + printf("2: Locking mutex\n"); + PTHREAD_REQUIRE(pthread_mutex_lock(&mutex)); + printf("2: Got mutex. *param = %d\n", *param); + (*param)++; + + PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex)); + + return param; +} + +ATF_TC(mutex4); +ATF_TC_HEAD(mutex4, tc) +{ + atf_tc_set_md_var(tc, "descr", "Checks mutexes"); +} +ATF_TC_BODY(mutex4, tc) +{ + int x; + pthread_t new; + pthread_mutexattr_t mattr; + void *joinval; + + printf("1: Mutex-test 4\n"); + + PTHREAD_REQUIRE(pthread_mutexattr_init(&mattr)); + PTHREAD_REQUIRE(pthread_mutexattr_settype(&mattr, PTHREAD_MUTEX_RECURSIVE)); + + PTHREAD_REQUIRE(pthread_mutex_init(&mutex, &mattr)); + + PTHREAD_REQUIRE(pthread_mutexattr_destroy(&mattr)); + + x = 1; + PTHREAD_REQUIRE(pthread_mutex_lock(&mutex)); + PTHREAD_REQUIRE(pthread_create(&new, NULL, mutex4_threadfunc, &x)); + + printf("1: Before recursively acquiring the mutex.\n"); + PTHREAD_REQUIRE(pthread_mutex_lock(&mutex)); + + printf("1: Before releasing the mutex once.\n"); + sleep(2); + PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex)); + printf("1: After releasing the mutex once.\n"); + + x = 20; + + printf("1: Before releasing the mutex twice.\n"); + sleep(2); + PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex)); + printf("1: After releasing the mutex twice.\n"); + + PTHREAD_REQUIRE(pthread_join(new, &joinval)); + + PTHREAD_REQUIRE(pthread_mutex_lock(&mutex)); + printf("1: Thread joined. X was %d. Return value (int) was %d\n", + x, *(int *)joinval); + ATF_REQUIRE_EQ(x, 21); + ATF_REQUIRE_EQ(*(int *)joinval, 21); + PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex)); +} + +ATF_TP_ADD_TCS(tp) +{ + ATF_TP_ADD_TC(tp, mutex1); + ATF_TP_ADD_TC(tp, mutex2); + ATF_TP_ADD_TC(tp, mutex3); + ATF_TP_ADD_TC(tp, mutex4); + + return atf_no_error(); +} diff --git a/contrib/netbsd-tests/lib/libpthread/t_name.c b/contrib/netbsd-tests/lib/libpthread/t_name.c new file mode 100644 index 0000000..d17895e --- /dev/null +++ b/contrib/netbsd-tests/lib/libpthread/t_name.c @@ -0,0 +1,103 @@ +/* $NetBSD: t_name.c,v 1.1 2010/07/16 15:42:53 jmmv Exp $ */ + +/* + * Copyright (c) 2008 The NetBSD Foundation, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__COPYRIGHT("@(#) Copyright (c) 2008\ + The NetBSD Foundation, inc. All rights reserved."); +__RCSID("$NetBSD: t_name.c,v 1.1 2010/07/16 15:42:53 jmmv Exp $"); + +#include <errno.h> +#include <pthread.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#include <atf-c.h> + +#include "h_common.h" + +#define NAME_TOO_LONG "12345678901234567890123456789012" /* 32 chars */ +#define NAME_JUST_RIGHT "1234567890123456789012345678901" /* 31 chars */ + +#define CONST_NAME "xyzzy" +char non_const_name[] = CONST_NAME; + +static void * +threadfunc(void *arg) +{ + pthread_t self = pthread_self(); + char retname[32]; + + PTHREAD_REQUIRE(pthread_getname_np(self, retname, sizeof(retname))); + ATF_REQUIRE_STREQ(retname, NAME_JUST_RIGHT); + + PTHREAD_REQUIRE(pthread_setname_np(self, non_const_name, NULL)); + (void) memset(non_const_name, 0, sizeof(non_const_name)); + PTHREAD_REQUIRE(pthread_getname_np(self, retname, sizeof(retname))); + ATF_REQUIRE_STREQ(retname, CONST_NAME); + + return NULL; +} + +ATF_TC(name); +ATF_TC_HEAD(name, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Checks pthread_{,attr}_{get,set}name_np() API"); +} +ATF_TC_BODY(name, tc) +{ + pthread_t thr, self = pthread_self(); + pthread_attr_t attr; + char retname[32]; + + PTHREAD_REQUIRE(pthread_attr_init(&attr)); + PTHREAD_REQUIRE(pthread_attr_getname_np(&attr, retname, + sizeof(retname), NULL)); + ATF_REQUIRE_EQ(retname[0], '\0'); + ATF_REQUIRE_EQ(pthread_attr_setname_np(&attr, NAME_TOO_LONG, NULL), EINVAL); + PTHREAD_REQUIRE(pthread_attr_setname_np(&attr, "%s", + __UNCONST(NAME_JUST_RIGHT))); + + (void) strcpy(retname, "foo"); + PTHREAD_REQUIRE(pthread_getname_np(self, retname, sizeof(retname))); + ATF_REQUIRE_EQ(retname[0], '\0'); + + PTHREAD_REQUIRE(pthread_create(&thr, &attr, threadfunc, NULL)); + PTHREAD_REQUIRE(pthread_join(thr, NULL)); + + ATF_REQUIRE_EQ(pthread_getname_np(thr, retname, sizeof(retname)), ESRCH); +} + +ATF_TP_ADD_TCS(tp) +{ + ATF_TP_ADD_TC(tp, name); + + return atf_no_error(); +} diff --git a/contrib/netbsd-tests/lib/libpthread/t_once.c b/contrib/netbsd-tests/lib/libpthread/t_once.c new file mode 100644 index 0000000..e879077 --- /dev/null +++ b/contrib/netbsd-tests/lib/libpthread/t_once.c @@ -0,0 +1,200 @@ +/* $NetBSD: t_once.c,v 1.1 2010/07/16 15:42:53 jmmv Exp $ */ + +/* + * Copyright (c) 2008 The NetBSD Foundation, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__COPYRIGHT("@(#) Copyright (c) 2008\ + The NetBSD Foundation, inc. All rights reserved."); +__RCSID("$NetBSD: t_once.c,v 1.1 2010/07/16 15:42:53 jmmv Exp $"); + +#include <pthread.h> +#include <signal.h> +#include <stdio.h> +#include <stdlib.h> + +#include <atf-c.h> + +#include "h_common.h" + +static pthread_once_t once = PTHREAD_ONCE_INIT; +static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; +static int x; + +#define NTHREADS 25 + +#ifdef __FreeBSD__ +#include <sys/time.h> +#endif + +static void +ofunc(void) +{ + printf("Variable x has value %d\n", x); + x++; +} + +ATF_TC(once1); +ATF_TC_HEAD(once1, tc) +{ + atf_tc_set_md_var(tc, "descr", "Checks pthread_once()"); +} +ATF_TC_BODY(once1, tc) +{ + + printf("1: Test 1 of pthread_once()\n"); + + PTHREAD_REQUIRE(pthread_once(&once, ofunc)); + PTHREAD_REQUIRE(pthread_once(&once, ofunc)); + + printf("1: X has value %d\n",x ); + ATF_REQUIRE_EQ(x, 1); +} + +static void +once2_ofunc(void) +{ + x++; + printf("ofunc: Variable x has value %d\n", x); + x++; +} + +static void * +once2_threadfunc(void *arg) +{ + int num; + + PTHREAD_REQUIRE(pthread_once(&once, once2_ofunc)); + + num = *(int *)arg; + printf("Thread %d sees x with value %d\n", num, x); + ATF_REQUIRE_EQ(x, 2); + + return NULL; +} + +ATF_TC(once2); +ATF_TC_HEAD(once2, tc) +{ + atf_tc_set_md_var(tc, "descr", "Checks pthread_once()"); +} +ATF_TC_BODY(once2, tc) +{ + pthread_t threads[NTHREADS]; + int id[NTHREADS]; + int i; + + printf("1: Test 2 of pthread_once()\n"); + + for (i=0; i < NTHREADS; i++) { + id[i] = i; + PTHREAD_REQUIRE(pthread_create(&threads[i], NULL, once2_threadfunc, &id[i])); + } + + for (i=0; i < NTHREADS; i++) + PTHREAD_REQUIRE(pthread_join(threads[i], NULL)); + + printf("1: X has value %d\n",x ); + ATF_REQUIRE_EQ(x, 2); +} + +static void +once3_cleanup(void *m) +{ + pthread_mutex_t *mu = m; + + PTHREAD_REQUIRE(pthread_mutex_unlock(mu)); +} + +static void +once3_ofunc(void) +{ + pthread_testcancel(); +} + +static void * +once3_threadfunc(void *arg) +{ + PTHREAD_REQUIRE(pthread_mutex_lock(&mutex)); + pthread_cleanup_push(once3_cleanup, &mutex); + PTHREAD_REQUIRE(pthread_once(&once, once3_ofunc)); + pthread_cleanup_pop(1); + + return NULL; +} + +static void +handler(int sig, siginfo_t *info, void *ctx) +{ + atf_tc_fail("Signal handler was called; " + "main thread deadlocked in pthread_once()"); +} + +ATF_TC(once3); +ATF_TC_HEAD(once3, tc) +{ + atf_tc_set_md_var(tc, "descr", "Checks pthread_once()"); +} +ATF_TC_BODY(once3, tc) +{ + pthread_t thread; + struct sigaction act; + struct itimerval it; + printf("Test 3 of pthread_once() (test versus cancellation)\n"); + + act.sa_sigaction = handler; + sigemptyset(&act.sa_mask); + act.sa_flags = SA_SIGINFO; + sigaction(SIGALRM, &act, NULL); + + timerclear(&it.it_value); + it.it_value.tv_usec = 500000; + timerclear(&it.it_interval); + setitimer(ITIMER_REAL, &it, NULL); + + PTHREAD_REQUIRE(pthread_mutex_lock(&mutex)); + PTHREAD_REQUIRE(pthread_create(&thread, NULL, once3_threadfunc, NULL)); + PTHREAD_REQUIRE(pthread_cancel(thread)); + PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex)); + PTHREAD_REQUIRE(pthread_join(thread, NULL)); + + PTHREAD_REQUIRE(pthread_once(&once, ofunc)); + + /* Cancel timer */ + timerclear(&it.it_value); + setitimer(ITIMER_REAL, &it, NULL); + + printf("Test succeeded\n"); +} + +ATF_TP_ADD_TCS(tp) +{ + ATF_TP_ADD_TC(tp, once1); + ATF_TP_ADD_TC(tp, once2); + ATF_TP_ADD_TC(tp, once3); + + return atf_no_error(); +} diff --git a/contrib/netbsd-tests/lib/libpthread/t_preempt.c b/contrib/netbsd-tests/lib/libpthread/t_preempt.c new file mode 100644 index 0000000..7ec43b6 --- /dev/null +++ b/contrib/netbsd-tests/lib/libpthread/t_preempt.c @@ -0,0 +1,128 @@ +/* $NetBSD: t_preempt.c,v 1.2 2010/11/03 16:10:22 christos Exp $ */ + +/* + * Copyright (c) 2008 The NetBSD Foundation, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__COPYRIGHT("@(#) Copyright (c) 2008\ + The NetBSD Foundation, inc. All rights reserved."); +__RCSID("$NetBSD: t_preempt.c,v 1.2 2010/11/03 16:10:22 christos Exp $"); + +#include <errno.h> +#include <fcntl.h> +#include <pthread.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#include <atf-c.h> + +#include "h_common.h" + +pthread_mutex_t mutex; +pthread_cond_t cond; +int started; + +#define HUGE_BUFFER 1<<20 +#define NTHREADS 1 + +static void * +threadfunc(void *arg) +{ + printf("2: Second thread.\n"); + + printf("2: Locking mutex\n"); + PTHREAD_REQUIRE(pthread_mutex_lock(&mutex)); + printf("2: Got mutex.\n"); + started++; + + PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex)); + PTHREAD_REQUIRE(pthread_cond_signal(&cond)); + sleep(1); + + return NULL; +} + +ATF_TC(preempt1); +ATF_TC_HEAD(preempt1, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Checks kernel preemption during a large uiomove"); +} +ATF_TC_BODY(preempt1, tc) +{ + int i; + ssize_t rv; + pthread_t new; + void *joinval; + + char *mem; + int fd; + + mem = malloc(HUGE_BUFFER); + ATF_REQUIRE_MSG(mem != NULL, "%s", strerror(errno)); + + fd = open("/dev/urandom", O_RDONLY, 0); + ATF_REQUIRE_MSG(fd != -1, "%s", strerror(errno)); + + printf("1: preempt test\n"); + + PTHREAD_REQUIRE(pthread_cond_init(&cond, NULL)); + PTHREAD_REQUIRE(pthread_mutex_init(&mutex, NULL)); + + PTHREAD_REQUIRE(pthread_mutex_lock(&mutex)); + + started = 0; + + for (i = 0; i < NTHREADS; i++) { + PTHREAD_REQUIRE(pthread_create(&new, NULL, threadfunc, NULL)); + } + + while (started < NTHREADS) { + PTHREAD_REQUIRE(pthread_cond_wait(&cond, &mutex)); + } + + printf("1: Thread has started.\n"); + + PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex)); + printf("1: After releasing the mutex.\n"); + + rv = read(fd, mem, HUGE_BUFFER); + close(fd); + ATF_REQUIRE_EQ(rv, HUGE_BUFFER); + + PTHREAD_REQUIRE(pthread_join(new, &joinval)); + + printf("1: Thread joined.\n"); +} + +ATF_TP_ADD_TCS(tp) +{ + ATF_TP_ADD_TC(tp, preempt1); + + return atf_no_error(); +} diff --git a/contrib/netbsd-tests/lib/libpthread/t_resolv.sh b/contrib/netbsd-tests/lib/libpthread/t_resolv.sh new file mode 100755 index 0000000..847eadc --- /dev/null +++ b/contrib/netbsd-tests/lib/libpthread/t_resolv.sh @@ -0,0 +1,42 @@ +# $NetBSD: t_resolv.sh,v 1.1 2010/07/16 15:42:53 jmmv Exp $ +# +# Copyright (c) 2008 The NetBSD Foundation, Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + +atf_test_case resolv +resolv_head() +{ + atf_set "descr" "Checks parallel name resolution" +} +resolv_body() +{ + "$(atf_get_srcdir)"/h_resolv -d -n 5 -h 5 \ + "$(atf_get_srcdir)"/d_mach || atf_fail "test failed" +} + +atf_init_test_cases() +{ + atf_add_test_case resolv +} diff --git a/contrib/netbsd-tests/lib/libpthread/t_rwlock.c b/contrib/netbsd-tests/lib/libpthread/t_rwlock.c new file mode 100644 index 0000000..b2a3d6f --- /dev/null +++ b/contrib/netbsd-tests/lib/libpthread/t_rwlock.c @@ -0,0 +1,125 @@ +/* $NetBSD: t_rwlock.c,v 1.1 2010/07/16 15:42:53 jmmv Exp $ */ + +/* + * Copyright (c) 2008 The NetBSD Foundation, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/*- + * Copyright (c)2004 YAMAMOTO Takashi, + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__COPYRIGHT("@(#) Copyright (c) 2008\ + The NetBSD Foundation, inc. All rights reserved."); +__RCSID("$NetBSD: t_rwlock.c,v 1.1 2010/07/16 15:42:53 jmmv Exp $"); + +#include <errno.h> +#include <pthread.h> +#include <stdlib.h> +#include <string.h> + +#include <atf-c.h> + +#include "h_common.h" + +pthread_rwlock_t lk; + +struct timespec to; + +/* ARGSUSED */ +static void * +do_nothing(void *dummy) +{ + return NULL; +} + +ATF_TC(rwlock1); +ATF_TC_HEAD(rwlock1, tc) +{ + atf_tc_set_md_var(tc, "descr", "Checks read/write locks"); +} +ATF_TC_BODY(rwlock1, tc) +{ + int error; + pthread_t t; + + PTHREAD_REQUIRE(pthread_create(&t, NULL, do_nothing, NULL)); + PTHREAD_REQUIRE(pthread_rwlock_init(&lk, NULL)); + PTHREAD_REQUIRE(pthread_rwlock_rdlock(&lk)); + PTHREAD_REQUIRE(pthread_rwlock_rdlock(&lk)); + PTHREAD_REQUIRE(pthread_rwlock_unlock(&lk)); + + ATF_REQUIRE_EQ(pthread_rwlock_trywrlock(&lk), EBUSY); + + ATF_REQUIRE_EQ_MSG(clock_gettime(CLOCK_REALTIME, &to), 0, + "%s", strerror(errno)); + to.tv_sec++; + error = pthread_rwlock_timedwrlock(&lk, &to); + ATF_REQUIRE_MSG(error == ETIMEDOUT || error == EDEADLK, + "%s", strerror(error)); + + PTHREAD_REQUIRE(pthread_rwlock_unlock(&lk)); + + ATF_REQUIRE_EQ_MSG(clock_gettime(CLOCK_REALTIME, &to), 0, + "%s", strerror(errno)); + to.tv_sec++; + PTHREAD_REQUIRE(pthread_rwlock_timedwrlock(&lk, &to)); + + ATF_REQUIRE_EQ_MSG(clock_gettime(CLOCK_REALTIME, &to), 0, + "%s", strerror(errno)); + to.tv_sec++; + error = pthread_rwlock_timedwrlock(&lk, &to); + ATF_REQUIRE_MSG(error == ETIMEDOUT || error == EDEADLK, + "%s", strerror(error)); +} + +ATF_TP_ADD_TCS(tp) +{ + ATF_TP_ADD_TC(tp, rwlock1); + + return atf_no_error(); +} diff --git a/contrib/netbsd-tests/lib/libpthread/t_sem.c b/contrib/netbsd-tests/lib/libpthread/t_sem.c new file mode 100644 index 0000000..5bb7ae7 --- /dev/null +++ b/contrib/netbsd-tests/lib/libpthread/t_sem.c @@ -0,0 +1,310 @@ +/* $NetBSD: t_sem.c,v 1.8 2014/11/04 00:20:19 justin Exp $ */ + +/* + * Copyright (c) 2008, 2010 The NetBSD Foundation, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/*- + * Copyright (c)2004 YAMAMOTO Takashi, + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/**************************************************************************** + * + * Copyright (C) 2000 Jason Evans <jasone@freebsd.org>. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice(s), this list of conditions and the following disclaimer as + * the first lines of this file unmodified other than the possible + * addition of one or more copyright notices. + * 2. Redistributions in binary form must reproduce the above copyright + * notice(s), this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#include <sys/cdefs.h> +__COPYRIGHT("@(#) Copyright (c) 2008, 2010\ + The NetBSD Foundation, inc. All rights reserved."); +__RCSID("$NetBSD: t_sem.c,v 1.8 2014/11/04 00:20:19 justin Exp $"); + +#include <errno.h> +#include <fcntl.h> +#include <pthread.h> +#include <semaphore.h> +#include <signal.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#include <atf-c.h> + +#include "h_common.h" + +#define NTHREADS 10 + +#define _LIBC_R_ + +#define SEM_REQUIRE(x) \ + ATF_REQUIRE_EQ_MSG(x, 0, "%s", strerror(errno)) + +static sem_t sem; + +#ifdef __FreeBSD__ +#include <sys/time.h> +#endif + +ATF_TC(named); +ATF_TC_HEAD(named, tc) +{ + atf_tc_set_md_var(tc, "descr", "Checks named semaphores"); +} +ATF_TC_BODY(named, tc) +{ + sem_t *semp; + + ATF_REQUIRE_MSG(-1 != sysconf(_SC_SEMAPHORES), "%s", strerror(errno)); + + printf("Test begin\n"); + + (void) sem_unlink("/foo"); + semp = sem_open("/foo", O_CREAT | O_EXCL, 0644, 0); + ATF_REQUIRE_MSG(semp != SEM_FAILED, "%s", strerror(errno)); + SEM_REQUIRE(sem_close(semp)); + SEM_REQUIRE(sem_unlink("/foo")); + + printf("Test end\n"); +} + +ATF_TC(unnamed); +ATF_TC_HEAD(unnamed, tc) +{ + atf_tc_set_md_var(tc, "descr", "Checks unnamed semaphores"); +} + +static void * +entry(void * a_arg) +{ + pthread_t self = pthread_self(); + sem_t *semp = (sem_t *) a_arg; + + printf("Thread %p waiting for semaphore...\n", self); + sem_wait(semp); + printf("Thread %p got semaphore\n", self); + + return NULL; +} + +ATF_TC_BODY(unnamed, tc) +{ + sem_t sem_a, sem_b; + pthread_t threads[NTHREADS]; + unsigned i, j; + int val; + + ATF_REQUIRE_MSG(-1 != sysconf(_SC_SEMAPHORES), "%s", strerror(errno)); + + printf("Test begin\n"); + + SEM_REQUIRE(sem_init(&sem_b, 0, 0)); + SEM_REQUIRE(sem_getvalue(&sem_b, &val)); + ATF_REQUIRE_EQ(0, val); + + SEM_REQUIRE(sem_post(&sem_b)); + SEM_REQUIRE(sem_getvalue(&sem_b, &val)); + ATF_REQUIRE_EQ(1, val); + + SEM_REQUIRE(sem_wait(&sem_b)); + ATF_REQUIRE_EQ(sem_trywait(&sem_b), -1); + ATF_REQUIRE_EQ(errno, EAGAIN); + SEM_REQUIRE(sem_post(&sem_b)); + SEM_REQUIRE(sem_trywait(&sem_b)); + SEM_REQUIRE(sem_post(&sem_b)); + SEM_REQUIRE(sem_wait(&sem_b)); + SEM_REQUIRE(sem_post(&sem_b)); + + SEM_REQUIRE(sem_destroy(&sem_b)); + + SEM_REQUIRE(sem_init(&sem_a, 0, 0)); + + for (j = 0; j < 2; j++) { + for (i = 0; i < NTHREADS; i++) { + PTHREAD_REQUIRE(pthread_create(&threads[i], NULL, + entry, (void *) &sem_a)); + } + + for (i = 0; i < NTHREADS; i++) { + usleep(10000); + printf("main loop %u: posting...\n", j+1); + SEM_REQUIRE(sem_post(&sem_a)); + } + + for (i = 0; i < NTHREADS; i++) { + PTHREAD_REQUIRE(pthread_join(threads[i], NULL)); + } + } + + SEM_REQUIRE(sem_destroy(&sem_a)); + + printf("Test end\n"); +} + +static void +sighandler(int signo) +{ + /* printf("signal %d\n", signo); */ + + ATF_REQUIRE_EQ_MSG(signo, SIGALRM, "unexpected signal"); + SEM_REQUIRE(sem_post(&sem)); +} + +static void +alarm_ms(const int ms) +{ + struct itimerval timer; + timer.it_interval.tv_sec = 0; + timer.it_interval.tv_usec = 0; + timer.it_value.tv_sec = 0; + timer.it_value.tv_usec = ms * 1000; + ATF_REQUIRE(setitimer(ITIMER_REAL, &timer, NULL) == 0); +} + +static void * +threadfunc(void *arg) +{ + int i, ret; + + printf("Entering loop\n"); + for (i = 0; i < 500; ) { + if ((i & 1) != 0) { + do { + ret = sem_wait(&sem); + } while (ret == -1 && errno == EINTR); + ATF_REQUIRE(ret == 0); + } else { + ret = sem_trywait(&sem); + if (ret == -1) { + ATF_REQUIRE(errno == EAGAIN); + continue; + } + } + printf("%s: %d\n", __func__, i); + alarm_ms(5); + i++; + } + + return NULL; +} + +static void +before_start_test(const bool use_pthread) +{ + pthread_t t; + + SEM_REQUIRE(sem_init(&sem, 0, 0)); + ATF_REQUIRE(SIG_ERR != signal(SIGALRM, sighandler)); + + alarm_ms(5); + + if (use_pthread) { + PTHREAD_REQUIRE(pthread_create(&t, NULL, threadfunc, NULL)); + PTHREAD_REQUIRE(pthread_join(t, NULL)); + } else { + threadfunc(NULL); + } +} + +ATF_TC(before_start_no_threads); +ATF_TC_HEAD(before_start_no_threads, tc) +{ + atf_tc_set_md_var(tc, "descr", "Checks using semaphores without any " + "thread running"); + atf_tc_set_md_var(tc, "timeout", "40"); +} +ATF_TC_BODY(before_start_no_threads, tc) +{ + before_start_test(false); +} + +ATF_TC(before_start_one_thread); +ATF_TC_HEAD(before_start_one_thread, tc) +{ + atf_tc_set_md_var(tc, "descr", "Checks using semaphores before " + "starting one thread"); + atf_tc_set_md_var(tc, "timeout", "40"); +} +ATF_TC_BODY(before_start_one_thread, tc) +{ + before_start_test(true); +} + +ATF_TP_ADD_TCS(tp) +{ + ATF_TP_ADD_TC(tp, named); + ATF_TP_ADD_TC(tp, unnamed); + ATF_TP_ADD_TC(tp, before_start_no_threads); + ATF_TP_ADD_TC(tp, before_start_one_thread); + + return atf_no_error(); +} diff --git a/contrib/netbsd-tests/lib/libpthread/t_sigalarm.c b/contrib/netbsd-tests/lib/libpthread/t_sigalarm.c new file mode 100644 index 0000000..0a58c4e --- /dev/null +++ b/contrib/netbsd-tests/lib/libpthread/t_sigalarm.c @@ -0,0 +1,107 @@ +/* $NetBSD: t_sigalarm.c,v 1.1 2010/07/16 15:42:53 jmmv Exp $ */ + +/* + * Copyright (c) 2008 The NetBSD Foundation, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__COPYRIGHT("@(#) Copyright (c) 2008\ + The NetBSD Foundation, inc. All rights reserved."); +__RCSID("$NetBSD: t_sigalarm.c,v 1.1 2010/07/16 15:42:53 jmmv Exp $"); + +#include <stdio.h> +#include <signal.h> +#include <unistd.h> +#include <pthread.h> + +#include <atf-c.h> + +#include "h_common.h" + +int alarm_set; + +#ifdef SA_SIGINFO +static void +alarm_handler(int signo, siginfo_t *si, void *ctx) +{ + ATF_REQUIRE_EQ_MSG(si->si_signo, signo, "Received unexpected signal"); + alarm_set = 1; +} +#else +static void +alarm_handler(int signo) +{ + ATF_REQUIRE_EQ_MSG(SIGALRM, signo, "Received unexpected signal"); + alarm_set = 1; +} +#endif + +static void * +setup(void *dummy) +{ + struct sigaction sa; + sigset_t ss; +#ifdef SA_SIGINFO + sa.sa_flags = SA_SIGINFO; + sa.sa_sigaction = alarm_handler; +#else + sa.sa_flags = 0; + sa.sa_handler = alarm_handler; +#endif + sigfillset(&ss); + sigprocmask(SIG_SETMASK, &ss, NULL); + sigemptyset(&sa.sa_mask); + sigaction(SIGALRM, &sa, NULL); + alarm(1); + + return NULL; +} + +ATF_TC(sigalarm); +ATF_TC_HEAD(sigalarm, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Checks sigsuspend in libpthread when pthread lib is initialized"); +} +ATF_TC_BODY(sigalarm, tc) +{ + sigset_t set; + pthread_t self = pthread_self(); + + PTHREAD_REQUIRE(pthread_create(&self, NULL, setup, NULL)); + + sigemptyset(&set); + sigsuspend(&set); + alarm(0); + + ATF_REQUIRE(alarm_set); +} + +ATF_TP_ADD_TCS(tp) +{ + ATF_TP_ADD_TC(tp, sigalarm); + + return atf_no_error(); +} diff --git a/contrib/netbsd-tests/lib/libpthread/t_siglongjmp.c b/contrib/netbsd-tests/lib/libpthread/t_siglongjmp.c new file mode 100644 index 0000000..298879c --- /dev/null +++ b/contrib/netbsd-tests/lib/libpthread/t_siglongjmp.c @@ -0,0 +1,109 @@ +/* $NetBSD: t_siglongjmp.c,v 1.1 2010/07/16 15:42:53 jmmv Exp $ */ + +/* + * Copyright (c) 2008 The NetBSD Foundation, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__COPYRIGHT("@(#) Copyright (c) 2008\ + The NetBSD Foundation, inc. All rights reserved."); +__RCSID("$NetBSD: t_siglongjmp.c,v 1.1 2010/07/16 15:42:53 jmmv Exp $"); + +/* + * Regression test for siglongjmp out of a signal handler back into + * its thread. + * + * Written by Christian Limpach <cl@NetBSD.org>, December 2003. + * Public domain. + */ + +#include <sys/resource.h> + +#include <pthread.h> +#include <setjmp.h> +#include <signal.h> +#include <unistd.h> + +#include <atf-c.h> + +#include "h_common.h" + +static sigjmp_buf env; + +static void * +thread(void *arg) +{ + return NULL; +} + +static void +handler(int sig, siginfo_t *info, void *ctx) +{ + siglongjmp(env, 1); +} + +ATF_TC(siglongjmp1); +ATF_TC_HEAD(siglongjmp1, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Checks siglongjmp() out of a signal handler back into its thread"); +} +ATF_TC_BODY(siglongjmp1, tc) +{ + pthread_t t; + sigset_t nset; + struct rlimit rlim; + struct sigaction act; + + rlim.rlim_cur = rlim.rlim_max = 0; + (void)setrlimit(RLIMIT_CORE, &rlim); + + PTHREAD_REQUIRE(pthread_create(&t, NULL, thread, NULL)); + + sigemptyset(&nset); + sigaddset(&nset, SIGUSR1); + PTHREAD_REQUIRE(pthread_sigmask(SIG_SETMASK, &nset, NULL)); + + act.sa_sigaction = handler; + sigemptyset(&act.sa_mask); + sigaddset(&act.sa_mask, SIGUSR2); + act.sa_flags = 0; + sigaction(SIGSEGV, &act, NULL); + + ATF_REQUIRE_EQ(sigsetjmp(env, 1), 0); + + PTHREAD_REQUIRE(pthread_sigmask(0, NULL, &nset)); + + ATF_REQUIRE_EQ_MSG(sigismember(&nset, SIGSEGV), 0, "SIGSEGV set"); + ATF_REQUIRE_EQ_MSG(sigismember(&nset, SIGUSR2), 0, "SIGUSR2 set"); + ATF_REQUIRE_MSG(sigismember(&nset, SIGUSR1), "SIGUSR1 not set"); +} + +ATF_TP_ADD_TCS(tp) +{ + ATF_TP_ADD_TC(tp, siglongjmp1); + + return atf_no_error(); +} diff --git a/contrib/netbsd-tests/lib/libpthread/t_sigmask.c b/contrib/netbsd-tests/lib/libpthread/t_sigmask.c new file mode 100644 index 0000000..69e0577 --- /dev/null +++ b/contrib/netbsd-tests/lib/libpthread/t_sigmask.c @@ -0,0 +1,261 @@ +/* $NetBSD: t_sigmask.c,v 1.3 2013/10/19 17:45:01 christos Exp $ */ + +/* + * Copyright (c) 2008, 2010 The NetBSD Foundation, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__COPYRIGHT("@(#) Copyright (c) 2008, 2010\ + The NetBSD Foundation, inc. All rights reserved."); +__RCSID("$NetBSD: t_sigmask.c,v 1.3 2013/10/19 17:45:01 christos Exp $"); + +/* + * Regression test for pthread_sigmask when SA upcalls aren't started yet. + * + * Written by Christian Limpach <cl@NetBSD.org>, December 2003. + * Public domain. + */ + +#include <errno.h> +#include <pthread.h> +#include <signal.h> +#include <stdio.h> +#include <unistd.h> + +#include <sys/resource.h> + +#include <atf-c.h> + +#include "h_common.h" + +static volatile sig_atomic_t flag; +static volatile sig_atomic_t flag2; + +static volatile pthread_t thr_usr1; +static volatile pthread_t thr_usr2; + +static sig_atomic_t count = 0; + +ATF_TC(upcalls_not_started); +ATF_TC_HEAD(upcalls_not_started, tc) +{ + atf_tc_set_md_var(tc, "descr", "Checks pthread_sigmask when SA upcalls " + "aren't started yet"); +} +ATF_TC_BODY(upcalls_not_started, tc) +{ + sigset_t nset; + struct rlimit rlim; + + rlim.rlim_cur = rlim.rlim_max = 0; + (void) setrlimit(RLIMIT_CORE, &rlim); + + sigemptyset(&nset); + sigaddset(&nset, SIGFPE); + pthread_sigmask(SIG_BLOCK, &nset, NULL); + + kill(getpid(), SIGFPE); +} + +static void +upcalls_not_started_handler1(int sig, siginfo_t *info, void *ctx) +{ + + kill(getpid(), SIGUSR2); + /* + * If the mask is properly set, SIGUSR2 will not be handled + * until this handler returns. + */ + flag = 1; +} + +static void +upcalls_not_started_handler2(int sig, siginfo_t *info, void *ctx) +{ + if (flag == 1) + flag = 2; +} + +ATF_TC(before_threads); +ATF_TC_HEAD(before_threads, tc) +{ + atf_tc_set_md_var(tc, "descr", "Checks that signal masks are respected " + "before threads are started"); +} +ATF_TC_BODY(before_threads, tc) +{ + struct sigaction act; + + act.sa_sigaction = upcalls_not_started_handler1; + sigemptyset(&act.sa_mask); + sigaddset(&act.sa_mask, SIGUSR2); + act.sa_flags = SA_SIGINFO; + + ATF_REQUIRE_EQ(sigaction(SIGUSR1, &act, NULL), 0); + + act.sa_sigaction = upcalls_not_started_handler2; + sigemptyset(&act.sa_mask); + act.sa_flags = SA_SIGINFO; + (void)sigaction(SIGUSR2, &act, NULL); + + kill(getpid(), SIGUSR1); + + ATF_REQUIRE_EQ(flag, 2); + printf("Success: Both handlers ran in order\n"); +} + +static void +respected_while_running_handler1(int sig, siginfo_t *info, void *ctx) +{ + + kill(getpid(), SIGUSR2); + /* + * If the mask is properly set, SIGUSR2 will not be handled + * by the current thread until this handler returns. + */ + flag = 1; + thr_usr1 = pthread_self(); +} + +static void +respected_while_running_handler2(int sig, siginfo_t *info, void *ctx) +{ + if (flag == 1) + flag = 2; + flag2 = 1; + thr_usr2 = pthread_self(); +} + +static void * +respected_while_running_threadroutine(void *arg) +{ + + kill(getpid(), SIGUSR1); + sleep(1); + + if (flag == 2) + printf("Success: Both handlers ran in order\n"); + else if (flag == 1 && flag2 == 1 && thr_usr1 != thr_usr2) + printf("Success: Handlers were invoked by different threads\n"); + else { + printf("Failure: flag=%d, flag2=%d, thr1=%p, thr2=%p\n", + (int)flag, (int)flag2, (void *)thr_usr1, (void *)thr_usr2); + atf_tc_fail("failure"); + } + + return NULL; +} + +ATF_TC(respected_while_running); +ATF_TC_HEAD(respected_while_running, tc) +{ + atf_tc_set_md_var(tc, "descr", "Checks that signal masks are respected " + "while threads are running"); +} +ATF_TC_BODY(respected_while_running, tc) +{ + struct sigaction act; + pthread_t thread; + + act.sa_sigaction = respected_while_running_handler1; + sigemptyset(&act.sa_mask); + sigaddset(&act.sa_mask, SIGUSR2); + act.sa_flags = SA_SIGINFO; + + ATF_REQUIRE_EQ(sigaction(SIGUSR1, &act, NULL), 0); + + act.sa_sigaction = respected_while_running_handler2; + sigemptyset(&act.sa_mask); + act.sa_flags = SA_SIGINFO; + (void)sigaction(SIGUSR2, &act, NULL); + + PTHREAD_REQUIRE(pthread_create(&thread, NULL, + respected_while_running_threadroutine, NULL)); + PTHREAD_REQUIRE(pthread_join(thread, NULL)); +} + +static void +incorrect_mask_bug_handler(int sig) +{ + count++; +} + +static void * +incorrect_mask_bug_sleeper(void* arg) +{ + int i; + for (i = 0; i < 10; i++) + sleep(1); + + atf_tc_fail("sleeper"); +} + +ATF_TC(incorrect_mask_bug); +ATF_TC_HEAD(incorrect_mask_bug, tc) +{ + atf_tc_set_md_var(tc, "descr", "Checks for bug in libpthread where " + "incorrect signal mask was used"); +} +ATF_TC_BODY(incorrect_mask_bug, tc) +{ + pthread_t id; + struct sigaction act; + + act.sa_sigaction = NULL; + sigemptyset(&act.sa_mask); + act.sa_flags = 0; + act.sa_handler = incorrect_mask_bug_handler; + + ATF_REQUIRE_EQ_MSG(sigaction(SIGALRM, &act, NULL), 0, "%s", + strerror(errno)); + + sigaddset(&act.sa_mask, SIGALRM); + PTHREAD_REQUIRE(pthread_sigmask(SIG_SETMASK, &act.sa_mask, NULL)); + + PTHREAD_REQUIRE(pthread_create(&id, NULL, incorrect_mask_bug_sleeper, + NULL)); + sleep(1); + + sigemptyset(&act.sa_mask); + PTHREAD_REQUIRE(pthread_sigmask(SIG_SETMASK, &act.sa_mask, NULL)); + + for (;;) { + alarm(1); + if (select(1, NULL, NULL, NULL, NULL) == -1 && errno == EINTR) + if (count == 2) + return; + } +} + +ATF_TP_ADD_TCS(tp) +{ + + ATF_TP_ADD_TC(tp, upcalls_not_started); + ATF_TP_ADD_TC(tp, before_threads); + ATF_TP_ADD_TC(tp, respected_while_running); + ATF_TP_ADD_TC(tp, incorrect_mask_bug); + + return atf_no_error(); +} diff --git a/contrib/netbsd-tests/lib/libpthread/t_sigsuspend.c b/contrib/netbsd-tests/lib/libpthread/t_sigsuspend.c new file mode 100644 index 0000000..1179657 --- /dev/null +++ b/contrib/netbsd-tests/lib/libpthread/t_sigsuspend.c @@ -0,0 +1,90 @@ +/* $NetBSD: t_sigsuspend.c,v 1.1 2010/07/16 15:42:53 jmmv Exp $ */ + +/* + * Copyright (c) 2008 The NetBSD Foundation, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__COPYRIGHT("@(#) Copyright (c) 2008\ + The NetBSD Foundation, inc. All rights reserved."); +__RCSID("$NetBSD: t_sigsuspend.c,v 1.1 2010/07/16 15:42:53 jmmv Exp $"); + +/* + * Regression test for sigsuspend in libpthread when pthread lib isn't + * initialized. + * + * Written by Love FIXME strand <lha@NetBSD.org>, March 2003. + * Public domain. + */ + +#include <stdio.h> +#include <signal.h> +#include <unistd.h> + +#include <atf-c.h> + +int alarm_set; + +static void +alarm_handler(int signo) +{ + alarm_set = 1; +} + +ATF_TC(sigsuspend); +ATF_TC_HEAD(sigsuspend, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Checks sigsuspend in libpthread when pthread lib isn't initialized"); +} +ATF_TC_BODY(sigsuspend, tc) +{ + struct sigaction sa; + sigset_t set; + + sa.sa_flags = 0; + sa.sa_handler = alarm_handler; + sigemptyset(&sa.sa_mask); + + sigaction(SIGALRM, &sa, NULL); + + alarm(1); + + sigemptyset(&set); + sigaddset(&set, SIGUSR1); + + sigsuspend(&set); + + alarm(0); + + ATF_REQUIRE(alarm_set); +} + +ATF_TP_ADD_TCS(tp) +{ + ATF_TP_ADD_TC(tp, sigsuspend); + + return atf_no_error(); +} diff --git a/contrib/netbsd-tests/lib/libpthread/t_sleep.c b/contrib/netbsd-tests/lib/libpthread/t_sleep.c new file mode 100644 index 0000000..93a30e3 --- /dev/null +++ b/contrib/netbsd-tests/lib/libpthread/t_sleep.c @@ -0,0 +1,104 @@ +/* $NetBSD: t_sleep.c,v 1.1 2010/07/16 15:42:53 jmmv Exp $ */ + +/* + * Copyright (c) 2008 The NetBSD Foundation, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__COPYRIGHT("@(#) Copyright (c) 2008\ + The NetBSD Foundation, inc. All rights reserved."); +__RCSID("$NetBSD: t_sleep.c,v 1.1 2010/07/16 15:42:53 jmmv Exp $"); + +#include <sys/time.h> + +#include <pthread.h> +#include <signal.h> +#include <stdio.h> +#include <unistd.h> + +#include <atf-c.h> + +#include "h_common.h" + +#define LONGTIME 2000000000 + +static void * +threadfunc(void *arg) +{ + sleep(LONGTIME); + + return NULL; +} + +static void +handler(int sig) +{ + /* + * Nothing to do; invoking the handler is enough to interrupt + * the sleep. + */ +} + +ATF_TC(sleep1); +ATF_TC_HEAD(sleep1, tc) +{ + atf_tc_set_md_var(tc, "descr", "Checks sleeping past the time when " + "time_t wraps"); +} +ATF_TC_BODY(sleep1, tc) +{ + pthread_t thread; + struct itimerval it; + struct sigaction act; + sigset_t mtsm; + + printf("Testing sleeps unreasonably far into the future.\n"); + + act.sa_handler = handler; + sigemptyset(&act.sa_mask); + act.sa_flags = 0; + sigaction(SIGALRM, &act, NULL); + + PTHREAD_REQUIRE(pthread_create(&thread, NULL, threadfunc, NULL)); + + /* make sure the signal is delivered to the child thread */ + sigemptyset(&mtsm); + sigaddset(&mtsm, SIGALRM); + PTHREAD_REQUIRE(pthread_sigmask(SIG_BLOCK, &mtsm, 0)); + + timerclear(&it.it_interval); + timerclear(&it.it_value); + it.it_value.tv_sec = 1; + setitimer(ITIMER_REAL, &it, NULL); + + PTHREAD_REQUIRE(pthread_join(thread, NULL)); +} + +ATF_TP_ADD_TCS(tp) +{ + ATF_TP_ADD_TC(tp, sleep1); + + return atf_no_error(); +} diff --git a/contrib/netbsd-tests/lib/libpthread/t_swapcontext.c b/contrib/netbsd-tests/lib/libpthread/t_swapcontext.c new file mode 100644 index 0000000..8fd2314 --- /dev/null +++ b/contrib/netbsd-tests/lib/libpthread/t_swapcontext.c @@ -0,0 +1,112 @@ +/* $NetBSD: t_swapcontext.c,v 1.2 2014/08/25 16:31:15 bouyer Exp $ */ + +/* + * Copyright (c) 2012 Emmanuel Dreyfus. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__RCSID("$NetBSD"); + +#include <pthread.h> +#include <ucontext.h> +#include <stdio.h> +#include <stdlib.h> + +#include <atf-c.h> + +#include "h_common.h" + +#define STACKSIZE 65536 + +char stack[STACKSIZE]; +ucontext_t nctx; +ucontext_t octx; +void *oself; +void *nself; +int val1, val2; + +/* ARGSUSED0 */ +static void +swapfunc(void *arg) +{ + /* + * If the test fails, we are very likely to crash + * without the opportunity to report + */ + nself = (void *)pthread_self(); + printf("after swapcontext self = %p\n", nself); + + ATF_REQUIRE_EQ(oself, nself); + printf("Test succeeded\n"); + /* Go back in main */ + ATF_REQUIRE(swapcontext(&nctx, &octx)); + + /* NOTREACHED */ + return; +} + +/* ARGSUSED0 */ +static void * +threadfunc(void *arg) +{ + nctx.uc_stack.ss_sp = stack; + nctx.uc_stack.ss_size = sizeof(stack); + + makecontext(&nctx, (void *)*swapfunc, 0); + + oself = (void *)pthread_self(); + printf("before swapcontext self = %p\n", oself); + PTHREAD_REQUIRE(swapcontext(&octx, &nctx)); + + /* NOTREACHED */ + return NULL; +} + + +ATF_TC(swapcontext1); +ATF_TC_HEAD(swapcontext1, tc) +{ + atf_tc_set_md_var(tc, "descr", "Testing if swapcontext() " + "alters pthread_self()"); +} +ATF_TC_BODY(swapcontext1, tc) +{ + pthread_t thread; + + oself = (void *)&val1; + nself = (void *)&val2; + + printf("Testing if swapcontext() alters pthread_self()\n"); + + PTHREAD_REQUIRE(getcontext(&nctx)); + PTHREAD_REQUIRE(pthread_create(&thread, NULL, threadfunc, NULL)); + PTHREAD_REQUIRE(pthread_join(thread, NULL)); +} + +ATF_TP_ADD_TCS(tp) +{ + ATF_TP_ADD_TC(tp, swapcontext1); + + return atf_no_error(); +} |