aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
authorwelinder@anemone.rentec.com <welinder@anemone.rentec.com>2004-09-26 15:08:26 -0700
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-07 21:03:23 -0700
commitac763443663d3f87b6fff67ea6e8a4384f0a86a8 (patch)
tree365cf77a8065e4673d5a32f2eaa64733fcb92ec8
parent1c849c0c3a50b115a58975431cd3dd876265bed6 (diff)
downloadsparse-dev-ac763443663d3f87b6fff67ea6e8a4384f0a86a8.tar.gz
New BitKeeper file ``test-sort.c''
-rw-r--r--Makefile3
-rw-r--r--test-sort.c45
2 files changed, 48 insertions, 0 deletions
diff --git a/Makefile b/Makefile
index 0360edfa..481960a0 100644
--- a/Makefile
+++ b/Makefile
@@ -37,6 +37,9 @@ test-parsing: test-parsing.o $(LIB_FILE)
test-linearize: test-linearize.o $(LIB_FILE)
$(CC) $(LDFLAGS) -o $@ $< $(LIBS)
+test-sort: test-sort.o $(LIB_FILE)
+ gcc $(LDFLAGS) -o $@ $< $(LIBS)
+
compile: compile.o compile-i386.o $(LIB_FILE)
$(CC) $(LDFLAGS) -o $@ $< compile-i386.o $(LIBS)
diff --git a/test-sort.c b/test-sort.c
new file mode 100644
index 00000000..c259e2b6
--- /dev/null
+++ b/test-sort.c
@@ -0,0 +1,45 @@
+#include "lib.h"
+#include <stdio.h>
+#include <stdlib.h>
+
+static int
+int_cmp (const void *_a, const void *_b)
+{
+ const int *a = _a;
+ const int *b = _b;
+ return *a - *b;
+}
+
+#define MIN(_x,_y) ((_x) < (_y) ? (_x) : (_y))
+
+int
+main (int argc, char **argv)
+{
+ struct ptr_list *l = NULL, *l2;
+ int i, *e;
+ const int N = argv[1] ? atoi (argv[1]) : 10000;
+
+ srand (N);
+ for (i = 0; i < 1000; i++)
+ (void)rand ();
+
+ for (i = 0; i < N; i++) {
+ e = (int *)malloc (sizeof (int));
+ *e = rand ();
+ add_ptr_list (&l, e);
+ }
+ sort_list (&l, int_cmp);
+ // Sort already sorted stuff.
+ sort_list (&l, int_cmp);
+
+ l2 = l;
+ do {
+ l2->nr = MIN (l2->nr, rand () % 3);
+ for (i = 0; i < l2->nr; i++)
+ *((int*)(l2->list[i])) = rand();
+ l2 = l2->next;
+ } while (l2 != l);
+ sort_list (&l, int_cmp);
+
+ return 0;
+}