Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/regress/lib/libc/randomid Add a regression test for randomid...



details:   https://anonhg.NetBSD.org/src/rev/9b7f19423b3e
branches:  trunk
changeset: 555341:9b7f19423b3e
user:      simonb <simonb%NetBSD.org@localhost>
date:      Fri Nov 14 23:10:48 2003 +0000

description:
Add a regression test for randomid(3).

diffstat:

 regress/lib/libc/randomid/Makefile |  10 ++++++
 regress/lib/libc/randomid/idtest.c |  55 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 65 insertions(+), 0 deletions(-)

diffs (73 lines):

diff -r e5853f2591d2 -r 9b7f19423b3e regress/lib/libc/randomid/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/regress/lib/libc/randomid/Makefile        Fri Nov 14 23:10:48 2003 +0000
@@ -0,0 +1,10 @@
+#      $NetBSD: Makefile,v 1.1 2003/11/14 23:10:48 simonb Exp $
+
+NOMAN= # defined
+
+PROG=  idtest
+
+regress: ${PROG}
+       ./${PROG}
+
+.include <bsd.prog.mk>
diff -r e5853f2591d2 -r 9b7f19423b3e regress/lib/libc/randomid/idtest.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/regress/lib/libc/randomid/idtest.c        Fri Nov 14 23:10:48 2003 +0000
@@ -0,0 +1,55 @@
+/* $NetBSD: idtest.c,v 1.1 2003/11/14 23:10:48 simonb Exp $ */
+
+/* If defined, abort at first short period and only test REGRESS times. */
+#define        REGRESS         10000000                /* should be enough... */
+
+#include <sys/types.h>
+
+#include <assert.h>
+#include <string.h>
+#include <limits.h>
+#include <randomid.h>
+
+#define        PERIOD          36000
+
+uint64_t last[65536];
+
+uint64_t n = 0;
+
+main()
+{
+       static randomid_t ctx = NULL;
+       uint64_t lowest;
+       uint16_t id;
+       int i;
+
+       memset(last, 0, sizeof(last));
+       ctx = randomid_new(16, (long)3600);
+
+       lowest = ULLONG_MAX;
+       while (n < ULLONG_MAX) {
+               id = randomid(ctx);
+               if (last[id] > 0) {
+                       if (n - last[id] <= lowest) {
+                               if (lowest != ULLONG_MAX) {
+                                       printf("id %5d  "
+                                           "last call for id at %9lld, "
+                                           "current call %9lld (diff %5lld)\n",
+                                           id, last[id], n, n - last[id]);
+#ifdef REGRESS
+                                       assert(lowest >= REGRESS);
+#endif
+                               }
+                               lowest = n - last[id];
+                       }
+               }
+               last[id] = n;
+               n++;
+#ifdef REGRESS
+               if (n > REGRESS)
+                       break;
+#endif
+       }
+       exit(0);
+}
+



Home | Main Index | Thread Index | Old Index