Module Name:    src
Committed By:   jruoho
Date:           Mon Apr  4 06:48:05 UTC 2011

Modified Files:
        src/distrib/sets/lists/tests: mi
        src/tests/syscall: Makefile
Added Files:
        src/tests/syscall: t_getpid.c

Log Message:
Two basic tests for getpid(2).


To generate a diff of this commit:
cvs rdiff -u -r1.285 -r1.286 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.13 -r1.14 src/tests/syscall/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/syscall/t_getpid.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.285 src/distrib/sets/lists/tests/mi:1.286
--- src/distrib/sets/lists/tests/mi:1.285	Sun Apr  3 16:12:45 2011
+++ src/distrib/sets/lists/tests/mi	Mon Apr  4 06:48:04 2011
@@ -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

Index: src/tests/syscall/Makefile
diff -u src/tests/syscall/Makefile:1.13 src/tests/syscall/Makefile:1.14
--- src/tests/syscall/Makefile:1.13	Sun Apr  3 16:12:45 2011
+++ src/tests/syscall/Makefile	Mon Apr  4 06:48:05 2011
@@ -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

Added files:

Index: src/tests/syscall/t_getpid.c
diff -u /dev/null src/tests/syscall/t_getpid.c:1.1
--- /dev/null	Mon Apr  4 06:48:05 2011
+++ src/tests/syscall/t_getpid.c	Mon Apr  4 06:48:05 2011
@@ -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();
+}

Reply via email to