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 Adjust as per apb@'s suggestion.
details: https://anonhg.NetBSD.org/src/rev/445a59a7437b
branches: trunk
changeset: 778481:445a59a7437b
user: jruoho <jruoho%NetBSD.org@localhost>
date: Thu Mar 29 08:56:06 2012 +0000
description:
Adjust as per apb@'s suggestion.
diffstat:
tests/lib/libc/stdlib/t_random.c | 37 ++++++++++++++++++++++---------------
1 files changed, 22 insertions(+), 15 deletions(-)
diffs (78 lines):
diff -r 350fef94d8ff -r 445a59a7437b tests/lib/libc/stdlib/t_random.c
--- a/tests/lib/libc/stdlib/t_random.c Thu Mar 29 08:52:31 2012 +0000
+++ b/tests/lib/libc/stdlib/t_random.c Thu Mar 29 08:56:06 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: t_random.c,v 1.2 2012/03/28 10:38:00 jruoho Exp $ */
+/* $NetBSD: t_random.c,v 1.3 2012/03/29 08:56:06 jruoho Exp $ */
/*-
* Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -29,47 +29,54 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: t_random.c,v 1.2 2012/03/28 10:38:00 jruoho Exp $");
+__RCSID("$NetBSD: t_random.c,v 1.3 2012/03/29 08:56:06 jruoho Exp $");
#include <atf-c.h>
+#include <stdio.h>
#include <stdlib.h>
/*
* TODO: Add some general RNG tests (cf. the famous "diehard" tests?).
*/
-ATF_TC(random_zero);
-ATF_TC_HEAD(random_zero, tc)
+ATF_TC(random_same);
+ATF_TC_HEAD(random_same, tc)
{
atf_tc_set_md_var(tc, "descr",
- "Test that random(3) does not always return "
- "zero when the seed is initialized to zero");
+ "Test that random(3) does not always return the same "
+ "value when the seed is initialized to zero");
}
-ATF_TC_BODY(random_zero, tc)
+#define MAX_ITER 10
+
+ATF_TC_BODY(random_same, tc)
{
- const size_t n = 1000000;
+ long buf[MAX_ITER];
size_t i, j;
- long x;
/*
* See CVE-2012-1577.
*/
srandom(0);
- for (i = j = 0; i < n; i++) {
+ for (i = 0; i < __arraycount(buf); i++) {
+
+ buf[i] = random();
+
+ for (j = 0; j < i; j++) {
- if ((x = random()) == 0)
- j++;
+ (void)fprintf(stderr, "i = %zu, j = %zu: "
+ "%ld vs. %ld\n", i, j, buf[i], buf[j]);
+
+ ATF_CHECK(buf[i] != buf[j]);
+ }
}
-
- ATF_REQUIRE(j != n);
}
ATF_TP_ADD_TCS(tp)
{
- ATF_TP_ADD_TC(tp, random_zero);
+ ATF_TP_ADD_TC(tp, random_same);
return atf_no_error();
}
Home |
Main Index |
Thread Index |
Old Index