Module Name: src
Committed By: jmmv
Date: Fri Jul 16 13:56:32 UTC 2010
Modified Files:
src/tests/lib: Makefile
Added Files:
src/tests/lib/libposix: Makefile t_rename.c
src/tests/lib/libposix/bsd: Makefile
src/tests/lib/libposix/posix1: Makefile
src/tests/lib/libposix/posix2: Makefile
src/tests/lib/libprop: Makefile t_basic.c
src/tests/lib/librt: Makefile t_sem.c
src/tests/lib/libskey: Makefile t_algorithms.c
src/tests/lib/libutil: Makefile t_snprintb.c t_sockaddr_snprintf.c
Log Message:
Convert the libposix, libprop, librt, libskey and libutil tests to ATF.
Initial work from the GSoC 2008 project by Lukasz Strzygowski.
To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/lib/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/lib/libposix/Makefile \
src/tests/lib/libposix/t_rename.c
cvs rdiff -u -r0 -r1.1 src/tests/lib/libposix/bsd/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/lib/libposix/posix1/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/lib/libposix/posix2/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/lib/libprop/Makefile \
src/tests/lib/libprop/t_basic.c
cvs rdiff -u -r0 -r1.1 src/tests/lib/librt/Makefile \
src/tests/lib/librt/t_sem.c
cvs rdiff -u -r0 -r1.1 src/tests/lib/libskey/Makefile \
src/tests/lib/libskey/t_algorithms.c
cvs rdiff -u -r0 -r1.1 src/tests/lib/libutil/Makefile \
src/tests/lib/libutil/t_snprintb.c \
src/tests/lib/libutil/t_sockaddr_snprintf.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/tests/lib/Makefile
diff -u src/tests/lib/Makefile:1.4 src/tests/lib/Makefile:1.5
--- src/tests/lib/Makefile:1.4 Tue Jul 13 21:13:26 2010
+++ src/tests/lib/Makefile Fri Jul 16 13:56:31 2010
@@ -1,8 +1,12 @@
-# $NetBSD: Makefile,v 1.4 2010/07/13 21:13:26 jmmv Exp $
+# $NetBSD: Makefile,v 1.5 2010/07/16 13:56:31 jmmv Exp $
.include <bsd.own.mk>
-TESTS_SUBDIRS= libc libevent semaphore
+TESTS_SUBDIRS= libc libevent libposix libprop librt libutil semaphore
+
+.if (${MKSKEY} != "no")
+TESTS_SUBDIRS+= libskey
+.endif
TESTSDIR= ${TESTSBASE}/lib
Added files:
Index: src/tests/lib/libposix/Makefile
diff -u /dev/null src/tests/lib/libposix/Makefile:1.1
--- /dev/null Fri Jul 16 13:56:32 2010
+++ src/tests/lib/libposix/Makefile Fri Jul 16 13:56:31 2010
@@ -0,0 +1,13 @@
+# $NetBSD: Makefile,v 1.1 2010/07/16 13:56:31 jmmv Exp $
+
+NOMAN= # defined
+
+.include <bsd.own.mk>
+
+TESTSDIR= ${TESTSBASE}/lib/libposix
+
+SUBDIR= bsd
+SUBDIR+= posix1
+SUBDIR+= posix2
+
+.include <bsd.test.mk>
Index: src/tests/lib/libposix/t_rename.c
diff -u /dev/null src/tests/lib/libposix/t_rename.c:1.1
--- /dev/null Fri Jul 16 13:56:32 2010
+++ src/tests/lib/libposix/t_rename.c Fri Jul 16 13:56:31 2010
@@ -0,0 +1,89 @@
+/* $NetBSD: t_rename.c,v 1.1 2010/07/16 13:56:31 jmmv Exp $ */
+
+/*
+ * Copyright (c) 2001, 2008, 2010 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__COPYRIGHT("@(#) Copyright (c) 2008, 2010\
+ The NetBSD Foundation, inc. All rights reserved.");
+__RCSID("$NetBSD: t_rename.c,v 1.1 2010/07/16 13:56:31 jmmv Exp $");
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <atf-c.h>
+
+#include "../../h_macros.h"
+
+ATF_TC(rename);
+ATF_TC_HEAD(rename, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Checks rename(2)");
+}
+ATF_TC_BODY(rename, tc)
+{
+ struct stat sb;
+
+ REQUIRE_LIBC(open("t1", O_CREAT | O_TRUNC | O_WRONLY, 0600), -1);
+ REQUIRE_LIBC(link("t1", "t2"), -1);
+
+ /* Check if rename to same name works as expected */
+ REQUIRE_LIBC(rename("t1", "t1"), -1);
+
+ /* Rename removed file? */
+ REQUIRE_LIBC(stat("t1", &sb), -1);
+
+ REQUIRE_LIBC(rename("t1", "t2"), -1);
+
+#if BSD_RENAME
+ /* check if rename of hardlinked file works the BSD way */
+ ATF_REQUIRE_MSG(stat("t1", &sb) != 0, "BSD rename should remove file t1");
+ ATF_REQUIRE_EQ(errno, ENOENT);
+#else
+ /* check if rename of hardlinked file works as the standard says */
+ REQUIRE_LIBC(stat("t1", &sb), -1);
+#endif
+ /* check if we get the expected error */
+ /* this also exercises icky shared libraries goo */
+ ATF_REQUIRE_MSG(rename("no/such/file/or/dir", "no/such/file/or/dir") != 0,
+ "No error renaming nonexistent file");
+ ATF_REQUIRE_EQ(errno, ENOENT);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, rename);
+
+ return atf_no_error();
+}
Index: src/tests/lib/libposix/bsd/Makefile
diff -u /dev/null src/tests/lib/libposix/bsd/Makefile:1.1
--- /dev/null Fri Jul 16 13:56:32 2010
+++ src/tests/lib/libposix/bsd/Makefile Fri Jul 16 13:56:31 2010
@@ -0,0 +1,14 @@
+# $NetBSD: Makefile,v 1.1 2010/07/16 13:56:31 jmmv Exp $
+
+NOMAN= # defined
+
+.include <bsd.own.mk>
+
+.PATH: ${.CURDIR}/..
+TESTSDIR= ${TESTSBASE}/lib/libposix/bsd
+
+CFLAGS+= -DBSD_RENAME
+
+TESTS_C= t_rename
+
+.include <bsd.test.mk>
Index: src/tests/lib/libposix/posix1/Makefile
diff -u /dev/null src/tests/lib/libposix/posix1/Makefile:1.1
--- /dev/null Fri Jul 16 13:56:32 2010
+++ src/tests/lib/libposix/posix1/Makefile Fri Jul 16 13:56:31 2010
@@ -0,0 +1,15 @@
+# $NetBSD: Makefile,v 1.1 2010/07/16 13:56:31 jmmv Exp $
+
+NOMAN= # defined
+
+.include <bsd.own.mk>
+
+.PATH: ${.CURDIR}/..
+TESTSDIR= ${TESTSBASE}/lib/libposix/posix1
+
+DPADD+= ${LIBPOSIX}
+LDADD+= -lposix
+
+TESTS_C= t_rename
+
+.include <bsd.test.mk>
Index: src/tests/lib/libposix/posix2/Makefile
diff -u /dev/null src/tests/lib/libposix/posix2/Makefile:1.1
--- /dev/null Fri Jul 16 13:56:32 2010
+++ src/tests/lib/libposix/posix2/Makefile Fri Jul 16 13:56:31 2010
@@ -0,0 +1,14 @@
+# $NetBSD: Makefile,v 1.1 2010/07/16 13:56:31 jmmv Exp $
+
+NOMAN= # defined
+
+.include <bsd.own.mk>
+
+.PATH: ${.CURDIR}/..
+TESTSDIR= ${TESTSBASE}/lib/libposix/posix2
+
+CFLAGS+= -D_POSIX_SOURCE
+
+TESTS_C= t_rename
+
+.include <bsd.test.mk>
Index: src/tests/lib/libprop/Makefile
diff -u /dev/null src/tests/lib/libprop/Makefile:1.1
--- /dev/null Fri Jul 16 13:56:32 2010
+++ src/tests/lib/libprop/Makefile Fri Jul 16 13:56:31 2010
@@ -0,0 +1,13 @@
+# $NetBSD: Makefile,v 1.1 2010/07/16 13:56:31 jmmv Exp $
+
+NOMAN= # defined
+
+.include <bsd.own.mk>
+
+TESTSDIR= ${TESTSBASE}/lib/libprop
+
+LDADD+= -lprop
+
+TESTS_C= t_basic
+
+.include <bsd.test.mk>
Index: src/tests/lib/libprop/t_basic.c
diff -u /dev/null src/tests/lib/libprop/t_basic.c:1.1
--- /dev/null Fri Jul 16 13:56:32 2010
+++ src/tests/lib/libprop/t_basic.c Fri Jul 16 13:56:31 2010
@@ -0,0 +1,168 @@
+/* $NetBSD: t_basic.c,v 1.1 2010/07/16 13:56:31 jmmv Exp $ */
+
+/*
+ * Copyright (c) 2008 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * Written by Jason Thorpe 5/26/2006.
+ * Public domain.
+ */
+
+#include <sys/cdefs.h>
+__COPYRIGHT("@(#) Copyright (c) 2008\
+ The NetBSD Foundation, inc. All rights reserved.");
+__RCSID("$NetBSD: t_basic.c,v 1.1 2010/07/16 13:56:31 jmmv Exp $");
+
+#include <prop/proplib.h>
+#include <stdlib.h>
+
+#include <atf-c.h>
+
+static const char compare1[] =
+"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+"<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"
+"<plist version=\"1.0\">\n"
+"<dict>\n"
+" <key>false-val</key>\n"
+" <false/>\n"
+" <key>one</key>\n"
+" <integer>1</integer>\n"
+" <key>three</key>\n"
+" <array>\n"
+" <dict>\n"
+" <key>one</key>\n"
+" <integer>1</integer>\n"
+" <key>two</key>\n"
+" <string>number-two</string>\n"
+" </dict>\n"
+" <dict>\n"
+" <key>one</key>\n"
+" <integer>1</integer>\n"
+" <key>two</key>\n"
+" <string>number-two</string>\n"
+" </dict>\n"
+" <dict>\n"
+" <key>one</key>\n"
+" <integer>1</integer>\n"
+" <key>two</key>\n"
+" <string>number-two</string>\n"
+" </dict>\n"
+" </array>\n"
+" <key>true-val</key>\n"
+" <true/>\n"
+" <key>two</key>\n"
+" <string>number-two</string>\n"
+"</dict>\n"
+"</plist>\n";
+
+ATF_TC(simple);
+ATF_TC_HEAD(simple, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Checks basic functionality of proplib");
+}
+ATF_TC_BODY(simple, tc)
+{
+ prop_dictionary_t dict;
+ char *ext1;
+
+ dict = prop_dictionary_create();
+ ATF_REQUIRE(dict != NULL);
+
+ {
+ prop_number_t num = prop_number_create_integer(1);
+ ATF_REQUIRE(num != NULL);
+
+ ATF_REQUIRE_EQ(prop_dictionary_set(dict, "one", num), true);
+ prop_object_release(num);
+ }
+
+ {
+ prop_string_t str = prop_string_create_cstring("number-two");
+ ATF_REQUIRE(str != NULL);
+
+ ATF_REQUIRE_EQ(prop_dictionary_set(dict, "two", str), true);
+ prop_object_release(str);
+ }
+
+ {
+ prop_array_t arr;
+ prop_dictionary_t dict_copy;
+ int i;
+
+ arr = prop_array_create();
+ ATF_REQUIRE(arr != NULL);
+
+ for (i = 0; i < 3; ++i) {
+ dict_copy = prop_dictionary_copy(dict);
+ ATF_REQUIRE(dict_copy != NULL);
+ ATF_REQUIRE_EQ(prop_array_add(arr, dict_copy), true);
+ prop_object_release(dict_copy);
+ }
+
+ ATF_REQUIRE_EQ(prop_dictionary_set(dict, "three", arr), true);
+ prop_object_release(arr);
+ }
+
+ {
+ prop_bool_t val = prop_bool_create(true);
+ ATF_REQUIRE(val != NULL);
+ ATF_REQUIRE_EQ(prop_dictionary_set(dict, "true-val", val), true);
+ prop_object_release(val);
+
+ val = prop_bool_create(false);
+ ATF_REQUIRE(val != NULL);
+ ATF_REQUIRE_EQ(prop_dictionary_set(dict, "false-val", val), true);
+ prop_object_release(val);
+ }
+
+ ext1 = prop_dictionary_externalize(dict);
+ ATF_REQUIRE(ext1 != NULL);
+ ATF_REQUIRE_STREQ(compare1, ext1);
+
+ {
+ prop_dictionary_t dict2;
+ char *ext2;
+
+ dict2 = prop_dictionary_internalize(ext1);
+ ATF_REQUIRE(dict2 != NULL);
+ ext2 = prop_dictionary_externalize(dict2);
+ ATF_REQUIRE(ext2 != NULL);
+ ATF_REQUIRE_STREQ(ext1, ext2);
+ prop_object_release(dict2);
+ free(ext2);
+ }
+
+ prop_object_release(dict);
+ free(ext1);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, simple);
+
+ return atf_no_error();
+}
Index: src/tests/lib/librt/Makefile
diff -u /dev/null src/tests/lib/librt/Makefile:1.1
--- /dev/null Fri Jul 16 13:56:32 2010
+++ src/tests/lib/librt/Makefile Fri Jul 16 13:56:32 2010
@@ -0,0 +1,13 @@
+# $NetBSD: Makefile,v 1.1 2010/07/16 13:56:32 jmmv Exp $
+
+NOMAN= # defined
+
+.include <bsd.own.mk>
+
+TESTSDIR= ${TESTSBASE}/lib/librt
+
+LDADD+= -lrt
+
+TESTS_C= t_sem
+
+.include <bsd.test.mk>
Index: src/tests/lib/librt/t_sem.c
diff -u /dev/null src/tests/lib/librt/t_sem.c:1.1
--- /dev/null Fri Jul 16 13:56:32 2010
+++ src/tests/lib/librt/t_sem.c Fri Jul 16 13:56:32 2010
@@ -0,0 +1,171 @@
+/* $NetBSD: t_sem.c,v 1.1 2010/07/16 13:56:32 jmmv Exp $ */
+
+/*
+ * Copyright (c) 2008, 2010 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * Copyright (C) 2000 Jason Evans <[email protected]>.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice(s), this list of conditions and the following disclaimer as
+ * the first lines of this file unmodified other than the possible
+ * addition of one or more copyright notices.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice(s), this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__COPYRIGHT("@(#) Copyright (c) 2008, 2010\
+ The NetBSD Foundation, inc. All rights reserved.");
+__RCSID("$NetBSD: t_sem.c,v 1.1 2010/07/16 13:56:32 jmmv Exp $");
+
+#include <sys/wait.h>
+
+#include <errno.h>
+#include <fcntl.h>
+#include <semaphore.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#include <atf-c.h>
+
+#define NCHILDREN 10
+
+ATF_TC(basic);
+ATF_TC_HEAD(basic, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Checks basic functionality of POSIX "
+ "semaphores");
+}
+ATF_TC_BODY(basic, tc)
+{
+ int val;
+ sem_t *sem_b;
+
+ ATF_REQUIRE(sysconf(_SC_SEMAPHORES) != -1);
+
+ sem_b = sem_open("/sem_b", O_CREAT | O_EXCL, 0644, 0);
+ ATF_REQUIRE(sem_b != SEM_FAILED);
+
+ ATF_REQUIRE_EQ(sem_getvalue(sem_b, &val), 0);
+ ATF_REQUIRE_EQ(val, 0);
+
+ ATF_REQUIRE_EQ(sem_post(sem_b), 0);
+ ATF_REQUIRE_EQ(sem_getvalue(sem_b, &val), 0);
+ ATF_REQUIRE_EQ(val, 1);
+
+ ATF_REQUIRE_EQ(sem_wait(sem_b), 0);
+ ATF_REQUIRE_EQ(sem_trywait(sem_b), -1);
+ ATF_REQUIRE_EQ(errno, EAGAIN);
+ ATF_REQUIRE_EQ(sem_post(sem_b), 0);
+ ATF_REQUIRE_EQ(sem_trywait(sem_b), 0);
+ ATF_REQUIRE_EQ(sem_post(sem_b), 0);
+ ATF_REQUIRE_EQ(sem_wait(sem_b), 0);
+ ATF_REQUIRE_EQ(sem_post(sem_b), 0);
+
+ ATF_REQUIRE_EQ(sem_close(sem_b), 0);
+ ATF_REQUIRE_EQ(sem_unlink("/sem_b"), 0);
+}
+
+ATF_TC(child);
+ATF_TC_HEAD(child, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Checks using semaphores to synchronize "
+ "parent with multiple child processes");
+}
+ATF_TC_BODY(child, tc)
+{
+ pid_t children[NCHILDREN];
+ unsigned i, j;
+ sem_t *sem_a;
+ int status;
+
+ pid_t pid;
+
+ sem_a = sem_open("/sem_a", O_CREAT | O_EXCL, 0644, 0);
+ ATF_REQUIRE(sem_a != SEM_FAILED);
+
+ for (j = 1; j <= 2; j++) {
+ for (i = 0; i < NCHILDREN; i++) {
+ switch ((pid = fork())) {
+ case -1:
+ atf_tc_fail("fork() returned -1");
+ case 0:
+ printf("PID %d waiting for semaphore...\n",
+ getpid());
+ ATF_REQUIRE_MSG(sem_wait(sem_a) == 0,
+ "sem_wait failed; iteration %d", j);
+ printf("PID %d got semaphore\n", getpid());
+ _exit(0);
+ default:
+ children[i] = pid;
+ break;
+ }
+ }
+
+ for (i = 0; i < NCHILDREN; i++) {
+ sleep(1);
+ printf("main loop %d: posting...\n", j);
+ ATF_REQUIRE_EQ(sem_post(sem_a), 0);
+ }
+
+ for (i = 0; i < NCHILDREN; i++) {
+ ATF_REQUIRE_EQ(waitpid(children[i], &status, 0), children[i]);
+ ATF_REQUIRE(WIFEXITED(status));
+ ATF_REQUIRE_EQ(WEXITSTATUS(status), 0);
+ }
+ }
+
+ ATF_REQUIRE_EQ(sem_close(sem_a), 0);
+ ATF_REQUIRE_EQ(sem_unlink("/sem_a"), 0);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, basic);
+ ATF_TP_ADD_TC(tp, child);
+
+ return atf_no_error();
+}
Index: src/tests/lib/libskey/Makefile
diff -u /dev/null src/tests/lib/libskey/Makefile:1.1
--- /dev/null Fri Jul 16 13:56:32 2010
+++ src/tests/lib/libskey/Makefile Fri Jul 16 13:56:32 2010
@@ -0,0 +1,14 @@
+# $NetBSD: Makefile,v 1.1 2010/07/16 13:56:32 jmmv Exp $
+
+NOMAN= # defined
+
+.include <bsd.own.mk>
+
+TESTSDIR= ${TESTSBASE}/lib/libskey
+
+DPADD+= ${LIBSKEY}
+LDADD+= -lskey
+
+TESTS_C= t_algorithms
+
+.include <bsd.test.mk>
Index: src/tests/lib/libskey/t_algorithms.c
diff -u /dev/null src/tests/lib/libskey/t_algorithms.c:1.1
--- /dev/null Fri Jul 16 13:56:32 2010
+++ src/tests/lib/libskey/t_algorithms.c Fri Jul 16 13:56:32 2010
@@ -0,0 +1,121 @@
+/* $NetBSD: t_algorithms.c,v 1.1 2010/07/16 13:56:32 jmmv Exp $ */
+
+/*
+ * Copyright (c) 2000, 2008, 2010 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__COPYRIGHT("@(#) Copyright (c) 2008, 2010\
+ The NetBSD Foundation, inc. All rights reserved.");
+__RCSID("$NetBSD: t_algorithms.c,v 1.1 2010/07/16 13:56:32 jmmv Exp $");
+
+#include <stdio.h>
+#include <strings.h>
+#include <skey.h>
+
+#include <atf-c.h>
+
+#define H_REQUIRE(x, y) \
+ ATF_REQUIRE_MSG(strcasecmp((x), (y)) == 0, "\"%s\" != \"%s\"", (x), (y))
+
+static void
+h_check(const char *pass, const char *seed,
+ const char *algo, const char *zero,
+ const char *one, const char *nine)
+{
+ char prn[64];
+ char data[16];
+ int i;
+
+ skey_set_algorithm(algo);
+
+ keycrunch(data, seed, pass);
+ btoa8(prn, data);
+ H_REQUIRE(prn, zero);
+
+ f(data);
+ btoa8(prn, data);
+ H_REQUIRE(prn, one);
+
+ for(i = 1; i < 99; ++i)
+ f(data);
+ btoa8(prn, data);
+ H_REQUIRE(prn, nine);
+}
+
+ATF_TC(md4);
+ATF_TC_HEAD(md4, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Checks MD4 algorithm");
+}
+ATF_TC_BODY(md4, tc)
+{
+ h_check("This is a test.", "TeSt", "md4", "D1854218EBBB0B51",
+ "63473EF01CD0B444", "C5E612776E6C237A");
+ h_check("AbCdEfGhIjK", "alpha1", "md4", "50076F47EB1ADE4E",
+ "65D20D1949B5F7AB", "D150C82CCE6F62D1");
+ h_check("OTP's are good", "correct", "md4", "849C79D4F6F55388",
+ "8C0992FB250847B1", "3F3BF4B4145FD74B");
+}
+
+ATF_TC(md5);
+ATF_TC_HEAD(md5, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Checks MD5 algorithm");
+}
+ATF_TC_BODY(md5, tc)
+{
+ h_check("This is a test.", "TeSt", "md5", "9E876134D90499DD",
+ "7965E05436F5029F", "50FE1962C4965880");
+ h_check("AbCdEfGhIjK", "alpha1", "md5", "87066DD9644BF206",
+ "7CD34C1040ADD14B", "5AA37A81F212146C");
+ h_check("OTP's are good", "correct", "md5", "F205753943DE4CF9",
+ "DDCDAC956F234937", "B203E28FA525BE47");
+}
+
+ATF_TC(sha1);
+ATF_TC_HEAD(sha1, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Checks SHA1 algorithm");
+}
+ATF_TC_BODY(sha1, tc)
+{
+ h_check("This is a test.", "TeSt", "sha1","BB9E6AE1979D8FF4",
+ "63D936639734385B", "87FEC7768B73CCF9");
+ h_check("AbCdEfGhIjK", "alpha1", "sha1","AD85F658EBE383C9",
+ "D07CE229B5CF119B", "27BC71035AAF3DC6");
+ h_check("OTP's are good", "correct", "sha1","D51F3E99BF8E6F0B",
+ "82AEB52D943774E4", "4F296A74FE1567EC");
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, md4);
+ ATF_TP_ADD_TC(tp, md5);
+ ATF_TP_ADD_TC(tp, sha1);
+
+ return atf_no_error();
+}
Index: src/tests/lib/libutil/Makefile
diff -u /dev/null src/tests/lib/libutil/Makefile:1.1
--- /dev/null Fri Jul 16 13:56:32 2010
+++ src/tests/lib/libutil/Makefile Fri Jul 16 13:56:32 2010
@@ -0,0 +1,19 @@
+# $NetBSD: Makefile,v 1.1 2010/07/16 13:56:32 jmmv Exp $
+
+NOMAN= # defined
+
+.include <bsd.own.mk>
+
+TESTSDIR= ${TESTSBASE}/lib/libutil
+
+DPADD+= ${LIBUTIL}
+LDADD+= -lutil
+
+TESTS_C= t_snprintb
+TESTS_C+= t_sockaddr_snprintf
+
+.if (${USE_INET6} != "no")
+CFLAGS+= -DINET6
+.endif
+
+.include <bsd.test.mk>
Index: src/tests/lib/libutil/t_snprintb.c
diff -u /dev/null src/tests/lib/libutil/t_snprintb.c:1.1
--- /dev/null Fri Jul 16 13:56:32 2010
+++ src/tests/lib/libutil/t_snprintb.c Fri Jul 16 13:56:32 2010
@@ -0,0 +1,75 @@
+/* $NetBSD: t_snprintb.c,v 1.1 2010/07/16 13:56:32 jmmv Exp $ */
+
+/*
+ * Copyright (c) 2002, 2004, 2008, 2010 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code was contributed to The NetBSD Foundation by Christos Zoulas.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__COPYRIGHT("@(#) Copyright (c) 2008, 2010\
+ The NetBSD Foundation, inc. All rights reserved.");
+__RCSID("$NetBSD: t_snprintb.c,v 1.1 2010/07/16 13:56:32 jmmv Exp $");
+
+#include <string.h>
+#include <util.h>
+
+#include <atf-c.h>
+
+static void
+h_snprintb(const char *fmt, uint64_t val, const char *res)
+{
+ char buf[1024];
+ int len, slen;
+
+ len = snprintb(buf, sizeof(buf), fmt, val);
+ slen = (int) strlen(res);
+
+ ATF_REQUIRE_STREQ(res, buf);
+ ATF_REQUIRE_EQ(len, slen);
+}
+
+ATF_TC(snprintb);
+ATF_TC_HEAD(snprintb, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Checks snprintb(3)");
+}
+ATF_TC_BODY(snprintb, tc)
+{
+ h_snprintb("\10\2BITTWO\1BITONE", 3, "03<BITTWO,BITONE>");
+
+ h_snprintb("\177\20b\05NOTBOOT\0b\06FPP\0b\013SDVMA\0b\015VIDEO\0"
+ "b\020LORES\0b\021FPA\0b\022DIAG\0b\016CACHE\0"
+ "b\017IOCACHE\0b\022LOOPBACK\0b\04DBGCACHE\0",
+ 0xe860, "0xe860<NOTBOOT,FPP,SDVMA,VIDEO,CACHE,IOCACHE>");
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, snprintb);
+
+ return atf_no_error();
+}
Index: src/tests/lib/libutil/t_sockaddr_snprintf.c
diff -u /dev/null src/tests/lib/libutil/t_sockaddr_snprintf.c:1.1
--- /dev/null Fri Jul 16 13:56:32 2010
+++ src/tests/lib/libutil/t_sockaddr_snprintf.c Fri Jul 16 13:56:32 2010
@@ -0,0 +1,185 @@
+/* $NetBSD: t_sockaddr_snprintf.c,v 1.1 2010/07/16 13:56:32 jmmv Exp $ */
+
+/*
+ * Copyright (c) 2002, 2004, 2008, 2010 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code was contributed to The NetBSD Foundation by Christos Zoulas.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__COPYRIGHT("@(#) Copyright (c) 2008, 2010\
+ The NetBSD Foundation, inc. All rights reserved.");
+__RCSID("$NetBSD: t_sockaddr_snprintf.c,v 1.1 2010/07/16 13:56:32 jmmv Exp $");
+
+#include <sys/socket.h> /* AF_ */
+#include <sys/un.h> /* sun */
+
+#include <net/if_dl.h> /* sdl */
+#include <netatalk/at.h> /* sat */
+#include <netinet/in.h> /* sin/sin6 */
+
+#include <string.h>
+#include <util.h>
+
+#include <atf-c.h>
+
+ATF_TC(sockaddr_snprintf_in);
+ATF_TC_HEAD(sockaddr_snprintf_in, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Checks sockaddr_snprintf(3) with sockaddr_in");
+}
+ATF_TC_BODY(sockaddr_snprintf_in, tc)
+{
+ char buf[1024];
+ struct sockaddr_in sin4;
+ int i;
+
+ memset(&sin4, 0, sizeof(sin4));
+ sin4.sin_len = sizeof(sin4);
+ sin4.sin_family = AF_INET;
+ sin4.sin_port = ntohs(80);
+ sin4.sin_addr.s_addr = ntohl(INADDR_LOOPBACK);
+ i = sockaddr_snprintf(buf, sizeof(buf), "%f %l %p %a",
+ (struct sockaddr *)&sin4);
+
+ ATF_REQUIRE_EQ_MSG(i, 17, "bad length for sin4");
+ ATF_REQUIRE_STREQ(buf, "2 16 80 127.0.0.1");
+}
+
+ATF_TC(sockaddr_snprintf_in6);
+ATF_TC_HEAD(sockaddr_snprintf_in6, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Checks sockaddr_snprintf(3) with sockaddr_in6");
+}
+ATF_TC_BODY(sockaddr_snprintf_in6, tc)
+{
+#ifdef INET6
+ char buf[1024];
+ struct sockaddr_in6 sin6;
+ int i;
+
+ memset(&sin6, 0, sizeof(sin6));
+ sin6.sin6_len = sizeof(sin6);
+ sin6.sin6_family = AF_INET6;
+ sin6.sin6_port = ntohs(80);
+ sin6.sin6_addr = in6addr_nodelocal_allnodes;
+ i = sockaddr_snprintf(buf, sizeof(buf), "%f %l %p %a",
+ (struct sockaddr *)&sin6);
+
+ ATF_REQUIRE_EQ_MSG(i, 16, "bad length for sin6");
+ ATF_REQUIRE_STREQ(buf, "24 28 80 ff01::1");
+#else
+ atf_tc_skip("Tests built with USE_INET6=no");
+#endif /* INET6 */
+}
+
+ATF_TC(sockaddr_snprintf_un);
+ATF_TC_HEAD(sockaddr_snprintf_un, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Checks sockaddr_snprintf(3) with sockaddr_un");
+}
+ATF_TC_BODY(sockaddr_snprintf_un, tc)
+{
+ char buf[1024];
+ struct sockaddr_un sun;
+ int i;
+
+ memset(&sun, 0, sizeof(sun));
+ sun.sun_len = sizeof(sun);
+ sun.sun_family = AF_UNIX;
+ strncpy(sun.sun_path, "/tmp/sock", sizeof(sun.sun_path));
+ i = sockaddr_snprintf(buf, sizeof(buf), "%f %l %a",
+ (struct sockaddr *)&sun);
+
+ ATF_REQUIRE_EQ_MSG(i, 15, "bad length for sun");
+ ATF_REQUIRE_STREQ(buf, "1 106 /tmp/sock");
+}
+
+ATF_TC(sockaddr_snprintf_at);
+ATF_TC_HEAD(sockaddr_snprintf_at, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Checks sockaddr_snprintf(3) with sockaddr_at");
+}
+ATF_TC_BODY(sockaddr_snprintf_at, tc)
+{
+ char buf[1024];
+ struct sockaddr_at sat;
+ int i;
+
+ memset(&sat, 0, sizeof(sat));
+ sat.sat_len = sizeof(sat);
+ sat.sat_family = AF_APPLETALK;
+ sat.sat_addr.s_net = ntohs(101);
+ sat.sat_addr.s_node = 3;
+ i = sockaddr_snprintf(buf, sizeof(buf), "%f %l %a",
+ (struct sockaddr *)&sat);
+
+ ATF_REQUIRE_EQ_MSG(i, 11, "bad length for sat");
+ ATF_REQUIRE_STREQ(buf, "16 16 101.3");
+}
+
+ATF_TC(sockaddr_snprintf_dl);
+ATF_TC_HEAD(sockaddr_snprintf_dl, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Checks sockaddr_snprintf(3) with sockaddr_dl");
+}
+ATF_TC_BODY(sockaddr_snprintf_dl, tc)
+{
+ char buf[1024];
+ struct sockaddr_dl sdl;
+ int i;
+
+ memset(&sdl, 0, sizeof(sdl));
+ sdl.sdl_len = sizeof(sdl);
+ sdl.sdl_family = AF_LINK;
+ sdl.sdl_index = 0;
+ sdl.sdl_type = 0;
+ sdl.sdl_nlen = 0;
+ sdl.sdl_alen = 6;
+ sdl.sdl_slen = 0;
+ memcpy(sdl.sdl_data, "\01\02\03\04\05\06", 6);
+ i = sockaddr_snprintf(buf, sizeof(buf), "%f %l %a",
+ (struct sockaddr *)&sdl);
+
+ ATF_REQUIRE_EQ_MSG(i, 17, "bad length for sdl");
+ ATF_REQUIRE_STREQ(buf, "18 20 1.2.3.4.5.6");
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, sockaddr_snprintf_in);
+ ATF_TP_ADD_TC(tp, sockaddr_snprintf_in6);
+ ATF_TP_ADD_TC(tp, sockaddr_snprintf_un);
+ ATF_TP_ADD_TC(tp, sockaddr_snprintf_at);
+ ATF_TP_ADD_TC(tp, sockaddr_snprintf_dl);
+
+ return atf_no_error();
+}