Sync usage with man page.
[netbsd-mini2440.git] / regress / lib / libc / randomid / idtest.c
blobd6237bea092ce3aaece44c70f76341fe63849463
1 /* $NetBSD: idtest.c,v 1.4 2003/12/10 05:22:18 itojun Exp $ */
3 /* If defined, abort at first short period and only test REGRESS times. */
4 #define REGRESS 10000000 /* should be enough... */
6 #include <sys/types.h>
8 #include <assert.h>
9 #include <randomid.h>
10 #include <inttypes.h>
11 #include <stdio.h>
12 #include <string.h>
13 #include <stdlib.h>
15 #define PERIOD 30000
17 uint64_t last[65536];
19 uint64_t n = 0;
21 main()
23 static randomid_t ctx = NULL;
24 uint64_t lowest;
25 uint16_t id;
26 int i;
28 memset(last, 0, sizeof(last));
29 ctx = randomid_new(16, (long)3600);
31 lowest = UINT64_MAX;
32 while (n < UINT64_MAX) {
33 id = randomid(ctx);
34 if (last[id] > 0) {
35 if (n - last[id] <= lowest) {
36 if (lowest != UINT64_MAX) {
37 printf("id %5d "
38 "last call for id at %9lld, "
39 "current call %9lld (diff %5lld)\n",
40 id, last[id], n, n - last[id]);
41 #ifdef REGRESS
42 if (n - last[id] < PERIOD) {
43 printf("diff (%"PRIu64") less "
44 "than minimum period "
45 "(%d)\n", n - last[id],
46 PERIOD);
47 abort();
49 #endif
51 lowest = n - last[id];
54 last[id] = n;
55 n++;
56 #ifdef REGRESS
57 if (n > REGRESS)
58 break;
59 #endif
61 exit(0);