summaryrefslogtreecommitdiff
path: root/test/harness/mainlists.c
blob: ef11f6ef8ea244f54a3788b942e7d27a1bae9231 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>

void * compcert_alloc(int sz)
{
  return malloc(sz);
}

struct cons { int hd; struct cons * tl; };
typedef struct cons * list;

extern list buildlist(int n);
extern list reverselist(list l);

int checklist(int n, list l)
{
  int i;
  for (i = 0; i <= n; i++) {
    if (l == NULL) return 0;
    if (l->hd != i) return 0;
    l = l->tl;
  }
  return (l == NULL);
}

int main(int argc, char ** argv)
{
  int n;

  if (argc >= 2) n = atoi(argv[1]); else n = 10;
  if (checklist(n, reverselist(buildlist(n)))) {
    printf("OK\n");
    return 0;
  } else {
    printf("Bug!\n");
    return 2;
  }
}