Skip to content
Snippets Groups Projects
Commit eb5d2cee authored by xleroy's avatar xleroy
Browse files

Rendu le test lists.c plus interessant

git-svn-id: https://yquem.inria.fr/compcert/svn/compcert/trunk@388 fca1b0fc-160b-0410-b1d3-a4f43f01ea2e
parent 94aea060
No related branches found
No related tags found
No related merge requests found
...@@ -28,6 +28,20 @@ struct list * reverselist (struct list * l) ...@@ -28,6 +28,20 @@ struct list * reverselist (struct list * l)
return r; return r;
} }
struct list * reverse_inplace(struct list * l)
{
struct list * prev, * next;
prev = NULL;
while (l != NULL) {
next = l->tl;
l->tl = prev;
prev = l;
l = next;
}
return prev;
}
int checklist(int n, struct list * l) int checklist(int n, struct list * l)
{ {
int i; int i;
...@@ -41,15 +55,27 @@ int checklist(int n, struct list * l) ...@@ -41,15 +55,27 @@ int checklist(int n, struct list * l)
int main(int argc, char ** argv) int main(int argc, char ** argv)
{ {
int n; int n, niter, i;
struct list * l;
if (argc >= 2) n = atoi(argv[1]); else n = 10; if (argc >= 2) n = atoi(argv[1]); else n = 1000;
if (checklist(n, reverselist(buildlist(n)))) { if (argc >= 3) niter = atoi(argv[1]); else niter = 100000;
l = buildlist(n);
if (checklist(n, reverselist(l))) {
printf("OK\n");
} else {
printf("Bug!\n");
return 2;
}
for (i = 0; i < 2*niter + 1; i++) {
l = reverse_inplace(l);
}
if (checklist(n, l)) {
printf("OK\n"); printf("OK\n");
return 0;
} else { } else {
printf("Bug!\n"); printf("Bug!\n");
return 2; return 2;
} }
return 0;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment