Example #1
0
int
main(int argc, char **argv) {
  mt_s   *mtctx;
  int     i;

  psetdebug(2);
  psetblocksize(1024);

  palloc(2048);
  palloc(128);
  palloc(999);
  palloc(1);
  palloc(2);
  palloc(3);
  palloc(4);
  palloc(2056);
  palloc(8);
  palloc(2064);
  palloc(8);
  palloc(2072);
  palloc(8);

  pdumppalloc();

  pfree();

  fprintf(stderr, "----------------------------------------\n");

  psetblocksize(10240);

  palloc(2048);
  palloc(128);
  palloc(999);
  palloc(8);
  palloc(8);
  palloc(8);
  palloc(8);
  palloc(2056);
  palloc(8);
  palloc(2064);
  palloc(8);
  palloc(2072);
  palloc(8);

  pdumppalloc();

  pfree();

  psetdebug(0);
  psetblocksize(16 * 1024 * 1024);

  mtctx = mtInit(time(NULL));
  for (i=0; i<512 * 1024; i++)
    palloc(mtRandom32(mtctx) & 0xfff);
  psetdebug(1);
  pfree();

  return(0);
}
Example #2
0
u32bit
testSeqCache(seqCache *SC) {
  u32bit      err    = 0;
  u32bit      numSeq = SC->getNumberOfSequences();
  seqInCore  *S      = 0L;
  double      start  = getTime();

  //  0 - getSequenceLength()
  fprintf(stderr, "0 - getSequenceLength()\n");
  for (u32bit sid=0; sid<numSeq; sid++)
    if (SC->getSequenceLength(sid) != correctSequence[sid].sequenceLength) {
      fprintf(stderr, "1 - length differs.\n");
      err++;
    }

  //  2 - stream with getSequenceInCore()
  fprintf(stderr, "2 - stream with getSequenceInCore()\n");
  S = SC->getSequenceInCore();
  while (S != 0L) {
    err += testSeqVsCorrect(S, 2);
    delete S;
    S = SC->getSequenceInCore();
  }

  //  3 - iterate with getSequenceInCore(sid++)
  fprintf(stderr, "3 - iterate with getSequenceInCore(sid++)\n");
  for (u32bit sid=0; sid<numSeq; sid++) {
    S = SC->getSequenceInCore(sid);
    err += testSeqVsCorrect(S, 3);
    delete S;
  }

  //  4 - random with getSequenceInCore(sid)
  fprintf(stderr, "4 - random with getSequenceInCore(sid)\n");
  for (u32bit cnt=0; cnt<4*numSeq; cnt++) {
    u32bit sid = mtRandom32(mtctx) % numSeq;
    S = SC->getSequenceInCore(sid);
    err += testSeqVsCorrect(S, 4);
    delete S;
  }

  fprintf(stderr, "Test took %f seconds.\n", getTime() - start);

  return(err);
}
Example #3
0
void
testIntersect(u32bit type) {
  u32bit   numTests = 1000000;
  u32bit  *beg     = new u32bit [numTests];
  u32bit  *len     = new u32bit [numTests];
  u32bit  *end     = new u32bit [numTests];
  u32bit  *abegh   = new u32bit [numTests];
  u32bit  *aendh   = new u32bit [numTests];
  u32bit  *bbegh   = new u32bit [numTests];
  u32bit  *bendh   = new u32bit [numTests];
  u32bit   errors  = 0;
  u32bit   passed  = 0;

  intervalList  A;
  intervalList  B;

  //
  //  Build two interval lists
  //
  //  type == 0 --> all pairwise
  //  type == 1 --> A sequence is solid
  //  type == 2 --> B sequence is solid
  //

  if (type == 1)
    A.add(1, 1500000000);
  if (type == 2)
    B.add(1, 1500000000);

  for (u32bit i=0; i<numTests; i++) {

    //  Compute the result we want to get
    //
    len[i] = mtRandom32(mt) % 200;
    if (len[i] < 100) {
      beg[i] = end[i] = mtRandom32(mt) % 100 + 100;
    } else {
      beg[i] = mtRandom32(mt) % 100 + 100;
      end[i] = beg[i] + len[i];
    }

    //  Reset if the type is 1 or 2.
    //
    if ((type == 1) || (type == 2)) {
      len[i] = mtRandom32(mt) % 100 + 100;
      beg[i] = mtRandom32(mt) % 100 + 100;
      end[i] = beg[i] + len[i];
    }

    //  Extend it to an interval -- we can extend exactly one end, or
    //  two opposite ends.
    //
    abegh[i] = 0;
    aendh[i] = 0;
    bbegh[i] = 0;
    bendh[i] = 0;

    if (type == 0) {
      switch (mtRandom32(mt) % 8) {
        case 0:
          abegh[i] = mtRandom32(mt) % 50;
          break;
        case 1:
          aendh[i] = mtRandom32(mt) % 50;
          break;
        case 2:
          bbegh[i] = mtRandom32(mt) % 50;
          break;
        case 3:
          bendh[i] = mtRandom32(mt) % 50;
          break;
        case 4:
          abegh[i] = mtRandom32(mt) % 50;
          aendh[i] = mtRandom32(mt) % 50;
          break;
        case 5:
          bbegh[i] = mtRandom32(mt) % 50;
          bendh[i] = mtRandom32(mt) % 50;
          break;
        case 6:
          abegh[i] = mtRandom32(mt) % 50;
          bendh[i] = mtRandom32(mt) % 50;
          break;
        case 7:
          aendh[i] = mtRandom32(mt) % 50;
          bbegh[i] = mtRandom32(mt) % 50;
          break;
      }
    }

    //  Add it to the lists -- if type == 1 or 2, these should then
    //  get merged into the one big thing.
    //
    A.add(1000 * i + beg[i] - abegh[i], abegh[i] + end[i] - beg[i] + aendh[i]);
    B.add(1000 * i + beg[i] - bbegh[i], bbegh[i] + end[i] - beg[i] + bendh[i]);
  }

  intervalList I;
  I.intersect(A, B);

  //
  //  Check the result.
  //

  for (u32bit i=0, j=0; i<numTests; i++) {
    u32bit  b = I.lo(j) - 1000 * i;
    u32bit  e = I.hi(j) - 1000 * i;

    if (len[i] < 100) {
      //
      //  Expect no result here.  We ca only test that the stuff that
      //  should be intersecting is correct, and if all that is, then
      //  I guess the non-intersection stuff is correct too.
      //
    } else {
      if ((b != beg[i]) || (e != end[i])) {
        fprintf(stderr, "FAILED[%4d]: "u32bitFMT"-"u32bitFMT" X "u32bitFMT"-"u32bitFMT" -> "u32bitFMT","u32bitFMT" ("u32bitFMT","u32bitFMT") (should have been "u32bitFMT","u32bitFMT")\n",
                i,
                beg[i] - abegh[i], beg[i] - abegh[i] + abegh[i] + end[i] - beg[i] + aendh[i],
                beg[i] - bbegh[i], beg[i] - bbegh[i] + bbegh[i] + end[i] - beg[i] + bendh[i],
                b, e, (u32bit)I.lo(j), (u32bit)I.hi(j),
                beg[i], end[i]);
        errors++;
      } else {
        passed++;
      }
      j++;
    }
  }

  fprintf(stderr, "intersection test had "u32bitFMT" successes and "u32bitFMT" errors.\n", passed, errors);
}
Example #4
0
void
testMerge(void) {
  intervalList  IL;

  //  Test 1:  one long sequence containing lots of little non-overlapping sequences
  //  Test 2:  three long overlapping sequences, containing lots of non-overlapping sequences
  //  Test 3:  dense random
  //  Test 4:  special cases

  fprintf(stderr, "Merge test 1\n");
  IL.clear();
  IL.add(0, 100000);
  for (u32bit i=0; i<999; i++)
    IL.add(100 + 100 * i, 50);
  IL.merge();
  for (u32bit i=0; i<IL.numberOfIntervals(); i++)
    fprintf(stderr, "IL["u32bitFMTW(3)"] "u64bitFMT" "u64bitFMT"\n", i, IL.lo(i), IL.hi(i));

  fprintf(stderr, "Merge test 2\n");
  IL.clear();
  IL.add(0, 25000);
  IL.add(25000, 25000);
  IL.add(50000, 50000);
  for (u32bit i=0; i<999; i++)
    IL.add(100 + 100 * i, 50);
  IL.merge();
  for (u32bit i=0; i<IL.numberOfIntervals(); i++)
    fprintf(stderr, "IL["u32bitFMTW(3)"] "u64bitFMT" "u64bitFMT"\n", i, IL.lo(i), IL.hi(i));

  fprintf(stderr, "Merge test 3\n");
  IL.clear();
  u32bit lo = 200;
  u32bit hi = 0;
  for (u32bit i=0; i<999; i++) {
    u32bit beg = mtRandom32(mt) % 100;
    u32bit end = mtRandom32(mt) % 100 + 100;
    if (beg < lo)  lo = beg;
    if (end > hi)  hi = end;
    IL.add(beg, end - beg);
  }
  IL.merge();
  if ((IL.lo(0) != lo) || (IL.hi(0) != hi))
    fprintf(stderr, "ERROR!\n");
  for (u32bit i=0; i<IL.numberOfIntervals(); i++)
    fprintf(stderr, "IL["u32bitFMTW(3)"] "u64bitFMT" "u64bitFMT"\n", i, IL.lo(i), IL.hi(i));

  fprintf(stderr, "Merge test 4a\n");
  IL.clear();
  IL.add(0, 25000);
  IL.add(25000, 25000);
  IL.add(50000, 50000);
  IL.merge();
  for (u32bit i=0; i<IL.numberOfIntervals(); i++)
    fprintf(stderr, "IL["u32bitFMTW(3)"] "u64bitFMT" "u64bitFMT"\n", i, IL.lo(i), IL.hi(i));

  fprintf(stderr, "Merge test 4b\n");
  IL.clear();
  IL.add(0, 25000);
  IL.add(25000, 25000);
  IL.add(50000, 50000);
  IL.add(20000, 5000);
  IL.add(45000, 5000);
  IL.add(95000, 5000);
  IL.merge();
  for (u32bit i=0; i<IL.numberOfIntervals(); i++)
    fprintf(stderr, "IL["u32bitFMTW(3)"] "u64bitFMT" "u64bitFMT"\n", i, IL.lo(i), IL.hi(i));
}
Example #5
0
int
main(int argc, char **argv) {

  mt_s *mtctx = mtInit(time(NULL));

  //  Test the bitPackedArray by writing a bunch of random gibberish
  //  to it, and see if it's the same.

  u32bit  *pos = new u32bit [testSize];
  u64bit  *val = new u64bit [testSize];
  u64bit  *ans = new u64bit [arrySize];

  bitPackedArray *ARR  = new bitPackedArray(wordSize, 16);
  u32bit          fail = u32bitZERO;

#if 1
  fprintf(stderr, "Touching the end of the array and clearing.\n");
  //ARR->set(arrySize, 0);
  //ARR->clear();

  fprintf(stderr, "Generating random test data.\n");

  //  Hit every element first, just to do it
  for (u32bit i=0; i<arrySize; i++) {
    pos[i]       = i;
    val[i]       = mtRandom64(mtctx);
    val[i]      &= u64bitMASK(wordSize);
    ans[pos[i]]  = val[i];
  }

  //  Then hit random elements, with replacement, looking for bugs
  for (u32bit i=arrySize; i<testSize; i++) {
    pos[i]       = mtRandom32(mtctx) % arrySize;
    val[i]       = mtRandom64(mtctx);
    val[i]      &= u64bitMASK(wordSize);
    ans[pos[i]]  = val[i];
  }

  fprintf(stderr, "Filling array.\n");

  for (u32bit i=0; i<testSize; i++)
    ARR->set(pos[i], val[i]);

  fprintf(stderr, "Validating array.\n");

  for (u32bit i=0; i<arrySize; i++)
    if (ARR->get(i) != ans[i]) {
      fprintf(stderr, "FAIL at i="u32bitFMT"\n", i);
      fail++;

      if (fail > 1024) {
        fprintf(stderr, "bitPackedArray has errors, aborting!\n");
        return(1);
      }
    }

  if (fail) {
    fprintf(stderr, "bitPackedArray had "u32bitFMT" errors.\n", fail);
    return(1);
  }

  fprintf(stderr, "OK!\n");
#endif

  delete    ARR;
  delete [] pos;
  delete [] val;
  delete [] ans;

  //
  //
  //

  for (u32bit testNum=0; testNum<32; testNum++) {
    u32bit  thisTestSize = 0;
    u32bit  thisWordSize = 0;

    //  Test a BIG heap the first iteration.
    if (testNum == 0) {
      thisTestSize = 857353; //23987153;
      thisWordSize = 63;

      fprintf(stderr, "Building heap "u32bitFMT" (wordsize="u32bitFMT" testsize="u32bitFMT").\n",
              testNum, thisWordSize, thisTestSize);
    } else {
      thisTestSize = (mtRandom64(mtctx) % (2 * testNum)) * 1024 + 1024;
      thisWordSize = (mtRandom64(mtctx) % 63) + 1;
    }

    u32bit  blockSize = mtRandom64(mtctx) % 32 + 1;
    bitPackedHeap  *HEAP = new bitPackedHeap(thisWordSize, blockSize);

    val = new u64bit [thisTestSize];
    for (u32bit i=0; i<thisTestSize; i++) {
      val[i]       = mtRandom64(mtctx);
      val[i]      &= u64bitMASK(thisWordSize);
      HEAP->add(val[i]);
    }

    fprintf(stderr, "Testing heap "u32bitFMT" (wordsize="u32bitFMT" testsize="u32bitFMT").\n",
            testNum, thisWordSize, thisTestSize);

    qsort(val, thisTestSize, sizeof(u64bit), u64bitcompare);

    for (u32bit i=0; i<thisTestSize; i++) {
      u64bit  h = HEAP->get();

      //fprintf(stderr, "val["u32bitFMT"]="u64bitFMT" -- HEAP="u64bitFMT"\n", i, val[i], h);

      if (val[i] != h) {
        fprintf(stderr, "val["u32bitFMT"]="u64bitFMT" !! HEAP="u64bitFMT"\n", i, val[i], h);
        fail++;
        if (fail > 25) {
          fprintf(stderr, "bitPackedHeap has errors, aborting!\n");
          return(1);
        }
      }
    }
    
    if (fail) {
      fprintf(stderr, "bitPackedHeap had "u32bitFMT" errors.!\n", fail);
      return(1);
    }

    delete    HEAP;
    delete [] val;
  }

  fprintf(stderr, "OK!\n");

  return(fail);
}
void
testBinaryEncoding(void) {
  time_t     mtseed     = time(0L);
  mt_s      *mtctx      = 0L;

  uint32     iterations = TEST_LENGTH;

  uint64    *bits        = new uint64 [iterations + 2];
  uint64     bpos        = uint64ZERO;

  uint64    *V           = new uint64 [iterations];
  uint64    *C           = new uint64 [iterations];
  uint64    *S           = new uint64 [iterations];

  uint32     failed      = 0;
  uint32     errors      = 0;

  fprintf(stderr, "Starting test of binary encoding\n");

  bpos   = uint64ZERO;
  mtctx = mtInit(mtseed);

  //  Build some values to stuff into the bits

  for (uint32 j=0; j < iterations; j++) {
    S[j] = (mtRandom32(mtctx) % 63) + 1;
    V[j] = mtRandom64(mtctx) & uint64MASK(S[j]);
    //fprintf(stderr, "[%2d] S="uint64FMT" V="uint64HEX"\n", j, S[j], V[j]);
  }

  //  Stuff them in, in blocks of some size.  At the same time, decode
  //  (this has found bugs in the past).

  failed = 0;
  for (uint32 j=0; j < iterations; ) {
    uint64 num = (mtRandom32(mtctx) % 8);

    if (j + num > iterations)
      num = iterations - j;

    if (num == 0) {
      setDecodedValue(bits, bpos, S[j], V[j]);
      C[j] = getDecodedValue(bits, bpos, S[j]);
      //fprintf(stderr, "[%2d] V="uint64HEX" C="uint64HEX" single\n", j, V[j], C[j]);
      bpos += S[j];
    } else {
      uint64 newp1 = setDecodedValues(bits, bpos, num, S+j, V+j);
      uint64 newp2 = getDecodedValues(bits, bpos, num, S+j, C+j);

      if (newp1 != newp2) {
        //  not perfect; we should be checking the values too, but we do that later.
        for (uint32 x=0; x<num; x++)
          fprintf(stderr, "[%2d] #1 V="uint64HEX" C="uint64HEX" multiple "uint32FMT" %s\n",
                  j+x, V[j+x], C[j+x], num, (V[j+x] == C[j+x]) ? "" : "FAILED");
        failed++;
      }

      bpos = newp2;
    }

    j += num;
    if (num == 0)
      j++;
  }
  if (failed) {
    fprintf(stderr, "binEncoding #1 failed encoding "uint32FMT" times.\n", failed);
    errors++;
  }

  //  Check that V == C

  failed = 0;
  for (uint32 j=0; j<iterations; j++) {
    if (V[j] != C[j]) {
      fprintf(stderr, "[%2d] #2 V="uint64HEX" C="uint64HEX" S="uint32FMT"\n",
              j, V[j], C[j], S[j]);
      failed++;
    }
  }
  if (failed) {
    fprintf(stderr, "binEncoding #2 failed encode/decode "uint32FMT" times.\n", failed);
    errors++;
  }


  //  Decode independently, with different nums

  bpos = 0;  //  reset to start of bits

  for (uint32 j=0; j < iterations; ) {
    uint64 num = (mtRandom32(mtctx) % 8);

    if (j + num > iterations)
      num = iterations - j;

    if (num == 0) {
      C[j] = getDecodedValue(bits, bpos, S[j]);
      bpos += S[j];
    } else {
      bpos = getDecodedValues(bits, bpos, num, S+j, C+j);
    }

    j += num;
    if (num == 0)
      j++;
  }

  //  Check that V == C

  failed = 0;
  for (uint32 j=0; j<iterations; j++) {
    if (V[j] != C[j]) {
      fprintf(stderr, "[%2d] #3 V="uint64HEX" C="uint64HEX" S="uint32FMT"\n",
              j, V[j], C[j], S[j]);
      failed++;
    }
  }
  if (failed) {
    fprintf(stderr, "binEncoding #3 failed decoding "uint32FMT" times.\n", failed);
    errors++;
  }

  //  Clean.

  delete [] bits;
  delete [] V;
  delete [] C;
  delete [] S;

  if (errors)
    exit(1);
}
void
testFibonacciEncoding(void) {
  time_t     mtseed     = time(0L);
  mt_s      *mtctx      = 0L;

  uint32     iterations = TEST_LENGTH / 4;

  uint64    *bits        = new uint64 [3 * iterations];
  uint64     bpos        = uint64ZERO;

  uint32     failed = 0;
  uint32     errors = 0;

  fprintf(stderr, "Starting test of fibonacci encoding\n");

  bpos   = uint64ZERO;
  mtctx  = mtInit(mtseed);
  failed = 0;

  for (uint32 j=0; j < iterations; j++) {
    uint64 siz1  = (mtRandom32(mtctx) % 63) + 1;
    uint64 val1  = mtRandom64(mtctx) & uint64MASK(siz1);
    uint64 siz2  = siz1;

    setFibonacciEncodedNumber(bits, bpos, &siz1, val1);

    uint64 val2 = getFibonacciEncodedNumber(bits, bpos, &siz2);

    if ((val1 != val2) || (siz1 != siz2)) {
      fprintf(stderr, "fibEnc #1 failed on "uint32FMT": got "uint64FMT" expected "uint64FMT"\n", j, val2, val1);
      failed++;
    }
    bpos += siz1;
  }
  if (failed) {
    fprintf(stderr, "fibEnc #1 failed "uint32FMT" times.\n", failed);
    errors++;
  }

  bpos   = uint64ZERO;
  mtctx  = mtInit(mtseed);
  failed = 0;

  for (uint32 j=0; j < iterations; j++) {
    uint64 siz1  = (mtRandom32(mtctx) % 63) + 1;
    uint64 val1  = mtRandom64(mtctx) & uint64MASK(siz1);
    uint64 val2  = getFibonacciEncodedNumber(bits, bpos, &siz1);

    if (val1 != val2) {
      fprintf(stderr, "fibEnc #2 failed on "uint32FMT": got "uint64FMT" expected "uint64FMT"\n", j, val2, val1);
      failed++;
    }
    bpos += siz1;
  }
  if (failed) {
    fprintf(stderr, "fibEnc #2 failed "uint32FMT" times.\n", failed);
    errors++;
  }

  delete [] bits;

  if (errors)
    exit(1);
}
void
testBinaryEncodingPrePost(void) {
  time_t     mtseed     = time(0L);
  mt_s      *mtctx      = 0L;

  uint32     iterations = TEST_LENGTH;

  uint64    *bits        = new uint64 [2 * iterations];
  uint64     bpos        = uint64ZERO;
  uint32     siz1       = uint64ZERO;
  uint64     val1       = uint64ZERO;
  uint64     val2       = uint64ZERO;

  fprintf(stderr, "Starting test of binary encoding pre/post increment\n");

  bpos   = uint64ZERO;
  mtctx = mtInit(mtseed);

  for (uint32 j=0; j < iterations; j++) {
    siz1  = (mtRandom32(mtctx) % 63) + 1;
    val1  = mtRandom64(mtctx) & uint64MASK(siz1);

    setDecodedValue(bits, bpos, siz1, val1);

    val2 = postDecrementDecodedValue(bits, bpos, siz1);
    if (val2 != val1) {
      fprintf(stderr, "postDec1 failed: got "uint64FMT" expected "uint64FMT" siz="uint32FMT"\n",
              val2, val1, siz1);
      exit(1);
    }
    val2  = getDecodedValue(bits, bpos, siz1) + 1;
    val2 &= uint64MASK(siz1);
    if (val2 != val1) {
      fprintf(stderr, "postDec2 failed: got "uint64FMT" expected "uint64FMT" siz="uint32FMT"\n",
              val2, val1, siz1);
      exit(1);
    }

    val2 = preDecrementDecodedValue(bits, bpos, siz1) + 2;
    val2 &= uint64MASK(siz1);
    if (val2 != val1) {
      fprintf(stderr, "preDec failed: got "uint64FMT" expected "uint64FMT" siz="uint32FMT"\n",
              val2, val1, siz1);
      exit(1);
    }

    val2 = postIncrementDecodedValue(bits, bpos, siz1) + 2;
    val2 &= uint64MASK(siz1);
    if (val2 != val1) {
      fprintf(stderr, "postInc failed: got "uint64FMT" expected "uint64FMT"\n", val2+2, val1-2);
      exit(1);
    }
    val2  = getDecodedValue(bits, bpos, siz1) + 1;
    val2 &= uint64MASK(siz1);
    if (val2 != val1) {
      fprintf(stderr, "postInc2 failed: got "uint64FMT" expected "uint64FMT" siz="uint32FMT"\n",
              val2, val1, siz1);
      exit(1);
    }

    val2 = preIncrementDecodedValue(bits, bpos, siz1);
    //  Should be back to original value, so no mask
    if (val2 != val1) {
      fprintf(stderr, "preInc failed: got "uint64FMT" expected "uint64FMT"\n", val2, val1);
      exit(1);
    }

    switch (j % 4) {
      case 0:
        val2 = postDecrementDecodedValue(bits, bpos, siz1);
        break;
      case 1:
        val2 = preDecrementDecodedValue(bits, bpos, siz1);
        break;
      case 2:
        val2 = postIncrementDecodedValue(bits, bpos, siz1);
        break;
      case 3:
        val2 = preIncrementDecodedValue(bits, bpos, siz1);
        break;
    }

    bpos += siz1;
  }

  bpos   = uint64ZERO;
  mtctx = mtInit(mtseed);

  //for (j=0; j < iterations; j++) {
  //}

  delete [] bits;
}