Source-Changes-HG archive

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

[src/trunk]: src Two basic tests for getpid(2).



details:   https://anonhg.NetBSD.org/src/rev/d975e9bf7bc3
branches:  trunk
changeset: 763775:d975e9bf7bc3
user:      jruoho <jruoho%NetBSD.org@localhost>
date:      Mon Apr 04 06:48:04 2011 +0000

description:
Two basic tests for getpid(2).

diffstat:

 distrib/sets/lists/tests/mi |    4 +-
 tests/syscall/Makefile      |    7 +-
 tests/syscall/t_getpid.c    |  134 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 142 insertions(+), 3 deletions(-)

diffs (182 lines):

diff -r 14d22a3e9adc -r d975e9bf7bc3 distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Mon Apr 04 06:05:52 2011 +0000
+++ b/distrib/sets/lists/tests/mi       Mon Apr 04 06:48:04 2011 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.285 2011/04/03 16:12:45 jruoho Exp $
+# $NetBSD: mi,v 1.286 2011/04/04 06:48:04 jruoho Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -568,6 +568,7 @@
 ./usr/libdata/debug/usr/tests/syscall/t_cmsg.debug                     tests-syscall-debug     debug,atf
 ./usr/libdata/debug/usr/tests/syscall/t_dup.debug                      tests-syscall-debug     debug,atf
 ./usr/libdata/debug/usr/tests/syscall/t_fsync.debug                    tests-syscall-debug     debug,atf
+./usr/libdata/debug/usr/tests/syscall/t_getpid.debug                   tests-syscall-debug     debug,atf
 ./usr/libdata/debug/usr/tests/syscall/t_mmap.debug                     tests-syscall-debug     debug,atf
 ./usr/libdata/debug/usr/tests/syscall/t_mprotect.debug                 tests-syscall-debug     debug,atf
 ./usr/libdata/debug/usr/tests/syscall/t_timer.debug                    tests-syscall-debug     debug,atf
@@ -2110,6 +2111,7 @@
 ./usr/tests/syscall/t_cmsg                     tests-syscall-tests     atf
 ./usr/tests/syscall/t_dup                      tests-syscall-tests     atf
 ./usr/tests/syscall/t_fsync                    tests-syscall-tests     atf
+./usr/tests/syscall/t_getpid                   tests-syscall-tests     atf
 ./usr/tests/syscall/t_mmap                     tests-syscall-tests     atf
 ./usr/tests/syscall/t_mprotect                 tests-syscall-tests     atf
 ./usr/tests/syscall/t_timer                    tests-syscall-tests     atf
diff -r 14d22a3e9adc -r d975e9bf7bc3 tests/syscall/Makefile
--- a/tests/syscall/Makefile    Mon Apr 04 06:05:52 2011 +0000
+++ b/tests/syscall/Makefile    Mon Apr 04 06:48:04 2011 +0000
@@ -1,10 +1,13 @@
-# $NetBSD: Makefile,v 1.13 2011/04/03 16:12:45 jruoho Exp $
+# $NetBSD: Makefile,v 1.14 2011/04/04 06:48:05 jruoho Exp $
 
 .include <bsd.own.mk>
 
 TESTSDIR=      ${TESTSBASE}/syscall
 
-TESTS_C+=      t_access t_cmsg t_dup t_fsync t_mmap t_mprotect t_timer
+TESTS_C+=      t_access t_cmsg t_dup t_fsync t_getpid
+TESTS_C+=      t_mmap t_mprotect t_timer
+
+LDADD.t_getpid+=-lpthread
 
 LDADD.t_cmsg+= -lrumpnet_local -lrumpnet_net -lrumpnet
 LDADD.t_cmsg+= -lrumpvfs -lrump -lrumpuser -lpthread
diff -r 14d22a3e9adc -r d975e9bf7bc3 tests/syscall/t_getpid.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/syscall/t_getpid.c  Mon Apr 04 06:48:04 2011 +0000
@@ -0,0 +1,134 @@
+/* $NetBSD: t_getpid.c,v 1.1 2011/04/04 06:48:05 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_getpid.c,v 1.1 2011/04/04 06:48:05 jruoho Exp $");
+
+#include <sys/wait.h>
+
+#include <stdlib.h>
+#include <pthread.h>
+#include <unistd.h>
+
+#include <atf-c.h>
+
+static int      maxiter = 10;
+static void    *threadfunc(void *);
+
+static void *
+threadfunc(void *arg)
+{
+       *(pid_t *)arg = getpid();
+
+       return NULL;
+}
+
+ATF_TC(getpid_process);
+ATF_TC_HEAD(getpid_process, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "Test getpid(2) with processes");
+}
+
+ATF_TC_BODY(getpid_process, tc)
+{
+       pid_t ppid, fpid, cpid, tpid, wpid;
+       int i, sta;
+
+       for (i = 0; i < maxiter; i++) {
+
+               tpid = getpid();
+               fpid = fork();
+
+               ATF_REQUIRE(fpid >= 0);
+
+               if (fpid == 0) {
+
+                       cpid = getpid();
+                       ppid = getppid();
+
+                       if (tpid != ppid)
+                               exit(EXIT_FAILURE);
+
+                       if (cpid == ppid)
+                               exit(EXIT_FAILURE);
+
+                       if (tpid == fpid)
+                               exit(EXIT_FAILURE);
+
+                       exit(EXIT_SUCCESS);
+               }
+
+               wpid = wait(&sta);
+
+               if (wpid != fpid)
+                       atf_tc_fail("PID mismatch");
+
+               ATF_REQUIRE(WIFEXITED(sta) != 0);
+
+               if (WEXITSTATUS(sta) != EXIT_SUCCESS)
+                       atf_tc_fail("PID mismatch");
+       }
+}
+
+ATF_TC(getpid_thread);
+ATF_TC_HEAD(getpid_thread, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "Test getpid(2) with threads");
+}
+
+ATF_TC_BODY(getpid_thread, tc)
+{
+       pid_t pid, tpid;
+       pthread_t tid;
+       int i, rv;
+
+       for (i = 0; i < maxiter; i++) {
+
+               pid = getpid();
+
+               rv = pthread_create(&tid, NULL, threadfunc, &tpid);
+               ATF_REQUIRE(rv == 0);
+
+               rv = pthread_join(tid, NULL);
+               ATF_REQUIRE(rv == 0);
+
+               if (pid != tpid)
+                       atf_tc_fail("Unequal PIDs");
+       }
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+       ATF_TP_ADD_TC(tp, getpid_process);
+       ATF_TP_ADD_TC(tp, getpid_thread);
+
+       return atf_no_error();
+}



Home | Main Index | Thread Index | Old Index