summaryrefslogtreecommitdiff
path: root/regress
diff options
context:
space:
mode:
authorNiels Provos <provos@cvs.openbsd.org>2002-06-11 22:10:23 +0000
committerNiels Provos <provos@cvs.openbsd.org>2002-06-11 22:10:23 +0000
commitf0680d10252a6e1b675dc0f029118fa1f5d56a30 (patch)
tree5e98c97ffe4f8b42cd65f37b05a1b0328e920dc1 /regress
parentb40d15ab1bbc4d869fb71078025da4b18b42fba4 (diff)
bsd makefiles are too stupid to deal with more than one program per
makefile. move into subdirs.
Diffstat (limited to 'regress')
-rw-r--r--regress/sys/sys/tree/Makefile4
-rw-r--r--regress/sys/sys/tree/rb/Makefile5
-rw-r--r--regress/sys/sys/tree/rb/rb-test.c79
-rw-r--r--regress/sys/sys/tree/splay/Makefile5
-rw-r--r--regress/sys/sys/tree/splay/splay-test.c (renamed from regress/sys/sys/tree/splay-test.c)0
5 files changed, 91 insertions, 2 deletions
diff --git a/regress/sys/sys/tree/Makefile b/regress/sys/sys/tree/Makefile
index 549809d88ca..c8bd2714ee5 100644
--- a/regress/sys/sys/tree/Makefile
+++ b/regress/sys/sys/tree/Makefile
@@ -1,5 +1,5 @@
-# $OpenBSD: Makefile,v 1.1 2002/06/11 21:55:57 provos Exp $
+# $OpenBSD: Makefile,v 1.2 2002/06/11 22:10:22 provos Exp $
-PROG= splay-test
+SUBDIRS= splay rb
.include <bsd.regress.mk>
diff --git a/regress/sys/sys/tree/rb/Makefile b/regress/sys/sys/tree/rb/Makefile
new file mode 100644
index 00000000000..61695ac2259
--- /dev/null
+++ b/regress/sys/sys/tree/rb/Makefile
@@ -0,0 +1,5 @@
+# $OpenBSD: Makefile,v 1.1 2002/06/11 22:10:22 provos Exp $
+
+PROG= rb-test
+
+.include <bsd.regress.mk>
diff --git a/regress/sys/sys/tree/rb/rb-test.c b/regress/sys/sys/tree/rb/rb-test.c
new file mode 100644
index 00000000000..9400edccec2
--- /dev/null
+++ b/regress/sys/sys/tree/rb/rb-test.c
@@ -0,0 +1,79 @@
+#include <sys/types.h>
+#include <sys/tree.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <err.h>
+#include <stdlib.h>
+
+struct node {
+ RB_ENTRY(node) node;
+ int key;
+};
+
+RB_HEAD(tree, node) root;
+
+int
+compare(struct node *a, struct node *b)
+{
+ if (a->key < b->key) return (-1);
+ else if (a->key > b->key) return (1);
+ return (0);
+}
+
+RB_PROTOTYPE(tree, node, node, compare);
+
+RB_GENERATE(tree, node, node, compare);
+
+#define ITER 150
+#define MIN 5
+#define MAX 5000
+
+int
+main(int argc, char **argv)
+{
+ struct node *tmp, *ins;
+ int i, max, min;
+
+ RB_INIT(&root);
+
+ for (i = 0; i < ITER; i++) {
+ tmp = malloc(sizeof(struct node));
+ if (tmp == NULL) err(1, "malloc");
+ do {
+ tmp->key = arc4random() % (MAX-MIN);
+ tmp->key += MIN;
+ } while (RB_FIND(tree, &root, tmp) != NULL);
+ if (i == 0)
+ max = min = tmp->key;
+ else {
+ if (tmp->key > max)
+ max = tmp->key;
+ if (tmp->key < min)
+ min = tmp->key;
+ }
+ if (RB_INSERT(tree, &root, tmp) != NULL)
+ errx(1, "RB_INSERT failed");
+ }
+
+ ins = RB_MIN(tree, &root);
+ if (ins->key != min)
+ errx(1, "min does not match");
+ tmp = ins;
+ ins = RB_MAX(tree, &root);
+ if (ins->key != max)
+ errx(1, "max does not match");
+
+ if (RB_REMOVE(tree, &root, tmp) != tmp)
+ errx(1, "RB_REMOVE failed");
+
+ for (i = 0; i < ITER - 1; i++) {
+ tmp = RB_ROOT(&root);
+ if (tmp == NULL)
+ errx(1, "RB_ROOT error");
+ if (RB_REMOVE(tree, &root, tmp) != tmp)
+ errx(1, "RB_REMOVE error");
+ free(tmp);
+ }
+
+ exit(0);
+}
diff --git a/regress/sys/sys/tree/splay/Makefile b/regress/sys/sys/tree/splay/Makefile
new file mode 100644
index 00000000000..66707f30ee3
--- /dev/null
+++ b/regress/sys/sys/tree/splay/Makefile
@@ -0,0 +1,5 @@
+# $OpenBSD: Makefile,v 1.1 2002/06/11 22:10:22 provos Exp $
+
+PROG= splay-test
+
+.include <bsd.regress.mk>
diff --git a/regress/sys/sys/tree/splay-test.c b/regress/sys/sys/tree/splay/splay-test.c
index cd8c1d6e311..cd8c1d6e311 100644
--- a/regress/sys/sys/tree/splay-test.c
+++ b/regress/sys/sys/tree/splay/splay-test.c