summaryrefslogtreecommitdiffstats
path: root/contrib/netbsd-tests/lib/libc/stdlib
diff options
context:
space:
mode:
authorngie <ngie@FreeBSD.org>2014-12-31 20:13:31 +0000
committerngie <ngie@FreeBSD.org>2014-12-31 20:13:31 +0000
commitb429a2bfd1380c777b9d59e54e17886b3855073e (patch)
treef5eb9fb5c3b79a2f3a7cba500581d24f4676622d /contrib/netbsd-tests/lib/libc/stdlib
parent155ee9c2f7fcb97a502844e0ca346b9f919b8cb2 (diff)
downloadFreeBSD-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/libc/stdlib')
-rw-r--r--contrib/netbsd-tests/lib/libc/stdlib/h_atexit.c212
-rw-r--r--contrib/netbsd-tests/lib/libc/stdlib/h_getopt.c130
-rw-r--r--contrib/netbsd-tests/lib/libc/stdlib/h_getopt_long.c242
-rw-r--r--contrib/netbsd-tests/lib/libc/stdlib/t_abs.c154
-rwxr-xr-xcontrib/netbsd-tests/lib/libc/stdlib/t_atexit.sh54
-rw-r--r--contrib/netbsd-tests/lib/libc/stdlib/t_atoi.c121
-rw-r--r--contrib/netbsd-tests/lib/libc/stdlib/t_div.c98
-rw-r--r--contrib/netbsd-tests/lib/libc/stdlib/t_exit.c186
-rw-r--r--contrib/netbsd-tests/lib/libc/stdlib/t_getenv.c211
-rw-r--r--contrib/netbsd-tests/lib/libc/stdlib/t_getenv_thread.c250
-rwxr-xr-xcontrib/netbsd-tests/lib/libc/stdlib/t_getopt.sh123
-rw-r--r--contrib/netbsd-tests/lib/libc/stdlib/t_hsearch.c411
-rw-r--r--contrib/netbsd-tests/lib/libc/stdlib/t_mi_vector_hash.c95
-rw-r--r--contrib/netbsd-tests/lib/libc/stdlib/t_posix_memalign.c88
-rw-r--r--contrib/netbsd-tests/lib/libc/stdlib/t_random.c82
-rw-r--r--contrib/netbsd-tests/lib/libc/stdlib/t_strtod.c342
-rw-r--r--contrib/netbsd-tests/lib/libc/stdlib/t_strtol.c234
-rw-r--r--contrib/netbsd-tests/lib/libc/stdlib/t_system.c83
18 files changed, 3116 insertions, 0 deletions
diff --git a/contrib/netbsd-tests/lib/libc/stdlib/h_atexit.c b/contrib/netbsd-tests/lib/libc/stdlib/h_atexit.c
new file mode 100644
index 0000000..c0641db
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libc/stdlib/h_atexit.c
@@ -0,0 +1,212 @@
+/* $NetBSD: h_atexit.c,v 1.1 2011/01/12 19:44:08 pgoyette Exp $ */
+
+/*-
+ * Copyright (c) 2011 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code was contributed to The NetBSD Foundation by Jason R. Thorpe.
+ *
+ * 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) 2011\
+ The NetBSD Foundation, inc. All rights reserved.");
+__RCSID("$NetBSD: h_atexit.c,v 1.1 2011/01/12 19:44:08 pgoyette 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__
+/*
+ * On shared object unload, in __cxa_finalize, call and clear all installed
+ * atexit and __cxa_atexit handlers that are either installed by unloaded
+ * dso, or points to the functions provided by the dso.
+ *
+ * The reason of the change is to ensure that there is no lingering pointers
+ * to the unloaded code after the dlclose(3). It is known reason for infinite
+ * stream of the crash reports for many programs which use loadable modules
+ * and fail to properly clean on module unload. Examples are apache, php,
+ * perl etc.
+ *
+ * You pass the &dso_handle_1 and &dso_handle_2, which points inside the
+ * main binary, to the registration function. The code from r211706,
+ * correctly detects that they are for the main binary, and on the first
+ * call to __cxa_finalize(), which also pass pointer to main binary, all
+ * registered functions from the main binary are executed.
+ */
+
+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;
+
+ ASSERT(0 == atexit(normal_handler_0));
+ ASSERT(0 == atexit(normal_handler_1));
+#ifdef __FreeBSD__
+ 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/libc/stdlib/h_getopt.c b/contrib/netbsd-tests/lib/libc/stdlib/h_getopt.c
new file mode 100644
index 0000000..ec2b9bb
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libc/stdlib/h_getopt.c
@@ -0,0 +1,130 @@
+/* $NetBSD: h_getopt.c,v 1.1 2011/01/01 23:56:49 pgoyette Exp $ */
+
+/*-
+ * Copyright (c) 2002 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 <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <err.h>
+#ifdef __FreeBSD__
+#include <libutil.h>
+#endif
+
+#define WS "\t\n "
+#define debug 0
+
+int
+main(int argc, char *argv[])
+{
+ size_t len, lineno = 0;
+ char *line, *ptr, *optstring = NULL, *result = NULL;
+ char buf[1024];
+ char *args[100];
+ char arg[100];
+ int nargs = -1;
+ int c;
+
+ while ((line = fparseln(stdin, &len, &lineno, NULL, 0)) != NULL) {
+ if (strncmp(line, "load:", 5) == 0) {
+ if (optstring)
+ free(optstring);
+ optstring = strtok(&line[6], WS);
+ if (optstring == NULL)
+ errx(1, "missing optstring at line %ld",
+ (unsigned long)lineno);
+ optstring = strdup(optstring);
+ if (debug)
+ fprintf(stderr, "optstring = %s\n", optstring);
+ } else if (strncmp(line, "args:", 5) == 0) {
+ for (; nargs >= 0; nargs--) {
+ if (args[nargs] != NULL)
+ free(args[nargs]);
+ }
+ args[nargs = 0] = strtok(&line[6], WS);
+ if (args[nargs] == NULL)
+ errx(1, "missing args at line %ld",
+ (unsigned long)lineno);
+
+ args[nargs] = strdup(args[nargs]);
+ while ((args[++nargs] = strtok(NULL, WS)) != NULL)
+ args[nargs] = strdup(args[nargs]);
+ if (debug) {
+ int i = 0;
+ for (i = 0; i < nargs; i++)
+ fprintf(stderr, "argv[%d] = %s\n", i,
+ args[i]);
+ }
+ } else if (strncmp(line, "result:", 7) == 0) {
+ buf[0] = '\0';
+ optind = optreset = 1;
+ if (result)
+ free(result);
+ result = strtok(&line[8], WS);
+ if (result == NULL)
+ errx(1, "missing result at line %ld",
+ (unsigned long)lineno);
+ result = strdup(result);
+ if (nargs == -1)
+ errx(1, "result: without args:");
+ if (debug)
+ fprintf(stderr, "result = %s\n", result);
+ while ((c = getopt(nargs, args, optstring)) != -1) {
+ if (c == ':')
+ err(1, "`:' found as argument char");
+ if ((ptr = strchr(optstring, c)) == NULL) {
+ snprintf(arg, sizeof(arg), "!%c,", c);
+ strcat(buf, arg);
+ continue;
+ }
+ if (ptr[1] != ':')
+ snprintf(arg, sizeof(arg), "%c,", c);
+ else
+ snprintf(arg, sizeof(arg), "%c=%s,",
+ c, optarg);
+ strcat(buf, arg);
+ }
+ len = strlen(buf);
+ if (len > 0) {
+ buf[len - 1] = '|';
+ buf[len] = '\0';
+ } else {
+ buf[0] = '|';
+ buf[1] = '\0';
+ }
+ snprintf(arg, sizeof(arg), "%d", nargs - optind);
+ strcat(buf, arg);
+ if (strcmp(buf, result) != 0)
+ errx(1, "`%s' != `%s'", buf, result);
+ }
+ free(line);
+ }
+ return 0;
+}
diff --git a/contrib/netbsd-tests/lib/libc/stdlib/h_getopt_long.c b/contrib/netbsd-tests/lib/libc/stdlib/h_getopt_long.c
new file mode 100644
index 0000000..2293e2c
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libc/stdlib/h_getopt_long.c
@@ -0,0 +1,242 @@
+/* $NetBSD: h_getopt_long.c,v 1.1 2011/01/01 23:56:49 pgoyette Exp $ */
+
+/*-
+ * Copyright (c) 2007 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 <ctype.h>
+#include <err.h>
+#include <getopt.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#ifdef __FreeBSD__
+#include <libutil.h>
+#endif
+
+#define SKIPWS(p) while (isspace((int)(*p))) p++
+#define WS "\t\n "
+
+int
+main(int argc, char *argv[])
+{
+ size_t len, lineno = 0;
+ char *line, *eptr, *longopt, *ptr, *optstring = NULL, *result = NULL;
+ char buf[1024];
+ char *args[128];
+ char arg[256];
+ int nargs = -1;
+ int c;
+ int nlongopts = 0;
+ int maxnlongopts = 0;
+ int *longopt_flags = NULL;
+ struct option *longopts = NULL;
+
+ while ((line = fparseln(stdin, &len, &lineno, NULL, 0)) != NULL) {
+ if (strncmp(line, "optstring:", 10) == 0) {
+ if (optstring)
+ free(optstring);
+ optstring = strtok(&line[11], WS);
+ if (optstring == NULL)
+ errx(1, "missing optstring at line %ld",
+ (unsigned long)lineno);
+ optstring = strdup(optstring);
+ } else if (strncmp(line, "longopts:", 9) == 0) {
+ if (longopts) {
+ int i;
+ for (i = 0; i < nlongopts; i++)
+ if (longopts[i].name != NULL)
+ free(__UNCONST(longopts[i].name));
+ free(longopts);
+ }
+ if (longopt_flags)
+ free(longopt_flags);
+ nlongopts = 0;
+ ptr = strtok(&line[10], WS);
+ if (ptr == NULL)
+ errx(1, "missing longopts at line %ld",
+ (unsigned long)lineno);
+ maxnlongopts = strtoul(ptr, &eptr, 10);
+ if (*eptr != '\0')
+ warnx("garbage in longopts at line %ld",
+ (unsigned long)lineno);
+ maxnlongopts++; /* space for trailer */
+ longopts =
+ (struct option *)calloc(sizeof(struct option),
+ maxnlongopts);
+ if (longopts == NULL)
+ err(1, "calloc");
+ longopt_flags = (int *)calloc(sizeof(int), maxnlongopts);
+ if (longopt_flags == NULL)
+ err(1, "calloc");
+ } else if (strncmp(line, "longopt:", 8) == 0) {
+ if (longopts == NULL)
+ errx(1, "longopt: without longopts at line %ld",
+ (unsigned long)lineno);
+ if (nlongopts >= maxnlongopts)
+ errx(1, "longopt: too many options at line %ld",
+ (unsigned long)lineno);
+ /* name */
+ ptr = &line[9];
+ SKIPWS(ptr);
+ longopt = strsep(&ptr, ",");
+ if (longopt == NULL)
+ errx(1, "missing longopt at line %ld",
+ (unsigned long)lineno);
+ longopts[nlongopts].name = strdup(longopt);
+ /* has_arg */
+ SKIPWS(ptr);
+ longopt = strsep(&ptr, ",");
+ if (*longopt != '\0') {
+ if (strncmp(longopt, "0", 1) == 0 ||
+ strncmp(longopt, "no_argument", 2) == 0)
+ longopts[nlongopts].has_arg = no_argument;
+ else if (strncmp(longopt, "1", 1) == 0 ||
+ strncmp(longopt, "required_argument", 8) == 0)
+ longopts[nlongopts].has_arg = required_argument;
+ else if (strncmp(longopt, "2", 1) == 0 ||
+ strncmp(longopt, "optional_argument", 8) == 0)
+ longopts[nlongopts].has_arg = optional_argument;
+ else
+ errx(1, "unknown has_arg %s at line %ld",
+ longopt, (unsigned long)lineno);
+ }
+ /* flag */
+ SKIPWS(ptr);
+ longopt = strsep(&ptr, ",");
+ if (*longopt != '\0' &&
+ strncmp(longopt, "NULL", 4) != 0)
+ longopts[nlongopts].flag = &longopt_flags[nlongopts];
+ /* val */
+ SKIPWS(ptr);
+ longopt = strsep(&ptr, ",");
+ if (*longopt == '\0')
+ errx(1, "missing val at line %ld",
+ (unsigned long)lineno);
+ if (*longopt != '\'') {
+ longopts[nlongopts].val =
+ (int)strtoul(longopt, &eptr, 10);
+ if (*eptr != '\0')
+ errx(1, "invalid val at line %ld",
+ (unsigned long)lineno);
+ } else
+ longopts[nlongopts].val = (int)longopt[1];
+ nlongopts++;
+ } else if (strncmp(line, "args:", 5) == 0) {
+ for (; nargs >= 0; nargs--) {
+ if (args[nargs] != NULL)
+ free(args[nargs]);
+ }
+ args[nargs = 0] = strtok(&line[6], WS);
+ if (args[nargs] == NULL)
+ errx(1, "Missing args");
+
+ args[nargs] = strdup(args[nargs]);
+ while ((args[++nargs] = strtok(NULL, WS)) != NULL)
+ args[nargs] = strdup(args[nargs]);
+ } else if (strncmp(line, "result:", 7) == 0) {
+ int li;
+ buf[0] = '\0';
+ optind = optreset = 1;
+ if (result)
+ free(result);
+ result = strtok(&line[8], WS);
+ if (result == NULL)
+ errx(1, "missing result at line %ld",
+ (unsigned long)lineno);
+ if (optstring == NULL)
+ errx(1, "result: without optstring");
+ if (longopts == NULL || nlongopts == 0)
+ errx(1, "result: without longopts");
+ result = strdup(result);
+ if (nargs == -1)
+ errx(1, "result: without args");
+ li = -2;
+ while ((c = getopt_long(nargs, args, optstring,
+ longopts, &li)) != -1) {
+ if (c == ':')
+ errx(1, "`:' found as argument char");
+ if (li == -2) {
+ ptr = strchr(optstring, c);
+ if (ptr == NULL) {
+ snprintf(arg, sizeof(arg),
+ "!%c,", c);
+ strcat(buf, arg);
+ continue;
+ }
+ if (ptr[1] != ':')
+ snprintf(arg, sizeof(arg),
+ "%c,", c);
+ else
+ snprintf(arg, sizeof(arg),
+ "%c=%s,", c, optarg);
+ } else {
+ switch (longopts[li].has_arg) {
+ case no_argument:
+ snprintf(arg, sizeof(arg), "-%s,",
+ longopts[li].name);
+ break;
+ case required_argument:
+ snprintf(arg, sizeof(arg),
+ "-%s=%s,",
+ longopts[li].name, optarg);
+ break;
+ case optional_argument:
+ snprintf(arg, sizeof(arg),
+ "-%s%s%s,",
+ longopts[li].name,
+ (optarg)? "=" : "",
+ (optarg)? optarg : "");
+ break;
+ default:
+ errx(1, "internal error");
+ }
+ }
+ strcat(buf, arg);
+ li = -2;
+ }
+ len = strlen(buf);
+ if (len > 0) {
+ buf[len - 1] = '|';
+ buf[len] = '\0';
+ } else {
+ buf[0] = '|';
+ buf[1] = '\0';
+ }
+ snprintf(arg, sizeof(arg), "%d", nargs - optind);
+ strcat(buf, arg);
+ if (strcmp(buf, result) != 0)
+ errx(1, "`%s' != `%s'", buf, result);
+ } else
+ errx(1, "unknown directive at line %ld",
+ (unsigned long)lineno);
+ free(line);
+ }
+ return 0;
+}
diff --git a/contrib/netbsd-tests/lib/libc/stdlib/t_abs.c b/contrib/netbsd-tests/lib/libc/stdlib/t_abs.c
new file mode 100644
index 0000000..282a125
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libc/stdlib/t_abs.c
@@ -0,0 +1,154 @@
+/* $NetBSD: t_abs.c,v 1.3 2014/03/01 22:38:13 joerg Exp $ */
+
+/*-
+ * Copyright (c) 2012 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_abs.c,v 1.3 2014/03/01 22:38:13 joerg Exp $");
+
+#include <atf-c.h>
+#include <inttypes.h>
+#include <limits.h>
+#include <stdlib.h>
+
+ATF_TC(abs_basic);
+ATF_TC_HEAD(abs_basic, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Test that abs(3) works");
+}
+
+ATF_TC_BODY(abs_basic, tc)
+{
+ static const struct {
+ int val;
+ int res;
+ } table[] = {
+ { 0, 0 },
+ { +0, 0 },
+ { -0, 0 },
+ { -0x1010, 0x1010 },
+ { INT_MAX, INT_MAX },
+ { -INT_MAX, INT_MAX },
+ };
+
+ for (size_t i = 0; i < __arraycount(table); i++)
+ ATF_CHECK(abs(table[i].val) == table[i].res);
+}
+
+ATF_TC(imaxabs_basic);
+ATF_TC_HEAD(imaxabs_basic, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Test that imaxabs(3) works");
+}
+
+ATF_TC_BODY(imaxabs_basic, tc)
+{
+ static const struct {
+ intmax_t val;
+ intmax_t res;
+ } table[] = {
+ { 0, 0 },
+ { INT_MAX, INT_MAX },
+ { -INT_MAX, INT_MAX },
+ { LONG_MAX, LONG_MAX },
+ { -LONG_MAX, LONG_MAX },
+ { LLONG_MAX, LLONG_MAX },
+ { -LLONG_MAX, LLONG_MAX },
+ { INT_MAX, INT_MAX },
+ { -INT_MAX, INT_MAX },
+ };
+
+ for (size_t i = 0; i < __arraycount(table); i++)
+ ATF_CHECK(imaxabs(table[i].val) == table[i].res);
+}
+
+ATF_TC(labs_basic);
+ATF_TC_HEAD(labs_basic, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Test that labs(3) works");
+}
+
+ATF_TC_BODY(labs_basic, tc)
+{
+ static const struct {
+ long val;
+ long res;
+ } table[] = {
+ { 0, 0 },
+ { +0, 0 },
+ { -0, 0 },
+ { -1, 1 },
+ { LONG_MAX, LONG_MAX },
+ { -LONG_MAX, LONG_MAX },
+ { INT_MAX, INT_MAX },
+ { -INT_MAX, INT_MAX },
+ };
+
+ for (size_t i = 0; i < __arraycount(table); i++)
+ ATF_CHECK(labs(table[i].val) == table[i].res);
+}
+
+ATF_TC(llabs_basic);
+ATF_TC_HEAD(llabs_basic, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Test that llabs(3) works");
+}
+
+ATF_TC_BODY(llabs_basic, tc)
+{
+ static const struct {
+ long long val;
+ long long res;
+ } table[] = {
+ { 0, 0 },
+ { +0, 0 },
+ { -0, 0 },
+ { -1, 1 },
+ { INT_MAX, INT_MAX },
+ { -INT_MAX, INT_MAX },
+ { LONG_MAX, LONG_MAX },
+ { -LONG_MAX, LONG_MAX },
+ { LLONG_MAX, LLONG_MAX },
+ { -LLONG_MAX, LLONG_MAX },
+ { -0x100000000LL, 0x100000000LL },
+ };
+
+ for (size_t i = 0; i < __arraycount(table); i++)
+ ATF_CHECK(llabs(table[i].val) == table[i].res);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, abs_basic);
+ ATF_TP_ADD_TC(tp, imaxabs_basic);
+ ATF_TP_ADD_TC(tp, labs_basic);
+ ATF_TP_ADD_TC(tp, llabs_basic);
+
+ return atf_no_error();
+}
diff --git a/contrib/netbsd-tests/lib/libc/stdlib/t_atexit.sh b/contrib/netbsd-tests/lib/libc/stdlib/t_atexit.sh
new file mode 100755
index 0000000..d11268b
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libc/stdlib/t_atexit.sh
@@ -0,0 +1,54 @@
+# $NetBSD: t_atexit.sh,v 1.1 2011/01/12 19:44:08 pgoyette Exp $
+#
+# Copyright (c) 2011 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(3) and __cxa_atexit()/__cxa_finalize()"
+}
+atexit_body()
+{
+ $(atf_get_srcdir)/h_atexit >out \
+ || atf_fail "h_exit failed, see output of the test for details"
+
+ cat >exp <<EOF
+cxa_handler_5
+cxa_handler_4
+cxa_handler_3
+cxa_handler_2
+normal_handler_1
+normal_handler_0
+EOF
+
+ diff -Nru exp out \
+ || atf_fail "h_exit failed, see output of the test for details"
+}
+
+atf_init_test_cases()
+{
+ atf_add_test_case atexit
+}
diff --git a/contrib/netbsd-tests/lib/libc/stdlib/t_atoi.c b/contrib/netbsd-tests/lib/libc/stdlib/t_atoi.c
new file mode 100644
index 0000000..3e0c35f
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libc/stdlib/t_atoi.c
@@ -0,0 +1,121 @@
+/* $NetBSD: t_atoi.c,v 1.2 2012/03/29 05:56:36 jruoho Exp $ */
+
+/*-
+ * Copyright (c) 2012 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_atoi.c,v 1.2 2012/03/29 05:56:36 jruoho Exp $");
+
+#include <atf-c.h>
+#include <float.h>
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+ATF_TC(atof_strtod);
+ATF_TC_HEAD(atof_strtod, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test that atof(3) matches the corresponding strtod(3) call");
+}
+
+ATF_TC_BODY(atof_strtod, tc)
+{
+ char buf[128];
+
+ (void)snprintf(buf, sizeof(buf), "%f\n", DBL_MAX);
+
+ ATF_REQUIRE(atof("0") == strtod("0", NULL));
+ ATF_REQUIRE(atof("-1") == strtod("-1", NULL));
+ ATF_REQUIRE(atof(buf) == strtod(buf, NULL));
+}
+
+ATF_TC(atoi_strtol);
+ATF_TC_HEAD(atoi_strtol, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test that atoi(3) matches the corresponding strtol(3) call");
+}
+
+ATF_TC_BODY(atoi_strtol, tc)
+{
+ char buf[64];
+
+ (void)snprintf(buf, sizeof(buf), "%d\n", INT_MAX);
+
+ ATF_REQUIRE(atoi("0") == strtol("0", NULL, 10));
+ ATF_REQUIRE(atoi("-1") == strtol("-1", NULL, 10));
+ ATF_REQUIRE(atoi(buf) == strtol(buf, NULL, 10));
+}
+
+ATF_TC(atol_strtol);
+ATF_TC_HEAD(atol_strtol, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test that atol(3) matches the corresponding strtol(3) call");
+}
+
+ATF_TC_BODY(atol_strtol, tc)
+{
+ char buf[64];
+
+ (void)snprintf(buf, sizeof(buf), "%ld\n", LONG_MAX);
+
+ ATF_REQUIRE(atol("0") == strtol("0", NULL, 10));
+ ATF_REQUIRE(atol("-1") == strtol("-1", NULL, 10));
+ ATF_REQUIRE(atol(buf) == strtol(buf, NULL, 10));
+}
+
+ATF_TC(atoll_strtoll);
+ATF_TC_HEAD(atoll_strtoll, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test that atoll(3) matches the corresponding strtoll(3) call");
+}
+
+ATF_TC_BODY(atoll_strtoll, tc)
+{
+ char buf[128];
+
+ (void)snprintf(buf, sizeof(buf), "%lld\n", LLONG_MAX);
+
+ ATF_REQUIRE(atoll("0") == strtoll("0", NULL, 10));
+ ATF_REQUIRE(atoll("-1") == strtoll("-1", NULL, 10));
+ ATF_REQUIRE(atoll(buf) == strtoll(buf, NULL, 10));
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, atof_strtod);
+ ATF_TP_ADD_TC(tp, atoi_strtol);
+ ATF_TP_ADD_TC(tp, atol_strtol);
+ ATF_TP_ADD_TC(tp, atoll_strtoll);
+
+ return atf_no_error();
+}
diff --git a/contrib/netbsd-tests/lib/libc/stdlib/t_div.c b/contrib/netbsd-tests/lib/libc/stdlib/t_div.c
new file mode 100644
index 0000000..376f357
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libc/stdlib/t_div.c
@@ -0,0 +1,98 @@
+/* $NetBSD: t_div.c,v 1.2 2011/07/07 11:12:18 jruoho Exp $ */
+
+/*-
+ * Copyright (c) 2001 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 <atf-c.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#define NUM 1999236
+#define DENOM 1000000
+#define QUOT 1
+#define REM 999236
+
+ATF_TC(div_basic);
+ATF_TC_HEAD(div_basic, tc)
+{
+
+ atf_tc_set_md_var(tc, "descr", "Test div(3) for correctness");
+}
+
+ATF_TC_BODY(div_basic, tc)
+{
+ div_t d;
+
+ d = div(NUM, DENOM);
+
+ ATF_CHECK(d.quot == QUOT);
+ ATF_CHECK(d.rem == REM);
+}
+
+ATF_TC(ldiv_basic);
+ATF_TC_HEAD(ldiv_basic, tc)
+{
+
+ atf_tc_set_md_var(tc, "descr", "Test ldiv(3) for correctness");
+}
+
+ATF_TC_BODY(ldiv_basic, tc)
+{
+ ldiv_t ld;
+
+ ld = ldiv(NUM, DENOM);
+
+ ATF_CHECK(ld.quot == QUOT);
+ ATF_CHECK(ld.rem == REM);
+}
+
+ATF_TC(lldiv_basic);
+ATF_TC_HEAD(lldiv_basic, tc)
+{
+
+ atf_tc_set_md_var(tc, "descr", "Test lllldiv(3) for correctness");
+}
+
+ATF_TC_BODY(lldiv_basic, tc)
+{
+ lldiv_t lld;
+
+ lld = lldiv(NUM, DENOM);
+
+ ATF_CHECK(lld.quot == QUOT);
+ ATF_CHECK(lld.rem == REM);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, div_basic);
+ ATF_TP_ADD_TC(tp, ldiv_basic);
+ ATF_TP_ADD_TC(tp, lldiv_basic);
+
+ return atf_no_error();
+}
diff --git a/contrib/netbsd-tests/lib/libc/stdlib/t_exit.c b/contrib/netbsd-tests/lib/libc/stdlib/t_exit.c
new file mode 100644
index 0000000..067cb51
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libc/stdlib/t_exit.c
@@ -0,0 +1,186 @@
+/* $NetBSD: t_exit.c,v 1.1 2011/05/09 07:31:51 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_exit.c,v 1.1 2011/05/09 07:31:51 jruoho Exp $");
+
+#include <sys/wait.h>
+
+#include <atf-c.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+static bool fail;
+static void func(void);
+
+static void
+func(void)
+{
+ fail = false;
+}
+
+ATF_TC(exit_atexit);
+ATF_TC_HEAD(exit_atexit, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "A basic test of atexit(3)");
+}
+
+ATF_TC_BODY(exit_atexit, tc)
+{
+ pid_t pid;
+ int sta;
+
+ pid = fork();
+ ATF_REQUIRE(pid >= 0);
+
+ if (pid == 0) {
+
+ if (atexit(func) != 0)
+ _exit(EXIT_FAILURE);
+
+ fail = true;
+
+ _exit(EXIT_SUCCESS);
+ }
+
+ (void)wait(&sta);
+
+ if (WIFEXITED(sta) == 0 || WEXITSTATUS(sta) != EXIT_SUCCESS)
+ atf_tc_fail("atexit(3) failed");
+
+ if (fail != false)
+ atf_tc_fail("atexit(3) was not called");
+}
+
+ATF_TC(exit_basic);
+ATF_TC_HEAD(exit_basic, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "A basic test of exit(3)");
+}
+
+ATF_TC_BODY(exit_basic, tc)
+{
+ pid_t pid;
+ int sta;
+
+ pid = fork();
+ ATF_REQUIRE(pid >= 0);
+
+ if (pid == 0) {
+ exit(EXIT_SUCCESS);
+ exit(EXIT_FAILURE);
+ }
+
+ (void)wait(&sta);
+
+ if (WIFEXITED(sta) == 0 || WEXITSTATUS(sta) != EXIT_SUCCESS)
+ atf_tc_fail("exit(3) did not exit successfully");
+}
+
+ATF_TC(exit_status);
+ATF_TC_HEAD(exit_status, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Test exit(3) status");
+}
+
+ATF_TC_BODY(exit_status, tc)
+{
+ const int n = 10;
+ int i, sta;
+ pid_t pid;
+
+ for (i = 0; i < n; i++) {
+
+ pid = fork();
+
+ if (pid < 0)
+ exit(EXIT_FAILURE);
+
+ if (pid == 0)
+ exit(i);
+
+ (void)wait(&sta);
+
+ if (WIFEXITED(sta) == 0 || WEXITSTATUS(sta) != i)
+ atf_tc_fail("invalid exit(3) status");
+ }
+}
+
+ATF_TC(exit_tmpfile);
+ATF_TC_HEAD(exit_tmpfile, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Temporary files are unlinked?");
+}
+
+ATF_TC_BODY(exit_tmpfile, tc)
+{
+ int sta, fd = -1;
+ char buf[12];
+ pid_t pid;
+ FILE *f;
+
+ (void)strlcpy(buf, "exit.XXXXXX", sizeof(buf));
+
+ pid = fork();
+ ATF_REQUIRE(pid >= 0);
+
+ if (pid == 0) {
+
+ fd = mkstemp(buf);
+
+ if (fd < 0)
+ exit(EXIT_FAILURE);
+
+ exit(EXIT_SUCCESS);
+ }
+
+ (void)wait(&sta);
+
+ if (WIFEXITED(sta) == 0 || WEXITSTATUS(sta) != EXIT_SUCCESS)
+ atf_tc_fail("failed to create temporary file");
+
+ f = fdopen(fd, "r");
+
+ if (f != NULL)
+ atf_tc_fail("exit(3) did not clear temporary file");
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, exit_atexit);
+ ATF_TP_ADD_TC(tp, exit_basic);
+ ATF_TP_ADD_TC(tp, exit_status);
+ ATF_TP_ADD_TC(tp, exit_tmpfile);
+
+ return atf_no_error();
+}
diff --git a/contrib/netbsd-tests/lib/libc/stdlib/t_getenv.c b/contrib/netbsd-tests/lib/libc/stdlib/t_getenv.c
new file mode 100644
index 0000000..5a8fa28
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libc/stdlib/t_getenv.c
@@ -0,0 +1,211 @@
+/* $NetBSD: t_getenv.c,v 1.2 2011/07/15 13:54:31 jruoho Exp $ */
+
+/*-
+ * Copyright (c) 2010 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 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_getenv.c,v 1.2 2011/07/15 13:54:31 jruoho Exp $");
+
+#include <atf-c.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#ifdef __FreeBSD__
+#include <signal.h>
+#endif
+
+extern char **environ;
+
+ATF_TC(clearenv_basic);
+ATF_TC_HEAD(clearenv_basic, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test user clearing environment directly");
+}
+
+ATF_TC_BODY(clearenv_basic, tc)
+{
+ char name[1024], value[1024];
+
+ for (size_t i = 0; i < 1024; i++) {
+ snprintf(name, sizeof(name), "crap%zu", i);
+ snprintf(value, sizeof(value), "%zu", i);
+ ATF_CHECK(setenv(name, value, 1) != -1);
+ }
+
+ *environ = NULL;
+
+ for (size_t i = 0; i < 1; i++) {
+ snprintf(name, sizeof(name), "crap%zu", i);
+ snprintf(value, sizeof(value), "%zu", i);
+ ATF_CHECK(setenv(name, value, 1) != -1);
+ }
+
+ ATF_CHECK_STREQ(getenv("crap0"), "0");
+ ATF_CHECK(getenv("crap1") == NULL);
+ ATF_CHECK(getenv("crap2") == NULL);
+}
+
+ATF_TC(getenv_basic);
+ATF_TC_HEAD(getenv_basic, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test setenv(3), getenv(3)");
+}
+
+ATF_TC_BODY(getenv_basic, tc)
+{
+ ATF_CHECK(setenv("EVIL", "very=bad", 1) != -1);
+ ATF_CHECK_STREQ(getenv("EVIL"), "very=bad");
+ ATF_CHECK(getenv("EVIL=very") == NULL);
+ ATF_CHECK(unsetenv("EVIL") != -1);
+}
+
+ATF_TC(putenv_basic);
+ATF_TC_HEAD(putenv_basic, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test putenv(3), getenv(3), unsetenv(3)");
+}
+
+
+ATF_TC_BODY(putenv_basic, tc)
+{
+ char string[1024];
+
+ snprintf(string, sizeof(string), "crap=true");
+ ATF_CHECK(putenv(string) != -1);
+ ATF_CHECK_STREQ(getenv("crap"), "true");
+ string[1] = 'l';
+ ATF_CHECK_STREQ(getenv("clap"), "true");
+ ATF_CHECK(getenv("crap") == NULL);
+ string[1] = 'r';
+ ATF_CHECK(unsetenv("crap") != -1);
+ ATF_CHECK(getenv("crap") == NULL);
+
+ ATF_CHECK_ERRNO(EINVAL, putenv(NULL) == -1);
+ ATF_CHECK_ERRNO(EINVAL, putenv(__UNCONST("val")) == -1);
+ ATF_CHECK_ERRNO(EINVAL, putenv(__UNCONST("=val")) == -1);
+}
+
+ATF_TC(setenv_basic);
+ATF_TC_HEAD(setenv_basic, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test setenv(3), getenv(3), unsetenv(3)");
+ atf_tc_set_md_var(tc, "timeout", "300");
+}
+
+ATF_TC_BODY(setenv_basic, tc)
+{
+ const size_t numvars = 8192;
+ size_t i, offset;
+ char name[1024];
+ char value[1024];
+
+ offset = lrand48();
+ for (i = 0; i < numvars; i++) {
+ (void)snprintf(name, sizeof(name), "var%zu",
+ (i * 7 + offset) % numvars);
+ (void)snprintf(value, sizeof(value), "value%ld", lrand48());
+ ATF_CHECK(setenv(name, value, 1) != -1);
+ ATF_CHECK(setenv(name, "foo", 0) != -1);
+ ATF_CHECK_STREQ(getenv(name), value);
+ }
+
+ offset = lrand48();
+ for (i = 0; i < numvars; i++) {
+ (void)snprintf(name, sizeof(name), "var%zu",
+ (i * 11 + offset) % numvars);
+ ATF_CHECK(unsetenv(name) != -1);
+ ATF_CHECK(getenv(name) == NULL);
+ ATF_CHECK(unsetenv(name) != -1);
+ }
+
+ ATF_CHECK_ERRNO(EINVAL, setenv(NULL, "val", 1) == -1);
+ ATF_CHECK_ERRNO(EINVAL, setenv("", "val", 1) == -1);
+ ATF_CHECK_ERRNO(EINVAL, setenv("v=r", "val", 1) == -1);
+#ifdef __FreeBSD__
+ /*
+ Both FreeBSD and OS/X does not validate the second
+ argument to setenv(3)
+ */
+ atf_tc_expect_signal(SIGSEGV, "FreeBSD does not validate the second "
+ "argument to setenv(3); see bin/189805");
+#endif
+
+ ATF_CHECK_ERRNO(EINVAL, setenv("var", NULL, 1) == -1);
+
+ ATF_CHECK(setenv("var", "=val", 1) == 0);
+ ATF_CHECK_STREQ(getenv("var"), "=val");
+}
+
+ATF_TC(setenv_mixed);
+ATF_TC_HEAD(setenv_mixed, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test mixing setenv(3), unsetenv(3) and putenv(3)");
+}
+
+ATF_TC_BODY(setenv_mixed, tc)
+{
+ char string[32];
+
+ (void)strcpy(string, "mixedcrap=putenv");
+
+ ATF_CHECK(setenv("mixedcrap", "setenv", 1) != -1);
+ ATF_CHECK_STREQ(getenv("mixedcrap"), "setenv");
+ ATF_CHECK(putenv(string) != -1);
+ ATF_CHECK_STREQ(getenv("mixedcrap"), "putenv");
+ ATF_CHECK(unsetenv("mixedcrap") != -1);
+ ATF_CHECK(getenv("mixedcrap") == NULL);
+
+ ATF_CHECK(putenv(string) != -1);
+ ATF_CHECK_STREQ(getenv("mixedcrap"), "putenv");
+ ATF_CHECK(setenv("mixedcrap", "setenv", 1) != -1);
+ ATF_CHECK_STREQ(getenv("mixedcrap"), "setenv");
+ ATF_CHECK(unsetenv("mixedcrap") != -1);
+ ATF_CHECK(getenv("mixedcrap") == NULL);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, clearenv_basic);
+ ATF_TP_ADD_TC(tp, getenv_basic);
+ ATF_TP_ADD_TC(tp, putenv_basic);
+ ATF_TP_ADD_TC(tp, setenv_basic);
+ ATF_TP_ADD_TC(tp, setenv_mixed);
+
+ return atf_no_error();
+}
diff --git a/contrib/netbsd-tests/lib/libc/stdlib/t_getenv_thread.c b/contrib/netbsd-tests/lib/libc/stdlib/t_getenv_thread.c
new file mode 100644
index 0000000..d935629
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libc/stdlib/t_getenv_thread.c
@@ -0,0 +1,250 @@
+/* $NetBSD: t_getenv_thread.c,v 1.2 2012/03/15 02:02:23 joerg Exp $ */
+
+/*-
+ * Copyright (c) 2010 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Matthias Scheler.
+ *
+ * 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_getenv_thread.c,v 1.2 2012/03/15 02:02:23 joerg Exp $");
+
+#include <atf-c.h>
+#include <errno.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+
+#define THREADED_NUM_THREADS 8
+#define THREADED_NUM_VARS 16
+#define THREADED_VAR_NAME "THREADED%zu"
+#define THREADED_RUN_TIME 10
+
+static void *thread_getenv_r(void *);
+static void *thread_putenv(void *);
+static void *thread_setenv(void *);
+static void *thread_unsetenv(void *);
+
+static void *
+thread_getenv_r(void *arg)
+{
+ time_t endtime;
+
+ endtime = *(time_t *)arg;
+ do {
+ size_t i;
+ char name[32], value[128];
+
+ i = lrand48() % THREADED_NUM_VARS;
+ (void)snprintf(name, sizeof(name), THREADED_VAR_NAME, i);
+
+ if (getenv_r(name, value, sizeof(value)) == -1) {
+ ATF_CHECK(errno == ENOENT);
+ }
+ } while (time(NULL) < endtime);
+
+ return NULL;
+}
+
+
+static void *
+thread_putenv(void *arg)
+{
+ time_t endtime;
+ size_t i;
+ static char vars[THREADED_NUM_VARS][128];
+
+ for (i = 0; i < THREADED_NUM_VARS; i++) {
+ (void)snprintf(vars[i], sizeof(vars[i]),
+ THREADED_VAR_NAME "=putenv %ld", i, lrand48());
+ }
+
+ endtime = *(time_t *)arg;
+ do {
+ char name[128];
+
+ i = lrand48() % THREADED_NUM_VARS;
+ (void)strlcpy(name, vars[i], sizeof(name));
+ *strchr(name, '=') = '\0';
+
+ ATF_CHECK(unsetenv(name) != -1);
+ ATF_CHECK(putenv(vars[i]) != -1);
+ } while (time(NULL) < endtime);
+
+ return NULL;
+}
+
+static void *
+thread_setenv(void *arg)
+{
+ time_t endtime;
+
+ endtime = *(time_t *)arg;
+ do {
+ size_t i;
+ char name[32], value[64];
+
+ i = lrand48() % THREADED_NUM_VARS;
+ (void)snprintf(name, sizeof(name), THREADED_VAR_NAME, i);
+ (void)snprintf(value, sizeof(value), "setenv %ld", lrand48());
+
+ ATF_CHECK(setenv(name, value, 1) != -1);
+ } while (time(NULL) < endtime);
+
+ return NULL;
+}
+
+static void *
+thread_unsetenv(void *arg)
+{
+ time_t endtime;
+
+ endtime = *(time_t *)arg;
+ do {
+ size_t i;
+ char name[32];
+
+ i = lrand48() % THREADED_NUM_VARS;
+ (void)snprintf(name, sizeof(name), THREADED_VAR_NAME, i);
+
+ ATF_CHECK(unsetenv(name) != -1);
+ } while (time(NULL) < endtime);
+
+ return NULL;
+}
+
+ATF_TC(getenv_r_thread);
+ATF_TC_HEAD(getenv_r_thread, tc)
+{
+
+ atf_tc_set_md_var(tc, "descr", "Test getenv_r(3) with threads");
+ atf_tc_set_md_var(tc, "timeout", "%d", THREADED_RUN_TIME + 5);
+}
+
+ATF_TC_BODY(getenv_r_thread, tc)
+{
+ pthread_t threads[THREADED_NUM_THREADS];
+ time_t endtime;
+ size_t i, j;
+
+ endtime = time(NULL) + THREADED_RUN_TIME;
+
+ for (i = j = 0; j < 2; j++) {
+
+ ATF_CHECK(pthread_create(&threads[i++], NULL, thread_getenv_r,
+ &endtime) == 0);
+ }
+
+ for (j = 0; j < i; j++)
+ ATF_CHECK(pthread_join(threads[j], NULL) == 0);
+}
+
+ATF_TC(putenv_thread);
+ATF_TC_HEAD(putenv_thread, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Test concurrent access by putenv(3)");
+ atf_tc_set_md_var(tc, "timeout", "%d", THREADED_RUN_TIME + 5);
+}
+
+ATF_TC_BODY(putenv_thread, tc)
+{
+ pthread_t threads[THREADED_NUM_THREADS];
+ time_t endtime;
+ size_t i, j;
+
+ endtime = time(NULL) + THREADED_RUN_TIME;
+
+ for (i = j = 0; j < 2; j++) {
+
+ ATF_CHECK(pthread_create(&threads[i++], NULL, thread_putenv,
+ &endtime) == 0);
+ }
+
+ for (j = 0; j < i; j++)
+ ATF_CHECK(pthread_join(threads[j], NULL) == 0);
+}
+
+ATF_TC(setenv_thread);
+ATF_TC_HEAD(setenv_thread, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Test concurrent access by setenv(3)");
+ atf_tc_set_md_var(tc, "timeout", "%d", THREADED_RUN_TIME + 5);
+}
+
+ATF_TC_BODY(setenv_thread, tc)
+{
+ pthread_t threads[THREADED_NUM_THREADS];
+ time_t endtime;
+ size_t i, j;
+
+ endtime = time(NULL) + THREADED_RUN_TIME;
+
+ for (i = j = 0; j < 2; j++) {
+
+ ATF_CHECK(pthread_create(&threads[i++], NULL, thread_setenv,
+ &endtime) == 0);
+ }
+
+ for (j = 0; j < i; j++)
+ ATF_CHECK(pthread_join(threads[j], NULL) == 0);
+}
+
+ATF_TC(unsetenv_thread);
+ATF_TC_HEAD(unsetenv_thread, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Test unsetenv(3) with threads");
+ atf_tc_set_md_var(tc, "timeout", "%d", THREADED_RUN_TIME + 5);
+}
+
+ATF_TC_BODY(unsetenv_thread, tc)
+{
+ pthread_t threads[THREADED_NUM_THREADS];
+ time_t endtime;
+ size_t i, j;
+
+ endtime = time(NULL) + THREADED_RUN_TIME;
+
+ for (i = j = 0; j < 2; j++) {
+
+ ATF_CHECK(pthread_create(&threads[i++], NULL, thread_unsetenv,
+ &endtime) == 0);
+ }
+
+ for (j = 0; j < i; j++)
+ ATF_CHECK(pthread_join(threads[j], NULL) == 0);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, getenv_r_thread);
+ ATF_TP_ADD_TC(tp, putenv_thread);
+ ATF_TP_ADD_TC(tp, setenv_thread);
+ ATF_TP_ADD_TC(tp, unsetenv_thread);
+
+ return atf_no_error();
+}
diff --git a/contrib/netbsd-tests/lib/libc/stdlib/t_getopt.sh b/contrib/netbsd-tests/lib/libc/stdlib/t_getopt.sh
new file mode 100755
index 0000000..cc10f65
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libc/stdlib/t_getopt.sh
@@ -0,0 +1,123 @@
+# $NetBSD: t_getopt.sh,v 1.1 2011/01/01 23:56:49 pgoyette 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.
+#
+
+h_getopt()
+{
+ atf_check -e save:stderr -x "$(atf_get_srcdir)/h_getopt" <<EOF
+load: $1
+args: $2
+result: $3
+EOF
+ cat stderr
+ rm -f stderr
+}
+
+h_getopt_long()
+{
+ atf_check -e save:stderr -x "$(atf_get_srcdir)/h_getopt_long" <<EOF
+$1
+args: $2
+result: $3
+EOF
+ cat stderr
+ rm -f stderr
+}
+
+atf_test_case getopt
+getopt_head()
+{
+ atf_set "descr" "Checks getopt(3)"
+}
+getopt_body()
+{
+ load="c:d"
+
+ h_getopt "${load}" "foo -c 1 -d foo" "c=1,d|1"
+ h_getopt "${load}" "foo -d foo bar" "d|2"
+ h_getopt "${load}" "foo -c 2 foo bar" "c=2|2"
+ h_getopt "${load}" "foo -e 1 foo bar" "!?|3"
+ h_getopt "${load}" "foo -d -- -c 1" "d|2"
+ h_getopt "${load}" "foo -c- 1" "c=-|1"
+ h_getopt "${load}" "foo -d - 1" "d|2"
+}
+
+atf_test_case getopt_long
+getopt_long_head()
+{
+ atf_set "descr" "Checks getopt_long(3)"
+}
+getopt_long_body()
+{
+ # GNU libc tests with these
+ load="optstring: abc:
+longopts: 5
+longopt: required, required_argument, , 'r'
+longopt: optional, optional_argument, , 'o'
+longopt: none, no_argument, , 'n'
+longopt: color, no_argument, , 'C'
+longopt: colour, no_argument, , 'C'"
+
+ h_getopt_long "${load}" "foo --req foobar" "-required=foobar|0"
+ h_getopt_long "${load}" "foo --opt=bazbug" "-optional=bazbug|0"
+
+ # This is problematic
+ #
+ # GNU libc 2.1.3 this fails with ambiguous result
+ # h_getopt_long "${load}" "foo --col" "!?|0"
+ #
+ # GNU libc 2.2 >= this works
+ h_getopt_long "${load}" "foo --col" "-color|0"
+
+ h_getopt_long "${load}" "foo --colour" "-colour|0"
+
+ # This is the real GNU libc test!
+ args="foo -a -b -cfoobar --required foobar --optional=bazbug --none random --col --color --colour"
+ # GNU libc 2.1.3 this fails with ambiguous
+ #result="a,b,c=foobar,-required=foobar,-optional=bazbug,-none,!?,-color,-colour|1"
+ #
+ # GNU libc 2.2 >= this works
+ result="a,b,c=foobar,-required=foobar,-optional=bazbug,-none,-color,-color,-colour|1"
+ h_getopt_long "${load}" "${args}" "${result}"
+
+ #
+ # The order of long options in the long option array should not matter.
+ # An exact match should never be treated as ambiguous.
+ #
+ load="optstring: fgl
+longopts: 3
+longopt: list-foobar, no_argument, lopt, 'f'
+longopt: list-goobar, no_argument, lopt, 'g'
+longopt: list, no_argument, lopt, 'l'"
+ h_getopt_long "${load}" "foo --list" "-list|0"
+}
+
+
+atf_init_test_cases()
+{
+ atf_add_test_case getopt
+ atf_add_test_case getopt_long
+}
diff --git a/contrib/netbsd-tests/lib/libc/stdlib/t_hsearch.c b/contrib/netbsd-tests/lib/libc/stdlib/t_hsearch.c
new file mode 100644
index 0000000..a0e77d3
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libc/stdlib/t_hsearch.c
@@ -0,0 +1,411 @@
+/* $NetBSD: t_hsearch.c,v 1.4 2014/07/20 20:17:21 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.
+ */
+
+/*
+ * Copyright (c) 2001 Christopher G. Demetriou
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed for the
+ * NetBSD Project. See http://www.NetBSD.org/ for
+ * information about NetBSD.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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.
+ *
+ * <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>>
+ */
+
+#include <sys/cdefs.h>
+__COPYRIGHT("@(#) Copyright (c) 2008\
+ The NetBSD Foundation, inc. All rights reserved.");
+__RCSID("$NetBSD: t_hsearch.c,v 1.4 2014/07/20 20:17:21 christos Exp $");
+
+#include <errno.h>
+#include <search.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <atf-c.h>
+
+#define REQUIRE_ERRNO(x) ATF_REQUIRE_MSG(x, "%s", strerror(errno))
+
+#ifdef __NetBSD__
+ATF_TC(hsearch_basic);
+ATF_TC_HEAD(hsearch_basic, tc)
+{
+
+ atf_tc_set_md_var(tc, "descr", "Checks basic insertions and searching");
+}
+
+ATF_TC_BODY(hsearch_basic, tc)
+{
+ ENTRY e, *ep;
+ char ch[2];
+ int i;
+
+ REQUIRE_ERRNO(hcreate(16) != 0);
+
+ /* ch[1] should be constant from here on down. */
+ ch[1] = '\0';
+
+ /* Basic insertions. Check enough that there'll be collisions. */
+ for (i = 0; i < 26; i++) {
+ ch[0] = 'a' + i;
+ e.key = strdup(ch); /* ptr to provided key is kept! */
+ ATF_REQUIRE(e.key != NULL);
+ e.data = (void *)(intptr_t)i;
+
+ ep = hsearch(e, ENTER);
+
+ ATF_REQUIRE(ep != NULL);
+ ATF_REQUIRE_STREQ(ep->key, ch);
+ ATF_REQUIRE_EQ((intptr_t)ep->data, i);
+ }
+
+ /* e.key should be constant from here on down. */
+ e.key = ch;
+
+ /* Basic lookups. */
+ for (i = 0; i < 26; i++) {
+ ch[0] = 'a' + i;
+
+ ep = hsearch(e, FIND);
+
+ ATF_REQUIRE(ep != NULL);
+ ATF_REQUIRE_STREQ(ep->key, ch);
+ ATF_REQUIRE_EQ((intptr_t)ep->data, i);
+ }
+
+ hdestroy1(free, NULL);
+}
+#endif
+
+ATF_TC(hsearch_duplicate);
+ATF_TC_HEAD(hsearch_duplicate, tc)
+{
+
+ atf_tc_set_md_var(tc, "descr", "Checks that inserting duplicate "
+ "doesn't overwrite existing data");
+}
+
+ATF_TC_BODY(hsearch_duplicate, tc)
+{
+ ENTRY e, *ep;
+
+ REQUIRE_ERRNO(hcreate(16));
+
+ e.key = __UNCONST("a");
+ e.data = (void *)(intptr_t) 0;
+
+ ep = hsearch(e, ENTER);
+
+ ATF_REQUIRE(ep != NULL);
+ ATF_REQUIRE_STREQ(ep->key, "a");
+ ATF_REQUIRE_EQ((intptr_t)ep->data, 0);
+
+ e.data = (void *)(intptr_t)12345;
+
+ ep = hsearch(e, ENTER);
+ ep = hsearch(e, FIND);
+
+ ATF_REQUIRE(ep != NULL);
+ ATF_REQUIRE_STREQ(ep->key, "a");
+ ATF_REQUIRE_EQ((intptr_t)ep->data, 0);
+
+ hdestroy();
+}
+
+ATF_TC(hsearch_nonexistent);
+ATF_TC_HEAD(hsearch_nonexistent, tc)
+{
+
+ atf_tc_set_md_var(tc, "descr",
+ "Checks searching for non-existent entry");
+}
+
+ATF_TC_BODY(hsearch_nonexistent, tc)
+{
+ ENTRY e, *ep;
+
+ REQUIRE_ERRNO(hcreate(16));
+
+ e.key = __UNCONST("A");
+ ep = hsearch(e, FIND);
+ ATF_REQUIRE_EQ(ep, NULL);
+
+ hdestroy();
+}
+
+ATF_TC(hsearch_two);
+ATF_TC_HEAD(hsearch_two, tc)
+{
+
+ atf_tc_set_md_var(tc, "descr",
+ "Checks that searching doesn't overwrite previous search results");
+}
+
+ATF_TC_BODY(hsearch_two, tc)
+{
+ ENTRY e, *ep, *ep2;
+
+ REQUIRE_ERRNO(hcreate(16));
+
+ e.key = __UNCONST("a");
+ e.data = (void*)(intptr_t)0;
+
+ ep = hsearch(e, ENTER);
+
+ ATF_REQUIRE(ep != NULL);
+ ATF_REQUIRE_STREQ(ep->key, "a");
+ ATF_REQUIRE_EQ((intptr_t)ep->data, 0);
+
+ e.key = __UNCONST("b");
+ e.data = (void*)(intptr_t)1;
+
+ ep = hsearch(e, ENTER);
+
+ ATF_REQUIRE(ep != NULL);
+ ATF_REQUIRE_STREQ(ep->key, "b");
+ ATF_REQUIRE_EQ((intptr_t)ep->data, 1);
+
+ e.key = __UNCONST("a");
+ ep = hsearch(e, FIND);
+
+ e.key = __UNCONST("b");
+ ep2 = hsearch(e, FIND);
+
+ ATF_REQUIRE(ep != NULL);
+ ATF_REQUIRE_STREQ(ep->key, "a");
+ ATF_REQUIRE_EQ((intptr_t)ep->data, 0);
+
+ ATF_REQUIRE(ep2 != NULL);
+ ATF_REQUIRE_STREQ(ep2->key, "b");
+ ATF_REQUIRE_EQ((intptr_t)ep2->data, 1);
+
+ hdestroy();
+}
+
+#if defined(__FreeBSD__) && 1100027 <= __FreeBSD_version
+#ifdef __NetBSD__
+ATF_TC(hsearch_r_basic);
+ATF_TC_HEAD(hsearch_r_basic, tc)
+{
+
+ atf_tc_set_md_var(tc, "descr", "Checks basic insertions and searching");
+}
+
+ATF_TC_BODY(hsearch_r_basic, tc)
+{
+ ENTRY e, *ep;
+ char ch[2];
+ int i;
+ struct hsearch_data t;
+
+ REQUIRE_ERRNO(hcreate_r(16, &t) != 0);
+
+ /* ch[1] should be constant from here on down. */
+ ch[1] = '\0';
+
+ /* Basic insertions. Check enough that there'll be collisions. */
+ for (i = 0; i < 26; i++) {
+ ch[0] = 'a' + i;
+ e.key = strdup(ch); /* ptr to provided key is kept! */
+ ATF_REQUIRE(e.key != NULL);
+ e.data = (void *)(intptr_t)i;
+
+ ATF_REQUIRE(hsearch_r(e, ENTER, &ep, &t) == 1);
+ ATF_REQUIRE(ep != NULL);
+ ATF_REQUIRE_STREQ(ep->key, ch);
+ ATF_REQUIRE_EQ((intptr_t)ep->data, i);
+ }
+
+ /* e.key should be constant from here on down. */
+ e.key = ch;
+
+ /* Basic lookups. */
+ for (i = 0; i < 26; i++) {
+ ch[0] = 'a' + i;
+
+ ATF_REQUIRE(hsearch_r(e, FIND, &ep, &t) == 1);
+ ATF_REQUIRE(ep != NULL);
+ ATF_REQUIRE_STREQ(ep->key, ch);
+ ATF_REQUIRE_EQ((intptr_t)ep->data, i);
+ }
+
+ hdestroy1_r(&t, free, NULL);
+}
+#endif
+
+ATF_TC(hsearch_r_duplicate);
+ATF_TC_HEAD(hsearch_r_duplicate, tc)
+{
+
+ atf_tc_set_md_var(tc, "descr", "Checks that inserting duplicate "
+ "doesn't overwrite existing data");
+}
+
+ATF_TC_BODY(hsearch_r_duplicate, tc)
+{
+ ENTRY e, *ep;
+ struct hsearch_data t;
+
+ REQUIRE_ERRNO(hcreate_r(16, &t));
+
+ e.key = __UNCONST("a");
+ e.data = (void *)(intptr_t) 0;
+
+ ATF_REQUIRE(hsearch_r(e, ENTER, &ep, &t) == 1);
+ ATF_REQUIRE(ep != NULL);
+ ATF_REQUIRE_STREQ(ep->key, "a");
+ ATF_REQUIRE_EQ((intptr_t)ep->data, 0);
+
+ e.data = (void *)(intptr_t)12345;
+
+ ATF_REQUIRE(hsearch_r(e, ENTER, &ep, &t) == 1);
+ ATF_REQUIRE(hsearch_r(e, FIND, &ep, &t) == 1);
+
+ ATF_REQUIRE(ep != NULL);
+ ATF_REQUIRE_STREQ(ep->key, "a");
+ ATF_REQUIRE_EQ((intptr_t)ep->data, 0);
+
+ hdestroy_r(&t);
+}
+
+ATF_TC(hsearch_r_nonexistent);
+ATF_TC_HEAD(hsearch_r_nonexistent, tc)
+{
+
+ atf_tc_set_md_var(tc, "descr",
+ "Checks searching for non-existent entry");
+}
+
+ATF_TC_BODY(hsearch_r_nonexistent, tc)
+{
+ ENTRY e, *ep;
+ struct hsearch_data t;
+
+ REQUIRE_ERRNO(hcreate_r(16, &t));
+
+ e.key = __UNCONST("A");
+ ATF_REQUIRE(hsearch_r(e, FIND, &ep, &t) == 1);
+ ATF_REQUIRE_EQ(ep, NULL);
+
+ hdestroy_r(&t);
+}
+
+ATF_TC(hsearch_r_two);
+ATF_TC_HEAD(hsearch_r_two, tc)
+{
+
+ atf_tc_set_md_var(tc, "descr",
+ "Checks that searching doesn't overwrite previous search results");
+}
+
+ATF_TC_BODY(hsearch_r_two, tc)
+{
+ ENTRY e, *ep, *ep2;
+ struct hsearch_data t;
+
+ REQUIRE_ERRNO(hcreate_r(16, &t));
+
+ e.key = __UNCONST("a");
+ e.data = (void*)(intptr_t)0;
+
+ ATF_REQUIRE(hsearch_r(e, ENTER, &ep, &t) == 1);
+ ATF_REQUIRE(ep != NULL);
+ ATF_REQUIRE_STREQ(ep->key, "a");
+ ATF_REQUIRE_EQ((intptr_t)ep->data, 0);
+
+ e.key = __UNCONST("b");
+ e.data = (void*)(intptr_t)1;
+
+ ATF_REQUIRE(hsearch_r(e, ENTER, &ep, &t) == 1);
+ ATF_REQUIRE(ep != NULL);
+ ATF_REQUIRE_STREQ(ep->key, "b");
+ ATF_REQUIRE_EQ((intptr_t)ep->data, 1);
+
+ e.key = __UNCONST("a");
+ ATF_REQUIRE(hsearch_r(e, FIND, &ep, &t) == 1);
+
+ e.key = __UNCONST("b");
+ ATF_REQUIRE(hsearch_r(e, FIND, &ep2, &t) == 1);
+
+ ATF_REQUIRE(ep != NULL);
+ ATF_REQUIRE_STREQ(ep->key, "a");
+ ATF_REQUIRE_EQ((intptr_t)ep->data, 0);
+
+ ATF_REQUIRE(ep2 != NULL);
+ ATF_REQUIRE_STREQ(ep2->key, "b");
+ ATF_REQUIRE_EQ((intptr_t)ep2->data, 1);
+
+ hdestroy_r(&t);
+}
+#endif
+
+ATF_TP_ADD_TCS(tp)
+{
+
+#ifdef __NetBSD__
+ ATF_TP_ADD_TC(tp, hsearch_basic);
+#endif
+ ATF_TP_ADD_TC(tp, hsearch_duplicate);
+ ATF_TP_ADD_TC(tp, hsearch_nonexistent);
+ ATF_TP_ADD_TC(tp, hsearch_two);
+
+#if defined(__FreeBSD__) && 1100027 <= __FreeBSD_version
+#ifdef __NetBSD__
+ ATF_TP_ADD_TC(tp, hsearch_r_basic);
+#endif
+ ATF_TP_ADD_TC(tp, hsearch_r_duplicate);
+ ATF_TP_ADD_TC(tp, hsearch_r_nonexistent);
+ ATF_TP_ADD_TC(tp, hsearch_r_two);
+#endif
+
+ return atf_no_error();
+}
diff --git a/contrib/netbsd-tests/lib/libc/stdlib/t_mi_vector_hash.c b/contrib/netbsd-tests/lib/libc/stdlib/t_mi_vector_hash.c
new file mode 100644
index 0000000..77d6443
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libc/stdlib/t_mi_vector_hash.c
@@ -0,0 +1,95 @@
+/* $NetBSD: t_mi_vector_hash.c,v 1.3 2011/07/07 11:12:18 jruoho Exp $ */
+/*-
+ * Copyright (c) 2009 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Joerg Sonnenberger.
+ *
+ * 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_mi_vector_hash.c,v 1.3 2011/07/07 11:12:18 jruoho Exp $");
+
+#include <atf-c.h>
+#include <stdlib.h>
+#include <string.h>
+
+ATF_TC(mi_vector_hash_basic);
+ATF_TC_HEAD(mi_vector_hash_basic, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test mi_vector_hash_vector_hash for consistent results");
+}
+
+static const struct testvector {
+ const char *vector;
+ uint32_t hashes[3];
+} testv[] = {
+ { "hello, world", { 0xd38f7f21, 0xbf6be9ab, 0x37a0e989 } },
+ { "", { 0x9b2ec03d, 0xdb2b69ae, 0xbd49d10d } },
+ { "a", { 0x9454baa3, 0xb711c708, 0x29eec818 } },
+ { "ab", { 0x9a5dca90, 0xdd212644, 0x9879ac41 } },
+ { "abc", { 0x0b91c470, 0x4770cdf5, 0x251e4793 } },
+ { "abcd", { 0x5f128df3, 0xf5a667a6, 0x5ae61fa5 } },
+ { "abcde", { 0x4cbae281, 0x799c0ed5, 0x03a96866 } },
+ { "abcdef", { 0x507a54c8, 0xb6bd06f4, 0xde922732 } },
+ { "abcdefg", { 0xae2bca5d, 0x61e960ef, 0xb9e6762c } },
+ { "abcdefgh", { 0xd1021264, 0x87f6988f, 0x053f775e } },
+ { "abcdefghi", { 0xe380defc, 0xfc35a811, 0x3a7b0a5f } },
+ { "abcdefghij", { 0x9a504408, 0x70d2e89d, 0xc9cac242 } },
+ { "abcdefghijk", { 0x376117d0, 0x89f434d4, 0xe52b8e4c } },
+ { "abcdefghijkl", { 0x92253599, 0x7b6ff99e, 0x0b1b3ea5 } },
+ { "abcdefghijklm", { 0x92ee6a52, 0x55587d47, 0x3122b031 } },
+ { "abcdefghijklmn", { 0x827baf08, 0x1d0ada73, 0xfec330e0 } },
+ { "abcdefghijklmno", { 0x06ab787d, 0xc1ad17c2, 0x11dccf31 } },
+ { "abcdefghijklmnop", { 0x2cf18103, 0x638c9268, 0xfa1ecf51 } },
+};
+
+ATF_TC_BODY(mi_vector_hash_basic, tc)
+{
+ size_t i, j, len;
+ uint32_t hashes[3];
+ char buf[256];
+
+ for (j = 0; j < 8; ++j) {
+ for (i = 0; i < sizeof(testv) / sizeof(testv[0]); ++i) {
+ len = strlen(testv[i].vector);
+ strcpy(buf + j, testv[i].vector);
+ mi_vector_hash(buf + j, len, 0, hashes);
+ ATF_CHECK_EQ(hashes[0], testv[i].hashes[0]);
+ ATF_CHECK_EQ(hashes[1], testv[i].hashes[1]);
+ ATF_CHECK_EQ(hashes[2], testv[i].hashes[2]);
+ }
+ }
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+ ATF_TP_ADD_TC(tp, mi_vector_hash_basic);
+
+ return atf_no_error();
+}
diff --git a/contrib/netbsd-tests/lib/libc/stdlib/t_posix_memalign.c b/contrib/netbsd-tests/lib/libc/stdlib/t_posix_memalign.c
new file mode 100644
index 0000000..47afb84
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libc/stdlib/t_posix_memalign.c
@@ -0,0 +1,88 @@
+/* $NetBSD: t_posix_memalign.c,v 1.2 2011/07/07 11:12:18 jruoho Exp $ */
+
+/*-
+ * Copyright (c) 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: t_posix_memalign.c,v 1.2 2011/07/07 11:12:18 jruoho Exp $");
+
+#include <atf-c.h>
+
+#include <errno.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+ATF_TC(posix_memalign_basic);
+ATF_TC_HEAD(posix_memalign_basic, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Checks posix_memalign(3)");
+}
+ATF_TC_BODY(posix_memalign_basic, tc)
+{
+ size_t size[] = {
+ 1, 2, 3, 4, 10, 100, 16384, 32768, 65536
+ };
+ size_t align[] = {
+ 512, 1024, 16, 32, 64, 4, 2048, 16, 2
+ };
+
+ size_t i;
+ void *p;
+
+ for (i = 0; i < __arraycount(size); i++) {
+ int ret;
+ p = (void*)0x1;
+
+ (void)printf("Checking posix_memalign(&p, %zd, %zd)...\n",
+ align[i], size[i]);
+ ret = posix_memalign(&p, align[i], size[i]);
+
+ if ( align[i] < sizeof(void *))
+ ATF_REQUIRE_EQ_MSG(ret, EINVAL,
+ "posix_memalign: %s", strerror(ret));
+ else {
+ ATF_REQUIRE_EQ_MSG(ret, 0,
+ "posix_memalign: %s", strerror(ret));
+ ATF_REQUIRE_EQ_MSG(((intptr_t)p) & (align[i] - 1), 0,
+ "p = %p", p);
+ free(p);
+ }
+ }
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+ ATF_TP_ADD_TC(tp, posix_memalign_basic);
+
+ return atf_no_error();
+}
diff --git a/contrib/netbsd-tests/lib/libc/stdlib/t_random.c b/contrib/netbsd-tests/lib/libc/stdlib/t_random.c
new file mode 100644
index 0000000..9a6d21e
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libc/stdlib/t_random.c
@@ -0,0 +1,82 @@
+/* $NetBSD: t_random.c,v 1.3 2012/03/29 08:56:06 jruoho Exp $ */
+
+/*-
+ * Copyright (c) 2012 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_random.c,v 1.3 2012/03/29 08:56:06 jruoho Exp $");
+
+#include <atf-c.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+/*
+ * TODO: Add some general RNG tests (cf. the famous "diehard" tests?).
+ */
+
+ATF_TC(random_same);
+ATF_TC_HEAD(random_same, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test that random(3) does not always return the same "
+ "value when the seed is initialized to zero");
+}
+
+#define MAX_ITER 10
+
+ATF_TC_BODY(random_same, tc)
+{
+ long buf[MAX_ITER];
+ size_t i, j;
+
+ /*
+ * See CVE-2012-1577.
+ */
+ srandom(0);
+
+ for (i = 0; i < __arraycount(buf); i++) {
+
+ buf[i] = random();
+
+ for (j = 0; j < i; j++) {
+
+ (void)fprintf(stderr, "i = %zu, j = %zu: "
+ "%ld vs. %ld\n", i, j, buf[i], buf[j]);
+
+ ATF_CHECK(buf[i] != buf[j]);
+ }
+ }
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, random_same);
+
+ return atf_no_error();
+}
diff --git a/contrib/netbsd-tests/lib/libc/stdlib/t_strtod.c b/contrib/netbsd-tests/lib/libc/stdlib/t_strtod.c
new file mode 100644
index 0000000..8f0f899
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libc/stdlib/t_strtod.c
@@ -0,0 +1,342 @@
+/* $NetBSD: t_strtod.c,v 1.32 2014/11/04 00:20:19 justin 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.
+ */
+
+/* Public domain, Otto Moerbeek <otto@drijf.net>, 2006. */
+
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: t_strtod.c,v 1.32 2014/11/04 00:20:19 justin Exp $");
+
+#include <errno.h>
+#include <math.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <atf-c.h>
+
+#if defined(__i386__) || defined(__amd64__) || defined(__sparc__)
+#include <fenv.h>
+#endif
+
+#if !defined(__vax__)
+static const char * const inf_strings[] =
+ { "Inf", "INF", "-Inf", "-INF", "Infinity", "+Infinity",
+ "INFINITY", "-INFINITY", "InFiNiTy", "+InFiNiTy" };
+const char *nan_string = "NaN(x)y";
+#endif
+
+#ifdef __FreeBSD__
+#define __HAVE_LONG_DOUBLE
+#endif
+
+ATF_TC(strtod_basic);
+ATF_TC_HEAD(strtod_basic, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "A basic test of strtod(3)");
+}
+
+ATF_TC_BODY(strtod_basic, tc)
+{
+ static const size_t n = 1024 * 1000;
+
+ for (size_t i = 1; i < n; i = i + 1024) {
+ char buf[512];
+ (void)snprintf(buf, sizeof(buf), "%zu.%zu", i, i + 1);
+
+ errno = 0;
+ double d = strtod(buf, NULL);
+
+ ATF_REQUIRE(d > 0.0);
+ ATF_REQUIRE(errno == 0);
+ }
+}
+
+ATF_TC(strtod_hex);
+ATF_TC_HEAD(strtod_hex, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "A strtod(3) with hexadecimals");
+}
+
+#ifdef __vax__
+#define SMALL_NUM 1.0e-38
+#else
+#define SMALL_NUM 1.0e-40
+#endif
+
+ATF_TC_BODY(strtod_hex, tc)
+{
+ const char *str;
+ char *end;
+ volatile double d;
+
+ str = "-0x0";
+ d = strtod(str, &end); /* -0.0 */
+
+ ATF_REQUIRE(end == str + 4);
+ ATF_REQUIRE(signbit(d) != 0);
+ ATF_REQUIRE(fabs(d) < SMALL_NUM);
+
+ str = "-0x";
+ d = strtod(str, &end); /* -0.0 */
+
+ ATF_REQUIRE(end == str + 2);
+ ATF_REQUIRE(signbit(d) != 0);
+ ATF_REQUIRE(fabs(d) < SMALL_NUM);
+}
+
+ATF_TC(strtod_inf);
+ATF_TC_HEAD(strtod_inf, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "A strtod(3) with INF (PR lib/33262)");
+}
+
+ATF_TC_BODY(strtod_inf, tc)
+{
+#ifndef __vax__
+ for (size_t i = 0; i < __arraycount(inf_strings); i++) {
+ volatile double d = strtod(inf_strings[i], NULL);
+ ATF_REQUIRE(isinf(d) != 0);
+ }
+#else
+ atf_tc_skip("vax not supported");
+#endif
+}
+
+ATF_TC(strtof_inf);
+ATF_TC_HEAD(strtof_inf, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "A strtof(3) with INF (PR lib/33262)");
+}
+
+ATF_TC_BODY(strtof_inf, tc)
+{
+#ifndef __vax__
+ for (size_t i = 0; i < __arraycount(inf_strings); i++) {
+ volatile float f = strtof(inf_strings[i], NULL);
+ ATF_REQUIRE(isinf(f) != 0);
+ }
+#else
+ atf_tc_skip("vax not supported");
+#endif
+}
+
+ATF_TC(strtold_inf);
+ATF_TC_HEAD(strtold_inf, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "A strtold(3) with INF (PR lib/33262)");
+}
+
+ATF_TC_BODY(strtold_inf, tc)
+{
+#ifndef __vax__
+# ifdef __HAVE_LONG_DOUBLE
+
+ for (size_t i = 0; i < __arraycount(inf_strings); i++) {
+ volatile long double ld = strtold(inf_strings[i], NULL);
+ ATF_REQUIRE(isinf(ld) != 0);
+ }
+# else
+ atf_tc_skip("Requires long double support");
+# endif
+#else
+ atf_tc_skip("vax not supported");
+#endif
+}
+
+ATF_TC(strtod_nan);
+ATF_TC_HEAD(strtod_nan, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "A strtod(3) with NaN");
+}
+
+ATF_TC_BODY(strtod_nan, tc)
+{
+#ifndef __vax__
+ char *end;
+
+ volatile double d = strtod(nan_string, &end);
+ ATF_REQUIRE(isnan(d) != 0);
+ ATF_REQUIRE(strcmp(end, "y") == 0);
+#else
+ atf_tc_skip("vax not supported");
+#endif
+}
+
+ATF_TC(strtof_nan);
+ATF_TC_HEAD(strtof_nan, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "A strtof(3) with NaN");
+}
+
+ATF_TC_BODY(strtof_nan, tc)
+{
+#ifndef __vax__
+ char *end;
+
+ volatile float f = strtof(nan_string, &end);
+ ATF_REQUIRE(isnanf(f) != 0);
+ ATF_REQUIRE(strcmp(end, "y") == 0);
+#else
+ atf_tc_skip("vax not supported");
+#endif
+}
+
+ATF_TC(strtold_nan);
+ATF_TC_HEAD(strtold_nan, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "A strtold(3) with NaN (PR lib/45020)");
+}
+
+ATF_TC_BODY(strtold_nan, tc)
+{
+#ifndef __vax__
+# ifdef __HAVE_LONG_DOUBLE
+
+ char *end;
+
+ volatile long double ld = strtold(nan_string, &end);
+ ATF_REQUIRE(isnan(ld) != 0);
+#ifdef __FreeBSD__
+ ATF_REQUIRE(strcmp(end, "y") == 0);
+#else
+ ATF_REQUIRE(__isnanl(ld) != 0);
+#endif
+ ATF_REQUIRE(strcmp(end, "y") == 0);
+# else
+ atf_tc_skip("Requires long double support");
+# endif
+#else
+ atf_tc_skip("vax not supported");
+#endif
+}
+
+ATF_TC(strtod_round);
+ATF_TC_HEAD(strtod_round, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Test rouding in strtod(3)");
+}
+
+ATF_TC_BODY(strtod_round, tc)
+{
+#if defined(__i386__) || defined(__amd64__) || defined(__sparc__)
+
+ /*
+ * Test that strtod(3) honors the current rounding mode.
+ * The used value is somewhere near 1 + DBL_EPSILON + FLT_EPSILON.
+ */
+ const char *val =
+ "1.00000011920928977282585492503130808472633361816406";
+
+ (void)fesetround(FE_UPWARD);
+
+ volatile double d1 = strtod(val, NULL);
+
+ (void)fesetround(FE_DOWNWARD);
+
+ volatile double d2 = strtod(val, NULL);
+
+ if (fabs(d1 - d2) > 0.0)
+ return;
+ else {
+ atf_tc_expect_fail("PR misc/44767");
+ atf_tc_fail("strtod(3) did not honor fesetround(3)");
+ }
+#else
+ atf_tc_skip("Requires one of i386, amd64 or sparc");
+#endif
+}
+
+ATF_TC(strtod_underflow);
+ATF_TC_HEAD(strtod_underflow, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Test underflow in strtod(3)");
+}
+
+ATF_TC_BODY(strtod_underflow, tc)
+{
+
+ const char *tmp =
+ "0.0000000000000000000000000000000000000000000000000000"
+ "000000000000000000000000000000000000000000000000000000"
+ "000000000000000000000000000000000000000000000000000000"
+ "000000000000000000000000000000000000000000000000000000"
+ "000000000000000000000000000000000000000000000000000000"
+ "000000000000000000000000000000000000000000000000000000"
+ "000000000000000000000000000000000000000000000000000000"
+ "000000000000000002";
+
+ errno = 0;
+ volatile double d = strtod(tmp, NULL);
+
+ if (d != 0 || errno != ERANGE)
+ atf_tc_fail("strtod(3) did not detect underflow");
+}
+
+/*
+ * Bug found by Geza Herman.
+ * See
+ * http://www.exploringbinary.com/a-bug-in-the-bigcomp-function-of-david-gays-strtod/
+ */
+ATF_TC(strtod_gherman_bug);
+ATF_TC_HEAD(strtod_gherman_bug, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Test a bug found by Geza Herman");
+}
+
+ATF_TC_BODY(strtod_gherman_bug, tc)
+{
+
+ const char *str =
+ "1.8254370818746402660437411213933955878019332885742187";
+
+ errno = 0;
+ volatile double d = strtod(str, NULL);
+
+ ATF_CHECK(d == 0x1.d34fd8378ea83p+0);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, strtod_basic);
+ ATF_TP_ADD_TC(tp, strtod_hex);
+ ATF_TP_ADD_TC(tp, strtod_inf);
+ ATF_TP_ADD_TC(tp, strtof_inf);
+ ATF_TP_ADD_TC(tp, strtold_inf);
+ ATF_TP_ADD_TC(tp, strtod_nan);
+ ATF_TP_ADD_TC(tp, strtof_nan);
+ ATF_TP_ADD_TC(tp, strtold_nan);
+ ATF_TP_ADD_TC(tp, strtod_round);
+ ATF_TP_ADD_TC(tp, strtod_underflow);
+ ATF_TP_ADD_TC(tp, strtod_gherman_bug);
+
+ return atf_no_error();
+}
diff --git a/contrib/netbsd-tests/lib/libc/stdlib/t_strtol.c b/contrib/netbsd-tests/lib/libc/stdlib/t_strtol.c
new file mode 100644
index 0000000..5a0c6d0
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libc/stdlib/t_strtol.c
@@ -0,0 +1,234 @@
+/* $NetBSD: t_strtol.c,v 1.5 2011/06/14 02:45:58 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_strtol.c,v 1.5 2011/06/14 02:45:58 jruoho Exp $");
+
+#include <atf-c.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <limits.h>
+
+struct test {
+ const char *str;
+ int64_t res;
+ int base;
+ const char *end;
+};
+
+static void check(struct test *, long int, long long int, char *);
+
+static void
+check(struct test *t, long int li, long long int lli, char *end)
+{
+
+ if (li != -1 && li != t->res)
+ atf_tc_fail_nonfatal("strtol(%s, &end, %d) failed "
+ "(rv = %ld)", t->str, t->base, li);
+
+ if (lli != -1 && lli != t->res)
+ atf_tc_fail_nonfatal("strtoll(%s, NULL, %d) failed "
+ "(rv = %lld)", t->str, t->base, lli);
+
+ if (t->end != NULL && strcmp(t->end, end) != 0)
+ atf_tc_fail_nonfatal("invalid end pointer ('%s') from "
+ "strtol(%s, &end, %d)", end, t->str, t->base);
+}
+
+ATF_TC(strtol_base);
+ATF_TC_HEAD(strtol_base, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Test strtol(3) with different bases");
+}
+
+ATF_TC_BODY(strtol_base, tc)
+{
+ struct test t[] = {
+ { "123456789", 123456789, 0, NULL },
+ { "111010110111100110100010101", 123456789, 2, NULL },
+ { "22121022020212200", 123456789, 3, NULL },
+ { "13112330310111", 123456789, 4, NULL },
+ { "223101104124", 123456789, 5, NULL },
+ { "20130035113", 123456789, 6, NULL },
+ { "3026236221", 123456789, 7, NULL },
+ { "726746425", 123456789, 8, NULL },
+ { "277266780", 123456789, 9, NULL },
+ { "123456789", 123456789, 10, NULL },
+ { "63762A05", 123456789, 11, NULL },
+ { "35418A99", 123456789, 12, NULL },
+ { "1C767471", 123456789, 13, NULL },
+ { "12579781", 123456789, 14, NULL },
+ { "AC89BC9", 123456789, 15, NULL },
+ { "75BCD15", 123456789, 16, NULL },
+ { "123456789", 342391, 8, NULL },
+ { "0123456789", 342391, 0, NULL },
+ { "0123456789", 123456789, 10, NULL },
+ { "0x75bcd15", 123456789, 0, NULL },
+ };
+
+ long long int lli;
+ long int li;
+ char *end;
+ size_t i;
+
+ for (i = 0; i < __arraycount(t); i++) {
+
+ li = strtol(t[i].str, &end, t[i].base);
+ lli = strtoll(t[i].str, NULL, t[i].base);
+
+ check(&t[i], li, lli, end);
+ }
+}
+
+ATF_TC(strtol_case);
+ATF_TC_HEAD(strtol_case, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Case insensitivity with strtol(3)");
+}
+
+ATF_TC_BODY(strtol_case, tc)
+{
+ struct test t[] = {
+ { "abcd", 0xabcd, 16, NULL },
+ { " dcba", 0xdcba, 16, NULL },
+ { "abcd dcba", 0xabcd, 16, " dcba" },
+ { "abc0x123", 0xabc0, 16, NULL },
+ { "abcd\0x123", 0xabcd, 16, "\0x123" },
+ { "ABCD", 0xabcd, 16, NULL },
+ { "aBcD", 0xabcd, 16, NULL },
+ { "0xABCD", 0xabcd, 16, NULL },
+ { "0xABCDX", 0xabcd, 16, "X" },
+ };
+
+ long long int lli;
+ long int li;
+ char *end;
+ size_t i;
+
+ for (i = 0; i < __arraycount(t); i++) {
+
+ li = strtol(t[i].str, &end, t[i].base);
+ lli = strtoll(t[i].str, NULL, t[i].base);
+
+ check(&t[i], li, lli, end);
+ }
+}
+
+ATF_TC(strtol_range);
+ATF_TC_HEAD(strtol_range, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Test ERANGE from strtol(3)");
+}
+
+ATF_TC_BODY(strtol_range, tc)
+{
+
+#if LONG_MAX == 0x7fffffff /* XXX: Is this portable? */
+
+ struct test t[] = {
+ { "20000000000", 2147483647, 8, NULL },
+ { "2147483648", 2147483647, 10, NULL },
+ { "80000000", 2147483647, 16, NULL },
+ };
+#else
+ struct test t[] = {
+ { "1000000000000000000000", 9223372036854775807, 8, NULL },
+ { "9223372036854775808", 9223372036854775807, 10, NULL },
+ { "8000000000000000", 9223372036854775807, 16, NULL },
+ };
+#endif
+
+ long int li;
+ char *end;
+ size_t i;
+
+ for (i = 0; i < __arraycount(t); i++) {
+
+ errno = 0;
+ li = strtol(t[i].str, &end, t[i].base);
+
+ if (errno != ERANGE)
+ atf_tc_fail("strtol(3) did not catch ERANGE");
+
+ check(&t[i], li, -1, end);
+ }
+}
+
+ATF_TC(strtol_signed);
+ATF_TC_HEAD(strtol_signed, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "A basic test of strtol(3)");
+}
+
+ATF_TC_BODY(strtol_signed, tc)
+{
+ struct test t[] = {
+ { "1", 1, 0, NULL },
+ { " 2", 2, 0, NULL },
+ { " 3", 3, 0, NULL },
+ { " -3", -3, 0, NULL },
+ { "--1", 0, 0, "--1" },
+ { "+-2", 0, 0, "+-2" },
+ { "++3", 0, 0, "++3" },
+ { "+9", 9, 0, NULL },
+ { "+123", 123, 0, NULL },
+ { "-1 3", -1, 0, " 3" },
+ { "-1.3", -1, 0, ".3" },
+ { "- 3", 0, 0, "- 3" },
+ { "+33.", 33, 0, "." },
+ { "30x0", 30, 0, "x0" },
+ };
+
+ long long int lli;
+ long int li;
+ char *end;
+ size_t i;
+
+ for (i = 0; i < __arraycount(t); i++) {
+
+ li = strtol(t[i].str, &end, t[i].base);
+ lli = strtoll(t[i].str, NULL, t[i].base);
+
+ check(&t[i], li, lli, end);
+ }
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, strtol_base);
+ ATF_TP_ADD_TC(tp, strtol_case);
+ ATF_TP_ADD_TC(tp, strtol_range);
+ ATF_TP_ADD_TC(tp, strtol_signed);
+
+ return atf_no_error();
+}
diff --git a/contrib/netbsd-tests/lib/libc/stdlib/t_system.c b/contrib/netbsd-tests/lib/libc/stdlib/t_system.c
new file mode 100644
index 0000000..235005b
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libc/stdlib/t_system.c
@@ -0,0 +1,83 @@
+/* $NetBSD: t_system.c,v 1.1 2011/09/11 10:32:23 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_system.c,v 1.1 2011/09/11 10:32:23 jruoho Exp $");
+
+#include <atf-c.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+static const char *path = "system";
+
+ATF_TC_WITH_CLEANUP(system_basic);
+ATF_TC_HEAD(system_basic, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "A basic test of system(3)");
+}
+
+ATF_TC_BODY(system_basic, tc)
+{
+ char buf[23];
+ int fd, i = 2;
+
+ ATF_REQUIRE(system("/bin/echo -n > system") == 0);
+
+ while (i >= 0) {
+ ATF_REQUIRE(system("/bin/echo -n garbage >> system") == 0);
+ i--;
+ }
+
+ fd = open(path, O_RDONLY);
+ ATF_REQUIRE(fd >= 0);
+
+ (void)memset(buf, '\0', sizeof(buf));
+
+ ATF_REQUIRE(read(fd, buf, 21) == 21);
+ ATF_REQUIRE(strcmp(buf, "garbagegarbagegarbage") == 0);
+
+ ATF_REQUIRE(close(fd) == 0);
+ ATF_REQUIRE(unlink(path) == 0);
+}
+
+ATF_TC_CLEANUP(system_basic, tc)
+{
+ (void)unlink(path);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, system_basic);
+
+ return atf_no_error();
+}
OpenPOWER on IntegriCloud