Beispiel #1
0
// try applying sequence
int try_sequence(SEQLIST *test_sequence, int mem_size) {
  SEQLIST *sptr;
  unsigned char *mblock;

  // reset the memory allocator being tested
  MEMORY_SIZE = mem_size;
  init_myalloc();

  for (sptr = test_sequence; !seq_null(sptr); sptr = seq_next(sptr)) {
    if (seq_alloc(sptr)) {     // allocate a block
      mblock = myalloc(seq_size(sptr));
      if (mblock == 0) {
        return 0; // failed -- return indication
      }
      else {
        // keep track of address allocated (for later frees)
        seq_set_myalloc_block(sptr, mblock);
        // put data in the block
        //  (so we can test that it holds data w/out corruption)
        fill_data(seq_ref_block(sptr), mblock, seq_size(sptr));
      }
    }
    else {    // dealloc
      myfree(seq_myalloc_block(seq_tofree(sptr)));
    }
  }

  return 1; // succeeded in allocating entire sequence
}
Beispiel #2
0
sequence fr_next(fastareader fr) {
  sequence seq;

  seq = seq_alloc();
  if (seq == NULL) {
    return NULL;
  }
  return fr_nextseq(fr,seq);
}
Beispiel #3
0
// check all still allocated blocks in a test sequence
//  contain the data originally placed into them
//  i.e. have not been corrupted
int check_data(SEQLIST *test_sequence) {
  int result;
  SEQLIST *current;

  result = 0; // stays zero if no errors

  for (current = test_sequence; !seq_null(current); current = seq_next(current)) {
    // only check if an allocate which has not been freed
    if (seq_alloc(current) && !seq_freed(current)) {
      if (!same_data(seq_ref_block(current), seq_myalloc_block(current),
                     seq_size(current))) {
        if (VERBOSE) {
          printf("Mismatch in sequence starting at:\n");
          seq_print(current);
        }

        // returning a 1 means it failed
        result = 1;
      }
    }
  }

  return result;
}