[Midnightbsd-cvs] src [10420] trunk/lib/libc/tests: add tests
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Tue Jun 5 17:54:19 EDT 2018
Revision: 10420
http://svnweb.midnightbsd.org/src/?rev=10420
Author: laffer1
Date: 2018-06-05 17:54:18 -0400 (Tue, 05 Jun 2018)
Log Message:
-----------
add tests
Added Paths:
-----------
trunk/lib/libc/tests/
trunk/lib/libc/tests/Makefile
trunk/lib/libc/tests/Makefile.netbsd-tests
trunk/lib/libc/tests/c063/
trunk/lib/libc/tests/c063/Makefile
trunk/lib/libc/tests/db/
trunk/lib/libc/tests/db/Makefile
trunk/lib/libc/tests/gen/
trunk/lib/libc/tests/gen/Makefile
trunk/lib/libc/tests/gen/arc4random_test.c
trunk/lib/libc/tests/gen/execve/
trunk/lib/libc/tests/gen/execve/Makefile
trunk/lib/libc/tests/gen/fmtcheck_test.c
trunk/lib/libc/tests/gen/fmtmsg_test.c
trunk/lib/libc/tests/gen/fnmatch_test.c
trunk/lib/libc/tests/gen/fnmatch_testcases.h
trunk/lib/libc/tests/gen/fpclassify2_test.c
trunk/lib/libc/tests/gen/ftw_test.c
trunk/lib/libc/tests/gen/popen_test.c
trunk/lib/libc/tests/gen/posix_spawn/
trunk/lib/libc/tests/gen/posix_spawn/Makefile
trunk/lib/libc/tests/gen/posix_spawn_test.c
trunk/lib/libc/tests/gen/realpath2_test.c
trunk/lib/libc/tests/gen/test-fnmatch.c
trunk/lib/libc/tests/gen/wordexp_test.c
trunk/lib/libc/tests/hash/
trunk/lib/libc/tests/hash/Makefile
trunk/lib/libc/tests/iconv/
trunk/lib/libc/tests/iconv/Makefile
trunk/lib/libc/tests/iconv/iconvctl_test.c
trunk/lib/libc/tests/inet/
trunk/lib/libc/tests/inet/Makefile
trunk/lib/libc/tests/locale/
trunk/lib/libc/tests/locale/Makefile
trunk/lib/libc/tests/locale/btowc_test.c
trunk/lib/libc/tests/locale/c16rtomb_test.c
trunk/lib/libc/tests/locale/iswctype_test.c
trunk/lib/libc/tests/locale/mblen_test.c
trunk/lib/libc/tests/locale/mbrlen_test.c
trunk/lib/libc/tests/locale/mbrtoc16_test.c
trunk/lib/libc/tests/locale/mbrtowc_test.c
trunk/lib/libc/tests/locale/mbsnrtowcs_test.c
trunk/lib/libc/tests/locale/mbsrtowcs_test.c
trunk/lib/libc/tests/locale/mbstowcs_test.c
trunk/lib/libc/tests/locale/mbtowc_test.c
trunk/lib/libc/tests/locale/towctrans_test.c
trunk/lib/libc/tests/locale/wcrtomb_test.c
trunk/lib/libc/tests/locale/wcsnrtombs_test.c
trunk/lib/libc/tests/locale/wcsrtombs_test.c
trunk/lib/libc/tests/locale/wcstombs_test.c
trunk/lib/libc/tests/locale/wctomb_test.c
trunk/lib/libc/tests/net/
trunk/lib/libc/tests/net/Makefile
trunk/lib/libc/tests/net/ether_test.c
trunk/lib/libc/tests/net/eui64_aton_test.c
trunk/lib/libc/tests/net/eui64_ntoa_test.c
trunk/lib/libc/tests/net/getaddrinfo/
trunk/lib/libc/tests/net/getaddrinfo/Makefile
trunk/lib/libc/tests/net/test-eui64.h
trunk/lib/libc/tests/nss/
trunk/lib/libc/tests/nss/Makefile
trunk/lib/libc/tests/nss/getaddrinfo_test.c
trunk/lib/libc/tests/nss/getgr_test.c
trunk/lib/libc/tests/nss/gethostby_test.c
trunk/lib/libc/tests/nss/getproto_test.c
trunk/lib/libc/tests/nss/getpw_test.c
trunk/lib/libc/tests/nss/getrpc_test.c
trunk/lib/libc/tests/nss/getserv_test.c
trunk/lib/libc/tests/nss/getusershell_test.c
trunk/lib/libc/tests/nss/testutil.h
trunk/lib/libc/tests/regex/
trunk/lib/libc/tests/regex/Makefile
trunk/lib/libc/tests/resolv/
trunk/lib/libc/tests/resolv/Makefile
trunk/lib/libc/tests/resolv/mach
trunk/lib/libc/tests/resolv/resolv_test.c
trunk/lib/libc/tests/rpc/
trunk/lib/libc/tests/rpc/Makefile
trunk/lib/libc/tests/setjmp/
trunk/lib/libc/tests/setjmp/Makefile
trunk/lib/libc/tests/ssp/
trunk/lib/libc/tests/ssp/Makefile
trunk/lib/libc/tests/stdio/
trunk/lib/libc/tests/stdio/Makefile
trunk/lib/libc/tests/stdio/fdopen_test.c
trunk/lib/libc/tests/stdio/fmemopen2_test.c
trunk/lib/libc/tests/stdio/fopen_test.c
trunk/lib/libc/tests/stdio/freopen_test.c
trunk/lib/libc/tests/stdio/getdelim_test.c
trunk/lib/libc/tests/stdio/mkostemp_test.c
trunk/lib/libc/tests/stdio/open_memstream2_test.c
trunk/lib/libc/tests/stdio/open_wmemstream_test.c
trunk/lib/libc/tests/stdio/perror_test.c
trunk/lib/libc/tests/stdio/print_positional_test.c
trunk/lib/libc/tests/stdio/printbasic_test.c
trunk/lib/libc/tests/stdio/printfloat_test.c
trunk/lib/libc/tests/stdio/scanfloat_test.c
trunk/lib/libc/tests/stdlib/
trunk/lib/libc/tests/stdlib/Makefile
trunk/lib/libc/tests/stdlib/cxa_thread_atexit_nothr_test.cc
trunk/lib/libc/tests/stdlib/cxa_thread_atexit_test.cc
trunk/lib/libc/tests/stdlib/heapsort_test.c
trunk/lib/libc/tests/stdlib/mergesort_test.c
trunk/lib/libc/tests/stdlib/qsort_test.c
trunk/lib/libc/tests/stdlib/test-sort.h
trunk/lib/libc/tests/string/
trunk/lib/libc/tests/string/Makefile
trunk/lib/libc/tests/string/stpncpy_test.c
trunk/lib/libc/tests/string/strerror_test.c
trunk/lib/libc/tests/string/wcscasecmp_test.c
trunk/lib/libc/tests/string/wcsnlen_test.c
trunk/lib/libc/tests/sys/
trunk/lib/libc/tests/sys/Makefile
trunk/lib/libc/tests/sys/mlock_helper.c
trunk/lib/libc/tests/sys/queue_test.c
trunk/lib/libc/tests/termios/
trunk/lib/libc/tests/termios/Makefile
trunk/lib/libc/tests/time/
trunk/lib/libc/tests/time/Makefile
trunk/lib/libc/tests/tls/
trunk/lib/libc/tests/tls/Makefile
trunk/lib/libc/tests/tls/dso/
trunk/lib/libc/tests/tls/dso/Makefile
trunk/lib/libc/tests/tls_dso/
trunk/lib/libc/tests/tls_dso/Makefile
trunk/lib/libc/tests/ttyio/
trunk/lib/libc/tests/ttyio/Makefile
Added: trunk/lib/libc/tests/Makefile
===================================================================
--- trunk/lib/libc/tests/Makefile (rev 0)
+++ trunk/lib/libc/tests/Makefile 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,40 @@
+# $MidnightBSD$
+# $FreeBSD: stable/10/lib/libc/tests/Makefile 313489 2017-02-09 22:57:56Z ngie $
+
+.include <bsd.own.mk>
+
+SUBDIR= tls_dso
+
+TESTS_SUBDIRS= c063
+TESTS_SUBDIRS+= db
+TESTS_SUBDIRS+= gen
+TESTS_SUBDIRS+= hash
+TESTS_SUBDIRS+= iconv
+TESTS_SUBDIRS+= inet
+TESTS_SUBDIRS+= net
+TESTS_SUBDIRS+= nss
+TESTS_SUBDIRS+= regex
+TESTS_SUBDIRS+= resolv
+TESTS_SUBDIRS+= rpc
+TESTS_SUBDIRS+= setjmp
+TESTS_SUBDIRS+= stdio
+TESTS_SUBDIRS+= stdlib
+TESTS_SUBDIRS+= string
+TESTS_SUBDIRS+= sys
+TESTS_SUBDIRS+= termios
+TESTS_SUBDIRS+= tls
+TESTS_SUBDIRS+= ttyio
+
+.if ${MK_ICONV} != "no"
+TESTS_SUBDIRS+= iconv
+.endif
+
+.if ${MK_LOCALES} != "no"
+TESTS_SUBDIRS+= locale
+.endif
+
+.if ${MK_SSP} != "no"
+TESTS_SUBDIRS+= ssp
+.endif
+
+.include <bsd.test.mk>
Property changes on: trunk/lib/libc/tests/Makefile
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/Makefile.netbsd-tests
===================================================================
--- trunk/lib/libc/tests/Makefile.netbsd-tests (rev 0)
+++ trunk/lib/libc/tests/Makefile.netbsd-tests 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,10 @@
+# $MidnightBSD$
+# $FreeBSD: stable/10/lib/libc/tests/Makefile.netbsd-tests 313488 2017-02-09 22:49:48Z ngie $
+
+TESTSRC:= ${SRCTOP}/contrib/netbsd-tests/${RELDIR:C/libc\/tests/libc/}
+
+TESTSDIR:= ${TESTSBASE}/${RELDIR:C/libc\/tests/libc/}
+
+WARNS?= 2
+
+.include <netbsd-tests.test.mk>
Property changes on: trunk/lib/libc/tests/Makefile.netbsd-tests
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/c063/Makefile
===================================================================
--- trunk/lib/libc/tests/c063/Makefile (rev 0)
+++ trunk/lib/libc/tests/c063/Makefile 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,26 @@
+# $MidnightBSD$
+# $FreeBSD: stable/10/lib/libc/tests/c063/Makefile 313488 2017-02-09 22:49:48Z ngie $
+
+#TODO: t_o_search
+
+NETBSD_ATF_TESTS_C= faccessat_test
+NETBSD_ATF_TESTS_C+= fchmodat_test
+NETBSD_ATF_TESTS_C+= fchownat_test
+NETBSD_ATF_TESTS_C+= fexecve_test
+NETBSD_ATF_TESTS_C+= fstatat_test
+NETBSD_ATF_TESTS_C+= linkat_test
+NETBSD_ATF_TESTS_C+= mkdirat_test
+NETBSD_ATF_TESTS_C+= mkfifoat_test
+NETBSD_ATF_TESTS_C+= mknodat_test
+NETBSD_ATF_TESTS_C+= openat_test
+NETBSD_ATF_TESTS_C+= readlinkat_test
+NETBSD_ATF_TESTS_C+= renameat_test
+NETBSD_ATF_TESTS_C+= symlinkat_test
+NETBSD_ATF_TESTS_C+= unlinkat_test
+NETBSD_ATF_TESTS_C+= utimensat
+
+CFLAGS+= -D_INCOMPLETE_XOPEN_C063
+
+.include "../Makefile.netbsd-tests"
+
+.include <bsd.test.mk>
Property changes on: trunk/lib/libc/tests/c063/Makefile
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/db/Makefile
===================================================================
--- trunk/lib/libc/tests/db/Makefile (rev 0)
+++ trunk/lib/libc/tests/db/Makefile 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,21 @@
+# $MidnightBSD$
+# $FreeBSD: stable/10/lib/libc/tests/db/Makefile 313535 2017-02-10 07:13:16Z ngie $
+
+BINDIR= ${TESTSDIR}
+
+PROGS= h_db
+PROGS+= h_lfsr
+
+FILESDIR= ${TESTSDIR}
+
+FILES+= README
+
+NETBSD_ATF_TESTS_C+= db_hash_seq_test
+NETBSD_ATF_TESTS_SH+= db_test
+ATF_TESTS_SH_SED_db_test= -e 's,/bin/csh,/bin/cat,g'
+
+CFLAGS+= -I${SRCTOP}/lib/libc/db/btree
+
+.include "../Makefile.netbsd-tests"
+
+.include <bsd.test.mk>
Property changes on: trunk/lib/libc/tests/db/Makefile
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/gen/Makefile
===================================================================
--- trunk/lib/libc/tests/gen/Makefile (rev 0)
+++ trunk/lib/libc/tests/gen/Makefile 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,97 @@
+# $MidnightBSD$
+# $FreeBSD: stable/10/lib/libc/tests/gen/Makefile 321878 2017-08-01 16:00:21Z asomers $
+
+.include <bsd.own.mk>
+
+ATF_TESTS_C+= arc4random_test
+ATF_TESTS_C+= fmtcheck2_test
+ATF_TESTS_C+= fmtmsg_test
+ATF_TESTS_C+= fnmatch2_test
+ATF_TESTS_C+= fpclassify2_test
+ATF_TESTS_C+= ftw_test
+ATF_TESTS_C+= popen_test
+ATF_TESTS_C+= posix_spawn_test
+ATF_TESTS_C+= wordexp_test
+ATF_TESTS_C+= realpath2_test
+
+# TODO: t_closefrom, t_cpuset, t_fmtcheck, t_randomid,
+# TODO: t_siginfo (fixes require further inspection)
+# TODO: t_sethostname_test (consistently screws up the hostname)
+
+CFLAGS+= -DTEST_LONG_DOUBLE
+
+# Not sure why this isn't defined for all architectures, since most
+# have long double.
+.if ${MACHINE_CPUARCH} == "aarch64" || \
+ ${MACHINE_CPUARCH} == "amd64" || \
+ ${MACHINE_CPUARCH} == "i386"
+CFLAGS+= -D__HAVE_LONG_DOUBLE
+.endif
+
+NETBSD_ATF_TESTS_C= alarm_test
+NETBSD_ATF_TESTS_C+= assert_test
+NETBSD_ATF_TESTS_C+= basedirname_test
+NETBSD_ATF_TESTS_C+= dir_test
+NETBSD_ATF_TESTS_C+= floatunditf_test
+NETBSD_ATF_TESTS_C+= fnmatch_test
+NETBSD_ATF_TESTS_C+= fpclassify_test
+NETBSD_ATF_TESTS_C+= fpsetmask_test
+NETBSD_ATF_TESTS_C+= fpsetround_test
+NETBSD_ATF_TESTS_C+= ftok_test
+NETBSD_ATF_TESTS_C+= getcwd_test
+NETBSD_ATF_TESTS_C+= getgrent_test
+NETBSD_ATF_TESTS_C+= glob_test
+NETBSD_ATF_TESTS_C+= humanize_number_test
+NETBSD_ATF_TESTS_C+= isnan_test
+NETBSD_ATF_TESTS_C+= nice_test
+NETBSD_ATF_TESTS_C+= pause_test
+NETBSD_ATF_TESTS_C+= raise_test
+NETBSD_ATF_TESTS_C+= realpath_test
+NETBSD_ATF_TESTS_C+= setdomainname_test
+NETBSD_ATF_TESTS_C+= sethostname_test
+NETBSD_ATF_TESTS_C+= sleep_test
+NETBSD_ATF_TESTS_C+= syslog_test
+NETBSD_ATF_TESTS_C+= time_test
+NETBSD_ATF_TESTS_C+= ttyname_test
+NETBSD_ATF_TESTS_C+= vis_test
+
+.include "../Makefile.netbsd-tests"
+
+LDADD.humanize_number_test+= -lutil
+DPADD.humanize_number_test+= ${LIBUTIL}
+
+LDADD.fpclassify_test+= -lm
+DPADD.fpclassify_test+= ${LIBM}
+LDADD.fpsetround_test+= -lm
+DPADD.fpsetround_test+= ${LIBM}
+LDADD.siginfo_test+= -lm
+DPADD.siginfo_test+= ${LIBM}
+
+LDADD.nice_test+= -lpthread
+DPADD.nice_test+= ${LIBPTHREAD}
+LDADD.syslog_test+= -lpthread
+DPADD.syslog_test+= ${LIBPTHREAD}
+
+CFLAGS+= -I${.CURDIR}
+
+SRCS.fmtcheck2_test= fmtcheck_test.c
+SRCS.fnmatch2_test= fnmatch_test.c
+
+TEST_METADATA.setdomainname_test+= is_exclusive=true
+TESTS_SUBDIRS= execve
+TESTS_SUBDIRS+= posix_spawn
+
+# The old testcase name
+TEST_FNMATCH= test-fnmatch
+CLEANFILES+= ${GEN_SH_CASE_TESTCASES}
+sh-tests: .PHONY
+.for target in clean obj depend all
+ @cd ${.CURDIR} && ${MAKE} PROG=${TEST_FNMATCH} \
+ -DNO_SUBDIR ${target}
+.endfor
+ @cd ${.OBJDIR} && ./${TEST_FNMATCH} -s 1 > \
+ ${SRCTOP}/bin/sh/tests/builtins/case2.0
+ @cd ${.OBJDIR} && ./${TEST_FNMATCH} -s 2 > \
+ ${SRCTOP}/bin/sh/tests/builtins/case3.0
+
+.include <bsd.test.mk>
Property changes on: trunk/lib/libc/tests/gen/Makefile
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/gen/arc4random_test.c
===================================================================
--- trunk/lib/libc/tests/gen/arc4random_test.c (rev 0)
+++ trunk/lib/libc/tests/gen/arc4random_test.c 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,90 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2011 David Schultz
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/lib/libc/tests/gen/arc4random_test.c 290881 2015-11-15 20:30:54Z ngie $");
+
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <sys/wait.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <atf-c.h>
+
+/*
+ * BUFSIZE is the number of bytes of rc4 output to compare. The probability
+ * that this test fails spuriously is 2**(-BUFSIZE * 8).
+ */
+#define BUFSIZE 8
+
+/*
+ * Test whether arc4random_buf() returns the same sequence of bytes in both
+ * parent and child processes. (Hint: It shouldn't.)
+ */
+ATF_TC_WITHOUT_HEAD(test_arc4random);
+ATF_TC_BODY(test_arc4random, tc)
+{
+ struct shared_page {
+ char parentbuf[BUFSIZE];
+ char childbuf[BUFSIZE];
+ } *page;
+ pid_t pid;
+ char c;
+
+ page = mmap(NULL, sizeof(struct shared_page), PROT_READ | PROT_WRITE,
+ MAP_ANON | MAP_SHARED, -1, 0);
+ ATF_REQUIRE_MSG(page != MAP_FAILED, "mmap failed; errno=%d", errno);
+
+ arc4random_buf(&c, 1);
+
+ pid = fork();
+ ATF_REQUIRE(0 <= pid);
+ if (pid == 0) {
+ /* child */
+ arc4random_buf(page->childbuf, BUFSIZE);
+ exit(0);
+ } else {
+ /* parent */
+ int status;
+ arc4random_buf(page->parentbuf, BUFSIZE);
+ wait(&status);
+ }
+ ATF_CHECK_MSG(memcmp(page->parentbuf, page->childbuf, BUFSIZE) != 0,
+ "sequences are the same");
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, test_arc4random);
+
+ return (atf_no_error());
+}
Property changes on: trunk/lib/libc/tests/gen/arc4random_test.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/gen/execve/Makefile
===================================================================
--- trunk/lib/libc/tests/gen/execve/Makefile (rev 0)
+++ trunk/lib/libc/tests/gen/execve/Makefile 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,10 @@
+# $MidnightBSD$
+# $FreeBSD: stable/10/lib/libc/tests/gen/execve/Makefile 313488 2017-02-09 22:49:48Z ngie $
+
+.include <bsd.own.mk>
+
+NETBSD_ATF_TESTS_C= execve_test
+
+.include "../../Makefile.netbsd-tests"
+
+.include <bsd.test.mk>
Property changes on: trunk/lib/libc/tests/gen/execve/Makefile
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/gen/fmtcheck_test.c
===================================================================
--- trunk/lib/libc/tests/gen/fmtcheck_test.c (rev 0)
+++ trunk/lib/libc/tests/gen/fmtcheck_test.c 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,106 @@
+/* $MidnightBSD$ */
+/* $NetBSD: tfmtcheck.c,v 1.3 2008/04/28 20:23:04 martin Exp $ */
+
+/*-
+ * Copyright (c) 2000 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code was contributed to The NetBSD Foundation by Allen Briggs.
+ *
+ * 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>
+__FBSDID("$FreeBSD: stable/10/lib/libc/tests/gen/fmtcheck_test.c 291190 2015-11-23 10:53:01Z ngie $");
+
+#include <sys/param.h>
+#include <err.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <atf-c.h>
+
+struct test_fmt {
+ char *fmt1;
+ char *fmt2;
+ int correct;
+} test_fmts[] = {
+ { "%d", "%d", 1 },
+ { "%2d", "%2.2d", 1 },
+ { "%x", "%d", 1 },
+ { "%u", "%d", 1 },
+ { "%03d", "%d", 1 },
+ { "%-2d", "%d", 1 },
+ { "%d", "%-12.1d", 1 },
+ { "%d", "%-01.3d", 1 },
+ { "%X", "%-01.3d", 1 },
+ { "%D", "%ld", 1 },
+ { "%s", "%s", 1 },
+ { "%s", "This is a %s test", 1 },
+ { "Hi, there. This is a %s test", "%s", 1 },
+ { "%d", "%s", 2 },
+ { "%e", "%s", 2 },
+ { "%r", "%d", 2 },
+ { "%*.2d", "%*d", 1 },
+ { "%2.*d", "%*d", 2 },
+ { "%*d", "%*d", 1 },
+ { "%-3", "%d", 2 },
+ { "%d %s", "%d", 2 },
+ { "%*.*.*d", "%*.*.*d", 2 },
+ { "%d", "%d %s", 1 },
+ { "%40s", "%20s", 1 },
+ { "%x %x %x", "%o %u %d", 1 },
+ { "%o %u %d", "%x %x %X", 1 },
+ { "%#o %u %#-d", "%x %#x %X", 1 },
+ { "%qd", "%llx", 1 },
+ { "%%", "%llx", 1 },
+ { "%p %30s %#llx %-10.*e", "This number %lu%% and string %s has %qd numbers and %.*g floats", 1 },
+};
+
+ATF_TC_WITHOUT_HEAD(fmtcheck_test);
+ATF_TC_BODY(fmtcheck_test, tc)
+{
+ int i;
+ const char *f, *cf, *f1, *f2;
+
+ for (i = 0; i < nitems(test_fmts); i++) {
+ f1 = test_fmts[i].fmt1;
+ f2 = test_fmts[i].fmt2;
+ f = fmtcheck(f1, f2);
+ if (test_fmts[i].correct == 1)
+ cf = f1;
+ else
+ cf = f2;
+ ATF_CHECK_MSG(f == cf,
+ "Test %d: (%s) vs. (%s) failed "
+ "(should have returned %s)", i + 1, f1, f2,
+ (test_fmts[i].correct == 1) ? "1st" : "2nd");
+ }
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, fmtcheck_test);
+
+ return (atf_no_error());
+}
Property changes on: trunk/lib/libc/tests/gen/fmtcheck_test.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/gen/fmtmsg_test.c
===================================================================
--- trunk/lib/libc/tests/gen/fmtmsg_test.c (rev 0)
+++ trunk/lib/libc/tests/gen/fmtmsg_test.c 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,253 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2012 Jilles Tjoelker
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/lib/libc/tests/gen/fmtmsg_test.c 291190 2015-11-23 10:53:01Z ngie $");
+
+#include <sys/param.h>
+#include <sys/wait.h>
+#include <err.h>
+#include <errno.h>
+#include <fmtmsg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <atf-c.h>
+
+static char *run_test(long classification, const char *label, int severity,
+ const char *text, const char *action, const char *tag);
+
+struct testcase {
+ long classification;
+ const char *label;
+ int severity;
+ const char *text;
+ const char *action;
+ const char *tag;
+ const char *msgverb;
+ const char *result;
+} testcases[] = {
+ {
+ MM_UTIL | MM_PRINT, "BSD:ls", MM_ERROR,
+ "illegal option -- z", "refer to manual", "BSD:ls:001",
+ NULL,
+ "BSD:ls: ERROR: illegal option -- z\n"
+ "TO FIX: refer to manual BSD:ls:001\n"
+ },
+ {
+ MM_UTIL | MM_PRINT, "BSD:ls", MM_ERROR,
+ "illegal option -- z", "refer to manual", "BSD:ls:001",
+ "text:severity:action:tag",
+ "illegal option -- z: ERROR\n"
+ "TO FIX: refer to manual BSD:ls:001\n"
+ },
+ {
+ MM_UTIL | MM_PRINT, "BSD:ls", MM_ERROR,
+ "illegal option -- z", "refer to manual", "BSD:ls:001",
+ "text",
+ "illegal option -- z\n"
+ },
+ {
+ MM_UTIL | MM_PRINT, "BSD:ls", MM_ERROR,
+ "illegal option -- z", "refer to manual", "BSD:ls:001",
+ "severity:text",
+ "ERROR: illegal option -- z\n"
+ },
+ {
+ MM_UTIL | MM_PRINT, "BSD:ls", MM_ERROR,
+ "illegal option -- z", "refer to manual", "BSD:ls:001",
+ "ignore me",
+ "BSD:ls: ERROR: illegal option -- z\n"
+ "TO FIX: refer to manual BSD:ls:001\n"
+ },
+ {
+ MM_UTIL | MM_PRINT, "BSD:ls", MM_ERROR,
+ "illegal option -- z", "refer to manual", "BSD:ls:001",
+ "tag:severity:text:nothing:action",
+ "BSD:ls: ERROR: illegal option -- z\n"
+ "TO FIX: refer to manual BSD:ls:001\n"
+ },
+ {
+ MM_UTIL | MM_PRINT, "BSD:ls", MM_ERROR,
+ "illegal option -- z", "refer to manual", "BSD:ls:001",
+ "",
+ "BSD:ls: ERROR: illegal option -- z\n"
+ "TO FIX: refer to manual BSD:ls:001\n"
+ },
+ {
+ MM_UTIL | MM_PRINT, MM_NULLLBL, MM_ERROR,
+ "illegal option -- z", "refer to manual", "BSD:ls:001",
+ NULL,
+ "ERROR: illegal option -- z\n"
+ "TO FIX: refer to manual BSD:ls:001\n"
+ },
+ {
+ MM_UTIL | MM_PRINT, "BSD:ls", MM_ERROR,
+ "illegal option -- z", MM_NULLACT, MM_NULLTAG,
+ NULL,
+ "BSD:ls: ERROR: illegal option -- z\n"
+ },
+ {
+ MM_UTIL | MM_NULLMC, "BSD:ls", MM_ERROR,
+ "illegal option -- z", "refer to manual", "BSD:ls:001",
+ NULL,
+ ""
+ },
+ {
+ MM_APPL | MM_PRINT, "ABCDEFGHIJ:abcdefghijklmn", MM_INFO,
+ "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
+ "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
+ "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
+ "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
+ "refer to manual", "ABCDEFGHIJ:abcdefghijklmn:001",
+ NULL,
+ "ABCDEFGHIJ:abcdefghijklmn: INFO: "
+ "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
+ "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
+ "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
+ "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n"
+ "TO FIX: refer to manual ABCDEFGHIJ:abcdefghijklmn:001\n"
+ },
+ {
+ MM_OPSYS | MM_PRINT, "TEST:test", MM_HALT,
+ "failed", "nothing can help me", "NOTHING",
+ NULL,
+ "TEST:test: HALT: failed\n"
+ "TO FIX: nothing can help me NOTHING\n"
+ },
+ {
+ MM_OPSYS | MM_PRINT, "TEST:test", MM_WARNING,
+ "failed", "nothing can help me", "NOTHING",
+ NULL,
+ "TEST:test: WARNING: failed\n"
+ "TO FIX: nothing can help me NOTHING\n"
+ },
+ {
+ MM_OPSYS | MM_PRINT, "TEST:test", MM_NOSEV,
+ "failed", "nothing can help me", "NOTHING",
+ NULL,
+ "TEST:test: failed\n"
+ "TO FIX: nothing can help me NOTHING\n"
+ }
+};
+
+static char *
+run_test(long classification, const char *label, int severity,
+ const char *text, const char *action, const char *tag)
+{
+ int pip[2];
+ pid_t pid, wpid;
+ char *result, *p;
+ size_t resultsize;
+ ssize_t n;
+ int status;
+
+ if (pipe(pip) == -1)
+ err(2, "pipe");
+ pid = fork();
+ if (pid == -1)
+ err(2, "fork");
+ if (pid == 0) {
+ close(pip[0]);
+ if (pip[1] != STDERR_FILENO &&
+ dup2(pip[1], STDERR_FILENO) == -1)
+ _exit(2);
+ if (fmtmsg(classification, label, severity, text, action, tag)
+ != MM_OK)
+ _exit(1);
+ else
+ _exit(0);
+ }
+ close(pip[1]);
+ resultsize = 1024;
+ result = malloc(resultsize);
+ p = result;
+ while ((n = read(pip[0], p, result + resultsize - p - 1)) != 0) {
+ if (n == -1) {
+ if (errno == EINTR)
+ continue;
+ else
+ err(2, "read");
+ }
+ p += n;
+ if (result + resultsize == p - 1) {
+ resultsize *= 2;
+ result = realloc(result, resultsize);
+ if (result == NULL)
+ err(2, "realloc");
+ }
+ }
+ if (memchr(result, '\0', p - result) != NULL) {
+ free(result);
+ return (NULL);
+ }
+ *p = '\0';
+ close(pip[0]);
+ while ((wpid = waitpid(pid, &status, 0)) == -1 && errno == EINTR)
+ ;
+ if (wpid == -1)
+ err(2, "waitpid");
+ if (status != 0) {
+ free(result);
+ return (NULL);
+ }
+ return (result);
+}
+
+ATF_TC_WITHOUT_HEAD(fmtmsg_test);
+ATF_TC_BODY(fmtmsg_test, tc)
+{
+ char *result;
+ struct testcase *t;
+ int i;
+
+ for (i = 0; i < nitems(testcases); i++) {
+ t = &testcases[i];
+ if (t->msgverb != NULL)
+ setenv("MSGVERB", t->msgverb, 1);
+ else
+ unsetenv("MSGVERB");
+ result = run_test(t->classification, t->label, t->severity,
+ t->text, t->action, t->tag);
+ ATF_CHECK_MSG(result != NULL, "testcase %d failed", i + 1);
+ if (result != NULL)
+ ATF_CHECK_MSG(strcmp(result, t->result) == 0,
+ "results for testcase %d didn't match; "
+ "`%s` != `%s`", i + 1, result, t->result);
+ free(result);
+ }
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, fmtmsg_test);
+
+ return (atf_no_error());
+}
Property changes on: trunk/lib/libc/tests/gen/fmtmsg_test.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/gen/fnmatch_test.c
===================================================================
--- trunk/lib/libc/tests/gen/fnmatch_test.c (rev 0)
+++ trunk/lib/libc/tests/gen/fnmatch_test.c 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,189 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2010 Jilles Tjoelker
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/lib/libc/tests/gen/fnmatch_test.c 291190 2015-11-23 10:53:01Z ngie $");
+
+#include <sys/param.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <atf-c.h>
+
+#include "fnmatch_testcases.h"
+
+static const char *
+flags_to_string(int flags)
+{
+ static const int flagvalues[] = { FNM_NOESCAPE, FNM_PATHNAME,
+ FNM_PERIOD, FNM_LEADING_DIR, FNM_CASEFOLD, 0 };
+ static const char flagnames[] = "FNM_NOESCAPE\0FNM_PATHNAME\0FNM_PERIOD\0FNM_LEADING_DIR\0FNM_CASEFOLD\0";
+ static char result[sizeof(flagnames) + 3 * sizeof(int) + 2];
+ char *p;
+ size_t i, len;
+ const char *fp;
+
+ p = result;
+ fp = flagnames;
+ for (i = 0; flagvalues[i] != 0; i++) {
+ len = strlen(fp);
+ if (flags & flagvalues[i]) {
+ if (p != result)
+ *p++ = '|';
+ memcpy(p, fp, len);
+ p += len;
+ flags &= ~flagvalues[i];
+ }
+ fp += len + 1;
+ }
+ if (p == result)
+ memcpy(p, "0", 2);
+ else if (flags != 0)
+ sprintf(p, "%d", flags);
+ else
+ *p = '\0';
+ return result;
+}
+
+ATF_TC_WITHOUT_HEAD(fnmatch_test);
+ATF_TC_BODY(fnmatch_test, tc)
+{
+ size_t i;
+ int flags, result;
+ struct testcase *t;
+
+ for (i = 0; i < nitems(testcases); i++) {
+ t = &testcases[i];
+ flags = t->flags;
+ do {
+ result = fnmatch(t->pattern, t->string, flags);
+ if (result != t->result)
+ break;
+ if (strchr(t->pattern, '\\') == NULL &&
+ !(flags & FNM_NOESCAPE)) {
+ flags |= FNM_NOESCAPE;
+ result = fnmatch(t->pattern, t->string, flags);
+ if (result != t->result)
+ break;
+ flags = t->flags;
+ }
+ if (strchr(t->pattern, '\\') != NULL &&
+ strchr(t->string, '\\') == NULL &&
+ t->result == FNM_NOMATCH &&
+ !(flags & (FNM_NOESCAPE | FNM_LEADING_DIR))) {
+ flags |= FNM_NOESCAPE;
+ result = fnmatch(t->pattern, t->string, flags);
+ if (result != t->result)
+ break;
+ flags = t->flags;
+ }
+ if ((t->string[0] != '.' || t->pattern[0] == '.' ||
+ t->result == FNM_NOMATCH) &&
+ !(flags & (FNM_PATHNAME | FNM_PERIOD))) {
+ flags |= FNM_PERIOD;
+ result = fnmatch(t->pattern, t->string, flags);
+ if (result != t->result)
+ break;
+ flags = t->flags;
+ }
+ if ((strchr(t->string, '/') == NULL ||
+ t->result == FNM_NOMATCH) &&
+ !(flags & FNM_PATHNAME)) {
+ flags |= FNM_PATHNAME;
+ result = fnmatch(t->pattern, t->string, flags);
+ if (result != t->result)
+ break;
+ flags = t->flags;
+ }
+ if ((((t->string[0] != '.' || t->pattern[0] == '.') &&
+ strstr(t->string, "/.") == NULL) ||
+ t->result == FNM_NOMATCH) &&
+ flags & FNM_PATHNAME && !(flags & FNM_PERIOD)) {
+ flags |= FNM_PERIOD;
+ result = fnmatch(t->pattern, t->string, flags);
+ if (result != t->result)
+ break;
+ flags = t->flags;
+ }
+ if ((((t->string[0] != '.' || t->pattern[0] == '.') &&
+ strchr(t->string, '/') == NULL) ||
+ t->result == FNM_NOMATCH) &&
+ !(flags & (FNM_PATHNAME | FNM_PERIOD))) {
+ flags |= FNM_PATHNAME | FNM_PERIOD;
+ result = fnmatch(t->pattern, t->string, flags);
+ if (result != t->result)
+ break;
+ flags = t->flags;
+ }
+ if ((strchr(t->string, '/') == NULL || t->result == 0)
+ && !(flags & FNM_LEADING_DIR)) {
+ flags |= FNM_LEADING_DIR;
+ result = fnmatch(t->pattern, t->string, flags);
+ if (result != t->result)
+ break;
+ flags = t->flags;
+ }
+ if (t->result == 0 && !(flags & FNM_CASEFOLD)) {
+ flags |= FNM_CASEFOLD;
+ result = fnmatch(t->pattern, t->string, flags);
+ if (result != t->result)
+ break;
+ flags = t->flags;
+ }
+ if (strchr(t->pattern, '\\') == NULL &&
+ t->result == 0 &&
+ !(flags & (FNM_NOESCAPE | FNM_CASEFOLD))) {
+ flags |= FNM_NOESCAPE | FNM_CASEFOLD;
+ result = fnmatch(t->pattern, t->string, flags);
+ if (result != t->result)
+ break;
+ flags = t->flags;
+ }
+ } while (0);
+
+ ATF_CHECK(result == t->result);
+ if (result == t->result)
+ printf("fnmatch(\"%s\", \"%s\", %s) == %d\n",
+ t->pattern, t->string, flags_to_string(flags), result);
+ else
+ printf("fnmatch(\"%s\", \"%s\", %s) != %d (was %d)\n",
+ t->pattern, t->string, flags_to_string(flags),
+ t->result, result);
+ }
+
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, fnmatch_test);
+
+ return (atf_no_error());
+}
Property changes on: trunk/lib/libc/tests/gen/fnmatch_test.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/gen/fnmatch_testcases.h
===================================================================
--- trunk/lib/libc/tests/gen/fnmatch_testcases.h (rev 0)
+++ trunk/lib/libc/tests/gen/fnmatch_testcases.h 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,177 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2010 Jilles Tjoelker
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/lib/libc/tests/gen/fnmatch_testcases.h 324505 2017-10-10 21:04:40Z pfg $");
+
+#include <fnmatch.h>
+
+struct testcase {
+ const char *pattern;
+ const char *string;
+ int flags;
+ int result;
+} testcases[] = {
+ { "", "", 0, 0 },
+ { "a", "a", 0, 0 },
+ { "a", "b", 0, FNM_NOMATCH },
+ { "a", "A", 0, FNM_NOMATCH },
+ { "*", "a", 0, 0 },
+ { "*", "aa", 0, 0 },
+ { "*a", "a", 0, 0 },
+ { "*a", "b", 0, FNM_NOMATCH },
+ { "*a*", "b", 0, FNM_NOMATCH },
+ { "*a*b*", "ab", 0, 0 },
+ { "*a*b*", "qaqbq", 0, 0 },
+ { "*a*bb*", "qaqbqbbq", 0, 0 },
+ { "*a*bc*", "qaqbqbcq", 0, 0 },
+ { "*a*bb*", "qaqbqbb", 0, 0 },
+ { "*a*bc*", "qaqbqbc", 0, 0 },
+ { "*a*bb", "qaqbqbb", 0, 0 },
+ { "*a*bc", "qaqbqbc", 0, 0 },
+ { "*a*bb", "qaqbqbbq", 0, FNM_NOMATCH },
+ { "*a*bc", "qaqbqbcq", 0, FNM_NOMATCH },
+ { "*a*a*a*a*a*a*a*a*a*a*", "aaaaaaaaa", 0, FNM_NOMATCH },
+ { "*a*a*a*a*a*a*a*a*a*a*", "aaaaaaaaaa", 0, 0 },
+ { "*a*a*a*a*a*a*a*a*a*a*", "aaaaaaaaaaa", 0, 0 },
+ { ".*.*.*.*.*.*.*.*.*.*", ".........", 0, FNM_NOMATCH },
+ { ".*.*.*.*.*.*.*.*.*.*", "..........", 0, 0 },
+ { ".*.*.*.*.*.*.*.*.*.*", "...........", 0, 0 },
+ { "*?*?*?*?*?*?*?*?*?*?*", "123456789", 0, FNM_NOMATCH },
+ { "??????????*", "123456789", 0, FNM_NOMATCH },
+ { "*??????????", "123456789", 0, FNM_NOMATCH },
+ { "*?*?*?*?*?*?*?*?*?*?*", "1234567890", 0, 0 },
+ { "??????????*", "1234567890", 0, 0 },
+ { "*??????????", "1234567890", 0, 0 },
+ { "*?*?*?*?*?*?*?*?*?*?*", "12345678901", 0, 0 },
+ { "??????????*", "12345678901", 0, 0 },
+ { "*??????????", "12345678901", 0, 0 },
+ { "[x]", "x", 0, 0 },
+ { "[*]", "*", 0, 0 },
+ { "[?]", "?", 0, 0 },
+ { "[", "[", 0, 0 },
+ { "[[]", "[", 0, 0 },
+ { "[[]", "x", 0, FNM_NOMATCH },
+ { "[*]", "", 0, FNM_NOMATCH },
+ { "[*]", "x", 0, FNM_NOMATCH },
+ { "[?]", "x", 0, FNM_NOMATCH },
+ { "*[*]*", "foo*foo", 0, 0 },
+ { "*[*]*", "foo", 0, FNM_NOMATCH },
+ { "[0-9]", "0", 0, 0 },
+ { "[0-9]", "5", 0, 0 },
+ { "[0-9]", "9", 0, 0 },
+ { "[0-9]", "/", 0, FNM_NOMATCH },
+ { "[0-9]", ":", 0, FNM_NOMATCH },
+ { "[0-9]", "*", 0, FNM_NOMATCH },
+ { "[!0-9]", "0", 0, FNM_NOMATCH },
+ { "[!0-9]", "5", 0, FNM_NOMATCH },
+ { "[!0-9]", "9", 0, FNM_NOMATCH },
+ { "[!0-9]", "/", 0, 0 },
+ { "[!0-9]", ":", 0, 0 },
+ { "[!0-9]", "*", 0, 0 },
+ { "*[0-9]", "a0", 0, 0 },
+ { "*[0-9]", "a5", 0, 0 },
+ { "*[0-9]", "a9", 0, 0 },
+ { "*[0-9]", "a/", 0, FNM_NOMATCH },
+ { "*[0-9]", "a:", 0, FNM_NOMATCH },
+ { "*[0-9]", "a*", 0, FNM_NOMATCH },
+ { "*[!0-9]", "a0", 0, FNM_NOMATCH },
+ { "*[!0-9]", "a5", 0, FNM_NOMATCH },
+ { "*[!0-9]", "a9", 0, FNM_NOMATCH },
+ { "*[!0-9]", "a/", 0, 0 },
+ { "*[!0-9]", "a:", 0, 0 },
+ { "*[!0-9]", "a*", 0, 0 },
+ { "*[0-9]", "a00", 0, 0 },
+ { "*[0-9]", "a55", 0, 0 },
+ { "*[0-9]", "a99", 0, 0 },
+ { "*[0-9]", "a0a0", 0, 0 },
+ { "*[0-9]", "a5a5", 0, 0 },
+ { "*[0-9]", "a9a9", 0, 0 },
+ { "\\*", "*", 0, 0 },
+ { "\\?", "?", 0, 0 },
+ { "\\[x]", "[x]", 0, 0 },
+ { "\\[", "[", 0, 0 },
+ { "\\\\", "\\", 0, 0 },
+ { "*\\**", "foo*foo", 0, 0 },
+ { "*\\**", "foo", 0, FNM_NOMATCH },
+ { "*\\\\*", "foo\\foo", 0, 0 },
+ { "*\\\\*", "foo", 0, FNM_NOMATCH },
+ { "\\(", "(", 0, 0 },
+ { "\\a", "a", 0, 0 },
+ { "\\*", "a", 0, FNM_NOMATCH },
+ { "\\?", "a", 0, FNM_NOMATCH },
+ { "\\*", "\\*", 0, FNM_NOMATCH },
+ { "\\?", "\\?", 0, FNM_NOMATCH },
+ { "\\[x]", "\\[x]", 0, FNM_NOMATCH },
+ { "\\[x]", "\\x", 0, FNM_NOMATCH },
+ { "\\[", "\\[", 0, FNM_NOMATCH },
+ { "\\(", "\\(", 0, FNM_NOMATCH },
+ { "\\a", "\\a", 0, FNM_NOMATCH },
+ { "\\", "\\", 0, FNM_NOMATCH },
+ { "\\", "", 0, FNM_NOMATCH },
+ { "\\*", "\\*", FNM_NOESCAPE, 0 },
+ { "\\?", "\\?", FNM_NOESCAPE, 0 },
+ { "\\", "\\", FNM_NOESCAPE, 0 },
+ { "\\\\", "\\", FNM_NOESCAPE, FNM_NOMATCH },
+ { "\\\\", "\\\\", FNM_NOESCAPE, 0 },
+ { "*\\*", "foo\\foo", FNM_NOESCAPE, 0 },
+ { "*\\*", "foo", FNM_NOESCAPE, FNM_NOMATCH },
+ { "*", ".", FNM_PERIOD, FNM_NOMATCH },
+ { "?", ".", FNM_PERIOD, FNM_NOMATCH },
+ { ".*", ".", 0, 0 },
+ { ".*", "..", 0, 0 },
+ { ".*", ".a", 0, 0 },
+ { "[0-9]", ".", FNM_PERIOD, FNM_NOMATCH },
+ { "a*", "a.", 0, 0 },
+ { "a/a", "a/a", FNM_PATHNAME, 0 },
+ { "a/*", "a/a", FNM_PATHNAME, 0 },
+ { "*/a", "a/a", FNM_PATHNAME, 0 },
+ { "*/*", "a/a", FNM_PATHNAME, 0 },
+ { "a*b/*", "abbb/x", FNM_PATHNAME, 0 },
+ { "a*b/*", "abbb/.x", FNM_PATHNAME, 0 },
+ { "*", "a/a", FNM_PATHNAME, FNM_NOMATCH },
+ { "*/*", "a/a/a", FNM_PATHNAME, FNM_NOMATCH },
+ { "b/*", "b/.x", FNM_PATHNAME | FNM_PERIOD, FNM_NOMATCH },
+ { "b*/*", "a/.x", FNM_PATHNAME | FNM_PERIOD, FNM_NOMATCH },
+ { "b/.*", "b/.x", FNM_PATHNAME | FNM_PERIOD, 0 },
+ { "b*/.*", "b/.x", FNM_PATHNAME | FNM_PERIOD, 0 },
+ { "a", "A", FNM_CASEFOLD, 0 },
+ { "A", "a", FNM_CASEFOLD, 0 },
+ { "[a]", "A", FNM_CASEFOLD, 0 },
+ { "[A]", "a", FNM_CASEFOLD, 0 },
+ { "a", "b", FNM_CASEFOLD, FNM_NOMATCH },
+ { "a", "a/b", FNM_PATHNAME, FNM_NOMATCH },
+ { "*", "a/b", FNM_PATHNAME, FNM_NOMATCH },
+ { "*b", "a/b", FNM_PATHNAME, FNM_NOMATCH },
+ { "a", "a/b", FNM_PATHNAME | FNM_LEADING_DIR, 0 },
+ { "*", "a/b", FNM_PATHNAME | FNM_LEADING_DIR, 0 },
+ { "*", ".a/b", FNM_PATHNAME | FNM_LEADING_DIR, 0 },
+ { "*a", ".a/b", FNM_PATHNAME | FNM_LEADING_DIR, 0 },
+ { "*", ".a/b", FNM_PATHNAME | FNM_PERIOD | FNM_LEADING_DIR, FNM_NOMATCH },
+ { "*a", ".a/b", FNM_PATHNAME | FNM_PERIOD | FNM_LEADING_DIR, FNM_NOMATCH },
+ { "a*b/*", "abbb/.x", FNM_PATHNAME | FNM_PERIOD, FNM_NOMATCH },
+};
Property changes on: trunk/lib/libc/tests/gen/fnmatch_testcases.h
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/gen/fpclassify2_test.c
===================================================================
--- trunk/lib/libc/tests/gen/fpclassify2_test.c (rev 0)
+++ trunk/lib/libc/tests/gen/fpclassify2_test.c 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,73 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2003 Mike Barcroft <mike at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: stable/10/lib/libc/tests/gen/fpclassify2_test.c 277441 2015-01-20 21:42:40Z ngie $
+ */
+
+#include <math.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <atf-c.h>
+
+ATF_TC_WITHOUT_HEAD(test_fpclassify);
+ATF_TC_BODY(test_fpclassify, tc)
+{
+
+ ATF_CHECK(fpclassify((float)0) == FP_ZERO);
+ ATF_CHECK(fpclassify((float)-0.0) == FP_ZERO);
+ ATF_CHECK(fpclassify((float)1) == FP_NORMAL);
+ ATF_CHECK(fpclassify((float)1000) == FP_NORMAL);
+ ATF_CHECK(fpclassify(HUGE_VALF) == FP_INFINITE);
+ ATF_CHECK(fpclassify((float)HUGE_VAL) == FP_INFINITE);
+ ATF_CHECK(fpclassify((float)HUGE_VALL) == FP_INFINITE);
+ ATF_CHECK(fpclassify(NAN) == FP_NAN);
+
+ ATF_CHECK(fpclassify((double)0) == FP_ZERO);
+ ATF_CHECK(fpclassify((double)-0) == FP_ZERO);
+ ATF_CHECK(fpclassify((double)1) == FP_NORMAL);
+ ATF_CHECK(fpclassify((double)1000) == FP_NORMAL);
+ ATF_CHECK(fpclassify(HUGE_VAL) == FP_INFINITE);
+ ATF_CHECK(fpclassify((double)HUGE_VALF) == FP_INFINITE);
+ ATF_CHECK(fpclassify((double)HUGE_VALL) == FP_INFINITE);
+ ATF_CHECK(fpclassify((double)NAN) == FP_NAN);
+
+ ATF_CHECK(fpclassify((long double)0) == FP_ZERO);
+ ATF_CHECK(fpclassify((long double)-0.0) == FP_ZERO);
+ ATF_CHECK(fpclassify((long double)1) == FP_NORMAL);
+ ATF_CHECK(fpclassify((long double)1000) == FP_NORMAL);
+ ATF_CHECK(fpclassify(HUGE_VALL) == FP_INFINITE);
+ ATF_CHECK(fpclassify((long double)HUGE_VALF) == FP_INFINITE);
+ ATF_CHECK(fpclassify((long double)HUGE_VAL) == FP_INFINITE);
+ ATF_CHECK(fpclassify((long double)NAN) == FP_NAN);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, test_fpclassify);
+
+ return (atf_no_error());
+}
Property changes on: trunk/lib/libc/tests/gen/fpclassify2_test.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/gen/ftw_test.c
===================================================================
--- trunk/lib/libc/tests/gen/ftw_test.c (rev 0)
+++ trunk/lib/libc/tests/gen/ftw_test.c 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,128 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2012 Jilles Tjoelker
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Limited test program for nftw() as specified by IEEE Std. 1003.1-2008.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/lib/libc/tests/gen/ftw_test.c 291190 2015-11-23 10:53:01Z ngie $");
+
+#include <sys/wait.h>
+#include <err.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <ftw.h>
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <spawn.h>
+#include <unistd.h>
+
+#include <atf-c.h>
+
+extern char **environ;
+
+static char template[] = "testftw.XXXXXXXXXX";
+static char dir[PATH_MAX];
+static int ftwflags;
+
+static int
+cb(const char *path, const struct stat *st, int type, struct FTW *f)
+{
+
+ switch (type) {
+ case FTW_D:
+ if ((ftwflags & FTW_DEPTH) == 0)
+ return (0);
+ break;
+ case FTW_DP:
+ if ((ftwflags & FTW_DEPTH) != 0)
+ return (0);
+ break;
+ case FTW_SL:
+ if ((ftwflags & FTW_PHYS) != 0)
+ return (0);
+ break;
+ }
+ ATF_CHECK_MSG(false,
+ "unexpected path=%s type=%d f.level=%d\n",
+ path, type, f->level);
+ return (0);
+}
+
+ATF_TC_WITHOUT_HEAD(ftw_test);
+ATF_TC_BODY(ftw_test, tc)
+{
+ int fd;
+
+ ATF_REQUIRE_MSG(mkdtemp(template) != NULL, "mkdtemp failed");
+
+ /* XXX: the path needs to be absolute for the 0/FTW_DEPTH testcases */
+ ATF_REQUIRE_MSG(realpath(template, dir) != NULL,
+ "realpath failed; errno=%d", errno);
+
+ fd = open(dir, O_DIRECTORY|O_RDONLY);
+ ATF_REQUIRE_MSG(fd != -1, "open failed; errno=%d", errno);
+
+ ATF_REQUIRE_MSG(mkdirat(fd, "d1", 0777) == 0,
+ "mkdirat failed; errno=%d", errno);
+
+ ATF_REQUIRE_MSG(symlinkat(dir, fd, "d1/looper") == 0,
+ "symlinkat failed; errno=%d", errno);
+
+ printf("ftwflags=FTW_PHYS\n");
+ ftwflags = FTW_PHYS;
+ ATF_REQUIRE_MSG(nftw(dir, cb, 10, ftwflags) != -1,
+ "nftw FTW_PHYS failed; errno=%d", errno);
+
+ printf("ftwflags=FTW_PHYS|FTW_DEPTH\n");
+ ftwflags = FTW_PHYS|FTW_DEPTH;
+ ATF_REQUIRE_MSG(nftw(dir, cb, 10, ftwflags) != -1,
+ "nftw FTW_PHYS|FTW_DEPTH failed; errno=%d", errno);
+
+ printf("ftwflags=0\n");
+ ftwflags = 0;
+ ATF_REQUIRE_MSG(nftw(dir, cb, 10, ftwflags) != -1,
+ "nftw 0 failed; errno=%d", errno);
+
+ printf("ftwflags=FTW_DEPTH\n");
+ ftwflags = FTW_DEPTH;
+ ATF_REQUIRE_MSG(nftw(dir, cb, 10, ftwflags) != -1,
+ "nftw FTW_DEPTH failed; errno=%d", errno);
+
+ close(fd);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, ftw_test);
+
+ return (atf_no_error());
+}
Property changes on: trunk/lib/libc/tests/gen/ftw_test.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/gen/popen_test.c
===================================================================
--- trunk/lib/libc/tests/gen/popen_test.c (rev 0)
+++ trunk/lib/libc/tests/gen/popen_test.c 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,252 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2013 Jilles Tjoelker
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Limited test program for popen() as specified by IEEE Std. 1003.1-2008,
+ * with BSD extensions.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/lib/libc/tests/gen/popen_test.c 291190 2015-11-23 10:53:01Z ngie $");
+
+#include <sys/param.h>
+#include <sys/wait.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <atf-c.h>
+
+static volatile sig_atomic_t got_sigpipe;
+
+static void
+sigpipe_handler(int sig __unused)
+{
+ got_sigpipe = 1;
+}
+
+static void
+check_cloexec(FILE *fp, const char *mode)
+{
+ int exp_flags, flags;
+
+ flags = fcntl(fileno(fp), F_GETFD);
+ ATF_CHECK_MSG(flags != -1, "fcntl(F_GETFD) failed; errno=%d", errno);
+ if (flags == -1)
+ return;
+ if (strchr(mode, 'e') != NULL)
+ exp_flags = FD_CLOEXEC;
+ else
+ exp_flags = 0;
+ ATF_CHECK_MSG((flags & FD_CLOEXEC) == exp_flags,
+ "bad cloexec flag; %d != %d", flags, exp_flags);
+}
+
+ATF_TC_WITHOUT_HEAD(popen_all_modes_test);
+ATF_TC_BODY(popen_all_modes_test, tc)
+{
+ FILE *fp;
+ int i, status;
+ const char *mode;
+ const char *allmodes[] = { "r", "w", "r+", "re", "we", "r+e", "re+" };
+
+ for (i = 0; i < nitems(allmodes); i++) {
+ mode = allmodes[i];
+ fp = popen("exit 7", mode);
+ ATF_CHECK_MSG(fp != NULL, "popen(, \"%s\") failed", mode);
+ if (fp == NULL)
+ continue;
+ check_cloexec(fp, mode);
+ status = pclose(fp);
+ ATF_CHECK_MSG(WIFEXITED(status) && WEXITSTATUS(status) == 7,
+ "bad exit status (no I/O)");
+ }
+}
+
+ATF_TC_WITHOUT_HEAD(popen_rmodes_test);
+ATF_TC_BODY(popen_rmodes_test, tc)
+{
+ FILE *fp;
+ const char *rmodes[] = { "r", "r+", "re", "r+e", "re+" };
+ const char *mode;
+ char buf[80];
+ int i, status;
+
+ for (i = 0; i < nitems(rmodes); i++) {
+ mode = rmodes[i];
+ fp = popen("exit 9", mode);
+ ATF_CHECK_MSG(fp != NULL, "popen(, \"%s\") failed", mode);
+ if (fp == NULL)
+ continue;
+ check_cloexec(fp, mode);
+ bool input_error_1 = !(fgetc(fp) != EOF || !feof(fp) || !ferror(fp));
+ ATF_CHECK_MSG(!input_error_1, "input error 1");
+ if (input_error_1)
+ continue;
+ status = pclose(fp);
+ ATF_CHECK_MSG(WIFEXITED(status) && WEXITSTATUS(status) == 9,
+ "bad exit status (input)");
+ }
+
+ for (i = 0; i < nitems(rmodes); i++) {
+ char *sres;
+ mode = rmodes[i];
+ fp = popen("echo hi there", mode);
+ ATF_CHECK_MSG(fp != NULL, "popen(, \"%s\") failed", mode);
+ if (fp == NULL)
+ continue;
+ check_cloexec(fp, mode);
+ ATF_CHECK_MSG((sres = fgets(buf, sizeof(buf), fp)) != NULL,
+ "Input error 2");
+ if (sres != NULL)
+ ATF_CHECK_MSG(strcmp(buf, "hi there\n") == 0,
+ "Bad input 1");
+ status = pclose(fp);
+ ATF_CHECK_MSG(WIFEXITED(status) && WEXITSTATUS(status) == 0,
+ "Bad exit status (input)");
+ }
+}
+
+ATF_TC_WITHOUT_HEAD(popen_wmodes_test);
+ATF_TC_BODY(popen_wmodes_test, tc)
+{
+ FILE *fp, *fp2;
+ const char *wmodes[] = { "w", "r+", "we", "r+e", "re+" };
+ const char *mode;
+ struct sigaction act, oact;
+ int i, j, status;
+
+ for (i = 0; i < nitems(wmodes); i++) {
+ mode = wmodes[i];
+ fp = popen("read x && [ \"$x\" = abcd ]", mode);
+ ATF_CHECK_MSG(fp != NULL, "popen(, \"%s\") failed", mode);
+ if (fp == NULL)
+ continue;
+ check_cloexec(fp, mode);
+ ATF_CHECK_MSG(fputs("abcd\n", fp) != EOF,
+ "Output error 1");
+ status = pclose(fp);
+ ATF_CHECK_MSG(WIFEXITED(status) && WEXITSTATUS(status) == 0,
+ "Bad exit status (output)");
+ }
+
+ act.sa_handler = sigpipe_handler;
+ act.sa_flags = SA_RESTART;
+ sigemptyset(&act.sa_mask);
+ ATF_CHECK_MSG(sigaction(SIGPIPE, &act, &oact) != -1,
+ "sigaction() failed");
+ for (i = 0; i < nitems(wmodes); i++) {
+ mode = wmodes[i];
+ fp = popen("exit 88", mode);
+ ATF_CHECK_MSG(fp != NULL, "popen(, \"%s\") failed", mode);
+ if (fp == NULL)
+ continue;
+ check_cloexec(fp, mode);
+ got_sigpipe = 0;
+ while (fputs("abcd\n", fp) != EOF)
+ ;
+ ATF_CHECK_MSG(ferror(fp) && errno == EPIPE, "Expected EPIPE");
+ ATF_CHECK_MSG(got_sigpipe, "Expected SIGPIPE");
+ status = pclose(fp);
+ ATF_CHECK_MSG(WIFEXITED(status) && WEXITSTATUS(status) == 88,
+ "Bad exit status (EPIPE)");
+ }
+ ATF_CHECK_MSG(sigaction(SIGPIPE, &oact, NULL) != -1,
+ "sigaction() failed");
+
+ for (i = 0; i < nitems(wmodes); i++) {
+ for (j = 0; j < nitems(wmodes); j++) {
+ mode = wmodes[i];
+ fp = popen("read x", mode);
+ ATF_CHECK_MSG(fp != NULL,
+ "popen(, \"%s\") failed", mode);
+ if (fp == NULL)
+ continue;
+ mode = wmodes[j];
+ fp2 = popen("read x", mode);
+ ATF_CHECK_MSG(fp2 != NULL,
+ "popen(, \"%s\") failed", mode);
+ if (fp2 == NULL) {
+ pclose(fp);
+ continue;
+ }
+ /* If fp2 inherits fp's pipe, we will deadlock here. */
+ status = pclose(fp);
+ ATF_CHECK_MSG(WIFEXITED(status) && WEXITSTATUS(status) == 1,
+ "bad exit status (2 pipes)");
+ status = pclose(fp2);
+ ATF_CHECK_MSG(WIFEXITED(status) && WEXITSTATUS(status) == 1,
+ "bad exit status (2 pipes)");
+ }
+ }
+}
+
+ATF_TC_WITHOUT_HEAD(popen_rwmodes_test);
+ATF_TC_BODY(popen_rwmodes_test, tc)
+{
+ const char *rwmodes[] = { "r+", "r+e", "re+" };
+ FILE *fp;
+ const char *mode;
+ char *sres;
+ char buf[80];
+ int i, ires, status;
+
+ for (i = 0; i < nitems(rwmodes); i++) {
+ mode = rwmodes[i];
+ fp = popen("read x && printf '%s\\n' \"Q${x#a}\"", mode);
+ ATF_CHECK_MSG(fp != NULL, "popen(, \"%s\") failed", mode);
+ if (fp == NULL)
+ continue;
+ check_cloexec(fp, mode);
+ ATF_CHECK_MSG((ires = fputs("abcd\n", fp)) != EOF,
+ "Output error 2");
+ if (ires != EOF) {
+ sres = fgets(buf, sizeof(buf), fp);
+ ATF_CHECK_MSG(sres != NULL, "Input error 3");
+ if (sres != NULL)
+ ATF_CHECK_MSG(strcmp(buf, "Qbcd\n") == 0,
+ "Bad input 2");
+ }
+ status = pclose(fp);
+ ATF_CHECK_MSG(WIFEXITED(status) && WEXITSTATUS(status) == 0,
+ "bad exit status (I/O)");
+ }
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, popen_all_modes_test);
+ ATF_TP_ADD_TC(tp, popen_rmodes_test);
+ ATF_TP_ADD_TC(tp, popen_wmodes_test);
+ ATF_TP_ADD_TC(tp, popen_rwmodes_test);
+
+ return (atf_no_error());
+}
Property changes on: trunk/lib/libc/tests/gen/popen_test.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/gen/posix_spawn/Makefile
===================================================================
--- trunk/lib/libc/tests/gen/posix_spawn/Makefile (rev 0)
+++ trunk/lib/libc/tests/gen/posix_spawn/Makefile 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,31 @@
+# $MidnightBSD$
+# $FreeBSD: stable/10/lib/libc/tests/gen/posix_spawn/Makefile 313488 2017-02-09 22:49:48Z ngie $
+
+.include <bsd.own.mk>
+
+BINDIR= ${TESTSDIR}
+
+NETBSD_ATF_TESTS_C= fileactions_test
+NETBSD_ATF_TESTS_C+= spawn_test
+NETBSD_ATF_TESTS_C+= spawnattr_test
+
+PROGS= h_fileactions
+PROGS+= h_spawn
+PROGS+= h_spawnattr
+
+SCRIPTS= h_nonexec
+SCRIPTS+= h_zero
+
+CLEANFILES+= h_nonexec
+
+.include "../../Makefile.netbsd-tests"
+
+h_zero:
+ dd if=/dev/zero of=h_zero bs=1k count=2
+ chmod a+x h_zero
+
+CLEANFILES+= h_zero
+
+WARNS?=3
+
+.include <bsd.test.mk>
Property changes on: trunk/lib/libc/tests/gen/posix_spawn/Makefile
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/gen/posix_spawn_test.c
===================================================================
--- trunk/lib/libc/tests/gen/posix_spawn_test.c (rev 0)
+++ trunk/lib/libc/tests/gen/posix_spawn_test.c 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,104 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2011 Jilles Tjoelker
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Test program for posix_spawn() and posix_spawnp() as specified by
+ * IEEE Std. 1003.1-2008.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/lib/libc/tests/gen/posix_spawn_test.c 291190 2015-11-23 10:53:01Z ngie $");
+
+#include <sys/wait.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <spawn.h>
+
+#include <atf-c.h>
+
+char *myenv[2] = { "answer=42", NULL };
+
+ATF_TC_WITHOUT_HEAD(posix_spawn_simple_test);
+ATF_TC_BODY(posix_spawn_simple_test, tc)
+{
+ char *myargs[4];
+ int error, status;
+ pid_t pid, waitres;
+
+ /* Make sure we have no child processes. */
+ while (waitpid(-1, NULL, 0) != -1)
+ ;
+ ATF_REQUIRE_MSG(errno == ECHILD, "errno was not ECHILD: %d", errno);
+
+ /* Simple test. */
+ myargs[0] = "sh";
+ myargs[1] = "-c";
+ myargs[2] = "exit $answer";
+ myargs[3] = NULL;
+ error = posix_spawnp(&pid, myargs[0], NULL, NULL, myargs, myenv);
+ ATF_REQUIRE(error == 0);
+ waitres = waitpid(pid, &status, 0);
+ ATF_REQUIRE(waitres == pid);
+ ATF_REQUIRE(WIFEXITED(status) && WEXITSTATUS(status) == 42);
+}
+
+ATF_TC_WITHOUT_HEAD(posix_spawn_no_such_command_negative_test);
+ATF_TC_BODY(posix_spawn_no_such_command_negative_test, tc)
+{
+ char *myargs[4];
+ int error, status;
+ pid_t pid, waitres;
+
+ /*
+ * If the executable does not exist, the function shall either fail
+ * and not create a child process or succeed and create a child
+ * process that exits with status 127.
+ */
+ myargs[0] = "/var/empty/nonexistent";
+ myargs[1] = NULL;
+ error = posix_spawn(&pid, myargs[0], NULL, NULL, myargs, myenv);
+ if (error == 0) {
+ waitres = waitpid(pid, &status, 0);
+ ATF_REQUIRE(waitres == pid);
+ ATF_REQUIRE(WIFEXITED(status) && WEXITSTATUS(status) == 127);
+ } else {
+ ATF_REQUIRE(error == ENOENT);
+ waitres = waitpid(-1, NULL, 0);
+ ATF_REQUIRE(waitres == -1 && errno == ECHILD);
+ }
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, posix_spawn_simple_test);
+ ATF_TP_ADD_TC(tp, posix_spawn_no_such_command_negative_test);
+
+ return (atf_no_error());
+}
Property changes on: trunk/lib/libc/tests/gen/posix_spawn_test.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/gen/realpath2_test.c
===================================================================
--- trunk/lib/libc/tests/gen/realpath2_test.c (rev 0)
+++ trunk/lib/libc/tests/gen/realpath2_test.c 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,103 @@
+/* $MidnightBSD$ */
+/*
+ * Copyright (c) 2017 Jan Kokemüller
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/lib/libc/tests/gen/realpath2_test.c 319419 2017-06-01 13:22:04Z kib $");
+
+#include <sys/param.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <atf-c.h>
+
+ATF_TC(realpath_buffer_overflow);
+ATF_TC_HEAD(realpath_buffer_overflow, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test for out of bounds read from 'left' array "
+ "(compile realpath.c with '-fsanitize=address')");
+}
+
+ATF_TC_BODY(realpath_buffer_overflow, tc)
+{
+ char path[MAXPATHLEN] = { 0 };
+ char resb[MAXPATHLEN] = { 0 };
+ size_t i;
+
+ path[0] = 'a';
+ path[1] = '/';
+ for (i = 2; i < sizeof(path) - 1; ++i) {
+ path[i] = 'a';
+ }
+
+ ATF_REQUIRE(realpath(path, resb) == NULL);
+}
+
+ATF_TC(realpath_empty_symlink);
+ATF_TC_HEAD(realpath_empty_symlink, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test for correct behavior when encountering empty symlinks");
+}
+
+ATF_TC_BODY(realpath_empty_symlink, tc)
+{
+ char path[MAXPATHLEN] = { 0 };
+ char slnk[MAXPATHLEN] = { 0 };
+ char resb[MAXPATHLEN] = { 0 };
+ int fd;
+
+ (void)strlcat(slnk, "empty_symlink", sizeof(slnk));
+
+ ATF_REQUIRE(symlink("", slnk) == 0);
+
+ fd = open("aaa", O_RDONLY | O_CREAT, 0600);
+
+ ATF_REQUIRE(fd >= 0);
+ ATF_REQUIRE(close(fd) == 0);
+
+ (void)strlcat(path, "empty_symlink", sizeof(path));
+ (void)strlcat(path, "/aaa", sizeof(path));
+
+ ATF_REQUIRE_ERRNO(ENOENT, realpath(path, resb) == NULL);
+
+ ATF_REQUIRE(unlink("aaa") == 0);
+ ATF_REQUIRE(unlink(slnk) == 0);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, realpath_buffer_overflow);
+ ATF_TP_ADD_TC(tp, realpath_empty_symlink);
+
+ return atf_no_error();
+}
Property changes on: trunk/lib/libc/tests/gen/realpath2_test.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/gen/test-fnmatch.c
===================================================================
--- trunk/lib/libc/tests/gen/test-fnmatch.c (rev 0)
+++ trunk/lib/libc/tests/gen/test-fnmatch.c 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,103 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2010 Jilles Tjoelker
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/lib/libc/tests/gen/test-fnmatch.c 291190 2015-11-23 10:53:01Z ngie $");
+
+#include <sys/param.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "fnmatch_testcases.h"
+
+static int
+write_sh_tests(const char *progname, int num)
+{
+ size_t i;
+ struct testcase *t;
+
+ printf("# Generated by %s -s %d, do not edit.\n", progname, num);
+ printf("# $" "FreeBSD$\n");
+ printf("failures=\n");
+ printf("failed() { printf '%%s\\n' \"Failed: $1 '$2' '$3'\"; failures=x$failures; }\n");
+ if (num == 1) {
+ printf("testmatch() { eval \"case \\$2 in ''$1) ;; *) failed testmatch \\\"\\$@\\\";; esac\"; }\n");
+ printf("testnomatch() { eval \"case \\$2 in ''$1) failed testnomatch \\\"\\$@\\\";; esac\"; }\n");
+ } else if (num == 2) {
+ printf("# We do not treat a backslash specially in this case,\n");
+ printf("# but this is not the case in all shells.\n");
+ printf("netestmatch() { case $2 in $1) ;; *) failed netestmatch \"$@\";; esac; }\n");
+ printf("netestnomatch() { case $2 in $1) failed netestnomatch \"$@\";; esac; }\n");
+ }
+
+ for (i = 0; i < nitems(testcases); i++) {
+ t = &testcases[i];
+ if (strchr(t->pattern, '\'') != NULL ||
+ strchr(t->string, '\'') != NULL)
+ continue;
+ if (t->flags == 0 && strcmp(t->pattern, "\\") == 0)
+ continue;
+ if (num == 1 && t->flags == 0)
+ printf("test%smatch '%s' '%s'\n",
+ t->result == FNM_NOMATCH ? "no" : "",
+ t->pattern, t->string);
+ if (num == 2 && (t->flags == FNM_NOESCAPE ||
+ (t->flags == 0 && strchr(t->pattern, '\\') == NULL)))
+ printf("netest%smatch '%s' '%s'\n",
+ t->result == FNM_NOMATCH ? "no" : "",
+ t->pattern, t->string);
+ }
+ printf("[ -z \"$failures\" ]\n");
+ return 0;
+}
+
+static void
+usage(char *progname)
+{
+ fprintf(stderr, "usage: %s [-s num]\n", progname);
+ fprintf(stderr, "-s option writes tests for sh(1), num is 1 or 2\n");
+}
+
+int
+main(int argc, char *argv[])
+{
+ int opt;
+
+ while ((opt = getopt(argc, argv, "s:")) != -1) {
+ switch (opt) {
+ case 's':
+ return (write_sh_tests(argv[0], atoi(optarg)));
+ default:
+ usage(argv[0]);
+ exit(1);
+ }
+ }
+ usage(argv[0]);
+ exit(1);
+}
Property changes on: trunk/lib/libc/tests/gen/test-fnmatch.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/gen/wordexp_test.c
===================================================================
--- trunk/lib/libc/tests/gen/wordexp_test.c (rev 0)
+++ trunk/lib/libc/tests/gen/wordexp_test.c 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,361 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2003 Tim J. Robbins
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Test program for wordexp() and wordfree() as specified by
+ * IEEE Std. 1003.1-2001.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/lib/libc/tests/gen/wordexp_test.c 291190 2015-11-23 10:53:01Z ngie $");
+
+#include <sys/wait.h>
+#include <errno.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <wordexp.h>
+
+#include <atf-c.h>
+
+static void
+chld_handler(int x)
+{
+ int status, serrno;
+
+ (void)x;
+ serrno = errno;
+ while (waitpid(-1, &status, WNOHANG) > 0)
+ ;
+ errno = serrno;
+}
+
+ATF_TC_WITHOUT_HEAD(simple_test);
+ATF_TC_BODY(simple_test, tc)
+{
+ wordexp_t we;
+ int r;
+
+ /* Test that the macros are there. */
+ (void)(WRDE_APPEND + WRDE_DOOFFS + WRDE_NOCMD + WRDE_REUSE +
+ WRDE_SHOWERR + WRDE_UNDEF);
+ (void)(WRDE_BADCHAR + WRDE_BADVAL + WRDE_CMDSUB + WRDE_NOSPACE +
+ WRDE_SYNTAX);
+
+ /* Simple test. */
+ r = wordexp("hello world", &we, 0);
+ ATF_REQUIRE(r == 0);
+ ATF_REQUIRE(we.we_wordc == 2);
+ ATF_REQUIRE(strcmp(we.we_wordv[0], "hello") == 0);
+ ATF_REQUIRE(strcmp(we.we_wordv[1], "world") == 0);
+ ATF_REQUIRE(we.we_wordv[2] == NULL);
+ wordfree(&we);
+}
+
+ATF_TC_WITHOUT_HEAD(long_output_test);
+ATF_TC_BODY(long_output_test, tc)
+{
+ char longdata[6 * 10000 + 1];
+ wordexp_t we;
+ int i, r;
+
+ /* Long output. */
+ for (i = 0; i < 10000; i++)
+ snprintf(longdata + 6 * i, 7, "%05d ", i);
+ r = wordexp(longdata, &we, 0);
+ ATF_REQUIRE(r == 0);
+ ATF_REQUIRE(we.we_wordc == 10000);
+ ATF_REQUIRE(we.we_wordv[10000] == NULL);
+ wordfree(&we);
+}
+
+ATF_TC_WITHOUT_HEAD(WRDE_DOOFFS_test);
+ATF_TC_BODY(WRDE_DOOFFS_test, tc)
+{
+ wordexp_t we;
+ int r;
+
+ we.we_offs = 3;
+ r = wordexp("hello world", &we, WRDE_DOOFFS);
+ ATF_REQUIRE(r == 0);
+ ATF_REQUIRE(we.we_wordc == 2);
+ ATF_REQUIRE(we.we_wordv[0] == NULL);
+ ATF_REQUIRE(we.we_wordv[1] == NULL);
+ ATF_REQUIRE(we.we_wordv[2] == NULL);
+ ATF_REQUIRE(strcmp(we.we_wordv[3], "hello") == 0);
+ ATF_REQUIRE(strcmp(we.we_wordv[4], "world") == 0);
+ ATF_REQUIRE(we.we_wordv[5] == NULL);
+ wordfree(&we);
+}
+
+ATF_TC_WITHOUT_HEAD(WRDE_REUSE_test);
+ATF_TC_BODY(WRDE_REUSE_test, tc)
+{
+ wordexp_t we;
+ int r;
+
+ r = wordexp("hello world", &we, 0);
+ r = wordexp("hello world", &we, WRDE_REUSE);
+ ATF_REQUIRE(r == 0);
+ ATF_REQUIRE(we.we_wordc == 2);
+ ATF_REQUIRE(strcmp(we.we_wordv[0], "hello") == 0);
+ ATF_REQUIRE(strcmp(we.we_wordv[1], "world") == 0);
+ ATF_REQUIRE(we.we_wordv[2] == NULL);
+ wordfree(&we);
+}
+
+ATF_TC_WITHOUT_HEAD(WRDE_APPEND_test);
+ATF_TC_BODY(WRDE_APPEND_test, tc)
+{
+ wordexp_t we;
+ int r;
+
+ r = wordexp("this is", &we, 0);
+ ATF_REQUIRE(r == 0);
+ r = wordexp("a test", &we, WRDE_APPEND);
+ ATF_REQUIRE(r == 0);
+ ATF_REQUIRE(we.we_wordc == 4);
+ ATF_REQUIRE(strcmp(we.we_wordv[0], "this") == 0);
+ ATF_REQUIRE(strcmp(we.we_wordv[1], "is") == 0);
+ ATF_REQUIRE(strcmp(we.we_wordv[2], "a") == 0);
+ ATF_REQUIRE(strcmp(we.we_wordv[3], "test") == 0);
+ ATF_REQUIRE(we.we_wordv[4] == NULL);
+ wordfree(&we);
+}
+
+ATF_TC_WITHOUT_HEAD(WRDE_DOOFFS__WRDE_APPEND_test);
+ATF_TC_BODY(WRDE_DOOFFS__WRDE_APPEND_test, tc)
+{
+ wordexp_t we;
+ int r;
+
+ we.we_offs = 2;
+ r = wordexp("this is", &we, WRDE_DOOFFS);
+ ATF_REQUIRE(r == 0);
+ r = wordexp("a test", &we, WRDE_APPEND|WRDE_DOOFFS);
+ ATF_REQUIRE(r == 0);
+ r = wordexp("of wordexp", &we, WRDE_APPEND|WRDE_DOOFFS);
+ ATF_REQUIRE(r == 0);
+ ATF_REQUIRE(we.we_wordc == 6);
+ ATF_REQUIRE(we.we_wordv[0] == NULL);
+ ATF_REQUIRE(we.we_wordv[1] == NULL);
+ ATF_REQUIRE(strcmp(we.we_wordv[2], "this") == 0);
+ ATF_REQUIRE(strcmp(we.we_wordv[3], "is") == 0);
+ ATF_REQUIRE(strcmp(we.we_wordv[4], "a") == 0);
+ ATF_REQUIRE(strcmp(we.we_wordv[5], "test") == 0);
+ ATF_REQUIRE(strcmp(we.we_wordv[6], "of") == 0);
+ ATF_REQUIRE(strcmp(we.we_wordv[7], "wordexp") == 0);
+ ATF_REQUIRE(we.we_wordv[8] == NULL);
+ wordfree(&we);
+}
+
+ATF_TC_WITHOUT_HEAD(WRDE_UNDEF_test);
+ATF_TC_BODY(WRDE_UNDEF_test, tc)
+{
+ wordexp_t we;
+ int r;
+
+ r = wordexp("${dont_set_me}", &we, WRDE_UNDEF);
+ ATF_REQUIRE(r == WRDE_BADVAL);
+}
+
+ATF_TC_WITHOUT_HEAD(WRDE_NOCMD_test);
+ATF_TC_BODY(WRDE_NOCMD_test, tc)
+{
+ wordexp_t we;
+ int r;
+
+ r = wordexp("`date`", &we, WRDE_NOCMD);
+ ATF_REQUIRE(r == WRDE_CMDSUB);
+ r = wordexp("\"`date`\"", &we, WRDE_NOCMD);
+ ATF_REQUIRE(r == WRDE_CMDSUB);
+ r = wordexp("$(date)", &we, WRDE_NOCMD);
+ ATF_REQUIRE(r == WRDE_CMDSUB);
+ r = wordexp("\"$(date)\"", &we, WRDE_NOCMD);
+ ATF_REQUIRE(r == WRDE_CMDSUB);
+ r = wordexp("$((3+5))", &we, WRDE_NOCMD);
+ ATF_REQUIRE(r == 0);
+ r = wordexp("\\$\\(date\\)", &we, WRDE_NOCMD|WRDE_REUSE);
+ ATF_REQUIRE(r == 0);
+ r = wordexp("'`date`'", &we, WRDE_NOCMD|WRDE_REUSE);
+ ATF_REQUIRE(r == 0);
+ r = wordexp("'$(date)'", &we, WRDE_NOCMD|WRDE_REUSE);
+ ATF_REQUIRE(r == 0);
+ wordfree(&we);
+}
+
+ATF_TC_WITHOUT_HEAD(WRDE_BADCHAR_test);
+ATF_TC_BODY(WRDE_BADCHAR_test, tc)
+{
+ wordexp_t we;
+ int r;
+
+ r = wordexp("'\n|&;<>(){}'", &we, 0);
+ ATF_REQUIRE(r == 0);
+ r = wordexp("\"\n|&;<>(){}\"", &we, WRDE_REUSE);
+ ATF_REQUIRE(r == 0);
+ r = wordexp("\\\n\\|\\&\\;\\<\\>\\(\\)\\{\\}", &we, WRDE_REUSE);
+ ATF_REQUIRE(r == 0);
+ wordfree(&we);
+ r = wordexp("test \n test", &we, 0);
+ ATF_REQUIRE(r == WRDE_BADCHAR);
+ r = wordexp("test | test", &we, 0);
+ ATF_REQUIRE(r == WRDE_BADCHAR);
+ r = wordexp("test & test", &we, 0);
+ ATF_REQUIRE(r == WRDE_BADCHAR);
+ r = wordexp("test ; test", &we, 0);
+ ATF_REQUIRE(r == WRDE_BADCHAR);
+ r = wordexp("test > test", &we, 0);
+ ATF_REQUIRE(r == WRDE_BADCHAR);
+ r = wordexp("test < test", &we, 0);
+ ATF_REQUIRE(r == WRDE_BADCHAR);
+ r = wordexp("test ( test", &we, 0);
+ ATF_REQUIRE(r == WRDE_BADCHAR);
+ r = wordexp("test ) test", &we, 0);
+ ATF_REQUIRE(r == WRDE_BADCHAR);
+ r = wordexp("test { test", &we, 0);
+ ATF_REQUIRE(r == WRDE_BADCHAR);
+ r = wordexp("test } test", &we, 0);
+ ATF_REQUIRE(r == WRDE_BADCHAR);
+}
+
+ATF_TC_WITHOUT_HEAD(WRDE_SYNTAX_test);
+ATF_TC_BODY(WRDE_SYNTAX_test, tc)
+{
+ wordexp_t we;
+ int r;
+
+ r = wordexp("'", &we, 0);
+ ATF_REQUIRE(r == WRDE_SYNTAX);
+ r = wordexp("'", &we, WRDE_UNDEF);
+ ATF_REQUIRE(r == WRDE_SYNTAX);
+ r = wordexp("'\\'", &we, 0);
+ ATF_REQUIRE(r == 0);
+ ATF_REQUIRE(we.we_wordc == 1);
+ ATF_REQUIRE(strcmp(we.we_wordv[0], "\\") == 0);
+ ATF_REQUIRE(we.we_wordv[1] == NULL);
+ wordfree(&we);
+ /* Two syntax errors that are not detected by the current we_check(). */
+ r = wordexp("${IFS:+'}", &we, 0);
+ ATF_REQUIRE(r == WRDE_SYNTAX);
+ r = wordexp("${IFS:+'}", &we, WRDE_UNDEF);
+ ATF_REQUIRE(r == WRDE_SYNTAX);
+ r = wordexp("$(case)", &we, 0);
+ ATF_REQUIRE(r == WRDE_SYNTAX);
+ r = wordexp("$(case)", &we, WRDE_UNDEF);
+ ATF_REQUIRE(r == WRDE_SYNTAX);
+}
+
+ATF_TC_WITHOUT_HEAD(with_SIGCHILD_handler_test);
+ATF_TC_BODY(with_SIGCHILD_handler_test, tc)
+{
+ struct sigaction sa;
+ wordexp_t we;
+ int r;
+
+ /* With a SIGCHLD handler that reaps all zombies. */
+ sa.sa_flags = 0;
+ sigemptyset(&sa.sa_mask);
+ sa.sa_handler = chld_handler;
+ r = sigaction(SIGCHLD, &sa, NULL);
+ ATF_REQUIRE(r == 0);
+ r = wordexp("hello world", &we, 0);
+ ATF_REQUIRE(r == 0);
+ ATF_REQUIRE(we.we_wordc == 2);
+ ATF_REQUIRE(strcmp(we.we_wordv[0], "hello") == 0);
+ ATF_REQUIRE(strcmp(we.we_wordv[1], "world") == 0);
+ ATF_REQUIRE(we.we_wordv[2] == NULL);
+ wordfree(&we);
+ sa.sa_handler = SIG_DFL;
+ r = sigaction(SIGCHLD, &sa, NULL);
+ ATF_REQUIRE(r == 0);
+}
+
+ATF_TC_WITHOUT_HEAD(with_unused_non_default_IFS_test);
+ATF_TC_BODY(with_unused_non_default_IFS_test, tc)
+{
+ wordexp_t we;
+ int r;
+
+ /*
+ * With IFS set to a non-default value (without depending on whether
+ * IFS is inherited or not).
+ */
+ r = setenv("IFS", ":", 1);
+ ATF_REQUIRE(r == 0);
+ r = wordexp("hello world", &we, 0);
+ ATF_REQUIRE(r == 0);
+ ATF_REQUIRE(we.we_wordc == 2);
+ ATF_REQUIRE(strcmp(we.we_wordv[0], "hello") == 0);
+ ATF_REQUIRE(strcmp(we.we_wordv[1], "world") == 0);
+ ATF_REQUIRE(we.we_wordv[2] == NULL);
+ wordfree(&we);
+ r = unsetenv("IFS");
+ ATF_REQUIRE(r == 0);
+}
+
+ATF_TC_WITHOUT_HEAD(with_used_non_default_IFS_test);
+ATF_TC_BODY(with_used_non_default_IFS_test, tc)
+{
+ wordexp_t we;
+ int r;
+
+ /*
+ * With IFS set to a non-default value, and using it.
+ */
+ r = setenv("IFS", ":", 1);
+ ATF_REQUIRE(r == 0);
+ r = wordexp("${IFS+hello:world}", &we, 0);
+ ATF_REQUIRE(r == 0);
+ ATF_REQUIRE(we.we_wordc == 2);
+ ATF_REQUIRE(strcmp(we.we_wordv[0], "hello") == 0);
+ ATF_REQUIRE(strcmp(we.we_wordv[1], "world") == 0);
+ ATF_REQUIRE(we.we_wordv[2] == NULL);
+ wordfree(&we);
+ r = unsetenv("IFS");
+ ATF_REQUIRE(r == 0);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+ ATF_TP_ADD_TC(tp, simple_test);
+ ATF_TP_ADD_TC(tp, long_output_test);
+ ATF_TP_ADD_TC(tp, WRDE_DOOFFS_test);
+ ATF_TP_ADD_TC(tp, WRDE_REUSE_test);
+ ATF_TP_ADD_TC(tp, WRDE_APPEND_test);
+ ATF_TP_ADD_TC(tp, WRDE_DOOFFS__WRDE_APPEND_test);
+ ATF_TP_ADD_TC(tp, WRDE_UNDEF_test);
+ ATF_TP_ADD_TC(tp, WRDE_NOCMD_test);
+ ATF_TP_ADD_TC(tp, WRDE_BADCHAR_test);
+ ATF_TP_ADD_TC(tp, WRDE_SYNTAX_test);
+ ATF_TP_ADD_TC(tp, with_SIGCHILD_handler_test);
+ ATF_TP_ADD_TC(tp, with_unused_non_default_IFS_test);
+ ATF_TP_ADD_TC(tp, with_used_non_default_IFS_test);
+
+ return (atf_no_error());
+}
Property changes on: trunk/lib/libc/tests/gen/wordexp_test.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/hash/Makefile
===================================================================
--- trunk/lib/libc/tests/hash/Makefile (rev 0)
+++ trunk/lib/libc/tests/hash/Makefile 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,37 @@
+# $MidnightBSD$
+# $FreeBSD: stable/10/lib/libc/tests/hash/Makefile 314817 2017-03-07 01:52:50Z ngie $
+
+.include <bsd.own.mk>
+
+NETBSD_ATF_TESTS_C=
+
+.if ${MK_OPENSSL} != "no"
+# XXX: doesn't compile
+#NETBSD_ATF_TESTS_C+= hmac_test
+NETBSD_ATF_TESTS_C+= sha2_test
+.endif
+
+NETBSD_ATF_TESTS_SH= hash_test
+
+BINDIR= ${TESTSDIR}
+
+PROGS+= h_hash
+
+FILESDIR= ${TESTSDIR}/data
+
+FILES+= data/md5test-in
+FILES+= data/md5test-out
+FILES+= data/sha1test-in
+FILES+= data/sha1test-out
+FILES+= data/sha1test2-out
+
+DPADD+= ${LIBMD}
+LDADD+= -lmd
+DPADD.sha2_test+= ${LIBCRYPTO}
+LDADD.sha2_test+= -lcrypto
+
+CFLAGS.h_hash+= -I${SRCTOP}/lib/libnetbsd
+
+.include "../Makefile.netbsd-tests"
+
+.include <bsd.test.mk>
Property changes on: trunk/lib/libc/tests/hash/Makefile
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/iconv/Makefile
===================================================================
--- trunk/lib/libc/tests/iconv/Makefile (rev 0)
+++ trunk/lib/libc/tests/iconv/Makefile 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,11 @@
+# $MidnightBSD$
+# $FreeBSD: stable/10/lib/libc/tests/iconv/Makefile 319252 2017-05-30 21:03:44Z asomers $
+
+PACKAGE= tests
+
+TESTSDIR= ${TESTSBASE}/lib/libc/iconv
+
+ATF_TESTS_C+= iconvctl_test
+WARNS?= 2
+
+.include <bsd.test.mk>
Property changes on: trunk/lib/libc/tests/iconv/Makefile
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/iconv/iconvctl_test.c
===================================================================
--- trunk/lib/libc/tests/iconv/iconvctl_test.c (rev 0)
+++ trunk/lib/libc/tests/iconv/iconvctl_test.c 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,70 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2016 Eric van Gyzen
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/lib/libc/tests/iconv/iconvctl_test.c 299704 2016-05-14 00:35:35Z vangyzen $");
+
+#include <iconv.h>
+
+#include <atf-c.h>
+
+void
+test_trivialp(const char *src, const char *dst, int expected)
+{
+ iconv_t ic;
+ int actual, status;
+
+ ic = iconv_open(dst, src);
+ ATF_REQUIRE(ic != (iconv_t)-1);
+
+ status = iconvctl(ic, ICONV_TRIVIALP, &actual);
+ ATF_REQUIRE(status == 0);
+
+ ATF_REQUIRE(actual == expected);
+
+ status = iconv_close(ic);
+ ATF_REQUIRE(status == 0);
+}
+
+ATF_TC_WITHOUT_HEAD(iconvctl_trivialp_test);
+ATF_TC_BODY(iconvctl_trivialp_test, tc)
+{
+
+ test_trivialp("ISO-8859-1", "ISO-8859-1", 1);
+ test_trivialp("ISO-8859-1", "ISO-8859-15", 0);
+ test_trivialp("ISO-8859-15", "ISO-8859-1", 0);
+ test_trivialp("ISO-8859-15", "UTF-8", 0);
+ test_trivialp("UTF-8", "ASCII", 0);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, iconvctl_trivialp_test);
+
+ return (atf_no_error());
+}
Property changes on: trunk/lib/libc/tests/iconv/iconvctl_test.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/inet/Makefile
===================================================================
--- trunk/lib/libc/tests/inet/Makefile (rev 0)
+++ trunk/lib/libc/tests/inet/Makefile 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,11 @@
+# $MidnightBSD$
+# $FreeBSD: stable/10/lib/libc/tests/inet/Makefile 313498 2017-02-10 01:13:12Z ngie $
+
+.include <bsd.own.mk>
+
+NETBSD_ATF_TESTS_C+= inet_addr_test
+NETBSD_ATF_TESTS_C+= inet_network_test
+
+.include "../Makefile.netbsd-tests"
+
+.include <bsd.test.mk>
Property changes on: trunk/lib/libc/tests/inet/Makefile
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/locale/Makefile
===================================================================
--- trunk/lib/libc/tests/locale/Makefile (rev 0)
+++ trunk/lib/libc/tests/locale/Makefile 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,45 @@
+# $MidnightBSD$
+# $FreeBSD: stable/10/lib/libc/tests/locale/Makefile 313488 2017-02-09 22:49:48Z ngie $
+
+.include <bsd.own.mk>
+
+ATF_TESTS_C+= btowc_test
+ATF_TESTS_C+= c16rtomb_test
+ATF_TESTS_C+= iswctype_test
+ATF_TESTS_C+= mblen_test
+ATF_TESTS_C+= mbrlen_test
+ATF_TESTS_C+= mbrtoc16_test
+ATF_TESTS_C+= mbrtowc_2_test
+ATF_TESTS_C+= mbsnrtowcs_2_test
+ATF_TESTS_C+= mbsrtowcs_test
+ATF_TESTS_C+= mbstowcs_2_test
+ATF_TESTS_C+= mbtowc_2_test
+ATF_TESTS_C+= towctrans_test
+ATF_TESTS_C+= wcrtomb_test
+ATF_TESTS_C+= wcsnrtombs_test
+ATF_TESTS_C+= wcsrtombs_test
+ATF_TESTS_C+= wcstombs_test
+ATF_TESTS_C+= wctomb_2_test
+
+NETBSD_ATF_TESTS_C= io_test
+NETBSD_ATF_TESTS_C+= mbrtowc_test
+NETBSD_ATF_TESTS_C+= mbstowcs_test
+NETBSD_ATF_TESTS_C+= mbsnrtowcs_test
+NETBSD_ATF_TESTS_C+= mbtowc_test
+NETBSD_ATF_TESTS_C+= wcscspn_test
+NETBSD_ATF_TESTS_C+= wcspbrk_test
+NETBSD_ATF_TESTS_C+= wcsspn_test
+NETBSD_ATF_TESTS_C+= wcstod_test
+NETBSD_ATF_TESTS_C+= wctomb_test
+
+SRCS.mbrtowc_2_test= mbrtowc_test.c
+SRCS.mbsnrtowcs_2_test= mbsnrtowcs_test.c
+SRCS.mbstowcs_2_test= mbstowcs_test.c
+SRCS.mbtowc_2_test= mbtowc_test.c
+SRCS.wctomb_2_test= wctomb_test.c
+
+CFLAGS.t_wctomb.c+= -Wno-stack-protector
+
+.include "../Makefile.netbsd-tests"
+
+.include <bsd.test.mk>
Property changes on: trunk/lib/libc/tests/locale/Makefile
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/locale/btowc_test.c
===================================================================
--- trunk/lib/libc/tests/locale/btowc_test.c (rev 0)
+++ trunk/lib/libc/tests/locale/btowc_test.c 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,72 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2002 Tim J. Robbins
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Test program for btowc() and wctob() as specified by IEEE Std. 1003.1-2001
+ * and ISO/IEC 9899:1999.
+ *
+ * The function is tested in the "C" and "ja_JP.eucJP" locales.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/lib/libc/tests/locale/btowc_test.c 291178 2015-11-23 08:31:41Z ngie $");
+
+#include <limits.h>
+#include <locale.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <wchar.h>
+
+#include <atf-c.h>
+
+ATF_TC_WITHOUT_HEAD(btowc_test);
+ATF_TC_BODY(btowc_test, tc)
+{
+ int i;
+
+ /* C/POSIX locale. */
+ ATF_REQUIRE(btowc(EOF) == WEOF);
+ ATF_REQUIRE(wctob(WEOF) == EOF);
+ for (i = 0; i < UCHAR_MAX; i++)
+ ATF_REQUIRE(btowc(i) == (wchar_t)i && i == (int)wctob(i));
+
+ /* Japanese (EUC) locale. */
+ ATF_REQUIRE(strcmp(setlocale(LC_CTYPE, "ja_JP.eucJP"), "ja_JP.eucJP") == 0);
+ ATF_REQUIRE(MB_CUR_MAX > 1);
+ ATF_REQUIRE(btowc('A') == L'A' && wctob(L'A') == 'A');
+ ATF_REQUIRE(btowc(0xa3) == WEOF && wctob(0xa3c1) == EOF);
+
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, btowc_test);
+
+ return (atf_no_error());
+}
Property changes on: trunk/lib/libc/tests/locale/btowc_test.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/locale/c16rtomb_test.c
===================================================================
--- trunk/lib/libc/tests/locale/c16rtomb_test.c (rev 0)
+++ trunk/lib/libc/tests/locale/c16rtomb_test.c 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,167 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2002 Tim J. Robbins
+ * All rights reserved.
+ *
+ * Copyright (c) 2013 Ed Schouten <ed at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+/*
+ * Test program for c16rtomb() as specified by ISO/IEC 9899:2011.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/lib/libc/tests/locale/c16rtomb_test.c 291178 2015-11-23 08:31:41Z ngie $");
+
+#include <errno.h>
+#include <limits.h>
+#include <locale.h>
+#include <stdio.h>
+#include <string.h>
+#include <uchar.h>
+
+#include <atf-c.h>
+
+static void
+require_lc_ctype(const char *locale_name)
+{
+ char *lc_ctype_set;
+
+ lc_ctype_set = setlocale(LC_CTYPE, locale_name);
+ if (lc_ctype_set == NULL)
+ atf_tc_fail("setlocale(LC_CTYPE, \"%s\") failed; errno=%d",
+ locale_name, errno);
+
+ ATF_REQUIRE(strcmp(lc_ctype_set, locale_name) == 0);
+}
+
+static mbstate_t s;
+static char buf[MB_LEN_MAX + 1];
+
+ATF_TC_WITHOUT_HEAD(c16rtomb_c_locale_test);
+ATF_TC_BODY(c16rtomb_c_locale_test, tc)
+{
+
+ require_lc_ctype("C");
+
+ /*
+ * If the buffer argument is NULL, c16 is implicitly 0,
+ * c16rtomb() resets its internal state.
+ */
+ ATF_REQUIRE(c16rtomb(NULL, L'\0', NULL) == 1);
+ ATF_REQUIRE(c16rtomb(NULL, 0xdc00, NULL) == 1);
+
+ /* Null wide character. */
+ memset(&s, 0, sizeof(s));
+ memset(buf, 0xcc, sizeof(buf));
+ ATF_REQUIRE(c16rtomb(buf, 0, &s) == 1);
+ ATF_REQUIRE((unsigned char)buf[0] == 0 && (unsigned char)buf[1] == 0xcc);
+
+ /* Latin letter A, internal state. */
+ ATF_REQUIRE(c16rtomb(NULL, L'\0', NULL) == 1);
+ ATF_REQUIRE(c16rtomb(NULL, L'A', NULL) == 1);
+
+ /* Latin letter A. */
+ memset(&s, 0, sizeof(s));
+ memset(buf, 0xcc, sizeof(buf));
+ ATF_REQUIRE(c16rtomb(buf, L'A', &s) == 1);
+ ATF_REQUIRE((unsigned char)buf[0] == 'A' && (unsigned char)buf[1] == 0xcc);
+
+ /* Unicode character 'Pile of poo'. */
+ memset(&s, 0, sizeof(s));
+ memset(buf, 0xcc, sizeof(buf));
+ ATF_REQUIRE(c16rtomb(buf, 0xd83d, &s) == 0);
+ ATF_REQUIRE(c16rtomb(buf, 0xdca9, &s) == (size_t)-1);
+ ATF_REQUIRE(errno == EILSEQ);
+ ATF_REQUIRE((unsigned char)buf[0] == 0xcc);
+}
+
+ATF_TC_WITHOUT_HEAD(c16rtomb_iso_8859_1_test);
+ATF_TC_BODY(c16rtomb_iso_8859_1_test, tc)
+{
+
+ require_lc_ctype("en_US.ISO8859-1");
+
+ /* Unicode character 'Euro sign'. */
+ memset(&s, 0, sizeof(s));
+ memset(buf, 0xcc, sizeof(buf));
+ ATF_REQUIRE(c16rtomb(buf, 0x20ac, &s) == (size_t)-1);
+ ATF_REQUIRE(errno == EILSEQ);
+ ATF_REQUIRE((unsigned char)buf[0] == 0xcc);
+}
+
+ATF_TC_WITHOUT_HEAD(c16rtomb_iso_8859_15_test);
+ATF_TC_BODY(c16rtomb_iso_8859_15_test, tc)
+{
+
+ require_lc_ctype("en_US.ISO8859-15");
+
+ /* Unicode character 'Euro sign'. */
+ memset(&s, 0, sizeof(s));
+ memset(buf, 0xcc, sizeof(buf));
+ ATF_REQUIRE(c16rtomb(buf, 0x20ac, &s) == 1);
+ ATF_REQUIRE((unsigned char)buf[0] == 0xa4 && (unsigned char)buf[1] == 0xcc);
+}
+
+ATF_TC_WITHOUT_HEAD(c16rtomb_utf_8_test);
+ATF_TC_BODY(c16rtomb_utf_8_test, tc)
+{
+
+ require_lc_ctype("en_US.UTF-8");
+
+ /* Unicode character 'Pile of poo'. */
+ memset(&s, 0, sizeof(s));
+ memset(buf, 0xcc, sizeof(buf));
+ ATF_REQUIRE(c16rtomb(buf, 0xd83d, &s) == 0);
+ ATF_REQUIRE(c16rtomb(buf, 0xdca9, &s) == 4);
+ ATF_REQUIRE((unsigned char)buf[0] == 0xf0 && (unsigned char)buf[1] == 0x9f &&
+ (unsigned char)buf[2] == 0x92 && (unsigned char)buf[3] == 0xa9 &&
+ (unsigned char)buf[4] == 0xcc);
+
+ /* Invalid code; 'Pile of poo' without the trail surrogate. */
+ memset(&s, 0, sizeof(s));
+ memset(buf, 0xcc, sizeof(buf));
+ ATF_REQUIRE(c16rtomb(buf, 0xd83d, &s) == 0);
+ ATF_REQUIRE(c16rtomb(buf, L'A', &s) == (size_t)-1);
+ ATF_REQUIRE(errno == EILSEQ);
+ ATF_REQUIRE((unsigned char)buf[0] == 0xcc);
+
+ /* Invalid code; 'Pile of poo' without the lead surrogate. */
+ memset(&s, 0, sizeof(s));
+ memset(buf, 0xcc, sizeof(buf));
+ ATF_REQUIRE(c16rtomb(buf, 0xdca9, &s) == (size_t)-1);
+ ATF_REQUIRE(errno == EILSEQ);
+ ATF_REQUIRE((unsigned char)buf[0] == 0xcc);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, c16rtomb_c_locale_test);
+ ATF_TP_ADD_TC(tp, c16rtomb_iso_8859_1_test);
+ ATF_TP_ADD_TC(tp, c16rtomb_iso_8859_15_test);
+ ATF_TP_ADD_TC(tp, c16rtomb_utf_8_test);
+
+ return (atf_no_error());
+}
Property changes on: trunk/lib/libc/tests/locale/c16rtomb_test.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/locale/iswctype_test.c
===================================================================
--- trunk/lib/libc/tests/locale/iswctype_test.c (rev 0)
+++ trunk/lib/libc/tests/locale/iswctype_test.c 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,123 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2003 Tim J. Robbins
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Test program for wctype() and iswctype() as specified by
+ * IEEE Std. 1003.1-2001 and ISO/IEC 9899:1999.
+ *
+ * The functions are tested in the "C" and "ja_JP.eucJP" locales.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/lib/libc/tests/locale/iswctype_test.c 291178 2015-11-23 08:31:41Z ngie $");
+
+#include <sys/param.h>
+#include <errno.h>
+#include <locale.h>
+#include <stdio.h>
+#include <string.h>
+#include <wchar.h>
+#include <wctype.h>
+
+#include <atf-c.h>
+
+static void
+require_lc_ctype(const char *locale_name)
+{
+ char *lc_ctype_set;
+
+ lc_ctype_set = setlocale(LC_CTYPE, locale_name);
+ if (lc_ctype_set == NULL)
+ atf_tc_fail("setlocale(LC_CTYPE, \"%s\") failed; errno=%d",
+ locale_name, errno);
+
+ ATF_REQUIRE(strcmp(lc_ctype_set, locale_name) == 0);
+}
+
+static wctype_t t;
+static int i, j;
+static struct {
+ const char *name;
+ int (*func)(wint_t);
+} cls[] = {
+ { "alnum", iswalnum },
+ { "alpha", iswalpha },
+ { "blank", iswblank },
+ { "cntrl", iswcntrl },
+ { "digit", iswdigit },
+ { "graph", iswgraph },
+ { "lower", iswlower },
+ { "print", iswprint },
+ { "punct", iswpunct },
+ { "space", iswspace },
+ { "upper", iswupper },
+ { "xdigit", iswxdigit }
+};
+
+ATF_TC_WITHOUT_HEAD(iswctype_c_locale_test);
+ATF_TC_BODY(iswctype_c_locale_test, tc)
+{
+
+ require_lc_ctype("C");
+ for (i = 0; i < nitems(cls); i++) {
+ t = wctype(cls[i].name);
+ ATF_REQUIRE(t != 0);
+ for (j = 0; j < 256; j++)
+ ATF_REQUIRE(cls[i].func(j) == iswctype(j, t));
+ }
+ t = wctype("elephant");
+ ATF_REQUIRE(t == 0);
+ for (i = 0; i < 256; i++)
+ ATF_REQUIRE(iswctype(i, t) == 0);
+}
+
+ATF_TC_WITHOUT_HEAD(iswctype_euc_jp_test);
+ATF_TC_BODY(iswctype_euc_jp_test, tc)
+{
+
+ require_lc_ctype("ja_JP.eucJP");
+
+ for (i = 0; i < nitems(cls); i++) {
+ t = wctype(cls[i].name);
+ ATF_REQUIRE(t != 0);
+ for (j = 0; j < 65536; j++)
+ ATF_REQUIRE(cls[i].func(j) == iswctype(j, t));
+ }
+ t = wctype("elephant");
+ ATF_REQUIRE(t == 0);
+ for (i = 0; i < 65536; i++)
+ ATF_REQUIRE(iswctype(i, t) == 0);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, iswctype_c_locale_test);
+ ATF_TP_ADD_TC(tp, iswctype_euc_jp_test);
+
+ return (atf_no_error());
+}
Property changes on: trunk/lib/libc/tests/locale/iswctype_test.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/locale/mblen_test.c
===================================================================
--- trunk/lib/libc/tests/locale/mblen_test.c (rev 0)
+++ trunk/lib/libc/tests/locale/mblen_test.c 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,117 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2002-2004 Tim J. Robbins
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Test program for mblen(), as specified by IEEE Std. 1003.1-2001 and
+ * ISO/IEC 9899:1990.
+ *
+ * The function is tested with both the "C" ("POSIX") LC_CTYPE setting and
+ * "ja_JP.eucJP". Other encodings are not tested.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/lib/libc/tests/locale/mblen_test.c 291178 2015-11-23 08:31:41Z ngie $");
+
+#include <limits.h>
+#include <locale.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <atf-c.h>
+
+ATF_TC_WITHOUT_HEAD(mblen_test);
+ATF_TC_BODY(mblen_test, tc)
+{
+ char buf[MB_LEN_MAX + 1];
+
+ /*
+ * C/POSIX locale.
+ */
+
+ ATF_REQUIRE(MB_CUR_MAX == 1);
+
+ /* No shift states in C locale. */
+ ATF_REQUIRE(mblen(NULL, 0) == 0);
+
+ /* Null wide character. */
+ memset(buf, 0xcc, sizeof(buf));
+ buf[0] = '\0';
+ ATF_REQUIRE(mblen(buf, 1) == 0);
+
+ /* Latin letter A. */
+ buf[0] = 'A';
+ ATF_REQUIRE(mblen(buf, 1) == 1);
+
+ /* Incomplete character sequence. */
+ buf[0] = '\0';
+ ATF_REQUIRE(mblen(buf, 0) == -1);
+ ATF_REQUIRE(mblen(NULL, 0) == 0);
+
+ /*
+ * Japanese (EUC) locale.
+ */
+
+ ATF_REQUIRE(strcmp(setlocale(LC_CTYPE, "ja_JP.eucJP"), "ja_JP.eucJP") == 0);
+ ATF_REQUIRE(MB_CUR_MAX > 1);
+
+ /* No shift states in EUC. */
+ ATF_REQUIRE(mblen(NULL, 0) == 0);
+
+ /* Null wide character. */
+ memset(buf, 0xcc, sizeof(buf));
+ buf[0] = '\0';
+ ATF_REQUIRE(mblen(buf, 1) == 0);
+
+ /* Latin letter A. */
+ buf[0] = 'A';
+ ATF_REQUIRE(mblen(buf, 1) == 1);
+
+ /* Incomplete character sequence. */
+ buf[0] = '\0';
+ ATF_REQUIRE(mblen(buf, 0) == -1);
+ ATF_REQUIRE(mblen(NULL, 0) == 0);
+
+ /* Incomplete character sequence (truncated double-byte). */
+ memset(buf, 0xcc, sizeof(buf));
+ buf[0] = 0xa3;
+ buf[1] = 0x00;
+ ATF_REQUIRE(mblen(buf, 1) == -1);
+ ATF_REQUIRE(mblen(NULL, 0) == 0);
+
+ /* Same as above, but complete. */
+ buf[1] = 0xc1;
+ ATF_REQUIRE(mblen(buf, 2) == 2);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, mblen_test);
+
+ return (atf_no_error());
+}
Property changes on: trunk/lib/libc/tests/locale/mblen_test.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/locale/mbrlen_test.c
===================================================================
--- trunk/lib/libc/tests/locale/mbrlen_test.c (rev 0)
+++ trunk/lib/libc/tests/locale/mbrlen_test.c 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,127 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2002 Tim J. Robbins
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Test program for mbrlen(), as specified by IEEE Std. 1003.1-2001 and
+ * ISO/IEC 9899:1999.
+ *
+ * The function is tested with both the "C" ("POSIX") LC_CTYPE setting and
+ * "ja_JP.eucJP". Other encodings are not tested.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/lib/libc/tests/locale/mbrlen_test.c 291178 2015-11-23 08:31:41Z ngie $");
+
+#include <errno.h>
+#include <limits.h>
+#include <locale.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <wchar.h>
+
+#include <atf-c.h>
+
+ATF_TC_WITHOUT_HEAD(mbrlen_test);
+ATF_TC_BODY(mbrlen_test, tc)
+{
+ mbstate_t s;
+ char buf[MB_LEN_MAX + 1];
+
+ /* C/POSIX locale. */
+ ATF_REQUIRE(MB_CUR_MAX == 1);
+
+ /* Null wide character, internal state. */
+ memset(buf, 0xcc, sizeof(buf));
+ buf[0] = 0;
+ ATF_REQUIRE(mbrlen(buf, 1, NULL) == 0);
+
+ /* Null wide character. */
+ memset(&s, 0, sizeof(s));
+ ATF_REQUIRE(mbrlen(buf, 1, &s) == 0);
+
+ /* Latin letter A, internal state. */
+ ATF_REQUIRE(mbrlen(NULL, 0, NULL) == 0);
+ buf[0] = 'A';
+ ATF_REQUIRE(mbrlen(buf, 1, NULL) == 1);
+
+ /* Latin letter A. */
+ memset(&s, 0, sizeof(s));
+ ATF_REQUIRE(mbrlen(buf, 1, &s) == 1);
+
+ /* Incomplete character sequence. */
+ memset(&s, 0, sizeof(s));
+ ATF_REQUIRE(mbrlen(buf, 0, &s) == (size_t)-2);
+
+ /* Japanese (EUC) locale. */
+
+ ATF_REQUIRE(strcmp(setlocale(LC_CTYPE, "ja_JP.eucJP"), "ja_JP.eucJP") == 0);
+ ATF_REQUIRE(MB_CUR_MAX > 1);
+
+ /* Null wide character, internal state. */
+ ATF_REQUIRE(mbrlen(NULL, 0, NULL) == 0);
+ memset(buf, 0xcc, sizeof(buf));
+ buf[0] = 0;
+ ATF_REQUIRE(mbrlen(buf, 1, NULL) == 0);
+
+ /* Null wide character. */
+ memset(&s, 0, sizeof(s));
+ ATF_REQUIRE(mbrlen(buf, 1, &s) == 0);
+
+ /* Latin letter A, internal state. */
+ ATF_REQUIRE(mbrlen(NULL, 0, NULL) == 0);
+ buf[0] = 'A';
+ ATF_REQUIRE(mbrlen(buf, 1, NULL) == 1);
+
+ /* Latin letter A. */
+ memset(&s, 0, sizeof(s));
+ ATF_REQUIRE(mbrlen(buf, 1, &s) == 1);
+
+ /* Incomplete character sequence (zero length). */
+ memset(&s, 0, sizeof(s));
+ ATF_REQUIRE(mbrlen(buf, 0, &s) == (size_t)-2);
+
+ /* Incomplete character sequence (truncated double-byte). */
+ memset(buf, 0xcc, sizeof(buf));
+ buf[0] = 0xa3;
+ buf[1] = 0x00;
+ memset(&s, 0, sizeof(s));
+ ATF_REQUIRE(mbrlen(buf, 1, &s) == (size_t)-2);
+
+ /* Same as above, but complete. */
+ buf[1] = 0xc1;
+ memset(&s, 0, sizeof(s));
+ ATF_REQUIRE(mbrlen(buf, 2, &s) == 2);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, mbrlen_test);
+
+ return (atf_no_error());
+}
Property changes on: trunk/lib/libc/tests/locale/mbrlen_test.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/locale/mbrtoc16_test.c
===================================================================
--- trunk/lib/libc/tests/locale/mbrtoc16_test.c (rev 0)
+++ trunk/lib/libc/tests/locale/mbrtoc16_test.c 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,215 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2002 Tim J. Robbins
+ * All rights reserved.
+ *
+ * Copyright (c) 2013 Ed Schouten <ed at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+/*
+ * Test program for mbrtoc16() as specified by ISO/IEC 9899:2011.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/lib/libc/tests/locale/mbrtoc16_test.c 291178 2015-11-23 08:31:41Z ngie $");
+
+#include <errno.h>
+#include <limits.h>
+#include <locale.h>
+#include <stdio.h>
+#include <string.h>
+#include <uchar.h>
+
+#include <atf-c.h>
+
+static void
+require_lc_ctype(const char *locale_name)
+{
+ char *lc_ctype_set;
+
+ lc_ctype_set = setlocale(LC_CTYPE, locale_name);
+ if (lc_ctype_set == NULL)
+ atf_tc_fail("setlocale(LC_CTYPE, \"%s\") failed; errno=%d",
+ locale_name, errno);
+
+ ATF_REQUIRE(strcmp(lc_ctype_set, locale_name) == 0);
+}
+
+static mbstate_t s;
+static char16_t c16;
+
+ATF_TC_WITHOUT_HEAD(mbrtoc16_c_locale_test);
+ATF_TC_BODY(mbrtoc16_c_locale_test, tc)
+{
+
+ require_lc_ctype("C");
+
+ /* Null wide character, internal state. */
+ ATF_REQUIRE(mbrtoc16(&c16, "", 1, NULL) == 0);
+ ATF_REQUIRE(c16 == 0);
+
+ /* Null wide character. */
+ memset(&s, 0, sizeof(s));
+ ATF_REQUIRE(mbrtoc16(&c16, "", 1, &s) == 0);
+ ATF_REQUIRE(c16 == 0);
+
+ /* Latin letter A, internal state. */
+ ATF_REQUIRE(mbrtoc16(NULL, 0, 0, NULL) == 0);
+ ATF_REQUIRE(mbrtoc16(&c16, "A", 1, NULL) == 1);
+ ATF_REQUIRE(c16 == L'A');
+
+ /* Latin letter A. */
+ memset(&s, 0, sizeof(s));
+ ATF_REQUIRE(mbrtoc16(&c16, "A", 1, &s) == 1);
+ ATF_REQUIRE(c16 == L'A');
+
+ /* Incomplete character sequence. */
+ c16 = L'z';
+ memset(&s, 0, sizeof(s));
+ ATF_REQUIRE(mbrtoc16(&c16, "", 0, &s) == (size_t)-2);
+ ATF_REQUIRE(c16 == L'z');
+
+ /* Check that mbrtoc16() doesn't access the buffer when n == 0. */
+ c16 = L'z';
+ memset(&s, 0, sizeof(s));
+ ATF_REQUIRE(mbrtoc16(&c16, "", 0, &s) == (size_t)-2);
+ ATF_REQUIRE(c16 == L'z');
+
+ /* Check that mbrtoc16() doesn't read ahead too aggressively. */
+ memset(&s, 0, sizeof(s));
+ ATF_REQUIRE(mbrtoc16(&c16, "AB", 2, &s) == 1);
+ ATF_REQUIRE(c16 == L'A');
+ ATF_REQUIRE(mbrtoc16(&c16, "C", 1, &s) == 1);
+ ATF_REQUIRE(c16 == L'C');
+
+}
+
+ATF_TC_WITHOUT_HEAD(mbrtoc16_iso_8859_1_test);
+ATF_TC_BODY(mbrtoc16_iso_8859_1_test, tc)
+{
+
+ require_lc_ctype("en_US.ISO8859-1");
+
+ /* Currency sign. */
+ memset(&s, 0, sizeof(s));
+ ATF_REQUIRE(mbrtoc16(&c16, "\xa4", 1, &s) == 1);
+ ATF_REQUIRE(c16 == 0xa4);
+}
+
+ATF_TC_WITHOUT_HEAD(mbrtoc16_iso_8859_15_test);
+ATF_TC_BODY(mbrtoc16_iso_8859_15_test, tc)
+{
+
+ require_lc_ctype("en_US.ISO8859-15");
+
+ /* Euro sign. */
+ memset(&s, 0, sizeof(s));
+ ATF_REQUIRE(mbrtoc16(&c16, "\xa4", 1, &s) == 1);
+ ATF_REQUIRE(c16 == 0x20ac);
+}
+
+ATF_TC_WITHOUT_HEAD(mbrtoc16_utf_8_test);
+ATF_TC_BODY(mbrtoc16_utf_8_test, tc)
+{
+
+ require_lc_ctype("en_US.UTF-8");
+
+ /* Null wide character, internal state. */
+ ATF_REQUIRE(mbrtoc16(NULL, 0, 0, NULL) == 0);
+ ATF_REQUIRE(mbrtoc16(&c16, "", 1, NULL) == 0);
+ ATF_REQUIRE(c16 == 0);
+
+ /* Null wide character. */
+ memset(&s, 0, sizeof(s));
+ ATF_REQUIRE(mbrtoc16(&c16, "", 1, &s) == 0);
+ ATF_REQUIRE(c16 == 0);
+
+ /* Latin letter A, internal state. */
+ ATF_REQUIRE(mbrtoc16(NULL, 0, 0, NULL) == 0);
+ ATF_REQUIRE(mbrtoc16(&c16, "A", 1, NULL) == 1);
+ ATF_REQUIRE(c16 == L'A');
+
+ /* Latin letter A. */
+ memset(&s, 0, sizeof(s));
+ ATF_REQUIRE(mbrtoc16(&c16, "A", 1, &s) == 1);
+ ATF_REQUIRE(c16 == L'A');
+
+ /* Incomplete character sequence (zero length). */
+ c16 = L'z';
+ memset(&s, 0, sizeof(s));
+ ATF_REQUIRE(mbrtoc16(&c16, "", 0, &s) == (size_t)-2);
+ ATF_REQUIRE(c16 == L'z');
+
+ /* Incomplete character sequence (truncated double-byte). */
+ memset(&s, 0, sizeof(s));
+ c16 = 0;
+ ATF_REQUIRE(mbrtoc16(&c16, "\xc3", 1, &s) == (size_t)-2);
+
+ /* Same as above, but complete. */
+ memset(&s, 0, sizeof(s));
+ c16 = 0;
+ ATF_REQUIRE(mbrtoc16(&c16, "\xc3\x84", 2, &s) == 2);
+ ATF_REQUIRE(c16 == 0xc4);
+
+ /* Test restarting behaviour. */
+ memset(&s, 0, sizeof(s));
+ c16 = 0;
+ ATF_REQUIRE(mbrtoc16(&c16, "\xc3", 1, &s) == (size_t)-2);
+ ATF_REQUIRE(c16 == 0);
+ ATF_REQUIRE(mbrtoc16(&c16, "\xb7", 1, &s) == 1);
+ ATF_REQUIRE(c16 == 0xf7);
+
+ /* Surrogate pair. */
+ memset(&s, 0, sizeof(s));
+ c16 = 0;
+ ATF_REQUIRE(mbrtoc16(&c16, "\xf0\x9f\x92\xa9", 4, &s) == 4);
+ ATF_REQUIRE(c16 == 0xd83d);
+ ATF_REQUIRE(mbrtoc16(&c16, "", 0, &s) == (size_t)-3);
+ ATF_REQUIRE(c16 == 0xdca9);
+
+ /* Letter e with acute, precomposed. */
+ memset(&s, 0, sizeof(s));
+ c16 = 0;
+ ATF_REQUIRE(mbrtoc16(&c16, "\xc3\xa9", 2, &s) == 2);
+ ATF_REQUIRE(c16 == 0xe9);
+
+ /* Letter e with acute, combined. */
+ memset(&s, 0, sizeof(s));
+ c16 = 0;
+ ATF_REQUIRE(mbrtoc16(&c16, "\x65\xcc\x81", 3, &s) == 1);
+ ATF_REQUIRE(c16 == 0x65);
+ ATF_REQUIRE(mbrtoc16(&c16, "\xcc\x81", 2, &s) == 2);
+ ATF_REQUIRE(c16 == 0x301);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, mbrtoc16_c_locale_test);
+ ATF_TP_ADD_TC(tp, mbrtoc16_iso_8859_1_test);
+ ATF_TP_ADD_TC(tp, mbrtoc16_iso_8859_15_test);
+ ATF_TP_ADD_TC(tp, mbrtoc16_utf_8_test);
+
+ return (atf_no_error());
+}
Property changes on: trunk/lib/libc/tests/locale/mbrtoc16_test.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/locale/mbrtowc_test.c
===================================================================
--- trunk/lib/libc/tests/locale/mbrtowc_test.c (rev 0)
+++ trunk/lib/libc/tests/locale/mbrtowc_test.c 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,166 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2002 Tim J. Robbins
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Test program for mbrtowc(), as specified by IEEE Std. 1003.1-2001 and
+ * ISO/IEC 9899:1999.
+ *
+ * The function is tested with both the "C" ("POSIX") LC_CTYPE setting and
+ * "ja_JP.eucJP". Other encodings are not tested.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/lib/libc/tests/locale/mbrtowc_test.c 291178 2015-11-23 08:31:41Z ngie $");
+
+#include <errno.h>
+#include <limits.h>
+#include <locale.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <wchar.h>
+
+#include <atf-c.h>
+
+ATF_TC_WITHOUT_HEAD(mbrtowc_test);
+ATF_TC_BODY(mbrtowc_test, tc)
+{
+ mbstate_t s;
+ wchar_t wc;
+ char buf[MB_LEN_MAX + 1];
+
+ /*
+ * C/POSIX locale.
+ */
+
+ ATF_REQUIRE(MB_CUR_MAX == 1);
+
+ /* Null wide character, internal state. */
+ memset(buf, 0xcc, sizeof(buf));
+ buf[0] = 0;
+ ATF_REQUIRE(mbrtowc(&wc, buf, 1, NULL) == 0);
+ ATF_REQUIRE(wc == 0);
+
+ /* Null wide character. */
+ memset(&s, 0, sizeof(s));
+ ATF_REQUIRE(mbrtowc(&wc, buf, 1, &s) == 0);
+ ATF_REQUIRE(wc == 0);
+
+ /* Latin letter A, internal state. */
+ ATF_REQUIRE(mbrtowc(NULL, 0, 0, NULL) == 0);
+ buf[0] = 'A';
+ ATF_REQUIRE(mbrtowc(&wc, buf, 1, NULL) == 1);
+ ATF_REQUIRE(wc == L'A');
+
+ /* Latin letter A. */
+ memset(&s, 0, sizeof(s));
+ ATF_REQUIRE(mbrtowc(&wc, buf, 1, &s) == 1);
+ ATF_REQUIRE(wc == L'A');
+
+ /* Incomplete character sequence. */
+ wc = L'z';
+ memset(&s, 0, sizeof(s));
+ ATF_REQUIRE(mbrtowc(&wc, buf, 0, &s) == (size_t)-2);
+ ATF_REQUIRE(wc == L'z');
+
+ /* Check that mbrtowc() doesn't access the buffer when n == 0. */
+ wc = L'z';
+ memset(&s, 0, sizeof(s));
+ buf[0] = '\0';
+ ATF_REQUIRE(mbrtowc(&wc, buf, 0, &s) == (size_t)-2);
+ ATF_REQUIRE(wc == L'z');
+
+ /*
+ * Japanese (EUC) locale.
+ */
+
+ ATF_REQUIRE(strcmp(setlocale(LC_CTYPE, "ja_JP.eucJP"), "ja_JP.eucJP") == 0);
+ ATF_REQUIRE(MB_CUR_MAX > 1);
+
+ /* Null wide character, internal state. */
+ ATF_REQUIRE(mbrtowc(NULL, 0, 0, NULL) == 0);
+ memset(buf, 0xcc, sizeof(buf));
+ buf[0] = 0;
+ ATF_REQUIRE(mbrtowc(&wc, buf, 1, NULL) == 0);
+ ATF_REQUIRE(wc == 0);
+
+ /* Null wide character. */
+ memset(&s, 0, sizeof(s));
+ ATF_REQUIRE(mbrtowc(&wc, buf, 1, &s) == 0);
+ ATF_REQUIRE(wc == 0);
+
+ /* Latin letter A, internal state. */
+ ATF_REQUIRE(mbrtowc(NULL, 0, 0, NULL) == 0);
+ buf[0] = 'A';
+ ATF_REQUIRE(mbrtowc(&wc, buf, 1, NULL) == 1);
+ ATF_REQUIRE(wc == L'A');
+
+ /* Latin letter A. */
+ memset(&s, 0, sizeof(s));
+ ATF_REQUIRE(mbrtowc(&wc, buf, 1, &s) == 1);
+ ATF_REQUIRE(wc == L'A');
+
+ /* Incomplete character sequence (zero length). */
+ wc = L'z';
+ memset(&s, 0, sizeof(s));
+ ATF_REQUIRE(mbrtowc(&wc, buf, 0, &s) == (size_t)-2);
+ ATF_REQUIRE(wc == L'z');
+
+ /* Incomplete character sequence (truncated double-byte). */
+ memset(buf, 0xcc, sizeof(buf));
+ buf[0] = 0xa3;
+ buf[1] = 0x00;
+ memset(&s, 0, sizeof(s));
+ wc = 0;
+ ATF_REQUIRE(mbrtowc(&wc, buf, 1, &s) == (size_t)-2);
+
+ /* Same as above, but complete. */
+ buf[1] = 0xc1;
+ memset(&s, 0, sizeof(s));
+ wc = 0;
+ ATF_REQUIRE(mbrtowc(&wc, buf, 2, &s) == 2);
+ ATF_REQUIRE(wc == 0xa3c1);
+
+ /* Test restarting behaviour. */
+ memset(buf, 0xcc, sizeof(buf));
+ buf[0] = 0xa3;
+ memset(&s, 0, sizeof(s));
+ wc = 0;
+ ATF_REQUIRE(mbrtowc(&wc, buf, 1, &s) == (size_t)-2);
+ ATF_REQUIRE(wc == 0);
+ buf[0] = 0xc1;
+ ATF_REQUIRE(mbrtowc(&wc, buf, 1, &s) == 1);
+ ATF_REQUIRE(wc == 0xa3c1);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, mbrtowc_test);
+
+ return (atf_no_error());
+}
Property changes on: trunk/lib/libc/tests/locale/mbrtowc_test.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/locale/mbsnrtowcs_test.c
===================================================================
--- trunk/lib/libc/tests/locale/mbsnrtowcs_test.c (rev 0)
+++ trunk/lib/libc/tests/locale/mbsnrtowcs_test.c 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,196 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2002-2004 Tim J. Robbins
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Test program for mbsnrtowcs().
+ *
+ * The function is tested with both the "C" ("POSIX") LC_CTYPE setting and
+ * "ja_JP.eucJP". Other encodings are not tested.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/lib/libc/tests/locale/mbsnrtowcs_test.c 291178 2015-11-23 08:31:41Z ngie $");
+
+#include <errno.h>
+#include <limits.h>
+#include <locale.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <wchar.h>
+
+#include <atf-c.h>
+
+ATF_TC_WITHOUT_HEAD(mbsnrtowcs_test);
+ATF_TC_BODY(mbsnrtowcs_test, tc)
+{
+ char srcbuf[128];
+ wchar_t dstbuf[128];
+ char *src;
+ mbstate_t s;
+
+ /* C/POSIX locale. */
+
+ /* Simple null terminated string. */
+ memset(srcbuf, 0xcc, sizeof(srcbuf));
+ strcpy(srcbuf, "hello");
+ wmemset(dstbuf, 0xcccc, sizeof(dstbuf) / sizeof(*dstbuf));
+ src = srcbuf;
+ memset(&s, 0, sizeof(s));
+ ATF_REQUIRE(mbsnrtowcs(dstbuf, (const char **)&src, 6, sizeof(dstbuf) /
+ sizeof(*dstbuf), &s) == 5);
+ ATF_REQUIRE(wcscmp(dstbuf, L"hello") == 0);
+ ATF_REQUIRE(dstbuf[6] == 0xcccc);
+ ATF_REQUIRE(src == NULL);
+
+ /* Simple null terminated string, stopping early. */
+ memset(srcbuf, 0xcc, sizeof(srcbuf));
+ strcpy(srcbuf, "hello");
+ wmemset(dstbuf, 0xcccc, sizeof(dstbuf) / sizeof(*dstbuf));
+ src = srcbuf;
+ memset(&s, 0, sizeof(s));
+ ATF_REQUIRE(mbsnrtowcs(dstbuf, (const char **)&src, 4, sizeof(dstbuf) /
+ sizeof(*dstbuf), &s) == 4);
+ ATF_REQUIRE(wmemcmp(dstbuf, L"hell", 4) == 0);
+ ATF_REQUIRE(dstbuf[5] == 0xcccc);
+ ATF_REQUIRE(src == srcbuf + 4);
+
+ /* Not enough space in destination buffer. */
+ memset(srcbuf, 0xcc, sizeof(srcbuf));
+ strcpy(srcbuf, "hello");
+ wmemset(dstbuf, 0xcccc, sizeof(dstbuf) / sizeof(*dstbuf));
+ src = srcbuf;
+ memset(&s, 0, sizeof(s));
+ ATF_REQUIRE(mbsnrtowcs(dstbuf, (const char **)&src, 6, 4, &s) == 4);
+ ATF_REQUIRE(wmemcmp(dstbuf, L"hell", 4) == 0);
+ ATF_REQUIRE(dstbuf[5] == 0xcccc);
+ ATF_REQUIRE(src == srcbuf + 4);
+
+ /* Null terminated string, internal dest. buffer */
+ memset(srcbuf, 0xcc, sizeof(srcbuf));
+ strcpy(srcbuf, "hello");
+ src = srcbuf;
+ memset(&s, 0, sizeof(s));
+ ATF_REQUIRE(mbsnrtowcs(NULL, (const char **)&src, 6, 0, &s) == 5);
+
+ /* Null terminated string, internal dest. buffer, stopping early */
+ memset(srcbuf, 0xcc, sizeof(srcbuf));
+ strcpy(srcbuf, "hello");
+ src = srcbuf;
+ memset(&s, 0, sizeof(s));
+ ATF_REQUIRE(mbsnrtowcs(NULL, (const char **)&src, 4, 0, &s) == 4);
+
+ /* Null terminated string, internal state. */
+ memset(srcbuf, 0xcc, sizeof(srcbuf));
+ strcpy(srcbuf, "hello");
+ wmemset(dstbuf, 0xcccc, sizeof(dstbuf) / sizeof(*dstbuf));
+ src = srcbuf;
+ ATF_REQUIRE(mbsnrtowcs(dstbuf, (const char **)&src, 6, sizeof(dstbuf) /
+ sizeof(*dstbuf), NULL) == 5);
+ ATF_REQUIRE(wcscmp(dstbuf, L"hello") == 0);
+ ATF_REQUIRE(dstbuf[6] == 0xcccc);
+ ATF_REQUIRE(src == NULL);
+
+ /* Null terminated string, internal state, internal dest. buffer. */
+ memset(srcbuf, 0xcc, sizeof(srcbuf));
+ strcpy(srcbuf, "hello");
+ src = srcbuf;
+ ATF_REQUIRE(mbsnrtowcs(NULL, (const char **)&src, 6, 0, NULL) == 5);
+
+ /* Empty source buffer. */
+ memset(srcbuf, 0xcc, sizeof(srcbuf));
+ srcbuf[0] = '\0';
+ src = srcbuf;
+ memset(&s, 0, sizeof(s));
+ wmemset(dstbuf, 0xcccc, sizeof(dstbuf) / sizeof(*dstbuf));
+ ATF_REQUIRE(mbsnrtowcs(dstbuf, (const char **)&src, 1, 1, &s) == 0);
+ ATF_REQUIRE(dstbuf[0] == 0);
+ ATF_REQUIRE(dstbuf[1] == 0xcccc);
+ ATF_REQUIRE(src == NULL);
+
+ /* Zero length destination buffer. */
+ memset(srcbuf, 0xcc, sizeof(srcbuf));
+ strcpy(srcbuf, "hello");
+ src = srcbuf;
+ memset(&s, 0, sizeof(s));
+ wmemset(dstbuf, 0xcccc, sizeof(dstbuf) / sizeof(*dstbuf));
+ ATF_REQUIRE(mbsnrtowcs(dstbuf, (const char **)&src, 1, 0, &s) == 0);
+ ATF_REQUIRE(dstbuf[0] == 0xcccc);
+ ATF_REQUIRE(src == srcbuf);
+
+ /* Zero length source buffer. */
+ memset(srcbuf, 0xcc, sizeof(srcbuf));
+ src = srcbuf;
+ memset(&s, 0, sizeof(s));
+ wmemset(dstbuf, 0xcccc, sizeof(dstbuf) / sizeof(*dstbuf));
+ ATF_REQUIRE(mbsnrtowcs(dstbuf, (const char **)&src, 0, 1, &s) == 0);
+ ATF_REQUIRE(dstbuf[0] == 0xcccc);
+ ATF_REQUIRE(src == srcbuf);
+
+ /*
+ * Japanese (EUC) locale.
+ */
+
+ ATF_REQUIRE(strcmp(setlocale(LC_CTYPE, "ja_JP.eucJP"), "ja_JP.eucJP") == 0);
+ ATF_REQUIRE(MB_CUR_MAX > 1);
+
+ memset(srcbuf, 0xcc, sizeof(srcbuf));
+ strcpy(srcbuf, "\xA3\xC1 B \xA3\xC3");
+ src = srcbuf;
+ memset(&s, 0, sizeof(s));
+ wmemset(dstbuf, 0xcccc, sizeof(dstbuf) / sizeof(*dstbuf));
+ ATF_REQUIRE(mbsnrtowcs(dstbuf, (const char **)&src, 8, sizeof(dstbuf) /
+ sizeof(*dstbuf), &s) == 5);
+ ATF_REQUIRE(dstbuf[0] == 0xA3C1 && dstbuf[1] == 0x20 && dstbuf[2] == 0x42 &&
+ dstbuf[3] == 0x20 && dstbuf[4] == 0xA3C3 && dstbuf[5] == 0);
+ ATF_REQUIRE(src == NULL);
+
+ /* Partial character. */
+ memset(srcbuf, 0xcc, sizeof(srcbuf));
+ strcpy(srcbuf, "\xA3\xC1 B \xA3\xC3");
+ src = srcbuf;
+ memset(&s, 0, sizeof(s));
+ wmemset(dstbuf, 0xcccc, sizeof(dstbuf) / sizeof(*dstbuf));
+ ATF_REQUIRE(mbsnrtowcs(dstbuf, (const char **)&src, 6, sizeof(dstbuf) /
+ sizeof(*dstbuf), &s) == 4);
+ ATF_REQUIRE(src == srcbuf + 6);
+ ATF_REQUIRE(!mbsinit(&s));
+ ATF_REQUIRE(mbsnrtowcs(dstbuf, (const char **)&src, 1, sizeof(dstbuf) /
+ sizeof(*dstbuf), &s) == 1);
+ ATF_REQUIRE(src == srcbuf + 7);
+ ATF_REQUIRE(mbsnrtowcs(dstbuf, (const char **)&src, 1, sizeof(dstbuf) /
+ sizeof(*dstbuf), &s) == 0);
+ ATF_REQUIRE(src == NULL);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, mbsnrtowcs_test);
+
+ return (atf_no_error());
+}
Property changes on: trunk/lib/libc/tests/locale/mbsnrtowcs_test.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/locale/mbsrtowcs_test.c
===================================================================
--- trunk/lib/libc/tests/locale/mbsrtowcs_test.c (rev 0)
+++ trunk/lib/libc/tests/locale/mbsrtowcs_test.c 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,154 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2002 Tim J. Robbins
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Test program for mbsrtowcs(), as specified by IEEE Std. 1003.1-2001 and
+ * ISO/IEC 9899:1999.
+ *
+ * The function is tested with both the "C" ("POSIX") LC_CTYPE setting and
+ * "ja_JP.eucJP". Other encodings are not tested.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/lib/libc/tests/locale/mbsrtowcs_test.c 291178 2015-11-23 08:31:41Z ngie $");
+
+#include <errno.h>
+#include <limits.h>
+#include <locale.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <wchar.h>
+
+#include <atf-c.h>
+
+ATF_TC_WITHOUT_HEAD(mbsrtowcs_test);
+ATF_TC_BODY(mbsrtowcs_test, tc)
+{
+ char srcbuf[128];
+ wchar_t dstbuf[128];
+ char *src;
+ mbstate_t s;
+
+ /*
+ * C/POSIX locale.
+ */
+
+ /* Simple null terminated string. */
+ memset(srcbuf, 0xcc, sizeof(srcbuf));
+ strcpy(srcbuf, "hello");
+ wmemset(dstbuf, 0xcccc, sizeof(dstbuf) / sizeof(*dstbuf));
+ src = srcbuf;
+ memset(&s, 0, sizeof(s));
+ ATF_REQUIRE(mbsrtowcs(dstbuf, (const char **)&src, sizeof(dstbuf) /
+ sizeof(*dstbuf), &s) == 5);
+ ATF_REQUIRE(wcscmp(dstbuf, L"hello") == 0);
+ ATF_REQUIRE(dstbuf[6] == 0xcccc);
+ ATF_REQUIRE(src == NULL);
+
+ /* Not enough space in destination buffer. */
+ memset(srcbuf, 0xcc, sizeof(srcbuf));
+ strcpy(srcbuf, "hello");
+ wmemset(dstbuf, 0xcccc, sizeof(dstbuf) / sizeof(*dstbuf));
+ src = srcbuf;
+ memset(&s, 0, sizeof(s));
+ ATF_REQUIRE(mbsrtowcs(dstbuf, (const char **)&src, 4, &s) == 4);
+ ATF_REQUIRE(wmemcmp(dstbuf, L"hell", 4) == 0);
+ ATF_REQUIRE(dstbuf[5] == 0xcccc);
+ ATF_REQUIRE(src == srcbuf + 4);
+
+ /* Null terminated string, internal dest. buffer */
+ memset(srcbuf, 0xcc, sizeof(srcbuf));
+ strcpy(srcbuf, "hello");
+ src = srcbuf;
+ memset(&s, 0, sizeof(s));
+ ATF_REQUIRE(mbsrtowcs(NULL, (const char **)&src, 0, &s) == 5);
+
+ /* Null terminated string, internal state. */
+ memset(srcbuf, 0xcc, sizeof(srcbuf));
+ strcpy(srcbuf, "hello");
+ wmemset(dstbuf, 0xcccc, sizeof(dstbuf) / sizeof(*dstbuf));
+ src = srcbuf;
+ ATF_REQUIRE(mbsrtowcs(dstbuf, (const char **)&src, sizeof(dstbuf) /
+ sizeof(*dstbuf), NULL) == 5);
+ ATF_REQUIRE(wcscmp(dstbuf, L"hello") == 0);
+ ATF_REQUIRE(dstbuf[6] == 0xcccc);
+ ATF_REQUIRE(src == NULL);
+
+ /* Null terminated string, internal state, internal dest. buffer. */
+ memset(srcbuf, 0xcc, sizeof(srcbuf));
+ strcpy(srcbuf, "hello");
+ src = srcbuf;
+ ATF_REQUIRE(mbsrtowcs(NULL, (const char **)&src, 0, NULL) == 5);
+
+ /* Empty source buffer. */
+ memset(srcbuf, 0xcc, sizeof(srcbuf));
+ srcbuf[0] = '\0';
+ src = srcbuf;
+ memset(&s, 0, sizeof(s));
+ wmemset(dstbuf, 0xcccc, sizeof(dstbuf) / sizeof(*dstbuf));
+ ATF_REQUIRE(mbsrtowcs(dstbuf, (const char **)&src, 1, &s) == 0);
+ ATF_REQUIRE(dstbuf[0] == 0);
+ ATF_REQUIRE(dstbuf[1] == 0xcccc);
+ ATF_REQUIRE(src == NULL);
+
+ /* Zero length destination buffer. */
+ memset(srcbuf, 0xcc, sizeof(srcbuf));
+ strcpy(srcbuf, "hello");
+ src = srcbuf;
+ memset(&s, 0, sizeof(s));
+ wmemset(dstbuf, 0xcccc, sizeof(dstbuf) / sizeof(*dstbuf));
+ ATF_REQUIRE(mbsrtowcs(dstbuf, (const char **)&src, 0, &s) == 0);
+ ATF_REQUIRE(dstbuf[0] == 0xcccc);
+ ATF_REQUIRE(src == srcbuf);
+
+ /*
+ * Japanese (EUC) locale.
+ */
+
+ ATF_REQUIRE(strcmp(setlocale(LC_CTYPE, "ja_JP.eucJP"), "ja_JP.eucJP") == 0);
+ ATF_REQUIRE(MB_CUR_MAX > 1);
+
+ memset(srcbuf, 0xcc, sizeof(srcbuf));
+ strcpy(srcbuf, "\xA3\xC1 B \xA3\xC3");
+ src = srcbuf;
+ memset(&s, 0, sizeof(s));
+ wmemset(dstbuf, 0xcccc, sizeof(dstbuf) / sizeof(*dstbuf));
+ ATF_REQUIRE(mbsrtowcs(dstbuf, (const char **)&src, sizeof(dstbuf) /
+ sizeof(*dstbuf), &s) == 5);
+ ATF_REQUIRE(dstbuf[0] == 0xA3C1 && dstbuf[1] == 0x20 && dstbuf[2] == 0x42 &&
+ dstbuf[3] == 0x20 && dstbuf[4] == 0xA3C3 && dstbuf[5] == 0);
+ ATF_REQUIRE(src == NULL);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, mbsrtowcs_test);
+
+ return (atf_no_error());
+}
Property changes on: trunk/lib/libc/tests/locale/mbsrtowcs_test.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/locale/mbstowcs_test.c
===================================================================
--- trunk/lib/libc/tests/locale/mbstowcs_test.c (rev 0)
+++ trunk/lib/libc/tests/locale/mbstowcs_test.c 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,112 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2002 Tim J. Robbins
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Test program for mbstowcs(), as specified by IEEE Std. 1003.1-2001 and
+ * ISO/IEC 9899:1999.
+ *
+ * The function is tested with both the "C" ("POSIX") LC_CTYPE setting and
+ * "ja_JP.eucJP". Other encodings are not tested.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/lib/libc/tests/locale/mbstowcs_test.c 291178 2015-11-23 08:31:41Z ngie $");
+
+#include <errno.h>
+#include <limits.h>
+#include <locale.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <wchar.h>
+
+#include <atf-c.h>
+
+ATF_TC_WITHOUT_HEAD(mbstowcs_test);
+ATF_TC_BODY(mbstowcs_test, tc)
+{
+ char srcbuf[128];
+ wchar_t dstbuf[128];
+
+ /* C/POSIX locale. */
+
+ /* Simple null terminated string. */
+ memset(srcbuf, 0xcc, sizeof(srcbuf));
+ strcpy(srcbuf, "hello");
+ wmemset(dstbuf, 0xcccc, sizeof(dstbuf) / sizeof(*dstbuf));
+ ATF_REQUIRE(mbstowcs(dstbuf, srcbuf, sizeof(dstbuf) / sizeof(*dstbuf)) == 5);
+ ATF_REQUIRE(wcscmp(dstbuf, L"hello") == 0);
+ ATF_REQUIRE(dstbuf[6] == 0xcccc);
+
+ /* Not enough space in destination buffer. */
+ memset(srcbuf, 0xcc, sizeof(srcbuf));
+ strcpy(srcbuf, "hello");
+ wmemset(dstbuf, 0xcccc, sizeof(dstbuf) / sizeof(*dstbuf));
+ ATF_REQUIRE(mbstowcs(dstbuf, srcbuf, 4) == 4);
+ ATF_REQUIRE(wmemcmp(dstbuf, L"hell", 4) == 0);
+ ATF_REQUIRE(dstbuf[5] == 0xcccc);
+
+ /* Null terminated string, internal dest. buffer (XSI extension) */
+ memset(srcbuf, 0xcc, sizeof(srcbuf));
+ strcpy(srcbuf, "hello");
+ ATF_REQUIRE(mbstowcs(NULL, srcbuf, 0) == 5);
+
+ /* Empty source buffer. */
+ memset(srcbuf, 0xcc, sizeof(srcbuf));
+ srcbuf[0] = '\0';
+ wmemset(dstbuf, 0xcccc, sizeof(dstbuf) / sizeof(*dstbuf));
+ ATF_REQUIRE(mbstowcs(dstbuf, srcbuf, 1) == 0);
+ ATF_REQUIRE(dstbuf[0] == 0);
+ ATF_REQUIRE(dstbuf[1] == 0xcccc);
+
+ /* Zero length destination buffer. */
+ memset(srcbuf, 0xcc, sizeof(srcbuf));
+ strcpy(srcbuf, "hello");
+ wmemset(dstbuf, 0xcccc, sizeof(dstbuf) / sizeof(*dstbuf));
+ ATF_REQUIRE(mbstowcs(dstbuf, srcbuf, 0) == 0);
+ ATF_REQUIRE(dstbuf[0] == 0xcccc);
+
+ /* Japanese (EUC) locale. */
+
+ ATF_REQUIRE(strcmp(setlocale(LC_CTYPE, "ja_JP.eucJP"), "ja_JP.eucJP") == 0);
+ ATF_REQUIRE(MB_CUR_MAX > 1);
+
+ memset(srcbuf, 0xcc, sizeof(srcbuf));
+ strcpy(srcbuf, "\xA3\xC1 B \xA3\xC3");
+ wmemset(dstbuf, 0xcccc, sizeof(dstbuf) / sizeof(*dstbuf));
+ ATF_REQUIRE(mbstowcs(dstbuf, srcbuf, sizeof(dstbuf) / sizeof(*dstbuf)) == 5);
+ ATF_REQUIRE(dstbuf[0] == 0xA3C1 && dstbuf[1] == 0x20 && dstbuf[2] == 0x42 &&
+ dstbuf[3] == 0x20 && dstbuf[4] == 0xA3C3 && dstbuf[5] == 0);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, mbstowcs_test);
+
+ return (atf_no_error());
+}
Property changes on: trunk/lib/libc/tests/locale/mbstowcs_test.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/locale/mbtowc_test.c
===================================================================
--- trunk/lib/libc/tests/locale/mbtowc_test.c (rev 0)
+++ trunk/lib/libc/tests/locale/mbtowc_test.c 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,123 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2002-2004 Tim J. Robbins
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Test program for mbtowc(), as specified by IEEE Std. 1003.1-2001 and
+ * ISO/IEC 9899:1990.
+ *
+ * The function is tested with both the "C" ("POSIX") LC_CTYPE setting and
+ * "ja_JP.eucJP". Other encodings are not tested.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/lib/libc/tests/locale/mbtowc_test.c 291178 2015-11-23 08:31:41Z ngie $");
+
+#include <limits.h>
+#include <locale.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <atf-c.h>
+
+ATF_TC_WITHOUT_HEAD(mbtowc_test);
+ATF_TC_BODY(mbtowc_test, tc)
+{
+ char buf[MB_LEN_MAX + 1];
+ wchar_t wc;
+
+ /* C/POSIX locale. */
+
+ ATF_REQUIRE(MB_CUR_MAX == 1);
+
+ /* No shift states in C locale. */
+ ATF_REQUIRE(mbtowc(NULL, NULL, 0) == 0);
+
+ /* Null wide character. */
+ wc = 0xcccc;
+ memset(buf, 0, sizeof(buf));
+ ATF_REQUIRE(mbtowc(&wc, buf, 1) == 0);
+ ATF_REQUIRE(wc == 0);
+
+ /* Latin letter A. */
+ buf[0] = 'A';
+ ATF_REQUIRE(mbtowc(&wc, buf, 1) == 1);
+ ATF_REQUIRE(wc == L'A');
+
+ /* Incomplete character sequence. */
+ wc = L'z';
+ buf[0] = '\0';
+ ATF_REQUIRE(mbtowc(&wc, buf, 0) == -1);
+ ATF_REQUIRE(wc == L'z');
+ ATF_REQUIRE(mbtowc(NULL, NULL, 0) == 0);
+
+ /* Japanese (EUC) locale. */
+
+ ATF_REQUIRE(strcmp(setlocale(LC_CTYPE, "ja_JP.eucJP"), "ja_JP.eucJP") == 0);
+ ATF_REQUIRE(MB_CUR_MAX > 1);
+
+ /* Null wide character */
+ memset(buf, 0xcc, sizeof(buf));
+ buf[0] = 0;
+ wc = 0xcccc;
+ ATF_REQUIRE(mbtowc(&wc, buf, 1) == 0);
+ ATF_REQUIRE(wc == 0);
+
+ /* Latin letter A. */
+ buf[0] = 'A';
+ ATF_REQUIRE(mbtowc(&wc, buf, 1) == 1);
+ ATF_REQUIRE(wc == L'A');
+
+ /* Incomplete character sequence (zero length). */
+ wc = L'z';
+ buf[0] = '\0';
+ ATF_REQUIRE(mbtowc(&wc, buf, 0) == -1);
+ ATF_REQUIRE(wc == L'z');
+ ATF_REQUIRE(mbtowc(NULL, NULL, 0) == 0);
+
+ /* Incomplete character sequence (truncated double-byte). */
+ memset(buf, 0xcc, sizeof(buf));
+ buf[0] = 0xa3;
+ buf[1] = 0x00;
+ wc = L'z';
+ ATF_REQUIRE(mbtowc(&wc, buf, 1) == -1);
+ ATF_REQUIRE(wc == L'z');
+ ATF_REQUIRE(mbtowc(NULL, NULL, 0) == 0);
+
+ /* Same as above, but complete. */
+ buf[1] = 0xc1;
+ ATF_REQUIRE(mbtowc(&wc, buf, 2) == 2);
+ ATF_REQUIRE(wc == 0xa3c1);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, mbtowc_test);
+
+ return (atf_no_error());
+}
Property changes on: trunk/lib/libc/tests/locale/mbtowc_test.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/locale/towctrans_test.c
===================================================================
--- trunk/lib/libc/tests/locale/towctrans_test.c (rev 0)
+++ trunk/lib/libc/tests/locale/towctrans_test.c 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,91 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2003 Tim J. Robbins
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Test program for wctrans() and towctrans() as specified by
+ * IEEE Std. 1003.1-2001 and ISO/IEC 9899:1999.
+ *
+ * The functions are tested in the "C" and "ja_JP.eucJP" locales.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/lib/libc/tests/locale/towctrans_test.c 291178 2015-11-23 08:31:41Z ngie $");
+
+#include <locale.h>
+#include <stdio.h>
+#include <string.h>
+#include <wchar.h>
+#include <wctype.h>
+
+#include <atf-c.h>
+
+ATF_TC_WITHOUT_HEAD(towctrans_test);
+ATF_TC_BODY(towctrans_test, tc)
+{
+ wctype_t t;
+ int i, j;
+ struct {
+ const char *name;
+ wint_t (*func)(wint_t);
+ } tran[] = {
+ { "tolower", towlower },
+ { "toupper", towupper },
+ };
+
+ /* C/POSIX locale. */
+ for (i = 0; i < sizeof(tran) / sizeof(*tran); i++) {
+ t = wctrans(tran[i].name);
+ ATF_REQUIRE(t != 0);
+ for (j = 0; j < 256; j++)
+ ATF_REQUIRE(tran[i].func(j) == towctrans(j, t));
+ }
+ t = wctrans("elephant");
+ ATF_REQUIRE(t == 0);
+ for (i = 0; i < 256; i++)
+ ATF_REQUIRE(towctrans(i, t) == i);
+
+ /* Japanese (EUC) locale. */
+ ATF_REQUIRE(strcmp(setlocale(LC_CTYPE, "ja_JP.eucJP"), "ja_JP.eucJP") == 0);
+ for (i = 0; i < sizeof(tran) / sizeof(*tran); i++) {
+ t = wctrans(tran[i].name);
+ ATF_REQUIRE(t != 0);
+ for (j = 0; j < 65536; j++)
+ ATF_REQUIRE(tran[i].func(j) == towctrans(j, t));
+ }
+ t = wctrans("elephant");
+ ATF_REQUIRE(t == 0);
+ for (i = 0; i < 65536; i++)
+ ATF_REQUIRE(towctrans(i, t) == i);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, towctrans_test);
+
+ return (atf_no_error());
+}
Property changes on: trunk/lib/libc/tests/locale/towctrans_test.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/locale/wcrtomb_test.c
===================================================================
--- trunk/lib/libc/tests/locale/wcrtomb_test.c (rev 0)
+++ trunk/lib/libc/tests/locale/wcrtomb_test.c 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,136 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2002 Tim J. Robbins
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Test program for wcrtomb(), as specified by IEEE Std. 1003.1-2001 and
+ * ISO/IEC 9899:1999.
+ *
+ * The function is tested with both the "C" ("POSIX") LC_CTYPE setting and
+ * "ja_JP.eucJP". Other encodings are not tested.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/lib/libc/tests/locale/wcrtomb_test.c 291178 2015-11-23 08:31:41Z ngie $");
+
+#include <errno.h>
+#include <limits.h>
+#include <locale.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <wchar.h>
+
+#include <atf-c.h>
+
+ATF_TC_WITHOUT_HEAD(wcrtomb_test);
+ATF_TC_BODY(wcrtomb_test, tc)
+{
+ mbstate_t s;
+ size_t len;
+ char buf[MB_LEN_MAX + 1];
+
+ /* C/POSIX locale. */
+
+ ATF_REQUIRE(MB_CUR_MAX == 1);
+
+ /*
+ * If the buffer argument is NULL, wc is implicitly L'\0',
+ * wcrtomb() resets its internal state.
+ */
+ ATF_REQUIRE(wcrtomb(NULL, L'\0', NULL) == 1);
+ ATF_REQUIRE(wcrtomb(NULL, UCHAR_MAX + 1, NULL) == 1);
+
+ /* Null wide character. */
+ memset(&s, 0, sizeof(s));
+ memset(buf, 0xcc, sizeof(buf));
+ len = wcrtomb(buf, L'\0', &s);
+ ATF_REQUIRE(len == 1);
+ ATF_REQUIRE((unsigned char)buf[0] == 0 && (unsigned char)buf[1] == 0xcc);
+
+ /* Latin letter A, internal state. */
+ ATF_REQUIRE(wcrtomb(NULL, L'\0', NULL) == 1);
+ ATF_REQUIRE(wcrtomb(NULL, L'A', NULL) == 1);
+
+ /* Latin letter A. */
+ memset(&s, 0, sizeof(s));
+ memset(buf, 0xcc, sizeof(buf));
+ len = wcrtomb(buf, L'A', &s);
+ ATF_REQUIRE(len == 1);
+ ATF_REQUIRE((unsigned char)buf[0] == 'A' && (unsigned char)buf[1] == 0xcc);
+
+ /* Invalid code. */
+ ATF_REQUIRE(wcrtomb(buf, UCHAR_MAX + 1, NULL) == (size_t)-1);
+ ATF_REQUIRE(errno == EILSEQ);
+
+ /*
+ * Japanese (EUC) locale.
+ */
+
+ ATF_REQUIRE(strcmp(setlocale(LC_CTYPE, "ja_JP.eucJP"), "ja_JP.eucJP") == 0);
+ ATF_REQUIRE(MB_CUR_MAX == 3);
+
+ /*
+ * If the buffer argument is NULL, wc is implicitly L'\0',
+ * wcrtomb() resets its internal state.
+ */
+ ATF_REQUIRE(wcrtomb(NULL, L'\0', NULL) == 1);
+
+ /* Null wide character. */
+ memset(&s, 0, sizeof(s));
+ memset(buf, 0xcc, sizeof(buf));
+ len = wcrtomb(buf, L'\0', &s);
+ ATF_REQUIRE(len == 1);
+ ATF_REQUIRE((unsigned char)buf[0] == 0 && (unsigned char)buf[1] == 0xcc);
+
+ /* Latin letter A, internal state. */
+ ATF_REQUIRE(wcrtomb(NULL, L'\0', NULL) == 1);
+ ATF_REQUIRE(wcrtomb(NULL, L'A', NULL) == 1);
+
+ /* Latin letter A. */
+ memset(&s, 0, sizeof(s));
+ memset(buf, 0xcc, sizeof(buf));
+ len = wcrtomb(buf, L'A', &s);
+ ATF_REQUIRE(len == 1);
+ ATF_REQUIRE((unsigned char)buf[0] == 'A' && (unsigned char)buf[1] == 0xcc);
+
+ /* Full width letter A. */
+ memset(&s, 0, sizeof(s));
+ memset(buf, 0xcc, sizeof(buf));
+ len = wcrtomb(buf, 0xa3c1, &s);
+ ATF_REQUIRE(len == 2);
+ ATF_REQUIRE((unsigned char)buf[0] == 0xa3 &&
+ (unsigned char)buf[1] == 0xc1 &&
+ (unsigned char)buf[2] == 0xcc);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, wcrtomb_test);
+
+ return (atf_no_error());
+}
Property changes on: trunk/lib/libc/tests/locale/wcrtomb_test.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/locale/wcsnrtombs_test.c
===================================================================
--- trunk/lib/libc/tests/locale/wcsnrtombs_test.c (rev 0)
+++ trunk/lib/libc/tests/locale/wcsnrtombs_test.c 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,196 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2002-2004 Tim J. Robbins
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Test program for wcsnrtombs().
+ *
+ * The function is tested with both the "C" ("POSIX") LC_CTYPE setting and
+ * "ja_JP.eucJP". Other encodings are not tested.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/lib/libc/tests/locale/wcsnrtombs_test.c 291178 2015-11-23 08:31:41Z ngie $");
+
+#include <errno.h>
+#include <limits.h>
+#include <locale.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <wchar.h>
+
+#include <atf-c.h>
+
+ATF_TC_WITHOUT_HEAD(wcsnrtombs_test);
+ATF_TC_BODY(wcsnrtombs_test, tc)
+{
+ wchar_t srcbuf[128];
+ char dstbuf[128];
+ wchar_t *src;
+ mbstate_t s;
+
+ /* C/POSIX locale. */
+
+ /* Simple null terminated string. */
+ wmemset(srcbuf, 0xcc, sizeof(srcbuf) / sizeof(*srcbuf));
+ wcscpy(srcbuf, L"hello");
+ memset(dstbuf, 0xcc, sizeof(dstbuf));
+ src = srcbuf;
+ memset(&s, 0, sizeof(s));
+ ATF_REQUIRE(wcsnrtombs(dstbuf, (const wchar_t **)&src, 6, sizeof(dstbuf),
+ &s) == 5);
+ ATF_REQUIRE(strcmp(dstbuf, "hello") == 0);
+ ATF_REQUIRE((unsigned char)dstbuf[6] == 0xcc);
+ ATF_REQUIRE(src == NULL);
+
+ /* Simple null terminated string, stopping early. */
+ wmemset(srcbuf, 0xcc, sizeof(srcbuf) / sizeof(*srcbuf));
+ wcscpy(srcbuf, L"hello");
+ memset(dstbuf, 0xcc, sizeof(dstbuf));
+ src = srcbuf;
+ memset(&s, 0, sizeof(s));
+ ATF_REQUIRE(wcsnrtombs(dstbuf, (const wchar_t **)&src, 4, sizeof(dstbuf),
+ &s) == 4);
+ ATF_REQUIRE(memcmp(dstbuf, "hell", 4) == 0);
+ ATF_REQUIRE((unsigned char)dstbuf[5] == 0xcc);
+ ATF_REQUIRE(src == srcbuf + 4);
+
+ /* Not enough space in destination buffer. */
+ wmemset(srcbuf, 0xcc, sizeof(srcbuf) / sizeof(*srcbuf));
+ wcscpy(srcbuf, L"hello");
+ memset(dstbuf, 0xcc, sizeof(dstbuf));
+ src = srcbuf;
+ memset(&s, 0, sizeof(s));
+ ATF_REQUIRE(wcsnrtombs(dstbuf, (const wchar_t **)&src, 6, 4,
+ &s) == 4);
+ ATF_REQUIRE(memcmp(dstbuf, "hell", 4) == 0);
+ ATF_REQUIRE((unsigned char)dstbuf[5] == 0xcc);
+ ATF_REQUIRE(src == srcbuf + 4);
+
+ /* Null terminated string, internal dest. buffer */
+ wmemset(srcbuf, 0xcc, sizeof(srcbuf) / sizeof(*srcbuf));
+ wcscpy(srcbuf, L"hello");
+ src = srcbuf;
+ memset(&s, 0, sizeof(s));
+ ATF_REQUIRE(wcsnrtombs(NULL, (const wchar_t **)&src, 6, sizeof(dstbuf),
+ &s) == 5);
+
+ /* Null terminated string, internal dest. buffer, stopping early. */
+ wmemset(srcbuf, 0xcc, sizeof(srcbuf) / sizeof(*srcbuf));
+ wcscpy(srcbuf, L"hello");
+ src = srcbuf;
+ memset(&s, 0, sizeof(s));
+ ATF_REQUIRE(wcsnrtombs(NULL, (const wchar_t **)&src, 4, sizeof(dstbuf),
+ &s) == 4);
+
+ /* Null terminated string, internal state. */
+ wmemset(srcbuf, 0xcc, sizeof(srcbuf) / sizeof(*srcbuf));
+ wcscpy(srcbuf, L"hello");
+ memset(dstbuf, 0xcc, sizeof(dstbuf));
+ src = srcbuf;
+ ATF_REQUIRE(wcsnrtombs(dstbuf, (const wchar_t **)&src, 6, sizeof(dstbuf),
+ NULL) == 5);
+ ATF_REQUIRE(strcmp(dstbuf, "hello") == 0);
+ ATF_REQUIRE((unsigned char)dstbuf[6] == 0xcc);
+ ATF_REQUIRE(src == NULL);
+
+ /* Null terminated string, internal state, internal dest. buffer. */
+ wmemset(srcbuf, 0xcc, sizeof(srcbuf) / sizeof(*srcbuf));
+ wcscpy(srcbuf, L"hello");
+ src = srcbuf;
+ ATF_REQUIRE(wcsnrtombs(NULL, (const wchar_t **)&src, 6, 0, NULL) == 5);
+
+ /* Empty source buffer. */
+ wmemset(srcbuf, 0xcc, sizeof(srcbuf) / sizeof(*srcbuf));
+ srcbuf[0] = L'\0';
+ memset(dstbuf, 0xcc, sizeof(dstbuf));
+ src = srcbuf;
+ memset(&s, 0, sizeof(s));
+ ATF_REQUIRE(wcsnrtombs(dstbuf, (const wchar_t **)&src, 1, sizeof(dstbuf),
+ &s) == 0);
+ ATF_REQUIRE(dstbuf[0] == L'\0');
+
+ /* Zero length destination buffer. */
+ wmemset(srcbuf, 0xcc, sizeof(srcbuf) / sizeof(*srcbuf));
+ wcscpy(srcbuf, L"hello");
+ memset(dstbuf, 0xcc, sizeof(dstbuf));
+ src = srcbuf;
+ memset(&s, 0, sizeof(s));
+ ATF_REQUIRE(wcsnrtombs(dstbuf, (const wchar_t **)&src, 6, 0, &s) == 0);
+ ATF_REQUIRE((unsigned char)dstbuf[0] == 0xcc);
+
+ /* Zero length source buffer. */
+ wmemset(srcbuf, 0xcc, sizeof(srcbuf) / sizeof(*srcbuf));
+ memset(dstbuf, 0xcc, sizeof(dstbuf));
+ src = srcbuf;
+ memset(&s, 0, sizeof(s));
+ ATF_REQUIRE(wcsnrtombs(dstbuf, (const wchar_t **)&src, 0, sizeof(dstbuf),
+ &s) == 0);
+ ATF_REQUIRE((unsigned char)dstbuf[0] == 0xcc);
+ ATF_REQUIRE(src == srcbuf);
+
+ /*
+ * Japanese (EUC) locale.
+ */
+
+ ATF_REQUIRE(strcmp(setlocale(LC_CTYPE, "ja_JP.eucJP"), "ja_JP.eucJP") == 0);
+ ATF_REQUIRE(MB_CUR_MAX > 1);
+
+ wmemset(srcbuf, 0xcc, sizeof(srcbuf) / sizeof(*srcbuf));
+ srcbuf[0] = 0xA3C1;
+ srcbuf[1] = 0x0020;
+ srcbuf[2] = 0x0042;
+ srcbuf[3] = 0x0020;
+ srcbuf[4] = 0xA3C3;
+ srcbuf[5] = 0x0000;
+ memset(dstbuf, 0xcc, sizeof(dstbuf));
+ src = srcbuf;
+ memset(&s, 0, sizeof(s));
+ ATF_REQUIRE(wcsnrtombs(dstbuf, (const wchar_t **)&src, 6, sizeof(dstbuf),
+ &s) == 7);
+ ATF_REQUIRE(strcmp(dstbuf, "\xA3\xC1 B \xA3\xC3") == 0);
+ ATF_REQUIRE((unsigned char)dstbuf[8] == 0xcc);
+ ATF_REQUIRE(src == NULL);
+
+ /* Stopping early. */
+ memset(dstbuf, 0xcc, sizeof(dstbuf));
+ src = srcbuf;
+ memset(&s, 0, sizeof(s));
+ ATF_REQUIRE(wcsnrtombs(dstbuf, (const wchar_t **)&src, 6, 6,
+ &s) == 5);
+ ATF_REQUIRE(memcmp(dstbuf, "\xA3\xC1 B ", 5) == 0);
+ ATF_REQUIRE((unsigned char)dstbuf[5] == 0xcc);
+ ATF_REQUIRE(src == srcbuf + 4);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, wcsnrtombs_test);
+
+ return (atf_no_error());
+}
Property changes on: trunk/lib/libc/tests/locale/wcsnrtombs_test.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/locale/wcsrtombs_test.c
===================================================================
--- trunk/lib/libc/tests/locale/wcsrtombs_test.c (rev 0)
+++ trunk/lib/libc/tests/locale/wcsrtombs_test.c 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,157 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2002 Tim J. Robbins
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Test program for wcsrtombs(), as specified by IEEE Std. 1003.1-2001 and
+ * ISO/IEC 9899:1999.
+ *
+ * The function is tested with both the "C" ("POSIX") LC_CTYPE setting and
+ * "ja_JP.eucJP". Other encodings are not tested.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/lib/libc/tests/locale/wcsrtombs_test.c 291178 2015-11-23 08:31:41Z ngie $");
+
+#include <errno.h>
+#include <limits.h>
+#include <locale.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <wchar.h>
+
+#include <atf-c.h>
+
+ATF_TC_WITHOUT_HEAD(wcsrtombs_test);
+ATF_TC_BODY(wcsrtombs_test, tc)
+{
+ wchar_t srcbuf[128];
+ char dstbuf[128];
+ wchar_t *src;
+ mbstate_t s;
+
+ /* C/POSIX locale. */
+
+ /* Simple null terminated string. */
+ wmemset(srcbuf, 0xcc, sizeof(srcbuf) / sizeof(*srcbuf));
+ wcscpy(srcbuf, L"hello");
+ memset(dstbuf, 0xcc, sizeof(dstbuf));
+ src = srcbuf;
+ memset(&s, 0, sizeof(s));
+ ATF_REQUIRE(wcsrtombs(dstbuf, (const wchar_t **)&src, sizeof(dstbuf),
+ &s) == 5);
+ ATF_REQUIRE(strcmp(dstbuf, "hello") == 0);
+ ATF_REQUIRE((unsigned char)dstbuf[6] == 0xcc);
+ ATF_REQUIRE(src == NULL);
+
+ /* Not enough space in destination buffer. */
+ wmemset(srcbuf, 0xcc, sizeof(srcbuf) / sizeof(*srcbuf));
+ wcscpy(srcbuf, L"hello");
+ memset(dstbuf, 0xcc, sizeof(dstbuf));
+ src = srcbuf;
+ memset(&s, 0, sizeof(s));
+ ATF_REQUIRE(wcsrtombs(dstbuf, (const wchar_t **)&src, 4,
+ &s) == 4);
+ ATF_REQUIRE(memcmp(dstbuf, "hell", 4) == 0);
+ ATF_REQUIRE((unsigned char)dstbuf[5] == 0xcc);
+ ATF_REQUIRE(src == srcbuf + 4);
+
+ /* Null terminated string, internal dest. buffer */
+ wmemset(srcbuf, 0xcc, sizeof(srcbuf) / sizeof(*srcbuf));
+ wcscpy(srcbuf, L"hello");
+ src = srcbuf;
+ memset(&s, 0, sizeof(s));
+ ATF_REQUIRE(wcsrtombs(NULL, (const wchar_t **)&src, sizeof(dstbuf),
+ &s) == 5);
+
+ /* Null terminated string, internal state. */
+ wmemset(srcbuf, 0xcc, sizeof(srcbuf) / sizeof(*srcbuf));
+ wcscpy(srcbuf, L"hello");
+ memset(dstbuf, 0xcc, sizeof(dstbuf));
+ src = srcbuf;
+ ATF_REQUIRE(wcsrtombs(dstbuf, (const wchar_t **)&src, sizeof(dstbuf),
+ NULL) == 5);
+ ATF_REQUIRE(strcmp(dstbuf, "hello") == 0);
+ ATF_REQUIRE((unsigned char)dstbuf[6] == 0xcc);
+ ATF_REQUIRE(src == NULL);
+
+ /* Null terminated string, internal state, internal dest. buffer. */
+ wmemset(srcbuf, 0xcc, sizeof(srcbuf) / sizeof(*srcbuf));
+ wcscpy(srcbuf, L"hello");
+ src = srcbuf;
+ ATF_REQUIRE(wcsrtombs(NULL, (const wchar_t **)&src, 0, NULL) == 5);
+
+ /* Empty source buffer. */
+ wmemset(srcbuf, 0xcc, sizeof(srcbuf) / sizeof(*srcbuf));
+ srcbuf[0] = L'\0';
+ memset(dstbuf, 0xcc, sizeof(dstbuf));
+ src = srcbuf;
+ memset(&s, 0, sizeof(s));
+ ATF_REQUIRE(wcsrtombs(dstbuf, (const wchar_t **)&src, sizeof(dstbuf),
+ &s) == 0);
+ ATF_REQUIRE(dstbuf[0] == L'\0');
+
+ /* Zero length destination buffer. */
+ wmemset(srcbuf, 0xcc, sizeof(srcbuf) / sizeof(*srcbuf));
+ wcscpy(srcbuf, L"hello");
+ memset(dstbuf, 0xcc, sizeof(dstbuf));
+ src = srcbuf;
+ memset(&s, 0, sizeof(s));
+ ATF_REQUIRE(wcsrtombs(dstbuf, (const wchar_t **)&src, 0, &s) == 0);
+ ATF_REQUIRE((unsigned char)dstbuf[0] == 0xcc);
+
+ /*
+ * Japanese (EUC) locale.
+ */
+
+ ATF_REQUIRE(strcmp(setlocale(LC_CTYPE, "ja_JP.eucJP"), "ja_JP.eucJP") == 0);
+ ATF_REQUIRE(MB_CUR_MAX > 1);
+
+ wmemset(srcbuf, 0xcc, sizeof(srcbuf) / sizeof(*srcbuf));
+ srcbuf[0] = 0xA3C1;
+ srcbuf[1] = 0x0020;
+ srcbuf[2] = 0x0042;
+ srcbuf[3] = 0x0020;
+ srcbuf[4] = 0xA3C3;
+ srcbuf[5] = 0x0000;
+ memset(dstbuf, 0xcc, sizeof(dstbuf));
+ src = srcbuf;
+ memset(&s, 0, sizeof(s));
+ ATF_REQUIRE(wcsrtombs(dstbuf, (const wchar_t **)&src, sizeof(dstbuf),
+ &s) == 7);
+ ATF_REQUIRE(strcmp(dstbuf, "\xA3\xC1 B \xA3\xC3") == 0);
+ ATF_REQUIRE((unsigned char)dstbuf[8] == 0xcc);
+ ATF_REQUIRE(src == NULL);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, wcsrtombs_test);
+
+ return (atf_no_error());
+}
Property changes on: trunk/lib/libc/tests/locale/wcsrtombs_test.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/locale/wcstombs_test.c
===================================================================
--- trunk/lib/libc/tests/locale/wcstombs_test.c (rev 0)
+++ trunk/lib/libc/tests/locale/wcstombs_test.c 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,131 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2002 Tim J. Robbins
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Test program for wcstombs(), as specified by IEEE Std. 1003.1-2001 and
+ * ISO/IEC 9899:1999.
+ *
+ * The function is tested with both the "C" ("POSIX") LC_CTYPE setting and
+ * "ja_JP.eucJP". Other encodings are not tested.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/lib/libc/tests/locale/wcstombs_test.c 291178 2015-11-23 08:31:41Z ngie $");
+
+#include <errno.h>
+#include <limits.h>
+#include <locale.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <wchar.h>
+
+#include <atf-c.h>
+
+ATF_TC_WITHOUT_HEAD(wcstombs_test);
+ATF_TC_BODY(wcstombs_test, tc)
+{
+ wchar_t srcbuf[128];
+ char dstbuf[128];
+
+ /* C/POSIX locale. */
+
+ /* Simple null terminated string. */
+ wmemset(srcbuf, 0xcc, sizeof(srcbuf) / sizeof(*srcbuf));
+ wcscpy(srcbuf, L"hello");
+ memset(dstbuf, 0xcc, sizeof(dstbuf));
+ ATF_REQUIRE(wcstombs(dstbuf, srcbuf, sizeof(dstbuf)) == 5);
+ ATF_REQUIRE(strcmp(dstbuf, "hello") == 0);
+ ATF_REQUIRE((unsigned char)dstbuf[6] == 0xcc);
+
+ /* Not enough space in destination buffer. */
+ wmemset(srcbuf, 0xcc, sizeof(srcbuf) / sizeof(*srcbuf));
+ wcscpy(srcbuf, L"hello");
+ memset(dstbuf, 0xcc, sizeof(dstbuf));
+ ATF_REQUIRE(wcstombs(dstbuf, srcbuf, 4) == 4);
+ ATF_REQUIRE(memcmp(dstbuf, "hell", 4) == 0);
+ ATF_REQUIRE((unsigned char)dstbuf[5] == 0xcc);
+
+ /* Null terminated string, internal dest. buffer */
+ wmemset(srcbuf, 0xcc, sizeof(srcbuf) / sizeof(*srcbuf));
+ wcscpy(srcbuf, L"hello");
+ ATF_REQUIRE(wcstombs(NULL, srcbuf, sizeof(dstbuf)) == 5);
+
+ /* Null terminated string, internal state. */
+ wmemset(srcbuf, 0xcc, sizeof(srcbuf) / sizeof(*srcbuf));
+ wcscpy(srcbuf, L"hello");
+ memset(dstbuf, 0xcc, sizeof(dstbuf));
+ ATF_REQUIRE(wcstombs(dstbuf, srcbuf, sizeof(dstbuf)) == 5);
+ ATF_REQUIRE(strcmp(dstbuf, "hello") == 0);
+ ATF_REQUIRE((unsigned char)dstbuf[6] == 0xcc);
+
+ /* Null terminated string, internal state, internal dest. buffer. */
+ wmemset(srcbuf, 0xcc, sizeof(srcbuf) / sizeof(*srcbuf));
+ wcscpy(srcbuf, L"hello");
+ ATF_REQUIRE(wcstombs(NULL, srcbuf, 0) == 5);
+
+ /* Empty source buffer. */
+ wmemset(srcbuf, 0xcc, sizeof(srcbuf) / sizeof(*srcbuf));
+ srcbuf[0] = L'\0';
+ memset(dstbuf, 0xcc, sizeof(dstbuf));
+ ATF_REQUIRE(wcstombs(dstbuf, srcbuf, sizeof(dstbuf)) == 0);
+ ATF_REQUIRE(dstbuf[0] == L'\0');
+
+ /* Zero length destination buffer. */
+ wmemset(srcbuf, 0xcc, sizeof(srcbuf) / sizeof(*srcbuf));
+ wcscpy(srcbuf, L"hello");
+ memset(dstbuf, 0xcc, sizeof(dstbuf));
+ ATF_REQUIRE(wcstombs(dstbuf, srcbuf, 0) == 0);
+ ATF_REQUIRE((unsigned char)dstbuf[0] == 0xcc);
+
+ /*
+ * Japanese (EUC) locale.
+ */
+
+ ATF_REQUIRE(strcmp(setlocale(LC_CTYPE, "ja_JP.eucJP"), "ja_JP.eucJP") == 0);
+ ATF_REQUIRE(MB_CUR_MAX > 1);
+
+ wmemset(srcbuf, 0xcc, sizeof(srcbuf) / sizeof(*srcbuf));
+ srcbuf[0] = 0xA3C1;
+ srcbuf[1] = 0x0020;
+ srcbuf[2] = 0x0042;
+ srcbuf[3] = 0x0020;
+ srcbuf[4] = 0xA3C3;
+ srcbuf[5] = 0x0000;
+ memset(dstbuf, 0xcc, sizeof(dstbuf));
+ ATF_REQUIRE(wcstombs(dstbuf, srcbuf, sizeof(dstbuf)) == 7);
+ ATF_REQUIRE(strcmp(dstbuf, "\xA3\xC1 B \xA3\xC3") == 0);
+ ATF_REQUIRE((unsigned char)dstbuf[8] == 0xcc);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, wcstombs_test);
+
+ return (atf_no_error());
+}
Property changes on: trunk/lib/libc/tests/locale/wcstombs_test.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/locale/wctomb_test.c
===================================================================
--- trunk/lib/libc/tests/locale/wctomb_test.c (rev 0)
+++ trunk/lib/libc/tests/locale/wctomb_test.c 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,114 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2002-2004 Tim J. Robbins
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Test program for wctomb(), as specified by IEEE Std. 1003.1-2001 and
+ * ISO/IEC 9899:1999.
+ *
+ * The function is tested with both the "C" ("POSIX") LC_CTYPE setting and
+ * "ja_JP.eucJP". Other encodings are not tested.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/lib/libc/tests/locale/wctomb_test.c 291178 2015-11-23 08:31:41Z ngie $");
+
+#include <errno.h>
+#include <limits.h>
+#include <locale.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <atf-c.h>
+
+ATF_TC_WITHOUT_HEAD(wctomb_test);
+ATF_TC_BODY(wctomb_test, tc)
+{
+ size_t len;
+ char buf[MB_LEN_MAX + 1];
+
+ /* C/POSIX locale. */
+
+ ATF_REQUIRE(MB_CUR_MAX == 1);
+
+ /* No shift states in C locale. */
+ ATF_REQUIRE(wctomb(NULL, L'\0') == 0);
+
+ /* Null wide character. */
+ memset(buf, 0xcc, sizeof(buf));
+ len = wctomb(buf, L'\0');
+ ATF_REQUIRE(len == 1);
+ ATF_REQUIRE((unsigned char)buf[0] == 0 && (unsigned char)buf[1] == 0xcc);
+
+ /* Latin letter A. */
+ memset(buf, 0xcc, sizeof(buf));
+ len = wctomb(buf, L'A');
+ ATF_REQUIRE(len == 1);
+ ATF_REQUIRE((unsigned char)buf[0] == 'A' && (unsigned char)buf[1] == 0xcc);
+
+ /* Invalid code. */
+ ATF_REQUIRE(wctomb(buf, UCHAR_MAX + 1) == -1);
+ ATF_REQUIRE(wctomb(NULL, 0) == 0);
+
+ /*
+ * Japanese (EUC) locale.
+ */
+
+ ATF_REQUIRE(strcmp(setlocale(LC_CTYPE, "ja_JP.eucJP"), "ja_JP.eucJP") == 0);
+ ATF_REQUIRE(MB_CUR_MAX == 3);
+
+ /* No shift states in EUC encoding. */
+ ATF_REQUIRE(wctomb(NULL, L'\0') == 0);
+
+ /* Null wide character. */
+ memset(buf, 0xcc, sizeof(buf));
+ len = wctomb(buf, L'\0');
+ ATF_REQUIRE(len == 1);
+ ATF_REQUIRE((unsigned char)buf[0] == 0 && (unsigned char)buf[1] == 0xcc);
+
+ /* Latin letter A. */
+ memset(buf, 0xcc, sizeof(buf));
+ len = wctomb(buf, L'A');
+ ATF_REQUIRE(len == 1);
+ ATF_REQUIRE((unsigned char)buf[0] == 'A' && (unsigned char)buf[1] == 0xcc);
+
+ /* Full width letter A. */
+ memset(buf, 0xcc, sizeof(buf));
+ len = wctomb(buf, 0xa3c1);
+ ATF_REQUIRE(len == 2);
+ ATF_REQUIRE((unsigned char)buf[0] == 0xa3 &&
+ (unsigned char)buf[1] == 0xc1 &&
+ (unsigned char)buf[2] == 0xcc);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, wctomb_test);
+
+ return (atf_no_error());
+}
Property changes on: trunk/lib/libc/tests/locale/wctomb_test.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/net/Makefile
===================================================================
--- trunk/lib/libc/tests/net/Makefile (rev 0)
+++ trunk/lib/libc/tests/net/Makefile 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,43 @@
+# $MidnightBSD$
+# $FreeBSD: stable/10/lib/libc/tests/net/Makefile 313488 2017-02-09 22:49:48Z ngie $
+
+ATF_TESTS_C+= ether_test
+ATF_TESTS_C+= eui64_aton_test
+ATF_TESTS_C+= eui64_ntoa_test
+
+CFLAGS+= -I${.CURDIR}
+
+NETBSD_ATF_TESTS_C+= getprotoent_test
+NETBSD_ATF_TESTS_C+= ether_aton_test
+
+SRCS.ether_aton_test= aton_ether_subr.c t_ether_aton.c
+
+# TODO: hostent_test
+NETBSD_ATF_TESTS_SH= nsdispatch_test
+NETBSD_ATF_TESTS_SH+= protoent_test
+NETBSD_ATF_TESTS_SH+= servent_test
+
+BINDIR= ${TESTSDIR}
+
+PROGS= h_nsd_recurse
+PROGS+= h_protoent
+PROGS+= h_servent
+PROGS+= h_dns_server
+
+DPADD.h_nsd_recurse+= ${LIBPTHREAD}
+LDADD.h_nsd_recurse+= -lpthread
+
+__MAKE_SHELL?= /bin/sh
+
+CLEANFILES+= aton_ether_subr.c
+aton_ether_subr.c: gen_ether_subr ${.CURDIR:H:H:H:H}/sys/net/if_ethersubr.c
+ ${__MAKE_SHELL} ${.ALLSRC} ${.TARGET}
+
+.include "../Makefile.netbsd-tests"
+
+# TODO: the testcases needs to be ported to FreeBSD
+#TESTS_SUBDIRS= getaddrinfo
+FILES+= hosts
+FILES+= resolv.conf
+
+.include <bsd.test.mk>
Property changes on: trunk/lib/libc/tests/net/Makefile
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/net/ether_test.c
===================================================================
--- trunk/lib/libc/tests/net/ether_test.c (rev 0)
+++ trunk/lib/libc/tests/net/ether_test.c 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,193 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2007 Robert N. M. Watson
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: stable/10/lib/libc/tests/net/ether_test.c 291175 2015-11-23 08:22:40Z ngie $
+ */
+
+#include <sys/types.h>
+
+#include <net/ethernet.h>
+
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <atf-c.h>
+
+static const char *ether_line_string = "01:23:45:67:89:ab ether_line_hostname";
+static const char *ether_line_hostname = "ether_line_hostname";
+static const struct ether_addr ether_line_addr = {
+ { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab }
+};
+
+ATF_TC_WITHOUT_HEAD(ether_line);
+ATF_TC_BODY(ether_line, tc)
+{
+ struct ether_addr e;
+ char hostname[256];
+
+ ATF_REQUIRE_MSG(ether_line(ether_line_string, &e, hostname) == 0,
+ "ether_line failed; errno=%d", errno);
+ ATF_REQUIRE_MSG(bcmp(&e, ðer_line_addr, ETHER_ADDR_LEN) == 0,
+ "bad address");
+ ATF_REQUIRE_MSG(strcmp(hostname, ether_line_hostname) == 0,
+ "bad hostname");
+}
+
+static const char *ether_line_bad_1_string = "x";
+
+ATF_TC_WITHOUT_HEAD(ether_line_bad_1);
+ATF_TC_BODY(ether_line_bad_1, tc)
+{
+ struct ether_addr e;
+ char hostname[256];
+
+ ATF_REQUIRE_MSG(ether_line(ether_line_bad_1_string, &e, hostname) != 0,
+ "ether_line succeeded unexpectedly");
+}
+
+static const char *ether_line_bad_2_string = "x x";
+
+ATF_TC_WITHOUT_HEAD(ether_line_bad_2);
+ATF_TC_BODY(ether_line_bad_2, tc)
+{
+ struct ether_addr e;
+ char hostname[256];
+
+ ATF_REQUIRE_MSG(ether_line(ether_line_bad_2_string, &e, hostname) != 0,
+ "ether_line succeeded unexpectedly");
+}
+
+static const char *ether_aton_string = "01:23:45:67:89:ab";
+static const struct ether_addr ether_aton_addr = {
+ { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab }
+};
+
+ATF_TC_WITHOUT_HEAD(ether_aton_r);
+ATF_TC_BODY(ether_aton_r, tc)
+{
+ struct ether_addr e, *ep;
+
+ ep = ether_aton_r(ether_aton_string, &e);
+
+ ATF_REQUIRE_MSG(ep != NULL, "ether_aton_r failed; errno=%d", errno);
+ ATF_REQUIRE_MSG(ep == &e,
+ "ether_aton_r returned different pointers; %p != %p", ep, &e);
+}
+
+static const char *ether_aton_bad_string = "x";
+
+ATF_TC_WITHOUT_HEAD(ether_aton_r_bad);
+ATF_TC_BODY(ether_aton_r_bad, tc)
+{
+ struct ether_addr e, *ep;
+
+ ep = ether_aton_r(ether_aton_bad_string, &e);
+ ATF_REQUIRE_MSG(ep == NULL, "ether_aton_r succeeded unexpectedly");
+}
+
+ATF_TC_WITHOUT_HEAD(ether_aton);
+ATF_TC_BODY(ether_aton, tc)
+{
+ struct ether_addr *ep;
+
+ ep = ether_aton(ether_aton_string);
+ ATF_REQUIRE_MSG(ep != NULL, "ether_aton failed");
+ ATF_REQUIRE_MSG(bcmp(ep, ðer_aton_addr, ETHER_ADDR_LEN) == 0,
+ "bad address");
+}
+
+ATF_TC_WITHOUT_HEAD(ether_aton_bad);
+ATF_TC_BODY(ether_aton_bad, tc)
+{
+ struct ether_addr *ep;
+
+ ep = ether_aton(ether_aton_bad_string);
+ ATF_REQUIRE_MSG(ep == NULL, "ether_aton succeeded unexpectedly");
+}
+
+static const char *ether_ntoa_string = "01:23:45:67:89:ab";
+static const struct ether_addr ether_ntoa_addr = {
+ { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab }
+};
+
+ATF_TC_WITHOUT_HEAD(ether_ntoa_r);
+ATF_TC_BODY(ether_ntoa_r, tc)
+{
+ char buf[256], *cp;
+
+ cp = ether_ntoa_r(ðer_ntoa_addr, buf);
+ ATF_REQUIRE_MSG(cp != NULL, "ether_ntoa_r failed");
+ ATF_REQUIRE_MSG(cp == buf,
+ "ether_ntoa_r returned a different pointer; %p != %p", cp, buf);
+ ATF_REQUIRE_MSG(strcmp(cp, ether_ntoa_string) == 0,
+ "strings did not match (`%s` != `%s`)", cp, ether_ntoa_string);
+}
+
+ATF_TC_WITHOUT_HEAD(ether_ntoa);
+ATF_TC_BODY(ether_ntoa, tc)
+{
+ char *cp;
+
+ cp = ether_ntoa(ðer_ntoa_addr);
+ ATF_REQUIRE_MSG(cp != NULL, "ether_ntoa failed");
+ ATF_REQUIRE_MSG(strcmp(cp, ether_ntoa_string) == 0,
+ "strings did not match (`%s` != `%s`)", cp, ether_ntoa_string);
+}
+
+#if 0
+ATF_TC_WITHOUT_HEAD(ether_ntohost);
+ATF_TC_BODY(ether_ntohost, tc)
+{
+
+}
+
+ATF_TC_WITHOUT_HEAD(ether_hostton);
+ATF_TC_BODY(ether_hostton, tc)
+{
+
+}
+#endif
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, ether_line);
+ ATF_TP_ADD_TC(tp, ether_line_bad_1);
+ ATF_TP_ADD_TC(tp, ether_line_bad_2);
+ ATF_TP_ADD_TC(tp, ether_aton_r);
+ ATF_TP_ADD_TC(tp, ether_aton_r_bad);
+ ATF_TP_ADD_TC(tp, ether_aton);
+ ATF_TP_ADD_TC(tp, ether_aton_bad);
+ ATF_TP_ADD_TC(tp, ether_ntoa_r);
+ ATF_TP_ADD_TC(tp, ether_ntoa);
+#if 0
+ ATF_TP_ADD_TC(tp, ether_ntohost);
+ ATF_TP_ADD_TC(tp, ether_hostton);
+#endif
+
+ return (atf_no_error());
+}
Property changes on: trunk/lib/libc/tests/net/ether_test.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/net/eui64_aton_test.c
===================================================================
--- trunk/lib/libc/tests/net/eui64_aton_test.c (rev 0)
+++ trunk/lib/libc/tests/net/eui64_aton_test.c 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,105 @@
+/* $MidnightBSD$ */
+/*
+ * Copyright 2004 The Aerospace Corporation. 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. The name of The Aerospace Corporation may not be used to endorse or
+ * promote products derived from this software.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AEROSPACE CORPORATION "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 AEROSPACE CORPORATION 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.
+ *
+ * $FreeBSD: stable/10/lib/libc/tests/net/eui64_aton_test.c 291175 2015-11-23 08:22:40Z ngie $
+ */
+
+#include <sys/types.h>
+#include <sys/eui64.h>
+#include <locale.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <atf-c.h>
+
+#include "test-eui64.h"
+
+static void
+test_str(const char *str, const struct eui64 *eui)
+{
+ struct eui64 e;
+ char buf[EUI64_SIZ];
+ int rc;
+
+ ATF_REQUIRE_MSG(eui64_aton(str, &e) == 0, "eui64_aton failed");
+ rc = memcmp(&e, eui, sizeof(e));
+ if (rc != 0) {
+ eui64_ntoa(&e, buf, sizeof(buf));
+ atf_tc_fail(
+ "eui64_aton(\"%s\", ..) failed; memcmp returned %d. "
+ "String obtained form eui64_ntoa was: `%s`",
+ str, rc, buf);
+ }
+}
+
+ATF_TC_WITHOUT_HEAD(id_ascii);
+ATF_TC_BODY(id_ascii, tc)
+{
+
+ test_str(test_eui64_id_ascii, &test_eui64_id);
+}
+
+ATF_TC_WITHOUT_HEAD(id_colon_ascii);
+ATF_TC_BODY(id_colon_ascii, tc)
+{
+
+ test_str(test_eui64_id_colon_ascii, &test_eui64_id);
+}
+
+ATF_TC_WITHOUT_HEAD(mac_ascii);
+ATF_TC_BODY(mac_ascii, tc)
+{
+
+ test_str(test_eui64_mac_ascii, &test_eui64_eui48);
+}
+
+ATF_TC_WITHOUT_HEAD(mac_colon_ascii);
+ATF_TC_BODY(mac_colon_ascii, tc)
+{
+
+ test_str(test_eui64_mac_colon_ascii, &test_eui64_eui48);
+}
+
+ATF_TC_WITHOUT_HEAD(hex_ascii);
+ATF_TC_BODY(hex_ascii, tc)
+{
+
+ test_str(test_eui64_hex_ascii, &test_eui64_id);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, id_ascii);
+ ATF_TP_ADD_TC(tp, id_colon_ascii);
+ ATF_TP_ADD_TC(tp, mac_ascii);
+ ATF_TP_ADD_TC(tp, mac_colon_ascii);
+ ATF_TP_ADD_TC(tp, hex_ascii);
+
+ return (atf_no_error());
+}
Property changes on: trunk/lib/libc/tests/net/eui64_aton_test.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/net/eui64_ntoa_test.c
===================================================================
--- trunk/lib/libc/tests/net/eui64_ntoa_test.c (rev 0)
+++ trunk/lib/libc/tests/net/eui64_ntoa_test.c 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,65 @@
+/* $MidnightBSD$ */
+/*
+ * Copyright 2004 The Aerospace Corporation. 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. The name of The Aerospace Corporation may not be used to endorse or
+ * promote products derived from this software.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AEROSPACE CORPORATION "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 AEROSPACE CORPORATION 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.
+ *
+ * $FreeBSD: stable/10/lib/libc/tests/net/eui64_ntoa_test.c 291175 2015-11-23 08:22:40Z ngie $
+ */
+
+#include <sys/types.h>
+#include <sys/eui64.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <atf-c.h>
+
+#include "test-eui64.h"
+
+static void
+test_str(const char *str, const struct eui64 *eui)
+{
+ char a[EUI64_SIZ];
+
+ ATF_REQUIRE_MSG(eui64_ntoa(&test_eui64_id, a, sizeof(a)) == 0,
+ "eui64_ntoa failed");
+ ATF_REQUIRE_MSG(strcmp(a, test_eui64_id_ascii) == 0,
+ "the strings mismatched: `%s` != `%s`", a, test_eui64_id_ascii);
+}
+
+ATF_TC_WITHOUT_HEAD(id_ascii);
+ATF_TC_BODY(id_ascii, tc)
+{
+
+ test_str(test_eui64_id_ascii, &test_eui64_id);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, id_ascii);
+
+ return (atf_no_error());
+}
Property changes on: trunk/lib/libc/tests/net/eui64_ntoa_test.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/net/getaddrinfo/Makefile
===================================================================
--- trunk/lib/libc/tests/net/getaddrinfo/Makefile (rev 0)
+++ trunk/lib/libc/tests/net/getaddrinfo/Makefile 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,28 @@
+# $MidnightBSD$
+# $FreeBSD: stable/10/lib/libc/tests/net/getaddrinfo/Makefile 313488 2017-02-09 22:49:48Z ngie $
+
+TESTSRC= ${SRCTOP}/contrib/netbsd-tests/lib/libc/net/${.CURDIR:T}
+
+.include <bsd.own.mk>
+
+BINDIR= ${TESTSDIR}
+
+.error "This testcase needs to be ported to FreeBSD (the output from getaddrinfo_test differs from NetBSD)"
+
+NETBSD_ATF_TESTS_SH= getaddrinfo_test
+
+PROGS= h_gai
+
+FILESDIR= ${TESTSDIR}/data
+
+FILES= basics_v4.exp basics_v4v6.exp
+FILES+= no_host_v4.exp no_host_v4v6.exp
+FILES+= no_serv_v4.exp no_serv_v4v6.exp
+FILES+= sock_raw_v4.exp sock_raw_v4v6.exp
+FILES+= spec_fam_v4.exp spec_fam_v4v6.exp
+FILES+= scoped.exp
+FILES+= unsup_fam.exp
+
+.include "../../Makefile.netbsd-tests"
+
+.include <bsd.test.mk>
Property changes on: trunk/lib/libc/tests/net/getaddrinfo/Makefile
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/net/test-eui64.h
===================================================================
--- trunk/lib/libc/tests/net/test-eui64.h (rev 0)
+++ trunk/lib/libc/tests/net/test-eui64.h 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,56 @@
+/* $MidnightBSD$ */
+/*
+ * Copyright 2004 The Aerospace Corporation. 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. The name of The Aerospace Corporation may not be used to endorse or
+ * promote products derived from this software.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AEROSPACE CORPORATION "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 AEROSPACE CORPORATION 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.
+ *
+ * $FreeBSD: stable/10/lib/libc/tests/net/test-eui64.h 291175 2015-11-23 08:22:40Z ngie $
+ */
+#ifndef _TEST_EUI64_H
+#define _TEST_EUI64_H
+
+struct eui64 test_eui64_id = {{0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77}};
+struct eui64 test_eui64_eui48 = {{0x00,0x11,0x22,0xFF,0xFE,0x33,0x44,0x55}};
+struct eui64 test_eui64_mac48 = {{0x00,0x11,0x22,0xFF,0xFF,0x33,0x44,0x55}};
+
+#define test_eui64_id_ascii "00-11-22-33-44-55-66-77"
+#define test_eui64_id_colon_ascii "00:11:22:33:44:55:66:77"
+#define test_eui64_hex_ascii "0x0011223344556677"
+#define test_eui64_eui48_ascii "00-11-22-ff-fe-33-44-55"
+#define test_eui64_mac48_ascii "00-11-22-ff-fe-33-44-55"
+#define test_eui64_mac_ascii "00-11-22-33-44-55"
+#define test_eui64_mac_colon_ascii "00:11:22:33:44:55"
+#define test_eui64_id_host "id"
+#define test_eui64_eui48_host "eui-48"
+#define test_eui64_mac48_host "mac-48"
+
+#define test_eui64_line_id "00-11-22-33-44-55-66-77 id"
+#define test_eui64_line_id_colon "00:11:22:33:44:55:66:77 id"
+#define test_eui64_line_eui48 "00-11-22-FF-fe-33-44-55 eui-48"
+#define test_eui64_line_mac48 "00-11-22-FF-ff-33-44-55 mac-48"
+#define test_eui64_line_eui48_6byte "00-11-22-33-44-55 eui-48"
+#define test_eui64_line_eui48_6byte_c "00:11:22:33:44:55 eui-48"
+
+#endif /* !_TEST_EUI64_H */
Property changes on: trunk/lib/libc/tests/net/test-eui64.h
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/nss/Makefile
===================================================================
--- trunk/lib/libc/tests/nss/Makefile (rev 0)
+++ trunk/lib/libc/tests/nss/Makefile 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,26 @@
+# $MidnightBSD$
+# $FreeBSD: stable/10/lib/libc/tests/nss/Makefile 321144 2017-07-18 18:09:26Z ngie $
+
+.PATH: ${.CURDIR:H}/resolv
+
+TESTSDIR= ${TESTSBASE}/lib/libc/nss
+
+BINDIR= ${TESTSDIR}
+
+ATF_TESTS_C+= getaddrinfo_test
+ATF_TESTS_C+= getgr_test
+ATF_TESTS_C+= gethostby_test
+TEST_METADATA.gethostby_test= timeout="1200"
+ATF_TESTS_C+= getpw_test
+ATF_TESTS_C+= getproto_test
+ATF_TESTS_C+= getrpc_test
+ATF_TESTS_C+= getserv_test
+ATF_TESTS_C+= getusershell_test
+
+FILES+= mach
+
+WARNS?= 3
+
+CFLAGS+= -I${SRCTOP}/tests
+
+.include <bsd.test.mk>
Property changes on: trunk/lib/libc/tests/nss/Makefile
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/nss/getaddrinfo_test.c
===================================================================
--- trunk/lib/libc/tests/nss/getaddrinfo_test.c (rev 0)
+++ trunk/lib/libc/tests/nss/getaddrinfo_test.c 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,558 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2006 Michael Bushkov <bushman at freebsd.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/lib/libc/tests/nss/getaddrinfo_test.c 321144 2017-07-18 18:09:26Z ngie $");
+
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <arpa/inet.h>
+#include <netinet/in.h>
+#include <errno.h>
+#include <netdb.h>
+#include <resolv.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stringlist.h>
+#include <unistd.h>
+
+#include <atf-c.h>
+
+#include "freebsd_test_suite/macros.h"
+#include "testutil.h"
+
+enum test_methods {
+ TEST_GETADDRINFO,
+ TEST_BUILD_SNAPSHOT
+};
+
+static struct addrinfo hints;
+static enum test_methods method = TEST_GETADDRINFO;
+
+DECLARE_TEST_DATA(addrinfo)
+DECLARE_TEST_FILE_SNAPSHOT(addrinfo)
+DECLARE_2PASS_TEST(addrinfo)
+
+static void clone_addrinfo(struct addrinfo *, struct addrinfo const *);
+static int compare_addrinfo(struct addrinfo *, struct addrinfo *, void *);
+static void dump_addrinfo(struct addrinfo *);
+
+static void sdump_addrinfo(struct addrinfo *, char *, size_t);
+
+IMPLEMENT_TEST_DATA(addrinfo)
+IMPLEMENT_TEST_FILE_SNAPSHOT(addrinfo)
+IMPLEMENT_2PASS_TEST(addrinfo)
+
+static void
+clone_addrinfo(struct addrinfo *dest, struct addrinfo const *src)
+{
+
+ ATF_REQUIRE(dest != NULL);
+ ATF_REQUIRE(src != NULL);
+
+ memcpy(dest, src, sizeof(struct addrinfo));
+ if (src->ai_canonname != NULL)
+ dest->ai_canonname = strdup(src->ai_canonname);
+
+ if (src->ai_addr != NULL) {
+ dest->ai_addr = malloc(src->ai_addrlen);
+ ATF_REQUIRE(dest->ai_addr != NULL);
+ memcpy(dest->ai_addr, src->ai_addr, src->ai_addrlen);
+ }
+
+ if (src->ai_next != NULL) {
+ dest->ai_next = malloc(sizeof(struct addrinfo));
+ ATF_REQUIRE(dest->ai_next != NULL);
+ clone_addrinfo(dest->ai_next, src->ai_next);
+ }
+}
+
+static int
+compare_addrinfo_(struct addrinfo *ai1, struct addrinfo *ai2)
+{
+
+ if ((ai1 == NULL) || (ai2 == NULL))
+ return (-1);
+
+ if (ai1->ai_flags != ai2->ai_flags ||
+ ai1->ai_family != ai2->ai_family ||
+ ai1->ai_socktype != ai2->ai_socktype ||
+ ai1->ai_protocol != ai2->ai_protocol ||
+ ai1->ai_addrlen != ai2->ai_addrlen ||
+ ((ai1->ai_addr == NULL || ai2->ai_addr == NULL) &&
+ ai1->ai_addr != ai2->ai_addr) ||
+ ((ai1->ai_canonname == NULL || ai2->ai_canonname == NULL) &&
+ ai1->ai_canonname != ai2->ai_canonname))
+ return (-1);
+
+ if (ai1->ai_canonname != NULL &&
+ strcmp(ai1->ai_canonname, ai2->ai_canonname) != 0)
+ return (-1);
+
+ if (ai1->ai_addr != NULL &&
+ memcmp(ai1->ai_addr, ai2->ai_addr, ai1->ai_addrlen) != 0)
+ return (-1);
+
+ if (ai1->ai_next == NULL && ai2->ai_next == NULL)
+ return (0);
+ else
+ return (compare_addrinfo_(ai1->ai_next, ai2->ai_next));
+}
+
+static int
+compare_addrinfo(struct addrinfo *ai1, struct addrinfo *ai2,
+ void *mdata __unused)
+{
+ int rv;
+
+ printf("testing equality of 2 addrinfo structures\n");
+
+ rv = compare_addrinfo_(ai1, ai2);
+
+ if (rv == 0)
+ printf("equal\n");
+ else {
+ dump_addrinfo(ai1);
+ dump_addrinfo(ai2);
+ printf("not equal\n");
+ }
+
+ return (rv);
+}
+
+static void
+free_addrinfo(struct addrinfo *ai)
+{
+ if (ai == NULL)
+ return;
+
+ free(ai->ai_addr);
+ free(ai->ai_canonname);
+ free_addrinfo(ai->ai_next);
+}
+
+void
+sdump_addrinfo(struct addrinfo *ai, char *buffer, size_t buflen)
+{
+ int written, i;
+
+ written = snprintf(buffer, buflen, "%d %d %d %d %d ",
+ ai->ai_flags, ai->ai_family, ai->ai_socktype, ai->ai_protocol,
+ ai->ai_addrlen);
+ buffer += written;
+ if (written > (int)buflen)
+ return;
+ buflen -= written;
+
+ written = snprintf(buffer, buflen, "%s ",
+ ai->ai_canonname == NULL ? "(null)" : ai->ai_canonname);
+ buffer += written;
+ if (written > (int)buflen)
+ return;
+ buflen -= written;
+
+ if (ai->ai_addr == NULL) {
+ written = snprintf(buffer, buflen, "(null)");
+ buffer += written;
+ if (written > (int)buflen)
+ return;
+ buflen -= written;
+ } else {
+ for (i = 0; i < (int)ai->ai_addrlen; i++) {
+ written = snprintf(buffer, buflen,
+ i + 1 != (int)ai->ai_addrlen ? "%d." : "%d",
+ ((unsigned char *)ai->ai_addr)[i]);
+ buffer += written;
+ if (written > (int)buflen)
+ return;
+ buflen -= written;
+
+ if (buflen == 0)
+ return;
+ }
+ }
+
+ if (ai->ai_next != NULL) {
+ written = snprintf(buffer, buflen, ":");
+ buffer += written;
+ if (written > (int)buflen)
+ return;
+ buflen -= written;
+
+ sdump_addrinfo(ai->ai_next, buffer, buflen);
+ }
+}
+
+void
+dump_addrinfo(struct addrinfo *result)
+{
+ if (result != NULL) {
+ char buffer[2048];
+ sdump_addrinfo(result, buffer, sizeof(buffer));
+ printf("%s\n", buffer);
+ } else
+ printf("(null)\n");
+}
+
+static int
+addrinfo_read_snapshot_addr(char *addr, unsigned char *result, size_t len)
+{
+ char *s, *ps, *ts;
+
+ ps = addr;
+ while ((s = strsep(&ps, ".")) != NULL) {
+ if (len == 0)
+ return (-1);
+
+ *result = (unsigned char)strtol(s, &ts, 10);
+ ++result;
+ if (*ts != '\0')
+ return (-1);
+
+ --len;
+ }
+ if (len != 0)
+ return (-1);
+ else
+ return (0);
+}
+
+static int
+addrinfo_read_snapshot_ai(struct addrinfo *ai, char *line)
+{
+ char *s, *ps, *ts;
+ int i, rv, *pi;
+
+ rv = 0;
+ i = 0;
+ ps = line;
+ memset(ai, 0, sizeof(struct addrinfo));
+ while ((s = strsep(&ps, " ")) != NULL) {
+ switch (i) {
+ case 0:
+ case 1:
+ case 2:
+ case 3:
+ pi = &ai->ai_flags + i;
+ *pi = (int)strtol(s, &ts, 10);
+ if (*ts != '\0')
+ goto fin;
+ break;
+ case 4:
+ ai->ai_addrlen = (socklen_t)strtol(s, &ts, 10);
+ if (*ts != '\0')
+ goto fin;
+ break;
+ case 5:
+ if (strcmp(s, "(null)") != 0) {
+ ai->ai_canonname = strdup(s);
+ ATF_REQUIRE(ai->ai_canonname != NULL);
+ }
+ break;
+ case 6:
+ if (strcmp(s, "(null)") != 0) {
+ ai->ai_addr = calloc(1, ai->ai_addrlen);
+ ATF_REQUIRE(ai->ai_addr != NULL);
+ rv = addrinfo_read_snapshot_addr(s,
+ (unsigned char *)ai->ai_addr,
+ ai->ai_addrlen);
+
+ if (rv != 0)
+ goto fin;
+ }
+ break;
+ default:
+ /* NOTE: should not be reachable */
+ rv = -1;
+ goto fin;
+ }
+
+ ++i;
+ }
+
+fin:
+ if (i != 7 || rv != 0) {
+ free_addrinfo(ai);
+ ai = NULL;
+ return (-1);
+ }
+
+ return (0);
+}
+
+static int
+addrinfo_read_snapshot_func(struct addrinfo *ai, char *line)
+{
+ struct addrinfo *ai2;
+ char *s, *ps;
+ int rv;
+
+ printf("1 line read from snapshot:\n%s\n", line);
+
+ rv = 0;
+ ps = line;
+
+ s = strsep(&ps, ":");
+ if (s == NULL)
+ return (-1);
+
+ rv = addrinfo_read_snapshot_ai(ai, s);
+ if (rv != 0)
+ return (-1);
+
+ ai2 = ai;
+ while ((s = strsep(&ps, ":")) != NULL) {
+ ai2->ai_next = calloc(1, sizeof(struct addrinfo));
+ ATF_REQUIRE(ai2->ai_next != NULL);
+
+ rv = addrinfo_read_snapshot_ai(ai2->ai_next, s);
+ if (rv != 0) {
+ free_addrinfo(ai);
+ ai = NULL;
+ return (-1);
+ }
+
+ ai2 = ai2->ai_next;
+ }
+
+ return (0);
+}
+
+static int
+addrinfo_test_correctness(struct addrinfo *ai, void *mdata __unused)
+{
+
+ printf("testing correctness with the following data:\n");
+ dump_addrinfo(ai);
+
+ if (ai == NULL)
+ goto errfin;
+
+ if (!(ai->ai_family >= 0 && ai->ai_family < AF_MAX))
+ goto errfin;
+
+ if (ai->ai_socktype != 0 && ai->ai_socktype != SOCK_STREAM &&
+ ai->ai_socktype != SOCK_DGRAM && ai->ai_socktype != SOCK_RAW)
+ goto errfin;
+
+ if (ai->ai_protocol != 0 && ai->ai_protocol != IPPROTO_UDP &&
+ ai->ai_protocol != IPPROTO_TCP)
+ goto errfin;
+
+ if ((ai->ai_flags & ~(AI_CANONNAME | AI_NUMERICHOST | AI_PASSIVE)) != 0)
+ goto errfin;
+
+ if (ai->ai_addrlen != ai->ai_addr->sa_len ||
+ ai->ai_family != ai->ai_addr->sa_family)
+ goto errfin;
+
+ printf("correct\n");
+
+ return (0);
+errfin:
+ printf("incorrect\n");
+
+ return (-1);
+}
+
+static int
+addrinfo_read_hostlist_func(struct addrinfo *ai, char *line)
+{
+ struct addrinfo *result;
+ int rv;
+
+ printf("resolving %s: ", line);
+ rv = getaddrinfo(line, NULL, &hints, &result);
+ if (rv == 0) {
+ printf("found\n");
+
+ rv = addrinfo_test_correctness(result, NULL);
+ if (rv != 0) {
+ freeaddrinfo(result);
+ result = NULL;
+ return (rv);
+ }
+
+ clone_addrinfo(ai, result);
+ freeaddrinfo(result);
+ result = NULL;
+ } else {
+ printf("not found\n");
+
+ memset(ai, 0, sizeof(struct addrinfo));
+ }
+ return (0);
+}
+
+static void
+run_tests(char *hostlist_file, const char *snapshot_file, int ai_family)
+{
+ struct addrinfo_test_data td, td_snap;
+ char *snapshot_file_copy;
+ int rv;
+
+ if (snapshot_file == NULL)
+ snapshot_file_copy = NULL;
+ else {
+ snapshot_file_copy = strdup(snapshot_file);
+ ATF_REQUIRE(snapshot_file_copy != NULL);
+ }
+
+ memset(&hints, 0, sizeof(struct addrinfo));
+ hints.ai_family = ai_family;
+ hints.ai_flags = AI_CANONNAME;
+
+ if (snapshot_file != NULL)
+ method = TEST_BUILD_SNAPSHOT;
+
+ TEST_DATA_INIT(addrinfo, &td, clone_addrinfo, free_addrinfo);
+ TEST_DATA_INIT(addrinfo, &td_snap, clone_addrinfo, free_addrinfo);
+
+ ATF_REQUIRE_MSG(access(hostlist_file, R_OK) == 0,
+ "can't access the hostlist file %s\n", hostlist_file);
+
+ printf("building host lists from %s\n", hostlist_file);
+
+ rv = TEST_SNAPSHOT_FILE_READ(addrinfo, hostlist_file, &td,
+ addrinfo_read_hostlist_func);
+ if (rv != 0)
+ goto fin;
+
+ if (snapshot_file != NULL) {
+ if (access(snapshot_file, W_OK | R_OK) != 0) {
+ if (errno == ENOENT)
+ method = TEST_BUILD_SNAPSHOT;
+ else {
+ printf("can't access the snapshot "
+ "file %s\n", snapshot_file);
+
+ rv = -1;
+ goto fin;
+ }
+ } else {
+ rv = TEST_SNAPSHOT_FILE_READ(addrinfo, snapshot_file,
+ &td_snap, addrinfo_read_snapshot_func);
+ if (rv != 0) {
+ printf("error reading snapshot file: %s\n",
+ strerror(errno));
+ goto fin;
+ }
+ }
+ }
+
+ switch (method) {
+ case TEST_GETADDRINFO:
+ if (snapshot_file != NULL)
+ ATF_CHECK(DO_2PASS_TEST(addrinfo, &td, &td_snap,
+ compare_addrinfo, NULL) == 0);
+ break;
+ case TEST_BUILD_SNAPSHOT:
+ if (snapshot_file != NULL) {
+ ATF_CHECK(TEST_SNAPSHOT_FILE_WRITE(addrinfo,
+ snapshot_file, &td, sdump_addrinfo) == 0);
+ }
+ break;
+ default:
+ break;
+ }
+
+fin:
+ TEST_DATA_DESTROY(addrinfo, &td_snap);
+ TEST_DATA_DESTROY(addrinfo, &td);
+
+ free(snapshot_file_copy);
+}
+
+#define HOSTLIST_FILE "mach"
+#define RUN_TESTS(tc, snapshot_file, ai_family) do { \
+ char *_hostlist_file; \
+ ATF_REQUIRE(0 < asprintf(&_hostlist_file, "%s/%s", \
+ atf_tc_get_config_var(tc, "srcdir"), HOSTLIST_FILE)); \
+ run_tests(_hostlist_file, snapshot_file, ai_family); \
+ free(_hostlist_file); \
+} while (0)
+
+ATF_TC_WITHOUT_HEAD(pf_unspec);
+ATF_TC_BODY(pf_unspec, tc)
+{
+
+ RUN_TESTS(tc, NULL, AF_UNSPEC);
+}
+
+ATF_TC_WITHOUT_HEAD(pf_unspec_with_snapshot);
+ATF_TC_BODY(pf_unspec_with_snapshot, tc)
+{
+
+ RUN_TESTS(tc, "snapshot_ai", AF_UNSPEC);
+}
+
+ATF_TC_WITHOUT_HEAD(pf_inet);
+ATF_TC_BODY(pf_inet, tc)
+{
+
+ ATF_REQUIRE_FEATURE("inet");
+ RUN_TESTS(tc, NULL, AF_INET);
+}
+
+ATF_TC_WITHOUT_HEAD(pf_inet_with_snapshot);
+ATF_TC_BODY(pf_inet_with_snapshot, tc)
+{
+
+ ATF_REQUIRE_FEATURE("inet");
+ RUN_TESTS(tc, "snapshot_ai4", AF_INET);
+}
+
+ATF_TC_WITHOUT_HEAD(pf_inet6);
+ATF_TC_BODY(pf_inet6, tc)
+{
+
+ ATF_REQUIRE_FEATURE("inet6");
+ RUN_TESTS(tc, NULL, AF_INET6);
+}
+
+ATF_TC_WITHOUT_HEAD(pf_inet6_with_snapshot);
+ATF_TC_BODY(pf_inet6_with_snapshot, tc)
+{
+
+ ATF_REQUIRE_FEATURE("inet6");
+ RUN_TESTS(tc, "snapshot_ai6", AF_INET6);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, pf_unspec);
+ ATF_TP_ADD_TC(tp, pf_unspec_with_snapshot);
+ ATF_TP_ADD_TC(tp, pf_inet);
+ ATF_TP_ADD_TC(tp, pf_inet_with_snapshot);
+ ATF_TP_ADD_TC(tp, pf_inet6);
+ ATF_TP_ADD_TC(tp, pf_inet6_with_snapshot);
+
+ return (atf_no_error());
+}
Property changes on: trunk/lib/libc/tests/nss/getaddrinfo_test.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/nss/getgr_test.c
===================================================================
--- trunk/lib/libc/tests/nss/getgr_test.c (rev 0)
+++ trunk/lib/libc/tests/nss/getgr_test.c 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,540 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2006 Michael Bushkov <bushman at freebsd.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/lib/libc/tests/nss/getgr_test.c 319298 2017-05-31 08:30:37Z ngie $");
+
+#include <arpa/inet.h>
+#include <errno.h>
+#include <grp.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stringlist.h>
+#include <unistd.h>
+
+#include <atf-c.h>
+
+#include "testutil.h"
+
+enum test_methods {
+ TEST_GETGRENT = 1,
+ TEST_GETGRNAM = 2,
+ TEST_GETGRGID = 4,
+ TEST_GETGRENT_2PASS = 8,
+ TEST_BUILD_SNAPSHOT = 16,
+};
+
+DECLARE_TEST_DATA(group)
+DECLARE_TEST_FILE_SNAPSHOT(group)
+DECLARE_1PASS_TEST(group)
+DECLARE_2PASS_TEST(group)
+
+static void clone_group(struct group *, struct group const *);
+static int compare_group(struct group *, struct group *, void *);
+static void dump_group(struct group *);
+static void free_group(struct group *);
+
+static void sdump_group(struct group *, char *, size_t);
+static int group_read_snapshot_func(struct group *, char *);
+
+static int group_check_ambiguity(struct group_test_data *,
+ struct group *);
+static int group_fill_test_data(struct group_test_data *);
+static int group_test_correctness(struct group *, void *);
+static int group_test_getgrnam(struct group *, void *);
+static int group_test_getgrgid(struct group *, void *);
+static int group_test_getgrent(struct group *, void *);
+
+IMPLEMENT_TEST_DATA(group)
+IMPLEMENT_TEST_FILE_SNAPSHOT(group)
+IMPLEMENT_1PASS_TEST(group)
+IMPLEMENT_2PASS_TEST(group)
+
+static void
+clone_group(struct group *dest, struct group const *src)
+{
+ ATF_REQUIRE(dest != NULL);
+ ATF_REQUIRE(src != NULL);
+
+ char **cp;
+ int members_num;
+
+ memset(dest, 0, sizeof(struct group));
+
+ if (src->gr_name != NULL) {
+ dest->gr_name = strdup(src->gr_name);
+ ATF_REQUIRE(dest->gr_name != NULL);
+ }
+
+ if (src->gr_passwd != NULL) {
+ dest->gr_passwd = strdup(src->gr_passwd);
+ ATF_REQUIRE(dest->gr_passwd != NULL);
+ }
+ dest->gr_gid = src->gr_gid;
+
+ if (src->gr_mem != NULL) {
+ members_num = 0;
+ for (cp = src->gr_mem; *cp; ++cp)
+ ++members_num;
+
+ dest->gr_mem = calloc(members_num + 1, sizeof(char *));
+ ATF_REQUIRE(dest->gr_mem != NULL);
+
+ for (cp = src->gr_mem; *cp; ++cp) {
+ dest->gr_mem[cp - src->gr_mem] = strdup(*cp);
+ ATF_REQUIRE(dest->gr_mem[cp - src->gr_mem] != NULL);
+ }
+ }
+}
+
+static void
+free_group(struct group *grp)
+{
+ char **cp;
+
+ ATF_REQUIRE(grp != NULL);
+
+ free(grp->gr_name);
+ free(grp->gr_passwd);
+
+ for (cp = grp->gr_mem; *cp; ++cp)
+ free(*cp);
+ free(grp->gr_mem);
+}
+
+static int
+compare_group(struct group *grp1, struct group *grp2, void *mdata)
+{
+ char **c1, **c2;
+
+ if (grp1 == grp2)
+ return (0);
+
+ if (grp1 == NULL || grp2 == NULL)
+ goto errfin;
+
+ if (strcmp(grp1->gr_name, grp2->gr_name) != 0 ||
+ strcmp(grp1->gr_passwd, grp2->gr_passwd) != 0 ||
+ grp1->gr_gid != grp2->gr_gid)
+ goto errfin;
+
+ c1 = grp1->gr_mem;
+ c2 = grp2->gr_mem;
+
+ if (grp1->gr_mem == NULL || grp2->gr_mem == NULL)
+ goto errfin;
+
+ for (; *c1 && *c2; ++c1, ++c2)
+ if (strcmp(*c1, *c2) != 0)
+ goto errfin;
+
+ if (*c1 != '\0' || *c2 != '\0')
+ goto errfin;
+
+ return 0;
+
+errfin:
+ if (mdata == NULL) {
+ printf("following structures are not equal:\n");
+ dump_group(grp1);
+ dump_group(grp2);
+ }
+
+ return (-1);
+}
+
+static void
+sdump_group(struct group *grp, char *buffer, size_t buflen)
+{
+ char **cp;
+ int written;
+
+ written = snprintf(buffer, buflen, "%s %s %d",
+ grp->gr_name, grp->gr_passwd, grp->gr_gid);
+ buffer += written;
+ if (written > (int)buflen)
+ return;
+ buflen -= written;
+
+ if (grp->gr_mem != NULL) {
+ if (*(grp->gr_mem) != '\0') {
+ for (cp = grp->gr_mem; *cp; ++cp) {
+ written = snprintf(buffer, buflen, " %s",*cp);
+ buffer += written;
+ if (written > (int)buflen)
+ return;
+ buflen -= written;
+
+ if (buflen == 0)
+ return;
+ }
+ } else
+ snprintf(buffer, buflen, " nomem");
+ } else
+ snprintf(buffer, buflen, " (null)");
+}
+
+static int
+group_read_snapshot_func(struct group *grp, char *line)
+{
+ StringList *sl;
+ char *s, *ps, *ts;
+ int i;
+
+ printf("1 line read from snapshot:\n%s\n", line);
+
+ i = 0;
+ sl = NULL;
+ ps = line;
+ memset(grp, 0, sizeof(struct group));
+ while ((s = strsep(&ps, " ")) != NULL) {
+ switch (i) {
+ case 0:
+ grp->gr_name = strdup(s);
+ ATF_REQUIRE(grp->gr_name != NULL);
+ break;
+
+ case 1:
+ grp->gr_passwd = strdup(s);
+ ATF_REQUIRE(grp->gr_passwd != NULL);
+ break;
+
+ case 2:
+ grp->gr_gid = (gid_t)strtol(s, &ts, 10);
+ if (*ts != '\0') {
+ free(grp->gr_name);
+ free(grp->gr_passwd);
+ grp->gr_name = NULL;
+ grp->gr_passwd = NULL;
+ return (-1);
+ }
+ break;
+
+ default:
+ if (sl == NULL) {
+ if (strcmp(s, "(null)") == 0)
+ return (0);
+
+ sl = sl_init();
+ ATF_REQUIRE(sl != NULL);
+
+ if (strcmp(s, "nomem") != 0) {
+ ts = strdup(s);
+ ATF_REQUIRE(ts != NULL);
+ sl_add(sl, ts);
+ }
+ } else {
+ ts = strdup(s);
+ ATF_REQUIRE(ts != NULL);
+ sl_add(sl, ts);
+ }
+ break;
+ }
+ ++i;
+ }
+
+ if (i < 3) {
+ free(grp->gr_name);
+ free(grp->gr_passwd);
+ memset(grp, 0, sizeof(struct group));
+ return (-1);
+ }
+
+ sl_add(sl, NULL);
+ grp->gr_mem = sl->sl_str;
+
+ /* NOTE: is it a dirty hack or not? */
+ free(sl);
+ return (0);
+}
+
+static void
+dump_group(struct group *result)
+{
+ if (result != NULL) {
+ char buffer[1024];
+ sdump_group(result, buffer, sizeof(buffer));
+ printf("%s\n", buffer);
+ } else
+ printf("(null)\n");
+}
+
+static int
+group_fill_test_data(struct group_test_data *td)
+{
+ struct group *grp;
+
+ setgroupent(1);
+ while ((grp = getgrent()) != NULL) {
+ if (group_test_correctness(grp, NULL) == 0)
+ TEST_DATA_APPEND(group, td, grp);
+ else
+ return (-1);
+ }
+ endgrent();
+
+ return (0);
+}
+
+static int
+group_test_correctness(struct group *grp, void *mdata __unused)
+{
+ printf("testing correctness with the following data:\n");
+ dump_group(grp);
+
+ if (grp == NULL)
+ goto errfin;
+
+ if (grp->gr_name == NULL)
+ goto errfin;
+
+ if (grp->gr_passwd == NULL)
+ goto errfin;
+
+ if (grp->gr_mem == NULL)
+ goto errfin;
+
+ printf("correct\n");
+
+ return (0);
+errfin:
+ printf("incorrect\n");
+
+ return (-1);
+}
+
+/* group_check_ambiguity() is needed here because when doing the getgrent()
+ * calls sequence, records from different nsswitch sources can be different,
+ * though having the same pw_name/pw_uid */
+static int
+group_check_ambiguity(struct group_test_data *td, struct group *pwd)
+{
+
+ return (TEST_DATA_FIND(group, td, pwd, compare_group,
+ NULL) != NULL ? 0 : -1);
+}
+
+static int
+group_test_getgrnam(struct group *grp_model, void *mdata)
+{
+ struct group *grp;
+
+ printf("testing getgrnam() with the following data:\n");
+ dump_group(grp_model);
+
+ grp = getgrnam(grp_model->gr_name);
+ if (group_test_correctness(grp, NULL) != 0)
+ goto errfin;
+
+ if (compare_group(grp, grp_model, NULL) != 0 &&
+ group_check_ambiguity((struct group_test_data *)mdata, grp) != 0)
+ goto errfin;
+
+ return (0);
+
+errfin:
+ return (-1);
+}
+
+static int
+group_test_getgrgid(struct group *grp_model, void *mdata)
+{
+ struct group *grp;
+
+ printf("testing getgrgid() with the following data...\n");
+ dump_group(grp_model);
+
+ grp = getgrgid(grp_model->gr_gid);
+ if (group_test_correctness(grp, NULL) != 0 ||
+ (compare_group(grp, grp_model, NULL) != 0 &&
+ group_check_ambiguity((struct group_test_data *)mdata, grp) != 0)) {
+ return (-1);
+ } else {
+ return (0);
+ }
+}
+
+static int
+group_test_getgrent(struct group *grp, void *mdata __unused)
+{
+ /* Only correctness can be checked when doing 1-pass test for
+ * getgrent(). */
+ return (group_test_correctness(grp, NULL));
+}
+
+static int
+run_tests(const char *snapshot_file, enum test_methods method)
+{
+ struct group_test_data td, td_snap, td_2pass;
+ int rv;
+
+ TEST_DATA_INIT(group, &td, clone_group, free_group);
+ TEST_DATA_INIT(group, &td_snap, clone_group, free_group);
+ if (snapshot_file != NULL) {
+ if (access(snapshot_file, W_OK | R_OK) != 0) {
+ if (errno == ENOENT)
+ method = TEST_BUILD_SNAPSHOT;
+ else {
+ printf("can't access the file %s\n",
+ snapshot_file);
+
+ rv = -1;
+ goto fin;
+ }
+ } else {
+ if (method == TEST_BUILD_SNAPSHOT) {
+ rv = 0;
+ goto fin;
+ }
+
+ TEST_SNAPSHOT_FILE_READ(group, snapshot_file,
+ &td_snap, group_read_snapshot_func);
+ }
+ }
+
+ rv = group_fill_test_data(&td);
+ if (rv == -1)
+ return (-1);
+ switch (method) {
+ case TEST_GETGRNAM:
+ if (snapshot_file == NULL)
+ rv = DO_1PASS_TEST(group, &td,
+ group_test_getgrnam, (void *)&td);
+ else
+ rv = DO_1PASS_TEST(group, &td_snap,
+ group_test_getgrnam, (void *)&td_snap);
+ break;
+ case TEST_GETGRGID:
+ if (snapshot_file == NULL)
+ rv = DO_1PASS_TEST(group, &td,
+ group_test_getgrgid, (void *)&td);
+ else
+ rv = DO_1PASS_TEST(group, &td_snap,
+ group_test_getgrgid, (void *)&td_snap);
+ break;
+ case TEST_GETGRENT:
+ if (snapshot_file == NULL)
+ rv = DO_1PASS_TEST(group, &td, group_test_getgrent,
+ (void *)&td);
+ else
+ rv = DO_2PASS_TEST(group, &td, &td_snap,
+ compare_group, NULL);
+ break;
+ case TEST_GETGRENT_2PASS:
+ TEST_DATA_INIT(group, &td_2pass, clone_group, free_group);
+ rv = group_fill_test_data(&td_2pass);
+ if (rv != -1)
+ rv = DO_2PASS_TEST(group, &td, &td_2pass,
+ compare_group, NULL);
+ TEST_DATA_DESTROY(group, &td_2pass);
+ break;
+ case TEST_BUILD_SNAPSHOT:
+ if (snapshot_file != NULL)
+ rv = TEST_SNAPSHOT_FILE_WRITE(group, snapshot_file, &td,
+ sdump_group);
+ break;
+ default:
+ rv = 0;
+ break;
+ }
+
+fin:
+ TEST_DATA_DESTROY(group, &td_snap);
+ TEST_DATA_DESTROY(group, &td);
+
+ return (rv);
+}
+
+#define SNAPSHOT_FILE "snapshot_grp"
+
+ATF_TC_WITHOUT_HEAD(getgrent);
+ATF_TC_BODY(getgrent, tc)
+{
+
+ ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_GETGRENT) == 0);
+}
+
+ATF_TC_WITHOUT_HEAD(getgrent_with_snapshot);
+ATF_TC_BODY(getgrent_with_snapshot, tc)
+{
+
+ ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_BUILD_SNAPSHOT) == 0);
+ ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_GETGRENT) == 0);
+}
+
+ATF_TC_WITHOUT_HEAD(getgrent_with_two_pass);
+ATF_TC_BODY(getgrent_with_two_pass, tc)
+{
+
+ ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_GETGRENT_2PASS) == 0);
+}
+
+ATF_TC_WITHOUT_HEAD(getgrgid);
+ATF_TC_BODY(getgrgid, tc)
+{
+
+ ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_GETGRGID) == 0);
+}
+
+ATF_TC_WITHOUT_HEAD(getgrgid_with_snapshot);
+ATF_TC_BODY(getgrgid_with_snapshot, tc)
+{
+
+ ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_BUILD_SNAPSHOT) == 0);
+ ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_GETGRGID) == 0);
+}
+
+ATF_TC_WITHOUT_HEAD(getgrnam);
+ATF_TC_BODY(getgrnam, tc)
+{
+
+ ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_GETGRNAM) == 0);
+}
+
+ATF_TC_WITHOUT_HEAD(getgrnam_with_snapshot);
+ATF_TC_BODY(getgrnam_with_snapshot, tc)
+{
+
+ ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_BUILD_SNAPSHOT) == 0);
+ ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_GETGRNAM) == 0);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, getgrent);
+ ATF_TP_ADD_TC(tp, getgrent_with_snapshot);
+ ATF_TP_ADD_TC(tp, getgrent_with_two_pass);
+ ATF_TP_ADD_TC(tp, getgrgid);
+ ATF_TP_ADD_TC(tp, getgrgid_with_snapshot);
+ ATF_TP_ADD_TC(tp, getgrnam);
+ ATF_TP_ADD_TC(tp, getgrnam_with_snapshot);
+
+ return (atf_no_error());
+}
Property changes on: trunk/lib/libc/tests/nss/getgr_test.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/nss/gethostby_test.c
===================================================================
--- trunk/lib/libc/tests/nss/gethostby_test.c (rev 0)
+++ trunk/lib/libc/tests/nss/gethostby_test.c 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,1514 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2006 Michael Bushkov <bushman at freebsd.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/lib/libc/tests/nss/gethostby_test.c 321144 2017-07-18 18:09:26Z ngie $");
+
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <arpa/inet.h>
+#include <netinet/in.h>
+#include <errno.h>
+#include <netdb.h>
+#include <resolv.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stringlist.h>
+#include <unistd.h>
+
+#include <atf-c.h>
+
+#include "freebsd_test_suite/macros.h"
+#include "testutil.h"
+
+enum test_methods {
+ TEST_GETHOSTBYNAME2,
+ TEST_GETHOSTBYADDR,
+ TEST_GETHOSTBYNAME2_GETADDRINFO,
+ TEST_GETHOSTBYADDR_GETNAMEINFO,
+ TEST_BUILD_SNAPSHOT,
+ TEST_BUILD_ADDR_SNAPSHOT
+};
+
+static int ipnode_flags = 0;
+static int af_type = AF_INET;
+static bool use_ipnode_functions;
+
+DECLARE_TEST_DATA(hostent)
+DECLARE_TEST_FILE_SNAPSHOT(hostent)
+DECLARE_1PASS_TEST(hostent)
+DECLARE_2PASS_TEST(hostent)
+
+/* These stubs will use gethostby***() or getipnodeby***() functions,
+ * depending on the use_ipnode_functions global variable value */
+static struct hostent *__gethostbyname2(const char *, int);
+static struct hostent *__gethostbyaddr(const void *, socklen_t, int);
+static void __freehostent(struct hostent *);
+
+static void clone_hostent(struct hostent *, struct hostent const *);
+static int compare_hostent(struct hostent *, struct hostent *, void *);
+static void dump_hostent(struct hostent *);
+static void free_hostent(struct hostent *);
+
+static int is_hostent_equal(struct hostent *, struct addrinfo *);
+
+static void sdump_hostent(struct hostent *, char *, size_t);
+static int hostent_read_hostlist_func(struct hostent *, char *);
+static int hostent_read_snapshot_addr(char *, unsigned char *, size_t);
+static int hostent_read_snapshot_func(struct hostent *, char *);
+
+static int hostent_test_correctness(struct hostent *, void *);
+static int hostent_test_gethostbyaddr(struct hostent *, void *);
+static int hostent_test_getaddrinfo_eq(struct hostent *, void *);
+static int hostent_test_getnameinfo_eq(struct hostent *, void *);
+
+IMPLEMENT_TEST_DATA(hostent)
+IMPLEMENT_TEST_FILE_SNAPSHOT(hostent)
+IMPLEMENT_1PASS_TEST(hostent)
+IMPLEMENT_2PASS_TEST(hostent)
+
+static struct hostent *
+__gethostbyname2(const char *name, int af)
+{
+ struct hostent *he;
+ int error;
+
+ if (use_ipnode_functions) {
+ error = 0;
+ he = getipnodebyname(name, af, ipnode_flags, &error);
+ if (he == NULL)
+ errno = error;
+ } else
+ he = gethostbyname2(name, af);
+
+ return (he);
+}
+
+static struct hostent *
+__gethostbyaddr(const void *addr, socklen_t len, int af)
+{
+ struct hostent *he;
+ int error;
+
+ if (use_ipnode_functions) {
+ error = 0;
+ he = getipnodebyaddr(addr, len, af, &error);
+ if (he == NULL)
+ errno = error;
+ } else
+ he = gethostbyaddr(addr, len, af);
+
+ return (he);
+}
+
+static void
+__freehostent(struct hostent *he)
+{
+
+ /* NOTE: checking for he != NULL - just in case */
+ if (use_ipnode_functions && he != NULL)
+ freehostent(he);
+}
+
+static void
+clone_hostent(struct hostent *dest, struct hostent const *src)
+{
+ ATF_REQUIRE(dest != NULL);
+ ATF_REQUIRE(src != NULL);
+
+ char **cp;
+ int aliases_num;
+ int addrs_num;
+ size_t offset;
+
+ memset(dest, 0, sizeof(struct hostent));
+
+ if (src->h_name != NULL) {
+ dest->h_name = strdup(src->h_name);
+ ATF_REQUIRE(dest->h_name != NULL);
+ }
+
+ dest->h_addrtype = src->h_addrtype;
+ dest->h_length = src->h_length;
+
+ if (src->h_aliases != NULL) {
+ aliases_num = 0;
+ for (cp = src->h_aliases; *cp; ++cp)
+ ++aliases_num;
+
+ dest->h_aliases = calloc(aliases_num + 1, sizeof(char *));
+ ATF_REQUIRE(dest->h_aliases != NULL);
+
+ for (cp = src->h_aliases; *cp; ++cp) {
+ dest->h_aliases[cp - src->h_aliases] = strdup(*cp);
+ ATF_REQUIRE(dest->h_aliases[cp - src->h_aliases] != NULL);
+ }
+ }
+
+ if (src->h_addr_list != NULL) {
+ addrs_num = 0;
+ for (cp = src->h_addr_list; *cp; ++cp)
+ ++addrs_num;
+
+ dest->h_addr_list = calloc(addrs_num + 1, sizeof(char *));
+ ATF_REQUIRE(dest->h_addr_list != NULL);
+
+ for (cp = src->h_addr_list; *cp; ++cp) {
+ offset = cp - src->h_addr_list;
+ dest->h_addr_list[offset] = malloc(src->h_length);
+ ATF_REQUIRE(dest->h_addr_list[offset] != NULL);
+ memcpy(dest->h_addr_list[offset],
+ src->h_addr_list[offset], src->h_length);
+ }
+ }
+}
+
+static void
+free_hostent(struct hostent *ht)
+{
+ char **cp;
+
+ ATF_REQUIRE(ht != NULL);
+
+ free(ht->h_name);
+
+ if (ht->h_aliases != NULL) {
+ for (cp = ht->h_aliases; *cp; ++cp)
+ free(*cp);
+ free(ht->h_aliases);
+ }
+
+ if (ht->h_addr_list != NULL) {
+ for (cp = ht->h_addr_list; *cp; ++cp)
+ free(*cp);
+ free(ht->h_addr_list);
+ }
+}
+
+static int
+compare_hostent(struct hostent *ht1, struct hostent *ht2, void *mdata)
+{
+ char **c1, **c2, **ct, **cb;
+ int b;
+
+ if (ht1 == ht2)
+ return 0;
+
+ if (ht1 == NULL || ht2 == NULL)
+ goto errfin;
+
+ if (ht1->h_name == NULL || ht2->h_name == NULL)
+ goto errfin;
+
+ if (ht1->h_addrtype != ht2->h_addrtype ||
+ ht1->h_length != ht2->h_length ||
+ strcmp(ht1->h_name, ht2->h_name) != 0)
+ goto errfin;
+
+ c1 = ht1->h_aliases;
+ c2 = ht2->h_aliases;
+
+ if ((ht1->h_aliases == NULL || ht2->h_aliases == NULL) &&
+ ht1->h_aliases != ht2->h_aliases)
+ goto errfin;
+
+ if (c1 != NULL && c2 != NULL) {
+ cb = c1;
+ for (;*c1; ++c1) {
+ b = 0;
+ for (ct = c2; *ct; ++ct) {
+ if (strcmp(*c1, *ct) == 0) {
+ b = 1;
+ break;
+ }
+ }
+ if (b == 0) {
+ printf("h1 aliases item can't be found in h2 "
+ "aliases\n");
+ goto errfin;
+ }
+ }
+
+ c1 = cb;
+ for (;*c2; ++c2) {
+ b = 0;
+ for (ct = c1; *ct; ++ct) {
+ if (strcmp(*c2, *ct) == 0) {
+ b = 1;
+ break;
+ }
+ }
+ if (b == 0) {
+ printf("h2 aliases item can't be found in h1 "
+ "aliases\n");
+ goto errfin;
+ }
+ }
+ }
+
+ c1 = ht1->h_addr_list;
+ c2 = ht2->h_addr_list;
+
+ if ((ht1->h_addr_list == NULL || ht2->h_addr_list== NULL) &&
+ ht1->h_addr_list != ht2->h_addr_list)
+ goto errfin;
+
+ if (c1 != NULL && c2 != NULL) {
+ cb = c1;
+ for (; *c1; ++c1) {
+ b = 0;
+ for (ct = c2; *ct; ++ct) {
+ if (memcmp(*c1, *ct, ht1->h_length) == 0) {
+ b = 1;
+ break;
+ }
+ }
+ if (b == 0) {
+ printf("h1 addresses item can't be found in "
+ "h2 addresses\n");
+ goto errfin;
+ }
+ }
+
+ c1 = cb;
+ for (; *c2; ++c2) {
+ b = 0;
+ for (ct = c1; *ct; ++ct) {
+ if (memcmp(*c2, *ct, ht1->h_length) == 0) {
+ b = 1;
+ break;
+ }
+ }
+ if (b == 0) {
+ printf("h2 addresses item can't be found in "
+ "h1 addresses\n");
+ goto errfin;
+ }
+ }
+ }
+
+ return 0;
+
+errfin:
+ if (mdata == NULL) {
+ printf("following structures are not equal:\n");
+ dump_hostent(ht1);
+ dump_hostent(ht2);
+ }
+
+ return (-1);
+}
+
+static int
+check_addrinfo_for_name(struct addrinfo *ai, char const *name)
+{
+ struct addrinfo *ai2;
+
+ for (ai2 = ai; ai2 != NULL; ai2 = ai2->ai_next) {
+ if (strcmp(ai2->ai_canonname, name) == 0)
+ return (0);
+ }
+
+ return (-1);
+}
+
+static int
+check_addrinfo_for_addr(struct addrinfo *ai, char const *addr,
+ socklen_t addrlen, int af)
+{
+ struct addrinfo *ai2;
+
+ for (ai2 = ai; ai2 != NULL; ai2 = ai2->ai_next) {
+ if (af != ai2->ai_family)
+ continue;
+
+ switch (af) {
+ case AF_INET:
+ if (memcmp(addr,
+ (void *)&((struct sockaddr_in *)ai2->ai_addr)->sin_addr,
+ MIN(addrlen, ai2->ai_addrlen)) == 0)
+ return (0);
+ break;
+ case AF_INET6:
+ if (memcmp(addr,
+ (void *)&((struct sockaddr_in6 *)ai2->ai_addr)->sin6_addr,
+ MIN(addrlen, ai2->ai_addrlen)) == 0)
+ return (0);
+ break;
+ default:
+ break;
+ }
+ }
+
+ return (-1);
+}
+
+static int
+is_hostent_equal(struct hostent *he, struct addrinfo *ai)
+{
+ char **cp;
+ int rv;
+
+#ifdef DEBUG
+ printf("checking equality of he and ai\n");
+#endif
+
+ rv = check_addrinfo_for_name(ai, he->h_name);
+ if (rv != 0) {
+ printf("not equal - he->h_name couldn't be found\n");
+ return (rv);
+ }
+
+ for (cp = he->h_addr_list; *cp; ++cp) {
+ rv = check_addrinfo_for_addr(ai, *cp, he->h_length,
+ he->h_addrtype);
+ if (rv != 0) {
+ printf("not equal - one of he->h_addr_list couldn't be found\n");
+ return (rv);
+ }
+ }
+
+#ifdef DEBUG
+ printf("equal\n");
+#endif
+
+ return (0);
+}
+
+static void
+sdump_hostent(struct hostent *ht, char *buffer, size_t buflen)
+{
+ char **cp;
+ size_t i;
+ int written;
+
+ written = snprintf(buffer, buflen, "%s %d %d",
+ ht->h_name, ht->h_addrtype, ht->h_length);
+ buffer += written;
+ if (written > (int)buflen)
+ return;
+ buflen -= written;
+
+ if (ht->h_aliases != NULL) {
+ if (*(ht->h_aliases) != NULL) {
+ for (cp = ht->h_aliases; *cp; ++cp) {
+ written = snprintf(buffer, buflen, " %s",*cp);
+ buffer += written;
+ if (written > (int)buflen)
+ return;
+ buflen -= written;
+
+ if (buflen == 0)
+ return;
+ }
+ } else {
+ written = snprintf(buffer, buflen, " noaliases");
+ buffer += written;
+ if (written > (int)buflen)
+ return;
+ buflen -= written;
+ }
+ } else {
+ written = snprintf(buffer, buflen, " (null)");
+ buffer += written;
+ if (written > (int)buflen)
+ return;
+ buflen -= written;
+ }
+
+ written = snprintf(buffer, buflen, " : ");
+ buffer += written;
+ if (written > (int)buflen)
+ return;
+ buflen -= written;
+
+ if (ht->h_addr_list != NULL) {
+ if (*(ht->h_addr_list) != NULL) {
+ for (cp = ht->h_addr_list; *cp; ++cp) {
+ for (i = 0; i < (size_t)ht->h_length; ++i) {
+ written = snprintf(buffer, buflen,
+ i + 1 != (size_t)ht->h_length ?
+ "%d." : "%d",
+ (unsigned char)(*cp)[i]);
+ buffer += written;
+ if (written > (int)buflen)
+ return;
+ buflen -= written;
+
+ if (buflen == 0)
+ return;
+ }
+
+ if (*(cp + 1)) {
+ written = snprintf(buffer, buflen,
+ " ");
+ buffer += written;
+ if (written > (int)buflen)
+ return;
+ buflen -= written;
+ }
+ }
+ } else {
+ written = snprintf(buffer, buflen, " noaddrs");
+ buffer += written;
+ if (written > (int)buflen)
+ return;
+ buflen -= written;
+ }
+ } else {
+ written = snprintf(buffer, buflen, " (null)");
+ buffer += written;
+ if (written > (int)buflen)
+ return;
+ buflen -= written;
+ }
+}
+
+static int
+hostent_read_hostlist_func(struct hostent *he, char *line)
+{
+ struct hostent *result;
+ int rv;
+
+#ifdef DEBUG
+ printf("resolving %s: ", line);
+#endif
+ result = __gethostbyname2(line, af_type);
+ if (result != NULL) {
+#ifdef DEBUG
+ printf("found\n");
+#endif
+
+ rv = hostent_test_correctness(result, NULL);
+ if (rv != 0) {
+ __freehostent(result);
+ return (rv);
+ }
+
+ clone_hostent(he, result);
+ __freehostent(result);
+ } else {
+#ifdef DEBUG
+ printf("not found\n");
+#endif
+ memset(he, 0, sizeof(struct hostent));
+ he->h_name = strdup(line);
+ ATF_REQUIRE(he->h_name != NULL);
+ }
+ return (0);
+}
+
+static int
+hostent_read_snapshot_addr(char *addr, unsigned char *result, size_t len)
+{
+ char *s, *ps, *ts;
+
+ ps = addr;
+ while ( (s = strsep(&ps, ".")) != NULL) {
+ if (len == 0)
+ return (-1);
+
+ *result = (unsigned char)strtol(s, &ts, 10);
+ ++result;
+ if (*ts != '\0')
+ return (-1);
+
+ --len;
+ }
+ if (len != 0)
+ return (-1);
+ else
+ return (0);
+}
+
+static int
+hostent_read_snapshot_func(struct hostent *ht, char *line)
+{
+ StringList *sl1, *sl2;
+ char *s, *ps, *ts;
+ int i, rv;
+
+#ifdef DEBUG
+ printf("1 line read from snapshot:\n%s\n", line);
+#endif
+
+ rv = 0;
+ i = 0;
+ sl1 = sl2 = NULL;
+ ps = line;
+ memset(ht, 0, sizeof(struct hostent));
+ while ((s = strsep(&ps, " ")) != NULL) {
+ switch (i) {
+ case 0:
+ ht->h_name = strdup(s);
+ ATF_REQUIRE(ht->h_name != NULL);
+ break;
+
+ case 1:
+ ht->h_addrtype = (int)strtol(s, &ts, 10);
+ if (*ts != '\0')
+ goto fin;
+ break;
+
+ case 2:
+ ht->h_length = (int)strtol(s, &ts, 10);
+ if (*ts != '\0')
+ goto fin;
+ break;
+
+ case 3:
+ if (sl1 == NULL) {
+ if (strcmp(s, "(null)") == 0)
+ return (0);
+
+ sl1 = sl_init();
+ ATF_REQUIRE(sl1 != NULL);
+
+ if (strcmp(s, "noaliases") != 0) {
+ ts = strdup(s);
+ ATF_REQUIRE(ts != NULL);
+ sl_add(sl1, ts);
+ }
+ } else {
+ if (strcmp(s, ":") == 0)
+ ++i;
+ else {
+ ts = strdup(s);
+ ATF_REQUIRE(ts != NULL);
+ sl_add(sl1, ts);
+ }
+ }
+ break;
+
+ case 4:
+ if (sl2 == NULL) {
+ if (strcmp(s, "(null)") == 0)
+ return (0);
+
+ sl2 = sl_init();
+ ATF_REQUIRE(sl2 != NULL);
+
+ if (strcmp(s, "noaddrs") != 0) {
+ ts = calloc(1, ht->h_length);
+ ATF_REQUIRE(ts != NULL);
+ rv = hostent_read_snapshot_addr(s,
+ (unsigned char *)ts,
+ ht->h_length);
+ sl_add(sl2, ts);
+ if (rv != 0)
+ goto fin;
+ }
+ } else {
+ ts = calloc(1, ht->h_length);
+ ATF_REQUIRE(ts != NULL);
+ rv = hostent_read_snapshot_addr(s,
+ (unsigned char *)ts, ht->h_length);
+ sl_add(sl2, ts);
+ if (rv != 0)
+ goto fin;
+ }
+ break;
+ default:
+ break;
+ }
+
+ if (i != 3 && i != 4)
+ ++i;
+ }
+
+fin:
+ if (sl1 != NULL) {
+ sl_add(sl1, NULL);
+ ht->h_aliases = sl1->sl_str;
+ }
+ if (sl2 != NULL) {
+ sl_add(sl2, NULL);
+ ht->h_addr_list = sl2->sl_str;
+ }
+
+ if ((i != 4) || (rv != 0)) {
+ free_hostent(ht);
+ memset(ht, 0, sizeof(struct hostent));
+ return (-1);
+ }
+
+ /* NOTE: is it a dirty hack or not? */
+ free(sl1);
+ free(sl2);
+ return (0);
+}
+
+static void
+dump_hostent(struct hostent *result)
+{
+ if (result != NULL) {
+ char buffer[1024];
+ sdump_hostent(result, buffer, sizeof(buffer));
+ printf("%s\n", buffer);
+ } else
+ printf("(null)\n");
+}
+
+static int
+hostent_test_correctness(struct hostent *ht, void *mdata __unused)
+{
+
+#ifdef DEBUG
+ printf("testing correctness with the following data:\n");
+ dump_hostent(ht);
+#endif
+
+ if (ht == NULL)
+ goto errfin;
+
+ if (ht->h_name == NULL)
+ goto errfin;
+
+ if (!((ht->h_addrtype >= 0) && (ht->h_addrtype < AF_MAX)))
+ goto errfin;
+
+ if ((ht->h_length != sizeof(struct in_addr)) &&
+ (ht->h_length != sizeof(struct in6_addr)))
+ goto errfin;
+
+ if (ht->h_aliases == NULL)
+ goto errfin;
+
+ if (ht->h_addr_list == NULL)
+ goto errfin;
+
+#ifdef DEBUG
+ printf("correct\n");
+#endif
+
+ return (0);
+errfin:
+ printf("incorrect\n");
+
+ return (-1);
+}
+
+static int
+hostent_test_gethostbyaddr(struct hostent *he, void *mdata)
+{
+ struct hostent *result;
+ struct hostent_test_data *addr_test_data;
+ int rv;
+
+ addr_test_data = (struct hostent_test_data *)mdata;
+
+ /* We should omit unresolved hostents */
+ if (he->h_addr_list != NULL) {
+ char **cp;
+ for (cp = he->h_addr_list; *cp; ++cp) {
+#ifdef DEBUG
+ printf("doing reverse lookup for %s\n", he->h_name);
+#endif
+
+ result = __gethostbyaddr(*cp, he->h_length,
+ he->h_addrtype);
+ if (result == NULL) {
+#ifdef DEBUG
+ printf("%s: warning: reverse lookup failed "
+ "for %s: %s\n", __func__, he->h_name,
+ strerror(errno));
+#endif
+ continue;
+ }
+ rv = hostent_test_correctness(result, NULL);
+ if (rv != 0) {
+ __freehostent(result);
+ return (rv);
+ }
+
+ if (addr_test_data != NULL)
+ TEST_DATA_APPEND(hostent, addr_test_data,
+ result);
+
+ __freehostent(result);
+ }
+ }
+
+ return (0);
+}
+
+static int
+hostent_test_getaddrinfo_eq(struct hostent *he, void *mdata __unused)
+{
+ struct addrinfo *ai, hints;
+ int rv;
+
+ ai = NULL;
+ memset(&hints, 0, sizeof(struct addrinfo));
+ hints.ai_family = af_type;
+ hints.ai_flags = AI_CANONNAME;
+
+ printf("using getaddrinfo() to resolve %s\n", he->h_name);
+
+ /* struct hostent *he was not resolved */
+ if (he->h_addr_list == NULL) {
+ /* We can be sure that he->h_name is not NULL */
+ rv = getaddrinfo(he->h_name, NULL, &hints, &ai);
+ if (rv == 0) {
+ printf("not ok - shouldn't have been resolved\n");
+ rv = -1;
+ } else
+ rv = 0;
+ } else {
+ rv = getaddrinfo(he->h_name, NULL, &hints, &ai);
+ if (rv != 0) {
+ printf("not ok - should have been resolved\n");
+ rv = -1;
+ goto done;
+ }
+ rv = is_hostent_equal(he, ai);
+ if (rv != 0) {
+ printf("not ok - addrinfo and hostent are not equal\n");
+ rv = -1;
+ }
+ }
+done:
+ if (ai != NULL)
+ freeaddrinfo(ai);
+ return (rv);
+}
+
+static int
+hostent_test_getnameinfo_eq(struct hostent *he, void *mdata __unused)
+{
+ char **cp;
+ char buffer[NI_MAXHOST];
+ struct sockaddr_in sin;
+ struct sockaddr_in6 sin6;
+ struct sockaddr *saddr;
+ struct hostent *result;
+ int i, rv;
+
+ if (he->h_addr_list == NULL)
+ return (0);
+
+ for (cp = he->h_addr_list; *cp; ++cp) {
+#ifdef DEBUG
+ printf("doing reverse lookup for %s\n", he->h_name);
+#endif
+ result = __gethostbyaddr(*cp, he->h_length,
+ he->h_addrtype);
+ if (result != NULL) {
+ rv = hostent_test_correctness(result, NULL);
+ if (rv != 0) {
+ __freehostent(result);
+ return (rv);
+ }
+ } else
+ printf("%s: warning: reverse lookup failed "
+ "for %s: %s\n", __func__, he->h_name,
+ strerror(errno));
+
+ switch (he->h_addrtype) {
+ case AF_INET:
+ memset(&sin, 0, sizeof(struct sockaddr_in));
+ sin.sin_len = sizeof(struct sockaddr_in);
+ sin.sin_family = AF_INET;
+ memcpy(&sin.sin_addr, *cp, he->h_length);
+
+ saddr = (struct sockaddr *)&sin;
+ break;
+ case AF_INET6:
+ memset(&sin6, 0, sizeof(struct sockaddr_in6));
+ sin6.sin6_len = sizeof(struct sockaddr_in6);
+ sin6.sin6_family = AF_INET6;
+ memcpy(&sin6.sin6_addr, *cp, he->h_length);
+
+ saddr = (struct sockaddr *)&sin6;
+ break;
+ default:
+ printf("warning: %d family is unsupported\n",
+ he->h_addrtype);
+ continue;
+ }
+
+ ATF_REQUIRE(saddr != NULL);
+ rv = getnameinfo(saddr, saddr->sa_len, buffer,
+ sizeof(buffer), NULL, 0, NI_NAMEREQD);
+
+ if (rv != 0 && result != NULL) {
+ printf("getnameinfo() didn't make the reverse "
+ "lookup, when it should have (%s)\n",
+ gai_strerror(rv));
+ return (rv);
+ }
+
+ if (rv == 0 && result == NULL) {
+ printf("getnameinfo() made the "
+ "reverse lookup, when it shouldn't have\n");
+ return (rv);
+ }
+
+ if (rv != 0 && result == NULL) {
+#ifdef DEBUG
+ printf("both getnameinfo() and ***byaddr() failed as "
+ "expected\n");
+#endif
+ continue;
+ }
+
+#ifdef DEBUG
+ printf("comparing %s with %s\n", result->h_name,
+ buffer);
+#endif
+
+ /*
+ * An address might reverse resolve to hostname alias or the
+ * official hostname, e.g. moon.vub.ac.be.
+ */
+ bool found_a_match = false;
+
+ if (strcmp(result->h_name, buffer) == 0) {
+ found_a_match = true;
+#ifdef DEBUG
+ printf("matched official hostname\n");
+#endif
+ } else {
+ for (i = 0; result->h_aliases[i] != NULL; i++) {
+ printf("[%d] resolved: %s\n", i,
+ result->h_aliases[i]);
+ if (strcmp(result->h_aliases[i],
+ buffer) == 0) {
+ printf("matched hostname alias\n");
+ found_a_match = true;
+ break;
+ }
+ }
+ }
+ __freehostent(result);
+
+ if (found_a_match) {
+#ifdef DEBUG
+ printf("getnameinfo() and ***byaddr() results are "
+ "equal\n");
+#endif
+ } else {
+ printf("getnameinfo() and ***byaddr() results are not "
+ "equal for %s\n", he->h_name);
+ return (-1);
+ }
+ }
+
+ return (0);
+}
+
+static int
+run_tests(const char *hostlist_file, const char *snapshot_file, int _af_type,
+ enum test_methods method, bool use_ipv6_mapping)
+{
+ char *snapshot_file_copy;
+ struct hostent_test_data td, td_addr, td_snap;
+ res_state statp;
+ int rv = -2;
+
+ if (snapshot_file == NULL)
+ snapshot_file_copy = NULL;
+ else {
+ snapshot_file_copy = strdup(snapshot_file);
+ ATF_REQUIRE(snapshot_file_copy != NULL);
+ }
+ snapshot_file = snapshot_file_copy;
+
+ switch (_af_type) {
+ case AF_INET:
+ ATF_REQUIRE_FEATURE("inet");
+ ATF_REQUIRE(!use_ipv6_mapping);
+ break;
+ case AF_INET6:
+ ATF_REQUIRE_FEATURE("inet6");
+ break;
+ default:
+ atf_tc_fail("unhandled address family: %d", _af_type);
+ break;
+ }
+
+ if (!use_ipnode_functions) {
+ statp = __res_state();
+ if (statp == NULL || ((statp->options & RES_INIT) == 0 &&
+ res_ninit(statp) == -1)) {
+ printf("error: can't init res_state\n");
+ rv = -1;
+ goto fin2;
+ }
+
+ if (use_ipv6_mapping)
+ statp->options |= RES_USE_INET6;
+ else
+ statp->options &= ~RES_USE_INET6;
+ }
+
+ TEST_DATA_INIT(hostent, &td, clone_hostent, free_hostent);
+ TEST_DATA_INIT(hostent, &td_addr, clone_hostent, free_hostent);
+ TEST_DATA_INIT(hostent, &td_snap, clone_hostent, free_hostent);
+
+ if (access(hostlist_file, R_OK) != 0) {
+ printf("can't access the hostlist file %s\n", hostlist_file);
+ rv = -1;
+ goto fin;
+ }
+
+#ifdef DEBUG
+ printf("building host lists from %s\n", hostlist_file);
+#endif
+
+ rv = TEST_SNAPSHOT_FILE_READ(hostent, hostlist_file, &td,
+ hostent_read_hostlist_func);
+ if (rv != 0) {
+ printf("failed to read the host list file: %s\n",
+ hostlist_file);
+ goto fin;
+ }
+
+ if (snapshot_file != NULL) {
+ if (access(snapshot_file, W_OK | R_OK) != 0) {
+ if (errno == ENOENT) {
+ if (method != TEST_GETHOSTBYADDR)
+ method = TEST_BUILD_SNAPSHOT;
+ else
+ method = TEST_BUILD_ADDR_SNAPSHOT;
+ } else {
+ printf("can't access the snapshot file %s\n",
+ snapshot_file);
+ rv = -1;
+ goto fin;
+ }
+ } else {
+ rv = TEST_SNAPSHOT_FILE_READ(hostent, snapshot_file,
+ &td_snap, hostent_read_snapshot_func);
+ if (rv != 0) {
+ printf("error reading snapshot file\n");
+ goto fin;
+ }
+ }
+ }
+
+ switch (method) {
+ case TEST_GETHOSTBYNAME2:
+ if (snapshot_file != NULL)
+ rv = DO_2PASS_TEST(hostent, &td, &td_snap,
+ compare_hostent, NULL);
+ break;
+ case TEST_GETHOSTBYADDR:
+ rv = DO_1PASS_TEST(hostent, &td,
+ hostent_test_gethostbyaddr, (void *)&td_addr);
+ if (rv != 0)
+ goto fin;
+
+ if (snapshot_file != NULL)
+ rv = DO_2PASS_TEST(hostent, &td_addr, &td_snap,
+ compare_hostent, NULL);
+ break;
+ case TEST_GETHOSTBYNAME2_GETADDRINFO:
+ rv = DO_1PASS_TEST(hostent, &td,
+ hostent_test_getaddrinfo_eq, NULL);
+ break;
+ case TEST_GETHOSTBYADDR_GETNAMEINFO:
+ rv = DO_1PASS_TEST(hostent, &td,
+ hostent_test_getnameinfo_eq, NULL);
+ break;
+ case TEST_BUILD_SNAPSHOT:
+ if (snapshot_file != NULL) {
+ rv = TEST_SNAPSHOT_FILE_WRITE(hostent, snapshot_file,
+ &td, sdump_hostent);
+ }
+ break;
+ case TEST_BUILD_ADDR_SNAPSHOT:
+ if (snapshot_file != NULL) {
+ rv = DO_1PASS_TEST(hostent, &td,
+ hostent_test_gethostbyaddr, (void *)&td_addr);
+ if (rv != 0)
+ goto fin;
+ rv = TEST_SNAPSHOT_FILE_WRITE(hostent, snapshot_file,
+ &td_addr, sdump_hostent);
+ }
+ break;
+ default:
+ rv = 0;
+ break;
+ }
+
+fin:
+ TEST_DATA_DESTROY(hostent, &td_snap);
+ TEST_DATA_DESTROY(hostent, &td_addr);
+ TEST_DATA_DESTROY(hostent, &td);
+
+fin2:
+ free(snapshot_file_copy);
+
+ return (rv);
+}
+
+#define HOSTLIST_FILE "mach"
+
+#define _RUN_TESTS(tc, snapshot_file, af_type, method, use_ipv6_mapping) \
+do { \
+ char *_hostlist_file; \
+ ATF_REQUIRE(0 < asprintf(&_hostlist_file, "%s/%s", \
+ atf_tc_get_config_var(tc, "srcdir"), HOSTLIST_FILE)); \
+ ATF_REQUIRE(run_tests(_hostlist_file, snapshot_file, af_type, \
+ method, use_ipv6_mapping) == 0); \
+ free(_hostlist_file); \
+} while (0)
+
+#define RUN_HOST_TESTS(tc, snapshot_file, af_type, method, use_ipv6_mapping) \
+do { \
+ use_ipnode_functions = false; \
+ _RUN_TESTS(tc, snapshot_file, af_type, method, use_ipv6_mapping); \
+} while (0)
+
+#define RUN_IPNODE_TESTS(tc, snapshot_file, af_type, method, use_ipv6_mapping) \
+do { \
+ use_ipnode_functions = true; \
+ _RUN_TESTS(tc, snapshot_file, af_type, method, use_ipv6_mapping); \
+} while (0)
+
+ATF_TC_WITHOUT_HEAD(gethostbyaddr_ipv4);
+ATF_TC_BODY(gethostbyaddr_ipv4, tc)
+{
+
+ RUN_HOST_TESTS(tc, NULL, AF_INET, TEST_GETHOSTBYADDR, false);
+}
+
+ATF_TC_WITHOUT_HEAD(gethostbyaddr_ipv4_with_snapshot);
+ATF_TC_BODY(gethostbyaddr_ipv4_with_snapshot, tc)
+{
+
+ RUN_HOST_TESTS(tc, "snapshot_htaddr4", AF_INET, TEST_GETHOSTBYADDR, false);
+}
+
+ATF_TC_WITHOUT_HEAD(gethostbyaddr_ipv6);
+ATF_TC_BODY(gethostbyaddr_ipv6, tc)
+{
+
+ RUN_HOST_TESTS(tc, NULL, AF_INET6, TEST_GETHOSTBYADDR, false);
+}
+
+ATF_TC_WITHOUT_HEAD(gethostbyaddr_ipv6_AI_V4MAPPED);
+ATF_TC_BODY(gethostbyaddr_ipv6_AI_V4MAPPED, tc)
+{
+
+ ipnode_flags = AI_V4MAPPED;
+ RUN_HOST_TESTS(tc, NULL, AF_INET6, TEST_GETHOSTBYADDR, true);
+}
+
+ATF_TC_WITHOUT_HEAD(gethostbyaddr_ipv6_with_snapshot);
+ATF_TC_BODY(gethostbyaddr_ipv6_with_snapshot, tc)
+{
+
+ RUN_HOST_TESTS(tc, "snapshot_htaddr6", AF_INET6, TEST_GETHOSTBYADDR, false);
+}
+
+ATF_TC_WITHOUT_HEAD(gethostbyaddr_ipv6_with_snapshot_AI_V4MAPPED);
+ATF_TC_BODY(gethostbyaddr_ipv6_with_snapshot_AI_V4MAPPED, tc)
+{
+
+ ipnode_flags = AI_V4MAPPED;
+ RUN_HOST_TESTS(tc, "snapshot_htaddr6map", AF_INET6, TEST_GETHOSTBYADDR, true);
+}
+
+ATF_TC_WITHOUT_HEAD(gethostbyname2_getaddrinfo_ipv4);
+ATF_TC_BODY(gethostbyname2_getaddrinfo_ipv4, tc)
+{
+
+ RUN_HOST_TESTS(tc, NULL, AF_INET, TEST_GETHOSTBYNAME2_GETADDRINFO, false);
+}
+
+ATF_TC_WITHOUT_HEAD(gethostbyname2_getaddrinfo_ipv6);
+ATF_TC_BODY(gethostbyname2_getaddrinfo_ipv6, tc)
+{
+
+ RUN_HOST_TESTS(tc, NULL, AF_INET6, TEST_GETHOSTBYNAME2_GETADDRINFO, false);
+}
+
+ATF_TC_WITHOUT_HEAD(gethostbyaddr_getnameinfo_ipv4);
+ATF_TC_BODY(gethostbyaddr_getnameinfo_ipv4, tc)
+{
+
+ RUN_HOST_TESTS(tc, NULL, AF_INET, TEST_GETHOSTBYADDR_GETNAMEINFO, false);
+}
+
+ATF_TC_WITHOUT_HEAD(gethostbyaddr_getnameinfo_ipv6);
+ATF_TC_BODY(gethostbyaddr_getnameinfo_ipv6, tc)
+{
+
+ RUN_HOST_TESTS(tc, NULL, AF_INET6, TEST_GETHOSTBYADDR_GETNAMEINFO, false);
+}
+
+ATF_TC_WITHOUT_HEAD(gethostbyname2_ipv4);
+ATF_TC_BODY(gethostbyname2_ipv4, tc)
+{
+
+ RUN_HOST_TESTS(tc, NULL, AF_INET, TEST_GETHOSTBYNAME2, false);
+}
+
+ATF_TC_WITHOUT_HEAD(gethostbyname2_ipv4_with_snapshot);
+ATF_TC_BODY(gethostbyname2_ipv4_with_snapshot, tc)
+{
+
+ RUN_HOST_TESTS(tc, "snapshot_htname4", AF_INET, TEST_GETHOSTBYNAME2, false);
+}
+
+ATF_TC_WITHOUT_HEAD(gethostbyname2_ipv6);
+ATF_TC_BODY(gethostbyname2_ipv6, tc)
+{
+
+ RUN_HOST_TESTS(tc, NULL, AF_INET6, TEST_GETHOSTBYNAME2, false);
+}
+
+ATF_TC_WITHOUT_HEAD(gethostbyname2_ipv6_AI_V4MAPPED);
+ATF_TC_BODY(gethostbyname2_ipv6_AI_V4MAPPED, tc)
+{
+
+ ipnode_flags = AI_V4MAPPED;
+ RUN_HOST_TESTS(tc, NULL, AF_INET6, TEST_GETHOSTBYNAME2, true);
+}
+
+ATF_TC_WITHOUT_HEAD(gethostbyname2_ipv6_with_snapshot);
+ATF_TC_BODY(gethostbyname2_ipv6_with_snapshot, tc)
+{
+
+ RUN_HOST_TESTS(tc, "snapshot_htname6", AF_INET6, TEST_GETHOSTBYNAME2, false);
+}
+
+ATF_TC_WITHOUT_HEAD(gethostbyname2_ipv6_with_snapshot_AI_V4MAPPED);
+ATF_TC_BODY(gethostbyname2_ipv6_with_snapshot_AI_V4MAPPED, tc)
+{
+
+ ipnode_flags = AI_V4MAPPED;
+ RUN_HOST_TESTS(tc, "snapshot_htname6map", AF_INET6, TEST_GETHOSTBYNAME2, true);
+}
+
+ATF_TC_WITHOUT_HEAD(getipnodebyaddr_ipv4);
+ATF_TC_BODY(getipnodebyaddr_ipv4, tc)
+{
+
+ RUN_IPNODE_TESTS(tc, NULL, AF_INET, TEST_GETHOSTBYADDR, false);
+}
+
+ATF_TC_WITHOUT_HEAD(getipnodebyaddr_ipv4_with_snapshot);
+ATF_TC_BODY(getipnodebyaddr_ipv4_with_snapshot, tc)
+{
+
+ RUN_IPNODE_TESTS(tc, "snapshot_ipnodeaddr4", AF_INET, TEST_GETHOSTBYADDR, false);
+}
+
+ATF_TC_WITHOUT_HEAD(getipnodebyaddr_getnameinfo_ipv4);
+ATF_TC_BODY(getipnodebyaddr_getnameinfo_ipv4, tc)
+{
+
+ RUN_IPNODE_TESTS(tc, NULL, AF_INET, TEST_GETHOSTBYADDR_GETNAMEINFO, false);
+}
+
+ATF_TC_WITHOUT_HEAD(getipnodebyaddr_ipv6);
+ATF_TC_BODY(getipnodebyaddr_ipv6, tc)
+{
+
+ RUN_IPNODE_TESTS(tc, NULL, AF_INET6, TEST_GETHOSTBYADDR, false);
+}
+
+ATF_TC_WITHOUT_HEAD(getipnodebyaddr_ipv6_AI_V4MAPPED);
+ATF_TC_BODY(getipnodebyaddr_ipv6_AI_V4MAPPED, tc)
+{
+
+ ipnode_flags = AI_V4MAPPED;
+ RUN_IPNODE_TESTS(tc, NULL, AF_INET6, TEST_GETHOSTBYADDR, true);
+}
+
+ATF_TC_WITHOUT_HEAD(getipnodebyaddr_ipv6_AI_V4MAPPED_CFG);
+ATF_TC_BODY(getipnodebyaddr_ipv6_AI_V4MAPPED_CFG, tc)
+{
+
+ ipnode_flags = AI_V4MAPPED_CFG;
+ RUN_IPNODE_TESTS(tc, NULL, AF_INET6, TEST_GETHOSTBYADDR, true);
+}
+
+ATF_TC_WITHOUT_HEAD(getipnodebyaddr_ipv6_AI_V4MAPPED_CFG_AI_ALL);
+ATF_TC_BODY(getipnodebyaddr_ipv6_AI_V4MAPPED_CFG_AI_ALL, tc)
+{
+
+ ipnode_flags = AI_V4MAPPED_CFG | AI_ALL;
+ RUN_IPNODE_TESTS(tc, NULL, AF_INET6, TEST_GETHOSTBYADDR, true);
+}
+
+ATF_TC_WITHOUT_HEAD(getipnodebyaddr_ipv6_with_snapshot);
+ATF_TC_BODY(getipnodebyaddr_ipv6_with_snapshot, tc)
+{
+
+ RUN_IPNODE_TESTS(tc, "snapshot_ipnodeaddr6", AF_INET6, TEST_GETHOSTBYADDR, false);
+}
+
+ATF_TC_WITHOUT_HEAD(getipnodebyaddr_ipv6_with_snapshot_AI_V4MAPPED);
+ATF_TC_BODY(getipnodebyaddr_ipv6_with_snapshot_AI_V4MAPPED, tc)
+{
+
+ ipnode_flags = AI_V4MAPPED;
+ RUN_IPNODE_TESTS(tc,
+ "snapshot_ipnodeaddr6_AI_V4MAPPED", AF_INET6,
+ TEST_GETHOSTBYADDR, true);
+}
+
+ATF_TC_WITHOUT_HEAD(getipnodebyaddr_ipv6_with_snapshot_AI_V4MAPPED_CFG);
+ATF_TC_BODY(getipnodebyaddr_ipv6_with_snapshot_AI_V4MAPPED_CFG, tc)
+{
+
+ ipnode_flags = AI_V4MAPPED_CFG;
+ RUN_IPNODE_TESTS(tc,
+ "snapshot_ipnodeaddr6_AI_V4MAPPED_CFG", AF_INET6,
+ TEST_GETHOSTBYADDR, true);
+}
+
+ATF_TC_WITHOUT_HEAD(getipnodebyaddr_ipv6_with_snapshot_AI_V4MAPPED_CFG_AI_ALL);
+ATF_TC_BODY(getipnodebyaddr_ipv6_with_snapshot_AI_V4MAPPED_CFG_AI_ALL, tc)
+{
+
+ ipnode_flags = AI_V4MAPPED_CFG | AI_ALL;
+ RUN_IPNODE_TESTS(tc,
+ "snapshot_ipnodeaddr6_AI_V4MAPPED_CFG_AI_ALL", AF_INET6,
+ TEST_GETHOSTBYADDR, true);
+}
+
+ATF_TC_WITHOUT_HEAD(getipnodebyaddr_getnameinfo_ipv6);
+ATF_TC_BODY(getipnodebyaddr_getnameinfo_ipv6, tc)
+{
+
+ RUN_IPNODE_TESTS(tc, NULL, AF_INET6, TEST_GETHOSTBYADDR_GETNAMEINFO, false);
+}
+
+ATF_TC_WITHOUT_HEAD(getipnodebyname_ipv4);
+ATF_TC_BODY(getipnodebyname_ipv4, tc)
+{
+
+ RUN_IPNODE_TESTS(tc, NULL, AF_INET, TEST_GETHOSTBYNAME2, false);
+}
+
+ATF_TC_WITHOUT_HEAD(getipnodebyname_ipv4_with_snapshot);
+ATF_TC_BODY(getipnodebyname_ipv4_with_snapshot, tc)
+{
+
+ RUN_IPNODE_TESTS(tc, "snapshot_ipnodename4", AF_INET, TEST_GETHOSTBYNAME2, false);
+}
+
+ATF_TC_WITHOUT_HEAD(getipnodebyname_ipv4_AI_ADDRCONFIG);
+ATF_TC_BODY(getipnodebyname_ipv4_AI_ADDRCONFIG, tc)
+{
+
+ ipnode_flags = AI_ADDRCONFIG;
+ RUN_IPNODE_TESTS(tc, NULL, AF_INET, TEST_GETHOSTBYNAME2, false);
+}
+
+ATF_TC_WITHOUT_HEAD(getipnodebyname_ipv4_with_snapshot_AI_ADDRCONFIG);
+ATF_TC_BODY(getipnodebyname_ipv4_with_snapshot_AI_ADDRCONFIG, tc)
+{
+
+ ipnode_flags = AI_ADDRCONFIG;
+ RUN_IPNODE_TESTS(tc, "snapshot_ipnodename4_AI_ADDRCONFIG", AF_INET,
+ TEST_GETHOSTBYNAME2, false);
+}
+
+ATF_TC_WITHOUT_HEAD(getipnodebyname_getaddrinfo_ipv4);
+ATF_TC_BODY(getipnodebyname_getaddrinfo_ipv4, tc)
+{
+
+ RUN_IPNODE_TESTS(tc, NULL, AF_INET, TEST_GETHOSTBYNAME2_GETADDRINFO, false);
+}
+
+ATF_TC_WITHOUT_HEAD(getipnodebyname_ipv6);
+ATF_TC_BODY(getipnodebyname_ipv6, tc)
+{
+
+ RUN_IPNODE_TESTS(tc, NULL, AF_INET6, TEST_GETHOSTBYNAME2, false);
+}
+
+ATF_TC_WITHOUT_HEAD(getipnodebyname_ipv6_with_snapshot);
+ATF_TC_BODY(getipnodebyname_ipv6_with_snapshot, tc)
+{
+
+ RUN_IPNODE_TESTS(tc, "snapshot_ipnodename6", AF_INET6, TEST_GETHOSTBYNAME2, false);
+}
+
+ATF_TC_WITHOUT_HEAD(getipnodebyname_ipv6_AI_ADDRCONFIG);
+ATF_TC_BODY(getipnodebyname_ipv6_AI_ADDRCONFIG, tc)
+{
+
+ ipnode_flags = AI_ADDRCONFIG;
+ RUN_IPNODE_TESTS(tc, NULL, AF_INET6, TEST_GETHOSTBYNAME2, false);
+}
+
+ATF_TC_WITHOUT_HEAD(getipnodebyname_ipv6_AI_V4MAPPED);
+ATF_TC_BODY(getipnodebyname_ipv6_AI_V4MAPPED, tc)
+{
+
+ ipnode_flags = AI_V4MAPPED;
+ RUN_IPNODE_TESTS(tc, NULL, AF_INET6, TEST_GETHOSTBYNAME2, true);
+}
+
+ATF_TC_WITHOUT_HEAD(getipnodebyname_ipv6_AI_V4MAPPED_CFG);
+ATF_TC_BODY(getipnodebyname_ipv6_AI_V4MAPPED_CFG, tc)
+{
+
+ ipnode_flags = AI_V4MAPPED_CFG;
+ RUN_IPNODE_TESTS(tc, NULL, AF_INET6, TEST_GETHOSTBYNAME2, true);
+}
+
+ATF_TC_WITHOUT_HEAD(getipnodebyname_ipv6_AI_V4MAPPED_CFG_AI_ADDRCONFIG);
+ATF_TC_BODY(getipnodebyname_ipv6_AI_V4MAPPED_CFG_AI_ADDRCONFIG, tc)
+{
+
+ ipnode_flags = AI_V4MAPPED_CFG | AI_ADDRCONFIG;
+ RUN_IPNODE_TESTS(tc, NULL, AF_INET6, TEST_GETHOSTBYNAME2, false);
+}
+
+ATF_TC_WITHOUT_HEAD(getipnodebyname_ipv6_AI_V4MAPPED_CFG_AI_ALL);
+ATF_TC_BODY(getipnodebyname_ipv6_AI_V4MAPPED_CFG_AI_ALL, tc)
+{
+
+ ipnode_flags = AI_V4MAPPED_CFG | AI_ALL;
+ RUN_IPNODE_TESTS(tc, NULL, AF_INET6, TEST_GETHOSTBYNAME2, true);
+}
+
+ATF_TC_WITHOUT_HEAD(getipnodebyname_ipv6_with_snapshot_AI_V4MAPPED);
+ATF_TC_BODY(getipnodebyname_ipv6_with_snapshot_AI_V4MAPPED, tc)
+{
+
+ ipnode_flags = AI_V4MAPPED;
+ RUN_IPNODE_TESTS(tc,
+ "snapshot_ipnodename6_AI_V4MAPPED", AF_INET6,
+ TEST_GETHOSTBYNAME2, true);
+}
+
+ATF_TC_WITHOUT_HEAD(getipnodebyname_ipv6_with_snapshot_AI_V4MAPPED_CFG);
+ATF_TC_BODY(getipnodebyname_ipv6_with_snapshot_AI_V4MAPPED_CFG, tc)
+{
+
+ ipnode_flags = AI_V4MAPPED_CFG;
+ RUN_IPNODE_TESTS(tc,
+ "snapshot_ipnodename6_AI_V4MAPPED_CFG", AF_INET6,
+ TEST_GETHOSTBYNAME2, true);
+}
+
+ATF_TC_WITHOUT_HEAD(getipnodebyname_ipv6_with_snapshot_AI_V4MAPPED_CFG_AI_ADDRCONFIG);
+ATF_TC_BODY(getipnodebyname_ipv6_with_snapshot_AI_V4MAPPED_CFG_AI_ADDRCONFIG, tc)
+{
+
+ ipnode_flags = AI_V4MAPPED_CFG | AI_ADDRCONFIG;
+ RUN_IPNODE_TESTS(tc,
+ "snapshot_ipnodename6_AI_V4MAPPED_CFG_AI_ADDRCONFIG", AF_INET6,
+ TEST_GETHOSTBYNAME2, false);
+}
+
+ATF_TC_WITHOUT_HEAD(getipnodebyname_ipv6_with_snapshot_AI_V4MAPPED_CFG_AI_ALL);
+ATF_TC_BODY(getipnodebyname_ipv6_with_snapshot_AI_V4MAPPED_CFG_AI_ALL, tc)
+{
+
+ ipnode_flags = AI_V4MAPPED_CFG | AI_ALL;
+ RUN_IPNODE_TESTS(tc,
+ "snapshot_ipnodename6_AI_V4MAPPED_CFG_AI_ALL", AF_INET6,
+ TEST_GETHOSTBYNAME2, true);
+}
+
+ATF_TC_WITHOUT_HEAD(getipnodebyname_ipv6_with_snapshot_AI_ADDRCONFIG);
+ATF_TC_BODY(getipnodebyname_ipv6_with_snapshot_AI_ADDRCONFIG, tc)
+{
+
+ ipnode_flags = AI_ADDRCONFIG;
+ RUN_IPNODE_TESTS(tc, "snapshot_ipnodename6_AI_ADDRCONFIG", AF_INET6,
+ TEST_GETHOSTBYNAME2, false);
+}
+
+ATF_TC_WITHOUT_HEAD(getipnodebyname_getaddrinfo_ipv6);
+ATF_TC_BODY(getipnodebyname_getaddrinfo_ipv6, tc)
+{
+
+ RUN_IPNODE_TESTS(tc, NULL, AF_INET6, TEST_GETHOSTBYNAME2_GETADDRINFO, false);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ /* gethostbyaddr */
+ ATF_TP_ADD_TC(tp, gethostbyaddr_ipv4);
+ ATF_TP_ADD_TC(tp, gethostbyaddr_ipv4_with_snapshot);
+ ATF_TP_ADD_TC(tp, gethostbyaddr_ipv6);
+ ATF_TP_ADD_TC(tp, gethostbyaddr_ipv6_AI_V4MAPPED); /* XXX */
+ ATF_TP_ADD_TC(tp, gethostbyaddr_ipv6_with_snapshot);
+ ATF_TP_ADD_TC(tp, gethostbyaddr_ipv6_with_snapshot_AI_V4MAPPED);
+ ATF_TP_ADD_TC(tp, gethostbyaddr_getnameinfo_ipv4);
+ ATF_TP_ADD_TC(tp, gethostbyaddr_getnameinfo_ipv6);
+
+ /* gethostbyname2 */
+ ATF_TP_ADD_TC(tp, gethostbyname2_getaddrinfo_ipv4);
+ ATF_TP_ADD_TC(tp, gethostbyname2_getaddrinfo_ipv6);
+ ATF_TP_ADD_TC(tp, gethostbyname2_ipv4);
+ ATF_TP_ADD_TC(tp, gethostbyname2_ipv4_with_snapshot);
+ ATF_TP_ADD_TC(tp, gethostbyname2_ipv6);
+ ATF_TP_ADD_TC(tp, gethostbyname2_ipv6_AI_V4MAPPED);
+ ATF_TP_ADD_TC(tp, gethostbyname2_ipv6_with_snapshot);
+ ATF_TP_ADD_TC(tp, gethostbyname2_ipv6_with_snapshot_AI_V4MAPPED);
+
+ /* getipnodebyaddr */
+ ATF_TP_ADD_TC(tp, getipnodebyaddr_ipv4);
+ ATF_TP_ADD_TC(tp, getipnodebyaddr_ipv4_with_snapshot);
+ ATF_TP_ADD_TC(tp, getipnodebyaddr_getnameinfo_ipv4);
+ ATF_TP_ADD_TC(tp, getipnodebyaddr_ipv6);
+ ATF_TP_ADD_TC(tp, getipnodebyaddr_ipv6_AI_V4MAPPED);
+ ATF_TP_ADD_TC(tp, getipnodebyaddr_ipv6_AI_V4MAPPED_CFG);
+ ATF_TP_ADD_TC(tp, getipnodebyaddr_ipv6_AI_V4MAPPED_CFG_AI_ALL);
+ ATF_TP_ADD_TC(tp, getipnodebyaddr_ipv6_with_snapshot);
+ ATF_TP_ADD_TC(tp, getipnodebyaddr_ipv6_with_snapshot_AI_V4MAPPED);
+ ATF_TP_ADD_TC(tp, getipnodebyaddr_ipv6_with_snapshot_AI_V4MAPPED_CFG);
+ ATF_TP_ADD_TC(tp, getipnodebyaddr_ipv6_with_snapshot_AI_V4MAPPED_CFG_AI_ALL);
+ ATF_TP_ADD_TC(tp, getipnodebyaddr_getnameinfo_ipv6);
+
+ /* getipnodebyname */
+ ATF_TP_ADD_TC(tp, getipnodebyname_ipv4);
+ ATF_TP_ADD_TC(tp, getipnodebyname_ipv4_with_snapshot);
+ ATF_TP_ADD_TC(tp, getipnodebyname_ipv4_AI_ADDRCONFIG);
+ ATF_TP_ADD_TC(tp, getipnodebyname_ipv4_with_snapshot_AI_ADDRCONFIG);
+ ATF_TP_ADD_TC(tp, getipnodebyname_getaddrinfo_ipv4);
+ ATF_TP_ADD_TC(tp, getipnodebyname_ipv6);
+ ATF_TP_ADD_TC(tp, getipnodebyname_ipv6_with_snapshot);
+ ATF_TP_ADD_TC(tp, getipnodebyname_ipv6_AI_ADDRCONFIG);
+ ATF_TP_ADD_TC(tp, getipnodebyname_ipv6_AI_V4MAPPED);
+ ATF_TP_ADD_TC(tp, getipnodebyname_ipv6_AI_V4MAPPED_CFG);
+ ATF_TP_ADD_TC(tp, getipnodebyname_ipv6_AI_V4MAPPED_CFG_AI_ADDRCONFIG);
+ ATF_TP_ADD_TC(tp, getipnodebyname_ipv6_AI_V4MAPPED_CFG_AI_ALL);
+ ATF_TP_ADD_TC(tp, getipnodebyname_ipv6_with_snapshot_AI_V4MAPPED);
+ ATF_TP_ADD_TC(tp, getipnodebyname_ipv6_with_snapshot_AI_V4MAPPED_CFG);
+ ATF_TP_ADD_TC(tp, getipnodebyname_ipv6_with_snapshot_AI_V4MAPPED_CFG_AI_ADDRCONFIG);
+ ATF_TP_ADD_TC(tp, getipnodebyname_ipv6_with_snapshot_AI_V4MAPPED_CFG_AI_ALL);
+ ATF_TP_ADD_TC(tp, getipnodebyname_ipv6_with_snapshot_AI_ADDRCONFIG);
+ ATF_TP_ADD_TC(tp, getipnodebyname_getaddrinfo_ipv6);
+
+ return (atf_no_error());
+}
Property changes on: trunk/lib/libc/tests/nss/gethostby_test.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/nss/getproto_test.c
===================================================================
--- trunk/lib/libc/tests/nss/getproto_test.c (rev 0)
+++ trunk/lib/libc/tests/nss/getproto_test.c 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,557 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2006 Michael Bushkov <bushman at freebsd.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/lib/libc/tests/nss/getproto_test.c 319298 2017-05-31 08:30:37Z ngie $");
+
+#include <arpa/inet.h>
+#include <assert.h>
+#include <errno.h>
+#include <netdb.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stringlist.h>
+#include <unistd.h>
+
+#include <atf-c.h>
+
+#include "testutil.h"
+
+enum test_methods {
+ TEST_GETPROTOENT,
+ TEST_GETPROTOBYNAME,
+ TEST_GETPROTOBYNUMBER,
+ TEST_GETPROTOENT_2PASS,
+ TEST_BUILD_SNAPSHOT
+};
+
+DECLARE_TEST_DATA(protoent)
+DECLARE_TEST_FILE_SNAPSHOT(protoent)
+DECLARE_1PASS_TEST(protoent)
+DECLARE_2PASS_TEST(protoent)
+
+static void clone_protoent(struct protoent *, struct protoent const *);
+static int compare_protoent(struct protoent *, struct protoent *, void *);
+static void dump_protoent(struct protoent *);
+static void free_protoent(struct protoent *);
+
+static void sdump_protoent(struct protoent *, char *, size_t);
+static int protoent_read_snapshot_func(struct protoent *, char *);
+
+static int protoent_check_ambiguity(struct protoent_test_data *,
+ struct protoent *);
+static int protoent_fill_test_data(struct protoent_test_data *);
+static int protoent_test_correctness(struct protoent *, void *);
+static int protoent_test_getprotobyname(struct protoent *, void *);
+static int protoent_test_getprotobynumber(struct protoent *, void *);
+static int protoent_test_getprotoent(struct protoent *, void *);
+
+IMPLEMENT_TEST_DATA(protoent)
+IMPLEMENT_TEST_FILE_SNAPSHOT(protoent)
+IMPLEMENT_1PASS_TEST(protoent)
+IMPLEMENT_2PASS_TEST(protoent)
+
+static void
+clone_protoent(struct protoent *dest, struct protoent const *src)
+{
+ assert(dest != NULL);
+ assert(src != NULL);
+
+ char **cp;
+ int aliases_num;
+
+ memset(dest, 0, sizeof(struct protoent));
+
+ if (src->p_name != NULL) {
+ dest->p_name = strdup(src->p_name);
+ assert(dest->p_name != NULL);
+ }
+
+ dest->p_proto = src->p_proto;
+
+ if (src->p_aliases != NULL) {
+ aliases_num = 0;
+ for (cp = src->p_aliases; *cp; ++cp)
+ ++aliases_num;
+
+ dest->p_aliases = calloc(aliases_num + 1, sizeof(char *));
+ assert(dest->p_aliases != NULL);
+
+ for (cp = src->p_aliases; *cp; ++cp) {
+ dest->p_aliases[cp - src->p_aliases] = strdup(*cp);
+ assert(dest->p_aliases[cp - src->p_aliases] != NULL);
+ }
+ }
+}
+
+static void
+free_protoent(struct protoent *pe)
+{
+ char **cp;
+
+ assert(pe != NULL);
+
+ free(pe->p_name);
+
+ for (cp = pe->p_aliases; *cp; ++cp)
+ free(*cp);
+ free(pe->p_aliases);
+}
+
+static int
+compare_protoent(struct protoent *pe1, struct protoent *pe2, void *mdata)
+{
+ char **c1, **c2;
+
+ if (pe1 == pe2)
+ return 0;
+
+ if ((pe1 == NULL) || (pe2 == NULL))
+ goto errfin;
+
+ if ((strcmp(pe1->p_name, pe2->p_name) != 0) ||
+ (pe1->p_proto != pe2->p_proto))
+ goto errfin;
+
+ c1 = pe1->p_aliases;
+ c2 = pe2->p_aliases;
+
+ if ((pe1->p_aliases == NULL) || (pe2->p_aliases == NULL))
+ goto errfin;
+
+ for (;*c1 && *c2; ++c1, ++c2)
+ if (strcmp(*c1, *c2) != 0)
+ goto errfin;
+
+ if ((*c1 != '\0') || (*c2 != '\0'))
+ goto errfin;
+
+ return 0;
+
+errfin:
+ if (mdata == NULL) {
+ printf("following structures are not equal:\n");
+ dump_protoent(pe1);
+ dump_protoent(pe2);
+ }
+
+ return (-1);
+}
+
+static void
+sdump_protoent(struct protoent *pe, char *buffer, size_t buflen)
+{
+ char **cp;
+ int written;
+
+ written = snprintf(buffer, buflen, "%s %d",
+ pe->p_name, pe->p_proto);
+ buffer += written;
+ if (written > (int)buflen)
+ return;
+ buflen -= written;
+
+ if (pe->p_aliases != NULL) {
+ if (*(pe->p_aliases) != '\0') {
+ for (cp = pe->p_aliases; *cp; ++cp) {
+ written = snprintf(buffer, buflen, " %s", *cp);
+ buffer += written;
+ if (written > (int)buflen)
+ return;
+ buflen -= written;
+
+ if (buflen == 0)
+ return;
+ }
+ } else
+ snprintf(buffer, buflen, " noaliases");
+ } else
+ snprintf(buffer, buflen, " (null)");
+}
+
+static int
+protoent_read_snapshot_func(struct protoent *pe, char *line)
+{
+ StringList *sl;
+ char *s, *ps, *ts;
+ int i;
+
+ printf("1 line read from snapshot:\n%s\n", line);
+
+ i = 0;
+ sl = NULL;
+ ps = line;
+ memset(pe, 0, sizeof(struct protoent));
+ while ( (s = strsep(&ps, " ")) != NULL) {
+ switch (i) {
+ case 0:
+ pe->p_name = strdup(s);
+ assert(pe->p_name != NULL);
+ break;
+
+ case 1:
+ pe->p_proto = (int)strtol(s, &ts, 10);
+ if (*ts != '\0') {
+ free(pe->p_name);
+ return (-1);
+ }
+ break;
+
+ default:
+ if (sl == NULL) {
+ if (strcmp(s, "(null)") == 0)
+ return (0);
+
+ sl = sl_init();
+ assert(sl != NULL);
+
+ if (strcmp(s, "noaliases") != 0) {
+ ts = strdup(s);
+ assert(ts != NULL);
+ sl_add(sl, ts);
+ }
+ } else {
+ ts = strdup(s);
+ assert(ts != NULL);
+ sl_add(sl, ts);
+ }
+ break;
+ }
+ ++i;
+ }
+
+ if (i < 3) {
+ free(pe->p_name);
+ memset(pe, 0, sizeof(struct protoent));
+ return (-1);
+ }
+
+ sl_add(sl, NULL);
+ pe->p_aliases = sl->sl_str;
+
+ /* NOTE: is it a dirty hack or not? */
+ free(sl);
+ return (0);
+}
+
+static void
+dump_protoent(struct protoent *result)
+{
+ if (result != NULL) {
+ char buffer[1024];
+ sdump_protoent(result, buffer, sizeof(buffer));
+ printf("%s\n", buffer);
+ } else
+ printf("(null)\n");
+}
+
+static int
+protoent_fill_test_data(struct protoent_test_data *td)
+{
+ struct protoent *pe;
+
+ setprotoent(1);
+ while ((pe = getprotoent()) != NULL) {
+ if (protoent_test_correctness(pe, NULL) == 0)
+ TEST_DATA_APPEND(protoent, td, pe);
+ else
+ return (-1);
+ }
+ endprotoent();
+
+ return (0);
+}
+
+static int
+protoent_test_correctness(struct protoent *pe, void *mdata __unused)
+{
+ printf("testing correctness with the following data:\n");
+ dump_protoent(pe);
+
+ if (pe == NULL)
+ goto errfin;
+
+ if (pe->p_name == NULL)
+ goto errfin;
+
+ if (pe->p_proto < 0)
+ goto errfin;
+
+ if (pe->p_aliases == NULL)
+ goto errfin;
+
+ printf("correct\n");
+
+ return (0);
+errfin:
+ printf("incorrect\n");
+
+ return (-1);
+}
+
+/* protoent_check_ambiguity() is needed when one port+proto is associated with
+ * more than one peice (these cases are usually marked as PROBLEM in
+ * /etc/peices. This functions is needed also when one peice+proto is
+ * associated with several ports. We have to check all the protoent structures
+ * to make sure that pe really exists and correct */
+static int
+protoent_check_ambiguity(struct protoent_test_data *td, struct protoent *pe)
+{
+
+ return (TEST_DATA_FIND(protoent, td, pe, compare_protoent,
+ NULL) != NULL ? 0 : -1);
+}
+
+static int
+protoent_test_getprotobyname(struct protoent *pe_model, void *mdata)
+{
+ char **alias;
+ struct protoent *pe;
+
+ printf("testing getprotobyname() with the following data:\n");
+ dump_protoent(pe_model);
+
+ pe = getprotobyname(pe_model->p_name);
+ if (protoent_test_correctness(pe, NULL) != 0)
+ goto errfin;
+
+ if ((compare_protoent(pe, pe_model, NULL) != 0) &&
+ (protoent_check_ambiguity((struct protoent_test_data *)mdata, pe)
+ !=0))
+ goto errfin;
+
+ for (alias = pe_model->p_aliases; *alias; ++alias) {
+ pe = getprotobyname(*alias);
+
+ if (protoent_test_correctness(pe, NULL) != 0)
+ goto errfin;
+
+ if ((compare_protoent(pe, pe_model, NULL) != 0) &&
+ (protoent_check_ambiguity(
+ (struct protoent_test_data *)mdata, pe) != 0))
+ goto errfin;
+ }
+
+ printf("ok\n");
+ return (0);
+
+errfin:
+ printf("not ok\n");
+
+ return (-1);
+}
+
+static int
+protoent_test_getprotobynumber(struct protoent *pe_model, void *mdata)
+{
+ struct protoent *pe;
+
+ printf("testing getprotobyport() with the following data...\n");
+ dump_protoent(pe_model);
+
+ pe = getprotobynumber(pe_model->p_proto);
+ if ((protoent_test_correctness(pe, NULL) != 0) ||
+ ((compare_protoent(pe, pe_model, NULL) != 0) &&
+ (protoent_check_ambiguity((struct protoent_test_data *)mdata, pe)
+ != 0))) {
+ printf("not ok\n");
+ return (-1);
+ } else {
+ printf("ok\n");
+ return (0);
+ }
+}
+
+static int
+protoent_test_getprotoent(struct protoent *pe, void *mdata __unused)
+{
+ /* Only correctness can be checked when doing 1-pass test for
+ * getprotoent(). */
+ return (protoent_test_correctness(pe, NULL));
+}
+
+static int
+run_tests(const char *snapshot_file, enum test_methods method)
+{
+ struct protoent_test_data td, td_snap, td_2pass;
+ int rv;
+
+ TEST_DATA_INIT(protoent, &td, clone_protoent, free_protoent);
+ TEST_DATA_INIT(protoent, &td_snap, clone_protoent, free_protoent);
+ if (snapshot_file != NULL) {
+ if (access(snapshot_file, W_OK | R_OK) != 0) {
+ if (errno == ENOENT)
+ method = TEST_BUILD_SNAPSHOT;
+ else {
+ printf("can't access the file %s\n",
+ snapshot_file);
+
+ rv = -1;
+ goto fin;
+ }
+ } else {
+ if (method == TEST_BUILD_SNAPSHOT) {
+ rv = 0;
+ goto fin;
+ }
+
+ TEST_SNAPSHOT_FILE_READ(protoent, snapshot_file,
+ &td_snap, protoent_read_snapshot_func);
+ }
+ }
+
+ rv = protoent_fill_test_data(&td);
+ if (rv == -1)
+ return (-1);
+ switch (method) {
+ case TEST_GETPROTOBYNAME:
+ if (snapshot_file == NULL)
+ rv = DO_1PASS_TEST(protoent, &td,
+ protoent_test_getprotobyname, (void *)&td);
+ else
+ rv = DO_1PASS_TEST(protoent, &td_snap,
+ protoent_test_getprotobyname, (void *)&td_snap);
+ break;
+ case TEST_GETPROTOBYNUMBER:
+ if (snapshot_file == NULL)
+ rv = DO_1PASS_TEST(protoent, &td,
+ protoent_test_getprotobynumber, (void *)&td);
+ else
+ rv = DO_1PASS_TEST(protoent, &td_snap,
+ protoent_test_getprotobynumber, (void *)&td_snap);
+ break;
+ case TEST_GETPROTOENT:
+ if (snapshot_file == NULL)
+ rv = DO_1PASS_TEST(protoent, &td,
+ protoent_test_getprotoent, (void *)&td);
+ else
+ rv = DO_2PASS_TEST(protoent, &td, &td_snap,
+ compare_protoent, NULL);
+ break;
+ case TEST_GETPROTOENT_2PASS:
+ TEST_DATA_INIT(protoent, &td_2pass, clone_protoent,
+ free_protoent);
+ rv = protoent_fill_test_data(&td_2pass);
+ if (rv != -1)
+ rv = DO_2PASS_TEST(protoent, &td, &td_2pass,
+ compare_protoent, NULL);
+ TEST_DATA_DESTROY(protoent, &td_2pass);
+ break;
+ case TEST_BUILD_SNAPSHOT:
+ if (snapshot_file != NULL)
+ rv = TEST_SNAPSHOT_FILE_WRITE(protoent, snapshot_file,
+ &td, sdump_protoent);
+ break;
+ default:
+ rv = 0;
+ break;
+ }
+
+fin:
+ TEST_DATA_DESTROY(protoent, &td_snap);
+ TEST_DATA_DESTROY(protoent, &td);
+
+ return (rv);
+}
+
+#define SNAPSHOT_FILE "snapshot_proto"
+
+ATF_TC_WITHOUT_HEAD(build_snapshot);
+ATF_TC_BODY(build_snapshot, tc)
+{
+
+ ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_BUILD_SNAPSHOT) == 0);
+}
+
+ATF_TC_WITHOUT_HEAD(getprotoent);
+ATF_TC_BODY(getprotoent, tc)
+{
+
+ ATF_REQUIRE(run_tests(NULL, TEST_GETPROTOENT) == 0);
+}
+
+ATF_TC_WITHOUT_HEAD(getprotoent_with_snapshot);
+ATF_TC_BODY(getprotoent_with_snapshot, tc)
+{
+
+ ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_BUILD_SNAPSHOT) == 0);
+ ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_GETPROTOENT) == 0);
+}
+
+ATF_TC_WITHOUT_HEAD(getprotoent_with_two_pass);
+ATF_TC_BODY(getprotoent_with_two_pass, tc)
+{
+
+ ATF_REQUIRE(run_tests(NULL, TEST_GETPROTOENT_2PASS) == 0);
+}
+
+ATF_TC_WITHOUT_HEAD(getprotobyname);
+ATF_TC_BODY(getprotobyname, tc)
+{
+
+ ATF_REQUIRE(run_tests(NULL, TEST_GETPROTOBYNAME) == 0);
+}
+
+ATF_TC_WITHOUT_HEAD(getprotobyname_with_snapshot);
+ATF_TC_BODY(getprotobyname_with_snapshot, tc)
+{
+
+ ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_BUILD_SNAPSHOT) == 0);
+ ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_GETPROTOBYNAME) == 0);
+}
+
+ATF_TC_WITHOUT_HEAD(getprotobynumber);
+ATF_TC_BODY(getprotobynumber, tc)
+{
+
+ ATF_REQUIRE(run_tests(NULL, TEST_GETPROTOBYNUMBER) == 0);
+}
+
+ATF_TC_WITHOUT_HEAD(getprotobynumber_with_snapshot);
+ATF_TC_BODY(getprotobynumber_with_snapshot, tc)
+{
+
+ ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_BUILD_SNAPSHOT) == 0);
+ ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_GETPROTOBYNUMBER) == 0);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, build_snapshot);
+ ATF_TP_ADD_TC(tp, getprotoent);
+ ATF_TP_ADD_TC(tp, getprotoent_with_snapshot);
+ ATF_TP_ADD_TC(tp, getprotoent_with_two_pass);
+ ATF_TP_ADD_TC(tp, getprotobyname);
+ ATF_TP_ADD_TC(tp, getprotobyname_with_snapshot);
+ ATF_TP_ADD_TC(tp, getprotobynumber);
+ ATF_TP_ADD_TC(tp, getprotobynumber_with_snapshot);
+
+ return (atf_no_error());
+}
Property changes on: trunk/lib/libc/tests/nss/getproto_test.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/nss/getpw_test.c
===================================================================
--- trunk/lib/libc/tests/nss/getpw_test.c (rev 0)
+++ trunk/lib/libc/tests/nss/getpw_test.c 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,533 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2006 Michael Bushkov <bushman at freebsd.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/lib/libc/tests/nss/getpw_test.c 319298 2017-05-31 08:30:37Z ngie $");
+
+#include <errno.h>
+#include <pwd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <atf-c.h>
+
+#include "testutil.h"
+
+enum test_methods {
+ TEST_GETPWENT,
+ TEST_GETPWNAM,
+ TEST_GETPWUID,
+ TEST_GETPWENT_2PASS,
+ TEST_BUILD_SNAPSHOT
+};
+
+DECLARE_TEST_DATA(passwd)
+DECLARE_TEST_FILE_SNAPSHOT(passwd)
+DECLARE_1PASS_TEST(passwd)
+DECLARE_2PASS_TEST(passwd)
+
+static void clone_passwd(struct passwd *, struct passwd const *);
+static int compare_passwd(struct passwd *, struct passwd *, void *);
+static void free_passwd(struct passwd *);
+
+static void sdump_passwd(struct passwd *, char *, size_t);
+#ifdef DEBUG
+static void dump_passwd(struct passwd *);
+#endif
+
+static int passwd_read_snapshot_func(struct passwd *, char *);
+
+static int passwd_check_ambiguity(struct passwd_test_data *, struct passwd *);
+static int passwd_fill_test_data(struct passwd_test_data *);
+static int passwd_test_correctness(struct passwd *, void *);
+static int passwd_test_getpwnam(struct passwd *, void *);
+static int passwd_test_getpwuid(struct passwd *, void *);
+static int passwd_test_getpwent(struct passwd *, void *);
+
+IMPLEMENT_TEST_DATA(passwd)
+IMPLEMENT_TEST_FILE_SNAPSHOT(passwd)
+IMPLEMENT_1PASS_TEST(passwd)
+IMPLEMENT_2PASS_TEST(passwd)
+
+static void
+clone_passwd(struct passwd *dest, struct passwd const *src)
+{
+ ATF_REQUIRE(dest != NULL);
+ ATF_REQUIRE(src != NULL);
+
+ memcpy(dest, src, sizeof(struct passwd));
+ if (src->pw_name != NULL)
+ dest->pw_name = strdup(src->pw_name);
+ if (src->pw_passwd != NULL)
+ dest->pw_passwd = strdup(src->pw_passwd);
+ if (src->pw_class != NULL)
+ dest->pw_class = strdup(src->pw_class);
+ if (src->pw_gecos != NULL)
+ dest->pw_gecos = strdup(src->pw_gecos);
+ if (src->pw_dir != NULL)
+ dest->pw_dir = strdup(src->pw_dir);
+ if (src->pw_shell != NULL)
+ dest->pw_shell = strdup(dest->pw_shell);
+}
+
+static int
+compare_passwd(struct passwd *pwd1, struct passwd *pwd2, void *mdata __unused)
+{
+ ATF_REQUIRE(pwd1 != NULL);
+ ATF_REQUIRE(pwd2 != NULL);
+
+ if (pwd1 == pwd2)
+ return (0);
+
+ if (pwd1->pw_uid != pwd2->pw_uid ||
+ pwd1->pw_gid != pwd2->pw_gid ||
+ pwd1->pw_change != pwd2->pw_change ||
+ pwd1->pw_expire != pwd2->pw_expire ||
+ pwd1->pw_fields != pwd2->pw_fields ||
+ strcmp(pwd1->pw_name, pwd2->pw_name) != 0 ||
+ strcmp(pwd1->pw_passwd, pwd2->pw_passwd) != 0 ||
+ strcmp(pwd1->pw_class, pwd2->pw_class) != 0 ||
+ strcmp(pwd1->pw_gecos, pwd2->pw_gecos) != 0 ||
+ strcmp(pwd1->pw_dir, pwd2->pw_dir) != 0 ||
+ strcmp(pwd1->pw_shell, pwd2->pw_shell) != 0)
+ return (-1);
+ else
+ return (0);
+}
+
+static void
+free_passwd(struct passwd *pwd)
+{
+ free(pwd->pw_name);
+ free(pwd->pw_passwd);
+ free(pwd->pw_class);
+ free(pwd->pw_gecos);
+ free(pwd->pw_dir);
+ free(pwd->pw_shell);
+}
+
+static void
+sdump_passwd(struct passwd *pwd, char *buffer, size_t buflen)
+{
+ snprintf(buffer, buflen, "%s:%s:%d:%d:%jd:%s:%s:%s:%s:%jd:%d",
+ pwd->pw_name, pwd->pw_passwd, pwd->pw_uid, pwd->pw_gid,
+ (uintmax_t)pwd->pw_change, pwd->pw_class, pwd->pw_gecos,
+ pwd->pw_dir, pwd->pw_shell, (uintmax_t)pwd->pw_expire,
+ pwd->pw_fields);
+}
+
+#ifdef DEBUG
+static void
+dump_passwd(struct passwd *pwd)
+{
+ if (pwd != NULL) {
+ char buffer[2048];
+ sdump_passwd(pwd, buffer, sizeof(buffer));
+ printf("%s\n", buffer);
+ } else
+ printf("(null)\n");
+}
+#endif
+
+static int
+passwd_read_snapshot_func(struct passwd *pwd, char *line)
+{
+ char *s, *ps, *ts;
+ int i;
+
+#ifdef DEBUG
+ printf("1 line read from snapshot:\n%s\n", line);
+#endif
+
+ i = 0;
+ ps = line;
+ memset(pwd, 0, sizeof(struct passwd));
+ while ((s = strsep(&ps, ":")) != NULL) {
+ switch (i) {
+ case 0:
+ pwd->pw_name = strdup(s);
+ ATF_REQUIRE(pwd->pw_name != NULL);
+ break;
+ case 1:
+ pwd->pw_passwd = strdup(s);
+ ATF_REQUIRE(pwd->pw_passwd != NULL);
+ break;
+ case 2:
+ pwd->pw_uid = (uid_t)strtol(s, &ts, 10);
+ if (*ts != '\0')
+ goto fin;
+ break;
+ case 3:
+ pwd->pw_gid = (gid_t)strtol(s, &ts, 10);
+ if (*ts != '\0')
+ goto fin;
+ break;
+ case 4:
+ pwd->pw_change = (time_t)strtol(s, &ts, 10);
+ if (*ts != '\0')
+ goto fin;
+ break;
+ case 5:
+ pwd->pw_class = strdup(s);
+ ATF_REQUIRE(pwd->pw_class != NULL);
+ break;
+ case 6:
+ pwd->pw_gecos = strdup(s);
+ ATF_REQUIRE(pwd->pw_gecos != NULL);
+ break;
+ case 7:
+ pwd->pw_dir = strdup(s);
+ ATF_REQUIRE(pwd->pw_dir != NULL);
+ break;
+ case 8:
+ pwd->pw_shell = strdup(s);
+ ATF_REQUIRE(pwd->pw_shell != NULL);
+ break;
+ case 9:
+ pwd->pw_expire = (time_t)strtol(s, &ts, 10);
+ if (*ts != '\0')
+ goto fin;
+ break;
+ case 10:
+ pwd->pw_fields = (int)strtol(s, &ts, 10);
+ if (*ts != '\0')
+ goto fin;
+ break;
+ default:
+ break;
+ }
+ ++i;
+ }
+
+fin:
+ if (i != 11) {
+ free_passwd(pwd);
+ memset(pwd, 0, sizeof(struct passwd));
+ return (-1);
+ }
+
+ return (0);
+}
+
+static int
+passwd_fill_test_data(struct passwd_test_data *td)
+{
+ struct passwd *pwd;
+
+ setpassent(1);
+ while ((pwd = getpwent()) != NULL) {
+ if (passwd_test_correctness(pwd, NULL) == 0)
+ TEST_DATA_APPEND(passwd, td, pwd);
+ else
+ return (-1);
+ }
+ endpwent();
+
+ return (0);
+}
+
+static int
+passwd_test_correctness(struct passwd *pwd, void *mdata __unused)
+{
+
+#ifdef DEBUG
+ printf("testing correctness with the following data:\n");
+ dump_passwd(pwd);
+#endif
+
+ if (pwd == NULL)
+ return (-1);
+
+ if (pwd->pw_name == NULL)
+ goto errfin;
+
+ if (pwd->pw_passwd == NULL)
+ goto errfin;
+
+ if (pwd->pw_class == NULL)
+ goto errfin;
+
+ if (pwd->pw_gecos == NULL)
+ goto errfin;
+
+ if (pwd->pw_dir == NULL)
+ goto errfin;
+
+ if (pwd->pw_shell == NULL)
+ goto errfin;
+
+#ifdef DEBUG
+ printf("correct\n");
+#endif
+
+ return (0);
+errfin:
+#ifdef DEBUG
+ printf("incorrect\n");
+#endif
+
+ return (-1);
+}
+
+/* passwd_check_ambiguity() is needed here because when doing the getpwent()
+ * calls sequence, records from different nsswitch sources can be different,
+ * though having the same pw_name/pw_uid */
+static int
+passwd_check_ambiguity(struct passwd_test_data *td, struct passwd *pwd)
+{
+
+ return (TEST_DATA_FIND(passwd, td, pwd, compare_passwd,
+ NULL) != NULL ? 0 : -1);
+}
+
+static int
+passwd_test_getpwnam(struct passwd *pwd_model, void *mdata)
+{
+ struct passwd *pwd;
+
+#ifdef DEBUG
+ printf("testing getpwnam() with the following data:\n");
+ dump_passwd(pwd_model);
+#endif
+
+ pwd = getpwnam(pwd_model->pw_name);
+ if (passwd_test_correctness(pwd, NULL) != 0)
+ goto errfin;
+
+ if ((compare_passwd(pwd, pwd_model, NULL) != 0) &&
+ (passwd_check_ambiguity((struct passwd_test_data *)mdata, pwd)
+ !=0))
+ goto errfin;
+
+#ifdef DEBUG
+ printf("ok\n");
+#endif
+ return (0);
+
+errfin:
+#ifdef DEBUG
+ printf("not ok\n");
+#endif
+ return (-1);
+}
+
+static int
+passwd_test_getpwuid(struct passwd *pwd_model, void *mdata)
+{
+ struct passwd *pwd;
+
+#ifdef DEBUG
+ printf("testing getpwuid() with the following data...\n");
+ dump_passwd(pwd_model);
+#endif
+
+ pwd = getpwuid(pwd_model->pw_uid);
+ if ((passwd_test_correctness(pwd, NULL) != 0) ||
+ ((compare_passwd(pwd, pwd_model, NULL) != 0) &&
+ (passwd_check_ambiguity((struct passwd_test_data *)mdata, pwd)
+ != 0))) {
+#ifdef DEBUG
+ printf("not ok\n");
+#endif
+ return (-1);
+ } else {
+#ifdef DEBUG
+ printf("ok\n");
+#endif
+ return (0);
+ }
+}
+
+static int
+passwd_test_getpwent(struct passwd *pwd, void *mdata __unused)
+{
+ /* Only correctness can be checked when doing 1-pass test for
+ * getpwent(). */
+ return (passwd_test_correctness(pwd, NULL));
+}
+
+static int
+run_tests(const char *snapshot_file, enum test_methods method)
+{
+ struct passwd_test_data td, td_snap, td_2pass;
+ int rv;
+
+ TEST_DATA_INIT(passwd, &td, clone_passwd, free_passwd);
+ TEST_DATA_INIT(passwd, &td_snap, clone_passwd, free_passwd);
+ if (snapshot_file != NULL) {
+ if (access(snapshot_file, W_OK | R_OK) != 0) {
+ if (errno == ENOENT)
+ method = TEST_BUILD_SNAPSHOT;
+ else {
+ printf("can't access the file %s\n",
+ snapshot_file);
+ rv = -1;
+ goto fin;
+ }
+ } else {
+ if (method == TEST_BUILD_SNAPSHOT) {
+ rv = 0;
+ goto fin;
+ }
+
+ TEST_SNAPSHOT_FILE_READ(passwd, snapshot_file,
+ &td_snap, passwd_read_snapshot_func);
+ }
+ }
+
+ rv = passwd_fill_test_data(&td);
+ if (rv == -1)
+ return (-1);
+
+ switch (method) {
+ case TEST_GETPWNAM:
+ if (snapshot_file == NULL)
+ rv = DO_1PASS_TEST(passwd, &td,
+ passwd_test_getpwnam, (void *)&td);
+ else
+ rv = DO_1PASS_TEST(passwd, &td_snap,
+ passwd_test_getpwnam, (void *)&td_snap);
+ break;
+ case TEST_GETPWUID:
+ if (snapshot_file == NULL)
+ rv = DO_1PASS_TEST(passwd, &td,
+ passwd_test_getpwuid, (void *)&td);
+ else
+ rv = DO_1PASS_TEST(passwd, &td_snap,
+ passwd_test_getpwuid, (void *)&td_snap);
+ break;
+ case TEST_GETPWENT:
+ if (snapshot_file == NULL)
+ rv = DO_1PASS_TEST(passwd, &td, passwd_test_getpwent,
+ (void *)&td);
+ else
+ rv = DO_2PASS_TEST(passwd, &td, &td_snap,
+ compare_passwd, NULL);
+ break;
+ case TEST_GETPWENT_2PASS:
+ TEST_DATA_INIT(passwd, &td_2pass, clone_passwd, free_passwd);
+ rv = passwd_fill_test_data(&td_2pass);
+ if (rv != -1)
+ rv = DO_2PASS_TEST(passwd, &td, &td_2pass,
+ compare_passwd, NULL);
+ TEST_DATA_DESTROY(passwd, &td_2pass);
+ break;
+ case TEST_BUILD_SNAPSHOT:
+ if (snapshot_file != NULL)
+ rv = TEST_SNAPSHOT_FILE_WRITE(passwd, snapshot_file,
+ &td, sdump_passwd);
+ break;
+ default:
+ rv = 0;
+ break;
+ }
+
+fin:
+ TEST_DATA_DESTROY(passwd, &td_snap);
+ TEST_DATA_DESTROY(passwd, &td);
+
+ return (rv);
+}
+
+#define SNAPSHOT_FILE "snapshot_pwd"
+
+ATF_TC_WITHOUT_HEAD(build_snapshot);
+ATF_TC_BODY(build_snapshot, tc)
+{
+
+ ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_BUILD_SNAPSHOT) == 0);
+}
+
+ATF_TC_WITHOUT_HEAD(getpwent);
+ATF_TC_BODY(getpwent, tc)
+{
+
+ ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_GETPWENT) == 0);
+}
+
+ATF_TC_WITHOUT_HEAD(getpwent_with_snapshot);
+ATF_TC_BODY(getpwent_with_snapshot, tc)
+{
+
+ ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_BUILD_SNAPSHOT) == 0);
+ ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_GETPWENT) == 0);
+}
+
+ATF_TC_WITHOUT_HEAD(getpwent_with_two_pass);
+ATF_TC_BODY(getpwent_with_two_pass, tc)
+{
+
+ ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_GETPWENT_2PASS) == 0);
+}
+
+ATF_TC_WITHOUT_HEAD(getpwnam);
+ATF_TC_BODY(getpwnam, tc)
+{
+
+ ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_GETPWNAM) == 0);
+}
+
+ATF_TC_WITHOUT_HEAD(getpwnam_with_snapshot);
+ATF_TC_BODY(getpwnam_with_snapshot, tc)
+{
+
+ ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_BUILD_SNAPSHOT) == 0);
+ ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_GETPWNAM) == 0);
+}
+
+ATF_TC_WITHOUT_HEAD(getpwuid);
+ATF_TC_BODY(getpwuid, tc)
+{
+
+ ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_GETPWUID) == 0);
+}
+
+ATF_TC_WITHOUT_HEAD(getpwuid_with_snapshot);
+ATF_TC_BODY(getpwuid_with_snapshot, tc)
+{
+
+ ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_BUILD_SNAPSHOT) == 0);
+ ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_GETPWUID) == 0);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, build_snapshot);
+ ATF_TP_ADD_TC(tp, getpwent);
+ ATF_TP_ADD_TC(tp, getpwent_with_snapshot);
+ ATF_TP_ADD_TC(tp, getpwent_with_two_pass);
+ ATF_TP_ADD_TC(tp, getpwnam);
+ ATF_TP_ADD_TC(tp, getpwnam_with_snapshot);
+ ATF_TP_ADD_TC(tp, getpwuid);
+ ATF_TP_ADD_TC(tp, getpwuid_with_snapshot);
+
+ return (atf_no_error());
+}
Property changes on: trunk/lib/libc/tests/nss/getpw_test.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/nss/getrpc_test.c
===================================================================
--- trunk/lib/libc/tests/nss/getrpc_test.c (rev 0)
+++ trunk/lib/libc/tests/nss/getrpc_test.c 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,559 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2006 Michael Bushkov <bushman at freebsd.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/lib/libc/tests/nss/getrpc_test.c 319298 2017-05-31 08:30:37Z ngie $");
+
+#include <arpa/inet.h>
+#include <rpc/rpc.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stringlist.h>
+#include <unistd.h>
+
+#include <atf-c.h>
+
+#include "testutil.h"
+
+enum test_methods {
+ TEST_GETRPCENT,
+ TEST_GETRPCBYNAME,
+ TEST_GETRPCBYNUMBER,
+ TEST_GETRPCENT_2PASS,
+ TEST_BUILD_SNAPSHOT
+};
+
+DECLARE_TEST_DATA(rpcent)
+DECLARE_TEST_FILE_SNAPSHOT(rpcent)
+DECLARE_1PASS_TEST(rpcent)
+DECLARE_2PASS_TEST(rpcent)
+
+static void clone_rpcent(struct rpcent *, struct rpcent const *);
+static int compare_rpcent(struct rpcent *, struct rpcent *, void *);
+static void dump_rpcent(struct rpcent *);
+static void free_rpcent(struct rpcent *);
+
+static void sdump_rpcent(struct rpcent *, char *, size_t);
+static int rpcent_read_snapshot_func(struct rpcent *, char *);
+
+static int rpcent_check_ambiguity(struct rpcent_test_data *,
+ struct rpcent *);
+static int rpcent_fill_test_data(struct rpcent_test_data *);
+static int rpcent_test_correctness(struct rpcent *, void *);
+static int rpcent_test_getrpcbyname(struct rpcent *, void *);
+static int rpcent_test_getrpcbynumber(struct rpcent *, void *);
+static int rpcent_test_getrpcent(struct rpcent *, void *);
+
+IMPLEMENT_TEST_DATA(rpcent)
+IMPLEMENT_TEST_FILE_SNAPSHOT(rpcent)
+IMPLEMENT_1PASS_TEST(rpcent)
+IMPLEMENT_2PASS_TEST(rpcent)
+
+static void
+clone_rpcent(struct rpcent *dest, struct rpcent const *src)
+{
+ ATF_REQUIRE(dest != NULL);
+ ATF_REQUIRE(src != NULL);
+
+ char **cp;
+ int aliases_num;
+
+ memset(dest, 0, sizeof(struct rpcent));
+
+ if (src->r_name != NULL) {
+ dest->r_name = strdup(src->r_name);
+ ATF_REQUIRE(dest->r_name != NULL);
+ }
+
+ dest->r_number = src->r_number;
+
+ if (src->r_aliases != NULL) {
+ aliases_num = 0;
+ for (cp = src->r_aliases; *cp; ++cp)
+ ++aliases_num;
+
+ dest->r_aliases = calloc(aliases_num + 1, sizeof(char *));
+ ATF_REQUIRE(dest->r_aliases != NULL);
+
+ for (cp = src->r_aliases; *cp; ++cp) {
+ dest->r_aliases[cp - src->r_aliases] = strdup(*cp);
+ ATF_REQUIRE(dest->r_aliases[cp - src->r_aliases] != NULL);
+ }
+ }
+}
+
+static void
+free_rpcent(struct rpcent *rpc)
+{
+ char **cp;
+
+ ATF_REQUIRE(rpc != NULL);
+
+ free(rpc->r_name);
+
+ for (cp = rpc->r_aliases; *cp; ++cp)
+ free(*cp);
+ free(rpc->r_aliases);
+}
+
+static int
+compare_rpcent(struct rpcent *rpc1, struct rpcent *rpc2, void *mdata)
+{
+ char **c1, **c2;
+
+ if (rpc1 == rpc2)
+ return 0;
+
+ if ((rpc1 == NULL) || (rpc2 == NULL))
+ goto errfin;
+
+ if ((strcmp(rpc1->r_name, rpc2->r_name) != 0) ||
+ (rpc1->r_number != rpc2->r_number))
+ goto errfin;
+
+ c1 = rpc1->r_aliases;
+ c2 = rpc2->r_aliases;
+
+ if ((rpc1->r_aliases == NULL) || (rpc2->r_aliases == NULL))
+ goto errfin;
+
+ for (;*c1 && *c2; ++c1, ++c2)
+ if (strcmp(*c1, *c2) != 0)
+ goto errfin;
+
+ if ((*c1 != '\0') || (*c2 != '\0'))
+ goto errfin;
+
+ return 0;
+
+errfin:
+ if (mdata == NULL) {
+ printf("following structures are not equal:\n");
+ dump_rpcent(rpc1);
+ dump_rpcent(rpc2);
+ }
+
+ return (-1);
+}
+
+static void
+sdump_rpcent(struct rpcent *rpc, char *buffer, size_t buflen)
+{
+ char **cp;
+ int written;
+
+ written = snprintf(buffer, buflen, "%s %d",
+ rpc->r_name, rpc->r_number);
+ buffer += written;
+ if (written > (int)buflen)
+ return;
+ buflen -= written;
+
+ if (rpc->r_aliases != NULL) {
+ if (*(rpc->r_aliases) != '\0') {
+ for (cp = rpc->r_aliases; *cp; ++cp) {
+ written = snprintf(buffer, buflen, " %s", *cp);
+ buffer += written;
+ if (written > (int)buflen)
+ return;
+ buflen -= written;
+
+ if (buflen == 0)
+ return;
+ }
+ } else
+ snprintf(buffer, buflen, " noaliases");
+ } else
+ snprintf(buffer, buflen, " (null)");
+}
+
+static int
+rpcent_read_snapshot_func(struct rpcent *rpc, char *line)
+{
+ StringList *sl;
+ char *s, *ps, *ts;
+ int i;
+
+ printf("1 line read from snapshot:\n%s\n", line);
+
+ i = 0;
+ sl = NULL;
+ ps = line;
+ memset(rpc, 0, sizeof(struct rpcent));
+ while ((s = strsep(&ps, " ")) != NULL) {
+ switch (i) {
+ case 0:
+ rpc->r_name = strdup(s);
+ ATF_REQUIRE(rpc->r_name != NULL);
+ break;
+
+ case 1:
+ rpc->r_number = (int)strtol(s, &ts, 10);
+ if (*ts != '\0') {
+ free(rpc->r_name);
+ return (-1);
+ }
+ break;
+
+ default:
+ if (sl == NULL) {
+ if (strcmp(s, "(null)") == 0)
+ return (0);
+
+ sl = sl_init();
+ ATF_REQUIRE(sl != NULL);
+
+ if (strcmp(s, "noaliases") != 0) {
+ ts = strdup(s);
+ ATF_REQUIRE(ts != NULL);
+ sl_add(sl, ts);
+ }
+ } else {
+ ts = strdup(s);
+ ATF_REQUIRE(ts != NULL);
+ sl_add(sl, ts);
+ }
+ break;
+ }
+ i++;
+ }
+
+ if (i < 3) {
+ free(rpc->r_name);
+ memset(rpc, 0, sizeof(struct rpcent));
+ return (-1);
+ }
+
+ sl_add(sl, NULL);
+ rpc->r_aliases = sl->sl_str;
+
+ /* NOTE: is it a dirty hack or not? */
+ free(sl);
+ return (0);
+}
+
+static void
+dump_rpcent(struct rpcent *result)
+{
+ if (result != NULL) {
+ char buffer[1024];
+ sdump_rpcent(result, buffer, sizeof(buffer));
+ printf("%s\n", buffer);
+ } else
+ printf("(null)\n");
+}
+
+static int
+rpcent_fill_test_data(struct rpcent_test_data *td)
+{
+ struct rpcent *rpc;
+
+ setrpcent(1);
+ while ((rpc = getrpcent()) != NULL) {
+ if (rpcent_test_correctness(rpc, NULL) == 0)
+ TEST_DATA_APPEND(rpcent, td, rpc);
+ else
+ return (-1);
+ }
+ endrpcent();
+
+ return (0);
+}
+
+static int
+rpcent_test_correctness(struct rpcent *rpc, void *mdata __unused)
+{
+
+ printf("testing correctness with the following data:\n");
+ dump_rpcent(rpc);
+
+ if (rpc == NULL)
+ goto errfin;
+
+ if (rpc->r_name == NULL)
+ goto errfin;
+
+ if (rpc->r_number < 0)
+ goto errfin;
+
+ if (rpc->r_aliases == NULL)
+ goto errfin;
+
+ printf("correct\n");
+
+ return (0);
+errfin:
+ printf("incorrect\n");
+
+ return (-1);
+}
+
+/* rpcent_check_ambiguity() is needed when one port+rpc is associated with
+ * more than one peice (these cases are usually marked as PROBLEM in
+ * /etc/peices. This functions is needed also when one peice+rpc is
+ * associated with several ports. We have to check all the rpcent structures
+ * to make sure that rpc really exists and correct */
+static int
+rpcent_check_ambiguity(struct rpcent_test_data *td, struct rpcent *rpc)
+{
+
+ return (TEST_DATA_FIND(rpcent, td, rpc, compare_rpcent,
+ NULL) != NULL ? 0 : -1);
+}
+
+static int
+rpcent_test_getrpcbyname(struct rpcent *rpc_model, void *mdata)
+{
+ char **alias;
+ struct rpcent *rpc;
+
+ printf("testing getrpcbyname() with the following data:\n");
+ dump_rpcent(rpc_model);
+
+ rpc = getrpcbyname(rpc_model->r_name);
+ if (rpcent_test_correctness(rpc, NULL) != 0)
+ goto errfin;
+
+ if ((compare_rpcent(rpc, rpc_model, NULL) != 0) &&
+ (rpcent_check_ambiguity((struct rpcent_test_data *)mdata, rpc)
+ !=0))
+ goto errfin;
+
+ for (alias = rpc_model->r_aliases; *alias; ++alias) {
+ rpc = getrpcbyname(*alias);
+
+ if (rpcent_test_correctness(rpc, NULL) != 0)
+ goto errfin;
+
+ if ((compare_rpcent(rpc, rpc_model, NULL) != 0) &&
+ (rpcent_check_ambiguity(
+ (struct rpcent_test_data *)mdata, rpc) != 0))
+ goto errfin;
+ }
+
+ printf("ok\n");
+ return (0);
+
+errfin:
+ printf("not ok\n");
+
+ return (-1);
+}
+
+static int
+rpcent_test_getrpcbynumber(struct rpcent *rpc_model, void *mdata)
+{
+ struct rpcent *rpc;
+
+ printf("testing getrpcbyport() with the following data...\n");
+ dump_rpcent(rpc_model);
+
+ rpc = getrpcbynumber(rpc_model->r_number);
+ if (rpcent_test_correctness(rpc, NULL) != 0 ||
+ (compare_rpcent(rpc, rpc_model, NULL) != 0 &&
+ rpcent_check_ambiguity((struct rpcent_test_data *)mdata, rpc)
+ != 0)) {
+ printf("not ok\n");
+ return (-1);
+ } else {
+ printf("ok\n");
+ return (0);
+ }
+}
+
+static int
+rpcent_test_getrpcent(struct rpcent *rpc, void *mdata __unused)
+{
+
+ /*
+ * Only correctness can be checked when doing 1-pass test for
+ * getrpcent().
+ */
+ return (rpcent_test_correctness(rpc, NULL));
+}
+
+static int
+run_tests(const char *snapshot_file, enum test_methods method)
+{
+ struct rpcent_test_data td, td_snap, td_2pass;
+ int rv;
+
+ TEST_DATA_INIT(rpcent, &td, clone_rpcent, free_rpcent);
+ TEST_DATA_INIT(rpcent, &td_snap, clone_rpcent, free_rpcent);
+ if (snapshot_file != NULL) {
+ if (access(snapshot_file, W_OK | R_OK) != 0) {
+ if (errno == ENOENT)
+ method = TEST_BUILD_SNAPSHOT;
+ else {
+ printf("can't access the file %s\n",
+ snapshot_file);
+
+ rv = -1;
+ goto fin;
+ }
+ } else {
+ if (method == TEST_BUILD_SNAPSHOT) {
+ rv = 0;
+ goto fin;
+ }
+
+ TEST_SNAPSHOT_FILE_READ(rpcent, snapshot_file,
+ &td_snap, rpcent_read_snapshot_func);
+ }
+ }
+
+ rv = rpcent_fill_test_data(&td);
+ if (rv == -1)
+ return (-1);
+ switch (method) {
+ case TEST_GETRPCBYNAME:
+ if (snapshot_file == NULL)
+ rv = DO_1PASS_TEST(rpcent, &td,
+ rpcent_test_getrpcbyname, (void *)&td);
+ else
+ rv = DO_1PASS_TEST(rpcent, &td_snap,
+ rpcent_test_getrpcbyname, (void *)&td_snap);
+ break;
+ case TEST_GETRPCBYNUMBER:
+ if (snapshot_file == NULL)
+ rv = DO_1PASS_TEST(rpcent, &td,
+ rpcent_test_getrpcbynumber, (void *)&td);
+ else
+ rv = DO_1PASS_TEST(rpcent, &td_snap,
+ rpcent_test_getrpcbynumber, (void *)&td_snap);
+ break;
+ case TEST_GETRPCENT:
+ if (snapshot_file == NULL)
+ rv = DO_1PASS_TEST(rpcent, &td, rpcent_test_getrpcent,
+ (void *)&td);
+ else
+ rv = DO_2PASS_TEST(rpcent, &td, &td_snap,
+ compare_rpcent, NULL);
+ break;
+ case TEST_GETRPCENT_2PASS:
+ TEST_DATA_INIT(rpcent, &td_2pass, clone_rpcent, free_rpcent);
+ rv = rpcent_fill_test_data(&td_2pass);
+ if (rv != -1)
+ rv = DO_2PASS_TEST(rpcent, &td, &td_2pass,
+ compare_rpcent, NULL);
+ TEST_DATA_DESTROY(rpcent, &td_2pass);
+ break;
+ case TEST_BUILD_SNAPSHOT:
+ if (snapshot_file != NULL)
+ rv = TEST_SNAPSHOT_FILE_WRITE(rpcent, snapshot_file, &td,
+ sdump_rpcent);
+ break;
+ default:
+ rv = 0;
+ break;
+ }
+
+fin:
+ TEST_DATA_DESTROY(rpcent, &td_snap);
+ TEST_DATA_DESTROY(rpcent, &td);
+
+ return (rv);
+}
+
+#define SNAPSHOT_FILE "snapshot_rpc"
+
+ATF_TC_WITHOUT_HEAD(build_snapshot);
+ATF_TC_BODY(build_snapshot, tc)
+{
+
+ ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_BUILD_SNAPSHOT) == 0);
+}
+
+ATF_TC_WITHOUT_HEAD(getrpcbyname);
+ATF_TC_BODY(getrpcbyname, tc)
+{
+
+ ATF_REQUIRE(run_tests(NULL, TEST_GETRPCBYNAME) == 0);
+}
+
+ATF_TC_WITHOUT_HEAD(getrpcbyname_with_snapshot);
+ATF_TC_BODY(getrpcbyname_with_snapshot, tc)
+{
+
+ ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_BUILD_SNAPSHOT) == 0);
+ ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_GETRPCBYNAME) == 0);
+}
+
+ATF_TC_WITHOUT_HEAD(getrpcbynumber);
+ATF_TC_BODY(getrpcbynumber, tc)
+{
+
+ ATF_REQUIRE(run_tests(NULL, TEST_GETRPCBYNUMBER) == 0);
+}
+
+ATF_TC_WITHOUT_HEAD(getrpcbynumber_with_snapshot);
+ATF_TC_BODY(getrpcbynumber_with_snapshot, tc)
+{
+
+ ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_BUILD_SNAPSHOT) == 0);
+ ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_GETRPCBYNUMBER) == 0);
+}
+
+ATF_TC_WITHOUT_HEAD(getrpcbyent);
+ATF_TC_BODY(getrpcbyent, tc)
+{
+
+ ATF_REQUIRE(run_tests(NULL, TEST_GETRPCENT) == 0);
+}
+
+ATF_TC_WITHOUT_HEAD(getrpcbyent_with_snapshot);
+ATF_TC_BODY(getrpcbyent_with_snapshot, tc)
+{
+
+ ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_BUILD_SNAPSHOT) == 0);
+ ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_GETRPCENT) == 0);
+}
+
+ATF_TC_WITHOUT_HEAD(getrpcbyent_with_two_pass);
+ATF_TC_BODY(getrpcbyent_with_two_pass, tc)
+{
+
+ ATF_REQUIRE(run_tests(NULL, TEST_GETRPCENT_2PASS) == 0);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, build_snapshot);
+ ATF_TP_ADD_TC(tp, getrpcbyname);
+ ATF_TP_ADD_TC(tp, getrpcbyname_with_snapshot);
+ ATF_TP_ADD_TC(tp, getrpcbynumber);
+ ATF_TP_ADD_TC(tp, getrpcbynumber_with_snapshot);
+ ATF_TP_ADD_TC(tp, getrpcbyent);
+ ATF_TP_ADD_TC(tp, getrpcbyent_with_snapshot);
+ ATF_TP_ADD_TC(tp, getrpcbyent_with_two_pass);
+
+ return (atf_no_error());
+}
Property changes on: trunk/lib/libc/tests/nss/getrpc_test.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/nss/getserv_test.c
===================================================================
--- trunk/lib/libc/tests/nss/getserv_test.c (rev 0)
+++ trunk/lib/libc/tests/nss/getserv_test.c 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,571 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2006 Michael Bushkov <bushman at freebsd.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/lib/libc/tests/nss/getserv_test.c 319298 2017-05-31 08:30:37Z ngie $");
+
+#include <arpa/inet.h>
+#include <errno.h>
+#include <netdb.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stringlist.h>
+#include <unistd.h>
+
+#include <atf-c.h>
+
+#include "testutil.h"
+
+enum test_methods {
+ TEST_GETSERVENT,
+ TEST_GETSERVBYNAME,
+ TEST_GETSERVBYPORT,
+ TEST_GETSERVENT_2PASS,
+ TEST_BUILD_SNAPSHOT
+};
+
+DECLARE_TEST_DATA(servent)
+DECLARE_TEST_FILE_SNAPSHOT(servent)
+DECLARE_1PASS_TEST(servent)
+DECLARE_2PASS_TEST(servent)
+
+static void clone_servent(struct servent *, struct servent const *);
+static int compare_servent(struct servent *, struct servent *, void *);
+static void dump_servent(struct servent *);
+static void free_servent(struct servent *);
+
+static void sdump_servent(struct servent *, char *, size_t);
+static int servent_read_snapshot_func(struct servent *, char *);
+
+static int servent_check_ambiguity(struct servent_test_data *,
+ struct servent *);
+static int servent_fill_test_data(struct servent_test_data *);
+static int servent_test_correctness(struct servent *, void *);
+static int servent_test_getservbyname(struct servent *, void *);
+static int servent_test_getservbyport(struct servent *, void *);
+static int servent_test_getservent(struct servent *, void *);
+
+IMPLEMENT_TEST_DATA(servent)
+IMPLEMENT_TEST_FILE_SNAPSHOT(servent)
+IMPLEMENT_1PASS_TEST(servent)
+IMPLEMENT_2PASS_TEST(servent)
+
+static void
+clone_servent(struct servent *dest, struct servent const *src)
+{
+ ATF_REQUIRE(dest != NULL);
+ ATF_REQUIRE(src != NULL);
+
+ char **cp;
+ int aliases_num;
+
+ memset(dest, 0, sizeof(struct servent));
+
+ if (src->s_name != NULL) {
+ dest->s_name = strdup(src->s_name);
+ ATF_REQUIRE(dest->s_name != NULL);
+ }
+
+ if (src->s_proto != NULL) {
+ dest->s_proto = strdup(src->s_proto);
+ ATF_REQUIRE(dest->s_proto != NULL);
+ }
+ dest->s_port = src->s_port;
+
+ if (src->s_aliases != NULL) {
+ aliases_num = 0;
+ for (cp = src->s_aliases; *cp; ++cp)
+ ++aliases_num;
+
+ dest->s_aliases = calloc(aliases_num + 1, sizeof(char *));
+ ATF_REQUIRE(dest->s_aliases != NULL);
+
+ for (cp = src->s_aliases; *cp; ++cp) {
+ dest->s_aliases[cp - src->s_aliases] = strdup(*cp);
+ ATF_REQUIRE(dest->s_aliases[cp - src->s_aliases] != NULL);
+ }
+ }
+}
+
+static void
+free_servent(struct servent *serv)
+{
+ char **cp;
+
+ ATF_REQUIRE(serv != NULL);
+
+ free(serv->s_name);
+ free(serv->s_proto);
+
+ for (cp = serv->s_aliases; *cp; ++cp)
+ free(*cp);
+ free(serv->s_aliases);
+}
+
+static int
+compare_servent(struct servent *serv1, struct servent *serv2, void *mdata)
+{
+ char **c1, **c2;
+
+ if (serv1 == serv2)
+ return 0;
+
+ if ((serv1 == NULL) || (serv2 == NULL))
+ goto errfin;
+
+ if ((strcmp(serv1->s_name, serv2->s_name) != 0) ||
+ (strcmp(serv1->s_proto, serv2->s_proto) != 0) ||
+ (serv1->s_port != serv2->s_port))
+ goto errfin;
+
+ c1 = serv1->s_aliases;
+ c2 = serv2->s_aliases;
+
+ if ((serv1->s_aliases == NULL) || (serv2->s_aliases == NULL))
+ goto errfin;
+
+ for (;*c1 && *c2; ++c1, ++c2)
+ if (strcmp(*c1, *c2) != 0)
+ goto errfin;
+
+ if ((*c1 != '\0') || (*c2 != '\0'))
+ goto errfin;
+
+ return 0;
+
+errfin:
+ if (mdata == NULL) {
+ printf("following structures are not equal:\n");
+ dump_servent(serv1);
+ dump_servent(serv2);
+ }
+
+ return (-1);
+}
+
+static void
+sdump_servent(struct servent *serv, char *buffer, size_t buflen)
+{
+ char **cp;
+ int written;
+
+ written = snprintf(buffer, buflen, "%s %d %s",
+ serv->s_name, ntohs(serv->s_port), serv->s_proto);
+ buffer += written;
+ if (written > (int)buflen)
+ return;
+ buflen -= written;
+
+ if (serv->s_aliases != NULL) {
+ if (*(serv->s_aliases) != '\0') {
+ for (cp = serv->s_aliases; *cp; ++cp) {
+ written = snprintf(buffer, buflen, " %s", *cp);
+ buffer += written;
+ if (written > (int)buflen)
+ return;
+ buflen -= written;
+
+ if (buflen == 0)
+ return;
+ }
+ } else
+ snprintf(buffer, buflen, " noaliases");
+ } else
+ snprintf(buffer, buflen, " (null)");
+}
+
+static int
+servent_read_snapshot_func(struct servent *serv, char *line)
+{
+ StringList *sl;
+ char *s, *ps, *ts;
+ int i;
+
+ printf("1 line read from snapshot:\n%s\n", line);
+
+ i = 0;
+ sl = NULL;
+ ps = line;
+ memset(serv, 0, sizeof(struct servent));
+ while ( (s = strsep(&ps, " ")) != NULL) {
+ switch (i) {
+ case 0:
+ serv->s_name = strdup(s);
+ ATF_REQUIRE(serv->s_name != NULL);
+ break;
+
+ case 1:
+ serv->s_port = htons(
+ (int)strtol(s, &ts, 10));
+ if (*ts != '\0') {
+ free(serv->s_name);
+ return (-1);
+ }
+ break;
+
+ case 2:
+ serv->s_proto = strdup(s);
+ ATF_REQUIRE(serv->s_proto != NULL);
+ break;
+
+ default:
+ if (sl == NULL) {
+ if (strcmp(s, "(null)") == 0)
+ return (0);
+
+ sl = sl_init();
+ ATF_REQUIRE(sl != NULL);
+
+ if (strcmp(s, "noaliases") != 0) {
+ ts = strdup(s);
+ ATF_REQUIRE(ts != NULL);
+ sl_add(sl, ts);
+ }
+ } else {
+ ts = strdup(s);
+ ATF_REQUIRE(ts != NULL);
+ sl_add(sl, ts);
+ }
+ break;
+ }
+ ++i;
+ }
+
+ if (i < 3) {
+ free(serv->s_name);
+ free(serv->s_proto);
+ memset(serv, 0, sizeof(struct servent));
+ return (-1);
+ }
+
+ sl_add(sl, NULL);
+ serv->s_aliases = sl->sl_str;
+
+ /* NOTE: is it a dirty hack or not? */
+ free(sl);
+ return (0);
+}
+
+static void
+dump_servent(struct servent *result)
+{
+ if (result != NULL) {
+ char buffer[1024];
+ sdump_servent(result, buffer, sizeof(buffer));
+ printf("%s\n", buffer);
+ } else
+ printf("(null)\n");
+}
+
+static int
+servent_fill_test_data(struct servent_test_data *td)
+{
+ struct servent *serv;
+
+ setservent(1);
+ while ((serv = getservent()) != NULL) {
+ if (servent_test_correctness(serv, NULL) == 0)
+ TEST_DATA_APPEND(servent, td, serv);
+ else
+ return (-1);
+ }
+ endservent();
+
+ return (0);
+}
+
+static int
+servent_test_correctness(struct servent *serv, void *mdata __unused)
+{
+ printf("testing correctness with the following data:\n");
+ dump_servent(serv);
+
+ if (serv == NULL)
+ goto errfin;
+
+ if (serv->s_name == NULL)
+ goto errfin;
+
+ if (serv->s_proto == NULL)
+ goto errfin;
+
+ if (ntohs(serv->s_port < 0))
+ goto errfin;
+
+ if (serv->s_aliases == NULL)
+ goto errfin;
+
+ printf("correct\n");
+
+ return (0);
+errfin:
+ printf("incorrect\n");
+
+ return (-1);
+}
+
+/* servent_check_ambiguity() is needed when one port+proto is associated with
+ * more than one service (these cases are usually marked as PROBLEM in
+ * /etc/services. This functions is needed also when one service+proto is
+ * associated with several ports. We have to check all the servent structures
+ * to make sure that serv really exists and correct */
+static int
+servent_check_ambiguity(struct servent_test_data *td, struct servent *serv)
+{
+
+ return (TEST_DATA_FIND(servent, td, serv, compare_servent,
+ NULL) != NULL ? 0 : -1);
+}
+
+static int
+servent_test_getservbyname(struct servent *serv_model, void *mdata)
+{
+ char **alias;
+ struct servent *serv;
+
+ printf("testing getservbyname() with the following data:\n");
+ dump_servent(serv_model);
+
+ serv = getservbyname(serv_model->s_name, serv_model->s_proto);
+ if (servent_test_correctness(serv, NULL) != 0)
+ goto errfin;
+
+ if ((compare_servent(serv, serv_model, NULL) != 0) &&
+ (servent_check_ambiguity((struct servent_test_data *)mdata, serv)
+ !=0))
+ goto errfin;
+
+ for (alias = serv_model->s_aliases; *alias; ++alias) {
+ serv = getservbyname(*alias, serv_model->s_proto);
+
+ if (servent_test_correctness(serv, NULL) != 0)
+ goto errfin;
+
+ if ((compare_servent(serv, serv_model, NULL) != 0) &&
+ (servent_check_ambiguity(
+ (struct servent_test_data *)mdata, serv) != 0))
+ goto errfin;
+ }
+
+ printf("ok\n");
+ return (0);
+
+errfin:
+ printf("not ok\n");
+
+ return (-1);
+}
+
+static int
+servent_test_getservbyport(struct servent *serv_model, void *mdata)
+{
+ struct servent *serv;
+
+ printf("testing getservbyport() with the following data...\n");
+ dump_servent(serv_model);
+
+ serv = getservbyport(serv_model->s_port, serv_model->s_proto);
+ if ((servent_test_correctness(serv, NULL) != 0) ||
+ ((compare_servent(serv, serv_model, NULL) != 0) &&
+ (servent_check_ambiguity((struct servent_test_data *)mdata, serv)
+ != 0))) {
+ printf("not ok\n");
+ return (-1);
+ } else {
+ printf("ok\n");
+ return (0);
+ }
+}
+
+static int
+servent_test_getservent(struct servent *serv, void *mdata __unused)
+{
+ /* Only correctness can be checked when doing 1-pass test for
+ * getservent(). */
+ return (servent_test_correctness(serv, NULL));
+}
+
+static int
+run_tests(const char *snapshot_file, enum test_methods method)
+{
+ struct servent_test_data td, td_snap, td_2pass;
+ int rv;
+
+ TEST_DATA_INIT(servent, &td, clone_servent, free_servent);
+ TEST_DATA_INIT(servent, &td_snap, clone_servent, free_servent);
+ if (snapshot_file != NULL) {
+ if (access(snapshot_file, W_OK | R_OK) != 0) {
+ if (errno == ENOENT)
+ method = TEST_BUILD_SNAPSHOT;
+ else {
+ printf("can't access the file %s\n",
+ snapshot_file);
+
+ rv = -1;
+ goto fin;
+ }
+ } else {
+ if (method == TEST_BUILD_SNAPSHOT) {
+ rv = 0;
+ goto fin;
+ }
+
+ TEST_SNAPSHOT_FILE_READ(servent, snapshot_file,
+ &td_snap, servent_read_snapshot_func);
+ }
+ }
+
+ rv = servent_fill_test_data(&td);
+ if (rv == -1)
+ return (-1);
+ switch (method) {
+ case TEST_GETSERVBYNAME:
+ if (snapshot_file == NULL)
+ rv = DO_1PASS_TEST(servent, &td,
+ servent_test_getservbyname, (void *)&td);
+ else
+ rv = DO_1PASS_TEST(servent, &td_snap,
+ servent_test_getservbyname, (void *)&td_snap);
+ break;
+ case TEST_GETSERVBYPORT:
+ if (snapshot_file == NULL)
+ rv = DO_1PASS_TEST(servent, &td,
+ servent_test_getservbyport, (void *)&td);
+ else
+ rv = DO_1PASS_TEST(servent, &td_snap,
+ servent_test_getservbyport, (void *)&td_snap);
+ break;
+ case TEST_GETSERVENT:
+ if (snapshot_file == NULL)
+ rv = DO_1PASS_TEST(servent, &td, servent_test_getservent,
+ (void *)&td);
+ else
+ rv = DO_2PASS_TEST(servent, &td, &td_snap,
+ compare_servent, NULL);
+ break;
+ case TEST_GETSERVENT_2PASS:
+ TEST_DATA_INIT(servent, &td_2pass, clone_servent, free_servent);
+ rv = servent_fill_test_data(&td_2pass);
+ if (rv != -1)
+ rv = DO_2PASS_TEST(servent, &td, &td_2pass,
+ compare_servent, NULL);
+ TEST_DATA_DESTROY(servent, &td_2pass);
+ break;
+ case TEST_BUILD_SNAPSHOT:
+ if (snapshot_file != NULL)
+ rv = TEST_SNAPSHOT_FILE_WRITE(servent, snapshot_file, &td,
+ sdump_servent);
+ break;
+ default:
+ rv = 0;
+ break;
+ }
+
+fin:
+ TEST_DATA_DESTROY(servent, &td_snap);
+ TEST_DATA_DESTROY(servent, &td);
+
+ return (rv);
+}
+
+#define SNAPSHOT_FILE "snapshot_serv"
+
+ATF_TC_WITHOUT_HEAD(build_snapshot);
+ATF_TC_BODY(build_snapshot, tc)
+{
+
+ ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_BUILD_SNAPSHOT) == 0);
+}
+
+ATF_TC_WITHOUT_HEAD(getservbyname);
+ATF_TC_BODY(getservbyname, tc)
+{
+
+ ATF_REQUIRE(run_tests(NULL, TEST_GETSERVBYNAME) == 0);
+}
+
+ATF_TC_WITHOUT_HEAD(getservbyname_with_snapshot);
+ATF_TC_BODY(getservbyname_with_snapshot, tc)
+{
+
+ ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_BUILD_SNAPSHOT) == 0);
+ ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_GETSERVBYNAME) == 0);
+}
+
+ATF_TC_WITHOUT_HEAD(getservbyport);
+ATF_TC_BODY(getservbyport, tc)
+{
+
+ ATF_REQUIRE(run_tests(NULL, TEST_GETSERVBYPORT) == 0);
+}
+
+ATF_TC_WITHOUT_HEAD(getservbyport_with_snapshot);
+ATF_TC_BODY(getservbyport_with_snapshot, tc)
+{
+
+ ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_BUILD_SNAPSHOT) == 0);
+ ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_GETSERVBYPORT) == 0);
+}
+
+ATF_TC_WITHOUT_HEAD(getservbyent);
+ATF_TC_BODY(getservbyent, tc)
+{
+
+ ATF_REQUIRE(run_tests(NULL, TEST_GETSERVENT) == 0);
+}
+
+ATF_TC_WITHOUT_HEAD(getservbyent_with_snapshot);
+ATF_TC_BODY(getservbyent_with_snapshot, tc)
+{
+
+ ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_BUILD_SNAPSHOT) == 0);
+ ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_GETSERVENT) == 0);
+}
+
+ATF_TC_WITHOUT_HEAD(getservbyent_with_two_pass);
+ATF_TC_BODY(getservbyent_with_two_pass, tc)
+{
+
+ ATF_REQUIRE(run_tests(NULL, TEST_GETSERVENT_2PASS) == 0);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, build_snapshot);
+ ATF_TP_ADD_TC(tp, getservbyent);
+ ATF_TP_ADD_TC(tp, getservbyent_with_snapshot);
+ ATF_TP_ADD_TC(tp, getservbyent_with_two_pass);
+ ATF_TP_ADD_TC(tp, getservbyname);
+ ATF_TP_ADD_TC(tp, getservbyname_with_snapshot);
+ ATF_TP_ADD_TC(tp, getservbyport);
+ ATF_TP_ADD_TC(tp, getservbyport_with_snapshot);
+
+ return (atf_no_error());
+}
Property changes on: trunk/lib/libc/tests/nss/getserv_test.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/nss/getusershell_test.c
===================================================================
--- trunk/lib/libc/tests/nss/getusershell_test.c (rev 0)
+++ trunk/lib/libc/tests/nss/getusershell_test.c 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,225 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2006 Michael Bushkov <bushman at freebsd.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/lib/libc/tests/nss/getusershell_test.c 319298 2017-05-31 08:30:37Z ngie $");
+
+#include <assert.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <atf-c.h>
+
+#include "testutil.h"
+
+enum test_methods {
+ TEST_GETUSERSHELL,
+ TEST_BUILD_SNAPSHOT
+};
+
+struct usershell {
+ char *path;
+};
+
+DECLARE_TEST_DATA(usershell)
+DECLARE_TEST_FILE_SNAPSHOT(usershell)
+DECLARE_2PASS_TEST(usershell)
+
+static void clone_usershell(struct usershell *, struct usershell const *);
+static int compare_usershell(struct usershell *, struct usershell *, void *);
+static void free_usershell(struct usershell *);
+
+static void sdump_usershell(struct usershell *, char *, size_t);
+static void dump_usershell(struct usershell *);
+
+IMPLEMENT_TEST_DATA(usershell)
+IMPLEMENT_TEST_FILE_SNAPSHOT(usershell)
+IMPLEMENT_2PASS_TEST(usershell)
+
+static void
+clone_usershell(struct usershell *dest, struct usershell const *src)
+{
+ assert(dest != NULL);
+ assert(src != NULL);
+
+ if (src->path != NULL) {
+ dest->path = strdup(src->path);
+ assert(dest->path != NULL);
+ }
+}
+
+static int
+compare_usershell(struct usershell *us1, struct usershell *us2,
+ void *mdata __unused)
+{
+ int rv;
+
+ assert(us1 != NULL);
+ assert(us2 != NULL);
+
+ dump_usershell(us1);
+ dump_usershell(us2);
+
+ if (us1 == us2)
+ return (0);
+
+ rv = strcmp(us1->path, us2->path);
+ if (rv != 0) {
+ printf("following structures are not equal:\n");
+ dump_usershell(us1);
+ dump_usershell(us2);
+ }
+
+ return (rv);
+}
+
+static void
+free_usershell(struct usershell *us)
+{
+ free(us->path);
+}
+
+static void
+sdump_usershell(struct usershell *us, char *buffer, size_t buflen)
+{
+ snprintf(buffer, buflen, "%s", us->path);
+}
+
+static void
+dump_usershell(struct usershell *us)
+{
+ if (us != NULL) {
+ char buffer[2048];
+ sdump_usershell(us, buffer, sizeof(buffer));
+ printf("%s\n", buffer);
+ } else
+ printf("(null)\n");
+}
+
+static int
+usershell_read_snapshot_func(struct usershell *us, char *line)
+{
+
+ us->path = strdup(line);
+ ATF_REQUIRE(us->path != NULL);
+
+ return (0);
+}
+
+static int
+run_tests(const char *snapshot_file, enum test_methods method)
+{
+ struct usershell_test_data td, td_snap;
+ struct usershell ushell;
+ int rv;
+
+ rv = 0;
+
+ TEST_DATA_INIT(usershell, &td, clone_usershell, free_usershell);
+ TEST_DATA_INIT(usershell, &td_snap, clone_usershell, free_usershell);
+
+ setusershell();
+ while ((ushell.path = getusershell()) != NULL) {
+ printf("usershell found:\n");
+ dump_usershell(&ushell);
+ TEST_DATA_APPEND(usershell, &td, &ushell);
+ }
+ endusershell();
+
+ if (snapshot_file != NULL) {
+ if (access(snapshot_file, W_OK | R_OK) != 0) {
+ if (errno == ENOENT)
+ method = TEST_BUILD_SNAPSHOT;
+ else {
+ printf("can't access the snapshot file %s\n",
+ snapshot_file);
+
+ rv = -1;
+ goto fin;
+ }
+ } else {
+ rv = TEST_SNAPSHOT_FILE_READ(usershell, snapshot_file,
+ &td_snap, usershell_read_snapshot_func);
+ if (rv != 0) {
+ printf("error reading snapshot file\n");
+ goto fin;
+ }
+ }
+ }
+
+ switch (method) {
+ case TEST_GETUSERSHELL:
+ rv = DO_2PASS_TEST(usershell, &td, &td_snap,
+ compare_usershell, NULL);
+ break;
+ case TEST_BUILD_SNAPSHOT:
+ if (snapshot_file != NULL) {
+ rv = TEST_SNAPSHOT_FILE_WRITE(usershell, snapshot_file,
+ &td, sdump_usershell);
+ }
+ break;
+ default:
+ rv = 0;
+ break;
+ }
+
+fin:
+ TEST_DATA_DESTROY(usershell, &td_snap);
+ TEST_DATA_DESTROY(usershell, &td);
+
+ return (rv);
+}
+
+#define SNAPSHOT_FILE "snapshot_usershell"
+
+ATF_TC_WITHOUT_HEAD(getusershell_with_snapshot);
+ATF_TC_BODY(getusershell_with_snapshot, tc)
+{
+
+ ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_BUILD_SNAPSHOT) == 0);
+}
+
+ATF_TC_WITHOUT_HEAD(getusershell_with_two_pass);
+ATF_TC_BODY(getusershell_with_two_pass, tc)
+{
+
+ ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_BUILD_SNAPSHOT) == 0);
+ ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_GETUSERSHELL) == 0);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, getusershell_with_snapshot);
+ ATF_TP_ADD_TC(tp, getusershell_with_two_pass);
+
+ return (atf_no_error());
+}
Property changes on: trunk/lib/libc/tests/nss/getusershell_test.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/nss/testutil.h
===================================================================
--- trunk/lib/libc/tests/nss/testutil.h (rev 0)
+++ trunk/lib/libc/tests/nss/testutil.h 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,331 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2006 Michael Bushkov <bushman at freebsd.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: stable/10/lib/libc/tests/nss/testutil.h 300454 2016-05-23 05:11:31Z ngie $
+ */
+
+#include <sys/queue.h>
+
+#define DECLARE_TEST_DATA(ent) \
+struct ent##_entry { \
+ struct ent data; \
+ STAILQ_ENTRY(ent##_entry) entries; \
+}; \
+ \
+struct ent##_test_data { \
+ void (*clone_func)(struct ent *, struct ent const *); \
+ void (*free_func)(struct ent *); \
+ \
+ STAILQ_HEAD(ent_head, ent##_entry) snapshot_data; \
+}; \
+ \
+void __##ent##_test_data_init(struct ent##_test_data *, \
+ void (*)(struct ent *, struct ent const *), \
+ void (*freef)(struct ent *)); \
+void __##ent##_test_data_destroy(struct ent##_test_data *); \
+ \
+void __##ent##_test_data_append(struct ent##_test_data *, struct ent *data);\
+int __##ent##_test_data_foreach(struct ent##_test_data *, \
+ int (*)(struct ent *, void *), void *); \
+int __##ent##_test_data_compare(struct ent##_test_data *, \
+ struct ent##_test_data *, int (*)(struct ent *, struct ent *, \
+ void *), void *); \
+struct ent *__##ent##_test_data_find(struct ent##_test_data *, struct ent *,\
+ int (*)(struct ent *, struct ent *, void *), void *); \
+void __##ent##_test_data_clear(struct ent##_test_data *);
+
+#define TEST_DATA_INIT(ent, td, clonef, freef)\
+ __##ent##_test_data_init(td, clonef, freef)
+#define TEST_DATA_DESTROY(ent, td) __##ent##_test_data_destroy(td)
+#define TEST_DATA_APPEND(ent, td, d) __##ent##_test_data_append(td, d)
+#define TEST_DATA_FOREACH(ent, td, f, mdata)\
+ __##ent##_test_data_foreach(td, f, mdata)
+#define TEST_DATA_COMPARE(ent, td1, td2, fcmp, mdata)\
+ __##ent##_test_data_compare(td1, td2, fcmp, mdata);
+#define TEST_DATA_FIND(ent, td, d, fcmp, mdata)\
+ __##ent##_test_data_find(td, d, fcmp, mdata)
+#define TEST_DATA_CLEAR(ent, td) __##ent##_test_data_clear(td)
+
+#define IMPLEMENT_TEST_DATA(ent) \
+void \
+__##ent##_test_data_init(struct ent##_test_data *td, \
+ void (*clonef)(struct ent *, struct ent const *), \
+ void (*freef)(struct ent *)) \
+{ \
+ ATF_REQUIRE(td != NULL); \
+ ATF_REQUIRE(clonef != NULL); \
+ ATF_REQUIRE(freef != NULL); \
+ \
+ memset(td, 0, sizeof(*td)); \
+ td->clone_func = clonef; \
+ td->free_func = freef; \
+ STAILQ_INIT(&td->snapshot_data); \
+} \
+ \
+void \
+__##ent##_test_data_destroy(struct ent##_test_data *td) \
+{ \
+ __##ent##_test_data_clear(td); \
+} \
+ \
+void \
+__##ent##_test_data_append(struct ent##_test_data *td, struct ent *app_data)\
+{ \
+ struct ent##_entry *e; \
+ \
+ ATF_REQUIRE(td != NULL); \
+ ATF_REQUIRE(app_data != NULL); \
+ \
+ e = (struct ent##_entry *)malloc(sizeof(struct ent##_entry)); \
+ ATF_REQUIRE(e != NULL); \
+ memset(e, 0, sizeof(struct ent##_entry)); \
+ \
+ td->clone_func(&e->data, app_data); \
+ STAILQ_INSERT_TAIL(&td->snapshot_data, e, entries); \
+} \
+ \
+int \
+__##ent##_test_data_foreach(struct ent##_test_data *td, \
+ int (*forf)(struct ent *, void *), void *mdata) \
+{ \
+ struct ent##_entry *e; \
+ int rv; \
+ \
+ ATF_REQUIRE(td != NULL); \
+ ATF_REQUIRE(forf != NULL); \
+ \
+ rv = 0; \
+ STAILQ_FOREACH(e, &td->snapshot_data, entries) { \
+ rv = forf(&e->data, mdata); \
+ if (rv != 0) \
+ break; \
+ } \
+ \
+ return (rv); \
+} \
+ \
+int \
+__##ent##_test_data_compare(struct ent##_test_data *td1, struct ent##_test_data *td2,\
+ int (*cmp_func)(struct ent *, struct ent *, void *), void *mdata)\
+{ \
+ struct ent##_entry *e1, *e2; \
+ int rv; \
+ \
+ ATF_REQUIRE(td1 != NULL); \
+ ATF_REQUIRE(td2 != NULL); \
+ ATF_REQUIRE(cmp_func != NULL); \
+ \
+ e1 = STAILQ_FIRST(&td1->snapshot_data); \
+ e2 = STAILQ_FIRST(&td2->snapshot_data); \
+ \
+ rv = 0; \
+ do { \
+ if ((e1 == NULL) || (e2 == NULL)) { \
+ if (e1 == e2) \
+ return (0); \
+ else \
+ return (-1); \
+ } \
+ \
+ rv = cmp_func(&e1->data, &e2->data, mdata); \
+ e1 = STAILQ_NEXT(e1, entries); \
+ e2 = STAILQ_NEXT(e2, entries); \
+ } while (rv == 0); \
+ \
+ return (rv); \
+} \
+ \
+struct ent * \
+__##ent##_test_data_find(struct ent##_test_data *td, struct ent *data, \
+ int (*cmp)(struct ent *, struct ent *, void *), void *mdata) \
+{ \
+ struct ent##_entry *e; \
+ struct ent *result; \
+ \
+ ATF_REQUIRE(td != NULL); \
+ ATF_REQUIRE(cmp != NULL); \
+ \
+ result = NULL; \
+ STAILQ_FOREACH(e, &td->snapshot_data, entries) { \
+ if (cmp(&e->data, data, mdata) == 0) { \
+ result = &e->data; \
+ break; \
+ } \
+ } \
+ \
+ return (result); \
+} \
+ \
+ \
+void \
+__##ent##_test_data_clear(struct ent##_test_data *td) \
+{ \
+ struct ent##_entry *e; \
+ ATF_REQUIRE(td != NULL); \
+ \
+ while (!STAILQ_EMPTY(&td->snapshot_data)) { \
+ e = STAILQ_FIRST(&td->snapshot_data); \
+ STAILQ_REMOVE_HEAD(&td->snapshot_data, entries); \
+ \
+ td->free_func(&e->data); \
+ free(e); \
+ e = NULL; \
+ } \
+}
+
+#define DECLARE_TEST_FILE_SNAPSHOT(ent) \
+struct ent##_snp_param { \
+ FILE *fp; \
+ void (*sdump_func)(struct ent *, char *, size_t); \
+}; \
+ \
+int __##ent##_snapshot_write_func(struct ent *, void *); \
+int __##ent##_snapshot_write(char const *, struct ent##_test_data *, \
+ void (*)(struct ent *, char *, size_t)); \
+int __##ent##_snapshot_read(char const *, struct ent##_test_data *, \
+ int (*)(struct ent *, char *));
+
+#define TEST_SNAPSHOT_FILE_WRITE(ent, fname, td, f) \
+ __##ent##_snapshot_write(fname, td, f)
+#define TEST_SNAPSHOT_FILE_READ(ent, fname, td, f) \
+ __##ent##_snapshot_read(fname, td, f)
+
+#define IMPLEMENT_TEST_FILE_SNAPSHOT(ent) \
+int \
+__##ent##_snapshot_write_func(struct ent *data, void *mdata) \
+{ \
+ char buffer[1024]; \
+ struct ent##_snp_param *param; \
+ \
+ ATF_REQUIRE(data != NULL); \
+ \
+ param = (struct ent##_snp_param *)mdata; \
+ param->sdump_func(data, buffer, sizeof(buffer)); \
+ fputs(buffer, param->fp); \
+ fputc('\n', param->fp); \
+ \
+ return (0); \
+} \
+ \
+int \
+__##ent##_snapshot_write(char const *fname, struct ent##_test_data *td, \
+ void (*sdump_func)(struct ent *, char *, size_t)) \
+{ \
+ struct ent##_snp_param param; \
+ \
+ ATF_REQUIRE(fname != NULL); \
+ ATF_REQUIRE(td != NULL); \
+ \
+ param.fp = fopen(fname, "w"); \
+ if (param.fp == NULL) \
+ return (-1); \
+ \
+ param.sdump_func = sdump_func; \
+ __##ent##_test_data_foreach(td, __##ent##_snapshot_write_func, ¶m);\
+ fclose(param.fp); \
+ \
+ return (0); \
+} \
+ \
+int \
+__##ent##_snapshot_read(char const *fname, struct ent##_test_data *td, \
+ int (*read_func)(struct ent *, char *)) \
+{ \
+ struct ent data; \
+ FILE *fi; \
+ size_t len; \
+ int rv; \
+ \
+ ATF_REQUIRE(fname != NULL); \
+ ATF_REQUIRE(td != NULL); \
+ \
+ fi = fopen(fname, "r"); \
+ if (fi == NULL) \
+ return (-1); \
+ \
+ rv = 0; \
+ while (!feof(fi)) { \
+ char *buf = fgetln(fi, &len); \
+ if (buf == NULL || len <= 1) \
+ continue; \
+ if (buf[len - 1] == '\n') \
+ buf[len - 1] = '\0'; \
+ else \
+ buf[len] = '\0'; \
+ if (buf[0] == '#') \
+ continue; \
+ rv = read_func(&data, buf); \
+ if (rv == 0) { \
+ __##ent##_test_data_append(td, &data); \
+ td->free_func(&data); \
+ } else \
+ goto fin; \
+ } \
+ \
+fin: \
+ fclose(fi); \
+ return (rv); \
+}
+
+#define DECLARE_1PASS_TEST(ent) \
+int __##ent##_1pass_test(struct ent##_test_data *, \
+ int (*)(struct ent *, void *), \
+ void *);
+
+#define DO_1PASS_TEST(ent, td, f, mdata) \
+ __##ent##_1pass_test(td, f, mdata)
+
+#define IMPLEMENT_1PASS_TEST(ent) \
+int \
+__##ent##_1pass_test(struct ent##_test_data *td, \
+ int (*tf)(struct ent *, void *), \
+ void *mdata) \
+{ \
+ int rv; \
+ rv = __##ent##_test_data_foreach(td, tf, mdata); \
+ \
+ return (rv); \
+}
+
+#define DECLARE_2PASS_TEST(ent) \
+int __##ent##_2pass_test(struct ent##_test_data *, \
+ struct ent##_test_data *, \
+ int (*)(struct ent *, struct ent *, void *), void *);
+
+#define DO_2PASS_TEST(ent, td1, td2, f, mdata) \
+ __##ent##_2pass_test(td1, td2, f, mdata)
+
+#define IMPLEMENT_2PASS_TEST(ent) \
+int \
+__##ent##_2pass_test(struct ent##_test_data *td1, \
+ struct ent##_test_data *td2, \
+ int (*cmp_func)(struct ent *, struct ent *, void *), \
+ void *cmp_mdata) \
+{ \
+ int rv; \
+ \
+ rv = __##ent##_test_data_compare(td1, td2, cmp_func, cmp_mdata); \
+ return (rv); \
+}
Property changes on: trunk/lib/libc/tests/nss/testutil.h
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/regex/Makefile
===================================================================
--- trunk/lib/libc/tests/regex/Makefile (rev 0)
+++ trunk/lib/libc/tests/regex/Makefile 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,59 @@
+# $MidnightBSD$
+# $FreeBSD: stable/10/lib/libc/tests/regex/Makefile 314817 2017-03-07 01:52:50Z ngie $
+
+.include <bsd.own.mk>
+
+BINDIR= ${TESTSDIR}
+
+# SKIP_LEFTASSOC -> these testcases fail on FreeBSD.
+IMPLEMENTATION?= -DREGEX_SPENCER -DSKIP_LEFTASSOC
+
+CFLAGS.h_regex+=-I${TESTSRC} -I${.CURDIR:H:H}/regex
+PROGS+= h_regex
+SRCS.h_regex= main.c split.c debug.c
+
+NETBSD_ATF_TESTS_SH= regex_test
+
+FILESDIR= ${TESTSDIR}/data
+FILES+= README
+FILES+= data/anchor.in
+FILES+= data/backref.in
+FILES+= data/basic.in
+FILES+= data/bracket.in
+FILES+= data/c_comments.in
+FILES+= data/complex.in
+FILES+= data/error.in
+FILES+= data/meta.in
+FILES+= data/nospec.in
+FILES+= data/paren.in
+FILES+= data/regress.in
+FILES+= data/repet_bounded.in
+FILES+= data/repet_multi.in
+FILES+= data/repet_ordinary.in
+FILES+= data/startend.in
+FILES+= data/subexp.in
+FILES+= data/subtle.in
+FILES+= data/word_bound.in
+FILES+= data/zero.in
+#FILES+= data/att/README
+FILES+= data/att/basic.dat
+FILES+= data/att/categorization.dat
+FILES+= data/att/forcedassoc.dat
+FILES+= data/att/leftassoc.dat
+FILES+= data/att/nullsubexpr.dat
+FILES+= data/att/repetition.dat
+FILES+= data/att/rightassoc.dat
+
+NETBSD_ATF_TESTS_C= exhaust_test
+NETBSD_ATF_TESTS_C+= regex_att_test
+
+.for t in ${NETBSD_ATF_TESTS_C}
+CFLAGS.$t+= -I${TESTSRC} ${IMPLEMENTATION}
+.endfor
+
+.include "../Makefile.netbsd-tests"
+
+DPADD.regex_att_test+= ${LIBUTIL}
+LDADD.regex_att_test+= -lutil
+
+.include <bsd.test.mk>
Property changes on: trunk/lib/libc/tests/regex/Makefile
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/resolv/Makefile
===================================================================
--- trunk/lib/libc/tests/resolv/Makefile (rev 0)
+++ trunk/lib/libc/tests/resolv/Makefile 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,16 @@
+# $MidnightBSD$
+# $FreeBSD: stable/10/lib/libc/tests/resolv/Makefile 292844 2015-12-28 23:05:13Z ngie $
+
+TESTSDIR= ${TESTSBASE}/lib/libc/resolv
+BINDIR= ${TESTSDIR}
+
+FILES+= mach
+
+ATF_TESTS_C+= resolv_test
+
+# Note: this test relies on being dynamically linked. You will get a
+# spurious PASS for a statically linked test.
+DPADD.resolv_test+= ${LIBPTHREAD}
+LDADD.resolv_test+= -lpthread
+
+.include <bsd.test.mk>
Property changes on: trunk/lib/libc/tests/resolv/Makefile
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/resolv/mach
===================================================================
--- trunk/lib/libc/tests/resolv/mach (rev 0)
+++ trunk/lib/libc/tests/resolv/mach 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,47 @@
+# $MidnightBSD$
+# $FreeBSD: stable/10/lib/libc/tests/resolv/mach 292317 2015-12-16 05:11:57Z ngie $
+localhost
+anoncvs.cirr.com
+anoncvs.netbsd.se
+antioche.antioche.eu.org
+centaurus.4web.cz
+chur.math.ntnu.no
+console.netbsd.org
+cvs.netbsd.org
+cvsup.netbsd.se
+ftp.chg.ru
+ftp.estpak.ee
+ftp.fsn.hu
+ftp.funet.fi
+ftp.netbsd.org
+ftp.nluug.nl
+ftp.plig.org
+ftp.uni-erlangen.de
+ftp.xgate.co.kr
+gd.tuwien.ac.at
+gort.ludd.luth.se
+irc.warped.net
+knug.youn.co.kr
+mail.jp.netbsd.org
+mail.netbsd.org
+melanoma.cs.rmit.edu.au
+mirror.aarnet.edu.au
+moon.vub.ac.be
+net.bsd.cz
+netbsd.3miasto.net
+netbsd.4ka.mipt.ru
+netbsd.csie.nctu.edu.tw
+netbsd.enderunix.org
+netbsd.ftp.fu-berlin.de
+netbsd.pair.com
+netbsdiso.interoute.net.uk
+netbsdwww.cs.rmit.edu.au
+netbsdwww.interoute.net.uk
+ns.netbsd.org
+skeleton.phys.spbu.ru
+www.en.netbsd.de
+www.netbsd.cl
+www.netbsd.nl
+www.netbsd.org
+www.netbsd.ro
+zeppo.rediris.es
Property changes on: trunk/lib/libc/tests/resolv/mach
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: trunk/lib/libc/tests/resolv/resolv_test.c
===================================================================
--- trunk/lib/libc/tests/resolv/resolv_test.c (rev 0)
+++ trunk/lib/libc/tests/resolv/resolv_test.c 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,332 @@
+/* $MidnightBSD$ */
+/* $NetBSD: resolv.c,v 1.6 2004/05/23 16:59:11 christos Exp $ */
+
+/*-
+ * Copyright (c) 2004 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.
+ */
+/* $FreeBSD: stable/10/lib/libc/tests/resolv/resolv_test.c 305272 2016-09-02 04:12:36Z ngie $ */
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: resolv.c,v 1.6 2004/05/23 16:59:11 christos Exp $");
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <netdb.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <stringlist.h>
+
+#include <atf-c.h>
+
+#define NTHREADS 10
+#define NHOSTS 100
+#define WS " \t\n\r"
+
+enum method {
+ METHOD_GETADDRINFO,
+ METHOD_GETHOSTBY,
+ METHOD_GETIPNODEBY
+};
+
+static StringList *hosts = NULL;
+static enum method method = METHOD_GETADDRINFO;
+static int *ask = NULL;
+static int *got = NULL;
+
+static void load(const char *);
+static void resolvone(int);
+static void *resolvloop(void *);
+static void run(int *);
+
+static pthread_mutex_t stats = PTHREAD_MUTEX_INITIALIZER;
+
+static void
+load(const char *fname)
+{
+ FILE *fp;
+ size_t len;
+ char *line;
+
+ if ((fp = fopen(fname, "r")) == NULL)
+ ATF_REQUIRE(fp != NULL);
+ while ((line = fgetln(fp, &len)) != NULL) {
+ char c = line[len];
+ char *ptr;
+ line[len] = '\0';
+ for (ptr = strtok(line, WS); ptr; ptr = strtok(NULL, WS)) {
+ if (ptr == '\0' || ptr[0] == '#')
+ continue;
+ sl_add(hosts, strdup(ptr));
+ }
+ line[len] = c;
+ }
+
+ (void)fclose(fp);
+}
+
+static int
+resolv_getaddrinfo(pthread_t self, char *host, int port)
+{
+ char portstr[6], buf[1024], hbuf[NI_MAXHOST], pbuf[NI_MAXSERV];
+ struct addrinfo hints, *res;
+ int error, len;
+
+ snprintf(portstr, sizeof(portstr), "%d", port);
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_family = AF_UNSPEC;
+ hints.ai_flags = AI_PASSIVE;
+ hints.ai_socktype = SOCK_STREAM;
+ error = getaddrinfo(host, portstr, &hints, &res);
+ len = snprintf(buf, sizeof(buf), "%p: host %s %s\n",
+ self, host, error ? "not found" : "ok");
+ (void)write(STDOUT_FILENO, buf, len);
+ if (error == 0) {
+ memset(hbuf, 0, sizeof(hbuf));
+ memset(pbuf, 0, sizeof(pbuf));
+ getnameinfo(res->ai_addr, res->ai_addrlen, hbuf, sizeof(hbuf),
+ pbuf, sizeof(pbuf), 0);
+ len = snprintf(buf, sizeof(buf),
+ "%p: reverse %s %s\n", self, hbuf, pbuf);
+ (void)write(STDOUT_FILENO, buf, len);
+ }
+ if (error == 0)
+ freeaddrinfo(res);
+ return error;
+}
+
+static int
+resolv_gethostby(pthread_t self, char *host)
+{
+ char buf[1024];
+ struct hostent *hp, *hp2;
+ int len;
+
+ hp = gethostbyname(host);
+ len = snprintf(buf, sizeof(buf), "%p: host %s %s\n",
+ self, host, (hp == NULL) ? "not found" : "ok");
+ (void)write(STDOUT_FILENO, buf, len);
+ if (hp) {
+ memcpy(buf, hp->h_addr, hp->h_length);
+ hp2 = gethostbyaddr(buf, hp->h_length, hp->h_addrtype);
+ if (hp2) {
+ len = snprintf(buf, sizeof(buf),
+ "%p: reverse %s\n", self, hp2->h_name);
+ (void)write(STDOUT_FILENO, buf, len);
+ }
+ }
+ return hp ? 0 : -1;
+}
+
+static int
+resolv_getipnodeby(pthread_t self, char *host)
+{
+ char buf[1024];
+ struct hostent *hp, *hp2;
+ int len, h_error;
+
+ hp = getipnodebyname(host, AF_INET, 0, &h_error);
+ len = snprintf(buf, sizeof(buf), "%p: host %s %s\n",
+ self, host, (hp == NULL) ? "not found" : "ok");
+ (void)write(STDOUT_FILENO, buf, len);
+ if (hp) {
+ memcpy(buf, hp->h_addr, hp->h_length);
+ hp2 = getipnodebyaddr(buf, hp->h_length, hp->h_addrtype,
+ &h_error);
+ if (hp2) {
+ len = snprintf(buf, sizeof(buf),
+ "%p: reverse %s\n", self, hp2->h_name);
+ (void)write(STDOUT_FILENO, buf, len);
+ }
+ if (hp2)
+ freehostent(hp2);
+ }
+ if (hp)
+ freehostent(hp);
+ return hp ? 0 : -1;
+}
+
+static void
+resolvone(int n)
+{
+ char buf[1024];
+ pthread_t self = pthread_self();
+ size_t i = (random() & 0x0fffffff) % hosts->sl_cur;
+ char *host = hosts->sl_str[i];
+ struct addrinfo hints, *res;
+ int error, len;
+
+ len = snprintf(buf, sizeof(buf), "%p: %d resolving %s %d\n",
+ self, n, host, (int)i);
+ (void)write(STDOUT_FILENO, buf, len);
+ switch (method) {
+ case METHOD_GETADDRINFO:
+ error = resolv_getaddrinfo(self, host, i);
+ break;
+ case METHOD_GETHOSTBY:
+ error = resolv_gethostby(self, host);
+ break;
+ case METHOD_GETIPNODEBY:
+ error = resolv_getipnodeby(self, host);
+ break;
+ default:
+ break;
+ }
+ pthread_mutex_lock(&stats);
+ ask[i]++;
+ got[i] += error == 0;
+ pthread_mutex_unlock(&stats);
+}
+
+static void *
+resolvloop(void *p)
+{
+ int *nhosts = (int *)p;
+ if (*nhosts == 0)
+ return NULL;
+ do
+ resolvone(*nhosts);
+ while (--(*nhosts));
+ return NULL;
+}
+
+static void
+run(int *nhosts)
+{
+ pthread_t self;
+ int rc;
+
+ self = pthread_self();
+ rc = pthread_create(&self, NULL, resolvloop, nhosts);
+ ATF_REQUIRE_MSG(rc == 0, "pthread_create failed: %s", strerror(rc));
+}
+
+static int
+run_tests(const char *hostlist_file, enum method method)
+{
+ int nthreads = NTHREADS;
+ int nhosts = NHOSTS;
+ int i, c, done, *nleft;
+ hosts = sl_init();
+
+ srandom(1234);
+
+ load(hostlist_file);
+
+ ATF_REQUIRE_MSG(0 < hosts->sl_cur, "0 hosts in %s", hostlist_file);
+
+ nleft = malloc(nthreads * sizeof(int));
+ ATF_REQUIRE(nleft != NULL);
+
+ ask = calloc(hosts->sl_cur, sizeof(int));
+ ATF_REQUIRE(ask != NULL);
+
+ got = calloc(hosts->sl_cur, sizeof(int));
+ ATF_REQUIRE(got != NULL);
+
+ for (i = 0; i < nthreads; i++) {
+ nleft[i] = nhosts;
+ run(&nleft[i]);
+ }
+
+ for (done = 0; !done;) {
+ done = 1;
+ for (i = 0; i < nthreads; i++) {
+ if (nleft[i] != 0) {
+ done = 0;
+ break;
+ }
+ }
+ sleep(1);
+ }
+ c = 0;
+ for (i = 0; i < hosts->sl_cur; i++) {
+ if (ask[i] != got[i] && got[i] != 0) {
+ printf("Error: host %s ask %d got %d\n",
+ hosts->sl_str[i], ask[i], got[i]);
+ c++;
+ }
+ }
+ free(nleft);
+ free(ask);
+ free(got);
+ sl_free(hosts, 1);
+ return c;
+}
+
+#define HOSTLIST_FILE "mach"
+
+#define RUN_TESTS(tc, method) \
+do { \
+ char *_hostlist_file; \
+ ATF_REQUIRE(0 < asprintf(&_hostlist_file, "%s/%s", \
+ atf_tc_get_config_var(tc, "srcdir"), HOSTLIST_FILE)); \
+ ATF_REQUIRE(run_tests(_hostlist_file, method) == 0); \
+} while(0)
+
+ATF_TC(getaddrinfo_test);
+ATF_TC_HEAD(getaddrinfo_test, tc) {
+ atf_tc_set_md_var(tc, "timeout", "1200");
+}
+ATF_TC_BODY(getaddrinfo_test, tc)
+{
+
+ RUN_TESTS(tc, METHOD_GETADDRINFO);
+}
+
+ATF_TC(gethostby_test);
+ATF_TC_HEAD(gethostby_test, tc) {
+ atf_tc_set_md_var(tc, "timeout", "1200");
+}
+ATF_TC_BODY(gethostby_test, tc)
+{
+
+ RUN_TESTS(tc, METHOD_GETHOSTBY);
+}
+
+ATF_TC(getipnodeby_test);
+ATF_TC_HEAD(getipnodeby_test, tc) {
+
+ atf_tc_set_md_var(tc, "timeout", "1200");
+}
+ATF_TC_BODY(getipnodeby_test, tc)
+{
+
+ RUN_TESTS(tc, METHOD_GETIPNODEBY);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, getaddrinfo_test);
+ ATF_TP_ADD_TC(tp, gethostby_test);
+ ATF_TP_ADD_TC(tp, getipnodeby_test);
+
+ return (atf_no_error());
+}
Property changes on: trunk/lib/libc/tests/resolv/resolv_test.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/rpc/Makefile
===================================================================
--- trunk/lib/libc/tests/rpc/Makefile (rev 0)
+++ trunk/lib/libc/tests/rpc/Makefile 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,27 @@
+# $MidnightBSD$
+# $FreeBSD: stable/10/lib/libc/tests/rpc/Makefile 313488 2017-02-09 22:49:48Z ngie $
+
+SRCS.xdr_test= ${RPCSRC:.x=_xdr.c} t_xdr.c ${RPCSRC:.x=.h} \
+ h_testbits.h
+
+NETBSD_ATF_TESTS_C= rpc_test
+NETBSD_ATF_TESTS_C+= xdr_test
+
+RPCSRC= h_testbits.x
+RPCGEN= RPCGEN_CPP=${CPP:Q} rpcgen -L -C
+
+h_testbits.h: ${RPCSRC}
+ ${RPCGEN} -h -o ${.TARGET} ${.ALLSRC}
+
+h_testbits_xdr.c: ${RPCSRC} h_testbits.h
+ ${RPCGEN} ${.ALLSRC:M*.x}
+
+CLEANFILES+= ${RPCSRC:.x=.h} ${RPCSRC:.x=.c} h_testbits_xdr.c
+CFLAGS+= -I${.OBJDIR}
+
+LDADD+= -lrpcsvc -lutil
+DPADD+= ${LIBRPCSVC} ${LIBUTIL}
+
+.include "../Makefile.netbsd-tests"
+
+.include <bsd.test.mk>
Property changes on: trunk/lib/libc/tests/rpc/Makefile
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/setjmp/Makefile
===================================================================
--- trunk/lib/libc/tests/setjmp/Makefile (rev 0)
+++ trunk/lib/libc/tests/setjmp/Makefile 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,14 @@
+# $MidnightBSD$
+# $FreeBSD: stable/10/lib/libc/tests/setjmp/Makefile 313488 2017-02-09 22:49:48Z ngie $
+
+NETBSD_ATF_TESTS_C= setjmp_test
+NETBSD_ATF_TESTS_C+= threadjmp_test
+
+DPADD.threadjmp_test+= ${LIBPTHREAD}
+LDADD.threadjmp_test+= -lpthread
+
+WARNS?= 4
+
+.include "../Makefile.netbsd-tests"
+
+.include <bsd.test.mk>
Property changes on: trunk/lib/libc/tests/setjmp/Makefile
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/ssp/Makefile
===================================================================
--- trunk/lib/libc/tests/ssp/Makefile (rev 0)
+++ trunk/lib/libc/tests/ssp/Makefile 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,48 @@
+# $MidnightBSD$
+# $FreeBSD: stable/10/lib/libc/tests/ssp/Makefile 313488 2017-02-09 22:49:48Z ngie $
+
+.include <bsd.own.mk>
+
+NO_WERROR=
+WARNS?= 2
+
+CFLAGS.h_raw+= -fstack-protector-all -Wstack-protector
+.if ${COMPILER_TYPE} == "clang"
+CFLAGS.h_raw+= -fsanitize=bounds
+.elif ${COMPILER_TYPE} == "gcc"
+CFLAGS.h_raw+= --param ssp-buffer-size=1
+DPADD+= ${LIBSSP}
+LDADD+= -lssp
+.endif
+
+NETBSD_ATF_TESTS_SH= ssp_test
+
+BINDIR= ${TESTSDIR}
+
+PROGS= h_fgets
+PROGS+= h_gets
+PROGS+= h_getcwd
+PROGS+= h_memcpy
+PROGS+= h_memmove
+PROGS+= h_memset
+# This testcase doesn't run properly when not compiled with -fsantize=bounds
+# with clang, which is currently contingent on a compiler_rt update
+.if ${COMPILER_TYPE} == "clang" && ${COMPILER_VERSION} < 30500
+PROGS+= h_raw
+.endif
+PROGS+= h_read
+PROGS+= h_readlink
+PROGS+= h_snprintf
+PROGS+= h_sprintf
+PROGS+= h_stpcpy
+PROGS+= h_stpncpy
+PROGS+= h_strcat
+PROGS+= h_strcpy
+PROGS+= h_strncat
+PROGS+= h_strncpy
+PROGS+= h_vsnprintf
+PROGS+= h_vsprintf
+
+.include "../Makefile.netbsd-tests"
+
+.include <bsd.test.mk>
Property changes on: trunk/lib/libc/tests/ssp/Makefile
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/stdio/Makefile
===================================================================
--- trunk/lib/libc/tests/stdio/Makefile (rev 0)
+++ trunk/lib/libc/tests/stdio/Makefile 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,47 @@
+# $MidnightBSD$
+# $FreeBSD: stable/10/lib/libc/tests/stdio/Makefile 313498 2017-02-10 01:13:12Z ngie $
+
+.include <bsd.own.mk>
+
+ATF_TESTS_C+= fdopen_test
+ATF_TESTS_C+= fmemopen2_test
+ATF_TESTS_C+= fopen2_test
+ATF_TESTS_C+= freopen_test
+ATF_TESTS_C+= getdelim_test
+ATF_TESTS_C+= mkostemp_test
+ATF_TESTS_C+= open_memstream2_test
+ATF_TESTS_C+= open_wmemstream_test
+ATF_TESTS_C+= perror_test
+ATF_TESTS_C+= print_positional_test
+ATF_TESTS_C+= printbasic_test
+ATF_TESTS_C+= printfloat_test
+ATF_TESTS_C+= scanfloat_test
+
+SRCS.fopen2_test= fopen_test.c
+
+NETBSD_ATF_TESTS_C= clearerr_test
+NETBSD_ATF_TESTS_C+= fflush_test
+NETBSD_ATF_TESTS_C+= fmemopen_test
+NETBSD_ATF_TESTS_C+= fopen_test
+NETBSD_ATF_TESTS_C+= fputc_test
+NETBSD_ATF_TESTS_C+= mktemp_test
+NETBSD_ATF_TESTS_C+= open_memstream_test
+NETBSD_ATF_TESTS_C+= popen_test
+NETBSD_ATF_TESTS_C+= printf_test
+NETBSD_ATF_TESTS_C+= scanf_test
+
+DPADD.printfloat_test+= ${LIBM}
+LDADD.printfloat_test+= -lm
+
+DPADD.scanfloat_test+= ${LIBM}
+LDADD.scanfloat_test+= -lm
+
+.if ${COMPILER_TYPE} == "gcc"
+# 90: use of assignment suppression and length modifier together in scanf format
+PROG_OVERRIDE_VARS+= NO_WFORMAT
+NO_WFORMAT.scanfloat_test=
+.endif
+
+.include "../Makefile.netbsd-tests"
+
+.include <bsd.test.mk>
Property changes on: trunk/lib/libc/tests/stdio/Makefile
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/stdio/fdopen_test.c
===================================================================
--- trunk/lib/libc/tests/stdio/fdopen_test.c (rev 0)
+++ trunk/lib/libc/tests/stdio/fdopen_test.c 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,226 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2014 Jilles Tjoelker
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/lib/libc/tests/stdio/fdopen_test.c 291840 2015-12-05 04:17:40Z ngie $");
+
+#include <errno.h>
+#include <fcntl.h>
+#include <paths.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <atf-c.h>
+
+static void
+runtest(const char *fname, int intmode, const char *strmode, bool success)
+{
+ FILE *fp;
+ int fd;
+
+ fd = open(fname, intmode);
+ ATF_REQUIRE_MSG(fd != -1,
+ "open(\"%s\", %#x) failed; errno=%d", fname, intmode, errno);
+
+ fp = fdopen(fd, strmode);
+ if (fp == NULL) {
+ close(fd);
+ ATF_REQUIRE_MSG(success == false,
+ "fdopen(open(\"%s\", %#x), \"%s\") succeeded unexpectedly",
+ fname, intmode, strmode);
+ return;
+ }
+ ATF_REQUIRE_MSG(success == true,
+ "fdopen(open(\"%s\", %#x), \"%s\") failed; errno=%d",
+ fname, intmode, strmode, errno);
+ fclose(fp);
+}
+
+ATF_TC_WITHOUT_HEAD(null__O_RDONLY__r_test);
+ATF_TC_BODY(null__O_RDONLY__r_test, tc)
+{
+
+ runtest(_PATH_DEVNULL, O_RDONLY, "r", true);
+}
+
+ATF_TC_WITHOUT_HEAD(null__O_WRONLY__r_test);
+ATF_TC_BODY(null__O_WRONLY__r_test, tc)
+{
+
+ runtest(_PATH_DEVNULL, O_WRONLY, "r", false);
+}
+
+ATF_TC_WITHOUT_HEAD(null__O_RDWR__r_test);
+ATF_TC_BODY(null__O_RDWR__r_test, tc)
+{
+
+ runtest(_PATH_DEVNULL, O_RDWR, "r", true);
+}
+
+ATF_TC_WITHOUT_HEAD(null__O_RDONLY__w_test);
+ATF_TC_BODY(null__O_RDONLY__w_test, tc)
+{
+
+ runtest(_PATH_DEVNULL, O_RDONLY, "w", false);
+}
+
+ATF_TC_WITHOUT_HEAD(null__O_WRONLY__w_test);
+ATF_TC_BODY(null__O_WRONLY__w_test, tc)
+{
+
+ runtest(_PATH_DEVNULL, O_WRONLY, "w", true);
+}
+
+ATF_TC_WITHOUT_HEAD(null__O_RDWR__w_test);
+ATF_TC_BODY(null__O_RDWR__w_test, tc)
+{
+
+ runtest(_PATH_DEVNULL, O_RDWR, "w", true);
+}
+
+ATF_TC_WITHOUT_HEAD(null__O_RDONLY__a_test);
+ATF_TC_BODY(null__O_RDONLY__a_test, tc)
+{
+
+ runtest(_PATH_DEVNULL, O_RDONLY, "a", false);
+}
+
+ATF_TC_WITHOUT_HEAD(null__O_WRONLY__a_test);
+ATF_TC_BODY(null__O_WRONLY__a_test, tc)
+{
+
+ runtest(_PATH_DEVNULL, O_WRONLY, "a", true);
+}
+
+ATF_TC_WITHOUT_HEAD(null__O_RDWR__test);
+ATF_TC_BODY(null__O_RDWR__test, tc)
+{
+
+ runtest(_PATH_DEVNULL, O_RDWR, "a", true);
+}
+
+ATF_TC_WITHOUT_HEAD(null__O_RDONLY__r_append);
+ATF_TC_BODY(null__O_RDONLY__r_append, tc)
+{
+
+ runtest(_PATH_DEVNULL, O_RDONLY, "r+", false);
+}
+
+ATF_TC_WITHOUT_HEAD(null__O_WRONLY__r_append);
+ATF_TC_BODY(null__O_WRONLY__r_append, tc)
+{
+
+ runtest(_PATH_DEVNULL, O_WRONLY, "r+", false);
+}
+
+ATF_TC_WITHOUT_HEAD(null__O_RDWR__r_append);
+ATF_TC_BODY(null__O_RDWR__r_append, tc)
+{
+
+ runtest(_PATH_DEVNULL, O_RDWR, "r+", true);
+}
+
+ATF_TC_WITHOUT_HEAD(null__O_RDONLY__w_append);
+ATF_TC_BODY(null__O_RDONLY__w_append, tc)
+{
+
+ runtest(_PATH_DEVNULL, O_RDONLY, "w+", false);
+}
+
+ATF_TC_WITHOUT_HEAD(null__O_WRONLY__w_append);
+ATF_TC_BODY(null__O_WRONLY__w_append, tc)
+{
+
+ runtest(_PATH_DEVNULL, O_WRONLY, "w+", false);
+}
+
+ATF_TC_WITHOUT_HEAD(null__O_RDWR__w_append);
+ATF_TC_BODY(null__O_RDWR__w_append, tc)
+{
+
+ runtest(_PATH_DEVNULL, O_RDWR, "w+", true);
+}
+
+ATF_TC_WITHOUT_HEAD(sh__O_EXEC__r);
+ATF_TC_BODY(sh__O_EXEC__r, tc)
+{
+
+ runtest("/bin/sh", O_EXEC, "r", false);
+}
+
+ATF_TC_WITHOUT_HEAD(sh__O_EXEC__w);
+ATF_TC_BODY(sh__O_EXEC__w, tc)
+{
+
+ runtest("/bin/sh", O_EXEC, "w", false);
+}
+
+ATF_TC_WITHOUT_HEAD(sh__O_EXEC__r_append);
+ATF_TC_BODY(sh__O_EXEC__r_append, tc)
+{
+
+ runtest("/bin/sh", O_EXEC, "r+", false);
+}
+
+ATF_TC_WITHOUT_HEAD(sh__O_EXEC__w_append);
+ATF_TC_BODY(sh__O_EXEC__w_append, tc)
+{
+
+ runtest("/bin/sh", O_EXEC, "w+", false);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, null__O_RDONLY__r_test);
+ ATF_TP_ADD_TC(tp, null__O_WRONLY__r_test);
+ ATF_TP_ADD_TC(tp, null__O_RDWR__r_test);
+ ATF_TP_ADD_TC(tp, null__O_RDONLY__w_test);
+ ATF_TP_ADD_TC(tp, null__O_WRONLY__w_test);
+ ATF_TP_ADD_TC(tp, null__O_RDWR__w_test);
+ ATF_TP_ADD_TC(tp, null__O_RDONLY__a_test);
+ ATF_TP_ADD_TC(tp, null__O_WRONLY__a_test);
+ ATF_TP_ADD_TC(tp, null__O_RDWR__test);
+ ATF_TP_ADD_TC(tp, null__O_RDONLY__r_append);
+ ATF_TP_ADD_TC(tp, null__O_WRONLY__r_append);
+ ATF_TP_ADD_TC(tp, null__O_RDWR__r_append);
+ ATF_TP_ADD_TC(tp, null__O_RDONLY__w_append);
+ ATF_TP_ADD_TC(tp, null__O_WRONLY__w_append);
+ ATF_TP_ADD_TC(tp, null__O_RDWR__w_append);
+ ATF_TP_ADD_TC(tp, sh__O_EXEC__r);
+ ATF_TP_ADD_TC(tp, sh__O_EXEC__w);
+ ATF_TP_ADD_TC(tp, sh__O_EXEC__r_append);
+ ATF_TP_ADD_TC(tp, sh__O_EXEC__w_append);
+
+ return (atf_no_error());
+}
+
+/*
+ vim:ts=8:cin:sw=8
+ */
Property changes on: trunk/lib/libc/tests/stdio/fdopen_test.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/stdio/fmemopen2_test.c
===================================================================
--- trunk/lib/libc/tests/stdio/fmemopen2_test.c (rev 0)
+++ trunk/lib/libc/tests/stdio/fmemopen2_test.c 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,288 @@
+/* $MidnightBSD$ */
+/*-
+Copyright (C) 2013 Pietro Cerutti <gahr at FreeBSD.org>
+
+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 AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGE.
+*/
+
+/*
+ * Test basic FILE * functions (fread, fwrite, fseek, fclose) against
+ * a FILE * retrieved using fmemopen()
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/lib/libc/tests/stdio/fmemopen2_test.c 299021 2016-05-04 00:30:36Z ngie $");
+
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <strings.h>
+
+#include <atf-c.h>
+
+ATF_TC_WITHOUT_HEAD(test_preexisting);
+ATF_TC_BODY(test_preexisting, tc)
+{
+ /* Use a pre-existing buffer. */
+ char buf[512];
+ char buf2[512];
+ char str[] = "Test writing some stuff";
+ char str2[] = "AAAAAAAAA";
+ char str3[] = "AAAA writing some stuff";
+ FILE *fp;
+ size_t nofw, nofr;
+ int rc;
+
+ /* Open a FILE * using fmemopen. */
+ fp = fmemopen(buf, sizeof(buf), "w");
+ ATF_REQUIRE(fp != NULL);
+
+ /* Write to the buffer. */
+ nofw = fwrite(str, 1, sizeof(str), fp);
+ ATF_REQUIRE(nofw == sizeof(str));
+
+ /* Close the FILE *. */
+ rc = fclose(fp);
+ ATF_REQUIRE(rc == 0);
+
+ /* Re-open the FILE * to read back the data. */
+ fp = fmemopen(buf, sizeof(buf), "r");
+ ATF_REQUIRE(fp != NULL);
+
+ /* Read from the buffer. */
+ bzero(buf2, sizeof(buf2));
+ nofr = fread(buf2, 1, sizeof(buf2), fp);
+ ATF_REQUIRE(nofr == sizeof(buf2));
+
+ /*
+ * Since a write on a FILE * retrieved by fmemopen
+ * will add a '\0' (if there's space), we can check
+ * the strings for equality.
+ */
+ ATF_REQUIRE(strcmp(str, buf2) == 0);
+
+ /* Close the FILE *. */
+ rc = fclose(fp);
+ ATF_REQUIRE(rc == 0);
+
+ /* Now open a FILE * on the first 4 bytes of the string. */
+ fp = fmemopen(str, 4, "w");
+ ATF_REQUIRE(fp != NULL);
+
+ /*
+ * Try to write more bytes than we shoud, we'll get a short count (4).
+ */
+ nofw = fwrite(str2, 1, sizeof(str2), fp);
+ ATF_REQUIRE(nofw == 4);
+
+ /* Close the FILE *. */
+ rc = fclose(fp);
+
+ /* Check that the string was not modified after the first 4 bytes. */
+ ATF_REQUIRE(strcmp(str, str3) == 0);
+}
+
+ATF_TC_WITHOUT_HEAD(test_autoalloc);
+ATF_TC_BODY(test_autoalloc, tc)
+{
+ /* Let fmemopen allocate the buffer. */
+ FILE *fp;
+ long pos;
+ size_t nofw, i;
+ int rc;
+
+ /* Open a FILE * using fmemopen. */
+ fp = fmemopen(NULL, 512, "w+");
+ ATF_REQUIRE(fp != NULL);
+
+ /* fill the buffer */
+ for (i = 0; i < 512; i++) {
+ nofw = fwrite("a", 1, 1, fp);
+ ATF_REQUIRE(nofw == 1);
+ }
+
+ /* Get the current position into the stream. */
+ pos = ftell(fp);
+ ATF_REQUIRE(pos == 512);
+
+ /* Try to write past the end, we should get a short object count (0) */
+ nofw = fwrite("a", 1, 1, fp);
+ ATF_REQUIRE(nofw == 0);
+
+ /* Close the FILE *. */
+ rc = fclose(fp);
+ ATF_REQUIRE(rc == 0);
+
+ /* Open a FILE * using a wrong mode */
+ fp = fmemopen(NULL, 512, "r");
+ ATF_REQUIRE(fp == NULL);
+
+ fp = fmemopen(NULL, 512, "w");
+ ATF_REQUIRE(fp == NULL);
+}
+
+ATF_TC_WITHOUT_HEAD(test_data_length);
+ATF_TC_BODY(test_data_length, tc)
+{
+ /*
+ * Here we test that a read operation doesn't go past the end of the
+ * data actually written, and that a SEEK_END seeks from the end of the
+ * data, not of the whole buffer.
+ */
+ FILE *fp;
+ char buf[512] = {'\0'};
+ char str[] = "Test data length. ";
+ char str2[] = "Do we have two sentences?";
+ char str3[sizeof(str) + sizeof(str2) -1];
+ long pos;
+ size_t nofw, nofr;
+ int rc;
+
+ /* Open a FILE * for updating our buffer. */
+ fp = fmemopen(buf, sizeof(buf), "w+");
+ ATF_REQUIRE(fp != NULL);
+
+ /* Write our string into the buffer. */
+ nofw = fwrite(str, 1, sizeof(str), fp);
+ ATF_REQUIRE(nofw == sizeof(str));
+
+ /* Now seek to the end and check that ftell gives us sizeof(str). */
+ rc = fseek(fp, 0, SEEK_END);
+ ATF_REQUIRE(rc == 0);
+ pos = ftell(fp);
+ ATF_REQUIRE(pos == sizeof(str));
+
+ /* Close the FILE *. */
+ rc = fclose(fp);
+ ATF_REQUIRE(rc == 0);
+
+ /* Reopen the buffer for appending. */
+ fp = fmemopen(buf, sizeof(buf), "a+");
+ ATF_REQUIRE(fp != NULL);
+
+ /* We should now be writing after the first string. */
+ nofw = fwrite(str2, 1, sizeof(str2), fp);
+ ATF_REQUIRE(nofw == sizeof(str2));
+
+ /* Rewind the FILE *. */
+ rc = fseek(fp, 0, SEEK_SET);
+ ATF_REQUIRE(rc == 0);
+
+ /* Make sure we're at the beginning. */
+ pos = ftell(fp);
+ ATF_REQUIRE(pos == 0);
+
+ /* Read the whole buffer. */
+ nofr = fread(str3, 1, sizeof(buf), fp);
+ ATF_REQUIRE(nofr == sizeof(str3));
+
+ /* Make sure the two strings are there. */
+ ATF_REQUIRE(strncmp(str3, str, sizeof(str) - 1) == 0);
+ ATF_REQUIRE(strncmp(str3 + sizeof(str) - 1, str2, sizeof(str2)) == 0);
+
+ /* Close the FILE *. */
+ rc = fclose(fp);
+ ATF_REQUIRE(rc == 0);
+}
+
+ATF_TC_WITHOUT_HEAD(test_binary);
+ATF_TC_BODY(test_binary, tc)
+{
+ /*
+ * Make sure that NULL bytes are never appended when opening a buffer
+ * in binary mode.
+ */
+
+ FILE *fp;
+ char buf[20];
+ char str[] = "Test";
+ size_t nofw;
+ int rc, i;
+
+ /* Pre-fill the buffer. */
+ memset(buf, 'A', sizeof(buf));
+
+ /* Open a FILE * in binary mode. */
+ fp = fmemopen(buf, sizeof(buf), "w+b");
+ ATF_REQUIRE(fp != NULL);
+
+ /* Write some data into it. */
+ nofw = fwrite(str, 1, strlen(str), fp);
+ ATF_REQUIRE(nofw == strlen(str));
+
+ /* Make sure that the buffer doesn't contain any NULL bytes. */
+ for (i = 0; i < sizeof(buf); i++)
+ ATF_REQUIRE(buf[i] != '\0');
+
+ /* Close the FILE *. */
+ rc = fclose(fp);
+ ATF_REQUIRE(rc == 0);
+}
+
+ATF_TC_WITHOUT_HEAD(test_append_binary_pos);
+ATF_TC_BODY(test_append_binary_pos, tc)
+{
+ /*
+ * For compatibility with other implementations (glibc), we set the
+ * position to 0 when opening an automatically allocated binary stream
+ * for appending.
+ */
+
+ FILE *fp;
+
+ fp = fmemopen(NULL, 16, "ab+");
+ ATF_REQUIRE(fp != NULL);
+ ATF_REQUIRE(ftell(fp) == 0L);
+ fclose(fp);
+
+ /* Make sure that a pre-allocated buffer behaves correctly. */
+ char buf[] = "Hello";
+ fp = fmemopen(buf, sizeof(buf), "ab+");
+ ATF_REQUIRE(fp != NULL);
+ ATF_REQUIRE(ftell(fp) == strlen(buf));
+ fclose(fp);
+}
+
+ATF_TC_WITHOUT_HEAD(test_size_0);
+ATF_TC_BODY(test_size_0, tc)
+{
+ /* POSIX mandates that we return EINVAL if size is 0. */
+
+ FILE *fp;
+
+ fp = fmemopen(NULL, 0, "r+");
+ ATF_REQUIRE(fp == NULL);
+ ATF_REQUIRE(errno == EINVAL);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, test_autoalloc);
+ ATF_TP_ADD_TC(tp, test_preexisting);
+ ATF_TP_ADD_TC(tp, test_data_length);
+ ATF_TP_ADD_TC(tp, test_binary);
+ ATF_TP_ADD_TC(tp, test_append_binary_pos);
+ ATF_TP_ADD_TC(tp, test_size_0);
+
+ return (atf_no_error());
+}
Property changes on: trunk/lib/libc/tests/stdio/fmemopen2_test.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/stdio/fopen_test.c
===================================================================
--- trunk/lib/libc/tests/stdio/fopen_test.c (rev 0)
+++ trunk/lib/libc/tests/stdio/fopen_test.c 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,206 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2013 Jilles Tjoelker
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/lib/libc/tests/stdio/fopen_test.c 291840 2015-12-05 04:17:40Z ngie $");
+
+#include <fcntl.h>
+#include <paths.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <atf-c.h>
+
+/*
+ * O_ACCMODE is currently defined incorrectly. This is what it should be.
+ * Various code depends on the incorrect value.
+ */
+#define CORRECT_O_ACCMODE (O_ACCMODE | O_EXEC)
+
+static void
+runtest(const char *fname, const char *mode)
+{
+ FILE *fp;
+ int exp_fget_ret, fget_ret, fd, flags, wantedflags;
+
+ fp = fopen(fname, mode);
+ ATF_REQUIRE_MSG(fp != NULL,
+ "fopen(\"%s\", \"%s\") failed", fname, mode);
+ fd = fileno(fp);
+ ATF_REQUIRE_MSG(fd >= 0, "fileno() failed for fopen");
+ exp_fget_ret = strchr(mode, 'e') != NULL ? FD_CLOEXEC : 0;
+ ATF_REQUIRE_MSG((fget_ret = fcntl(fd, F_GETFD)) == exp_fget_ret,
+ "fcntl(.., F_GETFD) didn't FD_CLOEXEC as expected %d != %d",
+ exp_fget_ret, fget_ret);
+ flags = fcntl(fd, F_GETFL);
+ if (strchr(mode, '+'))
+ wantedflags = O_RDWR | (*mode == 'a' ? O_APPEND : 0);
+ else if (*mode == 'r')
+ wantedflags = O_RDONLY;
+ else if (*mode == 'w')
+ wantedflags = O_WRONLY;
+ else if (*mode == 'a')
+ wantedflags = O_WRONLY | O_APPEND;
+ else
+ wantedflags = -1;
+ fclose(fp);
+ if (wantedflags == -1)
+ atf_tc_fail("unrecognized mode: %s", mode);
+ else if ((flags & (CORRECT_O_ACCMODE | O_APPEND)) != wantedflags)
+ atf_tc_fail("incorrect access mode: %s", mode);
+}
+
+ATF_TC_WITHOUT_HEAD(fopen_r_test);
+ATF_TC_BODY(fopen_r_test, tc)
+{
+
+ runtest(_PATH_DEVNULL, "r");
+}
+
+ATF_TC_WITHOUT_HEAD(fopen_r_append_test);
+ATF_TC_BODY(fopen_r_append_test, tc)
+{
+
+ runtest(_PATH_DEVNULL, "r+");
+}
+
+ATF_TC_WITHOUT_HEAD(fopen_w_test);
+ATF_TC_BODY(fopen_w_test, tc)
+{
+
+ runtest(_PATH_DEVNULL, "w");
+}
+
+ATF_TC_WITHOUT_HEAD(fopen_w_append_test);
+ATF_TC_BODY(fopen_w_append_test, tc)
+{
+
+ runtest(_PATH_DEVNULL, "w+");
+}
+
+ATF_TC_WITHOUT_HEAD(fopen_a_test);
+ATF_TC_BODY(fopen_a_test, tc)
+{
+
+ runtest(_PATH_DEVNULL, "a");
+}
+
+ATF_TC_WITHOUT_HEAD(fopen_a_append_test);
+ATF_TC_BODY(fopen_a_append_test, tc)
+{
+
+ runtest(_PATH_DEVNULL, "a+");
+}
+
+ATF_TC_WITHOUT_HEAD(fopen_re_test);
+ATF_TC_BODY(fopen_re_test, tc)
+{
+
+ runtest(_PATH_DEVNULL, "re");
+}
+
+ATF_TC_WITHOUT_HEAD(fopen_r_append_e_test);
+ATF_TC_BODY(fopen_r_append_e_test, tc)
+{
+
+ runtest(_PATH_DEVNULL, "r+e");
+}
+
+ATF_TC_WITHOUT_HEAD(fopen_we_test);
+ATF_TC_BODY(fopen_we_test, tc)
+{
+
+ runtest(_PATH_DEVNULL, "we");
+}
+
+ATF_TC_WITHOUT_HEAD(fopen_w_append_e_test);
+ATF_TC_BODY(fopen_w_append_e_test, tc)
+{
+
+ runtest(_PATH_DEVNULL, "w+e");
+}
+
+ATF_TC_WITHOUT_HEAD(fopen_ae_test);
+ATF_TC_BODY(fopen_ae_test, tc)
+{
+
+ runtest(_PATH_DEVNULL, "ae");
+}
+
+ATF_TC_WITHOUT_HEAD(fopen_a_append_e_test);
+ATF_TC_BODY(fopen_a_append_e_test, tc)
+{
+
+ runtest(_PATH_DEVNULL, "a+e");
+}
+
+ATF_TC_WITHOUT_HEAD(fopen_re_append_test);
+ATF_TC_BODY(fopen_re_append_test, tc)
+{
+
+ runtest(_PATH_DEVNULL, "re+");
+}
+
+ATF_TC_WITHOUT_HEAD(fopen_we_append_test);
+ATF_TC_BODY(fopen_we_append_test, tc)
+{
+
+ runtest(_PATH_DEVNULL, "we+");
+}
+
+ATF_TC_WITHOUT_HEAD(fopen_ae_append_test);
+ATF_TC_BODY(fopen_ae_append_test, tc)
+{
+
+ runtest(_PATH_DEVNULL, "ae+");
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, fopen_r_test);
+ ATF_TP_ADD_TC(tp, fopen_r_append_test);
+ ATF_TP_ADD_TC(tp, fopen_w_test);
+ ATF_TP_ADD_TC(tp, fopen_w_append_test);
+ ATF_TP_ADD_TC(tp, fopen_a_test);
+ ATF_TP_ADD_TC(tp, fopen_a_append_test);
+ ATF_TP_ADD_TC(tp, fopen_re_test);
+ ATF_TP_ADD_TC(tp, fopen_r_append_e_test);
+ ATF_TP_ADD_TC(tp, fopen_we_test);
+ ATF_TP_ADD_TC(tp, fopen_w_append_e_test);
+ ATF_TP_ADD_TC(tp, fopen_ae_test);
+ ATF_TP_ADD_TC(tp, fopen_a_append_e_test);
+ ATF_TP_ADD_TC(tp, fopen_re_append_test);
+ ATF_TP_ADD_TC(tp, fopen_we_append_test);
+ ATF_TP_ADD_TC(tp, fopen_ae_append_test);
+
+ return (atf_no_error());
+}
+
+/*
+ vim:ts=8:cin:sw=8
+ */
Property changes on: trunk/lib/libc/tests/stdio/fopen_test.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/stdio/freopen_test.c
===================================================================
--- trunk/lib/libc/tests/stdio/freopen_test.c (rev 0)
+++ trunk/lib/libc/tests/stdio/freopen_test.c 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,224 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2014 Jilles Tjoelker
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/lib/libc/tests/stdio/freopen_test.c 299021 2016-05-04 00:30:36Z ngie $");
+
+#include <errno.h>
+#include <paths.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <atf-c.h>
+
+static void
+runtest(const char *fname1, const char *mode1, const char *fname2,
+ const char *mode2, bool success)
+{
+ FILE *fp1, *fp2;
+ const char *fname2_print;
+
+ fname2_print = fname2 != NULL ? fname2 : "<NULL>";
+ fp1 = fopen(fname1, mode1);
+ ATF_REQUIRE_MSG(fp1 != NULL,
+ "fopen(\"%s\", \"%s\") failed; errno=%d", fname1, mode1, errno);
+ fp2 = freopen(fname2, mode2, fp1);
+ if (fp2 == NULL) {
+ ATF_REQUIRE_MSG(success == false,
+ "freopen(\"%s\", \"%s\", fopen(\"%s\", \"%s\")) succeeded "
+ "unexpectedly", fname2_print, mode2, fname1, mode1);
+ return;
+ }
+ ATF_REQUIRE_MSG(success == true,
+ "freopen(\"%s\", \"%s\", fopen(\"%s\", \"%s\")) failed: %d",
+ fname2_print, mode2, fname1, mode1, errno);
+ fclose(fp2);
+}
+
+ATF_TC_WITHOUT_HEAD(null__r__r__test);
+ATF_TC_BODY(null__r__r__test, tc)
+{
+
+ runtest(_PATH_DEVNULL, "r", NULL, "r", true);
+}
+
+ATF_TC_WITHOUT_HEAD(null__w__r__test);
+ATF_TC_BODY(null__w__r__test, tc)
+{
+
+ runtest(_PATH_DEVNULL, "w", NULL, "r", false);
+}
+
+ATF_TC_WITHOUT_HEAD(null__r_append__r__test);
+ATF_TC_BODY(null__r_append__r__test, tc)
+{
+
+ runtest(_PATH_DEVNULL, "r+", NULL, "r", true);
+}
+
+ATF_TC_WITHOUT_HEAD(null__r__w__test);
+ATF_TC_BODY(null__r__w__test, tc)
+{
+
+ runtest(_PATH_DEVNULL, "r", NULL, "w", false);
+}
+
+ATF_TC_WITHOUT_HEAD(null__w__w__test);
+ATF_TC_BODY(null__w__w__test, tc)
+{
+
+ runtest(_PATH_DEVNULL, "w", NULL, "w", true);
+}
+
+ATF_TC_WITHOUT_HEAD(null__r_append__w__test);
+ATF_TC_BODY(null__r_append__w__test, tc)
+{
+
+ runtest(_PATH_DEVNULL, "r+", NULL, "w", true);
+}
+
+ATF_TC_WITHOUT_HEAD(null__r__a__test);
+ATF_TC_BODY(null__r__a__test, tc)
+{
+
+ runtest(_PATH_DEVNULL, "r", NULL, "a", false);
+}
+
+ATF_TC_WITHOUT_HEAD(null__w__a__test);
+ATF_TC_BODY(null__w__a__test, tc)
+{
+
+ runtest(_PATH_DEVNULL, "w", NULL, "a", true);
+}
+
+ATF_TC_WITHOUT_HEAD(null__r_append__a__test);
+ATF_TC_BODY(null__r_append__a__test, tc)
+{
+
+ runtest(_PATH_DEVNULL, "r+", NULL, "a", true);
+}
+
+ATF_TC_WITHOUT_HEAD(null__r__r_append__test);
+ATF_TC_BODY(null__r__r_append__test, tc)
+{
+
+ runtest(_PATH_DEVNULL, "r", NULL, "r+", false);
+}
+
+ATF_TC_WITHOUT_HEAD(null__w__r_append__test);
+ATF_TC_BODY(null__w__r_append__test, tc)
+{
+
+ runtest(_PATH_DEVNULL, "w", NULL, "r+", false);
+}
+
+ATF_TC_WITHOUT_HEAD(null__r_append__r_append__test);
+ATF_TC_BODY(null__r_append__r_append__test, tc)
+{
+
+ runtest(_PATH_DEVNULL, "r+", NULL, "r+", true);
+}
+
+ATF_TC_WITHOUT_HEAD(null__r__w_append__test);
+ATF_TC_BODY(null__r__w_append__test, tc)
+{
+
+ runtest(_PATH_DEVNULL, "r", NULL, "w+", false);
+}
+
+ATF_TC_WITHOUT_HEAD(null__w__w_append__test);
+ATF_TC_BODY(null__w__w_append__test, tc)
+{
+
+ runtest(_PATH_DEVNULL, "w", NULL, "w+", false);
+}
+
+ATF_TC_WITHOUT_HEAD(null__r_append__w_append__test);
+ATF_TC_BODY(null__r_append__w_append__test, tc)
+{
+
+ runtest(_PATH_DEVNULL, "r+", NULL, "w+", true);
+}
+
+ATF_TC_WITHOUT_HEAD(sh__r__r__test);
+ATF_TC_BODY(sh__r__r__test, tc)
+{
+
+ runtest("/bin/sh", "r", NULL, "r", true);
+}
+
+ATF_TC_WITHOUT_HEAD(sh__sh__r__r__test);
+ATF_TC_BODY(sh__sh__r__r__test, tc)
+{
+
+ runtest("/bin/sh", "r", "/bin/sh", "r", true);
+}
+
+ATF_TC_WITHOUT_HEAD(sh__null__r__r__test);
+ATF_TC_BODY(sh__null__r__r__test, tc)
+{
+
+ runtest("/bin/sh", "r", _PATH_DEVNULL, "r", true);
+}
+
+ATF_TC_WITHOUT_HEAD(sh__null__r__w__test);
+ATF_TC_BODY(sh__null__r__w__test, tc)
+{
+
+ runtest("/bin/sh", "r", _PATH_DEVNULL, "w", true);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, null__r__r__test);
+ ATF_TP_ADD_TC(tp, null__w__r__test);
+ ATF_TP_ADD_TC(tp, null__r_append__r__test);
+ ATF_TP_ADD_TC(tp, null__r__w__test);
+ ATF_TP_ADD_TC(tp, null__w__w__test);
+ ATF_TP_ADD_TC(tp, null__r_append__w__test);
+ ATF_TP_ADD_TC(tp, null__r__a__test);
+ ATF_TP_ADD_TC(tp, null__w__a__test);
+ ATF_TP_ADD_TC(tp, null__r_append__a__test);
+ ATF_TP_ADD_TC(tp, null__r__r_append__test);
+ ATF_TP_ADD_TC(tp, null__w__r_append__test);
+ ATF_TP_ADD_TC(tp, null__r_append__r_append__test);
+ ATF_TP_ADD_TC(tp, null__r__w_append__test);
+ ATF_TP_ADD_TC(tp, null__w__w_append__test);
+ ATF_TP_ADD_TC(tp, null__r_append__w_append__test);
+ ATF_TP_ADD_TC(tp, sh__r__r__test);
+ ATF_TP_ADD_TC(tp, sh__sh__r__r__test);
+ ATF_TP_ADD_TC(tp, sh__null__r__r__test);
+ ATF_TP_ADD_TC(tp, sh__null__r__w__test);
+
+ return (atf_no_error());
+}
+
+/*
+ vim:ts=8:cin:sw=8
+ */
Property changes on: trunk/lib/libc/tests/stdio/freopen_test.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/stdio/getdelim_test.c
===================================================================
--- trunk/lib/libc/tests/stdio/getdelim_test.c (rev 0)
+++ trunk/lib/libc/tests/stdio/getdelim_test.c 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,238 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2009 David Schultz <das at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/lib/libc/tests/stdio/getdelim_test.c 292152 2015-12-13 04:29:09Z ngie $");
+
+#define _WITH_GETLINE
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <atf-c.h>
+
+#define CHUNK_MAX 10
+
+/* The assertions depend on this string. */
+char apothegm[] = "All work and no play\0 makes Jack a dull boy.\n";
+
+/*
+ * This is a neurotic reader function designed to give getdelim() a
+ * hard time. It reads through the string `apothegm' and returns a
+ * random number of bytes up to the requested length.
+ */
+static int
+_reader(void *cookie, char *buf, int len)
+{
+ size_t *offp = cookie;
+ size_t r;
+
+ r = random() % CHUNK_MAX + 1;
+ if (len > r)
+ len = r;
+ if (len > sizeof(apothegm) - *offp)
+ len = sizeof(apothegm) - *offp;
+ memcpy(buf, apothegm + *offp, len);
+ *offp += len;
+ return (len);
+}
+
+static FILE *
+mkfilebuf(void)
+{
+ size_t *offp;
+
+ offp = malloc(sizeof(*offp)); /* XXX leak */
+ *offp = 0;
+ return (fropen(offp, _reader));
+}
+
+ATF_TC_WITHOUT_HEAD(getline_basic);
+ATF_TC_BODY(getline_basic, tc)
+{
+ FILE *fp;
+ char *line;
+ size_t linecap;
+ int i;
+
+ srandom(0);
+
+ /*
+ * Test multiple times with different buffer sizes
+ * and different _reader() return values.
+ */
+ errno = 0;
+ for (i = 0; i < 8; i++) {
+ fp = mkfilebuf();
+ linecap = i;
+ line = malloc(i);
+ /* First line: the full apothegm */
+ ATF_REQUIRE(getline(&line, &linecap, fp) == sizeof(apothegm) - 1);
+ ATF_REQUIRE(memcmp(line, apothegm, sizeof(apothegm)) == 0);
+ ATF_REQUIRE(linecap >= sizeof(apothegm));
+ /* Second line: the NUL terminator following the newline */
+ ATF_REQUIRE(getline(&line, &linecap, fp) == 1);
+ ATF_REQUIRE(line[0] == '\0' && line[1] == '\0');
+ /* Third line: EOF */
+ line[0] = 'X';
+ ATF_REQUIRE(getline(&line, &linecap, fp) == -1);
+ ATF_REQUIRE(line[0] == '\0');
+ free(line);
+ line = NULL;
+ ATF_REQUIRE(feof(fp));
+ ATF_REQUIRE(!ferror(fp));
+ fclose(fp);
+ }
+ ATF_REQUIRE(errno == 0);
+}
+
+ATF_TC_WITHOUT_HEAD(stream_error);
+ATF_TC_BODY(stream_error, tc)
+{
+ char *line;
+ size_t linecap;
+
+ /* Make sure read errors are handled properly. */
+ line = NULL;
+ linecap = 0;
+ errno = 0;
+ ATF_REQUIRE(getline(&line, &linecap, stdout) == -1);
+ ATF_REQUIRE(errno == EBADF);
+ errno = 0;
+ ATF_REQUIRE(getdelim(&line, &linecap, 'X', stdout) == -1);
+ ATF_REQUIRE(errno == EBADF);
+ ATF_REQUIRE(ferror(stdout));
+}
+
+ATF_TC_WITHOUT_HEAD(invalid_params);
+ATF_TC_BODY(invalid_params, tc)
+{
+ FILE *fp;
+ char *line;
+ size_t linecap;
+
+ /* Make sure NULL linep or linecapp pointers are handled. */
+ fp = mkfilebuf();
+ ATF_REQUIRE(getline(NULL, &linecap, fp) == -1);
+ ATF_REQUIRE(errno == EINVAL);
+ ATF_REQUIRE(getline(&line, NULL, fp) == -1);
+ ATF_REQUIRE(errno == EINVAL);
+ ATF_REQUIRE(ferror(fp));
+ fclose(fp);
+}
+
+ATF_TC_WITHOUT_HEAD(eof);
+ATF_TC_BODY(eof, tc)
+{
+ FILE *fp;
+ char *line;
+ size_t linecap;
+
+ /* Make sure getline() allocates memory as needed if fp is at EOF. */
+ errno = 0;
+ fp = mkfilebuf();
+ while (!feof(fp)) /* advance to EOF; can't fseek this stream */
+ getc(fp);
+ line = NULL;
+ linecap = 0;
+ printf("getline\n");
+ ATF_REQUIRE(getline(&line, &linecap, fp) == -1);
+ ATF_REQUIRE(line[0] == '\0');
+ ATF_REQUIRE(linecap > 0);
+ ATF_REQUIRE(errno == 0);
+ printf("feof\n");
+ errno = 0;
+ ATF_REQUIRE(feof(fp));
+ ATF_REQUIRE(!ferror(fp));
+ fclose(fp);
+}
+
+ATF_TC_WITHOUT_HEAD(nul);
+ATF_TC_BODY(nul, tc)
+{
+ FILE *fp;
+ char *line;
+ size_t linecap, n;
+
+ errno = 0;
+ line = NULL;
+ linecap = 0;
+ /* Make sure a NUL delimiter works. */
+ fp = mkfilebuf();
+ n = strlen(apothegm);
+ printf("getdelim\n");
+ ATF_REQUIRE(getdelim(&line, &linecap, '\0', fp) == n + 1);
+ ATF_REQUIRE(strcmp(line, apothegm) == 0);
+ ATF_REQUIRE(line[n + 1] == '\0');
+ ATF_REQUIRE(linecap > n + 1);
+ n = strlen(apothegm + n + 1);
+ printf("getdelim 2\n");
+ ATF_REQUIRE(getdelim(&line, &linecap, '\0', fp) == n + 1);
+ ATF_REQUIRE(line[n + 1] == '\0');
+ ATF_REQUIRE(linecap > n + 1);
+ ATF_REQUIRE(errno == 0);
+ ATF_REQUIRE(!ferror(fp));
+ fclose(fp);
+}
+
+ATF_TC_WITHOUT_HEAD(empty_NULL_buffer);
+ATF_TC_BODY(empty_NULL_buffer, tc)
+{
+ FILE *fp;
+ char *line;
+ size_t linecap;
+
+ /* Make sure NULL *linep and zero *linecapp are handled. */
+ fp = mkfilebuf();
+ line = NULL;
+ linecap = 42;
+ ATF_REQUIRE(getline(&line, &linecap, fp) == sizeof(apothegm) - 1);
+ ATF_REQUIRE(memcmp(line, apothegm, sizeof(apothegm)) == 0);
+ fp = mkfilebuf();
+ free(line);
+ line = malloc(100);
+ linecap = 0;
+ ATF_REQUIRE(getline(&line, &linecap, fp) == sizeof(apothegm) - 1);
+ ATF_REQUIRE(memcmp(line, apothegm, sizeof(apothegm)) == 0);
+ free(line);
+ ATF_REQUIRE(!ferror(fp));
+ fclose(fp);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, getline_basic);
+ ATF_TP_ADD_TC(tp, stream_error);
+ ATF_TP_ADD_TC(tp, eof);
+ ATF_TP_ADD_TC(tp, invalid_params);
+ ATF_TP_ADD_TC(tp, nul);
+ ATF_TP_ADD_TC(tp, empty_NULL_buffer);
+
+ return (atf_no_error());
+}
Property changes on: trunk/lib/libc/tests/stdio/getdelim_test.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/stdio/mkostemp_test.c
===================================================================
--- trunk/lib/libc/tests/stdio/mkostemp_test.c (rev 0)
+++ trunk/lib/libc/tests/stdio/mkostemp_test.c 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,186 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2013 Jilles Tjoelker
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Test program for mkostemp().
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/lib/libc/tests/stdio/mkostemp_test.c 291840 2015-12-05 04:17:40Z ngie $");
+
+#include <sys/stat.h>
+
+#include <errno.h>
+#include <fcntl.h>
+#include <paths.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <atf-c.h>
+
+static const char template[] = "mkostemp.XXXXXXXX";
+static int testnum;
+
+#define MISCFLAGS (O_APPEND | O_DIRECT | O_SHLOCK | O_EXLOCK | O_SYNC)
+
+static void
+test_one(int oflags)
+{
+ char tmpf[sizeof(template)];
+ struct stat st1, st2;
+ int fd;
+
+ memcpy(tmpf, template, sizeof(tmpf));
+ fd = mkostemp(tmpf, oflags);
+ if (fd < 0) {
+ printf("not ok %d - oflags=%#x "
+ "mkostemp() reported failure: %s\n",
+ testnum++, oflags, strerror(errno));
+ return;
+ }
+ if (memcmp(tmpf, template, sizeof(tmpf) - 8 - 1) != 0) {
+ printf("not ok %d - oflags=%#x "
+ "returned pathname does not match template: %s\n",
+ testnum++, oflags, tmpf);
+ return;
+ }
+ do {
+ if (fcntl(fd, F_GETFD) !=
+ (oflags & O_CLOEXEC ? FD_CLOEXEC : 0)) {
+ printf("not ok %d - oflags=%#x "
+ "close-on-exec flag incorrect\n",
+ testnum++, oflags);
+ break;
+ }
+ if ((fcntl(fd, F_GETFL) & MISCFLAGS) != (oflags & MISCFLAGS)) {
+ printf("not ok %d - oflags=%#x "
+ "open flags incorrect\n",
+ testnum++, oflags);
+ break;
+ }
+ if (stat(tmpf, &st1) == -1) {
+ printf("not ok %d - oflags=%#x "
+ "cannot stat returned pathname %s: %s\n",
+ testnum++, oflags, tmpf, strerror(errno));
+ break;
+ }
+ if (fstat(fd, &st2) == -1) {
+ printf("not ok %d - oflags=%#x "
+ "cannot fstat returned fd %d: %s\n",
+ testnum++, oflags, fd, strerror(errno));
+ break;
+ }
+ if (!S_ISREG(st1.st_mode) || (st1.st_mode & 0777) != 0600 ||
+ st1.st_nlink != 1 || st1.st_size != 0) {
+ printf("not ok %d - oflags=%#x "
+ "named file attributes incorrect\n",
+ testnum++, oflags);
+ break;
+ }
+ if (!S_ISREG(st2.st_mode) || (st2.st_mode & 0777) != 0600 ||
+ st2.st_nlink != 1 || st2.st_size != 0) {
+ printf("not ok %d - oflags=%#x "
+ "opened file attributes incorrect\n",
+ testnum++, oflags);
+ break;
+ }
+ if (st1.st_dev != st2.st_dev || st1.st_ino != st2.st_ino) {
+ printf("not ok %d - oflags=%#x "
+ "named and opened file do not match\n",
+ testnum++, oflags);
+ break;
+ }
+ (void)unlink(tmpf);
+ if (fstat(fd, &st2) == -1)
+ printf("not ok %d - oflags=%#x "
+ "cannot fstat returned fd %d again: %s\n",
+ testnum++, oflags, fd, strerror(errno));
+ else if (st2.st_nlink != 0)
+ printf("not ok %d - oflags=%#x "
+ "st_nlink is not 0 after unlink\n",
+ testnum++, oflags);
+ else
+ printf("ok %d - oflags=%#x\n", testnum++, oflags);
+ (void)close(fd);
+ return;
+ } while (0);
+ (void)close(fd);
+ (void)unlink(tmpf);
+}
+
+ATF_TC_WITHOUT_HEAD(zero);
+ATF_TC_BODY(zero, tc)
+{
+
+ test_one(0);
+}
+
+ATF_TC_WITHOUT_HEAD(O_CLOEXEC);
+ATF_TC_BODY(O_CLOEXEC, tc)
+{
+
+ test_one(O_CLOEXEC);
+}
+
+ATF_TC_WITHOUT_HEAD(O_APPEND);
+ATF_TC_BODY(O_APPEND, tc)
+{
+
+ test_one(O_APPEND);
+}
+
+ATF_TC_WITHOUT_HEAD(O_APPEND__O_CLOEXEC);
+ATF_TC_BODY(O_APPEND__O_CLOEXEC, tc)
+{
+
+ test_one(O_APPEND|O_CLOEXEC);
+}
+
+ATF_TC_WITHOUT_HEAD(bad_flags);
+ATF_TC_BODY(bad_flags, tc)
+{
+
+ char tmpf[sizeof(template)];
+
+ memcpy(tmpf, template, sizeof(tmpf));
+ ATF_REQUIRE_MSG(mkostemp(tmpf, O_CREAT) == -1,
+ "mkostemp(O_CREAT) succeeded unexpectedly");
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, zero);
+ ATF_TP_ADD_TC(tp, O_CLOEXEC);
+ ATF_TP_ADD_TC(tp, O_APPEND);
+ ATF_TP_ADD_TC(tp, O_APPEND__O_CLOEXEC);
+ ATF_TP_ADD_TC(tp, bad_flags);
+
+ return (atf_no_error());
+}
Property changes on: trunk/lib/libc/tests/stdio/mkostemp_test.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/stdio/open_memstream2_test.c
===================================================================
--- trunk/lib/libc/tests/stdio/open_memstream2_test.c (rev 0)
+++ trunk/lib/libc/tests/stdio/open_memstream2_test.c 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,202 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2013 Hudson River Trading LLC
+ * Written by: John H. Baldwin <jhb at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/lib/libc/tests/stdio/open_memstream2_test.c 313498 2017-02-10 01:13:12Z ngie $");
+
+#include <err.h>
+#include <errno.h>
+#include <limits.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <wchar.h>
+
+#include <atf-c.h>
+
+static char *buf;
+static size_t len;
+
+static void
+assert_stream(const char *contents)
+{
+ if (strlen(contents) != len)
+ printf("bad length %zd for \"%s\"\n", len, contents);
+ else if (strncmp(buf, contents, strlen(contents)) != 0)
+ printf("bad buffer \"%s\" for \"%s\"\n", buf, contents);
+}
+
+ATF_TC_WITHOUT_HEAD(open_group_test);
+ATF_TC_BODY(open_group_test, tc)
+{
+ FILE *fp;
+ off_t eob;
+
+ fp = open_memstream(&buf, &len);
+ ATF_REQUIRE_MSG(fp != NULL, "open_memstream failed");
+
+ fprintf(fp, "hello my world");
+ fflush(fp);
+ assert_stream("hello my world");
+ eob = ftello(fp);
+ rewind(fp);
+ fprintf(fp, "good-bye");
+ fseeko(fp, eob, SEEK_SET);
+ fclose(fp);
+ assert_stream("good-bye world");
+ free(buf);
+}
+
+ATF_TC_WITHOUT_HEAD(simple_tests);
+ATF_TC_BODY(simple_tests, tc)
+{
+ static const char zerobuf[] =
+ { 'f', 'o', 'o', 0, 0, 0, 0, 'b', 'a', 'r', 0 };
+ char c;
+ FILE *fp;
+
+ fp = open_memstream(&buf, NULL);
+ ATF_REQUIRE_MSG(fp == NULL, "open_memstream did not fail");
+ ATF_REQUIRE_MSG(errno == EINVAL,
+ "open_memstream didn't fail with EINVAL");
+ fp = open_memstream(NULL, &len);
+ ATF_REQUIRE_MSG(fp == NULL, "open_memstream did not fail");
+ ATF_REQUIRE_MSG(errno == EINVAL,
+ "open_memstream didn't fail with EINVAL");
+ fp = open_memstream(&buf, &len);
+ ATF_REQUIRE_MSG(fp != NULL, "open_memstream failed; errno=%d", errno);
+ fflush(fp);
+ assert_stream("");
+ if (fwide(fp, 0) >= 0)
+ printf("stream is not byte-oriented\n");
+
+ fprintf(fp, "fo");
+ fflush(fp);
+ assert_stream("fo");
+ fputc('o', fp);
+ fflush(fp);
+ assert_stream("foo");
+ rewind(fp);
+ fflush(fp);
+ assert_stream("");
+ fseek(fp, 0, SEEK_END);
+ fflush(fp);
+ assert_stream("foo");
+
+ /*
+ * Test seeking out past the current end. Should zero-fill the
+ * intermediate area.
+ */
+ fseek(fp, 4, SEEK_END);
+ fprintf(fp, "bar");
+ fflush(fp);
+
+ /*
+ * Can't use assert_stream() here since this should contain
+ * embedded null characters.
+ */
+ if (len != 10)
+ printf("bad length %zd for zero-fill test\n", len);
+ else if (memcmp(buf, zerobuf, sizeof(zerobuf)) != 0)
+ printf("bad buffer for zero-fill test\n");
+
+ fseek(fp, 3, SEEK_SET);
+ fprintf(fp, " in ");
+ fflush(fp);
+ assert_stream("foo in ");
+ fseek(fp, 0, SEEK_END);
+ fflush(fp);
+ assert_stream("foo in bar");
+
+ rewind(fp);
+ if (fread(&c, sizeof(c), 1, fp) != 0)
+ printf("fread did not fail\n");
+ else if (!ferror(fp))
+ printf("error indicator not set after fread\n");
+ else
+ clearerr(fp);
+
+ fseek(fp, 4, SEEK_SET);
+ fprintf(fp, "bar baz");
+ fclose(fp);
+ assert_stream("foo bar baz");
+ free(buf);
+}
+
+ATF_TC_WITHOUT_HEAD(seek_tests);
+ATF_TC_BODY(seek_tests, tc)
+{
+ FILE *fp;
+
+ fp = open_memstream(&buf, &len);
+ ATF_REQUIRE_MSG(fp != NULL, "open_memstream failed: %d", errno);
+
+#define SEEK_FAIL(offset, whence, error) do { \
+ errno = 0; \
+ ATF_REQUIRE_MSG(fseeko(fp, (offset), (whence)) != 0, \
+ "fseeko(%s, %s) did not fail, set pos to %jd\n", \
+ __STRING(offset), __STRING(whence), \
+ (intmax_t)ftello(fp)); \
+ ATF_REQUIRE_MSG(errno == (error), \
+ "fseeko(%s, %s) failed with %d rather than %s\n", \
+ __STRING(offset), __STRING(whence), errno, \
+ __STRING(error)); \
+} while (0)
+
+#define SEEK_OK(offset, whence, result) do { \
+ ATF_REQUIRE_MSG(fseeko(fp, (offset), (whence)) == 0, \
+ "fseeko(%s, %s) failed: %s", \
+ __STRING(offset), __STRING(whence), strerror(errno)); \
+ ATF_REQUIRE_MSG(ftello(fp) == (result), \
+ "fseeko(%s, %s) seeked to %jd rather than %s\n", \
+ __STRING(offset), __STRING(whence), \
+ (intmax_t)ftello(fp), __STRING(result)); \
+} while (0)
+
+ SEEK_FAIL(-1, SEEK_SET, EINVAL);
+ SEEK_FAIL(-1, SEEK_CUR, EINVAL);
+ SEEK_FAIL(-1, SEEK_END, EINVAL);
+ fprintf(fp, "foo");
+ SEEK_OK(-1, SEEK_CUR, 2);
+ SEEK_OK(0, SEEK_SET, 0);
+ SEEK_OK(-1, SEEK_END, 2);
+ SEEK_OK(OFF_MAX - 1, SEEK_SET, OFF_MAX - 1);
+ SEEK_FAIL(2, SEEK_CUR, EOVERFLOW);
+ fclose(fp);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, open_group_test);
+ ATF_TP_ADD_TC(tp, simple_tests);
+ ATF_TP_ADD_TC(tp, seek_tests);
+
+ return (atf_no_error());
+}
Property changes on: trunk/lib/libc/tests/stdio/open_memstream2_test.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/stdio/open_wmemstream_test.c
===================================================================
--- trunk/lib/libc/tests/stdio/open_wmemstream_test.c (rev 0)
+++ trunk/lib/libc/tests/stdio/open_wmemstream_test.c 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,202 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2013 Hudson River Trading LLC
+ * Written by: John H. Baldwin <jhb at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/lib/libc/tests/stdio/open_wmemstream_test.c 291840 2015-12-05 04:17:40Z ngie $");
+
+#include <err.h>
+#include <errno.h>
+#include <limits.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <wchar.h>
+
+#include <atf-c.h>
+
+static wchar_t *buf;
+static size_t len;
+
+static void
+assert_stream(const wchar_t *contents)
+{
+ if (wcslen(contents) != len)
+ printf("bad length %zd for \"%ls\"\n", len, contents);
+ else if (wcsncmp(buf, contents, wcslen(contents)) != 0)
+ printf("bad buffer \"%ls\" for \"%ls\"\n", buf, contents);
+}
+
+ATF_TC_WITHOUT_HEAD(open_group_test);
+ATF_TC_BODY(open_group_test, tc)
+{
+ FILE *fp;
+ off_t eob;
+
+ fp = open_wmemstream(&buf, &len);
+ ATF_REQUIRE_MSG(fp != NULL, "open_wmemstream failed");
+
+ fwprintf(fp, L"hello my world");
+ fflush(fp);
+ assert_stream(L"hello my world");
+ eob = ftello(fp);
+ rewind(fp);
+ fwprintf(fp, L"good-bye");
+ fseeko(fp, eob, SEEK_SET);
+ fclose(fp);
+ assert_stream(L"good-bye world");
+ free(buf);
+}
+
+ATF_TC_WITHOUT_HEAD(simple_tests);
+ATF_TC_BODY(simple_tests, tc)
+{
+ static const wchar_t zerobuf[] =
+ { L'f', L'o', L'o', 0, 0, 0, 0, L'b', L'a', L'r', 0 };
+ wchar_t c;
+ FILE *fp;
+
+ fp = open_wmemstream(&buf, NULL);
+ ATF_REQUIRE_MSG(fp == NULL, "open_wmemstream did not fail");
+ ATF_REQUIRE_MSG(errno == EINVAL,
+ "open_wmemstream didn't fail with EINVAL");
+ fp = open_wmemstream(NULL, &len);
+ ATF_REQUIRE_MSG(fp == NULL, "open_wmemstream did not fail");
+ ATF_REQUIRE_MSG(errno == EINVAL,
+ "open_wmemstream didn't fail with EINVAL");
+ fp = open_wmemstream(&buf, &len);
+ ATF_REQUIRE_MSG(fp != NULL, "open_memstream failed; errno=%d", errno);
+ fflush(fp);
+ assert_stream(L"");
+ if (fwide(fp, 0) <= 0)
+ printf("stream is not wide-oriented\n");
+
+ fwprintf(fp, L"fo");
+ fflush(fp);
+ assert_stream(L"fo");
+ fputwc(L'o', fp);
+ fflush(fp);
+ assert_stream(L"foo");
+ rewind(fp);
+ fflush(fp);
+ assert_stream(L"");
+ fseek(fp, 0, SEEK_END);
+ fflush(fp);
+ assert_stream(L"foo");
+
+ /*
+ * Test seeking out past the current end. Should zero-fill the
+ * intermediate area.
+ */
+ fseek(fp, 4, SEEK_END);
+ fwprintf(fp, L"bar");
+ fflush(fp);
+
+ /*
+ * Can't use assert_stream() here since this should contain
+ * embedded null characters.
+ */
+ if (len != 10)
+ printf("bad length %zd for zero-fill test\n", len);
+ else if (memcmp(buf, zerobuf, sizeof(zerobuf)) != 0)
+ printf("bad buffer for zero-fill test\n");
+
+ fseek(fp, 3, SEEK_SET);
+ fwprintf(fp, L" in ");
+ fflush(fp);
+ assert_stream(L"foo in ");
+ fseek(fp, 0, SEEK_END);
+ fflush(fp);
+ assert_stream(L"foo in bar");
+
+ rewind(fp);
+ if (fread(&c, sizeof(c), 1, fp) != 0)
+ printf("fread did not fail\n");
+ else if (!ferror(fp))
+ printf("error indicator not set after fread\n");
+ else
+ clearerr(fp);
+
+ fseek(fp, 4, SEEK_SET);
+ fwprintf(fp, L"bar baz");
+ fclose(fp);
+ assert_stream(L"foo bar baz");
+ free(buf);
+}
+
+ATF_TC_WITHOUT_HEAD(seek_tests);
+ATF_TC_BODY(seek_tests, tc)
+{
+ FILE *fp;
+
+ fp = open_wmemstream(&buf, &len);
+ ATF_REQUIRE_MSG(fp != NULL, "open_wmemstream failed; errno=%d", errno);
+
+#define SEEK_FAIL(offset, whence, error) do { \
+ errno = 0; \
+ ATF_REQUIRE_MSG(fseeko(fp, (offset), (whence)) != 0, \
+ "fseeko(%s, %s) did not fail, set pos to %jd\n", \
+ __STRING(offset), __STRING(whence), \
+ (intmax_t)ftello(fp)); \
+ ATF_REQUIRE_MSG(errno == (error), \
+ "fseeko(%s, %s) failed with %d rather than %s\n", \
+ __STRING(offset), __STRING(whence), errno, \
+ __STRING(error)); \
+} while (0)
+
+#define SEEK_OK(offset, whence, result) do { \
+ ATF_REQUIRE_MSG(fseeko(fp, (offset), (whence)) == 0, \
+ "fseeko(%s, %s) failed: %s", \
+ __STRING(offset), __STRING(whence), strerror(errno)); \
+ ATF_REQUIRE_MSG(ftello(fp) == (result), \
+ "fseeko(%s, %s) seeked to %jd rather than %s\n", \
+ __STRING(offset), __STRING(whence), \
+ (intmax_t)ftello(fp), __STRING(result)); \
+} while (0)
+
+ SEEK_FAIL(-1, SEEK_SET, EINVAL);
+ SEEK_FAIL(-1, SEEK_CUR, EINVAL);
+ SEEK_FAIL(-1, SEEK_END, EINVAL);
+ fwprintf(fp, L"foo");
+ SEEK_OK(-1, SEEK_CUR, 2);
+ SEEK_OK(0, SEEK_SET, 0);
+ SEEK_OK(-1, SEEK_END, 2);
+ SEEK_OK(OFF_MAX - 1, SEEK_SET, OFF_MAX - 1);
+ SEEK_FAIL(2, SEEK_CUR, EOVERFLOW);
+ fclose(fp);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, open_group_test);
+ ATF_TP_ADD_TC(tp, simple_tests);
+ ATF_TP_ADD_TC(tp, seek_tests);
+
+ return (atf_no_error());
+}
Property changes on: trunk/lib/libc/tests/stdio/open_wmemstream_test.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/stdio/perror_test.c
===================================================================
--- trunk/lib/libc/tests/stdio/perror_test.c (rev 0)
+++ trunk/lib/libc/tests/stdio/perror_test.c 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,108 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2002 Tim J. Robbins
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Test program for perror() as specified by IEEE Std. 1003.1-2001 and
+ * ISO/IEC 9899:1999.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/lib/libc/tests/stdio/perror_test.c 291870 2015-12-05 21:49:35Z ngie $");
+
+#include <err.h>
+#include <errno.h>
+#include <limits.h>
+#include <paths.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <atf-c.h>
+
+static char tmpfil[PATH_MAX];
+
+ATF_TC_WITHOUT_HEAD(perror_test);
+ATF_TC_BODY(perror_test, tc)
+{
+ char lbuf[512];
+ int i;
+ char *s;
+
+ strcpy(tmpfil, "perror.XXXXXXXX");
+ ATF_REQUIRE(mkstemp(tmpfil) >= 0);
+ /* Reopen stderr on a file descriptor other than 2. */
+ fclose(stderr);
+ for (i = 0; i < 3; i++)
+ dup(0);
+ ATF_REQUIRE(freopen(tmpfil, "r+", stderr) != NULL);
+
+ /*
+ * Test that perror() doesn't call strerror() (4.4BSD bug),
+ * the two ways of omitting a program name, and the formatting when
+ * a program name is specified.
+ */
+ s = strerror(ENOENT);
+ ATF_REQUIRE_MSG(strcmp(s, "No such file or directory") == 0,
+ "message obtained was: %s", s);
+ errno = EPERM;
+ perror(NULL);
+ perror("");
+ perror("perror_test");
+ ATF_REQUIRE_MSG(strcmp(s, "No such file or directory") == 0,
+ "message obtained was: %s", s);
+
+ /*
+ * Read it back to check...
+ */
+ rewind(stderr);
+ s = fgets(lbuf, sizeof(lbuf), stderr);
+ ATF_REQUIRE(s != NULL);
+ ATF_REQUIRE_MSG(strcmp(s, "Operation not permitted\n") == 0,
+ "message obtained was: %s", s);
+ s = fgets(lbuf, sizeof(lbuf), stderr);
+ ATF_REQUIRE(s != NULL);
+ ATF_REQUIRE_MSG(strcmp(s, "Operation not permitted\n") == 0,
+ "message obtained was: %s", s);
+ s = fgets(lbuf, sizeof(lbuf), stderr);
+ ATF_REQUIRE(s != NULL);
+ ATF_REQUIRE_MSG(
+ strcmp(s, "perror_test: Operation not permitted\n") == 0,
+ "message obtained was: %s", s);
+ s = fgets(lbuf, sizeof(lbuf), stderr);
+ ATF_REQUIRE(s == NULL);
+ fclose(stderr);
+
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, perror_test);
+
+ return (atf_no_error());
+}
Property changes on: trunk/lib/libc/tests/stdio/perror_test.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/stdio/print_positional_test.c
===================================================================
--- trunk/lib/libc/tests/stdio/print_positional_test.c (rev 0)
+++ trunk/lib/libc/tests/stdio/print_positional_test.c 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,158 @@
+/* $MidnightBSD$ */
+/* $OpenBSD: sprintf_test.c,v 1.3 2004/09/16 20:22:26 otto Exp $ */
+
+/*
+ * Copyright (c) 2003 Theo de Raadt
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * - 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>
+__FBSDID("$FreeBSD: stable/10/lib/libc/tests/stdio/print_positional_test.c 301808 2016-06-10 18:13:41Z ngie $");
+
+#include <sys/param.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <wchar.h>
+
+#include <atf-c.h>
+
+const char correct[] =
+ "|xx 01 02 03 04\n"
+ "|xx 05 06 07 08\n"
+ "|xx 09 10 11 12\n"
+ "|xx 13 14 15 16\n"
+ "|xx 17 18 19 20\n"
+ "|xx 21 22 23 24\n"
+ "|xx 25 26 27 28\n"
+ "|xx 29 30 31 32\n"
+ "|xx 33 34 35 36\n"
+ "|xx 37 38 39 40\n"
+ "|xx 41 42 43 44\n"
+ "|xx 45 -1 1 -1 1\n";
+
+const char correct2[] =
+ "b bs BSD";
+static char buf[1024];
+static wchar_t wbuf1[1024], wbuf2[1024];
+static const char *temp;
+
+ATF_TC_WITHOUT_HEAD(positional_normal);
+ATF_TC_BODY(positional_normal, tc)
+{
+
+ /* Test positional arguments */
+ snprintf(buf, sizeof buf,
+ "|xx %1$s %2$s %3$s %4$s\n"
+ "|xx %5$s %6$s %7$s %8$s\n"
+ "|xx %9$s %10$s %11$s %12$s\n"
+ "|xx %13$s %14$s %15$s %16$s\n"
+ "|xx %17$s %18$s %19$s %20$s\n"
+ "|xx %21$s %22$s %23$s %24$s\n"
+ "|xx %25$s %26$s %27$s %28$s\n"
+ "|xx %29$s %30$s %31$s %32$s\n"
+ "|xx %33$s %34$s %35$s %36$s\n"
+ "|xx %37$s %38$s %39$s %40$s\n"
+ "|xx %41$s %42$s %43$s %44$s\n"
+ "|xx %45$d %46$ld %47$lld %48$d %49$lld\n",
+ "01", "02", "03", "04", "05", "06",
+ "07", "08", "09", "10", "11", "12",
+ "13", "14", "15", "16", "17", "18",
+ "19", "20", "21", "22", "23", "24",
+ "25", "26", "27", "28", "29", "30",
+ "31", "32", "33", "34", "35", "36",
+ "37", "38", "39", "40", "41", "42",
+ "43", "44", 45, -1L, 1LL, -1, 1LL
+ );
+ ATF_REQUIRE_MSG(wcscmp(wbuf1, wbuf2) == 0,
+ "buffers didn't match");
+}
+
+ATF_TC_WITHOUT_HEAD(positional_wide);
+ATF_TC_BODY(positional_wide, tc)
+{
+
+ swprintf(wbuf1, nitems(wbuf1),
+ L"|xx %1$s %2$s %3$s %4$s\n"
+ "|xx %5$s %6$s %7$s %8$s\n"
+ "|xx %9$s %10$s %11$s %12$s\n"
+ "|xx %13$s %14$s %15$s %16$s\n"
+ "|xx %17$s %18$s %19$s %20$s\n"
+ "|xx %21$s %22$s %23$s %24$s\n"
+ "|xx %25$s %26$s %27$s %28$s\n"
+ "|xx %29$s %30$s %31$s %32$s\n"
+ "|xx %33$s %34$s %35$s %36$s\n"
+ "|xx %37$s %38$s %39$s %40$s\n"
+ "|xx %41$s %42$s %43$s %44$s\n"
+ "|xx %45$d %46$ld %47$lld %48$d %49$lld\n",
+ "01", "02", "03", "04", "05", "06",
+ "07", "08", "09", "10", "11", "12",
+ "13", "14", "15", "16", "17", "18",
+ "19", "20", "21", "22", "23", "24",
+ "25", "26", "27", "28", "29", "30",
+ "31", "32", "33", "34", "35", "36",
+ "37", "38", "39", "40", "41", "42",
+ "43", "44", 45, -1L, 1LL, -1, 1LL
+ );
+ temp = correct;
+ mbsrtowcs(wbuf2, &temp, nitems(wbuf2), NULL);
+ ATF_REQUIRE_MSG(wcscmp(wbuf1, wbuf2) == 0,
+ "buffers didn't match");
+}
+
+ATF_TC_WITHOUT_HEAD(positional_precision);
+ATF_TC_BODY(positional_precision, tc)
+{
+
+ snprintf(buf, sizeof buf, "%2$.*4$s %2$.*3$s %1$s",
+ "BSD", "bsd", 2, 1);
+ ATF_REQUIRE_MSG(strcmp(buf, correct2) == 0,
+ "buffers didn't match");
+}
+
+ATF_TC_WITHOUT_HEAD(positional_precision_wide);
+ATF_TC_BODY(positional_precision_wide, tc)
+{
+
+ swprintf(wbuf1, sizeof buf, L"%2$.*4$s %2$.*3$s %1$s",
+ "BSD", "bsd", 2, 1);
+ temp = correct2;
+ mbsrtowcs(wbuf2, &temp, nitems(wbuf2), NULL);
+ ATF_REQUIRE_MSG(wcscmp(wbuf1, wbuf2) == 0,
+ "buffers didn't match");
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, positional_normal);
+ ATF_TP_ADD_TC(tp, positional_wide);
+ ATF_TP_ADD_TC(tp, positional_precision);
+ ATF_TP_ADD_TC(tp, positional_precision_wide);
+
+ return (atf_no_error());
+}
Property changes on: trunk/lib/libc/tests/stdio/print_positional_test.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/stdio/printbasic_test.c
===================================================================
--- trunk/lib/libc/tests/stdio/printbasic_test.c (rev 0)
+++ trunk/lib/libc/tests/stdio/printbasic_test.c 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,163 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2009 David Schultz <das at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Tests for basic and miscellaneous printf() formats.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/lib/libc/tests/stdio/printbasic_test.c 313723 2017-02-14 04:49:24Z ngie $");
+
+#include <err.h>
+#include <limits.h>
+#include <locale.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <wchar.h>
+
+#include <atf-c.h>
+
+#define S_UINT64MAX "18446744073709551615"
+#define S_UINT32MAX "4294967295"
+#define S_INT64MIN "-9223372036854775808"
+#define S_INT32MIN "-2147483648"
+
+#define S_SIZEMAX (SIZE_MAX == UINT64_MAX ? S_UINT64MAX : S_UINT32MAX)
+#define S_ULONGMAX (ULONG_MAX == UINT64_MAX ? S_UINT64MAX : S_UINT32MAX)
+#define S_ULLONGMAX (ULLONG_MAX == UINT64_MAX ? S_UINT64MAX : S_UINT32MAX)
+
+static void
+smash_stack(void)
+{
+ static uint32_t junk = 0xdeadbeef;
+ uint32_t buf[512];
+ int i;
+
+ for (i = 0; i < sizeof(buf) / sizeof(buf[0]); i++)
+ buf[i] = junk;
+}
+
+#define testfmt(result, fmt, ...) \
+ _testfmt((result), #__VA_ARGS__, fmt, __VA_ARGS__)
+static void
+_testfmt(const char *result, const char *argstr, const char *fmt,...)
+{
+#define BUF 100
+ wchar_t ws[BUF], wfmt[BUF], wresult[BUF];
+ char s[BUF];
+ va_list ap, ap2;
+
+ va_start(ap, fmt);
+ va_copy(ap2, ap);
+ smash_stack();
+ vsnprintf(s, sizeof(s), fmt, ap);
+ ATF_CHECK_MSG(strcmp(result, s) == 0,
+ "printf(\"%s\", %s) ==> [%s], expected [%s]",
+ fmt, argstr, s, result);
+
+ smash_stack();
+ mbstowcs(ws, s, BUF - 1);
+ mbstowcs(wfmt, fmt, BUF - 1);
+ mbstowcs(wresult, result, BUF - 1);
+ vswprintf(ws, sizeof(ws) / sizeof(ws[0]), wfmt, ap2);
+ ATF_CHECK_MSG(wcscmp(wresult, ws) == 0,
+ "wprintf(\"%ls\", %s) ==> [%ls], expected [%ls]",
+ wfmt, argstr, ws, wresult);
+
+ va_end(ap);
+ va_end(ap2);
+}
+
+ATF_TC_WITHOUT_HEAD(int_within_limits);
+ATF_TC_BODY(int_within_limits, tc)
+{
+
+ ATF_REQUIRE(setlocale(LC_NUMERIC, "C"));
+
+ /* The test requires these to be true. */
+ ATF_REQUIRE(UINTMAX_MAX == UINT64_MAX);
+ ATF_REQUIRE(UINT_MAX == UINT32_MAX);
+ ATF_REQUIRE(USHRT_MAX == 0xffff);
+ ATF_REQUIRE(UCHAR_MAX == 0xff);
+
+ /* Make sure we handle signed vs. unsigned args correctly. */
+ testfmt("-1", "%jd", (intmax_t)-1);
+ testfmt(S_UINT64MAX, "%ju", UINT64_MAX);
+
+ if (sizeof(ptrdiff_t) != sizeof(uintmax_t))
+ atf_tc_expect_fail("the %%t qualifier is broken on 32-bit "
+ "platforms where there's a mismatch between ptrdiff_t and "
+ "uintmax_t's type width; bug # 191674");
+
+ testfmt("-1", "%td", (ptrdiff_t)-1);
+ testfmt(S_SIZEMAX, "%tu", (size_t)-1);
+
+ testfmt("-1", "%zd", (ssize_t)-1);
+ testfmt(S_SIZEMAX, "%zu", (ssize_t)-1);
+
+ testfmt("-1", "%ld", (long)-1);
+ testfmt(S_ULONGMAX, "%lu", ULONG_MAX);
+
+ testfmt("-1", "%lld", (long long)-1);
+ testfmt(S_ULLONGMAX, "%llu", ULLONG_MAX);
+
+ testfmt("-1", "%d", -1);
+ testfmt(S_UINT32MAX, "%u", UINT32_MAX);
+
+ testfmt("-1", "%hd", -1);
+ testfmt("65535", "%hu", USHRT_MAX);
+
+ testfmt("-1", "%hhd", -1);
+ testfmt("255", "%hhu", UCHAR_MAX);
+}
+
+ATF_TC_WITHOUT_HEAD(int_limits);
+ATF_TC_BODY(int_limits, tc)
+{
+
+ ATF_REQUIRE(setlocale(LC_NUMERIC, "C"));
+
+ /*
+ * Check that printing the largest negative number does not cause
+ * overflow when it is negated.
+ */
+ testfmt(S_INT32MIN, "%d", INT_MIN);
+ testfmt(S_INT64MIN, "%jd", INTMAX_MIN);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, int_within_limits);
+ ATF_TP_ADD_TC(tp, int_limits);
+
+ return (atf_no_error());
+}
Property changes on: trunk/lib/libc/tests/stdio/printbasic_test.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/stdio/printfloat_test.c
===================================================================
--- trunk/lib/libc/tests/stdio/printfloat_test.c (rev 0)
+++ trunk/lib/libc/tests/stdio/printfloat_test.c 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,390 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2002-2009 David Schultz <das at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Test for printf() floating point formats.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/lib/libc/tests/stdio/printfloat_test.c 313720 2017-02-14 04:46:19Z ngie $");
+
+#include <err.h>
+#include <fenv.h>
+#include <float.h>
+#include <locale.h>
+#include <math.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <wchar.h>
+
+#include <atf-c.h>
+
+static void
+smash_stack(void)
+{
+ static uint32_t junk = 0xdeadbeef;
+ uint32_t buf[512];
+ int i;
+
+ for (i = 0; i < sizeof(buf) / sizeof(buf[0]); i++)
+ buf[i] = junk;
+}
+
+#define testfmt(result, fmt, ...) \
+ _testfmt((result), #__VA_ARGS__, fmt, __VA_ARGS__)
+static void
+_testfmt(const char *result, const char *argstr, const char *fmt,...)
+{
+#define BUF 100
+ wchar_t ws[BUF], wfmt[BUF], wresult[BUF];
+ char s[BUF];
+ va_list ap, ap2;
+
+ va_start(ap, fmt);
+ va_copy(ap2, ap);
+ smash_stack();
+ vsnprintf(s, sizeof(s), fmt, ap);
+ ATF_CHECK_MSG(strcmp(result, s) == 0,
+ "printf(\"%s\", %s) ==> [%s], expected [%s]",
+ fmt, argstr, s, result);
+
+ smash_stack();
+ mbstowcs(ws, s, BUF - 1);
+ mbstowcs(wfmt, fmt, BUF - 1);
+ mbstowcs(wresult, result, BUF - 1);
+ vswprintf(ws, sizeof(ws) / sizeof(ws[0]), wfmt, ap2);
+ ATF_CHECK_MSG(wcscmp(wresult, ws) == 0,
+ "wprintf(\"%ls\", %s) ==> [%ls], expected [%ls]",
+ wfmt, argstr, ws, wresult);
+
+ va_end(ap);
+ va_end(ap2);
+}
+
+ATF_TC_WITHOUT_HEAD(float_within_limits);
+ATF_TC_BODY(float_within_limits, tc)
+{
+
+ ATF_REQUIRE(setlocale(LC_NUMERIC, "C"));
+
+ /* Basic tests of decimal output functionality. */
+ testfmt(" 1.000000E+00", "%13E", 1.0);
+ testfmt(" 1.000000", "%13f", 1.0);
+ testfmt(" 1", "%13G", 1.0);
+ testfmt(" 1.000000E+00", "%13LE", 1.0L);
+ testfmt(" 1.000000", "%13Lf", 1.0L);
+ testfmt(" 1", "%13LG", 1.0L);
+
+ testfmt("2.718282", "%.*f", -2, 2.7182818);
+
+ testfmt("1.234568e+06", "%e", 1234567.8);
+ testfmt("1234567.800000", "%f", 1234567.8);
+ testfmt("1.23457E+06", "%G", 1234567.8);
+ testfmt("1.234568e+06", "%Le", 1234567.8L);
+ testfmt("1234567.800000", "%Lf", 1234567.8L);
+ testfmt("1.23457E+06", "%LG", 1234567.8L);
+
+#if (LDBL_MANT_DIG > DBL_MANT_DIG) && !defined(__i386__)
+ testfmt("123456789.864210", "%Lf", 123456789.8642097531L);
+ testfmt("-1.23457E+08", "%LG", -123456789.8642097531L);
+ testfmt("123456789.8642097531", "%.10Lf", 123456789.8642097531L);
+ testfmt(" 3.141592653589793238e-4000", "%L27.18Le",
+ 3.14159265358979323846e-4000L);
+#endif
+}
+
+ATF_TC_WITHOUT_HEAD(infinities_and_nans);
+ATF_TC_BODY(infinities_and_nans, tc)
+{
+
+ ATF_REQUIRE(setlocale(LC_NUMERIC, "C"));
+
+ testfmt("nan", "%e", NAN);
+ testfmt("NAN", "%F", NAN);
+ testfmt("nan", "%g", NAN);
+ testfmt("NAN", "%LE", (long double)NAN);
+ testfmt(" nan", "%05e", NAN);
+
+ testfmt("INF", "%E", HUGE_VAL);
+ testfmt("-inf", "%f", -HUGE_VAL);
+ testfmt("+inf", "%+g", HUGE_VAL);
+ testfmt(" inf", "%4.2Le", HUGE_VALL);
+ testfmt("-inf", "%Lf", -HUGE_VALL);
+ testfmt(" inf", "%05e", HUGE_VAL);
+ testfmt(" -inf", "%05e", -HUGE_VAL);
+}
+
+ATF_TC_WITHOUT_HEAD(padding);
+ATF_TC_BODY(padding, tc)
+{
+
+ ATF_REQUIRE(setlocale(LC_NUMERIC, "C"));
+
+ testfmt("0.000000e+00", "%e", 0.0);
+ testfmt("0.000000", "%F", (double)0.0);
+ testfmt("0", "%G", 0.0);
+ testfmt(" 0", "%3.0Lg", 0.0L);
+ testfmt(" 0", "%5.0f", 0.001);
+}
+
+ATF_TC_WITHOUT_HEAD(precision_specifiers);
+ATF_TC_BODY(precision_specifiers, tc)
+{
+
+ ATF_REQUIRE(setlocale(LC_NUMERIC, "C"));
+
+ testfmt("1.0123e+00", "%.4e", 1.0123456789);
+ testfmt("1.0123", "%.4f", 1.0123456789);
+ testfmt("1.012", "%.4g", 1.0123456789);
+ testfmt("1.2346e-02", "%.4e", 0.0123456789);
+ testfmt("0.0123", "%.4f", 0.0123456789);
+ testfmt("0.01235", "%.4g", 0.0123456789);
+}
+
+ATF_TC_WITHOUT_HEAD(thousands_separator_and_other_locale_tests);
+ATF_TC_BODY(thousands_separator_and_other_locale_tests, tc)
+{
+
+ ATF_REQUIRE(setlocale(LC_NUMERIC, "C"));
+
+ testfmt("12345678.0625", "%'.04f", 12345678.0625);
+ testfmt("0012345678.0625", "%'015.4F", 12345678.0625);
+
+ ATF_REQUIRE(setlocale(LC_NUMERIC, "hi_IN.ISCII-DEV")); /* grouping == 2;3 */
+ testfmt("123,456,78.0625", "%'.4f", 12345678.0625);
+ testfmt("00123,456,78.0625", "%'017.4F", 12345678.0625);
+ testfmt(" 90,00", "%'6.0f", 9000.0);
+ testfmt("90,00.0", "%'.1f", 9000.0);
+
+ ATF_REQUIRE(setlocale(LC_NUMERIC, "ru_RU.ISO8859-5")); /* decimalpoint==, */
+ testfmt("3,1415", "%g", 3.1415);
+
+ /* thousands=. decimalpoint=, grouping=3;3 */
+ ATF_REQUIRE(setlocale(LC_NUMERIC, "el_GR.ISO8859-7")); /* decimalpoint==, */
+ testfmt("1.234,00", "%'.2f", 1234.00);
+ testfmt("123.456,789", "%'.3f", 123456.789);
+
+ ATF_REQUIRE(setlocale(LC_NUMERIC, "C"));
+ testfmt("12345678.062500", "%'f", 12345678.0625);
+ testfmt("9000.000000", "%'f", 9000.0);
+}
+
+ATF_TC_WITHOUT_HEAD(signed_conversions);
+ATF_TC_BODY(signed_conversions, tc)
+{
+
+ ATF_REQUIRE(setlocale(LC_NUMERIC, "C"));
+
+ testfmt("+2.500000e-01", "%+e", 0.25);
+ testfmt("+0.000000", "%+F", 0.0);
+ testfmt("-1", "%+g", -1.0);
+
+ testfmt("-1.000000e+00", "% e", -1.0);
+ testfmt("+1.000000", "% +f", 1.0);
+ testfmt(" 1", "% g", 1.0);
+ testfmt(" 0", "% g", 0.0);
+}
+
+ATF_TC_WITHOUT_HEAD(alternate_form);
+ATF_TC_BODY(alternate_form, tc)
+{
+
+ ATF_REQUIRE(setlocale(LC_NUMERIC, "C"));
+
+ testfmt("1.250e+00", "%#.3e", 1.25);
+ testfmt("123.000000", "%#f", 123.0);
+ testfmt(" 12345.", "%#7.5g", 12345.0);
+ testfmt(" 1.00000", "%#8g", 1.0);
+ testfmt("0.0", "%#.2g", 0.0);
+}
+
+ATF_TC_WITHOUT_HEAD(padding_and_decimal_point_placement);
+ATF_TC_BODY(padding_and_decimal_point_placement, tc)
+{
+
+ ATF_REQUIRE(setlocale(LC_NUMERIC, "C"));
+
+ testfmt("03.2E+00", "%08.1E", 3.25);
+ testfmt("003.25", "%06.2F", 3.25);
+ testfmt("0003.25", "%07.4G", 3.25);
+
+ testfmt("3.14159e-05", "%g", 3.14159e-5);
+ testfmt("0.000314159", "%g", 3.14159e-4);
+ testfmt("3.14159e+06", "%g", 3.14159e6);
+ testfmt("314159", "%g", 3.14159e5);
+ testfmt("314159.", "%#g", 3.14159e5);
+
+ testfmt(" 9.000000e+03", "%13e", 9000.0);
+ testfmt(" 9000.000000", "%12f", 9000.0);
+ testfmt(" 9000", "%5g", 9000.0);
+ testfmt(" 900000.", "%#8g", 900000.0);
+ testfmt(" 9e+06", "%6g", 9000000.0);
+ testfmt(" 9.000000e-04", "%13e", 0.0009);
+ testfmt(" 0.000900", "%9f", 0.0009);
+ testfmt(" 0.0009", "%7g", 0.0009);
+ testfmt(" 9e-05", "%6g", 0.00009);
+ testfmt(" 9.00000e-05", "%#12g", 0.00009);
+ testfmt(" 9.e-05", "%#7.1g", 0.00009);
+
+ testfmt(" 0.0", "%4.1f", 0.0);
+ testfmt("90.0", "%4.1f", 90.0);
+ testfmt(" 100", "%4.0f", 100.0);
+ testfmt("9.0e+01", "%4.1e", 90.0);
+ testfmt("1e+02", "%4.0e", 100.0);
+}
+
+ATF_TC_WITHOUT_HEAD(decimal_rounding);
+ATF_TC_BODY(decimal_rounding, tc)
+{
+
+ ATF_REQUIRE(setlocale(LC_NUMERIC, "C"));
+
+ fesetround(FE_DOWNWARD);
+ testfmt("4.437", "%.3f", 4.4375);
+ testfmt("-4.438", "%.3f", -4.4375);
+ testfmt("4.437", "%.3Lf", 4.4375L);
+ testfmt("-4.438", "%.3Lf", -4.4375L);
+
+ fesetround(FE_UPWARD);
+ testfmt("4.438", "%.3f", 4.4375);
+ testfmt("-4.437", "%.3f", -4.4375);
+ testfmt("4.438", "%.3Lf", 4.4375L);
+ testfmt("-4.437", "%.3Lf", -4.4375L);
+
+ fesetround(FE_TOWARDZERO);
+ testfmt("4.437", "%.3f", 4.4375);
+ testfmt("-4.437", "%.3f", -4.4375);
+ testfmt("4.437", "%.3Lf", 4.4375L);
+ testfmt("-4.437", "%.3Lf", -4.4375L);
+
+ fesetround(FE_TONEAREST);
+ testfmt("4.438", "%.3f", 4.4375);
+ testfmt("-4.438", "%.3f", -4.4375);
+ testfmt("4.438", "%.3Lf", 4.4375L);
+ testfmt("-4.438", "%.3Lf", -4.4375L);
+}
+
+ATF_TC_WITHOUT_HEAD(hexadecimal_floating_point);
+ATF_TC_BODY(hexadecimal_floating_point, tc)
+{
+
+ ATF_REQUIRE(setlocale(LC_NUMERIC, "C"));
+
+ /*
+ * Hexadecimal floating point (%a, %A) tests. Some of these
+ * are only valid if the implementation converts to hex digits
+ * on nibble boundaries.
+ */
+ testfmt("0x0p+0", "%a", 0x0.0p0);
+ testfmt("0X0.P+0", "%#LA", 0x0.0p0L);
+ testfmt("inf", "%La", (long double)INFINITY);
+ testfmt("+INF", "%+A", INFINITY);
+ testfmt("nan", "%La", (long double)NAN);
+ testfmt("NAN", "%A", NAN);
+
+ testfmt(" 0x1.23p+0", "%10a", 0x1.23p0);
+ testfmt(" 0x1.23p-500", "%12a", 0x1.23p-500);
+ testfmt(" 0x1.2p+40", "%10.1a", 0x1.23p40);
+ testfmt(" 0X1.230000000000000000000000P-4", "%32.24A", 0x1.23p-4);
+ testfmt("0x1p-1074", "%a", 0x1p-1074);
+ testfmt("0x1.2345p-1024", "%a", 0x1.2345p-1024);
+
+#if (LDBL_MANT_DIG == 64)
+ testfmt("0x1.921fb54442d18468p+1", "%La", 0x3.243f6a8885a308dp0L);
+ testfmt("0x1p-16445", "%La", 0x1p-16445L);
+ testfmt("0x1.30ecap-16381", "%La", 0x9.8765p-16384L);
+#elif (LDBL_MANT_DIG == 113)
+ testfmt("0x1.921fb54442d18469898cc51701b8p+1", "%La",
+ 0x3.243f6a8885a308d313198a2e037p0L);
+ testfmt("0x1p-16494", "%La", 0x1p-16494L);
+ testfmt("0x1.2345p-16384", "%La", 0x1.2345p-16384L);
+#else
+ testfmt("0x1.921fb54442d18p+1", "%La", 0x3.243f6a8885a31p0L);
+ testfmt("0x1p-1074", "%La", 0x1p-1074L);
+ testfmt("0x1.30ecap-1021", "%La", 0x9.8765p-1024L);
+#endif
+}
+
+ATF_TC_WITHOUT_HEAD(hexadecimal_rounding);
+ATF_TC_BODY(hexadecimal_rounding, tc)
+{
+
+ ATF_REQUIRE(setlocale(LC_NUMERIC, "C"));
+
+ fesetround(FE_TOWARDZERO);
+ testfmt("0X1.23456789ABCP+0", "%.11A", 0x1.23456789abcdep0);
+ testfmt("-0x1.23456p+0", "%.5a", -0x1.23456789abcdep0);
+ testfmt("0x1.23456p+0", "%.5a", 0x1.23456789abcdep0);
+ testfmt("0x1.234567p+0", "%.6a", 0x1.23456789abcdep0);
+ testfmt("-0x1.234566p+0", "%.6a", -0x1.23456689abcdep0);
+
+ fesetround(FE_DOWNWARD);
+ testfmt("0X1.23456789ABCP+0", "%.11A", 0x1.23456789abcdep0);
+ testfmt("-0x1.23457p+0", "%.5a", -0x1.23456789abcdep0);
+ testfmt("0x1.23456p+0", "%.5a", 0x1.23456789abcdep0);
+ testfmt("0x1.234567p+0", "%.6a", 0x1.23456789abcdep0);
+ testfmt("-0x1.234567p+0", "%.6a", -0x1.23456689abcdep0);
+
+ fesetround(FE_UPWARD);
+ testfmt("0X1.23456789ABDP+0", "%.11A", 0x1.23456789abcdep0);
+ testfmt("-0x1.23456p+0", "%.5a", -0x1.23456789abcdep0);
+ testfmt("0x1.23457p+0", "%.5a", 0x1.23456789abcdep0);
+ testfmt("0x1.234568p+0", "%.6a", 0x1.23456789abcdep0);
+ testfmt("-0x1.234566p+0", "%.6a", -0x1.23456689abcdep0);
+
+ fesetround(FE_TONEAREST);
+ testfmt("0x1.23456789abcdep+4", "%a", 0x1.23456789abcdep4);
+ testfmt("0X1.23456789ABDP+0", "%.11A", 0x1.23456789abcdep0);
+ testfmt("-0x1.23456p+0", "%.5a", -0x1.23456789abcdep0);
+ testfmt("0x1.23456p+0", "%.5a", 0x1.23456789abcdep0);
+ testfmt("0x1.234568p+0", "%.6a", 0x1.23456789abcdep0);
+ testfmt("-0x1.234567p+0", "%.6a", -0x1.23456689abcdep0);
+ testfmt("0x1.00p-1029", "%.2a", 0x1.fffp-1030);
+ testfmt("0x1.00p-1026", "%.2a", 0xf.fffp-1030);
+ testfmt("0x1.83p+0", "%.2a", 1.51);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, float_within_limits);
+ ATF_TP_ADD_TC(tp, infinities_and_nans);
+ ATF_TP_ADD_TC(tp, padding);
+ ATF_TP_ADD_TC(tp, precision_specifiers);
+ ATF_TP_ADD_TC(tp, thousands_separator_and_other_locale_tests);
+ ATF_TP_ADD_TC(tp, signed_conversions);
+ ATF_TP_ADD_TC(tp, alternate_form);
+ ATF_TP_ADD_TC(tp, padding_and_decimal_point_placement);
+ ATF_TP_ADD_TC(tp, decimal_rounding);
+ ATF_TP_ADD_TC(tp, hexadecimal_floating_point);
+ ATF_TP_ADD_TC(tp, hexadecimal_rounding);
+
+ return (atf_no_error());
+}
Property changes on: trunk/lib/libc/tests/stdio/printfloat_test.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/stdio/scanfloat_test.c
===================================================================
--- trunk/lib/libc/tests/stdio/scanfloat_test.c (rev 0)
+++ trunk/lib/libc/tests/stdio/scanfloat_test.c 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,317 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (C) 2003, 2005 David Schultz <das at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Test for scanf() floating point formats.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/lib/libc/tests/stdio/scanfloat_test.c 291870 2015-12-05 21:49:35Z ngie $");
+
+#include <fenv.h>
+#include <float.h>
+#include <locale.h>
+#include <math.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <atf-c.h>
+
+#define eq(type, a, b) _eq(type##_EPSILON, (a), (b))
+static int
+_eq(long double epsilon, long double a, long double b)
+{
+ long double delta;
+
+ delta = fabsl(a - b);
+ return (delta <= epsilon);
+}
+
+ATF_TC_WITHOUT_HEAD(normalized_numbers);
+ATF_TC_BODY(normalized_numbers, tc)
+{
+ char buf[128];
+ long double ld = 0.0;
+ double d = 0.0;
+ float f = 0.0;
+
+ buf[0] = '\0';
+ ATF_REQUIRE(setlocale(LC_NUMERIC, ""));
+
+ sscanf("3.141592", "%e", &f);
+ ATF_REQUIRE(eq(FLT, f, 3.141592));
+
+ sscanf("3.141592653589793", "%lf", &d);
+ ATF_REQUIRE(eq(DBL, d, 3.141592653589793));
+
+ sscanf("1.234568e+06", "%E", &f);
+ ATF_REQUIRE(eq(FLT, f, 1.234568e+06));
+
+ sscanf("-1.234568e6", "%lF", &d);
+ ATF_REQUIRE(eq(DBL, d, -1.234568e6));
+
+ sscanf("+1.234568e-52", "%LG", &ld);
+ ATF_REQUIRE(eq(LDBL, ld, 1.234568e-52L));
+
+ sscanf("0.1", "%la", &d);
+ ATF_REQUIRE(eq(DBL, d, 0.1));
+
+ sscanf("00.2", "%lA", &d);
+ ATF_REQUIRE(eq(DBL, d, 0.2));
+
+ sscanf("123456", "%5le%s", &d, buf);
+ ATF_REQUIRE(eq(DBL, d, 12345.));
+ ATF_REQUIRE(strcmp(buf, "6") == 0);
+
+ sscanf("1.0Q", "%*5le%s", buf);
+ ATF_REQUIRE(strcmp(buf, "Q") == 0);
+
+ sscanf("-1.23e", "%e%s", &f, buf);
+ ATF_REQUIRE(eq(FLT, f, -1.23));
+ ATF_REQUIRE(strcmp(buf, "e") == 0);
+
+ sscanf("1.25e+", "%le%s", &d, buf);
+ ATF_REQUIRE(eq(DBL, d, 1.25));
+ ATF_REQUIRE(strcmp(buf, "e+") == 0);
+
+ sscanf("1.23E4E5", "%le%s", &d, buf);
+ ATF_REQUIRE(eq(DBL, d, 1.23e4));
+ ATF_REQUIRE(strcmp(buf, "E5") == 0);
+
+ sscanf("12e6", "%le", &d);
+ ATF_REQUIRE(eq(DBL, d, 12e6));
+
+ sscanf("1.a", "%le%s", &d, buf);
+ ATF_REQUIRE(eq(DBL, d, 1.0));
+ ATF_REQUIRE(strcmp(buf, "a") == 0);
+
+ sscanf(".0p4", "%le%s", &d, buf);
+ ATF_REQUIRE(eq(DBL, d, 0.0));
+ ATF_REQUIRE(strcmp(buf, "p4") == 0);
+
+ d = 0.25;
+ ATF_REQUIRE(sscanf(".", "%le", &d) == 0);
+ ATF_REQUIRE(d == 0.25);
+
+ sscanf("0x08", "%le", &d);
+ ATF_REQUIRE(d == 0x8p0);
+
+ sscanf("0x90a.bcdefP+09a", "%le%s", &d, buf);
+ ATF_REQUIRE(d == 0x90a.bcdefp+09);
+ ATF_REQUIRE(strcmp(buf, "a") == 0);
+
+#if (LDBL_MANT_DIG > DBL_MANT_DIG) && !defined(__i386__)
+ sscanf("3.14159265358979323846", "%Lg", &ld);
+ ATF_REQUIRE(eq(LDBL, ld, 3.14159265358979323846L));
+
+ sscanf(" 0X.0123456789abcdefffp-3g", "%Le%s", &ld, buf);
+ ATF_REQUIRE(ld == 0x0.0123456789abcdefffp-3L);
+ ATF_REQUIRE(strcmp(buf, "g") == 0);
+#endif
+
+ sscanf("0xg", "%le%s", &d, buf);
+ ATF_REQUIRE(d == 0.0);
+ ATF_REQUIRE(strcmp(buf, "xg") == 0);
+
+ ATF_REQUIRE(setlocale(LC_NUMERIC, "ru_RU.ISO8859-5")); /* decimalpoint==, */
+
+ sscanf("1.23", "%le%s", &d, buf);
+ ATF_REQUIRE(d == 1.0);
+ ATF_REQUIRE(strcmp(buf, ".23") == 0);
+
+ sscanf("1,23", "%le", &d);
+ ATF_REQUIRE(d == 1.23);
+
+ ATF_REQUIRE(setlocale(LC_NUMERIC, ""));
+}
+
+ATF_TC_WITHOUT_HEAD(infinities_and_nans);
+ATF_TC_BODY(infinities_and_nans, tc)
+{
+ char buf[128];
+ long double ld = 0.0;
+ double d = 0.0;
+ float f = 0.0;
+
+ ATF_REQUIRE(setlocale(LC_NUMERIC, "C"));
+
+ sscanf("-Inf", "%le", &d);
+ ATF_REQUIRE(d < 0.0 && isinf(d));
+
+ sscanf("iNfInItY and beyond", "%le%s", &d, buf);
+ ATF_REQUIRE(d > 0.0 && isinf(d));
+ ATF_REQUIRE(strcmp(buf, " and beyond"));
+
+ sscanf("NaN", "%le", &d);
+ ATF_REQUIRE(isnan(d));
+
+ sscanf("NAN(123Y", "%le%s", &d, buf);
+ ATF_REQUIRE(isnan(d));
+ ATF_REQUIRE(strcmp(buf, "(123Y") == 0);
+
+ sscanf("nan(f00f)plugh", "%le%s", &d, buf);
+ ATF_REQUIRE(isnan(d));
+ ATF_REQUIRE(strcmp(buf, "plugh") == 0);
+
+ sscanf("-nan", "%le", &d);
+ ATF_REQUIRE(isnan(d));
+
+ /* Only quiet NaNs should be returned. */
+ sscanf("NaN", "%e", &f);
+ sscanf("nan", "%le", &d);
+ sscanf("nan", "%Le", &ld);
+ feclearexcept(FE_ALL_EXCEPT);
+ ATF_REQUIRE(f != f);
+ ATF_REQUIRE(d != d);
+ ATF_REQUIRE(ld != ld);
+ ATF_REQUIRE(fetestexcept(FE_INVALID) == 0);
+ sscanf("nan(1234)", "%e", &f);
+ sscanf("nan(1234)", "%le", &d);
+ sscanf("nan(1234)", "%Le", &ld);
+ feclearexcept(FE_ALL_EXCEPT);
+ ATF_REQUIRE(f != f);
+ ATF_REQUIRE(d != d);
+ ATF_REQUIRE(ld != ld);
+ /* POSIX says we should only generate quiet NaNs. */
+ ATF_REQUIRE(fetestexcept(FE_INVALID) == 0);
+}
+
+ATF_TC_WITHOUT_HEAD(rounding_tests);
+ATF_TC_BODY(rounding_tests, tc)
+{
+ long double ld = 0.0;
+ double d = 0.0;
+
+ ATF_REQUIRE(setlocale(LC_NUMERIC, "C"));
+
+ fesetround(FE_DOWNWARD);
+
+ sscanf("1.999999999999999999999999999999999", "%le", &d);
+ ATF_REQUIRE(d < 2.0);
+ sscanf("0x1.ffffffffffffffp0", "%le", &d);
+ ATF_REQUIRE(d < 2.0);
+ sscanf("1.999999999999999999999999999999999", "%Le", &ld);
+ ATF_REQUIRE(ld < 2.0);
+
+ sscanf("1.0571892669084007", "%le", &d);
+ ATF_REQUIRE(d == 0x1.0ea3f4af0dc59p0);
+ sscanf("-1.0571892669084007", "%le", &d);
+ ATF_REQUIRE(d == -0x1.0ea3f4af0dc5ap0);
+ sscanf("1.0571892669084010", "%le", &d);
+ ATF_REQUIRE(d == 0x1.0ea3f4af0dc5ap0);
+
+ sscanf("0x1.23p-5000", "%le", &d);
+ ATF_REQUIRE(d == 0.0);
+
+ sscanf("0x1.2345678p-1050", "%le", &d);
+ ATF_REQUIRE(d == 0x1.234567p-1050);
+
+ fesetround(FE_UPWARD);
+
+ sscanf("1.0571892669084007", "%le", &d);
+ ATF_REQUIRE(d == 0x1.0ea3f4af0dc5ap0);
+ sscanf("-1.0571892669084007", "%le", &d);
+ ATF_REQUIRE(d == -0x1.0ea3f4af0dc59p0);
+ sscanf("1.0571892669084010", "%le", &d);
+ ATF_REQUIRE(d == 0x1.0ea3f4af0dc5bp0);
+
+ sscanf("0x1.23p-5000", "%le", &d);
+ ATF_REQUIRE(d == 0x1p-1074);
+
+ sscanf("0x1.2345678p-1050", "%le", &d);
+ ATF_REQUIRE(d == 0x1.234568p-1050);
+
+ fesetround(FE_TOWARDZERO);
+
+ sscanf("1.0571892669084007", "%le", &d);
+ ATF_REQUIRE(d == 0x1.0ea3f4af0dc59p0);
+ sscanf("-1.0571892669084007", "%le", &d);
+ ATF_REQUIRE(d == -0x1.0ea3f4af0dc59p0);
+ sscanf("1.0571892669084010", "%le", &d);
+ ATF_REQUIRE(d == 0x1.0ea3f4af0dc5ap0);
+
+ sscanf("0x1.23p-5000", "%le", &d);
+ ATF_REQUIRE(d == 0.0);
+
+ sscanf("0x1.2345678p-1050", "%le", &d);
+ ATF_REQUIRE(d == 0x1.234567p-1050);
+
+ fesetround(FE_TONEAREST);
+
+ /* 1.0571892669084007 is slightly closer to 0x1.0ea3f4af0dc59p0 */
+ sscanf("1.0571892669084007", "%le", &d);
+ ATF_REQUIRE(d == 0x1.0ea3f4af0dc59p0);
+ sscanf("-1.0571892669084007", "%le", &d);
+ ATF_REQUIRE(d == -0x1.0ea3f4af0dc59p0);
+ sscanf("1.0571892669084010", "%le", &d);
+ ATF_REQUIRE(d == 0x1.0ea3f4af0dc5bp0);
+
+ /* strtod() should round small numbers to 0. */
+ sscanf("0x1.23p-5000", "%le", &d);
+ ATF_REQUIRE(d == 0.0);
+
+ /* Extra digits in a denormal shouldn't break anything. */
+ sscanf("0x1.2345678p-1050", "%le", &d);
+ ATF_REQUIRE(d == 0x1.234568p-1050);
+}
+
+ATF_TC_WITHOUT_HEAD(strtod);
+ATF_TC_BODY(strtod, tc)
+{
+ char *endp;
+
+ ATF_REQUIRE(setlocale(LC_NUMERIC, "C"));
+
+ ATF_REQUIRE(strtod("0xy", &endp) == 0);
+ ATF_REQUIRE(strcmp("xy", endp) == 0);
+
+ /* This used to cause an infinite loop and round the wrong way. */
+ fesetround(FE_DOWNWARD);
+ ATF_REQUIRE(strtof("3.5e38", &endp) == FLT_MAX);
+ ATF_REQUIRE(strtod("2e308", &endp) == DBL_MAX);
+ fesetround(FE_UPWARD);
+ ATF_REQUIRE(strtof("3.5e38", &endp) == INFINITY);
+ ATF_REQUIRE(strtod("2e308", &endp) == INFINITY);
+ fesetround(FE_TOWARDZERO);
+ ATF_REQUIRE(strtof("3.5e38", &endp) == FLT_MAX);
+ ATF_REQUIRE(strtod("2e308", &endp) == DBL_MAX);
+ fesetround(FE_TONEAREST);
+ ATF_REQUIRE(strtof("3.5e38", &endp) == INFINITY);
+ ATF_REQUIRE(strtod("2e308", &endp) == INFINITY);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, normalized_numbers);
+ ATF_TP_ADD_TC(tp, infinities_and_nans);
+ ATF_TP_ADD_TC(tp, rounding_tests);
+ ATF_TP_ADD_TC(tp, strtod);
+
+ return (atf_no_error());
+}
Property changes on: trunk/lib/libc/tests/stdio/scanfloat_test.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/stdlib/Makefile
===================================================================
--- trunk/lib/libc/tests/stdlib/Makefile (rev 0)
+++ trunk/lib/libc/tests/stdlib/Makefile 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,66 @@
+# $MidnightBSD$
+# $FreeBSD: stable/10/lib/libc/tests/stdlib/Makefile 313535 2017-02-10 07:13:16Z ngie $
+
+.include <bsd.own.mk>
+
+ATF_TESTS_C+= heapsort_test
+ATF_TESTS_C+= mergesort_test
+ATF_TESTS_C+= qsort_test
+.if ${COMPILER_FEATURES:Mc++11}
+ATF_TESTS_CXX+= cxa_thread_atexit_test
+ATF_TESTS_CXX+= cxa_thread_atexit_nothr_test
+.endif
+
+# Not sure why this isn't defined for all architectures, since most
+# have long double.
+.if ${MACHINE_CPUARCH} == "aarch64" || \
+ ${MACHINE_CPUARCH} == "amd64" || \
+ ${MACHINE_CPUARCH} == "i386"
+CFLAGS+= -D__HAVE_LONG_DOUBLE
+.endif
+
+# TODO: t_getenv_thread, t_mi_vector_hash, t_strtoi
+NETBSD_ATF_TESTS_C+= abs_test
+NETBSD_ATF_TESTS_C+= atoi_test
+NETBSD_ATF_TESTS_C+= div_test
+NETBSD_ATF_TESTS_C+= getenv_test
+NETBSD_ATF_TESTS_C+= exit_test
+NETBSD_ATF_TESTS_C+= hsearch_test
+NETBSD_ATF_TESTS_C+= posix_memalign_test
+NETBSD_ATF_TESTS_C+= random_test
+NETBSD_ATF_TESTS_C+= strtod_test
+NETBSD_ATF_TESTS_C+= strtol_test
+NETBSD_ATF_TESTS_C+= system_test
+
+# TODO: need to come up with a correct explanation of what the patch pho does
+# with h_atexit
+#ATF_TESTS_SH= atexit_test
+NETBSD_ATF_TESTS_SH= getopt_test
+
+.include "../Makefile.netbsd-tests"
+
+BINDIR= ${TESTSDIR}
+
+# TODO: see comment above
+#PROGS+= h_atexit
+PROGS+= h_getopt h_getopt_long
+
+CFLAGS+= -I${.CURDIR}
+
+CXXFLAGS.cxa_thread_atexit_test+= -std=c++11
+CXXFLAGS.cxa_thread_atexit_nothr_test+= -std=c++11
+DPADD.cxa_thread_atexit_test+= ${LIBPTHREAD}
+LDADD.cxa_thread_atexit_test+= -lpthread
+
+.for t in h_getopt h_getopt_long
+CFLAGS.$t+= -I${LIBNETBSD_SRCDIR} -I${SRCTOP}/contrib/netbsd-tests
+LDFLAGS.$t+= -L${LIBNETBSD_OBJDIR}
+
+DPADD.$t+= ${LIBNETBSD} ${LIBUTIL}
+LDADD.$t+= -lnetbsd -lutil
+.endfor
+
+DPADD.strtod_test+= ${LIBM}
+LDADD.strtod_test+= -lm
+
+.include <bsd.test.mk>
Property changes on: trunk/lib/libc/tests/stdlib/Makefile
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/stdlib/cxa_thread_atexit_nothr_test.cc
===================================================================
--- trunk/lib/libc/tests/stdlib/cxa_thread_atexit_nothr_test.cc (rev 0)
+++ trunk/lib/libc/tests/stdlib/cxa_thread_atexit_nothr_test.cc 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,103 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2016 Mahdi Mokhtari <mokhi64 at gmail.com>
+ * Copyright (c) 2016 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/lib/libc/tests/stdlib/cxa_thread_atexit_nothr_test.cc 304527 2016-08-20 12:26:44Z kib $");
+
+#include <dlfcn.h>
+#include <atf-c++.hpp>
+#include <cstdio>
+#include <cstdlib>
+
+static FILE *output = NULL;
+
+struct Foo {
+ Foo() { ATF_REQUIRE(fprintf(output, "Created\n") > 0); }
+ ~Foo() { ATF_REQUIRE(fprintf(output, "Destroyed\n") > 0); }
+ void use() { ATF_REQUIRE(fprintf(output, "Used\n") > 0); }
+};
+
+static thread_local Foo f;
+
+/*
+ * This test must not be linked to libpthread.
+ */
+ATF_TEST_CASE_WITHOUT_HEAD(cxx__nothr);
+ATF_TEST_CASE_BODY(cxx__nothr)
+{
+ void *libthr_handle;
+
+ /* Avoid coredump during f construction. */
+ output = stderr;
+
+ libthr_handle = dlopen("libthr.so.3", RTLD_LAZY | RTLD_GLOBAL |
+ RTLD_NOLOAD);
+ ATF_REQUIRE(libthr_handle == NULL);
+}
+
+static void
+check_local_main(void)
+{
+ static const char out_log[] = "Created\nUsed\nDestroyed\n";
+
+ fflush(output);
+ ATF_REQUIRE(atf::utils::compare_file("test_main.txt", out_log));
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(cxx__thread_local_main);
+ATF_TEST_CASE_BODY(cxx__thread_local_main)
+{
+
+ ATF_REQUIRE((output = fopen("test_main.txt", "w")) != NULL);
+ f.use();
+ atexit(check_local_main);
+}
+
+extern "C" int __cxa_thread_atexit(void (*)(void *), void *, void *);
+
+static void
+again(void *arg)
+{
+
+ __cxa_thread_atexit(again, arg, &output);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(cxx__thread_inf_dtors);
+ATF_TEST_CASE_BODY(cxx__thread_inf_dtors)
+{
+
+ again(NULL);
+}
+
+ATF_INIT_TEST_CASES(tcs)
+{
+
+ ATF_ADD_TEST_CASE(tcs, cxx__nothr);
+ ATF_ADD_TEST_CASE(tcs, cxx__thread_local_main);
+ ATF_ADD_TEST_CASE(tcs, cxx__thread_inf_dtors);
+}
Property changes on: trunk/lib/libc/tests/stdlib/cxa_thread_atexit_nothr_test.cc
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/stdlib/cxa_thread_atexit_test.cc
===================================================================
--- trunk/lib/libc/tests/stdlib/cxa_thread_atexit_test.cc (rev 0)
+++ trunk/lib/libc/tests/stdlib/cxa_thread_atexit_test.cc 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,181 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2016 Mahdi Mokhtari <mokhi64 at gmail.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/lib/libc/tests/stdlib/cxa_thread_atexit_test.cc 304527 2016-08-20 12:26:44Z kib $");
+
+#include <dlfcn.h>
+#include <atf-c++.hpp>
+#include <cstdio>
+#include <cstdlib>
+#include <thread>
+
+static FILE *output = NULL;
+
+struct Foo {
+ Foo() { ATF_REQUIRE(fprintf(output, "Created\n") > 0); }
+ ~Foo() { ATF_REQUIRE(fprintf(output, "Destroyed\n") > 0); }
+ void use() { ATF_REQUIRE(fprintf(output, "Used\n") > 0); }
+};
+
+struct Bar {
+ Bar() {}
+ ~Bar() {
+ thread_local static Foo foo;
+ ATF_REQUIRE(fprintf(output, "DIED\n") > 0);
+ }
+ void use() {}
+};
+
+extern "C" int __cxa_thread_atexit(void (*)(void *), void *, void *);
+
+static void
+again(void *arg)
+{
+
+ __cxa_thread_atexit(again, arg, &output);
+}
+
+struct Baz {
+ Baz() {}
+ ~Baz() {
+ again(NULL);
+ }
+ void use() {}
+};
+
+static thread_local Foo f;
+static thread_local Foo g;
+static thread_local Bar h;
+static thread_local Baz e;
+
+/*
+ * This test must be linked to libpthread.
+ */
+ATF_TEST_CASE_WITHOUT_HEAD(cxx__thr);
+ATF_TEST_CASE_BODY(cxx__thr)
+{
+ void *libthr_handle;
+
+ /* Avoid coredump during f construction. */
+ output = stderr;
+
+ libthr_handle = dlopen("libthr.so.3", RTLD_LAZY | RTLD_GLOBAL |
+ RTLD_NOLOAD);
+ ATF_REQUIRE(libthr_handle != NULL);
+ dlclose(libthr_handle);
+}
+
+/*
+ * In this test f.use() will test cxa_thread_atexit() in non-threaded mode.
+ * After f.use() main will be threaded and we'll have one additional thread
+ * with its own TLS data.
+ */
+ATF_TEST_CASE_WITHOUT_HEAD(cxx__thread_local_before);
+ATF_TEST_CASE_BODY(cxx__thread_local_before)
+{
+ static const char out_log[] = "Created\nCreated\nUsed\nCreated\n"
+ "Created\nUsed\nCreated\nDIED\nDestroyed\nDestroyed\nDestroyed\n";
+
+ ATF_REQUIRE((output = fopen("test_before.txt", "w")) != NULL);
+
+ f.use();
+ std::thread t([]() { f.use(); });
+ t.join();
+
+ fflush(output);
+
+ ATF_REQUIRE(atf::utils::compare_file("test_before.txt", out_log));
+}
+
+/*
+ * In this test, f.use() will test __cxa_thread_atexit()
+ * in threaded mode (but still in main-threaed).
+ */
+ATF_TEST_CASE_WITHOUT_HEAD(cxx__thread_local_after);
+ATF_TEST_CASE_BODY(cxx__thread_local_after)
+{
+ static const char out_log[] = "Created\nCreated\nUsed\nCreated\n"
+ "DIED\nDestroyed\nDestroyed\nDestroyed\nCreated\nCreated\nUsed\n";
+
+ ATF_REQUIRE((output = fopen("test_after.txt", "w")) != NULL);
+
+ std::thread t([]() { g.use(); });
+ t.join();
+ sleep(1);
+ g.use();
+
+ fflush(output);
+
+ ATF_REQUIRE(atf::utils::compare_file("test_after.txt", out_log));
+}
+
+/*
+ * In this test, we register a new dtor while dtors are being run
+ * in __cxa_thread_atexit().
+ */
+ATF_TEST_CASE_WITHOUT_HEAD(cxx__thread_local_add_while_calling_dtors);
+ATF_TEST_CASE_BODY(cxx__thread_local_add_while_calling_dtors)
+{
+ static const char out_log[] = "Created\nCreated\nCreated\nDIED\n"
+ "Destroyed\nDestroyed\nDestroyed\n";
+
+ ATF_REQUIRE((output = fopen("test_add_meanwhile.txt", "w")) != NULL);
+
+ std::thread t([]() { h.use(); });
+ t.join();
+ sleep(1);
+
+ fflush(output);
+
+ ATF_REQUIRE(atf::utils::compare_file("test_add_meanwhile.txt", out_log));
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(cxx__thread_inf_dtors);
+ATF_TEST_CASE_BODY(cxx__thread_inf_dtors)
+{
+
+ /*
+ * Only added to make isolated run of this test not
+ * coredumping. Construction of Foo objects require filled
+ * output.
+ */
+ output = stderr;
+
+ std::thread t([]() { e.use(); });
+ t.join();
+}
+
+ATF_INIT_TEST_CASES(tcs)
+{
+
+ ATF_ADD_TEST_CASE(tcs, cxx__thr);
+ ATF_ADD_TEST_CASE(tcs, cxx__thread_local_before);
+ ATF_ADD_TEST_CASE(tcs, cxx__thread_local_after);
+ ATF_ADD_TEST_CASE(tcs, cxx__thread_local_add_while_calling_dtors);
+ ATF_ADD_TEST_CASE(tcs, cxx__thread_inf_dtors);
+}
Property changes on: trunk/lib/libc/tests/stdlib/cxa_thread_atexit_test.cc
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/stdlib/heapsort_test.c
===================================================================
--- trunk/lib/libc/tests/stdlib/heapsort_test.c (rev 0)
+++ trunk/lib/libc/tests/stdlib/heapsort_test.c 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,72 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (C) 2004 Maxim Sobolev <sobomax at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Test for heapsort() routine.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/lib/libc/tests/stdlib/heapsort_test.c 290876 2015-11-15 20:11:55Z ngie $");
+
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "test-sort.h"
+
+ATF_TC_WITHOUT_HEAD(heapsort_test);
+ATF_TC_BODY(heapsort_test, tc)
+{
+ int sresvector[IVEC_LEN];
+ int testvector[IVEC_LEN];
+ int i, j;
+
+ for (j = 2; j < IVEC_LEN; j++) {
+ /* Populate test vectors */
+ for (i = 0; i < j; i++)
+ testvector[i] = sresvector[i] = initvector[i];
+
+ /* Sort using heapsort(3) */
+ heapsort(testvector, j, sizeof(testvector[0]), sorthelp);
+ /* Sort using reference slow sorting routine */
+ ssort(sresvector, j);
+
+ /* Compare results */
+ for (i = 0; i < j; i++)
+ ATF_CHECK_MSG(testvector[i] == sresvector[i],
+ "item at index %d didn't match: %d != %d",
+ i, testvector[i], sresvector[i]);
+ }
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, heapsort_test);
+
+ return (atf_no_error());
+}
Property changes on: trunk/lib/libc/tests/stdlib/heapsort_test.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/stdlib/mergesort_test.c
===================================================================
--- trunk/lib/libc/tests/stdlib/mergesort_test.c (rev 0)
+++ trunk/lib/libc/tests/stdlib/mergesort_test.c 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,72 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (C) 2004 Maxim Sobolev <sobomax at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Test for mergesort() routine.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/lib/libc/tests/stdlib/mergesort_test.c 290876 2015-11-15 20:11:55Z ngie $");
+
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "test-sort.h"
+
+ATF_TC_WITHOUT_HEAD(mergesort_test);
+ATF_TC_BODY(mergesort_test, tc)
+{
+ int sresvector[IVEC_LEN];
+ int testvector[IVEC_LEN];
+ int i, j;
+
+ for (j = 2; j < IVEC_LEN; j++) {
+ /* Populate test vectors */
+ for (i = 0; i < j; i++)
+ testvector[i] = sresvector[i] = initvector[i];
+
+ /* Sort using mergesort(3) */
+ mergesort(testvector, j, sizeof(testvector[0]), sorthelp);
+ /* Sort using reference slow sorting routine */
+ ssort(sresvector, j);
+
+ /* Compare results */
+ for (i = 0; i < j; i++)
+ ATF_CHECK_MSG(testvector[i] == sresvector[i],
+ "item at index %d didn't match: %d != %d",
+ i, testvector[i], sresvector[i]);
+ }
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, mergesort_test);
+
+ return (atf_no_error());
+}
Property changes on: trunk/lib/libc/tests/stdlib/mergesort_test.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/stdlib/qsort_test.c
===================================================================
--- trunk/lib/libc/tests/stdlib/qsort_test.c (rev 0)
+++ trunk/lib/libc/tests/stdlib/qsort_test.c 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,72 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (C) 2004 Maxim Sobolev <sobomax at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Test for qsort() routine.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/lib/libc/tests/stdlib/qsort_test.c 290876 2015-11-15 20:11:55Z ngie $");
+
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "test-sort.h"
+
+ATF_TC_WITHOUT_HEAD(qsort_test);
+ATF_TC_BODY(qsort_test, tc)
+{
+ int testvector[IVEC_LEN];
+ int sresvector[IVEC_LEN];
+ int i, j;
+
+ for (j = 2; j < IVEC_LEN; j++) {
+ /* Populate test vectors */
+ for (i = 0; i < j; i++)
+ testvector[i] = sresvector[i] = initvector[i];
+
+ /* Sort using qsort(3) */
+ qsort(testvector, j, sizeof(testvector[0]), sorthelp);
+ /* Sort using reference slow sorting routine */
+ ssort(sresvector, j);
+
+ /* Compare results */
+ for (i = 0; i < j; i++)
+ ATF_CHECK_MSG(testvector[i] == sresvector[i],
+ "item at index %d didn't match: %d != %d",
+ i, testvector[i], sresvector[i]);
+ }
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, qsort_test);
+
+ return (atf_no_error());
+}
Property changes on: trunk/lib/libc/tests/stdlib/qsort_test.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/stdlib/test-sort.h
===================================================================
--- trunk/lib/libc/tests/stdlib/test-sort.h (rev 0)
+++ trunk/lib/libc/tests/stdlib/test-sort.h 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,274 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (C) 2004 Maxim Sobolev <sobomax at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: stable/10/lib/libc/tests/stdlib/test-sort.h 290876 2015-11-15 20:11:55Z ngie $
+ */
+
+#ifndef _TEST_SORT_H
+#define _TEST_SORT_H
+
+#include <sys/param.h>
+
+#include <atf-c.h>
+
+static int
+sorthelp(const void *a, const void *b)
+{
+ const int *oa, *ob;
+
+ oa = a;
+ ob = b;
+ /* Don't use "return *oa - *ob" since it's easy to cause overflow! */
+ if (*oa > *ob)
+ return (1);
+ if (*oa < *ob)
+ return (-1);
+ return (0);
+}
+
+/* Reference sorting routine (slooow!) */
+static void
+ssort(int v[], int nmemb)
+{
+ int i, j, k;
+
+ for (i = 0; i < nmemb; i++) {
+ for (j = i + 1; j < nmemb; j++) {
+ if (v[j] < v[i]) {
+ k = v[i];
+ v[i] = v[j];
+ v[j] = k;
+ }
+ }
+ }
+}
+
+/* Some random data */
+static int initvector[1024] = {
+ 599853225, 371951333, -428880425, 1450668530, 85530178, -460170550,
+ -270680269, 717137591, 106244401, -1138072905, -113532586,
+ 599690958, 464993720, 107690177, 24249019, -1151018550, 794225588,
+ 1494905642, -62951716, -734531757, 1197251494, 1020063925,
+ -634536734, -216634704, 617366508, -18840190, 481010395,
+ -1555785724, 128221950, -1747743676, 1119012320, -252160437,
+ 617137855, 1159833073, -106647920, -1570719046, -769400990,
+ -130308848, 1186546396, 215253591, 445832488, 160263176, 777264170,
+ -274636650, -696134447, 1057957088, -626175254, 188632134,
+ -98941793, -1602334908, -373717125, 885013862, 571258221,
+ -399572192, 407761463, -733249776, 12094800, -367046815, 178974501,
+ -452638559, -516580143, -94282073, 1411115180, -1151792797,
+ 1442815268, 1106583674, 515269284, -74019972, 598818901, 696848474,
+ -657910766, -287309335, 1538095746, 143543003, 851444033,
+ -947573348, 296222973, 1339592140, -947505360, 872027891,
+ -418844714, -583075597, -324758197, -964531573, 1016795914,
+ -866842580, -304084402, -286930819, 338975583, 803597943,
+ -452483372, 1525283506, -1185830826, -596405894, 905191340,
+ -1638026278, 106749913, 582771197, -730713796, 56052422,
+ 1498040174, 644967266, 182541575, 280483468, -1932835017,
+ -435546874, 940106007, 1753388509, -340355019, -231577358,
+ -714879035, 1051182949, 204261785, 1321346243, -895289878,
+ -240369893, 566608506, -350777580, -1384849829, -876816409,
+ 1013787299, -1408035937, -222626650, 1708168486, -645148461,
+ 1854654, -393012507, 179327030, -1607975548, -715202732, 730588290,
+ 246968517, -550975254, -101136772, -174103176, 1188941016,
+ 2004650834, -1501389866, -2021225998, 1219042515, -464113898,
+ 268565342, 126451123, -1045877126, -198918003, 310177444,
+ 1578314812, 1828867082, 453336898, -908485523, 749777130,
+ -1028565802, 61360571, 241484853, -175693399, 1816211059,
+ 533940889, -1496933703, 385185125, -821132413, -8923391,
+ -1429546239, 46190992, 449247332, -20432494, 778761611, -178782699,
+ -811194695, -632276211, 70196094, 890817525, -1447776908,
+ -323783741, -62333222, 954929503, 247668507, -1394420605,
+ 367913886, 1364926759, 1298781924, 357923028, -73644747,
+ -319744305, 61718202, -1454549286, 387493522, 2018321449,
+ 861026653, 289973298, 1755939093, -84772204, 43425266, -1325753781,
+ -679938775, 1228500370, -763816405, 548903035, 1765563727,
+ 425183052, 1424621863, -188287424, 554385654, 751831998,
+ 1377088085, 66622090, 139224450, -1305816167, 650140724, 593988868,
+ -444913321, 589045097, 1261428989, 101292769, -780376786,
+ 559307348, 1644593236, -1838606833, 53570301, -680576100,
+ -44969538, 268718267, -632104125, 276904628, 626299449, -11761453,
+ 545899086, -1027343598, -432251872, 539353494, -399575006,
+ -568383580, -677802882, 1296513472, 801202048, 806425805, 1983363,
+ 850487421, 38046173, 1535399484, 1998285544, -1301751898,
+ -46561973, 56545408, -1107662676, 456041145, -452923904,
+ -262219453, -371849200, 392524281, 1650231392, 1185585356,
+ 126610511, -1125389657, 1015981177, -1318481342, -213835789,
+ 1263484054, -654361441, 1408272041, -231555284, -1121778152,
+ -395512897, 332277674, -349703586, 1809474399, -223731607,
+ -1342224737, 736165236, 67535587, 89879082, 471445838, 423788300,
+ -384354470, 907475706, 154886390, -1406736539, -8558766,
+ -203405718, -422127884, 1048520863, 747418501, 87438975, 727668160,
+ -914936981, 428266976, -455742009, -949014605, 487159058,
+ -262526850, -309451504, -76928461, 1072951428, -1370953830,
+ 238231681, -1831047244, -405735199, -35941848, 469048670,
+ 505307987, -660553590, 876537439, -314195871, 999234339,
+ -1405846240, -579885695, 629067031, 863481510, -742301385,
+ -1723403128, -153070386, 782682839, -343111818, -877101810,
+ 1438467302, -319951459, -1585702508, -338381888, 484108815,
+ -1726935191, -749923706, 1657932127, -816151395, -566321865,
+ -133542331, 84961164, 598275578, 1302065347, -533098653,
+ -1766383037, 53169714, -464201288, 617735133, 862536123,
+ -141730724, -1967377125, -1023736305, -1012511106, 64484992,
+ -1250856831, 426409332, -355670055, -298251663, -867634978,
+ -776124819, 74018333, -425385214, -108004251, -1192766130,
+ 1294193867, -109867195, -78667637, 1164855393, -826007552,
+ -522528066, 1160283046, -1095276403, -1218917472, -396475366,
+ -77394733, -425603169, 251928357, -393559355, 1488845184,
+ 898455978, -773338691, -37627855, -345014717, 204298578, 209084274,
+ 1047080643, -414348222, 26496664, 705759824, 575149152, 604904761,
+ 624988690, 1446041250, 1000757225, -1354896151, 1422958189,
+ -1607165311, -832757521, 365074225, 1171764999, 1200795217,
+ -203957828, 23166236, -846818698, -547439867, -790192498,
+ -122123561, 914298013, 66225525, -36163174, -480698856,
+ -1269421818, 624641703, 254923102, 1564329013, -583609221,
+ -649433551, -743396069, 1182455435, 102658744, 285599336,
+ 692480463, -852737563, -660090184, 1374350065, 72300985, 690541659,
+ -1194212957, -1151816525, 157415641, 487398246, 1030153072,
+ 933723020, 1359181027, -1303457764, -1543773272, 774306017,
+ -854382652, 755485667, -864943584, -63242545, -1271480354,
+ 157720215, -205001173, 889984130, -581583822, -473779111,
+ -932136577, 735326252, 428638717, 1888884222, 561493709,
+ -1966427364, -1710208603, 340121869, 918894036, 927172509,
+ 904178436, 1476687667, 90796414, 651591731, -550913123, -42218158,
+ 637756529, 1091478400, 124976584, -48739309, -798898083, 393581349,
+ -1078624722, -789291577, 1010582542, -512317005, 1222773656,
+ 466454593, 1183558811, 822782663, -851624703, -850404012,
+ 1473672600, 852527073, 1073953362, 137635828, 936104739, -86567759,
+ -882563252, 1845232980, -737978404, -104703380, 149802989,
+ -349118325, 1479797538, 1966007488, 1254228842, 414304661,
+ -790805785, 31583329, -76864151, 558202855, -1447047313, 716720607,
+ -404224238, -54107627, 1747385914, -657407390, 202940208,
+ 1083067056, -532861378, 163426933, -130289277, 1301785258,
+ -302920320, -637947485, -644895903, -1668027530, 391890467,
+ -126586485, -536836984, -1154536413, -339505118, -1187229462,
+ -670985870, -601310813, -1350055158, -482479784, 139847714,
+ -253955849, 5190414, -542857077, 1175835684, -584165057,
+ 1132775766, -592091269, -891445655, -340995936, 736395810,
+ 779967964, 515095845, -1138437307, -259226729, -167820100,
+ -801611617, -282451622, -1313679283, -1436126694, 1258773990,
+ -717601098, -583559645, -1307478759, 1238647247, 1589011223,
+ -1029216445, -107030650, 400152690, -1349079913, 1428582247,
+ 21546946, 208807686, -169450574, -1086213374, -1242715198,
+ 669098277, 416626722, -1122525014, -1389466669, -391843085,
+ -56318357, 421040094, 212303518, 738666684, -1185364904,
+ -506192760, 646735912, -1424722633, 745226976, 1019191717,
+ -190891744, -310320868, -373655022, -665117060, 830760000,
+ 583906512, -330536027, 611092636, -321344259, -1255008904,
+ -777959046, -523043472, 88896910, 346062204, -163734816, 336635665,
+ 906060268, -128891583, 740952564, 916767203, 296514859, 198670559,
+ 358136672, -152253676, 12038867, -1469916749, -1020980597,
+ -897143313, 354240970, -97959800, 814172811, 1983363241, 264990663,
+ 105154676, 1060463014, 430172143, 375111946, -824526943,
+ -708877751, -1377442616, -236559551, 684724584, 1602131358,
+ -42140186, -763499840, -605167, 98575879, -376577598, 1689746083,
+ -777973879, -1396984691, -187780326, 281040966, 1858859521,
+ 158395760, 1022807978, -218458812, 811779708, 1495113833,
+ 1192561226, 629539535, -1365196683, -1120253162, 1091681956,
+ 134286445, 1172218369, -34093658, -137087343, -27869226,
+ -180889478, 55705436, 52362743, -1745516232, -926564477,
+ -513701675, -1666272054, 1457952810, 843953275, -478275722,
+ -1240291080, 101859661, -1606687523, 916365333, 314713310,
+ -22002688, 1019022641, -1171741314, -129050627, -211955813,
+ -1020176299, 1357865293, -609819628, 724533854, -1141449545,
+ 22285231, -97731145, -302329687, 191910894, -1300709885,
+ -644951895, 640448036, -1289009824, 1445456129, 846416471,
+ 1821291740, -1639640821, -712724532, -447475807, 132156847,
+ 258067455, 324301319, 278586969, -1544082357, 636007277, 977122066,
+ 127462480, 365126129, 1086276825, -432124148, 896598926,
+ -388550179, 273357331, -845018695, -1089465389, 384439820,
+ -558419772, 1476422025, 730712769, 190665059, -764968927,
+ -789708218, 637873581, 348429858, 1386000168, -638123594,
+ -842010345, -607926448, 19535163, -742771490, -18323344, 246155488,
+ 350409468, 1290907730, -492566468, 300358636, 501876267, 252441807,
+ 1233551975, -1431067042, 517177374, -1540299707, -948380761,
+ 1253997663, 693795998, 148707823, 152894502, 98729538, -30042824,
+ -563057441, 723726409, 367338961, 1395435261, 217868876,
+ 1220652431, 953572083, -1134905155, -734486813, -587470130,
+ -864647866, 1030737023, 781798521, -321076732, -460548153,
+ 122681678, -873728847, -1286304399, -75472885, 113390881,
+ -1556849198, -1070802176, 924389470, 957478910, 5974049, 709413506,
+ 476334647, 572869787, 776298405, -8822420, -99326499, -707855342,
+ -1187216303, 668038414, 262454769, -1120293198, -32011040,
+ 249812104, -101835410, 1082281087, -570183855, -954535179,
+ 1384361473, -983199686, 2017611313, 328926483, -878162849,
+ -1202254181, -225604951, 966898955, 247213529, -1257544612,
+ -197005970, -1039902730, -1947925142, 1752780907, -313410699,
+ -464474556, 416580338, -1063356643, -292212702, 57509168,
+ 1034124629, 1059212593, 468522867, 845369497, 1872717306,
+ -1216544764, -1419907623, 1376869956, -66585488, -1590974467,
+ -367070705, -1456529060, 791844031, 336217635, -1106832215,
+ 1476739427, -751018210, -1411671555, -1880387375, -1714242595,
+ 1169006474, -479442380, -892267555, -1471250266, -267888858,
+ 808634418, 1324777189, -585449929, 1127186951, 468768901,
+ -2002989138, -52352849, 186493053, 1258464606, 117157186,
+ 445919258, 908401949, -1112221136, 863904453, -942718649,
+ 796754809, -38943966, -781978872, -56814078, 1273857459,
+ -1781920832, 209979504, 811828269, -1150814437, 850061883,
+ -532968763, 252506408, -885025629, 391567580, -1295702482,
+ 574894420, 1462248349, 1622584325, -88443443, -1122006092,
+ -169758578, 456282338, -443233309, 436693483, -956563815,
+ -480221349, 435252860, -1114099391, 1060053979, -470893945,
+ -1273682879, -734596176, 639950927, -1278648701, 306274747,
+ -410562146, 1137869228, -1970746553, 1313830798, 1248071822,
+ -247297704, 1015218053, -1607348116, -261817613, -821413148,
+ -782942639, -628711083, 240953091, -629550668, -1584736319,
+ 856616893, -186759752, 197905373, 541638393, 603407919, -278480495,
+ 410077039, 544065371, -1509627427, 402918436, -450463799,
+ -131169308, 249920630, 1079548609, -927911828, 1444577689,
+ -353002528, -224292462, 1247795279, -790844631, -40427503,
+ 59829765, -332587567, 1319862109, -1261340753, 121711726,
+ 1342756342, -643495787, 100326201, -934436714, -69134888,
+ -898880561, -379524737, -577234570, -805827092, -1575493557,
+ -289920678, -476605057, 1235714994, -317239591, 418553949,
+ 410053338, -204985448, 1206503615, 202610372, -932244873,
+ 782207875, -288661931, -806814809, 1270953679, 2060991595,
+ -311412846, 327279979, 1148562672, 55239149, -610114433,
+ -1511688434, 87619740, -433503545, 326150519, -581293393,
+ -97417688, -289736140, -1543886029, -1251976119, 1585774446,
+ 1570011421, 432602745, 486343696, -834680922, 265004849,
+ -1132107706, 502627197, -815873818, 249635389, 1985714127,
+ -1095817653, -130743522, -645266828, -334621094, 199921747,
+ 1059256177, 378031303, 1519740920, 925540689, 1405957844,
+ 1387748290, -56138046, -770637828, -187984510, -1361735163,
+ 1294823206, -608941238, 451860688, -510549867, 1143516283,
+ -779090703, 1459305047, -600335915, -1684168049, 1516622316,
+ -631733335, -4360068, 499778796, 587600402, -1296000335, -37959743,
+ -1084203927, 1162902556, 246374600, -515103645, 341724568,
+ -702303954, 452229900, 485108287, 1170048553, -1510148355,
+ 611133912, 1997927484, -142022671, -724776653, -336090522,
+ 708283514, -1409637378, -2052637687, 376055110, 226628105,
+ -1714452033, -1776158002, 369167930, 1800807012, 710680889,
+ -69951947, -1223849766, -1862239787, 218536127, -656411794,
+ -1202269188, 609634805, -224425858, 519797951, 284223080,
+ 869408930, 270750206, -544967439, 2097168510, 31650971, -600985417,
+ -165303097, -257809088, -1043223971, 1827891621, -156827355,
+ 499719603
+};
+
+#define IVEC_LEN (nitems(initvector))
+
+#endif
Property changes on: trunk/lib/libc/tests/stdlib/test-sort.h
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/string/Makefile
===================================================================
--- trunk/lib/libc/tests/string/Makefile (rev 0)
+++ trunk/lib/libc/tests/string/Makefile 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,37 @@
+# $MidnightBSD$
+# $FreeBSD: stable/10/lib/libc/tests/string/Makefile 313488 2017-02-09 22:49:48Z ngie $
+
+ATF_TESTS_C+= stpncpy_test
+ATF_TESTS_C+= strerror2_test
+ATF_TESTS_C+= wcscasecmp_test
+ATF_TESTS_C+= wcsnlen_test
+
+# TODO: popcount, stresep
+
+NETBSD_ATF_TESTS_C+= memchr_test
+NETBSD_ATF_TESTS_C+= memcpy_test
+NETBSD_ATF_TESTS_C+= memmem_test
+NETBSD_ATF_TESTS_C+= memset_test
+NETBSD_ATF_TESTS_C+= strcat_test
+NETBSD_ATF_TESTS_C+= strchr_test
+NETBSD_ATF_TESTS_C+= strcmp_test
+NETBSD_ATF_TESTS_C+= strcpy_test
+NETBSD_ATF_TESTS_C+= strcspn_test
+NETBSD_ATF_TESTS_C+= strerror_test
+NETBSD_ATF_TESTS_C+= strlen_test
+NETBSD_ATF_TESTS_C+= strpbrk_test
+NETBSD_ATF_TESTS_C+= strrchr_test
+NETBSD_ATF_TESTS_C+= strspn_test
+NETBSD_ATF_TESTS_C+= swab_test
+
+SRCS.strerror2_test= strerror_test.c
+
+.include "../Makefile.netbsd-tests"
+
+LDADD.memchr_test+= -lmd
+DPADD.memchr_test+= ${LIBMD}
+
+LDADD.memcpy_test+= -lmd
+DPADD.memcpy_test+= ${LIBMD}
+
+.include <bsd.test.mk>
Property changes on: trunk/lib/libc/tests/string/Makefile
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/string/stpncpy_test.c
===================================================================
--- trunk/lib/libc/tests/string/stpncpy_test.c (rev 0)
+++ trunk/lib/libc/tests/string/stpncpy_test.c 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,111 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2009 David Schultz <das at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/lib/libc/tests/string/stpncpy_test.c 290875 2015-11-15 20:08:34Z ngie $");
+
+#include <sys/param.h>
+#include <sys/mman.h>
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <atf-c.h>
+
+static char *
+makebuf(size_t len, int guard_at_end)
+{
+ char *buf;
+ size_t alloc_size = roundup2(len, PAGE_SIZE) + PAGE_SIZE;
+
+ buf = mmap(NULL, alloc_size, PROT_READ | PROT_WRITE, MAP_ANON, -1, 0);
+ assert(buf);
+ if (guard_at_end) {
+ assert(munmap(buf + alloc_size - PAGE_SIZE, PAGE_SIZE) == 0);
+ return (buf + alloc_size - PAGE_SIZE - len);
+ } else {
+ assert(munmap(buf, PAGE_SIZE) == 0);
+ return (buf + PAGE_SIZE);
+ }
+}
+
+static void
+test_stpncpy(const char *s)
+{
+ char *src, *dst;
+ size_t size, len, bufsize, x;
+ int i, j;
+
+ size = strlen(s) + 1;
+ for (i = 0; i <= 1; i++) {
+ for (j = 0; j <= 1; j++) {
+ for (bufsize = 0; bufsize <= size + 10; bufsize++) {
+ src = makebuf(size, i);
+ memcpy(src, s, size);
+ dst = makebuf(bufsize, j);
+ memset(dst, 'X', bufsize);
+ len = (bufsize < size) ? bufsize : size - 1;
+ assert(stpncpy(dst, src, bufsize) == dst+len);
+ assert(memcmp(src, dst, len) == 0);
+ for (x = len; x < bufsize; x++)
+ assert(dst[x] == '\0');
+ }
+ }
+ }
+}
+
+ATF_TC_WITHOUT_HEAD(nul);
+ATF_TC_BODY(nul, tc)
+{
+
+ test_stpncpy("");
+}
+
+ATF_TC_WITHOUT_HEAD(foo);
+ATF_TC_BODY(foo, tc)
+{
+
+ test_stpncpy("foo");
+}
+
+ATF_TC_WITHOUT_HEAD(glorp);
+ATF_TC_BODY(glorp, tc)
+{
+
+ test_stpncpy("glorp");
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, nul);
+ ATF_TP_ADD_TC(tp, foo);
+ ATF_TP_ADD_TC(tp, glorp);
+
+ return (atf_no_error());
+}
Property changes on: trunk/lib/libc/tests/string/stpncpy_test.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/string/strerror_test.c
===================================================================
--- trunk/lib/libc/tests/string/strerror_test.c (rev 0)
+++ trunk/lib/libc/tests/string/strerror_test.c 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,207 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2001 Wes Peters <wes at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: stable/10/lib/libc/tests/string/strerror_test.c 290875 2015-11-15 20:08:34Z ngie $
+ */
+
+#include <assert.h>
+#include <errno.h>
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <atf-c.h>
+
+static char buf[64];
+static char *sret;
+static int iret;
+
+ATF_TC_WITHOUT_HEAD(strerror_unknown_error);
+ATF_TC_BODY(strerror_unknown_error, tc)
+{
+
+ errno = 0;
+ sret = strerror(INT_MAX);
+ snprintf(buf, sizeof(buf), "Unknown error: %d", INT_MAX);
+ ATF_CHECK(strcmp(sret, buf) == 0);
+ ATF_CHECK(errno == EINVAL);
+}
+
+ATF_TC_WITHOUT_HEAD(strerror_no_error);
+ATF_TC_BODY(strerror_no_error, tc)
+{
+
+ errno = 0;
+ sret = strerror(0);
+ ATF_CHECK(strcmp(sret, "No error: 0") == 0);
+ ATF_CHECK(errno == 0);
+}
+
+ATF_TC_WITHOUT_HEAD(strerror_EPERM_test);
+ATF_TC_BODY(strerror_EPERM_test, tc)
+{
+
+ errno = 0;
+ sret = strerror(EPERM);
+ ATF_CHECK(strcmp(sret, "Operation not permitted") == 0);
+ ATF_CHECK(errno == 0);
+}
+
+ATF_TC_WITHOUT_HEAD(strerror_EPFNOSUPPORT_test);
+ATF_TC_BODY(strerror_EPFNOSUPPORT_test, tc)
+{
+
+ errno = 0;
+ sret = strerror(EPFNOSUPPORT);
+ ATF_CHECK(strcmp(sret, "Protocol family not supported") == 0);
+ ATF_CHECK(errno == 0);
+}
+
+ATF_TC_WITHOUT_HEAD(strerror_ELAST_test);
+ATF_TC_BODY(strerror_ELAST_test, tc)
+{
+
+ errno = 0;
+ sret = strerror(ELAST);
+ ATF_CHECK(errno == 0);
+}
+
+ATF_TC_WITHOUT_HEAD(strerror_r__unknown_error);
+ATF_TC_BODY(strerror_r__unknown_error, tc)
+{
+
+ memset(buf, '*', sizeof(buf));
+ iret = strerror_r(-1, buf, sizeof(buf));
+ ATF_CHECK(strcmp(buf, "Unknown error: -1") == 0);
+ ATF_CHECK(iret == EINVAL);
+}
+
+ATF_TC_WITHOUT_HEAD(strerror_r__EPERM_one_byte_short);
+ATF_TC_BODY(strerror_r__EPERM_one_byte_short, tc)
+{
+
+ memset(buf, '*', sizeof(buf));
+ /* One byte too short. */
+ iret = strerror_r(EPERM, buf, strlen("Operation not permitted"));
+ ATF_CHECK(strcmp(buf, "Operation not permitte") == 0);
+ ATF_CHECK(iret == ERANGE);
+}
+
+ATF_TC_WITHOUT_HEAD(strerror_r__EPERM_unknown_error_one_byte_short);
+ATF_TC_BODY(strerror_r__EPERM_unknown_error_one_byte_short, tc)
+{
+
+ memset(buf, '*', sizeof(buf));
+ /* One byte too short. */
+ iret = strerror_r(-1, buf, strlen("Unknown error: -1"));
+ ATF_CHECK(strcmp(buf, "Unknown error: -") == 0);
+ ATF_CHECK(iret == EINVAL);
+}
+
+ATF_TC_WITHOUT_HEAD(strerror_r__EPERM_unknown_error_two_bytes_short);
+ATF_TC_BODY(strerror_r__EPERM_unknown_error_two_bytes_short, tc)
+{
+
+ memset(buf, '*', sizeof(buf));
+ /* Two bytes too short. */
+ iret = strerror_r(-2, buf, strlen("Unknown error: -2") - 1);
+ ATF_CHECK(strcmp(buf, "Unknown error: ") == 0);
+ ATF_CHECK(iret == EINVAL);
+}
+
+ATF_TC_WITHOUT_HEAD(strerror_r__EPERM_unknown_error_three_bytes_short);
+ATF_TC_BODY(strerror_r__EPERM_unknown_error_three_bytes_short, tc)
+{
+
+ memset(buf, '*', sizeof(buf));
+ /* Three bytes too short. */
+ iret = strerror_r(-2, buf, strlen("Unknown error: -2") - 2);
+ ATF_CHECK(strcmp(buf, "Unknown error:") == 0);
+ ATF_CHECK(iret == EINVAL);
+}
+
+ATF_TC_WITHOUT_HEAD(strerror_r__EPERM_unknown_error_12345_one_byte_short);
+ATF_TC_BODY(strerror_r__EPERM_unknown_error_12345_one_byte_short, tc)
+{
+
+ memset(buf, '*', sizeof(buf));
+ /* One byte too short. */
+ iret = strerror_r(12345, buf, strlen("Unknown error: 12345"));
+ ATF_CHECK(strcmp(buf, "Unknown error: 1234") == 0);
+ ATF_CHECK(iret == EINVAL);
+}
+
+ATF_TC_WITHOUT_HEAD(strerror_r__no_error);
+ATF_TC_BODY(strerror_r__no_error, tc)
+{
+
+ memset(buf, '*', sizeof(buf));
+ iret = strerror_r(0, buf, sizeof(buf));
+ ATF_CHECK(strcmp(buf, "No error: 0") == 0);
+ ATF_CHECK(iret == 0);
+}
+
+ATF_TC_WITHOUT_HEAD(strerror_r__EDEADLK);
+ATF_TC_BODY(strerror_r__EDEADLK, tc)
+{
+
+ memset(buf, '*', sizeof(buf));
+ iret = strerror_r(EDEADLK, buf, sizeof(buf));
+ ATF_CHECK(strcmp(buf, "Resource deadlock avoided") == 0);
+ ATF_CHECK(iret == 0);
+}
+
+ATF_TC_WITHOUT_HEAD(strerror_r__EPROCLIM);
+ATF_TC_BODY(strerror_r__EPROCLIM, tc)
+{
+
+ memset(buf, '*', sizeof(buf));
+ iret = strerror_r(EPROCLIM, buf, sizeof(buf));
+ ATF_CHECK(strcmp(buf, "Too many processes") == 0);
+ ATF_CHECK(iret == 0);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, strerror_unknown_error);
+ ATF_TP_ADD_TC(tp, strerror_no_error);
+ ATF_TP_ADD_TC(tp, strerror_EPERM_test);
+ ATF_TP_ADD_TC(tp, strerror_EPFNOSUPPORT_test);
+ ATF_TP_ADD_TC(tp, strerror_ELAST_test);
+ ATF_TP_ADD_TC(tp, strerror_r__unknown_error);
+ ATF_TP_ADD_TC(tp, strerror_r__EPERM_one_byte_short);
+ ATF_TP_ADD_TC(tp, strerror_r__EPERM_unknown_error_one_byte_short);
+ ATF_TP_ADD_TC(tp, strerror_r__EPERM_unknown_error_two_bytes_short);
+ ATF_TP_ADD_TC(tp, strerror_r__EPERM_unknown_error_three_bytes_short);
+ ATF_TP_ADD_TC(tp, strerror_r__EPERM_unknown_error_12345_one_byte_short);
+ ATF_TP_ADD_TC(tp, strerror_r__no_error);
+ ATF_TP_ADD_TC(tp, strerror_r__EDEADLK);
+ ATF_TP_ADD_TC(tp, strerror_r__EPROCLIM);
+
+ return (atf_no_error());
+}
Property changes on: trunk/lib/libc/tests/string/strerror_test.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/string/wcscasecmp_test.c
===================================================================
--- trunk/lib/libc/tests/string/wcscasecmp_test.c (rev 0)
+++ trunk/lib/libc/tests/string/wcscasecmp_test.c 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,129 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2009 David Schultz <das at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/lib/libc/tests/string/wcscasecmp_test.c 290875 2015-11-15 20:08:34Z ngie $");
+
+#include <assert.h>
+#include <locale.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <wchar.h>
+#include <wctype.h>
+
+#include <atf-c.h>
+
+ATF_TC_WITHOUT_HEAD(nul);
+ATF_TC_BODY(nul, tc)
+{
+
+ ATF_REQUIRE(setlocale(LC_CTYPE, "C") != NULL);
+
+ ATF_CHECK(wcscasecmp(L"", L"") == 0);
+ ATF_CHECK(wcsncasecmp(L"", L"", 50) == 0);
+ ATF_CHECK(wcsncasecmp(L"", L"", 0) == 0);
+}
+
+ATF_TC_WITHOUT_HEAD(wcscasecmp_equal);
+ATF_TC_BODY(wcscasecmp_equal, tc)
+{
+
+ ATF_REQUIRE(setlocale(LC_CTYPE, "C") != NULL);
+
+ ATF_CHECK(wcscasecmp(L"abc", L"abc") == 0);
+ ATF_CHECK(wcscasecmp(L"ABC", L"ABC") == 0);
+ ATF_CHECK(wcscasecmp(L"abc", L"ABC") == 0);
+ ATF_CHECK(wcscasecmp(L"ABC", L"abc") == 0);
+}
+
+ATF_TC_WITHOUT_HEAD(wcscasecmp_same_len_buffers);
+ATF_TC_BODY(wcscasecmp_same_len_buffers, tc)
+{
+
+ ATF_REQUIRE(setlocale(LC_CTYPE, "C") != NULL);
+
+ ATF_CHECK(wcscasecmp(L"abc", L"xyz") < 0);
+ ATF_CHECK(wcscasecmp(L"ABC", L"xyz") < 0);
+ ATF_CHECK(wcscasecmp(L"abc", L"XYZ") < 0);
+ ATF_CHECK(wcscasecmp(L"ABC", L"XYZ") < 0);
+ ATF_CHECK(wcscasecmp(L"xyz", L"abc") > 0);
+ ATF_CHECK(wcscasecmp(L"XYZ", L"abc") > 0);
+ ATF_CHECK(wcscasecmp(L"xyz", L"ABC") > 0);
+ ATF_CHECK(wcscasecmp(L"XYZ", L"ABC") > 0);
+}
+
+ATF_TC_WITHOUT_HEAD(wcscasecmp_mismatched_len_buffers);
+ATF_TC_BODY(wcscasecmp_mismatched_len_buffers, tc)
+{
+
+ ATF_REQUIRE(setlocale(LC_CTYPE, "C") != NULL);
+
+ ATF_CHECK(wcscasecmp(L"abc", L"ABCD") < 0);
+ ATF_CHECK(wcscasecmp(L"ABC", L"abcd") < 0);
+ ATF_CHECK(wcscasecmp(L"abcd", L"ABC") > 0);
+ ATF_CHECK(wcscasecmp(L"ABCD", L"abc") > 0);
+}
+
+ATF_TC_WITHOUT_HEAD(wcsncasecmp);
+ATF_TC_BODY(wcsncasecmp, tc)
+{
+
+ ATF_REQUIRE(setlocale(LC_CTYPE, "C") != NULL);
+
+ ATF_CHECK(wcsncasecmp(L"abc", L"ABCD", 4) < 0);
+ ATF_CHECK(wcsncasecmp(L"ABC", L"abcd", 4) < 0);
+ ATF_CHECK(wcsncasecmp(L"abcd", L"ABC", 4) > 0);
+ ATF_CHECK(wcsncasecmp(L"ABCD", L"abc", 4) > 0);
+ ATF_CHECK(wcsncasecmp(L"abc", L"ABCD", 3) == 0);
+ ATF_CHECK(wcsncasecmp(L"ABC", L"abcd", 3) == 0);
+}
+
+ATF_TC_WITHOUT_HEAD(wcscasecmp_greek);
+ATF_TC_BODY(wcscasecmp_greek, tc)
+{
+
+ ATF_REQUIRE(setlocale(LC_CTYPE, "C") != NULL);
+
+ ATF_CHECK(wcscasecmp(L"λ", L"Λ") != 0);
+ ATF_REQUIRE(setlocale(LC_CTYPE, "el_GR.UTF-8") != NULL);
+ ATF_CHECK(wcscasecmp(L"λ", L"Λ") == 0);
+ ATF_CHECK(wcscasecmp(L"λ", L"Ω") < 0);
+ ATF_CHECK(wcscasecmp(L"Ω", L"λ") > 0);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, nul);
+ ATF_TP_ADD_TC(tp, wcscasecmp_equal);
+ ATF_TP_ADD_TC(tp, wcscasecmp_same_len_buffers);
+ ATF_TP_ADD_TC(tp, wcscasecmp_mismatched_len_buffers);
+ ATF_TP_ADD_TC(tp, wcsncasecmp);
+ ATF_TP_ADD_TC(tp, wcscasecmp_greek);
+
+ return (atf_no_error());
+}
Property changes on: trunk/lib/libc/tests/string/wcscasecmp_test.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/string/wcsnlen_test.c
===================================================================
--- trunk/lib/libc/tests/string/wcsnlen_test.c (rev 0)
+++ trunk/lib/libc/tests/string/wcsnlen_test.c 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,105 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2009 David Schultz <das at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/lib/libc/tests/string/wcsnlen_test.c 290875 2015-11-15 20:08:34Z ngie $");
+
+#include <sys/param.h>
+#include <sys/mman.h>
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <wchar.h>
+
+#include <atf-c.h>
+
+static void *
+makebuf(size_t len, int guard_at_end)
+{
+ char *buf;
+ size_t alloc_size = roundup2(len, PAGE_SIZE) + PAGE_SIZE;
+
+ buf = mmap(NULL, alloc_size, PROT_READ | PROT_WRITE, MAP_ANON, -1, 0);
+ ATF_CHECK(buf);
+ if (guard_at_end) {
+ ATF_CHECK(munmap(buf + alloc_size - PAGE_SIZE, PAGE_SIZE) == 0);
+ return (buf + alloc_size - PAGE_SIZE - len);
+ } else {
+ ATF_CHECK(munmap(buf, PAGE_SIZE) == 0);
+ return (buf + PAGE_SIZE);
+ }
+}
+
+static void
+test_wcsnlen(const wchar_t *s)
+{
+ wchar_t *s1;
+ size_t size, len, bufsize;
+ int i;
+
+ size = wcslen(s) + 1;
+ for (i = 0; i <= 1; i++) {
+ for (bufsize = 0; bufsize <= size + 10; bufsize++) {
+ s1 = makebuf(bufsize * sizeof(wchar_t), i);
+ wmemcpy(s1, s, bufsize);
+ len = (size > bufsize) ? bufsize : size - 1;
+ ATF_CHECK(wcsnlen(s1, bufsize) == len);
+ }
+ }
+}
+
+ATF_TC_WITHOUT_HEAD(nul);
+ATF_TC_BODY(nul, tc)
+{
+
+ test_wcsnlen(L"");
+}
+
+ATF_TC_WITHOUT_HEAD(foo);
+ATF_TC_BODY(foo, tc)
+{
+
+ test_wcsnlen(L"foo");
+}
+
+ATF_TC_WITHOUT_HEAD(glorp);
+ATF_TC_BODY(glorp, tc)
+{
+
+ test_wcsnlen(L"glorp");
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, nul);
+ ATF_TP_ADD_TC(tp, foo);
+ ATF_TP_ADD_TC(tp, glorp);
+
+ return (atf_no_error());
+}
Property changes on: trunk/lib/libc/tests/string/wcsnlen_test.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/sys/Makefile
===================================================================
--- trunk/lib/libc/tests/sys/Makefile (rev 0)
+++ trunk/lib/libc/tests/sys/Makefile 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,97 @@
+# $MidnightBSD$
+# $FreeBSD: stable/10/lib/libc/tests/sys/Makefile 313535 2017-02-10 07:13:16Z ngie $
+
+.include <bsd.own.mk>
+
+ATF_TESTS_C+= queue_test
+
+# TODO: clone, lwp_create, lwp_ctl, posix_fadvise, recvmmsg,
+# swapcontext
+NETBSD_ATF_TESTS_C+= access_test
+NETBSD_ATF_TESTS_C+= bind_test
+NETBSD_ATF_TESTS_C+= chroot_test
+NETBSD_ATF_TESTS_C+= clock_gettime_test
+NETBSD_ATF_TESTS_C+= connect_test
+NETBSD_ATF_TESTS_C+= dup_test
+NETBSD_ATF_TESTS_C+= fsync_test
+NETBSD_ATF_TESTS_C+= getcontext_test
+NETBSD_ATF_TESTS_C+= getgroups_test
+NETBSD_ATF_TESTS_C+= getitimer_test
+NETBSD_ATF_TESTS_C+= getlogin_test
+NETBSD_ATF_TESTS_C+= getpid_test
+NETBSD_ATF_TESTS_C+= getrusage_test
+NETBSD_ATF_TESTS_C+= getsid_test
+NETBSD_ATF_TESTS_C+= getsockname_test
+NETBSD_ATF_TESTS_C+= gettimeofday_test
+NETBSD_ATF_TESTS_C+= issetugid_test
+NETBSD_ATF_TESTS_C+= kevent_test
+NETBSD_ATF_TESTS_C+= kill_test
+NETBSD_ATF_TESTS_C+= link_test
+NETBSD_ATF_TESTS_C+= listen_test
+NETBSD_ATF_TESTS_C+= mincore_test
+NETBSD_ATF_TESTS_C+= mkdir_test
+NETBSD_ATF_TESTS_C+= mkfifo_test
+NETBSD_ATF_TESTS_C+= mknod_test
+NETBSD_ATF_TESTS_C+= mlock_test
+NETBSD_ATF_TESTS_C+= mmap_test
+NETBSD_ATF_TESTS_C+= mprotect_test
+NETBSD_ATF_TESTS_C+= msgctl_test
+NETBSD_ATF_TESTS_C+= msgget_test
+NETBSD_ATF_TESTS_C+= msgrcv_test
+NETBSD_ATF_TESTS_C+= msgsnd_test
+NETBSD_ATF_TESTS_C+= msync_test
+NETBSD_ATF_TESTS_C+= nanosleep_test
+NETBSD_ATF_TESTS_C+= pipe_test
+NETBSD_ATF_TESTS_C+= pipe2_test
+NETBSD_ATF_TESTS_C+= poll_test
+NETBSD_ATF_TESTS_C+= posix_fallocate_test
+NETBSD_ATF_TESTS_C+= revoke_test
+NETBSD_ATF_TESTS_C+= select_test
+NETBSD_ATF_TESTS_C+= setrlimit_test
+NETBSD_ATF_TESTS_C+= setuid_test
+NETBSD_ATF_TESTS_C+= sigaction_test
+NETBSD_ATF_TESTS_C+= sigqueue_test
+NETBSD_ATF_TESTS_C+= sigtimedwait_test
+NETBSD_ATF_TESTS_C+= socketpair_test
+NETBSD_ATF_TESTS_C+= stat_test
+NETBSD_ATF_TESTS_C+= timer_create_test
+NETBSD_ATF_TESTS_C+= truncate_test
+NETBSD_ATF_TESTS_C+= ucontext_test
+NETBSD_ATF_TESTS_C+= umask_test
+NETBSD_ATF_TESTS_C+= unlink_test
+NETBSD_ATF_TESTS_C+= wait_test
+NETBSD_ATF_TESTS_C+= wait_noproc_test
+NETBSD_ATF_TESTS_C+= wait_noproc_wnohang_test
+NETBSD_ATF_TESTS_C+= write_test
+
+DPADD.getpid_test+= ${LIBPTHREAD}
+LDADD.getpid_test+= -lpthread
+DPADD.timer_create_test+= ${LIBRT}
+LDADD.timer_create_test+= -lrt
+
+CSTD?= c99
+
+.include "../Makefile.netbsd-tests"
+
+SRCS.mlock_test+= mlock_helper.c
+SRCS.setrlimit_test+= mlock_helper.c
+
+.if ${COMPILER_TYPE} == "gcc"
+WARNS?= 3
+.else
+WARNS?= 4
+.endif
+
+FILESGROUPS= FILES truncate_test_FILES
+
+truncate_test_FILES= truncate_test.root_owned
+truncate_test_FILESDIR= ${TESTSDIR}
+truncate_test_FILESMODE= 0600
+truncate_test_FILESOWNER= root
+truncate_test_FILESGRP= wheel
+
+CLEANFILES= truncate_test.root_owned
+truncate_test.root_owned:
+ dd if=/dev/null bs=1 count=1 of=${.TARGET}
+
+.include <bsd.test.mk>
Property changes on: trunk/lib/libc/tests/sys/Makefile
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/sys/mlock_helper.c
===================================================================
--- trunk/lib/libc/tests/sys/mlock_helper.c (rev 0)
+++ trunk/lib/libc/tests/sys/mlock_helper.c 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,115 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (C) 2016 Bryan Drewery <bdrewery at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Helper for mlock(3) to avoid EAGAIN errors
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/lib/libc/tests/sys/mlock_helper.c 315358 2017-03-16 02:04:16Z ngie $");
+
+#include <sys/types.h>
+#include <sys/sysctl.h>
+
+#include <atf-c.h>
+#include <errno.h>
+#include <limits.h>
+#include <stdio.h>
+
+#define VM_MAX_WIRED "vm.max_wired"
+
+static void
+vm_max_wired_sysctl(int *old_value, int *new_value)
+{
+ size_t old_len;
+ size_t new_len = (new_value == NULL ? 0 : sizeof(int));
+
+ if (old_value == NULL)
+ printf("Setting the new value to %d\n", *new_value);
+ else {
+ ATF_REQUIRE_MSG(sysctlbyname(VM_MAX_WIRED, NULL, &old_len,
+ new_value, new_len) == 0,
+ "sysctlbyname(%s) failed: %s", VM_MAX_WIRED, strerror(errno));
+ }
+
+ ATF_REQUIRE_MSG(sysctlbyname(VM_MAX_WIRED, old_value, &old_len,
+ new_value, new_len) == 0,
+ "sysctlbyname(%s) failed: %s", VM_MAX_WIRED, strerror(errno));
+
+ if (old_value != NULL)
+ printf("Saved the old value (%d)\n", *old_value);
+}
+
+void
+set_vm_max_wired(int new_value)
+{
+ FILE *fp;
+ int old_value;
+
+ fp = fopen(VM_MAX_WIRED, "w");
+ if (fp == NULL) {
+ atf_tc_skip("could not open %s for writing: %s",
+ VM_MAX_WIRED, strerror(errno));
+ return;
+ }
+
+ vm_max_wired_sysctl(&old_value, NULL);
+
+ ATF_REQUIRE_MSG(fprintf(fp, "%d", old_value) > 0,
+ "saving %s failed", VM_MAX_WIRED);
+
+ fclose(fp);
+
+ vm_max_wired_sysctl(NULL, &new_value);
+}
+
+void
+restore_vm_max_wired(void)
+{
+ FILE *fp;
+ int saved_max_wired;
+
+ fp = fopen(VM_MAX_WIRED, "r");
+ if (fp == NULL) {
+ perror("fopen failed\n");
+ return;
+ }
+
+ if (fscanf(fp, "%d", &saved_max_wired) != 1) {
+ perror("fscanf failed\n");
+ fclose(fp);
+ return;
+ }
+
+ fclose(fp);
+ printf("old value in %s: %d\n", VM_MAX_WIRED, saved_max_wired);
+
+ if (saved_max_wired == 0) /* This will cripple the test host */
+ return;
+
+ vm_max_wired_sysctl(NULL, &saved_max_wired);
+}
Property changes on: trunk/lib/libc/tests/sys/mlock_helper.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/sys/queue_test.c
===================================================================
--- trunk/lib/libc/tests/sys/queue_test.c (rev 0)
+++ trunk/lib/libc/tests/sys/queue_test.c 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,238 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2015 EMC Corp.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/lib/libc/tests/sys/queue_test.c 291182 2015-11-23 09:22:01Z ngie $");
+
+#include <sys/queue.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <atf-c.h>
+
+ATF_TC(slist_test);
+ATF_TC_HEAD(slist_test, tc)
+{
+
+ atf_tc_set_md_var(tc, "descr", "SLIST macro feature tests");
+}
+
+ATF_TC_BODY(slist_test, tc)
+{
+ SLIST_HEAD(stailhead, entry) head = SLIST_HEAD_INITIALIZER(head);
+ struct entry {
+ SLIST_ENTRY(entry) entries;
+ int i;
+ } *n1, *n2, *n3, *np;
+ int i, j, length;
+
+ SLIST_INIT(&head);
+
+ printf("Ensuring SLIST_EMPTY works\n");
+
+ ATF_REQUIRE(SLIST_EMPTY(&head));
+
+ i = length = 0;
+
+ SLIST_FOREACH(np, &head, entries) {
+ length++;
+ }
+ ATF_REQUIRE_EQ(length, 0);
+
+ printf("Ensuring SLIST_INSERT_HEAD works\n");
+
+ n1 = malloc(sizeof(struct entry));
+ ATF_REQUIRE(n1 != NULL);
+ n1->i = i++;
+
+ SLIST_INSERT_HEAD(&head, n1, entries);
+
+ printf("Ensuring SLIST_FIRST returns element 1\n");
+ ATF_REQUIRE_EQ(SLIST_FIRST(&head), n1);
+
+ j = length = 0;
+ SLIST_FOREACH(np, &head, entries) {
+ ATF_REQUIRE_EQ_MSG(np->i, j,
+ "%d (entry counter) != %d (counter)", np->i, j);
+ j++;
+ length++;
+ }
+ ATF_REQUIRE_EQ(length, 1);
+
+ printf("Ensuring SLIST_INSERT_AFTER works\n");
+
+ n2 = malloc(sizeof(struct entry));
+ ATF_REQUIRE(n2 != NULL);
+ n2->i = i++;
+
+ SLIST_INSERT_AFTER(n1, n2, entries);
+
+ n3 = malloc(sizeof(struct entry));
+ ATF_REQUIRE(n3 != NULL);
+ n3->i = i++;
+
+ SLIST_INSERT_AFTER(n2, n3, entries);
+
+ j = length = 0;
+ SLIST_FOREACH(np, &head, entries) {
+ ATF_REQUIRE_EQ_MSG(np->i, j,
+ "%d (entry counter) != %d (counter)", np->i, j);
+ j++;
+ length++;
+ }
+ ATF_REQUIRE_EQ(length, 3);
+
+ printf("Ensuring SLIST_REMOVE_HEAD works\n");
+
+ printf("Ensuring SLIST_FIRST returns element 1\n");
+ ATF_REQUIRE_EQ(SLIST_FIRST(&head), n1);
+
+ SLIST_REMOVE_HEAD(&head, entries);
+
+ printf("Ensuring SLIST_FIRST now returns element 2\n");
+ ATF_REQUIRE_EQ(SLIST_FIRST(&head), n2);
+
+ j = 1; /* Starting point's 1 this time */
+ length = 0;
+ SLIST_FOREACH(np, &head, entries) {
+ ATF_REQUIRE_EQ_MSG(np->i, j,
+ "%d (entry counter) != %d (counter)", np->i, j);
+ j++;
+ length++;
+ }
+ ATF_REQUIRE_EQ(length, 2);
+
+ printf("Ensuring SLIST_REMOVE_AFTER works by removing the tail\n");
+
+ SLIST_REMOVE_AFTER(n2, entries);
+
+ j = 1; /* Starting point's 1 this time */
+ length = 0;
+ SLIST_FOREACH(np, &head, entries) {
+ ATF_REQUIRE_EQ_MSG(np->i, j,
+ "%d (entry counter) != %d (counter)", np->i, j);
+ j++;
+ length++;
+ }
+ ATF_REQUIRE_EQ(length, 1);
+
+ printf("Ensuring SLIST_FIRST returns element 2\n");
+ ATF_REQUIRE_EQ(SLIST_FIRST(&head), n2);
+
+}
+
+ATF_TC(stailq_test);
+ATF_TC_HEAD(stailq_test, tc)
+{
+
+ atf_tc_set_md_var(tc, "descr", "STAILQ macro feature tests");
+}
+
+ATF_TC_BODY(stailq_test, tc)
+{
+ STAILQ_HEAD(stailhead, entry) head = STAILQ_HEAD_INITIALIZER(head);
+ struct entry {
+ STAILQ_ENTRY(entry) entries;
+ int i;
+ } *n1, *n2, *n3, *np;
+ int i, j, length;
+
+ printf("Ensuring empty STAILQs are treated properly\n");
+ STAILQ_INIT(&head);
+ ATF_REQUIRE(STAILQ_EMPTY(&head));
+
+ i = length = 0;
+
+ STAILQ_FOREACH(np, &head, entries) {
+ length++;
+ }
+ ATF_REQUIRE_EQ(length, 0);
+
+ printf("Ensuring STAILQ_INSERT_HEAD works\n");
+
+ n1 = malloc(sizeof(struct entry));
+ ATF_REQUIRE(n1 != NULL);
+ n1->i = i++;
+
+ STAILQ_INSERT_HEAD(&head, n1, entries);
+
+ j = length = 0;
+ STAILQ_FOREACH(np, &head, entries) {
+ ATF_REQUIRE_EQ_MSG(np->i, j,
+ "%d (entry counter) != %d (counter)", np->i, j);
+ j++;
+ length++;
+ }
+ ATF_REQUIRE_EQ(length, 1);
+
+ printf("Ensuring STAILQ_INSERT_TAIL works\n");
+
+ n2 = malloc(sizeof(struct entry));
+ ATF_REQUIRE(n2 != NULL);
+ n2->i = i++;
+
+ STAILQ_INSERT_TAIL(&head, n2, entries);
+
+ n3 = malloc(sizeof(struct entry));
+ ATF_REQUIRE(n3 != NULL);
+ n3->i = i++;
+
+ STAILQ_INSERT_TAIL(&head, n3, entries);
+
+ j = length = 0;
+ STAILQ_FOREACH(np, &head, entries) {
+ ATF_REQUIRE_EQ_MSG(np->i, j,
+ "%d (entry counter) != %d (counter)", np->i, j);
+ j++;
+ length++;
+ }
+ ATF_REQUIRE_EQ(length, 3);
+
+ printf("Ensuring STAILQ_REMOVE_HEAD works\n");
+
+ STAILQ_REMOVE_HEAD(&head, entries);
+
+ j = 1; /* Starting point's 1 this time */
+ length = 0;
+ STAILQ_FOREACH(np, &head, entries) {
+ ATF_REQUIRE_EQ_MSG(np->i, j,
+ "%d (entry counter) != %d (counter)", np->i, j);
+ j++;
+ length++;
+ }
+ ATF_REQUIRE_EQ(length, 2);
+
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, slist_test);
+ ATF_TP_ADD_TC(tp, stailq_test);
+
+ return (atf_no_error());
+}
Property changes on: trunk/lib/libc/tests/sys/queue_test.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/termios/Makefile
===================================================================
--- trunk/lib/libc/tests/termios/Makefile (rev 0)
+++ trunk/lib/libc/tests/termios/Makefile 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,10 @@
+# $MidnightBSD$
+# $FreeBSD: stable/10/lib/libc/tests/termios/Makefile 313488 2017-02-09 22:49:48Z ngie $
+
+.include <bsd.own.mk>
+
+NETBSD_ATF_TESTS_C= tcsetpgrp_test
+
+.include "../Makefile.netbsd-tests"
+
+.include <bsd.test.mk>
Property changes on: trunk/lib/libc/tests/termios/Makefile
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/time/Makefile
===================================================================
--- trunk/lib/libc/tests/time/Makefile (rev 0)
+++ trunk/lib/libc/tests/time/Makefile 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,11 @@
+# $MidnightBSD$
+# $FreeBSD: stable/10/lib/libc/tests/time/Makefile 313488 2017-02-09 22:49:48Z ngie $
+
+.include <bsd.own.mk>
+
+NETBSD_ATF_TESTS_C= mktime_test
+NETBSD_ATF_TESTS_C+= strptime_test
+
+.include "../Makefile.netbsd-tests"
+
+.include <bsd.test.mk>
Property changes on: trunk/lib/libc/tests/time/Makefile
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/tls/Makefile
===================================================================
--- trunk/lib/libc/tests/tls/Makefile (rev 0)
+++ trunk/lib/libc/tests/tls/Makefile 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,35 @@
+# $MidnightBSD$
+# $FreeBSD: stable/10/lib/libc/tests/tls/Makefile 313488 2017-02-09 22:49:48Z ngie $
+
+.include <bsd.own.mk>
+
+.if !defined(NO_PIC)
+SUBDIR+= dso
+.endif
+
+# TODO: doesn't link properly (for some odd reason it's trying to link in
+# libatf.so)
+#NETBSD_ATF_TESTS_C= tls_static_test
+.if !defined(NO_PIC)
+NETBSD_ATF_TESTS_C+= tls_dlopen_test
+NETBSD_ATF_TESTS_C+= tls_dynamic_test
+.endif
+
+.include "../Makefile.netbsd-tests"
+
+DSODIR= ${.OBJDIR}/../tls_dso
+
+DPADD.tls_static_test+= ${LIBPTHREAD}
+LDADD.tls_static_test+= -lpthread
+LDFLAGS.tls_static_test+= -static
+SRCS.tls_static_test= t_tls_static.c t_tls_static_helper.c
+
+DPADD.tls_dynamic_test+= ${LIBPTHREAD} ${DSODIR}/libh_tls_dynamic.so
+LDADD.tls_dynamic_test+= -lpthread -lh_tls_dynamic
+LDFLAGS.tls_dynamic_test+= -Wl,-rpath,${TESTSDIR} -L${DSODIR}
+
+DPADD.tls_dlopen_test+= ${LIBPTHREAD}
+LDADD.tls_dlopen_test+= -lpthread
+LDFLAGS.tls_dlopen_test+= -Wl,-rpath,${TESTSDIR} -Wl,-export-dynamic
+
+.include <bsd.test.mk>
Property changes on: trunk/lib/libc/tests/tls/Makefile
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/tls/dso/Makefile
===================================================================
--- trunk/lib/libc/tests/tls/dso/Makefile (rev 0)
+++ trunk/lib/libc/tests/tls/dso/Makefile 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,18 @@
+# $MidnightBSD$
+# $FreeBSD: stable/10/lib/libc/tests/tls/dso/Makefile 313488 2017-02-09 22:49:48Z ngie $
+
+OBJTOP= ${.OBJDIR:H:H:H:H:H}
+TESTSRC= ${SRCTOP}/contrib/netbsd-tests/lib/libc/tls/${.CURDIR:T}
+
+LIB= h_tls_dlopen
+SHLIB_NAME= h_tls_dlopen.so
+SRCS= h_tls_dlopen.c
+
+MAN=
+
+LIBDIR= ${TESTSBASE}/lib/libc/tls
+SHLIB_MAJOR= 1
+
+.include "../../Makefile.netbsd-tests"
+
+.include <bsd.lib.mk>
Property changes on: trunk/lib/libc/tests/tls/dso/Makefile
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/tls_dso/Makefile
===================================================================
--- trunk/lib/libc/tests/tls_dso/Makefile (rev 0)
+++ trunk/lib/libc/tests/tls_dso/Makefile 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,21 @@
+# $MidnightBSD$
+# $FreeBSD: stable/10/lib/libc/tests/tls_dso/Makefile 274075 2014-11-04 00:56:25Z ngie $
+
+.include <bsd.own.mk>
+
+LIB= h_tls_dynamic
+SRCS= h_tls_dynamic.c
+
+LIBDIR= ${TESTSBASE}/lib/libc/tls
+SHLIBDIR= ${TESTSBASE}/lib/libc/tls
+SHLIB_MAJOR= 1
+
+WITHOUT_STATIC=
+WITHOUT_PROFILE=
+WITHOUT_PIC=
+
+MAN=
+
+.include "../Makefile.netbsd-tests"
+
+.include <bsd.lib.mk>
Property changes on: trunk/lib/libc/tests/tls_dso/Makefile
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/lib/libc/tests/ttyio/Makefile
===================================================================
--- trunk/lib/libc/tests/ttyio/Makefile (rev 0)
+++ trunk/lib/libc/tests/ttyio/Makefile 2018-06-05 21:54:18 UTC (rev 10420)
@@ -0,0 +1,14 @@
+# $MidnightBSD$
+# $FreeBSD: stable/10/lib/libc/tests/ttyio/Makefile 313488 2017-02-09 22:49:48Z ngie $
+
+.include <bsd.own.mk>
+
+# TODO: ptm_test
+NETBSD_ATF_TESTS_C= ttyio_test
+
+DPADD.ttyio_test+= ${LIBUTIL}
+LDADD.ttyio_test+= -lutil
+
+.include "../Makefile.netbsd-tests"
+
+.include <bsd.test.mk>
Property changes on: trunk/lib/libc/tests/ttyio/Makefile
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
More information about the Midnightbsd-cvs
mailing list