diff options
author | xleroy <xleroy@fca1b0fc-160b-0410-b1d3-a4f43f01ea2e> | 2006-09-08 15:43:41 +0000 |
---|---|---|
committer | xleroy <xleroy@fca1b0fc-160b-0410-b1d3-a4f43f01ea2e> | 2006-09-08 15:43:41 +0000 |
commit | a5b33dcab2e6218e9e17f36a26520fd1dabc58bb (patch) | |
tree | 93f6b4595b7ba079ed3517b7bc07e50c3049adcf /test/c/qsort.c | |
parent | 43b4d97a655e52e3962c0d14bda39dacb24af901 (diff) | |
download | compcert-a5b33dcab2e6218e9e17f36a26520fd1dabc58bb.tar.gz compcert-a5b33dcab2e6218e9e17f36a26520fd1dabc58bb.zip |
MAJ des tests C
git-svn-id: https://yquem.inria.fr/compcert/svn/compcert/trunk@86 fca1b0fc-160b-0410-b1d3-a4f43f01ea2e
Diffstat (limited to 'test/c/qsort.c')
-rw-r--r-- | test/c/qsort.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/test/c/qsort.c b/test/c/qsort.c index 9f8e5b18..1d70463c 100644 --- a/test/c/qsort.c +++ b/test/c/qsort.c @@ -1,3 +1,7 @@ +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + void quicksort(int lo, int hi, int base[]) { int i,j; @@ -14,3 +18,33 @@ void quicksort(int lo, int hi, int base[]) } } +int cmplong(const void * i, const void * j) +{ + long vi = *((long *) i); + long vj = *((long *) j); + if (vi == vj) return 0; + if (vi < vj) return -1; + return 1; +} + +int main(int argc, char ** argv) +{ + int n, i; + long * a, * b; + int bench = 0; + + if (argc >= 2) n = atoi(argv[1]); else n = 1000; + if (argc >= 3) bench = 1; + a = malloc(n * sizeof(long)); + b = malloc(n * sizeof(long)); + for (i = 0; i < n; i++) b[i] = a[i] = rand() & 0xFFFF; + quicksort(0, n - 1, a); + if (!bench) { + qsort(b, n, sizeof(long), cmplong); + for (i = 0; i < n; i++) { + if (a[i] != b[i]) { printf("Bug!\n"); return 2; } + } + printf("OK\n"); + } + return 0; +} |