Ejemplo n.º 1
0
int main(int argc, char **argv) {
    int nthreads;

    if (1 == argc) {
      nthreads = DEFAULT_NTHREADS;
    } else if (2 == argc) {
      nthreads = atoi(argv[1]);
      if (nthreads < 1 || nthreads > MAX_NTHREADS) {
        fprintf(stderr, "Invalid # of threads argument\n");
        exit(1);
      }
    } else {
      fprintf(stderr, "Usage: %s [# of threads]\n", argv[0]);
      exit(1);
    }
    printf("Performing %d reversals of %d element lists in %d threads\n",
           N_REVERSALS, LIST_LENGTH, nthreads);
    AO_malloc_enable_mmap();

    /* Test various corner cases. */
    AO_free(NULL);
    AO_free(AO_malloc(0));
#   ifdef HAVE_MMAP
      AO_free(AO_malloc(CHUNK_SIZE - (sizeof(AO_t)-1))); /* large alloc */
#   endif

    run_parallel(nthreads, run_one_test, dummy_test, "AO_malloc/AO_free");
    return 0;
}
Ejemplo n.º 2
0
void * run_one_test(void * arg) {
  ln * x = make_list(1, LIST_LENGTH);
  int i;
  char *p = (char *)AO_malloc(LARGE_OBJ_SIZE);
  char *q;
  char a = 'a' + ((int)((AO_PTRDIFF_T)arg) * 2) % ('z' - 'a' + 1);
  char b = a + 1;

  if (0 == p) {
#   ifdef HAVE_MMAP
      fprintf(stderr, "AO_malloc(%d) failed\n", LARGE_OBJ_SIZE);
      abort();
#   else
      fprintf(stderr, "AO_malloc(%d) failed: This is normal without mmap\n",
              LARGE_OBJ_SIZE);
#   endif
  } else {
    p[0] = p[LARGE_OBJ_SIZE/2] = p[LARGE_OBJ_SIZE-1] = a;
    q = (char *)AO_malloc(LARGE_OBJ_SIZE);
    if (q == 0)
      {
        fprintf(stderr, "Out of memory\n");
          /* Normal for more than about 10 threads without mmap? */
        exit(2);
      }
    q[0] = q[LARGE_OBJ_SIZE/2] = q[LARGE_OBJ_SIZE-1] = b;
    if (p[0] != a || p[LARGE_OBJ_SIZE/2] != a || p[LARGE_OBJ_SIZE-1] != a) {
      fprintf(stderr, "First large allocation smashed\n");
      abort();
    }
    AO_free(p);
    if (q[0] != b || q[LARGE_OBJ_SIZE/2] != b || q[LARGE_OBJ_SIZE-1] != b) {
      fprintf(stderr, "Second large allocation smashed\n");
      abort();
    }
    AO_free(q);
  }
# ifdef DEBUG_RUN_ONE_TEST
    x = reverse(x, 0);
    print_list(x);
    x = reverse(x, 0);
    print_list(x);
# endif
  for (i = 0; i < N_REVERSALS; ++i) {
    x = reverse(x, 0);
  }
  check_list(x, 1, LIST_LENGTH);
  free_list(x);
  return NULL;
}
Ejemplo n.º 3
0
void * run_one_test(void * arg) {
  ln * x = make_list(1, LIST_LENGTH);
  int i;
  char *p = AO_malloc(LARGE_OBJ_SIZE);
  char *q;

  if (0 == p) {
#   ifdef HAVE_MMAP
      fprintf(stderr, "AO_malloc(%d) failed\n", LARGE_OBJ_SIZE);
      abort();
#   else
      fprintf(stderr, "AO_malloc(%d) failed: This is normal without mmap\n",
              LARGE_OBJ_SIZE);
#   endif
  } else {
    p[0] = p[LARGE_OBJ_SIZE/2] = p[LARGE_OBJ_SIZE-1] = 'a';
    q = AO_malloc(LARGE_OBJ_SIZE);
    if (q == 0)
      {
        fprintf(stderr, "Out of memory\n");
          /* Normal for more than about 10 threads without mmap? */
        exit(2);
      }
    q[0] = q[LARGE_OBJ_SIZE/2] = q[LARGE_OBJ_SIZE-1] = 'b';
    if (p[0] != 'a' || p[LARGE_OBJ_SIZE/2] != 'a'
        || p[LARGE_OBJ_SIZE-1] != 'a') {
      fprintf(stderr, "First large allocation smashed\n");
      abort();
    }
    AO_free(p);
    if (q[0] != 'b' || q[LARGE_OBJ_SIZE/2] != 'b'
        || q[LARGE_OBJ_SIZE-1] != 'b') {
      fprintf(stderr, "Second large allocation smashed\n");
      abort();
    }
    AO_free(q);
  }
# ifdef DEBUG_RUN_ONE_TEST
    x = reverse(x, 0);
    print_list(x);
    x = reverse(x, 0);
    print_list(x);
# endif
  for (i = 0; i < N_REVERSALS; ++i) {
    x = reverse(x, 0);
  }
  check_list(x, 1, LIST_LENGTH);
  return arg; /* use arg to suppress compiler warning */
}
Ejemplo n.º 4
0
void free_list(ln *x)
{
  while (x != NULL) {
    ln *next = x -> next;
    AO_free(x);
    x = next;
  }
}
Ejemplo n.º 5
0
/* nodes in x.                                                            */
ln *
reverse(ln *x, ln *y)
{
  ln * result;

  if (x == 0) return y;
  result = reverse(x -> next, cons(x -> data, y));
  AO_free(x);
  return result;
}
Ejemplo n.º 6
0
void * run_one_test(void * arg) {
  ln * x = make_list(1, LIST_LENGTH);
  int i;
  char *p = AO_malloc(LARGE_OBJ_SIZE);
  char *q;

  if (0 == p) {
    fprintf(stderr, "AO_malloc(%d) failed: This is normal without mmap\n",
            LARGE_OBJ_SIZE);
    AO_free(p);
  } else {
    p[0] = p[LARGE_OBJ_SIZE/2] = p[LARGE_OBJ_SIZE-1] = 'a';
    q = AO_malloc(LARGE_OBJ_SIZE);
    q[0] = q[LARGE_OBJ_SIZE/2] = q[LARGE_OBJ_SIZE-1] = 'b';
    if (p[0] != 'a' || p[LARGE_OBJ_SIZE/2] != 'a'
        || p[LARGE_OBJ_SIZE-1] != 'a') {
      fprintf(stderr, "First large allocation smashed\n");
      abort();
    }
    AO_free(p);
    if (q[0] != 'b' || q[LARGE_OBJ_SIZE/2] != 'b'
        || q[LARGE_OBJ_SIZE-1] != 'b') {
      fprintf(stderr, "Second large allocation smashed\n");
      abort();
    }
    AO_free(q);
  }
# ifdef DEBUG_RUN_ONE_TEST
    x = reverse(x, 0);
    print_list(x);
    x = reverse(x, 0);
    print_list(x);
# endif
  for (i = 0; i < N_REVERSALS; ++i) {
    x = reverse(x, 0);
  }
  check_list(x, 1, LIST_LENGTH);
  return 0;
}