Module Name:    src
Committed By:   jruoho
Date:           Mon May  9 07:31:51 UTC 2011

Modified Files:
        src/distrib/sets/lists/tests: mi
        src/tests/lib/libc/stdlib: Makefile
Added Files:
        src/tests/lib/libc/stdlib: t_exit.c

Log Message:
Few basic tests for exit(3).


To generate a diff of this commit:
cvs rdiff -u -r1.333 -r1.334 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.11 -r1.12 src/tests/lib/libc/stdlib/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/lib/libc/stdlib/t_exit.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.333 src/distrib/sets/lists/tests/mi:1.334
--- src/distrib/sets/lists/tests/mi:1.333	Mon May  9 06:04:14 2011
+++ src/distrib/sets/lists/tests/mi	Mon May  9 07:31:50 2011
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.333 2011/05/09 06:04:14 jruoho Exp $
+# $NetBSD: mi,v 1.334 2011/05/09 07:31:50 jruoho Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -433,6 +433,7 @@
 ./usr/libdata/debug/usr/tests/lib/libc/stdlib/t_div.debug		tests-lib-debug		debug,atf
 ./usr/libdata/debug/usr/tests/lib/libc/stdlib/t_environment.debug	tests-lib-debug		debug,atf
 ./usr/libdata/debug/usr/tests/lib/libc/stdlib/t_environment_pth.debug	tests-lib-debug		debug,atf
+./usr/libdata/debug/usr/tests/lib/libc/stdlib/t_exit.debug		tests-lib-debug		debug,atf
 ./usr/libdata/debug/usr/tests/lib/libc/stdlib/t_hsearch.debug		tests-lib-debug		debug,atf
 ./usr/libdata/debug/usr/tests/lib/libc/stdlib/t_mi_vector_hash.debug	tests-lib-debug		debug,atf
 ./usr/libdata/debug/usr/tests/lib/libc/stdlib/t_posix_memalign.debug	tests-lib-debug		debug,atf
@@ -1936,6 +1937,7 @@
 ./usr/tests/lib/libc/stdlib/t_div		tests-lib-tests		atf
 ./usr/tests/lib/libc/stdlib/t_environment	tests-lib-tests		atf
 ./usr/tests/lib/libc/stdlib/t_environment_pth	tests-lib-tests		atf
+./usr/tests/lib/libc/stdlib/t_exit		tests-lib-tests		atf
 ./usr/tests/lib/libc/stdlib/t_getopt		tests-lib-tests		atf
 ./usr/tests/lib/libc/stdlib/t_hsearch		tests-lib-tests		atf
 ./usr/tests/lib/libc/stdlib/t_mi_vector_hash	tests-lib-tests		atf

Index: src/tests/lib/libc/stdlib/Makefile
diff -u src/tests/lib/libc/stdlib/Makefile:1.11 src/tests/lib/libc/stdlib/Makefile:1.12
--- src/tests/lib/libc/stdlib/Makefile:1.11	Tue Apr  5 08:24:28 2011
+++ src/tests/lib/libc/stdlib/Makefile	Mon May  9 07:31:51 2011
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.11 2011/04/05 08:24:28 jruoho Exp $
+# $NetBSD: Makefile,v 1.12 2011/05/09 07:31:51 jruoho Exp $
 
 .include <bsd.own.mk>
 
@@ -7,6 +7,7 @@
 TESTS_C+=	t_div
 TESTS_C+=	t_environment
 TESTS_C+=	t_environment_pth
+TESTS_C+=	t_exit
 TESTS_C+=	t_hsearch
 TESTS_C+=	t_mi_vector_hash
 TESTS_C+=	t_posix_memalign

Added files:

Index: src/tests/lib/libc/stdlib/t_exit.c
diff -u /dev/null src/tests/lib/libc/stdlib/t_exit.c:1.1
--- /dev/null	Mon May  9 07:31:51 2011
+++ src/tests/lib/libc/stdlib/t_exit.c	Mon May  9 07:31:51 2011
@@ -0,0 +1,186 @@
+/* $NetBSD: t_exit.c,v 1.1 2011/05/09 07:31:51 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_exit.c,v 1.1 2011/05/09 07:31:51 jruoho Exp $");
+
+#include <sys/wait.h>
+
+#include <atf-c.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+static bool	fail;
+static void	func(void);
+
+static void
+func(void)
+{
+	fail = false;
+}
+
+ATF_TC(exit_atexit);
+ATF_TC_HEAD(exit_atexit, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "A basic test of atexit(3)");
+}
+
+ATF_TC_BODY(exit_atexit, tc)
+{
+	pid_t pid;
+	int sta;
+
+	pid = fork();
+	ATF_REQUIRE(pid >= 0);
+
+	if (pid == 0) {
+
+		if (atexit(func) != 0)
+			_exit(EXIT_FAILURE);
+
+		fail = true;
+
+		_exit(EXIT_SUCCESS);
+	}
+
+	(void)wait(&sta);
+
+	if (WIFEXITED(sta) == 0 || WEXITSTATUS(sta) != EXIT_SUCCESS)
+		atf_tc_fail("atexit(3) failed");
+
+	if (fail != false)
+		atf_tc_fail("atexit(3) was not called");
+}
+
+ATF_TC(exit_basic);
+ATF_TC_HEAD(exit_basic, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "A basic test of exit(3)");
+}
+
+ATF_TC_BODY(exit_basic, tc)
+{
+	pid_t pid;
+	int sta;
+
+	pid = fork();
+	ATF_REQUIRE(pid >= 0);
+
+	if (pid == 0) {
+		exit(EXIT_SUCCESS);
+		exit(EXIT_FAILURE);
+	}
+
+	(void)wait(&sta);
+
+	if (WIFEXITED(sta) == 0 || WEXITSTATUS(sta) != EXIT_SUCCESS)
+		atf_tc_fail("exit(3) did not exit successfully");
+}
+
+ATF_TC(exit_status);
+ATF_TC_HEAD(exit_status, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "Test exit(3) status");
+}
+
+ATF_TC_BODY(exit_status, tc)
+{
+	const int n = 10;
+	int i, sta;
+	pid_t pid;
+
+	for (i = 0; i < n; i++) {
+
+		pid = fork();
+
+		if (pid < 0)
+			exit(EXIT_FAILURE);
+
+		if (pid == 0)
+			exit(i);
+
+		(void)wait(&sta);
+
+		if (WIFEXITED(sta) == 0 || WEXITSTATUS(sta) != i)
+			atf_tc_fail("invalid exit(3) status");
+	}
+}
+
+ATF_TC(exit_tmpfile);
+ATF_TC_HEAD(exit_tmpfile, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "Temporary files are unlinked?");
+}
+
+ATF_TC_BODY(exit_tmpfile, tc)
+{
+	int sta, fd = -1;
+	char buf[12];
+	pid_t pid;
+	FILE *f;
+
+	(void)strlcpy(buf, "exit.XXXXXX", sizeof(buf));
+
+	pid = fork();
+	ATF_REQUIRE(pid >= 0);
+
+	if (pid == 0) {
+
+		fd = mkstemp(buf);
+
+		if (fd < 0)
+			exit(EXIT_FAILURE);
+
+		exit(EXIT_SUCCESS);
+	}
+
+	(void)wait(&sta);
+
+	if (WIFEXITED(sta) == 0 || WEXITSTATUS(sta) != EXIT_SUCCESS)
+		atf_tc_fail("failed to create temporary file");
+
+	f = fdopen(fd, "r");
+
+	if (f != NULL)
+		atf_tc_fail("exit(3) did not clear temporary file");
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+	ATF_TP_ADD_TC(tp, exit_atexit);
+	ATF_TP_ADD_TC(tp, exit_basic);
+	ATF_TP_ADD_TC(tp, exit_status);
+	ATF_TP_ADD_TC(tp, exit_tmpfile);
+
+	return atf_no_error();
+}

Reply via email to