summaryrefslogtreecommitdiff
path: root/regress/lib
diff options
context:
space:
mode:
authorArtur Grabowski <art@cvs.openbsd.org>2001-12-29 18:59:31 +0000
committerArtur Grabowski <art@cvs.openbsd.org>2001-12-29 18:59:31 +0000
commitd7fedd11be789abac2ac31721dea98dc3e4b2cdf (patch)
tree796e1a39fee3f5e116be5eed4305ac06228303ee /regress/lib
parent547078c0841b62343f5de259ae47af9ff051211e (diff)
Add options for slient operation and for specifying a count of rounds
instead of running to the limit.
Diffstat (limited to 'regress/lib')
-rw-r--r--regress/lib/libc/malloc/malloc0test.c39
1 files changed, 35 insertions, 4 deletions
diff --git a/regress/lib/libc/malloc/malloc0test.c b/regress/lib/libc/malloc/malloc0test.c
index 459e42c9850..d226af5a281 100644
--- a/regress/lib/libc/malloc/malloc0test.c
+++ b/regress/lib/libc/malloc/malloc0test.c
@@ -7,6 +7,8 @@
#include <unistd.h>
#include <stdlib.h>
#include <setjmp.h>
+#include <limits.h>
+#include <errno.h>
volatile sig_atomic_t got;
jmp_buf jmp;
@@ -59,10 +61,38 @@ main(int argc, char *argv[])
caddr_t zblob = malloc(0);
caddr_t *blobp, blob;
int size, rsize, tsize;
- int count = 0, prot;
+ int prot;
int rval = 0, fuckup = 0;
+ long limit = 200000, count;
+ int ch, silent = 0;
+ char *ep;
+ extern char *__progname;
- while (1) {
+ while ((ch = getopt(argc, argv, "sn:")) != -1) {
+ switch (ch) {
+ case 's':
+ silent = 1;
+ break;
+ case 'n':
+ errno = 0;
+ limit = strtol(optarg, &ep, 10);
+ if (optarg[0] == '\0' || *ep != '\0' ||
+ (errno == ERANGE &&
+ (limit == LONG_MAX || limit == LONG_MIN)))
+ goto usage;
+ break;
+ default:
+usage:
+ fprintf(stderr, "Usage: %s [-s][-n <count>]\n",
+ __progname);
+ exit(1);
+ }
+ }
+
+ if (limit == 0)
+ limit = LONG_MAX;
+
+ for (count = 0; count < limit; count++) {
size = arc4random() % SIZE;
blob = malloc(size);
if (blob == NULL) {
@@ -94,8 +124,9 @@ main(int argc, char *argv[])
}
*blobp = blob;
-
- if (++count % 100000 == 0)
+ if (!silent && count % 100000 == 0 && count != 0)
fprintf(stderr, "count = %d\n", count);
}
+
+ return rval;
} \ No newline at end of file