Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Few naive checks for cpuset(3) and ftok(3).



details:   https://anonhg.NetBSD.org/src/rev/4fbb62ad07bd
branches:  trunk
changeset: 771075:4fbb62ad07bd
user:      jruoho <jruoho%NetBSD.org@localhost>
date:      Tue Nov 08 05:47:00 2011 +0000

description:
Few naive checks for cpuset(3) and ftok(3).

diffstat:

 distrib/sets/lists/tests/mi   |    6 +-
 tests/lib/libc/gen/Makefile   |    4 +-
 tests/lib/libc/gen/t_cpuset.c |  114 ++++++++++++++++++++++++++++++++++++++++++
 tests/lib/libc/gen/t_ftok.c   |  107 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 229 insertions(+), 2 deletions(-)

diffs (289 lines):

diff -r 10a862c80f2c -r 4fbb62ad07bd distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Tue Nov 08 01:52:05 2011 +0000
+++ b/distrib/sets/lists/tests/mi       Tue Nov 08 05:47:00 2011 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.419 2011/11/06 18:53:00 christos Exp $
+# $NetBSD: mi,v 1.420 2011/11/08 05:47:00 jruoho Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -358,11 +358,13 @@
 ./usr/libdata/debug/usr/tests/lib/libc/gen/t_assert.debug              tests-lib-debug         debug,atf
 ./usr/libdata/debug/usr/tests/lib/libc/gen/t_basedirname.debug         tests-lib-debug         debug,atf
 ./usr/libdata/debug/usr/tests/lib/libc/gen/t_closefrom.debug           tests-lib-debug         debug,atf
+./usr/libdata/debug/usr/tests/lib/libc/gen/t_cpuset.debug              tests-lib-debug         debug,atf
 ./usr/libdata/debug/usr/tests/lib/libc/gen/t_dir.debug                 tests-lib-debug         debug,atf
 ./usr/libdata/debug/usr/tests/lib/libc/gen/t_fmtcheck.debug            tests-lib-debug         debug,atf
 ./usr/libdata/debug/usr/tests/lib/libc/gen/t_fpclassify.debug          tests-lib-debug         debug,atf
 ./usr/libdata/debug/usr/tests/lib/libc/gen/t_fpsetmask.debug           tests-lib-debug         debug,atf
 ./usr/libdata/debug/usr/tests/lib/libc/gen/t_fpsetround.debug          tests-lib-debug         debug,atf
+./usr/libdata/debug/usr/tests/lib/libc/gen/t_ftok.debug                        tests-lib-debug         debug,atf
 ./usr/libdata/debug/usr/tests/lib/libc/gen/t_fmtcheck.debug            tests-lib-debug         debug,atf
 ./usr/libdata/debug/usr/tests/lib/libc/gen/t_getcwd.debug              tests-lib-debug         debug,atf
 ./usr/libdata/debug/usr/tests/lib/libc/gen/t_getgrent.debug            tests-lib-debug         debug,atf
@@ -1919,11 +1921,13 @@
 ./usr/tests/lib/libc/gen/t_assert              tests-lib-tests         atf
 ./usr/tests/lib/libc/gen/t_basedirname         tests-lib-tests         atf
 ./usr/tests/lib/libc/gen/t_closefrom           tests-lib-tests         atf
+./usr/tests/lib/libc/gen/t_cpuset              tests-lib-tests         atf
 ./usr/tests/lib/libc/gen/t_dir                 tests-lib-tests         atf
 ./usr/tests/lib/libc/gen/t_fmtcheck            tests-lib-tests         atf
 ./usr/tests/lib/libc/gen/t_fpclassify          tests-lib-tests         atf
 ./usr/tests/lib/libc/gen/t_fpsetmask           tests-lib-tests         atf
 ./usr/tests/lib/libc/gen/t_fpsetround          tests-lib-tests         atf
+./usr/tests/lib/libc/gen/t_ftok                        tests-lib-tests         atf
 ./usr/tests/lib/libc/gen/t_getcwd              tests-lib-tests         atf
 ./usr/tests/lib/libc/gen/t_getgrent            tests-lib-tests         atf
 ./usr/tests/lib/libc/gen/t_glob                        tests-lib-tests         atf
diff -r 10a862c80f2c -r 4fbb62ad07bd tests/lib/libc/gen/Makefile
--- a/tests/lib/libc/gen/Makefile       Tue Nov 08 01:52:05 2011 +0000
+++ b/tests/lib/libc/gen/Makefile       Tue Nov 08 05:47:00 2011 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.32 2011/11/05 18:07:15 jruoho Exp $
+# $NetBSD: Makefile,v 1.33 2011/11/08 05:47:00 jruoho Exp $
 
 .include <bsd.own.mk>
 
@@ -8,11 +8,13 @@
 TESTS_C+=      t_assert
 TESTS_C+=      t_basedirname
 TESTS_C+=      t_closefrom
+TESTS_C+=      t_cpuset
 TESTS_C+=      t_dir
 TESTS_C+=      t_fmtcheck
 TESTS_C+=      t_fpclassify
 TESTS_C+=      t_fpsetmask
 TESTS_C+=      t_fpsetround
+TESTS_C+=      t_ftok
 TESTS_C+=      t_getcwd
 TESTS_C+=      t_getgrent
 TESTS_C+=      t_glob
diff -r 10a862c80f2c -r 4fbb62ad07bd tests/lib/libc/gen/t_cpuset.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/lib/libc/gen/t_cpuset.c     Tue Nov 08 05:47:00 2011 +0000
@@ -0,0 +1,114 @@
+/*     $NetBSD: t_cpuset.c,v 1.1 2011/11/08 05:47:00 jruoho Exp $ */
+
+/*-
+ * Copyright (c) 2011 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jukka Ruohonen.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: t_cpuset.c,v 1.1 2011/11/08 05:47:00 jruoho Exp $");
+
+#include <atf-c.h>
+#include <limits.h>
+#include <stdio.h>
+#include <sched.h>
+
+ATF_TC(cpuset_err);
+ATF_TC_HEAD(cpuset_err, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "Test errors from cpuset(3)");
+}
+
+ATF_TC_BODY(cpuset_err, tc)
+{
+       cpuset_t *set;
+
+       set = cpuset_create();
+       ATF_REQUIRE(set != NULL);
+
+       ATF_CHECK(cpuset_set(-1, set) == -1);
+       ATF_CHECK(cpuset_clr(-1, set) == -1);
+       ATF_CHECK(cpuset_isset(-1, set) == -1);
+
+       ATF_CHECK(cpuset_set(INT_MAX, set) == -1);
+       ATF_CHECK(cpuset_clr(INT_MAX, set) == -1);
+       ATF_CHECK(cpuset_isset(INT_MAX, set) == -1);
+
+       cpuset_destroy(set);
+}
+
+ATF_TC(cpuset_set);
+ATF_TC_HEAD(cpuset_set, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "Test cpuset_set(3)");
+}
+
+ATF_TC_BODY(cpuset_set, tc)
+{
+       cpuset_t *set;
+
+       set = cpuset_create();
+       ATF_REQUIRE(set != NULL);
+
+       ATF_REQUIRE(cpuset_set(0, set) == 0);
+       ATF_REQUIRE(cpuset_isset(0, set) > 0);
+       ATF_REQUIRE(cpuset_clr(0, set) == 0);
+       ATF_REQUIRE(cpuset_isset(0, set) == 0);
+
+       cpuset_destroy(set);
+}
+
+ATF_TC(cpuset_size);
+ATF_TC_HEAD(cpuset_size, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "Test puset_size(3)");
+}
+
+ATF_TC_BODY(cpuset_size, tc)
+{
+       cpuset_t *set;
+       size_t size;
+
+       set = cpuset_create();
+       ATF_REQUIRE(set != NULL);
+
+       size = cpuset_size(set);
+
+       ATF_CHECK(cpuset_set((size * 8) - 1, set) == 0);
+       ATF_CHECK(cpuset_set((size * 8) + 1, set) == -1);
+
+       cpuset_destroy(set);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+       ATF_TP_ADD_TC(tp, cpuset_err);
+       ATF_TP_ADD_TC(tp, cpuset_set);
+       ATF_TP_ADD_TC(tp, cpuset_size);
+
+       return atf_no_error();
+}
diff -r 10a862c80f2c -r 4fbb62ad07bd tests/lib/libc/gen/t_ftok.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/lib/libc/gen/t_ftok.c       Tue Nov 08 05:47:00 2011 +0000
@@ -0,0 +1,107 @@
+/*     $NetBSD: t_ftok.c,v 1.1 2011/11/08 05:47:00 jruoho Exp $ */
+
+/*-
+ * Copyright (c) 2011 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jukka Ruohonen.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: t_ftok.c,v 1.1 2011/11/08 05:47:00 jruoho Exp $");
+
+#include <sys/types.h>
+#include <sys/ipc.h>
+
+#include <atf-c.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+static const char *path = "ftok";
+static const char *hlnk = "hlnk";
+static const char *slnk = "slnk";
+static const int key = 123456789;
+
+ATF_TC(ftok_err);
+ATF_TC_HEAD(ftok_err, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "Test errors from ftok(3)");
+}
+
+ATF_TC_BODY(ftok_err, tc)
+{
+       ATF_REQUIRE(ftok("/a/b/c/d/e/f/g/h/i", key) == -1);
+}
+
+ATF_TC_WITH_CLEANUP(ftok_link);
+ATF_TC_HEAD(ftok_link, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "Test that links return the same key");
+}
+
+ATF_TC_BODY(ftok_link, tc)
+{
+       key_t k1, k2, k3;
+       int fd;
+
+       fd = open(path, O_RDONLY | O_CREAT);
+
+       ATF_REQUIRE(fd >= 0);
+       ATF_REQUIRE(link(path, hlnk) == 0);
+       ATF_REQUIRE(symlink(path, slnk) == 0);
+
+       k1 = ftok(path, key);
+       k2 = ftok(hlnk, key);
+       k3 = ftok(slnk, key);
+
+       ATF_REQUIRE(k1 != -1);
+       ATF_REQUIRE(k2 != -1);
+       ATF_REQUIRE(k3 != -1);
+
+       if (k1 != k2)
+               atf_tc_fail("ftok(3) gave different key for a hard link");
+
+       if (k1 != k3)
+               atf_tc_fail("ftok(3) gave different key for a symbolic link");
+
+       ATF_REQUIRE(unlink(path) == 0);
+       ATF_REQUIRE(unlink(hlnk) == 0);
+       ATF_REQUIRE(unlink(slnk) == 0);
+}
+
+ATF_TC_CLEANUP(ftok_link, tc)
+{
+       (void)unlink(path);
+       (void)unlink(hlnk);
+       (void)unlink(slnk);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+       ATF_TP_ADD_TC(tp, ftok_err);
+       ATF_TP_ADD_TC(tp, ftok_link);
+
+       return atf_no_error();
+}



Home | Main Index | Thread Index | Old Index