Module Name:    src
Committed By:   tron
Date:           Sun Nov 14 18:15:08 UTC 2010

Modified Files:
        src/tests/lib/libc/stdlib: t_environment.c

Log Message:
Update tests for *env(3):
- Introduce randomness into "t_setenv" to avoid freeing environment
  variables exactly in the order they have been allocated.
  Also call unsetenv(3) twice to make sure it behaves well if the
  environment variable doesn't exist.
- "t_getenv" is no longer a known failure after getenv(3) and getenv_r(3)
  have been fixed.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/tests/lib/libc/stdlib/t_environment.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/libc/stdlib/t_environment.c
diff -u src/tests/lib/libc/stdlib/t_environment.c:1.9 src/tests/lib/libc/stdlib/t_environment.c:1.10
--- src/tests/lib/libc/stdlib/t_environment.c:1.9	Sat Nov 13 21:08:36 2010
+++ src/tests/lib/libc/stdlib/t_environment.c	Sun Nov 14 18:15:08 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_environment.c,v 1.9 2010/11/13 21:08:36 tron Exp $	*/
+/*	$NetBSD: t_environment.c,v 1.10 2010/11/14 18:15:08 tron Exp $	*/
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: t_environment.c,v 1.9 2010/11/13 21:08:36 tron Exp $");
+__RCSID("$NetBSD: t_environment.c,v 1.10 2010/11/14 18:15:08 tron Exp $");
 
 #include <atf-c.h>
 #include <errno.h>
@@ -79,21 +79,28 @@
 
 ATF_TC_BODY(t_setenv, tc)
 {
-	size_t i;
+	const size_t numvars = 8192;
+	size_t i, offset;
 	char name[1024];
 	char value[1024];
-	for (i = 0; i < 10240; i++) {
-		snprintf(name, sizeof(name), "var%zu", i);
-		snprintf(value, sizeof(value), "value%ld", lrand48());
+
+	offset = lrand48();
+	for (i = 0; i < numvars; i++) {
+		(void)snprintf(name, sizeof(name), "var%zu",
+		    (i * 7 + offset) % numvars);
+		(void)snprintf(value, sizeof(value), "value%ld", lrand48());
 		ATF_CHECK(setenv(name, value, 1) != -1);
 		ATF_CHECK(setenv(name, "foo", 0) != -1);
 		ATF_CHECK_STREQ(getenv(name), value);
 	}
 
-	for (i = 0; i < 10240; i++) {
-		snprintf(name, sizeof(name), "var%zu", i);
+	offset = lrand48();
+	for (i = 0; i < numvars; i++) {
+		(void)snprintf(name, sizeof(name), "var%zu",
+		    (i * 11 + offset) % numvars);
 		ATF_CHECK(unsetenv(name) != -1);
 		ATF_CHECK(getenv(name) == NULL);
+		ATF_CHECK(unsetenv(name) != -1);
 	}
 
 	ATF_CHECK_ERRNO(EINVAL, setenv(NULL, "val", 1) == -1);
@@ -174,11 +181,7 @@
 {
 	ATF_CHECK(setenv("EVIL", "very=bad", 1) != -1);
 	ATF_CHECK_STREQ(getenv("EVIL"), "very=bad");
-
-	atf_tc_expect_fail("getenv(3) doesn't check variable names properly");
 	ATF_CHECK(getenv("EVIL=very") == NULL);
-
-	atf_tc_expect_pass();
 	ATF_CHECK(unsetenv("EVIL") != -1);
 }
 

Reply via email to