Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/tests/lib/libc/stdlib Update tests for *env(3):
details: https://anonhg.NetBSD.org/src/rev/b8561a546594
branches: trunk
changeset: 758742:b8561a546594
user: tron <tron%NetBSD.org@localhost>
date: Sun Nov 14 18:15:08 2010 +0000
description:
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.
diffstat:
tests/lib/libc/stdlib/t_environment.c | 27 +++++++++++++++------------
1 files changed, 15 insertions(+), 12 deletions(-)
diffs (65 lines):
diff -r 8a6580d062e8 -r b8561a546594 tests/lib/libc/stdlib/t_environment.c
--- a/tests/lib/libc/stdlib/t_environment.c Sun Nov 14 18:11:42 2010 +0000
+++ b/tests/lib/libc/stdlib/t_environment.c Sun Nov 14 18:15:08 2010 +0000
@@ -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);
}
Home |
Main Index |
Thread Index |
Old Index